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() == "setembeddedinforeignview")
68 return NativeResourceForIntegrationFunction(QFunctionPointer(QCocoaNativeInterface::setEmbeddedInForeignView));
69 if (resource.toLower() == "registercontentborderarea")
70 return NativeResourceForIntegrationFunction(QFunctionPointer(QCocoaNativeInterface::registerContentBorderArea));
71 if (resource.toLower() == "setcontentborderareaenabled")
72 return NativeResourceForIntegrationFunction(QFunctionPointer(QCocoaNativeInterface::setContentBorderAreaEnabled));
73 if (resource.toLower() == "testcontentborderposition")
74 return NativeResourceForIntegrationFunction(QFunctionPointer(QCocoaNativeInterface::testContentBorderPosition));
75
76 return nullptr;
77}
78
79void QCocoaNativeInterface::clearCurrentThreadCocoaEventDispatcherInterruptFlag()
80{
82}
83
84void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window)
85{
86 Q_UNUSED(window);
87 QCocoaMenuBar::updateMenuBarImmediately();
88}
89
90void QCocoaNativeInterface::registerDraggedTypes(const QStringList &types)
91{
92 QMacMimeRegistry::registerDraggedTypes(types);
93}
94
95void QCocoaNativeInterface::setEmbeddedInForeignView(QPlatformWindow *window, bool embedded)
96{
97 Q_UNUSED(embedded); // "embedded" state is now automatically detected
98 QCocoaWindow *cocoaPlatformWindow = static_cast<QCocoaWindow *>(window);
99 cocoaPlatformWindow->setEmbeddedInForeignView();
100}
101
102void QCocoaNativeInterface::registerTouchWindow(QWindow *window, bool enable)
103{
104 if (!window)
105 return;
106
107 QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
108 if (cocoaWindow)
109 cocoaWindow->registerTouch(enable);
110}
111
112void QCocoaNativeInterface::registerContentBorderArea(QWindow *window, quintptr identifier, int upper, int lower)
113{
114 if (!window)
115 return;
116
117 QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
118 if (cocoaWindow)
119 cocoaWindow->registerContentBorderArea(identifier, upper, lower);
120}
121
122void QCocoaNativeInterface::setContentBorderAreaEnabled(QWindow *window, quintptr identifier, bool enable)
123{
124 if (!window)
125 return;
126
127 QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
128 if (cocoaWindow)
129 cocoaWindow->setContentBorderAreaEnabled(identifier, enable);
130}
131
132bool QCocoaNativeInterface::testContentBorderPosition(QWindow *window, int position)
133{
134 if (!window)
135 return false;
136
137 QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
138 if (cocoaWindow)
139 return cocoaWindow->testContentBorderAreaPosition(position);
140 return false;
141}
142
143QT_END_NAMESPACE
static void clearCurrentThreadCocoaEventDispatcherInterruptFlag()
void setEmbeddedInForeignView()