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