home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qapplication.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  14KB  |  482 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qapplication.h   3.0.0   edited Oct 8 17:13 $
  3. **
  4. ** Definition of QApplication class
  5. **
  6. ** Created : 931107
  7. **
  8. ** Copyright (C) 1992-2000 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.  
  50. #ifndef QT_NO_REMOTE
  51. #include "quuid.h"
  52. #endif //QT_NO_REMOTE
  53.  
  54. class QSessionManager;
  55. class QStyle;
  56. class QTranslator;
  57. #if defined(Q_WS_QWS)
  58. class QWSDecoration;
  59. #endif
  60.  
  61. template <class type> class QPtrList;
  62.  
  63. class QApplication;
  64. extern Q_EXPORT QApplication *qApp;        // global application object
  65.  
  66. #if defined(QT_THREAD_SUPPORT)
  67. class QMutex;
  68. #endif
  69.  
  70.  
  71. class Q_EXPORT QApplication : public QObject
  72. {
  73.     Q_OBJECT
  74. public:
  75.     QApplication( int &argc, char **argv);
  76.     QApplication( int &argc, char **argv, bool GUIenabled );
  77.     enum Type { Tty, GuiClient, GuiServer };
  78.     QApplication( int &argc, char **argv, Type );
  79. #if defined(Q_WS_X11)
  80.     QApplication( Display* dpy, HANDLE visual = 0, HANDLE cmap = 0 );
  81.     QApplication( Display *dpy, int argc, char **argv,
  82.           HANDLE visual = 0, HANDLE cmap= 0 );
  83. #endif
  84.     virtual ~QApplication();
  85.  
  86.     int            argc()    const;
  87.     char      **argv()    const;
  88.  
  89.     Type type() const;
  90.  
  91. #ifndef QT_NO_STYLE
  92.     static QStyle  &style();
  93.     static void        setStyle( QStyle* );
  94.     static QStyle*  setStyle( const QString& );
  95. #endif
  96. #ifndef Q_QDOC
  97.     enum ColorMode { NormalColors, CustomColors };
  98.     static ColorMode colorMode();
  99.     static void      setColorMode( QApplication::ColorMode );
  100. #endif
  101.  
  102.     enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
  103.     static int         colorSpec();
  104.     static void      setColorSpec( int );
  105. #ifndef QT_NO_CURSOR
  106.     static QCursor  *overrideCursor();
  107.     static void         setOverrideCursor( const QCursor &, bool replace=FALSE );
  108.     static void         restoreOverrideCursor();
  109. #endif
  110.     static bool         hasGlobalMouseTracking();
  111.     static void         setGlobalMouseTracking( bool enable );
  112. #ifndef QT_NO_PALETTE
  113.     static QPalette  palette( const QWidget* = 0 );
  114.     static void         setPalette( const QPalette &, bool informWidgets=FALSE,
  115.                  const char* className = 0 );
  116. #endif
  117.     static QFont     font( const QWidget* = 0 );
  118.     static void         setFont( const QFont &, bool informWidgets=FALSE,
  119.                   const char* className = 0 );
  120.     static QFontMetrics fontMetrics();
  121.  
  122.     QWidget        *mainWidget()  const;
  123.     virtual void     setMainWidget( QWidget * );
  124.     virtual void     polish( QWidget * );
  125.  
  126.     static QWidgetList *allWidgets();
  127.     static QWidgetList *topLevelWidgets();
  128.  
  129.     static QDesktopWidget   *desktop();
  130.  
  131.     static QWidget     *activePopupWidget();
  132.     static QWidget     *activeModalWidget();
  133. #ifndef QT_NO_CLIPBOARD
  134.     static QClipboard  *clipboard();
  135. #endif
  136.     QWidget           *focusWidget() const;
  137.     QWidget           *activeWindow() const;
  138.  
  139.     static QWidget  *widgetAt( int x, int y, bool child=FALSE );
  140.     static QWidget  *widgetAt( const QPoint &, bool child=FALSE );
  141.  
  142.     int             exec();
  143.     void         processEvents();
  144.     void         processEvents( int maxtime );
  145.     void         processOneEvent();
  146.     bool         hasPendingEvents();
  147.     int             enter_loop();
  148.     void         exit_loop();
  149.     int             loopLevel() const;
  150.     static void         exit( int retcode=0 );
  151.  
  152.     static bool         sendEvent( QObject *receiver, QEvent *event );
  153.     static void         postEvent( QObject *receiver, QEvent *event );
  154.     static void         sendPostedEvents( QObject *receiver, int event_type );
  155.     static void         sendPostedEvents();
  156.  
  157.     static void      removePostedEvents( QObject *receiver );
  158.  
  159.     virtual bool     notify( QObject *, QEvent * );
  160.  
  161.     static bool         startingUp();
  162.     static bool         closingDown();
  163.  
  164.     static void         flushX();
  165.     static void flush();
  166.     static void         syncX();
  167.  
  168.     static void         beep();
  169.  
  170. #ifndef QT_NO_TRANSLATION
  171.     void         setDefaultCodec( QTextCodec * );
  172.     QTextCodec*         defaultCodec() const;
  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_PALETTE
  182.     // obsolete functions
  183.     static void      setWinStyleHighlightColor( const QColor &c ) {
  184.     QPalette p( palette() );
  185.     p.setColor( QColorGroup::Highlight, c );
  186.     setPalette( p, TRUE);
  187.     }
  188.     static const QColor &winStyleHighlightColor() {
  189.     return palette().active().highlight();
  190.     }
  191. #endif
  192.     static void      setDesktopSettingsAware( bool );
  193.     static bool      desktopSettingsAware();
  194.  
  195.     static void      setCursorFlashTime( int );
  196.     static int       cursorFlashTime();
  197.  
  198.     static void      setDoubleClickInterval( int );
  199.     static int       doubleClickInterval();
  200. #ifndef QT_NO_WHEELEVENT
  201.     static void      setWheelScrollLines( int );
  202.     static int       wheelScrollLines();
  203. #endif
  204.     static void         setGlobalStrut( const QSize & );
  205.     static QSize     globalStrut();
  206.  
  207. #ifndef QT_NO_COMPONENT
  208.     static void      setLibraryPaths(const QStringList &);
  209.     static QStringList libraryPaths();
  210.     static void      addLibraryPath(const QString &);
  211.     static void      removeLibraryPath(const QString &);
  212. #endif //QT_NO_COMPONENT
  213.     static void setStartDragTime( int ms );
  214.     static int startDragTime();
  215.     static void setStartDragDistance( int l );
  216.     static int startDragDistance();
  217.  
  218.     static void setReverseLayout( bool b );
  219.     static bool reverseLayout();
  220.  
  221.     static int horizontalAlignment( int align );
  222.  
  223.     static bool        isEffectEnabled( Qt::UIEffect );
  224.     static void        setEffectEnabled( Qt::UIEffect, bool enable = TRUE );
  225.  
  226. #if defined(Q_WS_MAC)
  227.     virtual bool     macEventFilter( EventRef );
  228. #elif defined(Q_WS_WIN)
  229.     virtual bool     winEventFilter( MSG * );
  230. #elif defined(Q_WS_X11)
  231.     virtual bool     x11EventFilter( XEvent * );
  232.     virtual int         x11ClientMessage( QWidget*, XEvent*, bool passive_only);
  233.     int              x11ProcessEvent( XEvent* );
  234. #elif defined(Q_WS_QWS)
  235.     virtual bool     qwsEventFilter( QWSEvent * );
  236.     int              qwsProcessEvent( QWSEvent* );
  237.     void             qwsSetCustomColors( QRgb *colortable, int start, int numColors );
  238. #ifndef QT_NO_QWS_MANAGER
  239.     static QWSDecoration &qwsDecoration();
  240.     static void      qwsSetDecoration( QWSDecoration *);
  241. #endif
  242. #endif
  243.  
  244. #if defined(Q_WS_WIN)
  245.     static WindowsVersion winVersion();
  246.     void         winFocus( QWidget *, bool );
  247.     static void         winMouseButtonUp();
  248. #endif
  249.  
  250. #ifndef QT_NO_SESSIONMANAGER
  251.     // session management
  252.     bool         isSessionRestored() const;
  253.     QString         sessionId() const;
  254.     virtual void     commitData( QSessionManager& sm );
  255.     virtual void     saveState( QSessionManager& sm );
  256. #endif
  257. #if defined(Q_WS_X11)
  258.     static void create_xim();
  259.     static void close_xim();
  260.     static bool x11_apply_settings();
  261. #endif
  262.     void         wakeUpGuiThread();
  263. #if defined(QT_THREAD_SUPPORT)
  264.     void         lock();
  265.     void         unlock(bool wakeUpGui = TRUE);
  266.     bool         locked();
  267.     bool             tryLock();
  268. #endif
  269.  
  270. signals:
  271.     void         lastWindowClosed();
  272.     void         aboutToQuit();
  273.     void         guiThreadAwake();
  274.  
  275. public slots:
  276.     void         quit();
  277.     void         closeAllWindows();
  278.  
  279. private:
  280.     void         construct( int &argc, char **argv, Type );
  281.     bool         processNextEvent( bool );
  282.     void         initialize( int, char ** );
  283.     void         init_precmdline();
  284.     void         process_cmdline( int* argcptr, char ** argv );
  285.     bool         internalNotify( QObject *, QEvent * );
  286. #if defined(Q_WS_QWS)
  287.     static QWidget *findChildWidget( const QWidget *p, const QPoint &pos );
  288.     static QWidget *findWidget( const QObjectList&, const QPoint &, bool rec );
  289. #endif
  290.  
  291. #if defined(Q_WS_MAC)
  292.     bool         do_mouse_down(Point *);
  293.     static QMAC_PASCAL OSStatus globalEventProcessor(EventHandlerCallRef,  EventRef, void *);
  294.     static QMAC_PASCAL void qt_trap_context_mouse(EventLoopTimerRef, void *);
  295.     static QMAC_PASCAL void qt_select_timer_callbk(EventLoopTimerRef, void *);
  296.     static bool qt_mac_apply_settings();
  297.     friend class QMacInputMethod;
  298.     friend bool qt_set_socket_handler( int, int, QObject *, bool);
  299.     friend void qt_mac_destroy_widget(QWidget *);
  300.     friend void qt_init(int *, char **, QApplication::Type);
  301. #endif
  302.  
  303. #if defined(QT_THREAD_SUPPORT)
  304.     static QMutex * qt_mutex;
  305. #endif
  306.  
  307.     int             app_argc;
  308.     char       **app_argv;
  309.     bool         quit_now;
  310.     int             quit_code;
  311.     static QStyle   *app_style;
  312.     static int         app_cspec;
  313. #ifndef QT_NO_PALETTE
  314.     static QPalette *app_pal;
  315. #endif
  316.     static QFont    *app_font;
  317. #ifndef QT_NO_CURSOR
  318.     static QCursor  *app_cursor;
  319. #endif
  320.     static int         app_tracking;
  321.     static bool         is_app_running;
  322.     static bool         is_app_closing;
  323.     static bool         app_exit_loop;
  324.     static int         loop_level;
  325.     static QWidget  *main_widget;
  326.     static QWidget  *focus_widget;
  327.     static QWidget  *active_window;
  328.     static bool         obey_desktop_settings;
  329.     static int         cursor_flash_time;
  330.     static int         mouse_double_click_time;
  331.     static int         wheel_scroll_lines;
  332.  
  333.     static bool         animate_ui;
  334.     static bool         animate_menu;
  335.     static bool         animate_tooltip;
  336.     static bool         animate_combo;
  337.     static bool         fade_menu;
  338.     static bool         fade_tooltip;
  339.  
  340.     QPtrList<QTranslator> *translators;
  341. #ifndef QT_NO_SESSIONMANAGER
  342.     QSessionManager *session_manager;
  343.     QString         session_id;
  344.     bool         is_session_restored;
  345. #endif
  346. #if defined(Q_WS_X11) && !defined (QT_NO_STYLE )
  347.     static void x11_initialize_style();
  348. #endif
  349.  
  350.     static QSize     app_strut;
  351.  
  352.     static QStringList *app_libpaths;
  353.  
  354.     static QAsciiDict<QPalette> *app_palettes;
  355.     static QAsciiDict<QFont>    *app_fonts;
  356.  
  357.     static QWidgetList *popupWidgets;
  358.     bool         inPopupMode() const;
  359.     void         closePopup( QWidget *popup );
  360.     void         openPopup( QWidget *popup );
  361.     void         setActiveWindow( QWidget* act );
  362.  
  363.     static bool      sendSpontaneousEvent( QObject *receiver, QEvent *event );
  364.     static void      removePostedEvent( QEvent * );
  365.  
  366.     friend class QWidget;
  367.     friend class QETWidget;
  368.     friend class QEvent;
  369.     friend Q_EXPORT void qt_ucm_initialize( QApplication * );
  370. #if defined(Q_WS_WIN)
  371.     friend bool qt_sendSpontaneousEvent( QObject*, QEvent* );
  372. #endif
  373.  
  374. #ifndef QT_NO_REMOTE
  375. public:
  376.     void setEnableRemoteControl(bool enable, const QUuid appId = QUuid());
  377.     bool remoteControlEnabled() const;
  378.     QUuid applicationId() const;
  379. #endif //QT_NO_REMOTE
  380.  
  381. private: // Disabled copy constructor and operator=
  382. #if defined(Q_DISABLE_COPY)
  383.     QApplication( const QApplication & );
  384.     QApplication &operator=( const QApplication & );
  385. #endif
  386. };
  387.  
  388. inline int QApplication::argc() const
  389. {
  390.     return app_argc;
  391. }
  392.  
  393. inline char **QApplication::argv() const
  394. {
  395.     return app_argv;
  396. }
  397. #ifndef QT_NO_CURSOR
  398. inline QCursor *QApplication::overrideCursor()
  399. {
  400.     return app_cursor;
  401. }
  402. #endif
  403. inline bool QApplication::hasGlobalMouseTracking()
  404. {
  405.     return app_tracking > 0;
  406. }
  407.  
  408. inline QWidget *QApplication::mainWidget() const
  409. {
  410.     return main_widget;
  411. }
  412.  
  413. inline QWidget *QApplication::focusWidget() const
  414. {
  415.     return focus_widget;
  416. }
  417.  
  418. inline QWidget *QApplication::activeWindow() const
  419. {
  420.     return active_window;
  421. }
  422.  
  423. inline QWidget *QApplication::widgetAt( const QPoint &p, bool child )
  424. {
  425.     return widgetAt( p.x(), p.y(), child );
  426. }
  427.  
  428. inline bool QApplication::inPopupMode() const
  429. {
  430.     return popupWidgets != 0;
  431. }
  432. #ifndef QT_NO_SESSIONMANAGER
  433. inline bool QApplication::isSessionRestored() const
  434. {
  435.     return is_session_restored;
  436. }
  437.  
  438. inline QString QApplication::sessionId() const
  439. {
  440.     return session_id;
  441. }
  442. #endif
  443. inline QSize QApplication::globalStrut()
  444. {
  445.     return app_strut;
  446. }
  447.  
  448. inline bool QApplication::sendEvent( QObject *receiver, QEvent *event )
  449. { return qApp ? qApp->notify( receiver, event ) : FALSE; }
  450.  
  451. inline bool QApplication::sendSpontaneousEvent( QObject *receiver, QEvent *event )
  452. { if ( event ) event->spont = TRUE; return qApp ? qApp->notify( receiver, event ) : FALSE; }
  453.  
  454. #ifdef QT_NO_TRANSLATION
  455. // Simple versions
  456. inline QString QApplication::translate( const char *, const char *sourceText,
  457.                     const char *, Encoding encoding ) const
  458. {
  459. #ifndef QT_NO_TEXTCODEC
  460.     if ( encoding == UnicodeUTF8 )
  461.     return QString::fromUtf8( sourceText );
  462.     else
  463. #endif    
  464.     return QString::fromLatin1( sourceText );
  465. }
  466. #endif
  467.  
  468. inline int QApplication::horizontalAlignment( int align )
  469. {
  470.     align &= AlignHorizontal_Mask;
  471.     if ( align == AlignAuto ) {
  472.     if ( reverseLayout() )
  473.         align = AlignRight;
  474.     else
  475.         align = AlignLeft;
  476.     }
  477.     return align;
  478. }
  479.  
  480. #endif // QAPPLICATION_H
  481.  
  482.