VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/VBoxUtils-darwin.h

Last change on this file was 103704, checked in by vboxsync, 2 months ago

FE/Qt: Get rid of few iprt includes around whole the GUI.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.0 KB
Line 
1/* $Id: VBoxUtils-darwin.h 103704 2024-03-06 15:15:36Z 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-2023 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: */
49class QImage;
50class QMainWindow;
51class QMenu;
52class QPixmap;
53class QToolBar;
54class QWidget;
55
56/* Cocoa declarations: */
57ADD_COCOA_NATIVE_REF(NSButton);
58ADD_COCOA_NATIVE_REF(NSEvent);
59ADD_COCOA_NATIVE_REF(NSImage);
60ADD_COCOA_NATIVE_REF(NSString);
61ADD_COCOA_NATIVE_REF(NSView);
62ADD_COCOA_NATIVE_REF(NSWindow);
63
64
65/** Mac OS X: Standard window button types. */
66enum 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
78RT_C_DECLS_BEGIN
79
80/********************************************************************************
81 *
82 * Window/View management (OS System native)
83 *
84 ********************************************************************************/
85NativeNSWindowRef darwinToNativeWindowImpl(NativeNSViewRef pView);
86NativeNSViewRef darwinToNativeViewImpl(NativeNSWindowRef pWindow);
87NativeNSButtonRef darwinNativeButtonOfWindowImpl(NativeNSWindowRef pWindow, StandardWindowButtonType enmButtonType);
88SHARED_LIBRARY_STUFF NativeNSStringRef darwinToNativeString(const char* pcszString);
89QString darwinFromNativeString(NativeNSStringRef pString);
90
91/********************************************************************************
92 *
93 * Simple setter methods (OS System native)
94 *
95 ********************************************************************************/
96void darwinSetShowsToolbarButtonImpl(NativeNSWindowRef pWindow, bool fEnabled);
97void darwinSetShowsResizeIndicatorImpl(NativeNSWindowRef pWindow, bool fEnabled);
98void darwinSetHidesAllTitleButtonsImpl(NativeNSWindowRef pWindow);
99SHARED_LIBRARY_STUFF void darwinLabelWindow(NativeNSWindowRef pWindow, NativeNSImageRef pImage, double dDpr);
100void darwinSetShowsWindowTransparentImpl(NativeNSWindowRef pWindow, bool fEnabled);
101SHARED_LIBRARY_STUFF void darwinSetWindowHasShadow(NativeNSWindowRef pWindow, bool fEnabled);
102SHARED_LIBRARY_STUFF void darwinSetMouseCoalescingEnabled(bool fEnabled);
103
104void darwintest(NativeNSWindowRef pWindow);
105/********************************************************************************
106 *
107 * Simple helper methods (OS System native)
108 *
109 ********************************************************************************/
110void darwinWindowAnimateResizeImpl(NativeNSWindowRef pWindow, int x, int y, int width, int height);
111void darwinWindowAnimateResizeNewImpl(NativeNSWindowRef pWindow, int height, bool fAnimate);
112void darwinTest(NativeNSViewRef pView, NativeNSViewRef pView1, int h);
113void darwinWindowInvalidateShapeImpl(NativeNSWindowRef pWindow);
114void darwinWindowInvalidateShadowImpl(NativeNSWindowRef pWindow);
115int darwinWindowToolBarHeight(NativeNSWindowRef pWindow);
116SHARED_LIBRARY_STUFF int darwinWindowTitleHeight(NativeNSWindowRef pWindow);
117bool darwinIsToolbarVisible(NativeNSWindowRef pWindow);
118SHARED_LIBRARY_STUFF bool darwinIsWindowMaximized(NativeNSWindowRef pWindow);
119void darwinMinaturizeWindow(NativeNSWindowRef pWindow);
120SHARED_LIBRARY_STUFF void darwinEnableFullscreenSupport(NativeNSWindowRef pWindow);
121SHARED_LIBRARY_STUFF void darwinEnableTransienceSupport(NativeNSWindowRef pWindow);
122SHARED_LIBRARY_STUFF void darwinToggleFullscreenMode(NativeNSWindowRef pWindow);
123SHARED_LIBRARY_STUFF void darwinToggleWindowZoom(NativeNSWindowRef pWindow);
124SHARED_LIBRARY_STUFF bool darwinIsInFullscreenMode(NativeNSWindowRef pWindow);
125SHARED_LIBRARY_STUFF bool darwinIsOnActiveSpace(NativeNSWindowRef pWindow);
126SHARED_LIBRARY_STUFF bool darwinScreensHaveSeparateSpaces();
127SHARED_LIBRARY_STUFF bool darwinIsScrollerStyleOverlay();
128
129bool darwinOpenFile(NativeNSStringRef pstrFile);
130
131SHARED_LIBRARY_STUFF float darwinSmallFontSize();
132SHARED_LIBRARY_STUFF bool darwinSetFrontMostProcess();
133SHARED_LIBRARY_STUFF uint64_t darwinGetCurrentProcessId();
134
135void darwinInstallResizeDelegate(NativeNSWindowRef pWindow);
136void darwinUninstallResizeDelegate(NativeNSWindowRef pWindow);
137
138bool darwinUnifiedToolbarEvents(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
139bool darwinMouseGrabEvents(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
140void darwinCreateContextMenuEvent(void *pvWin, int x, int y);
141
142SHARED_LIBRARY_STUFF bool darwinIsApplicationCommand(ConstNativeNSEventRef pEvent);
143
144void darwinRetranslateAppMenu();
145
146void darwinSendMouseGrabEvents(QWidget *pWidget, int type, int button, int buttons, int x, int y);
147
148SHARED_LIBRARY_STUFF QString darwinResolveAlias(const QString &strFile);
149
150RT_C_DECLS_END
151
152DECLINLINE(CGRect) darwinToCGRect(const QRect& aRect) { return CGRectMake(aRect.x(), aRect.y(), aRect.width(), aRect.height()); }
153DECLINLINE(CGRect) darwinFlipCGRect(CGRect aRect, double aTargetHeight) { aRect.origin.y = aTargetHeight - aRect.origin.y - aRect.size.height; return aRect; }
154DECLINLINE(CGRect) darwinFlipCGRect(CGRect aRect, const CGRect &aTarget) { return darwinFlipCGRect(aRect, aTarget.size.height); }
155DECLINLINE(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 */
174NativeNSViewRef 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 */
182NativeNSWindowRef 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 */
193NativeNSWindowRef 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 */
201NativeNSViewRef 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 */
210NativeNSButtonRef 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 */
223SHARED_LIBRARY_STUFF CGImageRef darwinToCGImageRef(const QImage *pImage);
224SHARED_LIBRARY_STUFF CGImageRef darwinToCGImageRef(const QPixmap *pPixmap);
225SHARED_LIBRARY_STUFF CGImageRef darwinToCGImageRef(const char *pczSource);
226
227SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const CGImageRef pImage);
228SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const QImage *pImage);
229SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const QPixmap *pPixmap);
230SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const char *pczSource);
231
232#include <QEvent>
233class UIGrabMouseEvent: public QEvent
234{
235public:
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
256private:
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 ********************************************************************************/
272void darwinSetShowsToolbarButton(QToolBar *aToolBar, bool fEnabled);
273SHARED_LIBRARY_STUFF void darwinLabelWindow(QWidget *pWidget, QPixmap *pPixmap);
274void darwinSetShowsResizeIndicator(QWidget *pWidget, bool fEnabled);
275SHARED_LIBRARY_STUFF void darwinSetHidesAllTitleButtons(QWidget *pWidget);
276void darwinSetShowsWindowTransparent(QWidget *pWidget, bool fEnabled);
277SHARED_LIBRARY_STUFF void darwinSetWindowHasShadow(QWidget *pWidget, bool fEnabled);
278SHARED_LIBRARY_STUFF void darwinDisableIconsInMenus(void);
279
280void darwinTest(QWidget *pWidget1, QWidget *pWidget2, int h);
281
282/********************************************************************************
283 *
284 * Simple helper methods (Qt Wrapper)
285 *
286 ********************************************************************************/
287SHARED_LIBRARY_STUFF void darwinWindowAnimateResize(QWidget *pWidget, const QRect &aTarget);
288void darwinWindowAnimateResizeNew(QWidget *pWidget, int h, bool fAnimate);
289void darwinWindowInvalidateShape(QWidget *pWidget);
290void darwinWindowInvalidateShadow(QWidget *pWidget);
291int darwinWindowToolBarHeight(QWidget *pWidget);
292SHARED_LIBRARY_STUFF int darwinWindowTitleHeight(QWidget *pWidget);
293bool darwinIsToolbarVisible(QToolBar *pToolBar);
294SHARED_LIBRARY_STUFF bool darwinIsWindowMaximized(QWidget *pWidget);
295void darwinMinaturizeWindow(QWidget *pWidget);
296SHARED_LIBRARY_STUFF void darwinEnableFullscreenSupport(QWidget *pWidget);
297SHARED_LIBRARY_STUFF void darwinEnableTransienceSupport(QWidget *pWidget);
298SHARED_LIBRARY_STUFF void darwinToggleFullscreenMode(QWidget *pWidget);
299SHARED_LIBRARY_STUFF void darwinToggleWindowZoom(QWidget *pWidget);
300SHARED_LIBRARY_STUFF bool darwinIsInFullscreenMode(QWidget *pWidget);
301SHARED_LIBRARY_STUFF bool darwinIsOnActiveSpace(QWidget *pWidget);
302bool darwinOpenFile(const QString &strFile);
303
304QString darwinSystemLanguage(void);
305QPixmap darwinCreateDragPixmap(const QPixmap& aPixmap, const QString &aText);
306
307void darwinInstallResizeDelegate(QWidget *pWidget);
308void darwinUninstallResizeDelegate(QWidget *pWidget);
309
310SHARED_LIBRARY_STUFF void darwinRegisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
311SHARED_LIBRARY_STUFF void darwinUnregisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
312
313SHARED_LIBRARY_STUFF void darwinMouseGrab(QWidget *pWidget);
314SHARED_LIBRARY_STUFF void darwinMouseRelease(QWidget *pWidget);
315
316SHARED_LIBRARY_STUFF void *darwinCocoaToCarbonEvent(void *pvCocoaEvent);
317
318#endif /* !FEQT_INCLUDED_SRC_platform_darwin_VBoxUtils_darwin_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use