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 | # include <iprt/cdefs.h> /* for __BEGIN_DECLS/__END_DECLS & stuff */
|
---|
42 |
|
---|
43 | # include <qglobal.h> /* for QT_MAC_USE_COCOA */
|
---|
44 | # include <QRect>
|
---|
45 |
|
---|
46 | # include <ApplicationServices/ApplicationServices.h>
|
---|
47 |
|
---|
48 | class QWidget;
|
---|
49 | class QToolBar;
|
---|
50 | class QPixmap;
|
---|
51 | class QImage;
|
---|
52 |
|
---|
53 | # ifdef QT_MAC_USE_COCOA
|
---|
54 | /* Cast this to void, cause Cocoa classes aren't usable in the C++ context. */
|
---|
55 | typedef void *NativeWindowRef;
|
---|
56 | typedef void *NativeViewRef;
|
---|
57 | # else /* QT_MAC_USE_COCOA */
|
---|
58 | # include <Carbon/Carbon.h>
|
---|
59 | typedef WindowRef NativeWindowRef;
|
---|
60 | typedef HIViewRef NativeViewRef;
|
---|
61 | # endif /* QT_MAC_USE_COCOA */
|
---|
62 | #endif /* __OBJC__ */
|
---|
63 |
|
---|
64 | __BEGIN_DECLS
|
---|
65 |
|
---|
66 | /********************************************************************************
|
---|
67 | *
|
---|
68 | * Window/View management (OS System native)
|
---|
69 | *
|
---|
70 | ********************************************************************************/
|
---|
71 | NativeWindowRef darwinToNativeWindowImpl (NativeViewRef aView);
|
---|
72 | NativeViewRef darwinToNativeViewImpl (NativeWindowRef aWindow);
|
---|
73 |
|
---|
74 | /********************************************************************************
|
---|
75 | *
|
---|
76 | * Simple setter methods (OS System native)
|
---|
77 | *
|
---|
78 | ********************************************************************************/
|
---|
79 | void darwinSetShowsToolbarButtonImpl (NativeWindowRef aWindow, bool aEnabled);
|
---|
80 | void darwinSetShowsResizeIndicatorImpl (NativeWindowRef aWindow, bool aEnabled);
|
---|
81 | void darwinSetHidesAllTitleButtonsImpl (NativeWindowRef aWindow);
|
---|
82 | void darwinSetShowsWindowTransparentImpl (NativeWindowRef aWindow, bool aEnabled);
|
---|
83 | void darwinSetMouseCoalescingEnabled (bool aEnabled);
|
---|
84 |
|
---|
85 | /********************************************************************************
|
---|
86 | *
|
---|
87 | * Simple helper methods (OS System native)
|
---|
88 | *
|
---|
89 | ********************************************************************************/
|
---|
90 | void darwinWindowAnimateResizeImpl (NativeWindowRef aWindow, int x, int y, int width, int height);
|
---|
91 | void darwinWindowInvalidateShapeImpl (NativeWindowRef aWindow);
|
---|
92 | void darwinWindowInvalidateShadowImpl (NativeWindowRef aWindow);
|
---|
93 |
|
---|
94 | __END_DECLS
|
---|
95 |
|
---|
96 | #ifndef __OBJC__
|
---|
97 | /********************************************************************************
|
---|
98 | *
|
---|
99 | * Window/View management (Qt Wrapper)
|
---|
100 | *
|
---|
101 | ********************************************************************************/
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Returns a reference to the native View of the QWidget.
|
---|
105 | *
|
---|
106 | * @returns either HIViewRef or NSView* of the QWidget.
|
---|
107 | * @param aWidget Pointer to the QWidget
|
---|
108 | */
|
---|
109 | NativeViewRef darwinToNativeView (QWidget *aWidget);
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Returns a reference to the native Window of the QWidget.
|
---|
113 | *
|
---|
114 | * @returns either WindowRef or NSWindow* of the QWidget.
|
---|
115 | * @param aWidget Pointer to the QWidget
|
---|
116 | */
|
---|
117 | NativeWindowRef darwinToNativeWindow (QWidget *aWidget);
|
---|
118 |
|
---|
119 | /* This is necessary because of the C calling convention. Its a simple wrapper
|
---|
120 | for darwinToNativeWindowImpl to allow operator overloading which isn't
|
---|
121 | allowed in C. */
|
---|
122 | /**
|
---|
123 | * Returns a reference to the native Window of the View..
|
---|
124 | *
|
---|
125 | * @returns either WindowRef or NSWindow* of the View.
|
---|
126 | * @param aWidget Pointer to the native View
|
---|
127 | */
|
---|
128 | NativeWindowRef darwinToNativeWindow (NativeViewRef aView);
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Returns a reference to the native View of the Window.
|
---|
132 | *
|
---|
133 | * @returns either HIViewRef or NSView* of the Window.
|
---|
134 | * @param aWidget Pointer to the native Window
|
---|
135 | */
|
---|
136 | NativeViewRef darwinToNativeView (NativeWindowRef aWindow);
|
---|
137 |
|
---|
138 | /********************************************************************************
|
---|
139 | *
|
---|
140 | * Simple setter methods (Qt Wrapper)
|
---|
141 | *
|
---|
142 | ********************************************************************************/
|
---|
143 | void darwinSetShowsToolbarButton (QToolBar *aToolBar, bool aEnabled);
|
---|
144 | void darwinSetShowsResizeIndicator (QWidget *aWidget, bool aEnabled);
|
---|
145 | void darwinSetHidesAllTitleButtons (QWidget *aWidget);
|
---|
146 | void darwinSetShowsWindowTransparent (QWidget *aWidget, bool aEnabled);
|
---|
147 | void darwinDisableIconsInMenus (void);
|
---|
148 |
|
---|
149 | /********************************************************************************
|
---|
150 | *
|
---|
151 | * Simple helper methods (Qt Wrapper)
|
---|
152 | *
|
---|
153 | ********************************************************************************/
|
---|
154 | void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget);
|
---|
155 | void darwinWindowInvalidateShape (QWidget *aWidget);
|
---|
156 | void darwinWindowInvalidateShadow (QWidget *aWidget);
|
---|
157 | QString darwinSystemLanguage (void);
|
---|
158 | QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText);
|
---|
159 |
|
---|
160 |
|
---|
161 | /********************************************************************************
|
---|
162 | *
|
---|
163 | * Graphics stuff (Qt Wrapper)
|
---|
164 | *
|
---|
165 | ********************************************************************************/
|
---|
166 | /**
|
---|
167 | * Returns a reference to the CGContext of the QWidget.
|
---|
168 | *
|
---|
169 | * @returns CGContextRef of the QWidget.
|
---|
170 | * @param aWidget Pointer to the QWidget
|
---|
171 | */
|
---|
172 | CGContextRef darwinToCGContextRef (QWidget *aWidget);
|
---|
173 |
|
---|
174 | CGImageRef darwinToCGImageRef (const QImage *aImage);
|
---|
175 | CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
|
---|
176 | CGImageRef darwinToCGImageRef (const char *aSource);
|
---|
177 |
|
---|
178 | DECLINLINE(CGRect) darwinToCGRect (const QRect& aRect) { return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height()); }
|
---|
179 | DECLINLINE(CGRect) darwinFlipCGRect (CGRect aRect, int aTargetHeight) { aRect.origin.y = aTargetHeight - aRect.origin.y - aRect.size.height; return aRect; }
|
---|
180 | DECLINLINE(CGRect) darwinFlipCGRect (CGRect aRect, const CGRect &aTarget) { return darwinFlipCGRect (aRect, aTarget.size.height); }
|
---|
181 | DECLINLINE(CGRect) darwinCenterRectTo (CGRect aRect, const CGRect& aToRect)
|
---|
182 | {
|
---|
183 | aRect.origin.x = aToRect.origin.x + (aToRect.size.width - aRect.size.width) / 2.0;
|
---|
184 | aRect.origin.y = aToRect.origin.y + (aToRect.size.height - aRect.size.height) / 2.0;
|
---|
185 | return aRect;
|
---|
186 | }
|
---|
187 |
|
---|
188 |
|
---|
189 |
|
---|
190 |
|
---|
191 |
|
---|
192 | /********************************************************************************
|
---|
193 | *
|
---|
194 | * Old carbon stuff. Have to be converted soon!
|
---|
195 | *
|
---|
196 | ********************************************************************************/
|
---|
197 |
|
---|
198 | #include <QWidget>
|
---|
199 |
|
---|
200 | # ifndef QT_MAC_USE_COCOA
|
---|
201 |
|
---|
202 | /* Asserts if a != noErr and prints the error code */
|
---|
203 | # define AssertCarbonOSStatus(a) AssertMsg ((a) == noErr, ("Carbon OSStatus: %d\n", static_cast<int> (a)))
|
---|
204 |
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Converts a QRect to a HIRect.
|
---|
208 | *
|
---|
209 | * @returns HIRect for the converted QRect.
|
---|
210 | * @param aRect the QRect to convert
|
---|
211 | */
|
---|
212 | DECLINLINE(HIRect) darwinToHIRect (const QRect &aRect)
|
---|
213 | {
|
---|
214 | return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height());
|
---|
215 | }
|
---|
216 |
|
---|
217 | /* Experimental region handler for the seamless mode */
|
---|
218 | OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
|
---|
219 |
|
---|
220 | /* Handler for the OpenGL overlay window stuff & the possible messages. */
|
---|
221 | enum
|
---|
222 | {
|
---|
223 | /* Event classes */
|
---|
224 | kEventClassVBox = 'vbox',
|
---|
225 | /* Event kinds */
|
---|
226 | kEventVBoxShowWindow = 'swin',
|
---|
227 | kEventVBoxHideWindow = 'hwin',
|
---|
228 | kEventVBoxMoveWindow = 'mwin',
|
---|
229 | kEventVBoxResizeWindow = 'rwin',
|
---|
230 | kEventVBoxDisposeWindow = 'dwin',
|
---|
231 | kEventVBoxUpdateDock = 'udck',
|
---|
232 | kEventVBoxUpdateContext = 'uctx',
|
---|
233 | kEventVBoxBoundsChanged = 'bchg'
|
---|
234 | };
|
---|
235 |
|
---|
236 | void PostBoundsChanged (const QRect& rect);
|
---|
237 | OSStatus darwinOverlayWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
|
---|
238 |
|
---|
239 | bool darwinIsMenuOpen (void);
|
---|
240 |
|
---|
241 | # endif /* !QT_MAC_USE_COCOA */
|
---|
242 |
|
---|
243 | # ifdef DEBUG
|
---|
244 | void darwinDebugPrintEvent (const char *aPrefix, EventRef aEvent);
|
---|
245 | # endif
|
---|
246 |
|
---|
247 | #endif /* !__OBJC__ */
|
---|
248 |
|
---|
249 | #endif /* __VBoxUtils_darwin_h */
|
---|
250 |
|
---|