e53896f82c3375fe5a6352faccabc9b40dfcd0c2
[profile/ivi/qtbase.git] / src / widgets / kernel / qapplication_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QAPPLICATION_P_H
43 #define QAPPLICATION_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
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.
53 //
54 // We mean it.
55 //
56
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"
63 #include "qwidget.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"
72 #include <QTime>
73 #include <QtGui/qwindowsysteminterface.h>
74 #include <private/qwindowsysteminterface_p.h>
75 #include <qpa/qplatformintegration.h>
76 #include "private/qguiapplication_p.h"
77
78 QT_BEGIN_NAMESPACE
79
80 class QClipboard;
81 class QGraphicsScene;
82 class QObject;
83 class QWidget;
84 class QSocketNotifier;
85 class QTouchDevice;
86 #ifndef QT_NO_GESTURES
87 class QGestureManager;
88 #endif
89
90 extern Q_GUI_EXPORT bool qt_is_gui_used;
91 #ifndef QT_NO_CLIPBOARD
92 extern QClipboard *qt_clipboard;
93 #endif
94
95 #if defined (Q_OS_WIN32) || defined (Q_OS_CYGWIN) || defined(Q_OS_WINCE)
96 extern QSysInfo::WinVersion qt_winver;
97 # ifdef Q_OS_WINCE
98   extern DWORD qt_cever;
99 # endif
100 #elif defined (Q_OS_MAC)
101 extern QSysInfo::MacVersion qt_macver;
102 #endif
103
104 typedef QHash<QByteArray, QFont> FontHash;
105 FontHash *qt_app_fonts_hash();
106
107 typedef QHash<QByteArray, QPalette> PaletteHash;
108 PaletteHash *qt_app_palettes_hash();
109
110 #define QApplicationPrivateBase QGuiApplicationPrivate
111
112 class Q_WIDGETS_EXPORT QApplicationPrivate : public QApplicationPrivateBase
113 {
114     Q_DECLARE_PUBLIC(QApplication)
115 public:
116     QApplicationPrivate(int &argc, char **argv, QApplication::Type type, int flags);
117     ~QApplicationPrivate();
118
119     virtual void notifyLayoutDirectionChange();
120     virtual void notifyActiveWindowChange(QWindow *);
121
122     virtual bool shouldQuit();
123
124 #if defined(Q_WS_X11)
125 #ifndef QT_NO_SETTINGS
126     static bool x11_apply_settings();
127 #endif
128     static void reset_instance_pointer();
129 #endif
130 #ifdef Q_OS_WINCE
131     static int autoMaximizeThreshold;
132 #endif
133     static bool autoSipEnabled;
134     static QString desktopStyleKey();
135
136
137     void createEventDispatcher();
138     static void dispatchEnterLeave(QWidget *enter, QWidget *leave);
139
140     //modality
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);
145 #ifdef Q_WS_MAC
146     static QWidget *tryModalHelper_sys(QWidget *top);
147         bool canQuit();
148 #endif
149
150     bool notify_helper(QObject *receiver, QEvent * e);
151
152     void construct(
153 #ifdef Q_WS_X11
154                    Display *dpy = 0, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0
155 #endif
156                    );
157     void initialize();
158     void process_cmdline();
159
160 #if defined(Q_WS_X11)
161     static void x11_initialize_style();
162 #endif
163
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);
170
171 #ifndef QT_NO_SESSIONMANAGER
172     QSessionManager *session_manager;
173     QString session_id;
174     QString session_key;
175     bool is_session_restored;
176 #endif
177
178 #ifndef QT_NO_GRAPHICSVIEW
179     // Maintain a list of all scenes to ensure font and palette propagation to
180     // all scenes.
181     QList<QGraphicsScene *> scene_list;
182 #endif
183
184     QBasicTimer toolTipWakeUp, toolTipFallAsleep;
185     QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos;
186     QPointer<QWidget> toolTipWidget;
187
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;
194
195 protected:
196     void notifyThemeChanged();
197 #ifndef QT_NO_DRAGANDDROP
198     void notifyDragStarted(const QDrag *);
199 #endif // QT_NO_DRAGANDDROP
200
201 public:
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;
211 #endif
212
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
216
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);
222
223 #if defined(Q_WS_X11)
224     static void applyX11SpecificCommandLineArguments(QWidget *main_widget);
225 #endif
226
227     static QApplicationPrivate *instance() { return self; }
228
229     static QString styleOverride;
230
231 #ifdef QT_KEYPAD_NAVIGATION
232     static QWidget *oldEditFocus;
233     static Qt::NavigationMode navigationMode;
234 #endif
235
236 #if defined(Q_WS_MAC) || defined(Q_WS_X11)
237     void _q_alertTimeOut();
238     QHash<QWidget *, QTimer *> alertTimerHash;
239 #endif
240 #ifndef QT_NO_STYLE_STYLESHEET
241     static QString styleSheet;
242 #endif
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);
251
252     static QWindow *windowForWidget(const QWidget *widget)
253     {
254         if (QWindow *window = widget->windowHandle())
255             return window;
256         if (const QWidget *nativeParent = widget->nativeParentWidget())
257             return nativeParent->windowHandle();
258         return 0;
259     }
260
261 #ifdef Q_OS_WIN
262     static HWND getHWNDForWidget(const QWidget *widget)
263     {
264         if (QWindow *window = windowForWidget(widget))
265             if (window->handle())
266                 return static_cast<HWND> (QGuiApplication::platformNativeInterface()->
267                                           nativeResourceForWindow(QByteArrayLiteral("handle"), window));
268         return 0;
269     }
270 #endif
271
272 #ifndef QT_NO_GESTURES
273     QGestureManager *gestureManager;
274     QWidget *gestureWidget;
275 #endif
276 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
277     QPixmap *move_cursor;
278     QPixmap *copy_cursor;
279     QPixmap *link_cursor;
280 #endif
281 #if defined(Q_WS_WIN)
282     QPixmap *ignore_cursor;
283 #endif
284
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,
297                                        ulong timestamp);
298     static void translateTouchCancel(QTouchDevice *device, ulong timestamp);
299
300     QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const;
301 private:
302     static QApplicationPrivate *self;
303
304     static void giveFocusAccordingToFocusPolicy(QWidget *w,
305                                                 Qt::FocusPolicy focusPolicy,
306                                                 Qt::FocusReason focusReason);
307     static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy);
308
309
310     static bool isAlien(QWidget *);
311 };
312
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 *);
318 #else
319   extern void qt_qpa_set_cursor(QWidget * w, bool force);
320 #endif
321
322 QT_END_NAMESPACE
323
324 #endif // QAPPLICATION_P_H