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 QtWidgets 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 QAPPLICATION_P_H
41#define QAPPLICATION_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 for the convenience
48// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
49// and many other. This header file may change from version to version
50// without notice, or even be removed.
51//
52// We mean it.
53//
54
55#include <QtWidgets/private/qtwidgetsglobal_p.h>
56#include "QtWidgets/qapplication.h"
57#include "QtGui/qevent.h"
58#include "QtGui/qfont.h"
59#include "QtGui/qcursor.h"
60#include "QtGui/qregion.h"
61#include "QtGui/qwindow.h"
62#include "qwidget.h"
63#include <qpa/qplatformnativeinterface.h>
64#include "QtCore/qmutex.h"
65#include "QtCore/qtranslator.h"
66#include "QtCore/qbasictimer.h"
67#include "QtCore/qhash.h"
68#include "QtCore/qpointer.h"
69#include "private/qcoreapplication_p.h"
70#include "QtCore/qpoint.h"
71#include <QTime>
72#include <qpa/qwindowsysteminterface.h>
73#include <qpa/qwindowsysteminterface_p.h>
74#include <qpa/qplatformintegration.h>
75#include "private/qguiapplication_p.h"
76
77QT_BEGIN_NAMESPACE
78
79class QClipboard;
80class QGraphicsScene;
81class QObject;
82class QWidget;
83class QSocketNotifier;
84class QTouchDevice;
85#ifndef QT_NO_GESTURES
86class QGestureManager;
87#endif
88
89extern Q_GUI_EXPORT bool qt_is_gui_used;
90#ifndef QT_NO_CLIPBOARD
91extern QClipboard *qt_clipboard;
92#endif
93
94typedef QHash<QByteArray, QFont> FontHash;
95Q_WIDGETS_EXPORT FontHash *qt_app_fonts_hash();
96
97typedef QHash<QByteArray, QPalette> PaletteHash;
98PaletteHash *qt_app_palettes_hash();
99
100#define QApplicationPrivateBase QGuiApplicationPrivate
101
102class Q_WIDGETS_EXPORT QApplicationPrivate : public QApplicationPrivateBase
103{
104 Q_DECLARE_PUBLIC(QApplication)
105public:
106 QApplicationPrivate(int &argc, char **argv, int flags);
107 ~QApplicationPrivate();
108
109 virtual void notifyLayoutDirectionChange() override;
110 virtual void notifyActiveWindowChange(QWindow *) override;
111
112 virtual bool shouldQuit() override;
113 bool tryCloseAllWindows() override;
114
115#if 0 // Used to be included in Qt4 for Q_WS_X11
116#if QT_CONFIG(settings)
117 static bool x11_apply_settings();
118#endif
119 static void reset_instance_pointer();
120#endif
121 static bool autoSipEnabled;
122 static QString desktopStyleKey();
123
124
125 void createEventDispatcher() override;
126 static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF);
127
128 void notifyWindowIconChanged() override;
129
130 //modality
131 bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = 0) const override;
132 static bool isBlockedByModal(QWidget *widget);
133 static bool modalState();
134 static bool tryModalHelper(QWidget *widget, QWidget **rettop = 0);
135#if 0 // Used to be included in Qt4 for Q_WS_MAC
136 static QWidget *tryModalHelper_sys(QWidget *top);
137 bool canQuit();
138#endif
139
140 bool notify_helper(QObject *receiver, QEvent * e);
141
142 void init(
143#if 0 // Used to be included in Qt4 for Q_WS_X11
144 Display *dpy = 0, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0
145#endif
146 );
147 void initialize();
148 void process_cmdline();
149
150#if 0 // Used to be included in Qt4 for Q_WS_X11
151 static void x11_initialize_style();
152#endif
153
154 static bool inPopupMode();
155 bool popupActive() override { return inPopupMode(); }
156 void closePopup(QWidget *popup);
157 void openPopup(QWidget *popup);
158 static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
159 static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next,
160 bool *wrappingOccurred = 0);
161
162#if QT_CONFIG(graphicsview)
163 // Maintain a list of all scenes to ensure font and palette propagation to
164 // all scenes.
165 QList<QGraphicsScene *> scene_list;
166#endif
167
168 QBasicTimer toolTipWakeUp, toolTipFallAsleep;
169 QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos;
170 QPointer<QWidget> toolTipWidget;
171
172 static QSize app_strut;
173 static QWidgetList *popupWidgets;
174 static QStyle *app_style;
175 static QPalette *sys_pal;
176 static QPalette *set_pal;
177
178protected:
179 void notifyThemeChanged() override;
180 void sendApplicationPaletteChange(bool toAllWidgets = false,
181 const char *className = nullptr) override;
182
183#if QT_CONFIG(draganddrop)
184 void notifyDragStarted(const QDrag *) override;
185#endif // QT_CONFIG(draganddrop)
186
187public:
188 static QFont *sys_font;
189 static QFont *set_font;
190 static QWidget *main_widget;
191 static QWidget *focus_widget;
192 static QWidget *hidden_focus_widget;
193 static QWidget *active_window;
194#if QT_CONFIG(wheelevent)
195 static int wheel_scroll_lines;
196 static QPointer<QWidget> wheel_widget;
197#endif
198
199 static int enabledAnimations; // Combination of QPlatformTheme::UiEffect
200 static bool widgetCount; // Coupled with -widgetcount switch
201
202 static void setSystemPalette(const QPalette &pal);
203 static void setPalette_helper(const QPalette &palette, const char* className, bool clearWidgetPaletteHash);
204 static void initializeWidgetPaletteHash();
205 static void initializeWidgetFontHash();
206 static void setSystemFont(const QFont &font);
207
208#if 0 // Used to be included in Qt4 for Q_WS_X11
209 static void applyX11SpecificCommandLineArguments(QWidget *main_widget);
210#endif
211
212 static QApplicationPrivate *instance() { return self; }
213
214#ifdef QT_KEYPAD_NAVIGATION
215 static QWidget *oldEditFocus;
216 static Qt::NavigationMode navigationMode;
217#endif
218
219#if 0 /* Used to be included in Qt4 for Q_WS_MAC */ || 0 /* Used to be included in Qt4 for Q_WS_X11 */
220 void _q_alertTimeOut();
221 QHash<QWidget *, QTimer *> alertTimerHash;
222#endif
223#ifndef QT_NO_STYLE_STYLESHEET
224 static QString styleSheet;
225#endif
226 static QPointer<QWidget> leaveAfterRelease;
227 static QWidget *pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos,
228 QEvent::Type type, Qt::MouseButtons buttons,
229 QWidget *buttonDown, QWidget *alienWidget);
230 static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
231 QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
232 bool spontaneous = true, bool onlyDispatchEnterLeave = false);
233 void sendSyntheticEnterLeave(QWidget *widget);
234
235 static QWindow *windowForWidget(const QWidget *widget)
236 {
237 if (QWindow *window = widget->windowHandle())
238 return window;
239 if (const QWidget *nativeParent = widget->nativeParentWidget())
240 return nativeParent->windowHandle();
241 return 0;
242 }
243
244#ifdef Q_OS_WIN
245 static HWND getHWNDForWidget(const QWidget *widget)
246 {
247 if (QWindow *window = windowForWidget(widget))
248 if (window->handle() && QGuiApplication::platformNativeInterface())
249 return static_cast<HWND> (QGuiApplication::platformNativeInterface()->
250 nativeResourceForWindow(QByteArrayLiteral("handle"), window));
251 return 0;
252 }
253#endif
254
255#ifndef QT_NO_GESTURES
256 QGestureManager *gestureManager;
257 QWidget *gestureWidget;
258#endif
259#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ || 0 /* Used to be included in Qt4 for Q_WS_WIN */
260 QPixmap *move_cursor;
261 QPixmap *copy_cursor;
262 QPixmap *link_cursor;
263#endif
264#if 0 // Used to be included in Qt4 for Q_WS_WIN
265 QPixmap *ignore_cursor;
266#endif
267
268 static bool updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent);
269 void initializeMultitouch();
270 void initializeMultitouch_sys();
271 void cleanupMultitouch();
272 void cleanupMultitouch_sys();
273 QWidget *findClosestTouchPointTarget(QTouchDevice *device, const QTouchEvent::TouchPoint &touchPoint);
274 void appendTouchPoint(const QTouchEvent::TouchPoint &touchPoint);
275 void removeTouchPoint(int touchPointId);
276 void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent);
277 static bool translateRawTouchEvent(QWidget *widget,
278 QTouchDevice *device,
279 const QList<QTouchEvent::TouchPoint> &touchPoints,
280 ulong timestamp);
281 static void translateTouchCancel(QTouchDevice *device, ulong timestamp);
282
283 QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override;
284private:
285 static QApplicationPrivate *self;
286 static bool tryCloseAllWidgetWindows(QWindowList *processedWindows);
287
288 static void giveFocusAccordingToFocusPolicy(QWidget *w, QEvent *event, QPoint localPos);
289 static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy);
290
291
292 static bool isAlien(QWidget *);
293};
294
295#if 0 // Used to be included in Qt4 for Q_WS_WIN
296 extern void qt_win_set_cursor(QWidget *, bool);
297#elif 0 // Used to be included in Qt4 for Q_WS_X11
298 extern void qt_x11_enforce_cursor(QWidget *, bool);
299 extern void qt_x11_enforce_cursor(QWidget *);
300#else
301 extern void qt_qpa_set_cursor(QWidget * w, bool force);
302#endif
303
304QT_END_NAMESPACE
305
306#endif // QAPPLICATION_P_H
307