summaryrefslogtreecommitdiffstats
path: root/src/kernel/qapplication.h
blob: 6e62b457606bd7b168f70844755d5ecb73ed636a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
/****************************************************************************
**
** Definition of TQApplication class
**
** Created : 931107
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of the kernel module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file.  Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#ifndef TQAPPLICATION_H
#define TQAPPLICATION_H

#ifndef QT_H
#include "qdesktopwidget.h"
#include "qasciidict.h"
#include "qpalette.h"
#include "qtranslator.h"
#include "qstrlist.h"
#include "qstringlist.h"
#endif // QT_H

class TQSessionManager;
class TQStyle;
class TQTranslator;
class TQEventLoop;
#if defined(Q_WS_X11)
class TQIMEvent;
#endif
#if defined(Q_WS_QWS)
class TQWSDecoration;
#endif

#ifdef QT_THREAD_SUPPORT
class TQMutex;
#endif // QT_THREAD_SUPPORT


class TQApplication;
extern Q_EXPORT TQApplication *qApp;		// global application object


class Q_EXPORT TQApplication : public TQObject
{
    Q_OBJECT
public:
    TQApplication( int &argc, char **argv );
    TQApplication( int &argc, char **argv, bool GUIenabled );
    enum Type { Tty, GuiClient, GuiServer };
    TQApplication( int &argc, char **argv, Type );
#if defined(Q_WS_X11)
    TQApplication( Display* dpy, HANDLE visual = 0, HANDLE cmap = 0 );
    TQApplication( Display *dpy, int argc, char **argv,
		  HANDLE visual = 0, HANDLE cmap= 0 );
#endif
    virtual ~TQApplication();

    int		    argc()	const;
    char	  **argv()	const;

    Type type() const;

#ifndef QT_NO_STYLE
    static TQStyle  &style();
    static void	    setStyle( TQStyle* );
    static TQStyle*  setStyle( const TQString& );
#endif
#ifndef Q_QDOC
    enum ColorMode { NormalColors, CustomColors };
    static ColorMode colorMode();
    static void      setColorMode( TQApplication::ColorMode );
#endif

    enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
    static int	     colorSpec();
    static void      setColorSpec( int );
#ifndef QT_NO_CURSOR
    static TQCursor  *overrideCursor();
    static void	     setOverrideCursor( const TQCursor &, bool replace=FALSE );
    static void	     restoreOverrideCursor();
#endif
    static bool	     hasGlobalMouseTracking();
    static void	     setGlobalMouseTracking( bool enable );
#ifndef QT_NO_PALETTE
    static TQPalette  palette( const TQWidget* = 0 );
    static void	     setPalette( const TQPalette &, bool informWidgets=FALSE,
				 const char* className = 0 );
#endif
    static TQFont     font( const TQWidget* = 0 );
    static void	     setFont( const TQFont &, bool informWidgets=FALSE,
			      const char* className = 0 );
    static TQFontMetrics fontMetrics();

    TQWidget	    *mainWidget()  const;
    virtual void     setMainWidget( TQWidget * );
    virtual void     polish( TQWidget * );

    static TQWidgetList *allWidgets();
    static TQWidgetList *topLevelWidgets();

    static TQDesktopWidget   *desktop();

    static TQWidget     *activePopupWidget();
    static TQWidget     *activeModalWidget();
#ifndef QT_NO_CLIPBOARD
    static TQClipboard  *clipboard();
#endif
    TQWidget	       *focusWidget() const;
    TQWidget	       *activeWindow() const;

    static TQWidget  *widgetAt( int x, int y, bool child=FALSE );
    static TQWidget  *widgetAt( const TQPoint &, bool child=FALSE );

    static TQEventLoop *eventLoop();

    int		     exec();
    void	     processEvents();
    void	     processEvents( int maxtime );
    void	     processOneEvent();
    bool	     hasPendingEvents();
    int		     enter_loop();
    void	     exit_loop();
    int		     loopLevel() const;
    static void	     exit( int retcode=0 );

    static bool	     sendEvent( TQObject *receiver, TQEvent *event );
    static void	     postEvent( TQObject *receiver, TQEvent *event );
    static void	     sendPostedEvents( TQObject *receiver, int event_type );
    static void	     sendPostedEvents();

    static void      removePostedEvents( TQObject *receiver );

    virtual bool     notify( TQObject *, TQEvent * );

    static bool	     startingUp();
    static bool	     closingDown();

    static void	     flushX();
    static void flush();
    static void	     syncX();

    static void	     beep();

#ifndef QT_NO_TRANSLATION
# ifndef QT_NO_TEXTCODEC
    void	     setDefaultCodec( TQTextCodec * );
    TQTextCodec*	     defaultCodec() const;
# endif
    void	     installTranslator( TQTranslator * );
    void	     removeTranslator( TQTranslator * );
#endif
    enum Encoding { DefaultCodec, UnicodeUTF8 };
    TQString	     translate( const char * context,
				const char * key,
				const char * comment = 0,
				Encoding encoding = DefaultCodec ) const;
#ifndef QT_NO_DIR
    TQString   applicationDirPath();
    TQString   applicationFilePath();
#endif
#ifndef QT_NO_PALETTE
    // obsolete functions
    static void      setWinStyleHighlightColor( const TQColor &c ) {
	TQPalette p( palette() );
	p.setColor( TQColorGroup::Highlight, c );
	setPalette( p, TRUE);
    }
    static const TQColor &winStyleHighlightColor() {
	return palette().active().highlight();
    }
#endif
    static void      setDesktopSettingsAware( bool );
    static bool      desktopSettingsAware();

    static void      setCursorFlashTime( int );
    static int       cursorFlashTime();

    static void      setDoubleClickInterval( int );
    static int       doubleClickInterval();
#ifndef QT_NO_WHEELEVENT
    static void      setWheelScrollLines( int );
    static int       wheelScrollLines();
#endif
    static void	     setGlobalStrut( const TQSize & );
    static TQSize     globalStrut();

#ifndef QT_NO_COMPONENT
    static void      setLibraryPaths( const TQStringList & );
    static TQStringList libraryPaths();
    static void      addLibraryPath( const TQString & );
    static void      removeLibraryPath( const TQString & );
#endif // QT_NO_COMPONENT
    static void setStartDragTime( int ms );
    static int startDragTime();
    static void setStartDragDistance( int l );
    static int startDragDistance();

    static void setReverseLayout( bool b );
    static bool reverseLayout();

    static int horizontalAlignment( int align );

    static bool	    isEffectEnabled( TQt::UIEffect );
    static void	    setEffectEnabled( TQt::UIEffect, bool enable = TRUE );

#if defined(Q_WS_MAC)
    virtual bool     macEventFilter( EventHandlerCallRef, EventRef );
#endif
#if defined(Q_WS_WIN)
    virtual bool     winEventFilter( MSG * );
#endif
#if defined(Q_WS_X11)
    virtual bool     x11EventFilter( XEvent * );
    virtual int	     x11ClientMessage( TQWidget*, XEvent*, bool passive_only);
    int              x11ProcessEvent( XEvent* );
#endif
#if defined(Q_WS_QWS)
    virtual bool     qwsEventFilter( TQWSEvent * );
    int              qwsProcessEvent( TQWSEvent* );
    void             qwsSetCustomColors( TQRgb *colortable, int start, int numColors );
/*!
  \internal
    Returns true if the process is GUI server
*/
    bool          qwsIsGUIServer();
