1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * Declarations of utility classes and functions
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef __VBoxUtils_h__
|
---|
24 | #define __VBoxUtils_h__
|
---|
25 |
|
---|
26 | /* Qt includes */
|
---|
27 | #include <QMouseEvent>
|
---|
28 | #include <QWidget>
|
---|
29 | #include <QTextBrowser>
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Simple class that filters out all key presses and releases
|
---|
33 | * got while the Alt key is pressed. For some very strange reason,
|
---|
34 | * QLineEdit accepts those combinations that are not used as accelerators,
|
---|
35 | * and inserts the corresponding characters to the entry field.
|
---|
36 | */
|
---|
37 | class QIAltKeyFilter : protected QObject
|
---|
38 | {
|
---|
39 | Q_OBJECT;
|
---|
40 |
|
---|
41 | public:
|
---|
42 |
|
---|
43 | QIAltKeyFilter (QObject *aParent) :QObject (aParent) {}
|
---|
44 |
|
---|
45 | void watchOn (QObject *aObject) { aObject->installEventFilter (this); }
|
---|
46 |
|
---|
47 | protected:
|
---|
48 |
|
---|
49 | bool eventFilter (QObject * /* aObject */, QEvent *aEvent)
|
---|
50 | {
|
---|
51 | if (aEvent->type() == QEvent::KeyPress || aEvent->type() == QEvent::KeyRelease)
|
---|
52 | {
|
---|
53 | QKeyEvent *event = static_cast<QKeyEvent *> (aEvent);
|
---|
54 | if (event->modifiers() & Qt::AltModifier)
|
---|
55 | return true;
|
---|
56 | }
|
---|
57 | return false;
|
---|
58 | }
|
---|
59 | };
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Simple class which simulates focus-proxy rule redirecting widget
|
---|
63 | * assigned shortcut to desired widget.
|
---|
64 | */
|
---|
65 | class QIFocusProxy : protected QObject
|
---|
66 | {
|
---|
67 | Q_OBJECT;
|
---|
68 |
|
---|
69 | public:
|
---|
70 |
|
---|
71 | QIFocusProxy (QWidget *aFrom, QWidget *aTo)
|
---|
72 | : QObject (aFrom), mFrom (aFrom), mTo (aTo)
|
---|
73 | {
|
---|
74 | mFrom->installEventFilter (this);
|
---|
75 | }
|
---|
76 |
|
---|
77 | protected:
|
---|
78 |
|
---|
79 | bool eventFilter (QObject *aObject, QEvent *aEvent)
|
---|
80 | {
|
---|
81 | if (aObject == mFrom && aEvent->type() == QEvent::Shortcut)
|
---|
82 | {
|
---|
83 | mTo->setFocus();
|
---|
84 | return true;
|
---|
85 | }
|
---|
86 | return QObject::eventFilter (aObject, aEvent);
|
---|
87 | }
|
---|
88 |
|
---|
89 | QWidget *mFrom;
|
---|
90 | QWidget *mTo;
|
---|
91 | };
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * QTextEdit reimplementation to feat some extended requirements.
|
---|
95 | */
|
---|
96 | class QRichTextEdit : public QTextEdit
|
---|
97 | {
|
---|
98 | Q_OBJECT;
|
---|
99 |
|
---|
100 | public:
|
---|
101 |
|
---|
102 | QRichTextEdit (QWidget *aParent) : QTextEdit (aParent) {}
|
---|
103 |
|
---|
104 | void setViewportMargins (int aLeft, int aTop, int aRight, int aBottom)
|
---|
105 | {
|
---|
106 | QTextEdit::setViewportMargins (aLeft, aTop, aRight, aBottom);
|
---|
107 | }
|
---|
108 | };
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * QTextBrowser reimplementation to feat some extended requirements.
|
---|
112 | */
|
---|
113 | class QRichTextBrowser : public QTextBrowser
|
---|
114 | {
|
---|
115 | Q_OBJECT;
|
---|
116 |
|
---|
117 | public:
|
---|
118 |
|
---|
119 | QRichTextBrowser (QWidget *aParent) : QTextBrowser (aParent) {}
|
---|
120 |
|
---|
121 | void setViewportMargins (int aLeft, int aTop, int aRight, int aBottom)
|
---|
122 | {
|
---|
123 | QTextBrowser::setViewportMargins (aLeft, aTop, aRight, aBottom);
|
---|
124 | }
|
---|
125 | };
|
---|
126 |
|
---|
127 | #ifdef Q_WS_MAC
|
---|
128 | # undef PAGE_SIZE
|
---|
129 | # undef PAGE_SHIFT
|
---|
130 | # include <Carbon/Carbon.h>
|
---|
131 |
|
---|
132 | /* Asserts if a != noErr and prints the error code */
|
---|
133 | #define AssertCarbonOSStatus(a) AssertMsg ((a) == noErr, ("Carbon OSStatus: %d\n", static_cast<int> (a)))
|
---|
134 |
|
---|
135 | class QImage;
|
---|
136 | class QPixmap;
|
---|
137 | class QToolBar;
|
---|
138 | class VBoxFrameBuffer;
|
---|
139 |
|
---|
140 | /* Converting stuff */
|
---|
141 | CGImageRef darwinToCGImageRef (const QImage *aImage);
|
---|
142 | CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
|
---|
143 | CGImageRef darwinToCGImageRef (const char *aSource);
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Returns a reference to the HIView of the QWidget.
|
---|
147 | *
|
---|
148 | * @returns HIViewRef of the QWidget.
|
---|
149 | * @param aWidget Pointer to the QWidget
|
---|
150 | */
|
---|
151 | inline HIViewRef darwinToHIViewRef (QWidget *aWidget)
|
---|
152 | {
|
---|
153 | return HIViewRef(aWidget->winId());
|
---|
154 | }
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Returns a reference to the Window of the HIView.
|
---|
158 | *
|
---|
159 | * @returns WindowRef of the HIView.
|
---|
160 | * @param aViewRef Reference to the HIView
|
---|
161 | */
|
---|
162 | inline WindowRef darwinToWindowRef (HIViewRef aViewRef)
|
---|
163 | {
|
---|
164 | return reinterpret_cast<WindowRef> (HIViewGetWindow(aViewRef));
|
---|
165 | }
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * Returns a reference to the Window of the QWidget.
|
---|
169 | *
|
---|
170 | * @returns WindowRef of the QWidget.
|
---|
171 | * @param aWidget Pointer to the QWidget
|
---|
172 | */
|
---|
173 | inline WindowRef darwinToWindowRef (QWidget *aWidget)
|
---|
174 | {
|
---|
175 | return ::darwinToWindowRef (::darwinToHIViewRef (aWidget));
|
---|
176 | }
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * Returns a reference to the CGContext of the QWidget.
|
---|
180 | *
|
---|
181 | * @returns CGContextRef of the QWidget.
|
---|
182 | * @param aWidget Pointer to the QWidget
|
---|
183 | */
|
---|
184 | inline CGContextRef darwinToCGContextRef (QWidget *aWidget)
|
---|
185 | {
|
---|
186 | return static_cast<CGContext *> (aWidget->macCGHandle());
|
---|
187 | }
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Converts a QRect to a HIRect.
|
---|
191 | *
|
---|
192 | * @returns HIRect for the converted QRect.
|
---|
193 | * @param aRect the QRect to convert
|
---|
194 | */
|
---|
195 | inline HIRect darwinToHIRect (const QRect &aRect)
|
---|
196 | {
|
---|
197 | return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height());
|
---|
198 | }
|
---|
199 |
|
---|
200 | QString darwinSystemLanguage();
|
---|
201 |
|
---|
202 | bool darwinIsMenuOpen();
|
---|
203 |
|
---|
204 | void darwinSetShowToolBarButton (QToolBar *aToolBar, bool aShow);
|
---|
205 |
|
---|
206 | void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget);
|
---|
207 |
|
---|
208 | /* Proxy icon creation */
|
---|
209 | QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText);
|
---|
210 |
|
---|
211 | /* Special routines for the dock handling */
|
---|
212 | CGImageRef darwinCreateDockBadge (const char *aSource);
|
---|
213 | void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
|
---|
214 | void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
|
---|
215 |
|
---|
216 | /* Icons in the menu of an mac application are unusual. */
|
---|
217 | void darwinDisableIconsInMenus();
|
---|
218 |
|
---|
219 | /* Experimental region handler for the seamless mode */
|
---|
220 | OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
|
---|
221 |
|
---|
222 | /* Handler for the OpenGL overlay window stuff & the possible messages. */
|
---|
223 | enum
|
---|
224 | {
|
---|
225 | /* Event classes */
|
---|
226 | kEventClassVBox = 'vbox',
|
---|
227 | /* Event kinds */
|
---|
228 | kEventVBoxShowWindow = 'swin',
|
---|
229 | kEventVBoxMoveWindow = 'mwin',
|
---|
230 | kEventVBoxResizeWindow = 'rwin',
|
---|
231 | };
|
---|
232 | OSStatus darwinOverlayWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
|
---|
233 |
|
---|
234 | # ifdef DEBUG
|
---|
235 | void darwinDebugPrintEvent (const char *aPrefix, EventRef aEvent);
|
---|
236 | # endif
|
---|
237 | #endif /* Q_WS_MAC */
|
---|
238 |
|
---|
239 | #endif // __VBoxUtils_h__
|
---|
240 |
|
---|