source: trunk/include/qapplication.h@ 7

Last change on this file since 7 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 15.5 KB
Line 
1/****************************************************************************
2** $Id: qapplication.h 2 2005-11-16 15:49:26Z dmik $
3**
4** Definition of QApplication class
5**
6** Created : 931107
7**
8** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
9**
10** This file is part of the kernel module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QAPPLICATION_H
39#define QAPPLICATION_H
40
41#ifndef QT_H
42#include "qdesktopwidget.h"
43#include "qasciidict.h"
44#include "qpalette.h"
45#include "qtranslator.h"
46#include "qstrlist.h"
47#include "qstringlist.h"
48#endif // QT_H
49
50class QSessionManager;
51class QStyle;
52class QTranslator;
53class QEventLoop;
54#if defined(Q_WS_QWS)
55class QWSDecoration;
56#endif
57
58#ifdef QT_THREAD_SUPPORT
59class QMutex;
60#endif // QT_THREAD_SUPPORT
61
62
63class QApplication;
64extern Q_EXPORT QApplication *qApp; // global application object
65
66
67class Q_EXPORT QApplication : public QObject
68{
69 Q_OBJECT
70public:
71 QApplication( int &argc, char **argv );
72 QApplication( int &argc, char **argv, bool GUIenabled );
73 enum Type { Tty, GuiClient, GuiServer };
74 QApplication( int &argc, char **argv, Type );
75#if defined(Q_WS_X11)
76 QApplication( Display* dpy, HANDLE visual = 0, HANDLE cmap = 0 );
77 QApplication( Display *dpy, int argc, char **argv,
78 HANDLE visual = 0, HANDLE cmap= 0 );
79#endif
80 virtual ~QApplication();
81
82 int argc() const;
83 char **argv() const;
84
85 Type type() const;
86
87#ifndef QT_NO_STYLE
88 static QStyle &style();
89 static void setStyle( QStyle* );
90 static QStyle* setStyle( const QString& );
91#endif
92#ifndef Q_QDOC
93 enum ColorMode { NormalColors, CustomColors };
94 static ColorMode colorMode();
95 static void setColorMode( QApplication::ColorMode );
96#endif
97
98 enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
99 static int colorSpec();
100 static void setColorSpec( int );
101#ifndef QT_NO_CURSOR
102 static QCursor *overrideCursor();
103 static void setOverrideCursor( const QCursor &, bool replace=FALSE );
104 static void restoreOverrideCursor();
105#endif
106 static bool hasGlobalMouseTracking();
107 static void setGlobalMouseTracking( bool enable );
108#ifndef QT_NO_PALETTE
109 static QPalette palette( const QWidget* = 0 );
110 static void setPalette( const QPalette &, bool informWidgets=FALSE,
111 const char* className = 0 );
112#endif
113 static QFont font( const QWidget* = 0 );
114 static void setFont( const QFont &, bool informWidgets=FALSE,
115 const char* className = 0 );
116 static QFontMetrics fontMetrics();
117
118 QWidget *mainWidget() const;
119 virtual void setMainWidget( QWidget * );
120 virtual void polish( QWidget * );
121
122 static QWidgetList *allWidgets();
123 static QWidgetList *topLevelWidgets();
124
125 static QDesktopWidget *desktop();
126
127 static QWidget *activePopupWidget();
128 static QWidget *activeModalWidget();
129#ifndef QT_NO_CLIPBOARD
130 static QClipboard *clipboard();
131#endif
132 QWidget *focusWidget() const;
133 QWidget *activeWindow() const;
134
135 static QWidget *widgetAt( int x, int y, bool child=FALSE );
136 static QWidget *widgetAt( const QPoint &, bool child=FALSE );
137
138 static QEventLoop *eventLoop();
139
140 int exec();
141 void processEvents();
142 void processEvents( int maxtime );
143 void processOneEvent();
144 bool hasPendingEvents();
145 int enter_loop();
146 void exit_loop();
147 int loopLevel() const;
148 static void exit( int retcode=0 );
149
150 static bool sendEvent( QObject *receiver, QEvent *event );
151 static void postEvent( QObject *receiver, QEvent *event );
152 static void sendPostedEvents( QObject *receiver, int event_type );
153 static void sendPostedEvents();
154
155 static void removePostedEvents( QObject *receiver );
156
157 virtual bool notify( QObject *, QEvent * );
158
159 static bool startingUp();
160 static bool closingDown();
161
162 static void flushX();
163 static void flush();
164 static void syncX();
165
166 static void beep();
167
168#ifndef QT_NO_TRANSLATION
169# ifndef QT_NO_TEXTCODEC
170 void setDefaultCodec( QTextCodec * );
171 QTextCodec* defaultCodec() const;
172# endif
173 void installTranslator( QTranslator * );
174 void removeTranslator( QTranslator * );
175#endif
176 enum Encoding { DefaultCodec, UnicodeUTF8 };
177 QString translate( const char * context,
178 const char * key,
179 const char * comment = 0,
180 Encoding encoding = DefaultCodec ) const;
181#ifndef QT_NO_DIR
182 QString applicationDirPath();
183 QString applicationFilePath();
184#endif
185#ifndef QT_NO_PALETTE
186 // obsolete functions
187 static void setWinStyleHighlightColor( const QColor &c ) {
188 QPalette p( palette() );
189 p.setColor( QColorGroup::Highlight, c );
190 setPalette( p, TRUE);
191 }
192 static const QColor &winStyleHighlightColor() {
193 return palette().active().highlight();
194 }
195#endif
196 static void setDesktopSettingsAware( bool );
197 static bool desktopSettingsAware();
198
199 static void setCursorFlashTime( int );
200 static int cursorFlashTime();
201
202 static void setDoubleClickInterval( int );
203 static int doubleClickInterval();
204#ifndef QT_NO_WHEELEVENT
205 static void setWheelScrollLines( int );
206 static int wheelScrollLines();
207#endif
208 static void setGlobalStrut( const QSize & );
209 static QSize globalStrut();
210
211#ifndef QT_NO_COMPONENT
212 static void setLibraryPaths( const QStringList & );
213 static QStringList libraryPaths();
214 static void addLibraryPath( const QString & );
215 static void removeLibraryPath( const QString & );
216#endif // QT_NO_COMPONENT
217 static void setStartDragTime( int ms );
218 static int startDragTime();
219 static void setStartDragDistance( int l );
220 static int startDragDistance();
221
222 static void setReverseLayout( bool b );
223 static bool reverseLayout();
224
225 static int horizontalAlignment( int align );
226
227 static bool isEffectEnabled( Qt::UIEffect );
228 static void setEffectEnabled( Qt::UIEffect, bool enable = TRUE );
229
230#if defined(Q_WS_MAC)
231 virtual bool macEventFilter( EventHandlerCallRef, EventRef );
232#endif
233#if defined(Q_WS_WIN)
234 virtual bool winEventFilter( MSG * );
235#endif
236#if defined(Q_WS_X11)
237 virtual bool x11EventFilter( XEvent * );
238 virtual int x11ClientMessage( QWidget*, XEvent*, bool passive_only);
239 int x11ProcessEvent( XEvent* );
240#endif
241#if defined(Q_WS_QWS)
242 virtual bool qwsEventFilter( QWSEvent * );
243 int qwsProcessEvent( QWSEvent* );
244 void qwsSetCustomColors( QRgb *colortable, int start, int numColors );
245#ifndef QT_NO_QWS_MANAGER
246 static QWSDecoration &qwsDecoration();
247 static void qwsSetDecoration( QWSDecoration *);
248#endif
249#endif
250
251#if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)
252 static WindowsVersion winVersion();
253#elif defined(Q_OS_MAC)
254 static MacintoshVersion macVersion();
255#endif
256#if defined(Q_WS_WIN)
257 void winFocus( QWidget *, bool );
258 static void winMouseButtonUp();
259#endif
260
261#ifndef QT_NO_SESSIONMANAGER
262 // session management
263 bool isSessionRestored() const;
264 QString sessionId() const;
265 QString sessionKey() const;
266 virtual void commitData( QSessionManager& sm );
267 virtual void saveState( QSessionManager& sm );
268#endif
269#if defined(Q_WS_X11)
270 static void create_xim();
271 static void close_xim();
272 static bool x11_apply_settings();
273#endif
274 void wakeUpGuiThread();
275#if defined(QT_THREAD_SUPPORT)
276 void lock();
277 void unlock(bool wakeUpGui = TRUE);
278 bool locked();
279 bool tryLock();
280#endif
281
282signals:
283 void lastWindowClosed();
284 void aboutToQuit();
285 void guiThreadAwake();
286
287public slots:
288 void quit();
289 void closeAllWindows();
290 void aboutQt();
291
292#if defined(Q_WS_QWS)
293protected:
294 void setArgs(int, char **);
295#endif
296
297protected:
298 bool event(QEvent *);
299
300private:
301 void construct( int &argc, char **argv, Type );
302 void initialize( int, char ** );
303 void init_precmdline();
304 void process_cmdline( int* argcptr, char ** argv );
305 bool internalNotify( QObject *, QEvent * );
306#if defined(Q_WS_QWS)
307 static QWidget *findChildWidget( const QWidget *p, const QPoint &pos );
308 static QWidget *findWidget( const QObjectList&, const QPoint &, bool rec );
309#endif
310
311#if defined(Q_WS_MAC)
312 bool do_mouse_down(Point *, bool *);
313 static QMAC_PASCAL OSStatus globalEventProcessor(EventHandlerCallRef, EventRef, void *);
314 static QMAC_PASCAL OSStatus globalAppleEventProcessor(const AppleEvent *, AppleEvent *, long);
315 static QMAC_PASCAL void qt_context_timer_callbk(EventLoopTimerRef, void *);
316 static QMAC_PASCAL void qt_select_timer_callbk(EventLoopTimerRef, void *);
317 static bool qt_mac_apply_settings();
318 friend class QMacInputMethod;
319 friend QMAC_PASCAL OSStatus qt_window_event(EventHandlerCallRef, EventRef, void *);
320 friend void qt_mac_update_os_settings();
321 friend bool qt_set_socket_handler( int, int, QObject *, bool);
322 friend void qt_mac_destroy_widget(QWidget *);
323 friend void qt_init(int *, char **, QApplication::Type);
324#endif
325
326#ifdef QT_THREAD_SUPPORT
327 static QMutex *qt_mutex;
328#endif // QT_THREAD_SUPPORT
329
330 int app_argc;
331 char **app_argv;
332 bool quit_now;
333 int quit_code;
334 static QStyle *app_style;
335 static int app_cspec;
336#ifndef QT_NO_PALETTE
337 static QPalette *app_pal;
338#endif
339 static QFont *app_font;
340#ifndef QT_NO_CURSOR
341 static QCursor *app_cursor;
342#endif
343 static QEventLoop* eventloop;
344 static int app_tracking;
345 static bool is_app_running;
346 static bool is_app_closing;
347 static bool app_exit_loop;
348 static int loop_level;
349 static QWidget *main_widget;
350 static QWidget *focus_widget;
351 static QWidget *active_window;
352 static bool obey_desktop_settings;
353 static int cursor_flash_time;
354 static int mouse_double_click_time;
355 static int wheel_scroll_lines;
356 static int composedUnicode; // Value, meta-composed character
357
358 static bool animate_ui;
359 static bool animate_menu;
360 static bool animate_tooltip;
361 static bool animate_combo;
362 static bool fade_menu;
363 static bool fade_tooltip;
364 static bool animate_toolbox;
365 static bool widgetCount; // Coupled with -widgetcount switch
366 static bool metaComposeUnicode;
367
368 QValueList<QTranslator*> *translators;
369#ifndef QT_NO_SESSIONMANAGER
370 QSessionManager *session_manager;
371 QString session_id;
372 static QString* session_key;
373 bool is_session_restored;
374#endif
375#if defined(Q_WS_X11) && !defined (QT_NO_STYLE )
376 static void x11_initialize_style();
377#endif
378
379 static QSize app_strut;
380#ifndef QT_NO_COMPONENT
381 static QStringList *app_libpaths;
382#endif
383 static QAsciiDict<QPalette> *app_palettes;
384 static QAsciiDict<QFont> *app_fonts;
385
386 static QWidgetList *popupWidgets;
387 bool inPopupMode() const;
388 void closePopup( QWidget *popup );
389 void openPopup( QWidget *popup );
390 void setActiveWindow( QWidget* act );
391
392 static bool sendSpontaneousEvent( QObject *receiver, QEvent *event );
393 static void removePostedEvent( QEvent * );
394
395 friend class QWidget;
396 friend class QETWidget;
397 friend class QDialog;
398 friend class QAccelManager;
399 friend class QEvent;
400 friend class QTranslator;
401 friend class QEventLoop;
402 friend Q_EXPORT void qt_ucm_initialize( QApplication * );
403#if defined(Q_WS_WIN)
404 friend bool qt_sendSpontaneousEvent( QObject*, QEvent* );
405#endif
406#if defined(Q_WS_QWS)
407 friend class QInputContext;
408#endif
409private: // Disabled copy constructor and operator=
410#if defined(Q_DISABLE_COPY)
411 QApplication( const QApplication & );
412 QApplication &operator=( const QApplication & );
413#endif
414};
415
416inline int QApplication::argc() const
417{
418 return app_argc;
419}
420
421inline char **QApplication::argv() const
422{
423 return app_argv;
424}
425
426#if defined(Q_WS_QWS)
427inline void QApplication::setArgs(int c, char **v)
428{
429 app_argc = c;
430 app_argv = v;
431}
432#endif
433
434#ifndef QT_NO_CURSOR
435inline QCursor *QApplication::overrideCursor()
436{
437 return app_cursor;
438}
439#endif
440inline bool QApplication::hasGlobalMouseTracking()
441{
442 return app_tracking > 0;
443}
444
445inline QWidget *QApplication::mainWidget() const
446{
447 return main_widget;
448}
449
450inline QWidget *QApplication::focusWidget() const
451{
452 return focus_widget;
453}
454
455inline QWidget *QApplication::activeWindow() const
456{
457 return active_window;
458}
459
460inline QWidget *QApplication::widgetAt( const QPoint &p, bool child )
461{
462 return widgetAt( p.x(), p.y(), child );
463}
464
465inline bool QApplication::inPopupMode() const
466{
467 return popupWidgets != 0;
468}
469#ifndef QT_NO_SESSIONMANAGER
470inline bool QApplication::isSessionRestored() const
471{
472 return is_session_restored;
473}
474
475inline QString QApplication::sessionId() const
476{
477 return session_id;
478}
479
480inline QString QApplication::sessionKey() const
481{
482 return session_key ? *session_key : QString::null;
483}
484#endif
485inline QSize QApplication::globalStrut()
486{
487 return app_strut;
488}
489
490inline bool QApplication::sendEvent( QObject *receiver, QEvent *event )
491{ if ( event ) event->spont = FALSE; return qApp ? qApp->notify( receiver, event ) : FALSE; }
492
493inline bool QApplication::sendSpontaneousEvent( QObject *receiver, QEvent *event )
494{ if ( event ) event->spont = TRUE; return qApp ? qApp->notify( receiver, event ) : FALSE; }
495
496#ifdef QT_NO_TRANSLATION
497// Simple versions
498inline QString QApplication::translate( const char *, const char *sourceText,
499 const char *, Encoding encoding ) const
500{
501#ifndef QT_NO_TEXTCODEC
502 if ( encoding == UnicodeUTF8 )
503 return QString::fromUtf8( sourceText );
504 else
505#endif
506 return QString::fromLatin1( sourceText );
507}
508#endif
509
510inline int QApplication::horizontalAlignment( int align )
511{
512 align &= AlignHorizontal_Mask;
513 if ( align == AlignAuto ) {
514 if ( reverseLayout() )
515 align = AlignRight;
516 else
517 align = AlignLeft;
518 }
519 return align;
520}
521
522#endif // QAPPLICATION_H
523
Note: See TracBrowser for help on using the repository browser.