#ifndef QT_NO_QWS_MANAGER
    static TQWSDecoration &qwsDecoration();
    static void      qwsSetDecoration( TQWSDecoration *);
#endif
#endif

#if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)
    static WindowsVersion winVersion();
#elif defined(Q_OS_MAC)
    static MacintoshVersion macVersion();
#endif
#if defined(Q_WS_WIN)
    void	     winFocus( TQWidget *, bool );
    static void	     winMouseButtonUp();
#endif

#ifndef QT_NO_SESSIONMANAGER
    // session management
    bool	     isSessionRestored() const;
    TQString 	sessionId() const;
    TQString 	sessionKey() const;
    virtual void     commitData( TQSessionManager& sm );
    virtual void     saveState( TQSessionManager& sm );
#endif
#if defined(Q_WS_X11)
#if !defined(QT_NO_IM_EXTENSIONS)
    virtual TQWidget *locateICHolderWidget( TQWidget *w );
    virtual TQWidgetList *icHolderWidgets();
    static void create_im();
    static void close_im();
#else
    TQWidget *locateICHolderWidget( TQWidget *w );
    TQWidgetList *icHolderWidgets();
    static void create_xim();
    static void close_xim();
#endif
    static TQString defaultInputMethod();
    void	changeAllInputContext( const TQString & );
    static bool x11_apply_settings();
