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 |
|
---|
30 | /**
|
---|
31 | * Simple class that filters out all key presses and releases
|
---|
32 | * got while the Alt key is pressed. For some very strange reason,
|
---|
33 | * QLineEdit accepts those combinations that are not used as accelerators,
|
---|
34 | * and inserts the corresponding characters to the entry field.
|
---|
35 | */
|
---|
36 | class QIAltKeyFilter : protected QObject
|
---|
37 | {
|
---|
38 | public:
|
---|
39 |
|
---|
40 | QIAltKeyFilter (QObject *aParent) :QObject (aParent) {}
|
---|
41 |
|
---|
42 | void watchOn (QObject *aObject) { aObject->installEventFilter (this); }
|
---|
43 |
|
---|
44 | protected:
|
---|
45 |
|
---|
46 | bool eventFilter (QObject * /* aObject */, QEvent *aEvent)
|
---|
47 | {
|
---|
48 | if (aEvent->type() == QEvent::KeyPress || aEvent->type() == QEvent::KeyRelease)
|
---|
49 | {
|
---|
50 | QKeyEvent *event = static_cast<QKeyEvent *> (aEvent);
|
---|
51 | if (event->modifiers() & Qt::AltModifier)
|
---|
52 | return true;
|
---|
53 | }
|
---|
54 | return false;
|
---|
55 | }
|
---|
56 | };
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Simple class which simulates focus-proxy rule redirecting widget
|
---|
60 | * assigned shortcut to desired widget.
|
---|
61 | */
|
---|
62 | class QIFocusProxy : protected QObject
|
---|
63 | {
|
---|
64 | public:
|
---|
65 |
|
---|
66 | QIFocusProxy (QWidget *aFrom, QWidget *aTo)
|
---|
67 | : QObject (aFrom), mFrom (aFrom), mTo (aTo)
|
---|
68 | {
|
---|
69 | mFrom->installEventFilter (this);
|
---|
70 | }
|
---|
71 |
|
---|
72 | protected:
|
---|
73 |
|
---|
74 | bool eventFilter (QObject *aObject, QEvent *aEvent)
|
---|
75 | {
|
---|
76 | if (aObject == mFrom && aEvent->type() == QEvent::Shortcut)
|
---|
77 | {
|
---|
78 | mTo->setFocus();
|
---|
79 | return true;
|
---|
80 | }
|
---|
81 | return QObject::eventFilter (aObject, aEvent);
|
---|
82 | }
|
---|
83 |
|
---|
84 | QWidget *mFrom;
|
---|
85 | QWidget *mTo;
|
---|
86 | };
|
---|
87 |
|
---|
88 | #ifdef Q_WS_MAC
|
---|
89 | # undef PAGE_SIZE
|
---|
90 | # undef PAGE_SHIFT
|
---|
91 | # include <Carbon/Carbon.h>
|
---|
92 |
|
---|
93 | /* Asserts if a != noErr and prints the error code */
|
---|
94 | #define AssertCarbonOSStatus(a) AssertMsg ((a) == noErr, ("Carbon OSStatus: %d\n", static_cast<int> (a)))
|
---|
95 |
|
---|
96 | class QImage;
|
---|
97 | class QPixmap;
|
---|
98 | class VBoxFrameBuffer;
|
---|
99 |
|
---|
100 | /* Converting stuff */
|
---|
101 | CGImageRef darwinToCGImageRef (const QImage *aImage);
|
---|
102 | CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
|
---|
103 | CGImageRef darwinToCGImageRef (const char *aSource);
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Returns a reference to the HIView of the QWidget.
|
---|
107 | *
|
---|
108 | * @returns HIViewRef of the QWidget.
|
---|
109 | * @param aWidget Pointer to the QWidget
|
---|
110 | */
|
---|
111 | inline HIViewRef darwinToHIViewRef (QWidget *aWidget)
|
---|
112 | {
|
---|
113 | return HIViewRef(aWidget->winId());
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Returns a reference to the Window of the HIView.
|
---|
118 | *
|
---|
119 | * @returns WindowRef of the HIView.
|
---|
120 | * @param aViewRef Reference to the HIView
|
---|
121 | */
|
---|
122 | inline WindowRef darwinToWindowRef (HIViewRef aViewRef)
|
---|
123 | {
|
---|
124 | return reinterpret_cast<WindowRef> (HIViewGetWindow(aViewRef));
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Returns a reference to the Window of the QWidget.
|
---|
129 | *
|
---|
130 | * @returns WindowRef of the QWidget.
|
---|
131 | * @param aWidget Pointer to the QWidget
|
---|
132 | */
|
---|
133 | inline WindowRef darwinToWindowRef (QWidget *aWidget)
|
---|
134 | {
|
---|
135 | return ::darwinToWindowRef (::darwinToHIViewRef (aWidget));
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Returns a reference to the CGContext of the QWidget.
|
---|
140 | *
|
---|
141 | * @returns CGContextRef of the QWidget.
|
---|
142 | * @param aWidget Pointer to the QWidget
|
---|
143 | */
|
---|
144 | inline CGContextRef darwinToCGContextRef (QWidget *aWidget)
|
---|
145 | {
|
---|
146 | return static_cast<CGContext *> (aWidget->macCGHandle());
|
---|
147 | }
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Converts a QRect to a HIRect.
|
---|
151 | *
|
---|
152 | * @returns HIRect for the converted QRect.
|
---|
153 | * @param aRect the QRect to convert
|
---|
154 | */
|
---|
155 | inline HIRect darwinToHIRect (const QRect &aRect)
|
---|
156 | {
|
---|
157 | return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height());
|
---|
158 | }
|
---|
159 |
|
---|
160 | /* Proxy icon creation */
|
---|
161 | QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText);
|
---|
162 |
|
---|
163 | /* Special routines for the dock handling */
|
---|
164 | CGImageRef darwinCreateDockBadge (const char *aSource);
|
---|
165 | void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
|
---|
166 | void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
|
---|
167 |
|
---|
168 | /* Icons in the menu of an mac application are unusual. */
|
---|
169 | void darwinDisableIconsInMenus();
|
---|
170 |
|
---|
171 | /* Experimental region handler for the seamless mode */
|
---|
172 | OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
|
---|
173 |
|
---|
174 | # ifdef DEBUG
|
---|
175 | void darwinDebugPrintEvent (const char *aPrefix, EventRef aEvent);
|
---|
176 | # endif
|
---|
177 | #endif /* Q_WS_MAC */
|
---|
178 |
|
---|
179 | #endif // __VBoxUtils_h__
|
---|
180 |
|
---|