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