VirtualBox

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

Last change on this file since 98103 was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • 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 98103 2023-01-17 14:15:46Z 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#include <iprt/cdefs.h>
45
46/* External includes: */
47#include <ApplicationServices/ApplicationServices.h>
48
49/* Forward declarations: */
50class QImage;
51class QMainWindow;
52class QMenu;
53class QPixmap;
54class QToolBar;
55class QWidget;
56
57/* Cocoa declarations: */
58ADD_COCOA_NATIVE_REF(NSButton);
59ADD_COCOA_NATIVE_REF(NSEvent);
60ADD_COCOA_NATIVE_REF(NSImage);
61ADD_COCOA_NATIVE_REF(NSString);
62ADD_COCOA_NATIVE_REF(NSView);
63ADD_COCOA_NATIVE_REF(NSWindow);
64
65
66/** Mac OS X: Standard window button types. */
67enum StandardWindowButtonType
68{
69 StandardWindowButtonType_Close, // Since OS X 10.2
70 StandardWindowButtonType_Miniaturize, // Since OS X 10.2
71 StandardWindowButtonType_Zoom, // Since OS X 10.2
72 StandardWindowButtonType_Toolbar, // Since OS X 10.2
73 StandardWindowButtonType_DocumentIcon, // Since OS X 10.2
74 StandardWindowButtonType_DocumentVersions, // Since OS X 10.7
75 StandardWindowButtonType_FullScreen // Since OS X 10.7
76};
77
78
79RT_C_DECLS_BEGIN
80
81/********************************************************************************
82 *
83 * Window/View management (OS System native)
84 *
85 ********************************************************************************/
86NativeNSWindowRef darwinToNativeWindowImpl(NativeNSViewRef pView);
87NativeNSViewRef darwinToNativeViewImpl(NativeNSWindowRef pWindow);
88NativeNSButtonRef darwinNativeButtonOfWindowImpl(NativeNSWindowRef pWindow, StandardWindowButtonType enmButtonType);
89SHARED_LIBRARY_STUFF NativeNSStringRef darwinToNativeString(const char* pcszString);
90QString darwinFromNativeString(NativeNSStringRef pString);
91
92/********************************************************************************
93 *
94 * Simple setter methods (OS System native)
95 *
96 ********************************************************************************/
97void darwinSetShowsToolbarButtonImpl(NativeNSWindowRef pWindow, bool fEnabled);
98void darwinSetShowsResizeIndicatorImpl(NativeNSWindowRef pWindow, bool fEnabled);
99void darwinSetHidesAllTitleButtonsImpl(NativeNSWindowRef pWindow);
100SHARED_LIBRARY_STUFF void darwinLabelWindow(NativeNSWindowRef pWindow, NativeNSImageRef pImage, double dDpr);
101void darwinSetShowsWindowTransparentImpl(NativeNSWindowRef pWindow, bool fEnabled);
102SHARED_LIBRARY_STUFF void darwinSetWindowHasShadow(NativeNSWindowRef pWindow, bool fEnabled);
103SHARED_LIBRARY_STUFF void darwinSetMouseCoalescingEnabled(bool fEnabled);
104
105void darwintest(NativeNSWindowRef pWindow);
106/********************************************************************************
107 *
108 * Simple helper methods (OS System native)
109 *
110 ********************************************************************************/
111void darwinWindowAnimateResizeImpl(NativeNSWindowRef pWindow, int x, int y, int width, int height);
112void darwinWindowAnimateResizeNewImpl(NativeNSWindowRef pWindow, int height, bool fAnimate);
113void darwinTest(NativeNSViewRef pView, NativeNSViewRef pView1, int h);
114void darwinWindowInvalidateShapeImpl(NativeNSWindowRef pWindow);
115void darwinWindowInvalidateShadowImpl(NativeNSWindowRef pWindow);
116int darwinWindowToolBarHeight(NativeNSWindowRef pWindow);
117SHARED_LIBRARY_STUFF int darwinWindowTitleHeight(NativeNSWindowRef pWindow);
118bool darwinIsToolbarVisible(NativeNSWindowRef pWindow);
119SHARED_LIBRARY_STUFF bool darwinIsWindowMaximized(NativeNSWindowRef pWindow);
120void darwinMinaturizeWindow(NativeNSWindowRef pWindow);
121SHARED_LIBRARY_STUFF void darwinEnableFullscreenSupport(NativeNSWindowRef pWindow);
122SHARED_LIBRARY_STUFF void darwinEnableTransienceSupport(NativeNSWindowRef pWindow);
123SHARED_LIBRARY_STUFF void darwinToggleFullscreenMode(NativeNSWindowRef pWindow);
124SHARED_LIBRARY_STUFF void darwinToggleWindowZoom(NativeNSWindowRef pWindow);
125SHARED_LIBRARY_STUFF bool darwinIsInFullscreenMode(NativeNSWindowRef pWindow);
126SHARED_LIBRARY_STUFF bool darwinIsOnActiveSpace(NativeNSWindowRef pWindow);
127SHARED_LIBRARY_STUFF bool darwinScreensHaveSeparateSpaces();
128SHARED_LIBRARY_STUFF bool darwinIsScrollerStyleOverlay();
129
130bool darwinOpenFile(NativeNSStringRef pstrFile);
131
132SHARED_LIBRARY_STUFF float darwinSmallFontSize();
133SHARED_LIBRARY_STUFF bool darwinSetFrontMostProcess();
134SHARED_LIBRARY_STUFF uint64_t darwinGetCurrentProcessId();
135
136void darwinInstallResizeDelegate(NativeNSWindowRef pWindow);
137void darwinUninstallResizeDelegate(NativeNSWindowRef pWindow);
138
139bool darwinUnifiedToolbarEvents(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
140bool darwinMouseGrabEvents(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
141void darwinCreateContextMenuEvent(void *pvWin, int x, int y);
142
143SHARED_LIBRARY_STUFF bool darwinIsApplicationCommand(ConstNativeNSEventRef pEvent);
144
145void darwinRetranslateAppMenu();
146
147void darwinSendMouseGrabEvents(QWidget *pWidget, int type, int button, int buttons, int x, int y);
148
149SHARED_LIBRARY_STUFF QString darwinResolveAlias(const QString &strFile);
150
151RT_C_DECLS_END
152
153DECLINLINE(CGRect) darwinToCGRect(const QRect& aRect) { return CGRectMake(aRect.x(), aRect.y(), aRect.width(), aRect.height()); }
154DECLINLINE(CGRect) darwinFlipCGRect(CGRect aRect, double aTargetHeight) { aRect.origin.y = aTargetHeight - aRect.origin.y - aRect.size.height; return aRect; }
155DECLINLINE(CGRect) darwinFlipCGRect(CGRect aRect, const CGRect &aTarget) { return darwinFlipCGRect(aRect, aTarget.size.height); }
156DECLINLINE(CGRect) darwinCenterRectTo(CGRect aRect, const CGRect& aToRect)
157{
158 aRect.origin.x = aToRect.origin.x + (aToRect.size.width - aRect.size.width) / 2.0;
159 aRect.origin.y = aToRect.origin.y + (aToRect.size.height - aRect.size.height) / 2.0;
160 return aRect;
161}
162
163/********************************************************************************
164 *
165 * Window/View management (Qt Wrapper)
166 *
167 ********************************************************************************/
168
169/**
170 * Returns a reference to the native View of the QWidget.
171 *
172 * @returns either HIViewRef or NSView* of the QWidget.
173 * @param pWidget Pointer to the QWidget
174 */
175NativeNSViewRef darwinToNativeView(QWidget *pWidget);
176
177/**
178 * Returns a reference to the native Window of the QWidget.
179 *
180 * @returns either WindowRef or NSWindow* of the QWidget.
181 * @param pWidget Pointer to the QWidget
182 */
183NativeNSWindowRef darwinToNativeWindow(QWidget *pWidget);
184
185/* This is necessary because of the C calling convention. Its a simple wrapper
186 for darwinToNativeWindowImpl to allow operator overloading which isn't
187 allowed in C. */
188/**
189 * Returns a reference to the native Window of the View..
190 *
191 * @returns either WindowRef or NSWindow* of the View.
192 * @param pWidget Pointer to the native View
193 */
194NativeNSWindowRef darwinToNativeWindow(NativeNSViewRef pView);
195
196/**
197 * Returns a reference to the native View of the Window.
198 *
199 * @returns either HIViewRef or NSView* of the Window.
200 * @param pWidget Pointer to the native Window
201 */
202NativeNSViewRef darwinToNativeView(NativeNSWindowRef pWindow);
203
204/**
205 * Returns a reference to the native button of QWidget.
206 *
207 * @returns corresponding NSButton* of the QWidget.
208 * @param pWidget Brings the pointer to the QWidget.
209 * @param enmButtonType Brings the type of the native button required.
210 */
211NativeNSButtonRef darwinNativeButtonOfWindow(QWidget *pWidget, StandardWindowButtonType enmButtonType);
212
213/********************************************************************************
214 *
215 * Graphics stuff (Qt Wrapper)
216 *
217 ********************************************************************************/
218/**
219 * Returns a reference to the CGContext of the QWidget.
220 *
221 * @returns CGContextRef of the QWidget.
222 * @param pWidget Pointer to the QWidget
223 */
224SHARED_LIBRARY_STUFF CGImageRef darwinToCGImageRef(const QImage *pImage);
225SHARED_LIBRARY_STUFF CGImageRef darwinToCGImageRef(const QPixmap *pPixmap);
226SHARED_LIBRARY_STUFF CGImageRef darwinToCGImageRef(const char *pczSource);
227
228SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const CGImageRef pImage);
229SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const QImage *pImage);
230SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const QPixmap *pPixmap);
231SHARED_LIBRARY_STUFF NativeNSImageRef darwinToNSImageRef(const char *pczSource);
232
233#include <QEvent>
234class UIGrabMouseEvent: public QEvent
235{
236public:
237 enum { GrabMouseEvent = QEvent::User + 200 };
238
239 UIGrabMouseEvent(QEvent::Type type, Qt::MouseButton button, Qt::MouseButtons buttons, int x, int y, int wheelDelta, Qt::Orientation o)
240 : QEvent((QEvent::Type)GrabMouseEvent)
241 , m_type(type)
242 , m_button(button)
243 , m_buttons(buttons)
244 , m_x(x)
245 , m_y(y)
246 , m_wheelDelta(wheelDelta)
247 , m_orientation(o)
248 {}
249 QEvent::Type mouseEventType() const { return m_type; }
250 Qt::MouseButton button() const { return m_button; }
251 Qt::MouseButtons buttons() const { return m_buttons; }
252 int xDelta() const { return m_x; }
253 int yDelta() const { return m_y; }
254 int wheelDelta() const { return m_wheelDelta; }
255 Qt::Orientation orientation() const { return m_orientation; }
256
257private:
258 /* Private members */
259 QEvent::Type m_type;
260 Qt::MouseButton m_button;
261 Qt::MouseButtons m_buttons;
262 int m_x;
263 int m_y;
264 int m_wheelDelta;
265 Qt::Orientation m_orientation;
266};
267
268/********************************************************************************
269 *
270 * Simple setter methods (Qt Wrapper)
271 *
272 ********************************************************************************/
273void darwinSetShowsToolbarButton(QToolBar *aToolBar, bool fEnabled);
274SHARED_LIBRARY_STUFF void darwinLabelWindow(QWidget *pWidget, QPixmap *pPixmap);
275void darwinSetShowsResizeIndicator(QWidget *pWidget, bool fEnabled);
276SHARED_LIBRARY_STUFF void darwinSetHidesAllTitleButtons(QWidget *pWidget);
277void darwinSetShowsWindowTransparent(QWidget *pWidget, bool fEnabled);
278SHARED_LIBRARY_STUFF void darwinSetWindowHasShadow(QWidget *pWidget, bool fEnabled);
279SHARED_LIBRARY_STUFF void darwinDisableIconsInMenus(void);
280
281void darwinTest(QWidget *pWidget1, QWidget *pWidget2, int h);
282
283/********************************************************************************
284 *
285 * Simple helper methods (Qt Wrapper)
286 *
287 ********************************************************************************/
288SHARED_LIBRARY_STUFF void darwinWindowAnimateResize(QWidget *pWidget, const QRect &aTarget);
289void darwinWindowAnimateResizeNew(QWidget *pWidget, int h, bool fAnimate);
290void darwinWindowInvalidateShape(QWidget *pWidget);
291void darwinWindowInvalidateShadow(QWidget *pWidget);
292int darwinWindowToolBarHeight(QWidget *pWidget);
293SHARED_LIBRARY_STUFF int darwinWindowTitleHeight(QWidget *pWidget);
294bool darwinIsToolbarVisible(QToolBar *pToolBar);
295SHARED_LIBRARY_STUFF bool darwinIsWindowMaximized(QWidget *pWidget);
296void darwinMinaturizeWindow(QWidget *pWidget);
297SHARED_LIBRARY_STUFF void darwinEnableFullscreenSupport(QWidget *pWidget);
298SHARED_LIBRARY_STUFF void darwinEnableTransienceSupport(QWidget *pWidget);
299SHARED_LIBRARY_STUFF void darwinToggleFullscreenMode(QWidget *pWidget);
300SHARED_LIBRARY_STUFF void darwinToggleWindowZoom(QWidget *pWidget);
301SHARED_LIBRARY_STUFF bool darwinIsInFullscreenMode(QWidget *pWidget);
302SHARED_LIBRARY_STUFF bool darwinIsOnActiveSpace(QWidget *pWidget);
303bool darwinOpenFile(const QString &strFile);
304
305QString darwinSystemLanguage(void);
306QPixmap darwinCreateDragPixmap(const QPixmap& aPixmap, const QString &aText);
307
308void darwinInstallResizeDelegate(QWidget *pWidget);
309void darwinUninstallResizeDelegate(QWidget *pWidget);
310
311SHARED_LIBRARY_STUFF void darwinRegisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
312SHARED_LIBRARY_STUFF void darwinUnregisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
313
314SHARED_LIBRARY_STUFF void darwinMouseGrab(QWidget *pWidget);
315SHARED_LIBRARY_STUFF void darwinMouseRelease(QWidget *pWidget);
316
317SHARED_LIBRARY_STUFF void *darwinCocoaToCarbonEvent(void *pvCocoaEvent);
318
319#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