1 | /* $Id: VBoxUtils-darwin.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Declarations of utility classes and functions for handling Darwin specific tasks.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_platform_darwin_VBoxUtils_darwin_h
|
---|
29 | #define FEQT_INCLUDED_SRC_platform_darwin_VBoxUtils_darwin_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QRect>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UILibraryDefs.h"
|
---|
39 |
|
---|
40 | /* Other VBox includes: */
|
---|
41 | #include <VBox/VBoxCocoa.h>
|
---|
42 | #include <ApplicationServices/ApplicationServices.h>
|
---|
43 | #undef PVM // Stupid, stupid apple headers (sys/param.h)!!
|
---|
44 |
|
---|
45 | /* External includes: */
|
---|
46 | #include <ApplicationServices/ApplicationServices.h>
|
---|
47 |
|
---|
48 | /* Forward declarations: */
|
---|
49 | class QImage;
|
---|
50 | class QMainWindow;
|
---|
51 | class QMenu;
|
---|
52 | class QPixmap;
|
---|
53 | class QToolBar;
|
---|
54 | class QWidget;
|
---|
55 |
|
---|
56 | /* Cocoa declarations: */
|
---|
57 | ADD_COCOA_NATIVE_REF(NSButton);
|
---|
58 | ADD_COCOA_NATIVE_REF(NSEvent);
|
---|
59 | ADD_COCOA_NATIVE_REF(NSImage);
|
---|
60 | ADD_COCOA_NATIVE_REF(NSString);
|
---|
61 | ADD_COCOA_NATIVE_REF(NSView);
|
---|
62 | ADD_COCOA_NATIVE_REF(NSWindow);
|
---|
63 |
|
---|
64 |
|
---|
65 | /** Mac OS X: Standard window button types. */
|
---|
66 | enum StandardWindowButtonType
|
---|
67 | {
|
---|
68 | StandardWindowButtonType_Close, // Since OS X 10.2
|
---|
69 | StandardWindowButtonType_Miniaturize, // Since OS X 10.2
|
---|
70 | StandardWindowButtonType_Zoom, // Since OS X 10.2
|
---|
71 | StandardWindowButtonType_Toolbar, // Since OS X 10.2
|
---|
72 | StandardWindowButtonType_DocumentIcon, // Since OS X 10.2
|
---|
73 | StandardWindowButtonType_DocumentVersions, // Since OS X 10.7
|
---|
74 | StandardWindowButtonType_FullScreen // Since OS X 10.7
|
---|
75 | };
|
---|
76 |
|
---|
77 |
|
---|
78 | RT_C_DECLS_BEGIN
|
---|
79 |
|
---|
80 | /********************************************************************************
|
---|
81 | *
|
---|
82 | * Window/View management (OS System native)
|
---|
83 | *
|
---|
84 | ********************************************************************************/
|
---|
85 | NativeNSWindowRef darwinToNativeWindowImpl(NativeNSViewRef pView);
|
---|
86 | NativeNSViewRef darwinToNativeViewImpl(NativeNSWindowRef pWindow);
|
---|
87 | NativeNSButtonRef darwinNativeButtonOfWindowImpl(NativeNSWindowRef pWindow, StandardWindowButtonType enmButtonType);
|
---|
88 | SHARED_LIBRARY_STUFF NativeNSStringRef darwinToNativeString(const char* pcszString);
|
---|
89 | QString darwinFromNativeString(NativeNSStringRef pString);
|
---|
90 |
|
---|
91 | /********************************************************************************
|
---|
92 | *
|
---|
93 | * Simple setter methods (OS System native)
|
---|
94 | *
|
---|
95 | ********************************************************************************/
|
---|
96 | void darwinSetShowsToolbarButtonImpl(NativeNSWindowRef pWindow, bool fEnabled);
|
---|
97 | void darwinSetShowsResizeIndicatorImpl(NativeNSWindowRef pWindow, bool fEnabled);
|
---|
98 | void darwinSetHidesAllTitleButtonsImpl(NativeNSWindowRef pWindow);
|
---|
99 | SHARED_LIBRARY_STUFF void darwinLabelWindow(NativeNSWindowRef pWindow, NativeNSImageRef pImage, double dDpr);
|
---|
100 | void darwinSetShowsWindowTransparentImpl(NativeNSWindowRef pWindow, bool fEnabled);
|
---|
101 | SHARED_LIBRARY_STUFF void darwinSetWindowHasShadow(NativeNSWindowRef pWindow, bool fEnabled);
|
---|
102 | SHARED_LIBRARY_STUFF void darwinSetMouseCoalescingEnabled(bool fEnabled);
|
---|
103 |
|
---|
104 | void darwintest(NativeNSWindowRef pWindow);
|
---|
105 | /********************************************************************************
|
---|
106 | *
|
---|
107 | * Simple helper methods (OS System native)
|
---|
108 | *
|
---|
109 | ********************************************************************************/
|
---|
110 | void darwinWindowAnimateResizeImpl(NativeNSWindowRef pWindow, int x, int y, int width, int height);
|
---|
111 | void darwinWindowAnimateResizeNewImpl(NativeNSWindowRef pWindow, int height, bool fAnimate);
|
---|
112 | void darwinTest(NativeNSViewRef pView, NativeNSViewRef pView1, int h);
|
---|
113 | void darwinWindowInvalidateShapeImpl(NativeNSWindowRef pWindow);
|
---|
114 | void darwinWindowInvalidateShadowImpl(NativeNSWindowRef pWindow);
|
---|
115 | int darwinWindowToolBarHeight(NativeNSWindowRef pWindow);
|
---|
116 | SHARED_LIBRARY_STUFF int darwinWindowTitleHeight(NativeNSWindowRef pWindow);
|
---|
117 | bool darwinIsToolbarVisible(NativeNSWindowRef pWindow);
|
---|
118 | SHARED_LIBRARY_STUFF bool darwinIsWindowMaximized(NativeNSWindowRef pWindow);
|
---|
119 | void darwinMinaturizeWindow(NativeNSWindowRef pWindow);
|
---|
120 | SHARED_LIBRARY_STUFF void darwinEnableFullscreenSupport(NativeNSWindowRef pWindow);
|
---|
121 | SHARED_LIBRARY_STUFF void darwinEnableTransienceSupport(NativeNSWindowRef pWindow);
|
---|
122 | SHARED_LIBRARY_STUFF void darwinToggleFullscreenMode(NativeNSWindowRef pWindow);
|
---|
123 | SHARED_LIBRARY_STUFF void darwinToggleWindowZoom(NativeNSWindowRef pWindow);
|
---|
124 | SHARED_LIBRARY_STUFF bool darwinIsInFullscreenMode(NativeNSWindowRef pWindow);
|
---|
125 | SHARED_LIBRARY_STUFF bool darwinIsOnActiveSpace(NativeNSWindowRef pWindow);
|
---|
126 | SHARED_LIBRARY_STUFF bool darwinScreensHaveSeparateSpaces();
|
---|
127 | SHARED_LIBRARY_STUFF bool darwinIsScrollerStyleOverlay();
|
---|
128 |
|
---|
129 | bool darwinOpenFile(NativeNSStringRef pstrFile);
|
---|
130 |
|
---|
131 | SHARED_LIBRARY_STUFF float darwinSmallFontSize();
|
---|
132 | SHARED_LIBRARY_STUFF bool darwinSetFrontMostProcess();
|
---|
133 | SHARED_LIBRARY_STUFF uint64_t darwinGetCurrentProcessId();
|
---|
134 |
|
---|
135 | void darwinInstallResizeDelegate(NativeNSWindowRef pWindow);
|
---|
136 | void darwinUninstallResizeDelegate(NativeNSWindowRef pWindow);
|
---|
137 |
|
---|
138 | bool darwinUnifiedToolbarEvents(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
|
---|
139 | bool darwinMouseGrabEvents(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
|
---|
140 | void darwinCreateContextMenuEvent(void *pvWin, int x, int y);
|
---|
141 |
|
---|
142 | SHARED_LIBRARY_STUFF bool darwinIsApplicationCommand(ConstNativeNSEventRef pEvent);
|
---|
143 |
|
---|
144 | void darwinRetranslateAppMenu();
|
---|
145 |
|
---|
146 | void darwinSendMouseGrabEvents(QWidget *pWidget, int type, int button, int buttons, int x, int y);
|
---|
147 |
|
---|
148 | SHARED_LIBRARY_STUFF QString darwinResolveAlias(const QString &strFile);
|
---|
149 |
|
---|
150 | RT_C_DECLS_END
|
---|
151 |
|
---|
152 | DECLINLINE(CGRect) darwinToCGRect(const QRect& aRect) { return CGRectMake(aRect.x(), aRect.y(), aRect.width(), aRect.height()); }
|
---|
153 | DECLINLINE(CGRect) darwinFlipCGRect(CGRect aRect, double aTargetHeight) { aRect.origin.y = aTargetHeight - aRect.origin.y - aRect.size.height; return aRect; }
|
---|
154 | DECLINLINE(CGRect) darwinFlipCGRect(CGRect aRect, const CGRect &aTarget) { return darwinFlipCGRect(aRect, aTarget.size.height); }
|
---|
155 | DECLINLINE(CGRect) darwinCenterRectTo(CGRect aRect, const CGRect& aToRect)
|
---|
156 | {
|
---|
157 | aRect.origin.x = aToRect.origin.x + (aToRect.size.width - aRect.size.width) / 2.0;
|
---|
158 | aRect.origin.y = aToRect.origin.y + (aToRect.size.height - aRect.size.height) / 2.0;
|
---|
159 | return aRect;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /********************************************************************************
|
---|
163 | *
|
---|
164 | * Window/View management (Qt Wrapper)
|
---|
165 | *
|
---|
166 | ********************************************************************************/
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Returns a reference to the native View of the QWidget.
|
---|
170 | *
|
---|
171 | * @returns either HIViewRef or NSView* of the QWidget.
|
---|
172 | * @param pWidget Pointer to the QWidget
|
---|
173 | */
|
---|
174 | NativeNSViewRef darwinToNativeView(QWidget *pWidget);
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Returns a reference to the native Window of the QWidget.
|
---|
178 | *
|
---|
179 | * @returns either WindowRef or NSWindow* of the QWidget.
|
---|
180 | * @param pWidget Pointer to the QWidget
|
---|
181 | */
|
---|
182 | NativeNSWindowRef darwinToNativeWindow(QWidget *pWidget);
|
---|
183 |
|
---|
184 | /* This is necessary because of the C calling convention. Its a simple wrapper
|
---|
185 | for darwinToNativeWindowImpl to allow operator overloading which isn't
|
---|
186 | allowed in C. */
|
---|
187 | /**
|
---|
188 | * Returns a reference to the native Window of the View..
|
---|
189 | *
|
---|
190 | * @returns either WindowRef or NSWindow* of the View.
|
---|
191 | * @param pWidget Pointer to the native View
|
---|
192 | */
|
---|
193 | NativeNSWindowRef darwinToNativeWindow(NativeNSViewRef pView);
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Returns a reference to the native View of the Window.
|
---|
197 | *
|
---|
198 | * @returns either HIViewRef or NSView* of the Window.
|
---|
199 | * @param pWidget Pointer to the native Window
|
---|
200 | */
|
---|
201 | NativeNSViewRef darwinToNativeView(NativeNSWindowRef pWindow);
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Returns a reference to the native button of QWidget.
|
---|
205 | *
|
---|
206 | * @returns corresponding NSButton* of the QWidget.
|
---|
207 | * @param pWidget Brings the pointer to the QWidget.
|
---|
208 | * @param enmButtonType Brings the type of the native button required.
|
---|
209 | */
|
---|
210 | NativeNSButtonRef darwinNativeButtonOfWindow(QWidget *pWidget, StandardWindowButtonType enmButtonType);
|
---|
211 |
|
---|
212 | /********************************************************************************
|
---|
213 | *
|
---|
214 | * Graphics stuff (Qt Wrapper)
|
---|
215 | *
|
---|
216 | ********************************************************************************/
|
---|
217 | /**
|
---|
218 | * Returns a reference to the CGContext of the QWidget.
|
---|
219 | *
|
---|
220 | * @returns CGContextRef of the QWidget.
|
---|
221 | * @param pWidget Pointer to the QWidget
|
---|
222 | */
|
---|
223 | SHARED_LIBRARY_STUFF CGImageRef darwinToCGImageRef(const QImage *pImage);
|
---|
224 | SHARED_LIBRARY_STUFF CGImageRef darwinToCGImageRef(const QPixmap *pPixmap);
|
---|
225 | SHARED_LIBRARY_STUFF CGImageRef darwinToCGImageRef(const char *pczSource);
|
---|
226 |
|
---|
227 | SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const CGImageRef pImage);
|
---|
228 | SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const QImage *pImage);
|
---|
229 | SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const QPixmap *pPixmap);
|
---|
230 | SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const char *pczSource);
|
---|
231 |
|
---|
232 | #include <QEvent>
|
---|
233 | class UIGrabMouseEvent: public QEvent
|
---|
234 | {
|
---|
235 | public:
|
---|
236 | enum { GrabMouseEvent = QEvent::User + 200 };
|
---|
237 |
|
---|
238 | UIGrabMouseEvent(QEvent::Type type, Qt::MouseButton button, Qt::MouseButtons buttons, int x, int y, int wheelDelta, Qt::Orientation o)
|
---|
239 | : QEvent((QEvent::Type)GrabMouseEvent)
|
---|
240 | , m_type(type)
|
---|
241 | , m_button(button)
|
---|
242 | , m_buttons(buttons)
|
---|
243 | , m_x(x)
|
---|
244 | , m_y(y)
|
---|
245 | , m_wheelDelta(wheelDelta)
|
---|
246 | , m_orientation(o)
|
---|
247 | {}
|
---|
248 | QEvent::Type mouseEventType() const { return m_type; }
|
---|
249 | Qt::MouseButton button() const { return m_button; }
|
---|
250 | Qt::MouseButtons buttons() const { return m_buttons; }
|
---|
251 | int xDelta() const { return m_x; }
|
---|
252 | int yDelta() const { return m_y; }
|
---|
253 | int wheelDelta() const { return m_wheelDelta; }
|
---|
254 | Qt::Orientation orientation() const { return m_orientation; }
|
---|
255 |
|
---|
256 | private:
|
---|
257 | /* Private members */
|
---|
258 | QEvent::Type m_type;
|
---|
259 | Qt::MouseButton m_button;
|
---|
260 | Qt::MouseButtons m_buttons;
|
---|
261 | int m_x;
|
---|
262 | int m_y;
|
---|
263 | int m_wheelDelta;
|
---|
264 | Qt::Orientation m_orientation;
|
---|
265 | };
|
---|
266 |
|
---|
267 | /********************************************************************************
|
---|
268 | *
|
---|
269 | * Simple setter methods (Qt Wrapper)
|
---|
270 | *
|
---|
271 | ********************************************************************************/
|
---|
272 | void darwinSetShowsToolbarButton(QToolBar *aToolBar, bool fEnabled);
|
---|
273 | SHARED_LIBRARY_STUFF void darwinLabelWindow(QWidget *pWidget, QPixmap *pPixmap);
|
---|
274 | void darwinSetShowsResizeIndicator(QWidget *pWidget, bool fEnabled);
|
---|
275 | SHARED_LIBRARY_STUFF void darwinSetHidesAllTitleButtons(QWidget *pWidget);
|
---|
276 | void darwinSetShowsWindowTransparent(QWidget *pWidget, bool fEnabled);
|
---|
277 | SHARED_LIBRARY_STUFF void darwinSetWindowHasShadow(QWidget *pWidget, bool fEnabled);
|
---|
278 | SHARED_LIBRARY_STUFF void darwinDisableIconsInMenus(void);
|
---|
279 |
|
---|
280 | void darwinTest(QWidget *pWidget1, QWidget *pWidget2, int h);
|
---|
281 |
|
---|
282 | /********************************************************************************
|
---|
283 | *
|
---|
284 | * Simple helper methods (Qt Wrapper)
|
---|
285 | *
|
---|
286 | ********************************************************************************/
|
---|
287 | SHARED_LIBRARY_STUFF void darwinWindowAnimateResize(QWidget *pWidget, const QRect &aTarget);
|
---|
288 | void darwinWindowAnimateResizeNew(QWidget *pWidget, int h, bool fAnimate);
|
---|
289 | void darwinWindowInvalidateShape(QWidget *pWidget);
|
---|
290 | void darwinWindowInvalidateShadow(QWidget *pWidget);
|
---|
291 | int darwinWindowToolBarHeight(QWidget *pWidget);
|
---|
292 | SHARED_LIBRARY_STUFF int darwinWindowTitleHeight(QWidget *pWidget);
|
---|
293 | bool darwinIsToolbarVisible(QToolBar *pToolBar);
|
---|
294 | SHARED_LIBRARY_STUFF bool darwinIsWindowMaximized(QWidget *pWidget);
|
---|
295 | void darwinMinaturizeWindow(QWidget *pWidget);
|
---|
296 | SHARED_LIBRARY_STUFF void darwinEnableFullscreenSupport(QWidget *pWidget);
|
---|
297 | SHARED_LIBRARY_STUFF void darwinEnableTransienceSupport(QWidget *pWidget);
|
---|
298 | SHARED_LIBRARY_STUFF void darwinToggleFullscreenMode(QWidget *pWidget);
|
---|
299 | SHARED_LIBRARY_STUFF void darwinToggleWindowZoom(QWidget *pWidget);
|
---|
300 | SHARED_LIBRARY_STUFF bool darwinIsInFullscreenMode(QWidget *pWidget);
|
---|
301 | SHARED_LIBRARY_STUFF bool darwinIsOnActiveSpace(QWidget *pWidget);
|
---|
302 | bool darwinOpenFile(const QString &strFile);
|
---|
303 |
|
---|
304 | QString darwinSystemLanguage(void);
|
---|
305 | QPixmap darwinCreateDragPixmap(const QPixmap& aPixmap, const QString &aText);
|
---|
306 |
|
---|
307 | void darwinInstallResizeDelegate(QWidget *pWidget);
|
---|
308 | void darwinUninstallResizeDelegate(QWidget *pWidget);
|
---|
309 |
|
---|
310 | SHARED_LIBRARY_STUFF void darwinRegisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
|
---|
311 | SHARED_LIBRARY_STUFF void darwinUnregisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
|
---|
312 |
|
---|
313 | SHARED_LIBRARY_STUFF void darwinMouseGrab(QWidget *pWidget);
|
---|
314 | SHARED_LIBRARY_STUFF void darwinMouseRelease(QWidget *pWidget);
|
---|
315 |
|
---|
316 | SHARED_LIBRARY_STUFF void *darwinCocoaToCarbonEvent(void *pvCocoaEvent);
|
---|
317 |
|
---|
318 | #endif /* !FEQT_INCLUDED_SRC_platform_darwin_VBoxUtils_darwin_h */
|
---|