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 QGUIAPPLICATION_P_H
41#define QGUIAPPLICATION_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtGui/private/qtguiglobal_p.h>
55#include <QtGui/qguiapplication.h>
56#include <QtGui/qicon.h>
57
58#include <QtCore/QPointF>
59#include <QtCore/QSharedPointer>
60#include <QtCore/private/qcoreapplication_p.h>
61
62#include <QtCore/qnativeinterface.h>
63#include <QtCore/private/qthread_p.h>
64
65#include <qpa/qwindowsysteminterface.h>
66#include <qpa/qwindowsysteminterface_p.h>
67#if QT_CONFIG(shortcut)
68# include "private/qshortcutmap_p.h"
69#endif
70
71QT_BEGIN_NAMESPACE
72
73class QColorTrcLut;
74class QPlatformIntegration;
75class QPlatformTheme;
76class QPlatformDragQtResponse;
77#if QT_CONFIG(draganddrop)
78class QDrag;
79#endif // QT_CONFIG(draganddrop)
80class QInputDeviceManager;
81#ifndef QT_NO_ACTION
82class QActionPrivate;
83#endif
84#if QT_CONFIG(shortcut)
85class QShortcutPrivate;
86#endif
87
88class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
89{
90 Q_DECLARE_PUBLIC(QGuiApplication)
91public:
92 QGuiApplicationPrivate(int &argc, char **argv, int flags);
93 ~QGuiApplicationPrivate();
94
95 void init();
96
97 void createPlatformIntegration();
98 void createEventDispatcher() override;
99 void eventDispatcherReady() override;
100
101 virtual void notifyLayoutDirectionChange();
102 virtual void notifyActiveWindowChange(QWindow *previous);
103
104#if QT_CONFIG(commandlineparser)
105 void addQtOptions(QList<QCommandLineOption> *options) override;
106#endif
107 virtual bool shouldQuit() override;
108 void quit() override;
109
110 bool shouldQuitInternal(const QWindowList &processedWindows);
111
112 static void captureGlobalModifierState(QEvent *e);
113 static Qt::KeyboardModifiers modifier_buttons;
114 static Qt::MouseButtons mouse_buttons;
115
116 static QPlatformIntegration *platform_integration;
117
118 static QPlatformIntegration *platformIntegration()
119 { return platform_integration; }
120
121 static QPlatformTheme *platform_theme;
122
123 static QPlatformTheme *platformTheme()
124 { return platform_theme; }
125
126 static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
127 {
128 if (QCoreApplication::instance())
129 return QCoreApplication::instance()->d_func()->threadData.loadRelaxed()->eventDispatcher.loadRelaxed();
130 else
131 return nullptr;
132 }
133
134 static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
135 static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
136 static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
137 static void processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e);
138
139 static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
140
141 static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
142
143 static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
144 static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
145
146 static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
147 static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
148 static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
149
150 static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e);
151
152 static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
153
154 static void processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
155
156 static void updateFilteredScreenOrientation(QScreen *screen);
157 static void processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
158 static void processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
159 static void processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
160 static void processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
161 static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
162
163 static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
164 static void processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e);
165
166 static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
167
168 static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
169 static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
170 static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
171
172#ifndef QT_NO_GESTURES
173 static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e);
174#endif
175
176 static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
177#ifndef QT_NO_CONTEXTMENU
178 static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e);
179#endif
180
181#if QT_CONFIG(draganddrop)
182 static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData,
183 const QPoint &p, Qt::DropActions supportedActions,
184 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
185 static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData,
186 const QPoint &p, Qt::DropActions supportedActions,
187 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
188#endif
189
190 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
191
192 static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
193
194 static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
195 {
196 if (!(alignment & Qt::AlignHorizontal_Mask))
197 alignment |= Qt::AlignLeft;
198 if (!(alignment & Qt::AlignAbsolute) && (alignment & (Qt::AlignLeft | Qt::AlignRight))) {
199 if (direction == Qt::RightToLeft)
200 alignment ^= (Qt::AlignLeft | Qt::AlignRight);
201 alignment |= Qt::AlignAbsolute;
202 }
203 return alignment;
204 }
205
206 static void emitLastWindowClosed();
207
208 QPixmap getPixmapCursor(Qt::CursorShape cshape);
209
210 void _q_updateFocusObject(QObject *object);
211
212 static QGuiApplicationPrivate *instance() { return self; }
213
214 static QIcon *app_icon;
215 static QString *platform_name;
216 static QString *displayName;
217 static QString *desktopFileName;
218
219 QWindowList modalWindowList;
220 static void showModalWindow(QWindow *window);
221 static void hideModalWindow(QWindow *window);
222 static void updateBlockedStatus(QWindow *window);
223 virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const;
224 virtual bool popupActive() { return false; }
225
226 static Qt::MouseButton mousePressButton;
227 static QPointF lastCursorPosition;
228 static QWindow *currentMouseWindow;
229 static QWindow *currentMousePressWindow;
230 static Qt::ApplicationState applicationState;
231 static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy;
232 static QPointer<QWindow> currentDragWindow;
233
234 // TODO remove this: QPointingDevice can store what we need directly
235 struct TabletPointData {
236 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
237 qint64 deviceId;
238 Qt::MouseButtons state;
239 QWindow *target;
240 };
241 static QList<TabletPointData> tabletDevicePoints;
242 static TabletPointData &tabletDevicePoint(qint64 deviceId);
243
244#ifndef QT_NO_CLIPBOARD
245 static QClipboard *qt_clipboard;
246#endif
247
248 static QPalette *app_pal;
249
250 static QWindowList window_list;
251 static QWindow *focus_window;
252
253#ifndef QT_NO_CURSOR
254 QList<QCursor> cursor_list;
255#endif
256 static QList<QScreen *> screen_list;
257
258 static QFont *app_font;
259
260 static QString styleOverride;
261 static QStyleHints *styleHints;
262 static bool obey_desktop_settings;
263 QInputMethod *inputMethod;
264
265 QString firstWindowTitle;
266 QIcon forcedWindowIcon;
267
268 static QList<QObject *> generic_plugin_list;
269#if QT_CONFIG(shortcut)
270 QShortcutMap shortcutMap;
271#endif
272
273#ifndef QT_NO_SESSIONMANAGER
274 QSessionManager *session_manager;
275 bool is_session_restored;
276 bool is_saving_session;
277 void commitData();
278 void saveState();
279#endif
280
281 QEvent::Type lastTouchType;
282 struct SynthesizedMouseData {
283 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
284 : pos(p), screenPos(sp), window(w) { }
285 QPointF pos;
286 QPointF screenPos;
287 QPointer<QWindow> window;
288 };
289 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
290
291 static QInputDeviceManager *inputDeviceManager();
292
293 const QColorTrcLut *colorProfileForA8Text();
294 const QColorTrcLut *colorProfileForA32Text();
295
296 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
297 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
298
299 virtual void notifyWindowIconChanged();
300
301 static void applyWindowGeometrySpecificationTo(QWindow *window);
302
303 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
304
305 static void resetCachedDevicePixelRatio();
306
307#ifndef QT_NO_ACTION
308 virtual QActionPrivate *createActionPrivate() const;
309#endif
310#ifndef QT_NO_SHORTCUT
311 virtual QShortcutPrivate *createShortcutPrivate() const;
312#endif
313
314 static void updatePalette();
315
316protected:
317 virtual void notifyThemeChanged();
318
319 static bool setPalette(const QPalette &palette);
320 virtual QPalette basePalette() const;
321 virtual void handlePaletteChanged(const char *className = nullptr);
322
323#if QT_CONFIG(draganddrop)
324 virtual void notifyDragStarted(const QDrag *);
325#endif // QT_CONFIG(draganddrop)
326
327private:
328 static void clearPalette();
329
330 friend class QDragManager;
331
332 static QGuiApplicationPrivate *self;
333 static int m_fakeMouseSourcePointId;
334 QSharedPointer<QColorTrcLut> m_a8ColorProfile;
335 QSharedPointer<QColorTrcLut> m_a32ColorProfile;
336
337 bool ownGlobalShareContext;
338
339 static QInputDeviceManager *m_inputDeviceManager;
340
341 // Cache the maximum device pixel ratio, to iterate through the screen list
342 // only the first time it's required, or when devices are added or removed.
343 static qreal m_maxDevicePixelRatio;
344};
345
346// ----------------- QNativeInterface -----------------
347
348namespace QNativeInterface::Private {
349
350#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
351
352class QWindowsMime;
353
354struct Q_GUI_EXPORT QWindowsApplication
355{
356 QT_DECLARE_NATIVE_INTERFACE(QWindowsApplication, 1, QGuiApplication)
357
358 enum WindowActivationBehavior {
359 DefaultActivateWindow,
360 AlwaysActivateWindow
361 };
362
363 enum TouchWindowTouchType {
364 NormalTouch = 0x00000000,
365 FineTouch = 0x00000001,
366 WantPalmTouch = 0x00000002
367 };
368
369 Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType)
370
371 enum DarkModeHandlingFlag {
372 DarkModeWindowFrames = 0x1,
373 DarkModeStyle = 0x2
374 };
375
376 Q_DECLARE_FLAGS(DarkModeHandling, DarkModeHandlingFlag)
377
378 virtual void setTouchWindowTouchType(TouchWindowTouchTypes type) = 0;
379 virtual TouchWindowTouchTypes touchWindowTouchType() const = 0;
380
381 virtual WindowActivationBehavior windowActivationBehavior() const = 0;
382 virtual void setWindowActivationBehavior(WindowActivationBehavior behavior) = 0;
383
384 virtual bool isTabletMode() const = 0;
385
386 virtual bool isWinTabEnabled() const = 0;
387 virtual bool setWinTabEnabled(bool enabled) = 0;
388
389 virtual bool isDarkMode() const = 0;
390
391 virtual DarkModeHandling darkModeHandling() const = 0;
392 virtual void setDarkModeHandling(DarkModeHandling handling) = 0;
393
394 virtual void registerMime(QWindowsMime *mime) = 0;
395 virtual void unregisterMime(QWindowsMime *mime) = 0;
396
397 virtual int registerMimeType(const QString &mime) = 0;
398
399 virtual HWND createMessageWindow(const QString &classNameTemplate,
400 const QString &windowName,
401 QFunctionPointer eventProc = nullptr) const = 0;
402
403 virtual bool asyncExpose() const = 0; // internal, used by Active Qt
404 virtual void setAsyncExpose(bool value) = 0;
405
406 virtual QVariant gpu() const = 0; // internal, used by qtdiag
407 virtual QVariant gpuList() const = 0;
408};
409#endif // Q_OS_WIN
410
411} // QNativeInterface::Private
412
413#if defined(Q_OS_WIN)
414Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
415Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::DarkModeHandling)
416#endif
417
418QT_END_NAMESPACE
419
420#endif // QGUIAPPLICATION_P_H
421

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