Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcocoahelpers.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QCOCOAHELPERS_H
6#define QCOCOAHELPERS_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It provides helper functions
13// for the Cocoa plugin. This header file may
14// change from version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qguiapplication_p.h>
20#include <QtCore/qloggingcategory.h>
21#include <QtGui/qpalette.h>
22#include <QtGui/qscreen.h>
23#include <qpa/qplatformdialoghelper.h>
24
25#include <objc/runtime.h>
26#include <objc/message.h>
27
28#if defined(__OBJC__)
29
30#import <AppKit/NSDragging.h>
31#import <AppKit/NSEvent.h>
32#import <AppKit/NSButton.h>
33
35
36struct mach_header;
37
39
50
51class QPixmap;
52class QString;
53
54// Conversion functions
57
62
64
65// Misc
68
71
74
76
79
80// strip out '&' characters, and convert "&&" to a single '&', in menu
81// text - since menu text is sometimes decorated with these for Windows
82// accelerators.
84
85// Similar to __NXKitString for localized AppKit strings
87
88enum {
91};
92
94public:
95 id target;
97 int argCount;
98 id arg1;
99 id arg2;
102 {
103 [target retain];
104 [arg1 retain];
105 [arg2 retain];
106 }
107
109 {
110 [arg2 release];
111 [arg1 release];
112 [target release];
113 }
114};
115
116template<typename T>
118{
119 // check for environment variable
120 if (!environment.isEmpty()) {
122 if (!env.isEmpty())
123 return T(env.toInt()); // works when T is bool, int.
124 }
125
126 return fallback;
127}
128
129template<typename T>
131{
132 // check for environment variable
133 if (!environment.isEmpty()) {
135 if (!env.isEmpty())
136 return T(env.toInt()); // works when T is bool, int.
137 }
138
139 // check for window property
140 if (window && !property.isNull()) {
143 return windowProperty.value<T>();
144 }
145
146 // return default value.
147 return fallback;
148}
149
150// https://stackoverflow.com/a/52722575/2761869
151template<class R>
152struct backwards_t {
153 R r;
154 constexpr auto begin() const { using std::rbegin; return rbegin(r); }
155 constexpr auto begin() { using std::rbegin; return rbegin(r); }
156 constexpr auto end() const { using std::rend; return rend(r); }
157 constexpr auto end() { using std::rend; return rend(r); }
158};
159template<class R>
160constexpr backwards_t<R> backwards(R&& r) { return {std::forward<R>(r)}; }
161
163
164// @compatibility_alias doesn't work with protocols
165#define QNSPanelDelegate QT_MANGLE_NAMESPACE(QNSPanelDelegate)
166
169- (void)onOkClicked;
170- (void)onCancelClicked;
171@end
172
174
177@property (nonatomic, readonly) NSView *panelContents; // ARC: unretained, make it weak
179
181- (void)dealloc;
182
184- (void)layout;
185
186@end
187
189
191
192// -------------------------------------------------------------------------
193
194struct InputMethodQueryResult : public QHash<int, QVariant>
195{
196 operator bool() { return !isEmpty(); }
197};
198
200
201// -------------------------------------------------------------------------
202
203struct KeyEvent
204{
205 ulong timestamp = 0;
207
208 Qt::Key key = Qt::Key_unknown;
211 bool isRepeat = false;
212
213 // Scan codes are hardware dependent codes for each key. There is no way to get these
214 // from Carbon or Cocoa, so leave it 0, as documented in QKeyEvent::nativeScanCode().
215 static const quint32 nativeScanCode = 0;
216
219
222};
223
225
226// -------------------------------------------------------------------------
227
228QDebug operator<<(QDebug, const NSRange &);
230
231#endif // __OBJC__
232
234
235#endif //QCOCOAHELPERS_H
static void clearCurrentThreadCocoaEventDispatcherInterruptFlag()
NSOpenGLContext * nativeContext() const override
void swapBuffers(QPlatformSurface *surface) override
Reimplement in subclass to native swap buffers calls.
void doneCurrent() override
friend QDebug operator<<(QDebug debug, const QCocoaGLContext *screen)
QSurfaceFormat format() const override
bool isSoftwareContext() const
bool isSharing() const override
void initialize() override
Called after a new instance is constructed.
void beginFrame() override
Called when the RHI begins rendering a new frame in the context.
QFunctionPointer getProcAddress(const char *procName) override
Reimplement in subclass to allow dynamic querying of OpenGL symbols.
QCocoaGLContext(QOpenGLContext *context)
bool makeCurrent(QPlatformSurface *surface) override
bool isValid() const override
NSMenu * nsMenu() const override
QList< QCocoaMenuItem * > merged() const
NSMenuItem * itemForRole(QPlatformMenuItem::MenuRole role)
void removeMenu(QPlatformMenu *menu) override
static void updateMenuBarImmediately()
void syncMenu_helper(QPlatformMenu *menu, bool menubarUpdate)
void syncMenu(QPlatformMenu *menuItem) override
void handleReparent(QWindow *newParentWindow) override
void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) override
QCocoaWindow * cocoaWindow() const
QWindow * parentWindow() const override
static void insertWindowMenu()
QPlatformMenu * menuForTag(quintptr tag) const override
void setParentEnabled(bool enabled)
void setRole(MenuRole role) override
NSMenuItem * sync()
void setNativeContents(WId item) override
bool isVisible() const
QCocoaMenu * menu() const
void setCheckable(bool) override
bool isSeparator() const
void setIsSeparator(bool isSeparator) override
void setText(const QString &text) override
NSMenuItem * nsItem()
void setIcon(const QIcon &icon) override
void setShortcut(const QKeySequence &shortcut) override
QString text() const
void setFont(const QFont &font) override
void setEnabled(bool isEnabled) override
void setVisible(bool isVisible) override
void setChecked(bool isChecked) override
bool isMerged() const
bool isEnabled() const
void setIconSize(int size) override
MenuRole effectiveRole() const
void setMenuParent(QObject *o)
QObject * menuParent() const
void dismiss() override
bool isVisible() const
Definition qcocoamenu.h:50
QPlatformMenuItem * menuItemForTag(quintptr tag) const override
QList< QCocoaMenuItem * > merged() const
void timerEvent(QTimerEvent *e) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
void setEnabled(bool enabled) override
QList< QCocoaMenuItem * > items() const
void setItemTargetAction(QCocoaMenuItem *item) const
NSMenuItem * attachedItem() const
void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override
Definition qcocoamenu.mm:93
void setIsOpen(bool isOpen)
void setAsDockMenu() const override
Definition qcocoamenu.mm:87
void setText(const QString &text) override
Definition qcocoamenu.mm:61
bool isEnabled() const override
void propagateEnabledState(bool enabled)
void syncSeparatorsCollapsible(bool enable) override
void setIsAboutToShow(bool isAbout)
void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override
void setIcon(const QIcon &) override
Definition qcocoamenu.h:41
bool isAboutToShow() const
void setFont(const QFont &font) override
Definition qcocoamenu.mm:73
bool isOpen() const
QPlatformMenuItem * menuItemAt(int position) const override
void syncMenuItem(QPlatformMenuItem *menuItem) override
void removeMenuItem(QPlatformMenuItem *menuItem) override
void syncMenuItem_helper(QPlatformMenuItem *menuItem, bool menubarUpdate)
void setAttachedItem(NSMenuItem *item)
NSMenu * nsMenu() const override
Definition qcocoamenu.mm:82
void setVisible(bool visible) override
void setMinimumWidth(int width) override
Definition qcocoamenu.mm:68
void * nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) override
NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource) override
void handleWindowStateChanged(HandleFlags flags=NoHandleFlags)
static void setupPopupMonitor()
void setContentBorderAreaEnabled(quintptr identifier, bool enable)
bool alwaysShowToolWindow() const
void setMenubar(QCocoaMenuBar *mb)
void toggleMaximized()
QWindow * childWindowAt(QPoint windowPoint)
void setAlertState(bool enabled) override
Reimplement this method to set whether the window demands attention (for example, by flashing the tas...
int m_registerTouchCount
Qt::WindowModality m_windowModality
QMargins safeAreaMargins() const override
The safe area margins of a window represent the area that is safe to place content within,...
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
void setWindowCursor(NSCursor *cursor)
bool testContentBorderAreaPosition(int position) const
NSView * view() const
QRect normalGeometry() const override
the geometry of the window as it will appear when shown as a normal (not maximized or full screen) to...
QMacKeyValueObserver m_safeAreaInsetsObserver
bool updatesWithDisplayLink() const
bool m_inSetStyleMask
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
bool isForeignWindow() const override
bool setMouseGrabEnabled(bool grab) override
QCocoaNSWindow * m_nsWindow
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
void setOpacity(qreal level) override
Reimplement to be able to let Qt set the opacity level of a window.
QCocoaNSWindow * createNSWindow(bool shouldBePanel)
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
static id s_globalMouseMonitor
void setMask(const QRegion &region) override
Reimplement to be able to let Qt set the mask of a window.
QHash< quintptr, bool > m_enabledContentBorderAreas
void setFrameStrutEventsEnabled(bool enabled) override
Reimplement this method to set whether frame strut events should be sent to enabled.
void toggleFullScreen()
QCocoaMenuBar * menubar() const
void setWindowFilePath(const QString &filePath) override
Reimplement to set the window file path to filePath.
void setCocoaGeometry(const QRect &rect)
QRect geometry() const override
Returns the current geometry of a window.
NSInteger windowLevel(Qt::WindowFlags flags)
void setContentBorderEnabled(bool enable) override
bool isOpaque() const
void setParent(const QPlatformWindow *window) override
This function is called to enable native child window in QPA.
static void removePopupMonitor()
bool m_frameStrutEventsEnabled
bool setWindowModified(bool modified) override
Reimplement to be able to let Qt indicate that the window has been modified.
NSWindow * nativeWindow() const
void applyContentBorderThickness(NSWindow *window=nullptr)
void setWindowState(Qt::WindowStates state) override
Changes the state of the NSWindow, going in/out of minimize/zoomed/fullscreen.
void updateSafeAreaMarginsIfNeeded()
bool windowShouldClose()
void registerTouch(bool enable)
void updateTitleBarButtons(Qt::WindowFlags flags)
QMargins frameMargins() const override
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
void updateNormalGeometry()
bool isFixedSize() const
bool isAlertState() const override
Reimplement this method return whether the window is in an alert state.
bool isExposed() const override
Returns if this window is exposed in the windowing system.
QFlatMap< quintptr, NSVisualEffectView * > m_effectViews
void deliverUpdateRequest() override
Delivers an QEvent::UpdateRequest event to the window.
bool isEmbedded() const override
Returns true if the window is a child of a non-Qt window.
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
void manageVisualEffectArea(quintptr identifier, const QRect &rect, NSVisualEffectMaterial material, NSVisualEffectBlendingMode blendMode, NSVisualEffectState activationState) override
bool shouldRefuseKeyWindowAndFirstResponder()
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
static QPointer< QCocoaWindow > s_windowUnderMouse
static void closeAllPopups()
void setWindowIcon(const QIcon &icon) override
Reimplement to set the window icon to icon.
bool isContentView() const
Checks if the window is the content view of its immediate NSWindow.
NSInteger m_alertRequest
QRect m_normalGeometry
void recreateWindowIfNeeded()
Recreates (or removes) the NSWindow for this QWindow, if needed.
void handleGeometryChange()
bool m_drawContentBorderGradient
bool m_resizableTransientParent
NSUInteger windowStyleMask(Qt::WindowFlags flags)
QCocoaMenuBar * m_menubar
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
bool startSystemMove() override
Reimplement this method to start a system move operation if the system supports it and return true to...
static const int NoAlertRequest
CALayer * contentLayer() const override
QRect m_exposedRect
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
void windowWillZoom()
bool setKeyboardGrabEnabled(bool grab) override
bool windowIsPopupType(Qt::WindowType type=Qt::Widget) const
void registerContentBorderArea(quintptr identifier, int upper, int lower)
void setEmbeddedInForeignView()
void applyWindowState(Qt::WindowStates newState)
QPoint bottomLeftClippedByNSWindowOffset() const override
bool isTransitioningToFullScreen() const
QHash< quintptr, BorderRange > m_contentBorderAreas
Qt::WindowStates windowState() const
qreal devicePixelRatio() const override
Reimplement this function in subclass to return the device pixel ratio for the window.
void initialize() override
Called as part of QWindow::create(), after constructing the window.
Qt::WindowStates m_lastReportedWindowState
QSurfaceFormat format() const override
Returns the actual surface format of the window.
bool frameStrutEventsEnabled() const override
Reimplement this method to return whether frame strut events are enabled.
static id s_applicationActivationObserver
NSView * m_view
void handleExposeEvent(const QRegion &region)
QMargins m_lastReportedSafeAreaMargins
\inmodule QtCore\reentrant
Definition qpoint.h:231
\inmodule QtSql
QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QCocoaWindow)
QT_DECLARE_NAMESPACED_OBJC_INTERFACE(QMacAccessibilityElement, NSObject -(void) invalidate;) QT_BEGIN_NAMESPACE bool QAccessibleCache
Q_FORWARD_DECLARE_OBJC_CLASS(NSOpenGLPixelFormat)
Q_FORWARD_DECLARE_OBJC_CLASS(NSMenuItem)
Q_FORWARD_DECLARE_OBJC_CLASS(NSMenu)
Q_FORWARD_DECLARE_OBJC_CLASS(NSObject)
QString qt_mac_applicationmenu_string(int type)
QT_FORWARD_DECLARE_CLASS(QCocoaMenu)
QT_FORWARD_DECLARE_CLASS(QCocoaMenuItem)
unsigned long NSUInteger
long NSInteger
Q_FORWARD_DECLARE_OBJC_CLASS(NSVisualEffectView)
Q_FORWARD_DECLARE_OBJC_CLASS(NSView)
Q_FORWARD_DECLARE_OBJC_CLASS(NSCursor)
const NSNotificationName QCocoaWindowWillReleaseQNSViewNotification
#define Q_NOTIFICATION_HANDLER(notification)
Q_FORWARD_DECLARE_OBJC_CLASS(NSObject)
bool operator<(BorderRange const &right) const
BorderRange(quintptr i, int u, int l)