#endif
    void	     wakeUpGuiThread();
#if defined(QT_THREAD_SUPPORT)
    void	     lock();
    void	     unlock(bool wakeUpGui = TRUE);
    bool	     locked();
    bool             tryLock();
#endif

signals:
    void	     lastWindowClosed();
    void	     aboutToQuit();
    void	     guiThreadAwake();

public slots:
    void	     quit();
    void	     closeAllWindows();
    void	     aboutTQt();

#if defined(Q_WS_QWS)
protected:
    void setArgs(int, char **);
#endif

protected:
    bool event(TQEvent *);

private:
    void construct( int &argc, char **argv, Type );
    void initialize( int, char ** );
    void init_precmdline();
    void process_cmdline( int* argcptr, char ** argv );
    bool internalNotify( TQObject *, TQEvent * );
#if defined(Q_WS_QWS)
    static TQWidget *findChildWidget( const TQWidget *p, const TQPoint &pos );
    static TQWidget *findWidget( const TQObjectList&, const TQPoint &, bool rec );
#endif

#if defined(Q_WS_MAC)
    bool do_mouse_down(Point *, bool *);
    static TQMAC_PASCAL OSStatus globalEventProcessor(EventHandlerCallRef,  EventRef, void *);
    static TQMAC_PASCAL OSStatus globalAppleEventProcessor(const AppleEvent *, AppleEvent *, long);
    static TQMAC_PASCAL void qt_context_timer_callbk(EventLoopTimerRef, void *);
    static TQMAC_PASCAL void qt_select_timer_callbk(EventLoopTimerRef, void *);
    static bool qt_mac_apply_settings();
    friend class TQMacInputMethod;
    friend TQMAC_PASCAL OSStatus qt_window_event(EventHandlerCallRef, EventRef, void *);
    friend void qt_mac_update_os_settings();
    friend bool qt_set_socket_handler( int, int, TQObject *, bool);
    friend void qt_mac_destroy_widget(TQWidget *);
    friend void qt_init(int *, char **, TQApplication::Type);
#endif

#if defined(Q_WS_X11)
private slots:
    void postIMEvent( TQObject *receiver, TQIMEvent *event );
#endif

private:
#ifdef QT_THREAD_SUPPORT
    static TQMutex   *qt_mutex;
#endif // QT_THREAD_SUPPORT

    int		     app_argc;
    char	   **app_argv;
    bool	     quit_now;
    int		     quit_code;
    static TQStyle   *app_style;
    static int	     app_cspec;
#ifndef QT_NO_PALETTE
    static TQPalette *app_pal;
#endif
    static TQFont    *app_font;
#ifndef QT_NO_CURSOR
    static TQCursor  *app_cursor;
#endif
    static TQEventLoop* eventloop;
    static int	     app_tracking;
    static bool	     is_app_running;
    static bool	     is_app_closing;
    static bool	     app_exit_loop;
    static int	     loop_level;
    static TQWidget  *main_widget;
    static TQWidget  *focus_widget;
    static TQWidget  *active_window;
    static bool	     obey_desktop_settings;
    static int	     cursor_flash_time;
    static int	     mouse_double_click_time;
    static int	     wheel_scroll_lines;
    static int	     composedUnicode; // Value, meta-composed character

    static bool	     animate_ui;
    static bool	     animate_menu;
    static bool	     animate_tooltip;
    static bool	     animate_combo;
    static bool	     fade_menu;
    static bool	     fade_tooltip;
    static bool	     animate_toolbox;
    static bool	     widgetCount; // Coupled with -widgetcount switch
    static bool	     metaComposeUnicode;

    TQValueList<TQTranslator*> *translators;
#ifndef QT_NO_SESSIONMANAGER
    TQSessionManager *session_manager;
    TQString	     session_id;
    static TQString* session_key;
    bool	     is_session_restored;
