source: trunk/src/gui/kernel/qapplication_p.h@ 67

Last change on this file since 67 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 13.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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 "QtGui/qapplication.h"
58#include "QtGui/qfont.h"
59#include "QtGui/qcursor.h"
60#include "QtGui/qregion.h"
61#include "QtCore/qmutex.h"
62#include "QtCore/qtranslator.h"
63#include "QtCore/qbasictimer.h"
64#include "QtCore/qhash.h"
65#include "QtCore/qpointer.h"
66#include "private/qcoreapplication_p.h"
67#include "private/qshortcutmap_p.h"
68#include <private/qthread_p.h>
69#ifdef Q_WS_QWS
70#include "QtGui/qscreen_qws.h"
71#include <private/qgraphicssystem_qws_p.h>
72#endif
73
74QT_BEGIN_NAMESPACE
75
76class QClipboard;
77class QGraphicsScene;
78class QGraphicsSystem;
79class QInputContext;
80class QKeyEvent;
81class QMouseEvent;
82class QObject;
83class QWheelEvent;
84class QWidget;
85
86extern bool qt_is_gui_used;
87#ifndef QT_NO_CLIPBOARD
88extern QClipboard *qt_clipboard;
89#endif
90
91#if defined (Q_OS_WIN32) || defined (Q_OS_CYGWIN) || defined(Q_OS_WINCE)
92extern QSysInfo::WinVersion qt_winver;
93enum { QT_TABLET_NPACKETQSIZE = 128 };
94# ifdef Q_OS_WINCE
95 extern DWORD qt_cever;
96# endif
97#elif defined (Q_OS_MAC)
98extern QSysInfo::MacVersion qt_macver;
99#endif
100#if defined(Q_WS_QWS)
101class QWSManager;
102class QDirectPainter;
103#endif
104
105#ifndef QT_NO_TABLET
106struct QTabletDeviceData
107{
108#ifndef Q_WS_MAC
109 int minPressure;
110 int maxPressure;
111 int minTanPressure;
112 int maxTanPressure;
113 int minX, maxX, minY, maxY, minZ, maxZ;
114 inline QPointF scaleCoord(int coordX, int coordY, int outOriginX, int outExtentX,
115 int outOriginY, int outExtentY) const;
116#endif
117
118#if defined(Q_WS_X11) || (defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA))
119 QPointer<QWidget> widgetToGetPress;
120#endif
121
122#ifdef Q_WS_X11
123 int deviceType;
124 enum {
125 TOTAL_XINPUT_EVENTS = 64
126 };
127 void *device;
128 int eventCount;
129 long unsigned int eventList[TOTAL_XINPUT_EVENTS]; // XEventClass is in fact a long unsigned int
130
131 int xinput_motion;
132 int xinput_key_press;
133 int xinput_key_release;
134 int xinput_button_press;
135 int xinput_button_release;
136 int xinput_proximity_in;
137 int xinput_proximity_out;
138#elif defined(Q_WS_WIN)
139 qint64 llId;
140 int currentDevice;
141 int currentPointerType;
142#elif defined(Q_WS_MAC)
143 quint64 tabletUniqueID;
144 int tabletDeviceType;
145 int tabletPointerType;
146 int capabilityMask;
147#endif
148};
149
150static inline int sign(int x)
151{
152 return x >= 0 ? 1 : -1;
153}
154
155#ifndef Q_WS_MAC
156inline QPointF QTabletDeviceData::scaleCoord(int coordX, int coordY,
157 int outOriginX, int outExtentX,
158 int outOriginY, int outExtentY) const
159{
160 QPointF ret;
161 if (sign(outExtentX) == sign(maxX))
162 ret.setX(((coordX - minX) * qAbs(outExtentX) / qAbs(qreal(maxX))) + outOriginX);
163 else
164 ret.setX(((qAbs(maxX) - (coordX - minX)) * qAbs(outExtentX) / qAbs(qreal(maxX)))
165 + outOriginX);
166
167 if (sign(outExtentY) == sign(maxY))
168 ret.setY(((coordY - minY) * qAbs(outExtentY) / qAbs(qreal(maxY))) + outOriginY);
169 else
170 ret.setY(((qAbs(maxY) - (coordY - minY)) * qAbs(outExtentY) / qAbs(qreal(maxY)))
171 + outOriginY);
172 return ret;
173}
174#endif
175
176typedef QList<QTabletDeviceData> QTabletDeviceDataList;
177QTabletDeviceDataList *qt_tablet_devices();
178# if defined(Q_WS_MAC)
179typedef QHash<int, QTabletDeviceData> QMacTabletHash;
180QMacTabletHash *qt_mac_tablet_hash();
181# endif
182#endif
183
184#ifdef QT3_SUPPORT
185extern "C" {
186 typedef bool (*Ptrqt_tryAccelEvent)(QWidget *w, QKeyEvent *e);
187 typedef bool (*Ptrqt_tryComposeUnicode)(QWidget *w, QKeyEvent *e);
188 typedef bool (*Ptrqt_dispatchAccelEvent)(QWidget *w, QKeyEvent *e);
189}
190#endif
191
192class QScopedLoopLevelCounter
193{
194 QThreadData *threadData;
195public:
196 QScopedLoopLevelCounter(QThreadData *threadData)
197 : threadData(threadData)
198 { ++threadData->loopLevel; }
199 ~QScopedLoopLevelCounter()
200 { --threadData->loopLevel; }
201};
202
203class Q_GUI_EXPORT QApplicationPrivate : public QCoreApplicationPrivate
204{
205 Q_DECLARE_PUBLIC(QApplication)
206public:
207 QApplicationPrivate(int &argc, char **argv, QApplication::Type type);
208 ~QApplicationPrivate();
209
210#if defined(Q_WS_X11)
211#ifndef QT_NO_SETTINGS
212 static QString kdeHome();
213 static bool x11_apply_settings();
214#endif
215 static void reset_instance_pointer();
216#elif defined(Q_WS_QWS)
217 static bool qws_apply_settings();
218 static QWidget *findWidget(const QObjectList&, const QPoint &, bool rec);
219#endif
220 static bool quitOnLastWindowClosed;
221 static void emitLastWindowClosed();
222#ifdef Q_OS_WINCE
223 static int autoMaximizeThreshold;
224 static bool autoSipEnabled;
225#endif
226
227 static QGraphicsSystem *graphicsSystem()
228#if !defined(Q_WS_QWS)
229 { return graphics_system; }
230#else
231 { return QScreen::instance()->graphicsSystem(); }
232#endif
233
234 void createEventDispatcher();
235 QString appName() const;
236
237 static void dispatchEnterLeave(QWidget *enter, QWidget *leave);
238
239 //modality
240 static void enterModal(QWidget*);
241 static void leaveModal(QWidget*);
242 static void enterModal_sys(QWidget*);
243 static void leaveModal_sys(QWidget*);
244 static bool isBlockedByModal(QWidget *widget);
245 static bool modalState();
246 static bool tryModalHelper(QWidget *widget, QWidget **rettop = 0);
247#ifdef Q_WS_MAC
248 static QWidget *tryModalHelper_sys(QWidget *top);
249 bool canQuit();
250#endif
251
252 bool notify_helper(QObject *receiver, QEvent * e);
253
254 void construct(
255#ifdef Q_WS_X11
256 Display *dpy = 0, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0
257#endif
258 );
259 void initialize();
260 void process_cmdline();
261
262#if defined(Q_WS_X11)
263 static void x11_initialize_style();
264#endif
265
266 enum KeyPlatform {
267 KB_Win = 1,
268 KB_Mac = 2,
269 KB_X11 = 4,
270 KB_KDE = 8,
271 KB_Gnome = 16,
272 KB_CDE = 32,
273 KB_All = 0xffff
274 };
275
276 static uint currentPlatform();
277 bool inPopupMode() const;
278 void closePopup(QWidget *popup);
279 void openPopup(QWidget *popup);
280 static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
281 static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next);
282
283#ifndef QT_NO_SESSIONMANAGER
284 QSessionManager *session_manager;
285 QString session_id;
286 QString session_key;
287 bool is_session_restored;
288#endif
289
290#ifndef QT_NO_CURSOR
291 QList<QCursor> cursor_list;
292#endif
293#ifndef QT_NO_GRAPHICSVIEW
294 // Maintain a list of all scenes to ensure font and palette propagation to
295 // all scenes.
296 QList<QGraphicsScene *> scene_list;
297#endif
298
299 QBasicTimer toolTipWakeUp, toolTipFallAsleep;
300 QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos;
301 QPointer<QWidget> toolTipWidget;
302#ifndef QT_NO_SHORTCUT
303 QShortcutMap shortcutMap;
304#endif
305
306#ifdef QT3_SUPPORT
307 bool qt_compat_used;
308 bool qt_compat_resolved;
309 Ptrqt_tryAccelEvent qt_tryAccelEvent;
310 Ptrqt_tryComposeUnicode qt_tryComposeUnicode;
311 Ptrqt_dispatchAccelEvent qt_dispatchAccelEvent;
312
313 bool use_compat() {
314 return qt_tryAccelEvent
315 && qt_tryComposeUnicode
316 && qt_dispatchAccelEvent;
317 }
318#endif
319 static QInputContext *inputContext;
320
321 static Qt::MouseButtons mouse_buttons;
322 static Qt::KeyboardModifiers modifier_buttons;
323
324 static QSize app_strut;
325 static QWidgetList *popupWidgets;
326 static QStyle *app_style;
327 static int app_cspec;
328 static QPalette *app_pal;
329 static QPalette *sys_pal;
330 static QPalette *set_pal;
331 static QGraphicsSystem *graphics_system;
332 static QString graphics_system_name;
333
334private:
335 static QFont *app_font; // private for a reason! Always use QApplication::font() instead!
336public:
337 static QFont *sys_font;
338 static QFont *set_font;
339 static QWidget *main_widget;
340 static QWidget *focus_widget;
341 static QWidget *hidden_focus_widget;
342 static QWidget *active_window;
343 static QIcon *app_icon;
344 static bool obey_desktop_settings;
345 static int cursor_flash_time;
346 static int mouse_double_click_time;
347 static int keyboard_input_time;
348 static int wheel_scroll_lines;
349
350 static bool animate_ui;
351 static bool animate_menu;
352 static bool animate_tooltip;
353 static bool animate_combo;
354 static bool fade_menu;
355 static bool fade_tooltip;
356 static bool animate_toolbox;
357 static bool widgetCount; // Coupled with -widgetcount switch
358#ifdef Q_WS_MAC
359 static bool native_modal_dialog_active;
360#endif
361#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
362 static bool inSizeMove;
363#endif
364
365 static void setSystemPalette(const QPalette &pal);
366 static void setPalette_helper(const QPalette &palette, const char* className, bool clearWidgetPaletteHash);
367 static void initializeWidgetPaletteHash();
368 static void setSystemFont(const QFont &font);
369
370#if defined(Q_WS_X11)
371 static void applyX11SpecificCommandLineArguments(QWidget *main_widget);
372#elif defined(Q_WS_QWS)
373 static void applyQWSSpecificCommandLineArguments(QWidget *main_widget);
374#endif
375
376#ifdef Q_WS_MAC
377 static OSStatus globalEventProcessor(EventHandlerCallRef, EventRef, void *);
378 static OSStatus globalAppleEventProcessor(const AppleEvent *, AppleEvent *, long);
379 static OSStatus tabletProximityCallback(EventHandlerCallRef, EventRef, void *);
380 static bool qt_mac_apply_settings();
381#endif
382
383#ifdef Q_WS_QWS
384 QPointer<QWSManager> last_manager;
385# ifndef QT_NO_DIRECTPAINTER
386 QMap<WId, QDirectPainter *> *directPainters;
387# endif
388 QRect maxWindowRect(const QScreen *screen) const { return maxWindowRects[screen]; }
389 void setMaxWindowRect(const QScreen *screen, int screenNo, const QRect &rect);
390 void setScreenTransformation(QScreen *screen, int screenNo, int transformation);
391#endif
392
393 static QApplicationPrivate *instance() { return self; }
394
395 static QString *styleOverride;
396
397 static int app_compile_version;
398
399#ifdef QT_KEYPAD_NAVIGATION
400 static bool keypadNavigation;
401 static QWidget *oldEditFocus;
402#endif
403
404#if defined(Q_WS_MAC) || defined(Q_WS_X11)
405 void _q_alertTimeOut();
406 QHash<QWidget *, QTimer *> alertTimerHash;
407#endif
408#if defined(QT_MAC_USE_COCOA)
409 void _q_runAppModalWindow();
410#endif
411#if defined(QT_MAC_USE_COCOA)
412 void _q_runModalWindow();
413#endif
414#ifndef QT_NO_STYLE_STYLESHEET
415 static QString styleSheet;
416#endif
417 static QPointer<QWidget> leaveAfterRelease;
418 static QWidget *pickMouseReceiver(QWidget *candidate, const QPoint &globalPos, QPoint &pos,
419 QEvent::Type type, Qt::MouseButtons buttons,
420 QWidget *buttonDown, QWidget *alienWidget);
421 static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
422 QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver);
423#if defined(Q_WS_WIN) || defined(Q_WS_X11)
424 void sendSyntheticEnterLeave(QWidget *widget);
425#endif
426
427private:
428#ifdef Q_WS_QWS
429 QMap<const QScreen*, QRect> maxWindowRects;
430#endif
431
432 static QApplicationPrivate *self;
433 static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy);
434};
435
436QT_END_NAMESPACE
437
438#endif // QAPPLICATION_P_H
Note: See TracBrowser for help on using the repository browser.