VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxUtils-darwin.h@ 24107

Last change on this file since 24107 was 24107, checked in by vboxsync, 15 years ago

FE/Qt4-OSX: initial set of native Cocoa controls

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette