1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the plugins of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QCOCOANATIVEINTERFACE_H 41 #define QCOCOANATIVEINTERFACE_H 42 43 #include <ApplicationServices/ApplicationServices.h> 44 45 #include <qpa/qplatformnativeinterface.h> 46 #include <QtGui/qpixmap.h> 47 48 QT_BEGIN_NAMESPACE 49 50 class QWidget; 51 class QPlatformPrinterSupport; 52 class QPrintEngine; 53 class QPlatformMenu; 54 class QPlatformMenuBar; 55 56 class QCocoaNativeInterface : public QPlatformNativeInterface 57 { 58 Q_OBJECT 59 public: 60 QCocoaNativeInterface(); 61 62 #ifndef QT_NO_OPENGL 63 void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context) override; 64 #endif 65 void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) override; 66 67 NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource) override; 68 69 #ifndef QT_NO_OPENGL 70 static void *cglContextForContext(QOpenGLContext *context); 71 static void *nsOpenGLContextForContext(QOpenGLContext* context); 72 #endif 73 74 QFunctionPointer platformFunction(const QByteArray &function) const override; 75 76 public Q_SLOTS: 77 void onAppFocusWindowChanged(QWindow *window); 78 79 private: 80 /* 81 "Virtual" function to create the platform printer support 82 implementation. 83 84 We use an invokable function instead of a virtual one, we do not want 85 this in the QPlatform* API yet. 86 87 This was added here only because QPlatformNativeInterface is a QObject 88 and allow us to use QMetaObject::indexOfMethod() from the printsupport 89 plugin. 90 */ 91 Q_INVOKABLE QPlatformPrinterSupport *createPlatformPrinterSupport(); 92 /* 93 Function to return the NSPrintInfo * from QMacPaintEnginePrivate. 94 Needed by the native print dialog in the Qt Print Support module. 95 */ 96 Q_INVOKABLE void *NSPrintInfoForPrintEngine(QPrintEngine *printEngine); 97 /* 98 Function to return the default background pixmap. 99 Needed by QWizard in the Qt widget module. 100 */ 101 Q_INVOKABLE QPixmap defaultBackgroundPixmapForQWizard(); 102 103 Q_INVOKABLE void clearCurrentThreadCocoaEventDispatcherInterruptFlag(); 104 105 // QMacPastebardMime support. The mac pasteboard void pointers are 106 // QMacPastebardMime instances from the cocoa plugin or qtmacextras 107 // These two classes are kept in sync and can be casted between. 108 static void addToMimeList(void *macPasteboardMime); 109 static void removeFromMimeList(void *macPasteboardMime); 110 static void registerDraggedTypes(const QStringList &types); 111 112 // Dock menu support 113 static void setDockMenu(QPlatformMenu *platformMenu); 114 115 // Function to return NSMenu * from QPlatformMenu 116 static void *qMenuToNSMenu(QPlatformMenu *platformMenu); 117 118 // Function to return NSMenu * from QPlatformMenuBar 119 static void *qMenuBarToNSMenu(QPlatformMenuBar *platformMenuBar); 120 121 // QImage <-> CGImage conversion functions 122 static CGImageRef qImageToCGImage(const QImage &image); 123 static QImage cgImageToQImage(CGImageRef image); 124 125 // Set a QWindow as a "guest" (subwindow) of a non-QWindow 126 static void setEmbeddedInForeignView(QPlatformWindow *window, bool embedded); 127 128 // Register if a window should deliver touch events. Enabling 129 // touch events has implications for delivery of other events, 130 // for example by causing scrolling event lag. 131 // 132 // The registration is ref-counted: multiple widgets can enable 133 // touch events, which then will be delivered until the widget 134 // deregisters. 135 static void registerTouchWindow(QWindow *window, bool enable); 136 137 // Enable the unified title and toolbar area for a window. 138 static void setContentBorderEnabled(QWindow *window, bool enable); 139 140 // Set the size of the unified title and toolbar area. 141 static void setContentBorderThickness(QWindow *window, int topThickness, int bottomThickness); 142 143 // Set the size for a unified toolbar content border area. 144 // Multiple callers can register areas and the platform plugin 145 // will extend the "unified" area to cover them. 146 static void registerContentBorderArea(QWindow *window, quintptr identifer, int upper, int lower); 147 148 // Enables or disiables a content border area. 149 static void setContentBorderAreaEnabled(QWindow *window, quintptr identifier, bool enable); 150 151 // Returns true if the given coordinate is inside the current 152 // content border. 153 static bool testContentBorderPosition(QWindow *window, int position); 154 155 // Sets a NSToolbar instance for the given QWindow. The 156 // toolbar will be attached to the native NSWindow when 157 // that is created; 158 static void setNSToolbar(QWindow *window, void *nsToolbar); 159 160 }; 161 162 QT_END_NAMESPACE 163 164 #endif // QCOCOANATIVEINTERFACE_H 165 166