VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 4 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/* $Id: UICocoaApplication.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UICocoaApplication class declaration.
4 */
5
6/*
7 * Copyright (C) 2009-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_UICocoaApplication_h
29#define FEQT_INCLUDED_SRC_platform_darwin_UICocoaApplication_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QMap>
36
37/* GUI includes: */
38#include "VBoxCocoaHelper.h"
39#include "VBoxUtils-darwin.h"
40#include "UILibraryDefs.h"
41
42/* Forward declarations: */
43class QObject;
44class QWidget;
45
46/* Cocoa declarations: */
47ADD_COCOA_NATIVE_REF(UICocoaApplicationPrivate);
48ADD_COCOA_NATIVE_REF(NSAutoreleasePool);
49ADD_COCOA_NATIVE_REF(NSString);
50ADD_COCOA_NATIVE_REF(NSWindow);
51ADD_COCOA_NATIVE_REF(NSButton);
52
53
54/** Event handler callback. */
55typedef bool (*PFNVBOXCACALLBACK)(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
56
57/** Native notification callback type for QObject. */
58typedef void (*PfnNativeNotificationCallbackForQObject)(QObject *pObject, const QMap<QString, QString> &userInfo);
59/** Native notification callback type for QWidget. */
60typedef void (*PfnNativeNotificationCallbackForQWidget)(const QString &strNativeNotificationName, QWidget *pWidget);
61/** Standard window button callback type for QWidget. */
62typedef void (*PfnStandardWindowButtonCallbackForQWidget)(StandardWindowButtonType emnButtonType, bool fWithOptionKey, QWidget *pWidget);
63
64
65/** Singleton prototype for our private NSApplication object. */
66class SHARED_LIBRARY_STUFF UICocoaApplication
67{
68public:
69
70 /** Creates singleton instance.
71 * @param fPreventAppNap Brings whether we should prevent AppNap. */
72 static void create(bool fPreventAppNap);
73 /** Returns singleton instance. */
74 static UICocoaApplication *instance();
75
76 /** Destructs cocoa application. */
77 virtual ~UICocoaApplication();
78
79 /** Returns whether we should prevent AppNap. */
80 bool isPreventAppNap() const { return m_fPreventAppNap; }
81
82 /** Returns whether application is currently active. */
83 bool isActive() const;
84
85 /** Returns whether app is in Dark mode. */
86 bool isDarkMode() const;
87
88 /** Hides the application. */
89 void hide();
90
91 /** Hides user elements such as menu-bar and dock. */
92 void hideUserElements();
93
94 /** Register native @a pfnCallback of the @a pvUser taking event @a fMask into account. */
95 void registerForNativeEvents(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser);
96 /** Unregister native @a pfnCallback of the @a pvUser taking event @a fMask into account. */
97 void unregisterForNativeEvents(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser);
98
99 /** Register passed @a pObject to native notification @a strNativeNotificationName, using @a pCallback as handler. */
100 void registerToNotificationOfWorkspace(const QString &strNativeNotificationName, QObject *pObject, PfnNativeNotificationCallbackForQObject pCallback);
101 /** Unregister passed @a pWidget from native notification @a strNativeNotificationName. */
102 void unregisterFromNotificationOfWorkspace(const QString &strNativeNotificationName, QObject *pObject);
103
104 /** Register passed @a pWidget to native notification @a strNativeNotificationName, using @a pCallback as handler. */
105 void registerToNotificationOfWindow(const QString &strNativeNotificationName, QWidget *pWidget, PfnNativeNotificationCallbackForQWidget pCallback);
106 /** Unregister passed @a pWidget from native notification @a strNativeNotificationName. */
107 void unregisterFromNotificationOfWindow(const QString &strNativeNotificationName, QWidget *pWidget);
108
109 /** Redirects native notification @a pstrNativeNotificationName for application to registered listener. */
110 void nativeNotificationProxyForObject(NativeNSStringRef pstrNativeNotificationName, const QMap<QString, QString> &userInfo);
111 /** Redirects native notification @a pstrNativeNotificationName for window @a pWindow to registered listener. */
112 void nativeNotificationProxyForWidget(NativeNSStringRef pstrNativeNotificationName, NativeNSWindowRef pWindow);
113
114 /** Register callback for standard window @a buttonType of passed @a pWidget as @a pCallback. */
115 void registerCallbackForStandardWindowButton(QWidget *pWidget, StandardWindowButtonType enmButtonType, PfnStandardWindowButtonCallbackForQWidget pCallback);
116 /** Unregister callback for standard window @a buttonType of passed @a pWidget. */
117 void unregisterCallbackForStandardWindowButton(QWidget *pWidget, StandardWindowButtonType enmButtonType);
118 /** Redirects standard window button selector to registered callback. */
119 void nativeCallbackProxyForStandardWindowButton(NativeNSButtonRef pButton, bool fWithOptionKey);
120
121private:
122
123 /** Constructs cocoa application.
124 * @param fPreventAppNap Brings whether we should prevent AppNap. */
125 UICocoaApplication(bool fPreventAppNap);
126
127 /** Holds the singleton access instance. */
128 static UICocoaApplication *s_pInstance;
129
130 /** Holds whether we should prevent AppNap. */
131 const bool m_fPreventAppNap;
132
133 /** Holds the private NSApplication instance. */
134 NativeUICocoaApplicationPrivateRef m_pNative;
135 /** Holds the private NSAutoreleasePool instance. */
136 NativeNSAutoreleasePoolRef m_pPool;
137
138 /** Map of notification callbacks registered for corresponding QObject(s). */
139 QMap<QObject*, QMap<QString, PfnNativeNotificationCallbackForQObject> > m_objectCallbacks;
140 /** Map of notification callbacks registered for corresponding QWidget(s). */
141 QMap<QWidget*, QMap<QString, PfnNativeNotificationCallbackForQWidget> > m_widgetCallbacks;
142
143 /** Map of callbacks registered for standard window button(s) of corresponding QWidget(s). */
144 QMap<QWidget*, QMap<StandardWindowButtonType, PfnStandardWindowButtonCallbackForQWidget> > m_stdWindowButtonCallbacks;
145};
146
147#endif /* !FEQT_INCLUDED_SRC_platform_darwin_UICocoaApplication_h */
148
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