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
qcocoanativeinterface.mm
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#include <AppKit/AppKit.h>
6
8#include "qcocoawindow.h"
9#include "qcocoamenu.h"
10#include "qcocoansmenu.h"
11#include "qcocoamenubar.h"
12#include "qcocoahelpers.h"
16
17#include <qbytearray.h>
18#include <qwindow.h>
19#include <qpixmap.h>
20#include <qpa/qplatformwindow.h>
21#include <QtGui/qsurfaceformat.h>
22#ifndef QT_NO_OPENGL
23#include <qpa/qplatformopenglcontext.h>
24#include <QtGui/qopenglcontext.h>
26#endif
27#include <QtGui/qguiapplication.h>
28#include <qdebug.h>
29
30#include <QtGui/private/qmacmimeregistry_p.h>
31#include <QtGui/private/qcoregraphics_p.h>
32
33#if QT_CONFIG(vulkan)
34#include <MoltenVK/mvk_vulkan.h>
35#endif
36
38
39QCocoaNativeInterface::QCocoaNativeInterface()
40{
41}
42
43void *QCocoaNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window)
44{
45 if (!window->handle())
46 return nullptr;
47
48 if (resourceString == "nsview") {
49 return static_cast<QCocoaWindow *>(window->handle())->m_view;
50 } else if (resourceString == "nswindow") {
51 return static_cast<QCocoaWindow *>(window->handle())->nativeWindow();
52#if QT_CONFIG(vulkan)
53 } else if (resourceString == "vkSurface") {
54 if (QVulkanInstance *instance = window->vulkanInstance())
55 return static_cast<QCocoaVulkanInstance *>(instance->handle())->surface(window);
56#endif
57 }
58 return nullptr;
59}
60
61QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInterface::nativeResourceFunctionForIntegration(const QByteArray &resource)
62{
63 if (resource.toLower() == "registerdraggedtypes")
64 return NativeResourceForIntegrationFunction(QFunctionPointer(QCocoaNativeInterface::registerDraggedTypes));
65 if (resource.toLower() == "registertouchwindow")
66 return NativeResourceForIntegrationFunction(QFunctionPointer(QCocoaNativeInterface::registerTouchWindow));
67 if (resource.toLower() == "registercontentborderarea")
68 return NativeResourceForIntegrationFunction(QFunctionPointer(QCocoaNativeInterface::registerContentBorderArea));
69 if (resource.toLower() == "setcontentborderareaenabled")
70 return NativeResourceForIntegrationFunction(QFunctionPointer(QCocoaNativeInterface::setContentBorderAreaEnabled));
71 if (resource.toLower() == "testcontentborderposition")
72 return NativeResourceForIntegrationFunction(QFunctionPointer(QCocoaNativeInterface::testContentBorderPosition));
73
74 return nullptr;
75}
76
77void QCocoaNativeInterface::clearCurrentThreadCocoaEventDispatcherInterruptFlag()
78{
80}
81
82void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window)
83{
84 Q_UNUSED(window);
85 QCocoaMenuBar::updateMenuBarImmediately();
86}
87
88void QCocoaNativeInterface::registerDraggedTypes(const QStringList &types)
89{
90 QMacMimeRegistry::registerDraggedTypes(types);
91}
92
93void QCocoaNativeInterface::registerTouchWindow(QWindow *window, bool enable)
94{
95 if (!window)
96 return;
97
98 QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
99 if (cocoaWindow)
100 cocoaWindow->registerTouch(enable);
101}
102
103void QCocoaNativeInterface::registerContentBorderArea(QWindow *window, quintptr identifier, int upper, int lower)
104{
105 if (!window)
106 return;
107
108 QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
109 if (cocoaWindow)
110 cocoaWindow->registerContentBorderArea(identifier, upper, lower);
111}
112
113void QCocoaNativeInterface::setContentBorderAreaEnabled(QWindow *window, quintptr identifier, bool enable)
114{
115 if (!window)
116 return;
117
118 QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
119 if (cocoaWindow)
120 cocoaWindow->setContentBorderAreaEnabled(identifier, enable);
121}
122
123bool QCocoaNativeInterface::testContentBorderPosition(QWindow *window, int position)
124{
125 if (!window)
126 return false;
127
128 QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
129 if (cocoaWindow)
130 return cocoaWindow->testContentBorderAreaPosition(position);
131 return false;
132}
133
134QT_END_NAMESPACE
static void clearCurrentThreadCocoaEventDispatcherInterruptFlag()
Combined button and popup list for selecting options.