#endif
#if defined(Q_WS_X11)
#if !defined (QT_NO_STYLE)
    static void x11_initialize_style();
#endif
    static TQString defaultIM; // default input method's name in this application.
#endif

    static TQSize     app_strut;
#ifndef QT_NO_COMPONENT
    static TQStringList *app_libpaths;
#endif
    static TQAsciiDict<TQPalette> *app_palettes;
    static TQAsciiDict<TQFont>    *app_fonts;

    static TQWidgetList *popupWidgets;
    bool	     inPopupMode() const;
    void	     closePopup( TQWidget *popup );
    void	     openPopup( TQWidget *popup );
    void	     setActiveWindow( TQWidget* act );

    static bool      sendSpontaneousEvent( TQObject *receiver, TQEvent *event );
    static void      removePostedEvent( TQEvent * );
    static void      removePostedEvents( TQObject *receiver, int event_type );

    friend class TQWidget;
    friend class TQETWidget;
    friend class TQDialog;
    friend class TQAccelManager;
    friend class TQEvent;
    friend class TQTranslator;
    friend class TQEventLoop;
    friend Q_EXPORT void qt_ucm_initialize( TQApplication * );
#if defined(Q_WS_WIN)
    friend bool qt_sendSpontaneousEvent( TQObject*, TQEvent* );
#endif
#if defined(Q_WS_QWS)
    friend class TQInputContext;
#endif
private: // Disabled copy constructor and operator=
#if defined(Q_DISABLE_COPY)
    TQApplication( const TQApplication & );
    TQApplication &operator=( const TQApplication & );
#endif
};

inline int TQApplication::argc() const
{
    return app_argc;
}

inline char **TQApplication::argv() const
{
    return app_argv;
}

#if defined(Q_WS_QWS)
inline void TQApplication::setArgs(int c, char **v)
{
        app_argc = c;
	    app_argv = v;
}
#endif

#ifndef QT_NO_CURSOR
inline TQCursor *TQApplication::overrideCursor()
{
    return app_cursor;
}
#endif
inline bool TQApplication::hasGlobalMouseTracking()
{
    return app_tracking > 0;
}

inline TQWidget *TQApplication::mainWidget() const
{
    return main_widget;
}

inline TQWidget *TQApplication::focusWidget() const
{
    return focus_widget;
}

inline TQWidget *TQApplication::activeWindow() const
{
    return active_window;
}

inline TQWidget *TQApplication::widgetAt( const TQPoint &p, bool child )
{
    return widgetAt( p.x(), p.y(), child );
}

inline bool TQApplication::inPopupMode() const
{
    return popupWidgets != 0;
}
#ifndef QT_NO_SESSIONMANAGER
inline bool TQApplication::isSessionRestored() const
{
    return is_session_restored;
}

inline TQString TQApplication::sessionId() const
{
    return session_id;
}

inline TQString TQApplication::sessionKey() const
{
    return session_key ? *session_key : TQString::null;
}
#endif
inline TQSize TQApplication::globalStrut()
{
    return app_strut;
}

inline bool TQApplication::sendEvent( TQObject *receiver, TQEvent *event )
{  if ( event ) event->spont = FALSE; return qApp ? qApp->notify( receiver, event ) : FALSE; }

inline bool TQApplication::sendSpontaneousEvent( TQObject *receiver, TQEvent *event )
{ if ( event ) event->spont = TRUE; return qApp ? qApp->notify( receiver, event ) : FALSE; }

#ifdef QT_NO_TRANSLATION
// Simple versions
inline TQString TQApplication::translate( const char *, const char *sourceText,
					const char *, Encoding encoding ) const
{
#ifndef QT_NO_TEXTCODEC
    if ( encoding == UnicodeUTF8 )
	return TQString::fromUtf8( sourceText );
    else
#endif
	return TQString::fromLatin1( sourceText );
}
#endif

inline int TQApplication::horizontalAlignment( int align )
{
    align &= AlignHorizontal_Mask;
    if ( align == AlignAuto ) {
	if ( reverseLayout() )
	    align = AlignRight;
	else
	    align = AlignLeft;
    }
    return align;
}

#endif // TQAPPLICATION_H