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
22QT_BEGIN_NAMESPACE
23
24
25class QPlatformWindow;
26class QWindow;
27class QPlatformBackingStore;
28class QPlatformFontDatabase;
29class QPlatformClipboard;
30class QPlatformNativeInterface;
31class QPlatformDrag;
32class QPlatformOpenGLContext;
33class QGuiGLFormat;
34class QAbstractEventDispatcher;
35class QPlatformInputContext;
36class QPlatformAccessibility;
37class QPlatformTheme;
38class QPlatformDialogHelper;
39class QPlatformSharedGraphicsCache;
40class QPlatformServices;
41class QPlatformSessionManager;
42class QKeyEvent;
43class QPlatformOffscreenSurface;
44class QOffscreenSurface;
45class QPlatformVulkanInstance;
46class QVulkanInstance;
47
48namespace QNativeInterface::Private {
49
50template <typename R, typename I, auto func, typename... Args>
51struct 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
63template <auto func>
64struct QInterfaceProxy;
65template <typename R, typename I, typename... Args, R(I::*func)(Args...)>
66struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {};
67template <typename R, typename I, typename... Args, R(I::*func)(Args...) const>
68struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {};
69
70} // QNativeInterface::Private
71
72class Q_GUI_EXPORT QPlatformIntegration
73{
74public:
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 ReplayMousePressOutsidePopup,
159 ItemViewActivateItemOnSingleClick,
160 UiEffects,
161 WheelScrollLines,
162 ShowShortcutsInContextMenus,
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
208protected:
209 QPlatformIntegration() = default;
210};
211
212QT_END_NAMESPACE
213
214#endif // QPLATFORMINTEGRATION_H
215

source code of qtbase/src/gui/kernel/qplatformintegration.h