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