| 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 QtGui module 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 QPLATFORMINTEGRATION_H |
| 41 | #define QPLATFORMINTEGRATION_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is part of the QPA API and is not meant to be used |
| 48 | // in applications. Usage of this API may make your code |
| 49 | // source and binary incompatible with future versions of Qt. |
| 50 | // |
| 51 | |
| 52 | #include <QtGui/qtguiglobal.h> |
| 53 | #include <QtGui/qwindowdefs.h> |
| 54 | #include <qpa/qplatformscreen.h> |
| 55 | #include <QtGui/qsurfaceformat.h> |
| 56 | #include <QtGui/qopenglcontext.h> |
| 57 | |
| 58 | QT_BEGIN_NAMESPACE |
| 59 | |
| 60 | |
| 61 | class QPlatformWindow; |
| 62 | class QWindow; |
| 63 | class QPlatformBackingStore; |
| 64 | class QPlatformFontDatabase; |
| 65 | class QPlatformClipboard; |
| 66 | class QPlatformNativeInterface; |
| 67 | class QPlatformDrag; |
| 68 | class QPlatformOpenGLContext; |
| 69 | class QGuiGLFormat; |
| 70 | class QAbstractEventDispatcher; |
| 71 | class QPlatformInputContext; |
| 72 | class QPlatformAccessibility; |
| 73 | class QPlatformTheme; |
| 74 | class QPlatformDialogHelper; |
| 75 | class QPlatformSharedGraphicsCache; |
| 76 | class QPlatformServices; |
| 77 | class QPlatformSessionManager; |
| 78 | class QKeyEvent; |
| 79 | class QPlatformOffscreenSurface; |
| 80 | class QOffscreenSurface; |
| 81 | class QPlatformVulkanInstance; |
| 82 | class QVulkanInstance; |
| 83 | |
| 84 | namespace QNativeInterface::Private { |
| 85 | |
| 86 | template <typename R, typename I, auto func, typename... Args> |
| 87 | struct QInterfaceProxyImp |
| 88 | { |
| 89 | template <typename T> |
| 90 | static R apply(T *obj, Args... args) |
| 91 | { |
| 92 | if (auto *iface = dynamic_cast<I*>(obj)) |
| 93 | return (iface->*func)(args...); |
| 94 | else |
| 95 | return R(); |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | template <auto func> |
| 100 | struct QInterfaceProxy; |
| 101 | template <typename R, typename I, typename... Args, R(I::*func)(Args...)> |
| 102 | struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {}; |
| 103 | template <typename R, typename I, typename... Args, R(I::*func)(Args...) const> |
| 104 | struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {}; |
| 105 | |
| 106 | } // QNativeInterface::Private |
| 107 | |
| 108 | class Q_GUI_EXPORT QPlatformIntegration |
| 109 | { |
| 110 | public: |
| 111 | Q_DISABLE_COPY_MOVE(QPlatformIntegration) |
| 112 | |
| 113 | enum Capability { |
| 114 | ThreadedPixmaps = 1, |
| 115 | OpenGL, |
| 116 | ThreadedOpenGL, |
| 117 | SharedGraphicsCache, |
| 118 | BufferQueueingOpenGL, |
| 119 | WindowMasks, |
| 120 | MultipleWindows, |
| 121 | ApplicationState, |
| 122 | ForeignWindows, |
| 123 | NonFullScreenWindows, |
| 124 | NativeWidgets, |
| 125 | WindowManagement, |
| 126 | WindowActivation, // whether requestActivate is supported |
| 127 | SyncState, |
| 128 | RasterGLSurface, |
| 129 | AllGLFunctionsQueryable, |
| 130 | ApplicationIcon, |
| 131 | SwitchableWidgetComposition, |
| 132 | TopStackedNativeChildWindows, |
| 133 | OpenGLOnRasterSurface, |
| 134 | MaximizeUsingFullscreenGeometry, |
| 135 | PaintEvents |
| 136 | }; |
| 137 | |
| 138 | virtual ~QPlatformIntegration() { } |
| 139 | |
| 140 | virtual bool hasCapability(Capability cap) const; |
| 141 | |
| 142 | virtual QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const; |
| 143 | virtual QPlatformWindow *createPlatformWindow(QWindow *window) const = 0; |
| 144 | virtual QPlatformWindow *createForeignWindow(QWindow *, WId) const { return nullptr; } |
| 145 | virtual QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const = 0; |
| 146 | #ifndef QT_NO_OPENGL |
| 147 | virtual QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; |
| 148 | #endif |
| 149 | virtual QPlatformSharedGraphicsCache *createPlatformSharedGraphicsCache(const char *cacheId) const; |
| 150 | virtual QPaintEngine *createImagePaintEngine(QPaintDevice *paintDevice) const; |
| 151 | |
| 152 | // Event dispatcher: |
| 153 | virtual QAbstractEventDispatcher *createEventDispatcher() const = 0; |
| 154 | virtual void initialize(); |
| 155 | virtual void destroy(); |
| 156 | |
| 157 | //Deeper window system integrations |
| 158 | virtual QPlatformFontDatabase *fontDatabase() const; |
| 159 | #ifndef QT_NO_CLIPBOARD |
| 160 | virtual QPlatformClipboard *clipboard() const; |
| 161 | #endif |
| 162 | #if QT_CONFIG(draganddrop) |
| 163 | virtual QPlatformDrag *drag() const; |
| 164 | #endif |
| 165 | virtual QPlatformInputContext *inputContext() const; |
| 166 | #ifndef QT_NO_ACCESSIBILITY |
| 167 | virtual QPlatformAccessibility *accessibility() const; |
| 168 | #endif |
| 169 | |
| 170 | // Access native handles. The window handle is already available from Wid; |
| 171 | virtual QPlatformNativeInterface *nativeInterface() const; |
| 172 | |
| 173 | virtual QPlatformServices *services() const; |
| 174 | |
| 175 | enum StyleHint { |
| 176 | CursorFlashTime, |
| 177 | KeyboardInputInterval, |
| 178 | MouseDoubleClickInterval, |
| 179 | StartDragDistance, |
| 180 | StartDragTime, |
| 181 | KeyboardAutoRepeatRate, |
| 182 | ShowIsFullScreen, |
| 183 | PasswordMaskDelay, |
| 184 | FontSmoothingGamma, |
| 185 | StartDragVelocity, |
| 186 | UseRtlExtensions, |
| 187 | PasswordMaskCharacter, |
| 188 | SetFocusOnTouchRelease, |
| 189 | ShowIsMaximized, |
| 190 | MousePressAndHoldInterval, |
| 191 | TabFocusBehavior, |
| 192 | , |
| 193 | ItemViewActivateItemOnSingleClick, |
| 194 | UiEffects, |
| 195 | WheelScrollLines, |
| 196 | , |
| 197 | MouseQuickSelectionThreshold |
| 198 | }; |
| 199 | |
| 200 | virtual QVariant styleHint(StyleHint hint) const; |
| 201 | virtual Qt::WindowState defaultWindowState(Qt::WindowFlags) const; |
| 202 | |
| 203 | virtual Qt::KeyboardModifiers queryKeyboardModifiers() const; |
| 204 | virtual QList<int> possibleKeys(const QKeyEvent *) const; |
| 205 | |
| 206 | virtual QStringList themeNames() const; |
| 207 | virtual QPlatformTheme *createPlatformTheme(const QString &name) const; |
| 208 | |
| 209 | virtual QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const; |
| 210 | |
| 211 | #ifndef QT_NO_SESSIONMANAGER |
| 212 | virtual QPlatformSessionManager *createPlatformSessionManager(const QString &id, const QString &key) const; |
| 213 | #endif |
| 214 | |
| 215 | virtual void sync(); |
| 216 | |
| 217 | #ifndef QT_NO_OPENGL |
| 218 | virtual QOpenGLContext::OpenGLModuleType openGLModuleType(); |
| 219 | #endif |
| 220 | virtual void setApplicationIcon(const QIcon &icon) const; |
| 221 | |
| 222 | virtual void beep() const; |
| 223 | virtual void quit() const; |
| 224 | |
| 225 | #if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC) |
| 226 | virtual QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const; |
| 227 | #endif |
| 228 | |
| 229 | template <auto func, typename... Args> |
| 230 | auto call(Args... args) |
| 231 | { |
| 232 | using namespace QNativeInterface::Private; |
| 233 | return QInterfaceProxy<func>::apply(this, args...); |
| 234 | } |
| 235 | |
| 236 | protected: |
| 237 | QPlatformIntegration() = default; |
| 238 | }; |
| 239 | |
| 240 | QT_END_NAMESPACE |
| 241 | |
| 242 | #endif // QPLATFORMINTEGRATION_H |
| 243 | |