1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * Declarations of utility classes and functions for handling Darwin specific
|
---|
5 | * tasks
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #ifndef ___VBoxUtils_darwin_h
|
---|
25 | #define ___VBoxUtils_darwin_h
|
---|
26 |
|
---|
27 | /*
|
---|
28 | * Here is some really magic in. The "OS System native" methods are implemented
|
---|
29 | * in the current OS specific way. This means either Carbon
|
---|
30 | * (VBoxUtils-darwin-carbon.cpp) or Cocoa (VBoxUtils-darwin-cocoa.m). The Qt
|
---|
31 | * wrapper methods handle the conversion from Q* data types to the native one
|
---|
32 | * (VBoxUtils-darwin.cpp).
|
---|
33 | */
|
---|
34 |
|
---|
35 | #ifdef __OBJC__
|
---|
36 | #import <AppKit/NSWindow.h>
|
---|
37 |
|
---|
38 | typedef NSWindow *NativeWindowRef;
|
---|
39 | typedef NSView *NativeViewRef;
|
---|
40 | #else
|
---|
41 |
|
---|
42 | # include <qglobal.h> /* for QT_MAC_USE_COCOA */
|
---|
43 | # include <QRect>
|
---|
44 |
|
---|
45 | # include <ApplicationServices/ApplicationServices.h>
|
---|
46 |
|
---|
47 | class QWidget;
|
---|
48 | class QToolBar;
|
---|
49 | class QPixmap;
|
---|
50 | class QImage;
|
---|
51 |
|
---|
52 | # ifdef QT_MAC_USE_COCOA
|
---|
53 | /* Cast this to void, cause Cocoa classes aren't usable in the C++ context. */
|
---|
54 | typedef void *NativeWindowRef;
|
---|
55 | typedef void *NativeViewRef;
|
---|
56 | # else /* QT_MAC_USE_COCOA */
|
---|
57 | # include <Carbon/Carbon.h>
|
---|
58 | typedef WindowRef NativeWindowRef;
|
---|
59 | typedef HIViewRef NativeViewRef;
|
---|
60 | # endif /* QT_MAC_USE_COCOA */
|
---|
61 | #endif /* __OBJC__ */
|
---|
62 |
|
---|
63 | #include <iprt/cdefs.h> /* for RT_C_DECLS_BEGIN/RT_C_DECLS_END & stuff */
|
---|
64 |
|
---|
65 | RT_C_DECLS_BEGIN
|
---|
66 |
|
---|
67 | /********************************************************************************
|
---|
68 | *
|
---|
69 | * Window/View management (OS System native)
|
---|
70 | *
|
---|
71 | ********************************************************************************/
|
---|
72 | NativeWindowRef darwinToNativeWindowImpl (NativeViewRef aView);
|
---|
73 | NativeViewRef darwinToNativeViewImpl (NativeWindowRef aWindow);
|
---|
74 |
|
---|
75 | /********************************************************************************
|
---|
76 | *
|
---|
77 | * Simple setter methods (OS System native)
|
---|
78 | *
|
---|
79 | ********************************************************************************/
|
---|
80 | void darwinSetShowsToolbarButtonImpl (NativeWindowRef aWindow, bool aEnabled);
|
---|
81 | void darwinSetShowsResizeIndicatorImpl (NativeWindowRef aWindow, bool aEnabled);
|
---|
82 | void darwinSetHidesAllTitleButtonsImpl (NativeWindowRef aWindow);
|
---|
83 | void darwinSetShowsWindowTransparentImpl (NativeWindowRef aWindow, bool aEnabled);
|
---|
84 | void darwinSetMouseCoalescingEnabled (bool aEnabled);
|
---|
85 |
|
---|
86 | /********************************************************************************
|
---|
87 | *
|
---|
88 | * Simple helper methods (OS System native)
|
---|
89 | *
|
---|
90 | ********************************************************************************/
|
---|
91 | void darwinWindowAnimateResizeImpl (NativeWindowRef aWindow, int x, int y, int width, int height);
|
---|
92 | void darwinWindowInvalidateShapeImpl (NativeWindowRef aWindow);
|
---|
93 | void darwinWindowInvalidateShadowImpl (NativeWindowRef aWindow);
|
---|
94 | int darwinWindowToolBarHeight (NativeWindowRef aWindow);
|
---|
95 |
|
---|
96 | RT_C_DECLS_END
|
---|
97 |
|
---|
98 | #ifndef __OBJC__
|
---|
99 | /********************************************************************************
|
---|
100 | *
|
---|
101 | * Window/View management (Qt Wrapper)
|
---|
102 | *
|
---|
103 | ********************************************************************************/
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Returns a reference to the native View of the QWidget.
|
---|
107 | *
|
---|
108 | * @returns either HIViewRef or NSView* of the QWidget.
|
---|
109 | * @param aWidget Pointer to the QWidget
|
---|
110 | */
|
---|
111 | NativeViewRef darwinToNativeView (QWidget *aWidget);
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Returns a reference to the native Window of the QWidget.
|
---|
115 | *
|
---|
116 | * @returns either WindowRef or NSWindow* of the QWidget.
|
---|
117 | * @param aWidget Pointer to the QWidget
|
---|
118 | */
|
---|
119 | NativeWindowRef darwinToNativeWindow (QWidget *aWidget);
|
---|
120 |
|
---|
121 | /* This is necessary because of the C calling convention. Its a simple wrapper
|
---|
122 | for darwinToNativeWindowImpl to allow operator overloading which isn't
|
---|
123 | allowed in C. */
|
---|
124 | /**
|
---|
125 | * Returns a reference to the native Window of the View..
|
---|
126 | *
|
---|
127 | * @returns either WindowRef or NSWindow* of the View.
|
---|
128 | * @param aWidget Pointer to the native View
|
---|
129 | */
|
---|
130 | NativeWindowRef darwinToNativeWindow (NativeViewRef aView);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Returns a reference to the native View of the Window.
|
---|
134 | *
|
---|
135 | * @returns either HIViewRef or NSView* of the Window.
|
---|
136 | * @param aWidget Pointer to the native Window
|
---|
137 | */
|
---|
138 | NativeViewRef darwinToNativeView (NativeWindowRef aWindow);
|
---|
139 |
|
---|
140 | /********************************************************************************
|
---|
141 | *
|
---|
142 | * Simple setter methods (Qt Wrapper)
|
---|
143 | *
|
---|
144 | ********************************************************************************/
|
---|
145 | void darwinSetShowsToolbarButton (QToolBar *aToolBar, bool aEnabled);
|
---|
146 | void darwinSetShowsResizeIndicator (QWidget *aWidget, bool aEnabled);
|
---|
147 | void darwinSetHidesAllTitleButtons (QWidget *aWidget);
|
---|
148 | void darwinSetShowsWindowTransparent (QWidget *aWidget, bool aEnabled);
|
---|
149 | void darwinDisableIconsInMenus (void);
|
---|
150 |
|
---|
151 | /********************************************************************************
|
---|
152 | *
|
---|
153 | * Simple helper methods (Qt Wrapper)
|
---|
154 | *
|
---|
155 | ********************************************************************************/
|
---|
156 | void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget);
|
---|
157 | void darwinWindowInvalidateShape (QWidget *aWidget);
|
---|
158 | void darwinWindowInvalidateShadow (QWidget *aWidget);
|
---|
159 | int darwinWindowToolBarHeight (QWidget *aWidget);
|
---|
160 | QString darwinSystemLanguage (void);
|
---|
161 | QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText);
|
---|
162 |
|
---|
163 |
|
---|
164 | /********************************************************************************
|
---|
165 | *
|
---|
166 | * Graphics stuff (Qt Wrapper)
|
---|
167 | *
|
---|
168 | ********************************************************************************/
|
---|
169 | /**
|
---|
170 | * Returns a reference to the CGContext of the QWidget.
|
---|
171 | *
|
---|
172 | * @returns CGContextRef of the QWidget.
|
---|
173 | * @param aWidget Pointer to the QWidget
|
---|
174 | */
|
---|
175 | CGContextRef darwinToCGContextRef (QWidget *aWidget);
|
---|
176 |
|
---|
177 | CGImageRef darwinToCGImageRef (const QImage *aImage);
|
---|
178 | CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
|
---|
179 | CGImageRef darwinToCGImageRef (const char *aSource);
|
---|
180 |
|
---|
181 | DECLINLINE(CGRect) darwinToCGRect (const QRect& aRect) { return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height()); }
|
---|
182 | DECLINLINE(CGRect) darwinFlipCGRect (CGRect aRect, int aTargetHeight) { aRect.origin.y = aTargetHeight - aRect.origin.y - aRect.size.height; return aRect; }
|
---|
183 | DECLINLINE(CGRect) darwinFlipCGRect (CGRect aRect, const CGRect &aTarget) { return darwinFlipCGRect (aRect, aTarget.size.height); }
|
---|
184 | DECLINLINE(CGRect) darwinCenterRectTo (CGRect aRect, const CGRect& aToRect)
|
---|
185 | {
|
---|
186 | aRect.origin.x = aToRect.origin.x + (aToRect.size.width - aRect.size.width) / 2.0;
|
---|
187 | aRect.origin.y = aToRect.origin.y + (aToRect.size.height - aRect.size.height) / 2.0;
|
---|
188 | return aRect;
|
---|
189 | }
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 | /********************************************************************************
|
---|
196 | *
|
---|
197 | * Old carbon stuff. Have to be converted soon!
|
---|
198 | *
|
---|
199 | ********************************************************************************/
|
---|
200 |
|
---|
201 | #include <QWidget>
|
---|
202 |
|
---|
203 | # ifndef QT_MAC_USE_COCOA
|
---|
204 |
|
---|
205 | /* Asserts if a != noErr and prints the error code */
|
---|
206 | # ifdef RT_STRICT
|
---|
207 | # define AssertCarbonOSStatus(a) AssertMsg ((a) == noErr, ("Carbon OSStatus: %d\n", static_cast<int> (a)))
|
---|
208 | # else
|
---|
209 | # define AssertCarbonOSStatus(a) do { NOREF(a); } while (0)
|
---|
210 | # endif
|
---|
211 |
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Converts a QRect to a HIRect.
|
---|
215 | *
|
---|
216 | * @returns HIRect for the converted QRect.
|
---|
217 | * @param aRect the QRect to convert
|
---|
218 | */
|
---|
219 | DECLINLINE(HIRect) darwinToHIRect (const QRect &aRect)
|
---|
220 | {
|
---|
221 | return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height());
|
---|
222 | }
|
---|
223 |
|
---|
224 | /* Experimental region handler for the seamless mode */
|
---|
225 | OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
|
---|
226 |
|
---|
227 | /* Handler for the OpenGL overlay window stuff & the possible messages. */
|
---|
228 | enum
|
---|
229 | {
|
---|
230 | /* Event classes */
|
---|
231 | kEventClassVBox = 'vbox',
|
---|
232 | /* Event kinds */
|
---|
233 | kEventVBoxShowWindow = 'swin',
|
---|
234 | kEventVBoxHideWindow = 'hwin',
|
---|
235 | kEventVBoxMoveWindow = 'mwin',
|
---|
236 | kEventVBoxResizeWindow = 'rwin',
|
---|
237 | kEventVBoxDisposeWindow = 'dwin',
|
---|
238 | kEventVBoxUpdateDock = 'udck',
|
---|
239 | kEventVBoxUpdateContext = 'uctx',
|
---|
240 | kEventVBoxBoundsChanged = 'bchg'
|
---|
241 | };
|
---|
242 |
|
---|
243 | void PostBoundsChanged (const QRect& rect);
|
---|
244 | OSStatus darwinOverlayWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
|
---|
245 |
|
---|
246 | bool darwinIsMenuOpen (void);
|
---|
247 |
|
---|
248 | # endif /* !QT_MAC_USE_COCOA */
|
---|
249 |
|
---|
250 | # ifdef DEBUG
|
---|
251 | void darwinDebugPrintEvent (const char *aPrefix, EventRef aEvent);
|
---|
252 | # endif
|
---|
253 |
|
---|
254 | #endif /* !__OBJC__ */
|
---|
255 |
|
---|
256 | #endif /* !___VBoxUtils_darwin_h */
|
---|
257 |
|
---|