1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QAPPLICATION_P_H
43 #define QAPPLICATION_P_H
49 // This file is not part of the Qt API. It exists for the convenience
50 // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
51 // and many other. This header file may change from version to version
52 // without notice, or even be removed.
57 #include "QtWidgets/qapplication.h"
58 #include "QtGui/qevent.h"
59 #include "QtGui/qfont.h"
60 #include "QtGui/qcursor.h"
61 #include "QtGui/qregion.h"
62 #include "QtGui/qwindow.h"
64 #include <qpa/qplatformnativeinterface.h>
65 #include "QtCore/qmutex.h"
66 #include "QtCore/qtranslator.h"
67 #include "QtCore/qbasictimer.h"
68 #include "QtCore/qhash.h"
69 #include "QtCore/qpointer.h"
70 #include "private/qcoreapplication_p.h"
71 #include "QtCore/qpoint.h"
73 #include <QtGui/qwindowsysteminterface.h>
74 #include <private/qwindowsysteminterface_p.h>
75 #include <qpa/qplatformintegration.h>
76 #include "private/qguiapplication_p.h"
84 class QSocketNotifier;
86 #ifndef QT_NO_GESTURES
87 class QGestureManager;
90 extern Q_GUI_EXPORT bool qt_is_gui_used;
91 #ifndef QT_NO_CLIPBOARD
92 extern QClipboard *qt_clipboard;
95 #if defined (Q_OS_WIN32) || defined (Q_OS_CYGWIN) || defined(Q_OS_WINCE)
96 extern QSysInfo::WinVersion qt_winver;
98 extern DWORD qt_cever;
100 #elif defined (Q_OS_MAC)
101 extern QSysInfo::MacVersion qt_macver;
104 typedef QHash<QByteArray, QFont> FontHash;
105 FontHash *qt_app_fonts_hash();
107 typedef QHash<QByteArray, QPalette> PaletteHash;
108 PaletteHash *qt_app_palettes_hash();
110 #define QApplicationPrivateBase QGuiApplicationPrivate
112 class Q_WIDGETS_EXPORT QApplicationPrivate : public QApplicationPrivateBase
114 Q_DECLARE_PUBLIC(QApplication)
116 QApplicationPrivate(int &argc, char **argv, QApplication::Type type, int flags);
117 ~QApplicationPrivate();
119 virtual void notifyLayoutDirectionChange();
120 virtual void notifyActiveWindowChange(QWindow *);
122 virtual bool shouldQuit();
124 #if defined(Q_WS_X11)
125 #ifndef QT_NO_SETTINGS
126 static bool x11_apply_settings();
128 static void reset_instance_pointer();
131 static int autoMaximizeThreshold;
133 static bool autoSipEnabled;
134 static QString desktopStyleKey();
137 void createEventDispatcher();
138 static void dispatchEnterLeave(QWidget *enter, QWidget *leave);
141 bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = 0) const Q_DECL_OVERRIDE;
142 static bool isBlockedByModal(QWidget *widget);
143 static bool modalState();
144 static bool tryModalHelper(QWidget *widget, QWidget **rettop = 0);
146 static QWidget *tryModalHelper_sys(QWidget *top);
150 bool notify_helper(QObject *receiver, QEvent * e);
154 Display *dpy = 0, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0
158 void process_cmdline();
160 #if defined(Q_WS_X11)
161 static void x11_initialize_style();
164 static bool inPopupMode();
165 void closePopup(QWidget *popup);
166 void openPopup(QWidget *popup);
167 static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
168 static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next);
169 void handleAutomaticMouseGrab(QWidget *widget, QMouseEvent *e);
171 #ifndef QT_NO_SESSIONMANAGER
172 QSessionManager *session_manager;
175 bool is_session_restored;
178 #ifndef QT_NO_GRAPHICSVIEW
179 // Maintain a list of all scenes to ensure font and palette propagation to
181 QList<QGraphicsScene *> scene_list;
184 QBasicTimer toolTipWakeUp, toolTipFallAsleep;
185 QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos;
186 QPointer<QWidget> toolTipWidget;
188 static QSize app_strut;
189 static QWidgetList *popupWidgets;
190 static QStyle *app_style;
191 static int app_cspec;
192 static QPalette *sys_pal;
193 static QPalette *set_pal;
196 void notifyThemeChanged();
197 #ifndef QT_NO_DRAGANDDROP
198 void notifyDragStarted(const QDrag *);
199 #endif // QT_NO_DRAGANDDROP
202 static QFont *sys_font;
203 static QFont *set_font;
204 static QWidget *main_widget;
205 static QWidget *focus_widget;
206 static QWidget *hidden_focus_widget;
207 static QWidget *active_window;
208 static QIcon *app_icon;
209 #ifndef QT_NO_WHEELEVENT
210 static int wheel_scroll_lines;
213 static int enabledAnimations; // Combination of QPlatformTheme::UiEffect
214 static bool widgetCount; // Coupled with -widgetcount switch
215 static bool load_testability; // Coupled with -testability switch
217 static void setSystemPalette(const QPalette &pal);
218 static void setPalette_helper(const QPalette &palette, const char* className, bool clearWidgetPaletteHash);
219 static void initializeWidgetPaletteHash();
220 static void initializeWidgetFontHash();
221 static void setSystemFont(const QFont &font);
223 #if defined(Q_WS_X11)
224 static void applyX11SpecificCommandLineArguments(QWidget *main_widget);
227 static QApplicationPrivate *instance() { return self; }
229 static QString styleOverride;
231 #ifdef QT_KEYPAD_NAVIGATION
232 static QWidget *oldEditFocus;
233 static Qt::NavigationMode navigationMode;
236 #if defined(Q_WS_MAC) || defined(Q_WS_X11)
237 void _q_alertTimeOut();
238 QHash<QWidget *, QTimer *> alertTimerHash;
240 #ifndef QT_NO_STYLE_STYLESHEET
241 static QString styleSheet;
243 static QPointer<QWidget> leaveAfterRelease;
244 static QWidget *pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos,
245 QEvent::Type type, Qt::MouseButtons buttons,
246 QWidget *buttonDown, QWidget *alienWidget);
247 static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
248 QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
249 bool spontaneous = true);
250 void sendSyntheticEnterLeave(QWidget *widget);
252 static QWindow *windowForWidget(const QWidget *widget)
254 if (QWindow *window = widget->windowHandle())
256 if (const QWidget *nativeParent = widget->nativeParentWidget())
257 return nativeParent->windowHandle();
262 static HWND getHWNDForWidget(const QWidget *widget)
264 if (QWindow *window = windowForWidget(widget))
265 if (window->handle())
266 return static_cast<HWND> (QGuiApplication::platformNativeInterface()->
267 nativeResourceForWindow(QByteArrayLiteral("handle"), window));
272 #ifndef QT_NO_GESTURES
273 QGestureManager *gestureManager;
274 QWidget *gestureWidget;
276 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
277 QPixmap *move_cursor;
278 QPixmap *copy_cursor;
279 QPixmap *link_cursor;
281 #if defined(Q_WS_WIN)
282 QPixmap *ignore_cursor;
285 static void updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent);
286 void initializeMultitouch();
287 void initializeMultitouch_sys();
288 void cleanupMultitouch();
289 void cleanupMultitouch_sys();
290 QWidget *findClosestTouchPointTarget(QTouchDevice *device, const QPointF &screenPos);
291 void appendTouchPoint(const QTouchEvent::TouchPoint &touchPoint);
292 void removeTouchPoint(int touchPointId);
293 bool translateTouchToMouse(QWidget *widget, QTouchEvent *event);
294 static void translateRawTouchEvent(QWidget *widget,
295 QTouchDevice *device,
296 const QList<QTouchEvent::TouchPoint> &touchPoints,
298 static void translateTouchCancel(QTouchDevice *device, ulong timestamp);
300 QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const;
302 static QApplicationPrivate *self;
304 static void giveFocusAccordingToFocusPolicy(QWidget *w,
305 Qt::FocusPolicy focusPolicy,
306 Qt::FocusReason focusReason);
307 static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy);
310 static bool isAlien(QWidget *);
313 #if defined(Q_WS_WIN)
314 extern void qt_win_set_cursor(QWidget *, bool);
315 #elif defined(Q_WS_X11)
316 extern void qt_x11_enforce_cursor(QWidget *, bool);
317 extern void qt_x11_enforce_cursor(QWidget *);
319 extern void qt_qpa_set_cursor(QWidget * w, bool force);
324 #endif // QAPPLICATION_P_H