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 = nullptr) const override;
132 static bool isBlockedByModal(QWidget *widget);
133 static bool modalState();
134 static bool tryModalHelper(QWidget *widget, QWidget **rettop = nullptr);
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#ifdef QT_KEYPAD_NAVIGATION
140 static bool keypadNavigationEnabled()
141 {
142 return navigationMode == Qt::NavigationModeKeypadTabOrder ||
143 navigationMode == Qt::NavigationModeKeypadDirectional;
144 }
145#endif
146
147 bool notify_helper(QObject *receiver, QEvent * e);
148
149 void init(
150#if 0 // Used to be included in Qt4 for Q_WS_X11
151 Display *dpy = 0, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0
152#endif
153 );
154 void initialize();
155 void process_cmdline();
156
157#if 0 // Used to be included in Qt4 for Q_WS_X11
158 static void x11_initialize_style();
159#endif
160
161 static bool inPopupMode();
162 bool popupActive() override { return inPopupMode(); }
163 void closePopup(QWidget *popup);
164 void openPopup(QWidget *popup);
165 static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
166 static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next,
167 bool *wrappingOccurred = nullptr);
168
169#if QT_CONFIG(graphicsview)
170 // Maintain a list of all scenes to ensure font and palette propagation to
171 // all scenes.
172 QList<QGraphicsScene *> scene_list;
173#endif
174
175 QBasicTimer toolTipWakeUp, toolTipFallAsleep;
176 QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos;
177 QPointer<QWidget> toolTipWidget;
178
179 static QSize app_strut;
180 static QWidgetList *popupWidgets;
181 static QStyle *app_style;
182 static QPalette *sys_pal;
183 static QPalette *set_pal;
184
185protected:
186 void notifyThemeChanged() override;
187 void sendApplicationPaletteChange(bool toAllWidgets = false,
188 const char *className = nullptr) override;
189
190#if QT_CONFIG(draganddrop)
191 void notifyDragStarted(const QDrag *) override;
192#endif // QT_CONFIG(draganddrop)
193
194public:
195 static QFont *sys_font;
196 static QFont *set_font;
197 static QWidget *main_widget;
198 static QWidget *focus_widget;
199 static QWidget *hidden_focus_widget;
200 static QWidget *active_window;
201#if QT_CONFIG(wheelevent)
202 static int wheel_scroll_lines;
203 static QPointer<QWidget> wheel_widget;
204#endif
205
206 static int enabledAnimations; // Combination of QPlatformTheme::UiEffect
207 static bool widgetCount; // Coupled with -widgetcount switch
208
209 static void setSystemPalette(const QPalette &pal);
210 static void setPalette_helper(const QPalette &palette, const char* className, bool clearWidgetPaletteHash);
211 static void initializeWidgetPaletteHash();
212 static void initializeWidgetFontHash();
213 static void setSystemFont(const QFont &font);
214
215#if 0 // Used to be included in Qt4 for Q_WS_X11
216 static void applyX11SpecificCommandLineArguments(QWidget *main_widget);
217#endif
218
219 static QApplicationPrivate *instance() { return self; }
220
221#ifdef QT_KEYPAD_NAVIGATION
222 static QWidget *oldEditFocus;
223 static Qt::NavigationMode navigationMode;
224#endif
225
226#if 0 /* Used to be included in Qt4 for Q_WS_MAC */ || 0 /* Used to be included in Qt4 for Q_WS_X11 */
227 void _q_alertTimeOut();
228 QHash<QWidget *, QTimer *> alertTimerHash;
229#endif
230#ifndef QT_NO_STYLE_STYLESHEET
231 static QString styleSheet;
232#endif
233 static QPointer<QWidget> leaveAfterRelease;
234 static QWidget *pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos,
235 QEvent::Type type, Qt::MouseButtons buttons,
236 QWidget *buttonDown, QWidget *alienWidget);
237 static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
238 QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
239 bool spontaneous = true, bool onlyDispatchEnterLeave = false);
240 void sendSyntheticEnterLeave(QWidget *widget);
241
242 static QWindow *windowForWidget(const QWidget *widget)
243 {
244 if (QWindow *window = widget->windowHandle())
245 return window;
246 if (const QWidget *nativeParent = widget->nativeParentWidget())
247 return nativeParent->windowHandle();
248 return nullptr;
249 }
250
251#ifdef Q_OS_WIN
252 static HWND getHWNDForWidget(const QWidget *widget)
253 {
254 if (QWindow *window = windowForWidget(widget))
255 if (window->handle() && QGuiApplication::platformNativeInterface())
256 return static_cast<HWND> (QGuiApplication::platformNativeInterface()->
257 nativeResourceForWindow(QByteArrayLiteral("handle"), window));
258 return 0;
259 }
260#endif
261
262#ifndef QT_NO_GESTURES
263 QGestureManager *gestureManager;
264 QWidget *gestureWidget;
265#endif
266#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ || 0 /* Used to be included in Qt4 for Q_WS_WIN */
267 QPixmap *move_cursor;
268 QPixmap *copy_cursor;
269 QPixmap *link_cursor;
270#endif
271#if 0 // Used to be included in Qt4 for Q_WS_WIN
272 QPixmap *ignore_cursor;
273#endif
274
275 static bool updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent);
276 void initializeMultitouch();
277 void initializeMultitouch_sys();
278 void cleanupMultitouch();
279 void cleanupMultitouch_sys();
280 QWidget *findClosestTouchPointTarget(QTouchDevice *device, const QTouchEvent::TouchPoint &touchPoint);
281 void appendTouchPoint(const QTouchEvent::TouchPoint &touchPoint);
282 void removeTouchPoint(int touchPointId);
283 void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent);
284 static bool translateRawTouchEvent(QWidget *widget,
285 QTouchDevice *device,
286 const QList<QTouchEvent::TouchPoint> &touchPoints,
287 ulong timestamp);
288 static void translateTouchCancel(QTouchDevice *device, ulong timestamp);
289
290 QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override;
291private:
292 static QApplicationPrivate *self;
293 static bool tryCloseAllWidgetWindows(QWindowList *processedWindows);
294
295 static void giveFocusAccordingToFocusPolicy(QWidget *w, QEvent *event, QPoint localPos);
296 static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy);
297
298
299 static bool isAlien(QWidget *);
300};
301
302#if 0 // Used to be included in Qt4 for Q_WS_WIN
303 extern void qt_win_set_cursor(QWidget *, bool);
304#elif 0 // Used to be included in Qt4 for Q_WS_X11
305 extern void qt_x11_enforce_cursor(QWidget *, bool);
306 extern void qt_x11_enforce_cursor(QWidget *);
307#else
308 extern void qt_qpa_set_cursor(QWidget * w, bool force);
309#endif
310
311QT_END_NAMESPACE
312
313#endif // QAPPLICATION_P_H
314