From 397b7afa8e3f32268c4454bf4783ac2a5a799658 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Tue, 15 Oct 2024 13:05:33 +0900 Subject: Rename ntqapplication, ntqconfig and ntqmodules files to equivalent tq* Signed-off-by: Michele Calgaro --- src/kernel/ntqapplication.h | 532 --- src/kernel/qapplication.cpp | 4969 ------------------------- src/kernel/qapplication_p.h | 95 - src/kernel/qapplication_x11.cpp | 6732 ---------------------------------- src/kernel/qdnd_x11.cpp | 2 +- src/kernel/qt_kernel.pri | 12 +- src/kernel/qt_pch.h | 2 +- src/kernel/qtaddons_x11.cpp | 2 +- src/kernel/tqabstractlayout.cpp | 2 +- src/kernel/tqaccel.cpp | 2 +- src/kernel/tqaccessible.cpp | 2 +- src/kernel/tqapplication.cpp | 4969 +++++++++++++++++++++++++ src/kernel/tqapplication.h | 532 +++ src/kernel/tqapplication_p.h | 95 + src/kernel/tqapplication_x11.cpp | 6732 ++++++++++++++++++++++++++++++++++ src/kernel/tqclipboard.cpp | 4 +- src/kernel/tqclipboard_x11.cpp | 12 +- src/kernel/tqcolor_x11.cpp | 4 +- src/kernel/tqcursor_x11.cpp | 2 +- src/kernel/tqdesktopwidget_x11.cpp | 4 +- src/kernel/tqdragobject.cpp | 2 +- src/kernel/tqdrawutil.cpp | 2 +- src/kernel/tqevent.cpp | 2 +- src/kernel/tqeventloop.cpp | 2 +- src/kernel/tqeventloop_unix.cpp | 2 +- src/kernel/tqeventloop_unix_glib.cpp | 2 +- src/kernel/tqeventloop_x11.cpp | 8 +- src/kernel/tqeventloop_x11_glib.cpp | 8 +- src/kernel/tqfont.cpp | 2 +- src/kernel/tqfont_x11.cpp | 2 +- src/kernel/tqfontdatabase.cpp | 4 +- src/kernel/tqiconset.cpp | 2 +- src/kernel/tqimage.cpp | 2 +- src/kernel/tqinputcontext.cpp | 2 +- src/kernel/tqinputcontext_x11.cpp | 2 +- src/kernel/tqlayout.cpp | 2 +- src/kernel/tqlocalfs.cpp | 2 +- src/kernel/tqmime.cpp | 2 +- src/kernel/tqmotifdnd_x11.cpp | 2 +- src/kernel/tqnamespace.h | 6 +- src/kernel/tqobject.cpp | 4 +- src/kernel/tqpaintdevice_x11.cpp | 2 +- src/kernel/tqpainter.cpp | 2 +- src/kernel/tqpixmap.cpp | 2 +- src/kernel/tqpixmap_x11.cpp | 6 +- src/kernel/tqprinter_unix.cpp | 2 +- src/kernel/tqprocess.cpp | 2 +- src/kernel/tqprocess_unix.cpp | 2 +- src/kernel/tqpsprinter.cpp | 2 +- src/kernel/tqrichtext.cpp | 2 +- src/kernel/tqrichtext_p.h | 2 +- src/kernel/tqsimplerichtext.cpp | 2 +- src/kernel/tqsizegrip.cpp | 4 +- src/kernel/tqsocketnotifier.cpp | 2 +- src/kernel/tqsound_x11.cpp | 2 +- src/kernel/tqstyle.cpp | 2 +- src/kernel/tqt3.h | 2 +- src/kernel/tqtextlayout.cpp | 2 +- src/kernel/tqthread.cpp | 2 +- src/kernel/tqthread_unix.cpp | 2 +- src/kernel/tqtimer.cpp | 2 +- src/kernel/tqtranslator.cpp | 2 +- src/kernel/tqurl.cpp | 2 +- src/kernel/tqwidget.cpp | 4 +- src/kernel/tqwidget_p.h | 2 +- src/kernel/tqwidget_x11.cpp | 20 +- 66 files changed, 12422 insertions(+), 12422 deletions(-) delete mode 100644 src/kernel/ntqapplication.h delete mode 100644 src/kernel/qapplication.cpp delete mode 100644 src/kernel/qapplication_p.h delete mode 100644 src/kernel/qapplication_x11.cpp create mode 100644 src/kernel/tqapplication.cpp create mode 100644 src/kernel/tqapplication.h create mode 100644 src/kernel/tqapplication_p.h create mode 100644 src/kernel/tqapplication_x11.cpp (limited to 'src/kernel') diff --git a/src/kernel/ntqapplication.h b/src/kernel/ntqapplication.h deleted file mode 100644 index 0e884583e..000000000 --- a/src/kernel/ntqapplication.h +++ /dev/null @@ -1,532 +0,0 @@ -/**************************************************************************** -** -** 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 "tqdesktopwidget.h" -#include "tqasciidict.h" -#include "tqpalette.h" -#include "tqtranslator.h" -#include "tqstrlist.h" -#include "tqstringlist.h" -#endif // QT_H - -class TQSessionManager; -class TQStyle; -class TQTranslator; -class TQEventLoop; -#if defined(TQ_WS_X11) -class TQIMEvent; -#endif - -#ifdef TQT_THREAD_SUPPORT -class TQMutex; -class TQThread; -#endif // TQT_THREAD_SUPPORT - - -class TQApplication; -extern TQ_EXPORT TQApplication *tqApp; // global application object - - -class TQ_EXPORT TQApplication : public TQObject -{ - TQ_OBJECT -public: - TQApplication( int &argc, char **argv ); - TQApplication( int &argc, char **argv, bool GUIenabled ); - TQApplication( int &argc, char **argv, bool GUIenabled, bool SMenabled ); - enum Type { Tty, GuiClient, GuiServer }; - TQApplication( int &argc, char **argv, Type ); -#if defined(TQ_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 TQT_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 TQT_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 TQT_NO_PALETTE - static TQPalette palette( const TQWidget* = 0 ); - static TQPalette palette( TQStringList ); - 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 TQT_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 TQT_NO_TRANSLATION -# ifndef TQT_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 TQT_NO_DIR - TQString applicationDirPath(); - TQString applicationFilePath(); -#endif -#ifndef TQT_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 TQT_NO_WHEELEVENT - static void setWheelScrollLines( int ); - static int wheelScrollLines(); -#endif - static void setGlobalStrut( const TQSize & ); - static TQSize globalStrut(); - -#ifndef TQT_NO_COMPONENT - static void setLibraryPaths( const TQStringList & ); - static TQStringList libraryPaths(); - static void addLibraryPath( const TQString & ); - static void removeLibraryPath( const TQString & ); -#endif // TQT_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(TQ_WS_MAC) - virtual bool macEventFilter( EventHandlerCallRef, EventRef ); -#endif -#if defined(TQ_WS_WIN) - virtual bool winEventFilter( MSG * ); -#endif -#if defined(TQ_WS_X11) - virtual bool x11EventFilter( XEvent * ); - virtual int x11ClientMessage( TQWidget*, XEvent*, bool passive_only); - int x11ProcessEvent( XEvent* ); -#endif - -#if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) - static WindowsVersion winVersion(); -#elif defined(Q_OS_MAC) - static MacintoshVersion macVersion(); -#endif -#if defined(TQ_WS_WIN) - void winFocus( TQWidget *, bool ); - static void winMouseButtonUp(); -#endif - -#ifndef TQT_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(TQ_WS_X11) -#if !defined(TQT_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(TQT_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(); - -protected: - bool event(TQEvent *); - -private: - void construct( int &argc, char **argv, Type, bool enable_sm ); - void initialize( int, char **, bool enable_sm = true ); - void init_precmdline(); - void process_cmdline( int* argcptr, char ** argv ); - bool internalNotify( TQObject *, TQEvent * ); - -#if defined(TQ_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 tqt_init(int *, char **, TQApplication::Type); -#endif - -#if defined(TQ_WS_X11) -private slots: - void postIMEvent( TQObject *receiver, TQIMEvent *event ); -#endif - -public: -#ifdef TQT_THREAD_SUPPORT - static TQMutex *tqt_mutex; -#endif // TQT_THREAD_SUPPORT - -private: - int app_argc; - char **app_argv; - bool quit_now; - int quit_code; - static TQStyle *app_style; - static int app_cspec; -#ifndef TQT_NO_PALETTE - static TQPalette *app_pal; -#endif - static TQFont *app_font; -#ifndef TQT_NO_CURSOR - static TQCursor *app_cursor; -#endif -#ifndef TQT_THREAD_SUPPORT - static TQEventLoop* eventloop; -#endif - 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 *translators; -#ifndef TQT_NO_SESSIONMANAGER - TQSessionManager *session_manager; - TQString session_id; - static TQString* session_key; - bool is_session_restored; -#endif -#if defined(TQ_WS_X11) -#if !defined (TQT_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 TQT_NO_COMPONENT - static TQStringList *app_libpaths; -#endif - static TQAsciiDict *app_palettes; - static TQAsciiDict *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 TQObject; - friend class TQWidget; - friend class TQETWidget; - friend class TQDialog; - friend class TQAccelManager; - friend class TQEvent; -#ifdef TQT_THREAD_SUPPORT - friend class TQThread; -#endif // TQT_THREAD_SUPPORT - friend class TQTranslator; - friend class TQEventLoop; - friend TQ_EXPORT void tqt_ucm_initialize( TQApplication * ); -#if defined(TQ_WS_WIN) - friend bool qt_sendSpontaneousEvent( TQObject*, TQEvent* ); -#endif -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQApplication( const TQApplication & ); - TQApplication &operator=( const TQApplication & ); -#endif - -private: - static TQEventLoop* currentEventLoop(); - -public: -#ifdef TQT_THREAD_SUPPORT - static TQThread* guiThread(); - static void threadTerminationHandler( TQThread * ); -#endif - static bool isGuiThread(); -}; - -inline int TQApplication::argc() const -{ - return app_argc; -} - -inline char **TQApplication::argv() const -{ - return app_argv; -} - -#ifndef TQT_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 TQT_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; -} - -#ifdef TQT_NO_TRANSLATION -// Simple versions -inline TQString TQApplication::translate( const char *, const char *sourceText, - const char *, Encoding encoding ) const -{ -#ifndef TQT_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 - diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp deleted file mode 100644 index db0fa0278..000000000 --- a/src/kernel/qapplication.cpp +++ /dev/null @@ -1,4969 +0,0 @@ -/**************************************************************************** -** -** Implementation 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. -** -**********************************************************************/ - -#include "tqobjectlist.h" -#include "ntqapplication.h" -#include "tqeventloop.h" -#include "tqeventloop_p.h" -#include "tqwidget.h" -#include "tqwidgetlist.h" -#include "tqwidgetintdict.h" -#include "tqptrdict.h" -#include "tqcleanuphandler.h" - -#include "tqtranslator.h" -#include "tqtextcodec.h" -#include "tqsessionmanager.h" -#include "tqdragobject.h" -#include "tqclipboard.h" -#include "tqcursor.h" -#include "tqstyle.h" -#include "tqstylefactory.h" -#include "tqfile.h" -#include "tqmessagebox.h" -#include "tqdir.h" -#include "tqfileinfo.h" -#ifdef TQ_WS_WIN -#include "tqinputcontext_p.h" -#endif -#include "tqfontdata_p.h" - -#if defined(TQT_THREAD_SUPPORT) -# include "tqmutex.h" -# include "tqthread.h" -# include -#endif // TQT_THREAD_SUPPORT - -#include - -#ifdef truncate -# undef truncate -#endif - -/*! - \class TQApplication ntqapplication.h - \brief The TQApplication class manages the GUI application's control - flow and main settings. - - \ingroup application - \mainclass - - It contains the main event loop, where all events from the window - system and other sources are processed and dispatched. It also - handles the application's initialization and finalization, and - provides session management. It also handles most system-wide and - application-wide settings. - - For any GUI application that uses TQt, there is precisely one - TQApplication object, no matter whether the application has 0, 1, 2 - or more windows at any time. - - The TQApplication object is accessible through the global pointer \c - tqApp. Its main areas of responsibility are: - \list - - \i It initializes the application with the user's desktop settings - such as palette(), font() and doubleClickInterval(). It keeps track - of these properties in case the user changes the desktop globally, for - example through some kind of control panel. - - \i It performs event handling, meaning that it receives events - from the underlying window system and dispatches them to the relevant - widgets. By using sendEvent() and postEvent() you can send your own - events to widgets. - - \i It parses common command line arguments and sets its internal - state accordingly. See the \link TQApplication::TQApplication() - constructor documentation\endlink below for more details about this. - - \i It defines the application's look and feel, which is - encapsulated in a TQStyle object. This can be changed at runtime - with setStyle(). - - \i It specifies how the application is to allocate colors. - See setColorSpec() for details. - - \i It provides localization of strings that are visible to the user - via translate(). - - \i It provides some magical objects like the desktop() and the - clipboard(). - - \i It knows about the application's windows. You can ask which - widget is at a certain position using widgetAt(), get a list of - topLevelWidgets() and closeAllWindows(), etc. - - \i It manages the application's mouse cursor handling, - see setOverrideCursor() and setGlobalMouseTracking(). - - \i On the X window system, it provides functions to flush and sync - the communication stream, see flushX() and syncX(). - - \i It provides support for sophisticated \link - session.html session management \endlink. This makes it possible - for applications to terminate gracefully when the user logs out, to - cancel a shutdown process if termination isn't possible and even to - preserve the entire application's state for a future session. See - isSessionRestored(), sessionId() and commitData() and saveState() - for details. - - \endlist - - The Application walk-through - example contains a typical complete main() that does the usual - things with TQApplication. - - Since the TQApplication object does so much initialization, it - must be created before any other objects related to the user - interface are created. - - Since it also deals with common command line arguments, it is - usually a good idea to create it \e before any interpretation or - modification of \c argv is done in the application itself. (Note - also that for X11, setMainWidget() may change the main widget - according to the \c -geometry option. To preserve this - functionality, you must set your defaults before setMainWidget() and - any overrides after.) - - \table - \header \i21 Groups of functions - \row - \i System settings - \i - desktopSettingsAware(), - setDesktopSettingsAware(), - cursorFlashTime(), - setCursorFlashTime(), - doubleClickInterval(), - setDoubleClickInterval(), - wheelScrollLines(), - setWheelScrollLines(), - palette(), - setPalette(), - font(), - setFont(), - fontMetrics(). - - \row - \i Event handling - \i - exec(), - processEvents(), - enter_loop(), - exit_loop(), - exit(), - quit(). - sendEvent(), - postEvent(), - sendPostedEvents(), - removePostedEvents(), - hasPendingEvents(), - notify(), - macEventFilter(), - x11EventFilter(), - x11ProcessEvent(), - winEventFilter(). - - \row - \i GUI Styles - \i - style(), - setStyle(), - polish(). - - \row - \i Color usage - \i - colorSpec(), - setColorSpec(), - - \row - \i Text handling - \i - installTranslator(), - removeTranslator() - translate(). - - \row - \i Widgets - \i - mainWidget(), - setMainWidget(), - allWidgets(), - topLevelWidgets(), - desktop(), - activePopupWidget(), - activeModalWidget(), - clipboard(), - focusWidget(), - winFocus(), - activeWindow(), - widgetAt(). - - \row - \i Advanced cursor handling - \i - hasGlobalMouseTracking(), - setGlobalMouseTracking(), - overrideCursor(), - setOverrideCursor(), - restoreOverrideCursor(). - - \row - \i X Window System synchronization - \i - flushX(), - syncX(). - - \row - \i Session management - \i - isSessionRestored(), - sessionId(), - commitData(), - saveState(). - - \row - \i Threading - \i - lock(), unlock(), locked(), tryLock(), - wakeUpGuiThread() - - \row - \i Miscellaneous - \i - closeAllWindows(), - startingUp(), - closingDown(), - type(). - \endtable - - \e {Non-GUI programs:} While TQt is not optimized or - designed for writing non-GUI programs, it's possible to use - \link tools.html some of its classes \endlink without creating a - TQApplication. This can be useful if you wish to share code between - a non-GUI server and a GUI client. - - \headerfile tqnamespace.h - \headerfile tqwindowdefs.h - \headerfile tqglobal.h -*/ - -/*! \enum TQt::HANDLE - \internal -*/ - -/*! - \enum TQApplication::Type - - \value Tty a console application - \value GuiClient a GUI client application - \value GuiServer a GUI server application -*/ - -/*! - \enum TQApplication::ColorSpec - - \value NormalColor the default color allocation policy - \value CustomColor the same as NormalColor for X11; allocates colors - to a palette on demand under Windows - \value ManyColor the right choice for applications that use thousands of - colors - - See setColorSpec() for full details. -*/ - -/* - The tqt_init() and tqt_cleanup() functions are implemented in the - qapplication_xyz.cpp file. -*/ - -void tqt_init( int *, char **, TQApplication::Type ); -void tqt_cleanup(); -#if defined(TQ_WS_X11) -void tqt_init( Display* dpy, TQt::HANDLE, TQt::HANDLE ); -void tqt_init( int *, char **, Display* dpy, TQt::HANDLE, TQt::HANDLE ); -#endif -TQ_EXPORT bool tqt_tryModalHelper( TQWidget *widget, TQWidget **rettop ); - -TQApplication *tqApp = 0; // global application object - -TQStyle *TQApplication::app_style = 0; // default application style -bool tqt_explicit_app_style = FALSE; // style explicitly set by programmer - -int TQApplication::app_cspec = TQApplication::NormalColor; -#ifndef TQT_NO_PALETTE -TQPalette *TQApplication::app_pal = 0; // default application palette -#endif -TQFont *TQApplication::app_font = 0; // default application font -bool tqt_app_has_font = FALSE; -#ifndef TQT_NO_CURSOR -TQCursor *TQApplication::app_cursor = 0; // default application cursor -#endif -int TQApplication::app_tracking = 0; // global mouse tracking -bool TQApplication::is_app_running = FALSE; // app starting up if FALSE -bool TQApplication::is_app_closing = FALSE; // app closing down if TRUE -int TQApplication::loop_level = 0; // event loop level -TQWidget *TQApplication::main_widget = 0; // main application widget -TQWidget *TQApplication::focus_widget = 0; // has keyboard input focus -TQWidget *TQApplication::active_window = 0; // toplevel with keyboard focus -bool TQApplication::obey_desktop_settings = TRUE; // use winsys resources -int TQApplication::cursor_flash_time = 1000; // text caret flash time -int TQApplication::mouse_double_click_time = 400; // mouse dbl click limit -#ifndef TQT_NO_WHEELEVENT -int TQApplication::wheel_scroll_lines = 3; // number of lines to scroll -#endif -bool tqt_is_gui_used; -bool TQ_EXPORT tqt_resolve_symlinks = TRUE; -bool TQ_EXPORT tqt_tab_all_widgets = TRUE; -TQRect tqt_maxWindowRect; -static int drag_time = 500; -static int drag_distance = 4; -static bool reverse_layout = FALSE; -TQSize TQApplication::app_strut = TQSize( 0,0 ); // no default application strut -bool TQApplication::animate_ui = TRUE; -bool TQApplication::animate_menu = FALSE; -bool TQApplication::fade_menu = FALSE; -bool TQApplication::animate_combo = FALSE; -bool TQApplication::animate_tooltip = FALSE; -bool TQApplication::fade_tooltip = FALSE; -bool TQApplication::animate_toolbox = FALSE; -bool TQApplication::widgetCount = FALSE; -TQApplication::Type tqt_appType=TQApplication::Tty; -#ifndef TQT_NO_COMPONENT -TQStringList *TQApplication::app_libpaths = 0; -#endif -bool TQApplication::metaComposeUnicode = FALSE; -int TQApplication::composedUnicode = 0; - -#ifdef TQT_THREAD_SUPPORT -TQMutex *TQApplication::tqt_mutex = 0; -TQMutex *tqt_sharedStringMutex = 0; -TQ_EXPORT TQMutex * tqt_sharedMetaObjectMutex = 0; - -#ifdef QT_USE_GLIBMAINLOOP -TQMutex *tqt_timerListMutex = 0; -#endif // QT_USE_GLIBMAINLOOP - -static TQt::HANDLE tqt_application_thread_id = 0; -TQ_EXPORT TQt::HANDLE tqt_get_application_thread_id() -{ - return tqt_application_thread_id; -} -#endif // TQT_THREAD_SUPPORT - -#ifndef TQT_THREAD_SUPPORT -TQEventLoop *TQApplication::eventloop = 0; // application event loop -#endif - -#ifdef TQT_THREAD_SUPPORT -TQEventLoop* TQApplication::currentEventLoop() { - TQThread* thread = TQThread::currentThreadObject(); - if (thread) { - if (thread->d) { - return thread->d->eventLoop; - } - } - return NULL; -} -#else -TQEventLoop* TQApplication::currentEventLoop() { - return TQApplication::eventloop; -} -#endif - -#ifndef TQT_NO_ACCEL -extern bool tqt_dispatchAccelEvent( TQWidget*, TQKeyEvent* ); // def in tqaccel.cpp -extern bool tqt_tryComposeUnicode( TQWidget*, TQKeyEvent* ); // def in tqaccel.cpp -#endif - -#if defined(QT_TABLET_SUPPORT) -bool chokeMouse = FALSE; -#endif - -void tqt_setMaxWindowRect(const TQRect& r) -{ - tqt_maxWindowRect = r; - // Re-resize any maximized windows - TQWidgetList* l = TQApplication::topLevelWidgets(); - if ( l ) { - TQWidget *w = l->first(); - while ( w ) { - if ( w->isVisible() && w->isMaximized() ) - { - w->showNormal(); //#### flicker - w->showMaximized(); - } - w = l->next(); - } - delete l; - } -} - -typedef void (*VFPTR)(); -typedef TQValueList TQVFuncList; -static TQVFuncList *postRList = 0; // list of post routines - -/*! - \relates TQApplication - - Adds a global routine that will be called from the TQApplication - destructor. This function is normally used to add cleanup routines - for program-wide functionality. - - The function given by \a p should take no arguments and return - nothing, like this: - \code - static int *global_ptr = 0; - - static void cleanup_ptr() - { - delete [] global_ptr; - global_ptr = 0; - } - - void init_ptr() - { - global_ptr = new int[100]; // allocate data - tqAddPostRoutine( cleanup_ptr ); // delete later - } - \endcode - - Note that for an application- or module-wide cleanup, - tqAddPostRoutine() is often not suitable. People have a tendency to - make such modules dynamically loaded, and then unload those modules - long before the TQApplication destructor is called, for example. - - For modules and libraries, using a reference-counted initialization - manager or TQt' parent-child delete mechanism may be better. Here is - an example of a private class which uses the parent-child mechanism - to call a cleanup function at the right time: - - \code - class MyPrivateInitStuff: public TQObject { - private: - MyPrivateInitStuff( TQObject * parent ): TQObject( parent) { - // initialization goes here - } - MyPrivateInitStuff * p; - - public: - static MyPrivateInitStuff * initStuff( TQObject * parent ) { - if ( !p ) - p = new MyPrivateInitStuff( parent ); - return p; - } - - ~MyPrivateInitStuff() { - // cleanup (the "post routine") goes here - } - } - \endcode - - By selecting the right parent widget/object, this can often be made - to clean up the module's data at the exact right moment. -*/ - -TQ_EXPORT void tqAddPostRoutine( TQtCleanUpFunction p) -{ - if ( !postRList ) { - postRList = new TQVFuncList; - TQ_CHECK_PTR( postRList ); - } - postRList->prepend( p ); -} - - -TQ_EXPORT void tqRemovePostRoutine( TQtCleanUpFunction p ) -{ - if ( !postRList ) return; - TQVFuncList::Iterator it = postRList->begin(); - while ( it != postRList->end() ) { - if ( *it == p ) { - postRList->remove( it ); - it = postRList->begin(); - } else { - ++it; - } - } -} - -// Default application palettes and fonts (per widget type) -TQAsciiDict *TQApplication::app_palettes = 0; -TQAsciiDict *TQApplication::app_fonts = 0; - -#ifndef TQT_NO_SESSIONMANAGER -TQString *TQApplication::session_key = 0; // ## session key. Should be a member in 4.0 -#endif -TQWidgetList *TQApplication::popupWidgets = 0; // has keyboard input focus - -TQDesktopWidget *tqt_desktopWidget = 0; // root window widgets -#ifndef TQT_NO_CLIPBOARD -TQClipboard *tqt_clipboard = 0; // global clipboard object -#endif -TQWidgetList * tqt_modal_stack=0; // stack of modal widgets - -#ifdef TQT_THREAD_SUPPORT - -// thread wrapper for the main() thread -class TQCoreApplicationThread : public TQThread -{ -public: - inline TQCoreApplicationThread() - { -#ifdef QT_CHECK_STATE - if ( tqt_gui_thread_self ) - tqWarning( "TQCoreApplicationThread: there should be exactly one main thread object" ); -#endif - tqt_gui_thread_self = this; - - TQThreadInstance::setCurrentThread(this); - - // thread should be running and not finished for the lifetime - // of the application (even if TQCoreApplication goes away) - d->running = true; - d->finished = false; - d->eventLoop = NULL; - } - - inline ~TQCoreApplicationThread() - { - tqt_gui_thread_self = nullptr; - - // avoid warning from TQThread - d->running = false; - // do some cleanup, namely clean up the thread-local storage associated with the GUI thread - TQThreadInstance::finishGuiThread(d); - } - - static TQCoreApplicationThread* self() { return tqt_gui_thread_self; } - -private: - inline void run() - { - // this function should never be called, it is implemented - // only so that we can instantiate the object - tqFatal("TQCoreApplicationThread: internal error"); - } - - static TQCoreApplicationThread* tqt_gui_thread_self; -}; - -TQCoreApplicationThread* TQCoreApplicationThread::tqt_gui_thread_self = nullptr; - -// construct exactly one instance of the core thread with static storage duration. Do it static -// rather than in the heap as we need it to be properly destroyed on the exit from the program. -static TQCoreApplicationThread tqt_main_thread; -#endif - -// Definitions for posted events -struct TQPostEvent { - TQPostEvent( TQObject *r, TQEvent *e ): receiver( r ), event( e ) {} - ~TQPostEvent() { delete event; } - TQObject *receiver; - TQEvent *event; -}; - -class TQ_EXPORT TQPostEventList : public TQPtrList -{ -public: - TQPostEventList(bool with_mutex = false) : TQPtrList(), m_mutex(nullptr) - { -#ifdef TQT_THREAD_SUPPORT - if (with_mutex) - { - m_mutex = new TQMutex(TRUE); - } -#endif - } - - ~TQPostEventList() - { - if (m_mutex) - { - delete m_mutex; - m_mutex = nullptr; - } - clear(); - } - - TQMutex* mutex() const { return m_mutex; } - -private: - TQMutex *m_mutex; - - TQPostEventList(const TQPostEventList &) = delete; - TQPostEventList &operator=(const TQPostEventList &) = delete; -}; - -class TQ_EXPORT TQPostEventListIt : public TQPtrListIterator -{ -public: - TQPostEventListIt( const TQPostEventList &l ) : TQPtrListIterator(l) {} - TQPostEventListIt &operator=(const TQPostEventListIt &i) -{ - return (TQPostEventListIt&)TQPtrListIterator::operator=(i); } -}; - -// The global list and its pointer are initialized in different functions -// to optimize access to the list pointer in normal usage -static TQPostEventList* InitGlobalPostedEventsList() -{ - static TQPostEventList _globalEventList(true); - _globalEventList.setAutoDelete(TRUE); - return &_globalEventList; -} - -static TQPostEventList* GlobalPostedEvents() -{ - static TQPostEventList *_globalPostedEvents = InitGlobalPostedEventsList(); - return _globalPostedEvents; -} - -uint qGlobalPostedEventsCount() -{ -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( GlobalPostedEvents()->mutex() ); -#endif // TQT_THREAD_SUPPORT - - return GlobalPostedEvents()->count(); -} - -#ifndef TQT_NO_PALETTE -TQPalette *tqt_std_pal = 0; - -void tqt_create_std_palette() -{ - if ( tqt_std_pal ) - delete tqt_std_pal; - - TQColor standardLightGray( 192, 192, 192 ); - TQColor light( 255, 255, 255 ); - TQColor dark( standardLightGray.dark( 150 ) ); - TQColorGroup std_act( TQt::black, standardLightGray, - light, dark, TQt::gray, - TQt::black, TQt::white ); - TQColorGroup std_dis( TQt::darkGray, standardLightGray, - light, dark, TQt::gray, - TQt::darkGray, std_act.background() ); - TQColorGroup std_inact( TQt::black, standardLightGray, - light, dark, TQt::gray, - TQt::black, TQt::white ); - tqt_std_pal = new TQPalette( std_act, std_dis, std_inact ); -} - -static void tqt_fix_tooltips() -{ - // No resources for this yet (unlike on Windows). - TQColorGroup cg( TQt::black, TQColor(255,255,220), - TQColor(96,96,96), TQt::black, TQt::black, - TQt::black, TQColor(255,255,220) ); - TQPalette pal( cg, cg, cg ); - TQApplication::setPalette( pal, TRUE, "TQTipLabel"); -} -#endif - -void TQApplication::process_cmdline( int* argcptr, char ** argv ) -{ - // process platform-indep command line - if ( !tqt_is_gui_used || !*argcptr) - return; - - int argc = *argcptr; - int i, j; - - j = 1; - for ( i=1; i= 0 ) { - if ( !session_key ) - session_key = new TQString; - *session_key = session_id.mid( p +1 ); - session_id = session_id.left( p ); - } - is_session_restored = TRUE; - } -#endif - } else if ( qstrcmp(arg, "-reverse") == 0 ) { - setReverseLayout( TRUE ); - } else if ( qstrcmp(arg, "-widgetcount") == 0 ) { - widgetCount = TRUE;; - } else { - argv[j++] = argv[i]; - } -#ifndef TQT_NO_STYLE - if ( !s.isEmpty() ) { - setStyle( s ); - } -#endif - } - - if(j < argc) { -#ifdef TQ_WS_MACX - static char* empty = "\0"; - argv[j] = empty; -#else - argv[j] = 0; -#endif - *argcptr = j; - } -} - -/*! - Initializes the window system and constructs an application object - with \a argc command line arguments in \a argv. - - The global \c tqApp pointer refers to this application object. Only - one application object should be created. - - This application object must be constructed before any \link - TQPaintDevice paint devices\endlink (including widgets, pixmaps, bitmaps - etc.). - - Note that \a argc and \a argv might be changed. TQt removes command - line arguments that it recognizes. The modified \a argc and \a argv - can also be accessed later with \c tqApp->argc() and \c tqApp->argv(). - The documentation for argv() contains a detailed description of how - to process command line arguments. - - TQt debugging options (not available if TQt was compiled with the - TQT_NO_DEBUG flag defined): - \list - \i -nograb, tells TQt that it must never grab the mouse or the keyboard. - \i -dograb (only under X11), running under a debugger can cause - an implicit -nograb, use -dograb to override. - \i -sync (only under X11), switches to synchronous mode for - debugging. - \endlist - - See \link debug.html Debugging Techniques \endlink for a more - detailed explanation. - - All TQt programs automatically support the following command line options: - \list - \i -reverse causes text to be formatted for right-to-left languages - rather than in the usual left-to-right direction. - \i -style= \e style, sets the application GUI style. Possible values - are \c motif, \c windows, and \c platinum. If you compiled TQt - with additional styles or have additional styles as plugins these - will be available to the \c -style command line option. - \i -style \e style, is the same as listed above. - \i -session= \e session, restores the application from an earlier - \link session.html session \endlink. - \i -session \e session, is the same as listed above. - \i -widgetcount, prints debug message at the end about number of widgets left - undestroyed and maximum number of widgets existed at the same time - \endlist - - The X11 version of TQt also supports some traditional X11 - command line options: - \list - \i -display \e display, sets the X display (default is $DISPLAY). - \i -geometry \e geometry, sets the client geometry of the - \link setMainWidget() main widget\endlink. - \i -fn or \c -font \e font, defines the application font. The - font should be specified using an X logical font description. - \i -bg or \c -background \e color, sets the default background color - and an application palette (light and dark shades are calculated). - \i -fg or \c -foreground \e color, sets the default foreground color. - \i -btn or \c -button \e color, sets the default button color. - \i -name \e name, sets the application name. - \i -title \e title, sets the application title (caption). - \i -visual \c TrueColor, forces the application to use a TrueColor visual - on an 8-bit display. - \i -ncols \e count, limits the number of colors allocated in the - color cube on an 8-bit display, if the application is using the - \c TQApplication::ManyColor color specification. If \e count is - 216 then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green, - and 6 of blue); for other values, a cube - approximately proportional to a 2x3x1 cube is used. - \i -cmap, causes the application to install a private color map - on an 8-bit display. - \endlist - - \sa argc(), argv() -*/ - -//######### BINARY COMPATIBILITY constructor -TQApplication::TQApplication( int &argc, char **argv ) -{ - construct( argc, argv, GuiClient, true ); -} - -/*! - Constructs an application object with \a argc command line arguments - in \a argv. If \a GUIenabled is TRUE, a GUI application is - constructed, otherwise a non-GUI (console) application is created. - - Set \a GUIenabled to FALSE for programs without a graphical user - interface that should be able to run without a window system. - - On X11, the window system is initialized if \a GUIenabled is TRUE. - If \a GUIenabled is FALSE, the application does not connect to the - X-server. - On Windows and Macintosh, currently the window system is always - initialized, regardless of the value of GUIenabled. This may change in - future versions of TQt. - - The following example shows how to create an application that - uses a graphical interface when available. - \code - int main( int argc, char **argv ) - { -#ifdef TQ_WS_X11 - bool useGUI = getenv( "DISPLAY" ) != 0; -#else - bool useGUI = TRUE; -#endif - TQApplication app(argc, argv, useGUI); - - if ( useGUI ) { - //start GUI version - ... - } else { - //start non-GUI version - ... - } - return app.exec(); - } -\endcode -*/ - -TQApplication::TQApplication( int &argc, char **argv, bool GUIenabled ) -{ - construct( argc, argv, GUIenabled ? GuiClient : Tty, true ); -} - -/*! - Constructs an application object with \a argc command line arguments - in \a argv. If \a GUIenabled is TRUE, a GUI application is - constructed, otherwise a non-GUI (console) application is created. - If \a SMEnabled is TRUE, session management support is enabled (default). - - Set \a GUIenabled to FALSE for programs without a graphical user - interface that should be able to run without a window system. - - Set \a SMEnabled to FALSE to disable session management. - Session management cannot be enabled at a later time if disabled here. - - On X11, the window system is initialized if \a GUIenabled is TRUE. - If \a GUIenabled is FALSE, the application does not connect to the - X-server. - On Windows and Macintosh, currently the window system is always - initialized, regardless of the value of GUIenabled. This may change in - future versions of TQt. - - The following example shows how to create an application that - uses a graphical interface when available. - \code - int main( int argc, char **argv ) - { -#ifdef TQ_WS_X11 - bool useGUI = getenv( "DISPLAY" ) != 0; -#else - bool useGUI = TRUE; -#endif - TQApplication app(argc, argv, useGUI); - - if ( useGUI ) { - //start GUI version - ... - } else { - //start non-GUI version - ... - } - return app.exec(); - } -\endcode -*/ - -TQApplication::TQApplication( int &argc, char **argv, bool GUIenabled, bool SMenabled ) -{ - construct( argc, argv, GUIenabled ? GuiClient : Tty, SMenabled ); -} - -/*! - Constructs an application object with \a argc command line arguments - in \a argv. -*/ -TQApplication::TQApplication( int &argc, char **argv, Type type ) -{ - construct( argc, argv, type, true ); -} - -TQ_EXPORT void tqt_ucm_initialize( TQApplication *theApp ) -{ - if ( tqApp ) - return; - int argc = theApp->argc(); - char **argv = theApp->argv(); - theApp->construct( argc, argv, tqApp->type(), true ); - - Q_ASSERT( tqApp == theApp ); -} - -void TQApplication::construct( int &argc, char **argv, Type type, bool enable_sm ) -{ - tqt_appType = type; - tqt_is_gui_used = (type != Tty); - init_precmdline(); - static const char *empty = ""; - if ( argc == 0 || argv == 0 ) { - argc = 0; - argv = (char **)∅ // ouch! careful with TQApplication::argv()! - } - app_argc = argc; - app_argv = argv; - - tqt_init( &argc, argv, type ); // Must be called before initialize() - process_cmdline( &argc, argv ); - initialize( argc, argv, enable_sm ); - if ( tqt_is_gui_used ) - tqt_maxWindowRect = desktop()->rect(); - if ( currentEventLoop() ) - currentEventLoop()->appStartingUp(); -} - -/*! - Returns the type of application, Tty, GuiClient or GuiServer. -*/ - -TQApplication::Type TQApplication::type() const -{ - return tqt_appType; -} - -#if defined(TQ_WS_X11) -/*! - Create an application, given an already open display \a dpy. If \a - visual and \a colormap are non-zero, the application will use those as - the default Visual and Colormap contexts. - - \warning TQt only supports TrueColor visuals at depths higher than 8 - bits-per-pixel. - - This is available only on X11. -*/ - -TQApplication::TQApplication( Display* dpy, HANDLE visual, HANDLE colormap ) -{ - static int aargc = 1; - // ### a string literal is a cont char* - // ### using it as a char* is wrong and could lead to segfaults - // ### if aargv is modified someday - static char *aargv[] = { (char*)"unknown", 0 }; - - app_argc = aargc; - app_argv = aargv; - - tqt_appType = GuiClient; - tqt_is_gui_used = TRUE; - tqt_appType = GuiClient; - init_precmdline(); - // ... no command line. - - if ( ! dpy ) { -#ifdef QT_CHECK_STATE - tqWarning( "TQApplication: invalid Display* argument." ); -#endif // QT_CHECK_STATE - - tqt_init( &aargc, aargv, GuiClient ); - } else { - tqt_init( dpy, visual, colormap ); - } - - initialize( aargc, aargv ); - - if ( tqt_is_gui_used ) - tqt_maxWindowRect = desktop()->rect(); - if ( currentEventLoop() ) - currentEventLoop()->appStartingUp(); -} - -/*! - Create an application, given an already open display \a dpy and using - \a argc command line arguments in \a argv. If \a - visual and \a colormap are non-zero, the application will use those as - the default Visual and Colormap contexts. - - \warning TQt only supports TrueColor visuals at depths higher than 8 - bits-per-pixel. - - This is available only on X11. - -*/ -TQApplication::TQApplication(Display *dpy, int argc, char **argv, - HANDLE visual, HANDLE colormap) -{ - tqt_appType = GuiClient; - tqt_is_gui_used = TRUE; - tqt_appType = GuiClient; - init_precmdline(); - - app_argc = argc; - app_argv = argv; - - if ( ! dpy ) { -#ifdef QT_CHECK_STATE - tqWarning( "TQApplication: invalid Display* argument." ); -#endif // QT_CHECK_STATE - - tqt_init( &argc, argv, GuiClient ); - } else { - tqt_init( &argc, argv, dpy, visual, colormap ); - } - - process_cmdline( &argc, argv ); - initialize(argc, argv); - - if ( tqt_is_gui_used ) - tqt_maxWindowRect = desktop()->rect(); - if ( currentEventLoop() ) - currentEventLoop()->appStartingUp(); -} - - -#endif // TQ_WS_X11 - -#ifdef TQT_THREAD_SUPPORT -TQThread* TQApplication::guiThread() { - return TQCoreApplicationThread::self(); -} - -bool TQApplication::isGuiThread() { - return (TQThread::currentThreadObject() == guiThread()); -} -#else -bool TQApplication::isGuiThread() { - return true; -} -#endif - -void TQApplication::init_precmdline() -{ - translators = 0; - is_app_closing = FALSE; -#ifndef TQT_NO_SESSIONMANAGER - is_session_restored = FALSE; -#endif -#if defined(QT_CHECK_STATE) - if ( tqApp ) - tqWarning( "TQApplication: There should be max one application object" ); -#endif - tqApp = (TQApplication*)this; -} - -/*! - Initializes the TQApplication object, called from the constructors. -*/ - -void TQApplication::initialize( int argc, char **argv, bool enable_sm ) -{ -#ifdef TQT_THREAD_SUPPORT - tqt_mutex = new TQMutex( TRUE ); - tqt_sharedStringMutex = new TQMutex( TRUE ); - tqt_sharedMetaObjectMutex = new TQMutex( TRUE ); -#ifdef QT_USE_GLIBMAINLOOP - tqt_timerListMutex = new TQMutex( TRUE ); -#endif // QT_USE_GLIBMAINLOOP - tqt_application_thread_id = TQThread::currentThread(); -#endif // TQT_THREAD_SUPPORT - - app_argc = argc; - app_argv = argv; - quit_now = FALSE; - quit_code = 0; - TQWidget::createMapper(); // create widget mapper -#ifndef TQT_NO_PALETTE - (void) palette(); // trigger creation of application palette -#endif - is_app_running = TRUE; // no longer starting up - -#ifndef TQT_NO_SESSIONMANAGER - if (enable_sm) { - // connect to the session manager - if ( !session_key ) - session_key = new TQString; - session_manager = new TQSessionManager( tqApp, session_id, *session_key ); - } - else { - session_manager = 0; - } -#endif - -} - - -/***************************************************************************** - Functions returning the active popup and modal widgets. - *****************************************************************************/ - -/*! - Returns the active popup widget. - - A popup widget is a special top level widget that sets the \c - WType_Popup widget flag, e.g. the TQPopupMenu widget. When the - application opens a popup widget, all events are sent to the popup. - Normal widgets and modal widgets cannot be accessed before the popup - widget is closed. - - Only other popup widgets may be opened when a popup widget is shown. - The popup widgets are organized in a stack. This function returns - the active popup widget at the top of the stack. - - \sa activeModalWidget(), topLevelWidgets() -*/ - -TQWidget *TQApplication::activePopupWidget() -{ - return popupWidgets ? popupWidgets->getLast() : 0; -} - - -/*! - Returns the active modal widget. - - A modal widget is a special top level widget which is a subclass of - TQDialog that specifies the modal parameter of the constructor as - TRUE. A modal widget must be closed before the user can continue - with other parts of the program. - - Modal widgets are organized in a stack. This function returns - the active modal widget at the top of the stack. - - \sa activePopupWidget(), topLevelWidgets() -*/ - -TQWidget *TQApplication::activeModalWidget() -{ - return tqt_modal_stack ? tqt_modal_stack->getFirst() : 0; -} - -/*! - Cleans up any window system resources that were allocated by this - application. Sets the global variable \c tqApp to 0. -*/ - -TQApplication::~TQApplication() -{ -#ifndef TQT_NO_CLIPBOARD - // flush clipboard contents - if ( tqt_clipboard ) { - TQCustomEvent event( TQEvent::Clipboard ); - TQApplication::sendEvent( tqt_clipboard, &event ); - } -#endif - - if ( currentEventLoop() ) - currentEventLoop()->appClosingDown(); - if ( postRList ) { - TQVFuncList::Iterator it = postRList->begin(); - while ( it != postRList->end() ) { // call post routines - (**it)(); - postRList->remove( it ); - it = postRList->begin(); - } - delete postRList; - postRList = 0; - } - - TQObject *tipmanager = child( "toolTipManager", "TQTipManager", FALSE ); - delete tipmanager; - - delete tqt_desktopWidget; - tqt_desktopWidget = 0; - is_app_closing = TRUE; - - // Due to hacks to speed up TQStyle engine (see git hash 523c1fd99) TQObjects now contain a - // reference to TQStyleControlElementData object which among other contain TQFont members. - // But for a proper cleanup all fonts should be destroyed before disconnecting from X11 (in - // tqt_cleanup()). So we will have to cleanup up the data explicitly. - cleanupControlElementData(); - -#ifndef TQT_NO_CLIPBOARD - delete tqt_clipboard; - tqt_clipboard = 0; -#endif - TQWidget::destroyMapper(); -#ifndef TQT_NO_PALETTE - delete tqt_std_pal; - tqt_std_pal = 0; - delete app_pal; - app_pal = 0; - delete app_palettes; - app_palettes = 0; -#endif - delete app_font; - app_font = 0; - delete app_fonts; - app_fonts = 0; -#ifndef TQT_NO_STYLE - delete app_style; - app_style = 0; -#endif -#ifndef TQT_NO_CURSOR - delete app_cursor; - app_cursor = 0; -#endif -#ifndef TQT_NO_TRANSLATION - delete translators; -#endif - -#ifndef TQT_NO_DRAGANDDROP - extern TQDragManager *qt_dnd_manager; - delete qt_dnd_manager; -#endif - - tqt_cleanup(); - -#ifndef TQT_NO_COMPONENT - delete app_libpaths; - app_libpaths = 0; -#endif - -#ifdef TQT_THREAD_SUPPORT - delete tqt_mutex; - tqt_mutex = 0; -#endif // TQT_THREAD_SUPPORT - - if( tqApp == this ) { - if ( postedEvents ) - removePostedEvents( this ); - tqApp = 0; - } - is_app_running = FALSE; - - if ( widgetCount ) { - tqDebug( "Widgets left: %i Max widgets: %i \n", TQWidget::instanceCounter, TQWidget::maxInstances ); - } -#ifndef TQT_NO_SESSIONMANAGER - if ( session_manager ) { - delete session_manager; - } - session_manager = 0; - if ( session_key ) { - delete session_key; - } - session_key = 0; -#endif //TQT_NO_SESSIONMANAGER - -#ifdef TQT_THREAD_SUPPORT - delete tqt_sharedMetaObjectMutex; - tqt_sharedMetaObjectMutex = 0; - delete tqt_sharedStringMutex; - tqt_sharedStringMutex = 0; -#ifdef QT_USE_GLIBMAINLOOP - delete tqt_timerListMutex; - tqt_timerListMutex = 0; -#endif // QT_USE_GLIBMAINLOOP -#endif // TQT_THREAD_SUPPORT - - tqt_explicit_app_style = FALSE; - tqt_app_has_font = FALSE; - app_tracking = 0; - obey_desktop_settings = TRUE; - cursor_flash_time = 1000; - mouse_double_click_time = 400; -#ifndef TQT_NO_WHEELEVENT - wheel_scroll_lines = 3; -#endif - drag_time = 500; - drag_distance = 4; - reverse_layout = FALSE; - app_strut = TQSize( 0, 0 ); - animate_ui = TRUE; - animate_menu = FALSE; - fade_menu = FALSE; - animate_combo = FALSE; - animate_tooltip = FALSE; - fade_tooltip = FALSE; - widgetCount = FALSE; -} - - -/*! - \fn int TQApplication::argc() const - - Returns the number of command line arguments. - - The documentation for argv() describes how to process command line - arguments. - - \sa argv(), TQApplication::TQApplication() -*/ - -/*! - \fn char **TQApplication::argv() const - - Returns the command line argument vector. - - \c argv()[0] is the program name, \c argv()[1] is the first - argument and \c argv()[argc()-1] is the last argument. - - A TQApplication object is constructed by passing \e argc and \e - argv from the \c main() function. Some of the arguments may be - recognized as TQt options and removed from the argument vector. For - example, the X11 version of TQt knows about \c -display, \c -font - and a few more options. - - Example: - \code - // showargs.cpp - displays program arguments in a list box - - #include - #include - - int main( int argc, char **argv ) - { - TQApplication a( argc, argv ); - TQListBox b; - a.setMainWidget( &b ); - for ( int i = 0; i < a.argc(); i++ ) // a.argc() == argc - b.insertItem( a.argv()[i] ); // a.argv()[i] == argv[i] - b.show(); - return a.exec(); - } - \endcode - - If you run \c{showargs -display unix:0 -font 9x15bold hello world} - under X11, the list box contains the three strings "showargs", - "hello" and "world". - - TQt provides a global pointer, \c tqApp, that points to the - TQApplication object, and through which you can access argc() and - argv() in functions other than main(). - - \sa argc(), TQApplication::TQApplication() -*/ - -/*! - \fn void TQApplication::setArgs( int argc, char **argv ) - \internal -*/ - - -#ifndef TQT_NO_STYLE - -static TQString *qt_style_override = 0; - -/*! - Returns the application's style object. - - \sa setStyle(), TQStyle -*/ -TQStyle& TQApplication::style() -{ -#ifndef TQT_NO_STYLE - if ( app_style ) - return *app_style; - if ( !tqt_is_gui_used ) - tqFatal( "No style available in non-gui applications!" ); - -#if defined(TQ_WS_X11) - if(!qt_style_override) - x11_initialize_style(); // run-time search for default style -#endif - if ( !app_style ) { - // Compile-time search for default style - // - TQString style; - if ( qt_style_override ) { - style = *qt_style_override; - delete qt_style_override; - qt_style_override = 0; - } else { -# if defined(TQ_WS_WIN) && defined(Q_OS_TEMP) - style = "PocketPC"; -#elif defined(TQ_WS_WIN) - if ( qWinVersion() >= TQt::WV_XP && qWinVersion() < TQt::WV_NT_based ) - style = "WindowsXP"; - else - style = "Windows"; // default styles for Windows -#elif defined(TQ_WS_X11) && defined(Q_OS_SOLARIS) - style = "CDE"; // default style for X11 on Solaris -#elif defined(TQ_WS_X11) && defined(Q_OS_IRIX) - style = "SGI"; // default style for X11 on IRIX -#elif defined(TQ_WS_X11) - style = "Motif"; // default style for X11 -#elif defined(TQ_WS_MAC) - style = "Macintosh"; // default style for all Mac's -#endif - } - app_style = TQStyleFactory::create( style ); - if ( !app_style && // platform default style not available, try alternatives - !(app_style = TQStyleFactory::create( "Windows" ) ) && - !(app_style = TQStyleFactory::create( "Platinum" ) ) && - !(app_style = TQStyleFactory::create( "MotifPlus" ) ) && - !(app_style = TQStyleFactory::create( "Motif" ) ) && - !(app_style = TQStyleFactory::create( "CDE" ) ) && - !(app_style = TQStyleFactory::create( "Aqua" ) ) && - !(app_style = TQStyleFactory::create( "SGI" ) ) && - !(app_style = TQStyleFactory::create( "Compact" ) ) -#ifndef TQT_NO_STRINGLIST - && !(app_style = TQStyleFactory::create( TQStyleFactory::keys()[0] ) ) -#endif - ) - tqFatal( "No %s style available!", style.latin1() ); - } - - TQPalette app_pal_copy ( *app_pal ); - app_style->polish( *app_pal ); - - if ( is_app_running && !is_app_closing && (*app_pal != app_pal_copy) ) { - TQEvent e( TQEvent::ApplicationPaletteChange ); - TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); - TQWidget *w; - while ( (w=it.current()) ) { // for all widgets... - ++it; - sendEvent( w, &e ); - } - } - - app_style->polish( tqApp ); -#endif - return *app_style; -} - -/*! - Sets the application's GUI style to \a style. Ownership of the style - object is transferred to TQApplication, so TQApplication will delete - the style object on application exit or when a new style is set. - - Example usage: - \code - TQApplication::setStyle( new TQWindowsStyle ); - \endcode - - When switching application styles, the color palette is set back to - the initial colors or the system defaults. This is necessary since - certain styles have to adapt the color palette to be fully - style-guide compliant. - - \sa style(), TQStyle, setPalette(), desktopSettingsAware() -*/ -void TQApplication::setStyle( TQStyle *style ) -{ - TQStyle* old = app_style; - app_style = style; -#ifdef TQ_WS_X11 - tqt_explicit_app_style = TRUE; -#endif // TQ_WS_X11 - - if ( startingUp() ) { - delete old; - return; - } - - // clean up the old style - if (old) { - if ( is_app_running && !is_app_closing ) { - TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); - TQWidget *w; - while ( (w=it.current()) ) { // for all widgets... - ++it; - if ( !w->testWFlags(WType_Desktop) && // except desktop - w->testWState(WState_Polished) ) { // has been polished - old->unPolish(w); - } - } - } - old->unPolish( tqApp ); - } - - // take care of possible palette requirements of certain gui - // styles. Do it before polishing the application since the style - // might call TQApplication::setStyle() itself - if ( !tqt_std_pal ) - tqt_create_std_palette(); - TQPalette tmpPal = *tqt_std_pal; - setPalette( tmpPal, TRUE ); - - // initialize the application with the new style - app_style->polish( tqApp ); - - // re-polish existing widgets if necessary - if (old) { - if ( is_app_running && !is_app_closing ) { - TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); - TQWidget *w; - while ( (w=it.current()) ) { // for all widgets... - ++it; - if ( !w->testWFlags(WType_Desktop) ) { // except desktop - if ( w->testWState(WState_Polished) ) - app_style->polish(w); // repolish - w->styleChange( *old ); - if ( w->isVisible() ){ - w->update(); - } - } - } - } - delete old; - } -} - -/*! - \overload - - Requests a TQStyle object for \a style from the TQStyleFactory. - - The string must be one of the TQStyleFactory::keys(), typically one - of "windows", "motif", "cde", "motifplus", "platinum", "sgi" and - "compact". Depending on the platform, "windowsxp", "aqua" or - "macintosh" may be available. - - A later call to the TQApplication constructor will override the - requested style when a "-style" option is passed in as a commandline - parameter. - - Returns 0 if an unknown \a style is passed, otherwise the TQStyle object - returned is set as the application's GUI style. -*/ -TQStyle* TQApplication::setStyle( const TQString& style ) -{ -#ifdef TQ_WS_X11 - tqt_explicit_app_style = TRUE; -#endif // TQ_WS_X11 - - if ( startingUp() ) { - if(qt_style_override) - *qt_style_override = style; - else - qt_style_override = new TQString(style); - return 0; - } - TQStyle *s = TQStyleFactory::create( style ); - if ( !s ) - return 0; - - setStyle( s ); - return s; -} - -#endif - - -#if 1 /* OBSOLETE */ - -TQApplication::ColorMode TQApplication::colorMode() -{ - return (TQApplication::ColorMode)app_cspec; -} - -void TQApplication::setColorMode( TQApplication::ColorMode mode ) -{ - app_cspec = mode; -} -#endif - - -/*! - Returns the color specification. - \sa TQApplication::setColorSpec() - */ - -int TQApplication::colorSpec() -{ - return app_cspec; -} - -/*! - Sets the color specification for the application to \a spec. - - The color specification controls how the application allocates colors - when run on a display with a limited amount of colors, e.g. 8 bit / 256 - color displays. - - The color specification must be set before you create the TQApplication - object. - - The options are: - \list - \i TQApplication::NormalColor. - This is the default color allocation strategy. Use this option if - your application uses buttons, menus, texts and pixmaps with few - colors. With this option, the application uses system global - colors. This works fine for most applications under X11, but on - Windows machines it may cause dithering of non-standard colors. - \i TQApplication::CustomColor. - Use this option if your application needs a small number of custom - colors. On X11, this option is the same as NormalColor. On Windows, TQt - creates a Windows palette, and allocates colors to it on demand. - \i TQApplication::ManyColor. - Use this option if your application is very color hungry - (e.g. it requires thousands of colors). - Under X11 the effect is: - \list - \i For 256-color displays which have at best a 256 color true color - visual, the default visual is used, and colors are allocated - from a color cube. The color cube is the 6x6x6 (216 color) "Web - palette"*, but the number of colors can be changed - by the \e -ncols option. The user can force the application to - use the true color visual with the \link - TQApplication::TQApplication() -visual \endlink option. - \i For 256-color displays which have a true color visual with more - than 256 colors, use that visual. Silicon Graphics X servers - have this feature, for example. They provide an 8 bit visual - by default but can deliver true color when asked. - \endlist - On Windows, TQt creates a Windows palette, and fills it with a color cube. - \endlist - - Be aware that the CustomColor and ManyColor choices may lead to colormap - flashing: The foreground application gets (most) of the available - colors, while the background windows will look less attractive. - - Example: - \code - int main( int argc, char **argv ) - { - TQApplication::setColorSpec( TQApplication::ManyColor ); - TQApplication a( argc, argv ); - ... - } - \endcode - - TQColor provides more functionality for controlling color allocation and - freeing up certain colors. See TQColor::enterAllocContext() for more - information. - - To check what mode you end up with, call TQColor::numBitPlanes() once - the TQApplication object exists. A value greater than 8 (typically - 16, 24 or 32) means true color. - - * The color cube used by TQt has 216 colors whose red, - green, and blue components always have one of the following values: - 0x00, 0x33, 0x66, 0x99, 0xCC, or 0xFF. - - \sa colorSpec(), TQColor::numBitPlanes(), TQColor::enterAllocContext() */ - -void TQApplication::setColorSpec( int spec ) -{ -#if defined(QT_CHECK_STATE) - if ( tqApp ) { - tqWarning( "TQApplication::setColorSpec: This function must be " - "called before the TQApplication object is created" ); - } -#endif - app_cspec = spec; -} - -/*! - \fn TQSize TQApplication::globalStrut() - - Returns the application's global strut. - - The strut is a size object whose dimensions are the minimum that any - GUI element that the user can interact with should have. For example - no button should be resized to be smaller than the global strut size. - - \sa setGlobalStrut() -*/ - -/*! - Sets the application's global strut to \a strut. - - The strut is a size object whose dimensions are the minimum that any - GUI element that the user can interact with should have. For example - no button should be resized to be smaller than the global strut size. - - The strut size should be considered when reimplementing GUI controls - that may be used on touch-screens or similar IO-devices. - - Example: - \code - TQSize& WidgetClass::sizeHint() const - { - return TQSize( 80, 25 ).expandedTo( TQApplication::globalStrut() ); - } - \endcode - - \sa globalStrut() -*/ - -void TQApplication::setGlobalStrut( const TQSize& strut ) -{ - app_strut = strut; -} - -#if defined( TQ_WS_WIN ) || defined( TQ_WS_MAC ) -extern const char *tqAppFileName(); -#endif - -#ifndef TQT_NO_DIR -#ifndef TQ_WS_WIN -static TQString resolveSymlinks( const TQString& path, int depth = 0 ) -{ - bool foundLink = FALSE; - TQString linkTarget; - TQString part = path; - int slashPos = path.length(); - - // too deep; we give up - if ( depth == 128 ) - return TQString::null; - - do { - part = part.left( slashPos ); - TQFileInfo fileInfo( part ); - if ( fileInfo.isSymLink() ) { - foundLink = TRUE; - linkTarget = fileInfo.readLink(); - break; - } - } while ( (slashPos = part.findRev('/')) != -1 ); - - if ( foundLink ) { - TQString path2; - if ( linkTarget[0] == '/' ) { - path2 = linkTarget; - if ( slashPos < (int) path.length() ) - path2 += "/" + path.right( path.length() - slashPos - 1 ); - } else { - TQString relPath; - relPath = part.left( part.findRev('/') + 1 ) + linkTarget; - if ( slashPos < (int) path.length() ) { - if ( !linkTarget.endsWith( "/" ) ) - relPath += "/"; - relPath += path.right( path.length() - slashPos - 1 ); - } - path2 = TQDir::current().absFilePath( relPath ); - } - path2 = TQDir::cleanDirPath( path2 ); - return resolveSymlinks( path2, depth + 1 ); - } else { - return path; - } -} -#endif // TQ_WS_WIN - -/*! - Returns the directory that contains the application executable. - - For example, if you have installed TQt in the \c{C:\Trolltech\TQt} - directory, and you run the \c{demo} example, this function will - return "C:/Trolltech/TQt/examples/demo". - - On Mac OS X this will point to the directory actually containing the - executable, which may be inside of an application bundle (if the - application is bundled). - - \warning On Unix, this function assumes that argv[0] contains the file - name of the executable (which it normally does). It also assumes that - the current directory hasn't been changed by the application. - - \sa applicationFilePath() -*/ -TQString TQApplication::applicationDirPath() -{ - return TQFileInfo( applicationFilePath() ).dirPath(); -} - -/*! - Returns the file path of the application executable. - - For example, if you have installed TQt in the \c{C:\Trolltech\TQt} - directory, and you run the \c{demo} example, this function will - return "C:/Trolltech/TQt/examples/demo/demo.exe". - - \warning On Unix, this function assumes that argv[0] contains the file - name of the executable (which it normally does). It also assumes that - the current directory hasn't been changed by the application. - - \sa applicationDirPath() -*/ -TQString TQApplication::applicationFilePath() -{ -#if defined( TQ_WS_WIN ) - TQFileInfo filePath; - QT_WA({ - WCHAR module_name[256]; - GetModuleFileNameW(0, module_name, sizeof(module_name)); - filePath = TQString::fromUcs2((const unsigned short *)module_name); - }, { - char module_name[256]; - GetModuleFileNameA(0, module_name, sizeof(module_name)); - filePath = TQString::fromLocal8Bit(module_name); - }); - - return filePath.filePath(); -#elif defined( TQ_WS_MAC ) - return TQDir::cleanDirPath( TQFile::decodeName( tqAppFileName() ) ); -#else - TQString argv0 = TQFile::decodeName( argv()[0] ); - TQString absPath; - - if ( argv0[0] == '/' ) { - /* - If argv0 starts with a slash, it is already an absolute - file path. - */ - absPath = argv0; - } else if ( argv0.find('/') != -1 ) { - /* - If argv0 contains one or more slashes, it is a file path - relative to the current directory. - */ - absPath = TQDir::current().absFilePath( argv0 ); - } else { - /* - Otherwise, the file path has to be determined using the - PATH environment variable. - */ - char *pEnv = getenv( "PATH" ); - TQStringList paths( TQStringList::split(TQChar(':'), pEnv) ); - TQStringList::const_iterator p = paths.begin(); - while ( p != paths.end() ) { - TQString candidate = TQDir::current().absFilePath( *p + "/" + argv0 ); - if ( TQFile::exists(candidate) ) { - absPath = candidate; - break; - } - ++p; - } - } - - absPath = TQDir::cleanDirPath( absPath ); - if ( TQFile::exists(absPath) ) { - return resolveSymlinks( absPath ); - } else { - return TQString::null; - } -#endif -} -#endif // TQT_NO_DIR - -#ifndef TQT_NO_COMPONENT - -/*! - Returns a list of paths that the application will search when - dynamically loading libraries. - The installation directory for plugins is the only entry if no - paths have been set. The default installation directory for plugins - is \c INSTALL/plugins, where \c INSTALL is the directory where TQt was - installed. The directory of the application executable (NOT the - working directory) is also added to the plugin paths. - - If you want to iterate over the list, you should iterate over a - copy, e.g. - \code - TQStringList list = app.libraryPaths(); - TQStringList::Iterator it = list.begin(); - while( it != list.end() ) { - myProcessing( *it ); - ++it; - } - \endcode - - See the \link plugins-howto.html plugins documentation\endlink for a - description of how the library paths are used. - - \sa setLibraryPaths(), addLibraryPath(), removeLibraryPath(), TQLibrary -*/ -TQStringList TQApplication::libraryPaths() -{ - if ( !app_libpaths ) { - app_libpaths = new TQStringList; - TQString installPathPlugins = TQString::fromLocal8Bit(tqInstallPathPlugins()); - if ( TQFile::exists(installPathPlugins) ) { -#ifdef TQ_WS_WIN - installPathPlugins.replace('\\', '/'); -#endif - app_libpaths->append(installPathPlugins); - } - - TQString app_location; - if (tqApp) - app_location = tqApp->applicationFilePath(); -#ifdef TQ_WS_WIN - else { - app_location = TQString(tqAppFileName()); - app_location.replace('\\', '/'); - } -#endif - if (!app_location.isEmpty()) { - app_location.truncate( app_location.findRev( '/' ) ); - if ( app_location != tqInstallPathPlugins() && TQFile::exists( app_location ) ) - app_libpaths->append( app_location ); - } - } - return *app_libpaths; -} - - -/*! - Sets the list of directories to search when loading libraries to \a paths. - All existing paths will be deleted and the path list will consist of the - paths given in \a paths. - - \sa libraryPaths(), addLibraryPath(), removeLibraryPath(), TQLibrary - */ -void TQApplication::setLibraryPaths( const TQStringList &paths ) -{ - delete app_libpaths; - app_libpaths = new TQStringList( paths ); -} - -/*! - Append \a path to the end of the library path list. If \a path is - empty or already in the path list, the path list is not changed. - - The default path list consists of a single entry, the installation - directory for plugins. The default installation directory for plugins - is \c INSTALL/plugins, where \c INSTALL is the directory where TQt was - installed. - - \sa removeLibraryPath(), libraryPaths(), setLibraryPaths() - */ -void TQApplication::addLibraryPath( const TQString &path ) -{ - if ( path.isEmpty() ) - return; - - // make sure that library paths is initialized - libraryPaths(); - - if ( !app_libpaths->contains( path ) ) - app_libpaths->prepend( path ); -} - -/*! - Removes \a path from the library path list. If \a path is empty or not - in the path list, the list is not changed. - - \sa addLibraryPath(), libraryPaths(), setLibraryPaths() -*/ -void TQApplication::removeLibraryPath( const TQString &path ) -{ - if ( path.isEmpty() ) - return; - - // make sure that library paths is initialized - libraryPaths(); - - if ( app_libpaths->contains( path ) ) - app_libpaths->remove( path ); -} -#endif //TQT_NO_COMPONENT - -/*! - Returns the application palette. - - If a widget is passed in \a w, the default palette for the - widget's class is returned. This may or may not be the application - palette. In most cases there isn't a special palette for certain - types of widgets, but one notable exception is the popup menu under - Windows, if the user has defined a special background color for - menus in the display settings. - - \sa setPalette(), TQWidget::palette() -*/ -#ifndef TQT_NO_PALETTE -TQPalette TQApplication::palette(const TQWidget* w) -{ -#if defined(QT_CHECK_STATE) - if ( !tqApp ) - tqWarning( "TQApplication::palette: This function can only be " - "called after the TQApplication object has been created" ); -#endif - if ( !app_pal ) { - if ( !tqt_std_pal ) - tqt_create_std_palette(); - app_pal = new TQPalette( *tqt_std_pal ); - tqt_fix_tooltips(); - } - - if ( w && app_palettes ) { - TQPalette* wp = app_palettes->find( w->className() ); - if ( wp ) - return *wp; - TQAsciiDictIterator it( *app_palettes ); - const char* name; - while ( (name=it.currentKey()) != 0 ) { - if ( w->inherits( name ) ) - return *it.current(); - ++it; - } - } - return *app_pal; -} - -TQPalette TQApplication::palette(TQStringList objectTypeList) -{ -#if defined(QT_CHECK_STATE) - if ( !tqApp ) - tqWarning( "TQApplication::palette: This function can only be " - "called after the TQApplication object has been created" ); -#endif - if ( !app_pal ) { - if ( !tqt_std_pal ) - tqt_create_std_palette(); - app_pal = new TQPalette( *tqt_std_pal ); - tqt_fix_tooltips(); - } - - if ( (objectTypeList.count() > 0) && app_palettes ) { - TQPalette* wp = app_palettes->find( objectTypeList[objectTypeList.count()-1] ); - if ( wp ) { - return *wp; - } - TQAsciiDictIterator it( *app_palettes ); - const char* name; - while ( (name=it.currentKey()) != 0 ) { - if ( objectTypeList.contains(name) ) { - return *it.current(); - } - ++it; - } - } - return *app_pal; -} - -/*! - Changes the default application palette to \a palette. If \a - informWidgets is TRUE, then existing widgets are informed about the - change and may adjust themselves to the new application - setting. If \a informWidgets is FALSE, the change only affects newly - created widgets. - - If \a className is passed, the change applies only to widgets that - inherit \a className (as reported by TQObject::inherits()). If - \a className is left 0, the change affects all widgets, thus overriding - any previously set class specific palettes. - - The palette may be changed according to the current GUI style in - TQStyle::polish(). - - \sa TQWidget::setPalette(), palette(), TQStyle::polish() -*/ - -void TQApplication::setPalette( const TQPalette &palette, bool informWidgets, - const char* className ) -{ - TQPalette pal = palette; - TQPalette *oldpal = 0; -#ifndef TQT_NO_STYLE - if ( !startingUp() ) // on startup this has been done already - tqApp->style().polish( pal ); // NB: non-const reference -#endif - bool all = FALSE; - if ( !className ) { - if ( !app_pal ) { - app_pal = new TQPalette( pal ); - TQ_CHECK_PTR( app_pal ); - } else { - *app_pal = pal; - } - all = app_palettes != 0; - delete app_palettes; - app_palettes = 0; - tqt_fix_tooltips(); - } else { - if ( !app_palettes ) { - app_palettes = new TQAsciiDict; - TQ_CHECK_PTR( app_palettes ); - app_palettes->setAutoDelete( TRUE ); - } - oldpal = app_palettes->find( className ); - app_palettes->insert( className, new TQPalette( pal ) ); - } - if ( informWidgets && is_app_running && !is_app_closing ) { - if ( !oldpal || ( *oldpal != pal ) ) { - TQEvent e( TQEvent::ApplicationPaletteChange ); - TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); - TQWidget *w; - while ( (w=it.current()) ) { // for all widgets... - ++it; - if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class - sendEvent( w, &e ); - } - } - } -} - -#endif // TQT_NO_PALETTE - -/*! - Returns the default font for the widget \a w, or the default - application font if \a w is 0. - - \sa setFont(), fontMetrics(), TQWidget::font() -*/ - -TQFont TQApplication::font( const TQWidget *w ) -{ - if ( w && app_fonts ) { - TQFont* wf = app_fonts->find( w->className() ); - if ( wf ) - return *wf; - TQAsciiDictIterator it( *app_fonts ); - const char* name; - while ( (name=it.currentKey()) != 0 ) { - if ( w->inherits( name ) ) - return *it.current(); - ++it; - } - } - if ( !app_font ) { - app_font = new TQFont( "Helvetica" ); - TQ_CHECK_PTR( app_font ); - } - return *app_font; -} - -/*! Changes the default application font to \a font. If \a - informWidgets is TRUE, then existing widgets are informed about the - change and may adjust themselves to the new application - setting. If \a informWidgets is FALSE, the change only affects newly - created widgets. If \a className is passed, the change applies only - to classes that inherit \a className (as reported by - TQObject::inherits()). - - On application start-up, the default font depends on the window - system. It can vary depending on both the window system version and - the locale. This function lets you override the default font; but - overriding may be a bad idea because, for example, some locales need - extra-large fonts to support their special characters. - - \sa font(), fontMetrics(), TQWidget::setFont() -*/ - -void TQApplication::setFont( const TQFont &font, bool informWidgets, - const char* className ) -{ - bool all = FALSE; - if ( !className ) { - tqt_app_has_font = TRUE; - if ( !app_font ) { - app_font = new TQFont( font ); - TQ_CHECK_PTR( app_font ); - } else { - *app_font = font; - } - - // make sure the application font is complete - app_font->detach(); - app_font->d->mask = TQFontPrivate::Complete; - - all = app_fonts != 0; - delete app_fonts; - app_fonts = 0; - } else { - if (!app_fonts){ - app_fonts = new TQAsciiDict; - TQ_CHECK_PTR( app_fonts ); - app_fonts->setAutoDelete( TRUE ); - } - TQFont* fnt = new TQFont(font); - TQ_CHECK_PTR( fnt ); - app_fonts->insert(className, fnt); - } - if ( informWidgets && is_app_running && !is_app_closing ) { - TQEvent e( TQEvent::ApplicationFontChange ); - TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); - TQWidget *w; - while ( (w=it.current()) ) { // for all widgets... - ++it; - if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class - sendEvent( w, &e ); - } - } -} - - -/*! - Initialization of the appearance of the widget \a w \e before it is first - shown. - - Usually widgets call this automatically when they are polished. It - may be used to do some style-based central customization of widgets. - - Note that you are not limited to the public functions of TQWidget. - Instead, based on meta information like TQObject::className() you are - able to customize any kind of widget. - - \sa TQStyle::polish(), TQWidget::polish(), setPalette(), setFont() -*/ - -void TQApplication::polish( TQWidget *w ) -{ -#ifndef TQT_NO_STYLE - w->style().polish( w ); -#endif -} - - -/*! - Returns a list of the top level widgets in the application. - - The list is created using \c new and must be deleted by the caller. - - The list is empty (TQPtrList::isEmpty()) if there are no top level - widgets. - - Note that some of the top level widgets may be hidden, for example - the tooltip if no tooltip is currently shown. - - Example: - \code - // Show all hidden top level widgets. - TQWidgetList *list = TQApplication::topLevelWidgets(); - TQWidgetListIt it( *list ); // iterate over the widgets - TQWidget * w; - while ( (w=it.current()) != 0 ) { // for each top level widget... - ++it; - if ( !w->isVisible() ) - w->show(); - } - delete list; // delete the list, not the widgets - \endcode - - \warning Delete the list as soon you have finished using it. - The widgets in the list may be deleted by someone else at any time. - - \sa allWidgets(), TQWidget::isTopLevel(), TQWidget::isVisible(), - TQPtrList::isEmpty() -*/ - -TQWidgetList *TQApplication::topLevelWidgets() -{ - return TQWidget::tlwList(); -} - -/*! - Returns a list of all the widgets in the application. - - The list is created using \c new and must be deleted by the caller. - - The list is empty (TQPtrList::isEmpty()) if there are no widgets. - - Note that some of the widgets may be hidden. - - Example that updates all widgets: - \code - TQWidgetList *list = TQApplication::allWidgets(); - TQWidgetListIt it( *list ); // iterate over the widgets - TQWidget * w; - while ( (w=it.current()) != 0 ) { // for each widget... - ++it; - w->update(); - } - delete list; // delete the list, not the widgets - \endcode - - The TQWidgetList class is defined in the \c tqwidgetlist.h header - file. - - \warning Delete the list as soon as you have finished using it. - The widgets in the list may be deleted by someone else at any time. - - \sa topLevelWidgets(), TQWidget::isVisible(), TQPtrList::isEmpty(), -*/ - -TQWidgetList *TQApplication::allWidgets() -{ - return TQWidget::wList(); -} - -/*! - \fn TQWidget *TQApplication::focusWidget() const - - Returns the application widget that has the keyboard input focus, or - 0 if no widget in this application has the focus. - - \sa TQWidget::setFocus(), TQWidget::hasFocus(), activeWindow() -*/ - -/*! - \fn TQWidget *TQApplication::activeWindow() const - - Returns the application top-level window that has the keyboard input - focus, or 0 if no application window has the focus. Note that - there might be an activeWindow() even if there is no focusWidget(), - for example if no widget in that window accepts key events. - - \sa TQWidget::setFocus(), TQWidget::hasFocus(), focusWidget() -*/ - -/*! - Returns display (screen) font metrics for the application font. - - \sa font(), setFont(), TQWidget::fontMetrics(), TQPainter::fontMetrics() -*/ - -TQFontMetrics TQApplication::fontMetrics() -{ - return desktop()->fontMetrics(); -} - - - -/*! - Tells the application to exit with return code 0 (success). - Equivalent to calling TQApplication::exit( 0 ). - - It's common to connect the lastWindowClosed() signal to quit(), and - you also often connect e.g. TQButton::clicked() or signals in - TQAction, TQPopupMenu or TQMenuBar to it. - - Example: - \code - TQPushButton *quitButton = new TQPushButton( "Quit" ); - connect( quitButton, TQ_SIGNAL(clicked()), tqApp, TQ_SLOT(quit()) ); - \endcode - - \sa exit() aboutToQuit() lastWindowClosed() TQAction -*/ - -void TQApplication::quit() -{ - TQApplication::exit( 0 ); -} - - -/*! - Closes all top-level windows. - - This function is particularly useful for applications with many - top-level windows. It could, for example, be connected to a "Quit" - entry in the file menu as shown in the following code example: - - \code - // the "Quit" menu entry should try to close all windows - TQPopupMenu* file = new TQPopupMenu( this ); - file->insertItem( "&Quit", tqApp, TQ_SLOT(closeAllWindows()), CTRL+Key_Q ); - - // when the last window is closed, the application should quit - connect( tqApp, TQ_SIGNAL( lastWindowClosed() ), tqApp, TQ_SLOT( quit() ) ); - \endcode - - The windows are closed in random order, until one window does not - accept the close event. - - \sa TQWidget::close(), TQWidget::closeEvent(), lastWindowClosed(), - quit(), topLevelWidgets(), TQWidget::isTopLevel() - - */ -void TQApplication::closeAllWindows() -{ - bool did_close = TRUE; - TQWidget *w; - while((w = activeModalWidget()) && did_close) { - if(w->isHidden()) - break; - did_close = w->close(); - } - TQWidgetList *list = TQApplication::topLevelWidgets(); - for ( w = list->first(); did_close && w; ) { - if ( !w->isHidden() ) { - did_close = w->close(); - delete list; - list = TQApplication::topLevelWidgets(); - w = list->first(); - } else { - w = list->next(); - } - } - delete list; -} - -/*! - Displays a simple message box about TQt. The message includes the - version number of TQt being used by the application. - - This is useful for inclusion in the Help menu of an application. - See the examples/menu/menu.cpp example. - - This function is a convenience slot for TQMessageBox::aboutTQt(). -*/ -void TQApplication::aboutTQt() -{ -#ifndef TQT_NO_MESSAGEBOX - TQMessageBox::aboutTQt( mainWidget() ); -#endif // TQT_NO_MESSAGEBOX -} - - -/*! - \fn void TQApplication::lastWindowClosed() - - This signal is emitted when the user has closed the last - top level window. - - The signal is very useful when your application has many top level - widgets but no main widget. You can then connect it to the quit() - slot. - - For convenience, this signal is \e not emitted for transient top level - widgets such as popup menus and dialogs. - - \sa mainWidget(), topLevelWidgets(), TQWidget::isTopLevel(), TQWidget::close() -*/ - -/*! - \fn void TQApplication::aboutToQuit() - - This signal is emitted when the application is about to quit the - main event loop, e.g. when the event loop level drops to zero. - This may happen either after a call to quit() from inside the - application or when the users shuts down the entire desktop session. - - The signal is particularly useful if your application has to do some - last-second cleanup. Note that no user interaction is possible in - this state. - - \sa quit() -*/ - - -/*! - \fn void TQApplication::guiThreadAwake() - - This signal is emitted after the event loop returns from a function - that could block. - - \sa wakeUpGuiThread() -*/ - - -/*! - \fn bool TQApplication::sendEvent( TQObject *receiver, TQEvent *event ) - - Sends event \a event directly to receiver \a receiver, using the - notify() function. Returns the value that was returned from the event - handler. - - The event is \e not deleted when the event has been sent. The normal - approach is to create the event on the stack, e.g. - \code - TQMouseEvent me( TQEvent::MouseButtonPress, pos, 0, 0 ); - TQApplication::sendEvent( mainWindow, &me ); - \endcode - If you create the event on the heap you must delete it. - - \sa postEvent(), notify() -*/ - -bool TQApplication::sendEvent( TQObject *receiver, TQEvent *event ) { - if ( event ) event->spont = FALSE; - return tqApp ? tqApp->notify( receiver, event ) : FALSE; -} - -bool TQApplication::sendSpontaneousEvent( TQObject *receiver, TQEvent *event ) { - if ( event ) event->spont = TRUE; - return tqApp ? tqApp->notify( receiver, event ) : FALSE; -} - -/*! - Sends event \a e to \a receiver: \a {receiver}->event(\a e). - Returns the value that is returned from the receiver's event handler. - - For certain types of events (e.g. mouse and key events), - the event will be propagated to the receiver's parent and so on up to - the top-level object if the receiver is not interested in the event - (i.e., it returns FALSE). - - There are five different ways that events can be processed; - reimplementing this virtual function is just one of them. All five - approaches are listed below: - \list 1 - \i Reimplementing this function. This is very powerful, providing - complete control; but only one subclass can be tqApp. - - \i Installing an event filter on tqApp. Such an event filter is able - to process all events for all widgets, so it's just as powerful as - reimplementing notify(); furthermore, it's possible to have more - than one application-global event filter. Global event filters even - see mouse events for \link TQWidget::isEnabled() disabled - widgets, \endlink and if \link setGlobalMouseTracking() global mouse - tracking \endlink is enabled, as well as mouse move events for all - widgets. - - \i Reimplementing TQObject::event() (as TQWidget does). If you do - this you get Tab key presses, and you get to see the events before - any widget-specific event filters. - - \i Installing an event filter on the object. Such an event filter - gets all the events except Tab and Shift-Tab key presses. - - \i Reimplementing paintEvent(), mousePressEvent() and so - on. This is the commonest, easiest and least powerful way. - \endlist - - \sa TQObject::event(), installEventFilter() -*/ - -bool TQApplication::notify( TQObject *receiver, TQEvent *e ) -{ - // no events are delivered after ~TQApplication() has started - if ( is_app_closing ) { - return FALSE; - } - - if ( receiver == 0 ) { // serious error -#if defined(QT_CHECK_NULL) - tqWarning( "TQApplication::notify: Unexpected null receiver" ); -#endif - return FALSE; - } - - if ( receiver && (e->type() == TQEvent::Destroy) ) { - return TRUE; - } - - if ( e->type() == TQEvent::ChildRemoved && receiver->postedEvents) { -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( GlobalPostedEvents()->mutex() ); -#endif // TQT_THREAD_SUPPORT - - // the TQObject destructor calls TQObject::removeChild, which calls - // TQApplication::sendEvent() directly. this can happen while the event - // loop is in the middle of posting events, and when we get here, we may - // not have any more posted events for this object. - if ( receiver->postedEvents ) { - // if this is a child remove event and the child insert - // hasn't been dispatched yet, kill that insert - TQPostEventList * l = receiver->postedEvents; - TQObject * c = ((TQChildEvent*)e)->child(); - TQPostEvent * pe; - l->first(); - while( ( pe = l->current()) != 0 ) { - if ( pe->event && pe->receiver == receiver && - pe->event->type() == TQEvent::ChildInserted && - ((TQChildEvent*)pe->event)->child() == c ) { - pe->event->posted = FALSE; - delete pe->event; - pe->event = 0; - l->remove(); - continue; - } - l->next(); - } - } - } - - bool res = FALSE; - if ( !receiver->isWidgetType() ) { - res = internalNotify( receiver, e ); - } - else switch ( e->type() ) { -#ifndef TQT_NO_ACCEL - case TQEvent::Accel: - { - TQKeyEvent* key = (TQKeyEvent*) e; - res = internalNotify( receiver, e ); - - if ( !res && !key->isAccepted() ) { - res = tqt_dispatchAccelEvent( (TQWidget*)receiver, key ); - } - - // next lines are for compatibility with TQt <= 3.0.x: old - // TQAccel was listening on toplevel widgets - if ( !res && !key->isAccepted() && !((TQWidget*)receiver)->isTopLevel() ) { - res = internalNotify( ((TQWidget*)receiver)->topLevelWidget(), e ); - } - } - break; -#endif //TQT_NO_ACCEL - case TQEvent::KeyPress: - case TQEvent::KeyRelease: - case TQEvent::AccelOverride: - { - TQWidget* w = (TQWidget*)receiver; - TQKeyEvent* key = (TQKeyEvent*) e; -#ifndef TQT_NO_ACCEL - if ( tqt_tryComposeUnicode( w, key ) ) - break; -#endif - bool def = key->isAccepted(); - while ( w ) { - if ( def ) - key->accept(); - else - key->ignore(); - res = internalNotify( w, e ); - if ( res || key->isAccepted() ) - break; - w = w->parentWidget( TRUE ); - } - } - break; - case TQEvent::MouseButtonPress: - if ( e->spontaneous() ) { - TQWidget* fw = (TQWidget*)receiver; - while ( fw->focusProxy() ) - fw = fw->focusProxy(); - if ( fw->isEnabled() && fw->focusPolicy() & TQWidget::ClickFocus ) { - TQFocusEvent::setReason( TQFocusEvent::Mouse); - fw->setFocus(); - TQFocusEvent::resetReason(); - } - } - // fall through intended - case TQEvent::MouseButtonRelease: - case TQEvent::MouseButtonDblClick: - case TQEvent::MouseMove: - { - TQWidget* w = (TQWidget*)receiver; - TQMouseEvent* mouse = (TQMouseEvent*) e; - TQPoint relpos = mouse->pos(); - while ( w ) { - TQMouseEvent me(mouse->type(), relpos, mouse->globalPos(), mouse->button(), mouse->state()); - me.spont = mouse->spontaneous(); - res = internalNotify( w, w == receiver ? mouse : &me ); - e->spont = FALSE; - if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation)) - break; - - relpos += w->pos(); - w = w->parentWidget(); - } - if ( res ) - mouse->accept(); - else - mouse->ignore(); - } - break; -#ifndef TQT_NO_WHEELEVENT - case TQEvent::Wheel: - { - if ( e->spontaneous() ) { - TQWidget* fw = (TQWidget*)receiver; - while ( fw->focusProxy() ) - fw = fw->focusProxy(); - if ( fw->isEnabled() && (fw->focusPolicy() & TQWidget::WheelFocus) == TQWidget::WheelFocus ) { - TQFocusEvent::setReason( TQFocusEvent::Mouse); - fw->setFocus(); - TQFocusEvent::resetReason(); - } - } - - TQWidget* w = (TQWidget*)receiver; - TQWheelEvent* wheel = (TQWheelEvent*) e; - TQPoint relpos = wheel->pos(); - while ( w ) { - TQWheelEvent we(relpos, wheel->globalPos(), wheel->delta(), wheel->state(), wheel->orientation()); - we.spont = wheel->spontaneous(); - res = internalNotify( w, w == receiver ? wheel : &we ); - e->spont = FALSE; - if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation)) - break; - - relpos += w->pos(); - w = w->parentWidget(); - } - if ( res ) - wheel->accept(); - else - wheel->ignore(); - } - break; -#endif - case TQEvent::ContextMenu: - { - TQWidget* w = (TQWidget*)receiver; - TQContextMenuEvent *context = (TQContextMenuEvent*) e; - TQPoint relpos = context->pos(); - while ( w ) { - TQContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->state()); - ce.spont = e->spontaneous(); - res = internalNotify( w, w == receiver ? context : &ce ); - e->spont = FALSE; - - if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation)) - break; - - relpos += w->pos(); - w = w->parentWidget(); - } - if ( res ) - context->accept(); - else - context->ignore(); - } - break; -#if defined (QT_TABLET_SUPPORT) - case TQEvent::TabletMove: - case TQEvent::TabletPress: - case TQEvent::TabletRelease: - { - TQWidget *w = (TQWidget*)receiver; - TQTabletEvent *tablet = (TQTabletEvent*)e; - TQPoint relpos = tablet->pos(); - while ( w ) { - TQTabletEvent te(tablet->pos(), tablet->globalPos(), tablet->device(), - tablet->pressure(), tablet->xTilt(), tablet->yTilt(), - tablet->uniqueId()); - te.spont = e->spontaneous(); - res = internalNotify( w, w == receiver ? tablet : &te ); - e->spont = FALSE; - if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation)) - break; - - relpos += w->pos(); - w = w->parentWidget(); - } - if ( res ) - tablet->accept(); - else - tablet->ignore(); - chokeMouse = tablet->isAccepted(); - } - break; -#endif - default: - res = internalNotify( receiver, e ); - break; - } - - return res; -} - -/*!\reimp - -*/ -bool TQApplication::event( TQEvent *e ) -{ - if(e->type() == TQEvent::Close) { - TQCloseEvent *ce = (TQCloseEvent*)e; - ce->accept(); - closeAllWindows(); - - TQWidgetList *list = topLevelWidgets(); - for(TQWidget *w = list->first(); w; w = list->next()) { - if ( !w->isHidden() && !w->isDesktop() && !w->isPopup() && - (!w->isDialog() || !w->parentWidget())) { - ce->ignore(); - break; - } - } - if(ce->isAccepted()) - return TRUE; - } else if (e->type() == TQEvent::Quit) { - quit(); - return TRUE; - } - return TQObject::event(e); -} - -#define HOVER_SENSITIVE_WIDGET_SELECT if ( widget->inherits("TQPushButton") \ - || widget->inherits("TQComboBox") \ - || widget->inherits("TQSpinWidget") \ - || widget->inherits("TQCheckBox") \ - || widget->inherits("TQRadioButton") \ - || widget->inherits("TQToolButton") \ - || widget->inherits("TQSlider") \ - || widget->inherits("TQScrollBar") \ - || widget->inherits("TQTabBar") \ - || widget->inherits("TQDockWindowHandle") \ - || widget->inherits("TQSplitterHandle") ) - -#define FOCUS_SENSITIVE_WIDGET_SELECT if ( widget->inherits("TQLineEdit") ) -#define FOCUS_SENSITIVE_PARENT_WIDGET_SELECT if ( widget->parentWidget() && widget->parentWidget()->inherits("TQSpinWidget") ) - -/*!\internal - - Helper function called by notify() - */ -bool TQApplication::internalNotify( TQObject *receiver, TQEvent * e) -{ - if ( eventFilters ) { - TQObjectListIt it( *eventFilters ); - TQObject *obj; - while ( (obj=it.current()) != 0 ) { // send to all filters - ++it; // until one returns TRUE - if ( obj->eventFilter(receiver,e) ) - return TRUE; - } - } - - bool consumed = FALSE; - bool handled = FALSE; - if ( receiver->isWidgetType() ) { - TQWidget *widget = (TQWidget*)receiver; - - // toggle HasMouse widget state on enter and leave - if ( e->type() == TQEvent::Enter || e->type() == TQEvent::DragEnter ) { - widget->setWState( WState_HasMouse ); - HOVER_SENSITIVE_WIDGET_SELECT { - widget->repaint(false); - } - } - else if ( e->type() == TQEvent::Leave || e->type() == TQEvent::DragLeave ) { - widget->clearWState( WState_HasMouse ); - HOVER_SENSITIVE_WIDGET_SELECT { - widget->repaint(false); - } - } - - // repaint information entry widgets on focus set/unset - if ( e->type() == TQEvent::FocusIn || e->type() == TQEvent::FocusOut ) { - FOCUS_SENSITIVE_WIDGET_SELECT { - widget->repaint(false); - } - FOCUS_SENSITIVE_PARENT_WIDGET_SELECT { - widget->parentWidget()->repaint(false); - } - } - - // throw away any mouse-tracking-only mouse events - if ( e->type() == TQEvent::MouseMove && - (((TQMouseEvent*)e)->state()&TQMouseEvent::MouseButtonMask) == 0 && - !widget->hasMouseTracking() ) { - handled = TRUE; - consumed = TRUE; - } else if ( !widget->isEnabled() ) { // throw away mouse events to disabled widgets - switch(e->type()) { - case TQEvent::MouseButtonPress: - case TQEvent::MouseButtonRelease: - case TQEvent::MouseButtonDblClick: - case TQEvent::MouseMove: - ( (TQMouseEvent*) e)->ignore(); - handled = TRUE; - consumed = TRUE; - break; -#ifndef TQT_NO_DRAGANDDROP - case TQEvent::DragEnter: - case TQEvent::DragMove: - ( (TQDragMoveEvent*) e)->ignore(); - handled = TRUE; - break; - - case TQEvent::DragLeave: - case TQEvent::DragResponse: - handled = TRUE; - break; - - case TQEvent::Drop: - ( (TQDropEvent*) e)->ignore(); - handled = TRUE; - break; -#endif -#ifndef TQT_NO_WHEELEVENT - case TQEvent::Wheel: - ( (TQWheelEvent*) e)->ignore(); - handled = TRUE; - break; -#endif - case TQEvent::ContextMenu: - ( (TQContextMenuEvent*) e)->ignore(); - handled = TRUE; - break; - default: - break; - } - } - - } - - if (!handled) { -#if defined(TQT_THREAD_SUPPORT) - int locklevel = 0; - int llcount; - if (TQApplication::tqt_mutex) { - TQApplication::tqt_mutex->lock(); // 1 of 2 - locklevel = tqt_mutex->level() - 1; - for (llcount=0; llcountunlock(); - } - TQApplication::tqt_mutex->unlock(); // 2 of 2 - } -#endif - consumed = receiver->event( e ); -#if defined(TQT_THREAD_SUPPORT) - if (TQApplication::tqt_mutex) { - for (llcount=0; llcountlock(); - } - } -#endif - } - e->spont = FALSE; - return consumed; -} - -/*! - Returns TRUE if an application object has not been created yet; - otherwise returns FALSE. - - \sa closingDown() -*/ - -bool TQApplication::startingUp() -{ - return !is_app_running; -} - -/*! - Returns TRUE if the application objects are being destroyed; - otherwise returns FALSE. - - \sa startingUp() -*/ - -bool TQApplication::closingDown() -{ - return is_app_closing; -} - - -/*! - Processes pending events, for 3 seconds or until there are no more - events to process, whichever is shorter. - - You can call this function occasionally when your program is busy - performing a long operation (e.g. copying a file). - - \sa exec(), TQTimer, TQEventLoop::processEvents() -*/ - -void TQApplication::processEvents() -{ - processEvents( 3000 ); -} - -/*! - \overload - - Processes pending events for \a maxtime milliseconds or until - there are no more events to process, whichever is shorter. - - You can call this function occasionally when you program is busy - doing a long operation (e.g. copying a file). - - \sa exec(), TQTimer, TQEventLoop::processEvents() -*/ -void TQApplication::processEvents( int maxtime ) -{ - eventLoop()->processEvents( TQEventLoop::AllEvents, maxtime ); -} - -/*! \obsolete - Waits for an event to occur, processes it, then returns. - - This function is useful for adapting TQt to situations where the - event processing must be grafted onto existing program loops. - - Using this function in new applications may be an indication of design - problems. - - \sa processEvents(), exec(), TQTimer -*/ - -void TQApplication::processOneEvent() -{ - eventLoop()->processEvents( TQEventLoop::AllEvents | - TQEventLoop::WaitForMore ); -} - -/***************************************************************************** - Main event loop wrappers - *****************************************************************************/ - -/*! - Returns the application event loop. This function will return - zero if called during and after destroying TQApplication. - - To create your own instance of TQEventLoop or TQEventLoop subclass create - it before you create the TQApplication object. - - \sa TQEventLoop -*/ -TQEventLoop *TQApplication::eventLoop() -{ - if ( !currentEventLoop() && !is_app_closing ) { - (void) new TQEventLoop( tqApp, "default event loop" ); - } - return currentEventLoop(); -} - - -/*! - Enters the main event loop and waits until exit() is called or the - main widget is destroyed, and returns the value that was set to - exit() (which is 0 if exit() is called via quit()). - - It is necessary to call this function to start event handling. The - main event loop receives events from the window system and - dispatches these to the application widgets. - - Generally speaking, no user interaction can take place before - calling exec(). As a special case, modal widgets like TQMessageBox - can be used before calling exec(), because modal widgets call - exec() to start a local event loop. - - To make your application perform idle processing, i.e. executing a - special function whenever there are no pending events, use a - TQTimer with 0 timeout. More advanced idle processing schemes can - be achieved using processEvents(). - - \sa quit(), exit(), processEvents(), setMainWidget() -*/ -int TQApplication::exec() -{ - return eventLoop()->exec(); -} - -/*! - Tells the application to exit with a return code. - - After this function has been called, the application leaves the main - event loop and returns from the call to exec(). The exec() function - returns \a retcode. - - By convention, a \a retcode of 0 means success, and any non-zero - value indicates an error. - - Note that unlike the C library function of the same name, this - function \e does return to the caller -- it is event processing that - stops. - - \sa quit(), exec() -*/ -void TQApplication::exit( int retcode ) -{ -#ifdef TQT_THREAD_SUPPORT - TQThread* thread = tqApp->guiThread(); - if (thread) { - if (thread->d) { - if (thread->d->eventLoop) { - thread->d->eventLoop->exit( retcode ); - } - } - } -#else - tqApp->eventLoop()->exit( retcode ); -#endif // TQT_THREAD_SUPPORT -} - -/*! - \obsolete - - This function enters the main event loop (recursively). Do not call - it unless you really know what you are doing. - - Use TQApplication::eventLoop()->enterLoop() instead. - -*/ -int TQApplication::enter_loop() -{ - return eventLoop()->enterLoop(); -} - -/*! - \obsolete - - This function exits from a recursive call to the main event loop. - Do not call it unless you are an expert. - - Use TQApplication::eventLoop()->exitLoop() instead. - -*/ -void TQApplication::exit_loop() -{ - eventLoop()->exitLoop(); -} - -/*! - \obsolete - - Returns the current loop level. - - Use TQApplication::eventLoop()->loopLevel() instead. - -*/ -int TQApplication::loopLevel() const -{ - return eventLoop()->loopLevel(); -} - -/*! - - Wakes up the GUI thread. - - \sa guiThreadAwake() \link threads.html Thread Support in TQt\endlink -*/ -void TQApplication::wakeUpGuiThread() -{ - eventLoop()->wakeUp(); -} - -/*! - This function returns TRUE if there are pending events; otherwise - returns FALSE. Pending events can be either from the window system - or posted events using TQApplication::postEvent(). -*/ -bool TQApplication::hasPendingEvents() -{ - return eventLoop()->hasPendingEvents(); -} - -#if !defined(TQ_WS_X11) - -// The doc and X implementation of these functions is in qapplication_x11.cpp - -void TQApplication::flushX() {} // do nothing - -void TQApplication::syncX() {} // do nothing - -#endif - -/*! - \fn void TQApplication::setWinStyleHighlightColor( const TQColor & ) - \obsolete - - Sets the color used to mark selections in windows style for all widgets - in the application. Will repaint all widgets if the color is changed. - - The default color is \c darkBlue. - \sa winStyleHighlightColor() -*/ - -/*! - \fn const TQColor& TQApplication::winStyleHighlightColor() - \obsolete - - Returns the color used to mark selections in windows style. - - \sa setWinStyleHighlightColor() -*/ - -/*! - Returns the version of the Windows operating system that is running: - - \list - \i TQt::WV_95 - Windows 95 - \i TQt::WV_98 - Windows 98 - \i TQt::WV_Me - Windows Me - \i TQt::WV_NT - Windows NT 4.x - \i TQt::WV_2000 - Windows 2000 (NT5) - \i TQt::WV_XP - Windows XP - \i TQt::WV_2003 - Windows Server 2003 family - \i TQt::WV_CE - Windows CE - \i TQt::WV_CENET - Windows CE.NET - \endlist - - Note that this function is implemented for the Windows version - of TQt only. -*/ - -#if defined(Q_OS_CYGWIN) -TQt::WindowsVersion TQApplication::winVersion() -{ - return qt_winver; -} -#endif - -#ifndef TQT_NO_TRANSLATION - -bool qt_detectRTLLanguage() -{ - return TQApplication::tr( "QT_LAYOUT_DIRECTION", - "Translate this string to the string 'LTR' in left-to-right" - " languages or to 'RTL' in right-to-left languages (such as Hebrew" - " and Arabic) to get proper widget layout." ) == "RTL"; -} - -/*! - Adds the message file \a mf to the list of message files to be used - for translations. - - Multiple message files can be installed. Translations are searched - for in the last installed message file, then the one from last, and - so on, back to the first installed message file. The search stops as - soon as a matching translation is found. - - \sa removeTranslator() translate() TQTranslator::load() -*/ - -void TQApplication::installTranslator( TQTranslator * mf ) -{ - if ( !mf ) - return; - if ( !translators ) - translators = new TQValueList; - - translators->prepend( mf ); - -#ifndef TQT_NO_TRANSLATION_BUILDER - if ( mf->isEmpty() ) - return; -#endif - - // hook to set the layout direction of dialogs - setReverseLayout( qt_detectRTLLanguage() ); - - TQWidgetList *list = topLevelWidgets(); - TQWidgetListIt it( *list ); - TQWidget *w; - while ( ( w=it.current() ) != 0 ) { - ++it; - if (!w->isDesktop()) - postEvent( w, new TQEvent( TQEvent::LanguageChange ) ); - } - delete list; -} - -/*! - Removes the message file \a mf from the list of message files used by - this application. (It does not delete the message file from the file - system.) - - \sa installTranslator() translate(), TQObject::tr() -*/ - -void TQApplication::removeTranslator( TQTranslator * mf ) -{ - if ( !translators || !mf ) - return; - - if ( translators->remove( mf ) && ! tqApp->closingDown() ) { - setReverseLayout( qt_detectRTLLanguage() ); - - TQWidgetList *list = topLevelWidgets(); - TQWidgetListIt it( *list ); - TQWidget *w; - while ( ( w=it.current() ) != 0 ) { - ++it; - postEvent( w, new TQEvent( TQEvent::LanguageChange ) ); - } - delete list; - } -} - -#ifndef TQT_NO_TEXTCODEC -/*! \obsolete - This is the same as TQTextCodec::setCodecForTr(). -*/ -void TQApplication::setDefaultCodec( TQTextCodec* codec ) -{ - TQTextCodec::setCodecForTr( codec ); -} - -/*! \obsolete - Returns TQTextCodec::codecForTr(). -*/ -TQTextCodec* TQApplication::defaultCodec() const -{ - return TQTextCodec::codecForTr(); -} -#endif //TQT_NO_TEXTCODEC - -/*! \enum TQApplication::Encoding - - This enum type defines the 8-bit encoding of character string - arguments to translate(): - - \value DefaultCodec - the encoding specified by - TQTextCodec::codecForTr() (Latin-1 if none has been set) - \value UnicodeUTF8 - UTF-8 - - \sa TQObject::tr(), TQObject::trUtf8(), TQString::fromUtf8() -*/ - -/*! \reentrant - Returns the translation text for \a sourceText, by querying the - installed messages files. The message files are searched from the most - recently installed message file back to the first installed message - file. - - TQObject::tr() and TQObject::trUtf8() provide this functionality more - conveniently. - - \a context is typically a class name (e.g., "MyDialog") and - \a sourceText is either English text or a short identifying text, if - the output text will be very long (as for help texts). - - \a comment is a disambiguating comment, for when the same \a - sourceText is used in different roles within the same context. By - default, it is null. \a encoding indicates the 8-bit encoding of - character stings - - See the \l TQTranslator documentation for more information about - contexts and comments. - - If none of the message files contain a translation for \a - sourceText in \a context, this function returns a TQString - equivalent of \a sourceText. The encoding of \a sourceText is - specified by \e encoding; it defaults to \c DefaultCodec. - - This function is not virtual. You can use alternative translation - techniques by subclassing \l TQTranslator. - - \warning This method is reentrant only if all translators are - installed \e before calling this method. Installing or removing - translators while performing translations is not supported. Doing - so will most likely result in crashes or other undesirable behavior. - - \sa TQObject::tr() installTranslator() defaultCodec() -*/ - -TQString TQApplication::translate( const char * context, const char * sourceText, - const char * comment, Encoding encoding ) const -{ - if ( !sourceText ) - return TQString::null; - - if ( translators ) { - TQValueList::iterator it; - TQTranslator * mf; - TQString result; - for ( it = translators->begin(); it != translators->end(); ++it ) { - mf = *it; - result = mf->findMessage( context, sourceText, comment ).translation(); - if ( !result.isNull() ) - return result; - } - } -#ifndef TQT_NO_TEXTCODEC - if ( encoding == UnicodeUTF8 ) - return TQString::fromUtf8( sourceText ); - else if ( TQTextCodec::codecForTr() != 0 ) - return TQTextCodec::codecForTr()->toUnicode( sourceText ); - else -#endif - return TQString::fromLatin1( sourceText ); -} - -#endif - -/***************************************************************************** - TQApplication management of posted events - *****************************************************************************/ - -//see also notify(), which does the removal of ChildInserted when ChildRemoved. - -/*! - Adds the event \a event with the object \a receiver as the receiver of the - event, to an event queue and returns immediately. - - The event must be allocated on the heap since the post event queue - will take ownership of the event and delete it once it has been posted. - - When control returns to the main event loop, all events that are - stored in the queue will be sent using the notify() function. - - \threadsafe - - \sa sendEvent(), notify() -*/ - -void TQApplication::postEvent( TQObject *receiver, TQEvent *event ) -{ - if ( receiver == 0 ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQApplication::postEvent: Unexpected null receiver" ); -#endif - delete event; - return; - } - -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( GlobalPostedEvents()->mutex() ); -#endif // TQT_THREAD_SUPPORT - - if ( !receiver->postedEvents ) { - receiver->postedEvents = new TQPostEventList; - } - TQPostEventList * l = receiver->postedEvents; - - // if this is one of the compressible events, do compression - if ( event->type() == TQEvent::Paint || - event->type() == TQEvent::LayoutHint || - event->type() == TQEvent::Resize || - event->type() == TQEvent::Move || - event->type() == TQEvent::LanguageChange ) { - l->first(); - TQPostEvent * cur = 0; - for ( ;; ) { - while ( (cur=l->current()) != 0 && - ( cur->receiver != receiver || - cur->event == 0 || - cur->event->type() != event->type() ) ) - l->next(); - if ( l->current() != 0 ) { - if ( cur->event->type() == TQEvent::Paint ) { - TQPaintEvent * p = (TQPaintEvent*)(cur->event); - if ( p->erase != ((TQPaintEvent*)event)->erase ) { - l->next(); - continue; - } - p->reg = p->reg.unite( ((TQPaintEvent *)event)->reg ); - p->rec = p->rec.unite( ((TQPaintEvent *)event)->rec ); - delete event; - return; - } else if ( cur->event->type() == TQEvent::LayoutHint ) { - delete event; - return; - } else if ( cur->event->type() == TQEvent::Resize ) { - ((TQResizeEvent *)(cur->event))->s = ((TQResizeEvent *)event)->s; - delete event; - return; - } else if ( cur->event->type() == TQEvent::Move ) { - ((TQMoveEvent *)(cur->event))->p = ((TQMoveEvent *)event)->p; - delete event; - return; - } else if ( cur->event->type() == TQEvent::LanguageChange ) { - delete event; - return; - } - } - break; - }; - } - -#if !defined(TQT_NO_IM) - // if this is one of the compressible IM events, do compression - else if ( event->type() == TQEvent::IMCompose ) { - l->last(); - TQPostEvent * cur = 0; - for ( ;; ) { - while ( (cur=l->current()) != 0 && - ( cur->receiver != receiver || - cur->event == 0 || - cur->event->type() != event->type() || - cur->event->type() != TQEvent::IMStart ) ) - l->prev(); - if ( l->current() != 0 ) { - // IMCompose must not be compressed with another one - // beyond its IMStart boundary - if ( cur->event->type() == TQEvent::IMStart ) { - break; - } else if ( cur->event->type() == TQEvent::IMCompose ) { - TQIMComposeEvent * e = (TQIMComposeEvent *)(cur->event); - *e = *(TQIMComposeEvent *)event; - delete event; - return; - } - } - break; - }; - } -#endif - - // if no compression could be done, just append something - event->posted = TRUE; - TQPostEvent * pe = new TQPostEvent( receiver, event ); - l->append( pe ); - GlobalPostedEvents()->append( pe ); - -#ifdef TQT_THREAD_SUPPORT - // Wake up the receiver thread event loop - TQThread* thread = receiver->contextThreadObject(); - if (thread) { - if (thread->d) { - if (thread->d->eventLoop) { - thread->d->eventLoop->wakeUp(); - return; - } - } - } - if ( event->type() == TQEvent::MetaCall ) { - return; - } -#endif - - if (currentEventLoop()) { - currentEventLoop()->wakeUp(); - } -} - - -/*! \overload - - Dispatches all posted events, i.e. empties the event queue. -*/ -void TQApplication::sendPostedEvents() -{ - sendPostedEvents( 0, 0 ); -} - - - -/*! - Immediately dispatches all events which have been previously queued - with TQApplication::postEvent() and which are for the object \a receiver - and have the event type \a event_type. - - Note that events from the window system are \e not dispatched by this - function, but by processEvents(). - - If \a receiver is null, the events of \a event_type are sent for all - objects. If \a event_type is 0, all the events are sent for \a receiver. -*/ - -void TQApplication::sendPostedEvents( TQObject *receiver, int event_type ) -{ - // Make sure the object hierarchy is stable before processing events - // to avoid endless loops - if ( receiver == 0 && event_type == 0 ) { - sendPostedEvents( 0, TQEvent::ChildInserted ); - } - -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( GlobalPostedEvents()->mutex() ); -#endif - - bool sent = TRUE; - while ( sent ) { - sent = FALSE; - - if (receiver && !receiver->postedEvents) { - return; - } - - // if we have a receiver, use the local list. Otherwise, use the - // global list - TQPostEventList * l = receiver ? receiver->postedEvents : GlobalPostedEvents(); - - // okay. here is the tricky loop. be careful about optimizing - // this, it looks the way it does for good reasons. - TQPostEventListIt it( *l ); - TQPostEvent *pe; - while ( (pe=it.current()) != 0 ) { - ++it; - Q_ASSERT(pe->receiver); - if ( pe->event // hasn't been sent yet - && ( receiver == 0 // we send to all receivers - || receiver == pe->receiver ) // we send to THAT receiver - && ( event_type == 0 // we send all types - || event_type == pe->event->type() ) // we send THAT type - && ( !pe->receiver->wasDeleted ) // don't send if receiver was deleted -#ifdef TQT_THREAD_SUPPORT - // only send if active thread is receiver object owning thread - && ( pe->receiver->contextThreadObject() == TQThread::currentThreadObject() ) -#endif - ) { - // first, we diddle the event so that we can deliver - // it, and that noone will try to touch it later. - pe->event->posted = FALSE; - TQEvent * e = pe->event; - TQObject * r = pe->receiver; - pe->event = 0; - - // next, update the data structure so that we're ready - // for the next event. - - // look for the local list, and take whatever we're - // delivering out of it. r->postedEvents maybe *l - if ( r->postedEvents ) { - r->postedEvents->removeRef( pe ); - // if possible, get rid of that list. this is not - // ideal - we will create and delete a list for - // each update() call. it would be better if we'd - // leave the list empty here, and delete it - // somewhere else if it isn't being used. - if ( r->postedEvents->isEmpty() ) { - delete r->postedEvents; - r->postedEvents = 0; - } - } - -#ifdef TQT_THREAD_SUPPORT - if ( locker.mutex() ) locker.mutex()->unlock(); -#endif // TQT_THREAD_SUPPORT - // after all that work, it's time to deliver the event. - if ( e->type() == TQEvent::Paint && r->isWidgetType() ) { - TQWidget * w = (TQWidget*)r; - TQPaintEvent * p = (TQPaintEvent*)e; - if ( w->isVisible() ) { - w->repaint( p->reg, p->erase ); - } - } else { - sent = TRUE; - TQApplication::sendEvent( r, e ); - } -#ifdef TQT_THREAD_SUPPORT - if ( locker.mutex() ) locker.mutex()->lock(); -#endif // TQT_THREAD_SUPPORT - - delete e; - // careful when adding anything below this point - the - // sendEvent() call might invalidate any invariants this - // function depends on. - } - } - - // clear the global list, i.e. remove everything that was - // delivered. - if ( l == GlobalPostedEvents() ) { - GlobalPostedEvents()->first(); - while( (pe=GlobalPostedEvents()->current()) != 0 ) { - if ( pe->event ) { - GlobalPostedEvents()->next(); - } - else { - GlobalPostedEvents()->remove(); - } - } - } - } -} - -/*! - Removes all events posted using postEvent() for \a receiver. - - The events are \e not dispatched, instead they are removed from the - queue. You should never need to call this function. If you do call it, - be aware that killing events may cause \a receiver to break one or - more invariants. - - \threadsafe -*/ - -void TQApplication::removePostedEvents( TQObject *receiver ) -{ - removePostedEvents( receiver, 0 ); -} - -/*! - Removes all events that have the event type \a event_type posted - using postEvent() for \a receiver. - - The events are \e not dispatched, instead they are removed from the - queue. - - If \a event_type is 0, all the events are removed from the queue. - - \threadsafe -*/ - -void TQApplication::removePostedEvents( TQObject *receiver, int event_type ) -{ - if ( !receiver ) { - return; - } - -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( GlobalPostedEvents()->mutex() ); -#endif // TQT_THREAD_SUPPORT - - // the TQObject destructor calls this function directly. this can - // happen while the event loop is in the middle of posting events, - // and when we get here, we may not have any more posted events - // for this object. - if ( !receiver->postedEvents ) { - return; - } - - // iterate over the object-specifc list and delete the events. - // leave the TQPostEvent objects; they'll be deleted by - // sendPostedEvents(). - TQPostEventList * l = receiver->postedEvents; - l->first(); - TQPostEvent * pe; - while( (pe=l->current()) != 0 ) { - if ( !event_type || pe->event->type() == event_type ) { - if ( pe->event ) { - pe->event->posted = FALSE; - delete pe->event; - pe->event = 0; - } - l->remove(); - } else { - l->next(); - } - } - if ( !event_type || !l->count() ) { - receiver->postedEvents = 0; - delete l; - } -} - - -/*! - Removes \a event from the queue of posted events, and emits a - warning message if appropriate. - - \warning This function can be \e really slow. Avoid using it, if - possible. - - \threadsafe -*/ - -void TQApplication::removePostedEvent( TQEvent * event ) -{ - if ( !event || !event->posted ) { - return; - } - -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( GlobalPostedEvents()->mutex() ); -#endif // TQT_THREAD_SUPPORT - - TQPostEventListIt it( *GlobalPostedEvents() ); - TQPostEvent * pe; - while( (pe = it.current()) != 0 ) { - ++it; - if ( pe->event == event ) { -#if defined(QT_DEBUG) - const char *n; - switch ( event->type() ) { - case TQEvent::Timer: - n = "Timer"; - break; - case TQEvent::MouseButtonPress: - n = "MouseButtonPress"; - break; - case TQEvent::MouseButtonRelease: - n = "MouseButtonRelease"; - break; - case TQEvent::MouseButtonDblClick: - n = "MouseButtonDblClick"; - break; - case TQEvent::MouseMove: - n = "MouseMove"; - break; -#ifndef TQT_NO_WHEELEVENT - case TQEvent::Wheel: - n = "Wheel"; - break; -#endif - case TQEvent::KeyPress: - n = "KeyPress"; - break; - case TQEvent::KeyRelease: - n = "KeyRelease"; - break; - case TQEvent::FocusIn: - n = "FocusIn"; - break; - case TQEvent::FocusOut: - n = "FocusOut"; - break; - case TQEvent::Enter: - n = "Enter"; - break; - case TQEvent::Leave: - n = "Leave"; - break; - case TQEvent::Paint: - n = "Paint"; - break; - case TQEvent::Move: - n = "Move"; - break; - case TQEvent::Resize: - n = "Resize"; - break; - case TQEvent::Create: - n = "Create"; - break; - case TQEvent::Destroy: - n = "Destroy"; - break; - case TQEvent::Close: - n = "Close"; - break; - case TQEvent::Quit: - n = "Quit"; - break; - default: - n = ""; - break; - } - tqWarning("TQEvent: Warning: %s event deleted while posted to %s %s", - n, - pe->receiver ? pe->receiver->className() : "null", - pe->receiver ? pe->receiver->name() : "object" ); - // note the beautiful uglehack if !pe->receiver :) -#endif - event->posted = FALSE; - delete pe->event; - pe->event = 0; - return; - } - } -} - -#ifdef TQT_THREAD_SUPPORT -static void tqThreadTerminationHandlerRecursive( TQObject* object, TQThread* originThread, TQThread* destinationThread ) { - TQThread* objectThread = object->contextThreadObject(); - if (objectThread && (objectThread == originThread)) { - TQThread::CleanupType cleanupType = objectThread->cleanupType(); - if (cleanupType == TQThread::CleanupMergeObjects) { - object->moveToThread(destinationThread); - } - else if (cleanupType == TQThread::CleanupNone) { - // Do nothing -#if defined(QT_DEBUG) - tqDebug( "TQApplication::threadTerminationHandler: object %p still owned by thread %p at thread termination!", object, objectThread); -#endif // QT_DEBUG - } - else { - // Do nothing -#if defined(QT_DEBUG) - tqDebug( "TQApplication::threadTerminationHandler: invalid thread termination cleanup type %d specified", cleanupType); -#endif // QT_DEBUG - } - } - TQObjectList children = object->childrenListObject(); - TQObject *childObject; - for ( childObject = children.first(); childObject; childObject = children.next() ) { - tqThreadTerminationHandlerRecursive(childObject, originThread, destinationThread); - } -} - -/*!\internal - - Migrates all objects from the specified thread in preparation - for thread destruction. - */ -void TQApplication::threadTerminationHandler( TQThread *originThread ) { - TQMutexLocker locker( tqt_mutex ); - TQThread* destinationThread = guiThread(); - const TQObjectList* objects = TQObject::objectTrees(); - for ( TQObjectListIt objectit( *objects ) ; *objectit; ++objectit ) { - tqThreadTerminationHandlerRecursive((*objectit), originThread, destinationThread); - } -} -#endif // TQT_THREAD_SUPPORT - -/*!\internal - - Sets the active window in reaction to a system event. Call this - from the platform specific event handlers. - - It sets the activeWindow() and focusWidget() attributes and sends - proper WindowActivate/WindowDeactivate and FocusIn/FocusOut events - to all appropriate widgets. - - \sa activeWindow() - */ -void TQApplication::setActiveWindow( TQWidget* act ) -{ - TQWidget* window = act?act->topLevelWidget():0; - - if ( active_window == window ) - return; - - // first the activation/deactivation events - if ( active_window ) { - TQWidgetList deacts; -#ifndef TQT_NO_STYLE - if ( style().styleHint(TQStyle::SH_Widget_ShareActivation, active_window ) ) { - TQWidgetList *list = topLevelWidgets(); - if ( list ) { - for ( TQWidget *w = list->first(); w; w = list->next() ) { - if ( w->isVisible() && w->isActiveWindow() ) - deacts.append(w); - } - delete list; - } - } else -#endif - deacts.append(active_window); - active_window = 0; - TQEvent e( TQEvent::WindowDeactivate ); - for(TQWidget *w = deacts.first(); w; w = deacts.next()) - TQApplication::sendSpontaneousEvent( w, &e ); - } - - active_window = window; - if ( active_window ) { - TQEvent e( TQEvent::WindowActivate ); - TQWidgetList acts; -#ifndef TQT_NO_STYLE - if ( style().styleHint(TQStyle::SH_Widget_ShareActivation, active_window ) ) { - TQWidgetList *list = topLevelWidgets(); - if ( list ) { - for ( TQWidget *w = list->first(); w; w = list->next() ) { - if ( w->isVisible() && w->isActiveWindow() ) - acts.append(w); - } - delete list; - } - } else -#endif - acts.append(active_window); - for(TQWidget *w = acts.first(); w; w = acts.next()) - TQApplication::sendSpontaneousEvent( w, &e ); - } - - // then focus events - TQFocusEvent::setReason( TQFocusEvent::ActiveWindow ); - if ( !active_window && focus_widget ) { - TQFocusEvent out( TQEvent::FocusOut ); - TQWidget *tmp = focus_widget; - focus_widget = 0; -#ifdef TQ_WS_WIN - TQInputContext::accept( tmp ); -#elif defined(TQ_WS_X11) - tmp->unfocusInputContext(); -#endif - TQApplication::sendSpontaneousEvent( tmp, &out ); - } else if ( active_window ) { - TQWidget *w = active_window->focusWidget(); - if ( w && w->focusPolicy() != TQWidget::NoFocus ) - w->setFocus(); - else - active_window->focusNextPrevChild( TRUE ); - } - TQFocusEvent::resetReason(); -} - - -/*!\internal - - Creates the proper Enter/Leave event when widget \a enter is entered - and widget \a leave is left. - */ -TQ_EXPORT void tqt_dispatchEnterLeave( TQWidget* enter, TQWidget* leave ) { -#if 0 - if ( leave ) { - TQEvent e( TQEvent::Leave ); - TQApplication::sendEvent( leave, & e ); - } - if ( enter ) { - TQEvent e( TQEvent::Enter ); - TQApplication::sendEvent( enter, & e ); - } - return; -#endif - - TQWidget* w ; - if ( !enter && !leave ) - return; - TQWidgetList leaveList; - TQWidgetList enterList; - - bool sameWindow = leave && enter && leave->topLevelWidget() == enter->topLevelWidget(); - if ( leave && !sameWindow ) { - w = leave; - do { - leaveList.append( w ); - } while ( (w = w->parentWidget( TRUE ) ) ); - } - if ( enter && !sameWindow ) { - w = enter; - do { - enterList.prepend( w ); - } while ( (w = w->parentWidget(TRUE) ) ); - } - if ( sameWindow ) { - int enterDepth = 0; - int leaveDepth = 0; - w = enter; - while ( ( w = w->parentWidget( TRUE ) ) ) - enterDepth++; - w = leave; - while ( ( w = w->parentWidget( TRUE ) ) ) - leaveDepth++; - TQWidget* wenter = enter; - TQWidget* wleave = leave; - while ( enterDepth > leaveDepth ) { - wenter = wenter->parentWidget(); - enterDepth--; - } - while ( leaveDepth > enterDepth ) { - wleave = wleave->parentWidget(); - leaveDepth--; - } - while ( !wenter->isTopLevel() && wenter != wleave ) { - wenter = wenter->parentWidget(); - wleave = wleave->parentWidget(); - } - - w = leave; - while ( w != wleave ) { - leaveList.append( w ); - w = w->parentWidget(); - } - w = enter; - while ( w != wenter ) { - enterList.prepend( w ); - w = w->parentWidget(); - } - } - - TQEvent leaveEvent( TQEvent::Leave ); - for ( w = leaveList.first(); w; w = leaveList.next() ) { - if ( !tqApp->activeModalWidget() || tqt_tryModalHelper( w, 0 )) - TQApplication::sendEvent( w, &leaveEvent ); - } - TQEvent enterEvent( TQEvent::Enter ); - for ( w = enterList.first(); w; w = enterList.next() ) { - if ( !tqApp->activeModalWidget() || tqt_tryModalHelper( w, 0 )) - TQApplication::sendEvent( w, &enterEvent ); - } -} - - -#ifdef TQ_WS_MACX -extern TQWidget *tqt_tryModalHelperMac( TQWidget * top ); //qapplication_mac.cpp -#endif - - -/*!\internal - - Called from qapplication_.cpp, returns TRUE - if the widget should accept the event. - */ -TQ_EXPORT bool tqt_tryModalHelper( TQWidget *widget, TQWidget **rettop ) { - TQWidget *modal=0, *top=TQApplication::activeModalWidget(); - if ( rettop ) *rettop = top; - - if ( tqApp->activePopupWidget() ) - return TRUE; - -#ifdef TQ_WS_MACX - top = tqt_tryModalHelperMac( top ); - if ( rettop ) *rettop = top; -#endif - - TQWidget* groupLeader = widget; - widget = widget->topLevelWidget(); - - if ( widget->testWFlags(TQt::WShowModal) ) // widget is modal - modal = widget; - if ( !top || modal == top ) // don't block event - return TRUE; - - TQWidget * p = widget->parentWidget(); // Check if the active modal widget is a parent of our widget - while ( p ) { - if ( p == top ) - return TRUE; - p = p->parentWidget(); - } - - while ( groupLeader && !groupLeader->testWFlags( TQt::WGroupLeader ) ) - groupLeader = groupLeader->parentWidget(); - - if ( groupLeader ) { - // Does groupLeader have a child in tqt_modal_stack? - bool unrelated = TRUE; - modal = tqt_modal_stack->first(); - while (modal && unrelated) { - TQWidget* p = modal->parentWidget(); - while ( p && p != groupLeader && !p->testWFlags( TQt::WGroupLeader) ) { - p = p->parentWidget(); - } - modal = tqt_modal_stack->next(); - if ( p == groupLeader ) unrelated = FALSE; - } - - if ( unrelated ) - return TRUE; // don't block event - } - return FALSE; -} - - -/*! - Returns the desktop widget (also called the root window). - - The desktop widget is useful for obtaining the size of the screen. - It may also be possible to draw on the desktop. We recommend against - assuming that it's possible to draw on the desktop, since this does - not work on all operating systems. - - \code - TQDesktopWidget *d = TQApplication::desktop(); - int w = d->width(); // returns desktop width - int h = d->height(); // returns desktop height - \endcode -*/ - -TQDesktopWidget *TQApplication::desktop() -{ - if ( !tqt_desktopWidget || // not created yet - !tqt_desktopWidget->isDesktop() ) { // reparented away - tqt_desktopWidget = new TQDesktopWidget(); - TQ_CHECK_PTR( tqt_desktopWidget ); - } - return tqt_desktopWidget; -} - -#ifndef TQT_NO_CLIPBOARD -/*! - Returns a pointer to the application global clipboard. -*/ -TQClipboard *TQApplication::clipboard() -{ - if ( tqt_clipboard == 0 ) { - tqt_clipboard = new TQClipboard; - TQ_CHECK_PTR( tqt_clipboard ); - } - return tqt_clipboard; -} -#endif // TQT_NO_CLIPBOARD - -/*! - By default, TQt will try to use the current standard colors, fonts - etc., from the underlying window system's desktop settings, - and use them for all relevant widgets. This behavior can be switched off - by calling this function with \a on set to FALSE. - - This static function must be called before creating the TQApplication - object, like this: - - \code - int main( int argc, char** argv ) { - TQApplication::setDesktopSettingsAware( FALSE ); // I know better than the user - TQApplication myApp( argc, argv ); // Use default fonts & colors - ... - } - \endcode - - \sa desktopSettingsAware() -*/ - -void TQApplication::setDesktopSettingsAware( bool on ) -{ - obey_desktop_settings = on; -} - -/*! - Returns the value set by setDesktopSettingsAware(); by default TRUE. - - \sa setDesktopSettingsAware() -*/ - -bool TQApplication::desktopSettingsAware() -{ - return obey_desktop_settings; -} - -/*! \fn void TQApplication::lock() - - Lock the TQt Library Mutex. If another thread has already locked the - mutex, the calling thread will block until the other thread has - unlocked the mutex. - - \sa unlock() locked() \link threads.html Thread Support in TQt\endlink -*/ - - -/*! \fn void TQApplication::unlock(bool wakeUpGui) - - Unlock the TQt Library Mutex. If \a wakeUpGui is TRUE (the default), - then the GUI thread will be woken with TQApplication::wakeUpGuiThread(). - - \sa lock(), locked() \link threads.html Thread Support in TQt\endlink -*/ - - -/*! \fn bool TQApplication::locked() - - Returns TRUE if the TQt Library Mutex is locked by a different thread; - otherwise returns FALSE. - - \warning Due to different implementations of recursive mutexes on - the supported platforms, calling this function from the same thread - that previously locked the mutex will give undefined results. - - \sa lock() unlock() \link threads.html Thread Support in TQt\endlink -*/ - -/*! \fn bool TQApplication::tryLock() - - Attempts to lock the TQt Library Mutex, and returns immediately. If - the lock was obtained, this function returns TRUE. If another thread - has locked the mutex, this function returns FALSE, instead of - waiting for the lock to become available. - - The mutex must be unlocked with unlock() before another thread can - successfully lock it. - - \sa lock(), unlock() \link threads.html Thread Support in TQt\endlink -*/ - -#if defined(TQT_THREAD_SUPPORT) -void TQApplication::lock() -{ - tqt_mutex->lock(); -} - -void TQApplication::unlock(bool wakeUpGui) -{ - tqt_mutex->unlock(); - - if (wakeUpGui) - wakeUpGuiThread(); -} - -bool TQApplication::locked() -{ - return tqt_mutex->locked(); -} - -bool TQApplication::tryLock() -{ - return tqt_mutex->tryLock(); -} -#endif - - -/*! - \fn bool TQApplication::isSessionRestored() const - - Returns TRUE if the application has been restored from an earlier - \link session.html session\endlink; otherwise returns FALSE. - - \sa sessionId(), commitData(), saveState() -*/ - - -/*! - \fn TQString TQApplication::sessionId() const - - Returns the current \link session.html session's\endlink identifier. - - If the application has been restored from an earlier session, this - identifier is the same as it was in that previous session. - - The session identifier is guaranteed to be unique both for different - applications and for different instances of the same application. - - \sa isSessionRestored(), sessionKey(), commitData(), saveState() - */ - -/*! - \fn TQString TQApplication::sessionKey() const - - Returns the session key in the current \link session.html - session\endlink. - - If the application has been restored from an earlier session, this - key is the same as it was when the previous session ended. - - The session key changes with every call of commitData() or - saveState(). - - \sa isSessionRestored(), sessionId(), commitData(), saveState() - */ - - -/*! - \fn void TQApplication::commitData( TQSessionManager& sm ) - - This function deals with \link session.html session - management\endlink. It is invoked when the TQSessionManager wants the - application to commit all its data. - - Usually this means saving all open files, after getting - permission from the user. Furthermore you may want to provide a means - by which the user can cancel the shutdown. - - Note that you should not exit the application within this function. - Instead, the session manager may or may not do this afterwards, - depending on the context. - - \warning Within this function, no user interaction is possible, \e - unless you ask the session manager \a sm for explicit permission. - See TQSessionManager::allowsInteraction() and - TQSessionManager::allowsErrorInteraction() for details and example - usage. - - The default implementation requests interaction and sends a close - event to all visible top level widgets. If any event was - rejected, the shutdown is canceled. - - \sa isSessionRestored(), sessionId(), saveState(), \link session.html the Session Management overview\endlink -*/ -#ifndef TQT_NO_SESSIONMANAGER -void TQApplication::commitData( TQSessionManager& sm ) -{ - - if ( sm.allowsInteraction() ) { - TQWidgetList done; - TQWidgetList *list = TQApplication::topLevelWidgets(); - bool cancelled = FALSE; - TQWidget* w = list->first(); - while ( !cancelled && w ) { - if ( !w->isHidden() ) { - TQCloseEvent e; - sendEvent( w, &e ); - cancelled = !e.isAccepted(); - if ( !cancelled ) - done.append( w ); - delete list; // one never knows... - list = TQApplication::topLevelWidgets(); - w = list->first(); - } else { - w = list->next(); - } - while ( w && done.containsRef( w ) ) - w = list->next(); - } - delete list; - if ( cancelled ) - sm.cancel(); - } -} - - -/*! - \fn void TQApplication::saveState( TQSessionManager& sm ) - - This function deals with \link session.html session - management\endlink. It is invoked when the - \link TQSessionManager session manager \endlink wants the application - to preserve its state for a future session. - - For example, a text editor would create a temporary file that - includes the current contents of its edit buffers, the location of - the cursor and other aspects of the current editing session. - - Note that you should never exit the application within this - function. Instead, the session manager may or may not do this - afterwards, depending on the context. Futhermore, most session - managers will very likely request a saved state immediately after - the application has been started. This permits the session manager - to learn about the application's restart policy. - - \warning Within this function, no user interaction is possible, \e - unless you ask the session manager \a sm for explicit permission. - See TQSessionManager::allowsInteraction() and - TQSessionManager::allowsErrorInteraction() for details. - - \sa isSessionRestored(), sessionId(), commitData(), \link session.html the Session Management overview\endlink -*/ - -void TQApplication::saveState( TQSessionManager& /* sm */ ) -{ -} -#endif //TQT_NO_SESSIONMANAGER -/*! - Sets the time after which a drag should start to \a ms ms. - - \sa startDragTime() -*/ - -void TQApplication::setStartDragTime( int ms ) -{ - drag_time = ms; -} - -/*! - If you support drag and drop in you application and a drag should - start after a mouse click and after a certain time elapsed, you - should use the value which this method returns as the delay (in ms). - - TQt also uses this delay internally, e.g. in TQTextEdit and TQLineEdit, - for starting a drag. - - The default value is 500 ms. - - \sa setStartDragTime(), startDragDistance() -*/ - -int TQApplication::startDragTime() -{ - return drag_time; -} - -/*! - Sets the distance after which a drag should start to \a l pixels. - - \sa startDragDistance() -*/ - -void TQApplication::setStartDragDistance( int l ) -{ - drag_distance = l; -} - -/*! - If you support drag and drop in you application and a drag should - start after a mouse click and after moving the mouse a certain - distance, you should use the value which this method returns as the - distance. - - For example, if the mouse position of the click is stored in \c - startPos and the current position (e.g. in the mouse move event) is - \c currPos, you can find out if a drag should be started with code - like this: - \code - if ( ( startPos - currPos ).manhattanLength() > - TQApplication::startDragDistance() ) - startTheDrag(); - \endcode - - TQt uses this value internally, e.g. in TQFileDialog. - - The default value is 4 pixels. - - \sa setStartDragDistance(), startDragTime(), TQPoint::manhattanLength() -*/ - -int TQApplication::startDragDistance() -{ - return drag_distance; -} - -/*! - If \a b is TRUE, all dialogs and widgets will be laid out in a - mirrored fashion, as required by right to left languages such as - Arabic and Hebrew. If \a b is FALSE, dialogs and widgets are laid - out left to right. - - Changing this flag in runtime does not cause a relayout of already - instantiated widgets. - - \sa reverseLayout() -*/ -void TQApplication::setReverseLayout( bool b ) -{ - if ( reverse_layout == b ) - return; - - reverse_layout = b; - - TQWidgetList *list = topLevelWidgets(); - TQWidgetListIt it( *list ); - TQWidget *w; - while ( ( w=it.current() ) != 0 ) { - ++it; - postEvent( w, new TQEvent( TQEvent::LayoutDirectionChange ) ); - } - delete list; -} - -/*! - Returns TRUE if all dialogs and widgets will be laid out in a - mirrored (right to left) fashion. Returns FALSE if dialogs and - widgets will be laid out left to right. - - \sa setReverseLayout() -*/ -bool TQApplication::reverseLayout() -{ - return reverse_layout; -} - - -/*! - \class TQSessionManager tqsessionmanager.h - \brief The TQSessionManager class provides access to the session manager. - - \ingroup application - \ingroup environment - - The session manager is responsible for session management, most - importantly for interruption and resumption. A "session" is a kind - of record of the state of the system, e.g. which applications were - run at start up and which applications are currently running. The - session manager is used to save the session, e.g. when the machine - is shut down; and to restore a session, e.g. when the machine is - started up. Use TQSettings to save and restore an individual - application's settings, e.g. window positions, recently used files, - etc. - - TQSessionManager provides an interface between the application and - the session manager so that the program can work well with the - session manager. In TQt, session management requests for action - are handled by the two virtual functions TQApplication::commitData() - and TQApplication::saveState(). Both provide a reference to - a session manager object as argument, to allow the application - to communicate with the session manager. - - During a session management action (i.e. within commitData() and - saveState()), no user interaction is possible \e unless the - application got explicit permission from the session manager. You - ask for permission by calling allowsInteraction() or, if it's really - urgent, allowsErrorInteraction(). TQt does not enforce this, but the - session manager may. - - You can try to abort the shutdown process by calling cancel(). The - default commitData() function does this if some top-level window - rejected its closeEvent(). - - For sophisticated session managers provided on Unix/X11, TQSessionManager - offers further possibilites to fine-tune an application's session - management behavior: setRestartCommand(), setDiscardCommand(), - setRestartHint(), setProperty(), requestPhase2(). See the respective - function descriptions for further details. -*/ - -/*! \enum TQSessionManager::RestartHint - - This enum type defines the circumstances under which this - application wants to be restarted by the session manager. The - current values are - - \value RestartIfRunning if the application is still running when - the session is shut down, it wants to be restarted at the start of - the next session. - - \value RestartAnyway the application wants to be started at the - start of the next session, no matter what. (This is useful for - utilities that run just after startup and then quit.) - - \value RestartImmediately the application wants to be started - immediately whenever it is not running. - - \value RestartNever the application does not want to be restarted - automatically. - - The default hint is \c RestartIfRunning. -*/ - - -/*! - \fn TQString TQSessionManager::sessionId() const - - Returns the identifier of the current session. - - If the application has been restored from an earlier session, this - identifier is the same as it was in that earlier session. - - \sa sessionKey(), TQApplication::sessionId() - */ - -/*! - \fn TQString TQSessionManager::sessionKey() const - - Returns the session key in the current session. - - If the application has been restored from an earlier session, this - key is the same as it was when the previous session ended. - - The session key changes with every call of commitData() or - saveState(). - - \sa sessionId(), TQApplication::sessionKey() - */ - -// ### Note: This function is undocumented, since it is #ifdef'd. - -/*! - \fn void* TQSessionManager::handle() const - - X11 only: returns a handle to the current \c SmcConnection. -*/ - - -/*! - \fn bool TQSessionManager::allowsInteraction() - - Asks the session manager for permission to interact with the - user. Returns TRUE if interaction is permitted; otherwise - returns FALSE. - - The rationale behind this mechanism is to make it possible to - synchronize user interaction during a shutdown. Advanced session - managers may ask all applications simultaneously to commit their - data, resulting in a much faster shutdown. - - When the interaction is completed we strongly recommend releasing the - user interaction semaphore with a call to release(). This way, other - applications may get the chance to interact with the user while your - application is still busy saving data. (The semaphore is implicitly - released when the application exits.) - - If the user decides to cancel the shutdown process during the - interaction phase, you must tell the session manager that this has - happened by calling cancel(). - - Here's an example of how an application's TQApplication::commitData() - might be implemented: - -\code -void MyApplication::commitData( TQSessionManager& sm ) { - if ( sm.allowsInteraction() ) { - switch ( TQMessageBox::warning( - yourMainWindow, - tr("Application Name"), - tr("Save changes to document Foo?"), - tr("&Yes"), - tr("&No"), - tr("Cancel"), - 0, 2) ) { - case 0: // yes - sm.release(); - // save document here; if saving fails, call sm.cancel() - break; - case 1: // continue without saving - break; - default: // cancel - sm.cancel(); - break; - } - } else { - // we did not get permission to interact, then - // do something reasonable instead. - } -} -\endcode - - If an error occurred within the application while saving its data, - you may want to try allowsErrorInteraction() instead. - - \sa TQApplication::commitData(), release(), cancel() -*/ - - -/*! - \fn bool TQSessionManager::allowsErrorInteraction() - - This is similar to allowsInteraction(), but also tells the session - manager that an error occurred. Session managers may give error - interaction request higher priority, which means that it is more likely - that an error interaction is permitted. However, you are still not - guaranteed that the session manager will allow interaction. - - \sa allowsInteraction(), release(), cancel() -*/ - -/*! - \fn void TQSessionManager::release() - - Releases the session manager's interaction semaphore after an - interaction phase. - - \sa allowsInteraction(), allowsErrorInteraction() -*/ - -/*! - \fn void TQSessionManager::cancel() - - Tells the session manager to cancel the shutdown process. Applications - should not call this function without first asking the user. - - \sa allowsInteraction(), allowsErrorInteraction() - -*/ - -/*! - \fn void TQSessionManager::setRestartHint( RestartHint hint ) - - Sets the application's restart hint to \a hint. On application - startup the hint is set to \c RestartIfRunning. - - Note that these flags are only hints, a session manager may or may - not respect them. - - We recommend setting the restart hint in TQApplication::saveState() - because most session managers perform a checkpoint shortly after an - application's startup. - - \sa restartHint() -*/ - -/*! - \fn TQSessionManager::RestartHint TQSessionManager::restartHint() const - - Returns the application's current restart hint. The default is - \c RestartIfRunning. - - \sa setRestartHint() -*/ - -/*! - \fn void TQSessionManager::setRestartCommand( const TQStringList& command ) - - If the session manager is capable of restoring sessions it will - execute \a command in order to restore the application. The command - defaults to - - \code - appname -session id - \endcode - - The \c -session option is mandatory; otherwise TQApplication cannot - tell whether it has been restored or what the current session - identifier is. See TQApplication::isSessionRestored() and - TQApplication::sessionId() for details. - - If your application is very simple, it may be possible to store the - entire application state in additional command line options. This - is usually a very bad idea because command lines are often limited - to a few hundred bytes. Instead, use TQSettings, or temporary files - or a database for this purpose. By marking the data with the unique - sessionId(), you will be able to restore the application in a future - session. - - \sa restartCommand(), setDiscardCommand(), setRestartHint() -*/ - -/*! - \fn TQStringList TQSessionManager::restartCommand() const - - Returns the currently set restart command. - - Note that if you want to iterate over the list, you should - iterate over a copy, e.g. - \code - TQStringList list = mySession.restartCommand(); - TQStringList::Iterator it = list.begin(); - while( it != list.end() ) { - myProcessing( *it ); - ++it; - } - \endcode - - \sa setRestartCommand(), restartHint() -*/ - -/*! - \fn void TQSessionManager::setDiscardCommand( const TQStringList& ) - - \sa discardCommand(), setRestartCommand() -*/ - - -/*! - \fn TQStringList TQSessionManager::discardCommand() const - - Returns the currently set discard command. - - Note that if you want to iterate over the list, you should - iterate over a copy, e.g. - \code - TQStringList list = mySession.discardCommand(); - TQStringList::Iterator it = list.begin(); - while( it != list.end() ) { - myProcessing( *it ); - ++it; - } - \endcode - - \sa setDiscardCommand(), restartCommand(), setRestartCommand() -*/ - -/*! - \overload void TQSessionManager::setManagerProperty( const TQString& name, - const TQString& value ) - - Low-level write access to the application's identification and state - records are kept in the session manager. - - The property called \a name has its value set to the string \a value. -*/ - -/*! - \fn void TQSessionManager::setManagerProperty( const TQString& name, - const TQStringList& value ) - - Low-level write access to the application's identification and state - record are kept in the session manager. - - The property called \a name has its value set to the string list \a value. -*/ - -/*! - \fn bool TQSessionManager::isPhase2() const - - Returns TRUE if the session manager is currently performing a second - session management phase; otherwise returns FALSE. - - \sa requestPhase2() -*/ - -/*! - \fn void TQSessionManager::requestPhase2() - - Requests a second session management phase for the application. The - application may then return immediately from the - TQApplication::commitData() or TQApplication::saveState() function, - and they will be called again once most or all other applications have - finished their session management. - - The two phases are useful for applications such as the X11 window manager - that need to store information about another application's windows - and therefore have to wait until these applications have completed their - respective session management tasks. - - Note that if another application has requested a second phase it - may get called before, simultaneously with, or after your - application's second phase. - - \sa isPhase2() -*/ - -/*! - \fn int TQApplication::horizontalAlignment( int align ) - - Strips out vertical alignment flags and transforms an - alignment \a align of AlignAuto into AlignLeft or - AlignRight according to the language used. The other horizontal - alignment flags are left untouched. -*/ - - -/***************************************************************************** - Stubbed session management support - *****************************************************************************/ -#ifndef TQT_NO_SESSIONMANAGER -#if defined( TQT_NO_SM_SUPPORT ) || defined( TQ_WS_WIN ) || defined( TQ_WS_MAC ) - -class TQSessionManagerData -{ -public: - TQStringList restartCommand; - TQStringList discardCommand; - TQString sessionId; - TQString sessionKey; - TQSessionManager::RestartHint restartHint; -}; - -TQSessionManager* qt_session_manager_self = 0; -TQSessionManager::TQSessionManager( TQApplication * app, TQString &id, TQString &key ) - : TQObject( app, "qt_sessionmanager" ) -{ - qt_session_manager_self = this; - d = new TQSessionManagerData; -#if defined(TQ_WS_WIN) && !defined(Q_OS_TEMP) - wchar_t guidstr[40]; - GUID guid; - CoCreateGuid( &guid ); - StringFromGUID2(guid, guidstr, 40); - id = TQString::fromUcs2((ushort*)guidstr); - CoCreateGuid( &guid ); - StringFromGUID2(guid, guidstr, 40); - key = TQString::fromUcs2((ushort*)guidstr); -#endif - d->sessionId = id; - d->sessionKey = key; - d->restartHint = RestartIfRunning; -} - -TQSessionManager::~TQSessionManager() -{ - delete d; - qt_session_manager_self = 0; -} - -TQString TQSessionManager::sessionId() const -{ - return d->sessionId; -} - -TQString TQSessionManager::sessionKey() const -{ - return d->sessionKey; -} - - -#if defined(TQ_WS_X11) || defined(TQ_WS_MAC) -void* TQSessionManager::handle() const -{ - return 0; -} -#endif - -#if !defined(TQ_WS_WIN) -bool TQSessionManager::allowsInteraction() -{ - return TRUE; -} - -bool TQSessionManager::allowsErrorInteraction() -{ - return TRUE; -} -void TQSessionManager::release() -{ -} - -void TQSessionManager::cancel() -{ -} -#endif - - -void TQSessionManager::setRestartHint( TQSessionManager::RestartHint hint) -{ - d->restartHint = hint; -} - -TQSessionManager::RestartHint TQSessionManager::restartHint() const -{ - return d->restartHint; -} - -void TQSessionManager::setRestartCommand( const TQStringList& command) -{ - d->restartCommand = command; -} - -TQStringList TQSessionManager::restartCommand() const -{ - return d->restartCommand; -} - -void TQSessionManager::setDiscardCommand( const TQStringList& command) -{ - d->discardCommand = command; -} - -TQStringList TQSessionManager::discardCommand() const -{ - return d->discardCommand; -} - -void TQSessionManager::setManagerProperty( const TQString&, const TQString&) -{ -} - -void TQSessionManager::setManagerProperty( const TQString&, const TQStringList& ) -{ -} - -bool TQSessionManager::isPhase2() const -{ - return FALSE; -} - -void TQSessionManager::requestPhase2() -{ -} - -#endif // TQT_NO_SM_SUPPORT -#endif //TQT_NO_SESSIONMANAGER diff --git a/src/kernel/qapplication_p.h b/src/kernel/qapplication_p.h deleted file mode 100644 index 08911eae7..000000000 --- a/src/kernel/qapplication_p.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Definition of some TQt private functions. -** -** Created : 000228 -** -** Copyright (C) 2000-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_P_H -#define TQAPPLICATION_P_H - - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of qapplication_*.cpp, tqwidget*.cpp, tqcolor_x11.cpp, tqfiledialog.cpp -// and many other. This header file may change from version to version -// without notice, or even be removed. -// -// We mean it. -// -// - -#ifndef QT_H -#endif // QT_H - -class TQWidget; -class TQObject; -class TQClipboard; -class TQKeyEvent; -class TQMouseEvent; -class TQWheelEvent; - -extern TQ_EXPORT bool tqt_modal_state(); -extern TQ_EXPORT void tqt_enter_modal( TQWidget* ); -extern TQ_EXPORT void tqt_leave_modal( TQWidget* ); - -extern bool tqt_is_gui_used; -#ifndef TQT_NO_CLIPBOARD -extern TQClipboard *tqt_clipboard; -#endif - -#if defined (Q_OS_WIN32) || defined (Q_OS_CYGWIN) -extern TQt::WindowsVersion qt_winver; -const int QT_TABLET_NPACKETQSIZE = 128; -# ifdef Q_OS_TEMP - extern DWORD qt_cever; -# endif -#elif defined (Q_OS_MAC) -extern TQt::MacintoshVersion qt_macver; -#endif - -#if defined (TQ_WS_X11) -extern int qt_ncols_option; -#endif - - -extern void tqt_dispatchEnterLeave( TQWidget*, TQWidget* ); -extern bool tqt_tryModalHelper( TQWidget *, TQWidget ** = 0 ); - -#endif diff --git a/src/kernel/qapplication_x11.cpp b/src/kernel/qapplication_x11.cpp deleted file mode 100644 index ec94e78b5..000000000 --- a/src/kernel/qapplication_x11.cpp +++ /dev/null @@ -1,6732 +0,0 @@ -/**************************************************************************** -** -** Implementation of X11 startup routines and event handling -** -** Created : 931029 -** -** 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. -** -**********************************************************************/ - -// ### 4.0: examine TQ_EXPORT's below. The respective symbols had all -// been in use (e.g. in the KDE wm ) before the introduction of a version -// map. One might want to turn some of them into propert public API and -// provide a proper alternative for others. See also the exports in -// qapplication_win.cpp which suggest a unification. - -#include "qplatformdefs.h" - -// POSIX Large File Support redefines open -> open64 -#if defined(open) -# undef open -#endif - -// Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED. -#if defined(connect) -# undef connect -#endif - -// POSIX Large File Support redefines truncate -> truncate64 -#if defined(truncate) -# undef truncate -#endif - -#include "ntqapplication.h" -#include "qapplication_p.h" -#include "tqcolor_p.h" -#include "tqcursor.h" -#include "tqwidget.h" -#include "tqwidget_p.h" -#include "tqobjectlist.h" -#include "tqwidgetlist.h" -#include "tqwidgetintdict.h" -#include "tqbitarray.h" -#include "tqpainter.h" -#include "tqpixmapcache.h" -#include "tqdatetime.h" -#include "tqtextcodec.h" -#include "tqdatastream.h" -#include "tqbuffer.h" -#include "tqsocketnotifier.h" -#include "tqsessionmanager.h" -#include "tqvaluelist.h" -#include "tqdict.h" -#include "tqguardedptr.h" -#include "tqclipboard.h" -#include "tqwhatsthis.h" // ######## dependency -#include "tqsettings.h" -#include "tqstylefactory.h" -#include "tqfileinfo.h" - -// Input method stuff - UNFINISHED -#ifndef TQT_NO_IM -#include "tqinputcontext.h" -#endif // TQT_NO_IM -#include "tqinternal_p.h" // shared double buffer cleanup - -#if defined(TQT_THREAD_SUPPORT) -# include "tqthread.h" -#endif - -#if defined(QT_DEBUG) && defined(Q_OS_LINUX) -# include "tqfile.h" -#endif - -#include "tqt_x11_p.h" - -#if !defined(TQT_NO_XFTFREETYPE) -// XFree86 4.0.3 implementation is missing XftInitFtLibrary forward -extern "C" Bool XftInitFtLibrary(void); -#endif - -#include -#include -#include -#include -#include - -//#define X_NOT_BROKEN -#ifdef X_NOT_BROKEN -// Some X libraries are built with setlocale #defined to _Xsetlocale, -// even though library users are then built WITHOUT such a definition. -// This creates a problem - TQt might setlocale() one value, but then -// X looks and doesn't see the value TQt set. The solution here is to -// implement _Xsetlocale just in case X calls it - redirecting it to -// the real libC version. -// -# ifndef setlocale -extern "C" char *_Xsetlocale(int category, const char *locale); -char *_Xsetlocale(int category, const char *locale) -{ - //tqDebug("_Xsetlocale(%d,%s),category,locale"); - return setlocale(category,locale); -} -# endif // setlocale -#endif // X_NOT_BROKEN - - -// resolve the conflict between X11's FocusIn and TQEvent::FocusIn -const int XFocusOut = FocusOut; -const int XFocusIn = FocusIn; -#undef FocusOut -#undef FocusIn - -const int XKeyPress = KeyPress; -const int XKeyRelease = KeyRelease; -#undef KeyPress -#undef KeyRelease - - -// Fix old X libraries -#ifndef XK_KP_Home -#define XK_KP_Home 0xFF95 -#endif -#ifndef XK_KP_Left -#define XK_KP_Left 0xFF96 -#endif -#ifndef XK_KP_Up -#define XK_KP_Up 0xFF97 -#endif -#ifndef XK_KP_Right -#define XK_KP_Right 0xFF98 -#endif -#ifndef XK_KP_Down -#define XK_KP_Down 0xFF99 -#endif -#ifndef XK_KP_Prior -#define XK_KP_Prior 0xFF9A -#endif -#ifndef XK_KP_Next -#define XK_KP_Next 0xFF9B -#endif -#ifndef XK_KP_End -#define XK_KP_End 0xFF9C -#endif -#ifndef XK_KP_Insert -#define XK_KP_Insert 0xFF9E -#endif -#ifndef XK_KP_Delete -#define XK_KP_Delete 0xFF9F -#endif - - -/***************************************************************************** - Internal variables and functions - *****************************************************************************/ -static const char *appName; // application name -static const char *appClass; // application class -static const char *appFont = 0; // application font -static const char *appBGCol = 0; // application bg color -static const char *appFGCol = 0; // application fg color -static const char *appBTNCol = 0; // application btn color -static const char *mwGeometry = 0; // main widget geometry -static const char *mwTitle = 0; // main widget title -//Ming-Che 10/10 -TQ_EXPORT char *qt_ximServer = 0; // XIM Server will connect to -static bool mwIconic = FALSE; // main widget iconified -//Ming-Che 10/10 -static Display *appDpy = 0; // X11 application display -static char *appDpyName = 0; // X11 display name -static bool appForeignDpy = FALSE; // we didn't create display -static bool appSync = FALSE; // X11 synchronization -#if defined(QT_DEBUG) -static bool appNoGrab = FALSE; // X11 grabbing enabled -static bool appDoGrab = FALSE; // X11 grabbing override (gdb) -#endif -static int appScreen; // X11 screen number -static int appScreenCount; // X11 screen count -static bool app_save_rootinfo = FALSE; // save root info -static bool app_do_modal = FALSE; // modal mode -static Window curWin = 0; // current window - -static GC* app_gc_ro = 0; // read-only GC -static GC* app_gc_tmp = 0; // temporary GC -static GC* app_gc_ro_m = 0; // read-only GC (monochrome) -static GC* app_gc_tmp_m = 0; // temporary GC (monochrome) -// symbols needed by extern TQXEmbed class -TQ_EXPORT Atom tqt_wm_protocols = 0; // window manager protocols -TQ_EXPORT Atom tqt_wm_delete_window = 0; // delete window protocol -TQ_EXPORT Atom tqt_wm_take_focus = 0; // take focus window protocol - -Atom qt_qt_scrolldone = 0; // scroll synchronization -Atom qt_net_wm_context_help = 0; // context help -Atom qt_net_wm_ping = 0; // _NET_WM_PING protocol - -static Atom qt_xsetroot_id = 0; -Atom qt_xa_clipboard = 0; -Atom qt_selection_property = 0; -Atom tqt_clipboard_sentinel = 0; -Atom qt_selection_sentinel = 0; -TQ_EXPORT Atom tqt_wm_state = 0; -Atom qt_wm_change_state = 0; -static Atom qt_settings_timestamp = 0; // TQt >=3 settings timestamp -static Atom qt_input_encoding = 0; // TQt desktop properties -static Atom qt_resource_manager = 0; // X11 Resource manager -Atom qt_sizegrip = 0; // sizegrip -Atom qt_wm_client_leader = 0; -TQ_EXPORT Atom tqt_window_role = 0; -TQ_EXPORT Atom tqt_sm_client_id = 0; -Atom qt_xa_motif_wm_hints = 0; -Atom qt_cde_running = 0; -Atom qt_twin_running = 0; -Atom qt_kwm_running = 0; -Atom qt_gbackground_properties = 0; -Atom qt_x_incr = 0; -Atom qt_utf8_string = 0; - -// detect broken window managers -Atom qt_sgi_desks_manager = 0; -bool qt_broken_wm = FALSE; -static void qt_detect_broken_window_manager(); - -// NET WM support -Atom qt_net_supported = 0; -Atom qt_net_wm_name = 0; -Atom qt_net_wm_icon_name = 0; -Atom qt_net_virtual_roots = 0; -Atom qt_net_workarea = 0; -Atom qt_net_wm_state = 0; -Atom qt_net_wm_state_modal = 0; -Atom qt_net_wm_state_max_v = 0; -Atom qt_net_wm_state_max_h = 0; -Atom qt_net_wm_state_fullscreen = 0; -Atom qt_net_wm_state_above = 0; -Atom qt_net_wm_action = 0; -Atom qt_net_wm_action_move = 0; -Atom qt_net_wm_action_resize = 0; -Atom qt_net_wm_action_minimize = 0; -Atom qt_net_wm_action_shade = 0; -Atom qt_net_wm_action_stick = 0; -Atom qt_net_wm_action_max_h = 0; -Atom qt_net_wm_action_max_v = 0; -Atom qt_net_wm_action_fullscreen = 0; -Atom qt_net_wm_action_change_desktop = 0; -Atom qt_net_wm_action_close = 0; -Atom qt_net_wm_action_above = 0; -Atom qt_net_wm_action_below = 0; -Atom qt_net_wm_window_type = 0; -Atom qt_net_wm_window_type_normal = 0; -Atom qt_net_wm_window_type_dialog = 0; -Atom qt_net_wm_window_type_toolbar = 0; -Atom qt_net_wm_window_type_menu = 0; -Atom qt_net_wm_window_type_utility = 0; -Atom qt_net_wm_window_type_splash = 0; -Atom qt_net_wm_window_type_override = 0; // KDE extension -Atom qt_net_wm_window_type_dropdown_menu = 0; -Atom qt_net_wm_window_type_popup_menu = 0; -Atom qt_net_wm_window_type_tooltip = 0; -Atom qt_net_wm_window_type_combo = 0; -Atom qt_net_wm_window_type_dnd = 0; -Atom qt_net_wm_frame_strut = 0; // KDE extension -Atom qt_net_wm_state_stays_on_top = 0; // KDE extension -Atom qt_net_wm_pid = 0; -Atom qt_net_wm_user_time = 0; -Atom qt_net_wm_full_placement = 0; // KDE extension -// Enlightenment support -Atom qt_enlightenment_desktop = 0; - -// window managers list of supported "stuff" -Atom *qt_net_supported_list = 0; -// list of virtual root windows -Window *qt_net_virtual_root_list = 0; - - -// X11 SYNC support -#ifndef TQT_NO_XSYNC -Atom qt_net_wm_sync_request_counter = 0; -Atom qt_net_wm_sync_request = 0; -#endif - -// client leader window -Window qt_x11_wm_client_leader = 0; - -// function to update the workarea of the screen - in tqdesktopwidget_x11.cpp -extern void qt_desktopwidget_update_workarea(); - -// current focus model -static const int FocusModel_Unknown = -1; -static const int FocusModel_Other = 0; -static const int FocusModel_PointerRoot = 1; -static int qt_focus_model = -1; - -#ifndef TQT_NO_XRANDR -// TRUE if TQt is compiled w/ XRandR support and XRandR exists on the connected -// Display -bool qt_use_xrandr = FALSE; -static int xrandr_eventbase; -#endif - -// TRUE if TQt is compiled w/ XRender support and XRender exists on the connected -// Display -TQ_EXPORT bool tqt_use_xrender = FALSE; - -#ifndef TQT_NO_XSYNC -// True if SYNC extension exists on the connected display -bool qt_use_xsync = FALSE; -static int xsync_eventbase; -static int xsync_errorbase; -#endif - -// modifier masks for alt/meta - detected when the application starts -static long qt_alt_mask = 0; -static long qt_meta_mask = 0; -// modifier mask to remove mode switch from modifiers that have alt/meta set -// this problem manifests itself on HP/UX 10.20 at least, and without it -// modifiers do not work at all... -static long qt_mode_switch_remove_mask = 0; - -// flags for extensions for special Languages, currently only for RTL languages -static bool qt_use_rtl_extensions = FALSE; -TQ_EXPORT bool tqt_hebrew_keyboard_hack = FALSE; - -static Window mouseActWindow = 0; // window where mouse is -static int mouseButtonPressed = 0; // last mouse button pressed -static int mouseButtonState = 0; // mouse button state -static Time mouseButtonPressTime = 0; // when was a button pressed -static short mouseXPos, mouseYPos; // mouse pres position in act window -static short mouseGlobalXPos, mouseGlobalYPos; // global mouse press position - -extern TQWidgetList *tqt_modal_stack; // stack of modal widgets -static bool ignoreNextMouseReleaseEvent = FALSE; // ignore the next mouse release - // event if return from a modal - // widget - -static TQWidget *popupButtonFocus = 0; -static TQWidget *popupOfPopupButtonFocus = 0; -static bool popupCloseDownMode = FALSE; -static bool popupGrabOk; - -static bool sm_blockUserInput = FALSE; // session management - -int qt_xfocusout_grab_counter = 0; - -#if defined (QT_TABLET_SUPPORT) -// since XInput event classes aren't created until we actually open an XInput -// device, here is a static list that we will use later on... -const int INVALID_EVENT = -1; -const int TOTAL_XINPUT_EVENTS = 7; - -XDevice *devStylus = NULL; -XDevice *devEraser = NULL; -XEventClass event_list_stylus[TOTAL_XINPUT_EVENTS]; -XEventClass event_list_eraser[TOTAL_XINPUT_EVENTS]; - -int qt_curr_events_stylus = 0; -int qt_curr_events_eraser = 0; - -// well, luckily we only need to do this once. -static int xinput_motion = INVALID_EVENT; -static int xinput_key_press = INVALID_EVENT; -static int xinput_key_release = INVALID_EVENT; -static int xinput_button_press = INVALID_EVENT; -static int xinput_button_release = INVALID_EVENT; - -// making this assumption on XFree86, since we can only use 1 device, -// the pressure for the eraser and the stylus should be the same, if they aren't -// well, they certainly have a strange pen then... -static int max_pressure; -extern bool chokeMouse; -#endif - -// last timestamp read from TQSettings -static uint appliedstamp = 0; - - -typedef int (*QX11EventFilter) (XEvent*); -QX11EventFilter tqt_set_x11_event_filter(QX11EventFilter filter); - -static QX11EventFilter qt_x11_event_filter = 0; -TQ_EXPORT QX11EventFilter tqt_set_x11_event_filter(QX11EventFilter filter) -{ - QX11EventFilter old_filter = qt_x11_event_filter; - qt_x11_event_filter = filter; - return old_filter; -} -static bool qt_x11EventFilter( XEvent* ev ) -{ - if ( qt_x11_event_filter && qt_x11_event_filter( ev ) ) - return TRUE; - return tqApp->x11EventFilter( ev ); -} - - - - - -#if !defined(TQT_NO_XIM) -//XIM qt_xim = 0; -TQ_EXPORT XIMStyle qt_xim_style = 0; -TQ_EXPORT XIMStyle qt_xim_preferred_style = 0; -static XIMStyle xim_default_style = XIMPreeditCallbacks | XIMStatusNothing; -#endif - -TQ_EXPORT int qt_ximComposingKeycode=0; -TQ_EXPORT TQTextCodec * qt_input_mapper = 0; - -TQ_EXPORT Time tqt_x_time = CurrentTime; -TQ_EXPORT Time tqt_x_user_time = CurrentTime; -extern bool qt_check_clipboard_sentinel(); //def in tqclipboard_x11.cpp -extern bool qt_check_selection_sentinel(); //def in tqclipboard_x11.cpp - -static void qt_save_rootinfo(); -bool tqt_try_modal( TQWidget *, XEvent * ); - -int qt_ncols_option = 216; // used in tqcolor_x11.cpp -int qt_visual_option = -1; -bool qt_cmap_option = FALSE; -TQWidget *qt_button_down = 0; // widget got last button-down - -extern bool tqt_tryAccelEvent( TQWidget*, TQKeyEvent* ); // def in tqaccel.cpp - -struct TQScrollInProgress { - static long serial; - TQScrollInProgress( TQWidget* w, int x, int y ) : - id( serial++ ), scrolled_widget( w ), dx( x ), dy( y ) {} - long id; - TQWidget* scrolled_widget; - int dx, dy; -}; -long TQScrollInProgress::serial=0; -static TQPtrList *sip_list = 0; - - -// stuff in qt_xdnd.cpp -// setup -extern void qt_xdnd_setup(); -// x event handling -extern void qt_handle_xdnd_enter( TQWidget *, const XEvent *, bool ); -extern void qt_handle_xdnd_position( TQWidget *, const XEvent *, bool ); -extern void qt_handle_xdnd_status( TQWidget *, const XEvent *, bool ); -extern void qt_handle_xdnd_leave( TQWidget *, const XEvent *, bool ); -extern void qt_handle_xdnd_drop( TQWidget *, const XEvent *, bool ); -extern void qt_handle_xdnd_finished( TQWidget *, const XEvent *, bool ); -extern void qt_xdnd_handle_selection_request( const XSelectionRequestEvent * ); -extern bool qt_xdnd_handle_badwindow(); - -extern void qt_motifdnd_handle_msg( TQWidget *, const XEvent *, bool ); -extern void qt_x11_motifdnd_init(); - -// client message atoms -extern Atom qt_xdnd_enter; -extern Atom qt_xdnd_position; -extern Atom qt_xdnd_status; -extern Atom qt_xdnd_leave; -extern Atom qt_xdnd_drop; -extern Atom qt_xdnd_finished; -// xdnd selection atom -extern Atom qt_xdnd_selection; -extern bool qt_xdnd_dragging; - -// gui or non-gui from qapplication.cpp -extern bool tqt_is_gui_used; -extern bool tqt_app_has_font; - -static bool qt_x11_cmdline_font = false; - - -extern bool tqt_resolve_symlinks; // from qapplication.cpp - -// Paint event clipping magic -extern void qt_set_paintevent_clipping( TQPaintDevice* dev, const TQRegion& region); -extern void qt_clear_paintevent_clipping(); - - -// Palette handling -extern TQPalette *tqt_std_pal; -extern void tqt_create_std_palette(); - -void qt_x11_intern_atom( const char *, Atom * ); - -static TQPtrList* deferred_map_list = 0; -static void qt_deferred_map_cleanup() -{ - delete deferred_map_list; - deferred_map_list = 0; -} -void qt_deferred_map_add( TQWidget* w) -{ - if ( !deferred_map_list ) { - deferred_map_list = new TQPtrList; - tqAddPostRoutine( qt_deferred_map_cleanup ); - } - deferred_map_list->append( w ); -} -void qt_deferred_map_take( TQWidget* w ) -{ - if (deferred_map_list ) { - deferred_map_list->remove( w ); - } -} -bool qt_deferred_map_contains( TQWidget* w ) -{ - if (!deferred_map_list) - return FALSE; - else - return deferred_map_list->contains( w ); -} - - -class TQETWidget : public TQWidget // event translator widget -{ -public: - void setWState( WFlags f ) { TQWidget::setWState(f); } - void clearWState( WFlags f ) { TQWidget::clearWState(f); } - void setWFlags( WFlags f ) { TQWidget::setWFlags(f); } - void clearWFlags( WFlags f ) { TQWidget::clearWFlags(f); } - bool translateMouseEvent( const XEvent * ); - bool translateKeyEventInternal( const XEvent *, int& count, TQString& text, int& state, char& ascii, int &code, TQEvent::Type &type, bool willRepeat=FALSE, bool statefulTranslation=TRUE ); - bool translateKeyEvent( const XEvent *, bool grab ); - bool translatePaintEvent( const XEvent * ); - bool translateConfigEvent( const XEvent * ); - bool translateCloseEvent( const XEvent * ); - bool translateScrollDoneEvent( const XEvent * ); - bool translateWheelEvent( int global_x, int global_y, int delta, int state, Orientation orient ); -#if defined (QT_TABLET_SUPPORT) - bool translateXinputEvent( const XEvent* ); -#endif - bool translatePropertyEvent(const XEvent *); -}; - - - - -// ************************************************************************ -// Input Method support -// ************************************************************************ - -/*! - An identifier name of the default input method. -*/ -TQString TQApplication::defaultIM = "imsw-multi"; - - -/*! - This function handles the query about location of the widget - holding the TQInputContext instance for widget \a w. - - The input context is used for text input to widget \a w. By - default, it returns the top-level widget of \a w. - - If you want to change the mapping of widget \w to TQInputContext - instance, reimplement both this function and - TQApplication::icHolderWidgets(). For example, suppose a tabbed web - browser. The browser should allocate a input context per tab - widget because users may switch the tabs and input a new text - during previous input contexts live. - - See also 'Sharing input context between text widgets' and 'Preedit - preservation' section of the class description of TQInputContext. - - \sa TQInputContext, icHolderWidgets() -*/ -TQWidget *TQApplication::locateICHolderWidget( TQWidget *w ) -{ - return w->topLevelWidget(); -} - - -/*! - This function returns all widgets holding TQInputContext. - - By default, This function returns top-level widgets. So if you - want to change the mapping of a widget to TQInputContext instance, - you must override this function and locateICHolderWidget(). - - \sa locateICHolderWidget() -*/ -TQWidgetList *TQApplication::icHolderWidgets() -{ - return TQApplication::topLevelWidgets(); -} - - -/*! - This function replaces all TQInputContext instances in the - application. The function's argument is the identifier name of - the newly selected input method. -*/ -void TQApplication::changeAllInputContext( const TQString &identifierName ) -{ - TQWidgetList *list = tqApp->icHolderWidgets(); - TQWidgetListIt it(*list); - while(it.current()) { - it.current()->changeInputContext( identifierName ); - ++it; - } - delete list; - - // defaultIM = identifierName ; // Change of defaultIM -- default input method -- may be enabled. -} - - -/*! - \internal - This is an internal function, you should never call this. - - \sa TQInputContext::imEventGenerated() -*/ -void TQApplication::postIMEvent( TQObject *receiver, TQIMEvent *event ) -{ - if ( event->type() == TQEvent::IMCompose ) { - // enable event compression to reduce preedit flicker on fast - // typing - postEvent( receiver, event ); - } else { - // cancel queued preedit update - if ( event->type() == TQEvent::IMEnd ) - removePostedEvents( receiver, TQEvent::IMCompose ); - - // to avoid event receiving order inversion between TQKeyEvent - // and TQIMEvent, we must send IMStart and IMEnd via - // sendEvent(). - sendEvent( receiver, event ); - delete event; - } -} - - -/*! - This function returns the identifier name of the default input - method in this Application. The value is identical to the value of - TQApplication::defaultIM. -*/ -TQString TQApplication::defaultInputMethod() -{ - return TQApplication::defaultIM; -} - - -#if !defined(TQT_NO_IM_EXTENSIONS) -/*! \internal - Creates the application input method. -*/ -void TQApplication::create_im() -{ -#ifndef TQT_NO_XIM - if ( ! qt_xim_preferred_style ) // no configured input style, use the default - qt_xim_preferred_style = xim_default_style; -#endif // TQT_NO_XIM -} - - -/*! \internal - Closes the application input method. -*/ -void TQApplication::close_im() -{ - TQWidgetList *list = tqApp->icHolderWidgets(); - TQWidgetListIt it(*list); - while(it.current()) { - it.current()->destroyInputContext(); - ++it; - } - delete list; -} - -#else - -/*! \internal - Creates the application input method. -*/ -void TQApplication::create_xim() -{ -#ifndef TQT_NO_XIM - if ( ! qt_xim_preferred_style ) // no configured input style, use the default - qt_xim_preferred_style = xim_default_style; -#endif // TQT_NO_XIM - - TQWidgetList *list= tqApp->topLevelWidgets(); - TQWidgetListIt it(*list); - TQWidget * w; - while( (w=it.current()) != 0 ) { - ++it; - w->createTLSysExtra(); - } - delete list; -} - - - /*! \internal - Closes the application input method. - */ -void TQApplication::close_xim() -{ -#ifndef TQT_NO_XIM - // Calling XCloseIM gives a Purify FMR error - // XCloseIM( qt_xim ); - // We prefer a less serious memory leak - - // if ( qt_xim ) - // qt_xim = 0; - -#endif // TQT_NO_XIM - TQWidgetList *list = tqApp->topLevelWidgets(); - TQWidgetListIt it(*list); - while(it.current()) { - it.current()->destroyInputContext(); - ++it; - } - delete list; -} -#endif - -/***************************************************************************** - Default X error handlers - *****************************************************************************/ - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -static bool x11_ignore_badwindow; -static bool x11_badwindow; - - // starts to ignore bad window errors from X -void qt_ignore_badwindow() -{ - x11_ignore_badwindow = TRUE; - x11_badwindow = FALSE; -} - - // ends ignoring bad window errors and returns whether an error - // had happen. -bool qt_badwindow() -{ - x11_ignore_badwindow = FALSE; - return x11_badwindow; -} - -static int (*original_x_errhandler)( Display *dpy, XErrorEvent * ); -static int (*original_xio_errhandler)( Display *dpy ); - -static int qt_x_errhandler( Display *dpy, XErrorEvent *err ) -{ - if ( err->error_code == BadWindow ) { - x11_badwindow = TRUE; - if ( err->request_code == 25 /* X_SendEvent */ && - qt_xdnd_handle_badwindow() ) - return 0; - if ( x11_ignore_badwindow ) - return 0; - } else if ( err->error_code == BadMatch && - err->request_code == 42 /* X_SetInputFocus */ ) { - return 0; - } - - char errstr[256]; - XGetErrorText( dpy, err->error_code, errstr, 256 ); - tqWarning( "X Error: %s %d\n" - " Major opcode: %d\n" - " Minor opcode: %d\n" - " Resource id: 0x%lx", - errstr, err->error_code, - err->request_code, - err->minor_code, - err->resourceid ); - - // ### we really should distinguish between severe, non-severe and - // ### application specific errors - - return 0; -} - - -static int qt_xio_errhandler( Display * ) -{ - tqWarning( "%s: Fatal IO error: client killed", appName ); - tqApp = 0; - exit( 1 ); - //### give the application a chance for a proper shutdown instead, - //### exit(1) doesn't help. - return 0; -} - -#if defined(Q_C_CALLBACKS) -} -#endif - - -// Memory leak: if the app exits before tqt_init_internal(), this dict -// isn't released correctly. -static TQAsciiDict *atoms_to_be_created = 0; -static bool create_atoms_now = 0; - -/***************************************************************************** - qt_x11_intern_atom() - efficiently interns an atom, now or later. - - If the application is being initialized, this function stores the - adddress of the atom and tqt_init_internal will do the actual work - quickly. If the application is running, the atom is created here. - - Neither argument may point to temporary variables. - *****************************************************************************/ - -void qt_x11_intern_atom( const char *name, Atom *result) -{ - if ( !name || !result || *result ) - return; - - if ( create_atoms_now ) { - *result = XInternAtom( appDpy, name, False ); - } else { - if ( !atoms_to_be_created ) { - atoms_to_be_created = new TQAsciiDict; - atoms_to_be_created->setAutoDelete( FALSE ); - } - atoms_to_be_created->insert( name, result ); - *result = 0; - } -} - - -static void tqt_x11_process_intern_atoms() -{ - if ( atoms_to_be_created ) { -#if defined(XlibSpecificationRelease) && (XlibSpecificationRelease >= 6) - int i = atoms_to_be_created->count(); - Atom * res = (Atom *)malloc( i * sizeof( Atom ) ); - Atom ** resp = (Atom **)malloc( i * sizeof( Atom* ) ); - char ** names = (char **)malloc( i * sizeof(const char*)); - - i = 0; - TQAsciiDictIterator it( *atoms_to_be_created ); - while( it.current() ) { - res[i] = 0; - resp[i] = it.current(); - names[i] = tqstrdup(it.currentKey()); - i++; - ++it; - } - XInternAtoms( appDpy, names, i, False, res ); - while( i ) { - i--; - delete [] names[i]; - if ( res[i] && resp[i] ) - *(resp[i]) = res[i]; - } - free( res ); - free( resp ); - free( names ); -#else - TQAsciiDictIterator it( *atoms_to_be_created ); - Atom * result; - const char * name; - while( (result = it.current()) != 0 ) { - name = it.currentKey(); - ++it; - *result = XInternAtom( appDpy, name, False ); - } -#endif - delete atoms_to_be_created; - atoms_to_be_created = 0; - create_atoms_now = TRUE; - } -} - - -/*! \internal - apply the settings to the application -*/ -bool TQApplication::x11_apply_settings() -{ - if (! tqt_std_pal) - tqt_create_std_palette(); - - Atom type; - int format; - long offset = 0; - unsigned long nitems, after = 1; - unsigned char *data = 0; - TQDateTime timestamp, settingsstamp; - bool update_timestamp = FALSE; - - if (XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow( 0 ), - qt_settings_timestamp, 0, 0, - False, AnyPropertyType, &type, &format, &nitems, - &after, &data) == Success && format == 8) { - if (data) - XFree(data); - - TQBuffer ts; - ts.open(IO_WriteOnly); - - while (after > 0) { - XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow( 0 ), - qt_settings_timestamp, - offset, 1024, False, AnyPropertyType, - &type, &format, &nitems, &after, &data); - if (format == 8) { - ts.writeBlock((const char *) data, nitems); - offset += nitems / 4; - } - - XFree(data); - } - - TQDataStream d(ts.buffer(), IO_ReadOnly); - d >> timestamp; - } - - TQSettings settings; - settingsstamp = settings.lastModificationTime( "/qt/font" ); - if (! settingsstamp.isValid()) - return FALSE; - - if ( appliedstamp && appliedstamp == settingsstamp.toTime_t() ) - return TRUE; - appliedstamp = settingsstamp.toTime_t(); - - if (! timestamp.isValid() || settingsstamp > timestamp) - update_timestamp = TRUE; - - /* - TQt settings. This is now they are written into the datastream. - - /qt/Palette/ * - TQPalette - /qt/font - TQFont - /qt/libraryPath - TQStringList - /qt/style - TQString - /qt/doubleClickInterval - int - /qt/cursorFlashTime - int - /qt/wheelScrollLines - int - /qt/colorSpec - TQString - /qt/defaultCodec - TQString - /qt/globalStrut - TQSize - /qt/GUIEffects - TQStringList - /qt/Font Substitutions/ * - TQStringList - /qt/Font Substitutions/... - TQStringList - */ - - TQString str; - TQStringList strlist; - int i, num; - TQPalette pal(TQApplication::palette()); - strlist = settings.readListEntry("/qt/Palette/active"); - if (strlist.count() == TQColorGroup::NColorRoles) { - for (i = 0; i < TQColorGroup::NColorRoles; i++) - pal.setColor(TQPalette::Active, (TQColorGroup::ColorRole) i, - TQColor(strlist[i])); - } - strlist = settings.readListEntry("/qt/Palette/inactive"); - if (strlist.count() == TQColorGroup::NColorRoles) { - for (i = 0; i < TQColorGroup::NColorRoles; i++) - pal.setColor(TQPalette::Inactive, (TQColorGroup::ColorRole) i, - TQColor(strlist[i])); - } - strlist = settings.readListEntry("/qt/Palette/disabled"); - if (strlist.count() == TQColorGroup::NColorRoles) { - for (i = 0; i < TQColorGroup::NColorRoles; i++) - pal.setColor(TQPalette::Disabled, (TQColorGroup::ColorRole) i, - TQColor(strlist[i])); - } - - // workaround for KDE 3.0, which messes up the buttonText value of - // the disabled palette in TQSettings - if ( pal.disabled().buttonText() == pal.active().buttonText() ) { - pal.setColor( TQPalette::Disabled, TQColorGroup::ButtonText, - pal.disabled().foreground() ); - } - - if (pal != *tqt_std_pal && pal != TQApplication::palette()) { - TQApplication::setPalette(pal, TRUE); - *tqt_std_pal = pal; - } - - TQFont font(TQApplication::font()); - if ( !tqt_app_has_font && !qt_x11_cmdline_font ) { - // read new font - str = settings.readEntry("/qt/font"); - if (! str.isNull() && ! str.isEmpty()) { - font.fromString(str); - - if (font != TQApplication::font()) - TQApplication::setFont(font, TRUE); - } - } - - // read library (ie. plugin) path list - TQString libpathkey = - TQString("/qt/%1.%2/libraryPath").arg( TQT_VERSION >> 16 ).arg( (TQT_VERSION & 0xff00 ) >> 8 ); - TQStringList pathlist = settings.readListEntry(libpathkey, ':'); - if (! pathlist.isEmpty()) { - TQStringList::ConstIterator it = pathlist.begin(); - while (it != pathlist.end()) - TQApplication::addLibraryPath(*it++); - } - - // read new TQStyle - extern bool tqt_explicit_app_style; // defined in qapplication.cpp - TQString stylename = settings.readEntry( "/qt/style" ); - if ( !stylename.isEmpty() && !tqt_explicit_app_style ) { - TQApplication::setStyle( stylename ); - // took the style from the user settings, so mark the explicit flag FALSE - tqt_explicit_app_style = FALSE; - } - - num = - settings.readNumEntry("/qt/doubleClickInterval", - TQApplication::doubleClickInterval()); - TQApplication::setDoubleClickInterval(num); - - num = - settings.readNumEntry("/qt/cursorFlashTime", - TQApplication::cursorFlashTime()); - TQApplication::setCursorFlashTime(num); - - num = - settings.readNumEntry("/qt/wheelScrollLines", - TQApplication::wheelScrollLines()); - TQApplication::setWheelScrollLines(num); - - TQString colorspec = settings.readEntry("/qt/colorSpec", "default"); - if (colorspec == "normal") - TQApplication::setColorSpec(TQApplication::NormalColor); - else if (colorspec == "custom") - TQApplication::setColorSpec(TQApplication::CustomColor); - else if (colorspec == "many") - TQApplication::setColorSpec(TQApplication::ManyColor); - else if (colorspec != "default") - colorspec = "default"; - - TQString defaultcodec = settings.readEntry("/qt/defaultCodec", "none"); - if (defaultcodec != "none") { - TQTextCodec *codec = TQTextCodec::codecForName(defaultcodec); - if (codec) - tqApp->setDefaultCodec(codec); - } - - TQStringList strut = settings.readListEntry("/qt/globalStrut"); - if (! strut.isEmpty()) { - if (strut.count() == 2) { - TQSize sz(strut[0].toUInt(), strut[1].toUInt()); - - if (sz.isValid()) - TQApplication::setGlobalStrut(sz); - } - } - - TQStringList effects = settings.readListEntry("/qt/GUIEffects"); - - TQApplication::setEffectEnabled( TQt::UI_General, effects.contains("general") ); - TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, effects.contains("animatemenu") ); - TQApplication::setEffectEnabled( TQt::UI_FadeMenu, effects.contains("fademenu") ); - TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, effects.contains("animatecombo") ); - TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, effects.contains("animatetooltip") ); - TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, effects.contains("fadetooltip") ); - TQApplication::setEffectEnabled( TQt::UI_AnimateToolBox, effects.contains("animatetoolbox") ); - - TQStringList fontsubs = - settings.entryList("/qt/Font Substitutions"); - if (!fontsubs.isEmpty()) { - TQStringList subs; - TQString fam, skey; - TQStringList::Iterator it = fontsubs.begin(); - while (it != fontsubs.end()) { - fam = (*it++); - skey = "/qt/Font Substitutions/" + fam; - subs = settings.readListEntry(skey); - TQFont::insertSubstitutions(fam, subs); - } - } - - qt_broken_wm = - settings.readBoolEntry("/qt/brokenWindowManager", qt_broken_wm); - - tqt_resolve_symlinks = - settings.readBoolEntry("/qt/resolveSymlinks", TRUE); - - qt_use_rtl_extensions = - settings.readBoolEntry("/qt/useRtlExtensions", FALSE); - -#ifndef TQT_NO_XIM - if (qt_xim_preferred_style == 0) { - TQString ximInputStyle = - settings.readEntry( "/qt/XIMInputStyle", - TQString::fromLatin1( "On The Spot" ) ).lower(); - if ( ximInputStyle == "over the spot" ) - qt_xim_preferred_style = XIMPreeditPosition | XIMStatusNothing; - else if ( ximInputStyle == "off the spot" ) - qt_xim_preferred_style = XIMPreeditArea | XIMStatusArea; - else if ( ximInputStyle == "root" ) - qt_xim_preferred_style = XIMPreeditNothing | XIMStatusNothing; - else // ximInputStyle == "on the spot" or others - qt_xim_preferred_style = XIMPreeditCallbacks | XIMStatusNothing; - } -#endif - -#ifndef TQT_NO_IM - /* - The identifier name of an input method is acquired from the - configuration file as a default. If a environment variable - "TQT_IM_SWITCHER" is not empty it will overwrite the - configuration file. The "imsw-multi" becomes the default if the entry - is not configured. - */ - if ( getenv( "TQT_IM_SWITCHER" ) ) - defaultIM = getenv( "TQT_IM_SWITCHER" ); -#ifndef TQT_NO_IM_EXTENSIONS - else - defaultIM = settings.readEntry( "/qt/DefaultInputMethodSwitcher", "imsw-multi" ); -#endif - - // defaultIM is restricted to be an IM-switcher. An IM-switcher - // has a 'imsw-' prefix - if ( ! defaultIM.startsWith( "imsw-" ) ) { - defaultIM = "imsw-multi"; - } -#endif - - if (update_timestamp) { - TQBuffer stamp; - TQDataStream s(stamp.buffer(), IO_WriteOnly); - s << settingsstamp; - - XChangeProperty(appDpy, TQPaintDevice::x11AppRootWindow( 0 ), - qt_settings_timestamp, qt_settings_timestamp, 8, - PropModeReplace, (unsigned char *) stamp.buffer().data(), - stamp.buffer().size()); - } - - return TRUE; -} - - -// read the _QT_INPUT_ENCODING property and apply the settings to -// the application -static void qt_set_input_encoding() -{ - Atom type; - int format; - ulong nitems, after = 1; - const char *data; - - int e = XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), - qt_input_encoding, 0, 1024, - False, XA_STRING, &type, &format, &nitems, - &after, (unsigned char**)&data ); - if ( e != Success || !nitems || type == None ) { - // Always use the locale codec, since we have no examples of non-local - // XIMs, and since we cannot get a sensible answer about the encoding - // from the XIM. - qt_input_mapper = TQTextCodec::codecForLocale(); - - } else { - if ( !tqstricmp( data, "locale" ) ) - qt_input_mapper = TQTextCodec::codecForLocale(); - else - qt_input_mapper = TQTextCodec::codecForName( data ); - // make sure we have an input codec - if( !qt_input_mapper ) - qt_input_mapper = TQTextCodec::codecForName( "ISO 8859-1" ); - } - if ( qt_input_mapper->mibEnum() == 11 ) // 8859-8 - qt_input_mapper = TQTextCodec::codecForName( "ISO 8859-8-I"); - if( data ) - XFree( (char *)data ); -} - -// set font, foreground and background from x11 resources. The -// arguments may override the resource settings. -static void qt_set_x11_resources( const char* font = 0, const char* fg = 0, - const char* bg = 0, const char* button = 0 ) -{ - if ( !tqt_std_pal ) - tqt_create_std_palette(); - - TQCString resFont, resFG, resBG, resEF, sysFont; - - TQApplication::setEffectEnabled( TQt::UI_General, FALSE); - TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, FALSE); - TQApplication::setEffectEnabled( TQt::UI_FadeMenu, FALSE); - TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, FALSE ); - TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, FALSE ); - TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, FALSE ); - TQApplication::setEffectEnabled( TQt::UI_AnimateToolBox, FALSE ); - - if ( TQApplication::desktopSettingsAware() && !TQApplication::x11_apply_settings() ) { - int format; - ulong nitems, after = 1; - TQCString res; - long offset = 0; - Atom type = None; - - while (after > 0) { - uchar *data; - XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow( 0 ), - qt_resource_manager, - offset, 8192, False, AnyPropertyType, - &type, &format, &nitems, &after, - &data ); - res += (char*)data; - offset += 2048; // offset is in 32bit quantities... 8192/4 == 2048 - if ( data ) - XFree( (char *)data ); - } - - TQCString key, value; - int l = 0, r; - TQCString apn = appName; - TQCString apc = appClass; - int apnl = apn.length(); - int apcl = apc.length(); - int resl = res.length(); - - while (l < resl) { - r = res.find( '\n', l ); - if ( r < 0 ) - r = resl; - while ( isspace((uchar) res[l]) ) - l++; - bool mine = FALSE; - if ( res[l] == '*' && - (res[l+1] == 'f' || res[l+1] == 'b' || res[l+1] == 'g' || - res[l+1] == 'F' || res[l+1] == 'B' || res[l+1] == 'G' || - res[l+1] == 's' || res[l+1] == 'S' ) ) { - // OPTIMIZED, since we only want "*[fbgs].." - - TQCString item = res.mid( l, r - l ).simplifyWhiteSpace(); - int i = item.find( ":" ); - key = item.left( i ).stripWhiteSpace().mid(1).lower(); - value = item.right( item.length() - i - 1 ).stripWhiteSpace(); - mine = TRUE; - } else if ( res[l] == appName[0] || (appClass && res[l] == appClass[0]) ) { - if (res.mid(l,apnl) == apn && (res[l+apnl] == '.' || res[l+apnl] == '*')) { - TQCString item = res.mid( l, r - l ).simplifyWhiteSpace(); - int i = item.find( ":" ); - key = item.left( i ).stripWhiteSpace().mid(apnl+1).lower(); - value = item.right( item.length() - i - 1 ).stripWhiteSpace(); - mine = TRUE; - } else if (res.mid(l,apcl) == apc && (res[l+apcl] == '.' || res[l+apcl] == '*')) { - TQCString item = res.mid( l, r - l ).simplifyWhiteSpace(); - int i = item.find( ":" ); - key = item.left( i ).stripWhiteSpace().mid(apcl+1).lower(); - value = item.right( item.length() - i - 1 ).stripWhiteSpace(); - mine = TRUE; - } - } - - if ( mine ) { - if ( !font && key == "systemfont") - sysFont = value.left( value.findRev(':') ).copy(); - if ( !font && key == "font") - resFont = value.copy(); - else if ( !fg && key == "foreground" ) - resFG = value.copy(); - else if ( !bg && key == "background") - resBG = value.copy(); - else if ( key == "guieffects") - resEF = value.copy(); - // NOTE: if you add more, change the [fbg] stuff above - } - - l = r + 1; - } - } - if ( !sysFont.isEmpty() ) - resFont = sysFont; - if ( resFont.isEmpty() ) - resFont = font; - if ( resFG.isEmpty() ) - resFG = fg; - if ( resBG.isEmpty() ) - resBG = bg; - if ( (!tqt_app_has_font || qt_x11_cmdline_font) && !resFont.isEmpty() ) { // set application font - TQFont fnt; - fnt.setRawName( resFont ); - - // the font we get may actually be an alias for another font, - // so we reset the application font to the real font info. - if ( ! fnt.exactMatch() ) { - TQFontInfo fontinfo( fnt ); - fnt.setFamily( fontinfo.family() ); - fnt.setRawMode( fontinfo.rawMode() ); - - if ( ! fnt.rawMode() ) { - fnt.setItalic( fontinfo.italic() ); - fnt.setWeight( fontinfo.weight() ); - fnt.setUnderline( fontinfo.underline() ); - fnt.setStrikeOut( fontinfo.strikeOut() ); - fnt.setStyleHint( fontinfo.styleHint() ); - - if ( fnt.pointSize() <= 0 && fnt.pixelSize() <= 0 ) - // size is all wrong... fix it - fnt.setPointSize( (int) ( ( fontinfo.pixelSize() * 72. / - (float) TQPaintDevice::x11AppDpiY() ) + - 0.5 ) ); - } - } - - if ( fnt != TQApplication::font() ) { - TQApplication::setFont( fnt, TRUE ); - } - } - - if ( button || !resBG.isEmpty() || !resFG.isEmpty() ) {// set app colors - TQColor btn; - TQColor bg; - TQColor fg; - if ( !resBG.isEmpty() ) - bg = TQColor(TQString(resBG)); - else - bg = tqt_std_pal->active().background(); - if ( !resFG.isEmpty() ) - fg = TQColor(TQString(resFG)); - else - fg = tqt_std_pal->active().foreground(); - if ( button ) - btn = TQColor( button ); - else if ( !resBG.isEmpty() ) - btn = bg; - else - btn = tqt_std_pal->active().button(); - - int h,s,v; - fg.hsv(&h,&s,&v); - TQColor base = TQt::white; - bool bright_mode = FALSE; - if (v >= 255-50) { - base = btn.dark(150); - bright_mode = TRUE; - } - - TQColorGroup cg( fg, btn, btn.light(), - btn.dark(), btn.dark(150), fg, TQt::white, base, bg ); - if (bright_mode) { - cg.setColor( TQColorGroup::HighlightedText, base ); - cg.setColor( TQColorGroup::Highlight, TQt::white ); - } else { - cg.setColor( TQColorGroup::HighlightedText, TQt::white ); - cg.setColor( TQColorGroup::Highlight, TQt::darkBlue ); - } - TQColor disabled( (fg.red()+btn.red())/2, - (fg.green()+btn.green())/2, - (fg.blue()+btn.blue())/2); - TQColorGroup dcg( disabled, btn, btn.light( 125 ), btn.dark(), btn.dark(150), - disabled, TQt::white, TQt::white, bg ); - if (bright_mode) { - dcg.setColor( TQColorGroup::HighlightedText, base ); - dcg.setColor( TQColorGroup::Highlight, TQt::white ); - } else { - dcg.setColor( TQColorGroup::HighlightedText, TQt::white ); - dcg.setColor( TQColorGroup::Highlight, TQt::darkBlue ); - } - TQPalette pal( cg, dcg, cg ); - if ( pal != *tqt_std_pal && pal != TQApplication::palette() ) - TQApplication::setPalette( pal, TRUE ); - *tqt_std_pal = pal; - } - - if ( !resEF.isEmpty() ) { - TQStringList effects = TQStringList::split(" ",resEF); - TQApplication::setEffectEnabled( TQt::UI_General, effects.contains("general") ); - TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, effects.contains("animatemenu") ); - TQApplication::setEffectEnabled( TQt::UI_FadeMenu, effects.contains("fademenu") ); - TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, effects.contains("animatecombo") ); - TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, effects.contains("animatetooltip") ); - TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, effects.contains("fadetooltip") ); - TQApplication::setEffectEnabled( TQt::UI_AnimateToolBox, effects.contains("animatetoolbox") ); - } -} - - -static void qt_detect_broken_window_manager() -{ - Atom type; - int format; - ulong nitems, after; - uchar *data = 0; - - // look for SGI's 4Dwm - int e = XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), - qt_sgi_desks_manager, 0, 1, False, XA_WINDOW, - &type, &format, &nitems, &after, &data); - if (data) - XFree(data); - - if (e == Success && type == XA_WINDOW && format == 32 && nitems == 1 && after == 0) { - // detected SGI 4Dwm - qt_broken_wm = TRUE; - } -} - - -// update the supported array -void qt_get_net_supported() -{ - Atom type; - int format; - long offset = 0; - unsigned long nitems, after; - unsigned char *data = 0; - - int e = XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), - qt_net_supported, 0, 0, - False, XA_ATOM, &type, &format, &nitems, &after, &data); - if (data) - XFree(data); - - if (qt_net_supported_list) - delete [] qt_net_supported_list; - qt_net_supported_list = 0; - - if (e == Success && type == XA_ATOM && format == 32) { - TQBuffer ts; - ts.open(IO_WriteOnly); - - while (after > 0) { - XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), - qt_net_supported, offset, 1024, - False, XA_ATOM, &type, &format, &nitems, &after, &data); - - if (type == XA_ATOM && format == 32) { - ts.writeBlock((const char *) data, nitems * sizeof(long)); - offset += nitems; - } else - after = 0; - if (data) - XFree(data); - } - - // compute nitems - TQByteArray buffer(ts.buffer()); - nitems = buffer.size() / sizeof(Atom); - qt_net_supported_list = new Atom[nitems + 1]; - Atom *a = (Atom *) buffer.data(); - uint i; - for (i = 0; i < nitems; i++) - qt_net_supported_list[i] = a[i]; - qt_net_supported_list[nitems] = 0; - } -} - - -bool qt_net_supports(Atom atom) -{ - if (! qt_net_supported_list) - return FALSE; - - bool supported = FALSE; - int i = 0; - while (qt_net_supported_list[i] != 0) { - if (qt_net_supported_list[i++] == atom) { - supported = TRUE; - break; - } - } - - return supported; -} - - -// update the virtual roots array -void qt_get_net_virtual_roots() -{ - if (qt_net_virtual_root_list) - delete [] qt_net_virtual_root_list; - qt_net_virtual_root_list = 0; - - if (! qt_net_supports(qt_net_virtual_roots)) - return; - - Atom type; - int format; - long offset = 0; - unsigned long nitems, after; - unsigned char *data; - - int e = XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), - qt_net_virtual_roots, 0, 0, - False, XA_ATOM, &type, &format, &nitems, &after, &data); - if (data) - XFree(data); - - if (e == Success && type == XA_ATOM && format == 32) { - TQBuffer ts; - ts.open(IO_WriteOnly); - - while (after > 0) { - XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), - qt_net_virtual_roots, offset, 1024, - False, XA_ATOM, &type, &format, &nitems, &after, &data); - - if (type == XA_ATOM && format == 32) { - ts.writeBlock((const char *) data, nitems * 4); - offset += nitems; - } else - after = 0; - if (data) - XFree(data); - } - - // compute nitems - TQByteArray buffer(ts.buffer()); - nitems = buffer.size() / sizeof(Window); - qt_net_virtual_root_list = new Window[nitems + 1]; - Window *a = (Window *) buffer.data(); - uint i; - for (i = 0; i < nitems; i++) - qt_net_virtual_root_list[i] = a[i]; - qt_net_virtual_root_list[nitems] = 0; - } -} - -void qt_x11_create_wm_client_leader() -{ - if ( qt_x11_wm_client_leader ) return; - - qt_x11_wm_client_leader = - XCreateSimpleWindow( TQPaintDevice::x11AppDisplay(), - TQPaintDevice::x11AppRootWindow(), - 0, 0, 1, 1, 0, 0, 0 ); - - // set client leader property to itself - XChangeProperty( TQPaintDevice::x11AppDisplay(), - qt_x11_wm_client_leader, qt_wm_client_leader, - XA_WINDOW, 32, PropModeReplace, - (unsigned char *)&qt_x11_wm_client_leader, 1 ); - - // If we are session managed, inform the window manager about it - TQCString session = tqApp->sessionId().latin1(); - if ( !session.isEmpty() ) { - XChangeProperty( TQPaintDevice::x11AppDisplay(), - qt_x11_wm_client_leader, tqt_sm_client_id, - XA_STRING, 8, PropModeReplace, - (unsigned char *)session.data(), session.length() ); - } -} - -static void qt_net_update_user_time(TQWidget *tlw) -{ - XChangeProperty(TQPaintDevice::x11AppDisplay(), tlw->winId(), qt_net_wm_user_time, XA_CARDINAL, - 32, PropModeReplace, (unsigned char *) &tqt_x_user_time, 1); -} - -static void qt_check_focus_model() -{ - Window fw = None; - int unused; - XGetInputFocus( appDpy, &fw, &unused ); - if ( fw == PointerRoot ) - qt_focus_model = FocusModel_PointerRoot; - else - qt_focus_model = FocusModel_Other; -} - - -/* - Returns a truecolor visual (if there is one). 8-bit TrueColor visuals - are ignored, unless the user has explicitly requested -visual TrueColor. - The SGI X server usually has an 8 bit default visual, but the application - can also ask for a truecolor visual. This is what we do if - TQApplication::colorSpec() is TQApplication::ManyColor. -*/ - -static Visual *find_truecolor_visual( Display *dpy, int scr, int *depth, int *ncols ) -{ - XVisualInfo *vi, rvi; - int best=0, n, i; - rvi.c_class = TrueColor; - rvi.screen = scr; - vi = XGetVisualInfo( dpy, VisualClassMask | VisualScreenMask, - &rvi, &n ); - if ( vi ) { - for ( i=0; i vi[best].depth ) - best = i; - } - } - Visual *v = DefaultVisual(dpy,scr); - if ( !vi || (vi[best].visualid == XVisualIDFromVisual(v)) || - (vi[best].depth <= 8 && qt_visual_option != TrueColor) ) - { - *depth = DefaultDepth(dpy,scr); - *ncols = DisplayCells(dpy,scr); - } else { - v = vi[best].visual; - *depth = vi[best].depth; - *ncols = vi[best].colormap_size; - } - if ( vi ) - XFree( (char *)vi ); - return v; -} - -static KeySym qt_x11_keycode_to_keysym(Display *dpy, KeyCode kc) { -#ifndef TQT_NO_XKB - return XkbKeycodeToKeysym(dpy, kc, 0, 0); -#else - KeySym rv = NoSymbol; - int keysyms_per_keycode; - KeySym *keysym_p = XGetKeyboardMapping(dpy, kc, 1, &keysyms_per_keycode); - if (keysyms_per_keycode>0) { //< Should always be true unless X server is bugged - rv = keysym_p[0]; - } - XFree(keysym_p); - - return rv; -#endif // TQT_NO_XKB -} - -/***************************************************************************** - tqt_init() - initializes TQt for X11 - *****************************************************************************/ - -#define XK_MISCELLANY -#define XK_LATIN1 -#define XK_KOREAN -#define XK_XKB_KEYS -#include - -// ### This should be static but it isn't because of the friend declaration -// ### in tqpaintdevice.h which then should have a static too but can't have -// ### it because "storage class specifiers invalid in friend function -// ### declarations" :-) Ideas anyone? -void tqt_init_internal( int *argcptr, char **argv, - Display *display, TQt::HANDLE visual, TQt::HANDLE colormap ) -{ - setlocale( LC_ALL, "" ); // use correct char set mapping - setlocale( LC_NUMERIC, "C" ); // make sprintf()/scanf() work - -#if defined(TQT_THREAD_SUPPORT) - if (( tqt_is_gui_used ) && ( !display )) { - // If TQt is running standalone with a GUI, initialize X11 threading - XInitThreads(); - } -#endif - - if ( display && ((!argcptr) || (!argv)) ) { - // TQt part of other application - - appForeignDpy = TRUE; - appDpy = display; - - // Set application name and class - appName = tqstrdup( "TQt-subapplication" ); - char *app_class = 0; - if (argv) { - const char* p = strrchr( argv[0], '/' ); - app_class = tqstrdup(p ? p + 1 : argv[0]); - if (app_class[0]) - app_class[0] = toupper(app_class[0]); - } - appClass = app_class; - - // Install default error handlers - original_x_errhandler = XSetErrorHandler( qt_x_errhandler ); - original_xio_errhandler = XSetIOErrorHandler( qt_xio_errhandler ); - } else { - // TQt controls everything (default) - - int argc = *argcptr; - int j; - - // Install default error handlers - original_x_errhandler = XSetErrorHandler( qt_x_errhandler ); - original_xio_errhandler = XSetIOErrorHandler( qt_xio_errhandler ); - - // Set application name and class - char *app_class = 0; - if (argv) { - const char *p = strrchr( argv[0], '/' ); - appName = p ? p + 1 : argv[0]; - app_class = tqstrdup(appName); - if (app_class[0]) - app_class[0] = toupper(app_class[0]); - } - appClass = app_class; - - // Get command line params - j = argc ? 1 : 0; - for ( int i=1; i 0 ) { - if ( c == '/' ) - s.truncate( 0 ); - else - s += (char)c; - } - if ( s == "gdb" ) { - appNoGrab = TRUE; - tqDebug( "TQt: gdb: -nograb added to command-line options.\n" - "\t Use the -dograb option to enforce grabbing." ); - } - f.close(); - } - } -#endif - if ( display ) { - // Display connection already opened by another application - - appForeignDpy = TRUE; - appDpy = display; - } - else { - // Connect to X server - - if( tqt_is_gui_used ) { - if ( ( appDpy = XOpenDisplay(appDpyName) ) == 0 ) { - tqWarning( "%s: cannot connect to X server %s", appName, - XDisplayName(appDpyName) ); - tqApp = 0; - exit( 1 ); - } - - if ( appSync ) // if "-sync" argument - XSynchronize( appDpy, TRUE ); - } - } - } - // Common code, regardless of whether display is foreign. - - // Get X parameters - - if( tqt_is_gui_used ) { - appScreen = DefaultScreen(appDpy); - appScreenCount = ScreenCount(appDpy); - - TQPaintDevice::x_appdisplay = appDpy; - TQPaintDevice::x_appscreen = appScreen; - - // allocate the arrays for the TQPaintDevice data - TQPaintDevice::x_appdepth_arr = new int[ appScreenCount ]; - TQPaintDevice::x_appcells_arr = new int[ appScreenCount ]; - TQPaintDevice::x_approotwindow_arr = new TQt::HANDLE[ appScreenCount ]; - TQPaintDevice::x_appcolormap_arr = new TQt::HANDLE[ appScreenCount ]; - TQPaintDevice::x_appdefcolormap_arr = new bool[ appScreenCount ]; - TQPaintDevice::x_appvisual_arr = new void*[ appScreenCount ]; - TQPaintDevice::x_appdefvisual_arr = new bool[ appScreenCount ]; - TQ_CHECK_PTR( TQPaintDevice::x_appdepth_arr ); - TQ_CHECK_PTR( TQPaintDevice::x_appcells_arr ); - TQ_CHECK_PTR( TQPaintDevice::x_approotwindow_arr ); - TQ_CHECK_PTR( TQPaintDevice::x_appcolormap_arr ); - TQ_CHECK_PTR( TQPaintDevice::x_appdefcolormap_arr ); - TQ_CHECK_PTR( TQPaintDevice::x_appvisual_arr ); - TQ_CHECK_PTR( TQPaintDevice::x_appdefvisual_arr ); - - int screen; - TQString serverVendor( ServerVendor( appDpy) ); - if (serverVendor.contains("XFree86") && VendorRelease(appDpy) < 40300000) - tqt_hebrew_keyboard_hack = TRUE; - - for ( screen = 0; screen < appScreenCount; ++screen ) { - TQPaintDevice::x_appdepth_arr[ screen ] = DefaultDepth(appDpy, screen); - TQPaintDevice::x_appcells_arr[ screen ] = DisplayCells(appDpy, screen); - TQPaintDevice::x_approotwindow_arr[ screen ] = RootWindow(appDpy, screen); - - // setup the visual and colormap for each screen - Visual *vis = 0; - if ( visual && screen == appScreen ) { - // use the provided visual on the default screen only - vis = (Visual *) visual; - - // figure out the depth of the visual we are using - XVisualInfo *vi, rvi; - int n; - rvi.visualid = XVisualIDFromVisual(vis); - rvi.screen = screen; - vi = XGetVisualInfo( appDpy, VisualIDMask | VisualScreenMask, &rvi, &n ); - if (vi) { - TQPaintDevice::x_appdepth_arr[ screen ] = vi->depth; - TQPaintDevice::x_appcells_arr[ screen ] = vi->visual->map_entries; - TQPaintDevice::x_appvisual_arr[ screen ] = vi->visual; - TQPaintDevice::x_appdefvisual_arr[ screen ] = FALSE; - XFree(vi); - } else { - // couldn't get info about the visual, use the default instead - vis = 0; - } - } - - if (!vis) { - // use the default visual - vis = DefaultVisual(appDpy, screen); - TQPaintDevice::x_appdefvisual_arr[ screen ] = TRUE; - - if ( qt_visual_option == TrueColor || - TQApplication::colorSpec() == TQApplication::ManyColor ) { - // find custom visual - - int d, c; - vis = find_truecolor_visual( appDpy, screen, &d, &c ); - TQPaintDevice::x_appdepth_arr[ screen ] = d; - TQPaintDevice::x_appcells_arr[ screen ] = c; - - TQPaintDevice::x_appvisual_arr[ screen ] = vis; - TQPaintDevice::x_appdefvisual_arr[ screen ] = - (XVisualIDFromVisual(vis) == - XVisualIDFromVisual(DefaultVisual(appDpy, screen))); - } - - TQPaintDevice::x_appvisual_arr[ screen ] = vis; - } - - // we assume that 8bpp == pseudocolor, but this is not - // always the case (according to the X server), so we need - // to make sure that our internal data is setup in a way - // that is compatible with our assumptions - if ( vis->c_class == TrueColor && - TQPaintDevice::x_appdepth_arr[ screen ] == 8 && - TQPaintDevice::x_appcells_arr[ screen ] == 8 ) - TQPaintDevice::x_appcells_arr[ screen ] = 256; - - if ( colormap && screen == appScreen ) { - // use the provided colormap for the default screen only - TQPaintDevice::x_appcolormap_arr[ screen ] = colormap; - TQPaintDevice::x_appdefcolormap_arr[ screen ] = FALSE; - } else { - if ( vis->c_class == TrueColor ) { - TQPaintDevice::x_appdefcolormap_arr[ screen ] = - TQPaintDevice::x_appdefvisual_arr[ screen ]; - } else { - TQPaintDevice::x_appdefcolormap_arr[ screen ] = - !qt_cmap_option && TQPaintDevice::x_appdefvisual_arr[ screen ]; - } - - if ( TQPaintDevice::x_appdefcolormap_arr[ screen ] ) { - // use default colormap - XStandardColormap *stdcmap; - VisualID vid = - XVisualIDFromVisual((Visual *) - TQPaintDevice::x_appvisual_arr[ screen ]); - int i, count; - - TQPaintDevice::x_appcolormap_arr[ screen ] = 0; - - if ( ! serverVendor.contains( "Hewlett-Packard" ) ) { - // on HPUX 10.20 local displays, the RGB_DEFAULT_MAP colormap - // doesn't give us correct colors. Why this happens, I have - // no clue, so we disable this for HPUX - if (XGetRGBColormaps(appDpy, - TQPaintDevice::x11AppRootWindow( screen ), - &stdcmap, &count, XA_RGB_DEFAULT_MAP)) { - i = 0; - while (i < count && - TQPaintDevice::x_appcolormap_arr[ screen ] == 0) { - if (stdcmap[i].visualid == vid) { - TQPaintDevice::x_appcolormap_arr[ screen ] = - stdcmap[i].colormap; - } - i++; - } - - XFree( (char *)stdcmap ); - } - } - - if (TQPaintDevice::x_appcolormap_arr[ screen ] == 0) { - TQPaintDevice::x_appcolormap_arr[ screen ] = - DefaultColormap(appDpy, screen); - } - } else { - // create a custom colormap - TQPaintDevice::x_appcolormap_arr[ screen ] = - XCreateColormap(appDpy, TQPaintDevice::x11AppRootWindow( screen ), - vis, AllocNone); - } - } - } - - // Set X paintdevice parameters for the default screen - TQPaintDevice::x_appdepth = TQPaintDevice::x_appdepth_arr[ appScreen ]; - TQPaintDevice::x_appcells = TQPaintDevice::x_appcells_arr[ appScreen ]; - TQPaintDevice::x_approotwindow = TQPaintDevice::x_approotwindow_arr[ appScreen ]; - TQPaintDevice::x_appcolormap = TQPaintDevice::x_appcolormap_arr[ appScreen ]; - TQPaintDevice::x_appdefcolormap = TQPaintDevice::x_appdefcolormap_arr[ appScreen ]; - TQPaintDevice::x_appvisual = TQPaintDevice::x_appvisual_arr[ appScreen ]; - TQPaintDevice::x_appdefvisual = TQPaintDevice::x_appdefvisual_arr[ appScreen ]; - - // Support protocols - - qt_x11_intern_atom( "WM_PROTOCOLS", &tqt_wm_protocols ); - qt_x11_intern_atom( "WM_DELETE_WINDOW", &tqt_wm_delete_window ); - qt_x11_intern_atom( "WM_STATE", &tqt_wm_state ); - qt_x11_intern_atom( "WM_CHANGE_STATE", &qt_wm_change_state ); - qt_x11_intern_atom( "WM_TAKE_FOCUS", &tqt_wm_take_focus ); - qt_x11_intern_atom( "WM_CLIENT_LEADER", &qt_wm_client_leader); - qt_x11_intern_atom( "WM_WINDOW_ROLE", &tqt_window_role); - qt_x11_intern_atom( "SM_CLIENT_ID", &tqt_sm_client_id); - qt_x11_intern_atom( "CLIPBOARD", &qt_xa_clipboard ); - qt_x11_intern_atom( "RESOURCE_MANAGER", &qt_resource_manager ); - qt_x11_intern_atom( "INCR", &qt_x_incr ); - qt_x11_intern_atom( "_XSETROOT_ID", &qt_xsetroot_id ); - qt_x11_intern_atom( "_QT_SELECTION", &qt_selection_property ); - qt_x11_intern_atom( "_QT_CLIPBOARD_SENTINEL", &tqt_clipboard_sentinel ); - qt_x11_intern_atom( "_QT_SELECTION_SENTINEL", &qt_selection_sentinel ); - qt_x11_intern_atom( "_QT_SCROLL_DONE", &qt_qt_scrolldone ); - qt_x11_intern_atom( "_QT_INPUT_ENCODING", &qt_input_encoding ); - qt_x11_intern_atom( "_QT_SIZEGRIP", &qt_sizegrip ); - qt_x11_intern_atom( "_NET_WM_CONTEXT_HELP", &qt_net_wm_context_help ); - qt_x11_intern_atom( "_NET_WM_PING", &qt_net_wm_ping ); - qt_x11_intern_atom( "_MOTIF_WM_HINTS", &qt_xa_motif_wm_hints ); - qt_x11_intern_atom( "DTWM_IS_RUNNING", &qt_cde_running ); - qt_x11_intern_atom( "KWIN_RUNNING", &qt_twin_running ); - qt_x11_intern_atom( "KWM_RUNNING", &qt_kwm_running ); - qt_x11_intern_atom( "GNOME_BACKGROUND_PROPERTIES", &qt_gbackground_properties ); - - TQString atomname("_QT_SETTINGS_TIMESTAMP_"); - atomname += XDisplayName(appDpyName); - qt_x11_intern_atom( atomname.latin1(), &qt_settings_timestamp ); - - qt_x11_intern_atom( "_NET_SUPPORTED", &qt_net_supported ); - qt_x11_intern_atom( "_NET_VIRTUAL_ROOTS", &qt_net_virtual_roots ); - qt_x11_intern_atom( "_NET_WORKAREA", &qt_net_workarea ); - qt_x11_intern_atom( "_NET_WM_STATE", &qt_net_wm_state ); - qt_x11_intern_atom( "_NET_WM_STATE_MODAL", &qt_net_wm_state_modal ); - qt_x11_intern_atom( "_NET_WM_STATE_MAXIMIZED_VERT", &qt_net_wm_state_max_v ); - qt_x11_intern_atom( "_NET_WM_STATE_MAXIMIZED_HORZ", &qt_net_wm_state_max_h ); - qt_x11_intern_atom( "_NET_WM_STATE_FULLSCREEN", &qt_net_wm_state_fullscreen ); - qt_x11_intern_atom( "_NET_WM_STATE_ABOVE", &qt_net_wm_state_above ); - qt_x11_intern_atom( "_NET_WM_ALLOWED_ACTIONS", &qt_net_wm_action ); - qt_x11_intern_atom( "_NET_WM_ACTION_MOVE", &qt_net_wm_action_move ); - qt_x11_intern_atom( "_NET_WM_ACTION_RESIZE", &qt_net_wm_action_resize ); - qt_x11_intern_atom( "_NET_WM_ACTION_MINIMIZE", &qt_net_wm_action_minimize ); - qt_x11_intern_atom( "_NET_WM_ACTION_SHADE", &qt_net_wm_action_shade ); - qt_x11_intern_atom( "_NET_WM_ACTION_STICK", &qt_net_wm_action_stick ); - qt_x11_intern_atom( "_NET_WM_ACTION_MAXIMIZE_HORZ", &qt_net_wm_action_max_h ); - qt_x11_intern_atom( "_NET_WM_ACTION_MAXIMIZE_VERT", &qt_net_wm_action_max_v ); - qt_x11_intern_atom( "_NET_WM_ACTION_FULLSCREEN", &qt_net_wm_action_fullscreen ); - qt_x11_intern_atom( "_NET_WM_ACTION_CHANGE_DESKTOP", &qt_net_wm_action_change_desktop ); - qt_x11_intern_atom( "_NET_WM_ACTION_CLOSE", &qt_net_wm_action_close ); - qt_x11_intern_atom( "_NET_WM_ACTION_ABOVE", &qt_net_wm_action_above ); - qt_x11_intern_atom( "_NET_WM_ACTION_BELOW", &qt_net_wm_action_below ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE", &qt_net_wm_window_type ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_NORMAL", &qt_net_wm_window_type_normal ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_DIALOG", &qt_net_wm_window_type_dialog ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_TOOLBAR", &qt_net_wm_window_type_toolbar ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_MENU", &qt_net_wm_window_type_menu ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_UTILITY", &qt_net_wm_window_type_utility ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_SPLASH", &qt_net_wm_window_type_splash ); - qt_x11_intern_atom( "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", &qt_net_wm_window_type_override ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", &qt_net_wm_window_type_dropdown_menu ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_POPUP_MENU", &qt_net_wm_window_type_popup_menu ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_TOOLTIP", &qt_net_wm_window_type_tooltip ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_COMBO", &qt_net_wm_window_type_combo ); - qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_DND", &qt_net_wm_window_type_dnd ); - qt_x11_intern_atom( "_KDE_NET_WM_FRAME_STRUT", &qt_net_wm_frame_strut ); - qt_x11_intern_atom( "_NET_WM_STATE_STAYS_ON_TOP", - &qt_net_wm_state_stays_on_top ); - qt_x11_intern_atom( "_NET_WM_PID", &qt_net_wm_pid ); - qt_x11_intern_atom( "_NET_WM_USER_TIME", &qt_net_wm_user_time ); - qt_x11_intern_atom( "_NET_WM_FULL_PLACEMENT", &qt_net_wm_full_placement ); - qt_x11_intern_atom( "ENLIGHTENMENT_DESKTOP", &qt_enlightenment_desktop ); - qt_x11_intern_atom( "_NET_WM_NAME", &qt_net_wm_name ); - qt_x11_intern_atom( "_NET_WM_ICON_NAME", &qt_net_wm_icon_name ); - qt_x11_intern_atom( "UTF8_STRING", &qt_utf8_string ); - qt_x11_intern_atom( "_SGI_DESKS_MANAGER", &qt_sgi_desks_manager ); - -#ifndef TQT_NO_XSYNC - qt_x11_intern_atom( "_NET_WM_SYNC_REQUEST_COUNTER", &qt_net_wm_sync_request_counter ); - qt_x11_intern_atom( "_NET_WM_SYNC_REQUEST", &qt_net_wm_sync_request ); -#endif - - qt_xdnd_setup(); - qt_x11_motifdnd_init(); - - // Finally create all atoms - tqt_x11_process_intern_atoms(); - - // look for broken window managers - qt_detect_broken_window_manager(); - - // initialize NET lists - qt_get_net_supported(); - qt_get_net_virtual_roots(); - -#ifndef TQT_NO_XRANDR - // See if XRandR is supported on the connected display - int xrandr_errorbase; - Q_UNUSED( xrandr_eventbase ); - if ( XRRQueryExtension( appDpy, &xrandr_eventbase, &xrandr_errorbase ) ) { - // XRandR is supported - qt_use_xrandr = TRUE; - } -#endif // TQT_NO_XRANDR - -#ifndef TQT_NO_XRENDER - // See if XRender is supported on the connected display - int xrender_eventbase, xrender_errorbase; - if (XRenderQueryExtension(appDpy, &xrender_eventbase, &xrender_errorbase)) { - // XRender is supported, let's see if we have a PictFormat for the - // default visual - XRenderPictFormat *format = - XRenderFindVisualFormat(appDpy, - (Visual *) TQPaintDevice::x_appvisual); - tqt_use_xrender = (format != 0) && (TQPaintDevice::x_appdepth != 8); - } -#endif // TQT_NO_XRENDER - -#ifndef TQT_NO_XSYNC - // Try to initialize SYNC extension on the connected display - int xsync_major, xsync_minor; - if ( XSyncQueryExtension( appDpy, &xsync_eventbase, &xsync_errorbase ) && - XSyncInitialize( appDpy, &xsync_major, &xsync_minor ) ) { - qt_use_xsync = TRUE; - } -#endif - -#ifndef TQT_NO_XKB - // If XKB is detected, set the GrabsUseXKBState option so input method - // compositions continue to work (ie. deadkeys) - unsigned int state = XkbPCF_GrabsUseXKBStateMask; - (void) XkbSetPerClientControls(appDpy, state, &state); -#endif - -#if !defined(TQT_NO_XFTFREETYPE) - // defined in tqfont_x11.cpp - extern bool tqt_has_xft; -#ifndef QT_XFT2 - if (!tqt_use_xrender) - tqt_has_xft = FALSE; - else -#endif - tqt_has_xft = XftInit(0) && XftInitFtLibrary(); - - if (tqt_has_xft) { - char *dpi_str = XGetDefault(appDpy, "Xft", "dpi"); - if (dpi_str) { - // use a custom DPI - char *end = 0; - int dpi = strtol(dpi_str, &end, 0); - if (dpi_str != end) { - for (int s = 0; s < ScreenCount(appDpy); ++s) { - TQPaintDevice::x11SetAppDpiX(dpi, s); - TQPaintDevice::x11SetAppDpiY(dpi, s); - } - } - } - } -#endif // TQT_NO_XFTFREETYPE - - // look at the modifier mapping, and get the correct masks for alt/meta - // find the alt/meta masks - XModifierKeymap *map = XGetModifierMapping(appDpy); - if (map) { - int i, maskIndex = 0, mapIndex = 0; - for (maskIndex = 0; maskIndex < 8; maskIndex++) { - for (i = 0; i < map->max_keypermod; i++) { - if (map->modifiermap[mapIndex]) { - KeySym sym = qt_x11_keycode_to_keysym(appDpy, map->modifiermap[ mapIndex ]); - if ( qt_alt_mask == 0 && - ( sym == XK_Alt_L || sym == XK_Alt_R ) ) { - qt_alt_mask = 1 << maskIndex; - } - if ( qt_meta_mask == 0 && - (sym == XK_Meta_L || sym == XK_Meta_R ) ) { - qt_meta_mask = 1 << maskIndex; - } - } - mapIndex++; - } - } - - // not look for mode_switch in qt_alt_mask and qt_meta_mask - if it is - // present in one or both, then we set qt_mode_switch_remove_mask. - // see TQETWidget::translateKeyEventInternal for an explanation - // of why this is needed - mapIndex = 0; - for ( maskIndex = 0; maskIndex < 8; maskIndex++ ) { - if ( qt_alt_mask != ( 1 << maskIndex ) && - qt_meta_mask != ( 1 << maskIndex ) ) { - for ( i = 0; i < map->max_keypermod; i++ ) - mapIndex++; - continue; - } - - for ( i = 0; i < map->max_keypermod; i++ ) { - if ( map->modifiermap[ mapIndex ] ) { - KeySym sym = qt_x11_keycode_to_keysym(appDpy, map->modifiermap[ mapIndex ]); - if ( sym == XK_Mode_switch ) { - qt_mode_switch_remove_mask |= 1 << maskIndex; - } - } - mapIndex++; - } - } - - XFreeModifiermap(map); - } else { - // assume defaults - qt_alt_mask = Mod1Mask; - qt_meta_mask = Mod4Mask; - qt_mode_switch_remove_mask = 0; - } - - // Misc. initialization - - TQColor::initialize(); - TQFont::initialize(); - TQCursor::initialize(); - TQPainter::initialize(); - } - -#if defined(TQT_THREAD_SUPPORT) - TQThread::initialize(); -#endif - - if( tqt_is_gui_used ) { - tqApp->setName( appName ); - - int screen; - for ( screen = 0; screen < appScreenCount; ++screen ) { - XSelectInput( appDpy, TQPaintDevice::x11AppRootWindow( screen ), - KeymapStateMask | EnterWindowMask | LeaveWindowMask | - PropertyChangeMask ); - -#ifndef TQT_NO_XRANDR - if (qt_use_xrandr) - XRRSelectInput( appDpy, TQPaintDevice::x11AppRootWindow( screen ), True ); -#endif // TQT_NO_XRANDR - } - } - - if ( tqt_is_gui_used ) { - qt_set_input_encoding(); - - qt_set_x11_resources( appFont, appFGCol, appBGCol, appBTNCol); - - // be smart about the size of the default font. most X servers have helvetica - // 12 point available at 2 resolutions: - // 75dpi (12 pixels) and 100dpi (17 pixels). - // At 95 DPI, a 12 point font should be 16 pixels tall - in which case a 17 - // pixel font is a closer match than a 12 pixel font - int ptsz = - (int) ( ( ( TQPaintDevice::x11AppDpiY() >= 95 ? 17. : 12. ) * - 72. / (float) TQPaintDevice::x11AppDpiY() ) + 0.5 ); - - if ( !tqt_app_has_font && !qt_x11_cmdline_font ) { - TQFont f( "Helvetica", ptsz ); - TQApplication::setFont( f ); - } - -#if !defined(TQT_NO_IM) -#if !defined(TQT_NO_IM_EXTENSIONS) - TQApplication::create_im(); -#else - TQApplication::create_xim(); -#endif -#endif - -#if defined (QT_TABLET_SUPPORT) - int ndev, - i, - j; - bool gotStylus, - gotEraser; - XDeviceInfo *devices, *devs; - XInputClassInfo *ip; - XAnyClassPtr any; - XValuatorInfoPtr v; - XAxisInfoPtr a; - XDevice *dev; - XEventClass *ev_class; - int curr_event_count; - -#if !defined(Q_OS_IRIX) - // XFree86 divides a stylus and eraser into 2 devices, so we must do for both... - const TQString XFREENAMESTYLUS = "stylus"; - const TQString XFREENAMEPEN = "pen"; - const TQString XFREENAMEERASER = "eraser"; -#endif - - devices = XListInputDevices( appDpy, &ndev); - if ( devices == NULL ) { - tqWarning( "Failed to get list of devices" ); - ndev = -1; - } - dev = NULL; - for ( devs = devices, i = 0; i < ndev; i++, devs++ ) { - gotEraser = FALSE; -#if defined(Q_OS_IRIX) - - gotStylus = ( !strncmp(devs->name, - WACOM_NAME, sizeof(WACOM_NAME) - 1) ); -#else - TQString devName = devs->name; - devName = devName.lower(); - gotStylus = ( devName.startsWith(XFREENAMEPEN) - || devName.startsWith(XFREENAMESTYLUS) ); - if ( !gotStylus ) - gotEraser = devName.startsWith( XFREENAMEERASER ); - -#endif - if ( gotStylus || gotEraser ) { - // I only wanted to do this once, so wrap pointers around these - curr_event_count = 0; - - if ( gotStylus ) { - devStylus = XOpenDevice( appDpy, devs->id ); - dev = devStylus; - ev_class = event_list_stylus; - } else if ( gotEraser ) { - devEraser = XOpenDevice( appDpy, devs->id ); - dev = devEraser; - ev_class = event_list_eraser; - } - if ( dev == NULL ) { - tqWarning( "Failed to open device" ); - } else { - if ( dev->num_classes > 0 ) { - for ( ip = dev->classes, j = 0; j < devs->num_classes; - ip++, j++ ) { - switch ( ip->input_class ) { - case KeyClass: - DeviceKeyPress( dev, xinput_key_press, - ev_class[curr_event_count] ); - curr_event_count++; - DeviceKeyRelease( dev, xinput_key_release, - ev_class[curr_event_count] ); - curr_event_count++; - break; - case ButtonClass: - DeviceButtonPress( dev, xinput_button_press, - ev_class[curr_event_count] ); - curr_event_count++; - DeviceButtonRelease( dev, xinput_button_release, - ev_class[curr_event_count] ); - curr_event_count++; - break; - case ValuatorClass: - // I'm only going to be interested in motion when the - // stylus is already down anyway! - DeviceMotionNotify( dev, xinput_motion, - ev_class[curr_event_count] ); - curr_event_count++; - break; - default: - break; - } - } - } - } - // get the min/max value for pressure! - any = (XAnyClassPtr) ( devs->inputclassinfo ); - if ( dev == devStylus ) { - qt_curr_events_stylus = curr_event_count; - for (j = 0; j < devs->num_classes; j++) { - if ( any->c_class == ValuatorClass ) { - v = (XValuatorInfoPtr) any; - a = (XAxisInfoPtr) ((char *) v + - sizeof (XValuatorInfo)); -#if defined (Q_OS_IRIX) - max_pressure = a[WAC_PRESSURE_I].max_value; -#else - max_pressure = a[2].max_value; -#endif - // got the max pressure no need to go further... - break; - } - any = (XAnyClassPtr) ((char *) any + any->length); - } - } else { - qt_curr_events_eraser = curr_event_count; - } - // at this point we are assuming there is only one - // wacom device... -#if defined (Q_OS_IRIX) - if ( devStylus != NULL ) { -#else - if ( devStylus != NULL && devEraser != NULL ) { -#endif - break; - } - } - } // end for loop - XFreeDeviceList( devices ); -#endif // QT_TABLET_SUPPORT - - } else { - // read some non-GUI settings when not using the X server... - - if ( TQApplication::desktopSettingsAware() ) { - TQSettings settings; - - // read library (ie. plugin) path list - TQString libpathkey = TQString("/qt/%1.%2/libraryPath") - .arg( TQT_VERSION >> 16 ) - .arg( (TQT_VERSION & 0xff00 ) >> 8 ); - TQStringList pathlist = - settings.readListEntry(libpathkey, ':'); - if (! pathlist.isEmpty()) { - TQStringList::ConstIterator it = pathlist.begin(); - while (it != pathlist.end()) - TQApplication::addLibraryPath(*it++); - } - - TQString defaultcodec = settings.readEntry("/qt/defaultCodec", "none"); - if (defaultcodec != "none") { - TQTextCodec *codec = TQTextCodec::codecForName(defaultcodec); - if (codec) - tqApp->setDefaultCodec(codec); - } - - tqt_resolve_symlinks = - settings.readBoolEntry("/qt/resolveSymlinks", TRUE); - } - } - } - - -#ifndef TQT_NO_STYLE - // run-time search for default style -void TQApplication::x11_initialize_style() -{ - Atom type; - int format; - unsigned long length, after; - uchar *data; - if ( !app_style && - XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), qt_twin_running, - 0, 1, False, AnyPropertyType, &type, &format, &length, - &after, &data ) == Success && length ) { - if ( data ) XFree( (char *)data ); - // twin is there. check if KDE's styles are available, - // otherwise use windows style - if ( (app_style = TQStyleFactory::create("highcolor") ) == 0 ) - app_style = TQStyleFactory::create("windows"); - } - if ( !app_style && - XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), qt_kwm_running, - 0, 1, False, AnyPropertyType, &type, &format, &length, - &after, &data ) == Success && length ) { - if ( data ) XFree( (char *)data ); - app_style = TQStyleFactory::create("windows"); - } - if ( !app_style && - XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), qt_cde_running, - 0, 1, False, AnyPropertyType, &type, &format, &length, - &after, &data ) == Success && length ) { - // DTWM is running, meaning most likely CDE is running... - if ( data ) XFree( (char *) data ); - app_style = TQStyleFactory::create( "cde" ); - } - // maybe another desktop? - if ( !app_style && - XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), - qt_gbackground_properties, 0, 1, False, AnyPropertyType, - &type, &format, &length, &after, &data ) == Success && - length ) { - if ( data ) XFree( (char *)data ); - // default to MotifPlus with hovering - app_style = TQStyleFactory::create("motifplus" ); - } -} -#endif - -void tqt_init( int *argcptr, char **argv, TQApplication::Type ) -{ - tqt_init_internal( argcptr, argv, 0, 0, 0 ); -} - -void tqt_init( Display *display, TQt::HANDLE visual, TQt::HANDLE colormap ) -{ - tqt_init_internal( 0, 0, display, visual, colormap ); -} - -void tqt_init( int *argcptr, char **argv, Display *display, TQt::HANDLE visual, TQt::HANDLE colormap ) -{ - tqt_init_internal( argcptr, argv, display, visual, colormap ); -} - - -/***************************************************************************** - tqt_cleanup() - cleans up when the application is finished - *****************************************************************************/ - -void tqt_cleanup() -{ - appliedstamp = 0; - - if ( app_save_rootinfo ) // root window must keep state - qt_save_rootinfo(); - - if ( tqt_is_gui_used ) { - TQPixmapCache::clear(); - TQPainter::cleanup(); - TQCursor::cleanup(); - TQFont::cleanup(); - TQColor::cleanup(); - TQSharedDoubleBuffer::cleanup(); - } -#if defined(TQT_THREAD_SUPPORT) - TQThread::cleanup(); -#endif - -#if defined (QT_TABLET_SUPPORT) - if ( devStylus != NULL ) - XCloseDevice( appDpy, devStylus ); - if ( devEraser != NULL ) - XCloseDevice( appDpy, devEraser ); -#endif - -#if !defined(TQT_NO_IM) -#if !defined(TQT_NO_IM_EXTENSIONS) - TQApplication::close_im(); -#else - TQApplication::close_xim(); -#endif -#endif - - if ( tqt_is_gui_used ) { - int screen; - for ( screen = 0; screen < appScreenCount; screen++ ) { - if ( ! TQPaintDevice::x11AppDefaultColormap( screen ) ) - XFreeColormap( TQPaintDevice::x11AppDisplay(), - TQPaintDevice::x11AppColormap( screen ) ); - } - } - -#define QT_CLEANUP_GC(g) if (g) { for (int i=0;i= appScreenCount ) { - tqDebug("invalid screen %d %d", scrn, appScreenCount ); - TQWidget* bla = 0; - bla->setName("hello"); - } - GC gc; - if ( monochrome ) { - if ( !app_gc_ro_m ) // create GC for bitmap - memset( (app_gc_ro_m = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) ); - if ( !app_gc_ro_m[scrn] ) - app_gc_ro_m[scrn] = create_gc( scrn, TRUE ); - gc = app_gc_ro_m[scrn]; - } else { // create standard GC - if ( !app_gc_ro ) - memset( (app_gc_ro = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) ); - if ( !app_gc_ro[scrn] ) - app_gc_ro[scrn] = create_gc( scrn, FALSE ); - gc = app_gc_ro[scrn]; - } - return gc; -} - -GC tqt_xget_temp_gc( int scrn, bool monochrome ) // get temporary GC -{ - if ( scrn < 0 || scrn >= appScreenCount ) { - tqDebug("invalid screen (tmp) %d %d", scrn, appScreenCount ); - TQWidget* bla = 0; - bla->setName("hello"); - } - GC gc; - if ( monochrome ) { - if ( !app_gc_tmp_m ) // create GC for bitmap - memset( (app_gc_tmp_m = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) ); - if ( !app_gc_tmp_m[scrn] ) - app_gc_tmp_m[scrn] = create_gc( scrn, TRUE ); - gc = app_gc_tmp_m[scrn]; - } else { // create standard GC - if ( !app_gc_tmp ) - memset( (app_gc_tmp = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) ); - if ( !app_gc_tmp[scrn] ) - app_gc_tmp[scrn] = create_gc( scrn, FALSE ); - gc = app_gc_tmp[scrn]; - } - return gc; -} - - -/***************************************************************************** - Platform specific TQApplication members - *****************************************************************************/ - -/*! - \fn TQWidget *TQApplication::mainWidget() const - - Returns the main application widget, or 0 if there is no main - widget. - - \sa setMainWidget() -*/ - -/*! - Sets the application's main widget to \a mainWidget. - - In most respects the main widget is like any other widget, except - that if it is closed, the application exits. Note that - TQApplication does \e not take ownership of the \a mainWidget, so - if you create your main widget on the heap you must delete it - yourself. - - You need not have a main widget; connecting lastWindowClosed() to - quit() is an alternative. - - For X11, this function also resizes and moves the main widget - according to the \e -geometry command-line option, so you should - set the default geometry (using \l TQWidget::setGeometry()) before - calling setMainWidget(). - - \sa mainWidget(), exec(), quit() -*/ - -void TQApplication::setMainWidget( TQWidget *mainWidget ) -{ -#if defined(QT_CHECK_STATE) - if ( mainWidget && mainWidget->parentWidget() && - ! mainWidget->parentWidget()->isDesktop() ) - tqWarning( "TQApplication::setMainWidget(): New main widget (%s/%s) " - "has a parent!", - mainWidget->className(), mainWidget->name() ); -#endif - main_widget = mainWidget; - if ( main_widget ) { // give WM command line - XSetWMProperties( main_widget->x11Display(), main_widget->winId(), - 0, 0, app_argv, app_argc, 0, 0, 0 ); - if ( mwTitle ) - XStoreName( main_widget->x11Display(), main_widget->winId(), (char*)mwTitle ); - if ( mwGeometry ) { // parse geometry - int x, y; - int w, h; - int m = XParseGeometry( (char*)mwGeometry, &x, &y, (uint*)&w, (uint*)&h ); - TQSize minSize = main_widget->minimumSize(); - TQSize maxSize = main_widget->maximumSize(); - if ( (m & XValue) == 0 ) - x = main_widget->geometry().x(); - if ( (m & YValue) == 0 ) - y = main_widget->geometry().y(); - if ( (m & WidthValue) == 0 ) - w = main_widget->width(); - if ( (m & HeightValue) == 0 ) - h = main_widget->height(); - w = TQMIN(w,maxSize.width()); - h = TQMIN(h,maxSize.height()); - w = TQMAX(w,minSize.width()); - h = TQMAX(h,minSize.height()); - if ( (m & XNegative) ) { - x = desktop()->width() + x - w; - qt_widget_tlw_gravity = NorthEastGravity; - } - if ( (m & YNegative) ) { - y = desktop()->height() + y - h; - qt_widget_tlw_gravity = (m & XNegative) ? SouthEastGravity : SouthWestGravity; - } - main_widget->setGeometry( x, y, w, h ); - } - } -} - -#ifndef TQT_NO_CURSOR - -/***************************************************************************** - TQApplication cursor stack - *****************************************************************************/ - -extern void tqt_x11_enforce_cursor( TQWidget * w ); - -typedef TQPtrList TQCursorList; - -static TQCursorList *cursorStack = 0; - -/*! - \fn TQCursor *TQApplication::overrideCursor() - - Returns the active application override cursor. - - This function returns 0 if no application cursor has been defined - (i.e. the internal cursor stack is empty). - - \sa setOverrideCursor(), restoreOverrideCursor() -*/ - -/*! - Sets the application override cursor to \a cursor. - - Application override cursors are intended for showing the user - that the application is in a special state, for example during an - operation that might take some time. - - This cursor will be displayed in all the application's widgets - until restoreOverrideCursor() or another setOverrideCursor() is - called. - - Application cursors are stored on an internal stack. - setOverrideCursor() pushes the cursor onto the stack, and - restoreOverrideCursor() pops the active cursor off the stack. - Every setOverrideCursor() must eventually be followed by a - corresponding restoreOverrideCursor(), otherwise the stack will - never be emptied. - - If \a replace is TRUE, the new cursor will replace the last - override cursor (the stack keeps its depth). If \a replace is - FALSE, the new stack is pushed onto the top of the stack. - - Example: - \code - TQApplication::setOverrideCursor( TQCursor(TQt::WaitCursor) ); - calculateHugeMandelbrot(); // lunch time... - TQApplication::restoreOverrideCursor(); - \endcode - - \sa overrideCursor(), restoreOverrideCursor(), TQWidget::setCursor() -*/ - -void TQApplication::setOverrideCursor( const TQCursor &cursor, bool replace ) -{ - if ( !cursorStack ) { - cursorStack = new TQCursorList; - TQ_CHECK_PTR( cursorStack ); - cursorStack->setAutoDelete( TRUE ); - } - app_cursor = new TQCursor( cursor ); - TQ_CHECK_PTR( app_cursor ); - if ( replace ) - cursorStack->removeLast(); - cursorStack->append( app_cursor ); - - TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); - TQWidget *w; - while ( (w=it.current()) ) { // for all widgets that have - if ( w->testWState( WState_OwnCursor ) ) - tqt_x11_enforce_cursor( w ); - ++it; - } - XFlush( appDpy ); // make X execute it NOW -} - -/*! - Undoes the last setOverrideCursor(). - - If setOverrideCursor() has been called twice, calling - restoreOverrideCursor() will activate the first cursor set. - Calling this function a second time restores the original widgets' - cursors. - - \sa setOverrideCursor(), overrideCursor(). -*/ - -void TQApplication::restoreOverrideCursor() -{ - if ( !cursorStack ) // no cursor stack - return; - cursorStack->removeLast(); - app_cursor = cursorStack->last(); - if ( TQWidget::mapper != 0 && !closingDown() ) { - TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); - TQWidget *w; - while ( (w=it.current()) ) { // set back to original cursors - if ( w->testWState( WState_OwnCursor ) ) - tqt_x11_enforce_cursor( w ); - ++it; - } - XFlush( appDpy ); - } - if ( !app_cursor ) { - delete cursorStack; - cursorStack = 0; - } -} - -#endif - -/*! - \fn bool TQApplication::hasGlobalMouseTracking() - - Returns TRUE if global mouse tracking is enabled; otherwise - returns FALSE. - - \sa setGlobalMouseTracking() -*/ - -/*! - Enables global mouse tracking if \a enable is TRUE, or disables it - if \a enable is FALSE. - - Enabling global mouse tracking makes it possible for widget event - filters or application event filters to get all mouse move events, - even when no button is depressed. This is useful for special GUI - elements, e.g. tooltips. - - Global mouse tracking does not affect widgets and their - mouseMoveEvent(). For a widget to get mouse move events when no - button is depressed, it must do TQWidget::setMouseTracking(TRUE). - - This function uses an internal counter. Each - setGlobalMouseTracking(TRUE) must have a corresponding - setGlobalMouseTracking(FALSE): - \code - // at this point global mouse tracking is off - TQApplication::setGlobalMouseTracking( TRUE ); - TQApplication::setGlobalMouseTracking( TRUE ); - TQApplication::setGlobalMouseTracking( FALSE ); - // at this point it's still on - TQApplication::setGlobalMouseTracking( FALSE ); - // but now it's off - \endcode - - \sa hasGlobalMouseTracking(), TQWidget::hasMouseTracking() -*/ - -void TQApplication::setGlobalMouseTracking( bool enable ) -{ - bool tellAllWidgets; - if ( enable ) { - tellAllWidgets = (++app_tracking == 1); - } else { - tellAllWidgets = (--app_tracking == 0); - } - if ( tellAllWidgets ) { - TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); - TQWidget *w; - while ( (w=it.current()) ) { - if ( app_tracking > 0 ) { // switch on - if ( !w->testWState(WState_MouseTracking) ) { - w->setMouseTracking( TRUE ); - w->clearWState( WState_MouseTracking ); - } - } else { // switch off - if ( !w->testWState(WState_MouseTracking) ) { - w->setWState( WState_MouseTracking ); - w->setMouseTracking( FALSE ); - } - } - ++it; - } - } -} - - -/***************************************************************************** - Routines to find a TQt widget from a screen position - *****************************************************************************/ - -Window qt_x11_findClientWindow( Window win, Atom property, bool leaf ) -{ - Atom type = None; - int format, i; - ulong nitems, after; - uchar *data; - Window root, parent, target=0, *children=0; - uint nchildren; - if ( XGetWindowProperty( appDpy, win, property, 0, 0, FALSE, AnyPropertyType, - &type, &format, &nitems, &after, &data ) == Success ) { - if ( data ) - XFree( (char *)data ); - if ( type ) - return win; - } - if ( !XQueryTree(appDpy,win,&root,&parent,&children,&nchildren) ) { - if ( children ) - XFree( (char *)children ); - return 0; - } - for ( i=nchildren-1; !target && i >= 0; i-- ) - target = qt_x11_findClientWindow( children[i], property, leaf ); - if ( children ) - XFree( (char *)children ); - return target; -} - - -/*! - Returns a pointer to the widget at global screen position \a - (x, y), or 0 if there is no TQt widget there. - - If \a child is FALSE and there is a child widget at position \a - (x, y), the top-level widget containing it is returned. If \a child - is TRUE the child widget at position \a (x, y) is returned. - - This function is normally rather slow. - - \sa TQCursor::pos(), TQWidget::grabMouse(), TQWidget::grabKeyboard() -*/ - -TQWidget *TQApplication::widgetAt( int x, int y, bool child ) -{ - int screen = TQCursor::x11Screen(); - int lx, ly; - - Window target; - if ( !XTranslateCoordinates(appDpy, - TQPaintDevice::x11AppRootWindow(screen), - TQPaintDevice::x11AppRootWindow(screen), - x, y, &lx, &ly, &target) ) { - return 0; - } - if ( !target || target == TQPaintDevice::x11AppRootWindow(screen) ) - return 0; - TQWidget *w, *c; - w = TQWidget::find( (WId)target ); - - if ( !w ) { - qt_ignore_badwindow(); - target = qt_x11_findClientWindow( target, tqt_wm_state, TRUE ); - if (qt_badwindow() ) - return 0; - w = TQWidget::find( (WId)target ); -#if 0 - if ( !w ) { - // Perhaps the widgets at (x,y) is inside a foreign application? - // Search all toplevel widgets to see if one is within target - TQWidgetList *list = topLevelWidgets(); - TQWidget *widget = list->first(); - while ( widget && !w ) { - Window ctarget = target; - if ( widget->isVisible() && !widget->isDesktop() ) { - Window wid = widget->winId(); - while ( ctarget && !w ) { - XTranslateCoordinates(appDpy, - TQPaintDevice::x11AppRootWindow(screen), - ctarget, x, y, &lx, &ly, &ctarget); - if ( ctarget == wid ) { - // Found - w = widget; - XTranslateCoordinates(appDpy, - TQPaintDevice::x11AppRootWindow(screen), - ctarget, x, y, &lx, &ly, &ctarget); - } - } - } - widget = list->next(); - } - delete list; - } -#endif - } - if ( child && w ) { - if ( (c = w->childAt( w->mapFromGlobal(TQPoint(x, y ) ) ) ) ) - return c; - } - return w; -} - -/*! - \overload TQWidget *TQApplication::widgetAt( const TQPoint &pos, bool child ) - - Returns a pointer to the widget at global screen position \a pos, - or 0 if there is no TQt widget there. - - If \a child is FALSE and there is a child widget at position \a - pos, the top-level widget containing it is returned. If \a child - is TRUE the child widget at position \a pos is returned. -*/ - - -/*! - Flushes the X event queue in the X11 implementation. This normally - returns almost immediately. Does nothing on other platforms. - - \sa syncX() -*/ - -void TQApplication::flushX() -{ - if ( appDpy ) - XFlush( appDpy ); -} - -/*! - Flushes the window system specific event queues. - - If you are doing graphical changes inside a loop that does not - return to the event loop on asynchronous window systems like X11 - or double buffered window systems like MacOS X, and you want to - visualize these changes immediately (e.g. Splash Screens), call - this function. - - \sa flushX() sendPostedEvents() TQPainter::flush() -*/ - -void TQApplication::flush() -{ - flushX(); -} - -/*! - Synchronizes with the X server in the X11 implementation. This - normally takes some time. Does nothing on other platforms. - - \sa flushX() -*/ - -void TQApplication::syncX() -{ - if ( appDpy ) - XSync( appDpy, False ); // don't discard events -} - - -/*! - Sounds the bell, using the default volume and sound. -*/ - -void TQApplication::beep() -{ - if ( appDpy ) - XBell( appDpy, 0 ); -} - - - -/***************************************************************************** - Special lookup functions for windows that have been reparented recently - *****************************************************************************/ - -static TQWidgetIntDict *wPRmapper = 0; // alternative widget mapper - -void qPRCreate( const TQWidget *widget, Window oldwin ) -{ // TQWidget::reparent mechanism - if ( !wPRmapper ) { - wPRmapper = new TQWidgetIntDict; - TQ_CHECK_PTR( wPRmapper ); - } - wPRmapper->insert( (long)oldwin, widget ); // add old window to mapper - TQETWidget *w = (TQETWidget *)widget; - w->setWState( TQt::WState_Reparented ); // set reparented flag -} - -void qPRCleanup( TQWidget *widget ) -{ - TQETWidget *etw = (TQETWidget *)widget; - if ( !(wPRmapper && etw->testWState(TQt::WState_Reparented)) ) - return; // not a reparented widget - TQWidgetIntDictIt it(*wPRmapper); - TQWidget *w; - while ( (w=it.current()) ) { - int key = it.currentKey(); - ++it; - if ( w == etw ) { // found widget - etw->clearWState( TQt::WState_Reparented ); // clear flag - wPRmapper->remove( key );// old window no longer needed - if ( wPRmapper->count() == 0 ) { // became empty - delete wPRmapper; // then reset alt mapper - wPRmapper = 0; - return; - } - } - } -} - -static TQETWidget *qPRFindWidget( Window oldwin ) -{ - return wPRmapper ? (TQETWidget*)wPRmapper->find((long)oldwin) : 0; -} - -/*! - \internal -*/ -int TQApplication::x11ClientMessage(TQWidget* w, XEvent* event, bool passive_only) -{ - TQETWidget *widget = (TQETWidget*)w; - if ( event->xclient.format == 32 && event->xclient.message_type ) { - if ( event->xclient.message_type == tqt_wm_protocols ) { - Atom a = event->xclient.data.l[0]; - if ( a == tqt_wm_delete_window ) { - if ( passive_only ) return 0; - widget->translateCloseEvent(event); - } - else if ( a == tqt_wm_take_focus ) { - TQWidget * amw = activeModalWidget(); - if ( (ulong) event->xclient.data.l[1] > tqt_x_time ) - tqt_x_time = event->xclient.data.l[1]; - if ( amw && amw != widget ) { - TQWidget* groupLeader = widget; - while ( groupLeader && !groupLeader->testWFlags( TQt::WGroupLeader ) - && groupLeader != amw ) - groupLeader = groupLeader->parentWidget(); - if ( !groupLeader ) { - TQWidget *p = amw->parentWidget(); - while (p && p != widget) - p = p->parentWidget(); - if (!p || !qt_net_supported_list) - amw->raise(); // help broken window managers - amw->setActiveWindow(); - } - } -#ifndef TQT_NO_WHATSTHIS - } else if ( a == qt_net_wm_context_help ) { - TQWhatsThis::enterWhatsThisMode(); -#endif // TQT_NO_WHATSTHIS - } else if ( a == qt_net_wm_ping ) { - // avoid send/reply loops - Window root = TQPaintDevice::x11AppRootWindow( w->x11Screen() ); - if (event->xclient.window != root) { - event->xclient.window = root; - XSendEvent( event->xclient.display, event->xclient.window, - False, SubstructureNotifyMask|SubstructureRedirectMask, event ); - } -#ifndef TQT_NO_XSYNC - } else if (a == qt_net_wm_sync_request ) { - widget->handleSyncRequest( event ); -#endif - } - } else if ( event->xclient.message_type == qt_qt_scrolldone ) { - widget->translateScrollDoneEvent(event); - } else if ( event->xclient.message_type == qt_xdnd_position ) { - qt_handle_xdnd_position( widget, event, passive_only ); - } else if ( event->xclient.message_type == qt_xdnd_enter ) { - qt_handle_xdnd_enter( widget, event, passive_only ); - } else if ( event->xclient.message_type == qt_xdnd_status ) { - qt_handle_xdnd_status( widget, event, passive_only ); - } else if ( event->xclient.message_type == qt_xdnd_leave ) { - qt_handle_xdnd_leave( widget, event, passive_only ); - } else if ( event->xclient.message_type == qt_xdnd_drop ) { - qt_handle_xdnd_drop( widget, event, passive_only ); - } else if ( event->xclient.message_type == qt_xdnd_finished ) { - qt_handle_xdnd_finished( widget, event, passive_only ); - } else { - if ( passive_only ) return 0; - // All other are interactions - } - } else { - qt_motifdnd_handle_msg( widget, event, passive_only ); - } - - return 0; -} - -/*! - This function does the core processing of individual X - \a{event}s, normally by dispatching TQt events to the right - destination. - - It returns 1 if the event was consumed by special handling, 0 if - the \a event was consumed by normal handling, and -1 if the \a - event was for an unrecognized widget. - - \sa x11EventFilter() -*/ -int TQApplication::x11ProcessEvent( XEvent* event ) -{ - switch ( event->type ) { - case ButtonPress: - ignoreNextMouseReleaseEvent = FALSE; - tqt_x_user_time = event->xbutton.time; - // fallthrough intended - case ButtonRelease: - tqt_x_time = event->xbutton.time; - break; - case MotionNotify: - tqt_x_time = event->xmotion.time; - break; - case XKeyPress: - tqt_x_user_time = event->xkey.time; - // fallthrough intended - case XKeyRelease: - tqt_x_time = event->xkey.time; - break; - case PropertyNotify: - tqt_x_time = event->xproperty.time; - break; - case EnterNotify: - case LeaveNotify: - tqt_x_time = event->xcrossing.time; - break; - case SelectionClear: - tqt_x_time = event->xselectionclear.time; - break; - default: - break; - } - - TQETWidget *widget = (TQETWidget*)TQWidget::find( (WId)event->xany.window ); - - if ( wPRmapper ) { // just did a widget reparent? - if ( widget == 0 ) { // not in std widget mapper - switch ( event->type ) { // only for mouse/key events - case ButtonPress: - case ButtonRelease: - case MotionNotify: - case XKeyPress: - case XKeyRelease: - widget = qPRFindWidget( event->xany.window ); - break; - } - } - else if ( widget->testWState(WState_Reparented) ) - qPRCleanup( widget ); // remove from alt mapper - } - - TQETWidget *keywidget=0; - bool grabbed=FALSE; - if ( event->type==XKeyPress || event->type==XKeyRelease ) { - keywidget = (TQETWidget*)TQWidget::keyboardGrabber(); - if ( keywidget ) { - grabbed = TRUE; - } else { - if ( focus_widget ) - keywidget = (TQETWidget*)focus_widget; - if ( !keywidget ) { - if ( inPopupMode() ) // no focus widget, see if we have a popup - keywidget = (TQETWidget*) activePopupWidget(); - else if ( widget ) - keywidget = (TQETWidget*)widget->topLevelWidget(); - } - } - } - -#ifndef TQT_NO_IM - // Filtering input events by the input context. It has to be taken - // place before any other key event consumers such as eventfilters - // and accelerators because some input methods require quite - // various key combination and sequences. It often conflicts with - // accelerators and so on, so we must give the input context the - // filtering opportunity first to ensure all input methods work - // properly regardless of application design. - -// #ifndef TQT_NO_IM_EXTENSIONS - if( keywidget && keywidget->isEnabled() && keywidget->isInputMethodEnabled() ) { -// #else -// if( keywidget && keywidget->isEnabled() ) { -// #endif - if( ( event->type==XKeyPress || event->type==XKeyRelease ) && - sm_blockUserInput ) // block user interaction during session management - return TRUE; - - // for XIM handling - TQInputContext *qic = keywidget->getInputContext(); - if( qic && qic->x11FilterEvent( keywidget, event ) ) - return TRUE; - - // filterEvent() accepts TQEvent *event rather than preexpanded key - // event attribute values. This is intended to pass other IM-related - // events in future. The IM-related events are supposed as - // TQWheelEvent, TQTabletEvent and so on. Other non IM-related events - // should not be forwarded to input contexts to prevent weird event - // handling. - if ( ( event->type == XKeyPress || event->type == XKeyRelease ) ) { - int code = -1; - int count = 0; - int state; - char ascii = 0; - TQEvent::Type type; - TQString text; - - keywidget->translateKeyEventInternal( event, count, text, - state, ascii, code, type, - FALSE, FALSE ); - - // both key press/release is required for some complex - // input methods. don't eliminate anything. - TQKeyEvent keyevent( type, code, ascii, state, text, FALSE, count ); - - if( qic && qic->filterEvent( &keyevent ) ) - return TRUE; - } - } else -#endif // TQT_NO_IM - { - if ( XFilterEvent( event, None ) ) - return TRUE; - } - - if ( qt_x11EventFilter(event) ) // send through app filter - return 1; - - if ( event->type == MappingNotify ) { // keyboard mapping changed - XRefreshKeyboardMapping( &event->xmapping ); - return 0; - } - - if ( event->type == PropertyNotify ) { // some properties changed - if ( event->xproperty.window == TQPaintDevice::x11AppRootWindow( 0 ) ) { - // root properties for the first screen - if ( event->xproperty.atom == tqt_clipboard_sentinel ) { - if (qt_check_clipboard_sentinel() ) - emit clipboard()->dataChanged(); - } else if ( event->xproperty.atom == qt_selection_sentinel ) { - if (qt_check_selection_sentinel() ) - emit clipboard()->selectionChanged(); - } else if ( obey_desktop_settings ) { - if ( event->xproperty.atom == qt_resource_manager ) - qt_set_x11_resources(); - else if ( event->xproperty.atom == qt_settings_timestamp ) - TQApplication::x11_apply_settings(); - } - } - if ( event->xproperty.window == TQPaintDevice::x11AppRootWindow() ) { - // root properties for the default screen - if ( event->xproperty.atom == qt_input_encoding ) { - qt_set_input_encoding(); - } else if ( event->xproperty.atom == qt_net_supported ) { - qt_get_net_supported(); - } else if ( event->xproperty.atom == qt_net_virtual_roots ) { - qt_get_net_virtual_roots(); - } else if ( event->xproperty.atom == qt_net_workarea ) { - qt_desktopwidget_update_workarea(); - } - } else if ( widget ) { - widget->translatePropertyEvent(event); - } else { - return -1; // don't know this window - } - return 0; - } - -#ifndef TQT_NO_XRANDR - // XRandR doesn't care if TQt doesn't know about the widget, so handle XRandR stuff before the !widget check below - if (event->type == xrandr_eventbase + RRScreenChangeNotify - || ( event->type == ConfigureNotify && event->xconfigure.window == TQPaintDevice::x11AppRootWindow())) { - // update Xlib internals with the latest screen configuration - XRRUpdateConfiguration(event); - - // update the size for desktop widget - int scr = XRRRootToScreen( appDpy, event->xany.window ); - TQWidget *w = desktop()->screen( scr ); - - if (w) { - int widgetScr = -1; - // make sure the specified widget is on the same screen that received the XRandR event - XWindowAttributes widgetAttr; - XGetWindowAttributes(appDpy, w->winId(), &widgetAttr); - if (widgetAttr.screen) { - widgetScr = XScreenNumberOfScreen(widgetAttr.screen); - } - - if ((widgetScr < 0) || (widgetScr == scr)) { - TQSize oldSize( w->size() ); - w->crect.setWidth( DisplayWidth( appDpy, scr ) ); - w->crect.setHeight( DisplayHeight( appDpy, scr ) ); - if ( w->size() != oldSize ) { - TQResizeEvent e( w->size(), oldSize ); - TQApplication::sendEvent( w, &e ); - emit desktop()->resized( scr ); - } - } - } - } -#endif // TQT_NO_XRANDR - - if ( !widget ) { // don't know this windows - TQWidget* popup = TQApplication::activePopupWidget(); - if ( popup ) { - - /* - That is more than suboptimal. The real solution should - do some keyevent and buttonevent translation, so that - the popup still continues to work as the user expects. - Unfortunately this translation is currently only - possible with a known widget. I'll change that soon - (Matthias). - */ - - // Danger - make sure we don't lock the server - switch ( event->type ) { - case ButtonPress: - case ButtonRelease: - case XKeyPress: - case XKeyRelease: - do { - popup->close(); - } while ( (popup = tqApp->activePopupWidget()) ); - return 1; - } - } - return -1; - } - - if ( event->type == XKeyPress || event->type == XKeyRelease ) - widget = keywidget; // send XKeyEvents through keywidget->x11Event() - - if ( app_do_modal ) // modal event handling - if ( !tqt_try_modal(widget, event) ) { - if ( event->type == ClientMessage ) - x11ClientMessage( widget, event, TRUE ); - return 1; - } - - - if ( widget->x11Event(event) ) // send through widget filter - return 1; -#if defined (QT_TABLET_SUPPORT) - if ( event->type == xinput_motion || - event->type == xinput_button_release || - event->type == xinput_button_press ) { - widget->translateXinputEvent( event ); - return 0; - } -#endif - - switch ( event->type ) { - - case ButtonRelease: // mouse event - if ( ignoreNextMouseReleaseEvent ) { - ignoreNextMouseReleaseEvent = FALSE; - break; - } - // fall through intended - case ButtonPress: - if (event->xbutton.root != RootWindow(widget->x11Display(), widget->x11Screen()) - && ! qt_xdnd_dragging) { - while ( activePopupWidget() ) - activePopupWidget()->close(); - return 1; - } - if (event->type == ButtonPress) - qt_net_update_user_time(widget->topLevelWidget()); - // fall through intended - case MotionNotify: -#if defined(QT_TABLET_SUPPORT) - if ( !chokeMouse ) { -#endif - widget->translateMouseEvent( event ); -#if defined(QT_TABLET_SUPPORT) - } else { - chokeMouse = FALSE; - } -#endif - break; - - case XKeyPress: // keyboard event - qt_net_update_user_time(widget->topLevelWidget()); - // fallthrough intended - case XKeyRelease: - { - if ( keywidget && keywidget->isEnabled() ) { // should always exist - // tqDebug( "sending key event" ); - keywidget->translateKeyEvent( event, grabbed ); - } - break; - } - - case GraphicsExpose: - case Expose: // paint event - widget->translatePaintEvent( event ); - break; - - case ConfigureNotify: // window move/resize event - if ( event->xconfigure.event == event->xconfigure.window ) - widget->translateConfigEvent( event ); - break; - - case XFocusIn: { // got focus - if ( widget->isDesktop() ) - break; - if ( inPopupMode() ) // some delayed focus event to ignore - break; - if ( !widget->isTopLevel() ) - break; - if ( event->xfocus.detail != NotifyAncestor && - event->xfocus.detail != NotifyInferior && - event->xfocus.detail != NotifyNonlinear ) - break; - widget->createInputContext(); - setActiveWindow( widget ); - if ( qt_focus_model == FocusModel_PointerRoot ) { - // We got real input focus from somewhere, but we were in PointerRoot - // mode, so we don't trust this event. Check the focus model to make - // sure we know what focus mode we are using... - qt_check_focus_model(); - } - } - break; - - case XFocusOut: // lost focus - if ( widget->isDesktop() ) - break; - if ( !widget->isTopLevel() ) - break; - if ( event->xfocus.mode == NotifyGrab ) - qt_xfocusout_grab_counter++; - if ( event->xfocus.mode != NotifyNormal ) - break; - if ( event->xfocus.detail != NotifyAncestor && - event->xfocus.detail != NotifyNonlinearVirtual && - event->xfocus.detail != NotifyNonlinear ) - break; - if ( !inPopupMode() && widget == active_window ) - setActiveWindow( 0 ); - break; - - case EnterNotify: { // enter window - if ( TQWidget::mouseGrabber() && widget != TQWidget::mouseGrabber() ) - break; - if ( inPopupMode() && widget->topLevelWidget() != activePopupWidget() ) - break; - if ( event->xcrossing.mode != NotifyNormal || - event->xcrossing.detail == NotifyVirtual || - event->xcrossing.detail == NotifyNonlinearVirtual ) - break; - if ( event->xcrossing.focus && - !widget->isDesktop() && !widget->isActiveWindow() ) { - if ( qt_focus_model == FocusModel_Unknown ) // check focus model - qt_check_focus_model(); - if ( qt_focus_model == FocusModel_PointerRoot ) // PointerRoot mode - setActiveWindow( widget ); - } - tqt_dispatchEnterLeave( widget, TQWidget::find( curWin ) ); - curWin = widget->winId(); - widget->translateMouseEvent( event ); //we don't get MotionNotify, emulate it - } - break; - - case LeaveNotify: { // leave window - if ( TQWidget::mouseGrabber() && widget != TQWidget::mouseGrabber() ) - break; - if ( curWin && widget->winId() != curWin ) - break; - if ( event->xcrossing.mode != NotifyNormal ) - break; - if ( !widget->isDesktop() ) - widget->translateMouseEvent( event ); //we don't get MotionNotify, emulate it - - TQWidget* enter = 0; - XEvent ev; - while ( XCheckMaskEvent( widget->x11Display(), EnterWindowMask | LeaveWindowMask , &ev ) - && !qt_x11EventFilter( &ev )) { - TQWidget* event_widget = TQWidget::find( ev.xcrossing.window ); - if( event_widget && event_widget->x11Event( &ev ) ) - break; - if ( ev.type == LeaveNotify && ev.xcrossing.mode == NotifyNormal ){ - enter = event_widget; - XPutBackEvent( widget->x11Display(), &ev ); - break; - } - if ( ev.xcrossing.mode != NotifyNormal || - ev.xcrossing.detail == NotifyVirtual || - ev.xcrossing.detail == NotifyNonlinearVirtual ) - continue; - enter = event_widget; - if ( ev.xcrossing.focus && - enter && !enter->isDesktop() && !enter->isActiveWindow() ) { - if ( qt_focus_model == FocusModel_Unknown ) // check focus model - qt_check_focus_model(); - if ( qt_focus_model == FocusModel_PointerRoot ) // PointerRoot mode - setActiveWindow( enter ); - } - break; - } - - if ( ( ! enter || enter->isDesktop() ) && - event->xcrossing.focus && widget == active_window && - qt_focus_model == FocusModel_PointerRoot // PointerRoot mode - ) { - setActiveWindow( 0 ); - } - - if ( !curWin ) - tqt_dispatchEnterLeave( widget, 0 ); - - tqt_dispatchEnterLeave( enter, widget ); - curWin = enter ? enter->winId() : 0; - } - break; - - case UnmapNotify: // window hidden - if ( widget->isTopLevel() && widget->isShown() ) { - widget->topData()->spont_unmapped = 1; - TQHideEvent e; - TQApplication::sendSpontaneousEvent( widget, &e ); - widget->hideChildren( TRUE ); - } - break; - - case MapNotify: // window shown - if ( widget->isTopLevel() && - widget->topData()->spont_unmapped ) { - widget->topData()->spont_unmapped = 0; - widget->showChildren( TRUE ); - TQShowEvent e; - TQApplication::sendSpontaneousEvent( widget, &e ); - } - break; - - case ClientMessage: // client message - return x11ClientMessage(widget,event,False); - - case ReparentNotify: // window manager reparents - while ( XCheckTypedWindowEvent( widget->x11Display(), - widget->winId(), - ReparentNotify, - event ) ) - ; // skip old reparent events - if ( event->xreparent.parent == TQPaintDevice::x11AppRootWindow() ) { - if ( widget->isTopLevel() ) { - widget->topData()->parentWinId = event->xreparent.parent; - if ( qt_deferred_map_contains( widget ) ) { - qt_deferred_map_take( widget ); - XMapWindow( appDpy, widget->winId() ); - } - } - } else - // store the parent. Useful for many things, embedding for instance. - widget->topData()->parentWinId = event->xreparent.parent; - if ( widget->isTopLevel() ) { - // the widget frame strut should also be invalidated - widget->topData()->fleft = widget->topData()->fright = - widget->topData()->ftop = widget->topData()->fbottom = 0; - - if ( qt_focus_model != FocusModel_Unknown ) { - // toplevel reparented... - TQWidget *newparent = TQWidget::find( event->xreparent.parent ); - if ( ! newparent || newparent->isDesktop() ) { - // we dont' know about the new parent (or we've been - // reparented to root), perhaps a window manager - // has been (re)started? reset the focus model to unknown - qt_focus_model = FocusModel_Unknown; - } - } - } - break; - - case SelectionRequest: { - XSelectionRequestEvent *req = &event->xselectionrequest; - if (! req) - break; - - if ( qt_xdnd_selection && req->selection == qt_xdnd_selection ) { - qt_xdnd_handle_selection_request( req ); - - } else if (tqt_clipboard) { - TQCustomEvent e( TQEvent::Clipboard, event ); - TQApplication::sendSpontaneousEvent( tqt_clipboard, &e ); - } - break; - } - case SelectionClear: { - XSelectionClearEvent *req = &event->xselectionclear; - // don't deliver dnd events to the clipboard, it gets confused - if (! req || ( qt_xdnd_selection && req->selection ) == qt_xdnd_selection) - break; - - if (tqt_clipboard) { - TQCustomEvent e( TQEvent::Clipboard, event ); - TQApplication::sendSpontaneousEvent( tqt_clipboard, &e ); - } - break; - } - - case SelectionNotify: { - XSelectionEvent *req = &event->xselection; - // don't deliver dnd events to the clipboard, it gets confused - if (! req || ( qt_xdnd_selection && req->selection ) == qt_xdnd_selection) - break; - - if (tqt_clipboard) { - TQCustomEvent e( TQEvent::Clipboard, event ); - TQApplication::sendSpontaneousEvent( tqt_clipboard, &e ); - } - break; - } - - default: - break; - } - - return 0; -} - -/*! - This virtual function is only implemented under X11. - - If you create an application that inherits TQApplication and - reimplement this function, you get direct access to all X events - that the are received from the X server. - - Return TRUE if you want to stop the event from being processed. - Return FALSE for normal event dispatching. - - \sa x11ProcessEvent() -*/ - -bool TQApplication::x11EventFilter( XEvent * ) -{ - return FALSE; -} - - - -/***************************************************************************** - Modal widgets; Since Xlib has little support for this we roll our own - modal widget mechanism. - A modal widget without a parent becomes application-modal. - A modal widget with a parent becomes modal to its parent and grandparents.. - - tqt_enter_modal() - Enters modal state - Arguments: - TQWidget *widget A modal widget - - tqt_leave_modal() - Leaves modal state for a widget - Arguments: - TQWidget *widget A modal widget - *****************************************************************************/ - -bool tqt_modal_state() -{ - return app_do_modal; -} - -void tqt_enter_modal( TQWidget *widget ) -{ - if ( !tqt_modal_stack ) { // create modal stack - tqt_modal_stack = new TQWidgetList; - TQ_CHECK_PTR( tqt_modal_stack ); - } - if (widget->parentWidget()) { - TQEvent e(TQEvent::WindowBlocked); - TQApplication::sendEvent(widget->parentWidget(), &e); - } - - tqt_dispatchEnterLeave( 0, TQWidget::find((WId)curWin) ); - tqt_modal_stack->insert( 0, widget ); - app_do_modal = TRUE; - curWin = 0; - ignoreNextMouseReleaseEvent = FALSE; -} - - -void tqt_leave_modal( TQWidget *widget ) -{ - if ( tqt_modal_stack && tqt_modal_stack->removeRef(widget) ) { - if ( tqt_modal_stack->isEmpty() ) { - delete tqt_modal_stack; - tqt_modal_stack = 0; - TQPoint p( TQCursor::pos() ); - TQWidget* w = TQApplication::widgetAt( p.x(), p.y(), TRUE ); - tqt_dispatchEnterLeave( w, TQWidget::find( curWin ) ); // send synthetic enter event - curWin = w? w->winId() : 0; - } - } - app_do_modal = tqt_modal_stack != 0; - ignoreNextMouseReleaseEvent = TRUE; - - if (widget->parentWidget()) { - TQEvent e(TQEvent::WindowUnblocked); - TQApplication::sendEvent(widget->parentWidget(), &e); - } -} - - -TQ_EXPORT bool tqt_try_modal( TQWidget *widget, XEvent *event ) -{ - if (qt_xdnd_dragging) { - // allow mouse events while DnD is active - switch (event->type) { - case ButtonPress: - case ButtonRelease: - case MotionNotify: - return TRUE; - default: - break; - } - } - - if ( tqt_tryModalHelper( widget ) ) - return TRUE; - - bool block_event = FALSE; - switch ( event->type ) { - case ButtonPress: // disallow mouse/key events - case ButtonRelease: - case MotionNotify: - case XKeyPress: - case XKeyRelease: - case EnterNotify: - case LeaveNotify: - case ClientMessage: - block_event = TRUE; - break; - default: - break; - } - - return !block_event; -} - - -/***************************************************************************** - Popup widget mechanism - - openPopup() - Adds a widget to the list of popup widgets - Arguments: - TQWidget *widget The popup widget to be added - - closePopup() - Removes a widget from the list of popup widgets - Arguments: - TQWidget *widget The popup widget to be removed - *****************************************************************************/ - - -static int openPopupCount = 0; -void TQApplication::openPopup( TQWidget *popup ) -{ - openPopupCount++; - if ( !popupWidgets ) { // create list - popupWidgets = new TQWidgetList; - TQ_CHECK_PTR( popupWidgets ); - } - popupWidgets->append( popup ); // add to end of list - - if ( popupWidgets->count() == 1 && !qt_nograb() ){ // grab mouse/keyboard - int r = XGrabKeyboard( popup->x11Display(), popup->winId(), FALSE, - GrabModeSync, GrabModeAsync, CurrentTime ); - if ( (popupGrabOk = (r == GrabSuccess)) ) { - r = XGrabPointer( popup->x11Display(), popup->winId(), TRUE, - (uint)(ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | EnterWindowMask | - LeaveWindowMask | PointerMotionMask), - GrabModeSync, GrabModeAsync, - None, None, CurrentTime ); - - if ( (popupGrabOk = (r == GrabSuccess)) ) - XAllowEvents( popup->x11Display(), SyncPointer, CurrentTime ); - else - XUngrabKeyboard( popup->x11Display(), CurrentTime ); - } - } else if ( popupGrabOk ) { - XAllowEvents( popup->x11Display(), SyncPointer, CurrentTime ); - } - - // popups are not focus-handled by the window system (the first - // popup grabbed the keyboard), so we have to do that manually: A - // new popup gets the focus - TQFocusEvent::setReason( TQFocusEvent::Popup ); - if ( popup->focusWidget()) - popup->focusWidget()->setFocus(); - else - popup->setFocus(); - TQFocusEvent::resetReason(); -} - -void TQApplication::closePopup( TQWidget *popup ) -{ - if ( !popupWidgets ) - return; - popupWidgets->removeRef( popup ); - if (popup == popupOfPopupButtonFocus) { - popupButtonFocus = 0; - popupOfPopupButtonFocus = 0; - } - if ( popupWidgets->count() == 0 ) { // this was the last popup - popupCloseDownMode = TRUE; // control mouse events - delete popupWidgets; - popupWidgets = 0; - if ( !qt_nograb() && popupGrabOk ) { // grabbing not disabled - if ( mouseButtonState != 0 - || popup->geometry(). contains(TQPoint(mouseGlobalXPos, mouseGlobalYPos) ) ) - { // mouse release event or inside - XAllowEvents( popup->x11Display(), AsyncPointer, - CurrentTime ); - } else { // mouse press event - mouseButtonPressTime -= 10000; // avoid double click - XAllowEvents( popup->x11Display(), ReplayPointer,CurrentTime ); - } - XUngrabPointer( popup->x11Display(), CurrentTime ); - XFlush( popup->x11Display() ); - } - if ( active_window ) { - TQFocusEvent::setReason( TQFocusEvent::Popup ); - if ( active_window->focusWidget() ) - active_window->focusWidget()->setFocus(); - else - active_window->setFocus(); - TQFocusEvent::resetReason(); - } - } else { - // popups are not focus-handled by the window system (the - // first popup grabbed the keyboard), so we have to do that - // manually: A popup was closed, so the previous popup gets - // the focus. - TQFocusEvent::setReason( TQFocusEvent::Popup ); - TQWidget* aw = popupWidgets->getLast(); - if (aw->focusWidget()) - aw->focusWidget()->setFocus(); - else - aw->setFocus(); - TQFocusEvent::resetReason(); - if ( popupWidgets->count() == 1 && !qt_nograb() ){ // grab mouse/keyboard - int r = XGrabKeyboard( aw->x11Display(), aw->winId(), FALSE, - GrabModeSync, GrabModeAsync, CurrentTime ); - if ( (popupGrabOk = (r == GrabSuccess)) ) { - r = XGrabPointer( aw->x11Display(), aw->winId(), TRUE, - (uint)(ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | EnterWindowMask | - LeaveWindowMask | PointerMotionMask), - GrabModeSync, GrabModeAsync, - None, None, CurrentTime ); - - if ( (popupGrabOk = (r == GrabSuccess)) ) - XAllowEvents( aw->x11Display(), SyncPointer, CurrentTime ); - } - } - } -} - -/***************************************************************************** - Event translation; translates X11 events to TQt events - *****************************************************************************/ - -// -// Mouse event translation -// -// Xlib doesn't give mouse double click events, so we generate them by -// comparing window, time and position between two mouse press events. -// - -// -// Keyboard event translation -// - -int qt_x11_translateButtonState( int s ) -{ - int bst = 0; - if ( s & Button1Mask ) - bst |= TQt::LeftButton; - if ( s & Button2Mask ) - bst |= TQt::MidButton; - if ( s & Button3Mask ) - bst |= TQt::RightButton; - if ( s & ShiftMask ) - bst |= TQt::ShiftButton; - if ( s & ControlMask ) - bst |= TQt::ControlButton; - if ( s & qt_alt_mask ) - bst |= TQt::AltButton; - if ( s & qt_meta_mask ) - bst |= TQt::MetaButton; - return bst; -} - -bool TQETWidget::translateMouseEvent( const XEvent *event ) -{ - static bool manualGrab = FALSE; - TQEvent::Type type; // event parameters - TQPoint pos; - TQPoint globalPos; - int button = 0; - int state; - XEvent nextEvent; - - if ( sm_blockUserInput ) // block user interaction during session management - return TRUE; - - static int x_root_save = -1, y_root_save = -1; - - if ( event->type == MotionNotify ) { // mouse move - if (event->xmotion.root != RootWindow(appDpy, x11Screen()) && - ! qt_xdnd_dragging ) - return FALSE; - - XMotionEvent lastMotion = event->xmotion; - while( XPending( appDpy ) ) { // compres mouse moves - XNextEvent( appDpy, &nextEvent ); - if ( nextEvent.type == ConfigureNotify - || nextEvent.type == PropertyNotify - || nextEvent.type == Expose - || nextEvent.type == NoExpose ) { - tqApp->x11ProcessEvent( &nextEvent ); - continue; - } else if ( nextEvent.type != MotionNotify || - nextEvent.xmotion.window != event->xmotion.window || - nextEvent.xmotion.state != event->xmotion.state ) { - XPutBackEvent( appDpy, &nextEvent ); - break; - } - if ( !qt_x11EventFilter(&nextEvent) - && !x11Event( &nextEvent ) ) // send event through filter - lastMotion = nextEvent.xmotion; - else - break; - } - type = TQEvent::MouseMove; - pos.rx() = lastMotion.x; - pos.ry() = lastMotion.y; - globalPos.rx() = lastMotion.x_root; - globalPos.ry() = lastMotion.y_root; - state = qt_x11_translateButtonState( lastMotion.state ); - if ( qt_button_down && (state & (LeftButton | - MidButton | - RightButton ) ) == 0 ) - qt_button_down = 0; - - // throw away mouse move events that are sent multiple times to the same - // position - bool throw_away = FALSE; - if ( x_root_save == globalPos.x() && - y_root_save == globalPos.y() ) - throw_away = TRUE; - x_root_save = globalPos.x(); - y_root_save = globalPos.y(); - if ( throw_away ) - return TRUE; - } else if ( event->type == EnterNotify || event->type == LeaveNotify) { - XEvent *xevent = (XEvent *)event; - //unsigned int xstate = event->xcrossing.state; - type = TQEvent::MouseMove; - pos.rx() = xevent->xcrossing.x; - pos.ry() = xevent->xcrossing.y; - globalPos.rx() = xevent->xcrossing.x_root; - globalPos.ry() = xevent->xcrossing.y_root; - state = qt_x11_translateButtonState( xevent->xcrossing.state ); - if ( qt_button_down && (state & (LeftButton | - MidButton | - RightButton ) ) == 0 ) - qt_button_down = 0; - if ( !qt_button_down ) - state = state & ~(LeftButton | MidButton | RightButton ); - } else { // button press or release - pos.rx() = event->xbutton.x; - pos.ry() = event->xbutton.y; - globalPos.rx() = event->xbutton.x_root; - globalPos.ry() = event->xbutton.y_root; - state = qt_x11_translateButtonState( event->xbutton.state ); - switch ( event->xbutton.button ) { - case Button1: button = LeftButton; break; - case Button2: button = MidButton; break; - case Button3: button = RightButton; break; - case Button4: - case Button5: - case 6: - case 7: - // the fancy mouse wheel. - - // take care about grabbing. We do this here since it - // is clear that we return anyway - if ( tqApp->inPopupMode() && popupGrabOk ) - XAllowEvents( x11Display(), SyncPointer, CurrentTime ); - - // We are only interested in ButtonPress. - if (event->type == ButtonPress ){ - - // compress wheel events (the X Server will simply - // send a button press for each single notch, - // regardless whether the application can catch up - // or not) - int delta = 1; - XEvent xevent; - while ( XCheckTypedWindowEvent(x11Display(),winId(), - ButtonPress,&xevent) ){ - if (xevent.xbutton.button != event->xbutton.button){ - XPutBackEvent(x11Display(), &xevent); - break; - } - delta++; - } - - // the delta is defined as multiples of - // WHEEL_DELTA, which is set to 120. Future wheels - // may offer a finer-resolution. A positive delta - // indicates forward rotation, a negative one - // backward rotation respectively. - int btn = event->xbutton.button; - delta *= 120 * ( (btn == Button4 || btn == 6) ? 1 : -1 ); - bool hor = ( ( (btn == Button4 || btn == Button5) && (state&AltButton) ) || - (btn == 6 || btn == 7) ); - translateWheelEvent( globalPos.x(), globalPos.y(), delta, state, (hor)?Horizontal:Vertical ); - } - return TRUE; - - // history navigation buttons - case 8: button = HistoryBackButton; break; - case 9: button = HistoryForwardButton; break; - } - if ( event->type == ButtonPress ) { // mouse button pressed -#if defined(Q_OS_IRIX) && defined(QT_TABLET_SUPPORT) - XEvent myEv; - if ( XCheckTypedEvent( appDpy, xinput_button_press, &myEv ) ) { - if ( translateXinputEvent( &myEv ) ) { - //Spontaneous event sent. Check if we need to continue. - if ( chokeMouse ) { - chokeMouse = FALSE; - return FALSE; - } - } - } -#endif - qt_button_down = childAt( pos ); //magic for masked widgets - if ( !qt_button_down || !qt_button_down->testWFlags(WMouseNoMask) ) - qt_button_down = this; - if ( mouseActWindow == event->xbutton.window && - mouseButtonPressed == button && - (long)event->xbutton.time -(long)mouseButtonPressTime - < TQApplication::doubleClickInterval() && - TQABS(event->xbutton.x - mouseXPos) < 5 && - TQABS(event->xbutton.y - mouseYPos) < 5 ) { - type = TQEvent::MouseButtonDblClick; - mouseButtonPressTime -= 2000; // no double-click next time - } else { - type = TQEvent::MouseButtonPress; - mouseButtonPressTime = event->xbutton.time; - } - mouseButtonPressed = button; // save event params for - mouseXPos = pos.x(); // future double click tests - mouseYPos = pos.y(); - mouseGlobalXPos = globalPos.x(); - mouseGlobalYPos = globalPos.y(); - } else { // mouse button released -#if defined(Q_OS_IRIX) && defined(QT_TABLET_SUPPORT) - XEvent myEv; - if ( XCheckTypedEvent( appDpy, xinput_button_release, &myEv ) ) { - if ( translateXinputEvent( &myEv ) ) { - //Spontaneous event sent. Check if we need to continue. - if ( chokeMouse ) { - chokeMouse = FALSE; - return FALSE; - } - } - } -#endif - if ( manualGrab ) { // release manual grab - manualGrab = FALSE; - XUngrabPointer( x11Display(), CurrentTime ); - XFlush( x11Display() ); - } - - type = TQEvent::MouseButtonRelease; - } - } - mouseActWindow = winId(); // save some event params - mouseButtonState = state; - if ( type == 0 ) // don't send event - return FALSE; - - if ( tqApp->inPopupMode() ) { // in popup mode - TQWidget *popup = tqApp->activePopupWidget(); - if ( popup != this ) { - if ( testWFlags(WType_Popup) && rect().contains(pos) ) - popup = this; - else // send to last popup - pos = popup->mapFromGlobal( globalPos ); - } - bool releaseAfter = FALSE; - TQWidget *popupChild = popup->childAt( pos ); - TQWidget *popupTarget = popupChild ? popupChild : popup; - - if (popup != popupOfPopupButtonFocus){ - popupButtonFocus = 0; - popupOfPopupButtonFocus = 0; - } - - if ( !popupTarget->isEnabled() ) { - if ( popupGrabOk ) - XAllowEvents( x11Display(), SyncPointer, CurrentTime ); - } - - switch ( type ) { - case TQEvent::MouseButtonPress: - case TQEvent::MouseButtonDblClick: - popupButtonFocus = popupChild; - popupOfPopupButtonFocus = popup; - break; - case TQEvent::MouseButtonRelease: - releaseAfter = TRUE; - break; - default: - break; // nothing for mouse move - } - - Display* dpy = x11Display(); // store display, send() may destroy us - - - int oldOpenPopupCount = openPopupCount; - - if ( popupButtonFocus ) { - TQMouseEvent e( type, popupButtonFocus->mapFromGlobal(globalPos), - globalPos, button, state ); - TQApplication::sendSpontaneousEvent( popupButtonFocus, &e ); - if ( releaseAfter ) { - popupButtonFocus = 0; - popupOfPopupButtonFocus = 0; - } - } else if ( popupChild ) { - TQMouseEvent e( type, popupChild->mapFromGlobal(globalPos), - globalPos, button, state ); - TQApplication::sendSpontaneousEvent( popupChild, &e ); - } else { - TQMouseEvent e( type, pos, globalPos, button, state ); - TQApplication::sendSpontaneousEvent( popup, &e ); - } - - if ( type == TQEvent::MouseButtonPress && button == RightButton && ( openPopupCount == oldOpenPopupCount ) ) { - TQWidget *popupEvent = popup; - if(popupButtonFocus) - popupEvent = popupButtonFocus; - else if(popupChild) - popupEvent = popupChild; - TQContextMenuEvent e( TQContextMenuEvent::Mouse, pos, globalPos, state ); - TQApplication::sendSpontaneousEvent( popupEvent, &e ); - } - - if ( releaseAfter ) - qt_button_down = 0; - - if ( tqApp->inPopupMode() ) { // still in popup mode - if ( popupGrabOk ) - XAllowEvents( dpy, SyncPointer, CurrentTime ); - } else { - if ( type != TQEvent::MouseButtonRelease && state != 0 && - TQWidget::find((WId)mouseActWindow) ) { - manualGrab = TRUE; // need to manually grab - XGrabPointer( dpy, mouseActWindow, False, - (uint)(ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | - EnterWindowMask | LeaveWindowMask), - GrabModeAsync, GrabModeAsync, - None, None, CurrentTime ); - } - } - - } else { - TQWidget *widget = this; - TQWidget *w = TQWidget::mouseGrabber(); - if ( !w ) - w = qt_button_down; - if ( w && w != this ) { - widget = w; - pos = w->mapFromGlobal( globalPos ); - } - - if ( popupCloseDownMode ) { - popupCloseDownMode = FALSE; - if ( testWFlags(WType_Popup) ) // ignore replayed event - return TRUE; - } - - if ( type == TQEvent::MouseButtonRelease && - (state & (~button) & ( LeftButton | - MidButton | - RightButton)) == 0 ) { - qt_button_down = 0; - } - - int oldOpenPopupCount = openPopupCount; - - TQMouseEvent e( type, pos, globalPos, button, state ); - TQApplication::sendSpontaneousEvent( widget, &e ); - - if ( type == TQEvent::MouseButtonPress && button == RightButton && ( openPopupCount == oldOpenPopupCount ) ) { - TQContextMenuEvent e( TQContextMenuEvent::Mouse, pos, globalPos, state ); - TQApplication::sendSpontaneousEvent( widget, &e ); - } - } - return TRUE; -} - - -// -// Wheel event translation -// -bool TQETWidget::translateWheelEvent( int global_x, int global_y, int delta, int state, Orientation orient ) -{ - // send the event to the widget or its ancestors - { - TQWidget* popup = tqApp->activePopupWidget(); - if ( popup && topLevelWidget() != popup ) - popup->close(); - TQWheelEvent e( mapFromGlobal(TQPoint( global_x, global_y)), - TQPoint(global_x, global_y), delta, state, orient ); - if ( TQApplication::sendSpontaneousEvent( this, &e ) ) - return TRUE; - } - - // send the event to the widget that has the focus or its ancestors, if different - TQWidget *w = this; - if ( w != tqApp->focusWidget() && ( w = tqApp->focusWidget() ) ) { - TQWidget* popup = tqApp->activePopupWidget(); - if ( popup && w != popup ) - popup->hide(); - TQWheelEvent e( mapFromGlobal(TQPoint( global_x, global_y)), - TQPoint(global_x, global_y), delta, state, orient ); - if ( TQApplication::sendSpontaneousEvent( w, &e ) ) - return TRUE; - } - return FALSE; -} - - -// -// XInput Translation Event -// -#if defined (QT_TABLET_SUPPORT) -bool TQETWidget::translateXinputEvent( const XEvent *ev ) -{ -#if defined (Q_OS_IRIX) - // Wacom has put defines in their wacom.h file so it would be quite wise - // to use them, need to think of a decent way of not using - // it when it doesn't exist... - XDeviceState *s; - XInputClass *iClass; - XValuatorState *vs; - int j; -#endif - TQWidget *w = this; - TQPoint global, - curr; - static int pressure = 0; - static int xTilt = 0, - yTilt = 0; - int deviceType = TQTabletEvent::NoDevice; - TQPair tId; - XEvent xinputMotionEvent; - XEvent mouseMotionEvent; -#if defined (Q_OS_IRIX) - XDevice *dev; -#endif - const XDeviceMotionEvent *motion = 0; - XDeviceButtonEvent *button = 0; - TQEvent::Type t; - - if ( ev->type == xinput_motion ) { - motion = (const XDeviceMotionEvent*)ev; - for (;;) { - if (!XCheckTypedWindowEvent(x11Display(), winId(), MotionNotify, &mouseMotionEvent)) - break; - if (!XCheckTypedWindowEvent(x11Display(), winId(), xinput_motion, &xinputMotionEvent)) { - XPutBackEvent(x11Display(), &mouseMotionEvent); - break; - } - if (mouseMotionEvent.xmotion.time != motion->time) { - XPutBackEvent(x11Display(), &mouseMotionEvent); - XPutBackEvent(x11Display(), &xinputMotionEvent); - break; - } - motion = ((const XDeviceMotionEvent*)&xinputMotionEvent); - } - t = TQEvent::TabletMove; - curr = TQPoint( motion->x, motion->y ); - } else { - if ( ev->type == xinput_button_press ) { - t = TQEvent::TabletPress; - } else { - t = TQEvent::TabletRelease; - } - button = (XDeviceButtonEvent*)ev; -/* - tqDebug( "\n\nXInput Button Event" ); - tqDebug( "serial:\t%d", button->serial ); - tqDebug( "send_event:\t%d", button->send_event ); - tqDebug( "display:\t%p", button->display ); - tqDebug( "window:\t%d", button->window ); - tqDebug( "deviceID:\t%d", button->deviceid ); - tqDebug( "root:\t%d", button->root ); - tqDebug( "subwindot:\t%d", button->subwindow ); - tqDebug( "x:\t%d", button->x ); - tqDebug( "y:\t%d", button->y ); - tqDebug( "x_root:\t%d", button->x_root ); - tqDebug( "y_root:\t%d", button->y_root ); - tqDebug( "state:\t%d", button->state ); - tqDebug( "button:\t%d", button->button ); - tqDebug( "same_screen:\t%d", button->same_screen ); - tqDebug( "time:\t%d", button->time ); -*/ - curr = TQPoint( button->x, button->y ); - } -#if defined(Q_OS_IRIX) - // default... - dev = devStylus; -#else - if ( ev->type == xinput_motion ) { - if ( motion->deviceid == devStylus->device_id ) { - deviceType = TQTabletEvent::Stylus; - } else if ( motion->deviceid == devEraser->device_id ) { - deviceType = TQTabletEvent::Eraser; - } - } else { - if ( button->deviceid == devStylus->device_id ) { - deviceType = TQTabletEvent::Stylus; - } else if ( button->deviceid == devEraser->device_id ) { - deviceType = TQTabletEvent::Eraser; - } - } -#endif - - const int PRESSURE_LEVELS = 255; - // we got the maximum pressure at start time, since various tablets have - // varying levels of distinguishing pressure changes, let's standardize and - // scale everything to 256 different levels... - static int scaleFactor = -1; - if ( scaleFactor == -1 ) { - if ( max_pressure > PRESSURE_LEVELS ) - scaleFactor = max_pressure / PRESSURE_LEVELS; - else - scaleFactor = PRESSURE_LEVELS / max_pressure; - } -#if defined (Q_OS_IRIX) - s = XQueryDeviceState( appDpy, dev ); - if ( s == NULL ) - return FALSE; - iClass = s->data; - for ( j = 0; j < s->num_classes; j++ ) { - if ( iClass->c_class == ValuatorClass ) { - vs = (XValuatorState *)iClass; - // figure out what device we have, based on bitmasking... - if ( vs->valuators[WAC_TRANSDUCER_I] - & WAC_TRANSDUCER_PROX_MSK ) { - switch ( vs->valuators[WAC_TRANSDUCER_I] - & WAC_TRANSDUCER_MSK ) { - case WAC_PUCK_ID: - deviceType = TQTabletEvent::Puck; - break; - case WAC_STYLUS_ID: - deviceType = TQTabletEvent::Stylus; - break; - case WAC_ERASER_ID: - deviceType = TQTabletEvent::Eraser; - break; - } - // Get a Unique Id for the device, Wacom gives us this ability - tId.first = vs->valuators[WAC_TRANSDUCER_I] & WAC_TRANSDUCER_ID_MSK; - tId.second = vs->valuators[WAC_SERIAL_NUM_I]; - } else - deviceType = TQTabletEvent::NoDevice; - // apparently Wacom needs a cast for the +/- values to make sense - xTilt = short(vs->valuators[WAC_XTILT_I]); - yTilt = short(vs->valuators[WAC_YTILT_I]); - if ( max_pressure > PRESSURE_LEVELS ) - pressure = vs->valuators[WAC_PRESSURE_I] / scaleFactor; - else - pressure = vs->valuators[WAC_PRESSURE_I] * scaleFactor; - global = TQPoint( vs->valuators[WAC_XCOORD_I], - vs->valuators[WAC_YCOORD_I] ); - break; - } - iClass = (XInputClass*)((char*)iClass + iClass->length); - } - XFreeDeviceState( s ); -#else - if ( motion ) { - xTilt = short(motion->axis_data[3]); - yTilt = short(motion->axis_data[4]); - if ( max_pressure > PRESSURE_LEVELS ) - pressure = motion->axis_data[2] / scaleFactor; - else - pressure = motion->axis_data[2] * scaleFactor; - global = TQPoint( motion->axis_data[0], motion->axis_data[1] ); - } else { - xTilt = short(button->axis_data[3]); - yTilt = short(button->axis_data[4]); - if ( max_pressure > PRESSURE_LEVELS ) - pressure = button->axis_data[2] / scaleFactor; - else - pressure = button->axis_data[2] * scaleFactor; - global = TQPoint( button->axis_data[0], button->axis_data[1] ); - } - // The only way to get these Ids is to scan the XFree86 log, which I'm not going to do. - tId.first = tId.second = -1; -#endif - - TQTabletEvent e( t, curr, global, deviceType, pressure, xTilt, yTilt, tId ); - TQApplication::sendSpontaneousEvent( w, &e ); - return TRUE; -} -#endif - -bool TQETWidget::translatePropertyEvent(const XEvent *event) -{ - if (!isTopLevel()) return TRUE; - - Atom ret; - int format, e; - unsigned char *data = 0; - unsigned long nitems, after; - - if (event->xproperty.atom == qt_net_wm_frame_strut) { - topData()->fleft = topData()->fright = topData()->ftop = topData()->fbottom = 0; - fstrut_dirty = 1; - - if (event->xproperty.state == PropertyNewValue) { - e = XGetWindowProperty(appDpy, event->xproperty.window, qt_net_wm_frame_strut, - 0, 4, // struts are 4 longs - False, XA_CARDINAL, &ret, &format, &nitems, &after, &data); - - if (e == Success && ret == XA_CARDINAL && - format == 32 && nitems == 4) { - long *strut = (long *) data; - topData()->fleft = strut[0]; - topData()->fright = strut[1]; - topData()->ftop = strut[2]; - topData()->fbottom = strut[3]; - fstrut_dirty = 0; - } - } - } else if (event->xproperty.atom == qt_net_wm_state) { - bool max = FALSE; - bool full = FALSE; - - if (event->xproperty.state == PropertyNewValue) { - // using length of 1024 should be safe for all current and - // possible NET states... - e = XGetWindowProperty(appDpy, event->xproperty.window, qt_net_wm_state, 0, 1024, - False, XA_ATOM, &ret, &format, &nitems, &after, &data); - - if (e == Success && ret == XA_ATOM && format == 32 && nitems > 0) { - Atom *states = (Atom *) data; - - unsigned long i; - for (i = 0; i < nitems; i++) { - if (states[i] == qt_net_wm_state_max_v || states[i] == qt_net_wm_state_max_h) - max = TRUE; - else if (states[i] == qt_net_wm_state_fullscreen) - full = TRUE; - } - } - } - - bool send_event = FALSE; - - if (qt_net_supports(qt_net_wm_state_max_v) - && qt_net_supports(qt_net_wm_state_max_h)) { - if (max && !isMaximized()) { - setWState(WState_Maximized); - send_event = TRUE; - } else if (!max && isMaximized()) { - clearWState(WState_Maximized); - send_event = TRUE; - } - } - - if (qt_net_supports(qt_net_wm_state_fullscreen)) { - if (full && !isFullScreen()) { - setWState(WState_FullScreen); - send_event = TRUE; - } else if (!full && isFullScreen()) { - clearWState(WState_FullScreen); - send_event = TRUE; - } - } - - if (send_event) { - TQEvent e(TQEvent::WindowStateChange); - TQApplication::sendSpontaneousEvent(this, &e); - } - } else if (event->xproperty.atom == tqt_wm_state) { - // the widget frame strut should also be invalidated - topData()->fleft = topData()->fright = topData()->ftop = topData()->fbottom = 0; - fstrut_dirty = 1; - - if (event->xproperty.state == PropertyDelete) { - // the window manager has removed the WM State property, - // so it is now in the withdrawn state (ICCCM 4.1.3.1) and - // we are free to reuse this window - topData()->parentWinId = 0; - // map the window if we were waiting for a transition to - // withdrawn - if ( qt_deferred_map_contains( this ) ) { - qt_deferred_map_take( this ); - XMapWindow( appDpy, winId() ); - } - } else if (topData()->parentWinId != TQPaintDevice::x11AppRootWindow(x11Screen())) { - // the window manager has changed the WM State property... - // we are wanting to see if we are withdrawn so that we - // can reuse this window... we only do this check *IF* we - // haven't been reparented to root - (the parentWinId != - // TQPaintDevice::x11AppRootWindow(x11Screen())) check - // above - - e = XGetWindowProperty(appDpy, winId(), tqt_wm_state, 0, 2, False, tqt_wm_state, - &ret, &format, &nitems, &after, &data ); - - if (e == Success && ret == tqt_wm_state && format == 32 && nitems > 0) { - long *state = (long *) data; - switch (state[0]) { - case WithdrawnState: - // if we are in the withdrawn state, we are free - // to reuse this window provided we remove the - // WM_STATE property (ICCCM 4.1.3.1) - XDeleteProperty(appDpy, winId(), tqt_wm_state); - - // set the parent id to zero, so that show() will - // work again - topData()->parentWinId = 0; - // map the window if we were waiting for a - // transition to withdrawn - if ( qt_deferred_map_contains( this ) ) { - qt_deferred_map_take( this ); - XMapWindow( appDpy, winId() ); - } - break; - - case IconicState: - if (!isMinimized()) { - // window was minimized - setWState(WState_Minimized); - TQEvent e(TQEvent::WindowStateChange); - TQApplication::sendSpontaneousEvent(this, &e); - } - break; - - default: - if (isMinimized()) { - // window was un-minimized - clearWState(WState_Minimized); - TQEvent e(TQEvent::WindowStateChange); - TQApplication::sendSpontaneousEvent(this, &e); - } - break; - } - } - } - } - - if (data) - XFree(data); - - return TRUE; -} - -#ifndef XK_ISO_Left_Tab -#define XK_ISO_Left_Tab 0xFE20 -#endif - -// the next lines are taken from XFree > 4.0 (X11/XF86keysyms.h), defining some special -// multimedia keys. They are included here as not every system has them. -#define XF86XK_Standby 0x1008FF10 -#define XF86XK_AudioLowerVolume 0x1008FF11 -#define XF86XK_AudioMute 0x1008FF12 -#define XF86XK_AudioRaiseVolume 0x1008FF13 -#define XF86XK_AudioPlay 0x1008FF14 -#define XF86XK_AudioStop 0x1008FF15 -#define XF86XK_AudioPrev 0x1008FF16 -#define XF86XK_AudioNext 0x1008FF17 -#define XF86XK_HomePage 0x1008FF18 -#define XF86XK_Calculator 0x1008FF1D -#define XF86XK_Mail 0x1008FF19 -#define XF86XK_Start 0x1008FF1A -#define XF86XK_Search 0x1008FF1B -#define XF86XK_AudioRecord 0x1008FF1C -#define XF86XK_Back 0x1008FF26 -#define XF86XK_Forward 0x1008FF27 -#define XF86XK_Stop 0x1008FF28 -#define XF86XK_Refresh 0x1008FF29 -#define XF86XK_Favorites 0x1008FF30 -#define XF86XK_AudioPause 0x1008FF31 -#define XF86XK_AudioMedia 0x1008FF32 -#define XF86XK_MyComputer 0x1008FF33 -#define XF86XK_OpenURL 0x1008FF38 -#define XF86XK_Launch0 0x1008FF40 -#define XF86XK_Launch1 0x1008FF41 -#define XF86XK_Launch2 0x1008FF42 -#define XF86XK_Launch3 0x1008FF43 -#define XF86XK_Launch4 0x1008FF44 -#define XF86XK_Launch5 0x1008FF45 -#define XF86XK_Launch6 0x1008FF46 -#define XF86XK_Launch7 0x1008FF47 -#define XF86XK_Launch8 0x1008FF48 -#define XF86XK_Launch9 0x1008FF49 -#define XF86XK_LaunchA 0x1008FF4A -#define XF86XK_LaunchB 0x1008FF4B -#define XF86XK_LaunchC 0x1008FF4C -#define XF86XK_LaunchD 0x1008FF4D -#define XF86XK_LaunchE 0x1008FF4E -#define XF86XK_LaunchF 0x1008FF4F -#define XF86XK_MonBrightnessUp 0x1008FF02 /* Monitor/panel brightness */ -#define XF86XK_MonBrightnessDown 0x1008FF03 /* Monitor/panel brightness */ -#define XF86XK_KbdLightOnOff 0x1008FF04 /* Keyboards may be lit */ -#define XF86XK_KbdBrightnessUp 0x1008FF05 /* Keyboards may be lit */ -#define XF86XK_KbdBrightnessDown 0x1008FF06 /* Keyboards may be lit */ -// end of XF86keysyms.h - - - -static const KeySym KeyTbl[] = { // keyboard mapping table - XK_Escape, TQt::Key_Escape, // misc keys - XK_Tab, TQt::Key_Tab, - XK_ISO_Left_Tab, TQt::Key_Backtab, - XK_BackSpace, TQt::Key_Backspace, - XK_Return, TQt::Key_Return, - XK_Insert, TQt::Key_Insert, - XK_KP_Insert, TQt::Key_Insert, - XK_Delete, TQt::Key_Delete, - XK_KP_Delete, TQt::Key_Delete, - XK_Clear, TQt::Key_Delete, - XK_Pause, TQt::Key_Pause, - XK_Print, TQt::Key_Print, - XK_KP_Begin, TQt::Key_Clear, - 0x1005FF60, TQt::Key_SysReq, // hardcoded Sun SysReq - 0x1007ff00, TQt::Key_SysReq, // hardcoded X386 SysReq - XK_Home, TQt::Key_Home, // cursor movement - XK_End, TQt::Key_End, - XK_Left, TQt::Key_Left, - XK_Up, TQt::Key_Up, - XK_Right, TQt::Key_Right, - XK_Down, TQt::Key_Down, - XK_Prior, TQt::Key_Prior, - XK_Next, TQt::Key_Next, - XK_KP_Home, TQt::Key_Home, - XK_KP_End, TQt::Key_End, - XK_KP_Left, TQt::Key_Left, - XK_KP_Up, TQt::Key_Up, - XK_KP_Right, TQt::Key_Right, - XK_KP_Down, TQt::Key_Down, - XK_KP_Prior, TQt::Key_Prior, - XK_KP_Next, TQt::Key_Next, - XK_Shift_L, TQt::Key_Shift, // modifiers - XK_Shift_R, TQt::Key_Shift, - XK_Shift_Lock, TQt::Key_Shift, - XK_Control_L, TQt::Key_Control, - XK_Control_R, TQt::Key_Control, - XK_Meta_L, TQt::Key_Meta, - XK_Meta_R, TQt::Key_Meta, - XK_Alt_L, TQt::Key_Alt, - XK_Alt_R, TQt::Key_Alt, - XK_Caps_Lock, TQt::Key_CapsLock, - XK_Num_Lock, TQt::Key_NumLock, - XK_Scroll_Lock, TQt::Key_ScrollLock, - XK_KP_Space, TQt::Key_Space, // numeric keypad - XK_KP_Tab, TQt::Key_Tab, - XK_KP_Enter, TQt::Key_Enter, - XK_KP_Equal, TQt::Key_Equal, - XK_KP_Multiply, TQt::Key_Asterisk, - XK_KP_Add, TQt::Key_Plus, - XK_KP_Separator, TQt::Key_Comma, - XK_KP_Subtract, TQt::Key_Minus, - XK_KP_Decimal, TQt::Key_Period, - XK_KP_Divide, TQt::Key_Slash, - XK_Super_L, TQt::Key_Super_L, - XK_Super_R, TQt::Key_Super_R, - XK_Menu, TQt::Key_Menu, - XK_Hyper_L, TQt::Key_Hyper_L, - XK_Hyper_R, TQt::Key_Hyper_R, - XK_Help, TQt::Key_Help, - 0x1000FF74, TQt::Key_BackTab, // hardcoded HP backtab - 0x1005FF10, TQt::Key_F11, // hardcoded Sun F36 (labeled F11) - 0x1005FF11, TQt::Key_F12, // hardcoded Sun F37 (labeled F12) - - // International input method support keys - - // International & multi-key character composition - XK_Multi_key, TQt::Key_Multi_key, - XK_Codeinput, TQt::Key_Codeinput, - XK_SingleCandidate, TQt::Key_SingleCandidate, - XK_MultipleCandidate, TQt::Key_MultipleCandidate, - XK_PreviousCandidate, TQt::Key_PreviousCandidate, - - // Misc Functions - XK_Mode_switch, TQt::Key_Mode_switch, - //XK_script_switch, TQt::Key_script_switch, - XK_script_switch, TQt::Key_Mode_switch, - - // Japanese keyboard support - XK_Kanji, TQt::Key_Kanji, - XK_Muhenkan, TQt::Key_Muhenkan, - //XK_Henkan_Mode, TQt::Key_Henkan_Mode, - XK_Henkan_Mode, TQt::Key_Henkan, - XK_Henkan, TQt::Key_Henkan, - XK_Romaji, TQt::Key_Romaji, - XK_Hiragana, TQt::Key_Hiragana, - XK_Katakana, TQt::Key_Katakana, - XK_Hiragana_Katakana, TQt::Key_Hiragana_Katakana, - XK_Zenkaku, TQt::Key_Zenkaku, - XK_Hankaku, TQt::Key_Hankaku, - XK_Zenkaku_Hankaku, TQt::Key_Zenkaku_Hankaku, - XK_Touroku, TQt::Key_Touroku, - XK_Massyo, TQt::Key_Massyo, - XK_Kana_Lock, TQt::Key_Kana_Lock, - XK_Kana_Shift, TQt::Key_Kana_Shift, - XK_Eisu_Shift, TQt::Key_Eisu_Shift, - XK_Eisu_toggle, TQt::Key_Eisu_toggle, - //XK_Kanji_Bangou, TQt::Key_Kanji_Bangou, - //XK_Zen_Koho, TQt::Key_Zen_Koho, - //XK_Mae_Koho, TQt::Key_Mae_Koho, - XK_Kanji_Bangou, TQt::Key_Codeinput, - XK_Zen_Koho, TQt::Key_MultipleCandidate, - XK_Mae_Koho, TQt::Key_PreviousCandidate, - -#ifdef XK_KOREAN - // Korean keyboard support - XK_Hangul, TQt::Key_Hangul, - XK_Hangul_Start, TQt::Key_Hangul_Start, - XK_Hangul_End, TQt::Key_Hangul_End, - XK_Hangul_Hanja, TQt::Key_Hangul_Hanja, - XK_Hangul_Jamo, TQt::Key_Hangul_Jamo, - XK_Hangul_Romaja, TQt::Key_Hangul_Romaja, - //XK_Hangul_Codeinput, TQt::Key_Hangul_Codeinput, - XK_Hangul_Codeinput, TQt::Key_Codeinput, - XK_Hangul_Jeonja, TQt::Key_Hangul_Jeonja, - XK_Hangul_Banja, TQt::Key_Hangul_Banja, - XK_Hangul_PreHanja, TQt::Key_Hangul_PreHanja, - XK_Hangul_PostHanja, TQt::Key_Hangul_PostHanja, - //XK_Hangul_SingleCandidate, TQt::Key_Hangul_SingleCandidate, - //XK_Hangul_MultipleCandidate, TQt::Key_Hangul_MultipleCandidate, - //XK_Hangul_PreviousCandidate, TQt::Key_Hangul_PreviousCandidate, - XK_Hangul_SingleCandidate, TQt::Key_SingleCandidate, - XK_Hangul_MultipleCandidate, TQt::Key_MultipleCandidate, - XK_Hangul_PreviousCandidate, TQt::Key_PreviousCandidate, - XK_Hangul_Special, TQt::Key_Hangul_Special, - //XK_Hangul_switch, TQt::Key_Hangul_switch, - XK_Hangul_switch, TQt::Key_Mode_switch, -#endif // XK_KOREAN - - // dead keys - XK_dead_grave, TQt::Key_Dead_Grave, - XK_dead_acute, TQt::Key_Dead_Acute, - XK_dead_circumflex, TQt::Key_Dead_Circumflex, - XK_dead_tilde, TQt::Key_Dead_Tilde, - XK_dead_macron, TQt::Key_Dead_Macron, - XK_dead_breve, TQt::Key_Dead_Breve, - XK_dead_abovedot, TQt::Key_Dead_Abovedot, - XK_dead_diaeresis, TQt::Key_Dead_Diaeresis, - XK_dead_abovering, TQt::Key_Dead_Abovering, - XK_dead_doubleacute, TQt::Key_Dead_Doubleacute, - XK_dead_caron, TQt::Key_Dead_Caron, - XK_dead_cedilla, TQt::Key_Dead_Cedilla, - XK_dead_ogonek, TQt::Key_Dead_Ogonek, - XK_dead_iota, TQt::Key_Dead_Iota, - XK_dead_voiced_sound, TQt::Key_Dead_Voiced_Sound, - XK_dead_semivoiced_sound, TQt::Key_Dead_Semivoiced_Sound, - XK_dead_belowdot, TQt::Key_Dead_Belowdot, - XK_dead_hook, TQt::Key_Dead_Hook, - XK_dead_horn, TQt::Key_Dead_Horn, - - // Special multimedia keys - // currently only tested with MS internet keyboard - - // browsing keys - XF86XK_Back, TQt::Key_Back, - XF86XK_Forward, TQt::Key_Forward, - XF86XK_Stop, TQt::Key_Stop, - XF86XK_Refresh, TQt::Key_Refresh, - XF86XK_Favorites, TQt::Key_Favorites, - XF86XK_AudioMedia, TQt::Key_LaunchMedia, - XF86XK_OpenURL, TQt::Key_OpenUrl, - XF86XK_HomePage, TQt::Key_HomePage, - XF86XK_Search, TQt::Key_Search, - - // media keys - XF86XK_AudioLowerVolume, TQt::Key_VolumeDown, - XF86XK_AudioMute, TQt::Key_VolumeMute, - XF86XK_AudioRaiseVolume, TQt::Key_VolumeUp, - XF86XK_AudioPlay, TQt::Key_MediaPlay, - XF86XK_AudioStop, TQt::Key_MediaStop, - XF86XK_AudioPrev, TQt::Key_MediaPrev, - XF86XK_AudioNext, TQt::Key_MediaNext, - XF86XK_AudioRecord, TQt::Key_MediaRecord, - - // launch keys - XF86XK_Mail, TQt::Key_LaunchMail, - XF86XK_MyComputer, TQt::Key_Launch0, - XF86XK_Calculator, TQt::Key_Launch1, - XF86XK_Standby, TQt::Key_Standby, - - XF86XK_Launch0, TQt::Key_Launch2, - XF86XK_Launch1, TQt::Key_Launch3, - XF86XK_Launch2, TQt::Key_Launch4, - XF86XK_Launch3, TQt::Key_Launch5, - XF86XK_Launch4, TQt::Key_Launch6, - XF86XK_Launch5, TQt::Key_Launch7, - XF86XK_Launch6, TQt::Key_Launch8, - XF86XK_Launch7, TQt::Key_Launch9, - XF86XK_Launch8, TQt::Key_LaunchA, - XF86XK_Launch9, TQt::Key_LaunchB, - XF86XK_LaunchA, TQt::Key_LaunchC, - XF86XK_LaunchB, TQt::Key_LaunchD, - XF86XK_LaunchC, TQt::Key_LaunchE, - XF86XK_LaunchD, TQt::Key_LaunchF, - XF86XK_MonBrightnessUp, TQt::Key_MonBrightnessUp, - XF86XK_MonBrightnessDown, TQt::Key_MonBrightnessDown, - XF86XK_KbdLightOnOff, TQt::Key_KeyboardLightOnOff, - XF86XK_KbdBrightnessUp, TQt::Key_KeyboardBrightnessUp, - XF86XK_KbdBrightnessDown, TQt::Key_KeyboardBrightnessDown, - - 0, 0 -}; - - -static TQIntDict *keyDict = 0; -static TQIntDict *textDict = 0; - -static void deleteKeyDicts() -{ - if ( keyDict ) - delete keyDict; - keyDict = 0; - if ( textDict ) - delete textDict; - textDict = 0; -} - -#if !defined(TQT_NO_XIM) -static const unsigned short katakanaKeysymsToUnicode[] = { - 0x0000, 0x3002, 0x300C, 0x300D, 0x3001, 0x30FB, 0x30F2, 0x30A1, - 0x30A3, 0x30A5, 0x30A7, 0x30A9, 0x30E3, 0x30E5, 0x30E7, 0x30C3, - 0x30FC, 0x30A2, 0x30A4, 0x30A6, 0x30A8, 0x30AA, 0x30AB, 0x30AD, - 0x30AF, 0x30B1, 0x30B3, 0x30B5, 0x30B7, 0x30B9, 0x30BB, 0x30BD, - 0x30BF, 0x30C1, 0x30C4, 0x30C6, 0x30C8, 0x30CA, 0x30CB, 0x30CC, - 0x30CD, 0x30CE, 0x30CF, 0x30D2, 0x30D5, 0x30D8, 0x30DB, 0x30DE, - 0x30DF, 0x30E0, 0x30E1, 0x30E2, 0x30E4, 0x30E6, 0x30E8, 0x30E9, - 0x30EA, 0x30EB, 0x30EC, 0x30ED, 0x30EF, 0x30F3, 0x309B, 0x309C -}; - -static const unsigned short cyrillicKeysymsToUnicode[] = { - 0x0000, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457, - 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x0000, 0x045e, 0x045f, - 0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407, - 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x0000, 0x040e, 0x040f, - 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, - 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, - 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, - 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, - 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, - 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, - 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, - 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a -}; - -static const unsigned short greekKeysymsToUnicode[] = { - 0x0000, 0x0386, 0x0388, 0x0389, 0x038a, 0x03aa, 0x0000, 0x038c, - 0x038e, 0x03ab, 0x0000, 0x038f, 0x0000, 0x0000, 0x0385, 0x2015, - 0x0000, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03ca, 0x0390, 0x03cc, - 0x03cd, 0x03cb, 0x03b0, 0x03ce, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, - 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, - 0x03a0, 0x03a1, 0x03a3, 0x0000, 0x03a4, 0x03a5, 0x03a6, 0x03a7, - 0x03a8, 0x03a9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, - 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, - 0x03c0, 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x03c5, 0x03c6, 0x03c7, - 0x03c8, 0x03c9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 -}; - -static const unsigned short technicalKeysymsToUnicode[] = { - 0x0000, 0x23B7, 0x250C, 0x2500, 0x2320, 0x2321, 0x2502, 0x23A1, - 0x23A3, 0x23A4, 0x23A6, 0x239B, 0x239D, 0x239E, 0x23A0, 0x23A8, - 0x23AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x2264, 0x2260, 0x2265, 0x222B, - 0x2234, 0x221D, 0x221E, 0x0000, 0x0000, 0x2207, 0x0000, 0x0000, - 0x223C, 0x2243, 0x0000, 0x0000, 0x0000, 0x21D4, 0x21D2, 0x2261, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x221A, 0x0000, - 0x0000, 0x0000, 0x2282, 0x2283, 0x2229, 0x222A, 0x2227, 0x2228, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2202, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0192, 0x0000, - 0x0000, 0x0000, 0x0000, 0x2190, 0x2191, 0x2192, 0x2193, 0x0000 -}; - -static const unsigned short specialKeysymsToUnicode[] = { - 0x25C6, 0x2592, 0x2409, 0x240C, 0x240D, 0x240A, 0x0000, 0x0000, - 0x2424, 0x240B, 0x2518, 0x2510, 0x250C, 0x2514, 0x253C, 0x23BA, - 0x23BB, 0x2500, 0x23BC, 0x23BD, 0x251C, 0x2524, 0x2534, 0x252C, - 0x2502, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 -}; - -static const unsigned short publishingKeysymsToUnicode[] = { - 0x0000, 0x2003, 0x2002, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009, - 0x200a, 0x2014, 0x2013, 0x0000, 0x0000, 0x0000, 0x2026, 0x2025, - 0x2153, 0x2154, 0x2155, 0x2156, 0x2157, 0x2158, 0x2159, 0x215a, - 0x2105, 0x0000, 0x0000, 0x2012, 0x2329, 0x0000, 0x232a, 0x0000, - 0x0000, 0x0000, 0x0000, 0x215b, 0x215c, 0x215d, 0x215e, 0x0000, - 0x0000, 0x2122, 0x2613, 0x0000, 0x25c1, 0x25b7, 0x25cb, 0x25af, - 0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x0000, 0x2032, 0x2033, - 0x0000, 0x271d, 0x0000, 0x25ac, 0x25c0, 0x25b6, 0x25cf, 0x25ae, - 0x25e6, 0x25ab, 0x25ad, 0x25b3, 0x25bd, 0x2606, 0x2022, 0x25aa, - 0x25b2, 0x25bc, 0x261c, 0x261e, 0x2663, 0x2666, 0x2665, 0x0000, - 0x2720, 0x2020, 0x2021, 0x2713, 0x2717, 0x266f, 0x266d, 0x2642, - 0x2640, 0x260e, 0x2315, 0x2117, 0x2038, 0x201a, 0x201e, 0x0000 -}; - -static const unsigned short aplKeysymsToUnicode[] = { - 0x0000, 0x0000, 0x0000, 0x003c, 0x0000, 0x0000, 0x003e, 0x0000, - 0x2228, 0x2227, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00af, 0x0000, 0x22a5, 0x2229, 0x230a, 0x0000, 0x005f, 0x0000, - 0x0000, 0x0000, 0x2218, 0x0000, 0x2395, 0x0000, 0x22a4, 0x25cb, - 0x0000, 0x0000, 0x0000, 0x2308, 0x0000, 0x0000, 0x222a, 0x0000, - 0x2283, 0x0000, 0x2282, 0x0000, 0x22a2, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x22a3, 0x0000, 0x0000, 0x0000 -}; - -static const unsigned short koreanKeysymsToUnicode[] = { - 0x0000, 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, 0x3137, - 0x3138, 0x3139, 0x313a, 0x313b, 0x313c, 0x313d, 0x313e, 0x313f, - 0x3140, 0x3141, 0x3142, 0x3143, 0x3144, 0x3145, 0x3146, 0x3147, - 0x3148, 0x3149, 0x314a, 0x314b, 0x314c, 0x314d, 0x314e, 0x314f, - 0x3150, 0x3151, 0x3152, 0x3153, 0x3154, 0x3155, 0x3156, 0x3157, - 0x3158, 0x3159, 0x315a, 0x315b, 0x315c, 0x315d, 0x315e, 0x315f, - 0x3160, 0x3161, 0x3162, 0x3163, 0x11a8, 0x11a9, 0x11aa, 0x11ab, - 0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, 0x11b3, - 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, 0x11bb, - 0x11bc, 0x11bd, 0x11be, 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x316d, - 0x3171, 0x3178, 0x317f, 0x3181, 0x3184, 0x3186, 0x318d, 0x318e, - 0x11eb, 0x11f0, 0x11f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x20a9 -}; - - -static TQChar keysymToUnicode(unsigned char byte3, unsigned char byte4) -{ - if ( byte3 == 0x04 ) { - // katakana - if ( byte4 > 0xa0 && byte4 < 0xe0 ) - return TQChar( katakanaKeysymsToUnicode[byte4 - 0xa0] ); - else if ( byte4 == 0x7e ) - return TQChar( 0x203e ); // Overline - } else if ( byte3 == 0x06 ) { - // russian, use lookup table - if ( byte4 > 0xa0 ) - return TQChar( cyrillicKeysymsToUnicode[byte4 - 0xa0] ); - } else if ( byte3 == 0x07 ) { - // greek - if ( byte4 > 0xa0 ) - return TQChar( greekKeysymsToUnicode[byte4 - 0xa0] ); - } else if ( byte3 == 0x08 ) { - // technical - if ( byte4 > 0xa0 ) - return TQChar( technicalKeysymsToUnicode[byte4 - 0xa0] ); - } else if ( byte3 == 0x09 ) { - // special - if ( byte4 >= 0xe0 ) - return TQChar( specialKeysymsToUnicode[byte4 - 0xe0] ); - } else if ( byte3 == 0x0a ) { - // publishing - if ( byte4 > 0xa0 ) - return TQChar( publishingKeysymsToUnicode[byte4 - 0xa0] ); - } else if ( byte3 == 0x0b ) { - // APL - if ( byte4 > 0xa0 ) - return TQChar( aplKeysymsToUnicode[byte4 - 0xa0] ); - } else if ( byte3 == 0x0e ) { - // Korean - if ( byte4 > 0xa0 ) - return TQChar( koreanKeysymsToUnicode[byte4 - 0xa0] ); - } - return TQChar(0x0); -} -#endif - - -bool TQETWidget::translateKeyEventInternal( const XEvent *event, int& count, - TQString& text, - int& state, - char& ascii, int& code, TQEvent::Type &type, bool willRepeat, bool statefulTranslation ) -{ - TQTextCodec *mapper = qt_input_mapper; - // some XmbLookupString implementations don't return buffer overflow correctly, - // so we increase the input buffer to allow for long strings... - // 256 chars * 2 bytes + 1 null-term == 513 bytes - TQCString chars(513); - TQChar converted; - KeySym key = 0; - - if ( !keyDict ) { - keyDict = new TQIntDict( 13 ); - keyDict->setAutoDelete( FALSE ); - textDict = new TQIntDict( 13 ); - textDict->setAutoDelete( FALSE ); - tqAddPostRoutine( deleteKeyDicts ); - } - - XKeyEvent xkeyevent = event->xkey; - - // save the modifier state, we will use the keystate uint later by passing - // it to qt_x11_translateButtonState - uint keystate = event->xkey.state; - // remove the modifiers where mode_switch exists... HPUX machines seem - // to have alt *AND* mode_switch both in Mod1Mask, which causes - // XLookupString to return things like '�' (aring) for ALT-A. This - // completely breaks modifiers. If we remove the modifier for Mode_switch, - // then things work correctly... - xkeyevent.state &= ~qt_mode_switch_remove_mask; - - type = (event->type == XKeyPress) - ? TQEvent::KeyPress : TQEvent::KeyRelease; -#if defined(TQT_NO_XIM) - - count = XLookupString( &xkeyevent, chars.data(), chars.size(), &key, 0 ); - - if ( count == 1 ) - ascii = chars[0]; - -#else - // Implementation for X11R5 and newer, using XIM - - int keycode = event->xkey.keycode; - - if ( type == TQEvent::KeyPress ) { - bool mb=FALSE; - // commit string handling is done by - // TQXIMInputContext::x11FilterEvent() and are passed to - // widgets via TQIMEvent regardless of XIM style, so the - // following code is commented out. -#if 0 - if ( qt_xim ) { - TQTLWExtra* xd = tlw->topData(); - TQInputContext *qic = (TQInputContext *) xd->xic; - if ( qic ) { - mb=TRUE; - count = qic->lookupString(&xkeyevent, chars, &key, &status); - } - } -#endif - if ( !mb ) { - count = XLookupString( &xkeyevent, - chars.data(), chars.size(), &key, 0 ); - } - if ( count && !keycode ) { - keycode = qt_ximComposingKeycode; - qt_ximComposingKeycode = 0; - } - if ( key ) - keyDict->replace( keycode, (void*)key ); - // all keysyms smaller than that are actally keys that can be mapped - // to unicode chars - if ( count == 0 && key < 0xff00 ) { - unsigned char byte3 = (unsigned char )(key >> 8); - int mib = -1; - switch( byte3 ) { - case 0: // Latin 1 - case 1: // Latin 2 - case 2: //latin 3 - case 3: // latin4 - mib = byte3 + 4; break; - case 5: // arabic - mib = 82; break; - case 12: // Hebrew - mib = 85; break; - case 13: // Thai - mib = 2259; break; - case 4: // kana - case 6: // cyrillic - case 7: // greek - case 8: // technical, no mapping here at the moment - case 9: // Special - case 10: // Publishing - case 11: // APL - case 14: // Korean, no mapping - mib = -1; // manual conversion - mapper = 0; - converted = keysymToUnicode( byte3, key & 0xff ); - case 0x20: - // currency symbols - if ( key >= 0x20a0 && key <= 0x20ac ) { - mib = -1; // manual conversion - mapper = 0; - converted = (uint)key; - } - break; - default: - break; - } - if ( mib != -1 ) { - mapper = TQTextCodec::codecForMib( mib ); - chars[0] = (unsigned char) (key & 0xff); // get only the fourth bit for conversion later - count++; - } - } else if ( key >= 0x1000000 && key <= 0x100ffff ) { - converted = (ushort) (key - 0x1000000); - mapper = 0; - } - if ( count < (int)chars.size()-1 ) - chars[count] = '\0'; - if ( count == 1 ) { - ascii = chars[0]; - // +256 so we can store all eight-bit codes, including ascii 0, - // and independent of whether char is signed or not. - textDict->replace( keycode, (void*)(long)(256+ascii) ); - } - } else { - key = (int)(long)keyDict->find( keycode ); - if ( key ) - if( !willRepeat && statefulTranslation ) // Take out key of dictionary only if this call. - keyDict->take( keycode ); - long s = (long)textDict->find( keycode ); - if ( s ) { - if( statefulTranslation ) - textDict->take( keycode ); - ascii = (char)(s-256); - } - } -#endif // !TQT_NO_XIM - - state = qt_x11_translateButtonState( keystate ); - - static int directionKeyEvent = 0; - static unsigned int lastWinId = 0; - if ( qt_use_rtl_extensions && type == TQEvent::KeyRelease && statefulTranslation ) { - if (directionKeyEvent == Key_Direction_R || directionKeyEvent == Key_Direction_L ) { - type = TQEvent::KeyPress; - code = directionKeyEvent; - chars[0] = 0; - directionKeyEvent = 0; - lastWinId = 0; - return TRUE; - } else { - directionKeyEvent = 0; - lastWinId = 0; - } - } - - // Watch for keypresses and if its a key belonging to the Ctrl-Shift - // direction-changing accel, remember it. - // We keep track of those keys instead of using the event's state - // (to figure out whether the Ctrl modifier is held while Shift is pressed, - // or Shift is held while Ctrl is pressed) since the 'state' doesn't tell - // us whether the modifier held is Left or Right. - if ( qt_use_rtl_extensions && type == TQEvent::KeyPress && statefulTranslation ) { - if (key == XK_Control_L || key == XK_Control_R || key == XK_Shift_L || key == XK_Shift_R) { - if (!directionKeyEvent) { - directionKeyEvent = key; - // This code exists in order to check that - // the event is occurred in the same widget. - lastWinId = winId(); - } - } else { - // this can no longer be a direction-changing accel. - // if any other key was pressed. - directionKeyEvent = Key_Space; - } - } - - // Commentary in X11/keysymdef says that X codes match ASCII, so it - // is safe to use the locale functions to process X codes in ISO8859-1. - // - // This is mainly for compatibility - applications should not use the - // TQt keycodes between 128 and 255, but should rather use the - // TQKeyEvent::text(). - // - if ( key < 128 || (key < 256 && (!qt_input_mapper || qt_input_mapper->mibEnum()==4)) ) { - code = isprint((int)key) ? toupper((int)key) : 0; // upper-case key, if known - } else if ( key >= XK_F1 && key <= XK_F35 ) { - code = Key_F1 + ((int)key - XK_F1); // function keys - } else if ( key >= XK_KP_0 && key <= XK_KP_9) { - code = Key_0 + ((int)key - XK_KP_0); // numeric keypad keys - state |= Keypad; - } else { - int i = 0; // any other keys - while ( KeyTbl[i] ) { - if ( key == KeyTbl[i] ) { - code = (int)KeyTbl[i+1]; - break; - } - i += 2; - } - switch ( key ) { - case XK_KP_Insert: - case XK_KP_Delete: - case XK_KP_Home: - case XK_KP_End: - case XK_KP_Left: - case XK_KP_Up: - case XK_KP_Right: - case XK_KP_Down: - case XK_KP_Prior: - case XK_KP_Next: - case XK_KP_Space: - case XK_KP_Tab: - case XK_KP_Enter: - case XK_KP_Equal: - case XK_KP_Multiply: - case XK_KP_Add: - case XK_KP_Separator: - case XK_KP_Subtract: - case XK_KP_Decimal: - case XK_KP_Divide: - state |= Keypad; - break; - default: - break; - } - - if ( code == Key_Tab && - (state & ShiftButton) == ShiftButton ) { - // map shift+tab to shift+backtab, TQAccel knows about it - // and will handle it. - code = Key_Backtab; - chars[0] = 0; - } - - if ( qt_use_rtl_extensions && type == TQEvent::KeyPress && statefulTranslation ) { - if ( directionKeyEvent && lastWinId == winId() ) { - if ( ( key == XK_Shift_L && directionKeyEvent == XK_Control_L ) || - ( key == XK_Control_L && directionKeyEvent == XK_Shift_L ) ) { - directionKeyEvent = Key_Direction_L; - } else if ( ( key == XK_Shift_R && directionKeyEvent == XK_Control_R ) || - ( key == XK_Control_R && directionKeyEvent == XK_Shift_R ) ) { - directionKeyEvent = Key_Direction_R; - } - } - else if ( directionKeyEvent == Key_Direction_L || directionKeyEvent == Key_Direction_R ) { - directionKeyEvent = Key_Space; // invalid - } - } - } - -#if 0 -#ifndef Q_EE - static int c = 0; - extern void qt_dialog_default_key(); -#define Q_EE(x) c = (c == x || (!c && x == 0x1000) )? x+1 : 0 - if ( tlw && state == '0' ) { - switch ( code ) { - case 0x4f: Q_EE(Key_Backtab); break; - case 0x52: Q_EE(Key_Tab); break; - case 0x54: Q_EE(Key_Escape); break; - case 0x4c: - if (c == Key_Return ) - qt_dialog_default_key(); - else - Q_EE(Key_Backspace); - break; - } - } -#undef Q_EE -#endif -#endif - - // convert chars (8bit) to text (unicode). - if ( mapper ) - text = mapper->toUnicode(chars,count); - else if ( !mapper && converted.unicode() != 0x0 ) - text = converted; - else - text = chars; - return TRUE; -} - - -struct qt_auto_repeat_data -{ - // match the window and keycode with timestamp delta of 10ms - Window window; - KeyCode keycode; - Time timestamp; - - // queue scanner state - bool release; - bool error; -}; - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -static Bool qt_keypress_scanner(Display *, XEvent *event, XPointer arg) -{ - if (event->type != XKeyPress && event->type != XKeyRelease) - return FALSE; - - qt_auto_repeat_data *d = (qt_auto_repeat_data *) arg; - if (d->error || - event->xkey.window != d->window || - event->xkey.keycode != d->keycode) { - d->error = TRUE; - return FALSE; - } - - if (event->type == XKeyPress) { - d->error = (! d->release || event->xkey.time - d->timestamp > 10); - return (! d->error); - } - - // must be XKeyRelease event - if (d->release) { - // found a second release - d->error = TRUE; - return FALSE; - } - - // found a single release - d->release = TRUE; - d->timestamp = event->xkey.time; - - return FALSE; -} - -static Bool qt_keyrelease_scanner(Display *, XEvent *event, XPointer arg) -{ - const qt_auto_repeat_data *d = (const qt_auto_repeat_data *) arg; - return (event->type == XKeyRelease && - event->xkey.window == d->window && - event->xkey.keycode == d->keycode); -} - -#if defined(Q_C_CALLBACKS) -} -#endif - -bool TQETWidget::translateKeyEvent( const XEvent *event, bool grab ) -{ - int code = -1; - int count = 0; - int state; - char ascii = 0; - - if ( sm_blockUserInput ) // block user interaction during session management - return TRUE; - - Display *dpy = x11Display(); - - if ( !isEnabled() ) - return TRUE; - - TQEvent::Type type; - bool autor = FALSE; - TQString text; - - translateKeyEventInternal( event, count, text, state, ascii, code, type, - qt_mode_switch_remove_mask != 0 ); - - static uint curr_autorep = 0; - // was this the last auto-repeater? - qt_auto_repeat_data auto_repeat_data; - auto_repeat_data.window = event->xkey.window; - auto_repeat_data.keycode = event->xkey.keycode; - auto_repeat_data.timestamp = event->xkey.time; - - if ( event->type == XKeyPress ) { - if ( curr_autorep == event->xkey.keycode ) { - autor = TRUE; - curr_autorep = 0; - } - } else { - // look ahead for auto-repeat - XEvent nextpress; - - auto_repeat_data.release = TRUE; - auto_repeat_data.error = FALSE; - if (XCheckIfEvent(dpy, &nextpress, &qt_keypress_scanner, - (XPointer) &auto_repeat_data)) { - autor = TRUE; - - // Put it back... we COULD send the event now and not need - // the static curr_autorep variable. - XPutBackEvent(dpy,&nextpress); - } - curr_autorep = autor ? event->xkey.keycode : 0; - } - - // process accelerators before doing key compression - if ( type == TQEvent::KeyPress && !grab ) { - // send accel events if the keyboard is not grabbed - TQKeyEvent a( type, code, ascii, state, text, autor, - TQMAX( TQMAX(count,1), int(text.length())) ); - if ( tqt_tryAccelEvent( this, &a ) ) - return TRUE; - } - - long save = 0; - if ( qt_mode_switch_remove_mask != 0 ) { - save = qt_mode_switch_remove_mask; - qt_mode_switch_remove_mask = 0; - - // translate the key event again, but this time apply any Mode_switch - // modifiers - translateKeyEventInternal( event, count, text, state, ascii, code, type ); - } - -#ifndef TQT_NO_IM - TQInputContext *qic = getInputContext(); -#endif - - // compress keys - if ( !text.isEmpty() && testWState(WState_CompressKeys) && -#ifndef TQT_NO_IM - // Ordinary input methods require discrete key events to work - // properly, so key compression has to be disabled when input - // context exists. - // - // And further consideration, some complex input method - // require all key press/release events discretely even if - // the input method awares of key compression and compressed - // keys are ordinary alphabets. For example, the uim project - // is planning to implement "combinational shift" feature for - // a Japanese input method, uim-skk. It will work as follows. - // - // 1. press "r" - // 2. press "u" - // 3. release both "r" and "u" in arbitrary order - // 4. above key sequence generates "Ru" - // - // Of course further consideration about other participants - // such as key repeat mechanism is required to implement such - // feature. - ! qic && -#endif // TQT_NO_IM - // do not compress keys if the key event we just got above matches - // one of the key ranges used to compute stopCompression - ! ( ( code >= Key_Escape && code <= Key_SysReq ) || - ( code >= Key_Home && code <= Key_Next ) || - ( code >= Key_Super_L && code <= Key_Direction_R ) || - ( ( code == 0 ) && ( ascii == '\n' ) ) ) ) { - // the widget wants key compression so it gets it - int codeIntern = -1; - int countIntern = 0; - int stateIntern; - char asciiIntern = 0; - XEvent evRelease; - XEvent evPress; - - // sync the event queue, this makes key compress work better - XSync( dpy, FALSE ); - - for (;;) { - TQString textIntern; - if ( !XCheckTypedWindowEvent(dpy,event->xkey.window, - XKeyRelease,&evRelease) ) - break; - if ( !XCheckTypedWindowEvent(dpy,event->xkey.window, - XKeyPress,&evPress) ) { - XPutBackEvent(dpy, &evRelease); - break; - } - TQEvent::Type t; - translateKeyEventInternal( &evPress, countIntern, textIntern, - stateIntern, asciiIntern, codeIntern, t ); - // use stopCompression to stop key compression for the following - // key event ranges: - bool stopCompression = - // 1) misc keys - ( codeIntern >= Key_Escape && codeIntern <= Key_SysReq ) || - // 2) cursor movement - ( codeIntern >= Key_Home && codeIntern <= Key_Next ) || - // 3) extra keys - ( codeIntern >= Key_Super_L && codeIntern <= Key_Direction_R ) || - // 4) something that a) doesn't translate to text or b) translates - // to newline text - ((codeIntern == 0) && (asciiIntern == '\n')); - if (stateIntern == state && !textIntern.isEmpty() && !stopCompression) { - text += textIntern; - count += countIntern; - } else { - XPutBackEvent(dpy, &evPress); - XPutBackEvent(dpy, &evRelease); - break; - } - } - } - - if ( save != 0 ) - qt_mode_switch_remove_mask = save; - - // autorepeat compression makes sense for all widgets (Windows - // does it automatically .... ) - if ( event->type == XKeyPress && text.length() <= 1 -#ifndef TQT_NO_IM - // input methods need discrete key events - && ! qic -#endif// TQT_NO_IM - ) { - XEvent dummy; - - for (;;) { - auto_repeat_data.release = FALSE; - auto_repeat_data.error = FALSE; - if (! XCheckIfEvent(dpy, &dummy, &qt_keypress_scanner, - (XPointer) &auto_repeat_data)) - break; - if (! XCheckIfEvent(dpy, &dummy, &qt_keyrelease_scanner, - (XPointer) &auto_repeat_data)) - break; - - count++; - if (!text.isEmpty()) - text += text[0]; - } - } - - if (code == 0 && ascii == '\n') { - code = Key_Return; - ascii = '\r'; - text = "\r"; - } - - // try the menukey first - if ( type == TQEvent::KeyPress && code == TQt::Key_Menu ) { - TQContextMenuEvent e( TQContextMenuEvent::Keyboard, TQPoint( 5, 5 ), mapToGlobal( TQPoint( 5, 5 ) ), 0 ); - TQApplication::sendSpontaneousEvent( this, &e ); - if( e.isAccepted() ) - return TRUE; - } - - TQKeyEvent e( type, code, ascii, state, text, autor, - TQMAX(TQMAX(count,1), int(text.length())) ); - return TQApplication::sendSpontaneousEvent( this, &e ); -} - - -// -// Paint event translation -// -// When receiving many expose events, we compress them (union of all expose -// rectangles) into one event which is sent to the widget. - -struct PaintEventInfo { - Window window; -}; - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -static Bool isPaintOrScrollDoneEvent( Display *, XEvent *ev, XPointer a ) -{ - PaintEventInfo *info = (PaintEventInfo *)a; - if ( ev->type == Expose || ev->type == GraphicsExpose - || ( ev->type == ClientMessage - && ev->xclient.message_type == qt_qt_scrolldone ) ) - { - if ( ev->xexpose.window == info->window ) - return True; - } - return False; -} - -#if defined(Q_C_CALLBACKS) -} -#endif - - -// declared above: static TQPtrList *sip_list = 0; - -void qt_insert_sip( TQWidget* scrolled_widget, int dx, int dy ) -{ - if ( !sip_list ) { - sip_list = new TQPtrList; - sip_list->setAutoDelete( TRUE ); - } - - TQScrollInProgress* sip = new TQScrollInProgress( scrolled_widget, dx, dy ); - sip_list->append( sip ); - - XClientMessageEvent client_message = {}; - client_message.type = ClientMessage; - client_message.window = scrolled_widget->winId(); - client_message.format = 32; - client_message.message_type = qt_qt_scrolldone; - client_message.data.l[0] = sip->id; - - XSendEvent( appDpy, scrolled_widget->winId(), False, NoEventMask, - (XEvent*)&client_message ); -} - -int qt_sip_count( TQWidget* scrolled_widget ) -{ - if ( !sip_list ) - return 0; - - int sips=0; - - for (TQScrollInProgress* sip = sip_list->first(); - sip; sip=sip_list->next()) - { - if ( sip->scrolled_widget == scrolled_widget ) - sips++; - } - - return sips; -} - -static -bool translateBySips( TQWidget* that, TQRect& paintRect ) -{ - if ( sip_list ) { - int dx=0, dy=0; - int sips=0; - for (TQScrollInProgress* sip = sip_list->first(); - sip; sip=sip_list->next()) - { - if ( sip->scrolled_widget == that ) { - if ( sips ) { - dx += sip->dx; - dy += sip->dy; - } - sips++; - } - } - if ( sips > 1 ) { - paintRect.moveBy( dx, dy ); - return TRUE; - } - } - return FALSE; -} - -bool TQETWidget::translatePaintEvent( const XEvent *event ) -{ - setWState( WState_Exposed ); - TQRect paintRect( event->xexpose.x, event->xexpose.y, - event->xexpose.width, event->xexpose.height ); - bool merging_okay = !testWFlags(WPaintClever); - XEvent xevent; - PaintEventInfo info; - info.window = winId(); - bool should_clip = translateBySips( this, paintRect ); - - TQRegion paintRegion( paintRect ); - - if ( merging_okay ) { - // WARNING: this is O(number_of_events * number_of_matching_events) - while ( XCheckIfEvent(x11Display(),&xevent,isPaintOrScrollDoneEvent, - (XPointer)&info) && - !qt_x11EventFilter(&xevent) && - !x11Event( &xevent ) ) // send event through filter - { - if ( xevent.type == Expose || xevent.type == GraphicsExpose ) { - TQRect exposure(xevent.xexpose.x, - xevent.xexpose.y, - xevent.xexpose.width, - xevent.xexpose.height); - if ( translateBySips( this, exposure ) ) - should_clip = TRUE; - paintRegion = paintRegion.unite( exposure ); - } else { - translateScrollDoneEvent( &xevent ); - } - } - } - - if ( should_clip ) { - paintRegion = paintRegion.intersect( rect() ); - if ( paintRegion.isEmpty() ) - return TRUE; - } - - TQPaintEvent e( paintRegion ); - setWState( WState_InPaintEvent ); - if ( !isTopLevel() && backgroundOrigin() != WidgetOrigin ) - erase( paintRegion ); - qt_set_paintevent_clipping( this, paintRegion ); - TQApplication::sendSpontaneousEvent( this, &e ); - qt_clear_paintevent_clipping(); - clearWState( WState_InPaintEvent ); - return TRUE; -} - -// -// Scroll-done event translation. -// - -bool TQETWidget::translateScrollDoneEvent( const XEvent *event ) -{ - if ( !sip_list ) return FALSE; - - long id = event->xclient.data.l[0]; - - // Remove any scroll-in-progress record for the given id. - for (TQScrollInProgress* sip = sip_list->first(); sip; sip=sip_list->next()) { - if ( sip->id == id ) { - sip_list->remove( sip_list->current() ); - return TRUE; - } - } - - return FALSE; -} - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif -#ifndef TQT_NO_XSYNC -static Bool qt_net_wm_sync_request_scanner(Display*, XEvent* event, XPointer arg) -{ - return (event->type == ClientMessage && event->xclient.window == *(Window*)arg - && event->xclient.message_type == tqt_wm_protocols - && ((unsigned int)event->xclient.data.l[ 0 ]) == qt_net_wm_sync_request ); -} -#endif - -#if defined(Q_C_CALLBACKS) -} -#endif - -// -// ConfigureNotify (window move and resize) event translation - -bool TQETWidget::translateConfigEvent( const XEvent *event ) -{ - // config pending is only set on resize, see tqwidget_x11.cpp, internalSetGeometry() - bool was_resize = testWState( WState_ConfigPending ); - - clearWState(WState_ConfigPending); - - if ( isTopLevel() ) { - TQPoint newCPos( geometry().topLeft() ); - TQSize newSize( event->xconfigure.width, event->xconfigure.height ); - - bool trust = (topData()->parentWinId == None || - topData()->parentWinId == TQPaintDevice::x11AppRootWindow()); - - if (event->xconfigure.send_event || trust ) { - // if a ConfigureNotify comes from a real sendevent request, we can - // trust its values. - newCPos.rx() = event->xconfigure.x + event->xconfigure.border_width; - newCPos.ry() = event->xconfigure.y + event->xconfigure.border_width; - } - - if ( isVisible() ) - TQApplication::syncX(); - - if (! extra || extra->compress_events) { - // ConfigureNotify compression for faster opaque resizing - XEvent otherEvent; - int compressed_configs = 0; - while ( XCheckTypedWindowEvent( x11Display(), winId(), ConfigureNotify, - &otherEvent ) ) { - if ( qt_x11EventFilter( &otherEvent ) ) - continue; - - if (x11Event( &otherEvent ) ) - continue; - - if ( otherEvent.xconfigure.event != otherEvent.xconfigure.window ) - continue; - - newSize.setWidth( otherEvent.xconfigure.width ); - newSize.setHeight( otherEvent.xconfigure.height ); - - if ( otherEvent.xconfigure.send_event || trust ) { - newCPos.rx() = otherEvent.xconfigure.x + - otherEvent.xconfigure.border_width; - newCPos.ry() = otherEvent.xconfigure.y + - otherEvent.xconfigure.border_width; - } - ++compressed_configs; - } -#ifndef TQT_NO_XSYNC - // _NET_WM_SYNC_REQUEST compression - Window wid = winId(); - while ( compressed_configs && - XCheckIfEvent( x11Display(), &otherEvent, - qt_net_wm_sync_request_scanner, (XPointer)&wid ) ) { - handleSyncRequest( (void*)&otherEvent ); - --compressed_configs; - } -#endif - } - - TQRect cr ( geometry() ); - if ( newSize != cr.size() ) { // size changed - was_resize = TRUE; - TQSize oldSize = size(); - cr.setSize( newSize ); - crect = cr; - - if ( isVisible() ) { - TQResizeEvent e( newSize, oldSize ); - TQApplication::sendSpontaneousEvent( this, &e ); - } else { - TQResizeEvent * e = new TQResizeEvent( newSize, oldSize ); - TQApplication::postEvent( this, e ); - } - } - - if ( newCPos != cr.topLeft() ) { // compare with cpos (exluding frame) - TQPoint oldPos = geometry().topLeft(); - cr.moveTopLeft( newCPos ); - crect = cr; - if ( isVisible() ) { - TQMoveEvent e( newCPos, oldPos ); // pos (including frame), not cpos - TQApplication::sendSpontaneousEvent( this, &e ); - } else { - TQMoveEvent * e = new TQMoveEvent( newCPos, oldPos ); - TQApplication::postEvent( this, e ); - } - } - } else { - XEvent xevent; - while ( XCheckTypedWindowEvent(x11Display(),winId(), ConfigureNotify,&xevent) && - !qt_x11EventFilter(&xevent) && - !x11Event( &xevent ) ) // send event through filter - ; - } - - bool transbg = backgroundOrigin() != WidgetOrigin; - // we ignore NorthWestGravity at the moment for reversed layout - if ( transbg || - (!testWFlags( WStaticContents ) && - testWState( WState_Exposed ) && was_resize ) || - TQApplication::reverseLayout() ) { - // remove unnecessary paint events from the queue - XEvent xevent; - while ( XCheckTypedWindowEvent( x11Display(), winId(), Expose, &xevent ) && - ! qt_x11EventFilter( &xevent ) && - ! x11Event( &xevent ) ) // send event through filter - ; - repaint( !testWFlags(WResizeNoErase) || transbg ); - } - - incrementSyncCounter(); - - return TRUE; -} - - -// -// Close window event translation. -// -bool TQETWidget::translateCloseEvent( const XEvent * ) -{ - return close(FALSE); -} - - -/*! - Sets the text cursor's flash (blink) time to \a msecs - milliseconds. The flash time is the time required to display, - invert and restore the caret display. Usually the text cursor is - displayed for \a msecs/2 milliseconds, then hidden for \a msecs/2 - milliseconds, but this may vary. - - Note that on Microsoft Windows, calling this function sets the - cursor flash time for all windows. - - \sa cursorFlashTime() -*/ -void TQApplication::setCursorFlashTime( int msecs ) -{ - cursor_flash_time = msecs; -} - - -/*! - Returns the text cursor's flash (blink) time in milliseconds. The - flash time is the time required to display, invert and restore the - caret display. - - The default value on X11 is 1000 milliseconds. On Windows, the - control panel value is used. - - Widgets should not cache this value since it may be changed at any - time by the user changing the global desktop settings. - - \sa setCursorFlashTime() -*/ -int TQApplication::cursorFlashTime() -{ - return cursor_flash_time; -} - -/*! - Sets the time limit that distinguishes a double click from two - consecutive mouse clicks to \a ms milliseconds. - - Note that on Microsoft Windows, calling this function sets the - double click interval for all windows. - - \sa doubleClickInterval() -*/ - -void TQApplication::setDoubleClickInterval( int ms ) -{ - mouse_double_click_time = ms; -} - - -/*! - Returns the maximum duration for a double click. - - The default value on X11 is 400 milliseconds. On Windows, the - control panel value is used. - - \sa setDoubleClickInterval() -*/ - -int TQApplication::doubleClickInterval() -{ - return mouse_double_click_time; -} - - -/*! - Sets the number of lines to scroll when the mouse wheel is rotated - to \a n. - - If this number exceeds the number of visible lines in a certain - widget, the widget should interpret the scroll operation as a - single page up / page down operation instead. - - \sa wheelScrollLines() -*/ -void TQApplication::setWheelScrollLines( int n ) -{ - wheel_scroll_lines = n; -} - -/*! - Returns the number of lines to scroll when the mouse wheel is - rotated. - - \sa setWheelScrollLines() -*/ -int TQApplication::wheelScrollLines() -{ - return wheel_scroll_lines; -} - -/*! - Enables the UI effect \a effect if \a enable is TRUE, otherwise - the effect will not be used. - - Note: All effects are disabled on screens running at less than - 16-bit color depth. - - \sa isEffectEnabled(), TQt::UIEffect, setDesktopSettingsAware() -*/ -void TQApplication::setEffectEnabled( TQt::UIEffect effect, bool enable ) -{ - switch (effect) { - case UI_AnimateMenu: - if ( enable ) fade_menu = FALSE; - animate_menu = enable; - break; - case UI_FadeMenu: - if ( enable ) - animate_menu = TRUE; - fade_menu = enable; - break; - case UI_AnimateCombo: - animate_combo = enable; - break; - case UI_AnimateTooltip: - if ( enable ) fade_tooltip = FALSE; - animate_tooltip = enable; - break; - case UI_FadeTooltip: - if ( enable ) - animate_tooltip = TRUE; - fade_tooltip = enable; - break; - case UI_AnimateToolBox: - animate_toolbox = enable; - break; - default: - animate_ui = enable; - break; - } -} - -/*! - Returns TRUE if \a effect is enabled; otherwise returns FALSE. - - By default, TQt will try to use the desktop settings. Call - setDesktopSettingsAware(FALSE) to prevent this. - - Note: All effects are disabled on screens running at less than - 16-bit color depth. - - \sa setEffectEnabled(), TQt::UIEffect -*/ -bool TQApplication::isEffectEnabled( TQt::UIEffect effect ) -{ - if ( TQColor::numBitPlanes() < 16 || !animate_ui ) - return FALSE; - - switch( effect ) { - case UI_AnimateMenu: - return animate_menu; - case UI_FadeMenu: - return fade_menu; - case UI_AnimateCombo: - return animate_combo; - case UI_AnimateTooltip: - return animate_tooltip; - case UI_FadeTooltip: - return fade_tooltip; - case UI_AnimateToolBox: - return animate_toolbox; - default: - return animate_ui; - } -} - -/***************************************************************************** - Session management support - *****************************************************************************/ - -#ifndef TQT_NO_SM_SUPPORT - -#include - -class TQSessionManagerData -{ -public: - TQSessionManagerData( TQSessionManager* mgr, TQString& id, TQString& key ) - : sm( mgr ), sessionId( id ), sessionKey( key ) {} - TQSessionManager* sm; - TQStringList restartCommand; - TQStringList discardCommand; - TQString& sessionId; - TQString& sessionKey; - TQSessionManager::RestartHint restartHint; -}; - -class TQSmSocketReceiver : public TQObject -{ - TQ_OBJECT -public: - TQSmSocketReceiver( int socket ) - : TQObject(0,0) - { - TQSocketNotifier* sn = new TQSocketNotifier( socket, TQSocketNotifier::Read, this ); - connect( sn, TQ_SIGNAL( activated(int) ), this, TQ_SLOT( socketActivated(int) ) ); - } - -public slots: - void socketActivated(int); -}; - - -static SmcConn smcConnection = 0; -static bool sm_interactionActive; -static bool sm_smActive; -static int sm_interactStyle; -static int sm_saveType; -static bool sm_cancel; -// static bool sm_waitingForPhase2; ### never used?!? -static bool sm_waitingForInteraction; -static bool sm_isshutdown; -// static bool sm_shouldbefast; ### never used?!? -static bool sm_phase2; -static bool sm_in_phase2; - -static TQSmSocketReceiver* sm_receiver = 0; - -static void resetSmState(); -static void sm_setProperty( const char* name, const char* type, - int num_vals, SmPropValue* vals); -static void sm_saveYourselfCallback( SmcConn smcConn, SmPointer clientData, - int saveType, Bool shutdown , int interactStyle, Bool fast); -static void sm_saveYourselfPhase2Callback( SmcConn smcConn, SmPointer clientData ) ; -static void sm_dieCallback( SmcConn smcConn, SmPointer clientData ) ; -static void sm_shutdownCancelledCallback( SmcConn smcConn, SmPointer clientData ); -static void sm_saveCompleteCallback( SmcConn smcConn, SmPointer clientData ); -static void sm_interactCallback( SmcConn smcConn, SmPointer clientData ); -static void sm_performSaveYourself( TQSessionManagerData* ); - -static void resetSmState() -{ -// sm_waitingForPhase2 = FALSE; ### never used?!? - sm_waitingForInteraction = FALSE; - sm_interactionActive = FALSE; - sm_interactStyle = SmInteractStyleNone; - sm_smActive = FALSE; - sm_blockUserInput = FALSE; - sm_isshutdown = FALSE; -// sm_shouldbefast = FALSE; ### never used?!? - sm_phase2 = FALSE; - sm_in_phase2 = FALSE; -} - - -// theoretically it's possible to set several properties at once. For -// simplicity, however, we do just one property at a time -static void sm_setProperty( const char* name, const char* type, - int num_vals, SmPropValue* vals) -{ - if (num_vals ) { - SmProp prop; - prop.name = (char*)name; - prop.type = (char*)type; - prop.num_vals = num_vals; - prop.vals = vals; - - SmProp* props[1]; - props[0] = ∝ - SmcSetProperties( smcConnection, 1, props ); - } - else { - char* names[1]; - names[0] = (char*) name; - SmcDeleteProperties( smcConnection, 1, names ); - } -} - -static void sm_setProperty( const TQString& name, const TQString& value) -{ - SmPropValue prop; - prop.length = value.length(); - prop.value = (SmPointer) value.latin1(); - sm_setProperty( name.latin1(), SmARRAY8, 1, &prop ); -} - -static void sm_setProperty( const TQString& name, const TQStringList& value) -{ - SmPropValue *prop = new SmPropValue[ value.count() ]; - int count = 0; - for ( TQStringList::ConstIterator it = value.begin(); it != value.end(); ++it ) { - prop[ count ].length = (*it).length(); - prop[ count ].value = (char*)(*it).latin1(); - ++count; - } - sm_setProperty( name.latin1(), SmLISTofARRAY8, count, prop ); - delete [] prop; -} - - -// workaround for broken libsm, see below -struct QT_smcConn { - unsigned int save_yourself_in_progress : 1; - unsigned int shutdown_in_progress : 1; -}; - -static void sm_saveYourselfCallback( SmcConn smcConn, SmPointer clientData, - int saveType, Bool shutdown , int interactStyle, Bool /*fast*/) -{ - if (smcConn != smcConnection ) - return; - sm_cancel = FALSE; - sm_smActive = TRUE; - sm_isshutdown = shutdown; - sm_saveType = saveType; - sm_interactStyle = interactStyle; -// sm_shouldbefast = fast; ### never used?!? - - // ugly workaround for broken libSM. libSM should do that _before_ - // actually invoking the callback in sm_process.c - ( (QT_smcConn*)smcConn )->save_yourself_in_progress = TRUE; - if ( sm_isshutdown ) - ( (QT_smcConn*)smcConn )->shutdown_in_progress = TRUE; - - sm_performSaveYourself( (TQSessionManagerData*) clientData ); - if ( !sm_isshutdown ) // we cannot expect a confirmation message in that case - resetSmState(); -} - -static void sm_performSaveYourself( TQSessionManagerData* smd ) -{ - if ( sm_isshutdown ) - sm_blockUserInput = TRUE; - - TQSessionManager* sm = smd->sm; - - // generate a new session key - timeval tv; - gettimeofday( &tv, 0 ); - smd->sessionKey = TQString::number( tv.tv_sec ) + "_" + TQString::number(tv.tv_usec); - - // tell the session manager about our program in best POSIX style - sm_setProperty( SmProgram, TQString( tqApp->argv()[0] ) ); - // tell the session manager about our user as well. - struct passwd* entry = getpwuid( geteuid() ); - if ( entry ) - sm_setProperty( SmUserID, TQString::fromLatin1( entry->pw_name ) ); - - // generate a restart and discard command that makes sense - TQStringList restart; - restart << tqApp->argv()[0] << "-session" << smd->sessionId + "_" + smd->sessionKey; - if (tqstricmp(tqAppName(), tqAppClass()) != 0) - restart << "-name" << tqAppName(); - sm->setRestartCommand( restart ); - TQStringList discard; - sm->setDiscardCommand( discard ); - - switch ( sm_saveType ) { - case SmSaveBoth: - tqApp->commitData( *sm ); - if ( sm_isshutdown && sm_cancel) - break; // we cancelled the shutdown, no need to save state - // fall through - case SmSaveLocal: - tqApp->saveState( *sm ); - break; - case SmSaveGlobal: - tqApp->commitData( *sm ); - break; - default: - break; - } - - if ( sm_phase2 && !sm_in_phase2 ) { - SmcRequestSaveYourselfPhase2( smcConnection, sm_saveYourselfPhase2Callback, (SmPointer*) smd ); - sm_blockUserInput = FALSE; - } - else { - // close eventual interaction monitors and cancel the - // shutdown, if required. Note that we can only cancel when - // performing a shutdown, it does not work for checkpoints - if ( sm_interactionActive ) { - SmcInteractDone( smcConnection, sm_isshutdown && sm_cancel); - sm_interactionActive = FALSE; - } - else if ( sm_cancel && sm_isshutdown ) { - if ( sm->allowsErrorInteraction() ) { - SmcInteractDone( smcConnection, True ); - sm_interactionActive = FALSE; - } - } - - // set restart and discard command in session manager - sm_setProperty( SmRestartCommand, sm->restartCommand() ); - sm_setProperty( SmDiscardCommand, sm->discardCommand() ); - - // set the restart hint - SmPropValue prop; - prop.length = sizeof( int ); - int value = sm->restartHint(); - prop.value = (SmPointer) &value; - sm_setProperty( SmRestartStyleHint, SmCARD8, 1, &prop ); - - // we are done - SmcSaveYourselfDone( smcConnection, !sm_cancel ); - } -} - -static void sm_dieCallback( SmcConn smcConn, SmPointer /* clientData */) -{ - if (smcConn != smcConnection ) - return; - resetSmState(); - TQEvent quitEvent(TQEvent::Quit); - TQApplication::sendEvent(tqApp, &quitEvent); -} - -static void sm_shutdownCancelledCallback( SmcConn smcConn, SmPointer /* clientData */) -{ - if (smcConn != smcConnection ) - return; - if ( sm_waitingForInteraction ) - tqApp->exit_loop(); - resetSmState(); -} - -static void sm_saveCompleteCallback( SmcConn smcConn, SmPointer /*clientData */) -{ - if (smcConn != smcConnection ) - return; - resetSmState(); -} - -static void sm_interactCallback( SmcConn smcConn, SmPointer /* clientData */ ) -{ - if (smcConn != smcConnection ) - return; - if ( sm_waitingForInteraction ) - tqApp->exit_loop(); -} - -static void sm_saveYourselfPhase2Callback( SmcConn smcConn, SmPointer clientData ) -{ - if (smcConn != smcConnection ) - return; - sm_in_phase2 = TRUE; - sm_performSaveYourself( (TQSessionManagerData*) clientData ); -} - - -void TQSmSocketReceiver::socketActivated(int) -{ - IceProcessMessages( SmcGetIceConnection( smcConnection ), 0, 0); -} - - -#undef Bool -#include "qapplication_x11.moc" - -TQSessionManager::TQSessionManager( TQApplication * app, TQString &id, TQString& key ) - : TQObject( app, "session manager" ) -{ - d = new TQSessionManagerData( this, id, key ); - d->restartHint = RestartIfRunning; - - resetSmState(); - char cerror[256]; - char* myId = 0; - char* prevId = (char*)id.latin1(); // we know what we are doing - - SmcCallbacks cb; - cb.save_yourself.callback = sm_saveYourselfCallback; - cb.save_yourself.client_data = (SmPointer) d; - cb.die.callback = sm_dieCallback; - cb.die.client_data = (SmPointer) d; - cb.save_complete.callback = sm_saveCompleteCallback; - cb.save_complete.client_data = (SmPointer) d; - cb.shutdown_cancelled.callback = sm_shutdownCancelledCallback; - cb.shutdown_cancelled.client_data = (SmPointer) d; - - // avoid showing a warning message below - const char* session_manager = getenv("SESSION_MANAGER"); - if ( !session_manager || !session_manager[0] ) - return; - - smcConnection = SmcOpenConnection( 0, 0, 1, 0, - SmcSaveYourselfProcMask | - SmcDieProcMask | - SmcSaveCompleteProcMask | - SmcShutdownCancelledProcMask, - &cb, - prevId, - &myId, - 256, cerror ); - - id = TQString::fromLatin1( myId ); - ::free( myId ); // it was allocated by C - - TQString error = cerror; - if (!smcConnection ) { - tqWarning("Session management error: %s", error.latin1() ); - } - else { - sm_receiver = new TQSmSocketReceiver( IceConnectionNumber( SmcGetIceConnection( smcConnection ) ) ); - } -} - -TQSessionManager::~TQSessionManager() -{ - if ( smcConnection ) - SmcCloseConnection( smcConnection, 0, 0 ); - smcConnection = 0; - delete sm_receiver; - delete d; -} - -TQString TQSessionManager::sessionId() const -{ - return d->sessionId; -} - -TQString TQSessionManager::sessionKey() const -{ - return d->sessionKey; -} - - -void* TQSessionManager::handle() const -{ - return (void*) smcConnection; -} - - -bool TQSessionManager::allowsInteraction() -{ - if ( sm_interactionActive ) - return TRUE; - - if ( sm_waitingForInteraction ) - return FALSE; - - if ( sm_interactStyle == SmInteractStyleAny ) { - sm_waitingForInteraction = SmcInteractRequest( smcConnection, SmDialogNormal, - sm_interactCallback, (SmPointer*) this ); - } - if ( sm_waitingForInteraction ) { - tqApp->enter_loop(); - sm_waitingForInteraction = FALSE; - if ( sm_smActive ) { // not cancelled - sm_interactionActive = TRUE; - sm_blockUserInput = FALSE; - return TRUE; - } - } - return FALSE; -} - -bool TQSessionManager::allowsErrorInteraction() -{ - if ( sm_interactionActive ) - return TRUE; - - if ( sm_waitingForInteraction ) - return FALSE; - - if ( sm_interactStyle == SmInteractStyleAny || sm_interactStyle == SmInteractStyleErrors ) { - sm_waitingForInteraction = SmcInteractRequest( smcConnection, SmDialogError, - sm_interactCallback, (SmPointer*) this ); - } - if ( sm_waitingForInteraction ) { - tqApp->enter_loop(); - sm_waitingForInteraction = FALSE; - if ( sm_smActive ) { // not cancelled - sm_interactionActive = TRUE; - sm_blockUserInput = FALSE; - return TRUE; - } - } - return FALSE; -} - -void TQSessionManager::release() -{ - if ( sm_interactionActive ) { - SmcInteractDone( smcConnection, False ); - sm_interactionActive = FALSE; - if ( sm_smActive && sm_isshutdown ) - sm_blockUserInput = TRUE; - } -} - -void TQSessionManager::cancel() -{ - sm_cancel = TRUE; -} - -void TQSessionManager::setRestartHint( TQSessionManager::RestartHint hint) -{ - d->restartHint = hint; -} - -TQSessionManager::RestartHint TQSessionManager::restartHint() const -{ - return d->restartHint; -} - -void TQSessionManager::setRestartCommand( const TQStringList& command) -{ - d->restartCommand = command; -} - -TQStringList TQSessionManager::restartCommand() const -{ - return d->restartCommand; -} - -void TQSessionManager::setDiscardCommand( const TQStringList& command) -{ - d->discardCommand = command; -} - -TQStringList TQSessionManager::discardCommand() const -{ - return d->discardCommand; -} - -void TQSessionManager::setManagerProperty( const TQString& name, const TQString& value) -{ - SmPropValue prop; - prop.length = value.length(); - prop.value = (SmPointer) value.utf8().data(); - sm_setProperty( name.latin1(), SmARRAY8, 1, &prop ); -} - -void TQSessionManager::setManagerProperty( const TQString& name, const TQStringList& value) -{ - SmPropValue *prop = new SmPropValue[ value.count() ]; - int count = 0; - for ( TQStringList::ConstIterator it = value.begin(); it != value.end(); ++it ) { - prop[ count ].length = (*it).length(); - prop[ count ].value = (char*)(*it).utf8().data(); - ++count; - } - sm_setProperty( name.latin1(), SmLISTofARRAY8, count, prop ); - delete [] prop; -} - -bool TQSessionManager::isPhase2() const -{ - return sm_in_phase2; -} - -void TQSessionManager::requestPhase2() -{ - sm_phase2 = TRUE; -} - - -#endif // TQT_NO_SM_SUPPORT diff --git a/src/kernel/qdnd_x11.cpp b/src/kernel/qdnd_x11.cpp index 571045f48..57bdcffd4 100644 --- a/src/kernel/qdnd_x11.cpp +++ b/src/kernel/qdnd_x11.cpp @@ -40,7 +40,7 @@ #include "qplatformdefs.h" -#include "ntqapplication.h" +#include "tqapplication.h" #ifndef TQT_NO_DRAGANDDROP diff --git a/src/kernel/qt_kernel.pri b/src/kernel/qt_kernel.pri index 84a383a5d..05d5c8cd7 100644 --- a/src/kernel/qt_kernel.pri +++ b/src/kernel/qt_kernel.pri @@ -5,8 +5,8 @@ kernel { HEADERS += \ $$KERNEL_H/tqaccel.h \ $$KERNEL_P/tqucomextra_p.h \ - $$KERNEL_H/ntqapplication.h \ - $$KERNEL_P/qapplication_p.h \ + $$KERNEL_H/tqapplication.h \ + $$KERNEL_P/tqapplication_p.h \ $$KERNEL_H/tqasyncimageio.h \ $$KERNEL_H/tqasyncio.h \ $$KERNEL_H/tqbitmap.h \ @@ -110,7 +110,7 @@ kernel { HEADERS+=$$KERNEL_P/tqeventloop_glib_p.h } - win32:SOURCES += $$KERNEL_CPP/qapplication_win.cpp \ + win32:SOURCES += $$KERNEL_CPP/tqapplication_win.cpp \ $$KERNEL_CPP/tqclipboard_win.cpp \ $$KERNEL_CPP/tqcolor_win.cpp \ $$KERNEL_CPP/tqcursor_win.cpp \ @@ -133,7 +133,7 @@ kernel { $$KERNEL_CPP/tqfontengine_win.cpp unix:x11 { - SOURCES += $$KERNEL_CPP/qapplication_x11.cpp \ + SOURCES += $$KERNEL_CPP/tqapplication_x11.cpp \ $$KERNEL_CPP/tqclipboard_x11.cpp \ $$KERNEL_CPP/tqcolor_x11.cpp \ $$KERNEL_CPP/tqcursor_x11.cpp \ @@ -163,7 +163,7 @@ kernel { exists(tqsound_mac.cpp):SOURCES += $$KERNEL_CPP/tqsound_mac.cpp } !embedded:!x11:mac { - SOURCES += $$KERNEL_CPP/qapplication_mac.cpp \ + SOURCES += $$KERNEL_CPP/tqapplication_mac.cpp \ $$KERNEL_CPP/tqclipboard_mac.cpp \ $$KERNEL_CPP/tqcolor_mac.cpp \ $$KERNEL_CPP/tqcursor_mac.cpp \ @@ -196,7 +196,7 @@ kernel { SOURCES += $$KERNEL_CPP/tqabstractlayout.cpp \ $$KERNEL_CPP/tqucomextra.cpp \ $$KERNEL_CPP/tqaccel.cpp \ - $$KERNEL_CPP/qapplication.cpp \ + $$KERNEL_CPP/tqapplication.cpp \ $$KERNEL_CPP/tqasyncimageio.cpp \ $$KERNEL_CPP/tqasyncio.cpp \ $$KERNEL_CPP/tqbitmap.cpp \ diff --git a/src/kernel/qt_pch.h b/src/kernel/qt_pch.h index 1420944ef..073f01b50 100644 --- a/src/kernel/qt_pch.h +++ b/src/kernel/qt_pch.h @@ -23,7 +23,7 @@ # endif #include // I must be first! #include // All moc genereated code has this include -#include +#include #include #include #include diff --git a/src/kernel/qtaddons_x11.cpp b/src/kernel/qtaddons_x11.cpp index 089466ec7..c1d83e805 100644 --- a/src/kernel/qtaddons_x11.cpp +++ b/src/kernel/qtaddons_x11.cpp @@ -32,7 +32,7 @@ #include #include -extern bool tqt_use_xrender; // defined in qapplication_x11.cpp +extern bool tqt_use_xrender; // defined in tqapplication_x11.cpp extern "C" { diff --git a/src/kernel/tqabstractlayout.cpp b/src/kernel/tqabstractlayout.cpp index 3f881ddbb..cbace549d 100644 --- a/src/kernel/tqabstractlayout.cpp +++ b/src/kernel/tqabstractlayout.cpp @@ -41,7 +41,7 @@ #include "tqlayout.h" #ifndef TQT_NO_LAYOUT -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqlayoutengine_p.h" #include "tqmenubar.h" #include "tqtoolbar.h" diff --git a/src/kernel/tqaccel.cpp b/src/kernel/tqaccel.cpp index ef6b665e6..6569aa8dc 100644 --- a/src/kernel/tqaccel.cpp +++ b/src/kernel/tqaccel.cpp @@ -43,7 +43,7 @@ #ifndef TQT_NO_ACCEL #include "tqsignal.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqwidget.h" #include "tqptrlist.h" #include "tqwhatsthis.h" diff --git a/src/kernel/tqaccessible.cpp b/src/kernel/tqaccessible.cpp index 5a43e402b..174e16633 100644 --- a/src/kernel/tqaccessible.cpp +++ b/src/kernel/tqaccessible.cpp @@ -43,7 +43,7 @@ #include "tqptrdict.h" #include "tqmetaobject.h" #include -#include "ntqapplication.h" +#include "tqapplication.h" #include /*! diff --git a/src/kernel/tqapplication.cpp b/src/kernel/tqapplication.cpp new file mode 100644 index 000000000..1cc5bf140 --- /dev/null +++ b/src/kernel/tqapplication.cpp @@ -0,0 +1,4969 @@ +/**************************************************************************** +** +** Implementation 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. +** +**********************************************************************/ + +#include "tqobjectlist.h" +#include "tqapplication.h" +#include "tqeventloop.h" +#include "tqeventloop_p.h" +#include "tqwidget.h" +#include "tqwidgetlist.h" +#include "tqwidgetintdict.h" +#include "tqptrdict.h" +#include "tqcleanuphandler.h" + +#include "tqtranslator.h" +#include "tqtextcodec.h" +#include "tqsessionmanager.h" +#include "tqdragobject.h" +#include "tqclipboard.h" +#include "tqcursor.h" +#include "tqstyle.h" +#include "tqstylefactory.h" +#include "tqfile.h" +#include "tqmessagebox.h" +#include "tqdir.h" +#include "tqfileinfo.h" +#ifdef TQ_WS_WIN +#include "tqinputcontext_p.h" +#endif +#include "tqfontdata_p.h" + +#if defined(TQT_THREAD_SUPPORT) +# include "tqmutex.h" +# include "tqthread.h" +# include +#endif // TQT_THREAD_SUPPORT + +#include + +#ifdef truncate +# undef truncate +#endif + +/*! + \class TQApplication tqapplication.h + \brief The TQApplication class manages the GUI application's control + flow and main settings. + + \ingroup application + \mainclass + + It contains the main event loop, where all events from the window + system and other sources are processed and dispatched. It also + handles the application's initialization and finalization, and + provides session management. It also handles most system-wide and + application-wide settings. + + For any GUI application that uses TQt, there is precisely one + TQApplication object, no matter whether the application has 0, 1, 2 + or more windows at any time. + + The TQApplication object is accessible through the global pointer \c + tqApp. Its main areas of responsibility are: + \list + + \i It initializes the application with the user's desktop settings + such as palette(), font() and doubleClickInterval(). It keeps track + of these properties in case the user changes the desktop globally, for + example through some kind of control panel. + + \i It performs event handling, meaning that it receives events + from the underlying window system and dispatches them to the relevant + widgets. By using sendEvent() and postEvent() you can send your own + events to widgets. + + \i It parses common command line arguments and sets its internal + state accordingly. See the \link TQApplication::TQApplication() + constructor documentation\endlink below for more details about this. + + \i It defines the application's look and feel, which is + encapsulated in a TQStyle object. This can be changed at runtime + with setStyle(). + + \i It specifies how the application is to allocate colors. + See setColorSpec() for details. + + \i It provides localization of strings that are visible to the user + via translate(). + + \i It provides some magical objects like the desktop() and the + clipboard(). + + \i It knows about the application's windows. You can ask which + widget is at a certain position using widgetAt(), get a list of + topLevelWidgets() and closeAllWindows(), etc. + + \i It manages the application's mouse cursor handling, + see setOverrideCursor() and setGlobalMouseTracking(). + + \i On the X window system, it provides functions to flush and sync + the communication stream, see flushX() and syncX(). + + \i It provides support for sophisticated \link + session.html session management \endlink. This makes it possible + for applications to terminate gracefully when the user logs out, to + cancel a shutdown process if termination isn't possible and even to + preserve the entire application's state for a future session. See + isSessionRestored(), sessionId() and commitData() and saveState() + for details. + + \endlist + + The Application walk-through + example contains a typical complete main() that does the usual + things with TQApplication. + + Since the TQApplication object does so much initialization, it + must be created before any other objects related to the user + interface are created. + + Since it also deals with common command line arguments, it is + usually a good idea to create it \e before any interpretation or + modification of \c argv is done in the application itself. (Note + also that for X11, setMainWidget() may change the main widget + according to the \c -geometry option. To preserve this + functionality, you must set your defaults before setMainWidget() and + any overrides after.) + + \table + \header \i21 Groups of functions + \row + \i System settings + \i + desktopSettingsAware(), + setDesktopSettingsAware(), + cursorFlashTime(), + setCursorFlashTime(), + doubleClickInterval(), + setDoubleClickInterval(), + wheelScrollLines(), + setWheelScrollLines(), + palette(), + setPalette(), + font(), + setFont(), + fontMetrics(). + + \row + \i Event handling + \i + exec(), + processEvents(), + enter_loop(), + exit_loop(), + exit(), + quit(). + sendEvent(), + postEvent(), + sendPostedEvents(), + removePostedEvents(), + hasPendingEvents(), + notify(), + macEventFilter(), + x11EventFilter(), + x11ProcessEvent(), + winEventFilter(). + + \row + \i GUI Styles + \i + style(), + setStyle(), + polish(). + + \row + \i Color usage + \i + colorSpec(), + setColorSpec(), + + \row + \i Text handling + \i + installTranslator(), + removeTranslator() + translate(). + + \row + \i Widgets + \i + mainWidget(), + setMainWidget(), + allWidgets(), + topLevelWidgets(), + desktop(), + activePopupWidget(), + activeModalWidget(), + clipboard(), + focusWidget(), + winFocus(), + activeWindow(), + widgetAt(). + + \row + \i Advanced cursor handling + \i + hasGlobalMouseTracking(), + setGlobalMouseTracking(), + overrideCursor(), + setOverrideCursor(), + restoreOverrideCursor(). + + \row + \i X Window System synchronization + \i + flushX(), + syncX(). + + \row + \i Session management + \i + isSessionRestored(), + sessionId(), + commitData(), + saveState(). + + \row + \i Threading + \i + lock(), unlock(), locked(), tryLock(), + wakeUpGuiThread() + + \row + \i Miscellaneous + \i + closeAllWindows(), + startingUp(), + closingDown(), + type(). + \endtable + + \e {Non-GUI programs:} While TQt is not optimized or + designed for writing non-GUI programs, it's possible to use + \link tools.html some of its classes \endlink without creating a + TQApplication. This can be useful if you wish to share code between + a non-GUI server and a GUI client. + + \headerfile tqnamespace.h + \headerfile tqwindowdefs.h + \headerfile tqglobal.h +*/ + +/*! \enum TQt::HANDLE + \internal +*/ + +/*! + \enum TQApplication::Type + + \value Tty a console application + \value GuiClient a GUI client application + \value GuiServer a GUI server application +*/ + +/*! + \enum TQApplication::ColorSpec + + \value NormalColor the default color allocation policy + \value CustomColor the same as NormalColor for X11; allocates colors + to a palette on demand under Windows + \value ManyColor the right choice for applications that use thousands of + colors + + See setColorSpec() for full details. +*/ + +/* + The tqt_init() and tqt_cleanup() functions are implemented in the + tqapplication_xyz.cpp file. +*/ + +void tqt_init( int *, char **, TQApplication::Type ); +void tqt_cleanup(); +#if defined(TQ_WS_X11) +void tqt_init( Display* dpy, TQt::HANDLE, TQt::HANDLE ); +void tqt_init( int *, char **, Display* dpy, TQt::HANDLE, TQt::HANDLE ); +#endif +TQ_EXPORT bool tqt_tryModalHelper( TQWidget *widget, TQWidget **rettop ); + +TQApplication *tqApp = 0; // global application object + +TQStyle *TQApplication::app_style = 0; // default application style +bool tqt_explicit_app_style = FALSE; // style explicitly set by programmer + +int TQApplication::app_cspec = TQApplication::NormalColor; +#ifndef TQT_NO_PALETTE +TQPalette *TQApplication::app_pal = 0; // default application palette +#endif +TQFont *TQApplication::app_font = 0; // default application font +bool tqt_app_has_font = FALSE; +#ifndef TQT_NO_CURSOR +TQCursor *TQApplication::app_cursor = 0; // default application cursor +#endif +int TQApplication::app_tracking = 0; // global mouse tracking +bool TQApplication::is_app_running = FALSE; // app starting up if FALSE +bool TQApplication::is_app_closing = FALSE; // app closing down if TRUE +int TQApplication::loop_level = 0; // event loop level +TQWidget *TQApplication::main_widget = 0; // main application widget +TQWidget *TQApplication::focus_widget = 0; // has keyboard input focus +TQWidget *TQApplication::active_window = 0; // toplevel with keyboard focus +bool TQApplication::obey_desktop_settings = TRUE; // use winsys resources +int TQApplication::cursor_flash_time = 1000; // text caret flash time +int TQApplication::mouse_double_click_time = 400; // mouse dbl click limit +#ifndef TQT_NO_WHEELEVENT +int TQApplication::wheel_scroll_lines = 3; // number of lines to scroll +#endif +bool tqt_is_gui_used; +bool TQ_EXPORT tqt_resolve_symlinks = TRUE; +bool TQ_EXPORT tqt_tab_all_widgets = TRUE; +TQRect tqt_maxWindowRect; +static int drag_time = 500; +static int drag_distance = 4; +static bool reverse_layout = FALSE; +TQSize TQApplication::app_strut = TQSize( 0,0 ); // no default application strut +bool TQApplication::animate_ui = TRUE; +bool TQApplication::animate_menu = FALSE; +bool TQApplication::fade_menu = FALSE; +bool TQApplication::animate_combo = FALSE; +bool TQApplication::animate_tooltip = FALSE; +bool TQApplication::fade_tooltip = FALSE; +bool TQApplication::animate_toolbox = FALSE; +bool TQApplication::widgetCount = FALSE; +TQApplication::Type tqt_appType=TQApplication::Tty; +#ifndef TQT_NO_COMPONENT +TQStringList *TQApplication::app_libpaths = 0; +#endif +bool TQApplication::metaComposeUnicode = FALSE; +int TQApplication::composedUnicode = 0; + +#ifdef TQT_THREAD_SUPPORT +TQMutex *TQApplication::tqt_mutex = 0; +TQMutex *tqt_sharedStringMutex = 0; +TQ_EXPORT TQMutex * tqt_sharedMetaObjectMutex = 0; + +#ifdef QT_USE_GLIBMAINLOOP +TQMutex *tqt_timerListMutex = 0; +#endif // QT_USE_GLIBMAINLOOP + +static TQt::HANDLE tqt_application_thread_id = 0; +TQ_EXPORT TQt::HANDLE tqt_get_application_thread_id() +{ + return tqt_application_thread_id; +} +#endif // TQT_THREAD_SUPPORT + +#ifndef TQT_THREAD_SUPPORT +TQEventLoop *TQApplication::eventloop = 0; // application event loop +#endif + +#ifdef TQT_THREAD_SUPPORT +TQEventLoop* TQApplication::currentEventLoop() { + TQThread* thread = TQThread::currentThreadObject(); + if (thread) { + if (thread->d) { + return thread->d->eventLoop; + } + } + return NULL; +} +#else +TQEventLoop* TQApplication::currentEventLoop() { + return TQApplication::eventloop; +} +#endif + +#ifndef TQT_NO_ACCEL +extern bool tqt_dispatchAccelEvent( TQWidget*, TQKeyEvent* ); // def in tqaccel.cpp +extern bool tqt_tryComposeUnicode( TQWidget*, TQKeyEvent* ); // def in tqaccel.cpp +#endif + +#if defined(QT_TABLET_SUPPORT) +bool chokeMouse = FALSE; +#endif + +void tqt_setMaxWindowRect(const TQRect& r) +{ + tqt_maxWindowRect = r; + // Re-resize any maximized windows + TQWidgetList* l = TQApplication::topLevelWidgets(); + if ( l ) { + TQWidget *w = l->first(); + while ( w ) { + if ( w->isVisible() && w->isMaximized() ) + { + w->showNormal(); //#### flicker + w->showMaximized(); + } + w = l->next(); + } + delete l; + } +} + +typedef void (*VFPTR)(); +typedef TQValueList TQVFuncList; +static TQVFuncList *postRList = 0; // list of post routines + +/*! + \relates TQApplication + + Adds a global routine that will be called from the TQApplication + destructor. This function is normally used to add cleanup routines + for program-wide functionality. + + The function given by \a p should take no arguments and return + nothing, like this: + \code + static int *global_ptr = 0; + + static void cleanup_ptr() + { + delete [] global_ptr; + global_ptr = 0; + } + + void init_ptr() + { + global_ptr = new int[100]; // allocate data + tqAddPostRoutine( cleanup_ptr ); // delete later + } + \endcode + + Note that for an application- or module-wide cleanup, + tqAddPostRoutine() is often not suitable. People have a tendency to + make such modules dynamically loaded, and then unload those modules + long before the TQApplication destructor is called, for example. + + For modules and libraries, using a reference-counted initialization + manager or TQt' parent-child delete mechanism may be better. Here is + an example of a private class which uses the parent-child mechanism + to call a cleanup function at the right time: + + \code + class MyPrivateInitStuff: public TQObject { + private: + MyPrivateInitStuff( TQObject * parent ): TQObject( parent) { + // initialization goes here + } + MyPrivateInitStuff * p; + + public: + static MyPrivateInitStuff * initStuff( TQObject * parent ) { + if ( !p ) + p = new MyPrivateInitStuff( parent ); + return p; + } + + ~MyPrivateInitStuff() { + // cleanup (the "post routine") goes here + } + } + \endcode + + By selecting the right parent widget/object, this can often be made + to clean up the module's data at the exact right moment. +*/ + +TQ_EXPORT void tqAddPostRoutine( TQtCleanUpFunction p) +{ + if ( !postRList ) { + postRList = new TQVFuncList; + TQ_CHECK_PTR( postRList ); + } + postRList->prepend( p ); +} + + +TQ_EXPORT void tqRemovePostRoutine( TQtCleanUpFunction p ) +{ + if ( !postRList ) return; + TQVFuncList::Iterator it = postRList->begin(); + while ( it != postRList->end() ) { + if ( *it == p ) { + postRList->remove( it ); + it = postRList->begin(); + } else { + ++it; + } + } +} + +// Default application palettes and fonts (per widget type) +TQAsciiDict *TQApplication::app_palettes = 0; +TQAsciiDict *TQApplication::app_fonts = 0; + +#ifndef TQT_NO_SESSIONMANAGER +TQString *TQApplication::session_key = 0; // ## session key. Should be a member in 4.0 +#endif +TQWidgetList *TQApplication::popupWidgets = 0; // has keyboard input focus + +TQDesktopWidget *tqt_desktopWidget = 0; // root window widgets +#ifndef TQT_NO_CLIPBOARD +TQClipboard *tqt_clipboard = 0; // global clipboard object +#endif +TQWidgetList * tqt_modal_stack=0; // stack of modal widgets + +#ifdef TQT_THREAD_SUPPORT + +// thread wrapper for the main() thread +class TQCoreApplicationThread : public TQThread +{ +public: + inline TQCoreApplicationThread() + { +#ifdef QT_CHECK_STATE + if ( tqt_gui_thread_self ) + tqWarning( "TQCoreApplicationThread: there should be exactly one main thread object" ); +#endif + tqt_gui_thread_self = this; + + TQThreadInstance::setCurrentThread(this); + + // thread should be running and not finished for the lifetime + // of the application (even if TQCoreApplication goes away) + d->running = true; + d->finished = false; + d->eventLoop = NULL; + } + + inline ~TQCoreApplicationThread() + { + tqt_gui_thread_self = nullptr; + + // avoid warning from TQThread + d->running = false; + // do some cleanup, namely clean up the thread-local storage associated with the GUI thread + TQThreadInstance::finishGuiThread(d); + } + + static TQCoreApplicationThread* self() { return tqt_gui_thread_self; } + +private: + inline void run() + { + // this function should never be called, it is implemented + // only so that we can instantiate the object + tqFatal("TQCoreApplicationThread: internal error"); + } + + static TQCoreApplicationThread* tqt_gui_thread_self; +}; + +TQCoreApplicationThread* TQCoreApplicationThread::tqt_gui_thread_self = nullptr; + +// construct exactly one instance of the core thread with static storage duration. Do it static +// rather than in the heap as we need it to be properly destroyed on the exit from the program. +static TQCoreApplicationThread tqt_main_thread; +#endif + +// Definitions for posted events +struct TQPostEvent { + TQPostEvent( TQObject *r, TQEvent *e ): receiver( r ), event( e ) {} + ~TQPostEvent() { delete event; } + TQObject *receiver; + TQEvent *event; +}; + +class TQ_EXPORT TQPostEventList : public TQPtrList +{ +public: + TQPostEventList(bool with_mutex = false) : TQPtrList(), m_mutex(nullptr) + { +#ifdef TQT_THREAD_SUPPORT + if (with_mutex) + { + m_mutex = new TQMutex(TRUE); + } +#endif + } + + ~TQPostEventList() + { + if (m_mutex) + { + delete m_mutex; + m_mutex = nullptr; + } + clear(); + } + + TQMutex* mutex() const { return m_mutex; } + +private: + TQMutex *m_mutex; + + TQPostEventList(const TQPostEventList &) = delete; + TQPostEventList &operator=(const TQPostEventList &) = delete; +}; + +class TQ_EXPORT TQPostEventListIt : public TQPtrListIterator +{ +public: + TQPostEventListIt( const TQPostEventList &l ) : TQPtrListIterator(l) {} + TQPostEventListIt &operator=(const TQPostEventListIt &i) +{ + return (TQPostEventListIt&)TQPtrListIterator::operator=(i); } +}; + +// The global list and its pointer are initialized in different functions +// to optimize access to the list pointer in normal usage +static TQPostEventList* InitGlobalPostedEventsList() +{ + static TQPostEventList _globalEventList(true); + _globalEventList.setAutoDelete(TRUE); + return &_globalEventList; +} + +static TQPostEventList* GlobalPostedEvents() +{ + static TQPostEventList *_globalPostedEvents = InitGlobalPostedEventsList(); + return _globalPostedEvents; +} + +uint qGlobalPostedEventsCount() +{ +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( GlobalPostedEvents()->mutex() ); +#endif // TQT_THREAD_SUPPORT + + return GlobalPostedEvents()->count(); +} + +#ifndef TQT_NO_PALETTE +TQPalette *tqt_std_pal = 0; + +void tqt_create_std_palette() +{ + if ( tqt_std_pal ) + delete tqt_std_pal; + + TQColor standardLightGray( 192, 192, 192 ); + TQColor light( 255, 255, 255 ); + TQColor dark( standardLightGray.dark( 150 ) ); + TQColorGroup std_act( TQt::black, standardLightGray, + light, dark, TQt::gray, + TQt::black, TQt::white ); + TQColorGroup std_dis( TQt::darkGray, standardLightGray, + light, dark, TQt::gray, + TQt::darkGray, std_act.background() ); + TQColorGroup std_inact( TQt::black, standardLightGray, + light, dark, TQt::gray, + TQt::black, TQt::white ); + tqt_std_pal = new TQPalette( std_act, std_dis, std_inact ); +} + +static void tqt_fix_tooltips() +{ + // No resources for this yet (unlike on Windows). + TQColorGroup cg( TQt::black, TQColor(255,255,220), + TQColor(96,96,96), TQt::black, TQt::black, + TQt::black, TQColor(255,255,220) ); + TQPalette pal( cg, cg, cg ); + TQApplication::setPalette( pal, TRUE, "TQTipLabel"); +} +#endif + +void TQApplication::process_cmdline( int* argcptr, char ** argv ) +{ + // process platform-indep command line + if ( !tqt_is_gui_used || !*argcptr) + return; + + int argc = *argcptr; + int i, j; + + j = 1; + for ( i=1; i= 0 ) { + if ( !session_key ) + session_key = new TQString; + *session_key = session_id.mid( p +1 ); + session_id = session_id.left( p ); + } + is_session_restored = TRUE; + } +#endif + } else if ( qstrcmp(arg, "-reverse") == 0 ) { + setReverseLayout( TRUE ); + } else if ( qstrcmp(arg, "-widgetcount") == 0 ) { + widgetCount = TRUE;; + } else { + argv[j++] = argv[i]; + } +#ifndef TQT_NO_STYLE + if ( !s.isEmpty() ) { + setStyle( s ); + } +#endif + } + + if(j < argc) { +#ifdef TQ_WS_MACX + static char* empty = "\0"; + argv[j] = empty; +#else + argv[j] = 0; +#endif + *argcptr = j; + } +} + +/*! + Initializes the window system and constructs an application object + with \a argc command line arguments in \a argv. + + The global \c tqApp pointer refers to this application object. Only + one application object should be created. + + This application object must be constructed before any \link + TQPaintDevice paint devices\endlink (including widgets, pixmaps, bitmaps + etc.). + + Note that \a argc and \a argv might be changed. TQt removes command + line arguments that it recognizes. The modified \a argc and \a argv + can also be accessed later with \c tqApp->argc() and \c tqApp->argv(). + The documentation for argv() contains a detailed description of how + to process command line arguments. + + TQt debugging options (not available if TQt was compiled with the + TQT_NO_DEBUG flag defined): + \list + \i -nograb, tells TQt that it must never grab the mouse or the keyboard. + \i -dograb (only under X11), running under a debugger can cause + an implicit -nograb, use -dograb to override. + \i -sync (only under X11), switches to synchronous mode for + debugging. + \endlist + + See \link debug.html Debugging Techniques \endlink for a more + detailed explanation. + + All TQt programs automatically support the following command line options: + \list + \i -reverse causes text to be formatted for right-to-left languages + rather than in the usual left-to-right direction. + \i -style= \e style, sets the application GUI style. Possible values + are \c motif, \c windows, and \c platinum. If you compiled TQt + with additional styles or have additional styles as plugins these + will be available to the \c -style command line option. + \i -style \e style, is the same as listed above. + \i -session= \e session, restores the application from an earlier + \link session.html session \endlink. + \i -session \e session, is the same as listed above. + \i -widgetcount, prints debug message at the end about number of widgets left + undestroyed and maximum number of widgets existed at the same time + \endlist + + The X11 version of TQt also supports some traditional X11 + command line options: + \list + \i -display \e display, sets the X display (default is $DISPLAY). + \i -geometry \e geometry, sets the client geometry of the + \link setMainWidget() main widget\endlink. + \i -fn or \c -font \e font, defines the application font. The + font should be specified using an X logical font description. + \i -bg or \c -background \e color, sets the default background color + and an application palette (light and dark shades are calculated). + \i -fg or \c -foreground \e color, sets the default foreground color. + \i -btn or \c -button \e color, sets the default button color. + \i -name \e name, sets the application name. + \i -title \e title, sets the application title (caption). + \i -visual \c TrueColor, forces the application to use a TrueColor visual + on an 8-bit display. + \i -ncols \e count, limits the number of colors allocated in the + color cube on an 8-bit display, if the application is using the + \c TQApplication::ManyColor color specification. If \e count is + 216 then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green, + and 6 of blue); for other values, a cube + approximately proportional to a 2x3x1 cube is used. + \i -cmap, causes the application to install a private color map + on an 8-bit display. + \endlist + + \sa argc(), argv() +*/ + +//######### BINARY COMPATIBILITY constructor +TQApplication::TQApplication( int &argc, char **argv ) +{ + construct( argc, argv, GuiClient, true ); +} + +/*! + Constructs an application object with \a argc command line arguments + in \a argv. If \a GUIenabled is TRUE, a GUI application is + constructed, otherwise a non-GUI (console) application is created. + + Set \a GUIenabled to FALSE for programs without a graphical user + interface that should be able to run without a window system. + + On X11, the window system is initialized if \a GUIenabled is TRUE. + If \a GUIenabled is FALSE, the application does not connect to the + X-server. + On Windows and Macintosh, currently the window system is always + initialized, regardless of the value of GUIenabled. This may change in + future versions of TQt. + + The following example shows how to create an application that + uses a graphical interface when available. + \code + int main( int argc, char **argv ) + { +#ifdef TQ_WS_X11 + bool useGUI = getenv( "DISPLAY" ) != 0; +#else + bool useGUI = TRUE; +#endif + TQApplication app(argc, argv, useGUI); + + if ( useGUI ) { + //start GUI version + ... + } else { + //start non-GUI version + ... + } + return app.exec(); + } +\endcode +*/ + +TQApplication::TQApplication( int &argc, char **argv, bool GUIenabled ) +{ + construct( argc, argv, GUIenabled ? GuiClient : Tty, true ); +} + +/*! + Constructs an application object with \a argc command line arguments + in \a argv. If \a GUIenabled is TRUE, a GUI application is + constructed, otherwise a non-GUI (console) application is created. + If \a SMEnabled is TRUE, session management support is enabled (default). + + Set \a GUIenabled to FALSE for programs without a graphical user + interface that should be able to run without a window system. + + Set \a SMEnabled to FALSE to disable session management. + Session management cannot be enabled at a later time if disabled here. + + On X11, the window system is initialized if \a GUIenabled is TRUE. + If \a GUIenabled is FALSE, the application does not connect to the + X-server. + On Windows and Macintosh, currently the window system is always + initialized, regardless of the value of GUIenabled. This may change in + future versions of TQt. + + The following example shows how to create an application that + uses a graphical interface when available. + \code + int main( int argc, char **argv ) + { +#ifdef TQ_WS_X11 + bool useGUI = getenv( "DISPLAY" ) != 0; +#else + bool useGUI = TRUE; +#endif + TQApplication app(argc, argv, useGUI); + + if ( useGUI ) { + //start GUI version + ... + } else { + //start non-GUI version + ... + } + return app.exec(); + } +\endcode +*/ + +TQApplication::TQApplication( int &argc, char **argv, bool GUIenabled, bool SMenabled ) +{ + construct( argc, argv, GUIenabled ? GuiClient : Tty, SMenabled ); +} + +/*! + Constructs an application object with \a argc command line arguments + in \a argv. +*/ +TQApplication::TQApplication( int &argc, char **argv, Type type ) +{ + construct( argc, argv, type, true ); +} + +TQ_EXPORT void tqt_ucm_initialize( TQApplication *theApp ) +{ + if ( tqApp ) + return; + int argc = theApp->argc(); + char **argv = theApp->argv(); + theApp->construct( argc, argv, tqApp->type(), true ); + + Q_ASSERT( tqApp == theApp ); +} + +void TQApplication::construct( int &argc, char **argv, Type type, bool enable_sm ) +{ + tqt_appType = type; + tqt_is_gui_used = (type != Tty); + init_precmdline(); + static const char *empty = ""; + if ( argc == 0 || argv == 0 ) { + argc = 0; + argv = (char **)∅ // ouch! careful with TQApplication::argv()! + } + app_argc = argc; + app_argv = argv; + + tqt_init( &argc, argv, type ); // Must be called before initialize() + process_cmdline( &argc, argv ); + initialize( argc, argv, enable_sm ); + if ( tqt_is_gui_used ) + tqt_maxWindowRect = desktop()->rect(); + if ( currentEventLoop() ) + currentEventLoop()->appStartingUp(); +} + +/*! + Returns the type of application, Tty, GuiClient or GuiServer. +*/ + +TQApplication::Type TQApplication::type() const +{ + return tqt_appType; +} + +#if defined(TQ_WS_X11) +/*! + Create an application, given an already open display \a dpy. If \a + visual and \a colormap are non-zero, the application will use those as + the default Visual and Colormap contexts. + + \warning TQt only supports TrueColor visuals at depths higher than 8 + bits-per-pixel. + + This is available only on X11. +*/ + +TQApplication::TQApplication( Display* dpy, HANDLE visual, HANDLE colormap ) +{ + static int aargc = 1; + // ### a string literal is a cont char* + // ### using it as a char* is wrong and could lead to segfaults + // ### if aargv is modified someday + static char *aargv[] = { (char*)"unknown", 0 }; + + app_argc = aargc; + app_argv = aargv; + + tqt_appType = GuiClient; + tqt_is_gui_used = TRUE; + tqt_appType = GuiClient; + init_precmdline(); + // ... no command line. + + if ( ! dpy ) { +#ifdef QT_CHECK_STATE + tqWarning( "TQApplication: invalid Display* argument." ); +#endif // QT_CHECK_STATE + + tqt_init( &aargc, aargv, GuiClient ); + } else { + tqt_init( dpy, visual, colormap ); + } + + initialize( aargc, aargv ); + + if ( tqt_is_gui_used ) + tqt_maxWindowRect = desktop()->rect(); + if ( currentEventLoop() ) + currentEventLoop()->appStartingUp(); +} + +/*! + Create an application, given an already open display \a dpy and using + \a argc command line arguments in \a argv. If \a + visual and \a colormap are non-zero, the application will use those as + the default Visual and Colormap contexts. + + \warning TQt only supports TrueColor visuals at depths higher than 8 + bits-per-pixel. + + This is available only on X11. + +*/ +TQApplication::TQApplication(Display *dpy, int argc, char **argv, + HANDLE visual, HANDLE colormap) +{ + tqt_appType = GuiClient; + tqt_is_gui_used = TRUE; + tqt_appType = GuiClient; + init_precmdline(); + + app_argc = argc; + app_argv = argv; + + if ( ! dpy ) { +#ifdef QT_CHECK_STATE + tqWarning( "TQApplication: invalid Display* argument." ); +#endif // QT_CHECK_STATE + + tqt_init( &argc, argv, GuiClient ); + } else { + tqt_init( &argc, argv, dpy, visual, colormap ); + } + + process_cmdline( &argc, argv ); + initialize(argc, argv); + + if ( tqt_is_gui_used ) + tqt_maxWindowRect = desktop()->rect(); + if ( currentEventLoop() ) + currentEventLoop()->appStartingUp(); +} + + +#endif // TQ_WS_X11 + +#ifdef TQT_THREAD_SUPPORT +TQThread* TQApplication::guiThread() { + return TQCoreApplicationThread::self(); +} + +bool TQApplication::isGuiThread() { + return (TQThread::currentThreadObject() == guiThread()); +} +#else +bool TQApplication::isGuiThread() { + return true; +} +#endif + +void TQApplication::init_precmdline() +{ + translators = 0; + is_app_closing = FALSE; +#ifndef TQT_NO_SESSIONMANAGER + is_session_restored = FALSE; +#endif +#if defined(QT_CHECK_STATE) + if ( tqApp ) + tqWarning( "TQApplication: There should be max one application object" ); +#endif + tqApp = (TQApplication*)this; +} + +/*! + Initializes the TQApplication object, called from the constructors. +*/ + +void TQApplication::initialize( int argc, char **argv, bool enable_sm ) +{ +#ifdef TQT_THREAD_SUPPORT + tqt_mutex = new TQMutex( TRUE ); + tqt_sharedStringMutex = new TQMutex( TRUE ); + tqt_sharedMetaObjectMutex = new TQMutex( TRUE ); +#ifdef QT_USE_GLIBMAINLOOP + tqt_timerListMutex = new TQMutex( TRUE ); +#endif // QT_USE_GLIBMAINLOOP + tqt_application_thread_id = TQThread::currentThread(); +#endif // TQT_THREAD_SUPPORT + + app_argc = argc; + app_argv = argv; + quit_now = FALSE; + quit_code = 0; + TQWidget::createMapper(); // create widget mapper +#ifndef TQT_NO_PALETTE + (void) palette(); // trigger creation of application palette +#endif + is_app_running = TRUE; // no longer starting up + +#ifndef TQT_NO_SESSIONMANAGER + if (enable_sm) { + // connect to the session manager + if ( !session_key ) + session_key = new TQString; + session_manager = new TQSessionManager( tqApp, session_id, *session_key ); + } + else { + session_manager = 0; + } +#endif + +} + + +/***************************************************************************** + Functions returning the active popup and modal widgets. + *****************************************************************************/ + +/*! + Returns the active popup widget. + + A popup widget is a special top level widget that sets the \c + WType_Popup widget flag, e.g. the TQPopupMenu widget. When the + application opens a popup widget, all events are sent to the popup. + Normal widgets and modal widgets cannot be accessed before the popup + widget is closed. + + Only other popup widgets may be opened when a popup widget is shown. + The popup widgets are organized in a stack. This function returns + the active popup widget at the top of the stack. + + \sa activeModalWidget(), topLevelWidgets() +*/ + +TQWidget *TQApplication::activePopupWidget() +{ + return popupWidgets ? popupWidgets->getLast() : 0; +} + + +/*! + Returns the active modal widget. + + A modal widget is a special top level widget which is a subclass of + TQDialog that specifies the modal parameter of the constructor as + TRUE. A modal widget must be closed before the user can continue + with other parts of the program. + + Modal widgets are organized in a stack. This function returns + the active modal widget at the top of the stack. + + \sa activePopupWidget(), topLevelWidgets() +*/ + +TQWidget *TQApplication::activeModalWidget() +{ + return tqt_modal_stack ? tqt_modal_stack->getFirst() : 0; +} + +/*! + Cleans up any window system resources that were allocated by this + application. Sets the global variable \c tqApp to 0. +*/ + +TQApplication::~TQApplication() +{ +#ifndef TQT_NO_CLIPBOARD + // flush clipboard contents + if ( tqt_clipboard ) { + TQCustomEvent event( TQEvent::Clipboard ); + TQApplication::sendEvent( tqt_clipboard, &event ); + } +#endif + + if ( currentEventLoop() ) + currentEventLoop()->appClosingDown(); + if ( postRList ) { + TQVFuncList::Iterator it = postRList->begin(); + while ( it != postRList->end() ) { // call post routines + (**it)(); + postRList->remove( it ); + it = postRList->begin(); + } + delete postRList; + postRList = 0; + } + + TQObject *tipmanager = child( "toolTipManager", "TQTipManager", FALSE ); + delete tipmanager; + + delete tqt_desktopWidget; + tqt_desktopWidget = 0; + is_app_closing = TRUE; + + // Due to hacks to speed up TQStyle engine (see git hash 523c1fd99) TQObjects now contain a + // reference to TQStyleControlElementData object which among other contain TQFont members. + // But for a proper cleanup all fonts should be destroyed before disconnecting from X11 (in + // tqt_cleanup()). So we will have to cleanup up the data explicitly. + cleanupControlElementData(); + +#ifndef TQT_NO_CLIPBOARD + delete tqt_clipboard; + tqt_clipboard = 0; +#endif + TQWidget::destroyMapper(); +#ifndef TQT_NO_PALETTE + delete tqt_std_pal; + tqt_std_pal = 0; + delete app_pal; + app_pal = 0; + delete app_palettes; + app_palettes = 0; +#endif + delete app_font; + app_font = 0; + delete app_fonts; + app_fonts = 0; +#ifndef TQT_NO_STYLE + delete app_style; + app_style = 0; +#endif +#ifndef TQT_NO_CURSOR + delete app_cursor; + app_cursor = 0; +#endif +#ifndef TQT_NO_TRANSLATION + delete translators; +#endif + +#ifndef TQT_NO_DRAGANDDROP + extern TQDragManager *qt_dnd_manager; + delete qt_dnd_manager; +#endif + + tqt_cleanup(); + +#ifndef TQT_NO_COMPONENT + delete app_libpaths; + app_libpaths = 0; +#endif + +#ifdef TQT_THREAD_SUPPORT + delete tqt_mutex; + tqt_mutex = 0; +#endif // TQT_THREAD_SUPPORT + + if( tqApp == this ) { + if ( postedEvents ) + removePostedEvents( this ); + tqApp = 0; + } + is_app_running = FALSE; + + if ( widgetCount ) { + tqDebug( "Widgets left: %i Max widgets: %i \n", TQWidget::instanceCounter, TQWidget::maxInstances ); + } +#ifndef TQT_NO_SESSIONMANAGER + if ( session_manager ) { + delete session_manager; + } + session_manager = 0; + if ( session_key ) { + delete session_key; + } + session_key = 0; +#endif //TQT_NO_SESSIONMANAGER + +#ifdef TQT_THREAD_SUPPORT + delete tqt_sharedMetaObjectMutex; + tqt_sharedMetaObjectMutex = 0; + delete tqt_sharedStringMutex; + tqt_sharedStringMutex = 0; +#ifdef QT_USE_GLIBMAINLOOP + delete tqt_timerListMutex; + tqt_timerListMutex = 0; +#endif // QT_USE_GLIBMAINLOOP +#endif // TQT_THREAD_SUPPORT + + tqt_explicit_app_style = FALSE; + tqt_app_has_font = FALSE; + app_tracking = 0; + obey_desktop_settings = TRUE; + cursor_flash_time = 1000; + mouse_double_click_time = 400; +#ifndef TQT_NO_WHEELEVENT + wheel_scroll_lines = 3; +#endif + drag_time = 500; + drag_distance = 4; + reverse_layout = FALSE; + app_strut = TQSize( 0, 0 ); + animate_ui = TRUE; + animate_menu = FALSE; + fade_menu = FALSE; + animate_combo = FALSE; + animate_tooltip = FALSE; + fade_tooltip = FALSE; + widgetCount = FALSE; +} + + +/*! + \fn int TQApplication::argc() const + + Returns the number of command line arguments. + + The documentation for argv() describes how to process command line + arguments. + + \sa argv(), TQApplication::TQApplication() +*/ + +/*! + \fn char **TQApplication::argv() const + + Returns the command line argument vector. + + \c argv()[0] is the program name, \c argv()[1] is the first + argument and \c argv()[argc()-1] is the last argument. + + A TQApplication object is constructed by passing \e argc and \e + argv from the \c main() function. Some of the arguments may be + recognized as TQt options and removed from the argument vector. For + example, the X11 version of TQt knows about \c -display, \c -font + and a few more options. + + Example: + \code + // showargs.cpp - displays program arguments in a list box + + #include + #include + + int main( int argc, char **argv ) + { + TQApplication a( argc, argv ); + TQListBox b; + a.setMainWidget( &b ); + for ( int i = 0; i < a.argc(); i++ ) // a.argc() == argc + b.insertItem( a.argv()[i] ); // a.argv()[i] == argv[i] + b.show(); + return a.exec(); + } + \endcode + + If you run \c{showargs -display unix:0 -font 9x15bold hello world} + under X11, the list box contains the three strings "showargs", + "hello" and "world". + + TQt provides a global pointer, \c tqApp, that points to the + TQApplication object, and through which you can access argc() and + argv() in functions other than main(). + + \sa argc(), TQApplication::TQApplication() +*/ + +/*! + \fn void TQApplication::setArgs( int argc, char **argv ) + \internal +*/ + + +#ifndef TQT_NO_STYLE + +static TQString *qt_style_override = 0; + +/*! + Returns the application's style object. + + \sa setStyle(), TQStyle +*/ +TQStyle& TQApplication::style() +{ +#ifndef TQT_NO_STYLE + if ( app_style ) + return *app_style; + if ( !tqt_is_gui_used ) + tqFatal( "No style available in non-gui applications!" ); + +#if defined(TQ_WS_X11) + if(!qt_style_override) + x11_initialize_style(); // run-time search for default style +#endif + if ( !app_style ) { + // Compile-time search for default style + // + TQString style; + if ( qt_style_override ) { + style = *qt_style_override; + delete qt_style_override; + qt_style_override = 0; + } else { +# if defined(TQ_WS_WIN) && defined(Q_OS_TEMP) + style = "PocketPC"; +#elif defined(TQ_WS_WIN) + if ( qWinVersion() >= TQt::WV_XP && qWinVersion() < TQt::WV_NT_based ) + style = "WindowsXP"; + else + style = "Windows"; // default styles for Windows +#elif defined(TQ_WS_X11) && defined(Q_OS_SOLARIS) + style = "CDE"; // default style for X11 on Solaris +#elif defined(TQ_WS_X11) && defined(Q_OS_IRIX) + style = "SGI"; // default style for X11 on IRIX +#elif defined(TQ_WS_X11) + style = "Motif"; // default style for X11 +#elif defined(TQ_WS_MAC) + style = "Macintosh"; // default style for all Mac's +#endif + } + app_style = TQStyleFactory::create( style ); + if ( !app_style && // platform default style not available, try alternatives + !(app_style = TQStyleFactory::create( "Windows" ) ) && + !(app_style = TQStyleFactory::create( "Platinum" ) ) && + !(app_style = TQStyleFactory::create( "MotifPlus" ) ) && + !(app_style = TQStyleFactory::create( "Motif" ) ) && + !(app_style = TQStyleFactory::create( "CDE" ) ) && + !(app_style = TQStyleFactory::create( "Aqua" ) ) && + !(app_style = TQStyleFactory::create( "SGI" ) ) && + !(app_style = TQStyleFactory::create( "Compact" ) ) +#ifndef TQT_NO_STRINGLIST + && !(app_style = TQStyleFactory::create( TQStyleFactory::keys()[0] ) ) +#endif + ) + tqFatal( "No %s style available!", style.latin1() ); + } + + TQPalette app_pal_copy ( *app_pal ); + app_style->polish( *app_pal ); + + if ( is_app_running && !is_app_closing && (*app_pal != app_pal_copy) ) { + TQEvent e( TQEvent::ApplicationPaletteChange ); + TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); + TQWidget *w; + while ( (w=it.current()) ) { // for all widgets... + ++it; + sendEvent( w, &e ); + } + } + + app_style->polish( tqApp ); +#endif + return *app_style; +} + +/*! + Sets the application's GUI style to \a style. Ownership of the style + object is transferred to TQApplication, so TQApplication will delete + the style object on application exit or when a new style is set. + + Example usage: + \code + TQApplication::setStyle( new TQWindowsStyle ); + \endcode + + When switching application styles, the color palette is set back to + the initial colors or the system defaults. This is necessary since + certain styles have to adapt the color palette to be fully + style-guide compliant. + + \sa style(), TQStyle, setPalette(), desktopSettingsAware() +*/ +void TQApplication::setStyle( TQStyle *style ) +{ + TQStyle* old = app_style; + app_style = style; +#ifdef TQ_WS_X11 + tqt_explicit_app_style = TRUE; +#endif // TQ_WS_X11 + + if ( startingUp() ) { + delete old; + return; + } + + // clean up the old style + if (old) { + if ( is_app_running && !is_app_closing ) { + TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); + TQWidget *w; + while ( (w=it.current()) ) { // for all widgets... + ++it; + if ( !w->testWFlags(WType_Desktop) && // except desktop + w->testWState(WState_Polished) ) { // has been polished + old->unPolish(w); + } + } + } + old->unPolish( tqApp ); + } + + // take care of possible palette requirements of certain gui + // styles. Do it before polishing the application since the style + // might call TQApplication::setStyle() itself + if ( !tqt_std_pal ) + tqt_create_std_palette(); + TQPalette tmpPal = *tqt_std_pal; + setPalette( tmpPal, TRUE ); + + // initialize the application with the new style + app_style->polish( tqApp ); + + // re-polish existing widgets if necessary + if (old) { + if ( is_app_running && !is_app_closing ) { + TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); + TQWidget *w; + while ( (w=it.current()) ) { // for all widgets... + ++it; + if ( !w->testWFlags(WType_Desktop) ) { // except desktop + if ( w->testWState(WState_Polished) ) + app_style->polish(w); // repolish + w->styleChange( *old ); + if ( w->isVisible() ){ + w->update(); + } + } + } + } + delete old; + } +} + +/*! + \overload + + Requests a TQStyle object for \a style from the TQStyleFactory. + + The string must be one of the TQStyleFactory::keys(), typically one + of "windows", "motif", "cde", "motifplus", "platinum", "sgi" and + "compact". Depending on the platform, "windowsxp", "aqua" or + "macintosh" may be available. + + A later call to the TQApplication constructor will override the + requested style when a "-style" option is passed in as a commandline + parameter. + + Returns 0 if an unknown \a style is passed, otherwise the TQStyle object + returned is set as the application's GUI style. +*/ +TQStyle* TQApplication::setStyle( const TQString& style ) +{ +#ifdef TQ_WS_X11 + tqt_explicit_app_style = TRUE; +#endif // TQ_WS_X11 + + if ( startingUp() ) { + if(qt_style_override) + *qt_style_override = style; + else + qt_style_override = new TQString(style); + return 0; + } + TQStyle *s = TQStyleFactory::create( style ); + if ( !s ) + return 0; + + setStyle( s ); + return s; +} + +#endif + + +#if 1 /* OBSOLETE */ + +TQApplication::ColorMode TQApplication::colorMode() +{ + return (TQApplication::ColorMode)app_cspec; +} + +void TQApplication::setColorMode( TQApplication::ColorMode mode ) +{ + app_cspec = mode; +} +#endif + + +/*! + Returns the color specification. + \sa TQApplication::setColorSpec() + */ + +int TQApplication::colorSpec() +{ + return app_cspec; +} + +/*! + Sets the color specification for the application to \a spec. + + The color specification controls how the application allocates colors + when run on a display with a limited amount of colors, e.g. 8 bit / 256 + color displays. + + The color specification must be set before you create the TQApplication + object. + + The options are: + \list + \i TQApplication::NormalColor. + This is the default color allocation strategy. Use this option if + your application uses buttons, menus, texts and pixmaps with few + colors. With this option, the application uses system global + colors. This works fine for most applications under X11, but on + Windows machines it may cause dithering of non-standard colors. + \i TQApplication::CustomColor. + Use this option if your application needs a small number of custom + colors. On X11, this option is the same as NormalColor. On Windows, TQt + creates a Windows palette, and allocates colors to it on demand. + \i TQApplication::ManyColor. + Use this option if your application is very color hungry + (e.g. it requires thousands of colors). + Under X11 the effect is: + \list + \i For 256-color displays which have at best a 256 color true color + visual, the default visual is used, and colors are allocated + from a color cube. The color cube is the 6x6x6 (216 color) "Web + palette"*, but the number of colors can be changed + by the \e -ncols option. The user can force the application to + use the true color visual with the \link + TQApplication::TQApplication() -visual \endlink option. + \i For 256-color displays which have a true color visual with more + than 256 colors, use that visual. Silicon Graphics X servers + have this feature, for example. They provide an 8 bit visual + by default but can deliver true color when asked. + \endlist + On Windows, TQt creates a Windows palette, and fills it with a color cube. + \endlist + + Be aware that the CustomColor and ManyColor choices may lead to colormap + flashing: The foreground application gets (most) of the available + colors, while the background windows will look less attractive. + + Example: + \code + int main( int argc, char **argv ) + { + TQApplication::setColorSpec( TQApplication::ManyColor ); + TQApplication a( argc, argv ); + ... + } + \endcode + + TQColor provides more functionality for controlling color allocation and + freeing up certain colors. See TQColor::enterAllocContext() for more + information. + + To check what mode you end up with, call TQColor::numBitPlanes() once + the TQApplication object exists. A value greater than 8 (typically + 16, 24 or 32) means true color. + + * The color cube used by TQt has 216 colors whose red, + green, and blue components always have one of the following values: + 0x00, 0x33, 0x66, 0x99, 0xCC, or 0xFF. + + \sa colorSpec(), TQColor::numBitPlanes(), TQColor::enterAllocContext() */ + +void TQApplication::setColorSpec( int spec ) +{ +#if defined(QT_CHECK_STATE) + if ( tqApp ) { + tqWarning( "TQApplication::setColorSpec: This function must be " + "called before the TQApplication object is created" ); + } +#endif + app_cspec = spec; +} + +/*! + \fn TQSize TQApplication::globalStrut() + + Returns the application's global strut. + + The strut is a size object whose dimensions are the minimum that any + GUI element that the user can interact with should have. For example + no button should be resized to be smaller than the global strut size. + + \sa setGlobalStrut() +*/ + +/*! + Sets the application's global strut to \a strut. + + The strut is a size object whose dimensions are the minimum that any + GUI element that the user can interact with should have. For example + no button should be resized to be smaller than the global strut size. + + The strut size should be considered when reimplementing GUI controls + that may be used on touch-screens or similar IO-devices. + + Example: + \code + TQSize& WidgetClass::sizeHint() const + { + return TQSize( 80, 25 ).expandedTo( TQApplication::globalStrut() ); + } + \endcode + + \sa globalStrut() +*/ + +void TQApplication::setGlobalStrut( const TQSize& strut ) +{ + app_strut = strut; +} + +#if defined( TQ_WS_WIN ) || defined( TQ_WS_MAC ) +extern const char *tqAppFileName(); +#endif + +#ifndef TQT_NO_DIR +#ifndef TQ_WS_WIN +static TQString resolveSymlinks( const TQString& path, int depth = 0 ) +{ + bool foundLink = FALSE; + TQString linkTarget; + TQString part = path; + int slashPos = path.length(); + + // too deep; we give up + if ( depth == 128 ) + return TQString::null; + + do { + part = part.left( slashPos ); + TQFileInfo fileInfo( part ); + if ( fileInfo.isSymLink() ) { + foundLink = TRUE; + linkTarget = fileInfo.readLink(); + break; + } + } while ( (slashPos = part.findRev('/')) != -1 ); + + if ( foundLink ) { + TQString path2; + if ( linkTarget[0] == '/' ) { + path2 = linkTarget; + if ( slashPos < (int) path.length() ) + path2 += "/" + path.right( path.length() - slashPos - 1 ); + } else { + TQString relPath; + relPath = part.left( part.findRev('/') + 1 ) + linkTarget; + if ( slashPos < (int) path.length() ) { + if ( !linkTarget.endsWith( "/" ) ) + relPath += "/"; + relPath += path.right( path.length() - slashPos - 1 ); + } + path2 = TQDir::current().absFilePath( relPath ); + } + path2 = TQDir::cleanDirPath( path2 ); + return resolveSymlinks( path2, depth + 1 ); + } else { + return path; + } +} +#endif // TQ_WS_WIN + +/*! + Returns the directory that contains the application executable. + + For example, if you have installed TQt in the \c{C:\Trolltech\TQt} + directory, and you run the \c{demo} example, this function will + return "C:/Trolltech/TQt/examples/demo". + + On Mac OS X this will point to the directory actually containing the + executable, which may be inside of an application bundle (if the + application is bundled). + + \warning On Unix, this function assumes that argv[0] contains the file + name of the executable (which it normally does). It also assumes that + the current directory hasn't been changed by the application. + + \sa applicationFilePath() +*/ +TQString TQApplication::applicationDirPath() +{ + return TQFileInfo( applicationFilePath() ).dirPath(); +} + +/*! + Returns the file path of the application executable. + + For example, if you have installed TQt in the \c{C:\Trolltech\TQt} + directory, and you run the \c{demo} example, this function will + return "C:/Trolltech/TQt/examples/demo/demo.exe". + + \warning On Unix, this function assumes that argv[0] contains the file + name of the executable (which it normally does). It also assumes that + the current directory hasn't been changed by the application. + + \sa applicationDirPath() +*/ +TQString TQApplication::applicationFilePath() +{ +#if defined( TQ_WS_WIN ) + TQFileInfo filePath; + QT_WA({ + WCHAR module_name[256]; + GetModuleFileNameW(0, module_name, sizeof(module_name)); + filePath = TQString::fromUcs2((const unsigned short *)module_name); + }, { + char module_name[256]; + GetModuleFileNameA(0, module_name, sizeof(module_name)); + filePath = TQString::fromLocal8Bit(module_name); + }); + + return filePath.filePath(); +#elif defined( TQ_WS_MAC ) + return TQDir::cleanDirPath( TQFile::decodeName( tqAppFileName() ) ); +#else + TQString argv0 = TQFile::decodeName( argv()[0] ); + TQString absPath; + + if ( argv0[0] == '/' ) { + /* + If argv0 starts with a slash, it is already an absolute + file path. + */ + absPath = argv0; + } else if ( argv0.find('/') != -1 ) { + /* + If argv0 contains one or more slashes, it is a file path + relative to the current directory. + */ + absPath = TQDir::current().absFilePath( argv0 ); + } else { + /* + Otherwise, the file path has to be determined using the + PATH environment variable. + */ + char *pEnv = getenv( "PATH" ); + TQStringList paths( TQStringList::split(TQChar(':'), pEnv) ); + TQStringList::const_iterator p = paths.begin(); + while ( p != paths.end() ) { + TQString candidate = TQDir::current().absFilePath( *p + "/" + argv0 ); + if ( TQFile::exists(candidate) ) { + absPath = candidate; + break; + } + ++p; + } + } + + absPath = TQDir::cleanDirPath( absPath ); + if ( TQFile::exists(absPath) ) { + return resolveSymlinks( absPath ); + } else { + return TQString::null; + } +#endif +} +#endif // TQT_NO_DIR + +#ifndef TQT_NO_COMPONENT + +/*! + Returns a list of paths that the application will search when + dynamically loading libraries. + The installation directory for plugins is the only entry if no + paths have been set. The default installation directory for plugins + is \c INSTALL/plugins, where \c INSTALL is the directory where TQt was + installed. The directory of the application executable (NOT the + working directory) is also added to the plugin paths. + + If you want to iterate over the list, you should iterate over a + copy, e.g. + \code + TQStringList list = app.libraryPaths(); + TQStringList::Iterator it = list.begin(); + while( it != list.end() ) { + myProcessing( *it ); + ++it; + } + \endcode + + See the \link plugins-howto.html plugins documentation\endlink for a + description of how the library paths are used. + + \sa setLibraryPaths(), addLibraryPath(), removeLibraryPath(), TQLibrary +*/ +TQStringList TQApplication::libraryPaths() +{ + if ( !app_libpaths ) { + app_libpaths = new TQStringList; + TQString installPathPlugins = TQString::fromLocal8Bit(tqInstallPathPlugins()); + if ( TQFile::exists(installPathPlugins) ) { +#ifdef TQ_WS_WIN + installPathPlugins.replace('\\', '/'); +#endif + app_libpaths->append(installPathPlugins); + } + + TQString app_location; + if (tqApp) + app_location = tqApp->applicationFilePath(); +#ifdef TQ_WS_WIN + else { + app_location = TQString(tqAppFileName()); + app_location.replace('\\', '/'); + } +#endif + if (!app_location.isEmpty()) { + app_location.truncate( app_location.findRev( '/' ) ); + if ( app_location != tqInstallPathPlugins() && TQFile::exists( app_location ) ) + app_libpaths->append( app_location ); + } + } + return *app_libpaths; +} + + +/*! + Sets the list of directories to search when loading libraries to \a paths. + All existing paths will be deleted and the path list will consist of the + paths given in \a paths. + + \sa libraryPaths(), addLibraryPath(), removeLibraryPath(), TQLibrary + */ +void TQApplication::setLibraryPaths( const TQStringList &paths ) +{ + delete app_libpaths; + app_libpaths = new TQStringList( paths ); +} + +/*! + Append \a path to the end of the library path list. If \a path is + empty or already in the path list, the path list is not changed. + + The default path list consists of a single entry, the installation + directory for plugins. The default installation directory for plugins + is \c INSTALL/plugins, where \c INSTALL is the directory where TQt was + installed. + + \sa removeLibraryPath(), libraryPaths(), setLibraryPaths() + */ +void TQApplication::addLibraryPath( const TQString &path ) +{ + if ( path.isEmpty() ) + return; + + // make sure that library paths is initialized + libraryPaths(); + + if ( !app_libpaths->contains( path ) ) + app_libpaths->prepend( path ); +} + +/*! + Removes \a path from the library path list. If \a path is empty or not + in the path list, the list is not changed. + + \sa addLibraryPath(), libraryPaths(), setLibraryPaths() +*/ +void TQApplication::removeLibraryPath( const TQString &path ) +{ + if ( path.isEmpty() ) + return; + + // make sure that library paths is initialized + libraryPaths(); + + if ( app_libpaths->contains( path ) ) + app_libpaths->remove( path ); +} +#endif //TQT_NO_COMPONENT + +/*! + Returns the application palette. + + If a widget is passed in \a w, the default palette for the + widget's class is returned. This may or may not be the application + palette. In most cases there isn't a special palette for certain + types of widgets, but one notable exception is the popup menu under + Windows, if the user has defined a special background color for + menus in the display settings. + + \sa setPalette(), TQWidget::palette() +*/ +#ifndef TQT_NO_PALETTE +TQPalette TQApplication::palette(const TQWidget* w) +{ +#if defined(QT_CHECK_STATE) + if ( !tqApp ) + tqWarning( "TQApplication::palette: This function can only be " + "called after the TQApplication object has been created" ); +#endif + if ( !app_pal ) { + if ( !tqt_std_pal ) + tqt_create_std_palette(); + app_pal = new TQPalette( *tqt_std_pal ); + tqt_fix_tooltips(); + } + + if ( w && app_palettes ) { + TQPalette* wp = app_palettes->find( w->className() ); + if ( wp ) + return *wp; + TQAsciiDictIterator it( *app_palettes ); + const char* name; + while ( (name=it.currentKey()) != 0 ) { + if ( w->inherits( name ) ) + return *it.current(); + ++it; + } + } + return *app_pal; +} + +TQPalette TQApplication::palette(TQStringList objectTypeList) +{ +#if defined(QT_CHECK_STATE) + if ( !tqApp ) + tqWarning( "TQApplication::palette: This function can only be " + "called after the TQApplication object has been created" ); +#endif + if ( !app_pal ) { + if ( !tqt_std_pal ) + tqt_create_std_palette(); + app_pal = new TQPalette( *tqt_std_pal ); + tqt_fix_tooltips(); + } + + if ( (objectTypeList.count() > 0) && app_palettes ) { + TQPalette* wp = app_palettes->find( objectTypeList[objectTypeList.count()-1] ); + if ( wp ) { + return *wp; + } + TQAsciiDictIterator it( *app_palettes ); + const char* name; + while ( (name=it.currentKey()) != 0 ) { + if ( objectTypeList.contains(name) ) { + return *it.current(); + } + ++it; + } + } + return *app_pal; +} + +/*! + Changes the default application palette to \a palette. If \a + informWidgets is TRUE, then existing widgets are informed about the + change and may adjust themselves to the new application + setting. If \a informWidgets is FALSE, the change only affects newly + created widgets. + + If \a className is passed, the change applies only to widgets that + inherit \a className (as reported by TQObject::inherits()). If + \a className is left 0, the change affects all widgets, thus overriding + any previously set class specific palettes. + + The palette may be changed according to the current GUI style in + TQStyle::polish(). + + \sa TQWidget::setPalette(), palette(), TQStyle::polish() +*/ + +void TQApplication::setPalette( const TQPalette &palette, bool informWidgets, + const char* className ) +{ + TQPalette pal = palette; + TQPalette *oldpal = 0; +#ifndef TQT_NO_STYLE + if ( !startingUp() ) // on startup this has been done already + tqApp->style().polish( pal ); // NB: non-const reference +#endif + bool all = FALSE; + if ( !className ) { + if ( !app_pal ) { + app_pal = new TQPalette( pal ); + TQ_CHECK_PTR( app_pal ); + } else { + *app_pal = pal; + } + all = app_palettes != 0; + delete app_palettes; + app_palettes = 0; + tqt_fix_tooltips(); + } else { + if ( !app_palettes ) { + app_palettes = new TQAsciiDict; + TQ_CHECK_PTR( app_palettes ); + app_palettes->setAutoDelete( TRUE ); + } + oldpal = app_palettes->find( className ); + app_palettes->insert( className, new TQPalette( pal ) ); + } + if ( informWidgets && is_app_running && !is_app_closing ) { + if ( !oldpal || ( *oldpal != pal ) ) { + TQEvent e( TQEvent::ApplicationPaletteChange ); + TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); + TQWidget *w; + while ( (w=it.current()) ) { // for all widgets... + ++it; + if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class + sendEvent( w, &e ); + } + } + } +} + +#endif // TQT_NO_PALETTE + +/*! + Returns the default font for the widget \a w, or the default + application font if \a w is 0. + + \sa setFont(), fontMetrics(), TQWidget::font() +*/ + +TQFont TQApplication::font( const TQWidget *w ) +{ + if ( w && app_fonts ) { + TQFont* wf = app_fonts->find( w->className() ); + if ( wf ) + return *wf; + TQAsciiDictIterator it( *app_fonts ); + const char* name; + while ( (name=it.currentKey()) != 0 ) { + if ( w->inherits( name ) ) + return *it.current(); + ++it; + } + } + if ( !app_font ) { + app_font = new TQFont( "Helvetica" ); + TQ_CHECK_PTR( app_font ); + } + return *app_font; +} + +/*! Changes the default application font to \a font. If \a + informWidgets is TRUE, then existing widgets are informed about the + change and may adjust themselves to the new application + setting. If \a informWidgets is FALSE, the change only affects newly + created widgets. If \a className is passed, the change applies only + to classes that inherit \a className (as reported by + TQObject::inherits()). + + On application start-up, the default font depends on the window + system. It can vary depending on both the window system version and + the locale. This function lets you override the default font; but + overriding may be a bad idea because, for example, some locales need + extra-large fonts to support their special characters. + + \sa font(), fontMetrics(), TQWidget::setFont() +*/ + +void TQApplication::setFont( const TQFont &font, bool informWidgets, + const char* className ) +{ + bool all = FALSE; + if ( !className ) { + tqt_app_has_font = TRUE; + if ( !app_font ) { + app_font = new TQFont( font ); + TQ_CHECK_PTR( app_font ); + } else { + *app_font = font; + } + + // make sure the application font is complete + app_font->detach(); + app_font->d->mask = TQFontPrivate::Complete; + + all = app_fonts != 0; + delete app_fonts; + app_fonts = 0; + } else { + if (!app_fonts){ + app_fonts = new TQAsciiDict; + TQ_CHECK_PTR( app_fonts ); + app_fonts->setAutoDelete( TRUE ); + } + TQFont* fnt = new TQFont(font); + TQ_CHECK_PTR( fnt ); + app_fonts->insert(className, fnt); + } + if ( informWidgets && is_app_running && !is_app_closing ) { + TQEvent e( TQEvent::ApplicationFontChange ); + TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); + TQWidget *w; + while ( (w=it.current()) ) { // for all widgets... + ++it; + if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class + sendEvent( w, &e ); + } + } +} + + +/*! + Initialization of the appearance of the widget \a w \e before it is first + shown. + + Usually widgets call this automatically when they are polished. It + may be used to do some style-based central customization of widgets. + + Note that you are not limited to the public functions of TQWidget. + Instead, based on meta information like TQObject::className() you are + able to customize any kind of widget. + + \sa TQStyle::polish(), TQWidget::polish(), setPalette(), setFont() +*/ + +void TQApplication::polish( TQWidget *w ) +{ +#ifndef TQT_NO_STYLE + w->style().polish( w ); +#endif +} + + +/*! + Returns a list of the top level widgets in the application. + + The list is created using \c new and must be deleted by the caller. + + The list is empty (TQPtrList::isEmpty()) if there are no top level + widgets. + + Note that some of the top level widgets may be hidden, for example + the tooltip if no tooltip is currently shown. + + Example: + \code + // Show all hidden top level widgets. + TQWidgetList *list = TQApplication::topLevelWidgets(); + TQWidgetListIt it( *list ); // iterate over the widgets + TQWidget * w; + while ( (w=it.current()) != 0 ) { // for each top level widget... + ++it; + if ( !w->isVisible() ) + w->show(); + } + delete list; // delete the list, not the widgets + \endcode + + \warning Delete the list as soon you have finished using it. + The widgets in the list may be deleted by someone else at any time. + + \sa allWidgets(), TQWidget::isTopLevel(), TQWidget::isVisible(), + TQPtrList::isEmpty() +*/ + +TQWidgetList *TQApplication::topLevelWidgets() +{ + return TQWidget::tlwList(); +} + +/*! + Returns a list of all the widgets in the application. + + The list is created using \c new and must be deleted by the caller. + + The list is empty (TQPtrList::isEmpty()) if there are no widgets. + + Note that some of the widgets may be hidden. + + Example that updates all widgets: + \code + TQWidgetList *list = TQApplication::allWidgets(); + TQWidgetListIt it( *list ); // iterate over the widgets + TQWidget * w; + while ( (w=it.current()) != 0 ) { // for each widget... + ++it; + w->update(); + } + delete list; // delete the list, not the widgets + \endcode + + The TQWidgetList class is defined in the \c tqwidgetlist.h header + file. + + \warning Delete the list as soon as you have finished using it. + The widgets in the list may be deleted by someone else at any time. + + \sa topLevelWidgets(), TQWidget::isVisible(), TQPtrList::isEmpty(), +*/ + +TQWidgetList *TQApplication::allWidgets() +{ + return TQWidget::wList(); +} + +/*! + \fn TQWidget *TQApplication::focusWidget() const + + Returns the application widget that has the keyboard input focus, or + 0 if no widget in this application has the focus. + + \sa TQWidget::setFocus(), TQWidget::hasFocus(), activeWindow() +*/ + +/*! + \fn TQWidget *TQApplication::activeWindow() const + + Returns the application top-level window that has the keyboard input + focus, or 0 if no application window has the focus. Note that + there might be an activeWindow() even if there is no focusWidget(), + for example if no widget in that window accepts key events. + + \sa TQWidget::setFocus(), TQWidget::hasFocus(), focusWidget() +*/ + +/*! + Returns display (screen) font metrics for the application font. + + \sa font(), setFont(), TQWidget::fontMetrics(), TQPainter::fontMetrics() +*/ + +TQFontMetrics TQApplication::fontMetrics() +{ + return desktop()->fontMetrics(); +} + + + +/*! + Tells the application to exit with return code 0 (success). + Equivalent to calling TQApplication::exit( 0 ). + + It's common to connect the lastWindowClosed() signal to quit(), and + you also often connect e.g. TQButton::clicked() or signals in + TQAction, TQPopupMenu or TQMenuBar to it. + + Example: + \code + TQPushButton *quitButton = new TQPushButton( "Quit" ); + connect( quitButton, TQ_SIGNAL(clicked()), tqApp, TQ_SLOT(quit()) ); + \endcode + + \sa exit() aboutToQuit() lastWindowClosed() TQAction +*/ + +void TQApplication::quit() +{ + TQApplication::exit( 0 ); +} + + +/*! + Closes all top-level windows. + + This function is particularly useful for applications with many + top-level windows. It could, for example, be connected to a "Quit" + entry in the file menu as shown in the following code example: + + \code + // the "Quit" menu entry should try to close all windows + TQPopupMenu* file = new TQPopupMenu( this ); + file->insertItem( "&Quit", tqApp, TQ_SLOT(closeAllWindows()), CTRL+Key_Q ); + + // when the last window is closed, the application should quit + connect( tqApp, TQ_SIGNAL( lastWindowClosed() ), tqApp, TQ_SLOT( quit() ) ); + \endcode + + The windows are closed in random order, until one window does not + accept the close event. + + \sa TQWidget::close(), TQWidget::closeEvent(), lastWindowClosed(), + quit(), topLevelWidgets(), TQWidget::isTopLevel() + + */ +void TQApplication::closeAllWindows() +{ + bool did_close = TRUE; + TQWidget *w; + while((w = activeModalWidget()) && did_close) { + if(w->isHidden()) + break; + did_close = w->close(); + } + TQWidgetList *list = TQApplication::topLevelWidgets(); + for ( w = list->first(); did_close && w; ) { + if ( !w->isHidden() ) { + did_close = w->close(); + delete list; + list = TQApplication::topLevelWidgets(); + w = list->first(); + } else { + w = list->next(); + } + } + delete list; +} + +/*! + Displays a simple message box about TQt. The message includes the + version number of TQt being used by the application. + + This is useful for inclusion in the Help menu of an application. + See the examples/menu/menu.cpp example. + + This function is a convenience slot for TQMessageBox::aboutTQt(). +*/ +void TQApplication::aboutTQt() +{ +#ifndef TQT_NO_MESSAGEBOX + TQMessageBox::aboutTQt( mainWidget() ); +#endif // TQT_NO_MESSAGEBOX +} + + +/*! + \fn void TQApplication::lastWindowClosed() + + This signal is emitted when the user has closed the last + top level window. + + The signal is very useful when your application has many top level + widgets but no main widget. You can then connect it to the quit() + slot. + + For convenience, this signal is \e not emitted for transient top level + widgets such as popup menus and dialogs. + + \sa mainWidget(), topLevelWidgets(), TQWidget::isTopLevel(), TQWidget::close() +*/ + +/*! + \fn void TQApplication::aboutToQuit() + + This signal is emitted when the application is about to quit the + main event loop, e.g. when the event loop level drops to zero. + This may happen either after a call to quit() from inside the + application or when the users shuts down the entire desktop session. + + The signal is particularly useful if your application has to do some + last-second cleanup. Note that no user interaction is possible in + this state. + + \sa quit() +*/ + + +/*! + \fn void TQApplication::guiThreadAwake() + + This signal is emitted after the event loop returns from a function + that could block. + + \sa wakeUpGuiThread() +*/ + + +/*! + \fn bool TQApplication::sendEvent( TQObject *receiver, TQEvent *event ) + + Sends event \a event directly to receiver \a receiver, using the + notify() function. Returns the value that was returned from the event + handler. + + The event is \e not deleted when the event has been sent. The normal + approach is to create the event on the stack, e.g. + \code + TQMouseEvent me( TQEvent::MouseButtonPress, pos, 0, 0 ); + TQApplication::sendEvent( mainWindow, &me ); + \endcode + If you create the event on the heap you must delete it. + + \sa postEvent(), notify() +*/ + +bool TQApplication::sendEvent( TQObject *receiver, TQEvent *event ) { + if ( event ) event->spont = FALSE; + return tqApp ? tqApp->notify( receiver, event ) : FALSE; +} + +bool TQApplication::sendSpontaneousEvent( TQObject *receiver, TQEvent *event ) { + if ( event ) event->spont = TRUE; + return tqApp ? tqApp->notify( receiver, event ) : FALSE; +} + +/*! + Sends event \a e to \a receiver: \a {receiver}->event(\a e). + Returns the value that is returned from the receiver's event handler. + + For certain types of events (e.g. mouse and key events), + the event will be propagated to the receiver's parent and so on up to + the top-level object if the receiver is not interested in the event + (i.e., it returns FALSE). + + There are five different ways that events can be processed; + reimplementing this virtual function is just one of them. All five + approaches are listed below: + \list 1 + \i Reimplementing this function. This is very powerful, providing + complete control; but only one subclass can be tqApp. + + \i Installing an event filter on tqApp. Such an event filter is able + to process all events for all widgets, so it's just as powerful as + reimplementing notify(); furthermore, it's possible to have more + than one application-global event filter. Global event filters even + see mouse events for \link TQWidget::isEnabled() disabled + widgets, \endlink and if \link setGlobalMouseTracking() global mouse + tracking \endlink is enabled, as well as mouse move events for all + widgets. + + \i Reimplementing TQObject::event() (as TQWidget does). If you do + this you get Tab key presses, and you get to see the events before + any widget-specific event filters. + + \i Installing an event filter on the object. Such an event filter + gets all the events except Tab and Shift-Tab key presses. + + \i Reimplementing paintEvent(), mousePressEvent() and so + on. This is the commonest, easiest and least powerful way. + \endlist + + \sa TQObject::event(), installEventFilter() +*/ + +bool TQApplication::notify( TQObject *receiver, TQEvent *e ) +{ + // no events are delivered after ~TQApplication() has started + if ( is_app_closing ) { + return FALSE; + } + + if ( receiver == 0 ) { // serious error +#if defined(QT_CHECK_NULL) + tqWarning( "TQApplication::notify: Unexpected null receiver" ); +#endif + return FALSE; + } + + if ( receiver && (e->type() == TQEvent::Destroy) ) { + return TRUE; + } + + if ( e->type() == TQEvent::ChildRemoved && receiver->postedEvents) { +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( GlobalPostedEvents()->mutex() ); +#endif // TQT_THREAD_SUPPORT + + // the TQObject destructor calls TQObject::removeChild, which calls + // TQApplication::sendEvent() directly. this can happen while the event + // loop is in the middle of posting events, and when we get here, we may + // not have any more posted events for this object. + if ( receiver->postedEvents ) { + // if this is a child remove event and the child insert + // hasn't been dispatched yet, kill that insert + TQPostEventList * l = receiver->postedEvents; + TQObject * c = ((TQChildEvent*)e)->child(); + TQPostEvent * pe; + l->first(); + while( ( pe = l->current()) != 0 ) { + if ( pe->event && pe->receiver == receiver && + pe->event->type() == TQEvent::ChildInserted && + ((TQChildEvent*)pe->event)->child() == c ) { + pe->event->posted = FALSE; + delete pe->event; + pe->event = 0; + l->remove(); + continue; + } + l->next(); + } + } + } + + bool res = FALSE; + if ( !receiver->isWidgetType() ) { + res = internalNotify( receiver, e ); + } + else switch ( e->type() ) { +#ifndef TQT_NO_ACCEL + case TQEvent::Accel: + { + TQKeyEvent* key = (TQKeyEvent*) e; + res = internalNotify( receiver, e ); + + if ( !res && !key->isAccepted() ) { + res = tqt_dispatchAccelEvent( (TQWidget*)receiver, key ); + } + + // next lines are for compatibility with TQt <= 3.0.x: old + // TQAccel was listening on toplevel widgets + if ( !res && !key->isAccepted() && !((TQWidget*)receiver)->isTopLevel() ) { + res = internalNotify( ((TQWidget*)receiver)->topLevelWidget(), e ); + } + } + break; +#endif //TQT_NO_ACCEL + case TQEvent::KeyPress: + case TQEvent::KeyRelease: + case TQEvent::AccelOverride: + { + TQWidget* w = (TQWidget*)receiver; + TQKeyEvent* key = (TQKeyEvent*) e; +#ifndef TQT_NO_ACCEL + if ( tqt_tryComposeUnicode( w, key ) ) + break; +#endif + bool def = key->isAccepted(); + while ( w ) { + if ( def ) + key->accept(); + else + key->ignore(); + res = internalNotify( w, e ); + if ( res || key->isAccepted() ) + break; + w = w->parentWidget( TRUE ); + } + } + break; + case TQEvent::MouseButtonPress: + if ( e->spontaneous() ) { + TQWidget* fw = (TQWidget*)receiver; + while ( fw->focusProxy() ) + fw = fw->focusProxy(); + if ( fw->isEnabled() && fw->focusPolicy() & TQWidget::ClickFocus ) { + TQFocusEvent::setReason( TQFocusEvent::Mouse); + fw->setFocus(); + TQFocusEvent::resetReason(); + } + } + // fall through intended + case TQEvent::MouseButtonRelease: + case TQEvent::MouseButtonDblClick: + case TQEvent::MouseMove: + { + TQWidget* w = (TQWidget*)receiver; + TQMouseEvent* mouse = (TQMouseEvent*) e; + TQPoint relpos = mouse->pos(); + while ( w ) { + TQMouseEvent me(mouse->type(), relpos, mouse->globalPos(), mouse->button(), mouse->state()); + me.spont = mouse->spontaneous(); + res = internalNotify( w, w == receiver ? mouse : &me ); + e->spont = FALSE; + if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation)) + break; + + relpos += w->pos(); + w = w->parentWidget(); + } + if ( res ) + mouse->accept(); + else + mouse->ignore(); + } + break; +#ifndef TQT_NO_WHEELEVENT + case TQEvent::Wheel: + { + if ( e->spontaneous() ) { + TQWidget* fw = (TQWidget*)receiver; + while ( fw->focusProxy() ) + fw = fw->focusProxy(); + if ( fw->isEnabled() && (fw->focusPolicy() & TQWidget::WheelFocus) == TQWidget::WheelFocus ) { + TQFocusEvent::setReason( TQFocusEvent::Mouse); + fw->setFocus(); + TQFocusEvent::resetReason(); + } + } + + TQWidget* w = (TQWidget*)receiver; + TQWheelEvent* wheel = (TQWheelEvent*) e; + TQPoint relpos = wheel->pos(); + while ( w ) { + TQWheelEvent we(relpos, wheel->globalPos(), wheel->delta(), wheel->state(), wheel->orientation()); + we.spont = wheel->spontaneous(); + res = internalNotify( w, w == receiver ? wheel : &we ); + e->spont = FALSE; + if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation)) + break; + + relpos += w->pos(); + w = w->parentWidget(); + } + if ( res ) + wheel->accept(); + else + wheel->ignore(); + } + break; +#endif + case TQEvent::ContextMenu: + { + TQWidget* w = (TQWidget*)receiver; + TQContextMenuEvent *context = (TQContextMenuEvent*) e; + TQPoint relpos = context->pos(); + while ( w ) { + TQContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->state()); + ce.spont = e->spontaneous(); + res = internalNotify( w, w == receiver ? context : &ce ); + e->spont = FALSE; + + if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation)) + break; + + relpos += w->pos(); + w = w->parentWidget(); + } + if ( res ) + context->accept(); + else + context->ignore(); + } + break; +#if defined (QT_TABLET_SUPPORT) + case TQEvent::TabletMove: + case TQEvent::TabletPress: + case TQEvent::TabletRelease: + { + TQWidget *w = (TQWidget*)receiver; + TQTabletEvent *tablet = (TQTabletEvent*)e; + TQPoint relpos = tablet->pos(); + while ( w ) { + TQTabletEvent te(tablet->pos(), tablet->globalPos(), tablet->device(), + tablet->pressure(), tablet->xTilt(), tablet->yTilt(), + tablet->uniqueId()); + te.spont = e->spontaneous(); + res = internalNotify( w, w == receiver ? tablet : &te ); + e->spont = FALSE; + if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation)) + break; + + relpos += w->pos(); + w = w->parentWidget(); + } + if ( res ) + tablet->accept(); + else + tablet->ignore(); + chokeMouse = tablet->isAccepted(); + } + break; +#endif + default: + res = internalNotify( receiver, e ); + break; + } + + return res; +} + +/*!\reimp + +*/ +bool TQApplication::event( TQEvent *e ) +{ + if(e->type() == TQEvent::Close) { + TQCloseEvent *ce = (TQCloseEvent*)e; + ce->accept(); + closeAllWindows(); + + TQWidgetList *list = topLevelWidgets(); + for(TQWidget *w = list->first(); w; w = list->next()) { + if ( !w->isHidden() && !w->isDesktop() && !w->isPopup() && + (!w->isDialog() || !w->parentWidget())) { + ce->ignore(); + break; + } + } + if(ce->isAccepted()) + return TRUE; + } else if (e->type() == TQEvent::Quit) { + quit(); + return TRUE; + } + return TQObject::event(e); +} + +#define HOVER_SENSITIVE_WIDGET_SELECT if ( widget->inherits("TQPushButton") \ + || widget->inherits("TQComboBox") \ + || widget->inherits("TQSpinWidget") \ + || widget->inherits("TQCheckBox") \ + || widget->inherits("TQRadioButton") \ + || widget->inherits("TQToolButton") \ + || widget->inherits("TQSlider") \ + || widget->inherits("TQScrollBar") \ + || widget->inherits("TQTabBar") \ + || widget->inherits("TQDockWindowHandle") \ + || widget->inherits("TQSplitterHandle") ) + +#define FOCUS_SENSITIVE_WIDGET_SELECT if ( widget->inherits("TQLineEdit") ) +#define FOCUS_SENSITIVE_PARENT_WIDGET_SELECT if ( widget->parentWidget() && widget->parentWidget()->inherits("TQSpinWidget") ) + +/*!\internal + + Helper function called by notify() + */ +bool TQApplication::internalNotify( TQObject *receiver, TQEvent * e) +{ + if ( eventFilters ) { + TQObjectListIt it( *eventFilters ); + TQObject *obj; + while ( (obj=it.current()) != 0 ) { // send to all filters + ++it; // until one returns TRUE + if ( obj->eventFilter(receiver,e) ) + return TRUE; + } + } + + bool consumed = FALSE; + bool handled = FALSE; + if ( receiver->isWidgetType() ) { + TQWidget *widget = (TQWidget*)receiver; + + // toggle HasMouse widget state on enter and leave + if ( e->type() == TQEvent::Enter || e->type() == TQEvent::DragEnter ) { + widget->setWState( WState_HasMouse ); + HOVER_SENSITIVE_WIDGET_SELECT { + widget->repaint(false); + } + } + else if ( e->type() == TQEvent::Leave || e->type() == TQEvent::DragLeave ) { + widget->clearWState( WState_HasMouse ); + HOVER_SENSITIVE_WIDGET_SELECT { + widget->repaint(false); + } + } + + // repaint information entry widgets on focus set/unset + if ( e->type() == TQEvent::FocusIn || e->type() == TQEvent::FocusOut ) { + FOCUS_SENSITIVE_WIDGET_SELECT { + widget->repaint(false); + } + FOCUS_SENSITIVE_PARENT_WIDGET_SELECT { + widget->parentWidget()->repaint(false); + } + } + + // throw away any mouse-tracking-only mouse events + if ( e->type() == TQEvent::MouseMove && + (((TQMouseEvent*)e)->state()&TQMouseEvent::MouseButtonMask) == 0 && + !widget->hasMouseTracking() ) { + handled = TRUE; + consumed = TRUE; + } else if ( !widget->isEnabled() ) { // throw away mouse events to disabled widgets + switch(e->type()) { + case TQEvent::MouseButtonPress: + case TQEvent::MouseButtonRelease: + case TQEvent::MouseButtonDblClick: + case TQEvent::MouseMove: + ( (TQMouseEvent*) e)->ignore(); + handled = TRUE; + consumed = TRUE; + break; +#ifndef TQT_NO_DRAGANDDROP + case TQEvent::DragEnter: + case TQEvent::DragMove: + ( (TQDragMoveEvent*) e)->ignore(); + handled = TRUE; + break; + + case TQEvent::DragLeave: + case TQEvent::DragResponse: + handled = TRUE; + break; + + case TQEvent::Drop: + ( (TQDropEvent*) e)->ignore(); + handled = TRUE; + break; +#endif +#ifndef TQT_NO_WHEELEVENT + case TQEvent::Wheel: + ( (TQWheelEvent*) e)->ignore(); + handled = TRUE; + break; +#endif + case TQEvent::ContextMenu: + ( (TQContextMenuEvent*) e)->ignore(); + handled = TRUE; + break; + default: + break; + } + } + + } + + if (!handled) { +#if defined(TQT_THREAD_SUPPORT) + int locklevel = 0; + int llcount; + if (TQApplication::tqt_mutex) { + TQApplication::tqt_mutex->lock(); // 1 of 2 + locklevel = tqt_mutex->level() - 1; + for (llcount=0; llcountunlock(); + } + TQApplication::tqt_mutex->unlock(); // 2 of 2 + } +#endif + consumed = receiver->event( e ); +#if defined(TQT_THREAD_SUPPORT) + if (TQApplication::tqt_mutex) { + for (llcount=0; llcountlock(); + } + } +#endif + } + e->spont = FALSE; + return consumed; +} + +/*! + Returns TRUE if an application object has not been created yet; + otherwise returns FALSE. + + \sa closingDown() +*/ + +bool TQApplication::startingUp() +{ + return !is_app_running; +} + +/*! + Returns TRUE if the application objects are being destroyed; + otherwise returns FALSE. + + \sa startingUp() +*/ + +bool TQApplication::closingDown() +{ + return is_app_closing; +} + + +/*! + Processes pending events, for 3 seconds or until there are no more + events to process, whichever is shorter. + + You can call this function occasionally when your program is busy + performing a long operation (e.g. copying a file). + + \sa exec(), TQTimer, TQEventLoop::processEvents() +*/ + +void TQApplication::processEvents() +{ + processEvents( 3000 ); +} + +/*! + \overload + + Processes pending events for \a maxtime milliseconds or until + there are no more events to process, whichever is shorter. + + You can call this function occasionally when you program is busy + doing a long operation (e.g. copying a file). + + \sa exec(), TQTimer, TQEventLoop::processEvents() +*/ +void TQApplication::processEvents( int maxtime ) +{ + eventLoop()->processEvents( TQEventLoop::AllEvents, maxtime ); +} + +/*! \obsolete + Waits for an event to occur, processes it, then returns. + + This function is useful for adapting TQt to situations where the + event processing must be grafted onto existing program loops. + + Using this function in new applications may be an indication of design + problems. + + \sa processEvents(), exec(), TQTimer +*/ + +void TQApplication::processOneEvent() +{ + eventLoop()->processEvents( TQEventLoop::AllEvents | + TQEventLoop::WaitForMore ); +} + +/***************************************************************************** + Main event loop wrappers + *****************************************************************************/ + +/*! + Returns the application event loop. This function will return + zero if called during and after destroying TQApplication. + + To create your own instance of TQEventLoop or TQEventLoop subclass create + it before you create the TQApplication object. + + \sa TQEventLoop +*/ +TQEventLoop *TQApplication::eventLoop() +{ + if ( !currentEventLoop() && !is_app_closing ) { + (void) new TQEventLoop( tqApp, "default event loop" ); + } + return currentEventLoop(); +} + + +/*! + Enters the main event loop and waits until exit() is called or the + main widget is destroyed, and returns the value that was set to + exit() (which is 0 if exit() is called via quit()). + + It is necessary to call this function to start event handling. The + main event loop receives events from the window system and + dispatches these to the application widgets. + + Generally speaking, no user interaction can take place before + calling exec(). As a special case, modal widgets like TQMessageBox + can be used before calling exec(), because modal widgets call + exec() to start a local event loop. + + To make your application perform idle processing, i.e. executing a + special function whenever there are no pending events, use a + TQTimer with 0 timeout. More advanced idle processing schemes can + be achieved using processEvents(). + + \sa quit(), exit(), processEvents(), setMainWidget() +*/ +int TQApplication::exec() +{ + return eventLoop()->exec(); +} + +/*! + Tells the application to exit with a return code. + + After this function has been called, the application leaves the main + event loop and returns from the call to exec(). The exec() function + returns \a retcode. + + By convention, a \a retcode of 0 means success, and any non-zero + value indicates an error. + + Note that unlike the C library function of the same name, this + function \e does return to the caller -- it is event processing that + stops. + + \sa quit(), exec() +*/ +void TQApplication::exit( int retcode ) +{ +#ifdef TQT_THREAD_SUPPORT + TQThread* thread = tqApp->guiThread(); + if (thread) { + if (thread->d) { + if (thread->d->eventLoop) { + thread->d->eventLoop->exit( retcode ); + } + } + } +#else + tqApp->eventLoop()->exit( retcode ); +#endif // TQT_THREAD_SUPPORT +} + +/*! + \obsolete + + This function enters the main event loop (recursively). Do not call + it unless you really know what you are doing. + + Use TQApplication::eventLoop()->enterLoop() instead. + +*/ +int TQApplication::enter_loop() +{ + return eventLoop()->enterLoop(); +} + +/*! + \obsolete + + This function exits from a recursive call to the main event loop. + Do not call it unless you are an expert. + + Use TQApplication::eventLoop()->exitLoop() instead. + +*/ +void TQApplication::exit_loop() +{ + eventLoop()->exitLoop(); +} + +/*! + \obsolete + + Returns the current loop level. + + Use TQApplication::eventLoop()->loopLevel() instead. + +*/ +int TQApplication::loopLevel() const +{ + return eventLoop()->loopLevel(); +} + +/*! + + Wakes up the GUI thread. + + \sa guiThreadAwake() \link threads.html Thread Support in TQt\endlink +*/ +void TQApplication::wakeUpGuiThread() +{ + eventLoop()->wakeUp(); +} + +/*! + This function returns TRUE if there are pending events; otherwise + returns FALSE. Pending events can be either from the window system + or posted events using TQApplication::postEvent(). +*/ +bool TQApplication::hasPendingEvents() +{ + return eventLoop()->hasPendingEvents(); +} + +#if !defined(TQ_WS_X11) + +// The doc and X implementation of these functions is in tqapplication_x11.cpp + +void TQApplication::flushX() {} // do nothing + +void TQApplication::syncX() {} // do nothing + +#endif + +/*! + \fn void TQApplication::setWinStyleHighlightColor( const TQColor & ) + \obsolete + + Sets the color used to mark selections in windows style for all widgets + in the application. Will repaint all widgets if the color is changed. + + The default color is \c darkBlue. + \sa winStyleHighlightColor() +*/ + +/*! + \fn const TQColor& TQApplication::winStyleHighlightColor() + \obsolete + + Returns the color used to mark selections in windows style. + + \sa setWinStyleHighlightColor() +*/ + +/*! + Returns the version of the Windows operating system that is running: + + \list + \i TQt::WV_95 - Windows 95 + \i TQt::WV_98 - Windows 98 + \i TQt::WV_Me - Windows Me + \i TQt::WV_NT - Windows NT 4.x + \i TQt::WV_2000 - Windows 2000 (NT5) + \i TQt::WV_XP - Windows XP + \i TQt::WV_2003 - Windows Server 2003 family + \i TQt::WV_CE - Windows CE + \i TQt::WV_CENET - Windows CE.NET + \endlist + + Note that this function is implemented for the Windows version + of TQt only. +*/ + +#if defined(Q_OS_CYGWIN) +TQt::WindowsVersion TQApplication::winVersion() +{ + return qt_winver; +} +#endif + +#ifndef TQT_NO_TRANSLATION + +bool qt_detectRTLLanguage() +{ + return TQApplication::tr( "QT_LAYOUT_DIRECTION", + "Translate this string to the string 'LTR' in left-to-right" + " languages or to 'RTL' in right-to-left languages (such as Hebrew" + " and Arabic) to get proper widget layout." ) == "RTL"; +} + +/*! + Adds the message file \a mf to the list of message files to be used + for translations. + + Multiple message files can be installed. Translations are searched + for in the last installed message file, then the one from last, and + so on, back to the first installed message file. The search stops as + soon as a matching translation is found. + + \sa removeTranslator() translate() TQTranslator::load() +*/ + +void TQApplication::installTranslator( TQTranslator * mf ) +{ + if ( !mf ) + return; + if ( !translators ) + translators = new TQValueList; + + translators->prepend( mf ); + +#ifndef TQT_NO_TRANSLATION_BUILDER + if ( mf->isEmpty() ) + return; +#endif + + // hook to set the layout direction of dialogs + setReverseLayout( qt_detectRTLLanguage() ); + + TQWidgetList *list = topLevelWidgets(); + TQWidgetListIt it( *list ); + TQWidget *w; + while ( ( w=it.current() ) != 0 ) { + ++it; + if (!w->isDesktop()) + postEvent( w, new TQEvent( TQEvent::LanguageChange ) ); + } + delete list; +} + +/*! + Removes the message file \a mf from the list of message files used by + this application. (It does not delete the message file from the file + system.) + + \sa installTranslator() translate(), TQObject::tr() +*/ + +void TQApplication::removeTranslator( TQTranslator * mf ) +{ + if ( !translators || !mf ) + return; + + if ( translators->remove( mf ) && ! tqApp->closingDown() ) { + setReverseLayout( qt_detectRTLLanguage() ); + + TQWidgetList *list = topLevelWidgets(); + TQWidgetListIt it( *list ); + TQWidget *w; + while ( ( w=it.current() ) != 0 ) { + ++it; + postEvent( w, new TQEvent( TQEvent::LanguageChange ) ); + } + delete list; + } +} + +#ifndef TQT_NO_TEXTCODEC +/*! \obsolete + This is the same as TQTextCodec::setCodecForTr(). +*/ +void TQApplication::setDefaultCodec( TQTextCodec* codec ) +{ + TQTextCodec::setCodecForTr( codec ); +} + +/*! \obsolete + Returns TQTextCodec::codecForTr(). +*/ +TQTextCodec* TQApplication::defaultCodec() const +{ + return TQTextCodec::codecForTr(); +} +#endif //TQT_NO_TEXTCODEC + +/*! \enum TQApplication::Encoding + + This enum type defines the 8-bit encoding of character string + arguments to translate(): + + \value DefaultCodec - the encoding specified by + TQTextCodec::codecForTr() (Latin-1 if none has been set) + \value UnicodeUTF8 - UTF-8 + + \sa TQObject::tr(), TQObject::trUtf8(), TQString::fromUtf8() +*/ + +/*! \reentrant + Returns the translation text for \a sourceText, by querying the + installed messages files. The message files are searched from the most + recently installed message file back to the first installed message + file. + + TQObject::tr() and TQObject::trUtf8() provide this functionality more + conveniently. + + \a context is typically a class name (e.g., "MyDialog") and + \a sourceText is either English text or a short identifying text, if + the output text will be very long (as for help texts). + + \a comment is a disambiguating comment, for when the same \a + sourceText is used in different roles within the same context. By + default, it is null. \a encoding indicates the 8-bit encoding of + character stings + + See the \l TQTranslator documentation for more information about + contexts and comments. + + If none of the message files contain a translation for \a + sourceText in \a context, this function returns a TQString + equivalent of \a sourceText. The encoding of \a sourceText is + specified by \e encoding; it defaults to \c DefaultCodec. + + This function is not virtual. You can use alternative translation + techniques by subclassing \l TQTranslator. + + \warning This method is reentrant only if all translators are + installed \e before calling this method. Installing or removing + translators while performing translations is not supported. Doing + so will most likely result in crashes or other undesirable behavior. + + \sa TQObject::tr() installTranslator() defaultCodec() +*/ + +TQString TQApplication::translate( const char * context, const char * sourceText, + const char * comment, Encoding encoding ) const +{ + if ( !sourceText ) + return TQString::null; + + if ( translators ) { + TQValueList::iterator it; + TQTranslator * mf; + TQString result; + for ( it = translators->begin(); it != translators->end(); ++it ) { + mf = *it; + result = mf->findMessage( context, sourceText, comment ).translation(); + if ( !result.isNull() ) + return result; + } + } +#ifndef TQT_NO_TEXTCODEC + if ( encoding == UnicodeUTF8 ) + return TQString::fromUtf8( sourceText ); + else if ( TQTextCodec::codecForTr() != 0 ) + return TQTextCodec::codecForTr()->toUnicode( sourceText ); + else +#endif + return TQString::fromLatin1( sourceText ); +} + +#endif + +/***************************************************************************** + TQApplication management of posted events + *****************************************************************************/ + +//see also notify(), which does the removal of ChildInserted when ChildRemoved. + +/*! + Adds the event \a event with the object \a receiver as the receiver of the + event, to an event queue and returns immediately. + + The event must be allocated on the heap since the post event queue + will take ownership of the event and delete it once it has been posted. + + When control returns to the main event loop, all events that are + stored in the queue will be sent using the notify() function. + + \threadsafe + + \sa sendEvent(), notify() +*/ + +void TQApplication::postEvent( TQObject *receiver, TQEvent *event ) +{ + if ( receiver == 0 ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQApplication::postEvent: Unexpected null receiver" ); +#endif + delete event; + return; + } + +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( GlobalPostedEvents()->mutex() ); +#endif // TQT_THREAD_SUPPORT + + if ( !receiver->postedEvents ) { + receiver->postedEvents = new TQPostEventList; + } + TQPostEventList * l = receiver->postedEvents; + + // if this is one of the compressible events, do compression + if ( event->type() == TQEvent::Paint || + event->type() == TQEvent::LayoutHint || + event->type() == TQEvent::Resize || + event->type() == TQEvent::Move || + event->type() == TQEvent::LanguageChange ) { + l->first(); + TQPostEvent * cur = 0; + for ( ;; ) { + while ( (cur=l->current()) != 0 && + ( cur->receiver != receiver || + cur->event == 0 || + cur->event->type() != event->type() ) ) + l->next(); + if ( l->current() != 0 ) { + if ( cur->event->type() == TQEvent::Paint ) { + TQPaintEvent * p = (TQPaintEvent*)(cur->event); + if ( p->erase != ((TQPaintEvent*)event)->erase ) { + l->next(); + continue; + } + p->reg = p->reg.unite( ((TQPaintEvent *)event)->reg ); + p->rec = p->rec.unite( ((TQPaintEvent *)event)->rec ); + delete event; + return; + } else if ( cur->event->type() == TQEvent::LayoutHint ) { + delete event; + return; + } else if ( cur->event->type() == TQEvent::Resize ) { + ((TQResizeEvent *)(cur->event))->s = ((TQResizeEvent *)event)->s; + delete event; + return; + } else if ( cur->event->type() == TQEvent::Move ) { + ((TQMoveEvent *)(cur->event))->p = ((TQMoveEvent *)event)->p; + delete event; + return; + } else if ( cur->event->type() == TQEvent::LanguageChange ) { + delete event; + return; + } + } + break; + }; + } + +#if !defined(TQT_NO_IM) + // if this is one of the compressible IM events, do compression + else if ( event->type() == TQEvent::IMCompose ) { + l->last(); + TQPostEvent * cur = 0; + for ( ;; ) { + while ( (cur=l->current()) != 0 && + ( cur->receiver != receiver || + cur->event == 0 || + cur->event->type() != event->type() || + cur->event->type() != TQEvent::IMStart ) ) + l->prev(); + if ( l->current() != 0 ) { + // IMCompose must not be compressed with another one + // beyond its IMStart boundary + if ( cur->event->type() == TQEvent::IMStart ) { + break; + } else if ( cur->event->type() == TQEvent::IMCompose ) { + TQIMComposeEvent * e = (TQIMComposeEvent *)(cur->event); + *e = *(TQIMComposeEvent *)event; + delete event; + return; + } + } + break; + }; + } +#endif + + // if no compression could be done, just append something + event->posted = TRUE; + TQPostEvent * pe = new TQPostEvent( receiver, event ); + l->append( pe ); + GlobalPostedEvents()->append( pe ); + +#ifdef TQT_THREAD_SUPPORT + // Wake up the receiver thread event loop + TQThread* thread = receiver->contextThreadObject(); + if (thread) { + if (thread->d) { + if (thread->d->eventLoop) { + thread->d->eventLoop->wakeUp(); + return; + } + } + } + if ( event->type() == TQEvent::MetaCall ) { + return; + } +#endif + + if (currentEventLoop()) { + currentEventLoop()->wakeUp(); + } +} + + +/*! \overload + + Dispatches all posted events, i.e. empties the event queue. +*/ +void TQApplication::sendPostedEvents() +{ + sendPostedEvents( 0, 0 ); +} + + + +/*! + Immediately dispatches all events which have been previously queued + with TQApplication::postEvent() and which are for the object \a receiver + and have the event type \a event_type. + + Note that events from the window system are \e not dispatched by this + function, but by processEvents(). + + If \a receiver is null, the events of \a event_type are sent for all + objects. If \a event_type is 0, all the events are sent for \a receiver. +*/ + +void TQApplication::sendPostedEvents( TQObject *receiver, int event_type ) +{ + // Make sure the object hierarchy is stable before processing events + // to avoid endless loops + if ( receiver == 0 && event_type == 0 ) { + sendPostedEvents( 0, TQEvent::ChildInserted ); + } + +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( GlobalPostedEvents()->mutex() ); +#endif + + bool sent = TRUE; + while ( sent ) { + sent = FALSE; + + if (receiver && !receiver->postedEvents) { + return; + } + + // if we have a receiver, use the local list. Otherwise, use the + // global list + TQPostEventList * l = receiver ? receiver->postedEvents : GlobalPostedEvents(); + + // okay. here is the tricky loop. be careful about optimizing + // this, it looks the way it does for good reasons. + TQPostEventListIt it( *l ); + TQPostEvent *pe; + while ( (pe=it.current()) != 0 ) { + ++it; + Q_ASSERT(pe->receiver); + if ( pe->event // hasn't been sent yet + && ( receiver == 0 // we send to all receivers + || receiver == pe->receiver ) // we send to THAT receiver + && ( event_type == 0 // we send all types + || event_type == pe->event->type() ) // we send THAT type + && ( !pe->receiver->wasDeleted ) // don't send if receiver was deleted +#ifdef TQT_THREAD_SUPPORT + // only send if active thread is receiver object owning thread + && ( pe->receiver->contextThreadObject() == TQThread::currentThreadObject() ) +#endif + ) { + // first, we diddle the event so that we can deliver + // it, and that noone will try to touch it later. + pe->event->posted = FALSE; + TQEvent * e = pe->event; + TQObject * r = pe->receiver; + pe->event = 0; + + // next, update the data structure so that we're ready + // for the next event. + + // look for the local list, and take whatever we're + // delivering out of it. r->postedEvents maybe *l + if ( r->postedEvents ) { + r->postedEvents->removeRef( pe ); + // if possible, get rid of that list. this is not + // ideal - we will create and delete a list for + // each update() call. it would be better if we'd + // leave the list empty here, and delete it + // somewhere else if it isn't being used. + if ( r->postedEvents->isEmpty() ) { + delete r->postedEvents; + r->postedEvents = 0; + } + } + +#ifdef TQT_THREAD_SUPPORT + if ( locker.mutex() ) locker.mutex()->unlock(); +#endif // TQT_THREAD_SUPPORT + // after all that work, it's time to deliver the event. + if ( e->type() == TQEvent::Paint && r->isWidgetType() ) { + TQWidget * w = (TQWidget*)r; + TQPaintEvent * p = (TQPaintEvent*)e; + if ( w->isVisible() ) { + w->repaint( p->reg, p->erase ); + } + } else { + sent = TRUE; + TQApplication::sendEvent( r, e ); + } +#ifdef TQT_THREAD_SUPPORT + if ( locker.mutex() ) locker.mutex()->lock(); +#endif // TQT_THREAD_SUPPORT + + delete e; + // careful when adding anything below this point - the + // sendEvent() call might invalidate any invariants this + // function depends on. + } + } + + // clear the global list, i.e. remove everything that was + // delivered. + if ( l == GlobalPostedEvents() ) { + GlobalPostedEvents()->first(); + while( (pe=GlobalPostedEvents()->current()) != 0 ) { + if ( pe->event ) { + GlobalPostedEvents()->next(); + } + else { + GlobalPostedEvents()->remove(); + } + } + } + } +} + +/*! + Removes all events posted using postEvent() for \a receiver. + + The events are \e not dispatched, instead they are removed from the + queue. You should never need to call this function. If you do call it, + be aware that killing events may cause \a receiver to break one or + more invariants. + + \threadsafe +*/ + +void TQApplication::removePostedEvents( TQObject *receiver ) +{ + removePostedEvents( receiver, 0 ); +} + +/*! + Removes all events that have the event type \a event_type posted + using postEvent() for \a receiver. + + The events are \e not dispatched, instead they are removed from the + queue. + + If \a event_type is 0, all the events are removed from the queue. + + \threadsafe +*/ + +void TQApplication::removePostedEvents( TQObject *receiver, int event_type ) +{ + if ( !receiver ) { + return; + } + +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( GlobalPostedEvents()->mutex() ); +#endif // TQT_THREAD_SUPPORT + + // the TQObject destructor calls this function directly. this can + // happen while the event loop is in the middle of posting events, + // and when we get here, we may not have any more posted events + // for this object. + if ( !receiver->postedEvents ) { + return; + } + + // iterate over the object-specifc list and delete the events. + // leave the TQPostEvent objects; they'll be deleted by + // sendPostedEvents(). + TQPostEventList * l = receiver->postedEvents; + l->first(); + TQPostEvent * pe; + while( (pe=l->current()) != 0 ) { + if ( !event_type || pe->event->type() == event_type ) { + if ( pe->event ) { + pe->event->posted = FALSE; + delete pe->event; + pe->event = 0; + } + l->remove(); + } else { + l->next(); + } + } + if ( !event_type || !l->count() ) { + receiver->postedEvents = 0; + delete l; + } +} + + +/*! + Removes \a event from the queue of posted events, and emits a + warning message if appropriate. + + \warning This function can be \e really slow. Avoid using it, if + possible. + + \threadsafe +*/ + +void TQApplication::removePostedEvent( TQEvent * event ) +{ + if ( !event || !event->posted ) { + return; + } + +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( GlobalPostedEvents()->mutex() ); +#endif // TQT_THREAD_SUPPORT + + TQPostEventListIt it( *GlobalPostedEvents() ); + TQPostEvent * pe; + while( (pe = it.current()) != 0 ) { + ++it; + if ( pe->event == event ) { +#if defined(QT_DEBUG) + const char *n; + switch ( event->type() ) { + case TQEvent::Timer: + n = "Timer"; + break; + case TQEvent::MouseButtonPress: + n = "MouseButtonPress"; + break; + case TQEvent::MouseButtonRelease: + n = "MouseButtonRelease"; + break; + case TQEvent::MouseButtonDblClick: + n = "MouseButtonDblClick"; + break; + case TQEvent::MouseMove: + n = "MouseMove"; + break; +#ifndef TQT_NO_WHEELEVENT + case TQEvent::Wheel: + n = "Wheel"; + break; +#endif + case TQEvent::KeyPress: + n = "KeyPress"; + break; + case TQEvent::KeyRelease: + n = "KeyRelease"; + break; + case TQEvent::FocusIn: + n = "FocusIn"; + break; + case TQEvent::FocusOut: + n = "FocusOut"; + break; + case TQEvent::Enter: + n = "Enter"; + break; + case TQEvent::Leave: + n = "Leave"; + break; + case TQEvent::Paint: + n = "Paint"; + break; + case TQEvent::Move: + n = "Move"; + break; + case TQEvent::Resize: + n = "Resize"; + break; + case TQEvent::Create: + n = "Create"; + break; + case TQEvent::Destroy: + n = "Destroy"; + break; + case TQEvent::Close: + n = "Close"; + break; + case TQEvent::Quit: + n = "Quit"; + break; + default: + n = ""; + break; + } + tqWarning("TQEvent: Warning: %s event deleted while posted to %s %s", + n, + pe->receiver ? pe->receiver->className() : "null", + pe->receiver ? pe->receiver->name() : "object" ); + // note the beautiful uglehack if !pe->receiver :) +#endif + event->posted = FALSE; + delete pe->event; + pe->event = 0; + return; + } + } +} + +#ifdef TQT_THREAD_SUPPORT +static void tqThreadTerminationHandlerRecursive( TQObject* object, TQThread* originThread, TQThread* destinationThread ) { + TQThread* objectThread = object->contextThreadObject(); + if (objectThread && (objectThread == originThread)) { + TQThread::CleanupType cleanupType = objectThread->cleanupType(); + if (cleanupType == TQThread::CleanupMergeObjects) { + object->moveToThread(destinationThread); + } + else if (cleanupType == TQThread::CleanupNone) { + // Do nothing +#if defined(QT_DEBUG) + tqDebug( "TQApplication::threadTerminationHandler: object %p still owned by thread %p at thread termination!", object, objectThread); +#endif // QT_DEBUG + } + else { + // Do nothing +#if defined(QT_DEBUG) + tqDebug( "TQApplication::threadTerminationHandler: invalid thread termination cleanup type %d specified", cleanupType); +#endif // QT_DEBUG + } + } + TQObjectList children = object->childrenListObject(); + TQObject *childObject; + for ( childObject = children.first(); childObject; childObject = children.next() ) { + tqThreadTerminationHandlerRecursive(childObject, originThread, destinationThread); + } +} + +/*!\internal + + Migrates all objects from the specified thread in preparation + for thread destruction. + */ +void TQApplication::threadTerminationHandler( TQThread *originThread ) { + TQMutexLocker locker( tqt_mutex ); + TQThread* destinationThread = guiThread(); + const TQObjectList* objects = TQObject::objectTrees(); + for ( TQObjectListIt objectit( *objects ) ; *objectit; ++objectit ) { + tqThreadTerminationHandlerRecursive((*objectit), originThread, destinationThread); + } +} +#endif // TQT_THREAD_SUPPORT + +/*!\internal + + Sets the active window in reaction to a system event. Call this + from the platform specific event handlers. + + It sets the activeWindow() and focusWidget() attributes and sends + proper WindowActivate/WindowDeactivate and FocusIn/FocusOut events + to all appropriate widgets. + + \sa activeWindow() + */ +void TQApplication::setActiveWindow( TQWidget* act ) +{ + TQWidget* window = act?act->topLevelWidget():0; + + if ( active_window == window ) + return; + + // first the activation/deactivation events + if ( active_window ) { + TQWidgetList deacts; +#ifndef TQT_NO_STYLE + if ( style().styleHint(TQStyle::SH_Widget_ShareActivation, active_window ) ) { + TQWidgetList *list = topLevelWidgets(); + if ( list ) { + for ( TQWidget *w = list->first(); w; w = list->next() ) { + if ( w->isVisible() && w->isActiveWindow() ) + deacts.append(w); + } + delete list; + } + } else +#endif + deacts.append(active_window); + active_window = 0; + TQEvent e( TQEvent::WindowDeactivate ); + for(TQWidget *w = deacts.first(); w; w = deacts.next()) + TQApplication::sendSpontaneousEvent( w, &e ); + } + + active_window = window; + if ( active_window ) { + TQEvent e( TQEvent::WindowActivate ); + TQWidgetList acts; +#ifndef TQT_NO_STYLE + if ( style().styleHint(TQStyle::SH_Widget_ShareActivation, active_window ) ) { + TQWidgetList *list = topLevelWidgets(); + if ( list ) { + for ( TQWidget *w = list->first(); w; w = list->next() ) { + if ( w->isVisible() && w->isActiveWindow() ) + acts.append(w); + } + delete list; + } + } else +#endif + acts.append(active_window); + for(TQWidget *w = acts.first(); w; w = acts.next()) + TQApplication::sendSpontaneousEvent( w, &e ); + } + + // then focus events + TQFocusEvent::setReason( TQFocusEvent::ActiveWindow ); + if ( !active_window && focus_widget ) { + TQFocusEvent out( TQEvent::FocusOut ); + TQWidget *tmp = focus_widget; + focus_widget = 0; +#ifdef TQ_WS_WIN + TQInputContext::accept( tmp ); +#elif defined(TQ_WS_X11) + tmp->unfocusInputContext(); +#endif + TQApplication::sendSpontaneousEvent( tmp, &out ); + } else if ( active_window ) { + TQWidget *w = active_window->focusWidget(); + if ( w && w->focusPolicy() != TQWidget::NoFocus ) + w->setFocus(); + else + active_window->focusNextPrevChild( TRUE ); + } + TQFocusEvent::resetReason(); +} + + +/*!\internal + + Creates the proper Enter/Leave event when widget \a enter is entered + and widget \a leave is left. + */ +TQ_EXPORT void tqt_dispatchEnterLeave( TQWidget* enter, TQWidget* leave ) { +#if 0 + if ( leave ) { + TQEvent e( TQEvent::Leave ); + TQApplication::sendEvent( leave, & e ); + } + if ( enter ) { + TQEvent e( TQEvent::Enter ); + TQApplication::sendEvent( enter, & e ); + } + return; +#endif + + TQWidget* w ; + if ( !enter && !leave ) + return; + TQWidgetList leaveList; + TQWidgetList enterList; + + bool sameWindow = leave && enter && leave->topLevelWidget() == enter->topLevelWidget(); + if ( leave && !sameWindow ) { + w = leave; + do { + leaveList.append( w ); + } while ( (w = w->parentWidget( TRUE ) ) ); + } + if ( enter && !sameWindow ) { + w = enter; + do { + enterList.prepend( w ); + } while ( (w = w->parentWidget(TRUE) ) ); + } + if ( sameWindow ) { + int enterDepth = 0; + int leaveDepth = 0; + w = enter; + while ( ( w = w->parentWidget( TRUE ) ) ) + enterDepth++; + w = leave; + while ( ( w = w->parentWidget( TRUE ) ) ) + leaveDepth++; + TQWidget* wenter = enter; + TQWidget* wleave = leave; + while ( enterDepth > leaveDepth ) { + wenter = wenter->parentWidget(); + enterDepth--; + } + while ( leaveDepth > enterDepth ) { + wleave = wleave->parentWidget(); + leaveDepth--; + } + while ( !wenter->isTopLevel() && wenter != wleave ) { + wenter = wenter->parentWidget(); + wleave = wleave->parentWidget(); + } + + w = leave; + while ( w != wleave ) { + leaveList.append( w ); + w = w->parentWidget(); + } + w = enter; + while ( w != wenter ) { + enterList.prepend( w ); + w = w->parentWidget(); + } + } + + TQEvent leaveEvent( TQEvent::Leave ); + for ( w = leaveList.first(); w; w = leaveList.next() ) { + if ( !tqApp->activeModalWidget() || tqt_tryModalHelper( w, 0 )) + TQApplication::sendEvent( w, &leaveEvent ); + } + TQEvent enterEvent( TQEvent::Enter ); + for ( w = enterList.first(); w; w = enterList.next() ) { + if ( !tqApp->activeModalWidget() || tqt_tryModalHelper( w, 0 )) + TQApplication::sendEvent( w, &enterEvent ); + } +} + + +#ifdef TQ_WS_MACX +extern TQWidget *tqt_tryModalHelperMac( TQWidget * top ); //tqapplication_mac.cpp +#endif + + +/*!\internal + + Called from tqapplication_.cpp, returns TRUE + if the widget should accept the event. + */ +TQ_EXPORT bool tqt_tryModalHelper( TQWidget *widget, TQWidget **rettop ) { + TQWidget *modal=0, *top=TQApplication::activeModalWidget(); + if ( rettop ) *rettop = top; + + if ( tqApp->activePopupWidget() ) + return TRUE; + +#ifdef TQ_WS_MACX + top = tqt_tryModalHelperMac( top ); + if ( rettop ) *rettop = top; +#endif + + TQWidget* groupLeader = widget; + widget = widget->topLevelWidget(); + + if ( widget->testWFlags(TQt::WShowModal) ) // widget is modal + modal = widget; + if ( !top || modal == top ) // don't block event + return TRUE; + + TQWidget * p = widget->parentWidget(); // Check if the active modal widget is a parent of our widget + while ( p ) { + if ( p == top ) + return TRUE; + p = p->parentWidget(); + } + + while ( groupLeader && !groupLeader->testWFlags( TQt::WGroupLeader ) ) + groupLeader = groupLeader->parentWidget(); + + if ( groupLeader ) { + // Does groupLeader have a child in tqt_modal_stack? + bool unrelated = TRUE; + modal = tqt_modal_stack->first(); + while (modal && unrelated) { + TQWidget* p = modal->parentWidget(); + while ( p && p != groupLeader && !p->testWFlags( TQt::WGroupLeader) ) { + p = p->parentWidget(); + } + modal = tqt_modal_stack->next(); + if ( p == groupLeader ) unrelated = FALSE; + } + + if ( unrelated ) + return TRUE; // don't block event + } + return FALSE; +} + + +/*! + Returns the desktop widget (also called the root window). + + The desktop widget is useful for obtaining the size of the screen. + It may also be possible to draw on the desktop. We recommend against + assuming that it's possible to draw on the desktop, since this does + not work on all operating systems. + + \code + TQDesktopWidget *d = TQApplication::desktop(); + int w = d->width(); // returns desktop width + int h = d->height(); // returns desktop height + \endcode +*/ + +TQDesktopWidget *TQApplication::desktop() +{ + if ( !tqt_desktopWidget || // not created yet + !tqt_desktopWidget->isDesktop() ) { // reparented away + tqt_desktopWidget = new TQDesktopWidget(); + TQ_CHECK_PTR( tqt_desktopWidget ); + } + return tqt_desktopWidget; +} + +#ifndef TQT_NO_CLIPBOARD +/*! + Returns a pointer to the application global clipboard. +*/ +TQClipboard *TQApplication::clipboard() +{ + if ( tqt_clipboard == 0 ) { + tqt_clipboard = new TQClipboard; + TQ_CHECK_PTR( tqt_clipboard ); + } + return tqt_clipboard; +} +#endif // TQT_NO_CLIPBOARD + +/*! + By default, TQt will try to use the current standard colors, fonts + etc., from the underlying window system's desktop settings, + and use them for all relevant widgets. This behavior can be switched off + by calling this function with \a on set to FALSE. + + This static function must be called before creating the TQApplication + object, like this: + + \code + int main( int argc, char** argv ) { + TQApplication::setDesktopSettingsAware( FALSE ); // I know better than the user + TQApplication myApp( argc, argv ); // Use default fonts & colors + ... + } + \endcode + + \sa desktopSettingsAware() +*/ + +void TQApplication::setDesktopSettingsAware( bool on ) +{ + obey_desktop_settings = on; +} + +/*! + Returns the value set by setDesktopSettingsAware(); by default TRUE. + + \sa setDesktopSettingsAware() +*/ + +bool TQApplication::desktopSettingsAware() +{ + return obey_desktop_settings; +} + +/*! \fn void TQApplication::lock() + + Lock the TQt Library Mutex. If another thread has already locked the + mutex, the calling thread will block until the other thread has + unlocked the mutex. + + \sa unlock() locked() \link threads.html Thread Support in TQt\endlink +*/ + + +/*! \fn void TQApplication::unlock(bool wakeUpGui) + + Unlock the TQt Library Mutex. If \a wakeUpGui is TRUE (the default), + then the GUI thread will be woken with TQApplication::wakeUpGuiThread(). + + \sa lock(), locked() \link threads.html Thread Support in TQt\endlink +*/ + + +/*! \fn bool TQApplication::locked() + + Returns TRUE if the TQt Library Mutex is locked by a different thread; + otherwise returns FALSE. + + \warning Due to different implementations of recursive mutexes on + the supported platforms, calling this function from the same thread + that previously locked the mutex will give undefined results. + + \sa lock() unlock() \link threads.html Thread Support in TQt\endlink +*/ + +/*! \fn bool TQApplication::tryLock() + + Attempts to lock the TQt Library Mutex, and returns immediately. If + the lock was obtained, this function returns TRUE. If another thread + has locked the mutex, this function returns FALSE, instead of + waiting for the lock to become available. + + The mutex must be unlocked with unlock() before another thread can + successfully lock it. + + \sa lock(), unlock() \link threads.html Thread Support in TQt\endlink +*/ + +#if defined(TQT_THREAD_SUPPORT) +void TQApplication::lock() +{ + tqt_mutex->lock(); +} + +void TQApplication::unlock(bool wakeUpGui) +{ + tqt_mutex->unlock(); + + if (wakeUpGui) + wakeUpGuiThread(); +} + +bool TQApplication::locked() +{ + return tqt_mutex->locked(); +} + +bool TQApplication::tryLock() +{ + return tqt_mutex->tryLock(); +} +#endif + + +/*! + \fn bool TQApplication::isSessionRestored() const + + Returns TRUE if the application has been restored from an earlier + \link session.html session\endlink; otherwise returns FALSE. + + \sa sessionId(), commitData(), saveState() +*/ + + +/*! + \fn TQString TQApplication::sessionId() const + + Returns the current \link session.html session's\endlink identifier. + + If the application has been restored from an earlier session, this + identifier is the same as it was in that previous session. + + The session identifier is guaranteed to be unique both for different + applications and for different instances of the same application. + + \sa isSessionRestored(), sessionKey(), commitData(), saveState() + */ + +/*! + \fn TQString TQApplication::sessionKey() const + + Returns the session key in the current \link session.html + session\endlink. + + If the application has been restored from an earlier session, this + key is the same as it was when the previous session ended. + + The session key changes with every call of commitData() or + saveState(). + + \sa isSessionRestored(), sessionId(), commitData(), saveState() + */ + + +/*! + \fn void TQApplication::commitData( TQSessionManager& sm ) + + This function deals with \link session.html session + management\endlink. It is invoked when the TQSessionManager wants the + application to commit all its data. + + Usually this means saving all open files, after getting + permission from the user. Furthermore you may want to provide a means + by which the user can cancel the shutdown. + + Note that you should not exit the application within this function. + Instead, the session manager may or may not do this afterwards, + depending on the context. + + \warning Within this function, no user interaction is possible, \e + unless you ask the session manager \a sm for explicit permission. + See TQSessionManager::allowsInteraction() and + TQSessionManager::allowsErrorInteraction() for details and example + usage. + + The default implementation requests interaction and sends a close + event to all visible top level widgets. If any event was + rejected, the shutdown is canceled. + + \sa isSessionRestored(), sessionId(), saveState(), \link session.html the Session Management overview\endlink +*/ +#ifndef TQT_NO_SESSIONMANAGER +void TQApplication::commitData( TQSessionManager& sm ) +{ + + if ( sm.allowsInteraction() ) { + TQWidgetList done; + TQWidgetList *list = TQApplication::topLevelWidgets(); + bool cancelled = FALSE; + TQWidget* w = list->first(); + while ( !cancelled && w ) { + if ( !w->isHidden() ) { + TQCloseEvent e; + sendEvent( w, &e ); + cancelled = !e.isAccepted(); + if ( !cancelled ) + done.append( w ); + delete list; // one never knows... + list = TQApplication::topLevelWidgets(); + w = list->first(); + } else { + w = list->next(); + } + while ( w && done.containsRef( w ) ) + w = list->next(); + } + delete list; + if ( cancelled ) + sm.cancel(); + } +} + + +/*! + \fn void TQApplication::saveState( TQSessionManager& sm ) + + This function deals with \link session.html session + management\endlink. It is invoked when the + \link TQSessionManager session manager \endlink wants the application + to preserve its state for a future session. + + For example, a text editor would create a temporary file that + includes the current contents of its edit buffers, the location of + the cursor and other aspects of the current editing session. + + Note that you should never exit the application within this + function. Instead, the session manager may or may not do this + afterwards, depending on the context. Futhermore, most session + managers will very likely request a saved state immediately after + the application has been started. This permits the session manager + to learn about the application's restart policy. + + \warning Within this function, no user interaction is possible, \e + unless you ask the session manager \a sm for explicit permission. + See TQSessionManager::allowsInteraction() and + TQSessionManager::allowsErrorInteraction() for details. + + \sa isSessionRestored(), sessionId(), commitData(), \link session.html the Session Management overview\endlink +*/ + +void TQApplication::saveState( TQSessionManager& /* sm */ ) +{ +} +#endif //TQT_NO_SESSIONMANAGER +/*! + Sets the time after which a drag should start to \a ms ms. + + \sa startDragTime() +*/ + +void TQApplication::setStartDragTime( int ms ) +{ + drag_time = ms; +} + +/*! + If you support drag and drop in you application and a drag should + start after a mouse click and after a certain time elapsed, you + should use the value which this method returns as the delay (in ms). + + TQt also uses this delay internally, e.g. in TQTextEdit and TQLineEdit, + for starting a drag. + + The default value is 500 ms. + + \sa setStartDragTime(), startDragDistance() +*/ + +int TQApplication::startDragTime() +{ + return drag_time; +} + +/*! + Sets the distance after which a drag should start to \a l pixels. + + \sa startDragDistance() +*/ + +void TQApplication::setStartDragDistance( int l ) +{ + drag_distance = l; +} + +/*! + If you support drag and drop in you application and a drag should + start after a mouse click and after moving the mouse a certain + distance, you should use the value which this method returns as the + distance. + + For example, if the mouse position of the click is stored in \c + startPos and the current position (e.g. in the mouse move event) is + \c currPos, you can find out if a drag should be started with code + like this: + \code + if ( ( startPos - currPos ).manhattanLength() > + TQApplication::startDragDistance() ) + startTheDrag(); + \endcode + + TQt uses this value internally, e.g. in TQFileDialog. + + The default value is 4 pixels. + + \sa setStartDragDistance(), startDragTime(), TQPoint::manhattanLength() +*/ + +int TQApplication::startDragDistance() +{ + return drag_distance; +} + +/*! + If \a b is TRUE, all dialogs and widgets will be laid out in a + mirrored fashion, as required by right to left languages such as + Arabic and Hebrew. If \a b is FALSE, dialogs and widgets are laid + out left to right. + + Changing this flag in runtime does not cause a relayout of already + instantiated widgets. + + \sa reverseLayout() +*/ +void TQApplication::setReverseLayout( bool b ) +{ + if ( reverse_layout == b ) + return; + + reverse_layout = b; + + TQWidgetList *list = topLevelWidgets(); + TQWidgetListIt it( *list ); + TQWidget *w; + while ( ( w=it.current() ) != 0 ) { + ++it; + postEvent( w, new TQEvent( TQEvent::LayoutDirectionChange ) ); + } + delete list; +} + +/*! + Returns TRUE if all dialogs and widgets will be laid out in a + mirrored (right to left) fashion. Returns FALSE if dialogs and + widgets will be laid out left to right. + + \sa setReverseLayout() +*/ +bool TQApplication::reverseLayout() +{ + return reverse_layout; +} + + +/*! + \class TQSessionManager tqsessionmanager.h + \brief The TQSessionManager class provides access to the session manager. + + \ingroup application + \ingroup environment + + The session manager is responsible for session management, most + importantly for interruption and resumption. A "session" is a kind + of record of the state of the system, e.g. which applications were + run at start up and which applications are currently running. The + session manager is used to save the session, e.g. when the machine + is shut down; and to restore a session, e.g. when the machine is + started up. Use TQSettings to save and restore an individual + application's settings, e.g. window positions, recently used files, + etc. + + TQSessionManager provides an interface between the application and + the session manager so that the program can work well with the + session manager. In TQt, session management requests for action + are handled by the two virtual functions TQApplication::commitData() + and TQApplication::saveState(). Both provide a reference to + a session manager object as argument, to allow the application + to communicate with the session manager. + + During a session management action (i.e. within commitData() and + saveState()), no user interaction is possible \e unless the + application got explicit permission from the session manager. You + ask for permission by calling allowsInteraction() or, if it's really + urgent, allowsErrorInteraction(). TQt does not enforce this, but the + session manager may. + + You can try to abort the shutdown process by calling cancel(). The + default commitData() function does this if some top-level window + rejected its closeEvent(). + + For sophisticated session managers provided on Unix/X11, TQSessionManager + offers further possibilites to fine-tune an application's session + management behavior: setRestartCommand(), setDiscardCommand(), + setRestartHint(), setProperty(), requestPhase2(). See the respective + function descriptions for further details. +*/ + +/*! \enum TQSessionManager::RestartHint + + This enum type defines the circumstances under which this + application wants to be restarted by the session manager. The + current values are + + \value RestartIfRunning if the application is still running when + the session is shut down, it wants to be restarted at the start of + the next session. + + \value RestartAnyway the application wants to be started at the + start of the next session, no matter what. (This is useful for + utilities that run just after startup and then quit.) + + \value RestartImmediately the application wants to be started + immediately whenever it is not running. + + \value RestartNever the application does not want to be restarted + automatically. + + The default hint is \c RestartIfRunning. +*/ + + +/*! + \fn TQString TQSessionManager::sessionId() const + + Returns the identifier of the current session. + + If the application has been restored from an earlier session, this + identifier is the same as it was in that earlier session. + + \sa sessionKey(), TQApplication::sessionId() + */ + +/*! + \fn TQString TQSessionManager::sessionKey() const + + Returns the session key in the current session. + + If the application has been restored from an earlier session, this + key is the same as it was when the previous session ended. + + The session key changes with every call of commitData() or + saveState(). + + \sa sessionId(), TQApplication::sessionKey() + */ + +// ### Note: This function is undocumented, since it is #ifdef'd. + +/*! + \fn void* TQSessionManager::handle() const + + X11 only: returns a handle to the current \c SmcConnection. +*/ + + +/*! + \fn bool TQSessionManager::allowsInteraction() + + Asks the session manager for permission to interact with the + user. Returns TRUE if interaction is permitted; otherwise + returns FALSE. + + The rationale behind this mechanism is to make it possible to + synchronize user interaction during a shutdown. Advanced session + managers may ask all applications simultaneously to commit their + data, resulting in a much faster shutdown. + + When the interaction is completed we strongly recommend releasing the + user interaction semaphore with a call to release(). This way, other + applications may get the chance to interact with the user while your + application is still busy saving data. (The semaphore is implicitly + released when the application exits.) + + If the user decides to cancel the shutdown process during the + interaction phase, you must tell the session manager that this has + happened by calling cancel(). + + Here's an example of how an application's TQApplication::commitData() + might be implemented: + +\code +void MyApplication::commitData( TQSessionManager& sm ) { + if ( sm.allowsInteraction() ) { + switch ( TQMessageBox::warning( + yourMainWindow, + tr("Application Name"), + tr("Save changes to document Foo?"), + tr("&Yes"), + tr("&No"), + tr("Cancel"), + 0, 2) ) { + case 0: // yes + sm.release(); + // save document here; if saving fails, call sm.cancel() + break; + case 1: // continue without saving + break; + default: // cancel + sm.cancel(); + break; + } + } else { + // we did not get permission to interact, then + // do something reasonable instead. + } +} +\endcode + + If an error occurred within the application while saving its data, + you may want to try allowsErrorInteraction() instead. + + \sa TQApplication::commitData(), release(), cancel() +*/ + + +/*! + \fn bool TQSessionManager::allowsErrorInteraction() + + This is similar to allowsInteraction(), but also tells the session + manager that an error occurred. Session managers may give error + interaction request higher priority, which means that it is more likely + that an error interaction is permitted. However, you are still not + guaranteed that the session manager will allow interaction. + + \sa allowsInteraction(), release(), cancel() +*/ + +/*! + \fn void TQSessionManager::release() + + Releases the session manager's interaction semaphore after an + interaction phase. + + \sa allowsInteraction(), allowsErrorInteraction() +*/ + +/*! + \fn void TQSessionManager::cancel() + + Tells the session manager to cancel the shutdown process. Applications + should not call this function without first asking the user. + + \sa allowsInteraction(), allowsErrorInteraction() + +*/ + +/*! + \fn void TQSessionManager::setRestartHint( RestartHint hint ) + + Sets the application's restart hint to \a hint. On application + startup the hint is set to \c RestartIfRunning. + + Note that these flags are only hints, a session manager may or may + not respect them. + + We recommend setting the restart hint in TQApplication::saveState() + because most session managers perform a checkpoint shortly after an + application's startup. + + \sa restartHint() +*/ + +/*! + \fn TQSessionManager::RestartHint TQSessionManager::restartHint() const + + Returns the application's current restart hint. The default is + \c RestartIfRunning. + + \sa setRestartHint() +*/ + +/*! + \fn void TQSessionManager::setRestartCommand( const TQStringList& command ) + + If the session manager is capable of restoring sessions it will + execute \a command in order to restore the application. The command + defaults to + + \code + appname -session id + \endcode + + The \c -session option is mandatory; otherwise TQApplication cannot + tell whether it has been restored or what the current session + identifier is. See TQApplication::isSessionRestored() and + TQApplication::sessionId() for details. + + If your application is very simple, it may be possible to store the + entire application state in additional command line options. This + is usually a very bad idea because command lines are often limited + to a few hundred bytes. Instead, use TQSettings, or temporary files + or a database for this purpose. By marking the data with the unique + sessionId(), you will be able to restore the application in a future + session. + + \sa restartCommand(), setDiscardCommand(), setRestartHint() +*/ + +/*! + \fn TQStringList TQSessionManager::restartCommand() const + + Returns the currently set restart command. + + Note that if you want to iterate over the list, you should + iterate over a copy, e.g. + \code + TQStringList list = mySession.restartCommand(); + TQStringList::Iterator it = list.begin(); + while( it != list.end() ) { + myProcessing( *it ); + ++it; + } + \endcode + + \sa setRestartCommand(), restartHint() +*/ + +/*! + \fn void TQSessionManager::setDiscardCommand( const TQStringList& ) + + \sa discardCommand(), setRestartCommand() +*/ + + +/*! + \fn TQStringList TQSessionManager::discardCommand() const + + Returns the currently set discard command. + + Note that if you want to iterate over the list, you should + iterate over a copy, e.g. + \code + TQStringList list = mySession.discardCommand(); + TQStringList::Iterator it = list.begin(); + while( it != list.end() ) { + myProcessing( *it ); + ++it; + } + \endcode + + \sa setDiscardCommand(), restartCommand(), setRestartCommand() +*/ + +/*! + \overload void TQSessionManager::setManagerProperty( const TQString& name, + const TQString& value ) + + Low-level write access to the application's identification and state + records are kept in the session manager. + + The property called \a name has its value set to the string \a value. +*/ + +/*! + \fn void TQSessionManager::setManagerProperty( const TQString& name, + const TQStringList& value ) + + Low-level write access to the application's identification and state + record are kept in the session manager. + + The property called \a name has its value set to the string list \a value. +*/ + +/*! + \fn bool TQSessionManager::isPhase2() const + + Returns TRUE if the session manager is currently performing a second + session management phase; otherwise returns FALSE. + + \sa requestPhase2() +*/ + +/*! + \fn void TQSessionManager::requestPhase2() + + Requests a second session management phase for the application. The + application may then return immediately from the + TQApplication::commitData() or TQApplication::saveState() function, + and they will be called again once most or all other applications have + finished their session management. + + The two phases are useful for applications such as the X11 window manager + that need to store information about another application's windows + and therefore have to wait until these applications have completed their + respective session management tasks. + + Note that if another application has requested a second phase it + may get called before, simultaneously with, or after your + application's second phase. + + \sa isPhase2() +*/ + +/*! + \fn int TQApplication::horizontalAlignment( int align ) + + Strips out vertical alignment flags and transforms an + alignment \a align of AlignAuto into AlignLeft or + AlignRight according to the language used. The other horizontal + alignment flags are left untouched. +*/ + + +/***************************************************************************** + Stubbed session management support + *****************************************************************************/ +#ifndef TQT_NO_SESSIONMANAGER +#if defined( TQT_NO_SM_SUPPORT ) || defined( TQ_WS_WIN ) || defined( TQ_WS_MAC ) + +class TQSessionManagerData +{ +public: + TQStringList restartCommand; + TQStringList discardCommand; + TQString sessionId; + TQString sessionKey; + TQSessionManager::RestartHint restartHint; +}; + +TQSessionManager* qt_session_manager_self = 0; +TQSessionManager::TQSessionManager( TQApplication * app, TQString &id, TQString &key ) + : TQObject( app, "qt_sessionmanager" ) +{ + qt_session_manager_self = this; + d = new TQSessionManagerData; +#if defined(TQ_WS_WIN) && !defined(Q_OS_TEMP) + wchar_t guidstr[40]; + GUID guid; + CoCreateGuid( &guid ); + StringFromGUID2(guid, guidstr, 40); + id = TQString::fromUcs2((ushort*)guidstr); + CoCreateGuid( &guid ); + StringFromGUID2(guid, guidstr, 40); + key = TQString::fromUcs2((ushort*)guidstr); +#endif + d->sessionId = id; + d->sessionKey = key; + d->restartHint = RestartIfRunning; +} + +TQSessionManager::~TQSessionManager() +{ + delete d; + qt_session_manager_self = 0; +} + +TQString TQSessionManager::sessionId() const +{ + return d->sessionId; +} + +TQString TQSessionManager::sessionKey() const +{ + return d->sessionKey; +} + + +#if defined(TQ_WS_X11) || defined(TQ_WS_MAC) +void* TQSessionManager::handle() const +{ + return 0; +} +#endif + +#if !defined(TQ_WS_WIN) +bool TQSessionManager::allowsInteraction() +{ + return TRUE; +} + +bool TQSessionManager::allowsErrorInteraction() +{ + return TRUE; +} +void TQSessionManager::release() +{ +} + +void TQSessionManager::cancel() +{ +} +#endif + + +void TQSessionManager::setRestartHint( TQSessionManager::RestartHint hint) +{ + d->restartHint = hint; +} + +TQSessionManager::RestartHint TQSessionManager::restartHint() const +{ + return d->restartHint; +} + +void TQSessionManager::setRestartCommand( const TQStringList& command) +{ + d->restartCommand = command; +} + +TQStringList TQSessionManager::restartCommand() const +{ + return d->restartCommand; +} + +void TQSessionManager::setDiscardCommand( const TQStringList& command) +{ + d->discardCommand = command; +} + +TQStringList TQSessionManager::discardCommand() const +{ + return d->discardCommand; +} + +void TQSessionManager::setManagerProperty( const TQString&, const TQString&) +{ +} + +void TQSessionManager::setManagerProperty( const TQString&, const TQStringList& ) +{ +} + +bool TQSessionManager::isPhase2() const +{ + return FALSE; +} + +void TQSessionManager::requestPhase2() +{ +} + +#endif // TQT_NO_SM_SUPPORT +#endif //TQT_NO_SESSIONMANAGER diff --git a/src/kernel/tqapplication.h b/src/kernel/tqapplication.h new file mode 100644 index 000000000..0e884583e --- /dev/null +++ b/src/kernel/tqapplication.h @@ -0,0 +1,532 @@ +/**************************************************************************** +** +** 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 "tqdesktopwidget.h" +#include "tqasciidict.h" +#include "tqpalette.h" +#include "tqtranslator.h" +#include "tqstrlist.h" +#include "tqstringlist.h" +#endif // QT_H + +class TQSessionManager; +class TQStyle; +class TQTranslator; +class TQEventLoop; +#if defined(TQ_WS_X11) +class TQIMEvent; +#endif + +#ifdef TQT_THREAD_SUPPORT +class TQMutex; +class TQThread; +#endif // TQT_THREAD_SUPPORT + + +class TQApplication; +extern TQ_EXPORT TQApplication *tqApp; // global application object + + +class TQ_EXPORT TQApplication : public TQObject +{ + TQ_OBJECT +public: + TQApplication( int &argc, char **argv ); + TQApplication( int &argc, char **argv, bool GUIenabled ); + TQApplication( int &argc, char **argv, bool GUIenabled, bool SMenabled ); + enum Type { Tty, GuiClient, GuiServer }; + TQApplication( int &argc, char **argv, Type ); +#if defined(TQ_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 TQT_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 TQT_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 TQT_NO_PALETTE + static TQPalette palette( const TQWidget* = 0 ); + static TQPalette palette( TQStringList ); + 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 TQT_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 TQT_NO_TRANSLATION +# ifndef TQT_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 TQT_NO_DIR + TQString applicationDirPath(); + TQString applicationFilePath(); +#endif +#ifndef TQT_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 TQT_NO_WHEELEVENT + static void setWheelScrollLines( int ); + static int wheelScrollLines(); +#endif + static void setGlobalStrut( const TQSize & ); + static TQSize globalStrut(); + +#ifndef TQT_NO_COMPONENT + static void setLibraryPaths( const TQStringList & ); + static TQStringList libraryPaths(); + static void addLibraryPath( const TQString & ); + static void removeLibraryPath( const TQString & ); +#endif // TQT_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(TQ_WS_MAC) + virtual bool macEventFilter( EventHandlerCallRef, EventRef ); +#endif +#if defined(TQ_WS_WIN) + virtual bool winEventFilter( MSG * ); +#endif +#if defined(TQ_WS_X11) + virtual bool x11EventFilter( XEvent * ); + virtual int x11ClientMessage( TQWidget*, XEvent*, bool passive_only); + int x11ProcessEvent( XEvent* ); +#endif + +#if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) + static WindowsVersion winVersion(); +#elif defined(Q_OS_MAC) + static MacintoshVersion macVersion(); +#endif +#if defined(TQ_WS_WIN) + void winFocus( TQWidget *, bool ); + static void winMouseButtonUp(); +#endif + +#ifndef TQT_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(TQ_WS_X11) +#if !defined(TQT_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(TQT_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(); + +protected: + bool event(TQEvent *); + +private: + void construct( int &argc, char **argv, Type, bool enable_sm ); + void initialize( int, char **, bool enable_sm = true ); + void init_precmdline(); + void process_cmdline( int* argcptr, char ** argv ); + bool internalNotify( TQObject *, TQEvent * ); + +#if defined(TQ_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 tqt_init(int *, char **, TQApplication::Type); +#endif + +#if defined(TQ_WS_X11) +private slots: + void postIMEvent( TQObject *receiver, TQIMEvent *event ); +#endif + +public: +#ifdef TQT_THREAD_SUPPORT + static TQMutex *tqt_mutex; +#endif // TQT_THREAD_SUPPORT + +private: + int app_argc; + char **app_argv; + bool quit_now; + int quit_code; + static TQStyle *app_style; + static int app_cspec; +#ifndef TQT_NO_PALETTE + static TQPalette *app_pal; +#endif + static TQFont *app_font; +#ifndef TQT_NO_CURSOR + static TQCursor *app_cursor; +#endif +#ifndef TQT_THREAD_SUPPORT + static TQEventLoop* eventloop; +#endif + 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 *translators; +#ifndef TQT_NO_SESSIONMANAGER + TQSessionManager *session_manager; + TQString session_id; + static TQString* session_key; + bool is_session_restored; +#endif +#if defined(TQ_WS_X11) +#if !defined (TQT_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 TQT_NO_COMPONENT + static TQStringList *app_libpaths; +#endif + static TQAsciiDict *app_palettes; + static TQAsciiDict *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 TQObject; + friend class TQWidget; + friend class TQETWidget; + friend class TQDialog; + friend class TQAccelManager; + friend class TQEvent; +#ifdef TQT_THREAD_SUPPORT + friend class TQThread; +#endif // TQT_THREAD_SUPPORT + friend class TQTranslator; + friend class TQEventLoop; + friend TQ_EXPORT void tqt_ucm_initialize( TQApplication * ); +#if defined(TQ_WS_WIN) + friend bool qt_sendSpontaneousEvent( TQObject*, TQEvent* ); +#endif +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQApplication( const TQApplication & ); + TQApplication &operator=( const TQApplication & ); +#endif + +private: + static TQEventLoop* currentEventLoop(); + +public: +#ifdef TQT_THREAD_SUPPORT + static TQThread* guiThread(); + static void threadTerminationHandler( TQThread * ); +#endif + static bool isGuiThread(); +}; + +inline int TQApplication::argc() const +{ + return app_argc; +} + +inline char **TQApplication::argv() const +{ + return app_argv; +} + +#ifndef TQT_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 TQT_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; +} + +#ifdef TQT_NO_TRANSLATION +// Simple versions +inline TQString TQApplication::translate( const char *, const char *sourceText, + const char *, Encoding encoding ) const +{ +#ifndef TQT_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 + diff --git a/src/kernel/tqapplication_p.h b/src/kernel/tqapplication_p.h new file mode 100644 index 000000000..742870dc3 --- /dev/null +++ b/src/kernel/tqapplication_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Definition of some TQt private functions. +** +** Created : 000228 +** +** Copyright (C) 2000-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_P_H +#define TQAPPLICATION_P_H + + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of tqapplication_*.cpp, tqwidget*.cpp, tqcolor_x11.cpp, tqfiledialog.cpp +// and many other. This header file may change from version to version +// without notice, or even be removed. +// +// We mean it. +// +// + +#ifndef QT_H +#endif // QT_H + +class TQWidget; +class TQObject; +class TQClipboard; +class TQKeyEvent; +class TQMouseEvent; +class TQWheelEvent; + +extern TQ_EXPORT bool tqt_modal_state(); +extern TQ_EXPORT void tqt_enter_modal( TQWidget* ); +extern TQ_EXPORT void tqt_leave_modal( TQWidget* ); + +extern bool tqt_is_gui_used; +#ifndef TQT_NO_CLIPBOARD +extern TQClipboard *tqt_clipboard; +#endif + +#if defined (Q_OS_WIN32) || defined (Q_OS_CYGWIN) +extern TQt::WindowsVersion qt_winver; +const int QT_TABLET_NPACKETQSIZE = 128; +# ifdef Q_OS_TEMP + extern DWORD qt_cever; +# endif +#elif defined (Q_OS_MAC) +extern TQt::MacintoshVersion qt_macver; +#endif + +#if defined (TQ_WS_X11) +extern int qt_ncols_option; +#endif + + +extern void tqt_dispatchEnterLeave( TQWidget*, TQWidget* ); +extern bool tqt_tryModalHelper( TQWidget *, TQWidget ** = 0 ); + +#endif diff --git a/src/kernel/tqapplication_x11.cpp b/src/kernel/tqapplication_x11.cpp new file mode 100644 index 000000000..6744532f4 --- /dev/null +++ b/src/kernel/tqapplication_x11.cpp @@ -0,0 +1,6732 @@ +/**************************************************************************** +** +** Implementation of X11 startup routines and event handling +** +** Created : 931029 +** +** 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. +** +**********************************************************************/ + +// ### 4.0: examine TQ_EXPORT's below. The respective symbols had all +// been in use (e.g. in the KDE wm ) before the introduction of a version +// map. One might want to turn some of them into propert public API and +// provide a proper alternative for others. See also the exports in +// tqapplication_win.cpp which suggest a unification. + +#include "qplatformdefs.h" + +// POSIX Large File Support redefines open -> open64 +#if defined(open) +# undef open +#endif + +// Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED. +#if defined(connect) +# undef connect +#endif + +// POSIX Large File Support redefines truncate -> truncate64 +#if defined(truncate) +# undef truncate +#endif + +#include "tqapplication.h" +#include "tqapplication_p.h" +#include "tqcolor_p.h" +#include "tqcursor.h" +#include "tqwidget.h" +#include "tqwidget_p.h" +#include "tqobjectlist.h" +#include "tqwidgetlist.h" +#include "tqwidgetintdict.h" +#include "tqbitarray.h" +#include "tqpainter.h" +#include "tqpixmapcache.h" +#include "tqdatetime.h" +#include "tqtextcodec.h" +#include "tqdatastream.h" +#include "tqbuffer.h" +#include "tqsocketnotifier.h" +#include "tqsessionmanager.h" +#include "tqvaluelist.h" +#include "tqdict.h" +#include "tqguardedptr.h" +#include "tqclipboard.h" +#include "tqwhatsthis.h" // ######## dependency +#include "tqsettings.h" +#include "tqstylefactory.h" +#include "tqfileinfo.h" + +// Input method stuff - UNFINISHED +#ifndef TQT_NO_IM +#include "tqinputcontext.h" +#endif // TQT_NO_IM +#include "tqinternal_p.h" // shared double buffer cleanup + +#if defined(TQT_THREAD_SUPPORT) +# include "tqthread.h" +#endif + +#if defined(QT_DEBUG) && defined(Q_OS_LINUX) +# include "tqfile.h" +#endif + +#include "tqt_x11_p.h" + +#if !defined(TQT_NO_XFTFREETYPE) +// XFree86 4.0.3 implementation is missing XftInitFtLibrary forward +extern "C" Bool XftInitFtLibrary(void); +#endif + +#include +#include +#include +#include +#include + +//#define X_NOT_BROKEN +#ifdef X_NOT_BROKEN +// Some X libraries are built with setlocale #defined to _Xsetlocale, +// even though library users are then built WITHOUT such a definition. +// This creates a problem - TQt might setlocale() one value, but then +// X looks and doesn't see the value TQt set. The solution here is to +// implement _Xsetlocale just in case X calls it - redirecting it to +// the real libC version. +// +# ifndef setlocale +extern "C" char *_Xsetlocale(int category, const char *locale); +char *_Xsetlocale(int category, const char *locale) +{ + //tqDebug("_Xsetlocale(%d,%s),category,locale"); + return setlocale(category,locale); +} +# endif // setlocale +#endif // X_NOT_BROKEN + + +// resolve the conflict between X11's FocusIn and TQEvent::FocusIn +const int XFocusOut = FocusOut; +const int XFocusIn = FocusIn; +#undef FocusOut +#undef FocusIn + +const int XKeyPress = KeyPress; +const int XKeyRelease = KeyRelease; +#undef KeyPress +#undef KeyRelease + + +// Fix old X libraries +#ifndef XK_KP_Home +#define XK_KP_Home 0xFF95 +#endif +#ifndef XK_KP_Left +#define XK_KP_Left 0xFF96 +#endif +#ifndef XK_KP_Up +#define XK_KP_Up 0xFF97 +#endif +#ifndef XK_KP_Right +#define XK_KP_Right 0xFF98 +#endif +#ifndef XK_KP_Down +#define XK_KP_Down 0xFF99 +#endif +#ifndef XK_KP_Prior +#define XK_KP_Prior 0xFF9A +#endif +#ifndef XK_KP_Next +#define XK_KP_Next 0xFF9B +#endif +#ifndef XK_KP_End +#define XK_KP_End 0xFF9C +#endif +#ifndef XK_KP_Insert +#define XK_KP_Insert 0xFF9E +#endif +#ifndef XK_KP_Delete +#define XK_KP_Delete 0xFF9F +#endif + + +/***************************************************************************** + Internal variables and functions + *****************************************************************************/ +static const char *appName; // application name +static const char *appClass; // application class +static const char *appFont = 0; // application font +static const char *appBGCol = 0; // application bg color +static const char *appFGCol = 0; // application fg color +static const char *appBTNCol = 0; // application btn color +static const char *mwGeometry = 0; // main widget geometry +static const char *mwTitle = 0; // main widget title +//Ming-Che 10/10 +TQ_EXPORT char *qt_ximServer = 0; // XIM Server will connect to +static bool mwIconic = FALSE; // main widget iconified +//Ming-Che 10/10 +static Display *appDpy = 0; // X11 application display +static char *appDpyName = 0; // X11 display name +static bool appForeignDpy = FALSE; // we didn't create display +static bool appSync = FALSE; // X11 synchronization +#if defined(QT_DEBUG) +static bool appNoGrab = FALSE; // X11 grabbing enabled +static bool appDoGrab = FALSE; // X11 grabbing override (gdb) +#endif +static int appScreen; // X11 screen number +static int appScreenCount; // X11 screen count +static bool app_save_rootinfo = FALSE; // save root info +static bool app_do_modal = FALSE; // modal mode +static Window curWin = 0; // current window + +static GC* app_gc_ro = 0; // read-only GC +static GC* app_gc_tmp = 0; // temporary GC +static GC* app_gc_ro_m = 0; // read-only GC (monochrome) +static GC* app_gc_tmp_m = 0; // temporary GC (monochrome) +// symbols needed by extern TQXEmbed class +TQ_EXPORT Atom tqt_wm_protocols = 0; // window manager protocols +TQ_EXPORT Atom tqt_wm_delete_window = 0; // delete window protocol +TQ_EXPORT Atom tqt_wm_take_focus = 0; // take focus window protocol + +Atom qt_qt_scrolldone = 0; // scroll synchronization +Atom qt_net_wm_context_help = 0; // context help +Atom qt_net_wm_ping = 0; // _NET_WM_PING protocol + +static Atom qt_xsetroot_id = 0; +Atom qt_xa_clipboard = 0; +Atom qt_selection_property = 0; +Atom tqt_clipboard_sentinel = 0; +Atom qt_selection_sentinel = 0; +TQ_EXPORT Atom tqt_wm_state = 0; +Atom qt_wm_change_state = 0; +static Atom qt_settings_timestamp = 0; // TQt >=3 settings timestamp +static Atom qt_input_encoding = 0; // TQt desktop properties +static Atom qt_resource_manager = 0; // X11 Resource manager +Atom qt_sizegrip = 0; // sizegrip +Atom qt_wm_client_leader = 0; +TQ_EXPORT Atom tqt_window_role = 0; +TQ_EXPORT Atom tqt_sm_client_id = 0; +Atom qt_xa_motif_wm_hints = 0; +Atom qt_cde_running = 0; +Atom qt_twin_running = 0; +Atom qt_kwm_running = 0; +Atom qt_gbackground_properties = 0; +Atom qt_x_incr = 0; +Atom qt_utf8_string = 0; + +// detect broken window managers +Atom qt_sgi_desks_manager = 0; +bool qt_broken_wm = FALSE; +static void qt_detect_broken_window_manager(); + +// NET WM support +Atom qt_net_supported = 0; +Atom qt_net_wm_name = 0; +Atom qt_net_wm_icon_name = 0; +Atom qt_net_virtual_roots = 0; +Atom qt_net_workarea = 0; +Atom qt_net_wm_state = 0; +Atom qt_net_wm_state_modal = 0; +Atom qt_net_wm_state_max_v = 0; +Atom qt_net_wm_state_max_h = 0; +Atom qt_net_wm_state_fullscreen = 0; +Atom qt_net_wm_state_above = 0; +Atom qt_net_wm_action = 0; +Atom qt_net_wm_action_move = 0; +Atom qt_net_wm_action_resize = 0; +Atom qt_net_wm_action_minimize = 0; +Atom qt_net_wm_action_shade = 0; +Atom qt_net_wm_action_stick = 0; +Atom qt_net_wm_action_max_h = 0; +Atom qt_net_wm_action_max_v = 0; +Atom qt_net_wm_action_fullscreen = 0; +Atom qt_net_wm_action_change_desktop = 0; +Atom qt_net_wm_action_close = 0; +Atom qt_net_wm_action_above = 0; +Atom qt_net_wm_action_below = 0; +Atom qt_net_wm_window_type = 0; +Atom qt_net_wm_window_type_normal = 0; +Atom qt_net_wm_window_type_dialog = 0; +Atom qt_net_wm_window_type_toolbar = 0; +Atom qt_net_wm_window_type_menu = 0; +Atom qt_net_wm_window_type_utility = 0; +Atom qt_net_wm_window_type_splash = 0; +Atom qt_net_wm_window_type_override = 0; // KDE extension +Atom qt_net_wm_window_type_dropdown_menu = 0; +Atom qt_net_wm_window_type_popup_menu = 0; +Atom qt_net_wm_window_type_tooltip = 0; +Atom qt_net_wm_window_type_combo = 0; +Atom qt_net_wm_window_type_dnd = 0; +Atom qt_net_wm_frame_strut = 0; // KDE extension +Atom qt_net_wm_state_stays_on_top = 0; // KDE extension +Atom qt_net_wm_pid = 0; +Atom qt_net_wm_user_time = 0; +Atom qt_net_wm_full_placement = 0; // KDE extension +// Enlightenment support +Atom qt_enlightenment_desktop = 0; + +// window managers list of supported "stuff" +Atom *qt_net_supported_list = 0; +// list of virtual root windows +Window *qt_net_virtual_root_list = 0; + + +// X11 SYNC support +#ifndef TQT_NO_XSYNC +Atom qt_net_wm_sync_request_counter = 0; +Atom qt_net_wm_sync_request = 0; +#endif + +// client leader window +Window qt_x11_wm_client_leader = 0; + +// function to update the workarea of the screen - in tqdesktopwidget_x11.cpp +extern void qt_desktopwidget_update_workarea(); + +// current focus model +static const int FocusModel_Unknown = -1; +static const int FocusModel_Other = 0; +static const int FocusModel_PointerRoot = 1; +static int qt_focus_model = -1; + +#ifndef TQT_NO_XRANDR +// TRUE if TQt is compiled w/ XRandR support and XRandR exists on the connected +// Display +bool qt_use_xrandr = FALSE; +static int xrandr_eventbase; +#endif + +// TRUE if TQt is compiled w/ XRender support and XRender exists on the connected +// Display +TQ_EXPORT bool tqt_use_xrender = FALSE; + +#ifndef TQT_NO_XSYNC +// True if SYNC extension exists on the connected display +bool qt_use_xsync = FALSE; +static int xsync_eventbase; +static int xsync_errorbase; +#endif + +// modifier masks for alt/meta - detected when the application starts +static long qt_alt_mask = 0; +static long qt_meta_mask = 0; +// modifier mask to remove mode switch from modifiers that have alt/meta set +// this problem manifests itself on HP/UX 10.20 at least, and without it +// modifiers do not work at all... +static long qt_mode_switch_remove_mask = 0; + +// flags for extensions for special Languages, currently only for RTL languages +static bool qt_use_rtl_extensions = FALSE; +TQ_EXPORT bool tqt_hebrew_keyboard_hack = FALSE; + +static Window mouseActWindow = 0; // window where mouse is +static int mouseButtonPressed = 0; // last mouse button pressed +static int mouseButtonState = 0; // mouse button state +static Time mouseButtonPressTime = 0; // when was a button pressed +static short mouseXPos, mouseYPos; // mouse pres position in act window +static short mouseGlobalXPos, mouseGlobalYPos; // global mouse press position + +extern TQWidgetList *tqt_modal_stack; // stack of modal widgets +static bool ignoreNextMouseReleaseEvent = FALSE; // ignore the next mouse release + // event if return from a modal + // widget + +static TQWidget *popupButtonFocus = 0; +static TQWidget *popupOfPopupButtonFocus = 0; +static bool popupCloseDownMode = FALSE; +static bool popupGrabOk; + +static bool sm_blockUserInput = FALSE; // session management + +int qt_xfocusout_grab_counter = 0; + +#if defined (QT_TABLET_SUPPORT) +// since XInput event classes aren't created until we actually open an XInput +// device, here is a static list that we will use later on... +const int INVALID_EVENT = -1; +const int TOTAL_XINPUT_EVENTS = 7; + +XDevice *devStylus = NULL; +XDevice *devEraser = NULL; +XEventClass event_list_stylus[TOTAL_XINPUT_EVENTS]; +XEventClass event_list_eraser[TOTAL_XINPUT_EVENTS]; + +int qt_curr_events_stylus = 0; +int qt_curr_events_eraser = 0; + +// well, luckily we only need to do this once. +static int xinput_motion = INVALID_EVENT; +static int xinput_key_press = INVALID_EVENT; +static int xinput_key_release = INVALID_EVENT; +static int xinput_button_press = INVALID_EVENT; +static int xinput_button_release = INVALID_EVENT; + +// making this assumption on XFree86, since we can only use 1 device, +// the pressure for the eraser and the stylus should be the same, if they aren't +// well, they certainly have a strange pen then... +static int max_pressure; +extern bool chokeMouse; +#endif + +// last timestamp read from TQSettings +static uint appliedstamp = 0; + + +typedef int (*QX11EventFilter) (XEvent*); +QX11EventFilter tqt_set_x11_event_filter(QX11EventFilter filter); + +static QX11EventFilter qt_x11_event_filter = 0; +TQ_EXPORT QX11EventFilter tqt_set_x11_event_filter(QX11EventFilter filter) +{ + QX11EventFilter old_filter = qt_x11_event_filter; + qt_x11_event_filter = filter; + return old_filter; +} +static bool qt_x11EventFilter( XEvent* ev ) +{ + if ( qt_x11_event_filter && qt_x11_event_filter( ev ) ) + return TRUE; + return tqApp->x11EventFilter( ev ); +} + + + + + +#if !defined(TQT_NO_XIM) +//XIM qt_xim = 0; +TQ_EXPORT XIMStyle qt_xim_style = 0; +TQ_EXPORT XIMStyle qt_xim_preferred_style = 0; +static XIMStyle xim_default_style = XIMPreeditCallbacks | XIMStatusNothing; +#endif + +TQ_EXPORT int qt_ximComposingKeycode=0; +TQ_EXPORT TQTextCodec * qt_input_mapper = 0; + +TQ_EXPORT Time tqt_x_time = CurrentTime; +TQ_EXPORT Time tqt_x_user_time = CurrentTime; +extern bool qt_check_clipboard_sentinel(); //def in tqclipboard_x11.cpp +extern bool qt_check_selection_sentinel(); //def in tqclipboard_x11.cpp + +static void qt_save_rootinfo(); +bool tqt_try_modal( TQWidget *, XEvent * ); + +int qt_ncols_option = 216; // used in tqcolor_x11.cpp +int qt_visual_option = -1; +bool qt_cmap_option = FALSE; +TQWidget *qt_button_down = 0; // widget got last button-down + +extern bool tqt_tryAccelEvent( TQWidget*, TQKeyEvent* ); // def in tqaccel.cpp + +struct TQScrollInProgress { + static long serial; + TQScrollInProgress( TQWidget* w, int x, int y ) : + id( serial++ ), scrolled_widget( w ), dx( x ), dy( y ) {} + long id; + TQWidget* scrolled_widget; + int dx, dy; +}; +long TQScrollInProgress::serial=0; +static TQPtrList *sip_list = 0; + + +// stuff in qt_xdnd.cpp +// setup +extern void qt_xdnd_setup(); +// x event handling +extern void qt_handle_xdnd_enter( TQWidget *, const XEvent *, bool ); +extern void qt_handle_xdnd_position( TQWidget *, const XEvent *, bool ); +extern void qt_handle_xdnd_status( TQWidget *, const XEvent *, bool ); +extern void qt_handle_xdnd_leave( TQWidget *, const XEvent *, bool ); +extern void qt_handle_xdnd_drop( TQWidget *, const XEvent *, bool ); +extern void qt_handle_xdnd_finished( TQWidget *, const XEvent *, bool ); +extern void qt_xdnd_handle_selection_request( const XSelectionRequestEvent * ); +extern bool qt_xdnd_handle_badwindow(); + +extern void qt_motifdnd_handle_msg( TQWidget *, const XEvent *, bool ); +extern void qt_x11_motifdnd_init(); + +// client message atoms +extern Atom qt_xdnd_enter; +extern Atom qt_xdnd_position; +extern Atom qt_xdnd_status; +extern Atom qt_xdnd_leave; +extern Atom qt_xdnd_drop; +extern Atom qt_xdnd_finished; +// xdnd selection atom +extern Atom qt_xdnd_selection; +extern bool qt_xdnd_dragging; + +// gui or non-gui from tqapplication.cpp +extern bool tqt_is_gui_used; +extern bool tqt_app_has_font; + +static bool qt_x11_cmdline_font = false; + + +extern bool tqt_resolve_symlinks; // from tqapplication.cpp + +// Paint event clipping magic +extern void qt_set_paintevent_clipping( TQPaintDevice* dev, const TQRegion& region); +extern void qt_clear_paintevent_clipping(); + + +// Palette handling +extern TQPalette *tqt_std_pal; +extern void tqt_create_std_palette(); + +void qt_x11_intern_atom( const char *, Atom * ); + +static TQPtrList* deferred_map_list = 0; +static void qt_deferred_map_cleanup() +{ + delete deferred_map_list; + deferred_map_list = 0; +} +void qt_deferred_map_add( TQWidget* w) +{ + if ( !deferred_map_list ) { + deferred_map_list = new TQPtrList; + tqAddPostRoutine( qt_deferred_map_cleanup ); + } + deferred_map_list->append( w ); +} +void qt_deferred_map_take( TQWidget* w ) +{ + if (deferred_map_list ) { + deferred_map_list->remove( w ); + } +} +bool qt_deferred_map_contains( TQWidget* w ) +{ + if (!deferred_map_list) + return FALSE; + else + return deferred_map_list->contains( w ); +} + + +class TQETWidget : public TQWidget // event translator widget +{ +public: + void setWState( WFlags f ) { TQWidget::setWState(f); } + void clearWState( WFlags f ) { TQWidget::clearWState(f); } + void setWFlags( WFlags f ) { TQWidget::setWFlags(f); } + void clearWFlags( WFlags f ) { TQWidget::clearWFlags(f); } + bool translateMouseEvent( const XEvent * ); + bool translateKeyEventInternal( const XEvent *, int& count, TQString& text, int& state, char& ascii, int &code, TQEvent::Type &type, bool willRepeat=FALSE, bool statefulTranslation=TRUE ); + bool translateKeyEvent( const XEvent *, bool grab ); + bool translatePaintEvent( const XEvent * ); + bool translateConfigEvent( const XEvent * ); + bool translateCloseEvent( const XEvent * ); + bool translateScrollDoneEvent( const XEvent * ); + bool translateWheelEvent( int global_x, int global_y, int delta, int state, Orientation orient ); +#if defined (QT_TABLET_SUPPORT) + bool translateXinputEvent( const XEvent* ); +#endif + bool translatePropertyEvent(const XEvent *); +}; + + + + +// ************************************************************************ +// Input Method support +// ************************************************************************ + +/*! + An identifier name of the default input method. +*/ +TQString TQApplication::defaultIM = "imsw-multi"; + + +/*! + This function handles the query about location of the widget + holding the TQInputContext instance for widget \a w. + + The input context is used for text input to widget \a w. By + default, it returns the top-level widget of \a w. + + If you want to change the mapping of widget \w to TQInputContext + instance, reimplement both this function and + TQApplication::icHolderWidgets(). For example, suppose a tabbed web + browser. The browser should allocate a input context per tab + widget because users may switch the tabs and input a new text + during previous input contexts live. + + See also 'Sharing input context between text widgets' and 'Preedit + preservation' section of the class description of TQInputContext. + + \sa TQInputContext, icHolderWidgets() +*/ +TQWidget *TQApplication::locateICHolderWidget( TQWidget *w ) +{ + return w->topLevelWidget(); +} + + +/*! + This function returns all widgets holding TQInputContext. + + By default, This function returns top-level widgets. So if you + want to change the mapping of a widget to TQInputContext instance, + you must override this function and locateICHolderWidget(). + + \sa locateICHolderWidget() +*/ +TQWidgetList *TQApplication::icHolderWidgets() +{ + return TQApplication::topLevelWidgets(); +} + + +/*! + This function replaces all TQInputContext instances in the + application. The function's argument is the identifier name of + the newly selected input method. +*/ +void TQApplication::changeAllInputContext( const TQString &identifierName ) +{ + TQWidgetList *list = tqApp->icHolderWidgets(); + TQWidgetListIt it(*list); + while(it.current()) { + it.current()->changeInputContext( identifierName ); + ++it; + } + delete list; + + // defaultIM = identifierName ; // Change of defaultIM -- default input method -- may be enabled. +} + + +/*! + \internal + This is an internal function, you should never call this. + + \sa TQInputContext::imEventGenerated() +*/ +void TQApplication::postIMEvent( TQObject *receiver, TQIMEvent *event ) +{ + if ( event->type() == TQEvent::IMCompose ) { + // enable event compression to reduce preedit flicker on fast + // typing + postEvent( receiver, event ); + } else { + // cancel queued preedit update + if ( event->type() == TQEvent::IMEnd ) + removePostedEvents( receiver, TQEvent::IMCompose ); + + // to avoid event receiving order inversion between TQKeyEvent + // and TQIMEvent, we must send IMStart and IMEnd via + // sendEvent(). + sendEvent( receiver, event ); + delete event; + } +} + + +/*! + This function returns the identifier name of the default input + method in this Application. The value is identical to the value of + TQApplication::defaultIM. +*/ +TQString TQApplication::defaultInputMethod() +{ + return TQApplication::defaultIM; +} + + +#if !defined(TQT_NO_IM_EXTENSIONS) +/*! \internal + Creates the application input method. +*/ +void TQApplication::create_im() +{ +#ifndef TQT_NO_XIM + if ( ! qt_xim_preferred_style ) // no configured input style, use the default + qt_xim_preferred_style = xim_default_style; +#endif // TQT_NO_XIM +} + + +/*! \internal + Closes the application input method. +*/ +void TQApplication::close_im() +{ + TQWidgetList *list = tqApp->icHolderWidgets(); + TQWidgetListIt it(*list); + while(it.current()) { + it.current()->destroyInputContext(); + ++it; + } + delete list; +} + +#else + +/*! \internal + Creates the application input method. +*/ +void TQApplication::create_xim() +{ +#ifndef TQT_NO_XIM + if ( ! qt_xim_preferred_style ) // no configured input style, use the default + qt_xim_preferred_style = xim_default_style; +#endif // TQT_NO_XIM + + TQWidgetList *list= tqApp->topLevelWidgets(); + TQWidgetListIt it(*list); + TQWidget * w; + while( (w=it.current()) != 0 ) { + ++it; + w->createTLSysExtra(); + } + delete list; +} + + + /*! \internal + Closes the application input method. + */ +void TQApplication::close_xim() +{ +#ifndef TQT_NO_XIM + // Calling XCloseIM gives a Purify FMR error + // XCloseIM( qt_xim ); + // We prefer a less serious memory leak + + // if ( qt_xim ) + // qt_xim = 0; + +#endif // TQT_NO_XIM + TQWidgetList *list = tqApp->topLevelWidgets(); + TQWidgetListIt it(*list); + while(it.current()) { + it.current()->destroyInputContext(); + ++it; + } + delete list; +} +#endif + +/***************************************************************************** + Default X error handlers + *****************************************************************************/ + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +static bool x11_ignore_badwindow; +static bool x11_badwindow; + + // starts to ignore bad window errors from X +void qt_ignore_badwindow() +{ + x11_ignore_badwindow = TRUE; + x11_badwindow = FALSE; +} + + // ends ignoring bad window errors and returns whether an error + // had happen. +bool qt_badwindow() +{ + x11_ignore_badwindow = FALSE; + return x11_badwindow; +} + +static int (*original_x_errhandler)( Display *dpy, XErrorEvent * ); +static int (*original_xio_errhandler)( Display *dpy ); + +static int qt_x_errhandler( Display *dpy, XErrorEvent *err ) +{ + if ( err->error_code == BadWindow ) { + x11_badwindow = TRUE; + if ( err->request_code == 25 /* X_SendEvent */ && + qt_xdnd_handle_badwindow() ) + return 0; + if ( x11_ignore_badwindow ) + return 0; + } else if ( err->error_code == BadMatch && + err->request_code == 42 /* X_SetInputFocus */ ) { + return 0; + } + + char errstr[256]; + XGetErrorText( dpy, err->error_code, errstr, 256 ); + tqWarning( "X Error: %s %d\n" + " Major opcode: %d\n" + " Minor opcode: %d\n" + " Resource id: 0x%lx", + errstr, err->error_code, + err->request_code, + err->minor_code, + err->resourceid ); + + // ### we really should distinguish between severe, non-severe and + // ### application specific errors + + return 0; +} + + +static int qt_xio_errhandler( Display * ) +{ + tqWarning( "%s: Fatal IO error: client killed", appName ); + tqApp = 0; + exit( 1 ); + //### give the application a chance for a proper shutdown instead, + //### exit(1) doesn't help. + return 0; +} + +#if defined(Q_C_CALLBACKS) +} +#endif + + +// Memory leak: if the app exits before tqt_init_internal(), this dict +// isn't released correctly. +static TQAsciiDict *atoms_to_be_created = 0; +static bool create_atoms_now = 0; + +/***************************************************************************** + qt_x11_intern_atom() - efficiently interns an atom, now or later. + + If the application is being initialized, this function stores the + adddress of the atom and tqt_init_internal will do the actual work + quickly. If the application is running, the atom is created here. + + Neither argument may point to temporary variables. + *****************************************************************************/ + +void qt_x11_intern_atom( const char *name, Atom *result) +{ + if ( !name || !result || *result ) + return; + + if ( create_atoms_now ) { + *result = XInternAtom( appDpy, name, False ); + } else { + if ( !atoms_to_be_created ) { + atoms_to_be_created = new TQAsciiDict; + atoms_to_be_created->setAutoDelete( FALSE ); + } + atoms_to_be_created->insert( name, result ); + *result = 0; + } +} + + +static void tqt_x11_process_intern_atoms() +{ + if ( atoms_to_be_created ) { +#if defined(XlibSpecificationRelease) && (XlibSpecificationRelease >= 6) + int i = atoms_to_be_created->count(); + Atom * res = (Atom *)malloc( i * sizeof( Atom ) ); + Atom ** resp = (Atom **)malloc( i * sizeof( Atom* ) ); + char ** names = (char **)malloc( i * sizeof(const char*)); + + i = 0; + TQAsciiDictIterator it( *atoms_to_be_created ); + while( it.current() ) { + res[i] = 0; + resp[i] = it.current(); + names[i] = tqstrdup(it.currentKey()); + i++; + ++it; + } + XInternAtoms( appDpy, names, i, False, res ); + while( i ) { + i--; + delete [] names[i]; + if ( res[i] && resp[i] ) + *(resp[i]) = res[i]; + } + free( res ); + free( resp ); + free( names ); +#else + TQAsciiDictIterator it( *atoms_to_be_created ); + Atom * result; + const char * name; + while( (result = it.current()) != 0 ) { + name = it.currentKey(); + ++it; + *result = XInternAtom( appDpy, name, False ); + } +#endif + delete atoms_to_be_created; + atoms_to_be_created = 0; + create_atoms_now = TRUE; + } +} + + +/*! \internal + apply the settings to the application +*/ +bool TQApplication::x11_apply_settings() +{ + if (! tqt_std_pal) + tqt_create_std_palette(); + + Atom type; + int format; + long offset = 0; + unsigned long nitems, after = 1; + unsigned char *data = 0; + TQDateTime timestamp, settingsstamp; + bool update_timestamp = FALSE; + + if (XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow( 0 ), + qt_settings_timestamp, 0, 0, + False, AnyPropertyType, &type, &format, &nitems, + &after, &data) == Success && format == 8) { + if (data) + XFree(data); + + TQBuffer ts; + ts.open(IO_WriteOnly); + + while (after > 0) { + XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow( 0 ), + qt_settings_timestamp, + offset, 1024, False, AnyPropertyType, + &type, &format, &nitems, &after, &data); + if (format == 8) { + ts.writeBlock((const char *) data, nitems); + offset += nitems / 4; + } + + XFree(data); + } + + TQDataStream d(ts.buffer(), IO_ReadOnly); + d >> timestamp; + } + + TQSettings settings; + settingsstamp = settings.lastModificationTime( "/qt/font" ); + if (! settingsstamp.isValid()) + return FALSE; + + if ( appliedstamp && appliedstamp == settingsstamp.toTime_t() ) + return TRUE; + appliedstamp = settingsstamp.toTime_t(); + + if (! timestamp.isValid() || settingsstamp > timestamp) + update_timestamp = TRUE; + + /* + TQt settings. This is now they are written into the datastream. + + /qt/Palette/ * - TQPalette + /qt/font - TQFont + /qt/libraryPath - TQStringList + /qt/style - TQString + /qt/doubleClickInterval - int + /qt/cursorFlashTime - int + /qt/wheelScrollLines - int + /qt/colorSpec - TQString + /qt/defaultCodec - TQString + /qt/globalStrut - TQSize + /qt/GUIEffects - TQStringList + /qt/Font Substitutions/ * - TQStringList + /qt/Font Substitutions/... - TQStringList + */ + + TQString str; + TQStringList strlist; + int i, num; + TQPalette pal(TQApplication::palette()); + strlist = settings.readListEntry("/qt/Palette/active"); + if (strlist.count() == TQColorGroup::NColorRoles) { + for (i = 0; i < TQColorGroup::NColorRoles; i++) + pal.setColor(TQPalette::Active, (TQColorGroup::ColorRole) i, + TQColor(strlist[i])); + } + strlist = settings.readListEntry("/qt/Palette/inactive"); + if (strlist.count() == TQColorGroup::NColorRoles) { + for (i = 0; i < TQColorGroup::NColorRoles; i++) + pal.setColor(TQPalette::Inactive, (TQColorGroup::ColorRole) i, + TQColor(strlist[i])); + } + strlist = settings.readListEntry("/qt/Palette/disabled"); + if (strlist.count() == TQColorGroup::NColorRoles) { + for (i = 0; i < TQColorGroup::NColorRoles; i++) + pal.setColor(TQPalette::Disabled, (TQColorGroup::ColorRole) i, + TQColor(strlist[i])); + } + + // workaround for KDE 3.0, which messes up the buttonText value of + // the disabled palette in TQSettings + if ( pal.disabled().buttonText() == pal.active().buttonText() ) { + pal.setColor( TQPalette::Disabled, TQColorGroup::ButtonText, + pal.disabled().foreground() ); + } + + if (pal != *tqt_std_pal && pal != TQApplication::palette()) { + TQApplication::setPalette(pal, TRUE); + *tqt_std_pal = pal; + } + + TQFont font(TQApplication::font()); + if ( !tqt_app_has_font && !qt_x11_cmdline_font ) { + // read new font + str = settings.readEntry("/qt/font"); + if (! str.isNull() && ! str.isEmpty()) { + font.fromString(str); + + if (font != TQApplication::font()) + TQApplication::setFont(font, TRUE); + } + } + + // read library (ie. plugin) path list + TQString libpathkey = + TQString("/qt/%1.%2/libraryPath").arg( TQT_VERSION >> 16 ).arg( (TQT_VERSION & 0xff00 ) >> 8 ); + TQStringList pathlist = settings.readListEntry(libpathkey, ':'); + if (! pathlist.isEmpty()) { + TQStringList::ConstIterator it = pathlist.begin(); + while (it != pathlist.end()) + TQApplication::addLibraryPath(*it++); + } + + // read new TQStyle + extern bool tqt_explicit_app_style; // defined in tqapplication.cpp + TQString stylename = settings.readEntry( "/qt/style" ); + if ( !stylename.isEmpty() && !tqt_explicit_app_style ) { + TQApplication::setStyle( stylename ); + // took the style from the user settings, so mark the explicit flag FALSE + tqt_explicit_app_style = FALSE; + } + + num = + settings.readNumEntry("/qt/doubleClickInterval", + TQApplication::doubleClickInterval()); + TQApplication::setDoubleClickInterval(num); + + num = + settings.readNumEntry("/qt/cursorFlashTime", + TQApplication::cursorFlashTime()); + TQApplication::setCursorFlashTime(num); + + num = + settings.readNumEntry("/qt/wheelScrollLines", + TQApplication::wheelScrollLines()); + TQApplication::setWheelScrollLines(num); + + TQString colorspec = settings.readEntry("/qt/colorSpec", "default"); + if (colorspec == "normal") + TQApplication::setColorSpec(TQApplication::NormalColor); + else if (colorspec == "custom") + TQApplication::setColorSpec(TQApplication::CustomColor); + else if (colorspec == "many") + TQApplication::setColorSpec(TQApplication::ManyColor); + else if (colorspec != "default") + colorspec = "default"; + + TQString defaultcodec = settings.readEntry("/qt/defaultCodec", "none"); + if (defaultcodec != "none") { + TQTextCodec *codec = TQTextCodec::codecForName(defaultcodec); + if (codec) + tqApp->setDefaultCodec(codec); + } + + TQStringList strut = settings.readListEntry("/qt/globalStrut"); + if (! strut.isEmpty()) { + if (strut.count() == 2) { + TQSize sz(strut[0].toUInt(), strut[1].toUInt()); + + if (sz.isValid()) + TQApplication::setGlobalStrut(sz); + } + } + + TQStringList effects = settings.readListEntry("/qt/GUIEffects"); + + TQApplication::setEffectEnabled( TQt::UI_General, effects.contains("general") ); + TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, effects.contains("animatemenu") ); + TQApplication::setEffectEnabled( TQt::UI_FadeMenu, effects.contains("fademenu") ); + TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, effects.contains("animatecombo") ); + TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, effects.contains("animatetooltip") ); + TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, effects.contains("fadetooltip") ); + TQApplication::setEffectEnabled( TQt::UI_AnimateToolBox, effects.contains("animatetoolbox") ); + + TQStringList fontsubs = + settings.entryList("/qt/Font Substitutions"); + if (!fontsubs.isEmpty()) { + TQStringList subs; + TQString fam, skey; + TQStringList::Iterator it = fontsubs.begin(); + while (it != fontsubs.end()) { + fam = (*it++); + skey = "/qt/Font Substitutions/" + fam; + subs = settings.readListEntry(skey); + TQFont::insertSubstitutions(fam, subs); + } + } + + qt_broken_wm = + settings.readBoolEntry("/qt/brokenWindowManager", qt_broken_wm); + + tqt_resolve_symlinks = + settings.readBoolEntry("/qt/resolveSymlinks", TRUE); + + qt_use_rtl_extensions = + settings.readBoolEntry("/qt/useRtlExtensions", FALSE); + +#ifndef TQT_NO_XIM + if (qt_xim_preferred_style == 0) { + TQString ximInputStyle = + settings.readEntry( "/qt/XIMInputStyle", + TQString::fromLatin1( "On The Spot" ) ).lower(); + if ( ximInputStyle == "over the spot" ) + qt_xim_preferred_style = XIMPreeditPosition | XIMStatusNothing; + else if ( ximInputStyle == "off the spot" ) + qt_xim_preferred_style = XIMPreeditArea | XIMStatusArea; + else if ( ximInputStyle == "root" ) + qt_xim_preferred_style = XIMPreeditNothing | XIMStatusNothing; + else // ximInputStyle == "on the spot" or others + qt_xim_preferred_style = XIMPreeditCallbacks | XIMStatusNothing; + } +#endif + +#ifndef TQT_NO_IM + /* + The identifier name of an input method is acquired from the + configuration file as a default. If a environment variable + "TQT_IM_SWITCHER" is not empty it will overwrite the + configuration file. The "imsw-multi" becomes the default if the entry + is not configured. + */ + if ( getenv( "TQT_IM_SWITCHER" ) ) + defaultIM = getenv( "TQT_IM_SWITCHER" ); +#ifndef TQT_NO_IM_EXTENSIONS + else + defaultIM = settings.readEntry( "/qt/DefaultInputMethodSwitcher", "imsw-multi" ); +#endif + + // defaultIM is restricted to be an IM-switcher. An IM-switcher + // has a 'imsw-' prefix + if ( ! defaultIM.startsWith( "imsw-" ) ) { + defaultIM = "imsw-multi"; + } +#endif + + if (update_timestamp) { + TQBuffer stamp; + TQDataStream s(stamp.buffer(), IO_WriteOnly); + s << settingsstamp; + + XChangeProperty(appDpy, TQPaintDevice::x11AppRootWindow( 0 ), + qt_settings_timestamp, qt_settings_timestamp, 8, + PropModeReplace, (unsigned char *) stamp.buffer().data(), + stamp.buffer().size()); + } + + return TRUE; +} + + +// read the _QT_INPUT_ENCODING property and apply the settings to +// the application +static void qt_set_input_encoding() +{ + Atom type; + int format; + ulong nitems, after = 1; + const char *data; + + int e = XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), + qt_input_encoding, 0, 1024, + False, XA_STRING, &type, &format, &nitems, + &after, (unsigned char**)&data ); + if ( e != Success || !nitems || type == None ) { + // Always use the locale codec, since we have no examples of non-local + // XIMs, and since we cannot get a sensible answer about the encoding + // from the XIM. + qt_input_mapper = TQTextCodec::codecForLocale(); + + } else { + if ( !tqstricmp( data, "locale" ) ) + qt_input_mapper = TQTextCodec::codecForLocale(); + else + qt_input_mapper = TQTextCodec::codecForName( data ); + // make sure we have an input codec + if( !qt_input_mapper ) + qt_input_mapper = TQTextCodec::codecForName( "ISO 8859-1" ); + } + if ( qt_input_mapper->mibEnum() == 11 ) // 8859-8 + qt_input_mapper = TQTextCodec::codecForName( "ISO 8859-8-I"); + if( data ) + XFree( (char *)data ); +} + +// set font, foreground and background from x11 resources. The +// arguments may override the resource settings. +static void qt_set_x11_resources( const char* font = 0, const char* fg = 0, + const char* bg = 0, const char* button = 0 ) +{ + if ( !tqt_std_pal ) + tqt_create_std_palette(); + + TQCString resFont, resFG, resBG, resEF, sysFont; + + TQApplication::setEffectEnabled( TQt::UI_General, FALSE); + TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, FALSE); + TQApplication::setEffectEnabled( TQt::UI_FadeMenu, FALSE); + TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, FALSE ); + TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, FALSE ); + TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, FALSE ); + TQApplication::setEffectEnabled( TQt::UI_AnimateToolBox, FALSE ); + + if ( TQApplication::desktopSettingsAware() && !TQApplication::x11_apply_settings() ) { + int format; + ulong nitems, after = 1; + TQCString res; + long offset = 0; + Atom type = None; + + while (after > 0) { + uchar *data; + XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow( 0 ), + qt_resource_manager, + offset, 8192, False, AnyPropertyType, + &type, &format, &nitems, &after, + &data ); + res += (char*)data; + offset += 2048; // offset is in 32bit quantities... 8192/4 == 2048 + if ( data ) + XFree( (char *)data ); + } + + TQCString key, value; + int l = 0, r; + TQCString apn = appName; + TQCString apc = appClass; + int apnl = apn.length(); + int apcl = apc.length(); + int resl = res.length(); + + while (l < resl) { + r = res.find( '\n', l ); + if ( r < 0 ) + r = resl; + while ( isspace((uchar) res[l]) ) + l++; + bool mine = FALSE; + if ( res[l] == '*' && + (res[l+1] == 'f' || res[l+1] == 'b' || res[l+1] == 'g' || + res[l+1] == 'F' || res[l+1] == 'B' || res[l+1] == 'G' || + res[l+1] == 's' || res[l+1] == 'S' ) ) { + // OPTIMIZED, since we only want "*[fbgs].." + + TQCString item = res.mid( l, r - l ).simplifyWhiteSpace(); + int i = item.find( ":" ); + key = item.left( i ).stripWhiteSpace().mid(1).lower(); + value = item.right( item.length() - i - 1 ).stripWhiteSpace(); + mine = TRUE; + } else if ( res[l] == appName[0] || (appClass && res[l] == appClass[0]) ) { + if (res.mid(l,apnl) == apn && (res[l+apnl] == '.' || res[l+apnl] == '*')) { + TQCString item = res.mid( l, r - l ).simplifyWhiteSpace(); + int i = item.find( ":" ); + key = item.left( i ).stripWhiteSpace().mid(apnl+1).lower(); + value = item.right( item.length() - i - 1 ).stripWhiteSpace(); + mine = TRUE; + } else if (res.mid(l,apcl) == apc && (res[l+apcl] == '.' || res[l+apcl] == '*')) { + TQCString item = res.mid( l, r - l ).simplifyWhiteSpace(); + int i = item.find( ":" ); + key = item.left( i ).stripWhiteSpace().mid(apcl+1).lower(); + value = item.right( item.length() - i - 1 ).stripWhiteSpace(); + mine = TRUE; + } + } + + if ( mine ) { + if ( !font && key == "systemfont") + sysFont = value.left( value.findRev(':') ).copy(); + if ( !font && key == "font") + resFont = value.copy(); + else if ( !fg && key == "foreground" ) + resFG = value.copy(); + else if ( !bg && key == "background") + resBG = value.copy(); + else if ( key == "guieffects") + resEF = value.copy(); + // NOTE: if you add more, change the [fbg] stuff above + } + + l = r + 1; + } + } + if ( !sysFont.isEmpty() ) + resFont = sysFont; + if ( resFont.isEmpty() ) + resFont = font; + if ( resFG.isEmpty() ) + resFG = fg; + if ( resBG.isEmpty() ) + resBG = bg; + if ( (!tqt_app_has_font || qt_x11_cmdline_font) && !resFont.isEmpty() ) { // set application font + TQFont fnt; + fnt.setRawName( resFont ); + + // the font we get may actually be an alias for another font, + // so we reset the application font to the real font info. + if ( ! fnt.exactMatch() ) { + TQFontInfo fontinfo( fnt ); + fnt.setFamily( fontinfo.family() ); + fnt.setRawMode( fontinfo.rawMode() ); + + if ( ! fnt.rawMode() ) { + fnt.setItalic( fontinfo.italic() ); + fnt.setWeight( fontinfo.weight() ); + fnt.setUnderline( fontinfo.underline() ); + fnt.setStrikeOut( fontinfo.strikeOut() ); + fnt.setStyleHint( fontinfo.styleHint() ); + + if ( fnt.pointSize() <= 0 && fnt.pixelSize() <= 0 ) + // size is all wrong... fix it + fnt.setPointSize( (int) ( ( fontinfo.pixelSize() * 72. / + (float) TQPaintDevice::x11AppDpiY() ) + + 0.5 ) ); + } + } + + if ( fnt != TQApplication::font() ) { + TQApplication::setFont( fnt, TRUE ); + } + } + + if ( button || !resBG.isEmpty() || !resFG.isEmpty() ) {// set app colors + TQColor btn; + TQColor bg; + TQColor fg; + if ( !resBG.isEmpty() ) + bg = TQColor(TQString(resBG)); + else + bg = tqt_std_pal->active().background(); + if ( !resFG.isEmpty() ) + fg = TQColor(TQString(resFG)); + else + fg = tqt_std_pal->active().foreground(); + if ( button ) + btn = TQColor( button ); + else if ( !resBG.isEmpty() ) + btn = bg; + else + btn = tqt_std_pal->active().button(); + + int h,s,v; + fg.hsv(&h,&s,&v); + TQColor base = TQt::white; + bool bright_mode = FALSE; + if (v >= 255-50) { + base = btn.dark(150); + bright_mode = TRUE; + } + + TQColorGroup cg( fg, btn, btn.light(), + btn.dark(), btn.dark(150), fg, TQt::white, base, bg ); + if (bright_mode) { + cg.setColor( TQColorGroup::HighlightedText, base ); + cg.setColor( TQColorGroup::Highlight, TQt::white ); + } else { + cg.setColor( TQColorGroup::HighlightedText, TQt::white ); + cg.setColor( TQColorGroup::Highlight, TQt::darkBlue ); + } + TQColor disabled( (fg.red()+btn.red())/2, + (fg.green()+btn.green())/2, + (fg.blue()+btn.blue())/2); + TQColorGroup dcg( disabled, btn, btn.light( 125 ), btn.dark(), btn.dark(150), + disabled, TQt::white, TQt::white, bg ); + if (bright_mode) { + dcg.setColor( TQColorGroup::HighlightedText, base ); + dcg.setColor( TQColorGroup::Highlight, TQt::white ); + } else { + dcg.setColor( TQColorGroup::HighlightedText, TQt::white ); + dcg.setColor( TQColorGroup::Highlight, TQt::darkBlue ); + } + TQPalette pal( cg, dcg, cg ); + if ( pal != *tqt_std_pal && pal != TQApplication::palette() ) + TQApplication::setPalette( pal, TRUE ); + *tqt_std_pal = pal; + } + + if ( !resEF.isEmpty() ) { + TQStringList effects = TQStringList::split(" ",resEF); + TQApplication::setEffectEnabled( TQt::UI_General, effects.contains("general") ); + TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, effects.contains("animatemenu") ); + TQApplication::setEffectEnabled( TQt::UI_FadeMenu, effects.contains("fademenu") ); + TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, effects.contains("animatecombo") ); + TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, effects.contains("animatetooltip") ); + TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, effects.contains("fadetooltip") ); + TQApplication::setEffectEnabled( TQt::UI_AnimateToolBox, effects.contains("animatetoolbox") ); + } +} + + +static void qt_detect_broken_window_manager() +{ + Atom type; + int format; + ulong nitems, after; + uchar *data = 0; + + // look for SGI's 4Dwm + int e = XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), + qt_sgi_desks_manager, 0, 1, False, XA_WINDOW, + &type, &format, &nitems, &after, &data); + if (data) + XFree(data); + + if (e == Success && type == XA_WINDOW && format == 32 && nitems == 1 && after == 0) { + // detected SGI 4Dwm + qt_broken_wm = TRUE; + } +} + + +// update the supported array +void qt_get_net_supported() +{ + Atom type; + int format; + long offset = 0; + unsigned long nitems, after; + unsigned char *data = 0; + + int e = XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), + qt_net_supported, 0, 0, + False, XA_ATOM, &type, &format, &nitems, &after, &data); + if (data) + XFree(data); + + if (qt_net_supported_list) + delete [] qt_net_supported_list; + qt_net_supported_list = 0; + + if (e == Success && type == XA_ATOM && format == 32) { + TQBuffer ts; + ts.open(IO_WriteOnly); + + while (after > 0) { + XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), + qt_net_supported, offset, 1024, + False, XA_ATOM, &type, &format, &nitems, &after, &data); + + if (type == XA_ATOM && format == 32) { + ts.writeBlock((const char *) data, nitems * sizeof(long)); + offset += nitems; + } else + after = 0; + if (data) + XFree(data); + } + + // compute nitems + TQByteArray buffer(ts.buffer()); + nitems = buffer.size() / sizeof(Atom); + qt_net_supported_list = new Atom[nitems + 1]; + Atom *a = (Atom *) buffer.data(); + uint i; + for (i = 0; i < nitems; i++) + qt_net_supported_list[i] = a[i]; + qt_net_supported_list[nitems] = 0; + } +} + + +bool qt_net_supports(Atom atom) +{ + if (! qt_net_supported_list) + return FALSE; + + bool supported = FALSE; + int i = 0; + while (qt_net_supported_list[i] != 0) { + if (qt_net_supported_list[i++] == atom) { + supported = TRUE; + break; + } + } + + return supported; +} + + +// update the virtual roots array +void qt_get_net_virtual_roots() +{ + if (qt_net_virtual_root_list) + delete [] qt_net_virtual_root_list; + qt_net_virtual_root_list = 0; + + if (! qt_net_supports(qt_net_virtual_roots)) + return; + + Atom type; + int format; + long offset = 0; + unsigned long nitems, after; + unsigned char *data; + + int e = XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), + qt_net_virtual_roots, 0, 0, + False, XA_ATOM, &type, &format, &nitems, &after, &data); + if (data) + XFree(data); + + if (e == Success && type == XA_ATOM && format == 32) { + TQBuffer ts; + ts.open(IO_WriteOnly); + + while (after > 0) { + XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(), + qt_net_virtual_roots, offset, 1024, + False, XA_ATOM, &type, &format, &nitems, &after, &data); + + if (type == XA_ATOM && format == 32) { + ts.writeBlock((const char *) data, nitems * 4); + offset += nitems; + } else + after = 0; + if (data) + XFree(data); + } + + // compute nitems + TQByteArray buffer(ts.buffer()); + nitems = buffer.size() / sizeof(Window); + qt_net_virtual_root_list = new Window[nitems + 1]; + Window *a = (Window *) buffer.data(); + uint i; + for (i = 0; i < nitems; i++) + qt_net_virtual_root_list[i] = a[i]; + qt_net_virtual_root_list[nitems] = 0; + } +} + +void qt_x11_create_wm_client_leader() +{ + if ( qt_x11_wm_client_leader ) return; + + qt_x11_wm_client_leader = + XCreateSimpleWindow( TQPaintDevice::x11AppDisplay(), + TQPaintDevice::x11AppRootWindow(), + 0, 0, 1, 1, 0, 0, 0 ); + + // set client leader property to itself + XChangeProperty( TQPaintDevice::x11AppDisplay(), + qt_x11_wm_client_leader, qt_wm_client_leader, + XA_WINDOW, 32, PropModeReplace, + (unsigned char *)&qt_x11_wm_client_leader, 1 ); + + // If we are session managed, inform the window manager about it + TQCString session = tqApp->sessionId().latin1(); + if ( !session.isEmpty() ) { + XChangeProperty( TQPaintDevice::x11AppDisplay(), + qt_x11_wm_client_leader, tqt_sm_client_id, + XA_STRING, 8, PropModeReplace, + (unsigned char *)session.data(), session.length() ); + } +} + +static void qt_net_update_user_time(TQWidget *tlw) +{ + XChangeProperty(TQPaintDevice::x11AppDisplay(), tlw->winId(), qt_net_wm_user_time, XA_CARDINAL, + 32, PropModeReplace, (unsigned char *) &tqt_x_user_time, 1); +} + +static void qt_check_focus_model() +{ + Window fw = None; + int unused; + XGetInputFocus( appDpy, &fw, &unused ); + if ( fw == PointerRoot ) + qt_focus_model = FocusModel_PointerRoot; + else + qt_focus_model = FocusModel_Other; +} + + +/* + Returns a truecolor visual (if there is one). 8-bit TrueColor visuals + are ignored, unless the user has explicitly requested -visual TrueColor. + The SGI X server usually has an 8 bit default visual, but the application + can also ask for a truecolor visual. This is what we do if + TQApplication::colorSpec() is TQApplication::ManyColor. +*/ + +static Visual *find_truecolor_visual( Display *dpy, int scr, int *depth, int *ncols ) +{ + XVisualInfo *vi, rvi; + int best=0, n, i; + rvi.c_class = TrueColor; + rvi.screen = scr; + vi = XGetVisualInfo( dpy, VisualClassMask | VisualScreenMask, + &rvi, &n ); + if ( vi ) { + for ( i=0; i vi[best].depth ) + best = i; + } + } + Visual *v = DefaultVisual(dpy,scr); + if ( !vi || (vi[best].visualid == XVisualIDFromVisual(v)) || + (vi[best].depth <= 8 && qt_visual_option != TrueColor) ) + { + *depth = DefaultDepth(dpy,scr); + *ncols = DisplayCells(dpy,scr); + } else { + v = vi[best].visual; + *depth = vi[best].depth; + *ncols = vi[best].colormap_size; + } + if ( vi ) + XFree( (char *)vi ); + return v; +} + +static KeySym qt_x11_keycode_to_keysym(Display *dpy, KeyCode kc) { +#ifndef TQT_NO_XKB + return XkbKeycodeToKeysym(dpy, kc, 0, 0); +#else + KeySym rv = NoSymbol; + int keysyms_per_keycode; + KeySym *keysym_p = XGetKeyboardMapping(dpy, kc, 1, &keysyms_per_keycode); + if (keysyms_per_keycode>0) { //< Should always be true unless X server is bugged + rv = keysym_p[0]; + } + XFree(keysym_p); + + return rv; +#endif // TQT_NO_XKB +} + +/***************************************************************************** + tqt_init() - initializes TQt for X11 + *****************************************************************************/ + +#define XK_MISCELLANY +#define XK_LATIN1 +#define XK_KOREAN +#define XK_XKB_KEYS +#include + +// ### This should be static but it isn't because of the friend declaration +// ### in tqpaintdevice.h which then should have a static too but can't have +// ### it because "storage class specifiers invalid in friend function +// ### declarations" :-) Ideas anyone? +void tqt_init_internal( int *argcptr, char **argv, + Display *display, TQt::HANDLE visual, TQt::HANDLE colormap ) +{ + setlocale( LC_ALL, "" ); // use correct char set mapping + setlocale( LC_NUMERIC, "C" ); // make sprintf()/scanf() work + +#if defined(TQT_THREAD_SUPPORT) + if (( tqt_is_gui_used ) && ( !display )) { + // If TQt is running standalone with a GUI, initialize X11 threading + XInitThreads(); + } +#endif + + if ( display && ((!argcptr) || (!argv)) ) { + // TQt part of other application + + appForeignDpy = TRUE; + appDpy = display; + + // Set application name and class + appName = tqstrdup( "TQt-subapplication" ); + char *app_class = 0; + if (argv) { + const char* p = strrchr( argv[0], '/' ); + app_class = tqstrdup(p ? p + 1 : argv[0]); + if (app_class[0]) + app_class[0] = toupper(app_class[0]); + } + appClass = app_class; + + // Install default error handlers + original_x_errhandler = XSetErrorHandler( qt_x_errhandler ); + original_xio_errhandler = XSetIOErrorHandler( qt_xio_errhandler ); + } else { + // TQt controls everything (default) + + int argc = *argcptr; + int j; + + // Install default error handlers + original_x_errhandler = XSetErrorHandler( qt_x_errhandler ); + original_xio_errhandler = XSetIOErrorHandler( qt_xio_errhandler ); + + // Set application name and class + char *app_class = 0; + if (argv) { + const char *p = strrchr( argv[0], '/' ); + appName = p ? p + 1 : argv[0]; + app_class = tqstrdup(appName); + if (app_class[0]) + app_class[0] = toupper(app_class[0]); + } + appClass = app_class; + + // Get command line params + j = argc ? 1 : 0; + for ( int i=1; i 0 ) { + if ( c == '/' ) + s.truncate( 0 ); + else + s += (char)c; + } + if ( s == "gdb" ) { + appNoGrab = TRUE; + tqDebug( "TQt: gdb: -nograb added to command-line options.\n" + "\t Use the -dograb option to enforce grabbing." ); + } + f.close(); + } + } +#endif + if ( display ) { + // Display connection already opened by another application + + appForeignDpy = TRUE; + appDpy = display; + } + else { + // Connect to X server + + if( tqt_is_gui_used ) { + if ( ( appDpy = XOpenDisplay(appDpyName) ) == 0 ) { + tqWarning( "%s: cannot connect to X server %s", appName, + XDisplayName(appDpyName) ); + tqApp = 0; + exit( 1 ); + } + + if ( appSync ) // if "-sync" argument + XSynchronize( appDpy, TRUE ); + } + } + } + // Common code, regardless of whether display is foreign. + + // Get X parameters + + if( tqt_is_gui_used ) { + appScreen = DefaultScreen(appDpy); + appScreenCount = ScreenCount(appDpy); + + TQPaintDevice::x_appdisplay = appDpy; + TQPaintDevice::x_appscreen = appScreen; + + // allocate the arrays for the TQPaintDevice data + TQPaintDevice::x_appdepth_arr = new int[ appScreenCount ]; + TQPaintDevice::x_appcells_arr = new int[ appScreenCount ]; + TQPaintDevice::x_approotwindow_arr = new TQt::HANDLE[ appScreenCount ]; + TQPaintDevice::x_appcolormap_arr = new TQt::HANDLE[ appScreenCount ]; + TQPaintDevice::x_appdefcolormap_arr = new bool[ appScreenCount ]; + TQPaintDevice::x_appvisual_arr = new void*[ appScreenCount ]; + TQPaintDevice::x_appdefvisual_arr = new bool[ appScreenCount ]; + TQ_CHECK_PTR( TQPaintDevice::x_appdepth_arr ); + TQ_CHECK_PTR( TQPaintDevice::x_appcells_arr ); + TQ_CHECK_PTR( TQPaintDevice::x_approotwindow_arr ); + TQ_CHECK_PTR( TQPaintDevice::x_appcolormap_arr ); + TQ_CHECK_PTR( TQPaintDevice::x_appdefcolormap_arr ); + TQ_CHECK_PTR( TQPaintDevice::x_appvisual_arr ); + TQ_CHECK_PTR( TQPaintDevice::x_appdefvisual_arr ); + + int screen; + TQString serverVendor( ServerVendor( appDpy) ); + if (serverVendor.contains("XFree86") && VendorRelease(appDpy) < 40300000) + tqt_hebrew_keyboard_hack = TRUE; + + for ( screen = 0; screen < appScreenCount; ++screen ) { + TQPaintDevice::x_appdepth_arr[ screen ] = DefaultDepth(appDpy, screen); + TQPaintDevice::x_appcells_arr[ screen ] = DisplayCells(appDpy, screen); + TQPaintDevice::x_approotwindow_arr[ screen ] = RootWindow(appDpy, screen); + + // setup the visual and colormap for each screen + Visual *vis = 0; + if ( visual && screen == appScreen ) { + // use the provided visual on the default screen only + vis = (Visual *) visual; + + // figure out the depth of the visual we are using + XVisualInfo *vi, rvi; + int n; + rvi.visualid = XVisualIDFromVisual(vis); + rvi.screen = screen; + vi = XGetVisualInfo( appDpy, VisualIDMask | VisualScreenMask, &rvi, &n ); + if (vi) { + TQPaintDevice::x_appdepth_arr[ screen ] = vi->depth; + TQPaintDevice::x_appcells_arr[ screen ] = vi->visual->map_entries; + TQPaintDevice::x_appvisual_arr[ screen ] = vi->visual; + TQPaintDevice::x_appdefvisual_arr[ screen ] = FALSE; + XFree(vi); + } else { + // couldn't get info about the visual, use the default instead + vis = 0; + } + } + + if (!vis) { + // use the default visual + vis = DefaultVisual(appDpy, screen); + TQPaintDevice::x_appdefvisual_arr[ screen ] = TRUE; + + if ( qt_visual_option == TrueColor || + TQApplication::colorSpec() == TQApplication::ManyColor ) { + // find custom visual + + int d, c; + vis = find_truecolor_visual( appDpy, screen, &d, &c ); + TQPaintDevice::x_appdepth_arr[ screen ] = d; + TQPaintDevice::x_appcells_arr[ screen ] = c; + + TQPaintDevice::x_appvisual_arr[ screen ] = vis; + TQPaintDevice::x_appdefvisual_arr[ screen ] = + (XVisualIDFromVisual(vis) == + XVisualIDFromVisual(DefaultVisual(appDpy, screen))); + } + + TQPaintDevice::x_appvisual_arr[ screen ] = vis; + } + + // we assume that 8bpp == pseudocolor, but this is not + // always the case (according to the X server), so we need + // to make sure that our internal data is setup in a way + // that is compatible with our assumptions + if ( vis->c_class == TrueColor && + TQPaintDevice::x_appdepth_arr[ screen ] == 8 && + TQPaintDevice::x_appcells_arr[ screen ] == 8 ) + TQPaintDevice::x_appcells_arr[ screen ] = 256; + + if ( colormap && screen == appScreen ) { + // use the provided colormap for the default screen only + TQPaintDevice::x_appcolormap_arr[ screen ] = colormap; + TQPaintDevice::x_appdefcolormap_arr[ screen ] = FALSE; + } else { + if ( vis->c_class == TrueColor ) { + TQPaintDevice::x_appdefcolormap_arr[ screen ] = + TQPaintDevice::x_appdefvisual_arr[ screen ]; + } else { + TQPaintDevice::x_appdefcolormap_arr[ screen ] = + !qt_cmap_option && TQPaintDevice::x_appdefvisual_arr[ screen ]; + } + + if ( TQPaintDevice::x_appdefcolormap_arr[ screen ] ) { + // use default colormap + XStandardColormap *stdcmap; + VisualID vid = + XVisualIDFromVisual((Visual *) + TQPaintDevice::x_appvisual_arr[ screen ]); + int i, count; + + TQPaintDevice::x_appcolormap_arr[ screen ] = 0; + + if ( ! serverVendor.contains( "Hewlett-Packard" ) ) { + // on HPUX 10.20 local displays, the RGB_DEFAULT_MAP colormap + // doesn't give us correct colors. Why this happens, I have + // no clue, so we disable this for HPUX + if (XGetRGBColormaps(appDpy, + TQPaintDevice::x11AppRootWindow( screen ), + &stdcmap, &count, XA_RGB_DEFAULT_MAP)) { + i = 0; + while (i < count && + TQPaintDevice::x_appcolormap_arr[ screen ] == 0) { + if (stdcmap[i].visualid == vid) { + TQPaintDevice::x_appcolormap_arr[ screen ] = + stdcmap[i].colormap; + } + i++; + } + + XFree( (char *)stdcmap ); + } + } + + if (TQPaintDevice::x_appcolormap_arr[ screen ] == 0) { + TQPaintDevice::x_appcolormap_arr[ screen ] = + DefaultColormap(appDpy, screen); + } + } else { + // create a custom colormap + TQPaintDevice::x_appcolormap_arr[ screen ] = + XCreateColormap(appDpy, TQPaintDevice::x11AppRootWindow( screen ), + vis, AllocNone); + } + } + } + + // Set X paintdevice parameters for the default screen + TQPaintDevice::x_appdepth = TQPaintDevice::x_appdepth_arr[ appScreen ]; + TQPaintDevice::x_appcells = TQPaintDevice::x_appcells_arr[ appScreen ]; + TQPaintDevice::x_approotwindow = TQPaintDevice::x_approotwindow_arr[ appScreen ]; + TQPaintDevice::x_appcolormap = TQPaintDevice::x_appcolormap_arr[ appScreen ]; + TQPaintDevice::x_appdefcolormap = TQPaintDevice::x_appdefcolormap_arr[ appScreen ]; + TQPaintDevice::x_appvisual = TQPaintDevice::x_appvisual_arr[ appScreen ]; + TQPaintDevice::x_appdefvisual = TQPaintDevice::x_appdefvisual_arr[ appScreen ]; + + // Support protocols + + qt_x11_intern_atom( "WM_PROTOCOLS", &tqt_wm_protocols ); + qt_x11_intern_atom( "WM_DELETE_WINDOW", &tqt_wm_delete_window ); + qt_x11_intern_atom( "WM_STATE", &tqt_wm_state ); + qt_x11_intern_atom( "WM_CHANGE_STATE", &qt_wm_change_state ); + qt_x11_intern_atom( "WM_TAKE_FOCUS", &tqt_wm_take_focus ); + qt_x11_intern_atom( "WM_CLIENT_LEADER", &qt_wm_client_leader); + qt_x11_intern_atom( "WM_WINDOW_ROLE", &tqt_window_role); + qt_x11_intern_atom( "SM_CLIENT_ID", &tqt_sm_client_id); + qt_x11_intern_atom( "CLIPBOARD", &qt_xa_clipboard ); + qt_x11_intern_atom( "RESOURCE_MANAGER", &qt_resource_manager ); + qt_x11_intern_atom( "INCR", &qt_x_incr ); + qt_x11_intern_atom( "_XSETROOT_ID", &qt_xsetroot_id ); + qt_x11_intern_atom( "_QT_SELECTION", &qt_selection_property ); + qt_x11_intern_atom( "_QT_CLIPBOARD_SENTINEL", &tqt_clipboard_sentinel ); + qt_x11_intern_atom( "_QT_SELECTION_SENTINEL", &qt_selection_sentinel ); + qt_x11_intern_atom( "_QT_SCROLL_DONE", &qt_qt_scrolldone ); + qt_x11_intern_atom( "_QT_INPUT_ENCODING", &qt_input_encoding ); + qt_x11_intern_atom( "_QT_SIZEGRIP", &qt_sizegrip ); + qt_x11_intern_atom( "_NET_WM_CONTEXT_HELP", &qt_net_wm_context_help ); + qt_x11_intern_atom( "_NET_WM_PING", &qt_net_wm_ping ); + qt_x11_intern_atom( "_MOTIF_WM_HINTS", &qt_xa_motif_wm_hints ); + qt_x11_intern_atom( "DTWM_IS_RUNNING", &qt_cde_running ); + qt_x11_intern_atom( "KWIN_RUNNING", &qt_twin_running ); + qt_x11_intern_atom( "KWM_RUNNING", &qt_kwm_running ); + qt_x11_intern_atom( "GNOME_BACKGROUND_PROPERTIES", &qt_gbackground_properties ); + + TQString atomname("_QT_SETTINGS_TIMESTAMP_"); + atomname += XDisplayName(appDpyName); + qt_x11_intern_atom( atomname.latin1(), &qt_settings_timestamp ); + + qt_x11_intern_atom( "_NET_SUPPORTED", &qt_net_supported ); + qt_x11_intern_atom( "_NET_VIRTUAL_ROOTS", &qt_net_virtual_roots ); + qt_x11_intern_atom( "_NET_WORKAREA", &qt_net_workarea ); + qt_x11_intern_atom( "_NET_WM_STATE", &qt_net_wm_state ); + qt_x11_intern_atom( "_NET_WM_STATE_MODAL", &qt_net_wm_state_modal ); + qt_x11_intern_atom( "_NET_WM_STATE_MAXIMIZED_VERT", &qt_net_wm_state_max_v ); + qt_x11_intern_atom( "_NET_WM_STATE_MAXIMIZED_HORZ", &qt_net_wm_state_max_h ); + qt_x11_intern_atom( "_NET_WM_STATE_FULLSCREEN", &qt_net_wm_state_fullscreen ); + qt_x11_intern_atom( "_NET_WM_STATE_ABOVE", &qt_net_wm_state_above ); + qt_x11_intern_atom( "_NET_WM_ALLOWED_ACTIONS", &qt_net_wm_action ); + qt_x11_intern_atom( "_NET_WM_ACTION_MOVE", &qt_net_wm_action_move ); + qt_x11_intern_atom( "_NET_WM_ACTION_RESIZE", &qt_net_wm_action_resize ); + qt_x11_intern_atom( "_NET_WM_ACTION_MINIMIZE", &qt_net_wm_action_minimize ); + qt_x11_intern_atom( "_NET_WM_ACTION_SHADE", &qt_net_wm_action_shade ); + qt_x11_intern_atom( "_NET_WM_ACTION_STICK", &qt_net_wm_action_stick ); + qt_x11_intern_atom( "_NET_WM_ACTION_MAXIMIZE_HORZ", &qt_net_wm_action_max_h ); + qt_x11_intern_atom( "_NET_WM_ACTION_MAXIMIZE_VERT", &qt_net_wm_action_max_v ); + qt_x11_intern_atom( "_NET_WM_ACTION_FULLSCREEN", &qt_net_wm_action_fullscreen ); + qt_x11_intern_atom( "_NET_WM_ACTION_CHANGE_DESKTOP", &qt_net_wm_action_change_desktop ); + qt_x11_intern_atom( "_NET_WM_ACTION_CLOSE", &qt_net_wm_action_close ); + qt_x11_intern_atom( "_NET_WM_ACTION_ABOVE", &qt_net_wm_action_above ); + qt_x11_intern_atom( "_NET_WM_ACTION_BELOW", &qt_net_wm_action_below ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE", &qt_net_wm_window_type ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_NORMAL", &qt_net_wm_window_type_normal ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_DIALOG", &qt_net_wm_window_type_dialog ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_TOOLBAR", &qt_net_wm_window_type_toolbar ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_MENU", &qt_net_wm_window_type_menu ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_UTILITY", &qt_net_wm_window_type_utility ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_SPLASH", &qt_net_wm_window_type_splash ); + qt_x11_intern_atom( "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", &qt_net_wm_window_type_override ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", &qt_net_wm_window_type_dropdown_menu ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_POPUP_MENU", &qt_net_wm_window_type_popup_menu ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_TOOLTIP", &qt_net_wm_window_type_tooltip ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_COMBO", &qt_net_wm_window_type_combo ); + qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_DND", &qt_net_wm_window_type_dnd ); + qt_x11_intern_atom( "_KDE_NET_WM_FRAME_STRUT", &qt_net_wm_frame_strut ); + qt_x11_intern_atom( "_NET_WM_STATE_STAYS_ON_TOP", + &qt_net_wm_state_stays_on_top ); + qt_x11_intern_atom( "_NET_WM_PID", &qt_net_wm_pid ); + qt_x11_intern_atom( "_NET_WM_USER_TIME", &qt_net_wm_user_time ); + qt_x11_intern_atom( "_NET_WM_FULL_PLACEMENT", &qt_net_wm_full_placement ); + qt_x11_intern_atom( "ENLIGHTENMENT_DESKTOP", &qt_enlightenment_desktop ); + qt_x11_intern_atom( "_NET_WM_NAME", &qt_net_wm_name ); + qt_x11_intern_atom( "_NET_WM_ICON_NAME", &qt_net_wm_icon_name ); + qt_x11_intern_atom( "UTF8_STRING", &qt_utf8_string ); + qt_x11_intern_atom( "_SGI_DESKS_MANAGER", &qt_sgi_desks_manager ); + +#ifndef TQT_NO_XSYNC + qt_x11_intern_atom( "_NET_WM_SYNC_REQUEST_COUNTER", &qt_net_wm_sync_request_counter ); + qt_x11_intern_atom( "_NET_WM_SYNC_REQUEST", &qt_net_wm_sync_request ); +#endif + + qt_xdnd_setup(); + qt_x11_motifdnd_init(); + + // Finally create all atoms + tqt_x11_process_intern_atoms(); + + // look for broken window managers + qt_detect_broken_window_manager(); + + // initialize NET lists + qt_get_net_supported(); + qt_get_net_virtual_roots(); + +#ifndef TQT_NO_XRANDR + // See if XRandR is supported on the connected display + int xrandr_errorbase; + Q_UNUSED( xrandr_eventbase ); + if ( XRRQueryExtension( appDpy, &xrandr_eventbase, &xrandr_errorbase ) ) { + // XRandR is supported + qt_use_xrandr = TRUE; + } +#endif // TQT_NO_XRANDR + +#ifndef TQT_NO_XRENDER + // See if XRender is supported on the connected display + int xrender_eventbase, xrender_errorbase; + if (XRenderQueryExtension(appDpy, &xrender_eventbase, &xrender_errorbase)) { + // XRender is supported, let's see if we have a PictFormat for the + // default visual + XRenderPictFormat *format = + XRenderFindVisualFormat(appDpy, + (Visual *) TQPaintDevice::x_appvisual); + tqt_use_xrender = (format != 0) && (TQPaintDevice::x_appdepth != 8); + } +#endif // TQT_NO_XRENDER + +#ifndef TQT_NO_XSYNC + // Try to initialize SYNC extension on the connected display + int xsync_major, xsync_minor; + if ( XSyncQueryExtension( appDpy, &xsync_eventbase, &xsync_errorbase ) && + XSyncInitialize( appDpy, &xsync_major, &xsync_minor ) ) { + qt_use_xsync = TRUE; + } +#endif + +#ifndef TQT_NO_XKB + // If XKB is detected, set the GrabsUseXKBState option so input method + // compositions continue to work (ie. deadkeys) + unsigned int state = XkbPCF_GrabsUseXKBStateMask; + (void) XkbSetPerClientControls(appDpy, state, &state); +#endif + +#if !defined(TQT_NO_XFTFREETYPE) + // defined in tqfont_x11.cpp + extern bool tqt_has_xft; +#ifndef QT_XFT2 + if (!tqt_use_xrender) + tqt_has_xft = FALSE; + else +#endif + tqt_has_xft = XftInit(0) && XftInitFtLibrary(); + + if (tqt_has_xft) { + char *dpi_str = XGetDefault(appDpy, "Xft", "dpi"); + if (dpi_str) { + // use a custom DPI + char *end = 0; + int dpi = strtol(dpi_str, &end, 0); + if (dpi_str != end) { + for (int s = 0; s < ScreenCount(appDpy); ++s) { + TQPaintDevice::x11SetAppDpiX(dpi, s); + TQPaintDevice::x11SetAppDpiY(dpi, s); + } + } + } + } +#endif // TQT_NO_XFTFREETYPE + + // look at the modifier mapping, and get the correct masks for alt/meta + // find the alt/meta masks + XModifierKeymap *map = XGetModifierMapping(appDpy); + if (map) { + int i, maskIndex = 0, mapIndex = 0; + for (maskIndex = 0; maskIndex < 8; maskIndex++) { + for (i = 0; i < map->max_keypermod; i++) { + if (map->modifiermap[mapIndex]) { + KeySym sym = qt_x11_keycode_to_keysym(appDpy, map->modifiermap[ mapIndex ]); + if ( qt_alt_mask == 0 && + ( sym == XK_Alt_L || sym == XK_Alt_R ) ) { + qt_alt_mask = 1 << maskIndex; + } + if ( qt_meta_mask == 0 && + (sym == XK_Meta_L || sym == XK_Meta_R ) ) { + qt_meta_mask = 1 << maskIndex; + } + } + mapIndex++; + } + } + + // not look for mode_switch in qt_alt_mask and qt_meta_mask - if it is + // present in one or both, then we set qt_mode_switch_remove_mask. + // see TQETWidget::translateKeyEventInternal for an explanation + // of why this is needed + mapIndex = 0; + for ( maskIndex = 0; maskIndex < 8; maskIndex++ ) { + if ( qt_alt_mask != ( 1 << maskIndex ) && + qt_meta_mask != ( 1 << maskIndex ) ) { + for ( i = 0; i < map->max_keypermod; i++ ) + mapIndex++; + continue; + } + + for ( i = 0; i < map->max_keypermod; i++ ) { + if ( map->modifiermap[ mapIndex ] ) { + KeySym sym = qt_x11_keycode_to_keysym(appDpy, map->modifiermap[ mapIndex ]); + if ( sym == XK_Mode_switch ) { + qt_mode_switch_remove_mask |= 1 << maskIndex; + } + } + mapIndex++; + } + } + + XFreeModifiermap(map); + } else { + // assume defaults + qt_alt_mask = Mod1Mask; + qt_meta_mask = Mod4Mask; + qt_mode_switch_remove_mask = 0; + } + + // Misc. initialization + + TQColor::initialize(); + TQFont::initialize(); + TQCursor::initialize(); + TQPainter::initialize(); + } + +#if defined(TQT_THREAD_SUPPORT) + TQThread::initialize(); +#endif + + if( tqt_is_gui_used ) { + tqApp->setName( appName ); + + int screen; + for ( screen = 0; screen < appScreenCount; ++screen ) { + XSelectInput( appDpy, TQPaintDevice::x11AppRootWindow( screen ), + KeymapStateMask | EnterWindowMask | LeaveWindowMask | + PropertyChangeMask ); + +#ifndef TQT_NO_XRANDR + if (qt_use_xrandr) + XRRSelectInput( appDpy, TQPaintDevice::x11AppRootWindow( screen ), True ); +#endif // TQT_NO_XRANDR + } + } + + if ( tqt_is_gui_used ) { + qt_set_input_encoding(); + + qt_set_x11_resources( appFont, appFGCol, appBGCol, appBTNCol); + + // be smart about the size of the default font. most X servers have helvetica + // 12 point available at 2 resolutions: + // 75dpi (12 pixels) and 100dpi (17 pixels). + // At 95 DPI, a 12 point font should be 16 pixels tall - in which case a 17 + // pixel font is a closer match than a 12 pixel font + int ptsz = + (int) ( ( ( TQPaintDevice::x11AppDpiY() >= 95 ? 17. : 12. ) * + 72. / (float) TQPaintDevice::x11AppDpiY() ) + 0.5 ); + + if ( !tqt_app_has_font && !qt_x11_cmdline_font ) { + TQFont f( "Helvetica", ptsz ); + TQApplication::setFont( f ); + } + +#if !defined(TQT_NO_IM) +#if !defined(TQT_NO_IM_EXTENSIONS) + TQApplication::create_im(); +#else + TQApplication::create_xim(); +#endif +#endif + +#if defined (QT_TABLET_SUPPORT) + int ndev, + i, + j; + bool gotStylus, + gotEraser; + XDeviceInfo *devices, *devs; + XInputClassInfo *ip; + XAnyClassPtr any; + XValuatorInfoPtr v; + XAxisInfoPtr a; + XDevice *dev; + XEventClass *ev_class; + int curr_event_count; + +#if !defined(Q_OS_IRIX) + // XFree86 divides a stylus and eraser into 2 devices, so we must do for both... + const TQString XFREENAMESTYLUS = "stylus"; + const TQString XFREENAMEPEN = "pen"; + const TQString XFREENAMEERASER = "eraser"; +#endif + + devices = XListInputDevices( appDpy, &ndev); + if ( devices == NULL ) { + tqWarning( "Failed to get list of devices" ); + ndev = -1; + } + dev = NULL; + for ( devs = devices, i = 0; i < ndev; i++, devs++ ) { + gotEraser = FALSE; +#if defined(Q_OS_IRIX) + + gotStylus = ( !strncmp(devs->name, + WACOM_NAME, sizeof(WACOM_NAME) - 1) ); +#else + TQString devName = devs->name; + devName = devName.lower(); + gotStylus = ( devName.startsWith(XFREENAMEPEN) + || devName.startsWith(XFREENAMESTYLUS) ); + if ( !gotStylus ) + gotEraser = devName.startsWith( XFREENAMEERASER ); + +#endif + if ( gotStylus || gotEraser ) { + // I only wanted to do this once, so wrap pointers around these + curr_event_count = 0; + + if ( gotStylus ) { + devStylus = XOpenDevice( appDpy, devs->id ); + dev = devStylus; + ev_class = event_list_stylus; + } else if ( gotEraser ) { + devEraser = XOpenDevice( appDpy, devs->id ); + dev = devEraser; + ev_class = event_list_eraser; + } + if ( dev == NULL ) { + tqWarning( "Failed to open device" ); + } else { + if ( dev->num_classes > 0 ) { + for ( ip = dev->classes, j = 0; j < devs->num_classes; + ip++, j++ ) { + switch ( ip->input_class ) { + case KeyClass: + DeviceKeyPress( dev, xinput_key_press, + ev_class[curr_event_count] ); + curr_event_count++; + DeviceKeyRelease( dev, xinput_key_release, + ev_class[curr_event_count] ); + curr_event_count++; + break; + case ButtonClass: + DeviceButtonPress( dev, xinput_button_press, + ev_class[curr_event_count] ); + curr_event_count++; + DeviceButtonRelease( dev, xinput_button_release, + ev_class[curr_event_count] ); + curr_event_count++; + break; + case ValuatorClass: + // I'm only going to be interested in motion when the + // stylus is already down anyway! + DeviceMotionNotify( dev, xinput_motion, + ev_class[curr_event_count] ); + curr_event_count++; + break; + default: + break; + } + } + } + } + // get the min/max value for pressure! + any = (XAnyClassPtr) ( devs->inputclassinfo ); + if ( dev == devStylus ) { + qt_curr_events_stylus = curr_event_count; + for (j = 0; j < devs->num_classes; j++) { + if ( any->c_class == ValuatorClass ) { + v = (XValuatorInfoPtr) any; + a = (XAxisInfoPtr) ((char *) v + + sizeof (XValuatorInfo)); +#if defined (Q_OS_IRIX) + max_pressure = a[WAC_PRESSURE_I].max_value; +#else + max_pressure = a[2].max_value; +#endif + // got the max pressure no need to go further... + break; + } + any = (XAnyClassPtr) ((char *) any + any->length); + } + } else { + qt_curr_events_eraser = curr_event_count; + } + // at this point we are assuming there is only one + // wacom device... +#if defined (Q_OS_IRIX) + if ( devStylus != NULL ) { +#else + if ( devStylus != NULL && devEraser != NULL ) { +#endif + break; + } + } + } // end for loop + XFreeDeviceList( devices ); +#endif // QT_TABLET_SUPPORT + + } else { + // read some non-GUI settings when not using the X server... + + if ( TQApplication::desktopSettingsAware() ) { + TQSettings settings; + + // read library (ie. plugin) path list + TQString libpathkey = TQString("/qt/%1.%2/libraryPath") + .arg( TQT_VERSION >> 16 ) + .arg( (TQT_VERSION & 0xff00 ) >> 8 ); + TQStringList pathlist = + settings.readListEntry(libpathkey, ':'); + if (! pathlist.isEmpty()) { + TQStringList::ConstIterator it = pathlist.begin(); + while (it != pathlist.end()) + TQApplication::addLibraryPath(*it++); + } + + TQString defaultcodec = settings.readEntry("/qt/defaultCodec", "none"); + if (defaultcodec != "none") { + TQTextCodec *codec = TQTextCodec::codecForName(defaultcodec); + if (codec) + tqApp->setDefaultCodec(codec); + } + + tqt_resolve_symlinks = + settings.readBoolEntry("/qt/resolveSymlinks", TRUE); + } + } + } + + +#ifndef TQT_NO_STYLE + // run-time search for default style +void TQApplication::x11_initialize_style() +{ + Atom type; + int format; + unsigned long length, after; + uchar *data; + if ( !app_style && + XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), qt_twin_running, + 0, 1, False, AnyPropertyType, &type, &format, &length, + &after, &data ) == Success && length ) { + if ( data ) XFree( (char *)data ); + // twin is there. check if KDE's styles are available, + // otherwise use windows style + if ( (app_style = TQStyleFactory::create("highcolor") ) == 0 ) + app_style = TQStyleFactory::create("windows"); + } + if ( !app_style && + XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), qt_kwm_running, + 0, 1, False, AnyPropertyType, &type, &format, &length, + &after, &data ) == Success && length ) { + if ( data ) XFree( (char *)data ); + app_style = TQStyleFactory::create("windows"); + } + if ( !app_style && + XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), qt_cde_running, + 0, 1, False, AnyPropertyType, &type, &format, &length, + &after, &data ) == Success && length ) { + // DTWM is running, meaning most likely CDE is running... + if ( data ) XFree( (char *) data ); + app_style = TQStyleFactory::create( "cde" ); + } + // maybe another desktop? + if ( !app_style && + XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), + qt_gbackground_properties, 0, 1, False, AnyPropertyType, + &type, &format, &length, &after, &data ) == Success && + length ) { + if ( data ) XFree( (char *)data ); + // default to MotifPlus with hovering + app_style = TQStyleFactory::create("motifplus" ); + } +} +#endif + +void tqt_init( int *argcptr, char **argv, TQApplication::Type ) +{ + tqt_init_internal( argcptr, argv, 0, 0, 0 ); +} + +void tqt_init( Display *display, TQt::HANDLE visual, TQt::HANDLE colormap ) +{ + tqt_init_internal( 0, 0, display, visual, colormap ); +} + +void tqt_init( int *argcptr, char **argv, Display *display, TQt::HANDLE visual, TQt::HANDLE colormap ) +{ + tqt_init_internal( argcptr, argv, display, visual, colormap ); +} + + +/***************************************************************************** + tqt_cleanup() - cleans up when the application is finished + *****************************************************************************/ + +void tqt_cleanup() +{ + appliedstamp = 0; + + if ( app_save_rootinfo ) // root window must keep state + qt_save_rootinfo(); + + if ( tqt_is_gui_used ) { + TQPixmapCache::clear(); + TQPainter::cleanup(); + TQCursor::cleanup(); + TQFont::cleanup(); + TQColor::cleanup(); + TQSharedDoubleBuffer::cleanup(); + } +#if defined(TQT_THREAD_SUPPORT) + TQThread::cleanup(); +#endif + +#if defined (QT_TABLET_SUPPORT) + if ( devStylus != NULL ) + XCloseDevice( appDpy, devStylus ); + if ( devEraser != NULL ) + XCloseDevice( appDpy, devEraser ); +#endif + +#if !defined(TQT_NO_IM) +#if !defined(TQT_NO_IM_EXTENSIONS) + TQApplication::close_im(); +#else + TQApplication::close_xim(); +#endif +#endif + + if ( tqt_is_gui_used ) { + int screen; + for ( screen = 0; screen < appScreenCount; screen++ ) { + if ( ! TQPaintDevice::x11AppDefaultColormap( screen ) ) + XFreeColormap( TQPaintDevice::x11AppDisplay(), + TQPaintDevice::x11AppColormap( screen ) ); + } + } + +#define QT_CLEANUP_GC(g) if (g) { for (int i=0;i= appScreenCount ) { + tqDebug("invalid screen %d %d", scrn, appScreenCount ); + TQWidget* bla = 0; + bla->setName("hello"); + } + GC gc; + if ( monochrome ) { + if ( !app_gc_ro_m ) // create GC for bitmap + memset( (app_gc_ro_m = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) ); + if ( !app_gc_ro_m[scrn] ) + app_gc_ro_m[scrn] = create_gc( scrn, TRUE ); + gc = app_gc_ro_m[scrn]; + } else { // create standard GC + if ( !app_gc_ro ) + memset( (app_gc_ro = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) ); + if ( !app_gc_ro[scrn] ) + app_gc_ro[scrn] = create_gc( scrn, FALSE ); + gc = app_gc_ro[scrn]; + } + return gc; +} + +GC tqt_xget_temp_gc( int scrn, bool monochrome ) // get temporary GC +{ + if ( scrn < 0 || scrn >= appScreenCount ) { + tqDebug("invalid screen (tmp) %d %d", scrn, appScreenCount ); + TQWidget* bla = 0; + bla->setName("hello"); + } + GC gc; + if ( monochrome ) { + if ( !app_gc_tmp_m ) // create GC for bitmap + memset( (app_gc_tmp_m = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) ); + if ( !app_gc_tmp_m[scrn] ) + app_gc_tmp_m[scrn] = create_gc( scrn, TRUE ); + gc = app_gc_tmp_m[scrn]; + } else { // create standard GC + if ( !app_gc_tmp ) + memset( (app_gc_tmp = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) ); + if ( !app_gc_tmp[scrn] ) + app_gc_tmp[scrn] = create_gc( scrn, FALSE ); + gc = app_gc_tmp[scrn]; + } + return gc; +} + + +/***************************************************************************** + Platform specific TQApplication members + *****************************************************************************/ + +/*! + \fn TQWidget *TQApplication::mainWidget() const + + Returns the main application widget, or 0 if there is no main + widget. + + \sa setMainWidget() +*/ + +/*! + Sets the application's main widget to \a mainWidget. + + In most respects the main widget is like any other widget, except + that if it is closed, the application exits. Note that + TQApplication does \e not take ownership of the \a mainWidget, so + if you create your main widget on the heap you must delete it + yourself. + + You need not have a main widget; connecting lastWindowClosed() to + quit() is an alternative. + + For X11, this function also resizes and moves the main widget + according to the \e -geometry command-line option, so you should + set the default geometry (using \l TQWidget::setGeometry()) before + calling setMainWidget(). + + \sa mainWidget(), exec(), quit() +*/ + +void TQApplication::setMainWidget( TQWidget *mainWidget ) +{ +#if defined(QT_CHECK_STATE) + if ( mainWidget && mainWidget->parentWidget() && + ! mainWidget->parentWidget()->isDesktop() ) + tqWarning( "TQApplication::setMainWidget(): New main widget (%s/%s) " + "has a parent!", + mainWidget->className(), mainWidget->name() ); +#endif + main_widget = mainWidget; + if ( main_widget ) { // give WM command line + XSetWMProperties( main_widget->x11Display(), main_widget->winId(), + 0, 0, app_argv, app_argc, 0, 0, 0 ); + if ( mwTitle ) + XStoreName( main_widget->x11Display(), main_widget->winId(), (char*)mwTitle ); + if ( mwGeometry ) { // parse geometry + int x, y; + int w, h; + int m = XParseGeometry( (char*)mwGeometry, &x, &y, (uint*)&w, (uint*)&h ); + TQSize minSize = main_widget->minimumSize(); + TQSize maxSize = main_widget->maximumSize(); + if ( (m & XValue) == 0 ) + x = main_widget->geometry().x(); + if ( (m & YValue) == 0 ) + y = main_widget->geometry().y(); + if ( (m & WidthValue) == 0 ) + w = main_widget->width(); + if ( (m & HeightValue) == 0 ) + h = main_widget->height(); + w = TQMIN(w,maxSize.width()); + h = TQMIN(h,maxSize.height()); + w = TQMAX(w,minSize.width()); + h = TQMAX(h,minSize.height()); + if ( (m & XNegative) ) { + x = desktop()->width() + x - w; + qt_widget_tlw_gravity = NorthEastGravity; + } + if ( (m & YNegative) ) { + y = desktop()->height() + y - h; + qt_widget_tlw_gravity = (m & XNegative) ? SouthEastGravity : SouthWestGravity; + } + main_widget->setGeometry( x, y, w, h ); + } + } +} + +#ifndef TQT_NO_CURSOR + +/***************************************************************************** + TQApplication cursor stack + *****************************************************************************/ + +extern void tqt_x11_enforce_cursor( TQWidget * w ); + +typedef TQPtrList TQCursorList; + +static TQCursorList *cursorStack = 0; + +/*! + \fn TQCursor *TQApplication::overrideCursor() + + Returns the active application override cursor. + + This function returns 0 if no application cursor has been defined + (i.e. the internal cursor stack is empty). + + \sa setOverrideCursor(), restoreOverrideCursor() +*/ + +/*! + Sets the application override cursor to \a cursor. + + Application override cursors are intended for showing the user + that the application is in a special state, for example during an + operation that might take some time. + + This cursor will be displayed in all the application's widgets + until restoreOverrideCursor() or another setOverrideCursor() is + called. + + Application cursors are stored on an internal stack. + setOverrideCursor() pushes the cursor onto the stack, and + restoreOverrideCursor() pops the active cursor off the stack. + Every setOverrideCursor() must eventually be followed by a + corresponding restoreOverrideCursor(), otherwise the stack will + never be emptied. + + If \a replace is TRUE, the new cursor will replace the last + override cursor (the stack keeps its depth). If \a replace is + FALSE, the new stack is pushed onto the top of the stack. + + Example: + \code + TQApplication::setOverrideCursor( TQCursor(TQt::WaitCursor) ); + calculateHugeMandelbrot(); // lunch time... + TQApplication::restoreOverrideCursor(); + \endcode + + \sa overrideCursor(), restoreOverrideCursor(), TQWidget::setCursor() +*/ + +void TQApplication::setOverrideCursor( const TQCursor &cursor, bool replace ) +{ + if ( !cursorStack ) { + cursorStack = new TQCursorList; + TQ_CHECK_PTR( cursorStack ); + cursorStack->setAutoDelete( TRUE ); + } + app_cursor = new TQCursor( cursor ); + TQ_CHECK_PTR( app_cursor ); + if ( replace ) + cursorStack->removeLast(); + cursorStack->append( app_cursor ); + + TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); + TQWidget *w; + while ( (w=it.current()) ) { // for all widgets that have + if ( w->testWState( WState_OwnCursor ) ) + tqt_x11_enforce_cursor( w ); + ++it; + } + XFlush( appDpy ); // make X execute it NOW +} + +/*! + Undoes the last setOverrideCursor(). + + If setOverrideCursor() has been called twice, calling + restoreOverrideCursor() will activate the first cursor set. + Calling this function a second time restores the original widgets' + cursors. + + \sa setOverrideCursor(), overrideCursor(). +*/ + +void TQApplication::restoreOverrideCursor() +{ + if ( !cursorStack ) // no cursor stack + return; + cursorStack->removeLast(); + app_cursor = cursorStack->last(); + if ( TQWidget::mapper != 0 && !closingDown() ) { + TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); + TQWidget *w; + while ( (w=it.current()) ) { // set back to original cursors + if ( w->testWState( WState_OwnCursor ) ) + tqt_x11_enforce_cursor( w ); + ++it; + } + XFlush( appDpy ); + } + if ( !app_cursor ) { + delete cursorStack; + cursorStack = 0; + } +} + +#endif + +/*! + \fn bool TQApplication::hasGlobalMouseTracking() + + Returns TRUE if global mouse tracking is enabled; otherwise + returns FALSE. + + \sa setGlobalMouseTracking() +*/ + +/*! + Enables global mouse tracking if \a enable is TRUE, or disables it + if \a enable is FALSE. + + Enabling global mouse tracking makes it possible for widget event + filters or application event filters to get all mouse move events, + even when no button is depressed. This is useful for special GUI + elements, e.g. tooltips. + + Global mouse tracking does not affect widgets and their + mouseMoveEvent(). For a widget to get mouse move events when no + button is depressed, it must do TQWidget::setMouseTracking(TRUE). + + This function uses an internal counter. Each + setGlobalMouseTracking(TRUE) must have a corresponding + setGlobalMouseTracking(FALSE): + \code + // at this point global mouse tracking is off + TQApplication::setGlobalMouseTracking( TRUE ); + TQApplication::setGlobalMouseTracking( TRUE ); + TQApplication::setGlobalMouseTracking( FALSE ); + // at this point it's still on + TQApplication::setGlobalMouseTracking( FALSE ); + // but now it's off + \endcode + + \sa hasGlobalMouseTracking(), TQWidget::hasMouseTracking() +*/ + +void TQApplication::setGlobalMouseTracking( bool enable ) +{ + bool tellAllWidgets; + if ( enable ) { + tellAllWidgets = (++app_tracking == 1); + } else { + tellAllWidgets = (--app_tracking == 0); + } + if ( tellAllWidgets ) { + TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::mapper) ); + TQWidget *w; + while ( (w=it.current()) ) { + if ( app_tracking > 0 ) { // switch on + if ( !w->testWState(WState_MouseTracking) ) { + w->setMouseTracking( TRUE ); + w->clearWState( WState_MouseTracking ); + } + } else { // switch off + if ( !w->testWState(WState_MouseTracking) ) { + w->setWState( WState_MouseTracking ); + w->setMouseTracking( FALSE ); + } + } + ++it; + } + } +} + + +/***************************************************************************** + Routines to find a TQt widget from a screen position + *****************************************************************************/ + +Window qt_x11_findClientWindow( Window win, Atom property, bool leaf ) +{ + Atom type = None; + int format, i; + ulong nitems, after; + uchar *data; + Window root, parent, target=0, *children=0; + uint nchildren; + if ( XGetWindowProperty( appDpy, win, property, 0, 0, FALSE, AnyPropertyType, + &type, &format, &nitems, &after, &data ) == Success ) { + if ( data ) + XFree( (char *)data ); + if ( type ) + return win; + } + if ( !XQueryTree(appDpy,win,&root,&parent,&children,&nchildren) ) { + if ( children ) + XFree( (char *)children ); + return 0; + } + for ( i=nchildren-1; !target && i >= 0; i-- ) + target = qt_x11_findClientWindow( children[i], property, leaf ); + if ( children ) + XFree( (char *)children ); + return target; +} + + +/*! + Returns a pointer to the widget at global screen position \a + (x, y), or 0 if there is no TQt widget there. + + If \a child is FALSE and there is a child widget at position \a + (x, y), the top-level widget containing it is returned. If \a child + is TRUE the child widget at position \a (x, y) is returned. + + This function is normally rather slow. + + \sa TQCursor::pos(), TQWidget::grabMouse(), TQWidget::grabKeyboard() +*/ + +TQWidget *TQApplication::widgetAt( int x, int y, bool child ) +{ + int screen = TQCursor::x11Screen(); + int lx, ly; + + Window target; + if ( !XTranslateCoordinates(appDpy, + TQPaintDevice::x11AppRootWindow(screen), + TQPaintDevice::x11AppRootWindow(screen), + x, y, &lx, &ly, &target) ) { + return 0; + } + if ( !target || target == TQPaintDevice::x11AppRootWindow(screen) ) + return 0; + TQWidget *w, *c; + w = TQWidget::find( (WId)target ); + + if ( !w ) { + qt_ignore_badwindow(); + target = qt_x11_findClientWindow( target, tqt_wm_state, TRUE ); + if (qt_badwindow() ) + return 0; + w = TQWidget::find( (WId)target ); +#if 0 + if ( !w ) { + // Perhaps the widgets at (x,y) is inside a foreign application? + // Search all toplevel widgets to see if one is within target + TQWidgetList *list = topLevelWidgets(); + TQWidget *widget = list->first(); + while ( widget && !w ) { + Window ctarget = target; + if ( widget->isVisible() && !widget->isDesktop() ) { + Window wid = widget->winId(); + while ( ctarget && !w ) { + XTranslateCoordinates(appDpy, + TQPaintDevice::x11AppRootWindow(screen), + ctarget, x, y, &lx, &ly, &ctarget); + if ( ctarget == wid ) { + // Found + w = widget; + XTranslateCoordinates(appDpy, + TQPaintDevice::x11AppRootWindow(screen), + ctarget, x, y, &lx, &ly, &ctarget); + } + } + } + widget = list->next(); + } + delete list; + } +#endif + } + if ( child && w ) { + if ( (c = w->childAt( w->mapFromGlobal(TQPoint(x, y ) ) ) ) ) + return c; + } + return w; +} + +/*! + \overload TQWidget *TQApplication::widgetAt( const TQPoint &pos, bool child ) + + Returns a pointer to the widget at global screen position \a pos, + or 0 if there is no TQt widget there. + + If \a child is FALSE and there is a child widget at position \a + pos, the top-level widget containing it is returned. If \a child + is TRUE the child widget at position \a pos is returned. +*/ + + +/*! + Flushes the X event queue in the X11 implementation. This normally + returns almost immediately. Does nothing on other platforms. + + \sa syncX() +*/ + +void TQApplication::flushX() +{ + if ( appDpy ) + XFlush( appDpy ); +} + +/*! + Flushes the window system specific event queues. + + If you are doing graphical changes inside a loop that does not + return to the event loop on asynchronous window systems like X11 + or double buffered window systems like MacOS X, and you want to + visualize these changes immediately (e.g. Splash Screens), call + this function. + + \sa flushX() sendPostedEvents() TQPainter::flush() +*/ + +void TQApplication::flush() +{ + flushX(); +} + +/*! + Synchronizes with the X server in the X11 implementation. This + normally takes some time. Does nothing on other platforms. + + \sa flushX() +*/ + +void TQApplication::syncX() +{ + if ( appDpy ) + XSync( appDpy, False ); // don't discard events +} + + +/*! + Sounds the bell, using the default volume and sound. +*/ + +void TQApplication::beep() +{ + if ( appDpy ) + XBell( appDpy, 0 ); +} + + + +/***************************************************************************** + Special lookup functions for windows that have been reparented recently + *****************************************************************************/ + +static TQWidgetIntDict *wPRmapper = 0; // alternative widget mapper + +void qPRCreate( const TQWidget *widget, Window oldwin ) +{ // TQWidget::reparent mechanism + if ( !wPRmapper ) { + wPRmapper = new TQWidgetIntDict; + TQ_CHECK_PTR( wPRmapper ); + } + wPRmapper->insert( (long)oldwin, widget ); // add old window to mapper + TQETWidget *w = (TQETWidget *)widget; + w->setWState( TQt::WState_Reparented ); // set reparented flag +} + +void qPRCleanup( TQWidget *widget ) +{ + TQETWidget *etw = (TQETWidget *)widget; + if ( !(wPRmapper && etw->testWState(TQt::WState_Reparented)) ) + return; // not a reparented widget + TQWidgetIntDictIt it(*wPRmapper); + TQWidget *w; + while ( (w=it.current()) ) { + int key = it.currentKey(); + ++it; + if ( w == etw ) { // found widget + etw->clearWState( TQt::WState_Reparented ); // clear flag + wPRmapper->remove( key );// old window no longer needed + if ( wPRmapper->count() == 0 ) { // became empty + delete wPRmapper; // then reset alt mapper + wPRmapper = 0; + return; + } + } + } +} + +static TQETWidget *qPRFindWidget( Window oldwin ) +{ + return wPRmapper ? (TQETWidget*)wPRmapper->find((long)oldwin) : 0; +} + +/*! + \internal +*/ +int TQApplication::x11ClientMessage(TQWidget* w, XEvent* event, bool passive_only) +{ + TQETWidget *widget = (TQETWidget*)w; + if ( event->xclient.format == 32 && event->xclient.message_type ) { + if ( event->xclient.message_type == tqt_wm_protocols ) { + Atom a = event->xclient.data.l[0]; + if ( a == tqt_wm_delete_window ) { + if ( passive_only ) return 0; + widget->translateCloseEvent(event); + } + else if ( a == tqt_wm_take_focus ) { + TQWidget * amw = activeModalWidget(); + if ( (ulong) event->xclient.data.l[1] > tqt_x_time ) + tqt_x_time = event->xclient.data.l[1]; + if ( amw && amw != widget ) { + TQWidget* groupLeader = widget; + while ( groupLeader && !groupLeader->testWFlags( TQt::WGroupLeader ) + && groupLeader != amw ) + groupLeader = groupLeader->parentWidget(); + if ( !groupLeader ) { + TQWidget *p = amw->parentWidget(); + while (p && p != widget) + p = p->parentWidget(); + if (!p || !qt_net_supported_list) + amw->raise(); // help broken window managers + amw->setActiveWindow(); + } + } +#ifndef TQT_NO_WHATSTHIS + } else if ( a == qt_net_wm_context_help ) { + TQWhatsThis::enterWhatsThisMode(); +#endif // TQT_NO_WHATSTHIS + } else if ( a == qt_net_wm_ping ) { + // avoid send/reply loops + Window root = TQPaintDevice::x11AppRootWindow( w->x11Screen() ); + if (event->xclient.window != root) { + event->xclient.window = root; + XSendEvent( event->xclient.display, event->xclient.window, + False, SubstructureNotifyMask|SubstructureRedirectMask, event ); + } +#ifndef TQT_NO_XSYNC + } else if (a == qt_net_wm_sync_request ) { + widget->handleSyncRequest( event ); +#endif + } + } else if ( event->xclient.message_type == qt_qt_scrolldone ) { + widget->translateScrollDoneEvent(event); + } else if ( event->xclient.message_type == qt_xdnd_position ) { + qt_handle_xdnd_position( widget, event, passive_only ); + } else if ( event->xclient.message_type == qt_xdnd_enter ) { + qt_handle_xdnd_enter( widget, event, passive_only ); + } else if ( event->xclient.message_type == qt_xdnd_status ) { + qt_handle_xdnd_status( widget, event, passive_only ); + } else if ( event->xclient.message_type == qt_xdnd_leave ) { + qt_handle_xdnd_leave( widget, event, passive_only ); + } else if ( event->xclient.message_type == qt_xdnd_drop ) { + qt_handle_xdnd_drop( widget, event, passive_only ); + } else if ( event->xclient.message_type == qt_xdnd_finished ) { + qt_handle_xdnd_finished( widget, event, passive_only ); + } else { + if ( passive_only ) return 0; + // All other are interactions + } + } else { + qt_motifdnd_handle_msg( widget, event, passive_only ); + } + + return 0; +} + +/*! + This function does the core processing of individual X + \a{event}s, normally by dispatching TQt events to the right + destination. + + It returns 1 if the event was consumed by special handling, 0 if + the \a event was consumed by normal handling, and -1 if the \a + event was for an unrecognized widget. + + \sa x11EventFilter() +*/ +int TQApplication::x11ProcessEvent( XEvent* event ) +{ + switch ( event->type ) { + case ButtonPress: + ignoreNextMouseReleaseEvent = FALSE; + tqt_x_user_time = event->xbutton.time; + // fallthrough intended + case ButtonRelease: + tqt_x_time = event->xbutton.time; + break; + case MotionNotify: + tqt_x_time = event->xmotion.time; + break; + case XKeyPress: + tqt_x_user_time = event->xkey.time; + // fallthrough intended + case XKeyRelease: + tqt_x_time = event->xkey.time; + break; + case PropertyNotify: + tqt_x_time = event->xproperty.time; + break; + case EnterNotify: + case LeaveNotify: + tqt_x_time = event->xcrossing.time; + break; + case SelectionClear: + tqt_x_time = event->xselectionclear.time; + break; + default: + break; + } + + TQETWidget *widget = (TQETWidget*)TQWidget::find( (WId)event->xany.window ); + + if ( wPRmapper ) { // just did a widget reparent? + if ( widget == 0 ) { // not in std widget mapper + switch ( event->type ) { // only for mouse/key events + case ButtonPress: + case ButtonRelease: + case MotionNotify: + case XKeyPress: + case XKeyRelease: + widget = qPRFindWidget( event->xany.window ); + break; + } + } + else if ( widget->testWState(WState_Reparented) ) + qPRCleanup( widget ); // remove from alt mapper + } + + TQETWidget *keywidget=0; + bool grabbed=FALSE; + if ( event->type==XKeyPress || event->type==XKeyRelease ) { + keywidget = (TQETWidget*)TQWidget::keyboardGrabber(); + if ( keywidget ) { + grabbed = TRUE; + } else { + if ( focus_widget ) + keywidget = (TQETWidget*)focus_widget; + if ( !keywidget ) { + if ( inPopupMode() ) // no focus widget, see if we have a popup + keywidget = (TQETWidget*) activePopupWidget(); + else if ( widget ) + keywidget = (TQETWidget*)widget->topLevelWidget(); + } + } + } + +#ifndef TQT_NO_IM + // Filtering input events by the input context. It has to be taken + // place before any other key event consumers such as eventfilters + // and accelerators because some input methods require quite + // various key combination and sequences. It often conflicts with + // accelerators and so on, so we must give the input context the + // filtering opportunity first to ensure all input methods work + // properly regardless of application design. + +// #ifndef TQT_NO_IM_EXTENSIONS + if( keywidget && keywidget->isEnabled() && keywidget->isInputMethodEnabled() ) { +// #else +// if( keywidget && keywidget->isEnabled() ) { +// #endif + if( ( event->type==XKeyPress || event->type==XKeyRelease ) && + sm_blockUserInput ) // block user interaction during session management + return TRUE; + + // for XIM handling + TQInputContext *qic = keywidget->getInputContext(); + if( qic && qic->x11FilterEvent( keywidget, event ) ) + return TRUE; + + // filterEvent() accepts TQEvent *event rather than preexpanded key + // event attribute values. This is intended to pass other IM-related + // events in future. The IM-related events are supposed as + // TQWheelEvent, TQTabletEvent and so on. Other non IM-related events + // should not be forwarded to input contexts to prevent weird event + // handling. + if ( ( event->type == XKeyPress || event->type == XKeyRelease ) ) { + int code = -1; + int count = 0; + int state; + char ascii = 0; + TQEvent::Type type; + TQString text; + + keywidget->translateKeyEventInternal( event, count, text, + state, ascii, code, type, + FALSE, FALSE ); + + // both key press/release is required for some complex + // input methods. don't eliminate anything. + TQKeyEvent keyevent( type, code, ascii, state, text, FALSE, count ); + + if( qic && qic->filterEvent( &keyevent ) ) + return TRUE; + } + } else +#endif // TQT_NO_IM + { + if ( XFilterEvent( event, None ) ) + return TRUE; + } + + if ( qt_x11EventFilter(event) ) // send through app filter + return 1; + + if ( event->type == MappingNotify ) { // keyboard mapping changed + XRefreshKeyboardMapping( &event->xmapping ); + return 0; + } + + if ( event->type == PropertyNotify ) { // some properties changed + if ( event->xproperty.window == TQPaintDevice::x11AppRootWindow( 0 ) ) { + // root properties for the first screen + if ( event->xproperty.atom == tqt_clipboard_sentinel ) { + if (qt_check_clipboard_sentinel() ) + emit clipboard()->dataChanged(); + } else if ( event->xproperty.atom == qt_selection_sentinel ) { + if (qt_check_selection_sentinel() ) + emit clipboard()->selectionChanged(); + } else if ( obey_desktop_settings ) { + if ( event->xproperty.atom == qt_resource_manager ) + qt_set_x11_resources(); + else if ( event->xproperty.atom == qt_settings_timestamp ) + TQApplication::x11_apply_settings(); + } + } + if ( event->xproperty.window == TQPaintDevice::x11AppRootWindow() ) { + // root properties for the default screen + if ( event->xproperty.atom == qt_input_encoding ) { + qt_set_input_encoding(); + } else if ( event->xproperty.atom == qt_net_supported ) { + qt_get_net_supported(); + } else if ( event->xproperty.atom == qt_net_virtual_roots ) { + qt_get_net_virtual_roots(); + } else if ( event->xproperty.atom == qt_net_workarea ) { + qt_desktopwidget_update_workarea(); + } + } else if ( widget ) { + widget->translatePropertyEvent(event); + } else { + return -1; // don't know this window + } + return 0; + } + +#ifndef TQT_NO_XRANDR + // XRandR doesn't care if TQt doesn't know about the widget, so handle XRandR stuff before the !widget check below + if (event->type == xrandr_eventbase + RRScreenChangeNotify + || ( event->type == ConfigureNotify && event->xconfigure.window == TQPaintDevice::x11AppRootWindow())) { + // update Xlib internals with the latest screen configuration + XRRUpdateConfiguration(event); + + // update the size for desktop widget + int scr = XRRRootToScreen( appDpy, event->xany.window ); + TQWidget *w = desktop()->screen( scr ); + + if (w) { + int widgetScr = -1; + // make sure the specified widget is on the same screen that received the XRandR event + XWindowAttributes widgetAttr; + XGetWindowAttributes(appDpy, w->winId(), &widgetAttr); + if (widgetAttr.screen) { + widgetScr = XScreenNumberOfScreen(widgetAttr.screen); + } + + if ((widgetScr < 0) || (widgetScr == scr)) { + TQSize oldSize( w->size() ); + w->crect.setWidth( DisplayWidth( appDpy, scr ) ); + w->crect.setHeight( DisplayHeight( appDpy, scr ) ); + if ( w->size() != oldSize ) { + TQResizeEvent e( w->size(), oldSize ); + TQApplication::sendEvent( w, &e ); + emit desktop()->resized( scr ); + } + } + } + } +#endif // TQT_NO_XRANDR + + if ( !widget ) { // don't know this windows + TQWidget* popup = TQApplication::activePopupWidget(); + if ( popup ) { + + /* + That is more than suboptimal. The real solution should + do some keyevent and buttonevent translation, so that + the popup still continues to work as the user expects. + Unfortunately this translation is currently only + possible with a known widget. I'll change that soon + (Matthias). + */ + + // Danger - make sure we don't lock the server + switch ( event->type ) { + case ButtonPress: + case ButtonRelease: + case XKeyPress: + case XKeyRelease: + do { + popup->close(); + } while ( (popup = tqApp->activePopupWidget()) ); + return 1; + } + } + return -1; + } + + if ( event->type == XKeyPress || event->type == XKeyRelease ) + widget = keywidget; // send XKeyEvents through keywidget->x11Event() + + if ( app_do_modal ) // modal event handling + if ( !tqt_try_modal(widget, event) ) { + if ( event->type == ClientMessage ) + x11ClientMessage( widget, event, TRUE ); + return 1; + } + + + if ( widget->x11Event(event) ) // send through widget filter + return 1; +#if defined (QT_TABLET_SUPPORT) + if ( event->type == xinput_motion || + event->type == xinput_button_release || + event->type == xinput_button_press ) { + widget->translateXinputEvent( event ); + return 0; + } +#endif + + switch ( event->type ) { + + case ButtonRelease: // mouse event + if ( ignoreNextMouseReleaseEvent ) { + ignoreNextMouseReleaseEvent = FALSE; + break; + } + // fall through intended + case ButtonPress: + if (event->xbutton.root != RootWindow(widget->x11Display(), widget->x11Screen()) + && ! qt_xdnd_dragging) { + while ( activePopupWidget() ) + activePopupWidget()->close(); + return 1; + } + if (event->type == ButtonPress) + qt_net_update_user_time(widget->topLevelWidget()); + // fall through intended + case MotionNotify: +#if defined(QT_TABLET_SUPPORT) + if ( !chokeMouse ) { +#endif + widget->translateMouseEvent( event ); +#if defined(QT_TABLET_SUPPORT) + } else { + chokeMouse = FALSE; + } +#endif + break; + + case XKeyPress: // keyboard event + qt_net_update_user_time(widget->topLevelWidget()); + // fallthrough intended + case XKeyRelease: + { + if ( keywidget && keywidget->isEnabled() ) { // should always exist + // tqDebug( "sending key event" ); + keywidget->translateKeyEvent( event, grabbed ); + } + break; + } + + case GraphicsExpose: + case Expose: // paint event + widget->translatePaintEvent( event ); + break; + + case ConfigureNotify: // window move/resize event + if ( event->xconfigure.event == event->xconfigure.window ) + widget->translateConfigEvent( event ); + break; + + case XFocusIn: { // got focus + if ( widget->isDesktop() ) + break; + if ( inPopupMode() ) // some delayed focus event to ignore + break; + if ( !widget->isTopLevel() ) + break; + if ( event->xfocus.detail != NotifyAncestor && + event->xfocus.detail != NotifyInferior && + event->xfocus.detail != NotifyNonlinear ) + break; + widget->createInputContext(); + setActiveWindow( widget ); + if ( qt_focus_model == FocusModel_PointerRoot ) { + // We got real input focus from somewhere, but we were in PointerRoot + // mode, so we don't trust this event. Check the focus model to make + // sure we know what focus mode we are using... + qt_check_focus_model(); + } + } + break; + + case XFocusOut: // lost focus + if ( widget->isDesktop() ) + break; + if ( !widget->isTopLevel() ) + break; + if ( event->xfocus.mode == NotifyGrab ) + qt_xfocusout_grab_counter++; + if ( event->xfocus.mode != NotifyNormal ) + break; + if ( event->xfocus.detail != NotifyAncestor && + event->xfocus.detail != NotifyNonlinearVirtual && + event->xfocus.detail != NotifyNonlinear ) + break; + if ( !inPopupMode() && widget == active_window ) + setActiveWindow( 0 ); + break; + + case EnterNotify: { // enter window + if ( TQWidget::mouseGrabber() && widget != TQWidget::mouseGrabber() ) + break; + if ( inPopupMode() && widget->topLevelWidget() != activePopupWidget() ) + break; + if ( event->xcrossing.mode != NotifyNormal || + event->xcrossing.detail == NotifyVirtual || + event->xcrossing.detail == NotifyNonlinearVirtual ) + break; + if ( event->xcrossing.focus && + !widget->isDesktop() && !widget->isActiveWindow() ) { + if ( qt_focus_model == FocusModel_Unknown ) // check focus model + qt_check_focus_model(); + if ( qt_focus_model == FocusModel_PointerRoot ) // PointerRoot mode + setActiveWindow( widget ); + } + tqt_dispatchEnterLeave( widget, TQWidget::find( curWin ) ); + curWin = widget->winId(); + widget->translateMouseEvent( event ); //we don't get MotionNotify, emulate it + } + break; + + case LeaveNotify: { // leave window + if ( TQWidget::mouseGrabber() && widget != TQWidget::mouseGrabber() ) + break; + if ( curWin && widget->winId() != curWin ) + break; + if ( event->xcrossing.mode != NotifyNormal ) + break; + if ( !widget->isDesktop() ) + widget->translateMouseEvent( event ); //we don't get MotionNotify, emulate it + + TQWidget* enter = 0; + XEvent ev; + while ( XCheckMaskEvent( widget->x11Display(), EnterWindowMask | LeaveWindowMask , &ev ) + && !qt_x11EventFilter( &ev )) { + TQWidget* event_widget = TQWidget::find( ev.xcrossing.window ); + if( event_widget && event_widget->x11Event( &ev ) ) + break; + if ( ev.type == LeaveNotify && ev.xcrossing.mode == NotifyNormal ){ + enter = event_widget; + XPutBackEvent( widget->x11Display(), &ev ); + break; + } + if ( ev.xcrossing.mode != NotifyNormal || + ev.xcrossing.detail == NotifyVirtual || + ev.xcrossing.detail == NotifyNonlinearVirtual ) + continue; + enter = event_widget; + if ( ev.xcrossing.focus && + enter && !enter->isDesktop() && !enter->isActiveWindow() ) { + if ( qt_focus_model == FocusModel_Unknown ) // check focus model + qt_check_focus_model(); + if ( qt_focus_model == FocusModel_PointerRoot ) // PointerRoot mode + setActiveWindow( enter ); + } + break; + } + + if ( ( ! enter || enter->isDesktop() ) && + event->xcrossing.focus && widget == active_window && + qt_focus_model == FocusModel_PointerRoot // PointerRoot mode + ) { + setActiveWindow( 0 ); + } + + if ( !curWin ) + tqt_dispatchEnterLeave( widget, 0 ); + + tqt_dispatchEnterLeave( enter, widget ); + curWin = enter ? enter->winId() : 0; + } + break; + + case UnmapNotify: // window hidden + if ( widget->isTopLevel() && widget->isShown() ) { + widget->topData()->spont_unmapped = 1; + TQHideEvent e; + TQApplication::sendSpontaneousEvent( widget, &e ); + widget->hideChildren( TRUE ); + } + break; + + case MapNotify: // window shown + if ( widget->isTopLevel() && + widget->topData()->spont_unmapped ) { + widget->topData()->spont_unmapped = 0; + widget->showChildren( TRUE ); + TQShowEvent e; + TQApplication::sendSpontaneousEvent( widget, &e ); + } + break; + + case ClientMessage: // client message + return x11ClientMessage(widget,event,False); + + case ReparentNotify: // window manager reparents + while ( XCheckTypedWindowEvent( widget->x11Display(), + widget->winId(), + ReparentNotify, + event ) ) + ; // skip old reparent events + if ( event->xreparent.parent == TQPaintDevice::x11AppRootWindow() ) { + if ( widget->isTopLevel() ) { + widget->topData()->parentWinId = event->xreparent.parent; + if ( qt_deferred_map_contains( widget ) ) { + qt_deferred_map_take( widget ); + XMapWindow( appDpy, widget->winId() ); + } + } + } else + // store the parent. Useful for many things, embedding for instance. + widget->topData()->parentWinId = event->xreparent.parent; + if ( widget->isTopLevel() ) { + // the widget frame strut should also be invalidated + widget->topData()->fleft = widget->topData()->fright = + widget->topData()->ftop = widget->topData()->fbottom = 0; + + if ( qt_focus_model != FocusModel_Unknown ) { + // toplevel reparented... + TQWidget *newparent = TQWidget::find( event->xreparent.parent ); + if ( ! newparent || newparent->isDesktop() ) { + // we dont' know about the new parent (or we've been + // reparented to root), perhaps a window manager + // has been (re)started? reset the focus model to unknown + qt_focus_model = FocusModel_Unknown; + } + } + } + break; + + case SelectionRequest: { + XSelectionRequestEvent *req = &event->xselectionrequest; + if (! req) + break; + + if ( qt_xdnd_selection && req->selection == qt_xdnd_selection ) { + qt_xdnd_handle_selection_request( req ); + + } else if (tqt_clipboard) { + TQCustomEvent e( TQEvent::Clipboard, event ); + TQApplication::sendSpontaneousEvent( tqt_clipboard, &e ); + } + break; + } + case SelectionClear: { + XSelectionClearEvent *req = &event->xselectionclear; + // don't deliver dnd events to the clipboard, it gets confused + if (! req || ( qt_xdnd_selection && req->selection ) == qt_xdnd_selection) + break; + + if (tqt_clipboard) { + TQCustomEvent e( TQEvent::Clipboard, event ); + TQApplication::sendSpontaneousEvent( tqt_clipboard, &e ); + } + break; + } + + case SelectionNotify: { + XSelectionEvent *req = &event->xselection; + // don't deliver dnd events to the clipboard, it gets confused + if (! req || ( qt_xdnd_selection && req->selection ) == qt_xdnd_selection) + break; + + if (tqt_clipboard) { + TQCustomEvent e( TQEvent::Clipboard, event ); + TQApplication::sendSpontaneousEvent( tqt_clipboard, &e ); + } + break; + } + + default: + break; + } + + return 0; +} + +/*! + This virtual function is only implemented under X11. + + If you create an application that inherits TQApplication and + reimplement this function, you get direct access to all X events + that the are received from the X server. + + Return TRUE if you want to stop the event from being processed. + Return FALSE for normal event dispatching. + + \sa x11ProcessEvent() +*/ + +bool TQApplication::x11EventFilter( XEvent * ) +{ + return FALSE; +} + + + +/***************************************************************************** + Modal widgets; Since Xlib has little support for this we roll our own + modal widget mechanism. + A modal widget without a parent becomes application-modal. + A modal widget with a parent becomes modal to its parent and grandparents.. + + tqt_enter_modal() + Enters modal state + Arguments: + TQWidget *widget A modal widget + + tqt_leave_modal() + Leaves modal state for a widget + Arguments: + TQWidget *widget A modal widget + *****************************************************************************/ + +bool tqt_modal_state() +{ + return app_do_modal; +} + +void tqt_enter_modal( TQWidget *widget ) +{ + if ( !tqt_modal_stack ) { // create modal stack + tqt_modal_stack = new TQWidgetList; + TQ_CHECK_PTR( tqt_modal_stack ); + } + if (widget->parentWidget()) { + TQEvent e(TQEvent::WindowBlocked); + TQApplication::sendEvent(widget->parentWidget(), &e); + } + + tqt_dispatchEnterLeave( 0, TQWidget::find((WId)curWin) ); + tqt_modal_stack->insert( 0, widget ); + app_do_modal = TRUE; + curWin = 0; + ignoreNextMouseReleaseEvent = FALSE; +} + + +void tqt_leave_modal( TQWidget *widget ) +{ + if ( tqt_modal_stack && tqt_modal_stack->removeRef(widget) ) { + if ( tqt_modal_stack->isEmpty() ) { + delete tqt_modal_stack; + tqt_modal_stack = 0; + TQPoint p( TQCursor::pos() ); + TQWidget* w = TQApplication::widgetAt( p.x(), p.y(), TRUE ); + tqt_dispatchEnterLeave( w, TQWidget::find( curWin ) ); // send synthetic enter event + curWin = w? w->winId() : 0; + } + } + app_do_modal = tqt_modal_stack != 0; + ignoreNextMouseReleaseEvent = TRUE; + + if (widget->parentWidget()) { + TQEvent e(TQEvent::WindowUnblocked); + TQApplication::sendEvent(widget->parentWidget(), &e); + } +} + + +TQ_EXPORT bool tqt_try_modal( TQWidget *widget, XEvent *event ) +{ + if (qt_xdnd_dragging) { + // allow mouse events while DnD is active + switch (event->type) { + case ButtonPress: + case ButtonRelease: + case MotionNotify: + return TRUE; + default: + break; + } + } + + if ( tqt_tryModalHelper( widget ) ) + return TRUE; + + bool block_event = FALSE; + switch ( event->type ) { + case ButtonPress: // disallow mouse/key events + case ButtonRelease: + case MotionNotify: + case XKeyPress: + case XKeyRelease: + case EnterNotify: + case LeaveNotify: + case ClientMessage: + block_event = TRUE; + break; + default: + break; + } + + return !block_event; +} + + +/***************************************************************************** + Popup widget mechanism + + openPopup() + Adds a widget to the list of popup widgets + Arguments: + TQWidget *widget The popup widget to be added + + closePopup() + Removes a widget from the list of popup widgets + Arguments: + TQWidget *widget The popup widget to be removed + *****************************************************************************/ + + +static int openPopupCount = 0; +void TQApplication::openPopup( TQWidget *popup ) +{ + openPopupCount++; + if ( !popupWidgets ) { // create list + popupWidgets = new TQWidgetList; + TQ_CHECK_PTR( popupWidgets ); + } + popupWidgets->append( popup ); // add to end of list + + if ( popupWidgets->count() == 1 && !qt_nograb() ){ // grab mouse/keyboard + int r = XGrabKeyboard( popup->x11Display(), popup->winId(), FALSE, + GrabModeSync, GrabModeAsync, CurrentTime ); + if ( (popupGrabOk = (r == GrabSuccess)) ) { + r = XGrabPointer( popup->x11Display(), popup->winId(), TRUE, + (uint)(ButtonPressMask | ButtonReleaseMask | + ButtonMotionMask | EnterWindowMask | + LeaveWindowMask | PointerMotionMask), + GrabModeSync, GrabModeAsync, + None, None, CurrentTime ); + + if ( (popupGrabOk = (r == GrabSuccess)) ) + XAllowEvents( popup->x11Display(), SyncPointer, CurrentTime ); + else + XUngrabKeyboard( popup->x11Display(), CurrentTime ); + } + } else if ( popupGrabOk ) { + XAllowEvents( popup->x11Display(), SyncPointer, CurrentTime ); + } + + // popups are not focus-handled by the window system (the first + // popup grabbed the keyboard), so we have to do that manually: A + // new popup gets the focus + TQFocusEvent::setReason( TQFocusEvent::Popup ); + if ( popup->focusWidget()) + popup->focusWidget()->setFocus(); + else + popup->setFocus(); + TQFocusEvent::resetReason(); +} + +void TQApplication::closePopup( TQWidget *popup ) +{ + if ( !popupWidgets ) + return; + popupWidgets->removeRef( popup ); + if (popup == popupOfPopupButtonFocus) { + popupButtonFocus = 0; + popupOfPopupButtonFocus = 0; + } + if ( popupWidgets->count() == 0 ) { // this was the last popup + popupCloseDownMode = TRUE; // control mouse events + delete popupWidgets; + popupWidgets = 0; + if ( !qt_nograb() && popupGrabOk ) { // grabbing not disabled + if ( mouseButtonState != 0 + || popup->geometry(). contains(TQPoint(mouseGlobalXPos, mouseGlobalYPos) ) ) + { // mouse release event or inside + XAllowEvents( popup->x11Display(), AsyncPointer, + CurrentTime ); + } else { // mouse press event + mouseButtonPressTime -= 10000; // avoid double click + XAllowEvents( popup->x11Display(), ReplayPointer,CurrentTime ); + } + XUngrabPointer( popup->x11Display(), CurrentTime ); + XFlush( popup->x11Display() ); + } + if ( active_window ) { + TQFocusEvent::setReason( TQFocusEvent::Popup ); + if ( active_window->focusWidget() ) + active_window->focusWidget()->setFocus(); + else + active_window->setFocus(); + TQFocusEvent::resetReason(); + } + } else { + // popups are not focus-handled by the window system (the + // first popup grabbed the keyboard), so we have to do that + // manually: A popup was closed, so the previous popup gets + // the focus. + TQFocusEvent::setReason( TQFocusEvent::Popup ); + TQWidget* aw = popupWidgets->getLast(); + if (aw->focusWidget()) + aw->focusWidget()->setFocus(); + else + aw->setFocus(); + TQFocusEvent::resetReason(); + if ( popupWidgets->count() == 1 && !qt_nograb() ){ // grab mouse/keyboard + int r = XGrabKeyboard( aw->x11Display(), aw->winId(), FALSE, + GrabModeSync, GrabModeAsync, CurrentTime ); + if ( (popupGrabOk = (r == GrabSuccess)) ) { + r = XGrabPointer( aw->x11Display(), aw->winId(), TRUE, + (uint)(ButtonPressMask | ButtonReleaseMask | + ButtonMotionMask | EnterWindowMask | + LeaveWindowMask | PointerMotionMask), + GrabModeSync, GrabModeAsync, + None, None, CurrentTime ); + + if ( (popupGrabOk = (r == GrabSuccess)) ) + XAllowEvents( aw->x11Display(), SyncPointer, CurrentTime ); + } + } + } +} + +/***************************************************************************** + Event translation; translates X11 events to TQt events + *****************************************************************************/ + +// +// Mouse event translation +// +// Xlib doesn't give mouse double click events, so we generate them by +// comparing window, time and position between two mouse press events. +// + +// +// Keyboard event translation +// + +int qt_x11_translateButtonState( int s ) +{ + int bst = 0; + if ( s & Button1Mask ) + bst |= TQt::LeftButton; + if ( s & Button2Mask ) + bst |= TQt::MidButton; + if ( s & Button3Mask ) + bst |= TQt::RightButton; + if ( s & ShiftMask ) + bst |= TQt::ShiftButton; + if ( s & ControlMask ) + bst |= TQt::ControlButton; + if ( s & qt_alt_mask ) + bst |= TQt::AltButton; + if ( s & qt_meta_mask ) + bst |= TQt::MetaButton; + return bst; +} + +bool TQETWidget::translateMouseEvent( const XEvent *event ) +{ + static bool manualGrab = FALSE; + TQEvent::Type type; // event parameters + TQPoint pos; + TQPoint globalPos; + int button = 0; + int state; + XEvent nextEvent; + + if ( sm_blockUserInput ) // block user interaction during session management + return TRUE; + + static int x_root_save = -1, y_root_save = -1; + + if ( event->type == MotionNotify ) { // mouse move + if (event->xmotion.root != RootWindow(appDpy, x11Screen()) && + ! qt_xdnd_dragging ) + return FALSE; + + XMotionEvent lastMotion = event->xmotion; + while( XPending( appDpy ) ) { // compres mouse moves + XNextEvent( appDpy, &nextEvent ); + if ( nextEvent.type == ConfigureNotify + || nextEvent.type == PropertyNotify + || nextEvent.type == Expose + || nextEvent.type == NoExpose ) { + tqApp->x11ProcessEvent( &nextEvent ); + continue; + } else if ( nextEvent.type != MotionNotify || + nextEvent.xmotion.window != event->xmotion.window || + nextEvent.xmotion.state != event->xmotion.state ) { + XPutBackEvent( appDpy, &nextEvent ); + break; + } + if ( !qt_x11EventFilter(&nextEvent) + && !x11Event( &nextEvent ) ) // send event through filter + lastMotion = nextEvent.xmotion; + else + break; + } + type = TQEvent::MouseMove; + pos.rx() = lastMotion.x; + pos.ry() = lastMotion.y; + globalPos.rx() = lastMotion.x_root; + globalPos.ry() = lastMotion.y_root; + state = qt_x11_translateButtonState( lastMotion.state ); + if ( qt_button_down && (state & (LeftButton | + MidButton | + RightButton ) ) == 0 ) + qt_button_down = 0; + + // throw away mouse move events that are sent multiple times to the same + // position + bool throw_away = FALSE; + if ( x_root_save == globalPos.x() && + y_root_save == globalPos.y() ) + throw_away = TRUE; + x_root_save = globalPos.x(); + y_root_save = globalPos.y(); + if ( throw_away ) + return TRUE; + } else if ( event->type == EnterNotify || event->type == LeaveNotify) { + XEvent *xevent = (XEvent *)event; + //unsigned int xstate = event->xcrossing.state; + type = TQEvent::MouseMove; + pos.rx() = xevent->xcrossing.x; + pos.ry() = xevent->xcrossing.y; + globalPos.rx() = xevent->xcrossing.x_root; + globalPos.ry() = xevent->xcrossing.y_root; + state = qt_x11_translateButtonState( xevent->xcrossing.state ); + if ( qt_button_down && (state & (LeftButton | + MidButton | + RightButton ) ) == 0 ) + qt_button_down = 0; + if ( !qt_button_down ) + state = state & ~(LeftButton | MidButton | RightButton ); + } else { // button press or release + pos.rx() = event->xbutton.x; + pos.ry() = event->xbutton.y; + globalPos.rx() = event->xbutton.x_root; + globalPos.ry() = event->xbutton.y_root; + state = qt_x11_translateButtonState( event->xbutton.state ); + switch ( event->xbutton.button ) { + case Button1: button = LeftButton; break; + case Button2: button = MidButton; break; + case Button3: button = RightButton; break; + case Button4: + case Button5: + case 6: + case 7: + // the fancy mouse wheel. + + // take care about grabbing. We do this here since it + // is clear that we return anyway + if ( tqApp->inPopupMode() && popupGrabOk ) + XAllowEvents( x11Display(), SyncPointer, CurrentTime ); + + // We are only interested in ButtonPress. + if (event->type == ButtonPress ){ + + // compress wheel events (the X Server will simply + // send a button press for each single notch, + // regardless whether the application can catch up + // or not) + int delta = 1; + XEvent xevent; + while ( XCheckTypedWindowEvent(x11Display(),winId(), + ButtonPress,&xevent) ){ + if (xevent.xbutton.button != event->xbutton.button){ + XPutBackEvent(x11Display(), &xevent); + break; + } + delta++; + } + + // the delta is defined as multiples of + // WHEEL_DELTA, which is set to 120. Future wheels + // may offer a finer-resolution. A positive delta + // indicates forward rotation, a negative one + // backward rotation respectively. + int btn = event->xbutton.button; + delta *= 120 * ( (btn == Button4 || btn == 6) ? 1 : -1 ); + bool hor = ( ( (btn == Button4 || btn == Button5) && (state&AltButton) ) || + (btn == 6 || btn == 7) ); + translateWheelEvent( globalPos.x(), globalPos.y(), delta, state, (hor)?Horizontal:Vertical ); + } + return TRUE; + + // history navigation buttons + case 8: button = HistoryBackButton; break; + case 9: button = HistoryForwardButton; break; + } + if ( event->type == ButtonPress ) { // mouse button pressed +#if defined(Q_OS_IRIX) && defined(QT_TABLET_SUPPORT) + XEvent myEv; + if ( XCheckTypedEvent( appDpy, xinput_button_press, &myEv ) ) { + if ( translateXinputEvent( &myEv ) ) { + //Spontaneous event sent. Check if we need to continue. + if ( chokeMouse ) { + chokeMouse = FALSE; + return FALSE; + } + } + } +#endif + qt_button_down = childAt( pos ); //magic for masked widgets + if ( !qt_button_down || !qt_button_down->testWFlags(WMouseNoMask) ) + qt_button_down = this; + if ( mouseActWindow == event->xbutton.window && + mouseButtonPressed == button && + (long)event->xbutton.time -(long)mouseButtonPressTime + < TQApplication::doubleClickInterval() && + TQABS(event->xbutton.x - mouseXPos) < 5 && + TQABS(event->xbutton.y - mouseYPos) < 5 ) { + type = TQEvent::MouseButtonDblClick; + mouseButtonPressTime -= 2000; // no double-click next time + } else { + type = TQEvent::MouseButtonPress; + mouseButtonPressTime = event->xbutton.time; + } + mouseButtonPressed = button; // save event params for + mouseXPos = pos.x(); // future double click tests + mouseYPos = pos.y(); + mouseGlobalXPos = globalPos.x(); + mouseGlobalYPos = globalPos.y(); + } else { // mouse button released +#if defined(Q_OS_IRIX) && defined(QT_TABLET_SUPPORT) + XEvent myEv; + if ( XCheckTypedEvent( appDpy, xinput_button_release, &myEv ) ) { + if ( translateXinputEvent( &myEv ) ) { + //Spontaneous event sent. Check if we need to continue. + if ( chokeMouse ) { + chokeMouse = FALSE; + return FALSE; + } + } + } +#endif + if ( manualGrab ) { // release manual grab + manualGrab = FALSE; + XUngrabPointer( x11Display(), CurrentTime ); + XFlush( x11Display() ); + } + + type = TQEvent::MouseButtonRelease; + } + } + mouseActWindow = winId(); // save some event params + mouseButtonState = state; + if ( type == 0 ) // don't send event + return FALSE; + + if ( tqApp->inPopupMode() ) { // in popup mode + TQWidget *popup = tqApp->activePopupWidget(); + if ( popup != this ) { + if ( testWFlags(WType_Popup) && rect().contains(pos) ) + popup = this; + else // send to last popup + pos = popup->mapFromGlobal( globalPos ); + } + bool releaseAfter = FALSE; + TQWidget *popupChild = popup->childAt( pos ); + TQWidget *popupTarget = popupChild ? popupChild : popup; + + if (popup != popupOfPopupButtonFocus){ + popupButtonFocus = 0; + popupOfPopupButtonFocus = 0; + } + + if ( !popupTarget->isEnabled() ) { + if ( popupGrabOk ) + XAllowEvents( x11Display(), SyncPointer, CurrentTime ); + } + + switch ( type ) { + case TQEvent::MouseButtonPress: + case TQEvent::MouseButtonDblClick: + popupButtonFocus = popupChild; + popupOfPopupButtonFocus = popup; + break; + case TQEvent::MouseButtonRelease: + releaseAfter = TRUE; + break; + default: + break; // nothing for mouse move + } + + Display* dpy = x11Display(); // store display, send() may destroy us + + + int oldOpenPopupCount = openPopupCount; + + if ( popupButtonFocus ) { + TQMouseEvent e( type, popupButtonFocus->mapFromGlobal(globalPos), + globalPos, button, state ); + TQApplication::sendSpontaneousEvent( popupButtonFocus, &e ); + if ( releaseAfter ) { + popupButtonFocus = 0; + popupOfPopupButtonFocus = 0; + } + } else if ( popupChild ) { + TQMouseEvent e( type, popupChild->mapFromGlobal(globalPos), + globalPos, button, state ); + TQApplication::sendSpontaneousEvent( popupChild, &e ); + } else { + TQMouseEvent e( type, pos, globalPos, button, state ); + TQApplication::sendSpontaneousEvent( popup, &e ); + } + + if ( type == TQEvent::MouseButtonPress && button == RightButton && ( openPopupCount == oldOpenPopupCount ) ) { + TQWidget *popupEvent = popup; + if(popupButtonFocus) + popupEvent = popupButtonFocus; + else if(popupChild) + popupEvent = popupChild; + TQContextMenuEvent e( TQContextMenuEvent::Mouse, pos, globalPos, state ); + TQApplication::sendSpontaneousEvent( popupEvent, &e ); + } + + if ( releaseAfter ) + qt_button_down = 0; + + if ( tqApp->inPopupMode() ) { // still in popup mode + if ( popupGrabOk ) + XAllowEvents( dpy, SyncPointer, CurrentTime ); + } else { + if ( type != TQEvent::MouseButtonRelease && state != 0 && + TQWidget::find((WId)mouseActWindow) ) { + manualGrab = TRUE; // need to manually grab + XGrabPointer( dpy, mouseActWindow, False, + (uint)(ButtonPressMask | ButtonReleaseMask | + ButtonMotionMask | + EnterWindowMask | LeaveWindowMask), + GrabModeAsync, GrabModeAsync, + None, None, CurrentTime ); + } + } + + } else { + TQWidget *widget = this; + TQWidget *w = TQWidget::mouseGrabber(); + if ( !w ) + w = qt_button_down; + if ( w && w != this ) { + widget = w; + pos = w->mapFromGlobal( globalPos ); + } + + if ( popupCloseDownMode ) { + popupCloseDownMode = FALSE; + if ( testWFlags(WType_Popup) ) // ignore replayed event + return TRUE; + } + + if ( type == TQEvent::MouseButtonRelease && + (state & (~button) & ( LeftButton | + MidButton | + RightButton)) == 0 ) { + qt_button_down = 0; + } + + int oldOpenPopupCount = openPopupCount; + + TQMouseEvent e( type, pos, globalPos, button, state ); + TQApplication::sendSpontaneousEvent( widget, &e ); + + if ( type == TQEvent::MouseButtonPress && button == RightButton && ( openPopupCount == oldOpenPopupCount ) ) { + TQContextMenuEvent e( TQContextMenuEvent::Mouse, pos, globalPos, state ); + TQApplication::sendSpontaneousEvent( widget, &e ); + } + } + return TRUE; +} + + +// +// Wheel event translation +// +bool TQETWidget::translateWheelEvent( int global_x, int global_y, int delta, int state, Orientation orient ) +{ + // send the event to the widget or its ancestors + { + TQWidget* popup = tqApp->activePopupWidget(); + if ( popup && topLevelWidget() != popup ) + popup->close(); + TQWheelEvent e( mapFromGlobal(TQPoint( global_x, global_y)), + TQPoint(global_x, global_y), delta, state, orient ); + if ( TQApplication::sendSpontaneousEvent( this, &e ) ) + return TRUE; + } + + // send the event to the widget that has the focus or its ancestors, if different + TQWidget *w = this; + if ( w != tqApp->focusWidget() && ( w = tqApp->focusWidget() ) ) { + TQWidget* popup = tqApp->activePopupWidget(); + if ( popup && w != popup ) + popup->hide(); + TQWheelEvent e( mapFromGlobal(TQPoint( global_x, global_y)), + TQPoint(global_x, global_y), delta, state, orient ); + if ( TQApplication::sendSpontaneousEvent( w, &e ) ) + return TRUE; + } + return FALSE; +} + + +// +// XInput Translation Event +// +#if defined (QT_TABLET_SUPPORT) +bool TQETWidget::translateXinputEvent( const XEvent *ev ) +{ +#if defined (Q_OS_IRIX) + // Wacom has put defines in their wacom.h file so it would be quite wise + // to use them, need to think of a decent way of not using + // it when it doesn't exist... + XDeviceState *s; + XInputClass *iClass; + XValuatorState *vs; + int j; +#endif + TQWidget *w = this; + TQPoint global, + curr; + static int pressure = 0; + static int xTilt = 0, + yTilt = 0; + int deviceType = TQTabletEvent::NoDevice; + TQPair tId; + XEvent xinputMotionEvent; + XEvent mouseMotionEvent; +#if defined (Q_OS_IRIX) + XDevice *dev; +#endif + const XDeviceMotionEvent *motion = 0; + XDeviceButtonEvent *button = 0; + TQEvent::Type t; + + if ( ev->type == xinput_motion ) { + motion = (const XDeviceMotionEvent*)ev; + for (;;) { + if (!XCheckTypedWindowEvent(x11Display(), winId(), MotionNotify, &mouseMotionEvent)) + break; + if (!XCheckTypedWindowEvent(x11Display(), winId(), xinput_motion, &xinputMotionEvent)) { + XPutBackEvent(x11Display(), &mouseMotionEvent); + break; + } + if (mouseMotionEvent.xmotion.time != motion->time) { + XPutBackEvent(x11Display(), &mouseMotionEvent); + XPutBackEvent(x11Display(), &xinputMotionEvent); + break; + } + motion = ((const XDeviceMotionEvent*)&xinputMotionEvent); + } + t = TQEvent::TabletMove; + curr = TQPoint( motion->x, motion->y ); + } else { + if ( ev->type == xinput_button_press ) { + t = TQEvent::TabletPress; + } else { + t = TQEvent::TabletRelease; + } + button = (XDeviceButtonEvent*)ev; +/* + tqDebug( "\n\nXInput Button Event" ); + tqDebug( "serial:\t%d", button->serial ); + tqDebug( "send_event:\t%d", button->send_event ); + tqDebug( "display:\t%p", button->display ); + tqDebug( "window:\t%d", button->window ); + tqDebug( "deviceID:\t%d", button->deviceid ); + tqDebug( "root:\t%d", button->root ); + tqDebug( "subwindot:\t%d", button->subwindow ); + tqDebug( "x:\t%d", button->x ); + tqDebug( "y:\t%d", button->y ); + tqDebug( "x_root:\t%d", button->x_root ); + tqDebug( "y_root:\t%d", button->y_root ); + tqDebug( "state:\t%d", button->state ); + tqDebug( "button:\t%d", button->button ); + tqDebug( "same_screen:\t%d", button->same_screen ); + tqDebug( "time:\t%d", button->time ); +*/ + curr = TQPoint( button->x, button->y ); + } +#if defined(Q_OS_IRIX) + // default... + dev = devStylus; +#else + if ( ev->type == xinput_motion ) { + if ( motion->deviceid == devStylus->device_id ) { + deviceType = TQTabletEvent::Stylus; + } else if ( motion->deviceid == devEraser->device_id ) { + deviceType = TQTabletEvent::Eraser; + } + } else { + if ( button->deviceid == devStylus->device_id ) { + deviceType = TQTabletEvent::Stylus; + } else if ( button->deviceid == devEraser->device_id ) { + deviceType = TQTabletEvent::Eraser; + } + } +#endif + + const int PRESSURE_LEVELS = 255; + // we got the maximum pressure at start time, since various tablets have + // varying levels of distinguishing pressure changes, let's standardize and + // scale everything to 256 different levels... + static int scaleFactor = -1; + if ( scaleFactor == -1 ) { + if ( max_pressure > PRESSURE_LEVELS ) + scaleFactor = max_pressure / PRESSURE_LEVELS; + else + scaleFactor = PRESSURE_LEVELS / max_pressure; + } +#if defined (Q_OS_IRIX) + s = XQueryDeviceState( appDpy, dev ); + if ( s == NULL ) + return FALSE; + iClass = s->data; + for ( j = 0; j < s->num_classes; j++ ) { + if ( iClass->c_class == ValuatorClass ) { + vs = (XValuatorState *)iClass; + // figure out what device we have, based on bitmasking... + if ( vs->valuators[WAC_TRANSDUCER_I] + & WAC_TRANSDUCER_PROX_MSK ) { + switch ( vs->valuators[WAC_TRANSDUCER_I] + & WAC_TRANSDUCER_MSK ) { + case WAC_PUCK_ID: + deviceType = TQTabletEvent::Puck; + break; + case WAC_STYLUS_ID: + deviceType = TQTabletEvent::Stylus; + break; + case WAC_ERASER_ID: + deviceType = TQTabletEvent::Eraser; + break; + } + // Get a Unique Id for the device, Wacom gives us this ability + tId.first = vs->valuators[WAC_TRANSDUCER_I] & WAC_TRANSDUCER_ID_MSK; + tId.second = vs->valuators[WAC_SERIAL_NUM_I]; + } else + deviceType = TQTabletEvent::NoDevice; + // apparently Wacom needs a cast for the +/- values to make sense + xTilt = short(vs->valuators[WAC_XTILT_I]); + yTilt = short(vs->valuators[WAC_YTILT_I]); + if ( max_pressure > PRESSURE_LEVELS ) + pressure = vs->valuators[WAC_PRESSURE_I] / scaleFactor; + else + pressure = vs->valuators[WAC_PRESSURE_I] * scaleFactor; + global = TQPoint( vs->valuators[WAC_XCOORD_I], + vs->valuators[WAC_YCOORD_I] ); + break; + } + iClass = (XInputClass*)((char*)iClass + iClass->length); + } + XFreeDeviceState( s ); +#else + if ( motion ) { + xTilt = short(motion->axis_data[3]); + yTilt = short(motion->axis_data[4]); + if ( max_pressure > PRESSURE_LEVELS ) + pressure = motion->axis_data[2] / scaleFactor; + else + pressure = motion->axis_data[2] * scaleFactor; + global = TQPoint( motion->axis_data[0], motion->axis_data[1] ); + } else { + xTilt = short(button->axis_data[3]); + yTilt = short(button->axis_data[4]); + if ( max_pressure > PRESSURE_LEVELS ) + pressure = button->axis_data[2] / scaleFactor; + else + pressure = button->axis_data[2] * scaleFactor; + global = TQPoint( button->axis_data[0], button->axis_data[1] ); + } + // The only way to get these Ids is to scan the XFree86 log, which I'm not going to do. + tId.first = tId.second = -1; +#endif + + TQTabletEvent e( t, curr, global, deviceType, pressure, xTilt, yTilt, tId ); + TQApplication::sendSpontaneousEvent( w, &e ); + return TRUE; +} +#endif + +bool TQETWidget::translatePropertyEvent(const XEvent *event) +{ + if (!isTopLevel()) return TRUE; + + Atom ret; + int format, e; + unsigned char *data = 0; + unsigned long nitems, after; + + if (event->xproperty.atom == qt_net_wm_frame_strut) { + topData()->fleft = topData()->fright = topData()->ftop = topData()->fbottom = 0; + fstrut_dirty = 1; + + if (event->xproperty.state == PropertyNewValue) { + e = XGetWindowProperty(appDpy, event->xproperty.window, qt_net_wm_frame_strut, + 0, 4, // struts are 4 longs + False, XA_CARDINAL, &ret, &format, &nitems, &after, &data); + + if (e == Success && ret == XA_CARDINAL && + format == 32 && nitems == 4) { + long *strut = (long *) data; + topData()->fleft = strut[0]; + topData()->fright = strut[1]; + topData()->ftop = strut[2]; + topData()->fbottom = strut[3]; + fstrut_dirty = 0; + } + } + } else if (event->xproperty.atom == qt_net_wm_state) { + bool max = FALSE; + bool full = FALSE; + + if (event->xproperty.state == PropertyNewValue) { + // using length of 1024 should be safe for all current and + // possible NET states... + e = XGetWindowProperty(appDpy, event->xproperty.window, qt_net_wm_state, 0, 1024, + False, XA_ATOM, &ret, &format, &nitems, &after, &data); + + if (e == Success && ret == XA_ATOM && format == 32 && nitems > 0) { + Atom *states = (Atom *) data; + + unsigned long i; + for (i = 0; i < nitems; i++) { + if (states[i] == qt_net_wm_state_max_v || states[i] == qt_net_wm_state_max_h) + max = TRUE; + else if (states[i] == qt_net_wm_state_fullscreen) + full = TRUE; + } + } + } + + bool send_event = FALSE; + + if (qt_net_supports(qt_net_wm_state_max_v) + && qt_net_supports(qt_net_wm_state_max_h)) { + if (max && !isMaximized()) { + setWState(WState_Maximized); + send_event = TRUE; + } else if (!max && isMaximized()) { + clearWState(WState_Maximized); + send_event = TRUE; + } + } + + if (qt_net_supports(qt_net_wm_state_fullscreen)) { + if (full && !isFullScreen()) { + setWState(WState_FullScreen); + send_event = TRUE; + } else if (!full && isFullScreen()) { + clearWState(WState_FullScreen); + send_event = TRUE; + } + } + + if (send_event) { + TQEvent e(TQEvent::WindowStateChange); + TQApplication::sendSpontaneousEvent(this, &e); + } + } else if (event->xproperty.atom == tqt_wm_state) { + // the widget frame strut should also be invalidated + topData()->fleft = topData()->fright = topData()->ftop = topData()->fbottom = 0; + fstrut_dirty = 1; + + if (event->xproperty.state == PropertyDelete) { + // the window manager has removed the WM State property, + // so it is now in the withdrawn state (ICCCM 4.1.3.1) and + // we are free to reuse this window + topData()->parentWinId = 0; + // map the window if we were waiting for a transition to + // withdrawn + if ( qt_deferred_map_contains( this ) ) { + qt_deferred_map_take( this ); + XMapWindow( appDpy, winId() ); + } + } else if (topData()->parentWinId != TQPaintDevice::x11AppRootWindow(x11Screen())) { + // the window manager has changed the WM State property... + // we are wanting to see if we are withdrawn so that we + // can reuse this window... we only do this check *IF* we + // haven't been reparented to root - (the parentWinId != + // TQPaintDevice::x11AppRootWindow(x11Screen())) check + // above + + e = XGetWindowProperty(appDpy, winId(), tqt_wm_state, 0, 2, False, tqt_wm_state, + &ret, &format, &nitems, &after, &data ); + + if (e == Success && ret == tqt_wm_state && format == 32 && nitems > 0) { + long *state = (long *) data; + switch (state[0]) { + case WithdrawnState: + // if we are in the withdrawn state, we are free + // to reuse this window provided we remove the + // WM_STATE property (ICCCM 4.1.3.1) + XDeleteProperty(appDpy, winId(), tqt_wm_state); + + // set the parent id to zero, so that show() will + // work again + topData()->parentWinId = 0; + // map the window if we were waiting for a + // transition to withdrawn + if ( qt_deferred_map_contains( this ) ) { + qt_deferred_map_take( this ); + XMapWindow( appDpy, winId() ); + } + break; + + case IconicState: + if (!isMinimized()) { + // window was minimized + setWState(WState_Minimized); + TQEvent e(TQEvent::WindowStateChange); + TQApplication::sendSpontaneousEvent(this, &e); + } + break; + + default: + if (isMinimized()) { + // window was un-minimized + clearWState(WState_Minimized); + TQEvent e(TQEvent::WindowStateChange); + TQApplication::sendSpontaneousEvent(this, &e); + } + break; + } + } + } + } + + if (data) + XFree(data); + + return TRUE; +} + +#ifndef XK_ISO_Left_Tab +#define XK_ISO_Left_Tab 0xFE20 +#endif + +// the next lines are taken from XFree > 4.0 (X11/XF86keysyms.h), defining some special +// multimedia keys. They are included here as not every system has them. +#define XF86XK_Standby 0x1008FF10 +#define XF86XK_AudioLowerVolume 0x1008FF11 +#define XF86XK_AudioMute 0x1008FF12 +#define XF86XK_AudioRaiseVolume 0x1008FF13 +#define XF86XK_AudioPlay 0x1008FF14 +#define XF86XK_AudioStop 0x1008FF15 +#define XF86XK_AudioPrev 0x1008FF16 +#define XF86XK_AudioNext 0x1008FF17 +#define XF86XK_HomePage 0x1008FF18 +#define XF86XK_Calculator 0x1008FF1D +#define XF86XK_Mail 0x1008FF19 +#define XF86XK_Start 0x1008FF1A +#define XF86XK_Search 0x1008FF1B +#define XF86XK_AudioRecord 0x1008FF1C +#define XF86XK_Back 0x1008FF26 +#define XF86XK_Forward 0x1008FF27 +#define XF86XK_Stop 0x1008FF28 +#define XF86XK_Refresh 0x1008FF29 +#define XF86XK_Favorites 0x1008FF30 +#define XF86XK_AudioPause 0x1008FF31 +#define XF86XK_AudioMedia 0x1008FF32 +#define XF86XK_MyComputer 0x1008FF33 +#define XF86XK_OpenURL 0x1008FF38 +#define XF86XK_Launch0 0x1008FF40 +#define XF86XK_Launch1 0x1008FF41 +#define XF86XK_Launch2 0x1008FF42 +#define XF86XK_Launch3 0x1008FF43 +#define XF86XK_Launch4 0x1008FF44 +#define XF86XK_Launch5 0x1008FF45 +#define XF86XK_Launch6 0x1008FF46 +#define XF86XK_Launch7 0x1008FF47 +#define XF86XK_Launch8 0x1008FF48 +#define XF86XK_Launch9 0x1008FF49 +#define XF86XK_LaunchA 0x1008FF4A +#define XF86XK_LaunchB 0x1008FF4B +#define XF86XK_LaunchC 0x1008FF4C +#define XF86XK_LaunchD 0x1008FF4D +#define XF86XK_LaunchE 0x1008FF4E +#define XF86XK_LaunchF 0x1008FF4F +#define XF86XK_MonBrightnessUp 0x1008FF02 /* Monitor/panel brightness */ +#define XF86XK_MonBrightnessDown 0x1008FF03 /* Monitor/panel brightness */ +#define XF86XK_KbdLightOnOff 0x1008FF04 /* Keyboards may be lit */ +#define XF86XK_KbdBrightnessUp 0x1008FF05 /* Keyboards may be lit */ +#define XF86XK_KbdBrightnessDown 0x1008FF06 /* Keyboards may be lit */ +// end of XF86keysyms.h + + + +static const KeySym KeyTbl[] = { // keyboard mapping table + XK_Escape, TQt::Key_Escape, // misc keys + XK_Tab, TQt::Key_Tab, + XK_ISO_Left_Tab, TQt::Key_Backtab, + XK_BackSpace, TQt::Key_Backspace, + XK_Return, TQt::Key_Return, + XK_Insert, TQt::Key_Insert, + XK_KP_Insert, TQt::Key_Insert, + XK_Delete, TQt::Key_Delete, + XK_KP_Delete, TQt::Key_Delete, + XK_Clear, TQt::Key_Delete, + XK_Pause, TQt::Key_Pause, + XK_Print, TQt::Key_Print, + XK_KP_Begin, TQt::Key_Clear, + 0x1005FF60, TQt::Key_SysReq, // hardcoded Sun SysReq + 0x1007ff00, TQt::Key_SysReq, // hardcoded X386 SysReq + XK_Home, TQt::Key_Home, // cursor movement + XK_End, TQt::Key_End, + XK_Left, TQt::Key_Left, + XK_Up, TQt::Key_Up, + XK_Right, TQt::Key_Right, + XK_Down, TQt::Key_Down, + XK_Prior, TQt::Key_Prior, + XK_Next, TQt::Key_Next, + XK_KP_Home, TQt::Key_Home, + XK_KP_End, TQt::Key_End, + XK_KP_Left, TQt::Key_Left, + XK_KP_Up, TQt::Key_Up, + XK_KP_Right, TQt::Key_Right, + XK_KP_Down, TQt::Key_Down, + XK_KP_Prior, TQt::Key_Prior, + XK_KP_Next, TQt::Key_Next, + XK_Shift_L, TQt::Key_Shift, // modifiers + XK_Shift_R, TQt::Key_Shift, + XK_Shift_Lock, TQt::Key_Shift, + XK_Control_L, TQt::Key_Control, + XK_Control_R, TQt::Key_Control, + XK_Meta_L, TQt::Key_Meta, + XK_Meta_R, TQt::Key_Meta, + XK_Alt_L, TQt::Key_Alt, + XK_Alt_R, TQt::Key_Alt, + XK_Caps_Lock, TQt::Key_CapsLock, + XK_Num_Lock, TQt::Key_NumLock, + XK_Scroll_Lock, TQt::Key_ScrollLock, + XK_KP_Space, TQt::Key_Space, // numeric keypad + XK_KP_Tab, TQt::Key_Tab, + XK_KP_Enter, TQt::Key_Enter, + XK_KP_Equal, TQt::Key_Equal, + XK_KP_Multiply, TQt::Key_Asterisk, + XK_KP_Add, TQt::Key_Plus, + XK_KP_Separator, TQt::Key_Comma, + XK_KP_Subtract, TQt::Key_Minus, + XK_KP_Decimal, TQt::Key_Period, + XK_KP_Divide, TQt::Key_Slash, + XK_Super_L, TQt::Key_Super_L, + XK_Super_R, TQt::Key_Super_R, + XK_Menu, TQt::Key_Menu, + XK_Hyper_L, TQt::Key_Hyper_L, + XK_Hyper_R, TQt::Key_Hyper_R, + XK_Help, TQt::Key_Help, + 0x1000FF74, TQt::Key_BackTab, // hardcoded HP backtab + 0x1005FF10, TQt::Key_F11, // hardcoded Sun F36 (labeled F11) + 0x1005FF11, TQt::Key_F12, // hardcoded Sun F37 (labeled F12) + + // International input method support keys + + // International & multi-key character composition + XK_Multi_key, TQt::Key_Multi_key, + XK_Codeinput, TQt::Key_Codeinput, + XK_SingleCandidate, TQt::Key_SingleCandidate, + XK_MultipleCandidate, TQt::Key_MultipleCandidate, + XK_PreviousCandidate, TQt::Key_PreviousCandidate, + + // Misc Functions + XK_Mode_switch, TQt::Key_Mode_switch, + //XK_script_switch, TQt::Key_script_switch, + XK_script_switch, TQt::Key_Mode_switch, + + // Japanese keyboard support + XK_Kanji, TQt::Key_Kanji, + XK_Muhenkan, TQt::Key_Muhenkan, + //XK_Henkan_Mode, TQt::Key_Henkan_Mode, + XK_Henkan_Mode, TQt::Key_Henkan, + XK_Henkan, TQt::Key_Henkan, + XK_Romaji, TQt::Key_Romaji, + XK_Hiragana, TQt::Key_Hiragana, + XK_Katakana, TQt::Key_Katakana, + XK_Hiragana_Katakana, TQt::Key_Hiragana_Katakana, + XK_Zenkaku, TQt::Key_Zenkaku, + XK_Hankaku, TQt::Key_Hankaku, + XK_Zenkaku_Hankaku, TQt::Key_Zenkaku_Hankaku, + XK_Touroku, TQt::Key_Touroku, + XK_Massyo, TQt::Key_Massyo, + XK_Kana_Lock, TQt::Key_Kana_Lock, + XK_Kana_Shift, TQt::Key_Kana_Shift, + XK_Eisu_Shift, TQt::Key_Eisu_Shift, + XK_Eisu_toggle, TQt::Key_Eisu_toggle, + //XK_Kanji_Bangou, TQt::Key_Kanji_Bangou, + //XK_Zen_Koho, TQt::Key_Zen_Koho, + //XK_Mae_Koho, TQt::Key_Mae_Koho, + XK_Kanji_Bangou, TQt::Key_Codeinput, + XK_Zen_Koho, TQt::Key_MultipleCandidate, + XK_Mae_Koho, TQt::Key_PreviousCandidate, + +#ifdef XK_KOREAN + // Korean keyboard support + XK_Hangul, TQt::Key_Hangul, + XK_Hangul_Start, TQt::Key_Hangul_Start, + XK_Hangul_End, TQt::Key_Hangul_End, + XK_Hangul_Hanja, TQt::Key_Hangul_Hanja, + XK_Hangul_Jamo, TQt::Key_Hangul_Jamo, + XK_Hangul_Romaja, TQt::Key_Hangul_Romaja, + //XK_Hangul_Codeinput, TQt::Key_Hangul_Codeinput, + XK_Hangul_Codeinput, TQt::Key_Codeinput, + XK_Hangul_Jeonja, TQt::Key_Hangul_Jeonja, + XK_Hangul_Banja, TQt::Key_Hangul_Banja, + XK_Hangul_PreHanja, TQt::Key_Hangul_PreHanja, + XK_Hangul_PostHanja, TQt::Key_Hangul_PostHanja, + //XK_Hangul_SingleCandidate, TQt::Key_Hangul_SingleCandidate, + //XK_Hangul_MultipleCandidate, TQt::Key_Hangul_MultipleCandidate, + //XK_Hangul_PreviousCandidate, TQt::Key_Hangul_PreviousCandidate, + XK_Hangul_SingleCandidate, TQt::Key_SingleCandidate, + XK_Hangul_MultipleCandidate, TQt::Key_MultipleCandidate, + XK_Hangul_PreviousCandidate, TQt::Key_PreviousCandidate, + XK_Hangul_Special, TQt::Key_Hangul_Special, + //XK_Hangul_switch, TQt::Key_Hangul_switch, + XK_Hangul_switch, TQt::Key_Mode_switch, +#endif // XK_KOREAN + + // dead keys + XK_dead_grave, TQt::Key_Dead_Grave, + XK_dead_acute, TQt::Key_Dead_Acute, + XK_dead_circumflex, TQt::Key_Dead_Circumflex, + XK_dead_tilde, TQt::Key_Dead_Tilde, + XK_dead_macron, TQt::Key_Dead_Macron, + XK_dead_breve, TQt::Key_Dead_Breve, + XK_dead_abovedot, TQt::Key_Dead_Abovedot, + XK_dead_diaeresis, TQt::Key_Dead_Diaeresis, + XK_dead_abovering, TQt::Key_Dead_Abovering, + XK_dead_doubleacute, TQt::Key_Dead_Doubleacute, + XK_dead_caron, TQt::Key_Dead_Caron, + XK_dead_cedilla, TQt::Key_Dead_Cedilla, + XK_dead_ogonek, TQt::Key_Dead_Ogonek, + XK_dead_iota, TQt::Key_Dead_Iota, + XK_dead_voiced_sound, TQt::Key_Dead_Voiced_Sound, + XK_dead_semivoiced_sound, TQt::Key_Dead_Semivoiced_Sound, + XK_dead_belowdot, TQt::Key_Dead_Belowdot, + XK_dead_hook, TQt::Key_Dead_Hook, + XK_dead_horn, TQt::Key_Dead_Horn, + + // Special multimedia keys + // currently only tested with MS internet keyboard + + // browsing keys + XF86XK_Back, TQt::Key_Back, + XF86XK_Forward, TQt::Key_Forward, + XF86XK_Stop, TQt::Key_Stop, + XF86XK_Refresh, TQt::Key_Refresh, + XF86XK_Favorites, TQt::Key_Favorites, + XF86XK_AudioMedia, TQt::Key_LaunchMedia, + XF86XK_OpenURL, TQt::Key_OpenUrl, + XF86XK_HomePage, TQt::Key_HomePage, + XF86XK_Search, TQt::Key_Search, + + // media keys + XF86XK_AudioLowerVolume, TQt::Key_VolumeDown, + XF86XK_AudioMute, TQt::Key_VolumeMute, + XF86XK_AudioRaiseVolume, TQt::Key_VolumeUp, + XF86XK_AudioPlay, TQt::Key_MediaPlay, + XF86XK_AudioStop, TQt::Key_MediaStop, + XF86XK_AudioPrev, TQt::Key_MediaPrev, + XF86XK_AudioNext, TQt::Key_MediaNext, + XF86XK_AudioRecord, TQt::Key_MediaRecord, + + // launch keys + XF86XK_Mail, TQt::Key_LaunchMail, + XF86XK_MyComputer, TQt::Key_Launch0, + XF86XK_Calculator, TQt::Key_Launch1, + XF86XK_Standby, TQt::Key_Standby, + + XF86XK_Launch0, TQt::Key_Launch2, + XF86XK_Launch1, TQt::Key_Launch3, + XF86XK_Launch2, TQt::Key_Launch4, + XF86XK_Launch3, TQt::Key_Launch5, + XF86XK_Launch4, TQt::Key_Launch6, + XF86XK_Launch5, TQt::Key_Launch7, + XF86XK_Launch6, TQt::Key_Launch8, + XF86XK_Launch7, TQt::Key_Launch9, + XF86XK_Launch8, TQt::Key_LaunchA, + XF86XK_Launch9, TQt::Key_LaunchB, + XF86XK_LaunchA, TQt::Key_LaunchC, + XF86XK_LaunchB, TQt::Key_LaunchD, + XF86XK_LaunchC, TQt::Key_LaunchE, + XF86XK_LaunchD, TQt::Key_LaunchF, + XF86XK_MonBrightnessUp, TQt::Key_MonBrightnessUp, + XF86XK_MonBrightnessDown, TQt::Key_MonBrightnessDown, + XF86XK_KbdLightOnOff, TQt::Key_KeyboardLightOnOff, + XF86XK_KbdBrightnessUp, TQt::Key_KeyboardBrightnessUp, + XF86XK_KbdBrightnessDown, TQt::Key_KeyboardBrightnessDown, + + 0, 0 +}; + + +static TQIntDict *keyDict = 0; +static TQIntDict *textDict = 0; + +static void deleteKeyDicts() +{ + if ( keyDict ) + delete keyDict; + keyDict = 0; + if ( textDict ) + delete textDict; + textDict = 0; +} + +#if !defined(TQT_NO_XIM) +static const unsigned short katakanaKeysymsToUnicode[] = { + 0x0000, 0x3002, 0x300C, 0x300D, 0x3001, 0x30FB, 0x30F2, 0x30A1, + 0x30A3, 0x30A5, 0x30A7, 0x30A9, 0x30E3, 0x30E5, 0x30E7, 0x30C3, + 0x30FC, 0x30A2, 0x30A4, 0x30A6, 0x30A8, 0x30AA, 0x30AB, 0x30AD, + 0x30AF, 0x30B1, 0x30B3, 0x30B5, 0x30B7, 0x30B9, 0x30BB, 0x30BD, + 0x30BF, 0x30C1, 0x30C4, 0x30C6, 0x30C8, 0x30CA, 0x30CB, 0x30CC, + 0x30CD, 0x30CE, 0x30CF, 0x30D2, 0x30D5, 0x30D8, 0x30DB, 0x30DE, + 0x30DF, 0x30E0, 0x30E1, 0x30E2, 0x30E4, 0x30E6, 0x30E8, 0x30E9, + 0x30EA, 0x30EB, 0x30EC, 0x30ED, 0x30EF, 0x30F3, 0x309B, 0x309C +}; + +static const unsigned short cyrillicKeysymsToUnicode[] = { + 0x0000, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457, + 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x0000, 0x045e, 0x045f, + 0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407, + 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x0000, 0x040e, 0x040f, + 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, + 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, + 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, + 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, + 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, + 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, + 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, + 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a +}; + +static const unsigned short greekKeysymsToUnicode[] = { + 0x0000, 0x0386, 0x0388, 0x0389, 0x038a, 0x03aa, 0x0000, 0x038c, + 0x038e, 0x03ab, 0x0000, 0x038f, 0x0000, 0x0000, 0x0385, 0x2015, + 0x0000, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03ca, 0x0390, 0x03cc, + 0x03cd, 0x03cb, 0x03b0, 0x03ce, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, + 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, + 0x03a0, 0x03a1, 0x03a3, 0x0000, 0x03a4, 0x03a5, 0x03a6, 0x03a7, + 0x03a8, 0x03a9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, + 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, + 0x03c0, 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x03c5, 0x03c6, 0x03c7, + 0x03c8, 0x03c9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 +}; + +static const unsigned short technicalKeysymsToUnicode[] = { + 0x0000, 0x23B7, 0x250C, 0x2500, 0x2320, 0x2321, 0x2502, 0x23A1, + 0x23A3, 0x23A4, 0x23A6, 0x239B, 0x239D, 0x239E, 0x23A0, 0x23A8, + 0x23AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x2264, 0x2260, 0x2265, 0x222B, + 0x2234, 0x221D, 0x221E, 0x0000, 0x0000, 0x2207, 0x0000, 0x0000, + 0x223C, 0x2243, 0x0000, 0x0000, 0x0000, 0x21D4, 0x21D2, 0x2261, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x221A, 0x0000, + 0x0000, 0x0000, 0x2282, 0x2283, 0x2229, 0x222A, 0x2227, 0x2228, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2202, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0192, 0x0000, + 0x0000, 0x0000, 0x0000, 0x2190, 0x2191, 0x2192, 0x2193, 0x0000 +}; + +static const unsigned short specialKeysymsToUnicode[] = { + 0x25C6, 0x2592, 0x2409, 0x240C, 0x240D, 0x240A, 0x0000, 0x0000, + 0x2424, 0x240B, 0x2518, 0x2510, 0x250C, 0x2514, 0x253C, 0x23BA, + 0x23BB, 0x2500, 0x23BC, 0x23BD, 0x251C, 0x2524, 0x2534, 0x252C, + 0x2502, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 +}; + +static const unsigned short publishingKeysymsToUnicode[] = { + 0x0000, 0x2003, 0x2002, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009, + 0x200a, 0x2014, 0x2013, 0x0000, 0x0000, 0x0000, 0x2026, 0x2025, + 0x2153, 0x2154, 0x2155, 0x2156, 0x2157, 0x2158, 0x2159, 0x215a, + 0x2105, 0x0000, 0x0000, 0x2012, 0x2329, 0x0000, 0x232a, 0x0000, + 0x0000, 0x0000, 0x0000, 0x215b, 0x215c, 0x215d, 0x215e, 0x0000, + 0x0000, 0x2122, 0x2613, 0x0000, 0x25c1, 0x25b7, 0x25cb, 0x25af, + 0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x0000, 0x2032, 0x2033, + 0x0000, 0x271d, 0x0000, 0x25ac, 0x25c0, 0x25b6, 0x25cf, 0x25ae, + 0x25e6, 0x25ab, 0x25ad, 0x25b3, 0x25bd, 0x2606, 0x2022, 0x25aa, + 0x25b2, 0x25bc, 0x261c, 0x261e, 0x2663, 0x2666, 0x2665, 0x0000, + 0x2720, 0x2020, 0x2021, 0x2713, 0x2717, 0x266f, 0x266d, 0x2642, + 0x2640, 0x260e, 0x2315, 0x2117, 0x2038, 0x201a, 0x201e, 0x0000 +}; + +static const unsigned short aplKeysymsToUnicode[] = { + 0x0000, 0x0000, 0x0000, 0x003c, 0x0000, 0x0000, 0x003e, 0x0000, + 0x2228, 0x2227, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00af, 0x0000, 0x22a5, 0x2229, 0x230a, 0x0000, 0x005f, 0x0000, + 0x0000, 0x0000, 0x2218, 0x0000, 0x2395, 0x0000, 0x22a4, 0x25cb, + 0x0000, 0x0000, 0x0000, 0x2308, 0x0000, 0x0000, 0x222a, 0x0000, + 0x2283, 0x0000, 0x2282, 0x0000, 0x22a2, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x22a3, 0x0000, 0x0000, 0x0000 +}; + +static const unsigned short koreanKeysymsToUnicode[] = { + 0x0000, 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, 0x3137, + 0x3138, 0x3139, 0x313a, 0x313b, 0x313c, 0x313d, 0x313e, 0x313f, + 0x3140, 0x3141, 0x3142, 0x3143, 0x3144, 0x3145, 0x3146, 0x3147, + 0x3148, 0x3149, 0x314a, 0x314b, 0x314c, 0x314d, 0x314e, 0x314f, + 0x3150, 0x3151, 0x3152, 0x3153, 0x3154, 0x3155, 0x3156, 0x3157, + 0x3158, 0x3159, 0x315a, 0x315b, 0x315c, 0x315d, 0x315e, 0x315f, + 0x3160, 0x3161, 0x3162, 0x3163, 0x11a8, 0x11a9, 0x11aa, 0x11ab, + 0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, 0x11b3, + 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, 0x11bb, + 0x11bc, 0x11bd, 0x11be, 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x316d, + 0x3171, 0x3178, 0x317f, 0x3181, 0x3184, 0x3186, 0x318d, 0x318e, + 0x11eb, 0x11f0, 0x11f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x20a9 +}; + + +static TQChar keysymToUnicode(unsigned char byte3, unsigned char byte4) +{ + if ( byte3 == 0x04 ) { + // katakana + if ( byte4 > 0xa0 && byte4 < 0xe0 ) + return TQChar( katakanaKeysymsToUnicode[byte4 - 0xa0] ); + else if ( byte4 == 0x7e ) + return TQChar( 0x203e ); // Overline + } else if ( byte3 == 0x06 ) { + // russian, use lookup table + if ( byte4 > 0xa0 ) + return TQChar( cyrillicKeysymsToUnicode[byte4 - 0xa0] ); + } else if ( byte3 == 0x07 ) { + // greek + if ( byte4 > 0xa0 ) + return TQChar( greekKeysymsToUnicode[byte4 - 0xa0] ); + } else if ( byte3 == 0x08 ) { + // technical + if ( byte4 > 0xa0 ) + return TQChar( technicalKeysymsToUnicode[byte4 - 0xa0] ); + } else if ( byte3 == 0x09 ) { + // special + if ( byte4 >= 0xe0 ) + return TQChar( specialKeysymsToUnicode[byte4 - 0xe0] ); + } else if ( byte3 == 0x0a ) { + // publishing + if ( byte4 > 0xa0 ) + return TQChar( publishingKeysymsToUnicode[byte4 - 0xa0] ); + } else if ( byte3 == 0x0b ) { + // APL + if ( byte4 > 0xa0 ) + return TQChar( aplKeysymsToUnicode[byte4 - 0xa0] ); + } else if ( byte3 == 0x0e ) { + // Korean + if ( byte4 > 0xa0 ) + return TQChar( koreanKeysymsToUnicode[byte4 - 0xa0] ); + } + return TQChar(0x0); +} +#endif + + +bool TQETWidget::translateKeyEventInternal( const XEvent *event, int& count, + TQString& text, + int& state, + char& ascii, int& code, TQEvent::Type &type, bool willRepeat, bool statefulTranslation ) +{ + TQTextCodec *mapper = qt_input_mapper; + // some XmbLookupString implementations don't return buffer overflow correctly, + // so we increase the input buffer to allow for long strings... + // 256 chars * 2 bytes + 1 null-term == 513 bytes + TQCString chars(513); + TQChar converted; + KeySym key = 0; + + if ( !keyDict ) { + keyDict = new TQIntDict( 13 ); + keyDict->setAutoDelete( FALSE ); + textDict = new TQIntDict( 13 ); + textDict->setAutoDelete( FALSE ); + tqAddPostRoutine( deleteKeyDicts ); + } + + XKeyEvent xkeyevent = event->xkey; + + // save the modifier state, we will use the keystate uint later by passing + // it to qt_x11_translateButtonState + uint keystate = event->xkey.state; + // remove the modifiers where mode_switch exists... HPUX machines seem + // to have alt *AND* mode_switch both in Mod1Mask, which causes + // XLookupString to return things like '�' (aring) for ALT-A. This + // completely breaks modifiers. If we remove the modifier for Mode_switch, + // then things work correctly... + xkeyevent.state &= ~qt_mode_switch_remove_mask; + + type = (event->type == XKeyPress) + ? TQEvent::KeyPress : TQEvent::KeyRelease; +#if defined(TQT_NO_XIM) + + count = XLookupString( &xkeyevent, chars.data(), chars.size(), &key, 0 ); + + if ( count == 1 ) + ascii = chars[0]; + +#else + // Implementation for X11R5 and newer, using XIM + + int keycode = event->xkey.keycode; + + if ( type == TQEvent::KeyPress ) { + bool mb=FALSE; + // commit string handling is done by + // TQXIMInputContext::x11FilterEvent() and are passed to + // widgets via TQIMEvent regardless of XIM style, so the + // following code is commented out. +#if 0 + if ( qt_xim ) { + TQTLWExtra* xd = tlw->topData(); + TQInputContext *qic = (TQInputContext *) xd->xic; + if ( qic ) { + mb=TRUE; + count = qic->lookupString(&xkeyevent, chars, &key, &status); + } + } +#endif + if ( !mb ) { + count = XLookupString( &xkeyevent, + chars.data(), chars.size(), &key, 0 ); + } + if ( count && !keycode ) { + keycode = qt_ximComposingKeycode; + qt_ximComposingKeycode = 0; + } + if ( key ) + keyDict->replace( keycode, (void*)key ); + // all keysyms smaller than that are actally keys that can be mapped + // to unicode chars + if ( count == 0 && key < 0xff00 ) { + unsigned char byte3 = (unsigned char )(key >> 8); + int mib = -1; + switch( byte3 ) { + case 0: // Latin 1 + case 1: // Latin 2 + case 2: //latin 3 + case 3: // latin4 + mib = byte3 + 4; break; + case 5: // arabic + mib = 82; break; + case 12: // Hebrew + mib = 85; break; + case 13: // Thai + mib = 2259; break; + case 4: // kana + case 6: // cyrillic + case 7: // greek + case 8: // technical, no mapping here at the moment + case 9: // Special + case 10: // Publishing + case 11: // APL + case 14: // Korean, no mapping + mib = -1; // manual conversion + mapper = 0; + converted = keysymToUnicode( byte3, key & 0xff ); + case 0x20: + // currency symbols + if ( key >= 0x20a0 && key <= 0x20ac ) { + mib = -1; // manual conversion + mapper = 0; + converted = (uint)key; + } + break; + default: + break; + } + if ( mib != -1 ) { + mapper = TQTextCodec::codecForMib( mib ); + chars[0] = (unsigned char) (key & 0xff); // get only the fourth bit for conversion later + count++; + } + } else if ( key >= 0x1000000 && key <= 0x100ffff ) { + converted = (ushort) (key - 0x1000000); + mapper = 0; + } + if ( count < (int)chars.size()-1 ) + chars[count] = '\0'; + if ( count == 1 ) { + ascii = chars[0]; + // +256 so we can store all eight-bit codes, including ascii 0, + // and independent of whether char is signed or not. + textDict->replace( keycode, (void*)(long)(256+ascii) ); + } + } else { + key = (int)(long)keyDict->find( keycode ); + if ( key ) + if( !willRepeat && statefulTranslation ) // Take out key of dictionary only if this call. + keyDict->take( keycode ); + long s = (long)textDict->find( keycode ); + if ( s ) { + if( statefulTranslation ) + textDict->take( keycode ); + ascii = (char)(s-256); + } + } +#endif // !TQT_NO_XIM + + state = qt_x11_translateButtonState( keystate ); + + static int directionKeyEvent = 0; + static unsigned int lastWinId = 0; + if ( qt_use_rtl_extensions && type == TQEvent::KeyRelease && statefulTranslation ) { + if (directionKeyEvent == Key_Direction_R || directionKeyEvent == Key_Direction_L ) { + type = TQEvent::KeyPress; + code = directionKeyEvent; + chars[0] = 0; + directionKeyEvent = 0; + lastWinId = 0; + return TRUE; + } else { + directionKeyEvent = 0; + lastWinId = 0; + } + } + + // Watch for keypresses and if its a key belonging to the Ctrl-Shift + // direction-changing accel, remember it. + // We keep track of those keys instead of using the event's state + // (to figure out whether the Ctrl modifier is held while Shift is pressed, + // or Shift is held while Ctrl is pressed) since the 'state' doesn't tell + // us whether the modifier held is Left or Right. + if ( qt_use_rtl_extensions && type == TQEvent::KeyPress && statefulTranslation ) { + if (key == XK_Control_L || key == XK_Control_R || key == XK_Shift_L || key == XK_Shift_R) { + if (!directionKeyEvent) { + directionKeyEvent = key; + // This code exists in order to check that + // the event is occurred in the same widget. + lastWinId = winId(); + } + } else { + // this can no longer be a direction-changing accel. + // if any other key was pressed. + directionKeyEvent = Key_Space; + } + } + + // Commentary in X11/keysymdef says that X codes match ASCII, so it + // is safe to use the locale functions to process X codes in ISO8859-1. + // + // This is mainly for compatibility - applications should not use the + // TQt keycodes between 128 and 255, but should rather use the + // TQKeyEvent::text(). + // + if ( key < 128 || (key < 256 && (!qt_input_mapper || qt_input_mapper->mibEnum()==4)) ) { + code = isprint((int)key) ? toupper((int)key) : 0; // upper-case key, if known + } else if ( key >= XK_F1 && key <= XK_F35 ) { + code = Key_F1 + ((int)key - XK_F1); // function keys + } else if ( key >= XK_KP_0 && key <= XK_KP_9) { + code = Key_0 + ((int)key - XK_KP_0); // numeric keypad keys + state |= Keypad; + } else { + int i = 0; // any other keys + while ( KeyTbl[i] ) { + if ( key == KeyTbl[i] ) { + code = (int)KeyTbl[i+1]; + break; + } + i += 2; + } + switch ( key ) { + case XK_KP_Insert: + case XK_KP_Delete: + case XK_KP_Home: + case XK_KP_End: + case XK_KP_Left: + case XK_KP_Up: + case XK_KP_Right: + case XK_KP_Down: + case XK_KP_Prior: + case XK_KP_Next: + case XK_KP_Space: + case XK_KP_Tab: + case XK_KP_Enter: + case XK_KP_Equal: + case XK_KP_Multiply: + case XK_KP_Add: + case XK_KP_Separator: + case XK_KP_Subtract: + case XK_KP_Decimal: + case XK_KP_Divide: + state |= Keypad; + break; + default: + break; + } + + if ( code == Key_Tab && + (state & ShiftButton) == ShiftButton ) { + // map shift+tab to shift+backtab, TQAccel knows about it + // and will handle it. + code = Key_Backtab; + chars[0] = 0; + } + + if ( qt_use_rtl_extensions && type == TQEvent::KeyPress && statefulTranslation ) { + if ( directionKeyEvent && lastWinId == winId() ) { + if ( ( key == XK_Shift_L && directionKeyEvent == XK_Control_L ) || + ( key == XK_Control_L && directionKeyEvent == XK_Shift_L ) ) { + directionKeyEvent = Key_Direction_L; + } else if ( ( key == XK_Shift_R && directionKeyEvent == XK_Control_R ) || + ( key == XK_Control_R && directionKeyEvent == XK_Shift_R ) ) { + directionKeyEvent = Key_Direction_R; + } + } + else if ( directionKeyEvent == Key_Direction_L || directionKeyEvent == Key_Direction_R ) { + directionKeyEvent = Key_Space; // invalid + } + } + } + +#if 0 +#ifndef Q_EE + static int c = 0; + extern void qt_dialog_default_key(); +#define Q_EE(x) c = (c == x || (!c && x == 0x1000) )? x+1 : 0 + if ( tlw && state == '0' ) { + switch ( code ) { + case 0x4f: Q_EE(Key_Backtab); break; + case 0x52: Q_EE(Key_Tab); break; + case 0x54: Q_EE(Key_Escape); break; + case 0x4c: + if (c == Key_Return ) + qt_dialog_default_key(); + else + Q_EE(Key_Backspace); + break; + } + } +#undef Q_EE +#endif +#endif + + // convert chars (8bit) to text (unicode). + if ( mapper ) + text = mapper->toUnicode(chars,count); + else if ( !mapper && converted.unicode() != 0x0 ) + text = converted; + else + text = chars; + return TRUE; +} + + +struct qt_auto_repeat_data +{ + // match the window and keycode with timestamp delta of 10ms + Window window; + KeyCode keycode; + Time timestamp; + + // queue scanner state + bool release; + bool error; +}; + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +static Bool qt_keypress_scanner(Display *, XEvent *event, XPointer arg) +{ + if (event->type != XKeyPress && event->type != XKeyRelease) + return FALSE; + + qt_auto_repeat_data *d = (qt_auto_repeat_data *) arg; + if (d->error || + event->xkey.window != d->window || + event->xkey.keycode != d->keycode) { + d->error = TRUE; + return FALSE; + } + + if (event->type == XKeyPress) { + d->error = (! d->release || event->xkey.time - d->timestamp > 10); + return (! d->error); + } + + // must be XKeyRelease event + if (d->release) { + // found a second release + d->error = TRUE; + return FALSE; + } + + // found a single release + d->release = TRUE; + d->timestamp = event->xkey.time; + + return FALSE; +} + +static Bool qt_keyrelease_scanner(Display *, XEvent *event, XPointer arg) +{ + const qt_auto_repeat_data *d = (const qt_auto_repeat_data *) arg; + return (event->type == XKeyRelease && + event->xkey.window == d->window && + event->xkey.keycode == d->keycode); +} + +#if defined(Q_C_CALLBACKS) +} +#endif + +bool TQETWidget::translateKeyEvent( const XEvent *event, bool grab ) +{ + int code = -1; + int count = 0; + int state; + char ascii = 0; + + if ( sm_blockUserInput ) // block user interaction during session management + return TRUE; + + Display *dpy = x11Display(); + + if ( !isEnabled() ) + return TRUE; + + TQEvent::Type type; + bool autor = FALSE; + TQString text; + + translateKeyEventInternal( event, count, text, state, ascii, code, type, + qt_mode_switch_remove_mask != 0 ); + + static uint curr_autorep = 0; + // was this the last auto-repeater? + qt_auto_repeat_data auto_repeat_data; + auto_repeat_data.window = event->xkey.window; + auto_repeat_data.keycode = event->xkey.keycode; + auto_repeat_data.timestamp = event->xkey.time; + + if ( event->type == XKeyPress ) { + if ( curr_autorep == event->xkey.keycode ) { + autor = TRUE; + curr_autorep = 0; + } + } else { + // look ahead for auto-repeat + XEvent nextpress; + + auto_repeat_data.release = TRUE; + auto_repeat_data.error = FALSE; + if (XCheckIfEvent(dpy, &nextpress, &qt_keypress_scanner, + (XPointer) &auto_repeat_data)) { + autor = TRUE; + + // Put it back... we COULD send the event now and not need + // the static curr_autorep variable. + XPutBackEvent(dpy,&nextpress); + } + curr_autorep = autor ? event->xkey.keycode : 0; + } + + // process accelerators before doing key compression + if ( type == TQEvent::KeyPress && !grab ) { + // send accel events if the keyboard is not grabbed + TQKeyEvent a( type, code, ascii, state, text, autor, + TQMAX( TQMAX(count,1), int(text.length())) ); + if ( tqt_tryAccelEvent( this, &a ) ) + return TRUE; + } + + long save = 0; + if ( qt_mode_switch_remove_mask != 0 ) { + save = qt_mode_switch_remove_mask; + qt_mode_switch_remove_mask = 0; + + // translate the key event again, but this time apply any Mode_switch + // modifiers + translateKeyEventInternal( event, count, text, state, ascii, code, type ); + } + +#ifndef TQT_NO_IM + TQInputContext *qic = getInputContext(); +#endif + + // compress keys + if ( !text.isEmpty() && testWState(WState_CompressKeys) && +#ifndef TQT_NO_IM + // Ordinary input methods require discrete key events to work + // properly, so key compression has to be disabled when input + // context exists. + // + // And further consideration, some complex input method + // require all key press/release events discretely even if + // the input method awares of key compression and compressed + // keys are ordinary alphabets. For example, the uim project + // is planning to implement "combinational shift" feature for + // a Japanese input method, uim-skk. It will work as follows. + // + // 1. press "r" + // 2. press "u" + // 3. release both "r" and "u" in arbitrary order + // 4. above key sequence generates "Ru" + // + // Of course further consideration about other participants + // such as key repeat mechanism is required to implement such + // feature. + ! qic && +#endif // TQT_NO_IM + // do not compress keys if the key event we just got above matches + // one of the key ranges used to compute stopCompression + ! ( ( code >= Key_Escape && code <= Key_SysReq ) || + ( code >= Key_Home && code <= Key_Next ) || + ( code >= Key_Super_L && code <= Key_Direction_R ) || + ( ( code == 0 ) && ( ascii == '\n' ) ) ) ) { + // the widget wants key compression so it gets it + int codeIntern = -1; + int countIntern = 0; + int stateIntern; + char asciiIntern = 0; + XEvent evRelease; + XEvent evPress; + + // sync the event queue, this makes key compress work better + XSync( dpy, FALSE ); + + for (;;) { + TQString textIntern; + if ( !XCheckTypedWindowEvent(dpy,event->xkey.window, + XKeyRelease,&evRelease) ) + break; + if ( !XCheckTypedWindowEvent(dpy,event->xkey.window, + XKeyPress,&evPress) ) { + XPutBackEvent(dpy, &evRelease); + break; + } + TQEvent::Type t; + translateKeyEventInternal( &evPress, countIntern, textIntern, + stateIntern, asciiIntern, codeIntern, t ); + // use stopCompression to stop key compression for the following + // key event ranges: + bool stopCompression = + // 1) misc keys + ( codeIntern >= Key_Escape && codeIntern <= Key_SysReq ) || + // 2) cursor movement + ( codeIntern >= Key_Home && codeIntern <= Key_Next ) || + // 3) extra keys + ( codeIntern >= Key_Super_L && codeIntern <= Key_Direction_R ) || + // 4) something that a) doesn't translate to text or b) translates + // to newline text + ((codeIntern == 0) && (asciiIntern == '\n')); + if (stateIntern == state && !textIntern.isEmpty() && !stopCompression) { + text += textIntern; + count += countIntern; + } else { + XPutBackEvent(dpy, &evPress); + XPutBackEvent(dpy, &evRelease); + break; + } + } + } + + if ( save != 0 ) + qt_mode_switch_remove_mask = save; + + // autorepeat compression makes sense for all widgets (Windows + // does it automatically .... ) + if ( event->type == XKeyPress && text.length() <= 1 +#ifndef TQT_NO_IM + // input methods need discrete key events + && ! qic +#endif// TQT_NO_IM + ) { + XEvent dummy; + + for (;;) { + auto_repeat_data.release = FALSE; + auto_repeat_data.error = FALSE; + if (! XCheckIfEvent(dpy, &dummy, &qt_keypress_scanner, + (XPointer) &auto_repeat_data)) + break; + if (! XCheckIfEvent(dpy, &dummy, &qt_keyrelease_scanner, + (XPointer) &auto_repeat_data)) + break; + + count++; + if (!text.isEmpty()) + text += text[0]; + } + } + + if (code == 0 && ascii == '\n') { + code = Key_Return; + ascii = '\r'; + text = "\r"; + } + + // try the menukey first + if ( type == TQEvent::KeyPress && code == TQt::Key_Menu ) { + TQContextMenuEvent e( TQContextMenuEvent::Keyboard, TQPoint( 5, 5 ), mapToGlobal( TQPoint( 5, 5 ) ), 0 ); + TQApplication::sendSpontaneousEvent( this, &e ); + if( e.isAccepted() ) + return TRUE; + } + + TQKeyEvent e( type, code, ascii, state, text, autor, + TQMAX(TQMAX(count,1), int(text.length())) ); + return TQApplication::sendSpontaneousEvent( this, &e ); +} + + +// +// Paint event translation +// +// When receiving many expose events, we compress them (union of all expose +// rectangles) into one event which is sent to the widget. + +struct PaintEventInfo { + Window window; +}; + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +static Bool isPaintOrScrollDoneEvent( Display *, XEvent *ev, XPointer a ) +{ + PaintEventInfo *info = (PaintEventInfo *)a; + if ( ev->type == Expose || ev->type == GraphicsExpose + || ( ev->type == ClientMessage + && ev->xclient.message_type == qt_qt_scrolldone ) ) + { + if ( ev->xexpose.window == info->window ) + return True; + } + return False; +} + +#if defined(Q_C_CALLBACKS) +} +#endif + + +// declared above: static TQPtrList *sip_list = 0; + +void qt_insert_sip( TQWidget* scrolled_widget, int dx, int dy ) +{ + if ( !sip_list ) { + sip_list = new TQPtrList; + sip_list->setAutoDelete( TRUE ); + } + + TQScrollInProgress* sip = new TQScrollInProgress( scrolled_widget, dx, dy ); + sip_list->append( sip ); + + XClientMessageEvent client_message = {}; + client_message.type = ClientMessage; + client_message.window = scrolled_widget->winId(); + client_message.format = 32; + client_message.message_type = qt_qt_scrolldone; + client_message.data.l[0] = sip->id; + + XSendEvent( appDpy, scrolled_widget->winId(), False, NoEventMask, + (XEvent*)&client_message ); +} + +int qt_sip_count( TQWidget* scrolled_widget ) +{ + if ( !sip_list ) + return 0; + + int sips=0; + + for (TQScrollInProgress* sip = sip_list->first(); + sip; sip=sip_list->next()) + { + if ( sip->scrolled_widget == scrolled_widget ) + sips++; + } + + return sips; +} + +static +bool translateBySips( TQWidget* that, TQRect& paintRect ) +{ + if ( sip_list ) { + int dx=0, dy=0; + int sips=0; + for (TQScrollInProgress* sip = sip_list->first(); + sip; sip=sip_list->next()) + { + if ( sip->scrolled_widget == that ) { + if ( sips ) { + dx += sip->dx; + dy += sip->dy; + } + sips++; + } + } + if ( sips > 1 ) { + paintRect.moveBy( dx, dy ); + return TRUE; + } + } + return FALSE; +} + +bool TQETWidget::translatePaintEvent( const XEvent *event ) +{ + setWState( WState_Exposed ); + TQRect paintRect( event->xexpose.x, event->xexpose.y, + event->xexpose.width, event->xexpose.height ); + bool merging_okay = !testWFlags(WPaintClever); + XEvent xevent; + PaintEventInfo info; + info.window = winId(); + bool should_clip = translateBySips( this, paintRect ); + + TQRegion paintRegion( paintRect ); + + if ( merging_okay ) { + // WARNING: this is O(number_of_events * number_of_matching_events) + while ( XCheckIfEvent(x11Display(),&xevent,isPaintOrScrollDoneEvent, + (XPointer)&info) && + !qt_x11EventFilter(&xevent) && + !x11Event( &xevent ) ) // send event through filter + { + if ( xevent.type == Expose || xevent.type == GraphicsExpose ) { + TQRect exposure(xevent.xexpose.x, + xevent.xexpose.y, + xevent.xexpose.width, + xevent.xexpose.height); + if ( translateBySips( this, exposure ) ) + should_clip = TRUE; + paintRegion = paintRegion.unite( exposure ); + } else { + translateScrollDoneEvent( &xevent ); + } + } + } + + if ( should_clip ) { + paintRegion = paintRegion.intersect( rect() ); + if ( paintRegion.isEmpty() ) + return TRUE; + } + + TQPaintEvent e( paintRegion ); + setWState( WState_InPaintEvent ); + if ( !isTopLevel() && backgroundOrigin() != WidgetOrigin ) + erase( paintRegion ); + qt_set_paintevent_clipping( this, paintRegion ); + TQApplication::sendSpontaneousEvent( this, &e ); + qt_clear_paintevent_clipping(); + clearWState( WState_InPaintEvent ); + return TRUE; +} + +// +// Scroll-done event translation. +// + +bool TQETWidget::translateScrollDoneEvent( const XEvent *event ) +{ + if ( !sip_list ) return FALSE; + + long id = event->xclient.data.l[0]; + + // Remove any scroll-in-progress record for the given id. + for (TQScrollInProgress* sip = sip_list->first(); sip; sip=sip_list->next()) { + if ( sip->id == id ) { + sip_list->remove( sip_list->current() ); + return TRUE; + } + } + + return FALSE; +} + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif +#ifndef TQT_NO_XSYNC +static Bool qt_net_wm_sync_request_scanner(Display*, XEvent* event, XPointer arg) +{ + return (event->type == ClientMessage && event->xclient.window == *(Window*)arg + && event->xclient.message_type == tqt_wm_protocols + && ((unsigned int)event->xclient.data.l[ 0 ]) == qt_net_wm_sync_request ); +} +#endif + +#if defined(Q_C_CALLBACKS) +} +#endif + +// +// ConfigureNotify (window move and resize) event translation + +bool TQETWidget::translateConfigEvent( const XEvent *event ) +{ + // config pending is only set on resize, see tqwidget_x11.cpp, internalSetGeometry() + bool was_resize = testWState( WState_ConfigPending ); + + clearWState(WState_ConfigPending); + + if ( isTopLevel() ) { + TQPoint newCPos( geometry().topLeft() ); + TQSize newSize( event->xconfigure.width, event->xconfigure.height ); + + bool trust = (topData()->parentWinId == None || + topData()->parentWinId == TQPaintDevice::x11AppRootWindow()); + + if (event->xconfigure.send_event || trust ) { + // if a ConfigureNotify comes from a real sendevent request, we can + // trust its values. + newCPos.rx() = event->xconfigure.x + event->xconfigure.border_width; + newCPos.ry() = event->xconfigure.y + event->xconfigure.border_width; + } + + if ( isVisible() ) + TQApplication::syncX(); + + if (! extra || extra->compress_events) { + // ConfigureNotify compression for faster opaque resizing + XEvent otherEvent; + int compressed_configs = 0; + while ( XCheckTypedWindowEvent( x11Display(), winId(), ConfigureNotify, + &otherEvent ) ) { + if ( qt_x11EventFilter( &otherEvent ) ) + continue; + + if (x11Event( &otherEvent ) ) + continue; + + if ( otherEvent.xconfigure.event != otherEvent.xconfigure.window ) + continue; + + newSize.setWidth( otherEvent.xconfigure.width ); + newSize.setHeight( otherEvent.xconfigure.height ); + + if ( otherEvent.xconfigure.send_event || trust ) { + newCPos.rx() = otherEvent.xconfigure.x + + otherEvent.xconfigure.border_width; + newCPos.ry() = otherEvent.xconfigure.y + + otherEvent.xconfigure.border_width; + } + ++compressed_configs; + } +#ifndef TQT_NO_XSYNC + // _NET_WM_SYNC_REQUEST compression + Window wid = winId(); + while ( compressed_configs && + XCheckIfEvent( x11Display(), &otherEvent, + qt_net_wm_sync_request_scanner, (XPointer)&wid ) ) { + handleSyncRequest( (void*)&otherEvent ); + --compressed_configs; + } +#endif + } + + TQRect cr ( geometry() ); + if ( newSize != cr.size() ) { // size changed + was_resize = TRUE; + TQSize oldSize = size(); + cr.setSize( newSize ); + crect = cr; + + if ( isVisible() ) { + TQResizeEvent e( newSize, oldSize ); + TQApplication::sendSpontaneousEvent( this, &e ); + } else { + TQResizeEvent * e = new TQResizeEvent( newSize, oldSize ); + TQApplication::postEvent( this, e ); + } + } + + if ( newCPos != cr.topLeft() ) { // compare with cpos (exluding frame) + TQPoint oldPos = geometry().topLeft(); + cr.moveTopLeft( newCPos ); + crect = cr; + if ( isVisible() ) { + TQMoveEvent e( newCPos, oldPos ); // pos (including frame), not cpos + TQApplication::sendSpontaneousEvent( this, &e ); + } else { + TQMoveEvent * e = new TQMoveEvent( newCPos, oldPos ); + TQApplication::postEvent( this, e ); + } + } + } else { + XEvent xevent; + while ( XCheckTypedWindowEvent(x11Display(),winId(), ConfigureNotify,&xevent) && + !qt_x11EventFilter(&xevent) && + !x11Event( &xevent ) ) // send event through filter + ; + } + + bool transbg = backgroundOrigin() != WidgetOrigin; + // we ignore NorthWestGravity at the moment for reversed layout + if ( transbg || + (!testWFlags( WStaticContents ) && + testWState( WState_Exposed ) && was_resize ) || + TQApplication::reverseLayout() ) { + // remove unnecessary paint events from the queue + XEvent xevent; + while ( XCheckTypedWindowEvent( x11Display(), winId(), Expose, &xevent ) && + ! qt_x11EventFilter( &xevent ) && + ! x11Event( &xevent ) ) // send event through filter + ; + repaint( !testWFlags(WResizeNoErase) || transbg ); + } + + incrementSyncCounter(); + + return TRUE; +} + + +// +// Close window event translation. +// +bool TQETWidget::translateCloseEvent( const XEvent * ) +{ + return close(FALSE); +} + + +/*! + Sets the text cursor's flash (blink) time to \a msecs + milliseconds. The flash time is the time required to display, + invert and restore the caret display. Usually the text cursor is + displayed for \a msecs/2 milliseconds, then hidden for \a msecs/2 + milliseconds, but this may vary. + + Note that on Microsoft Windows, calling this function sets the + cursor flash time for all windows. + + \sa cursorFlashTime() +*/ +void TQApplication::setCursorFlashTime( int msecs ) +{ + cursor_flash_time = msecs; +} + + +/*! + Returns the text cursor's flash (blink) time in milliseconds. The + flash time is the time required to display, invert and restore the + caret display. + + The default value on X11 is 1000 milliseconds. On Windows, the + control panel value is used. + + Widgets should not cache this value since it may be changed at any + time by the user changing the global desktop settings. + + \sa setCursorFlashTime() +*/ +int TQApplication::cursorFlashTime() +{ + return cursor_flash_time; +} + +/*! + Sets the time limit that distinguishes a double click from two + consecutive mouse clicks to \a ms milliseconds. + + Note that on Microsoft Windows, calling this function sets the + double click interval for all windows. + + \sa doubleClickInterval() +*/ + +void TQApplication::setDoubleClickInterval( int ms ) +{ + mouse_double_click_time = ms; +} + + +/*! + Returns the maximum duration for a double click. + + The default value on X11 is 400 milliseconds. On Windows, the + control panel value is used. + + \sa setDoubleClickInterval() +*/ + +int TQApplication::doubleClickInterval() +{ + return mouse_double_click_time; +} + + +/*! + Sets the number of lines to scroll when the mouse wheel is rotated + to \a n. + + If this number exceeds the number of visible lines in a certain + widget, the widget should interpret the scroll operation as a + single page up / page down operation instead. + + \sa wheelScrollLines() +*/ +void TQApplication::setWheelScrollLines( int n ) +{ + wheel_scroll_lines = n; +} + +/*! + Returns the number of lines to scroll when the mouse wheel is + rotated. + + \sa setWheelScrollLines() +*/ +int TQApplication::wheelScrollLines() +{ + return wheel_scroll_lines; +} + +/*! + Enables the UI effect \a effect if \a enable is TRUE, otherwise + the effect will not be used. + + Note: All effects are disabled on screens running at less than + 16-bit color depth. + + \sa isEffectEnabled(), TQt::UIEffect, setDesktopSettingsAware() +*/ +void TQApplication::setEffectEnabled( TQt::UIEffect effect, bool enable ) +{ + switch (effect) { + case UI_AnimateMenu: + if ( enable ) fade_menu = FALSE; + animate_menu = enable; + break; + case UI_FadeMenu: + if ( enable ) + animate_menu = TRUE; + fade_menu = enable; + break; + case UI_AnimateCombo: + animate_combo = enable; + break; + case UI_AnimateTooltip: + if ( enable ) fade_tooltip = FALSE; + animate_tooltip = enable; + break; + case UI_FadeTooltip: + if ( enable ) + animate_tooltip = TRUE; + fade_tooltip = enable; + break; + case UI_AnimateToolBox: + animate_toolbox = enable; + break; + default: + animate_ui = enable; + break; + } +} + +/*! + Returns TRUE if \a effect is enabled; otherwise returns FALSE. + + By default, TQt will try to use the desktop settings. Call + setDesktopSettingsAware(FALSE) to prevent this. + + Note: All effects are disabled on screens running at less than + 16-bit color depth. + + \sa setEffectEnabled(), TQt::UIEffect +*/ +bool TQApplication::isEffectEnabled( TQt::UIEffect effect ) +{ + if ( TQColor::numBitPlanes() < 16 || !animate_ui ) + return FALSE; + + switch( effect ) { + case UI_AnimateMenu: + return animate_menu; + case UI_FadeMenu: + return fade_menu; + case UI_AnimateCombo: + return animate_combo; + case UI_AnimateTooltip: + return animate_tooltip; + case UI_FadeTooltip: + return fade_tooltip; + case UI_AnimateToolBox: + return animate_toolbox; + default: + return animate_ui; + } +} + +/***************************************************************************** + Session management support + *****************************************************************************/ + +#ifndef TQT_NO_SM_SUPPORT + +#include + +class TQSessionManagerData +{ +public: + TQSessionManagerData( TQSessionManager* mgr, TQString& id, TQString& key ) + : sm( mgr ), sessionId( id ), sessionKey( key ) {} + TQSessionManager* sm; + TQStringList restartCommand; + TQStringList discardCommand; + TQString& sessionId; + TQString& sessionKey; + TQSessionManager::RestartHint restartHint; +}; + +class TQSmSocketReceiver : public TQObject +{ + TQ_OBJECT +public: + TQSmSocketReceiver( int socket ) + : TQObject(0,0) + { + TQSocketNotifier* sn = new TQSocketNotifier( socket, TQSocketNotifier::Read, this ); + connect( sn, TQ_SIGNAL( activated(int) ), this, TQ_SLOT( socketActivated(int) ) ); + } + +public slots: + void socketActivated(int); +}; + + +static SmcConn smcConnection = 0; +static bool sm_interactionActive; +static bool sm_smActive; +static int sm_interactStyle; +static int sm_saveType; +static bool sm_cancel; +// static bool sm_waitingForPhase2; ### never used?!? +static bool sm_waitingForInteraction; +static bool sm_isshutdown; +// static bool sm_shouldbefast; ### never used?!? +static bool sm_phase2; +static bool sm_in_phase2; + +static TQSmSocketReceiver* sm_receiver = 0; + +static void resetSmState(); +static void sm_setProperty( const char* name, const char* type, + int num_vals, SmPropValue* vals); +static void sm_saveYourselfCallback( SmcConn smcConn, SmPointer clientData, + int saveType, Bool shutdown , int interactStyle, Bool fast); +static void sm_saveYourselfPhase2Callback( SmcConn smcConn, SmPointer clientData ) ; +static void sm_dieCallback( SmcConn smcConn, SmPointer clientData ) ; +static void sm_shutdownCancelledCallback( SmcConn smcConn, SmPointer clientData ); +static void sm_saveCompleteCallback( SmcConn smcConn, SmPointer clientData ); +static void sm_interactCallback( SmcConn smcConn, SmPointer clientData ); +static void sm_performSaveYourself( TQSessionManagerData* ); + +static void resetSmState() +{ +// sm_waitingForPhase2 = FALSE; ### never used?!? + sm_waitingForInteraction = FALSE; + sm_interactionActive = FALSE; + sm_interactStyle = SmInteractStyleNone; + sm_smActive = FALSE; + sm_blockUserInput = FALSE; + sm_isshutdown = FALSE; +// sm_shouldbefast = FALSE; ### never used?!? + sm_phase2 = FALSE; + sm_in_phase2 = FALSE; +} + + +// theoretically it's possible to set several properties at once. For +// simplicity, however, we do just one property at a time +static void sm_setProperty( const char* name, const char* type, + int num_vals, SmPropValue* vals) +{ + if (num_vals ) { + SmProp prop; + prop.name = (char*)name; + prop.type = (char*)type; + prop.num_vals = num_vals; + prop.vals = vals; + + SmProp* props[1]; + props[0] = ∝ + SmcSetProperties( smcConnection, 1, props ); + } + else { + char* names[1]; + names[0] = (char*) name; + SmcDeleteProperties( smcConnection, 1, names ); + } +} + +static void sm_setProperty( const TQString& name, const TQString& value) +{ + SmPropValue prop; + prop.length = value.length(); + prop.value = (SmPointer) value.latin1(); + sm_setProperty( name.latin1(), SmARRAY8, 1, &prop ); +} + +static void sm_setProperty( const TQString& name, const TQStringList& value) +{ + SmPropValue *prop = new SmPropValue[ value.count() ]; + int count = 0; + for ( TQStringList::ConstIterator it = value.begin(); it != value.end(); ++it ) { + prop[ count ].length = (*it).length(); + prop[ count ].value = (char*)(*it).latin1(); + ++count; + } + sm_setProperty( name.latin1(), SmLISTofARRAY8, count, prop ); + delete [] prop; +} + + +// workaround for broken libsm, see below +struct QT_smcConn { + unsigned int save_yourself_in_progress : 1; + unsigned int shutdown_in_progress : 1; +}; + +static void sm_saveYourselfCallback( SmcConn smcConn, SmPointer clientData, + int saveType, Bool shutdown , int interactStyle, Bool /*fast*/) +{ + if (smcConn != smcConnection ) + return; + sm_cancel = FALSE; + sm_smActive = TRUE; + sm_isshutdown = shutdown; + sm_saveType = saveType; + sm_interactStyle = interactStyle; +// sm_shouldbefast = fast; ### never used?!? + + // ugly workaround for broken libSM. libSM should do that _before_ + // actually invoking the callback in sm_process.c + ( (QT_smcConn*)smcConn )->save_yourself_in_progress = TRUE; + if ( sm_isshutdown ) + ( (QT_smcConn*)smcConn )->shutdown_in_progress = TRUE; + + sm_performSaveYourself( (TQSessionManagerData*) clientData ); + if ( !sm_isshutdown ) // we cannot expect a confirmation message in that case + resetSmState(); +} + +static void sm_performSaveYourself( TQSessionManagerData* smd ) +{ + if ( sm_isshutdown ) + sm_blockUserInput = TRUE; + + TQSessionManager* sm = smd->sm; + + // generate a new session key + timeval tv; + gettimeofday( &tv, 0 ); + smd->sessionKey = TQString::number( tv.tv_sec ) + "_" + TQString::number(tv.tv_usec); + + // tell the session manager about our program in best POSIX style + sm_setProperty( SmProgram, TQString( tqApp->argv()[0] ) ); + // tell the session manager about our user as well. + struct passwd* entry = getpwuid( geteuid() ); + if ( entry ) + sm_setProperty( SmUserID, TQString::fromLatin1( entry->pw_name ) ); + + // generate a restart and discard command that makes sense + TQStringList restart; + restart << tqApp->argv()[0] << "-session" << smd->sessionId + "_" + smd->sessionKey; + if (tqstricmp(tqAppName(), tqAppClass()) != 0) + restart << "-name" << tqAppName(); + sm->setRestartCommand( restart ); + TQStringList discard; + sm->setDiscardCommand( discard ); + + switch ( sm_saveType ) { + case SmSaveBoth: + tqApp->commitData( *sm ); + if ( sm_isshutdown && sm_cancel) + break; // we cancelled the shutdown, no need to save state + // fall through + case SmSaveLocal: + tqApp->saveState( *sm ); + break; + case SmSaveGlobal: + tqApp->commitData( *sm ); + break; + default: + break; + } + + if ( sm_phase2 && !sm_in_phase2 ) { + SmcRequestSaveYourselfPhase2( smcConnection, sm_saveYourselfPhase2Callback, (SmPointer*) smd ); + sm_blockUserInput = FALSE; + } + else { + // close eventual interaction monitors and cancel the + // shutdown, if required. Note that we can only cancel when + // performing a shutdown, it does not work for checkpoints + if ( sm_interactionActive ) { + SmcInteractDone( smcConnection, sm_isshutdown && sm_cancel); + sm_interactionActive = FALSE; + } + else if ( sm_cancel && sm_isshutdown ) { + if ( sm->allowsErrorInteraction() ) { + SmcInteractDone( smcConnection, True ); + sm_interactionActive = FALSE; + } + } + + // set restart and discard command in session manager + sm_setProperty( SmRestartCommand, sm->restartCommand() ); + sm_setProperty( SmDiscardCommand, sm->discardCommand() ); + + // set the restart hint + SmPropValue prop; + prop.length = sizeof( int ); + int value = sm->restartHint(); + prop.value = (SmPointer) &value; + sm_setProperty( SmRestartStyleHint, SmCARD8, 1, &prop ); + + // we are done + SmcSaveYourselfDone( smcConnection, !sm_cancel ); + } +} + +static void sm_dieCallback( SmcConn smcConn, SmPointer /* clientData */) +{ + if (smcConn != smcConnection ) + return; + resetSmState(); + TQEvent quitEvent(TQEvent::Quit); + TQApplication::sendEvent(tqApp, &quitEvent); +} + +static void sm_shutdownCancelledCallback( SmcConn smcConn, SmPointer /* clientData */) +{ + if (smcConn != smcConnection ) + return; + if ( sm_waitingForInteraction ) + tqApp->exit_loop(); + resetSmState(); +} + +static void sm_saveCompleteCallback( SmcConn smcConn, SmPointer /*clientData */) +{ + if (smcConn != smcConnection ) + return; + resetSmState(); +} + +static void sm_interactCallback( SmcConn smcConn, SmPointer /* clientData */ ) +{ + if (smcConn != smcConnection ) + return; + if ( sm_waitingForInteraction ) + tqApp->exit_loop(); +} + +static void sm_saveYourselfPhase2Callback( SmcConn smcConn, SmPointer clientData ) +{ + if (smcConn != smcConnection ) + return; + sm_in_phase2 = TRUE; + sm_performSaveYourself( (TQSessionManagerData*) clientData ); +} + + +void TQSmSocketReceiver::socketActivated(int) +{ + IceProcessMessages( SmcGetIceConnection( smcConnection ), 0, 0); +} + + +#undef Bool +#include "tqapplication_x11.moc" + +TQSessionManager::TQSessionManager( TQApplication * app, TQString &id, TQString& key ) + : TQObject( app, "session manager" ) +{ + d = new TQSessionManagerData( this, id, key ); + d->restartHint = RestartIfRunning; + + resetSmState(); + char cerror[256]; + char* myId = 0; + char* prevId = (char*)id.latin1(); // we know what we are doing + + SmcCallbacks cb; + cb.save_yourself.callback = sm_saveYourselfCallback; + cb.save_yourself.client_data = (SmPointer) d; + cb.die.callback = sm_dieCallback; + cb.die.client_data = (SmPointer) d; + cb.save_complete.callback = sm_saveCompleteCallback; + cb.save_complete.client_data = (SmPointer) d; + cb.shutdown_cancelled.callback = sm_shutdownCancelledCallback; + cb.shutdown_cancelled.client_data = (SmPointer) d; + + // avoid showing a warning message below + const char* session_manager = getenv("SESSION_MANAGER"); + if ( !session_manager || !session_manager[0] ) + return; + + smcConnection = SmcOpenConnection( 0, 0, 1, 0, + SmcSaveYourselfProcMask | + SmcDieProcMask | + SmcSaveCompleteProcMask | + SmcShutdownCancelledProcMask, + &cb, + prevId, + &myId, + 256, cerror ); + + id = TQString::fromLatin1( myId ); + ::free( myId ); // it was allocated by C + + TQString error = cerror; + if (!smcConnection ) { + tqWarning("Session management error: %s", error.latin1() ); + } + else { + sm_receiver = new TQSmSocketReceiver( IceConnectionNumber( SmcGetIceConnection( smcConnection ) ) ); + } +} + +TQSessionManager::~TQSessionManager() +{ + if ( smcConnection ) + SmcCloseConnection( smcConnection, 0, 0 ); + smcConnection = 0; + delete sm_receiver; + delete d; +} + +TQString TQSessionManager::sessionId() const +{ + return d->sessionId; +} + +TQString TQSessionManager::sessionKey() const +{ + return d->sessionKey; +} + + +void* TQSessionManager::handle() const +{ + return (void*) smcConnection; +} + + +bool TQSessionManager::allowsInteraction() +{ + if ( sm_interactionActive ) + return TRUE; + + if ( sm_waitingForInteraction ) + return FALSE; + + if ( sm_interactStyle == SmInteractStyleAny ) { + sm_waitingForInteraction = SmcInteractRequest( smcConnection, SmDialogNormal, + sm_interactCallback, (SmPointer*) this ); + } + if ( sm_waitingForInteraction ) { + tqApp->enter_loop(); + sm_waitingForInteraction = FALSE; + if ( sm_smActive ) { // not cancelled + sm_interactionActive = TRUE; + sm_blockUserInput = FALSE; + return TRUE; + } + } + return FALSE; +} + +bool TQSessionManager::allowsErrorInteraction() +{ + if ( sm_interactionActive ) + return TRUE; + + if ( sm_waitingForInteraction ) + return FALSE; + + if ( sm_interactStyle == SmInteractStyleAny || sm_interactStyle == SmInteractStyleErrors ) { + sm_waitingForInteraction = SmcInteractRequest( smcConnection, SmDialogError, + sm_interactCallback, (SmPointer*) this ); + } + if ( sm_waitingForInteraction ) { + tqApp->enter_loop(); + sm_waitingForInteraction = FALSE; + if ( sm_smActive ) { // not cancelled + sm_interactionActive = TRUE; + sm_blockUserInput = FALSE; + return TRUE; + } + } + return FALSE; +} + +void TQSessionManager::release() +{ + if ( sm_interactionActive ) { + SmcInteractDone( smcConnection, False ); + sm_interactionActive = FALSE; + if ( sm_smActive && sm_isshutdown ) + sm_blockUserInput = TRUE; + } +} + +void TQSessionManager::cancel() +{ + sm_cancel = TRUE; +} + +void TQSessionManager::setRestartHint( TQSessionManager::RestartHint hint) +{ + d->restartHint = hint; +} + +TQSessionManager::RestartHint TQSessionManager::restartHint() const +{ + return d->restartHint; +} + +void TQSessionManager::setRestartCommand( const TQStringList& command) +{ + d->restartCommand = command; +} + +TQStringList TQSessionManager::restartCommand() const +{ + return d->restartCommand; +} + +void TQSessionManager::setDiscardCommand( const TQStringList& command) +{ + d->discardCommand = command; +} + +TQStringList TQSessionManager::discardCommand() const +{ + return d->discardCommand; +} + +void TQSessionManager::setManagerProperty( const TQString& name, const TQString& value) +{ + SmPropValue prop; + prop.length = value.length(); + prop.value = (SmPointer) value.utf8().data(); + sm_setProperty( name.latin1(), SmARRAY8, 1, &prop ); +} + +void TQSessionManager::setManagerProperty( const TQString& name, const TQStringList& value) +{ + SmPropValue *prop = new SmPropValue[ value.count() ]; + int count = 0; + for ( TQStringList::ConstIterator it = value.begin(); it != value.end(); ++it ) { + prop[ count ].length = (*it).length(); + prop[ count ].value = (char*)(*it).utf8().data(); + ++count; + } + sm_setProperty( name.latin1(), SmLISTofARRAY8, count, prop ); + delete [] prop; +} + +bool TQSessionManager::isPhase2() const +{ + return sm_in_phase2; +} + +void TQSessionManager::requestPhase2() +{ + sm_phase2 = TRUE; +} + + +#endif // TQT_NO_SM_SUPPORT diff --git a/src/kernel/tqclipboard.cpp b/src/kernel/tqclipboard.cpp index f7c2836f5..ee476a1a5 100644 --- a/src/kernel/tqclipboard.cpp +++ b/src/kernel/tqclipboard.cpp @@ -42,8 +42,8 @@ #ifndef TQT_NO_CLIPBOARD -#include "ntqapplication.h" -#include "qapplication_p.h" +#include "tqapplication.h" +#include "tqapplication_p.h" #include "tqdragobject.h" #include "tqpixmap.h" diff --git a/src/kernel/tqclipboard_x11.cpp b/src/kernel/tqclipboard_x11.cpp index 16af49f8e..16772b491 100644 --- a/src/kernel/tqclipboard_x11.cpp +++ b/src/kernel/tqclipboard_x11.cpp @@ -64,7 +64,7 @@ #ifndef TQT_NO_CLIPBOARD -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqeventloop.h" #include "tqbitmap.h" #include "tqdatetime.h" @@ -74,7 +74,7 @@ #include "tqvaluelist.h" #include "tqmap.h" #include "tqt_x11_p.h" -#include "qapplication_p.h" +#include "tqapplication_p.h" // REVISED: arnt @@ -83,12 +83,12 @@ Internal TQClipboard functions for X11. *****************************************************************************/ -// from qapplication_x11.cpp +// from tqapplication_x11.cpp typedef int (*QX11EventFilter) (XEvent*); extern QX11EventFilter tqt_set_x11_event_filter (QX11EventFilter filter); -extern Time tqt_x_time; // def. in qapplication_x11.cpp -extern Time qt_x_incr; // def. in qapplication_x11.cpp +extern Time tqt_x_time; // def. in tqapplication_x11.cpp +extern Time qt_x_incr; // def. in tqapplication_x11.cpp extern Atom qt_xa_clipboard; extern Atom qt_selection_property; extern Atom tqt_clipboard_sentinel; @@ -1575,7 +1575,7 @@ void TQClipboard::setData( TQMimeSource* src, Mode mode ) /* - Called by the main event loop in qapplication_x11.cpp when the + Called by the main event loop in tqapplication_x11.cpp when the _QT_SELECTION_SENTINEL property has been changed (i.e. when some TQt process has performed TQClipboard::setData(). If it returns TRUE, the TQClipBoard dataChanged() signal should be emitted. diff --git a/src/kernel/tqcolor_x11.cpp b/src/kernel/tqcolor_x11.cpp index fe5f6685c..77f48037a 100644 --- a/src/kernel/tqcolor_x11.cpp +++ b/src/kernel/tqcolor_x11.cpp @@ -42,8 +42,8 @@ #include "tqcolor_p.h" #include "string.h" #include "tqpaintdevice.h" -#include "ntqapplication.h" -#include "qapplication_p.h" +#include "tqapplication.h" +#include "tqapplication_p.h" #include "tqt_x11_p.h" // NOT REVISED diff --git a/src/kernel/tqcursor_x11.cpp b/src/kernel/tqcursor_x11.cpp index 3724706c2..6a66e3cda 100644 --- a/src/kernel/tqcursor_x11.cpp +++ b/src/kernel/tqcursor_x11.cpp @@ -41,7 +41,7 @@ #include "tqcursor.h" #include "tqbitmap.h" #include "tqimage.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqdatastream.h" #include "tqnamespace.h" #include "tqt_x11_p.h" diff --git a/src/kernel/tqdesktopwidget_x11.cpp b/src/kernel/tqdesktopwidget_x11.cpp index 2a9e5bd9e..35d021c51 100644 --- a/src/kernel/tqdesktopwidget_x11.cpp +++ b/src/kernel/tqdesktopwidget_x11.cpp @@ -37,7 +37,7 @@ **********************************************************************/ #include "tqdesktopwidget.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqobjectlist.h" #include "tqt_x11_p.h" #include @@ -45,7 +45,7 @@ // defined in tqwidget_x11.cpp extern int qt_x11_create_desktop_on_screen; -// defined in qapplication_x11.cpp +// defined in tqapplication_x11.cpp extern Atom qt_net_workarea; extern bool qt_net_supports(Atom atom); diff --git a/src/kernel/tqdragobject.cpp b/src/kernel/tqdragobject.cpp index b6fac2bd0..04b9f43a1 100644 --- a/src/kernel/tqdragobject.cpp +++ b/src/kernel/tqdragobject.cpp @@ -47,7 +47,7 @@ #include "tqdragobject.h" #include "tqtextcodec.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqpoint.h" #include "tqwidget.h" #include "tqbuffer.h" diff --git a/src/kernel/tqdrawutil.cpp b/src/kernel/tqdrawutil.cpp index 0c3283ddc..79aa69378 100644 --- a/src/kernel/tqdrawutil.cpp +++ b/src/kernel/tqdrawutil.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_DRAWUTIL #include "tqbitmap.h" #include "tqpixmapcache.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqpainter.h" /*! diff --git a/src/kernel/tqevent.cpp b/src/kernel/tqevent.cpp index e8d042b06..fc59d9164 100644 --- a/src/kernel/tqevent.cpp +++ b/src/kernel/tqevent.cpp @@ -40,7 +40,7 @@ #include "tqevent.h" #include "tqcursor.h" -#include "ntqapplication.h" +#include "tqapplication.h" /*! diff --git a/src/kernel/tqeventloop.cpp b/src/kernel/tqeventloop.cpp index 3a7d72833..0cc3036d6 100644 --- a/src/kernel/tqeventloop.cpp +++ b/src/kernel/tqeventloop.cpp @@ -38,7 +38,7 @@ #include "tqeventloop_p.h" // includes qplatformdefs.h #include "tqeventloop.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqdatetime.h" #ifdef TQT_THREAD_SUPPORT diff --git a/src/kernel/tqeventloop_unix.cpp b/src/kernel/tqeventloop_unix.cpp index 8ab816426..fc0a0b48b 100644 --- a/src/kernel/tqeventloop_unix.cpp +++ b/src/kernel/tqeventloop_unix.cpp @@ -38,7 +38,7 @@ #include "tqeventloop_p.h" // includes qplatformdefs.h #include "tqeventloop.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqbitarray.h" #include "tqmutex.h" #include diff --git a/src/kernel/tqeventloop_unix_glib.cpp b/src/kernel/tqeventloop_unix_glib.cpp index 200c9245d..eec66d0af 100644 --- a/src/kernel/tqeventloop_unix_glib.cpp +++ b/src/kernel/tqeventloop_unix_glib.cpp @@ -38,7 +38,7 @@ #include "tqeventloop_glib_p.h" // includes qplatformdefs.h #include "tqeventloop.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqbitarray.h" #include "tqmutex.h" diff --git a/src/kernel/tqeventloop_x11.cpp b/src/kernel/tqeventloop_x11.cpp index 743d48e70..13ba8c6af 100644 --- a/src/kernel/tqeventloop_x11.cpp +++ b/src/kernel/tqeventloop_x11.cpp @@ -38,7 +38,7 @@ #include "tqeventloop_p.h" // includes qplatformdefs.h #include "tqeventloop.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqbitarray.h" #include "tqcolor_p.h" #include "tqt_x11_p.h" @@ -59,7 +59,7 @@ static const int XKeyRelease = KeyRelease; #undef KeyPress #undef KeyRelease -// from qapplication.cpp +// from tqapplication.cpp extern bool tqt_is_gui_used; // from tqeventloop_unix.cpp @@ -170,7 +170,7 @@ bool TQEventLoop::processEvents( ProcessEventsFlags flags ) case ClientMessage: { - // from qapplication_x11.cpp + // from tqapplication_x11.cpp extern Atom tqt_wm_protocols; extern Atom tqt_wm_take_focus; extern Atom qt_qt_scrolldone; @@ -405,7 +405,7 @@ bool TQEventLoop::processEvents( ProcessEventsFlags flags ) bool TQEventLoop::hasPendingEvents() const { - extern uint qGlobalPostedEventsCount(); // from qapplication.cpp + extern uint qGlobalPostedEventsCount(); // from tqapplication.cpp return ( qGlobalPostedEventsCount() || XPending( TQPaintDevice::x11AppDisplay() ) ); } diff --git a/src/kernel/tqeventloop_x11_glib.cpp b/src/kernel/tqeventloop_x11_glib.cpp index 28069fe1b..cf2126591 100644 --- a/src/kernel/tqeventloop_x11_glib.cpp +++ b/src/kernel/tqeventloop_x11_glib.cpp @@ -41,7 +41,7 @@ #include "tqeventloop_glib_p.h" // includes qplatformdefs.h #include "tqeventloop.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqbitarray.h" #include "tqcolor_p.h" #include "tqt_x11_p.h" @@ -140,7 +140,7 @@ static const int XKeyRelease = KeyRelease; #undef KeyPress #undef KeyRelease -// from qapplication.cpp +// from tqapplication.cpp extern bool tqt_is_gui_used; // from tqeventloop_unix.cpp @@ -339,7 +339,7 @@ bool TQEventLoop::processX11Events() case ClientMessage: { - // from qapplication_x11.cpp + // from tqapplication_x11.cpp extern Atom tqt_wm_protocols; extern Atom tqt_wm_take_focus; extern Atom qt_qt_scrolldone; @@ -645,7 +645,7 @@ bool TQEventLoop::hasPendingEvents() const TQMutexLocker locker( TQApplication::tqt_mutex ); #endif // TQT_THREAD_SUPPORT - extern uint qGlobalPostedEventsCount(); // from qapplication.cpp + extern uint qGlobalPostedEventsCount(); // from tqapplication.cpp return ( qGlobalPostedEventsCount() || ( (tqt_is_gui_used && TQApplication::isGuiThread()) ? XPending( TQPaintDevice::x11AppDisplay() ) : 0)); } diff --git a/src/kernel/tqfont.cpp b/src/kernel/tqfont.cpp index e058e49d4..c8395d342 100644 --- a/src/kernel/tqfont.cpp +++ b/src/kernel/tqfont.cpp @@ -48,7 +48,7 @@ #include "tqdict.h" #include "tqcache.h" #include "tqdatastream.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqcleanuphandler.h" #include "tqstringlist.h" #ifdef TQ_WS_MAC diff --git a/src/kernel/tqfont_x11.cpp b/src/kernel/tqfont_x11.cpp index 373a82a5f..77742a5f0 100644 --- a/src/kernel/tqfont_x11.cpp +++ b/src/kernel/tqfont_x11.cpp @@ -45,7 +45,7 @@ #include "qplatformdefs.h" #include "tqfont.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqcleanuphandler.h" #include "tqfontinfo.h" #include "tqfontdatabase.h" diff --git a/src/kernel/tqfontdatabase.cpp b/src/kernel/tqfontdatabase.cpp index 0702bb67f..5413f2db4 100644 --- a/src/kernel/tqfontdatabase.cpp +++ b/src/kernel/tqfontdatabase.cpp @@ -43,7 +43,7 @@ #ifndef TQT_NO_FONTDATABASE #include -#include +#include #include #include "tqfontengine_p.h" @@ -1330,7 +1330,7 @@ TQString TQFontDatabase::styleString( const TQFont &f ) Example: \code -#include +#include #include #include diff --git a/src/kernel/tqiconset.cpp b/src/kernel/tqiconset.cpp index 2a251c2ff..22e8a8f1d 100644 --- a/src/kernel/tqiconset.cpp +++ b/src/kernel/tqiconset.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_ICONSET -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqbitmap.h" #include "tqcleanuphandler.h" #include "tqimage.h" diff --git a/src/kernel/tqimage.cpp b/src/kernel/tqimage.cpp index 50ed52222..177c0a6af 100644 --- a/src/kernel/tqimage.cpp +++ b/src/kernel/tqimage.cpp @@ -53,7 +53,7 @@ #include #include "tqimageformatinterface_p.h" #include "tqwmatrix.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqmime.h" #include "tqdragobject.h" #include diff --git a/src/kernel/tqinputcontext.cpp b/src/kernel/tqinputcontext.cpp index 7d15aa0c7..7f0d5501d 100644 --- a/src/kernel/tqinputcontext.cpp +++ b/src/kernel/tqinputcontext.cpp @@ -41,7 +41,7 @@ #include "qplatformdefs.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqwidget.h" #include "tqpopupmenu.h" diff --git a/src/kernel/tqinputcontext_x11.cpp b/src/kernel/tqinputcontext_x11.cpp index 7377b264c..70fa9f160 100644 --- a/src/kernel/tqinputcontext_x11.cpp +++ b/src/kernel/tqinputcontext_x11.cpp @@ -42,7 +42,7 @@ #include "qplatformdefs.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqwidget.h" #include "tqt_x11_p.h" diff --git a/src/kernel/tqlayout.cpp b/src/kernel/tqlayout.cpp index bfab60480..814f1565b 100644 --- a/src/kernel/tqlayout.cpp +++ b/src/kernel/tqlayout.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_LAYOUT -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqwidget.h" #include "tqptrlist.h" #include "tqsizepolicy.h" diff --git a/src/kernel/tqlocalfs.cpp b/src/kernel/tqlocalfs.cpp index 5adc77fb2..69e2eba72 100644 --- a/src/kernel/tqlocalfs.cpp +++ b/src/kernel/tqlocalfs.cpp @@ -45,7 +45,7 @@ #include "tqfileinfo.h" #include "tqfile.h" #include "tqurlinfo.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqurloperator.h" #include "tqguardedptr.h" diff --git a/src/kernel/tqmime.cpp b/src/kernel/tqmime.cpp index d230d88d8..ba12e4c8e 100644 --- a/src/kernel/tqmime.cpp +++ b/src/kernel/tqmime.cpp @@ -46,7 +46,7 @@ #include "tqdir.h" #include "tqdragobject.h" #include "tqcleanuphandler.h" -#include "ntqapplication.h" // ### for now +#include "tqapplication.h" // ### for now #include "tqclipboard.h" // ### for now /*! diff --git a/src/kernel/tqmotifdnd_x11.cpp b/src/kernel/tqmotifdnd_x11.cpp index cf5867aeb..e1481446f 100644 --- a/src/kernel/tqmotifdnd_x11.cpp +++ b/src/kernel/tqmotifdnd_x11.cpp @@ -68,7 +68,7 @@ in doc/dnd.doc, where the documentation system can see it. */ #include "qplatformdefs.h" -#include "ntqapplication.h" +#include "tqapplication.h" #ifndef TQT_NO_DRAGANDDROP diff --git a/src/kernel/tqnamespace.h b/src/kernel/tqnamespace.h index f5ec7dd1d..4ff686c1c 100644 --- a/src/kernel/tqnamespace.h +++ b/src/kernel/tqnamespace.h @@ -814,7 +814,7 @@ public: CustomPattern=24 }; - // documented in qapplication_mac.cpp + // documented in tqapplication_mac.cpp enum MacintoshVersion { //Unknown MV_Unknown = 0x0000, @@ -835,7 +835,7 @@ public: MV_TIGER = MV_10_DOT_4 }; - // documented in qapplication_win.cpp + // documented in tqapplication_win.cpp enum WindowsVersion { WV_32s = 0x0001, WV_95 = 0x0002, @@ -1005,7 +1005,7 @@ public: }; // "handle" type for system objects. Documented as \internal in - // qapplication.cpp + // tqapplication.cpp #if defined(TQ_WS_MAC) typedef void * HANDLE; #elif defined(TQ_WS_WIN) diff --git a/src/kernel/tqobject.cpp b/src/kernel/tqobject.cpp index 85c69f8ba..e37cf1481 100644 --- a/src/kernel/tqobject.cpp +++ b/src/kernel/tqobject.cpp @@ -39,7 +39,7 @@ **********************************************************************/ #include "tqvariant.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqobject.h" #include "tqobjectlist.h" #include "tqsignalslotimp.h" @@ -454,7 +454,7 @@ static TQCString qt_rmWS( const char *s ) } -// Event functions, implemented in qapplication_xxx.cpp +// Event functions, implemented in tqapplication_xxx.cpp int qStartTimer( int interval, TQObject *obj ); bool qKillTimer( int id ); diff --git a/src/kernel/tqpaintdevice_x11.cpp b/src/kernel/tqpaintdevice_x11.cpp index 37bdfa83e..efeaf78fa 100644 --- a/src/kernel/tqpaintdevice_x11.cpp +++ b/src/kernel/tqpaintdevice_x11.cpp @@ -43,7 +43,7 @@ #include "tqpainter.h" #include "tqwidget.h" #include "tqbitmap.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqt_x11_p.h" diff --git a/src/kernel/tqpainter.cpp b/src/kernel/tqpainter.cpp index b66f16d2b..452af0a57 100644 --- a/src/kernel/tqpainter.cpp +++ b/src/kernel/tqpainter.cpp @@ -47,7 +47,7 @@ #include "tqwidget.h" #include "tqimage.h" #include "tqpaintdevicemetrics.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqrichtext_p.h" #include "tqregexp.h" #include "tqcleanuphandler.h" diff --git a/src/kernel/tqpixmap.cpp b/src/kernel/tqpixmap.cpp index 4a40d821b..c3eceba6b 100644 --- a/src/kernel/tqpixmap.cpp +++ b/src/kernel/tqpixmap.cpp @@ -47,7 +47,7 @@ #include "tqdatastream.h" #include "tqbuffer.h" #include "tqobjectlist.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include #include "tqmime.h" #include "tqdragobject.h" diff --git a/src/kernel/tqpixmap_x11.cpp b/src/kernel/tqpixmap_x11.cpp index 9f8c6b7d1..36c050005 100644 --- a/src/kernel/tqpixmap_x11.cpp +++ b/src/kernel/tqpixmap_x11.cpp @@ -71,7 +71,7 @@ #include "tqpaintdevicemetrics.h" #include "tqimage.h" #include "tqwmatrix.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqt_x11_p.h" #include @@ -371,7 +371,7 @@ static void build_scale_table( uint **table, uint nBits ) static int defaultScreen = -1; -extern bool tqt_use_xrender; // defined in qapplication_x11.cpp +extern bool tqt_use_xrender; // defined in tqapplication_x11.cpp extern bool tqt_has_xft; // defined in tqfont_x11.cpp #ifndef TQT_NO_XFTFREETYPE @@ -2421,7 +2421,7 @@ TQ_EXPORT void copyBlt( TQPixmap *dst, int dx, int dy, #ifndef TQT_NO_XFTFREETYPE // copy alpha data - extern bool tqt_use_xrender; // from qapplication_x11.cpp + extern bool tqt_use_xrender; // from tqapplication_x11.cpp if ( ! tqt_use_xrender || ! src->data->alphapm ) return; diff --git a/src/kernel/tqprinter_unix.cpp b/src/kernel/tqprinter_unix.cpp index 2899d86df..e53dc5ff6 100644 --- a/src/kernel/tqprinter_unix.cpp +++ b/src/kernel/tqprinter_unix.cpp @@ -54,7 +54,7 @@ static inline int qt_open(const char *pathname, int flags, mode_t mode) #include "tqpaintdevicemetrics.h" #include "tqpsprinter_p.h" #include "tqprintdialog.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqprinter_p.h" #include // For ::sleep() diff --git a/src/kernel/tqprocess.cpp b/src/kernel/tqprocess.cpp index bfca757a8..b43c12b4a 100644 --- a/src/kernel/tqprocess.cpp +++ b/src/kernel/tqprocess.cpp @@ -45,7 +45,7 @@ #ifndef TQT_NO_PROCESS -#include "ntqapplication.h" +#include "tqapplication.h" #include "private/tqinternal_p.h" diff --git a/src/kernel/tqprocess_unix.cpp b/src/kernel/tqprocess_unix.cpp index b9a79afda..606d1fd28 100644 --- a/src/kernel/tqprocess_unix.cpp +++ b/src/kernel/tqprocess_unix.cpp @@ -49,7 +49,7 @@ #ifndef TQT_NO_PROCESS -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqptrqueue.h" #include "tqptrlist.h" #include "tqsocketnotifier.h" diff --git a/src/kernel/tqpsprinter.cpp b/src/kernel/tqpsprinter.cpp index 80e00ae23..bc283807c 100644 --- a/src/kernel/tqpsprinter.cpp +++ b/src/kernel/tqpsprinter.cpp @@ -57,7 +57,7 @@ #undef Q_PRINTER_USE_TYPE42 #include "tqpainter.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqpaintdevicemetrics.h" #include "tqimage.h" #include "tqdatetime.h" diff --git a/src/kernel/tqrichtext.cpp b/src/kernel/tqrichtext.cpp index 9866a6c9c..57b091721 100644 --- a/src/kernel/tqrichtext.cpp +++ b/src/kernel/tqrichtext.cpp @@ -47,7 +47,7 @@ #include "tqfont.h" #include "tqtextstream.h" #include "tqfile.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqmap.h" #include "tqfileinfo.h" #include "tqstylesheet.h" diff --git a/src/kernel/tqrichtext_p.h b/src/kernel/tqrichtext_p.h index 1032c74eb..11dfcc6d1 100644 --- a/src/kernel/tqrichtext_p.h +++ b/src/kernel/tqrichtext_p.h @@ -74,7 +74,7 @@ #include "tqpainter.h" #include "tqlayout.h" #include "tqobject.h" -#include "ntqapplication.h" +#include "tqapplication.h" #endif // QT_H #ifndef TQT_NO_RICHTEXT diff --git a/src/kernel/tqsimplerichtext.cpp b/src/kernel/tqsimplerichtext.cpp index 4c98f1fd3..c2808b1cd 100644 --- a/src/kernel/tqsimplerichtext.cpp +++ b/src/kernel/tqsimplerichtext.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_RICHTEXT #include "tqrichtext_p.h" -#include "ntqapplication.h" +#include "tqapplication.h" class TQSimpleRichTextData { diff --git a/src/kernel/tqsizegrip.cpp b/src/kernel/tqsizegrip.cpp index 017c3e6a0..65b29a1c9 100644 --- a/src/kernel/tqsizegrip.cpp +++ b/src/kernel/tqsizegrip.cpp @@ -43,12 +43,12 @@ #ifndef TQT_NO_SIZEGRIP #include "tqpainter.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqstyle.h" #if defined(TQ_WS_X11) #include "tqt_x11_p.h" -extern Atom qt_sizegrip; // defined in qapplication_x11.cpp +extern Atom qt_sizegrip; // defined in tqapplication_x11.cpp #elif defined (TQ_WS_WIN ) #include "tqobjectlist.h" #include "qt_windows.h" diff --git a/src/kernel/tqsocketnotifier.cpp b/src/kernel/tqsocketnotifier.cpp index b350403a5..3a3d32a07 100644 --- a/src/kernel/tqsocketnotifier.cpp +++ b/src/kernel/tqsocketnotifier.cpp @@ -39,7 +39,7 @@ **********************************************************************/ #include "tqsocketnotifier.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqevent.h" #include "tqeventloop.h" #include "qplatformdefs.h" diff --git a/src/kernel/tqsound_x11.cpp b/src/kernel/tqsound_x11.cpp index bbdbf5b44..dba19b144 100644 --- a/src/kernel/tqsound_x11.cpp +++ b/src/kernel/tqsound_x11.cpp @@ -44,7 +44,7 @@ #include "tqptrdict.h" #include "tqsocketnotifier.h" -#include "ntqapplication.h" +#include "tqapplication.h" #ifdef QT_NAS_SUPPORT diff --git a/src/kernel/tqstyle.cpp b/src/kernel/tqstyle.cpp index dfa1c2cbe..27a4ce33c 100644 --- a/src/kernel/tqstyle.cpp +++ b/src/kernel/tqstyle.cpp @@ -40,7 +40,7 @@ #include "tqstyle.h" #ifndef TQT_NO_STYLE -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqpainter.h" #include "tqbitmap.h" #include "tqpixmapcache.h" diff --git a/src/kernel/tqt3.h b/src/kernel/tqt3.h index cff4b0895..9300c254e 100644 --- a/src/kernel/tqt3.h +++ b/src/kernel/tqt3.h @@ -258,7 +258,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/tqtextlayout.cpp b/src/kernel/tqtextlayout.cpp index 3e71ccd39..0d50e4106 100644 --- a/src/kernel/tqtextlayout.cpp +++ b/src/kernel/tqtextlayout.cpp @@ -40,7 +40,7 @@ #include "tqtextengine_p.h" #include -#include +#include #include diff --git a/src/kernel/tqthread.cpp b/src/kernel/tqthread.cpp index 560577589..9a1d1f602 100644 --- a/src/kernel/tqthread.cpp +++ b/src/kernel/tqthread.cpp @@ -45,7 +45,7 @@ #include #ifndef QT_H -# include "ntqapplication.h" +# include "tqapplication.h" #endif // QT_H diff --git a/src/kernel/tqthread_unix.cpp b/src/kernel/tqthread_unix.cpp index db780ee18..714b35c31 100644 --- a/src/kernel/tqthread_unix.cpp +++ b/src/kernel/tqthread_unix.cpp @@ -47,7 +47,7 @@ typedef pthread_mutex_t Q_MUTEX_T; #include #include #include -#include +#include #include #include diff --git a/src/kernel/tqtimer.cpp b/src/kernel/tqtimer.cpp index 3d19923e8..84803f1b5 100644 --- a/src/kernel/tqtimer.cpp +++ b/src/kernel/tqtimer.cpp @@ -302,7 +302,7 @@ bool TQSingleShotTimer::event( TQEvent * ) Example: \code - #include + #include #include int main( int argc, char **argv ) diff --git a/src/kernel/tqtranslator.cpp b/src/kernel/tqtranslator.cpp index fd86a73ca..b6a11feb3 100644 --- a/src/kernel/tqtranslator.cpp +++ b/src/kernel/tqtranslator.cpp @@ -60,7 +60,7 @@ static inline int qt_open(const char *pathname, int flags, mode_t mode) #include "tqwidgetlist.h" #include "tqintdict.h" #include "tqstring.h" -#include "ntqapplication.h" +#include "tqapplication.h" #include "tqfile.h" #include "tqbuffer.h" #include "tqdatastream.h" diff --git a/src/kernel/tqurl.cpp b/src/kernel/tqurl.cpp index 1155e9fa1..7d0066f0c 100644 --- a/src/kernel/tqurl.cpp +++ b/src/kernel/tqurl.cpp @@ -1010,7 +1010,7 @@ void TQUrl::setEncodedPathAndQuery( const TQString& pathAndQuery ) d->cleanPathDirty = TRUE; } -extern bool tqt_resolve_symlinks; // defined in qapplication.cpp +extern bool tqt_resolve_symlinks; // defined in tqapplication.cpp /*! Returns the path of the URL. If \a correct is TRUE, the path is diff --git a/src/kernel/tqwidget.cpp b/src/kernel/tqwidget.cpp index 33c4768a6..71fe8ea16 100644 --- a/src/kernel/tqwidget.cpp +++ b/src/kernel/tqwidget.cpp @@ -47,8 +47,8 @@ #include "tqfocusdata.h" #include "tqcursor.h" #include "tqpixmap.h" -#include "ntqapplication.h" -#include "qapplication_p.h" +#include "tqapplication.h" +#include "tqapplication_p.h" #include "tqbrush.h" #include "tqlayout.h" #include "tqstylefactory.h" diff --git a/src/kernel/tqwidget_p.h b/src/kernel/tqwidget_p.h index 0c0eb9460..6815665c2 100644 --- a/src/kernel/tqwidget_p.h +++ b/src/kernel/tqwidget_p.h @@ -47,7 +47,7 @@ // ------------- // // This file is not part of the TQt API. It exists for the convenience -// of qapplication_*.cpp, tqwidget*.cpp and tqfiledialog.cpp. This header +// of tqapplication_*.cpp, tqwidget*.cpp and tqfiledialog.cpp. This header // file may change from version to version without notice, or even be removed. // // We mean it. diff --git a/src/kernel/tqwidget_x11.cpp b/src/kernel/tqwidget_x11.cpp index 2f90c4905..c8492c6e6 100644 --- a/src/kernel/tqwidget_x11.cpp +++ b/src/kernel/tqwidget_x11.cpp @@ -38,8 +38,8 @@ ** **********************************************************************/ -#include "ntqapplication.h" -#include "qapplication_p.h" +#include "tqapplication.h" +#include "tqapplication_p.h" #include "tqnamespace.h" #include "tqpaintdevicemetrics.h" #include "tqpainter.h" @@ -55,11 +55,11 @@ // NOT REVISED -// defined in qapplication_x11.cpp +// defined in tqapplication_x11.cpp extern Window qt_x11_wm_client_leader; extern void qt_x11_create_wm_client_leader(); -// defined in qapplication_x11.cpp +// defined in tqapplication_x11.cpp void qt_insert_sip( TQWidget*, int, int ); int qt_sip_count( TQWidget* ); bool qt_wstate_iconified( WId ); @@ -77,7 +77,7 @@ extern void qt_clear_paintevent_clipping(); extern bool qt_dnd_enable( TQWidget* w, bool on ); extern bool qt_nograb(); -// defined in qapplication_x11.cpp +// defined in tqapplication_x11.cpp extern void qt_deferred_map_add( TQWidget* ); extern void qt_deferred_map_take( TQWidget* ); extern bool qt_deferred_map_contains(TQWidget *); @@ -85,7 +85,7 @@ extern bool qt_deferred_map_contains(TQWidget *); static TQWidget *mouseGrb = 0; static TQWidget *keyboardGrb = 0; -// defined in qapplication_x11.cpp +// defined in tqapplication_x11.cpp extern Time tqt_x_time; extern Time tqt_x_user_time; @@ -104,7 +104,7 @@ int qt_x11_create_desktop_on_screen = -1; TQWidget member functions *****************************************************************************/ -// defined in qapplication_x11.cpp +// defined in tqapplication_x11.cpp extern Atom tqt_wm_state; extern Atom qt_wm_change_state; extern Atom tqt_wm_delete_window; @@ -157,7 +157,7 @@ extern Atom qt_enlightenment_desktop; extern Atom qt_net_virtual_roots; extern bool qt_broken_wm; -// defined in qapplication_x11.cpp +// defined in tqapplication_x11.cpp extern bool qt_net_supports(Atom); extern unsigned long *qt_net_virtual_root_list; @@ -835,7 +835,7 @@ void TQWidget::destroy( bool destroyWindow, bool destroySubWindows ) #endif setWinId( 0 ); - extern void qPRCleanup( TQWidget *widget ); // from qapplication_x11.cpp + extern void qPRCleanup( TQWidget *widget ); // from tqapplication_x11.cpp if ( testWState(WState_Reparented) ) qPRCleanup(this); @@ -2228,7 +2228,7 @@ void TQWidget::internalSetGeometry( int x, int y, int w, int h, bool isMove ) } if ( isResize ) { - // set config pending only on resize, see qapplication_x11.cpp, translateConfigEvent() + // set config pending only on resize, see tqapplication_x11.cpp, translateConfigEvent() setWState( WState_ConfigPending ); TQResizeEvent e( size(), oldSize ); -- cgit v1.2.3