From 8ef4ea451dd81dd66b34ed31aaa631f6df24a192 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 24 Jul 2024 21:06:28 +0900 Subject: Rename environment class nt* related files to equivalent tq* Signed-off-by: Michele Calgaro --- src/kernel/ntqapplication.h | 4 +- src/kernel/ntqdesktopwidget.h | 100 -- src/kernel/ntqevent.h | 619 -------- src/kernel/ntqeventloop.h | 149 -- src/kernel/ntqinputcontext.h | 2 +- src/kernel/ntqnamespace.h | 6 +- src/kernel/ntqt.h | 8 +- src/kernel/ntqtranslator.h | 167 --- src/kernel/qapplication.cpp | 6 +- src/kernel/qapplication_x11.cpp | 2 +- src/kernel/qdesktopwidget_x11.cpp | 356 ----- src/kernel/qdnd_x11.cpp | 4 +- src/kernel/qevent.cpp | 2579 ---------------------------------- src/kernel/qeventloop.cpp | 423 ------ src/kernel/qeventloop_glib_p.h | 119 -- src/kernel/qeventloop_p.h | 156 -- src/kernel/qeventloop_unix.cpp | 594 -------- src/kernel/qeventloop_unix_glib.cpp | 750 ---------- src/kernel/qeventloop_x11.cpp | 425 ------ src/kernel/qeventloop_x11_glib.cpp | 684 --------- src/kernel/qt_kernel.pri | 38 +- src/kernel/qtranslator.cpp | 1478 ------------------- src/kernel/tqclipboard_x11.cpp | 2 +- src/kernel/tqdesktopwidget.h | 100 ++ src/kernel/tqdesktopwidget_x11.cpp | 356 +++++ src/kernel/tqevent.cpp | 2579 ++++++++++++++++++++++++++++++++++ src/kernel/tqevent.h | 619 ++++++++ src/kernel/tqeventloop.cpp | 423 ++++++ src/kernel/tqeventloop.h | 149 ++ src/kernel/tqeventloop_glib_p.h | 119 ++ src/kernel/tqeventloop_p.h | 156 ++ src/kernel/tqeventloop_unix.cpp | 594 ++++++++ src/kernel/tqeventloop_unix_glib.cpp | 750 ++++++++++ src/kernel/tqeventloop_x11.cpp | 425 ++++++ src/kernel/tqeventloop_x11_glib.cpp | 684 +++++++++ src/kernel/tqfontengine_x11.cpp | 41 +- src/kernel/tqobject.h | 2 +- src/kernel/tqsocketnotifier.cpp | 4 +- src/kernel/tqthread.cpp | 2 +- src/kernel/tqtranslator.cpp | 1478 +++++++++++++++++++ src/kernel/tqtranslator.h | 167 +++ src/kernel/tqwidget.cpp | 4 +- 42 files changed, 8673 insertions(+), 8650 deletions(-) delete mode 100644 src/kernel/ntqdesktopwidget.h delete mode 100644 src/kernel/ntqevent.h delete mode 100644 src/kernel/ntqeventloop.h delete mode 100644 src/kernel/ntqtranslator.h delete mode 100644 src/kernel/qdesktopwidget_x11.cpp delete mode 100644 src/kernel/qevent.cpp delete mode 100644 src/kernel/qeventloop.cpp delete mode 100644 src/kernel/qeventloop_glib_p.h delete mode 100644 src/kernel/qeventloop_p.h delete mode 100644 src/kernel/qeventloop_unix.cpp delete mode 100644 src/kernel/qeventloop_unix_glib.cpp delete mode 100644 src/kernel/qeventloop_x11.cpp delete mode 100644 src/kernel/qeventloop_x11_glib.cpp delete mode 100644 src/kernel/qtranslator.cpp create mode 100644 src/kernel/tqdesktopwidget.h create mode 100644 src/kernel/tqdesktopwidget_x11.cpp create mode 100644 src/kernel/tqevent.cpp create mode 100644 src/kernel/tqevent.h create mode 100644 src/kernel/tqeventloop.cpp create mode 100644 src/kernel/tqeventloop.h create mode 100644 src/kernel/tqeventloop_glib_p.h create mode 100644 src/kernel/tqeventloop_p.h create mode 100644 src/kernel/tqeventloop_unix.cpp create mode 100644 src/kernel/tqeventloop_unix_glib.cpp create mode 100644 src/kernel/tqeventloop_x11.cpp create mode 100644 src/kernel/tqeventloop_x11_glib.cpp create mode 100644 src/kernel/tqtranslator.cpp create mode 100644 src/kernel/tqtranslator.h (limited to 'src/kernel') diff --git a/src/kernel/ntqapplication.h b/src/kernel/ntqapplication.h index fc4448089..0e884583e 100644 --- a/src/kernel/ntqapplication.h +++ b/src/kernel/ntqapplication.h @@ -42,10 +42,10 @@ #define TQAPPLICATION_H #ifndef QT_H -#include "ntqdesktopwidget.h" +#include "tqdesktopwidget.h" #include "tqasciidict.h" #include "tqpalette.h" -#include "ntqtranslator.h" +#include "tqtranslator.h" #include "tqstrlist.h" #include "tqstringlist.h" #endif // QT_H diff --git a/src/kernel/ntqdesktopwidget.h b/src/kernel/ntqdesktopwidget.h deleted file mode 100644 index 201267708..000000000 --- a/src/kernel/ntqdesktopwidget.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Definition of TQDesktopWidget class. -** -** 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 TQDESKTOPWIDGET_H -#define TQDESKTOPWIDGET_H - -#ifndef QT_H -#include "tqwidget.h" -#endif // QT_H - -class TQApplication; -class TQDesktopWidgetPrivate; /* Don't touch! */ - -class TQ_EXPORT TQDesktopWidget : public TQWidget -{ - TQ_OBJECT -public: - TQDesktopWidget(); - ~TQDesktopWidget(); - - bool isVirtualDesktop() const; - - int numScreens() const; - int primaryScreen() const; - - int screenNumber( TQWidget *widget = 0 ) const; // ### 4.0: const TQWidget* - int screenNumber( const TQPoint & ) const; - - TQWidget *screen( int screen = -1 ); - - const TQRect& screenGeometry( int screen = -1 ) const; - const TQRect& screenGeometry( TQWidget *widget ) const - { return screenGeometry( screenNumber( widget ) ); } - const TQRect& screenGeometry( const TQPoint &point ) const - { return screenGeometry( screenNumber( point ) ); } - - const TQRect& availableGeometry( int screen = -1 ) const; - const TQRect& availableGeometry( TQWidget *widget ) const - { return availableGeometry( screenNumber( widget ) ); } - const TQRect& availableGeometry( const TQPoint &point ) const - { return availableGeometry( screenNumber( point ) ); } - - void insertChild( TQObject * ); - - inline void emitResizedSignal(int value) { emit resized(value); } - -signals: - void resized( int ); - void workAreaResized( int ); - -protected: - void resizeEvent( TQResizeEvent *e ); - -private: - TQDesktopWidgetPrivate *d; - -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQDesktopWidget( const TQDesktopWidget & ); - TQDesktopWidget &operator=( const TQDesktopWidget & ); -#endif - - friend class TQApplication; -}; - -#endif //TQDESKTOPWIDGET_H diff --git a/src/kernel/ntqevent.h b/src/kernel/ntqevent.h deleted file mode 100644 index f05fc2c94..000000000 --- a/src/kernel/ntqevent.h +++ /dev/null @@ -1,619 +0,0 @@ -/**************************************************************************** -** -** Definition of event classes -** -** 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. -** -**********************************************************************/ - -#ifndef TQEVENT_H -#define TQEVENT_H - -#ifndef QT_H -#include "ntqwindowdefs.h" -#include "tqregion.h" -#include "ntqnamespace.h" -#include "tqmime.h" -#include "tqpair.h" -#endif // QT_H - -class TQ_EXPORT TQEvent: public TQt // event base class -{ -public: - enum Type { - - /* - If you get a strange compiler error on the line with None, - it's probably because you're also including X11 headers, - which #define the symbol None. Put the X11 includes after - the TQt includes to solve this problem. - */ - - None = 0, // invalid event - - - Timer = 1, // timer event - MouseButtonPress = 2, // mouse button pressed - MouseButtonRelease = 3, // mouse button released - MouseButtonDblClick = 4, // mouse button double click - MouseMove = 5, // mouse move - KeyPress = 6, // key pressed - KeyRelease = 7, // key released - FocusIn = 8, // keyboard focus received - FocusOut = 9, // keyboard focus lost - Enter = 10, // mouse enters widget - Leave = 11, // mouse leaves widget - Paint = 12, // paint widget - Move = 13, // move widget - Resize = 14, // resize widget - Create = 15, // after object creation - Destroy = 16, // during object destruction - Show = 17, // widget is shown - Hide = 18, // widget is hidden - Close = 19, // request to close widget - Quit = 20, // request to quit application - Reparent = 21, // widget has been reparented - ShowMinimized = 22, // widget is shown minimized - ShowNormal = 23, // widget is shown normal - WindowActivate = 24, // window was activated - WindowDeactivate = 25, // window was deactivated - ShowToParent = 26, // widget is shown to parent - HideToParent = 27, // widget is hidden to parent - ShowMaximized = 28, // widget is shown maximized - ShowFullScreen = 29, // widget is shown full-screen - Accel = 30, // accelerator event - Wheel = 31, // wheel event - AccelAvailable = 32, // accelerator available event - CaptionChange = 33, // caption changed - IconChange = 34, // icon changed - ParentFontChange = 35, // parent font changed - ApplicationFontChange = 36, // application font changed - ParentPaletteChange = 37, // parent palette changed - ApplicationPaletteChange = 38, // application palette changed - PaletteChange = 39, // widget palette changed - Clipboard = 40, // internal clipboard event - Speech = 42, // reserved for speech input - SockAct = 50, // socket activation - AccelOverride = 51, // accelerator override event - DeferredDelete = 52, // deferred delete event - DragEnter = 60, // drag moves into widget - DragMove = 61, // drag moves in widget - DragLeave = 62, // drag leaves or is cancelled - Drop = 63, // actual drop - DragResponse = 64, // drag accepted/rejected - ChildInserted = 70, // new child widget - ChildRemoved = 71, // deleted child widget - LayoutHint = 72, // child min/max size changed - ShowWindowRequest = 73, // widget's window should be mapped - WindowBlocked = 74, // window is about to be blocked modally - WindowUnblocked = 75, // windows modal blocking has ended - ActivateControl = 80, // ActiveX activation - DeactivateControl = 81, // ActiveX deactivation - ContextMenu = 82, // context popup menu - IMStart = 83, // input method composition start - IMCompose = 84, // input method composition - IMEnd = 85, // input method composition end - Accessibility = 86, // accessibility information is requested - TabletMove = 87, // Wacom tablet event - LocaleChange = 88, // the system locale changed - LanguageChange = 89, // the application language changed - LayoutDirectionChange = 90, // the layout direction changed - Style = 91, // internal style event - TabletPress = 92, // tablet press - TabletRelease = 93, // tablet release - OkRequest = 94, // CE (Ok) button pressed - HelpRequest = 95, // CE (?) button pressed - WindowStateChange = 96, // window state has changed - IconDrag = 97, // proxy icon dragged - MetaCall = 98, // meta method call (internal) - ThreadChange = 99, // thread changed - User = 1000, // first user event id - MaxUser = 65535 // last user event id - }; - - - TQEvent( Type type ) : t(type), posted(FALSE), spont(FALSE) {} - virtual ~TQEvent(); - Type type() const { return t; } - bool spontaneous() const { return spont; } -protected: - Type t; -private: - uint posted : 1; - uint spont : 1; - - - friend class TQApplication; - friend class TQAccelManager; - friend class TQBaseApplication; - friend class TQETWidget; -}; - - -class TQ_EXPORT TQTimerEvent : public TQEvent -{ -public: - TQTimerEvent( int timerId ) - : TQEvent(Timer), id(timerId) {} - int timerId() const { return id; } -protected: - int id; -}; - - -class TQ_EXPORT TQMouseEvent : public TQEvent -{ -public: - TQMouseEvent( Type type, const TQPoint &pos, int button, int state ); - - TQMouseEvent( Type type, const TQPoint &pos, const TQPoint&globalPos, - int button, int state ) - : TQEvent(type), p(pos), g(globalPos), b((ushort)button),s((ushort)state),accpt(TRUE) {}; - - const TQPoint &pos() const { return p; } - const TQPoint &globalPos() const { return g; } - int x() const { return p.x(); } - int y() const { return p.y(); } - int globalX() const { return g.x(); } - int globalY() const { return g.y(); } - ButtonState button() const { return (ButtonState) b; } - ButtonState state() const { return (ButtonState) s; } - ButtonState stateAfter() const; - bool isAccepted() const { return accpt; } - void accept() { accpt = TRUE; } - void ignore() { accpt = FALSE; } -protected: - TQPoint p; - TQPoint g; - ushort b; - ushort s; - uint accpt:1; -}; - - -#ifndef TQT_NO_WHEELEVENT -class TQ_EXPORT TQWheelEvent : public TQEvent -{ -public: - TQWheelEvent( const TQPoint &pos, int delta, int state, Orientation orient = Vertical ); - TQWheelEvent( const TQPoint &pos, const TQPoint& globalPos, int delta, int state, Orientation orient = Vertical ) - : TQEvent(Wheel), p(pos), g(globalPos), d(delta), s((ushort)state), - accpt(TRUE), o(orient) {} - int delta() const { return d; } - const TQPoint &pos() const { return p; } - const TQPoint &globalPos() const { return g; } - int x() const { return p.x(); } - int y() const { return p.y(); } - int globalX() const { return g.x(); } - int globalY() const { return g.y(); } - ButtonState state() const { return ButtonState(s); } - Orientation orientation() const { return o; } - bool isAccepted() const { return accpt; } - void accept() { accpt = TRUE; } - void ignore() { accpt = FALSE; } -protected: - TQPoint p; - TQPoint g; - int d; - ushort s; - bool accpt; - Orientation o; -}; -#endif - -class TQ_EXPORT TQTabletEvent : public TQEvent -{ -public: - enum TabletDevice { NoDevice = -1, Puck, Stylus, Eraser }; - TQTabletEvent( Type t, const TQPoint &pos, const TQPoint &globalPos, int device, - int pressure, int xTilt, int yTilt, const TQPair &uId ); - TQTabletEvent( const TQPoint &pos, const TQPoint &globalPos, int device, - int pressure, int xTilt, int yTilt, const TQPair &uId ) - : TQEvent( TabletMove ), mPos( pos ), mGPos( globalPos ), mDev( device ), - mPress( pressure ), mXT( xTilt ), mYT( yTilt ), mType( uId.first ), - mPhy( uId.second ), mbAcc(TRUE) - {} - int pressure() const { return mPress; } - int xTilt() const { return mXT; } - int yTilt() const { return mYT; } - const TQPoint &pos() const { return mPos; } - const TQPoint &globalPos() const { return mGPos; } - int x() const { return mPos.x(); } - int y() const { return mPos.y(); } - int globalX() const { return mGPos.x(); } - int globalY() const { return mGPos.y(); } - TabletDevice device() const { return TabletDevice(mDev); } - int isAccepted() const { return mbAcc; } - void accept() { mbAcc = TRUE; } - void ignore() { mbAcc = FALSE; } - TQPair uniqueId() { return TQPair( mType, mPhy); } -protected: - TQPoint mPos; - TQPoint mGPos; - int mDev, - mPress, - mXT, - mYT, - mType, - mPhy; - bool mbAcc; - -}; - -class TQ_EXPORT TQKeyEvent : public TQEvent -{ -public: - TQKeyEvent( Type type, int key, int ascii, int state, - const TQString& text=TQString::null, bool autorep=FALSE, ushort count=1 ) - : TQEvent(type), txt(text), k((ushort)key), s((ushort)state), - a((uchar)ascii), accpt(TRUE), autor(autorep), c(count) - { - if ( key >= Key_Back && key <= Key_MediaLast ) - accpt = FALSE; - } - int key() const { return k; } - int ascii() const { return a; } - ButtonState state() const { return ButtonState(s); } - ButtonState stateAfter() const; - bool isAccepted() const { return accpt; } - TQString text() const { return txt; } - bool isAutoRepeat() const { return autor; } - int count() const { return int(c); } - void accept() { accpt = TRUE; } - void ignore() { accpt = FALSE; } - -protected: - TQString txt; - ushort k, s; - uchar a; - uint accpt:1; - uint autor:1; - ushort c; -}; - - -class TQ_EXPORT TQFocusEvent : public TQEvent -{ -public: - - TQFocusEvent( Type type ) - : TQEvent(type) {} - - bool gotFocus() const { return type() == FocusIn; } - bool lostFocus() const { return type() == FocusOut; } - - enum Reason { Mouse, Tab, Backtab, ActiveWindow, Popup, Shortcut, Other }; - static Reason reason(); - static void setReason( Reason reason ); - static void resetReason(); - -private: - static Reason m_reason; - static Reason prev_reason; -}; - - -class TQ_EXPORT TQPaintEvent : public TQEvent -{ -public: - TQPaintEvent( const TQRegion& paintRegion, bool erased = TRUE) - : TQEvent(Paint), - rec(paintRegion.boundingRect()), - reg(paintRegion), - erase(erased){} - TQPaintEvent( const TQRect &paintRect, bool erased = TRUE ) - : TQEvent(Paint), - rec(paintRect), - reg(paintRect), - erase(erased){} - TQPaintEvent( const TQRegion &paintRegion, const TQRect &paintRect, bool erased = TRUE ) - : TQEvent(Paint), - rec(paintRect), - reg(paintRegion), - erase(erased){} - - const TQRect &rect() const { return rec; } - const TQRegion ®ion() const { return reg; } - bool erased() const { return erase; } -protected: - friend class TQApplication; - friend class TQBaseApplication; - TQRect rec; - TQRegion reg; - bool erase; -}; - - -class TQ_EXPORT TQMoveEvent : public TQEvent -{ -public: - TQMoveEvent( const TQPoint &pos, const TQPoint &oldPos ) - : TQEvent(Move), p(pos), oldp(oldPos) {} - const TQPoint &pos() const { return p; } - const TQPoint &oldPos()const { return oldp;} -protected: - TQPoint p, oldp; - friend class TQApplication; - friend class TQBaseApplication; -}; - - -class TQ_EXPORT TQResizeEvent : public TQEvent -{ -public: - TQResizeEvent( const TQSize &size, const TQSize &oldSize ) - : TQEvent(Resize), s(size), olds(oldSize) {} - const TQSize &size() const { return s; } - const TQSize &oldSize()const { return olds;} -protected: - TQSize s, olds; - friend class TQApplication; - friend class TQBaseApplication; -}; - - -class TQ_EXPORT TQCloseEvent : public TQEvent -{ -public: - TQCloseEvent() - : TQEvent(Close), accpt(FALSE) {} - bool isAccepted() const { return accpt; } - void accept() { accpt = TRUE; } - void ignore() { accpt = FALSE; } -protected: - bool accpt; -}; - - -class TQ_EXPORT TQIconDragEvent : public TQEvent -{ -public: - TQIconDragEvent() - : TQEvent(IconDrag), accpt(FALSE) {} - - bool isAccepted() const { return accpt; } - void accept() { accpt = TRUE; } - void ignore() { accpt = FALSE; } -protected: - bool accpt; -}; - -class TQ_EXPORT TQShowEvent : public TQEvent -{ -public: - TQShowEvent() - : TQEvent(Show) {} -}; - - -class TQ_EXPORT TQHideEvent : public TQEvent -{ -public: - TQHideEvent() - : TQEvent(Hide) {} -}; - -class TQ_EXPORT TQContextMenuEvent : public TQEvent -{ -public: - enum Reason { Mouse, Keyboard, Other }; - TQContextMenuEvent( Reason reason, const TQPoint &pos, const TQPoint &globalPos, int state ) - : TQEvent( ContextMenu ), p( pos ), gp( globalPos ), accpt( TRUE ), consum( TRUE ), - reas( reason ), s((ushort)state) {} - TQContextMenuEvent( Reason reason, const TQPoint &pos, int state ); - - int x() const { return p.x(); } - int y() const { return p.y(); } - int globalX() const { return gp.x(); } - int globalY() const { return gp.y(); } - - const TQPoint& pos() const { return p; } - const TQPoint& globalPos() const { return gp; } - - ButtonState state() const { return (ButtonState) s; } - bool isAccepted() const { return accpt; } - bool isConsumed() const { return consum; } - void consume() { accpt = FALSE; consum = TRUE; } - void accept() { accpt = TRUE; consum = TRUE; } - void ignore() { accpt = FALSE; consum = FALSE; } - - Reason reason() const { return Reason( reas ); } - -protected: - TQPoint p; - TQPoint gp; - bool accpt; - bool consum; - uint reas:8; - ushort s; -}; - - -class TQ_EXPORT TQIMEvent : public TQEvent -{ -public: - TQIMEvent( Type type, const TQString &text, int cursorPosition ) - : TQEvent(type), txt(text), cpos(cursorPosition), a(TRUE) {} - const TQString &text() const { return txt; } - int cursorPos() const { return cpos; } - bool isAccepted() const { return a; } - void accept() { a = TRUE; } - void ignore() { a = FALSE; } - int selectionLength() const; - -private: - TQString txt; - int cpos; - bool a; -}; - -class TQ_EXPORT TQIMComposeEvent : public TQIMEvent -{ -public: - TQIMComposeEvent( Type type, const TQString &text, int cursorPosition, - int selLength ) - : TQIMEvent( type, text, cursorPosition ), selLen( selLength ) { } - -private: - int selLen; - - friend class TQIMEvent; -}; - -inline int TQIMEvent::selectionLength() const -{ - if ( type() != IMCompose ) return 0; - TQIMComposeEvent *that = (TQIMComposeEvent *) this; - return that->selLen; -} - - -#ifndef TQT_NO_DRAGANDDROP - -// This class is rather closed at the moment. If you need to create your -// own DND event objects, write to qt-bugs@trolltech.com and we'll try to -// find a way to extend it so it covers your needs. - -class TQ_EXPORT TQDropEvent : public TQEvent, public TQMimeSource -{ -public: - TQDropEvent( const TQPoint& pos, Type typ=Drop ) - : TQEvent(typ), p(pos), - act(0), accpt(0), accptact(0), resv(0), - d(0) - {} - const TQPoint &pos() const { return p; } - bool isAccepted() const { return accpt || accptact; } - void accept(bool y=TRUE) { accpt = y; } - void ignore() { accpt = FALSE; } - - bool isActionAccepted() const { return accptact; } - void acceptAction(bool y=TRUE) { accptact = y; } - enum Action { Copy, Link, Move, Private, UserAction=100 }; - void setAction( Action a ) { act = (uint)a; } - Action action() const { return Action(act); } - - TQWidget* source() const; - const char* format( int n = 0 ) const; - TQByteArray encodedData( const char* ) const; - bool provides( const char* ) const; - - TQByteArray data(const char* f) const { return encodedData(f); } - - void setPoint( const TQPoint& np ) { p = np; } - -protected: - TQPoint p; - uint act:8; - uint accpt:1; - uint accptact:1; - uint resv:5; - void * d; -}; - - - -class TQ_EXPORT TQDragMoveEvent : public TQDropEvent -{ -public: - TQDragMoveEvent( const TQPoint& pos, Type typ=DragMove ) - : TQDropEvent(pos,typ), - rect( pos, TQSize( 1, 1 ) ) {} - TQRect answerRect() const { return rect; } - void accept( bool y=TRUE ) { TQDropEvent::accept(y); } - void accept( const TQRect & r) { accpt = TRUE; rect = r; } - void ignore( const TQRect & r) { accpt =FALSE; rect = r; } - void ignore() { TQDropEvent::ignore(); } - -protected: - TQRect rect; -}; - - -class TQ_EXPORT TQDragEnterEvent : public TQDragMoveEvent -{ -public: - TQDragEnterEvent( const TQPoint& pos ) : - TQDragMoveEvent(pos, DragEnter) { } -}; - - -/* An internal class */ -class TQ_EXPORT TQDragResponseEvent : public TQEvent -{ -public: - TQDragResponseEvent( bool accepted ) - : TQEvent(DragResponse), a(accepted) {} - bool dragAccepted() const { return a; } -protected: - bool a; -}; - - -class TQ_EXPORT TQDragLeaveEvent : public TQEvent -{ -public: - TQDragLeaveEvent() - : TQEvent(DragLeave) {} -}; - -#endif // TQT_NO_DRAGANDDROP - -class TQ_EXPORT TQChildEvent : public TQEvent -{ -public: - TQChildEvent( Type type, TQObject *child ) - : TQEvent(type), c(child) {} - TQObject *child() const { return c; } - bool inserted() const { return t == ChildInserted; } - bool removed() const { return t == ChildRemoved; } -protected: - TQObject *c; -}; - - -class TQ_EXPORT TQCustomEvent : public TQEvent -{ -public: - TQCustomEvent( int type ); - TQCustomEvent( Type type, void *data ) - : TQEvent(type), d(data) {}; - void *data() const { return d; } - void setData( void* data ) { d = data; } -private: - void *d; -}; - -#endif // TQEVENT_H diff --git a/src/kernel/ntqeventloop.h b/src/kernel/ntqeventloop.h deleted file mode 100644 index 75741a597..000000000 --- a/src/kernel/ntqeventloop.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Declaration of TQEventLoop class -** -** 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 TQEVENTLOOP_H -#define TQEVENTLOOP_H - -#ifndef QT_H -#include "tqobject.h" -#include "tqsocketnotifier.h" -#endif // QT_H - -#ifdef Q_QDOC -#else // Q_QDOC -#if defined(QT_USE_GLIBMAINLOOP) -#include -#endif // QT_USE_GLIBMAINLOOP -#endif // Q_QDOC - -class TQEventLoopPrivate; -class TQSocketNotifier; -class TQTimer; -#ifdef TQ_WS_MAC -struct timeval; //stdc struct -struct TimerInfo; //internal structure (qeventloop_mac.cpp) -#endif - -#if defined(TQT_THREAD_SUPPORT) -class TQMutex; -#endif // TQT_THREAD_SUPPORT - - -class TQ_EXPORT TQEventLoop : public TQObject -{ - TQ_OBJECT - -public: - TQEventLoop( TQObject *parent = 0, const char *name = 0 ); - ~TQEventLoop(); - - enum ProcessEvents { - AllEvents = 0x00, - ExcludeUserInput = 0x01, - ExcludeSocketNotifiers = 0x02, - WaitForMore = 0x04 - }; - typedef uint ProcessEventsFlags; - - void processEvents( ProcessEventsFlags flags, int maxtime ); - virtual bool processEvents( ProcessEventsFlags flags ); - - virtual bool hasPendingEvents() const; - - virtual void registerSocketNotifier( TQSocketNotifier * ); - virtual void unregisterSocketNotifier( TQSocketNotifier * ); - void setSocketNotifierPending( TQSocketNotifier * ); - int activateSocketNotifiers(); - - int activateTimers(); - int timeToWait() const; - - virtual int exec(); - virtual void exit( int retcode = 0 ); - - virtual int enterLoop(); - virtual void exitLoop(); - virtual int loopLevel() const; - - virtual void wakeUp(); - - void setSingleToolkitEventHandling(bool enabled); - -signals: - void awake(); - void aboutToBlock(); - -private: -#if defined(TQ_WS_MAC) - friend TQMAC_PASCAL void qt_mac_select_timer_callbk(EventLoopTimerRef, void *); - int macHandleSelect(timeval *); - void macHandleTimer(TimerInfo *); -#endif // TQ_WS_MAC - - // internal initialization/cleanup - implemented in various platform specific files - void init(); - void cleanup(); - virtual void appStartingUp(); - virtual void appClosingDown(); - - // data for the default implementation - other implementations should not - // use/need this data - TQEventLoopPrivate *d; - - friend class TQApplication; - -#ifdef Q_QDOC -#else // Q_QDOC -#if defined(QT_USE_GLIBMAINLOOP) - - // glib main loop support - /* internal: used to fit glib-main-loop gsource concept */ -public: - bool gsourcePrepare(GSource *gs, int * timeout); - bool gsourceCheck(GSource * gs); - bool gsourceDispatch(GSource * gs); - - bool processX11Events(); - - // end glib main loop support - -#endif //QT_USE_GLIBMAINLOOP -#endif // Q_QDOC -}; - -#endif // TQEVENTLOOP_H diff --git a/src/kernel/ntqinputcontext.h b/src/kernel/ntqinputcontext.h index 2486fc3a9..0ab8e728a 100644 --- a/src/kernel/ntqinputcontext.h +++ b/src/kernel/ntqinputcontext.h @@ -41,7 +41,7 @@ #ifndef QT_H #include "tqobject.h" #include "ntqglobal.h" -#include "ntqevent.h" +#include "tqevent.h" #include "tqstring.h" #include "tqptrlist.h" #endif diff --git a/src/kernel/ntqnamespace.h b/src/kernel/ntqnamespace.h index b056c8363..4557114db 100644 --- a/src/kernel/ntqnamespace.h +++ b/src/kernel/ntqnamespace.h @@ -72,7 +72,7 @@ public: static const TQColor & darkMagenta; static const TQColor & darkYellow; - // documented in qevent.cpp + // documented in tqevent.cpp enum ButtonState { // mouse/keyboard state values NoButton = 0x0000, LeftButton = 0x0001, @@ -342,7 +342,7 @@ public: Identical }; - // documented in qevent.cpp + // documented in tqevent.cpp enum Modifier { // accelerator modifiers META = 0x00100000, SHIFT = 0x00200000, @@ -354,7 +354,7 @@ public: ASCII_ACCEL = UNICODE_ACCEL // 1.x compat }; - // documented in qevent.cpp + // documented in tqevent.cpp enum Key { Key_Escape = 0x1000, // misc keys Key_Tab = 0x1001, diff --git a/src/kernel/ntqt.h b/src/kernel/ntqt.h index 5d9f7d4bc..11305209b 100644 --- a/src/kernel/ntqt.h +++ b/src/kernel/ntqt.h @@ -54,7 +54,7 @@ #include "tqpaintdevice.h" #include "tqfontmetrics.h" #include "tqdict.h" -#include "ntqevent.h" +#include "tqevent.h" #include "tqhostaddress.h" #include "tqstringlist.h" #include "tqcolor.h" @@ -101,7 +101,7 @@ #include #include #include "tqsocketnotifier.h" -#include +#include #include #include #include "tqbuffer.h" @@ -219,7 +219,7 @@ #include #include #include -#include "ntqtranslator.h" +#include "tqtranslator.h" #include #include #include @@ -242,7 +242,7 @@ #include #include #include -#include "ntqdesktopwidget.h" +#include "tqdesktopwidget.h" #include #include "tqurl.h" #include "tqurloperator.h" diff --git a/src/kernel/ntqtranslator.h b/src/kernel/ntqtranslator.h deleted file mode 100644 index 39f9faa36..000000000 --- a/src/kernel/ntqtranslator.h +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -** -** Definition of the translator class -** -** Created : 980906 -** -** Copyright (C) 1998-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 TQTRANSLATOR_H -#define TQTRANSLATOR_H - -#ifndef QT_H -#include "tqobject.h" -#include "tqvaluelist.h" -#endif // QT_H - -#ifndef TQT_NO_TRANSLATION - -class TQTranslatorPrivate; - -class TQ_EXPORT TQTranslatorMessage -{ -public: - TQTranslatorMessage(); - TQTranslatorMessage( const char * context, - const char * sourceText, - const char * comment, - const TQString& translation = TQString::null ); - TQTranslatorMessage( TQDataStream & ); - TQTranslatorMessage( const TQTranslatorMessage & m ); - - TQTranslatorMessage & operator=( const TQTranslatorMessage & m ); - - uint hash() const { return h; } - const char *context() const { return cx; } - const char *sourceText() const { return st; } - const char *comment() const { return cm; } - - void setTranslation( const TQString & translation ) { tn = translation; } - TQString translation() const { return tn; } - - enum Prefix { NoPrefix, Hash, HashContext, HashContextSourceText, - HashContextSourceTextComment }; - void write( TQDataStream & s, bool strip = FALSE, - Prefix prefix = HashContextSourceTextComment ) const; - Prefix commonPrefix( const TQTranslatorMessage& ) const; - - bool operator==( const TQTranslatorMessage& m ) const; - bool operator!=( const TQTranslatorMessage& m ) const - { return !operator==( m ); } - bool operator<( const TQTranslatorMessage& m ) const; - bool operator<=( const TQTranslatorMessage& m ) const - { return !m.operator<( *this ); } - bool operator>( const TQTranslatorMessage& m ) const - { return m.operator<( *this ); } - bool operator>=( const TQTranslatorMessage& m ) const - { return !operator<( m ); } - -private: - uint h; - TQCString cx; - TQCString st; - TQCString cm; - TQString tn; - - enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16, - Tag_Hash, Tag_SourceText, Tag_Context, Tag_Comment, - Tag_Obsolete1 }; -}; - - -class TQ_EXPORT TQTranslator: public TQObject -{ - TQ_OBJECT -public: - TQTranslator( TQObject * parent = 0, const char * name = 0 ); - ~TQTranslator(); - -#ifndef TQT_NO_COMPAT - TQString find( const char *context, const char *sourceText, const char * comment = 0 ) const { - return findMessage( context, sourceText, comment ).translation(); - } -#endif - virtual TQTranslatorMessage findMessage( const char *, const char *, - const char * = 0 ) const; - - bool load( const TQString & filename, - const TQString & directory = TQString::null, - const TQString & search_delimiters = TQString::null, - const TQString & suffix = TQString::null ); - bool load( const uchar *data, int len ) { - clear(); - return do_load( data, len ); - } - - void clear(); - -#ifndef TQT_NO_TRANSLATION_BUILDER - enum SaveMode { Everything, Stripped }; - - bool save( const TQString & filename, SaveMode mode = Everything ); - - void insert( const TQTranslatorMessage& ); - void insert( const char *context, const char *sourceText, const TQString &translation ) { - insert( TQTranslatorMessage(context, sourceText, "", translation) ); - } - void remove( const TQTranslatorMessage& ); - void remove( const char *context, const char *sourceText ) { - remove( TQTranslatorMessage(context, sourceText, "") ); - } - bool contains( const char *, const char *, const char * comment = 0 ) const; - - void squeeze( SaveMode = Everything ); - void unsqueeze(); - - TQValueList messages() const; -#endif - - bool isEmpty() const; - -private: -#if defined(TQ_DISABLE_COPY) - TQTranslator( const TQTranslator & ); - TQTranslator &operator=( const TQTranslator & ); -#endif - - bool do_load( const uchar *data, int len ); - - TQTranslatorPrivate * d; -}; - -#endif // TQT_NO_TRANSLATION - -#endif diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index d37efef76..a44d10389 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -40,15 +40,15 @@ #include "tqobjectlist.h" #include "ntqapplication.h" -#include "ntqeventloop.h" -#include "qeventloop_p.h" +#include "tqeventloop.h" +#include "tqeventloop_p.h" #include "tqwidget.h" #include "tqwidgetlist.h" #include "tqwidgetintdict.h" #include "tqptrdict.h" #include "ntqcleanuphandler.h" -#include "ntqtranslator.h" +#include "tqtranslator.h" #include "tqtextcodec.h" #include "tqsessionmanager.h" #include "tqdragobject.h" diff --git a/src/kernel/qapplication_x11.cpp b/src/kernel/qapplication_x11.cpp index aa6fd907b..18a0eb7f0 100644 --- a/src/kernel/qapplication_x11.cpp +++ b/src/kernel/qapplication_x11.cpp @@ -310,7 +310,7 @@ Atom qt_net_wm_sync_request = 0; // client leader window Window qt_x11_wm_client_leader = 0; -// function to update the workarea of the screen - in qdesktopwidget_x11.cpp +// function to update the workarea of the screen - in tqdesktopwidget_x11.cpp extern void qt_desktopwidget_update_workarea(); // current focus model diff --git a/src/kernel/qdesktopwidget_x11.cpp b/src/kernel/qdesktopwidget_x11.cpp deleted file mode 100644 index db3763530..000000000 --- a/src/kernel/qdesktopwidget_x11.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQDesktopWidget class. -** -** 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 "ntqdesktopwidget.h" -#include "ntqapplication.h" -#include "tqobjectlist.h" -#include "qt_x11_p.h" -#include - -// defined in tqwidget_x11.cpp -extern int qt_x11_create_desktop_on_screen; - -// defined in qapplication_x11.cpp -extern Atom qt_net_workarea; -extern bool qt_net_supports(Atom atom); - -// function to update the workarea of the screen -static bool qt_desktopwidget_workarea_dirty = TRUE; -void qt_desktopwidget_update_workarea() -{ - qt_desktopwidget_workarea_dirty = TRUE; -} - - -class TQSingleDesktopWidget : public TQWidget -{ -public: - TQSingleDesktopWidget(); - ~TQSingleDesktopWidget(); -}; - -TQSingleDesktopWidget::TQSingleDesktopWidget() - : TQWidget( 0, "desktop", WType_Desktop ) -{ -} - -TQSingleDesktopWidget::~TQSingleDesktopWidget() -{ - while ( children() ) - removeChild( children()->getFirst() ); -} - - -class TQDesktopWidgetPrivate -{ -public: - TQDesktopWidgetPrivate(); - ~TQDesktopWidgetPrivate(); - - void init(); - - bool use_xinerama; - int defaultScreen; - int screenCount; - - TQWidget **screens; - TQRect *rects; - TQRect *workareas; -}; - -TQDesktopWidgetPrivate::TQDesktopWidgetPrivate() - : use_xinerama(FALSE), defaultScreen(0), screenCount(1), - screens( 0 ), rects( 0 ), workareas( 0 ) -{ -} - -TQDesktopWidgetPrivate::~TQDesktopWidgetPrivate() -{ - if ( screens ) { - for ( int i = 0; i < screenCount; ++i ) { - if (i == defaultScreen) continue; - delete screens[i]; - screens[i] = 0; - } - - free(screens); - } - - if ( rects ) delete [] rects; - if ( workareas ) delete [] workareas; -} - -void TQDesktopWidgetPrivate::init() -{ - // get the screen count - int newScreenCount; - -#ifndef TQT_NO_XINERAMA - XineramaScreenInfo *xinerama_screeninfo = 0; - int unused; - use_xinerama = (XineramaQueryExtension(TQPaintDevice::x11AppDisplay(), - &unused, &unused) && - XineramaIsActive(TQPaintDevice::x11AppDisplay())); - - if (use_xinerama) { - xinerama_screeninfo = - XineramaQueryScreens(TQPaintDevice::x11AppDisplay(), &newScreenCount); - - if (xinerama_screeninfo) - defaultScreen = 0; - } else -#endif // TQT_NO_XINERAMA - { - defaultScreen = DefaultScreen(TQPaintDevice::x11AppDisplay()); - newScreenCount = ScreenCount(TQPaintDevice::x11AppDisplay()); - use_xinerama = false; - } - - delete [] rects; - rects = new TQRect[ newScreenCount ]; - delete [] workareas; - workareas = new TQRect[ newScreenCount ]; - - // get the geometry of each screen - int i, j, x, y, w, h; - for ( i = 0, j = 0; i < newScreenCount; i++ ) { - -#ifndef TQT_NO_XINERAMA - if (use_xinerama) { - x = xinerama_screeninfo[i].x_org; - y = xinerama_screeninfo[i].y_org; - w = xinerama_screeninfo[i].width; - h = xinerama_screeninfo[i].height; - } else -#endif // TQT_NO_XINERAMA - { - x = 0; - y = 0; - w = WidthOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), i)); - h = HeightOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), i)); - } - - workareas[i] = TQRect(); - rects[j].setRect(x, y, w, h); - - // overlapping? - if (j > 0 && rects[j-1].intersects(rects[j])) { - // pick the bigger one, ignore the other - if ((rects[j].width()*rects[j].height()) > - (rects[j-1].width()*rects[j-1].height())) - rects[j-1] = rects[j]; - } - else - j++; - } - - if (screens) { - // leaks TQWidget* pointers on purpose, can't delete them as pointer escapes - screens = (TQWidget**) realloc(screens, j * sizeof(TQWidget*)); - if (j > screenCount) - memset(&screens[screenCount], 0, (j-screenCount) * sizeof(TQWidget*)); - } - - screenCount = j; - -#ifndef TQT_NO_XINERAMA - if (use_xinerama && screenCount == 1) - use_xinerama = false; - - if (xinerama_screeninfo) - XFree(xinerama_screeninfo); -#endif // TQT_NO_XINERAMA - -} - -// the TQDesktopWidget itself will be created on the default screen -// as qt_x11_create_desktop_on_screen defaults to -1 -TQDesktopWidget::TQDesktopWidget() - : TQWidget( 0, "desktop", WType_Desktop ) -{ - d = new TQDesktopWidgetPrivate(); - - /* - we don't call d->init() here, since the initial resize event - will end up calling init() a second time, which is inefficient. - instead, for the sending of all posted event to the desktop - widget (including the initial resize event, which calls - d->init()). - */ - TQApplication::sendPostedEvents( this, 0 ); -} - -TQDesktopWidget::~TQDesktopWidget() -{ - delete d; -} - -bool TQDesktopWidget::isVirtualDesktop() const -{ - return d->use_xinerama; -} - -int TQDesktopWidget::primaryScreen() const -{ - return d->defaultScreen; -} - -int TQDesktopWidget::numScreens() const -{ - return d->screenCount; -} - -TQWidget *TQDesktopWidget::screen( int screen ) -{ - if (d->use_xinerama) - return this; - - if ( screen < 0 || screen >= d->screenCount ) - screen = d->defaultScreen; - - if ( ! d->screens ) { - d->screens = (TQWidget**) calloc( d->screenCount, sizeof(TQWidget*)); - d->screens[ d->defaultScreen ] = this; - } - - if ( ! d->screens[screen] || // not created yet - ! d->screens[screen]->isDesktop() ) { // reparented away - qt_x11_create_desktop_on_screen = screen; - d->screens[screen] = new TQSingleDesktopWidget; - qt_x11_create_desktop_on_screen = -1; - } - - return d->screens[screen]; -} - -const TQRect& TQDesktopWidget::availableGeometry( int screen ) const -{ - if ( qt_desktopwidget_workarea_dirty ) { - // the workareas are dirty, invalidate them - for ( int i = 0; i < d->screenCount; ++i ) - d->workareas[i] = TQRect(); - qt_desktopwidget_workarea_dirty = FALSE; - } - - if ( screen < 0 || screen >= d->screenCount ) - screen = d->defaultScreen; - - if ( d->workareas[screen].isValid() ) - return d->workareas[screen]; - - if ( ! isVirtualDesktop() && qt_net_supports( qt_net_workarea ) ) { - Atom ret; - int format, e; - unsigned char *data = 0; - unsigned long nitems, after; - - e = XGetWindowProperty( TQPaintDevice::x11AppDisplay(), - TQPaintDevice::x11AppRootWindow( screen ), - qt_net_workarea, 0, 4, False, XA_CARDINAL, - &ret, &format, &nitems, &after, &data ); - - if (e == Success && ret == XA_CARDINAL && - format == 32 && nitems == 4) { - long *workarea = (long *) data; - d->workareas[screen].setRect( workarea[0], workarea[1], - workarea[2], workarea[3] ); - } else { - d->workareas[screen] = screenGeometry(screen); - } - if ( data ) - XFree( data ); - } else { - d->workareas[screen] = screenGeometry(screen); - } - - return d->workareas[screen]; -} - -const TQRect& TQDesktopWidget::screenGeometry( int screen ) const -{ - if ( screen < 0 || screen >= d->screenCount ) - screen = d->defaultScreen; - - return d->rects[ screen ]; -} - -int TQDesktopWidget::screenNumber( TQWidget *widget ) const -{ - if ( !widget ) - return d->defaultScreen; - -#ifndef TQT_NO_XINERAMA - if (d->use_xinerama) { - // this is how we do it for xinerama - TQRect frame = widget->frameGeometry(); - if ( !widget->isTopLevel() ) - frame.moveTopLeft( widget->mapToGlobal( TQPoint( 0, 0 ) ) ); - - int maxSize = -1; - int maxScreen = -1; - - for ( int i = 0; i < d->screenCount; ++i ) { - TQRect sect = d->rects[i].intersect( frame ); - int size = sect.width() * sect.height(); - if ( size > maxSize && sect.width() > 0 && sect.height() > 0 ) { - maxSize = size; - maxScreen = i; - } - } - return maxScreen; - } -#endif // TQT_NO_XINERAMA - - return widget->x11Screen(); -} - -int TQDesktopWidget::screenNumber( const TQPoint &point ) const -{ - for ( int i = 0; i < d->screenCount; ++i ) { - if ( d->rects[i].contains( point ) ) - return i; - } - return -1; -} - -void TQDesktopWidget::resizeEvent( TQResizeEvent *event ) -{ - d->init(); - qt_desktopwidget_workarea_dirty = TRUE; - TQWidget::resizeEvent( event ); -} diff --git a/src/kernel/qdnd_x11.cpp b/src/kernel/qdnd_x11.cpp index accf14209..5194ee878 100644 --- a/src/kernel/qdnd_x11.cpp +++ b/src/kernel/qdnd_x11.cpp @@ -1484,7 +1484,7 @@ bool qt_xdnd_handle_badwindow() /*! - \class TQDragMoveEvent ntqevent.h + \class TQDragMoveEvent tqevent.h \ingroup events \ingroup draganddrop \brief The TQDragMoveEvent class provides an event which is sent while a drag and drop is in progress. @@ -1658,7 +1658,7 @@ bool qt_dnd_enable( TQWidget* w, bool on ) /*! - \class TQDropEvent ntqevent.h + \class TQDropEvent tqevent.h \ingroup events \ingroup draganddrop diff --git a/src/kernel/qevent.cpp b/src/kernel/qevent.cpp deleted file mode 100644 index 36f59c53f..000000000 --- a/src/kernel/qevent.cpp +++ /dev/null @@ -1,2579 +0,0 @@ -/**************************************************************************** -** -** Implementation of event classes -** -** 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. -** -**********************************************************************/ - -#include "ntqevent.h" -#include "ntqcursor.h" -#include "ntqapplication.h" - - -/*! - \class TQEvent ntqevent.h - \brief The TQEvent class is the base class of all - event classes. Event objects contain event parameters. - - \ingroup events - \ingroup environment - - TQt's main event loop (TQApplication::exec()) fetches native window - system events from the event queue, translates them into TQEvents - and sends the translated events to TQObjects. - - In general, events come from the underlying window system - (spontaneous() returns TRUE) but it is also possible to manually - send events using TQApplication::sendEvent() and - TQApplication::postEvent() (spontaneous() returns FALSE). - - TQObjects receive events by having their TQObject::event() function - called. The function can be reimplemented in subclasses to - customize event handling and add additional event types; - TQWidget::event() is a notable example. By default, events are - dispatched to event handlers like TQObject::timerEvent() and - TQWidget::mouseMoveEvent(). TQObject::installEventFilter() allows an - object to intercept events destined for another object. - - The basic TQEvent contains only an event type parameter. - Subclasses of TQEvent contain additional parameters that describe - the particular event. - - \sa TQObject::event() TQObject::installEventFilter() - TQWidget::event() TQApplication::sendEvent() - TQApplication::postEvent() TQApplication::processEvents() -*/ - - -/*! - \enum TQt::ButtonState - - This enum type describes the state of the mouse and the modifier - buttons. - - \value NoButton used when the button state does not refer to any - button (see TQMouseEvent::button()). - \value LeftButton set if the left button is pressed, or if this - event refers to the left button. (The left button may be - the right button on left-handed mice.) - \value RightButton the right button. - \value MidButton the middle button. - \value HistoryBackButton history navigation back button. - \value HistoryForwardButton history navigation forward button. - \value ShiftButton a Shift key on the keyboard is also pressed. - \value ControlButton a Ctrl key on the keyboard is also pressed. - \value AltButton an Alt key on the keyboard is also pressed. - \value MetaButton a Meta key on the keyboard is also pressed. - \value Keypad a keypad button is pressed. - \value KeyButtonMask a mask for ShiftButton, ControlButton, - AltButton and MetaButton. - \value MouseButtonMask a mask for LeftButton, RightButton, MidButton, - HistoryBackButton and HistoryForwardButton. -*/ - -/*! - \enum TQEvent::Type - - This enum type defines the valid event types in TQt. The event - types and the specialized classes for each type are these: - - \value None Not an event. - \value Accessibility Accessibility information is requested - \value Timer Regular timer events, \l{TQTimerEvent}. - \value MouseButtonPress Mouse press, \l{TQMouseEvent}. - \value MouseButtonRelease Mouse release, \l{TQMouseEvent}. - \value MouseButtonDblClick Mouse press again, \l{TQMouseEvent}. - \value MouseMove Mouse move, \l{TQMouseEvent}. - \value KeyPress Key press (including Shift, for example), \l{TQKeyEvent}. - \value KeyRelease Key release, \l{TQKeyEvent}. - \value IMStart The start of input method composition, \l{TQIMEvent}. - \value IMCompose Input method composition is taking place, \l{TQIMEvent}. - \value IMEnd The end of input method composition, \l{TQIMEvent}. - \value FocusIn Widget gains keyboard focus, \l{TQFocusEvent}. - \value FocusOut Widget loses keyboard focus, \l{TQFocusEvent}. - \value Enter Mouse enters widget's boundaries. - \value Leave Mouse leaves widget's boundaries. - \value Paint Screen update necessary, \l{TQPaintEvent}. - \value Move Widget's position changed, \l{TQMoveEvent}. - \value Resize Widget's size changed, \l{TQResizeEvent}. - \value Show Widget was shown on screen, \l{TQShowEvent}. - \value Hide Widget was hidden, \l{TQHideEvent}. - \value ShowToParent A child widget has been shown. - \value HideToParent A child widget has been hidden. - \value Close Widget was closed (permanently), \l{TQCloseEvent}. - \value ShowNormal Widget should be shown normally (obsolete). - \value ShowMaximized Widget should be shown maximized (obsolete). - \value ShowMinimized Widget should be shown minimized (obsolete). - \value ShowFullScreen Widget should be shown full-screen (obsolete). - \value ShowWindowRequest Widget's window should be shown (obsolete). - \value DeferredDelete The object will be deleted after it has - cleaned up. - \value Accel Key press in child for shortcut key handling, \l{TQKeyEvent}. - \value Wheel Mouse wheel rolled, \l{TQWheelEvent}. - \value ContextMenu Context popup menu, \l{TQContextMenuEvent} - \value AccelOverride Key press in child, for overriding shortcut key handling, \l{TQKeyEvent}. - \value AccelAvailable internal. - \value WindowActivate Window was activated. - \value WindowDeactivate Window was deactivated. - \value CaptionChange Widget's caption changed. - \value IconChange Widget's icon changed. - \value ParentFontChange Font of the parent widget changed. - \value ApplicationFontChange Default application font changed. - \value PaletteChange Palette of the widget changed. - \value ParentPaletteChange Palette of the parent widget changed. - \value ApplicationPaletteChange Default application palette changed. - \value Clipboard Clipboard contents have changed. - \value SockAct Socket activated, used to implement \l{TQSocketNotifier}. - \value DragEnter A drag-and-drop enters widget, \l{TQDragEnterEvent}. - \value DragMove A drag-and-drop is in progress, \l{TQDragMoveEvent}. - \value DragLeave A drag-and-drop leaves widget, \l{TQDragLeaveEvent}. - \value Drop A drag-and-drop is completed, \l{TQDropEvent}. - \value DragResponse Internal event used by TQt on some platforms. - \value ChildInserted Object gets a child, \l{TQChildEvent}. - \value ChildRemoved Object loses a child, \l{TQChildEvent}. - \value LayoutHint Widget child has changed layout properties. - \value ActivateControl Internal event used by TQt on some platforms. - \value DeactivateControl Internal event used by TQt on some platforms. - \value LanguageChange The application translation changed, \l{TQTranslator} - \value LayoutDirectionChange The direction of layouts changed - \value LocaleChange The system locale changed - \value Quit Reserved. - \value Create Reserved. - \value Destroy Reserved. - \value Reparent Reserved. - \value Speech Reserved for speech input. - \value TabletMove A Wacom Tablet Move Event. - \value Style Internal use only - \value TabletPress A Wacom Tablet Press Event - \value TabletRelease A Wacom Tablet Release Event - \value OkRequest Internal event used by TQt on some platforms. - \value HelpRequest Internal event used by TQt on some platforms. - \value IconDrag Internal event used by TQt on some platforms when proxy icon is dragged. - \value WindowStateChange The window's state, i.e. minimized, - maximized or full-screen, has changed. See \l{TQWidget::windowState()}. - \value WindowBlocked The window is modally blocked - \value WindowUnblocked The window leaves modal blocking - - \value User User defined event. - \value MaxUser Last user event id. - - User events should have values between User and MaxUser inclusive. -*/ -/*! - \fn TQEvent::TQEvent( Type type ) - - Contructs an event object of type \a type. -*/ - -/*! - \fn TQEvent::Type TQEvent::type() const - - Returns the event type. -*/ - -/*! - \fn bool TQEvent::spontaneous() const - - Returns TRUE if the event originated outside the application, i.e. - it is a system event; otherwise returns FALSE. -*/ - - -/*! - \class TQTimerEvent ntqevent.h - \brief The TQTimerEvent class contains parameters that describe a - timer event. - - \ingroup events - - Timer events are sent at regular intervals to objects that have - started one or more timers. Each timer has a unique identifier. A - timer is started with TQObject::startTimer(). - - The TQTimer class provides a high-level programming interface that - uses signals instead of events. It also provides one-shot timers. - - The event handler TQObject::timerEvent() receives timer events. - - \sa TQTimer, TQObject::timerEvent(), TQObject::startTimer(), - TQObject::killTimer(), TQObject::killTimers() -*/ - -/*! - \fn TQTimerEvent::TQTimerEvent( int timerId ) - - Constructs a timer event object with the timer identifier set to - \a timerId. -*/ - -/*! - \fn int TQTimerEvent::timerId() const - - Returns the unique timer identifier, which is the same identifier - as returned from TQObject::startTimer(). -*/ - - -/*! - \class TQMouseEvent ntqevent.h - \ingroup events - - \brief The TQMouseEvent class contains parameters that describe a mouse event. - - Mouse events occur when a mouse button is pressed or released - inside a widget or when the mouse cursor is moved. - - Mouse move events will occur only when a mouse button is pressed - down, unless mouse tracking has been enabled with - TQWidget::setMouseTracking(). - - TQt automatically grabs the mouse when a mouse button is pressed - inside a widget; the widget will continue to receive mouse events - until the last mouse button is released. - - A mouse event contains a special accept flag that indicates - whether the receiver wants the event. You should call - TQMouseEvent::ignore() if the mouse event is not handled by your - widget. A mouse event is propagated up the parent widget chain - until a widget accepts it with TQMouseEvent::accept() or an event - filter consumes it. - - The functions pos(), x() and y() give the cursor position relative - to the widget that receives the mouse event. If you move the - widget as a result of the mouse event, use the global position - returned by globalPos() to avoid a shaking motion. - - The TQWidget::setEnabled() function can be used to enable or - disable mouse and keyboard events for a widget. - - The event handlers TQWidget::mousePressEvent(), - TQWidget::mouseReleaseEvent(), TQWidget::mouseDoubleClickEvent() and - TQWidget::mouseMoveEvent() receive mouse events. - - \sa TQWidget::setMouseTracking(), TQWidget::grabMouse(), - TQCursor::pos() -*/ - -/*! - \fn TQMouseEvent::TQMouseEvent( Type type, const TQPoint &pos, int button, int state ) - - Constructs a mouse event object. - - The \a type parameter must be one of \c TQEvent::MouseButtonPress, - \c TQEvent::MouseButtonRelease, \c TQEvent::MouseButtonDblClick or - \c TQEvent::MouseMove. - - The \a pos parameter specifies the position relative to the - receiving widget. \a button specifies the \link TQt::ButtonState - button\endlink that caused the event, which should be \c - TQt::NoButton (0), if \a type is \c MouseMove. \a state is the - \link TQt::ButtonState ButtonState\endlink at the time of the - event. - - The globalPos() is initialized to TQCursor::pos(), which may not be - appropriate. Use the other constructor to specify the global - position explicitly. -*/ - -TQMouseEvent::TQMouseEvent( Type type, const TQPoint &pos, int button, int state ) - : TQEvent(type), p(pos), b(button),s((ushort)state), accpt(TRUE){ - g = TQCursor::pos(); -} - - -/*! - \fn TQMouseEvent::TQMouseEvent( Type type, const TQPoint &pos, const TQPoint &globalPos, int button, int state ) - - Constructs a mouse event object. - - The \a type parameter must be \c TQEvent::MouseButtonPress, \c - TQEvent::MouseButtonRelease, \c TQEvent::MouseButtonDblClick or \c - TQEvent::MouseMove. - - The \a pos parameter specifies the position relative to the - receiving widget. \a globalPos is the position in absolute - coordinates. \a button specifies the \link TQt::ButtonState - button\endlink that caused the event, which should be \c - TQt::NoButton (0), if \a type is \c MouseMove. \a state is the - \link TQt::ButtonState ButtonState\endlink at the time of the - event. - -*/ - -/*! - \fn const TQPoint &TQMouseEvent::pos() const - - Returns the position of the mouse pointer relative to the widget - that received the event. - - If you move the widget as a result of the mouse event, use the - global position returned by globalPos() to avoid a shaking motion. - - \sa x(), y(), globalPos() -*/ - -/*! - \fn const TQPoint &TQMouseEvent::globalPos() const - - Returns the global position of the mouse pointer \e{at the time - of the event}. This is important on asynchronous window systems - like X11. Whenever you move your widgets around in response to - mouse events, globalPos() may differ a lot from the current - pointer position TQCursor::pos(), and from TQWidget::mapToGlobal( - pos() ). - - \sa globalX(), globalY() -*/ - -/*! - \fn int TQMouseEvent::x() const - - Returns the x-position of the mouse pointer, relative to the - widget that received the event. - - \sa y(), pos() -*/ - -/*! - \fn int TQMouseEvent::y() const - - Returns the y-position of the mouse pointer, relative to the - widget that received the event. - - \sa x(), pos() -*/ - -/*! - \fn int TQMouseEvent::globalX() const - - Returns the global x-position of the mouse pointer at the time of - the event. - - \sa globalY(), globalPos() -*/ - -/*! - \fn int TQMouseEvent::globalY() const - - Returns the global y-position of the mouse pointer at the time of - the event. - - \sa globalX(), globalPos() -*/ - -/*! - \fn ButtonState TQMouseEvent::button() const - - Returns the button that caused the event. - - Possible return values are \c LeftButton, \c RightButton, \c - MidButton and \c NoButton. - - Note that the returned value is always \c NoButton for mouse move - events. - - \sa state() TQt::ButtonState -*/ - - -/*! - \fn ButtonState TQMouseEvent::state() const - - Returns the button state (a combination of mouse buttons and - keyboard modifiers), i.e. what buttons and keys were being pressed - immediately before the event was generated. - - This means that if you have a \c TQEvent::MouseButtonPress or a \c - TQEvent::MouseButtonDblClick state() will \e not include the mouse - button that's pressed. But once the mouse button has been - released, the \c TQEvent::MouseButtonRelease event will have the - button() that was pressed. - - This value is mainly interesting for \c TQEvent::MouseMove; for the - other cases, button() is more useful. - - The returned value is \c LeftButton, \c RightButton, \c MidButton, - \c ShiftButton, \c ControlButton and \c AltButton OR'ed together. - - \sa button() stateAfter() TQt::ButtonState -*/ - -/*! - \fn ButtonState TQMouseEvent::stateAfter() const - - Returns the state of buttons after the event. - - \sa state() TQt::ButtonState -*/ -TQt::ButtonState TQMouseEvent::stateAfter() const -{ - return TQt::ButtonState(state()^button()); -} - - - -/*! - \fn bool TQMouseEvent::isAccepted() const - - Returns TRUE if the receiver of the event wants to keep the key; - otherwise returns FALSE. -*/ - -/*! - \fn void TQMouseEvent::accept() - - Sets the accept flag of the mouse event object. - - Setting the accept parameter indicates that the receiver of the - event wants the mouse event. Unwanted mouse events are sent to the - parent widget. - - The accept flag is set by default. - - \sa ignore() -*/ - - -/*! - \fn void TQMouseEvent::ignore() - - Clears the accept flag parameter of the mouse event object. - - Clearing the accept parameter indicates that the event receiver - does not want the mouse event. Unwanted mouse events are sent to - the parent widget. - - The accept flag is set by default. - - \sa accept() -*/ - - -/*! - \class TQWheelEvent ntqevent.h - \brief The TQWheelEvent class contains parameters that describe a wheel event. - - \ingroup events - - Wheel events are sent to the widget under the mouse, and if that widget - does not handle the event they are sent to the focus widget. The rotation - distance is provided by delta(). The functions pos() and globalPos() return - the mouse pointer location at the time of the event. - - A wheel event contains a special accept flag that indicates - whether the receiver wants the event. You should call - TQWheelEvent::accept() if you handle the wheel event; otherwise it - will be sent to the parent widget. - - The TQWidget::setEnable() function can be used to enable or disable - mouse and keyboard events for a widget. - - The event handler TQWidget::wheelEvent() receives wheel events. - - \sa TQMouseEvent, TQWidget::grabMouse() -*/ - -/*! - \fn Orientation TQWheelEvent::orientation() const - - Returns the wheel's orientation. -*/ - -/*! - \fn TQWheelEvent::TQWheelEvent( const TQPoint &pos, int delta, int state, Orientation orient = Vertical ); - - Constructs a wheel event object. - - The globalPos() is initialized to TQCursor::pos(), i.e. \a pos, - which is usually (but not always) right. Use the other constructor - if you need to specify the global position explicitly. \a delta - contains the rotation distance, \a state holds the keyboard - modifier flags at the time of the event and \a orient holds the - wheel's orientation. - - \sa pos(), delta(), state() -*/ -#ifndef TQT_NO_WHEELEVENT -TQWheelEvent::TQWheelEvent( const TQPoint &pos, int delta, int state, Orientation orient ) - : TQEvent(Wheel), p(pos), d(delta), s((ushort)state), - accpt(TRUE), o(orient) -{ - g = TQCursor::pos(); -} -#endif -/*! - \fn TQWheelEvent::TQWheelEvent( const TQPoint &pos, const TQPoint& globalPos, int delta, int state, Orientation orient = Vertical ) - - Constructs a wheel event object. The position when the event - occurred is given in \a pos and \a globalPos. \a delta contains - the rotation distance, \a state holds the keyboard modifier flags - at the time of the event and \a orient holds the wheel's - orientation. - - \sa pos(), globalPos(), delta(), state() -*/ - -/*! - \fn int TQWheelEvent::delta() const - - Returns the distance that the wheel is rotated expressed in - multiples or divisions of the \e{wheel delta}, which is currently - defined to be 120. A positive value indicates that the wheel was - rotated forwards away from the user; a negative value indicates - that the wheel was rotated backwards toward the user. - - The \e{wheel delta} constant was defined to be 120 by wheel mouse - vendors to allow building finer-resolution wheels in the future, - including perhaps a freely rotating wheel with no notches. The - expectation is that such a device would send more messages per - rotation but with a smaller value in each message. -*/ - -/*! - \fn const TQPoint &TQWheelEvent::pos() const - - Returns the position of the mouse pointer, relative to the widget - that received the event. - - If you move your widgets around in response to mouse - events, use globalPos() instead of this function. - - \sa x(), y(), globalPos() -*/ - -/*! - \fn int TQWheelEvent::x() const - - Returns the x-position of the mouse pointer, relative to the - widget that received the event. - - \sa y(), pos() -*/ - -/*! - \fn int TQWheelEvent::y() const - - Returns the y-position of the mouse pointer, relative to the - widget that received the event. - - \sa x(), pos() -*/ - - -/*! - \fn const TQPoint &TQWheelEvent::globalPos() const - - Returns the global position of the mouse pointer \e{at the time - of the event}. This is important on asynchronous window systems - such as X11; whenever you move your widgets around in response to - mouse events, globalPos() can differ a lot from the current - pointer position TQCursor::pos(). - - \sa globalX(), globalY() -*/ - -/*! - \fn int TQWheelEvent::globalX() const - - Returns the global x-position of the mouse pointer at the time of - the event. - - \sa globalY(), globalPos() -*/ - -/*! - \fn int TQWheelEvent::globalY() const - - Returns the global y-position of the mouse pointer at the time of - the event. - - \sa globalX(), globalPos() -*/ - - -/*! - \fn ButtonState TQWheelEvent::state() const - - Returns the keyboard modifier flags of the event. - - The returned value is \c ShiftButton, \c ControlButton, and \c - AltButton OR'ed together. -*/ - -/*! - \fn bool TQWheelEvent::isAccepted() const - - Returns TRUE if the receiver of the event handles the wheel event; - otherwise returns FALSE. -*/ - -/*! - \fn void TQWheelEvent::accept() - - Sets the accept flag of the wheel event object. - - Setting the accept parameter indicates that the receiver of the - event wants the wheel event. Unwanted wheel events are sent to the - parent widget. - - The accept flag is set by default. - - \sa ignore() -*/ - -/*! - \fn void TQWheelEvent::ignore() - - Clears the accept flag parameter of the wheel event object. - - Clearing the accept parameter indicates that the event receiver - does not want the wheel event. Unwanted wheel events are sent to - the parent widget. The accept flag is set by default. - - \sa accept() -*/ - - -/*! - \enum TQt::Modifier - - This enum type describes the keyboard modifier keys supported by - TQt. - - \value SHIFT the Shift keys provided on all standard keyboards. - \value META the Meta keys. - \value CTRL the Ctrl keys. - \value ALT the normal Alt keys, but not e.g. AltGr. - \value MODIFIER_MASK is a mask of Shift, Ctrl, Alt and Meta. - \value UNICODE_ACCEL the accelerator is specified as a Unicode code - point, not as a TQt Key. -*/ - -/*! - \class TQKeyEvent ntqevent.h - \brief The TQKeyEvent class contains describes a key event. - - \ingroup events - - Key events occur when a key is pressed or released when a widget - has keyboard input focus. - - A key event contains a special accept flag that indicates whether the - receiver wants the key event. You should call TQKeyEvent::ignore() if the - key press or release event is not handled by your widget. A key event is - propagated up the parent widget chain until a widget accepts it with - TQKeyEvent::accept() or an event filter consumes it. - Key events for multi media keys are ignored by default. You should call - TQKeyEvent::accept() if your widget handles those events. - - The TQWidget::setEnable() function can be used to enable or disable - mouse and keyboard events for a widget. - - The event handlers TQWidget::keyPressEvent() and - TQWidget::keyReleaseEvent() receive key events. - - \sa TQFocusEvent, TQWidget::grabKeyboard() -*/ - -/*! - \fn TQKeyEvent::TQKeyEvent( Type type, int key, int ascii, int state, - const TQString& text, bool autorep, ushort count ) - - Constructs a key event object. - - The \a type parameter must be \c TQEvent::KeyPress or \c - TQEvent::KeyRelease. If \a key is 0 the event is not a result of a - known key (e.g. it may be the result of a compose sequence or - keyboard macro). \a ascii is the ASCII code of the key that was - pressed or released. \a state holds the keyboard modifiers. \a - text is the Unicode text that the key generated. If \a autorep is - TRUE, isAutoRepeat() will be TRUE. \a count is the number of - single keys. - - The accept flag is set to TRUE. -*/ - -/*! - \fn int TQKeyEvent::key() const - - Returns the code of the key that was pressed or released. - - See \l TQt::Key for the list of keyboard codes. These codes are - independent of the underlying window system. - - A value of either 0 or Key_unknown means that the event is not - the result of a known key (e.g. it may be the result of a compose - sequence or a keyboard macro, or due to key event compression). - - Applications should not use the TQt latin 1 keycodes between 128 - and 255, but should rather use the TQKeyEvent::text(). This is - mainly for compatibility. - - \sa TQWidget::setKeyCompression() -*/ - -/*! - \fn int TQKeyEvent::ascii() const - - Returns the ASCII code of the key that was pressed or released. We - recommend using text() instead. - - \sa text() -*/ - -/*! - \fn TQString TQKeyEvent::text() const - - Returns the Unicode text that this key generated. The text returned - migth be empty, which is the case when pressing or - releasing modifying keys as Shift, Control, Alt and Meta. In these - cases key() will contain a valid value. - - \sa TQWidget::setKeyCompression() -*/ - -/*! - \fn ButtonState TQKeyEvent::state() const - - Returns the keyboard modifier flags that existed immediately - before the event occurred. - - The returned value is \c ShiftButton, \c ControlButton, \c AltButton - and \c MetaButton OR'ed together. - - \sa stateAfter() -*/ - -/*! - \fn ButtonState TQKeyEvent::stateAfter() const - - Returns the keyboard modifier flags that existed immediately after - the event occurred. - - \warning This function cannot be trusted. - - \sa state() -*/ -//###### We must check with XGetModifierMapping -TQt::ButtonState TQKeyEvent::stateAfter() const -{ - if ( key() == Key_Shift ) - return TQt::ButtonState(state()^ShiftButton); - if ( key() == Key_Control ) - return TQt::ButtonState(state()^ControlButton); - if ( key() == Key_Alt ) - return TQt::ButtonState(state()^AltButton); - if ( key() == Key_Meta ) - return TQt::ButtonState(state()^MetaButton); - return state(); -} - -/*! - \fn bool TQKeyEvent::isAccepted() const - - Returns TRUE if the receiver of the event wants to keep the key; - otherwise returns FALSE -*/ - -/*! - \fn void TQKeyEvent::accept() - - Sets the accept flag of the key event object. - - Setting the accept parameter indicates that the receiver of the - event wants the key event. Unwanted key events are sent to the - parent widget. - - The accept flag is set by default. - - \sa ignore() -*/ - -/*! - \fn bool TQKeyEvent::isAutoRepeat() const - - Returns TRUE if this event comes from an auto-repeating key and - FALSE if it comes from an initial key press. - - Note that if the event is a multiple-key compressed event that is - partly due to auto-repeat, this function could return either TRUE - or FALSE indeterminately. -*/ - -/*! - \fn int TQKeyEvent::count() const - - Returns the number of single keys for this event. If text() is not - empty, this is simply the length of the string. - - \sa TQWidget::setKeyCompression() -*/ - -/*! - \fn void TQKeyEvent::ignore() - - Clears the accept flag parameter of the key event object. - - Clearing the accept parameter indicates that the event receiver - does not want the key event. Unwanted key events are sent to the - parent widget. - - The accept flag is set by default. - - \sa accept() -*/ - -/*! - \enum TQt::Key - - The key names used by TQt. - - \value Key_Escape - \value Key_Tab - \value Key_Backtab - \value Key_Backspace - \value Key_Return - \value Key_Enter - \value Key_Insert - \value Key_Delete - \value Key_Pause - \value Key_Print - \value Key_SysReq - \value Key_Home - \value Key_End - \value Key_Left - \value Key_Up - \value Key_Right - \value Key_Down - \value Key_Prior - \value Key_Next - \value Key_Shift - \value Key_Control - \value Key_Meta - \value Key_Alt - \value Key_CapsLock - \value Key_NumLock - \value Key_ScrollLock - \value Key_Clear - \value Key_F1 - \value Key_F2 - \value Key_F3 - \value Key_F4 - \value Key_F5 - \value Key_F6 - \value Key_F7 - \value Key_F8 - \value Key_F9 - \value Key_F10 - \value Key_F11 - \value Key_F12 - \value Key_F13 - \value Key_F14 - \value Key_F15 - \value Key_F16 - \value Key_F17 - \value Key_F18 - \value Key_F19 - \value Key_F20 - \value Key_F21 - \value Key_F22 - \value Key_F23 - \value Key_F24 - \value Key_F25 - \value Key_F26 - \value Key_F27 - \value Key_F28 - \value Key_F29 - \value Key_F30 - \value Key_F31 - \value Key_F32 - \value Key_F33 - \value Key_F34 - \value Key_F35 - \value Key_Super_L - \value Key_Super_R - \value Key_Menu - \value Key_Hyper_L - \value Key_Hyper_R - \value Key_Help - \value Key_Space - \value Key_Any - \value Key_Exclam - \value Key_QuoteDbl - \value Key_NumberSign - \value Key_Dollar - \value Key_Percent - \value Key_Ampersand - \value Key_Apostrophe - \value Key_ParenLeft - \value Key_ParenRight - \value Key_Asterisk - \value Key_Plus - \value Key_Comma - \value Key_Minus - \value Key_Period - \value Key_Slash - \value Key_0 - \value Key_1 - \value Key_2 - \value Key_3 - \value Key_4 - \value Key_5 - \value Key_6 - \value Key_7 - \value Key_8 - \value Key_9 - \value Key_Colon - \value Key_Semicolon - \value Key_Less - \value Key_Equal - \value Key_Greater - \value Key_Question - \value Key_At - \value Key_A - \value Key_B - \value Key_C - \value Key_D - \value Key_E - \value Key_F - \value Key_G - \value Key_H - \value Key_I - \value Key_J - \value Key_K - \value Key_L - \value Key_M - \value Key_N - \value Key_O - \value Key_P - \value Key_Q - \value Key_R - \value Key_S - \value Key_T - \value Key_U - \value Key_V - \value Key_W - \value Key_X - \value Key_Y - \value Key_Z - \value Key_BracketLeft - \value Key_Backslash - \value Key_BracketRight - \value Key_AsciiCircum - \value Key_Underscore - \value Key_QuoteLeft - \value Key_BraceLeft - \value Key_Bar - \value Key_BraceRight - \value Key_AsciiTilde - - \value Key_nobreakspace - \value Key_exclamdown - \value Key_cent - \value Key_sterling - \value Key_currency - \value Key_yen - \value Key_brokenbar - \value Key_section - \value Key_diaeresis - \value Key_copyright - \value Key_ordfeminine - \value Key_guillemotleft - \value Key_notsign - \value Key_hyphen - \value Key_registered - \value Key_macron - \value Key_degree - \value Key_plusminus - \value Key_twosuperior - \value Key_threesuperior - \value Key_acute - \value Key_mu - \value Key_paragraph - \value Key_periodcentered - \value Key_cedilla - \value Key_onesuperior - \value Key_masculine - \value Key_guillemotright - \value Key_onequarter - \value Key_onehalf - \value Key_threequarters - \value Key_questiondown - \value Key_Agrave - \value Key_Aacute - \value Key_Acircumflex - \value Key_Atilde - \value Key_Adiaeresis - \value Key_Aring - \value Key_AE - \value Key_Ccedilla - \value Key_Egrave - \value Key_Eacute - \value Key_Ecircumflex - \value Key_Ediaeresis - \value Key_Igrave - \value Key_Iacute - \value Key_Icircumflex - \value Key_Idiaeresis - \value Key_ETH - \value Key_Ntilde - \value Key_Ograve - \value Key_Oacute - \value Key_Ocircumflex - \value Key_Otilde - \value Key_Odiaeresis - \value Key_multiply - \value Key_Ooblique - \value Key_Ugrave - \value Key_Uacute - \value Key_Ucircumflex - \value Key_Udiaeresis - \value Key_Yacute - \value Key_THORN - \value Key_ssharp - \value Key_agrave - \value Key_aacute - \value Key_acircumflex - \value Key_atilde - \value Key_adiaeresis - \value Key_aring - \value Key_ae - \value Key_ccedilla - \value Key_egrave - \value Key_eacute - \value Key_ecircumflex - \value Key_ediaeresis - \value Key_igrave - \value Key_iacute - \value Key_icircumflex - \value Key_idiaeresis - \value Key_eth - \value Key_ntilde - \value Key_ograve - \value Key_oacute - \value Key_ocircumflex - \value Key_otilde - \value Key_odiaeresis - \value Key_division - \value Key_oslash - \value Key_ugrave - \value Key_uacute - \value Key_ucircumflex - \value Key_udiaeresis - \value Key_yacute - \value Key_thorn - \value Key_ydiaeresis - - Multimedia keys - - \value Key_Back - \value Key_Forward - \value Key_Stop - \value Key_Refresh - - \value Key_VolumeDown - \value Key_VolumeMute - \value Key_VolumeUp - \value Key_BassBoost - \value Key_BassUp - \value Key_BassDown - \value Key_TrebleUp - \value Key_TrebleDown - - \value Key_MediaPlay - \value Key_MediaStop - \value Key_MediaPrev - \value Key_MediaNext - \value Key_MediaRecord - - \value Key_HomePage - \value Key_Favorites - \value Key_Search - \value Key_Standby - \value Key_OpenUrl - - \value Key_LaunchMail - \value Key_LaunchMedia - \value Key_Launch0 - \value Key_Launch1 - \value Key_Launch2 - \value Key_Launch3 - \value Key_Launch4 - \value Key_Launch5 - \value Key_Launch6 - \value Key_Launch7 - \value Key_Launch8 - \value Key_Launch9 - \value Key_LaunchA - \value Key_LaunchB - \value Key_LaunchC - \value Key_LaunchD - \value Key_LaunchE - \value Key_LaunchF - \value Key_MonBrightnessUp - \value Key_MonBrightnessDown - \value Key_KeyboardLightOnOff - \value Key_KeyboardBrightnessUp - \value Key_KeyboardBrightnessDown - - \value Key_MediaLast - - \value Key_unknown - - \value Key_Direction_L internal use only - \value Key_Direction_R internal use only - -*/ - - -/*! - \class TQFocusEvent ntqevent.h - \brief The TQFocusEvent class contains event parameters for widget focus - events. - - \ingroup events - - Focus events are sent to widgets when the keyboard input focus - changes. Focus events occur due to mouse actions, keypresses (e.g. - Tab or Backtab), the window system, popup menus, keyboard - shortcuts or other application specific reasons. The reason for a - particular focus event is returned by reason() in the appropriate - event handler. - - The event handlers TQWidget::focusInEvent() and - TQWidget::focusOutEvent() receive focus events. - - Use setReason() to set the reason for all focus events, and - resetReason() to set the reason for all focus events to the reason - in force before the last setReason() call. - - \sa TQWidget::setFocus(), TQWidget::setFocusPolicy() -*/ - -/*! - \fn TQFocusEvent::TQFocusEvent( Type type ) - - Constructs a focus event object. - - The \a type parameter must be either \c TQEvent::FocusIn or \c - TQEvent::FocusOut. -*/ - - - -TQFocusEvent::Reason TQFocusEvent::m_reason = TQFocusEvent::Other; -TQFocusEvent::Reason TQFocusEvent::prev_reason = TQFocusEvent::Other; - - -/*! - \enum TQFocusEvent::Reason - - This enum specifies why the focus changed. - - \value Mouse because of a mouse action. - \value Tab because of a Tab press. - \value Backtab because of a Backtab press - (possibly including Shift/Control, e.g. Shift+Tab). - \value ActiveWindow because the window system made this window (in)active. - \value Popup because the application opened/closed a popup that grabbed/released focus. - \value Shortcut because of a keyboard shortcut. - \value Other any other reason, usually application-specific. - - See the \link focus.html keyboard focus overview\endlink for more - about focus. -*/ - -/*! - Returns the reason for this focus event. - - \sa setReason() - */ -TQFocusEvent::Reason TQFocusEvent::reason() -{ - return m_reason; -} - -/*! - Sets the reason for all future focus events to \a reason. - - \sa reason(), resetReason() - */ -void TQFocusEvent::setReason( Reason reason ) -{ - prev_reason = m_reason; - m_reason = reason; -} - -/*! - Resets the reason for all future focus events to the value before - the last setReason() call. - - \sa reason(), setReason() - */ -void TQFocusEvent::resetReason() -{ - m_reason = prev_reason; -} - -/*! - \fn bool TQFocusEvent::gotFocus() const - - Returns TRUE if the widget received the text input focus; - otherwise returns FALSE. -*/ - -/*! - \fn bool TQFocusEvent::lostFocus() const - - Returns TRUE if the widget lost the text input focus; otherwise - returns FALSE. -*/ - - -/*! - \class TQPaintEvent ntqevent.h - \brief The TQPaintEvent class contains event parameters for paint events. - - \ingroup events - - Paint events are sent to widgets that need to update themselves, - for instance when part of a widget is exposed because a covering - widget is moved. - - The event contains a region() that needs to be updated, and a - rect() that is the bounding rectangle of that region. Both are - provided because many widgets can't make much use of region(), and - rect() can be much faster than region().boundingRect(). Painting - is clipped to region() during processing of a paint event. - - The erased() function returns TRUE if the region() has been - cleared to the widget's background (see - TQWidget::backgroundMode()), and FALSE if the region's contents are - arbitrary. - - \sa TQPainter TQWidget::update() TQWidget::repaint() - TQWidget::paintEvent() TQWidget::backgroundMode() TQRegion -*/ - -/*! - \fn TQPaintEvent::TQPaintEvent( const TQRegion &paintRegion, bool erased=TRUE ) - - Constructs a paint event object with the region that should be - updated. The region is given by \a paintRegion. If \a erased is - TRUE the region will be cleared before repainting. -*/ - -/*! - \fn TQPaintEvent::TQPaintEvent( const TQRect &paintRect, bool erased=TRUE ) - - Constructs a paint event object with the rectangle that should be - updated. The region is also given by \a paintRect. If \a erased is - TRUE the region will be cleared before repainting. -*/ - -/*! - \fn TQPaintEvent::TQPaintEvent( const TQRegion &paintRegion, const TQRect &paintRect, bool erased=TRUE ) - - Constructs a paint event object with the rectangle \a paintRect - that should be updated. The region is given by \a paintRegion. If - \a erased is TRUE the region will be cleared before repainting. -*/ - -/*! - \fn const TQRect &TQPaintEvent::rect() const - - Returns the rectangle that should be updated. - - \sa region(), TQPainter::setClipRect() -*/ - -/*! - \fn const TQRegion &TQPaintEvent::region() const - - Returns the region that should be updated. - - \sa rect(), TQPainter::setClipRegion() -*/ - -/*! - \fn bool TQPaintEvent::erased() const - - Returns TRUE if the paint event region (or rectangle) has been - erased with the widget's background; otherwise returns FALSE. -*/ - -/*! - \class TQMoveEvent ntqevent.h - \brief The TQMoveEvent class contains event parameters for move events. - - \ingroup events - - Move events are sent to widgets that have been moved to a new position - relative to their parent. - - The event handler TQWidget::moveEvent() receives move events. - - \sa TQWidget::move(), TQWidget::setGeometry() -*/ - -/*! - \fn TQMoveEvent::TQMoveEvent( const TQPoint &pos, const TQPoint &oldPos ) - - Constructs a move event with the new and old widget positions, \a - pos and \a oldPos respectively. -*/ - -/*! - \fn const TQPoint &TQMoveEvent::pos() const - - Returns the new position of the widget. This excludes the window - frame for top level widgets. -*/ - -/*! - \fn const TQPoint &TQMoveEvent::oldPos() const - - Returns the old position of the widget. -*/ - - -/*! - \class TQResizeEvent ntqevent.h - \brief The TQResizeEvent class contains event parameters for resize events. - - \ingroup events - - Resize events are sent to widgets that have been resized. - - The event handler TQWidget::resizeEvent() receives resize events. - - \sa TQWidget::resize(), TQWidget::setGeometry() -*/ - -/*! - \fn TQResizeEvent::TQResizeEvent( const TQSize &size, const TQSize &oldSize ) - - Constructs a resize event with the new and old widget sizes, \a - size and \a oldSize respectively. -*/ - -/*! - \fn const TQSize &TQResizeEvent::size() const - - Returns the new size of the widget, which is the same as - TQWidget::size(). -*/ - -/*! - \fn const TQSize &TQResizeEvent::oldSize() const - - Returns the old size of the widget. -*/ - - -/*! - \class TQCloseEvent ntqevent.h - \brief The TQCloseEvent class contains parameters that describe a close event. - - \ingroup events - - Close events are sent to widgets that the user wants to close, - usually by choosing "Close" from the window menu, or by clicking - the `X' titlebar button. They are also sent when you call - TQWidget::close() to close a widget programmatically. - - Close events contain a flag that indicates whether the receiver - wants the widget to be closed or not. When a widget accepts the - close event, it is hidden (and destroyed if it was created with - the \c WDestructiveClose flag). If it refuses to accept the close - event nothing happens. (Under X11 it is possible that the window - manager will forcibly close the window; but at the time of writing - we are not aware of any window manager that does this.) - - The application's main widget -- TQApplication::mainWidget() -- - is a special case. When it accepts the close event, TQt leaves the - main event loop and the application is immediately terminated - (i.e. it returns from the call to TQApplication::exec() in the - main() function). - - The event handler TQWidget::closeEvent() receives close events. The - default implementation of this event handler accepts the close - event. If you do not want your widget to be hidden, or want some - special handing, you should reimplement the event handler. - - The \link simple-application.html#closeEvent closeEvent() in the - Application Walkthrough\endlink shows a close event handler that - asks whether to save a document before closing. - - If you want the widget to be deleted when it is closed, create it - with the \c WDestructiveClose widget flag. This is very useful for - independent top-level windows in a multi-window application. - - \l{TQObject}s emits the \link TQObject::destroyed() - destroyed()\endlink signal when they are deleted. - - If the last top-level window is closed, the - TQApplication::lastWindowClosed() signal is emitted. - - The isAccepted() function returns TRUE if the event's receiver has - agreed to close the widget; call accept() to agree to close the - widget and call ignore() if the receiver of this event does not - want the widget to be closed. - - \sa TQWidget::close(), TQWidget::hide(), TQObject::destroyed(), - TQApplication::setMainWidget(), TQApplication::lastWindowClosed(), - TQApplication::exec(), TQApplication::quit() -*/ - -/*! - \fn TQCloseEvent::TQCloseEvent() - - Constructs a close event object with the accept parameter flag set - to FALSE. - - \sa accept() -*/ - -/*! - \fn bool TQCloseEvent::isAccepted() const - - Returns TRUE if the receiver of the event has agreed to close the - widget; otherwise returns FALSE. - - \sa accept(), ignore() -*/ - -/*! - \fn void TQCloseEvent::accept() - - Sets the accept flag of the close event object. - - Setting the accept flag indicates that the receiver of this event - agrees to close the widget. - - The accept flag is \e not set by default. - - If you choose to accept in TQWidget::closeEvent(), the widget will - be hidden. If the widget's \c WDestructiveClose flag is set, it - will also be destroyed. - - \sa ignore(), TQWidget::hide() -*/ - -/*! - \fn void TQCloseEvent::ignore() - - Clears the accept flag of the close event object. - - Clearing the accept flag indicates that the receiver of this event - does not want the widget to be closed. - - The close event is constructed with the accept flag cleared. - - \sa accept() -*/ - -/*! - \class TQIconDragEvent ntqevent.h - \brief The TQIconDragEvent class signals that a main icon drag has begun. - - \ingroup events - - Icon drag events are sent to widgets when the main icon of a window has been dragged away. - On Mac OS X this is fired when the proxy icon of a window is dragged off titlebar, in response to - this event is is normal to begin using drag and drop. -*/ - -/*! - \fn TQIconDragEvent::TQIconDragEvent() - - Constructs an icon drag event object with the accept parameter - flag set to FALSE. - - \sa accept() -*/ - -/*! - \fn bool TQIconDragEvent::isAccepted() const - - Returns TRUE if the receiver of the event has started a drag and - drop operation; otherwise returns FALSE. - - \sa accept(), ignore() -*/ - -/*! - \fn void TQIconDragEvent::accept() - - Sets the accept flag of the icon drag event object. - - Setting the accept flag indicates that the receiver of this event - has started a drag and drop oeration. - - The accept flag is \e not set by default. - - \sa ignore(), TQWidget::hide() -*/ - -/*! - \fn void TQIconDragEvent::ignore() - - Clears the accept flag of the icon drag object. - - Clearing the accept flag indicates that the receiver of this event - has not handled the icon drag as a result other events can be sent. - - The icon drag event is constructed with the accept flag cleared. - - \sa accept() -*/ - -/*! - \class TQContextMenuEvent ntqevent.h - \brief The TQContextMenuEvent class contains parameters that describe a context menu event. - - \ingroup events - - Context menu events are sent to widgets when a user triggers a - context menu. What triggers this is platform dependent. For - example, on Windows, pressing the menu button or releasing the - right mouse button will cause this event to be sent. - - When this event occurs it is customary to show a TQPopupMenu with a - context menu, if this is relevant to the context. - - Context menu events contain a special accept flag that indicates - whether the receiver accepted the event. If the event handler does - not accept the event, then whatever triggered the event will be - handled as a regular input event if possible. - - \sa TQPopupMenu -*/ - -/*! - \fn TQContextMenuEvent::TQContextMenuEvent( Reason reason, const TQPoint &pos, const TQPoint &globalPos, int state ) - - Constructs a context menu event object with the accept parameter - flag set to FALSE. - - The \a reason parameter must be \c TQContextMenuEvent::Mouse or \c - TQContextMenuEvent::Keyboard. - - The \a pos parameter specifies the mouse position relative to the - receiving widget. \a globalPos is the mouse position in absolute - coordinates. \a state is the ButtonState at the time of the event. -*/ - - -/*! - \fn TQContextMenuEvent::TQContextMenuEvent( Reason reason, const TQPoint &pos, int state ) - - Constructs a context menu event object with the accept parameter - flag set to FALSE. - - The \a reason parameter must be \c TQContextMenuEvent::Mouse or \c - TQContextMenuEvent::Keyboard. - - The \a pos parameter specifies the mouse position relative to the - receiving widget. \a state is the ButtonState at the time of the - event. - - The globalPos() is initialized to TQCursor::pos(), which may not be - appropriate. Use the other constructor to specify the global - position explicitly. -*/ - -TQContextMenuEvent::TQContextMenuEvent( Reason reason, const TQPoint &pos, int state ) - : TQEvent( ContextMenu ), p( pos ), accpt(TRUE), consum(TRUE), - reas( reason ), s((ushort)state) -{ - gp = TQCursor::pos(); -} - -/*! - \fn const TQPoint &TQContextMenuEvent::pos() const - - Returns the position of the mouse pointer relative to the widget - that received the event. - - \sa x(), y(), globalPos() -*/ - -/*! - \fn int TQContextMenuEvent::x() const - - Returns the x-position of the mouse pointer, relative to the - widget that received the event. - - \sa y(), pos() -*/ - -/*! - \fn int TQContextMenuEvent::y() const - - Returns the y-position of the mouse pointer, relative to the - widget that received the event. - - \sa x(), pos() -*/ - -/*! - \fn const TQPoint &TQContextMenuEvent::globalPos() const - - Returns the global position of the mouse pointer at the time of - the event. - - \sa x(), y(), pos() -*/ - -/*! - \fn int TQContextMenuEvent::globalX() const - - Returns the global x-position of the mouse pointer at the time of - the event. - - \sa globalY(), globalPos() -*/ - -/*! - \fn int TQContextMenuEvent::globalY() const - - Returns the global y-position of the mouse pointer at the time of - the event. - - \sa globalX(), globalPos() -*/ - -/*! - \fn ButtonState TQContextMenuEvent::state() const - - Returns the button state (a combination of mouse buttons and - keyboard modifiers), i.e. what buttons and keys were being - pressed immediately before the event was generated. - - The returned value is \c LeftButton, \c RightButton, \c MidButton, - \c ShiftButton, \c ControlButton and \c AltButton OR'ed together. -*/ - -/*! - \fn bool TQContextMenuEvent::isConsumed() const - - Returns TRUE (which stops propagation of the event) if the - receiver has blocked the event; otherwise returns FALSE. - - \sa accept(), ignore(), consume() -*/ - -/*! - \fn void TQContextMenuEvent::consume() - - Sets the consume flag of the context event object. - - Setting the consume flag indicates that the receiver of this event - does not want the event to be propagated further (i.e. not sent to - parent classes.) - - The consumed flag is not set by default. - - \sa ignore() accept() -*/ - -/*! - \fn bool TQContextMenuEvent::isAccepted() const - - Returns TRUE if the receiver has processed the event; otherwise - returns FALSE. - - \sa accept(), ignore(), consume() -*/ - -/*! - \fn void TQContextMenuEvent::accept() - - Sets the accept flag of the context event object. - - Setting the accept flag indicates that the receiver of this event - has processed the event. Processing the event means you did - something with it and it will be implicitly consumed. - - The accept flag is not set by default. - - \sa ignore() consume() -*/ - -/*! - \fn void TQContextMenuEvent::ignore() - - Clears the accept flag of the context event object. - - Clearing the accept flag indicates that the receiver of this event - does not need to show a context menu. This will implicitly remove - the consumed flag as well. - - The accept flag is not set by default. - - \sa accept() consume() -*/ - -/*! - \enum TQContextMenuEvent::Reason - - This enum describes the reason the ContextMenuEvent was sent. The - values are: - - \value Mouse The mouse caused the event to be sent. Normally this - means the right mouse button was clicked, but this is platform - specific. - - \value Keyboard The keyboard caused this event to be sent. On - Windows this means the menu button was pressed. - - \value Other The event was sent by some other means (i.e. not by - the mouse or keyboard). -*/ - - -/*! - \fn TQContextMenuEvent::Reason TQContextMenuEvent::reason() const - - Returns the reason for this context event. -*/ - - -/*! - \class TQIMEvent ntqevent.h - \brief The TQIMEvent class provides parameters for input method events. - - \ingroup events - - Input method events are sent to widgets when an input method is - used to enter text into a widget. Input methods are widely used to - enter text in Asian and other complex languages. - - The events are of interest to widgets that accept keyboard input - and want to be able to correctly handle complex languages. Text - input in such languages is usually a three step process. - - \list 1 - \i Starting to Compose
- When the user presses the first key on a keyboard an input context - is created. This input context will contain a string with the - typed characters. - - \i Composing
- With every new key pressed, the input method will try to create a - matching string for the text typed so far. While the input context - is active, the user can only move the cursor inside the string - belonging to this input context. - - \i Completing
- At some point, e.g. when the user presses the Spacebar, they get - to this stage, where they can choose from a number of strings that - match the text they have typed so far. The user can press Enter to - confirm their choice or Escape to cancel the input; in either case - the input context will be closed. - \endlist - - Note that the particular key presses used for a given input - context may differ from those we've mentioned here, i.e. they may - not be Spacebar, Enter and Escape. - - These three stages are represented by three different types of - events. The IMStartEvent, IMComposeEvent and IMEndEvent. When a - new input context is created, an IMStartEvent will be sent to the - widget and delivered to the \l TQWidget::imStartEvent() function. - The widget can then update internal data structures to reflect - this. - - After this, an IMComposeEvent will be sent to the widget for - every key the user presses. It will contain the current - composition string the widget has to show and the current cursor - position within the composition string. This string is temporary - and can change with every key the user types, so the widget will - need to store the state before the composition started (the state - it had when it received the IMStartEvent). IMComposeEvents will be - delivered to the \l TQWidget::imComposeEvent() function. - - Usually, widgets try to mark the part of the text that is part of - the current composition in a way that is visible to the user. A - commonly used visual cue is to use a dotted underline. - - After the user has selected the final string, an IMEndEvent will - be sent to the widget. The event contains the final string the - user selected, and could be empty if they canceled the - composition. This string should be accepted as the final text the - user entered, and the intermediate composition string should be - cleared. These events are delivered to \l TQWidget::imEndEvent(). - - If the user clicks another widget, taking the focus out of the - widget where the composition is taking place the IMEndEvent will - be sent and the string it holds will be the result of the - composition up to that point (which may be an empty string). -*/ - -/*! - \fn TQIMEvent::TQIMEvent( Type type, const TQString &text, int cursorPosition ) - - Constructs a new TQIMEvent with the accept flag set to FALSE. \a - type can be one of TQEvent::IMStartEvent, TQEvent::IMComposeEvent - or TQEvent::IMEndEvent. \a text contains the current compostion - string and \a cursorPosition the current position of the cursor - inside \a text. -*/ - -/*! - \fn const TQString &TQIMEvent::text() const - - Returns the composition text. This is a null string for an - IMStartEvent, and contains the final accepted string (which may be - empty) in the IMEndEvent. -*/ - -/*! - \fn int TQIMEvent::cursorPos() const - - Returns the current cursor position inside the composition string. - Will return -1 for IMStartEvent and IMEndEvent. -*/ - -/*! - \fn int TQIMEvent::selectionLength() const - - Returns the number of characters in the composition string ( - starting at cursorPos() ) that should be marked as selected by the - input widget receiving the event. - Will return 0 for IMStartEvent and IMEndEvent. -*/ - -/*! - \fn bool TQIMEvent::isAccepted() const - - Returns TRUE if the receiver of the event processed the event; - otherwise returns FALSE. -*/ - -/*! - \fn void TQIMEvent::accept() - - Sets the accept flag of the input method event object. - - Setting the accept parameter indicates that the receiver of the - event processed the input method event. - - The accept flag is not set by default. - - \sa ignore() -*/ - - -/*! - \fn void TQIMEvent::ignore() - - Clears the accept flag parameter of the input method event object. - - Clearing the accept parameter indicates that the event receiver - does not want the input method event. - - The accept flag is cleared by default. - - \sa accept() -*/ - -/*! - \class TQTabletEvent ntqevent.h - \brief The TQTabletEvent class contains parameters that describe a Tablet - event. - - \ingroup events - - Tablet Events are generated from a Wacom© tablet. Most of - the time you will want to deal with events from the tablet as if - they were events from a mouse, for example retrieving the position - with x(), y(), pos(), globalX(), globalY() and globalPos(). In - some situations you may wish to retrieve the extra information - provided by the tablet device driver, for example, you might want - to adjust color brightness based on pressure. TQTabletEvent allows - you to get the pressure(), the xTilt() and yTilt(), as well as the - type of device being used with device() (see \l{TabletDevice}). - - A tablet event contains a special accept flag that indicates - whether the receiver wants the event. You should call - TQTabletEvent::accept() if you handle the tablet event; otherwise - it will be sent to the parent widget. - - The TQWidget::setEnabled() function can be used to enable or - disable mouse and keyboard events for a widget. - - The event handler TQWidget::tabletEvent() receives all three types of tablet - events. TQt will first send a tabletEvent and then, if it is not accepted, - it will send a mouse event. This allows applications that don't utilize - tablets to use a tablet like a mouse while also enabling those who want to - use both tablets and mouses differently. - -*/ - -/*! - \enum TQTabletEvent::TabletDevice - - This enum defines what type of device is generating the event. - - \value NoDevice No device, or an unknown device. - \value Puck A Puck (a device that is similar to a flat mouse with - a transparent circle with cross-hairs). - \value Stylus A Stylus (the narrow end of the pen). - \value Eraser An Eraser (the broad end of the pen). - \omit - \value Menu A menu button was pressed (currently unimplemented). -*/ - -/*! - \fn TQTabletEvent::TQTabletEvent( Type t, const TQPoint &pos, - const TQPoint &globalPos, int device, - int pressure, int xTilt, int yTilt, - const TQPair &uId ) - Construct a tablet event of type \a t. The position of when the event occurred is given - int \a pos and \a globalPos. \a device contains the \link TabletDevice device type\endlink, - \a pressure contains the pressure exerted on the \a device, \a xTilt and \a yTilt contain - \a device's degree of tilt from the X and Y axis respectively. The \a uId contains an - event id. - - On Irix, \a globalPos will contain the high-resolution coordinates received from the - tablet device driver, instead of from the windowing system. - - \sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt() -*/ - -TQTabletEvent::TQTabletEvent( Type t, const TQPoint &pos, const TQPoint &globalPos, int device, - int pressure, int xTilt, int yTilt, - const TQPair &uId ) - : TQEvent( t ), - mPos( pos ), - mGPos( globalPos ), - mDev( device ), - mPress( pressure ), - mXT( xTilt ), - mYT( yTilt ), - mType( uId.first ), - mPhy( uId.second ), - mbAcc(TRUE) -{} - -/*! - \obsolete - \fn TQTabletEvent::TQTabletEvent( const TQPoint &pos, const TQPoint &globalPos, int device, int pressure, int xTilt, int yTilt, const TQPair &uId ) - - Constructs a tablet event object. The position when the event - occurred is is given in \a pos and \a globalPos. \a device - contains the \link TabletDevice device type\endlink, \a pressure - contains the pressure exerted on the \a device, \a xTilt and \a - yTilt contain the \a device's degrees of tilt from the X and Y - axis respectively. The \a uId contains an event id. - - On Irix, \a globalPos will contain the high-resolution coordinates - received from the tablet device driver, instead of from the - windowing system. - - \sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt() -*/ - -/*! - \fn TabletDevices TQTabletEvent::device() const - - Returns the type of device that generated the event. Useful if you - want one end of the pen to do something different than the other. - - \sa TabletDevice -*/ - -/*! - \fn int TQTabletEvent::pressure() const - - Returns the pressure that is exerted on the device. This number is - a value from 0 (no pressure) to 255 (maximum pressure). The - pressure is always scaled to be within this range no matter how - many pressure levels the underlying hardware supports. -*/ - -/*! - \fn int TQTabletEvent::xTilt() const - - Returns the difference from the perpendicular in the X Axis. - Positive values are towards the tablet's physical right. The angle - is in the range -60 to +60 degrees. - - \sa yTilt() -*/ - -/*! - \fn int TQTabletEvent::yTilt() const - - Returns the difference from the perpendicular in the Y Axis. - Positive values are towards the bottom of the tablet. The angle is - within the range -60 to +60 degrees. - - \sa xTilt() -*/ - -/*! - \fn const TQPoint &TQTabletEvent::pos() const - - Returns the position of the device, relative to the widget that - received the event. - - If you move widgets around in response to mouse events, use - globalPos() instead of this function. - - \sa x(), y(), globalPos() -*/ - -/*! - \fn int TQTabletEvent::x() const - - Returns the x-position of the device, relative to the widget that - received the event. - - \sa y(), pos() -*/ - -/*! - \fn int TQTabletEvent::y() const - - Returns the y-position of the device, relative to the widget that - received the event. - - \sa x(), pos() -*/ - -/*! - \fn const TQPoint &TQTabletEvent::globalPos() const - - Returns the global position of the device \e{at the time of the - event}. This is important on asynchronous windows systems like X11; - whenever you move your widgets around in response to mouse events, - globalPos() can differ significantly from the current position - TQCursor::pos(). - - \sa globalX(), globalY() -*/ - -/*! - \fn int TQTabletEvent::globalX() const - - Returns the global x-position of the mouse pointer at the time of - the event. - - \sa globalY(), globalPos() -*/ - -/*! - \fn int TQTabletEvent::globalY() const - - Returns the global y-position of the mouse pointer at the time of - the event. - - \sa globalX(), globalPos() -*/ - -/*! - \fn bool TQTabletEvent::isAccepted() const - - Returns TRUE if the receiver of the event handles the tablet - event; otherwise returns FALSE. -*/ - -/*! - \fn void TQTabletEvent::accept() - - Sets the accept flag of the tablet event object. - - Setting the accept flag indicates that the receiver of the event - wants the tablet event. Unwanted tablet events are sent to the - parent widget. - - The accept flag is set by default. - - \sa ignore() -*/ - -/*! - \fn void TQTabletEvent::ignore() - - Clears the accept flag parameter of the tablet event object. - - Clearing the accept flag indicates that the event receiver does - not want the tablet event. Unwanted tablet events are sent to the - parent widget. - - The accept flag is set by default. - - \sa accept() -*/ - -/*! - \fn TQPair TQTabletEvent::uniqueId() - - Returns a unique ID for the current device. It is possible to - generate a unique ID for any Wacom© device. This makes it - possible to differentiate between multiple devices being used at - the same time on the tablet. The \c first member contains a value - for the type, the \c second member contains a physical ID obtained - from the device. Each combination of these values is unique. Note: - for different platforms, the \c first value is different due to - different driver implementations. -*/ - -/*! - \class TQChildEvent ntqevent.h - \brief The TQChildEvent class contains event parameters for child object - events. - - \ingroup events - - Child events are sent to objects when children are inserted or - removed. - - A \c ChildRemoved event is sent immediately, but a \c - ChildInserted event is \e posted (with TQApplication::postEvent()). - - Note that if a child is removed immediately after it is inserted, - the \c ChildInserted event may be suppressed, but the \c - ChildRemoved event will always be sent. In this case there will be - a \c ChildRemoved event without a corresponding \c ChildInserted - event. - - The handler for these events is TQObject::childEvent(). -*/ - -/*! - \fn TQChildEvent::TQChildEvent( Type type, TQObject *child ) - - Constructs a child event object. The \a child is the object that - is to be removed or inserted. - - The \a type parameter must be either \c TQEvent::ChildInserted or - \c TQEvent::ChildRemoved. -*/ - -/*! - \fn TQObject *TQChildEvent::child() const - - Returns the child widget that was inserted or removed. -*/ - -/*! - \fn bool TQChildEvent::inserted() const - - Returns TRUE if the widget received a new child; otherwise returns - FALSE. -*/ - -/*! - \fn bool TQChildEvent::removed() const - - Returns TRUE if the object lost a child; otherwise returns FALSE. -*/ - - - - -/*! - \class TQCustomEvent ntqevent.h - \brief The TQCustomEvent class provides support for custom events. - - \ingroup events - - TQCustomEvent is a generic event class for user-defined events. - User defined events can be sent to widgets or other TQObject - instances using TQApplication::postEvent() or - TQApplication::sendEvent(). Subclasses of TQObject can easily - receive custom events by implementing the TQObject::customEvent() - event handler function. - - TQCustomEvent objects should be created with a type ID that - uniquely identifies the event type. To avoid clashes with the - TQt-defined events types, the value should be at least as large as - the value of the "User" entry in the TQEvent::Type enum. - - TQCustomEvent contains a generic void* data member that may be used - for transferring event-specific data to the receiver. Note that - since events are normally delivered asynchronously, the data - pointer, if used, must remain valid until the event has been - received and processed. - - TQCustomEvent can be used as-is for simple user-defined event - types, but normally you will want to make a subclass of it for - your event types. In a subclass, you can add data members that are - suitable for your event type. - - Example: - \code - class ColorChangeEvent : public TQCustomEvent - { - public: - ColorChangeEvent( TQColor color ) - : TQCustomEvent( 65432 ), c( color ) {} - TQColor color() const { return c; } - private: - TQColor c; - }; - - // To send an event of this custom event type: - - ColorChangeEvent* ce = new ColorChangeEvent( blue ); - TQApplication::postEvent( receiver, ce ); // TQt will delete it when done - - // To receive an event of this custom event type: - - void MyWidget::customEvent( TQCustomEvent * e ) - { - if ( e->type() == 65432 ) { // It must be a ColorChangeEvent - ColorChangeEvent* ce = (ColorChangeEvent*)e; - newColor = ce->color(); - } - } - \endcode - - \sa TQWidget::customEvent(), TQApplication::notify() -*/ - - -/*! - Constructs a custom event object with event type \a type. The - value of \a type must be at least as large as TQEvent::User. The - data pointer is set to 0. -*/ - -TQCustomEvent::TQCustomEvent( int type ) - : TQEvent( (TQEvent::Type)type ), d( 0 ) -{ -} - - -/*! - \fn TQCustomEvent::TQCustomEvent( Type type, void *data ) - - Constructs a custom event object with the event type \a type and a - pointer to \a data. (Note that any int value may safely be cast to - TQEvent::Type). -*/ - - -/*! - \fn void TQCustomEvent::setData( void* data ) - - Sets the generic data pointer to \a data. - - \sa data() -*/ - -/*! - \fn void *TQCustomEvent::data() const - - Returns a pointer to the generic event data. - - \sa setData() -*/ - - - -/*! - \fn TQDragMoveEvent::TQDragMoveEvent( const TQPoint& pos, Type type ) - - Creates a TQDragMoveEvent for which the mouse is at point \a pos, - and the event is of type \a type. - - \warning Do not create a TQDragMoveEvent yourself since these - objects rely on TQt's internal state. -*/ - -/*! - \fn void TQDragMoveEvent::accept( const TQRect & r ) - - The same as accept(), but also notifies that future moves will - also be acceptable if they remain within the rectangle \a r on the - widget: this can improve performance, but may also be ignored by - the underlying system. - - If the rectangle is \link TQRect::isEmpty() empty\endlink, then - drag move events will be sent continuously. This is useful if the - source is scrolling in a timer event. -*/ - -/*! - \fn void TQDragMoveEvent::ignore( const TQRect & r) - - The opposite of accept(const TQRect&), i.e. says that moves within - rectangle \a r are not acceptable (will be ignored). -*/ - -/*! - \fn TQRect TQDragMoveEvent::answerRect() const - - Returns the rectangle for which the acceptance of the move event - applies. -*/ - - - -/*! - \fn const TQPoint& TQDropEvent::pos() const - - Returns the position where the drop was made. -*/ - -/*! - \fn bool TQDropEvent::isAccepted () const - - Returns TRUE if the drop target accepts the event; otherwise - returns FALSE. -*/ - -/*! - \fn void TQDropEvent::accept(bool y=TRUE) - - Call this function to indicate whether the event provided data - which your widget processed. Set \a y to TRUE (the default) if - your widget could process the data, otherwise set \a y to FALSE. - To get the data, use encodedData(), or preferably, the decode() - methods of existing TQDragObject subclasses, such as - TQTextDrag::decode(), or your own subclasses. - - \sa acceptAction() -*/ - -/*! - \fn void TQDropEvent::acceptAction(bool y=TRUE) - - Call this to indicate that the action described by action() is - accepted (i.e. if \a y is TRUE, which is the default), not merely - the default copy action. If you call acceptAction(TRUE), there is - no need to also call accept(TRUE). -*/ - -/*! - \fn void TQDragMoveEvent::accept( bool y ) - \reimp - \internal - Remove in 3.0 -*/ - -/*! - \fn void TQDragMoveEvent::ignore() - \reimp - \internal - Remove in 3.0 -*/ - - -/*! - \enum TQDropEvent::Action - - This enum describes the action which a source requests that a - target perform with dropped data. - - \value Copy The default action. The source simply uses the data - provided in the operation. - \value Link The source should somehow create a link to the - location specified by the data. - \value Move The source should somehow move the object from the - location specified by the data to a new location. - \value Private The target has special knowledge of the MIME type, - which the source should respond to in a similar way to - a Copy. - \value UserAction The source and target can co-operate using - special actions. This feature is not currently - supported. - - The Link and Move actions only makes sense if the data is a - reference, for example, text/uri-list file lists (see TQUriDrag). -*/ - -/*! - \fn void TQDropEvent::setAction( Action a ) - - Sets the action to \a a. This is used internally, you should not - need to call this in your code: the \e source decides the action, - not the target. -*/ - -/*! - \fn Action TQDropEvent::action() const - - Returns the Action which the target is requesting to be performed - with the data. If your application understands the action and can - process the supplied data, call acceptAction(); if your - application can process the supplied data but can only perform the - Copy action, call accept(). -*/ - -/*! - \fn void TQDropEvent::ignore() - - The opposite of accept(), i.e. you have ignored the drop event. -*/ - -/*! - \fn bool TQDropEvent::isActionAccepted () const - - Returns TRUE if the drop action was accepted by the drop site; - otherwise returns FALSE. -*/ - - -/*! - \fn void TQDropEvent::setPoint (const TQPoint & np) - - Sets the drop to happen at point \a np. You do not normally need - to use this as it will be set internally before your widget - receives the drop event. -*/ // ### here too - what coordinate system? - - -/*! - \class TQDragEnterEvent ntqevent.h - \brief The TQDragEnterEvent class provides an event which is sent to the widget when a drag and drop first drags onto the widget. - - \ingroup events - \ingroup draganddrop - - This event is always immediately followed by a TQDragMoveEvent, so - you only need to respond to one or the other event. This class - inherits most of its functionality from TQDragMoveEvent, which in - turn inherits most of its functionality from TQDropEvent. - - \sa TQDragLeaveEvent, TQDragMoveEvent, TQDropEvent -*/ - -/*! - \fn TQDragEnterEvent::TQDragEnterEvent (const TQPoint & pos) - - Constructs a TQDragEnterEvent entering at the given point, \a pos. - - \warning Do not create a TQDragEnterEvent yourself since these - objects rely on TQt's internal state. -*/ - -/*! - \class TQDragLeaveEvent ntqevent.h - \brief The TQDragLeaveEvent class provides an event which is sent to the widget when a drag and drop leaves the widget. - - \ingroup events - \ingroup draganddrop - - This event is always preceded by a TQDragEnterEvent and a series of - \l{TQDragMoveEvent}s. It is not sent if a TQDropEvent is sent - instead. - - \sa TQDragEnterEvent, TQDragMoveEvent, TQDropEvent -*/ - -/*! - \fn TQDragLeaveEvent::TQDragLeaveEvent() - - Constructs a TQDragLeaveEvent. - - \warning Do not create a TQDragLeaveEvent yourself since these - objects rely on TQt's internal state. -*/ - -/*! - \class TQHideEvent ntqevent.h - \brief The TQHideEvent class provides an event which is sent after a widget is hidden. - - \ingroup events - - This event is sent just before TQWidget::hide() returns, and also - when a top-level window has been hidden (iconified) by the user. - - If spontaneous() is TRUE the event originated outside the - application, i.e. the user hid the window using the window manager - controls, either by iconifying the window or by switching to - another virtual desktop where the window isn't visible. The window - will become hidden but not withdrawn. If the window was iconified, - TQWidget::isMinimized() returns TRUE. - - \sa TQShowEvent -*/ - -/*! - \fn TQHideEvent::TQHideEvent() - - Constructs a TQHideEvent. -*/ - -/*! - \class TQShowEvent ntqevent.h - \brief The TQShowEvent class provides an event which is sent when a widget is shown. - - \ingroup events - - There are two kinds of show events: show events caused by the - window system (spontaneous) and internal show events. Spontaneous - show events are sent just after the window system shows the - window, including after a top-level window has been shown - (un-iconified) by the user. Internal show events are delivered - just before the widget becomes visible. - - \sa TQHideEvent -*/ - -/*! - \fn TQShowEvent::TQShowEvent() - - Constructs a TQShowEvent. -*/ - - -/*! - \fn TQByteArray TQDropEvent::data(const char* f) const - - \obsolete - - Use TQDropEvent::encodedData(). -*/ - - -/*! - Destroys the event. If it was \link - TQApplication::postEvent() posted \endlink, - it will be removed from the list of events to be posted. -*/ - -TQEvent::~TQEvent() -{ - if ( posted && tqApp ) - TQApplication::removePostedEvent( this ); -} diff --git a/src/kernel/qeventloop.cpp b/src/kernel/qeventloop.cpp deleted file mode 100644 index ce0f2bc82..000000000 --- a/src/kernel/qeventloop.cpp +++ /dev/null @@ -1,423 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQEventLoop class -** -** 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 "qeventloop_p.h" // includes qplatformdefs.h -#include "ntqeventloop.h" -#include "ntqapplication.h" -#include "tqdatetime.h" - -#ifdef TQT_THREAD_SUPPORT -# include "tqthread.h" -# include "private/tqthreadinstance_p.h" -#endif - -/*! - \class TQEventLoop - \brief The TQEventLoop class manages the event queue. - - \ingroup application - \ingroup events - - It receives events from the window system and other sources. It - then sends them to TQApplication for processing and delivery. - - TQEventLoop allows the application programmer to have more control - over event delivery. Programs that perform long operations can - call either processOneEvent() or processEvents() with various - ProcessEvent values OR'ed together to control which events should - be delivered. - - TQEventLoop also allows the integration of an external event loop - with the TQt event loop. The Motif Extension included with TQt - includes a reimplementation of TQEventLoop for merging TQt and Motif - events together. - - To use your own instance of TQEventLoop or TQEventLoop subclass create - it before you create the TQApplication object. -*/ - -/*! \enum TQEventLoop::ProcessEvents - - This enum controls the types of events processed by the - processEvents() functions. - - \value AllEvents - All events are processed - \value ExcludeUserInput - Do not process user input events. - ( ButtonPress, KeyPress, etc. ) - \value ExcludeSocketNotifiers - Do not process socket notifier - events. - \value WaitForMore - Wait for events if no pending events - are available. - - \sa processEvents() -*/ - -/*! \enum TQEventLoop::ProcessEventsFlags - A \c typedef to allow various ProcessEvents values to be OR'ed together. - - \sa ProcessEvents - */ - -/*! - Creates a TQEventLoop object, this object becomes the global event loop object. - There can only be one event loop object. The TQEventLoop is usually constructed - by calling TQApplication::eventLoop(). To create your own event loop object create - it before you instantiate the TQApplication object. - - The \a parent and \a name arguments are passed on to the TQObject constructor. -*/ -TQEventLoop::TQEventLoop( TQObject *parent, const char *name ) - : TQObject( parent, name ) -{ -#if defined(QT_CHECK_STATE) - if ( TQApplication::currentEventLoop() ) - tqFatal( "TQEventLoop: there must be only one event loop object per thread. \nIf this is supposed to be the main GUI event loop, construct it before TQApplication." ); -#ifdef TQT_THREAD_SUPPORT - if (!TQThread::currentThreadObject()) { - tqFatal( "TQEventLoop: this object can only be used in threads constructed via TQThread." ); - } -#endif // TQT_THREAD_SUPPORT -#endif // QT_CHECK_STATE - - d = new TQEventLoopPrivate; - - init(); - -#ifdef TQT_THREAD_SUPPORT - TQThread* thread = TQThread::currentThreadObject(); - if (thread) { - if (thread->d) { - thread->d->eventLoop = this; - } - } -#else - TQApplication::eventloop = this; -#endif -} - -/*! - Destructs the TQEventLoop object. -*/ -TQEventLoop::~TQEventLoop() -{ - cleanup(); - delete d; -#ifdef TQT_THREAD_SUPPORT - TQThread* thread = TQThread::currentThreadObject(); - if (thread) { - if (thread->d) { - thread->d->eventLoop = 0; - } - } -#else - TQApplication::eventloop = 0; -#endif -} - -/*! - Enters the main event loop and waits until exit() is called, and - returns the value that was set to exit(). - - 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 TQApplication::quit(), exit(), processEvents() -*/ -int TQEventLoop::exec() -{ - d->reset(); - - enterLoop(); - - // cleanup - d->looplevel = 0; - d->quitnow = FALSE; - d->exitloop = FALSE; - d->shortcut = FALSE; - // don't reset quitcode! - - return d->quitcode; -} - -/*! \fn void TQEventLoop::exit( int retcode = 0 ) - - Tells the event loop to exit with a return code. - - After this function has been called, the event loop 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 TQApplication::quit(), exec() -*/ -void TQEventLoop::exit( int retcode ) -{ - if ( d->quitnow ) // preserve existing quitcode - return; - d->quitcode = retcode; - d->quitnow = TRUE; - d->exitloop = TRUE; - d->shortcut = TRUE; -} - - -/*! \fn int TQEventLoop::enterLoop() - - This function enters the main event loop (recursively). Do not call - it unless you really know what you are doing. - */ -int TQEventLoop::enterLoop() -{ - // save the current exitloop state - bool old_exitloop = d->exitloop; - d->exitloop = FALSE; - d->shortcut = FALSE; - - d->looplevel++; - while ( ! d->exitloop ) { - processEvents( AllEvents | WaitForMore ); - } - d->looplevel--; - - // restore the exitloop state, but if quitnow is TRUE, we need to keep - // exitloop set so that all other event loops drop out. - d->exitloop = old_exitloop || d->quitnow; - d->shortcut = d->quitnow; - - if ( d->looplevel < 1 ) { - d->quitnow = FALSE; - d->exitloop = FALSE; - d->shortcut = FALSE; - emit tqApp->aboutToQuit(); - - // send deferred deletes - TQApplication::sendPostedEvents( 0, TQEvent::DeferredDelete ); - } - - return d->looplevel; -} - -/*! \fn void TQEventLoop::exitLoop() - - This function exits from a recursive call to the main event loop. - Do not call it unless you really know what you are doing. -*/ -void TQEventLoop::exitLoop() -{ - d->exitloop = TRUE; - d->shortcut = TRUE; -} - -/*! \fn void TQEventLoop::loopLevel() const - - Returns the current loop level. -*/ -int TQEventLoop::loopLevel() const -{ - return d->looplevel; -} - -/*! - Process pending events that match \a flags for a maximum of \a - maxTime milliseconds, or until there are no more events to - process, which ever is shorter. - - This function is especially useful if you have a long running - operation and want to show its progress without allowing user - input, i.e. by using the \c ExcludeUserInput flag. - - NOTE: This function will not process events continuously; it - returns after all available events are processed. - - NOTE: Specifying the \c WaitForMore flag makes no sense and will - be ignored. -*/ -void TQEventLoop::processEvents( ProcessEventsFlags flags, int maxTime ) -{ - TQTime start = TQTime::currentTime(); - TQTime now; - while ( ! d->quitnow && processEvents( flags & ~WaitForMore ) ) { - now = TQTime::currentTime(); - if ( start.msecsTo( now ) > maxTime ) - break; - } -} - -/*! - \fn bool TQEventLoop::processEvents( ProcessEventsFlags flags ) - \overload - - Processes pending events that match \a flags until there are no - more events to process. - - This function is especially useful if you have a long running - operation and want to show its progress without allowing user - input, i.e. by using the \c ExcludeUserInput flag. - - If the \c WaitForMore flag is set in \a flags, the behavior of - this function is as follows: - - \list - - \i If events are available, this function returns after processing - them. - - \i If no events are available, this function will wait until more - are available and return after processing newly available events. - - \endlist - - If the \c WaitForMore flag is \e not set in \a flags, and no - events are available, this function will return immediately. - - NOTE: This function will not process events continuously; it - returns after all available events are processed. - - This function returns TRUE if an event was processed; otherwise it - returns FALSE. - - \sa ProcessEvents hasPendingEvents() -*/ - -/*! \fn bool TQEventLoop::hasPendingEvents() const - - Returns TRUE if there is an event waiting, otherwise it returns FALSE. -*/ - -/*! \fn void TQEventLoop::registerSocketNotifier( TQSocketNotifier *notifier ) - - Registers \a notifier with the event loop. Subclasses need to - reimplement this method to tie a socket notifier into another - event loop. Reimplementations \e MUST call the base - implementation. -*/ - -/*! \fn void TQEventLoop::unregisterSocketNotifier( TQSocketNotifier *notifier ) - - Unregisters \a notifier from the event loop. Subclasses need to - reimplement this method to tie a socket notifier into another - event loop. Reimplementations \e MUST call the base - implementation. -*/ - -/*! \fn void TQEventLoop::setSocketNotifierPending( TQSocketNotifier *notifier ) - - Marks \a notifier as pending. The socket notifier will be - activated the next time activateSocketNotifiers() is called. -*/ - -/*! \fn int TQEventLoop::activateSocketNotifiers() - - Activates all pending socket notifiers and returns the number of - socket notifiers that were activated. -*/ - -/*! \fn int TQEventLoop::activateTimers() - - Activates all TQt timers and returns the number of timers that were - activated. - - TQEventLoop subclasses that do their own timer handling need to - call this after the time returned by timeToWait() has elapsed. - - Note: This function is only useful on systems where \c select() is - used to block the eventloop. On Windows, this function always - returns 0. On MacOS X, this function always returns 0 when the - GUI is enabled. On MacOS X, this function returns the documented - value when the GUI is disabled. -*/ - -/*! \fn int TQEventLoop::timeToWait() const - - Returns the number of milliseconds that TQt needs to handle its - timers or -1 if there are no timers running. - - TQEventLoop subclasses that do their own timer handling need to use - this to make sure that TQt's timers continue to work. - - Note: This function is only useful on systems where \c select() is - used to block the eventloop. On Windows, this function always - returns -1. On MacOS X, this function always returns -1 when the - GUI is enabled. On MacOS X, this function returns the documented - value when the GUI is disabled. -*/ - -/*! \fn void TQEventLoop::wakeUp() - \threadsafe - - Wakes up the event loop. - - \sa awake() -*/ - -/*! \fn void TQEventLoop::awake() - - This signal is emitted after the event loop returns from a - function that could block. - - \sa wakeUp() aboutToBlock() -*/ - -/*! \fn void TQEventLoop::aboutToBlock() - - This signal is emitted before the event loop calls a function that - could block. - - \sa awake() -*/ - -#if !defined(TQ_WS_X11) -void TQEventLoop::appStartingUp(){} -void TQEventLoop::appClosingDown(){} -#endif // TQ_WS_X11 diff --git a/src/kernel/qeventloop_glib_p.h b/src/kernel/qeventloop_glib_p.h deleted file mode 100644 index cc7a3874e..000000000 --- a/src/kernel/qeventloop_glib_p.h +++ /dev/null @@ -1,119 +0,0 @@ -/** -** TQt->glib main event loop integration by Norbert Frese 2005 -** code based on qeventloop_p.h 3.3.5 -** -*/ - -/**************************************************************************** -** $Id: qt/qeventloop_glib_p.h -** -** Definition of TQEventLoop class -** -** Copyright (C) 1992-2005 Trolltech AS. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef TQEVENTLOOP_GLIB_P_H -#define TQEVENTLOOP_GLIB_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. This header file may -// change from version to version without notice, or even be -// removed. -// -// We mean it. -// -// - -#ifndef QT_H -#include "qplatformdefs.h" -#endif // QT_H - -// SCO OpenServer redefines raise -> kill -#if defined(raise) -# undef raise -#endif - -#include "ntqeventloop.h" -#include "ntqwindowdefs.h" - -class TQSocketNotifier; - -#include "tqptrlist.h" - -#include - -// uncomment this for main loop related debug-output - -// #define DEBUG_QT_GLIBMAINLOOP 1 - -// Wrapper for TQSocketNotifier Object and GPollFD - -struct TQSockNotGPollFD -{ - TQSocketNotifier *obj; - GPollFD gPollFD; - gushort events; // save events - bool pending; -}; - -class TQEventLoopPrivate -{ -public: - TQEventLoopPrivate(); - ~TQEventLoopPrivate(); - - void reset(); - - int looplevel; - int quitcode; - unsigned int quitnow : 1; - unsigned int exitloop : 1; - unsigned int shortcut : 1; - -#if defined(TQ_WS_X11) - int xfd; - GPollFD x_gPollFD; -#endif // TQ_WS_X11 - - int thread_pipe[2]; - GPollFD threadPipe_gPollFD; - TQPtrList sn_list; - - // pending socket notifiers list - TQPtrList sn_pending_list; - - // store flags for one iteration - uint pev_flags; - - // My GSource - GSource * gSource; - bool singletoolkit; - - // main context - GMainContext *ctx; - GMainLoop *mainloop; - bool ctx_is_default; -}; - -#endif // TQEVENTLOOP_GLIB_P_H diff --git a/src/kernel/qeventloop_p.h b/src/kernel/qeventloop_p.h deleted file mode 100644 index 8ab5f954f..000000000 --- a/src/kernel/qeventloop_p.h +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** Definition of TQEventLoop class -** -** 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. -** -** 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 TQEVENTLOOP_P_H -#define TQEVENTLOOP_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. This header file may -// change from version to version without notice, or even be -// removed. -// -// We mean it. -// -// - -#if defined(QT_USE_GLIBMAINLOOP) -#include "qeventloop_glib_p.h" // use a different header file!!! -#else - -#ifndef QT_H -#include "qplatformdefs.h" -#endif // QT_H - -// SCO OpenServer redefines raise -> kill -#if defined(raise) -# undef raise -#endif - -#include "ntqwindowdefs.h" - -class TQSocketNotifier; -#ifdef Q_OS_MAC -class TQMacSockNotPrivate; -#endif - -#if defined(Q_OS_UNIX) || defined (TQ_WS_WIN) -#include "tqptrlist.h" -#endif // Q_OS_UNIX || TQ_WS_WIN - -#if defined(Q_OS_UNIX) -struct TQSockNot -{ - TQSocketNotifier *obj; - int fd; - fd_set *queue; -}; - -class TQSockNotType -{ -public: - TQSockNotType(); - ~TQSockNotType(); - - TQPtrList *list; - fd_set select_fds; - fd_set enabled_fds; - fd_set pending_fds; - -}; -#endif // Q_OS_UNIX - -#if defined(TQ_WS_WIN) -struct TQSockNot { - TQSocketNotifier *obj; - int fd; -}; -#endif // TQ_WS_WIN - -class TQEventLoopPrivate -{ -public: - TQEventLoopPrivate() - { - reset(); - } - - void reset() { - looplevel = 0; - quitcode = 0; - quitnow = FALSE; - exitloop = FALSE; - shortcut = FALSE; - } - - int looplevel; - int quitcode; - unsigned int quitnow : 1; - unsigned int exitloop : 1; - unsigned int shortcut : 1; - -#if defined(TQ_WS_MAC) - uchar next_select_timer; - EventLoopTimerRef select_timer; -#endif - -#if defined(TQ_WS_X11) - int xfd; -#endif // TQ_WS_X11 - -#if defined(Q_OS_UNIX) - int thread_pipe[2]; - - // pending socket notifiers list - TQPtrList sn_pending_list; - // highest fd for all socket notifiers - int sn_highest; - // 3 socket notifier types - read, write and exception - TQSockNotType sn_vec[3]; -#endif - -#ifdef TQ_WS_WIN - // pending socket notifiers list - TQPtrList sn_pending_list; -#endif // TQ_WS_WIN - -}; - -#endif // !QT_USE_GLIBMAINLOOP - -#endif // TQEVENTLOOP_P_H diff --git a/src/kernel/qeventloop_unix.cpp b/src/kernel/qeventloop_unix.cpp deleted file mode 100644 index 2f71b4c05..000000000 --- a/src/kernel/qeventloop_unix.cpp +++ /dev/null @@ -1,594 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQEventLoop class -** -** 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. -** -**********************************************************************/ - -#include "qeventloop_p.h" // includes qplatformdefs.h -#include "ntqeventloop.h" -#include "ntqapplication.h" -#include "tqbitarray.h" -#include "tqmutex.h" -#include -#include - - -/***************************************************************************** - Timer handling; UNIX has no application timer support so we'll have to - make our own from scratch. - - NOTE: These functions are for internal use. TQObject::startTimer() and - TQObject::killTimer() are for public use. - The TQTimer class provides a high-level interface which translates - timer events into signals. - - qStartTimer( interval, obj ) - Starts a timer which will run until it is killed with qKillTimer() - Arguments: - int interval timer interval in milliseconds - TQObject *obj where to send the timer event - Returns: - int timer identifier, or zero if not successful - - qKillTimer( timerId ) - Stops a timer specified by a timer identifier. - Arguments: - int timerId timer identifier - Returns: - bool TRUE if successful - - qKillTimer( obj ) - Stops all timers that are sent to the specified object. - Arguments: - TQObject *obj object receiving timer events - Returns: - bool TRUE if successful - *****************************************************************************/ - -// -// Internal data structure for timers -// - -struct TimerInfo { // internal timer info - int id; // - timer identifier - timeval interval; // - timer interval - timeval timeout; // - when to sent event - TQObject *obj; // - object to receive event -}; - -typedef TQPtrList TimerList; // list of TimerInfo structs - -static TQBitArray *timerBitVec; // timer bit vector -static TimerList *timerList = 0; // timer list - -static void initTimers(); -void cleanupTimers(); -static timeval watchtime; // watch if time is turned back -timeval *qt_wait_timer(); -timeval *qt_wait_timer_max = 0; - -// -// Internal operator functions for timevals -// - -static inline bool operator<( const timeval &t1, const timeval &t2 ) -{ - return t1.tv_sec < t2.tv_sec || - (t1.tv_sec == t2.tv_sec && t1.tv_usec < t2.tv_usec); -} - -static inline bool operator==( const timeval &t1, const timeval &t2 ) -{ - return t1.tv_sec == t2.tv_sec && t1.tv_usec == t2.tv_usec; -} - -static inline timeval &operator+=( timeval &t1, const timeval &t2 ) -{ - t1.tv_sec += t2.tv_sec; - if ( (t1.tv_usec += t2.tv_usec) >= 1000000 ) { - t1.tv_sec++; - t1.tv_usec -= 1000000; - } - return t1; -} - -static inline timeval operator+( const timeval &t1, const timeval &t2 ) -{ - timeval tmp; - tmp.tv_sec = t1.tv_sec + t2.tv_sec; - if ( (tmp.tv_usec = t1.tv_usec + t2.tv_usec) >= 1000000 ) { - tmp.tv_sec++; - tmp.tv_usec -= 1000000; - } - return tmp; -} - -static inline timeval operator-( const timeval &t1, const timeval &t2 ) -{ - timeval tmp; - tmp.tv_sec = t1.tv_sec - t2.tv_sec; - if ( (tmp.tv_usec = t1.tv_usec - t2.tv_usec) < 0 ) { - tmp.tv_sec--; - tmp.tv_usec += 1000000; - } - return tmp; -} - - -// -// Internal functions for manipulating timer data structures. -// The timerBitVec array is used for keeping track of timer identifiers. -// - -static int allocTimerId() // find avail timer identifier -{ - int i = timerBitVec->size()-1; - while ( i >= 0 && (*timerBitVec)[i] ) - i--; - if ( i < 0 ) { - i = timerBitVec->size(); - timerBitVec->resize( 4 * i ); - for( int j=timerBitVec->size()-1; j > i; j-- ) - timerBitVec->clearBit( j ); - } - timerBitVec->setBit( i ); - return i+1; -} - -static void insertTimer( const TimerInfo *ti ) // insert timer info into list -{ - TimerInfo *t = timerList->first(); - int index = 0; -#if defined(QT_DEBUG) - int dangerCount = 0; -#endif - while ( t && t->timeout < ti->timeout ) { // list is sorted by timeout -#if defined(QT_DEBUG) - if ( t->obj == ti->obj ) - dangerCount++; -#endif - t = timerList->next(); - index++; - } - timerList->insert( index, ti ); // inserts sorted -#if defined(QT_DEBUG) - if ( dangerCount > 16 ) - tqDebug( "TQObject: %d timers now exist for object %s::%s", - dangerCount, ti->obj->className(), ti->obj->name() ); -#endif -} - -static inline void getTime( timeval &t ) // get time of day -{ - gettimeofday( &t, 0 ); - while ( t.tv_usec >= 1000000 ) { // NTP-related fix - t.tv_usec -= 1000000; - t.tv_sec++; - } - while ( t.tv_usec < 0 ) { - if ( t.tv_sec > 0 ) { - t.tv_usec += 1000000; - t.tv_sec--; - } else { - t.tv_usec = 0; - break; - } - } -} - -static void repairTimer( const timeval &time ) // repair broken timer -{ - timeval diff = watchtime - time; - TimerInfo *t = timerList->first(); - while ( t ) { // repair all timers - t->timeout = t->timeout - diff; - t = timerList->next(); - } -} - -// -// Timer activation functions (called from the event loop) -// - -/* - Returns the time to wait for the next timer, or null if no timers are - waiting. - - The result is bounded to qt_wait_timer_max if this exists. -*/ - -timeval *qt_wait_timer() -{ - static timeval tm; - bool first = TRUE; - timeval currentTime; - if ( timerList && timerList->count() ) { // there are waiting timers - getTime( currentTime ); - if ( first ) { - if ( currentTime < watchtime ) // clock was turned back - repairTimer( currentTime ); - first = FALSE; - watchtime = currentTime; - } - TimerInfo *t = timerList->first(); // first waiting timer - if ( currentTime < t->timeout ) { // time to wait - tm = t->timeout - currentTime; - } else { - tm.tv_sec = 0; // no time to wait - tm.tv_usec = 0; - } - if ( qt_wait_timer_max && *qt_wait_timer_max < tm ) - tm = *qt_wait_timer_max; - return &tm; - } - if ( qt_wait_timer_max ) { - tm = *qt_wait_timer_max; - return &tm; - } - return 0; // no timers -} - -// Timer initialization -static void initTimers() // initialize timers -{ - timerBitVec = new TQBitArray( 128 ); - TQ_CHECK_PTR( timerBitVec ); - int i = timerBitVec->size(); - while( i-- > 0 ) - timerBitVec->clearBit( i ); - timerList = new TimerList; - TQ_CHECK_PTR( timerList ); - timerList->setAutoDelete( TRUE ); - gettimeofday( &watchtime, 0 ); -} - -// Timer cleanup -void cleanupTimers() -{ - delete timerList; - timerList = 0; - delete timerBitVec; - timerBitVec = 0; -} - -// Main timer functions for starting and killing timers -int qStartTimer( int interval, TQObject *obj ) -{ - if ( !timerList ) // initialize timer data - initTimers(); - int id = allocTimerId(); // get free timer id - if ( id <= 0 || - id > (int)timerBitVec->size() || !obj )// cannot create timer - return 0; - timerBitVec->setBit( id-1 ); // set timer active - TimerInfo *t = new TimerInfo; // create timer - TQ_CHECK_PTR( t ); - t->id = id; - t->interval.tv_sec = interval/1000; - t->interval.tv_usec = (interval%1000)*1000; - timeval currentTime; - getTime( currentTime ); - t->timeout = currentTime + t->interval; - t->obj = obj; - insertTimer( t ); // put timer in list - return id; -} - -bool qKillTimer( int id ) -{ - TimerInfo *t; - if ( !timerList || id <= 0 || - id > (int)timerBitVec->size() || !timerBitVec->testBit( id-1 ) ) - return FALSE; // not init'd or invalid timer - t = timerList->first(); - while ( t && t->id != id ) // find timer info in list - t = timerList->next(); - if ( t ) { // id found - timerBitVec->clearBit( id-1 ); // set timer inactive - return timerList->remove(); - } - else // id not found - return FALSE; -} - -bool qKillTimer( TQObject *obj ) -{ - TimerInfo *t; - if ( !timerList ) // not initialized - return FALSE; - t = timerList->first(); - while ( t ) { // check all timers - if ( t->obj == obj ) { // object found - timerBitVec->clearBit( t->id-1 ); - timerList->remove(); - t = timerList->current(); - } else { - t = timerList->next(); - } - } - return TRUE; -} - -/***************************************************************************** - Socket notifier type - *****************************************************************************/ -TQSockNotType::TQSockNotType() - : list( 0 ) -{ - FD_ZERO( &select_fds ); - FD_ZERO( &enabled_fds ); - FD_ZERO( &pending_fds ); -} - -TQSockNotType::~TQSockNotType() -{ - if ( list ) - delete list; - list = 0; -} - -/***************************************************************************** - TQEventLoop implementations for UNIX - *****************************************************************************/ -void TQEventLoop::registerSocketNotifier( TQSocketNotifier *notifier ) -{ - int sockfd = notifier->socket(); - int type = notifier->type(); - if ( sockfd < 0 || sockfd >= FD_SETSIZE || type < 0 || type > 2 || notifier == 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQSocketNotifier: Internal error" ); -#endif - return; - } - - TQPtrList *list = d->sn_vec[type].list; - fd_set *fds = &d->sn_vec[type].enabled_fds; - TQSockNot *sn; - - if ( ! list ) { - // create new list, the TQSockNotType destructor will delete it for us - list = new TQPtrList; - TQ_CHECK_PTR( list ); - list->setAutoDelete( TRUE ); - d->sn_vec[type].list = list; - } - - sn = new TQSockNot; - TQ_CHECK_PTR( sn ); - sn->obj = notifier; - sn->fd = sockfd; - sn->queue = &d->sn_vec[type].pending_fds; - - if ( list->isEmpty() ) { - list->insert( 0, sn ); - } else { // sort list by fd, decreasing - TQSockNot *p = list->first(); - while ( p && p->fd > sockfd ) - p = list->next(); -#if defined(QT_CHECK_STATE) - if ( p && p->fd == sockfd ) { - static const char *t[] = { "read", "write", "exception" }; - tqWarning( "TQSocketNotifier: Multiple socket notifiers for " - "same socket %d and type %s", sockfd, t[type] ); - } -#endif - if ( p ) - list->insert( list->at(), sn ); - else - list->append( sn ); - } - - FD_SET( sockfd, fds ); - d->sn_highest = TQMAX( d->sn_highest, sockfd ); -} - -void TQEventLoop::unregisterSocketNotifier( TQSocketNotifier *notifier ) -{ - int sockfd = notifier->socket(); - int type = notifier->type(); - if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQSocketNotifier: Internal error" ); -#endif - return; - } - - TQPtrList *list = d->sn_vec[type].list; - fd_set *fds = &d->sn_vec[type].enabled_fds; - TQSockNot *sn; - if ( ! list ) - return; - sn = list->first(); - while ( sn && !(sn->obj == notifier && sn->fd == sockfd) ) - sn = list->next(); - if ( !sn ) // not found - return; - - FD_CLR( sockfd, fds ); // clear fd bit - FD_CLR( sockfd, sn->queue ); - d->sn_pending_list.removeRef( sn ); // remove from activation list - list->remove(); // remove notifier found above - - if ( d->sn_highest == sockfd ) { // find highest fd - d->sn_highest = -1; - for ( int i=0; i<3; i++ ) { - if ( d->sn_vec[i].list && ! d->sn_vec[i].list->isEmpty() ) - d->sn_highest = TQMAX( d->sn_highest, // list is fd-sorted - d->sn_vec[i].list->getFirst()->fd ); - } - } -} - -void TQEventLoop::setSocketNotifierPending( TQSocketNotifier *notifier ) -{ - int sockfd = notifier->socket(); - int type = notifier->type(); - if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQSocketNotifier: Internal error" ); -#endif - return; - } - - TQPtrList *list = d->sn_vec[type].list; - TQSockNot *sn; - if ( ! list ) - return; - sn = list->first(); - while ( sn && !(sn->obj == notifier && sn->fd == sockfd) ) - sn = list->next(); - if ( ! sn ) { // not found - return; - } - - // We choose a random activation order to be more fair under high load. - // If a constant order is used and a peer early in the list can - // saturate the IO, it might grab our attention completely. - // Also, if we're using a straight list, the callback routines may - // delete other entries from the list before those other entries are - // processed. - if ( ! FD_ISSET( sn->fd, sn->queue ) ) { - d->sn_pending_list.insert( (rand() & 0xff) % - (d->sn_pending_list.count()+1), sn ); - FD_SET( sn->fd, sn->queue ); - } -} - -void TQEventLoop::wakeUp() -{ - /* - Apparently, there is not consistency among different operating - systems on how to use FIONREAD. - - FreeBSD, Linux and Solaris all expect the 3rd argument to - ioctl() to be an int, which is normally 32-bit even on 64-bit - machines. - - IRIX, on the other hand, expects a size_t, which is 64-bit on - 64-bit machines. - - So, the solution is to use size_t initialized to zero to make - sure all bits are set to zero, preventing underflow with the - FreeBSD/Linux/Solaris ioctls. - */ - size_t nbytes = 0; - char c = 0; - if ( ::ioctl( d->thread_pipe[0], FIONREAD, (char*)&nbytes ) >= 0 && nbytes == 0 ) { - if (::write( d->thread_pipe[1], &c, 1 ) < 0) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQEventLoop: Internal error (failed thread pipe write)" ); -#endif - } - } -} - -int TQEventLoop::timeToWait() const -{ - timeval *tm = qt_wait_timer(); - if ( ! tm ) // no active timers - return -1; - return (tm->tv_sec*1000) + (tm->tv_usec/1000); -} - -int TQEventLoop::activateTimers() -{ - if ( !timerList || !timerList->count() ) // no timers - return 0; - bool first = TRUE; - timeval currentTime; - int n_act = 0, maxCount = timerList->count(); - TimerInfo *begin = 0; - TimerInfo *t; - - for ( ;; ) { - if ( ! maxCount-- ) - break; - getTime( currentTime ); // get current time - if ( first ) { - if ( currentTime < watchtime ) // clock was turned back - repairTimer( currentTime ); - first = FALSE; - watchtime = currentTime; - } - t = timerList->first(); - if ( !t || currentTime < t->timeout ) // no timer has expired - break; - if ( ! begin ) { - begin = t; - } else if ( begin == t ) { - // avoid sending the same timer multiple times - break; - } else if ( t->interval < begin->interval || t->interval == begin->interval ) { - begin = t; - } - timerList->take(); // unlink from list - t->timeout += t->interval; - if ( t->timeout < currentTime ) - t->timeout = currentTime + t->interval; - insertTimer( t ); // relink timer - if ( t->interval.tv_usec > 0 || t->interval.tv_sec > 0 ) - n_act++; - TQTimerEvent e( t->id ); - TQApplication::sendEvent( t->obj, &e ); // send event - if ( !timerList ) // sendEvent allows other threads to execute, therefore we must check for list existence when it returns! - return 0; - if ( timerList->findRef( begin ) == -1 ) - begin = 0; - } - return n_act; -} - -int TQEventLoop::activateSocketNotifiers() -{ - if ( d->sn_pending_list.isEmpty() ) - return 0; - - // activate entries - int n_act = 0; - TQEvent event( TQEvent::SockAct ); - TQPtrListIterator it( d->sn_pending_list ); - TQSockNot *sn; - while ( (sn=it.current()) ) { - ++it; - d->sn_pending_list.removeRef( sn ); - if ( FD_ISSET(sn->fd, sn->queue) ) { - FD_CLR( sn->fd, sn->queue ); - TQApplication::sendEvent( sn->obj, &event ); - n_act++; - } - } - - return n_act; -} diff --git a/src/kernel/qeventloop_unix_glib.cpp b/src/kernel/qeventloop_unix_glib.cpp deleted file mode 100644 index 11cb9ad94..000000000 --- a/src/kernel/qeventloop_unix_glib.cpp +++ /dev/null @@ -1,750 +0,0 @@ -/** -** TQt->glib main event loop integration by Norbert Frese 2005 -** code based on qeventloop_unix.cpp 3.3.5 -** -*/ - -/**************************************************************************** -** $Id: qt/qeventloop_unix_glib.cpp -** -** Implementation of TQEventLoop class -** -** Copyright (C) 2000-2005 Trolltech AS. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be distributed under the terms of the Q Public License -** as defined by Trolltech AS of Norway and appearing in the file -** LICENSE.TQPL included in the packaging of this file. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/qpl/ for TQPL licensing information. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - - -#include "qeventloop_glib_p.h" // includes qplatformdefs.h -#include "ntqeventloop.h" -#include "ntqapplication.h" -#include "tqbitarray.h" -#include "tqmutex.h" - -#if defined(TQT_THREAD_SUPPORT) - #include "tqthread.h" -#endif - -#include -#include - -#include - -#ifdef TQT_THREAD_SUPPORT -#ifdef QT_USE_GLIBMAINLOOP -extern TQMutex *tqt_timerListMutex; -#endif // QT_USE_GLIBMAINLOOP -#endif // TQT_THREAD_SUPPORT - -/***************************************************************************** - Timer handling; UNIX has no application timer support so we'll have to - make our own from scratch. - - NOTE: These functions are for internal use. TQObject::startTimer() and - TQObject::killTimer() are for public use. - The TQTimer class provides a high-level interface which translates - timer events into signals. - - qStartTimer( interval, obj ) - Starts a timer which will run until it is killed with qKillTimer() - Arguments: - int interval timer interval in milliseconds - TQObject *obj where to send the timer event - Returns: - int timer identifier, or zero if not successful - - qKillTimer( timerId ) - Stops a timer specified by a timer identifier. - Arguments: - int timerId timer identifier - Returns: - bool TRUE if successful - - qKillTimer( obj ) - Stops all timers that are sent to the specified object. - Arguments: - TQObject *obj object receiving timer events - Returns: - bool TRUE if successful - *****************************************************************************/ - -// -// Internal data structure for timers -// - -struct TimerInfo { // internal timer info - int id; // - timer identifier - timeval interval; // - timer interval - timeval timeout; // - when to sent event - TQObject *obj; // - object to receive event -}; - -typedef TQPtrList TimerList; // list of TimerInfo structs - -static TQBitArray *timerBitVec; // timer bit vector -static TimerList *timerList = 0; // timer list - -static void initTimers(); -void cleanupTimers(); -static timeval watchtime; // watch if time is turned back -timeval *qt_wait_timer(); -timeval *qt_wait_timer_max = 0; - -// -// Internal operator functions for timevals -// - -static inline bool operator<( const timeval &t1, const timeval &t2 ) -{ - return (t1.tv_sec < t2.tv_sec) || ((t1.tv_sec == t2.tv_sec) && (t1.tv_usec < t2.tv_usec)); -} - -static inline bool operator==( const timeval &t1, const timeval &t2 ) -{ - return t1.tv_sec == t2.tv_sec && t1.tv_usec == t2.tv_usec; -} - -static inline timeval &operator+=( timeval &t1, const timeval &t2 ) -{ - t1.tv_sec += t2.tv_sec; - if ( (t1.tv_usec += t2.tv_usec) >= 1000000 ) { - t1.tv_sec++; - t1.tv_usec -= 1000000; - } - return t1; -} - -static inline timeval operator+( const timeval &t1, const timeval &t2 ) -{ - timeval tmp; - tmp.tv_sec = t1.tv_sec + t2.tv_sec; - if ( (tmp.tv_usec = t1.tv_usec + t2.tv_usec) >= 1000000 ) { - tmp.tv_sec++; - tmp.tv_usec -= 1000000; - } - return tmp; -} - -static inline timeval operator-( const timeval &t1, const timeval &t2 ) -{ - timeval tmp; - tmp.tv_sec = t1.tv_sec - t2.tv_sec; - if ( (tmp.tv_usec = t1.tv_usec - t2.tv_usec) < 0 ) { - tmp.tv_sec--; - tmp.tv_usec += 1000000; - } - return tmp; -} - - -// -// Internal functions for manipulating timer data structures. -// The timerBitVec array is used for keeping track of timer identifiers. -// - -static int allocTimerId() // find avail timer identifier -{ - int i = timerBitVec->size()-1; - while ( i >= 0 && (*timerBitVec)[i] ) { - i--; - } - if ( i < 0 ) { - i = timerBitVec->size(); - timerBitVec->resize( 4 * i ); - for( int j=timerBitVec->size()-1; j > i; j-- ) { - timerBitVec->clearBit( j ); - } - } - timerBitVec->setBit( i ); - return i+1; -} - -static void insertTimer( const TimerInfo *ti ) // insert timer info into list -{ -#if defined(TQT_THREAD_SUPPORT) - tqt_timerListMutex->lock(); -#endif - TimerInfo *t = timerList->first(); - int index = 0; -#if defined(QT_DEBUG) - int dangerCount = 0; -#endif - while ( t && t->timeout < ti->timeout ) { // list is sorted by timeout -#if defined(QT_DEBUG) - if ( t->obj == ti->obj ) { - dangerCount++; - } -#endif - t = timerList->next(); - index++; - } - timerList->insert( index, ti ); // inserts sorted -#if defined(QT_DEBUG) - if ( dangerCount > 16 ) { - tqDebug( "TQObject: %d timers now exist for object %s::%s", dangerCount, ti->obj->className(), ti->obj->name() ); - } -#endif -#if defined(TQT_THREAD_SUPPORT) - tqt_timerListMutex->unlock(); -#endif -} - -static inline void getTime( timeval &t ) // get time of day -{ - gettimeofday( &t, 0 ); - while ( t.tv_usec >= 1000000 ) { // NTP-related fix - t.tv_usec -= 1000000; - t.tv_sec++; - } - while ( t.tv_usec < 0 ) { - if ( t.tv_sec > 0 ) { - t.tv_usec += 1000000; - t.tv_sec--; - } - else { - t.tv_usec = 0; - break; - } - } -} - -static void repairTimer( const timeval &time ) // repair broken timer -{ -#if defined(TQT_THREAD_SUPPORT) - tqt_timerListMutex->lock(); -#endif - timeval diff = watchtime - time; - TimerInfo *t = timerList->first(); - while ( t ) { // repair all timers - t->timeout = t->timeout - diff; - t = timerList->next(); - } -#if defined(TQT_THREAD_SUPPORT) - tqt_timerListMutex->unlock(); -#endif -} - -// -// Timer activation functions (called from the event loop) -// - -/* - Returns the time to wait for the next timer, or null if no timers are - waiting. - - The result is bounded to qt_wait_timer_max if this exists. -*/ - -timeval *qt_wait_timer() -{ -#if defined(TQT_THREAD_SUPPORT) - tqt_timerListMutex->lock(); -#endif - static timeval tm; - bool first = TRUE; - timeval currentTime; - if ( timerList && timerList->count() ) { // there are waiting timers - getTime( currentTime ); - if ( first ) { - if ( currentTime < watchtime ) { // clock was turned back - repairTimer( currentTime ); - } - first = FALSE; - watchtime = currentTime; - } - TimerInfo *t = timerList->first(); // first waiting timer - if ( currentTime < t->timeout ) { // time to wait - tm = t->timeout - currentTime; - } - else { - tm.tv_sec = 0; // no time to wait - tm.tv_usec = 0; - } - if ( qt_wait_timer_max && *qt_wait_timer_max < tm ) { - tm = *qt_wait_timer_max; - } -#if defined(TQT_THREAD_SUPPORT) - tqt_timerListMutex->unlock(); -#endif - return &tm; - } - if ( qt_wait_timer_max ) { - tm = *qt_wait_timer_max; -#if defined(TQT_THREAD_SUPPORT) - tqt_timerListMutex->unlock(); -#endif - return &tm; - } -#if defined(TQT_THREAD_SUPPORT) - tqt_timerListMutex->unlock(); -#endif - return 0; // no timers -} - -// Timer initialization -static void initTimers() // initialize timers -{ - timerBitVec = new TQBitArray( 128 ); - TQ_CHECK_PTR( timerBitVec ); - int i = timerBitVec->size(); - while( i-- > 0 ) { - timerBitVec->clearBit( i ); - } - timerList = new TimerList; -#if defined(TQT_THREAD_SUPPORT) - tqt_timerListMutex = new TQMutex(true); -#endif - TQ_CHECK_PTR( timerList ); - timerList->setAutoDelete( TRUE ); - gettimeofday( &watchtime, 0 ); -} - -// Timer cleanup -void cleanupTimers() -{ - delete timerList; - timerList = 0; - delete timerBitVec; - timerBitVec = 0; -} - -// Main timer functions for starting and killing timers -int qStartTimer( int interval, TQObject *obj ) -{ -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->lock(); -#endif - if ( !timerList ) { // initialize timer data - initTimers(); -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->lock(); -#endif - } - int id = allocTimerId(); // get free timer id - if ( (id <= 0) || (id > (int)timerBitVec->size()) || (!obj) ) { // cannot create timer -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - return 0; - } - timerBitVec->setBit( id-1 ); // set timer active - TimerInfo *t = new TimerInfo; // create timer - TQ_CHECK_PTR( t ); - t->id = id; - t->interval.tv_sec = interval/1000; - t->interval.tv_usec = (interval%1000)*1000; - timeval currentTime; - getTime( currentTime ); - t->timeout = currentTime + t->interval; - t->obj = obj; - insertTimer( t ); // put timer in list -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - return id; -} - -bool qKillTimer( int id ) -{ -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->lock(); -#endif - TimerInfo *t; - if ( (!timerList) || (id <= 0) || (id > (int)timerBitVec->size()) || (!timerBitVec->testBit( id-1 )) ) { -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - return FALSE; // not init'd or invalid timer - } - t = timerList->first(); - while ( t && t->id != id ) { // find timer info in list - t = timerList->next(); - } - if ( t ) { // id found - bool ret; - timerBitVec->clearBit( id-1 ); // set timer inactive - ret = timerList->remove(); -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - return ret; - } - else { // id not found -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - return FALSE; - } -} - -bool qKillTimer( TQObject *obj ) -{ -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->lock(); -#endif - TimerInfo *t; - if ( !timerList ) { // not initialized -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - return FALSE; - } - t = timerList->first(); - while ( t ) { // check all timers - if ( t->obj == obj ) { // object found - timerBitVec->clearBit( t->id-1 ); - timerList->remove(); - t = timerList->current(); - } - else { - t = timerList->next(); - } - } -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - return TRUE; -} - - -TQEventLoopPrivate::TQEventLoopPrivate() { -#if defined(TQ_WS_X11) - xfd = -1; - x_gPollFD.fd = -1; - x_gPollFD.events = 0; - x_gPollFD.revents = 0; -#endif // TQ_WS_X11 - gSource = nullptr; - singletoolkit = TRUE; - ctx = nullptr; - mainloop = nullptr; - ctx_is_default = false; - reset(); -} - -TQEventLoopPrivate::~TQEventLoopPrivate() { - // -} - -void TQEventLoopPrivate::reset() { - looplevel = 0; - quitcode = 0; - quitnow = FALSE; - exitloop = FALSE; - shortcut = FALSE; -} - - -/***************************************************************************** - TQEventLoop implementations for Glib-Main-Loop - *****************************************************************************/ - - - - -void TQEventLoop::registerSocketNotifier( TQSocketNotifier *notifier ) -{ - int sockfd = notifier->socket(); - int type = notifier->type(); - if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQSocketNotifier: Internal error" ); -#endif - return; - } - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("register socket notifier %d\n", sockfd); -#endif - - TQPtrList *list = &d->sn_list; - TQSockNotGPollFD *sn; - - /* - if ( ! list ) { - // create new list, the TQSockNotType destructor will delete it for us - list = new TQPtrList; - TQ_CHECK_PTR( list ); - list->setAutoDelete( TRUE ); - d->sn_list = list; - } - */ - - gushort events=0; - switch (type) { - case 0: - events = G_IO_IN | G_IO_HUP; - break; - case 1: - events = G_IO_OUT; - break; - case 2: - events = G_IO_PRI | G_IO_ERR | G_IO_NVAL; - break; - } - - sn = new TQSockNotGPollFD; - TQ_CHECK_PTR( sn ); - sn->obj = notifier; - sn->gPollFD.fd = sockfd; - sn->gPollFD.events = events; - sn->events = events; // save events! - sn->pending = FALSE; - - list->append( sn ); - - g_source_add_poll(d->gSource, &sn->gPollFD); - -} - -void TQEventLoop::unregisterSocketNotifier( TQSocketNotifier *notifier ) -{ - int sockfd = notifier->socket(); - int type = notifier->type(); - if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQSocketNotifier: Internal error" ); -#endif - return; - } - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("unregister socket notifier %d\n", sockfd); -#endif - - TQPtrList *list = &d->sn_list; - TQSockNotGPollFD *sn; - if ( ! list ) { - return; - } - sn = list->first(); - while ( sn && !(sn->obj == notifier) ) { - sn = list->next(); - } - if ( !sn ) { // not found - return; - } - - d->sn_pending_list.removeRef( sn ); - list->remove(); // remove notifier found above - g_source_remove_poll(d->gSource, &sn->gPollFD); - - delete sn; // we don't autodelete - lets do it manually - -} - -void TQEventLoop::setSocketNotifierPending( TQSocketNotifier *notifier ) -{ - int sockfd = notifier->socket(); - int type = notifier->type(); - if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQSocketNotifier: Internal error" ); -#endif - return; - } - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("set socket notifier pending %d\n", sockfd); -#endif - - TQPtrList *list = &d->sn_list; - TQSockNotGPollFD *sn; - if ( ! list ) - return; - sn = list->first(); - while ( sn && !(sn->obj == notifier) ) - sn = list->next(); - if ( ! sn ) { // not found - return; - } - - // We choose a random activation order to be more fair under high load. - // If a constant order is used and a peer early in the list can - // saturate the IO, it might grab our attention completely. - // Also, if we're using a straight list, the callback routines may - // delete other entries from the list before those other entries are - // processed. - if ( !sn->pending ) { - d->sn_pending_list.insert( (rand() & 0xff) % - (d->sn_pending_list.count()+1), sn ); - sn->pending = TRUE; // add it only once! - } -} - -void TQEventLoop::wakeUp() -{ - /* - Apparently, there is not consistency among different operating - systems on how to use FIONREAD. - - FreeBSD, Linux and Solaris all expect the 3rd argument to - ioctl() to be an int, which is normally 32-bit even on 64-bit - machines. - - IRIX, on the other hand, expects a size_t, which is 64-bit on - 64-bit machines. - - So, the solution is to use size_t initialized to zero to make - sure all bits are set to zero, preventing underflow with the - FreeBSD/Linux/Solaris ioctls. - */ - size_t nbytes = 0; - char c = 0; - if ( ::ioctl( d->thread_pipe[0], FIONREAD, (char*)&nbytes ) >= 0 && nbytes == 0 ) { - if (::write( d->thread_pipe[1], &c, 1 ) < 0) { - // Failed! - } - } -} - -int TQEventLoop::timeToWait() const -{ - timeval *tm = qt_wait_timer(); - if ( !tm ) { // no active timers - return -1; - } - return (tm->tv_sec*1000) + (tm->tv_usec/1000); -} - -int TQEventLoop::activateTimers() -{ -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->lock(); -#endif - if ( !timerList || !timerList->count() ) { // no timers -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - return 0; - } - bool first = TRUE; - timeval currentTime; - int n_act = 0, maxCount = timerList->count(); - TimerInfo *begin = 0; - TimerInfo *t; - - for ( ;; ) { - if ( ! maxCount-- ) { - break; - } - getTime( currentTime ); // get current time - if ( first ) { - if ( currentTime < watchtime ) { // clock was turned back - repairTimer( currentTime ); - } - first = FALSE; - watchtime = currentTime; - } - t = timerList->first(); - if ( !t || currentTime < t->timeout ) { // no timer has expired - break; - } - if ( ! begin ) { - begin = t; - } - else if ( begin == t ) { - // avoid sending the same timer multiple times - break; - } - else if ( t->interval < begin->interval || t->interval == begin->interval ) { - begin = t; - } - timerList->take(); // unlink from list - t->timeout += t->interval; - if ( t->timeout < currentTime ) { - t->timeout = currentTime + t->interval; - } - insertTimer( t ); // relink timer - if ( t->interval.tv_usec > 0 || t->interval.tv_sec > 0 ) { - n_act++; - } -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - TQTimerEvent e( t->id ); -#if defined(TQT_THREAD_SUPPORT) - // Be careful...the current thread may not be the target object's thread! - if ((!t->obj) || - (TQThread::currentThreadObject() && TQThread::currentThreadObject()->threadPostedEventsDisabled()) || - (t->obj && t->obj->contextThreadObject() == TQThread::currentThreadObject())) { - TQApplication::sendEvent( t->obj, &e ); // send event - } - else { - TQApplication::postEvent( t->obj, new TQTimerEvent(e) ); // post event to correct thread - } -#else // defined(TQT_THREAD_SUPPORT) - TQApplication::sendEvent( t->obj, &e ); // send event -#endif // defined(TQT_THREAD_SUPPORT) -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->lock(); -#endif - if ( timerList->findRef( begin ) == -1 ) { - begin = 0; - } - } -#if defined(TQT_THREAD_SUPPORT) - if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif - return n_act; -} - -int TQEventLoop::activateSocketNotifiers() -{ - if ( d->sn_pending_list.isEmpty() ) { - return 0; - } - - // activate entries - int n_act = 0; - TQEvent event( TQEvent::SockAct ); - TQPtrListIterator it( d->sn_pending_list ); - TQSockNotGPollFD *sn; - while ( (sn=it.current()) ) { - ++it; - d->sn_pending_list.removeRef( sn ); - if ( sn->pending ) { -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("activate sn : send event fd=%d\n", sn->gPollFD.fd ); -#endif - sn->pending = FALSE; -#if defined(TQT_THREAD_SUPPORT) - // Be careful...the current thread may not be the target object's thread! - if ((!sn->obj) || - (TQThread::currentThreadObject() && TQThread::currentThreadObject()->threadPostedEventsDisabled()) || - (sn->obj && sn->obj->contextThreadObject() == TQThread::currentThreadObject())) { - TQApplication::sendEvent( sn->obj, &event ); // send event - } - else { - TQApplication::postEvent( sn->obj, new TQEvent(event) ); // post event to correct thread - } -#else // defined(TQT_THREAD_SUPPORT) - TQApplication::sendEvent( sn->obj, &event ); // send event -#endif // defined(TQT_THREAD_SUPPORT) - n_act++; - } - } - - return n_act; -} diff --git a/src/kernel/qeventloop_x11.cpp b/src/kernel/qeventloop_x11.cpp deleted file mode 100644 index db0bb4e71..000000000 --- a/src/kernel/qeventloop_x11.cpp +++ /dev/null @@ -1,425 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQEventLoop class -** -** 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. -** -**********************************************************************/ - -#include "qeventloop_p.h" // includes qplatformdefs.h -#include "ntqeventloop.h" -#include "ntqapplication.h" -#include "tqbitarray.h" -#include "tqcolor_p.h" -#include "qt_x11_p.h" - -#if defined(TQT_THREAD_SUPPORT) -# include "tqmutex.h" -#endif // TQT_THREAD_SUPPORT - -#include - - -// resolve the conflict between X11's FocusIn and TQEvent::FocusIn -#undef FocusOut -#undef FocusIn - -static const int XKeyPress = KeyPress; -static const int XKeyRelease = KeyRelease; -#undef KeyPress -#undef KeyRelease - -// from qapplication.cpp -extern bool tqt_is_gui_used; - -// from qeventloop_unix.cpp -extern timeval *qt_wait_timer(); -extern void cleanupTimers(); - -// ### this needs to go away at some point... -typedef void (*VFPTR)(); -typedef TQValueList TQVFuncList; -void qt_install_preselect_handler( VFPTR ); -void qt_remove_preselect_handler( VFPTR ); -static TQVFuncList *qt_preselect_handler = 0; -void qt_install_postselect_handler( VFPTR ); -void qt_remove_postselect_handler( VFPTR ); -static TQVFuncList *qt_postselect_handler = 0; - -void qt_install_preselect_handler( VFPTR handler ) -{ - if ( !qt_preselect_handler ) - qt_preselect_handler = new TQVFuncList; - qt_preselect_handler->append( handler ); -} -void qt_remove_preselect_handler( VFPTR handler ) -{ - if ( qt_preselect_handler ) { - TQVFuncList::Iterator it = qt_preselect_handler->find( handler ); - if ( it != qt_preselect_handler->end() ) - qt_preselect_handler->remove( it ); - } -} -void qt_install_postselect_handler( VFPTR handler ) -{ - if ( !qt_postselect_handler ) - qt_postselect_handler = new TQVFuncList; - qt_postselect_handler->prepend( handler ); -} -void qt_remove_postselect_handler( VFPTR handler ) -{ - if ( qt_postselect_handler ) { - TQVFuncList::Iterator it = qt_postselect_handler->find( handler ); - if ( it != qt_postselect_handler->end() ) - qt_postselect_handler->remove( it ); - } -} - - -void TQEventLoop::init() -{ - // initialize the common parts of the event loop - pipe( d->thread_pipe ); - fcntl(d->thread_pipe[0], F_SETFD, FD_CLOEXEC); - fcntl(d->thread_pipe[1], F_SETFD, FD_CLOEXEC); - - d->sn_highest = -1; - - // intitialize the X11 parts of the event loop - d->xfd = -1; - if ( tqt_is_gui_used ) - d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() ); -} - -void TQEventLoop::cleanup() -{ - // cleanup the common parts of the event loop - close( d->thread_pipe[0] ); - close( d->thread_pipe[1] ); - cleanupTimers(); - - // cleanup the X11 parts of the event loop - d->xfd = -1; -} - -bool TQEventLoop::processEvents( ProcessEventsFlags flags ) -{ - // process events from the X server - XEvent event; - int nevents = 0; - -#if defined(TQT_THREAD_SUPPORT) - TQMutexLocker locker( TQApplication::tqt_mutex ); -#endif - - // handle gui and posted events - if ( tqt_is_gui_used ) { - TQApplication::sendPostedEvents(); - - if (TQApplication::isGuiThread()) { - // Two loops so that posted events accumulate - while ( XPending( TQPaintDevice::x11AppDisplay() ) ) { - // also flushes output buffer - while ( XPending( TQPaintDevice::x11AppDisplay() ) ) { - if ( d->shortcut ) { - return FALSE; - } - - XNextEvent( TQPaintDevice::x11AppDisplay(), &event ); - - if ( flags & ExcludeUserInput ) { - switch ( event.type ) { - case ButtonPress: - case ButtonRelease: - case MotionNotify: - case XKeyPress: - case XKeyRelease: - case EnterNotify: - case LeaveNotify: - continue; - - case ClientMessage: - { - // from qapplication_x11.cpp - extern Atom tqt_wm_protocols; - extern Atom tqt_wm_take_focus; - extern Atom qt_qt_scrolldone; - - // only keep the wm_take_focus and - // qt_qt_scrolldone protocols, discard all - // other client messages - if ( event.xclient.format != 32 ) - continue; - - if ( event.xclient.message_type == tqt_wm_protocols || - (Atom) event.xclient.data.l[0] == tqt_wm_take_focus ) - break; - if ( event.xclient.message_type == qt_qt_scrolldone ) - break; - } - - default: break; - } - } - - nevents++; - if ( tqApp->x11ProcessEvent( &event ) == 1 ) - return TRUE; - } - } - } - } - - if ( d->shortcut ) { - return FALSE; - } - - TQApplication::sendPostedEvents(); - - const uint exclude_all = ExcludeSocketNotifiers | 0x08; - // 0x08 == ExcludeTimers for X11 only - if ( nevents > 0 && ( flags & exclude_all ) == exclude_all && - ( flags & WaitForMore ) ) { - return TRUE; - } - - // don't block if exitLoop() or exit()/quit() has been called. - bool canWait = d->exitloop || d->quitnow ? FALSE : (flags & WaitForMore); - - // Process timers and socket notifiers - the common UNIX stuff - - // return the maximum time we can wait for an event. - static timeval zerotm; - timeval *tm = 0; - if ( ! ( flags & 0x08 ) ) { // 0x08 == ExcludeTimers for X11 only - tm = qt_wait_timer(); // wait for timer or X event - if ( !canWait ) { - if ( !tm ) - tm = &zerotm; - tm->tv_sec = 0; // no time to wait - tm->tv_usec = 0; - } - } - - int highest = 0; - if ( ! ( flags & ExcludeSocketNotifiers ) ) { - // return the highest fd we can wait for input on - if ( d->sn_highest >= 0 ) { // has socket notifier(s) - if ( d->sn_vec[0].list && ! d->sn_vec[0].list->isEmpty() ) - d->sn_vec[0].select_fds = d->sn_vec[0].enabled_fds; - else - FD_ZERO( &d->sn_vec[0].select_fds ); - - if ( d->sn_vec[1].list && ! d->sn_vec[1].list->isEmpty() ) - d->sn_vec[1].select_fds = d->sn_vec[1].enabled_fds; - else - FD_ZERO( &d->sn_vec[1].select_fds ); - - if ( d->sn_vec[2].list && ! d->sn_vec[2].list->isEmpty() ) - d->sn_vec[2].select_fds = d->sn_vec[2].enabled_fds; - else - FD_ZERO( &d->sn_vec[2].select_fds ); - } else { - FD_ZERO( &d->sn_vec[0].select_fds ); - - FD_ZERO( &d->sn_vec[1].select_fds ); - FD_ZERO( &d->sn_vec[2].select_fds ); - } - - highest = d->sn_highest; - } else { - FD_ZERO( &d->sn_vec[0].select_fds ); - FD_ZERO( &d->sn_vec[1].select_fds ); - FD_ZERO( &d->sn_vec[2].select_fds ); - } - - if ( tqt_is_gui_used && TQApplication::isGuiThread() ) { - // select for events on the event socket - only on X11 - FD_SET( d->xfd, &d->sn_vec[0].select_fds ); - highest = TQMAX( highest, d->xfd ); - } - - FD_SET( d->thread_pipe[0], &d->sn_vec[0].select_fds ); - highest = TQMAX( highest, d->thread_pipe[0] ); - - if ( canWait ) - emit aboutToBlock(); - - if ( qt_preselect_handler ) { - TQVFuncList::Iterator it, end = qt_preselect_handler->end(); - for ( it = qt_preselect_handler->begin(); it != end; ++it ) - (**it)(); - } - - // unlock the GUI mutex and select. when we return from this function, there is - // something for us to do -#if defined(TQT_THREAD_SUPPORT) - if ( locker.mutex() ) locker.mutex()->unlock(); - else return false; -#endif - - int nsel; - do { - nsel = select( highest + 1, - &d->sn_vec[0].select_fds, - &d->sn_vec[1].select_fds, - &d->sn_vec[2].select_fds, - tm ); - } while (nsel == -1 && (errno == EINTR || errno == EAGAIN)); - - // relock the GUI mutex before processing any pending events -#if defined(TQT_THREAD_SUPPORT) - if ( locker.mutex() ) locker.mutex()->lock(); - else return false; -#endif - - // we are awake, broadcast it - emit awake(); - emit tqApp->guiThreadAwake(); - - if (nsel == -1) { - if (errno == EBADF) { - // it seems a socket notifier has a bad fd... find out - // which one it is and disable it - fd_set fdset; - zerotm.tv_sec = zerotm.tv_usec = 0l; - - for (int type = 0; type < 3; ++type) { - TQPtrList *list = d->sn_vec[type].list; - if (!list) continue; - - TQSockNot *sn = list->first(); - while (sn) { - FD_ZERO(&fdset); - FD_SET(sn->fd, &fdset); - - int ret = -1; - do { - switch (type) { - case 0: // read - ret = select(sn->fd + 1, &fdset, 0, 0, &zerotm); - break; - case 1: // write - ret = select(sn->fd + 1, 0, &fdset, 0, &zerotm); - break; - case 2: // except - ret = select(sn->fd + 1, 0, 0, &fdset, &zerotm); - break; - } - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); - - if (ret == -1 && errno == EBADF) { - // disable the invalid socket notifier - static const char *t[] = { "Read", "Write", "Exception" }; - tqWarning("TQSocketNotifier: invalid socket %d and type '%s', disabling...", - sn->fd, t[type]); - sn->obj->setEnabled(FALSE); - } - - sn = list->next(); - } - } - } else { - // EINVAL... shouldn't happen, so let's complain to stderr - // and hope someone sends us a bug report - perror( "select" ); - } - } - - // some other thread woke us up... consume the data on the thread pipe so that - // select doesn't immediately return next time - if ( nsel > 0 && FD_ISSET( d->thread_pipe[0], &d->sn_vec[0].select_fds ) ) { - char c; - ::read( d->thread_pipe[0], &c, 1 ); - } - - if ( qt_postselect_handler ) { - TQVFuncList::Iterator it, end = qt_postselect_handler->end(); - for ( it = qt_postselect_handler->begin(); it != end; ++it ) - (**it)(); - } - - // activate socket notifiers - if ( ! ( flags & ExcludeSocketNotifiers ) && nsel > 0 && d->sn_highest >= 0 ) { - // if select says data is ready on any socket, then set the socket notifier - // to pending - int i; - for ( i=0; i<3; i++ ) { - if ( ! d->sn_vec[i].list ) - continue; - - TQPtrList *list = d->sn_vec[i].list; - TQSockNot *sn = list->first(); - while ( sn ) { - if ( FD_ISSET( sn->fd, &d->sn_vec[i].select_fds ) ) - setSocketNotifierPending( sn->obj ); - sn = list->next(); - } - } - - nevents += activateSocketNotifiers(); - } - - // activate timers - if ( ! ( flags & 0x08 ) ) { - // 0x08 == ExcludeTimers for X11 only - nevents += activateTimers(); - } - - // color approx. optimization - only on X11 - qt_reset_color_avail(); - - // return true if we handled events, false otherwise - return (nevents > 0); -} - -bool TQEventLoop::hasPendingEvents() const -{ - extern uint qGlobalPostedEventsCount(); // from qapplication.cpp - return ( qGlobalPostedEventsCount() || XPending( TQPaintDevice::x11AppDisplay() ) ); -} - -void TQEventLoop::appStartingUp() -{ - if ( tqt_is_gui_used ) - d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() ); -} - -void TQEventLoop::appClosingDown() -{ - d->xfd = -1; -} - -void TQEventLoop::setSingleToolkitEventHandling(bool enabled) { - // Do nothing -} diff --git a/src/kernel/qeventloop_x11_glib.cpp b/src/kernel/qeventloop_x11_glib.cpp deleted file mode 100644 index ff64cb93c..000000000 --- a/src/kernel/qeventloop_x11_glib.cpp +++ /dev/null @@ -1,684 +0,0 @@ -/** -** TQt->glib main event loop integration by Norbert Frese 2005 -** code based on qeventloop_x11.cpp 3.3.5 -** -*/ - -/**************************************************************************** -** $Id: qt/qeventloop_x11_glib.cpp -** -** Implementation of TQEventLoop class -** -** Copyright (C) 2000-2005 Trolltech AS. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be distributed under the terms of the Q Public License -** as defined by Trolltech AS of Norway and appearing in the file -** LICENSE.TQPL included in the packaging of this file. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition -** licenses for Unix/X11 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 -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for -** information about TQt Commercial License Agreements. -** See http://www.trolltech.com/qpl/ for TQPL licensing information. -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#include "qeventloop_glib_p.h" // includes qplatformdefs.h -#include "ntqeventloop.h" -#include "ntqapplication.h" -#include "tqbitarray.h" -#include "tqcolor_p.h" -#include "qt_x11_p.h" - -#if defined(TQT_THREAD_SUPPORT) -# include "tqmutex.h" -# include "tqthread.h" -#endif // TQT_THREAD_SUPPORT - -#include - -#include -#include - -// #define DEBUG_QT_GLIBMAINLOOP 1 - -// TQt-GSource Structure and Callbacks - -typedef struct { - GSource source; - TQEventLoop * qeventLoop; -} TQtGSource; - -static gboolean qt_gsource_prepare ( GSource *source, gint *timeout ); -static gboolean qt_gsource_check ( GSource *source ); -static gboolean qt_gsource_dispatch ( GSource *source, GSourceFunc callback, gpointer user_data ); - -static GSourceFuncs qt_gsource_funcs = { - qt_gsource_prepare, - qt_gsource_check, - qt_gsource_dispatch, - NULL, - NULL, - NULL -}; - -// forward main loop callbacks to TQEventLoop methods! - -static gboolean qt_gsource_prepare ( GSource *source, gint *timeout ) -{ - TQtGSource * qtGSource = (TQtGSource*) source; - TQEventLoop* candidateEventLoop = qtGSource->qeventLoop; - TQEventLoop* activeThreadEventLoop = TQApplication::eventLoop(); - - if (candidateEventLoop == activeThreadEventLoop) { - return candidateEventLoop->gsourcePrepare(source, timeout); - } - else { - // Prepare failed - return FALSE; - } -} - -static gboolean qt_gsource_check ( GSource *source ) -{ - TQtGSource * qtGSource = (TQtGSource*) source; - TQEventLoop* candidateEventLoop = qtGSource->qeventLoop; - TQEventLoop* activeThreadEventLoop = TQApplication::eventLoop(); - - if (candidateEventLoop == activeThreadEventLoop) { - return candidateEventLoop->gsourceCheck(source); - } - else { - // Check failed - return FALSE; - } -} - -static gboolean qt_gsource_dispatch ( GSource *source, GSourceFunc callback, gpointer user_data ) -{ - Q_UNUSED(callback); - Q_UNUSED(user_data); - - TQtGSource * qtGSource = (TQtGSource*) source; - TQEventLoop* candidateEventLoop = qtGSource->qeventLoop; - TQEventLoop* activeThreadEventLoop = TQApplication::eventLoop(); - - if (candidateEventLoop == activeThreadEventLoop) { - return candidateEventLoop->gsourceDispatch(source); - } - else { - // Dispatch failed - return FALSE; - } -} - - -// ------------------------------------------------- - -// resolve the conflict between X11's FocusIn and TQEvent::FocusIn -#undef FocusOut -#undef FocusIn - -static const int XKeyPress = KeyPress; -static const int XKeyRelease = KeyRelease; -#undef KeyPress -#undef KeyRelease - -// from qapplication.cpp -extern bool tqt_is_gui_used; - -// from qeventloop_unix.cpp -extern timeval *qt_wait_timer(); -extern void cleanupTimers(); - -// ### this needs to go away at some point... -typedef void (*VFPTR)(); -typedef TQValueList TQVFuncList; -void qt_install_preselect_handler( VFPTR ); -void qt_remove_preselect_handler( VFPTR ); -static TQVFuncList *qt_preselect_handler = 0; -void qt_install_postselect_handler( VFPTR ); -void qt_remove_postselect_handler( VFPTR ); -static TQVFuncList *qt_postselect_handler = 0; - -void qt_install_preselect_handler( VFPTR handler ) -{ - if ( !qt_preselect_handler ) { - qt_preselect_handler = new TQVFuncList; - } - qt_preselect_handler->append( handler ); -} - -void qt_remove_preselect_handler( VFPTR handler ) -{ - if ( qt_preselect_handler ) { - TQVFuncList::Iterator it = qt_preselect_handler->find( handler ); - if ( it != qt_preselect_handler->end() ) { - qt_preselect_handler->remove( it ); - } - } -} - -void qt_install_postselect_handler( VFPTR handler ) -{ - if ( !qt_postselect_handler ) { - qt_postselect_handler = new TQVFuncList; - } - qt_postselect_handler->prepend( handler ); -} - -void qt_remove_postselect_handler( VFPTR handler ) -{ - if ( qt_postselect_handler ) { - TQVFuncList::Iterator it = qt_postselect_handler->find( handler ); - if ( it != qt_postselect_handler->end() ) { - qt_postselect_handler->remove( it ); - } - } -} - -void TQEventLoop::init() -{ - // initialize ProcessEventFlags (all events & wait for more) - d->pev_flags = AllEvents | WaitForMore; - - // initialize the common parts of the event loop - if (pipe( d->thread_pipe ) < 0) { - // Error! - } - fcntl(d->thread_pipe[0], F_SETFD, FD_CLOEXEC); - fcntl(d->thread_pipe[1], F_SETFD, FD_CLOEXEC); - - // intitialize the X11 parts of the event loop - d->xfd = -1; - if ( tqt_is_gui_used && TQApplication::isGuiThread() ) { - d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() ); - } - - // new main context for thread - d->ctx = g_main_context_new(); - g_main_context_push_thread_default(d->ctx); - d->ctx_is_default = true; - - // new GSource - TQtGSource * qtGSource = (TQtGSource*) g_source_new(&qt_gsource_funcs, sizeof(TQtGSource)); - g_source_set_can_recurse ((GSource*)qtGSource, TRUE); - qtGSource->qeventLoop = this; - - // init main loop and attach gsource -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside init(1)\n"); -#endif - - d->mainloop = g_main_loop_new (d->ctx, 1); - g_source_attach( (GSource*)qtGSource, d->ctx ); - d->gSource = (GSource*)qtGSource; - - // poll for X11 events - if ( tqt_is_gui_used && TQApplication::isGuiThread() ) { - d->x_gPollFD.fd = d->xfd; - d->x_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR; - g_source_add_poll(d->gSource, &d->x_gPollFD); - } - - // poll thread-pipe - d->threadPipe_gPollFD.fd = d->thread_pipe[0]; - d->threadPipe_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR; - - g_source_add_poll(d->gSource, &d->threadPipe_gPollFD); - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside init(2)\n"); -#endif -} - -void TQEventLoop::cleanup() -{ - // cleanup the common parts of the event loop - close( d->thread_pipe[0] ); - close( d->thread_pipe[1] ); - cleanupTimers(); - - // cleanup the X11 parts of the event loop - d->xfd = -1; - - // stop polling the GSource - g_source_remove_poll(d->gSource, &d->threadPipe_gPollFD); - g_source_remove_poll(d->gSource, &d->x_gPollFD); - g_source_destroy(d->gSource); - - // unref the main loop - g_main_loop_unref(d->mainloop); - d->mainloop = nullptr; - - // unref the gsource - g_source_unref(d->gSource); - d->gSource = nullptr; - - // unref the main context - g_main_context_unref(d->ctx); - d->ctx = nullptr; -} - -bool TQEventLoop::processEvents( ProcessEventsFlags flags ) -{ -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside processEvents(1) looplevel=%d eventloop=%p d->ctx=%p this=%p\n", d->looplevel, TQApplication::eventLoop(), d->ctx, this ); fflush(stdout); -#endif - - ProcessEventsFlags save_flags; - int rval; - save_flags = d->pev_flags; - - d->pev_flags = flags; - - rval = g_main_context_iteration(d->ctx, flags & WaitForMore ? TRUE : FALSE); - - d->pev_flags = save_flags; - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside processEvents(2) looplevel=%d eventloop=%p d->ctx=%p this=%p rval=%d\n", d->looplevel, TQApplication::eventLoop(), d->ctx, this, rval ); fflush(stdout); -#endif - - return rval; // were events processed? -} - - -bool TQEventLoop::processX11Events() -{ - ProcessEventsFlags flags = d->pev_flags; - // process events from the X server - XEvent event; - int nevents = 0; - -#if defined(TQT_THREAD_SUPPORT) - TQMutexLocker locker( TQApplication::tqt_mutex ); -#endif - - // handle gui and posted events - if ( tqt_is_gui_used ) { - TQApplication::sendPostedEvents(); - - if (TQApplication::isGuiThread()) { - // Two loops so that posted events accumulate - while ( XPending( TQPaintDevice::x11AppDisplay() ) ) { - // also flushes output buffer - while ( XPending( TQPaintDevice::x11AppDisplay() ) ) { - if ( d->shortcut ) { - return FALSE; - } - - XNextEvent( TQPaintDevice::x11AppDisplay(), &event ); - - if ( flags & ExcludeUserInput ) { - switch ( event.type ) { - case ButtonPress: - case ButtonRelease: - case MotionNotify: - case XKeyPress: - case XKeyRelease: - case EnterNotify: - case LeaveNotify: - continue; - - case ClientMessage: - { - // from qapplication_x11.cpp - extern Atom tqt_wm_protocols; - extern Atom tqt_wm_take_focus; - extern Atom qt_qt_scrolldone; - - // only keep the wm_take_focus and - // qt_qt_scrolldone protocols, discard all - // other client messages - if ( event.xclient.format != 32 ) - continue; - - if ( event.xclient.message_type == tqt_wm_protocols || - (Atom) event.xclient.data.l[0] == tqt_wm_take_focus ) - break; - if ( event.xclient.message_type == qt_qt_scrolldone ) - break; - } - - default: break; - } - } - - nevents++; - if ( tqApp->x11ProcessEvent( &event ) == 1 ) { - return TRUE; - } - } - } - } - } - - if ( d->shortcut ) { - return FALSE; - } - - TQApplication::sendPostedEvents(); - - const uint exclude_all = ExcludeSocketNotifiers | 0x08; - // 0x08 == ExcludeTimers for X11 only - if ( nevents > 0 && ( flags & exclude_all ) == exclude_all && ( flags & WaitForMore ) ) { - return TRUE; - } - return FALSE; -} - - -bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout) -{ - Q_UNUSED(gs); - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourcePrepare(1)\n"); -#endif - - ProcessEventsFlags flags = d->pev_flags; - -#if defined(TQT_THREAD_SUPPORT) - TQMutexLocker locker( TQApplication::tqt_mutex ); -#endif - - // don't block if exitLoop() or exit()/quit() has been called. - bool canWait = d->exitloop || d->quitnow ? FALSE : (flags & WaitForMore); - - // Process timers and socket notifiers - the common UNIX stuff - - // return the maximum time we can wait for an event. - static timeval zerotm; - timeval *tm = 0; - if ( ! ( flags & 0x08 ) ) { // 0x08 == ExcludeTimers for X11 only - tm = qt_wait_timer(); // wait for timer or X event - if ( !canWait ) { - if ( !tm ) { - tm = &zerotm; - } - tm->tv_sec = 0; // no time to wait - tm->tv_usec = 0; - } - } - - // include or exclude SocketNotifiers (by setting or cleaning poll events) - if ( ! ( flags & ExcludeSocketNotifiers ) ) { - TQPtrListIterator it( d->sn_list ); - TQSockNotGPollFD *sn; - while ( (sn=it.current()) ) { - ++it; - sn->gPollFD.events = sn->events; // restore poll events - } - } - else { - TQPtrListIterator it( d->sn_list ); - TQSockNotGPollFD *sn; - while ( (sn=it.current()) ) { - ++it; - sn->gPollFD.events = 0; // delete poll events - } - } - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourcePrepare(2) canwait=%d\n", canWait); -#endif - - if ( canWait ) { - emit aboutToBlock(); - } - - if ( qt_preselect_handler ) { - TQVFuncList::Iterator it, end = qt_preselect_handler->end(); - for ( it = qt_preselect_handler->begin(); it != end; ++it ) - (**it)(); - } - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourcePrepare(2.1) canwait=%d\n", canWait); -#endif - - // do we have to dispatch events? - if (hasPendingEvents()) { - *timeout = 0; // no time to stay in poll -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourcePrepare(3a)\n"); -#endif - return FALSE; - } - - // stay in poll until something happens? - if (!tm) { // fixme - *timeout = -1; // wait forever -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourcePrepare(3b) timeout=%d \n", *timeout); -#endif - return FALSE; - } - - // else timeout >=0 - *timeout = tm->tv_sec * 1000 + tm->tv_usec/1000; - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourcePrepare(3c) timeout=%d \n", *timeout); -#endif - - return FALSE; -} - - -bool TQEventLoop::gsourceCheck(GSource *gs) { - Q_UNUSED(gs); - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourceCheck(1)\n"); -#endif - - // Socketnotifier events? - TQPtrList *list = &d->sn_list; - //if ( list ) { - TQSockNotGPollFD *sn = list->first(); - while ( sn ) { - if ( sn->gPollFD.revents ) { - return TRUE; - } - sn = list->next(); - } - //} - - if (d->x_gPollFD.revents) { -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourceCheck(2) xfd!\n"); -#endif - - return TRUE; // we got events! - } - if (d->threadPipe_gPollFD.revents) { -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourceCheck(2) threadpipe!!\n"); -#endif - - return TRUE; // we got events! - } - if (hasPendingEvents()) { -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourceCheck(2) pendingEvents!\n"); -#endif - - return TRUE; // we got more X11 events! - } - - // check if we have timers to activate? - timeval * tm = qt_wait_timer(); - if (tm && (tm->tv_sec == 0 && tm->tv_usec == 0 )) { -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourceCheck(2) qtwaittimer!\n"); -#endif - - return TRUE; - } - - // nothing to dispatch -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourceCheck(2) nothing to dispatch!\n"); -#endif - - return FALSE; -} - - -bool TQEventLoop::gsourceDispatch(GSource *gs) { - Q_UNUSED(gs); - - // relock the GUI mutex before processing any pending events -#if defined(TQT_THREAD_SUPPORT) - TQMutexLocker locker( TQApplication::tqt_mutex ); -#endif -#if defined(TQT_THREAD_SUPPORT) - if (locker.mutex()) locker.mutex()->lock(); -#endif - - int nevents=0; - ProcessEventsFlags flags = d->pev_flags; - -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourceDispatch(1)\n"); -#endif - - // we are awake, broadcast it - emit awake(); - emit tqApp->guiThreadAwake(); - - // some other thread woke us up... consume the data on the thread pipe so that - // select doesn't immediately return next time - - if ( d->threadPipe_gPollFD.revents) { - char c; - if (::read( d->thread_pipe[0], &c, 1 ) < 0) { - // Error! - } - } - - if ( qt_postselect_handler ) { - TQVFuncList::Iterator it, end = qt_postselect_handler->end(); - for ( it = qt_postselect_handler->begin(); it != end; ++it ) - (**it)(); - } - - // activate socket notifiers - if ( ! ( flags & ExcludeSocketNotifiers )) { - // if select says data is ready on any socket, then set the socket notifier - // to pending - // if ( &d->sn_list ) { - TQPtrList *list = &d->sn_list; - TQSockNotGPollFD *sn = list->first(); - while ( sn ) { - if ( sn->gPollFD.revents ) - setSocketNotifierPending( sn->obj ); - sn = list->next(); - } - // } - - if (TQApplication::isGuiThread()) { - nevents += activateSocketNotifiers(); - } - } - - // activate timers - if ( ! ( flags & 0x08 ) ) { - // 0x08 == ExcludeTimers for X11 only - if (TQApplication::isGuiThread()) { - nevents += activateTimers(); - } - } - - // return true if we handled events, false otherwise - //return (nevents > 0); - - // now process x11 events! -#ifdef DEBUG_QT_GLIBMAINLOOP - printf("inside gsourceDispatch(2) hasPendingEvents=%d\n", hasPendingEvents()); -#endif - - if (hasPendingEvents()) { - // color approx. optimization - only on X11 - qt_reset_color_avail(); - -#if defined(TQT_THREAD_SUPPORT) - if (locker.mutex()) locker.mutex()->unlock(); -#endif - processX11Events(); - } - else { -#if defined(TQT_THREAD_SUPPORT) - if (locker.mutex()) locker.mutex()->unlock(); -#endif - } - - if (d->singletoolkit) { - return TRUE; // Eat the event - } - else { - return FALSE; // Pass the event on to GTK - } -} - -bool TQEventLoop::hasPendingEvents() const -{ -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( TQApplication::tqt_mutex ); -#endif // TQT_THREAD_SUPPORT - - extern uint qGlobalPostedEventsCount(); // from qapplication.cpp - return ( qGlobalPostedEventsCount() || ( (tqt_is_gui_used && TQApplication::isGuiThread()) ? XPending( TQPaintDevice::x11AppDisplay() ) : 0)); -} - -void TQEventLoop::appStartingUp() -{ - if ( tqt_is_gui_used ) { - d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() ); - if ( (d->x_gPollFD.fd == -1) && TQApplication::isGuiThread() ) { - d->x_gPollFD.fd = d->xfd; - d->x_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR; - g_source_add_poll(d->gSource, &d->x_gPollFD); - } - } -} - -void TQEventLoop::appClosingDown() -{ - d->xfd = -1; -} - -void TQEventLoop::setSingleToolkitEventHandling(bool enabled) { - d->singletoolkit = enabled; - - if (!d->singletoolkit) { - if (d->ctx_is_default) { - d->ctx_is_default = false; - g_main_context_pop_thread_default(d->ctx); - } - } - else { - if (!d->ctx_is_default) { - g_main_context_push_thread_default(d->ctx); - d->ctx_is_default = true; - } - } -} diff --git a/src/kernel/qt_kernel.pri b/src/kernel/qt_kernel.pri index c97ca4618..64424b6d6 100644 --- a/src/kernel/qt_kernel.pri +++ b/src/kernel/qt_kernel.pri @@ -16,14 +16,14 @@ kernel { $$KERNEL_P/tqcolor_p.h \ $$KERNEL_H/ntqconnection.h \ $$KERNEL_H/ntqcursor.h \ - $$KERNEL_H/ntqdesktopwidget.h \ + $$KERNEL_H/tqdesktopwidget.h \ $$KERNEL_H/tqdragobject.h \ $$KERNEL_H/ntqdrawutil.h \ $$KERNEL_H/tqdropsite.h \ - $$KERNEL_H/ntqevent.h \ - $$KERNEL_H/ntqeventloop.h \ - $$KERNEL_P/qeventloop_p.h \ - $$KERNEL_P/qeventloop_glib_p.h \ + $$KERNEL_H/tqevent.h \ + $$KERNEL_H/tqeventloop.h \ + $$KERNEL_P/tqeventloop_p.h \ + $$KERNEL_P/tqeventloop_glib_p.h \ $$KERNEL_H/ntqfocusdata.h \ $$KERNEL_H/tqfont.h \ $$KERNEL_P/tqfontdata_p.h \ @@ -39,7 +39,7 @@ kernel { $$KERNEL_H/ntqkeysequence.h \ $$KERNEL_H/ntqlayout.h \ $$KERNEL_P/qlayoutengine_p.h \ - $$KERNEL_H/ntqtranslator.h \ + $$KERNEL_H/tqtranslator.h \ $$KERNEL_H/ntqmetaobject.h \ $$KERNEL_H/tqmime.h \ $$KERNEL_H/tqmovie.h \ @@ -107,16 +107,16 @@ kernel { } glibmainloop { - HEADERS+=$$KERNEL_P/qeventloop_glib_p.h + HEADERS+=$$KERNEL_P/tqeventloop_glib_p.h } win32:SOURCES += $$KERNEL_CPP/qapplication_win.cpp \ $$KERNEL_CPP/tqclipboard_win.cpp \ $$KERNEL_CPP/tqcolor_win.cpp \ $$KERNEL_CPP/qcursor_win.cpp \ - $$KERNEL_CPP/qdesktopwidget_win.cpp \ + $$KERNEL_CPP/tqdesktopwidget_win.cpp \ $$KERNEL_CPP/qdnd_win.cpp \ - $$KERNEL_CPP/qeventloop_win.cpp \ + $$KERNEL_CPP/tqeventloop_win.cpp \ $$KERNEL_CPP/tqfont_win.cpp \ $$KERNEL_CPP/qinputcontext_win.cpp \ $$KERNEL_CPP/tqmime_win.cpp \ @@ -138,7 +138,7 @@ kernel { $$KERNEL_CPP/tqcolor_x11.cpp \ $$KERNEL_CPP/qcursor_x11.cpp \ $$KERNEL_CPP/qdnd_x11.cpp \ - $$KERNEL_CPP/qdesktopwidget_x11.cpp \ + $$KERNEL_CPP/tqdesktopwidget_x11.cpp \ $$KERNEL_CPP/tqfont_x11.cpp \ $$KERNEL_CPP/qinputcontext.cpp \ $$KERNEL_CPP/qinputcontext_x11.cpp \ @@ -152,9 +152,9 @@ kernel { $$KERNEL_CPP/tqwidgetcreate_x11.cpp \ $$KERNEL_CPP/tqfontengine_x11.cpp glibmainloop { - SOURCES += $$KERNEL_CPP/qeventloop_x11_glib.cpp + SOURCES += $$KERNEL_CPP/tqeventloop_x11_glib.cpp } else { - SOURCES += $$KERNEL_CPP/qeventloop_x11.cpp + SOURCES += $$KERNEL_CPP/tqeventloop_x11.cpp } } @@ -169,14 +169,14 @@ kernel { $$KERNEL_CPP/qcursor_mac.cpp \ $$KERNEL_CPP/tqmime_mac.cpp \ $$KERNEL_CPP/qdnd_mac.cpp \ - $$KERNEL_CPP/qdesktopwidget_mac.cpp \ + $$KERNEL_CPP/tqdesktopwidget_mac.cpp \ $$KERNEL_CPP/tqpixmap_mac.cpp \ $$KERNEL_CPP/tqprinter_mac.cpp \ $$KERNEL_CPP/tqpaintdevice_mac.cpp \ $$KERNEL_CPP/tqpainter_mac.cpp \ $$KERNEL_CPP/tqregion_mac.cpp \ $$KERNEL_CPP/tqwidget_mac.cpp \ - $$KERNEL_CPP/qeventloop_mac.cpp \ + $$KERNEL_CPP/tqeventloop_mac.cpp \ $$KERNEL_CPP/tqfont_mac.cpp \ $$KERNEL_CPP/tqfontengine_mac.cpp DEFINES += QMAC_ONE_PIXEL_LOCK @@ -184,9 +184,9 @@ kernel { SOURCES += $$KERNEL_CPP/tqprinter_unix.cpp \ $$KERNEL_CPP/qpsprinter.cpp glibmainloop { - SOURCES += $$KERNEL_CPP/qeventloop_unix_glib.cpp + SOURCES += $$KERNEL_CPP/tqeventloop_unix_glib.cpp } else { - SOURCES += $$KERNEL_CPP/qeventloop_unix.cpp + SOURCES += $$KERNEL_CPP/tqeventloop_unix.cpp } } @@ -208,8 +208,8 @@ kernel { $$KERNEL_CPP/tqdragobject.cpp \ $$KERNEL_CPP/qdrawutil.cpp \ $$KERNEL_CPP/tqdropsite.cpp \ - $$KERNEL_CPP/qevent.cpp \ - $$KERNEL_CPP/qeventloop.cpp \ + $$KERNEL_CPP/tqevent.cpp \ + $$KERNEL_CPP/tqeventloop.cpp \ $$KERNEL_CPP/qfocusdata.cpp \ $$KERNEL_CPP/tqfont.cpp \ $$KERNEL_CPP/tqfontdatabase.cpp \ @@ -220,7 +220,7 @@ kernel { $$KERNEL_CPP/qkeysequence.cpp \ $$KERNEL_CPP/qlayout.cpp \ $$KERNEL_CPP/qlayoutengine.cpp \ - $$KERNEL_CPP/qtranslator.cpp \ + $$KERNEL_CPP/tqtranslator.cpp \ $$KERNEL_CPP/qmetaobject.cpp \ $$KERNEL_CPP/tqmime.cpp \ $$KERNEL_CPP/tqmovie.cpp \ diff --git a/src/kernel/qtranslator.cpp b/src/kernel/qtranslator.cpp deleted file mode 100644 index cda1735ae..000000000 --- a/src/kernel/qtranslator.cpp +++ /dev/null @@ -1,1478 +0,0 @@ -/**************************************************************************** -** -** Localization database support. -** -** Created : 980906 -** -** Copyright (C) 1998-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 "qplatformdefs.h" - -// POSIX Large File Support redefines open -> open64 -static inline int qt_open(const char *pathname, int flags, mode_t mode) -{ return ::open(pathname, flags, mode); } -#if defined(open) -# undef open -#endif - -// POSIX Large File Support redefines truncate -> truncate64 -#if defined(truncate) -# undef truncate -#endif - -#include "ntqtranslator.h" - -#ifndef TQT_NO_TRANSLATION - -#include "tqfileinfo.h" -#include "tqwidgetlist.h" -#include "tqintdict.h" -#include "tqstring.h" -#include "ntqapplication.h" -#include "tqfile.h" -#include "tqbuffer.h" -#include "tqdatastream.h" -#include "tqmap.h" -#include "ntqtl.h" - -#if defined(Q_OS_UNIX) -#define QT_USE_MMAP -#endif - -// most of the headers below are already included in qplatformdefs.h -// also this lacks Large File support but that's probably irrelevant -#if defined(QT_USE_MMAP) -// for mmap -#include -#include -#include -#include -#include -// for htonl -#include -#endif - -#include - -/* -$ mcookie -3cb86418caef9c95cd211cbf60a1bddd -$ -*/ - -// magic number for the file -static const int MagicLength = 16; -static const uchar magic[MagicLength] = { - 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95, - 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd -}; - -static bool match( const char* found, const char* target ) -{ - // 0 means anything, "" means empty - return found == 0 || qstrcmp( found, target ) == 0; -} - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -/* - Yes, unfortunately, we have code here that depends on endianness. - The candidate is big endian (it comes from a .qm file) whereas the - target endianness depends on the system TQt is running on. -*/ -#ifdef Q_OS_TEMP -static int __cdecl cmp_uint32_little( const void* target, const void* candidate ) -#else -static int cmp_uint32_little( const void* target, const void* candidate ) -#endif -{ - const uchar* t = (const uchar*) target; - const uchar* c = (const uchar*) candidate; - return t[3] != c[0] ? (int) t[3] - (int) c[0] - : t[2] != c[1] ? (int) t[2] - (int) c[1] - : t[1] != c[2] ? (int) t[1] - (int) c[2] - : (int) t[0] - (int) c[3]; -} - -#ifdef Q_OS_TEMP -static int __cdecl cmp_uint32_big( const void* target, const void* candidate ) -#else -static int cmp_uint32_big( const void* target, const void* candidate ) -#endif -{ - const uchar* t = (const uchar*) target; - const uchar* c = (const uchar*) candidate; - return t[0] != c[0] ? (int) t[0] - (int) c[0] - : t[1] != c[1] ? (int) t[1] - (int) c[1] - : t[2] != c[2] ? (int) t[2] - (int) c[2] - : (int) t[3] - (int) c[3]; -} - -#if defined(Q_C_CALLBACKS) -} -#endif - -static int systemWordSize = 0; -static bool systemBigEndian; - -static uint elfHash( const char * name ) -{ - const uchar *k; - uint h = 0; - uint g; - - if ( name ) { - k = (const uchar *) name; - while ( *k ) { - h = ( h << 4 ) + *k++; - if ( (g = (h & 0xf0000000)) != 0 ) - h ^= g >> 24; - h &= ~g; - } - } - if ( !h ) - h = 1; - return h; -} - -extern bool qt_detectRTLLanguage(); - -class TQTranslatorPrivate { -public: - struct Offset { - Offset() - : h( 0 ), o( 0 ) { } - Offset( const TQTranslatorMessage& m, int offset ) - : h( m.hash() ), o( offset ) { } - - bool operator<( const Offset&k ) const { - return ( h != k.h ) ? h < k.h : o < k.o; - } - TQ_DUMMY_COMPARISON_OPERATOR(TQTranslatorPrivate::Offset) - uint h; - uint o; - }; - - enum { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69 }; - - TQTranslatorPrivate() : - unmapPointer( 0 ), unmapLength( 0 ), - messageArray( 0 ), offsetArray( 0 ), contextArray( 0 ) -#ifndef TQT_NO_TRANSLATION_BUILDER - , messages( 0 ) -#endif - { } - // TQTranslator must finalize this before deallocating it - - // for mmap'ed files, this is what needs to be unmapped. - char * unmapPointer; - unsigned int unmapLength; - - // for squeezed but non-file data, this is what needs to be deleted - TQByteArray * messageArray; - TQByteArray * offsetArray; - TQByteArray * contextArray; - -#ifndef TQT_NO_TRANSLATION_BUILDER - TQMap * messages; -#endif -#ifdef TQ_WS_WIN - int oldPermissionLookup; -#endif -}; - - -/*! - \class TQTranslator - - \brief The TQTranslator class provides internationalization support for text - output. - - \ingroup i18n - \ingroup environment - \mainclass - - An object of this class contains a set of TQTranslatorMessage - objects, each of which specifies a translation from a source - language to a target language. TQTranslator provides functions to - look up translations, add new ones, remove them, load and save - them, etc. - - The most common use of TQTranslator is to: load a translator file - created with \link linguist-manual.book TQt Linguist\endlink, - install it using TQApplication::installTranslator(), and use it via - TQObject::tr(). For example: - - \code - int main( int argc, char ** argv ) - { - TQApplication app( argc, argv ); - - TQTranslator translator( 0 ); - translator.load( "french.qm", "." ); - app.installTranslator( &translator ); - - MyWidget m; - app.setMainWidget( &m ); - m.show(); - - return app.exec(); - } - \endcode - Note that the translator must be created \e before the - application's main window. - - Most applications will never need to do anything else with this - class. The other functions provided by this class are useful for - applications that work on translator files. - - We call a translation a "messsage". For this reason, translation - files are sometimes referred to as "message files". - - It is possible to lookup a translation using findMessage() (as - tr() and TQApplication::translate() do) and contains(), to insert a - new translation messsage using insert(), and to remove one using - remove(). - - Translation tools often need more information than the bare source - text and translation, for example, context information to help - the translator. But end-user programs that are using translations - usually only need lookup. To cater for these different needs, - TQTranslator can use stripped translator files that use the minimum - of memory and which support little more functionality than - findMessage(). - - Thus, load() may not load enough information to make anything more - than findMessage() work. save() has an argument indicating - whether to save just this minimum of information or to save - everything. - - "Everything" means that for each translation item the following - information is kept: - - \list - \i The \e {translated text} - the return value from tr(). - \i The input key: - \list - \i The \e {source text} - usually the argument to tr(). - \i The \e context - usually the class name for the tr() caller. - \i The \e comment - a comment that helps disambiguate different uses - of the same text in the same context. - \endlist - \endlist - - The minimum for each item is just the information necessary for - findMessage() to return the right text. This may include the - source, context and comment, but usually it is just a hash value - and the translated text. - - For example, the "Cancel" in a dialog might have "Anuluj" when the - program runs in Polish (in this case the source text would be - "Cancel"). The context would (normally) be the dialog's class - name; there would normally be no comment, and the translated text - would be "Anuluj". - - But it's not always so simple. The Spanish version of a printer - dialog with settings for two-sided printing and binding would - probably require both "Activado" and "Activada" as translations - for "Enabled". In this case the source text would be "Enabled" in - both cases, and the context would be the dialog's class name, but - the two items would have disambiguating comments such as - "two-sided printing" for one and "binding" for the other. The - comment enables the translator to choose the appropriate gender - for the Spanish version, and enables TQt to distinguish between - translations. - - Note that when TQTranslator loads a stripped file, most functions - do not work. The functions that do work with stripped files are - explicitly documented as such. - - \sa TQTranslatorMessage TQApplication::installTranslator() - TQApplication::removeTranslator() TQObject::tr() TQApplication::translate() -*/ - -/*! - \enum TQTranslator::SaveMode - - This enum type defines how TQTranslator writes translation - files. There are two modes: - - \value Everything files are saved with all available information - \value Stripped files are saved with just enough information for - end-user applications - - Note that when TQTranslator loads a stripped file, most functions do - not work. The functions that do work with stripped files are - explicitly documented as such. -*/ - -#if defined(TQ_WS_WIN) -extern int qt_ntfs_permission_lookup; -#endif - -/*! - Constructs an empty message file object that is not connected to - any file. The object is called \a name with parent \a parent. -*/ - -TQTranslator::TQTranslator( TQObject * parent, const char * name ) - : TQObject( parent, name ) -{ - d = new TQTranslatorPrivate; -#if defined(TQ_WS_WIN) - d->oldPermissionLookup = qt_ntfs_permission_lookup; -#endif -} - - -/*! - Destroys the object and frees any allocated resources. -*/ - -TQTranslator::~TQTranslator() -{ - if ( tqApp ) - tqApp->removeTranslator( this ); - clear(); - delete d; -} - - -extern bool qt_detectRTLLanguage(); - -/*! - Loads \a filename, which may be an absolute file name or relative - to \a directory. The previous contents of this translator object - is discarded. Returns TRUE if the file is loaded successfully; - otherwise returns FALSE. - - If the full file name does not exist, other file names are tried - in the following order: - - \list 1 - \i File name with \a suffix appended (".qm" if the \a suffix is - TQString::null). - \i File name with text after a character in \a search_delimiters - stripped ("_." is the default for \a search_delimiters if it is - TQString::null). - \i File name stripped and \a suffix appended. - \i File name stripped further, etc. - \endlist - - For example, an application running in the fr_CA locale - (French-speaking Canada) might call load("foo.fr_ca", - "/opt/foolib"). load() would then try to open the first existing - readable file from this list: - - \list 1 - \i /opt/foolib/foo.fr_ca - \i /opt/foolib/foo.fr_ca.qm - \i /opt/foolib/foo.fr - \i /opt/foolib/foo.fr.qm - \i /opt/foolib/foo - \i /opt/foolib/foo.qm - \endlist - - \sa save() -*/ - -bool TQTranslator::load( const TQString & filename, const TQString & directory, - const TQString & search_delimiters, - const TQString & suffix ) -{ - clear(); - - TQString prefix; - - if ( filename[0] == '/' -#ifdef TQ_WS_WIN - || (filename[0] && filename[1] == ':') || filename[0] == '\\' -#endif - ) - prefix = TQString::fromLatin1( "" ); - else - prefix = directory; - - if ( prefix.length() ) { - if ( prefix[int(prefix.length()-1)] != '/' ) - prefix += TQChar( '/' ); - } - - TQString fname = filename; - TQString realname; - TQString delims; - delims = search_delimiters.isNull() ? - TQString::fromLatin1( "_." ) : search_delimiters; - -#if defined(TQ_WS_WIN) - qt_ntfs_permission_lookup--; -#endif - for ( ;; ) { - TQFileInfo fi; - - realname = prefix + fname; - fi.setFile( realname ); - if ( fi.isReadable() ) - break; - - realname += suffix.isNull() ? TQString::fromLatin1( ".qm" ) : suffix; - fi.setFile( realname ); - if ( fi.isReadable() ) - break; - - int rightmost = 0; - for ( int i = 0; i < (int)delims.length(); i++ ) { - int k = fname.findRev( delims[i] ); - if ( k > rightmost ) - rightmost = k; - } - - // no truncations? fail - if ( rightmost == 0 ) { -#if defined(TQ_WS_WIN) - if (d->oldPermissionLookup != qt_ntfs_permission_lookup) - qt_ntfs_permission_lookup++; -#endif - return FALSE; - } - - fname.truncate( rightmost ); - } -#if defined(TQ_WS_WIN) - if (d->oldPermissionLookup != qt_ntfs_permission_lookup) - qt_ntfs_permission_lookup++; -#endif - - // realname is now the fully qualified name of a readable file. - -#if defined(QT_USE_MMAP) - -#ifndef MAP_FILE -#define MAP_FILE 0 -#endif -#ifndef MAP_FAILED -#define MAP_FAILED -1 -#endif - - int f; - - f = qt_open( TQFile::encodeName(realname), O_RDONLY, 0666 ); - if ( f < 0 ) { - // tqDebug( "can't open %s: %s", realname.ascii(), strerror( errno ) ); - return FALSE; - } - - struct stat st; - if ( fstat( f, &st ) ) { - // tqDebug( "can't stat %s: %s", realname.ascii(), strerror( errno ) ); - return FALSE; - } - char * tmp; - tmp = (char*)mmap( 0, st.st_size, // any address, whole file - PROT_READ, // read-only memory - MAP_FILE | MAP_PRIVATE, // swap-backed map from file - f, 0 ); // from offset 0 of f - if ( !tmp || tmp == (char*)MAP_FAILED ) { - // tqDebug( "can't mmap %s: %s", filename.ascii(), strerror( errno ) ); - return FALSE; - } - - ::close( f ); - - d->unmapPointer = tmp; - d->unmapLength = st.st_size; -#else - TQFile f( realname ); - if ( !f.exists() ) - return FALSE; - d->unmapLength = f.size(); - d->unmapPointer = new char[d->unmapLength]; - bool ok = FALSE; - if ( f.open(IO_ReadOnly) ) { - ok = d->unmapLength == - (uint)f.readBlock( d->unmapPointer, d->unmapLength ); - f.close(); - } - if ( !ok ) { - delete [] d->unmapPointer; - d->unmapPointer = 0; - return FALSE; - } -#endif - - return do_load( (const uchar *) d->unmapPointer, d->unmapLength ); -} - -/*! - \overload - \fn bool TQTranslator::load( const uchar *data, int len ) - - Loads the .qm file data \a data of length \a len into the - translator. Returns TRUE if the data is loaded successfully; - otherwise returns FALSE. - - The data is not copied. The caller must be able to guarantee that \a data - will not be deleted or modified. -*/ - -bool TQTranslator::do_load( const uchar *data, int len ) -{ - if ( len < MagicLength || memcmp( data, magic, MagicLength ) != 0 ) { - clear(); - return FALSE; - } - - TQByteArray array; - array.setRawData( (const char *) data, len ); - TQDataStream s( array, IO_ReadOnly ); - bool ok = TRUE; - - s.device()->at( MagicLength ); - - TQ_UINT8 tag = 0; - TQ_UINT32 blockLen = 0; - s >> tag >> blockLen; - while ( tag && blockLen ) { - if ( (TQ_UINT32) s.device()->at() + blockLen > (TQ_UINT32) len ) { - ok = FALSE; - break; - } - - if ( tag == TQTranslatorPrivate::Contexts && !d->contextArray ) { - d->contextArray = new TQByteArray; - d->contextArray->setRawData( array.data() + s.device()->at(), - blockLen ); - } else if ( tag == TQTranslatorPrivate::Hashes && !d->offsetArray ) { - d->offsetArray = new TQByteArray; - d->offsetArray->setRawData( array.data() + s.device()->at(), - blockLen ); - } else if ( tag == TQTranslatorPrivate::Messages && !d->messageArray ) { - d->messageArray = new TQByteArray; - d->messageArray->setRawData( array.data() + s.device()->at(), - blockLen ); - } - - if ( !s.device()->at(s.device()->at() + blockLen) ) { - ok = FALSE; - break; - } - tag = 0; - blockLen = 0; - if ( !s.atEnd() ) - s >> tag >> blockLen; - } - array.resetRawData( (const char *) data, len ); - - if ( tqApp && tqApp->translators && tqApp->translators->contains(this) ) - tqApp->setReverseLayout( qt_detectRTLLanguage() ); - return ok; -} - -#ifndef TQT_NO_TRANSLATION_BUILDER - -/*! - Saves this message file to \a filename, overwriting the previous - contents of \a filename. If \a mode is \c Everything (the - default), all the information is preserved. If \a mode is \c - Stripped, any information that is not necessary for findMessage() - is stripped away. - - \sa load() -*/ - -bool TQTranslator::save( const TQString & filename, SaveMode mode ) -{ - TQFile f( filename ); - if ( f.open( IO_WriteOnly ) ) { - squeeze( mode ); - - TQDataStream s( &f ); - s.writeRawBytes( (const char *)magic, MagicLength ); - TQ_UINT8 tag; - - if ( d->offsetArray != 0 ) { - tag = (TQ_UINT8) TQTranslatorPrivate::Hashes; - TQ_UINT32 oas = (TQ_UINT32) d->offsetArray->size(); - s << tag << oas; - s.writeRawBytes( d->offsetArray->data(), oas ); - } - if ( d->messageArray != 0 ) { - tag = (TQ_UINT8) TQTranslatorPrivate::Messages; - TQ_UINT32 mas = (TQ_UINT32) d->messageArray->size(); - s << tag << mas; - s.writeRawBytes( d->messageArray->data(), mas ); - } - if ( d->contextArray != 0 ) { - tag = (TQ_UINT8) TQTranslatorPrivate::Contexts; - TQ_UINT32 cas = (TQ_UINT32) d->contextArray->size(); - s << tag << cas; - s.writeRawBytes( d->contextArray->data(), cas ); - } - return TRUE; - } - return FALSE; -} - -#endif - -/*! - Empties this translator of all contents. - - This function works with stripped translator files. -*/ - -void TQTranslator::clear() -{ - if ( d->unmapPointer && d->unmapLength ) { -#if defined(QT_USE_MMAP) - munmap( d->unmapPointer, d->unmapLength ); -#else - delete [] d->unmapPointer; -#endif - d->unmapPointer = 0; - d->unmapLength = 0; - } - - if ( d->messageArray ) { - d->messageArray->resetRawData( d->messageArray->data(), - d->messageArray->size() ); - delete d->messageArray; - d->messageArray = 0; - } - if ( d->offsetArray ) { - d->offsetArray->resetRawData( d->offsetArray->data(), - d->offsetArray->size() ); - delete d->offsetArray; - d->offsetArray = 0; - } - if ( d->contextArray ) { - d->contextArray->resetRawData( d->contextArray->data(), - d->contextArray->size() ); - delete d->contextArray; - d->contextArray = 0; - } -#ifndef TQT_NO_TRANSLATION_BUILDER - delete d->messages; - d->messages = 0; -#endif - - if ( tqApp ) { - tqApp->setReverseLayout( qt_detectRTLLanguage() ); - - TQWidgetList *list = TQApplication::topLevelWidgets(); - TQWidgetListIt it( *list ); - TQWidget *w; - while ( ( w=it.current() ) != 0 ) { - ++it; - if (!w->isDesktop()) - tqApp->postEvent( w, new TQEvent( TQEvent::LanguageChange ) ); - } - delete list; - } -} - -#ifndef TQT_NO_TRANSLATION_BUILDER - -/*! - Converts this message file to the compact format used to store - message files on disk. - - You should never need to call this directly; save() and other - functions call it as necessary. \a mode is for internal use. - - \sa save() unsqueeze() -*/ - -void TQTranslator::squeeze( SaveMode mode ) -{ - if ( !d->messages ) { - if ( mode == Stripped ) - unsqueeze(); - else - return; - } - - TQMap * messages = d->messages; - - d->messages = 0; - clear(); - - d->messageArray = new TQByteArray; - d->offsetArray = new TQByteArray; - - TQMap offsets; - - TQDataStream ms( *d->messageArray, IO_WriteOnly ); - TQMap::Iterator it = messages->begin(), next; - int cpPrev = 0, cpNext = 0; - for ( it = messages->begin(); it != messages->end(); ++it ) { - cpPrev = cpNext; - next = it; - ++next; - if ( next == messages->end() ) - cpNext = 0; - else - cpNext = (int) it.key().commonPrefix( next.key() ); - offsets.replace( TQTranslatorPrivate::Offset(it.key(), - ms.device()->at()), (void*)0 ); - it.key().write( ms, mode == Stripped, - (TQTranslatorMessage::Prefix) TQMAX(cpPrev, cpNext + 1) ); - } - - d->offsetArray->resize( 0 ); - TQMap::Iterator offset; - offset = offsets.begin(); - TQDataStream ds( *d->offsetArray, IO_WriteOnly ); - while ( offset != offsets.end() ) { - TQTranslatorPrivate::Offset k = offset.key(); - ++offset; - ds << (TQ_UINT32)k.h << (TQ_UINT32)k.o; - } - - if ( mode == Stripped ) { - TQAsciiDict contextSet( 1511 ); - int baudelaire; - - for ( it = messages->begin(); it != messages->end(); ++it ) - contextSet.replace( it.key().context(), &baudelaire ); - - TQ_UINT16 hTableSize; - if ( contextSet.count() < 200 ) - hTableSize = ( contextSet.count() < 60 ) ? 151 : 503; - else if ( contextSet.count() < 2500 ) - hTableSize = ( contextSet.count() < 750 ) ? 1511 : 5003; - else - hTableSize = 15013; - - TQIntDict hDict( hTableSize ); - TQAsciiDictIterator c = contextSet; - while ( c.current() != 0 ) { - hDict.insert( (long) (elfHash(c.currentKey()) % hTableSize), - c.currentKey() ); - ++c; - } - - /* - The contexts found in this translator are stored in a hash - table to provide fast lookup. The context array has the - following format: - - TQ_UINT16 hTableSize; - TQ_UINT16 hTable[hTableSize]; - TQ_UINT8 contextPool[...]; - - The context pool stores the contexts as Pascal strings: - - TQ_UINT8 len; - TQ_UINT8 data[len]; - - Let's consider the look-up of context "FunnyDialog". A - hash value between 0 and hTableSize - 1 is computed, say h. - If hTable[h] is 0, "FunnyDialog" is not covered by this - translator. Else, we check in the contextPool at offset - 2 * hTable[h] to see if "FunnyDialog" is one of the - contexts stored there, until we find it or we meet the - empty string. - */ - d->contextArray = new TQByteArray; - d->contextArray->resize( 2 + (hTableSize << 1) ); - TQDataStream t( *d->contextArray, IO_WriteOnly ); - TQ_UINT16 *hTable = new TQ_UINT16[hTableSize]; - memset( hTable, 0, hTableSize * sizeof(TQ_UINT16) ); - - t << hTableSize; - t.device()->at( 2 + (hTableSize << 1) ); - t << (TQ_UINT16) 0; // the entry at offset 0 cannot be used - uint upto = 2; - - for ( int i = 0; i < hTableSize; i++ ) { - const char *con = hDict.find( i ); - if ( con == 0 ) { - hTable[i] = 0; - } else { - hTable[i] = (TQ_UINT16) ( upto >> 1 ); - do { - uint len = (uint) tqstrlen( con ); - len = TQMIN( len, 255 ); - t << (TQ_UINT8) len; - t.writeRawBytes( con, len ); - upto += 1 + len; - hDict.remove( i ); - } while ( (con = hDict.find(i)) != 0 ); - do { - t << (TQ_UINT8) 0; // empty string (at least one) - upto++; - } while ( (upto & 0x1) != 0 ); // offsets have to be even - } - } - t.device()->at( 2 ); - for ( int j = 0; j < hTableSize; j++ ) - t << hTable[j]; - delete [] hTable; - - if ( upto > 131072 ) { - tqWarning( "TQTranslator::squeeze: Too many contexts" ); - delete d->contextArray; - d->contextArray = 0; - } - } - delete messages; -} - - -/*! - Converts this message file into an easily modifiable data - structure, less compact than the format used in the files. - - You should never need to call this function; it is called by - insert() and friends as necessary. - - \sa squeeze() -*/ - -void TQTranslator::unsqueeze() -{ - if ( d->messages ) - return; - - d->messages = new TQMap; - if ( !d->messageArray ) - return; - - TQDataStream s( *d->messageArray, IO_ReadOnly ); - for ( ;; ) { - TQTranslatorMessage m( s ); - if ( m.hash() == 0 ) - break; - d->messages->insert( m, (void *) 0 ); - } -} - - -/*! - Returns TRUE if this message file contains a message with the key - (\a context, \a sourceText, \a comment); otherwise returns FALSE. - - This function works with stripped translator files. - - (This is is a one-liner that calls findMessage().) -*/ - -bool TQTranslator::contains( const char* context, const char* sourceText, - const char* comment ) const -{ - return !findMessage( context, sourceText, comment ).translation().isNull(); -} - - -/*! - Inserts \a message into this message file. - - This function does \e not work with stripped translator files. It - may appear to, but that is not dependable. - - \sa remove() -*/ - -void TQTranslator::insert( const TQTranslatorMessage& message ) -{ - unsqueeze(); - d->messages->remove( message ); // safer - d->messages->insert( message, (void *) 0 ); -} - - -/*! - \fn void TQTranslator::insert( const char *, const char *, const TQString & ) - \overload - \obsolete -*/ - -/*! - Removes \a message from this translator. - - This function works with stripped translator files. - - \sa insert() -*/ - -void TQTranslator::remove( const TQTranslatorMessage& message ) -{ - unsqueeze(); - d->messages->remove( message ); -} - - -/*! - \fn void TQTranslator::remove( const char *, const char * ) - \overload - \obsolete - - Removes the translation associated to the key (\a context, \a sourceText, - "") from this translator. -*/ -#endif - -/*! - \fn TQString TQTranslator::find( const char*, const char*, const char* ) const - \obsolete - - Please use findMessage() instead. - - Returns the translation for the key (\a context, \a sourceText, - \a comment) or TQString::null if there is none in this translator. -*/ - -/*! Returns the TQTranslatorMessage for the key - (\a context, \a sourceText, \a comment). If none is found, - also tries (\a context, \a sourceText, ""). -*/ - -TQTranslatorMessage TQTranslator::findMessage( const char* context, - const char* sourceText, - const char* comment ) const -{ - if ( context == 0 ) - context = ""; - if ( sourceText == 0 ) - sourceText = ""; - if ( comment == 0 ) - comment = ""; - -#ifndef TQT_NO_TRANSLATION_BUILDER - if ( d->messages ) { - TQMap::ConstIterator it; - - it = d->messages->find( TQTranslatorMessage(context, sourceText, - comment) ); - if ( it != d->messages->end() ) - return it.key(); - - if ( comment[0] ) { - it = d->messages->find( TQTranslatorMessage(context, sourceText, - "") ); - if ( it != d->messages->end() ) - return it.key(); - } - return TQTranslatorMessage(); - } -#endif - - if ( !d->offsetArray ) - return TQTranslatorMessage(); - - /* - Check if the context belongs to this TQTranslator. If many translators are - installed, this step is necessary. - */ - if ( d->contextArray ) { - TQ_UINT16 hTableSize = 0; - TQDataStream t( *d->contextArray, IO_ReadOnly ); - t >> hTableSize; - uint g = elfHash( context ) % hTableSize; - t.device()->at( 2 + (g << 1) ); - TQ_UINT16 off; - t >> off; - if ( off == 0 ) - return TQTranslatorMessage(); - t.device()->at( 2 + (hTableSize << 1) + (off << 1) ); - - TQ_UINT8 len; - char con[256]; - for ( ;; ) { - t >> len; - if ( len == 0 || t.atEnd() ) - return TQTranslatorMessage(); - t.readRawBytes( con, len ); - con[len] = '\0'; - if ( qstrcmp(con, context) == 0 ) - break; - } - } - - size_t numItems = d->offsetArray->size() / ( 2 * sizeof(TQ_UINT32) ); - if ( !numItems ) - return TQTranslatorMessage(); - - if ( systemWordSize == 0 ) - tqSysInfo( &systemWordSize, &systemBigEndian ); - - for ( ;; ) { - TQ_UINT32 h = elfHash( TQCString(sourceText) + comment ); - - char *r = (char *) bsearch( &h, d->offsetArray->data(), numItems, - 2 * sizeof(TQ_UINT32), - systemBigEndian ? cmp_uint32_big - : cmp_uint32_little ); - if ( r != 0 ) { - // go back on equal key - while ( r != d->offsetArray->data() && - cmp_uint32_big(r - 8, r) == 0 ) - r -= 8; - - TQDataStream s( *d->offsetArray, IO_ReadOnly ); - s.device()->at( r - d->offsetArray->data() ); - - TQ_UINT32 rh, ro; - s >> rh >> ro; - - TQDataStream ms( *d->messageArray, IO_ReadOnly ); - while ( rh == h ) { - ms.device()->at( ro ); - TQTranslatorMessage m( ms ); - if ( match(m.context(), context) - && match(m.sourceText(), sourceText) - && match(m.comment(), comment) ) - return m; - if ( s.atEnd() ) - break; - s >> rh >> ro; - } - } - if ( !comment[0] ) - break; - comment = ""; - } - return TQTranslatorMessage(); -} - -/*! - Returns TRUE if this translator is empty, otherwise returns FALSE. - This function works with stripped and unstripped translation files. -*/ -bool TQTranslator::isEmpty() const -{ - return !( d->unmapPointer || d->unmapLength || d->messageArray || - d->offsetArray || d->contextArray -#ifndef TQT_NO_TRANSLATION_BUILDER - || (d->messages && d->messages->count()) -#endif - ); -} - - -#ifndef TQT_NO_TRANSLATION_BUILDER - -/*! - Returns a list of the messages in the translator. This function is - rather slow. Because it is seldom called, it's optimized for - simplicity and small size, rather than speed. - - If you want to iterate over the list, you should iterate over a - copy, e.g. - \code - TQValueList list = myTranslator.messages(); - TQValueList::Iterator it = list.begin(); - while ( it != list.end() ) { - process_message( *it ); - ++it; - } - \endcode -*/ - -TQValueList TQTranslator::messages() const -{ - if ( d->messages ) - return d->messages->keys(); - - ((TQTranslator *) this)->unsqueeze(); - TQValueList result = d->messages->keys(); - delete d->messages; - d->messages = 0; - return result; -} - -#endif - -/*! - \class TQTranslatorMessage - - \brief The TQTranslatorMessage class contains a translator message and its - properties. - - \ingroup i18n - \ingroup environment - - This class is of no interest to most applications. It is useful - for translation tools such as \link linguist-manual.book TQt - Linguist\endlink. It is provided simply to make the API complete - and regular. - - For a TQTranslator object, a lookup key is a triple (\e context, \e - {source text}, \e comment) that uniquely identifies a message. An - extended key is a quadruple (\e hash, \e context, \e {source - text}, \e comment), where \e hash is computed from the source text - and the comment. Unless you plan to read and write messages - yourself, you need not worry about the hash value. - - TQTranslatorMessage stores this triple or quadruple and the relevant - translation if there is any. - - \sa TQTranslator -*/ - -/*! - Constructs a translator message with the extended key (0, 0, 0, 0) - and TQString::null as translation. -*/ - -TQTranslatorMessage::TQTranslatorMessage() - : h( 0 ), cx( 0 ), st( 0 ), cm( 0 ) -{ -} - - -/*! - Constructs an translator message with the extended key (\e h, \a - context, \a sourceText, \a comment), where \e h is computed from - \a sourceText and \a comment, and possibly with a \a translation. -*/ - -TQTranslatorMessage::TQTranslatorMessage( const char * context, - const char * sourceText, - const char * comment, - const TQString& translation ) - : cx( context ), st( sourceText ), cm( comment ), tn( translation ) -{ - // 0 means we don't know, "" means empty - if ( cx == (const char*)0 ) - cx = ""; - if ( st == (const char*)0 ) - st = ""; - if ( cm == (const char*)0 ) - cm = ""; - h = elfHash( st + cm ); -} - - -/*! - Constructs a translator message read from the \a stream. The - resulting message may have any combination of content. - - \sa TQTranslator::save() -*/ - -TQTranslatorMessage::TQTranslatorMessage( TQDataStream & stream ) - : cx( 0 ), st( 0 ), cm( 0 ) -{ - TQString str16; - char tag; - TQ_UINT8 obs1; - - for ( ;; ) { - tag = 0; - if ( !stream.atEnd() ) - stream.readRawBytes( &tag, 1 ); - switch( (Tag)tag ) { - case Tag_End: - if ( h == 0 ) - h = elfHash( st + cm ); - return; - case Tag_SourceText16: // obsolete - stream >> str16; - st = str16.latin1(); - break; - case Tag_Translation: - stream >> tn; - break; - case Tag_Context16: // obsolete - stream >> str16; - cx = str16.latin1(); - break; - case Tag_Hash: - stream >> h; - break; - case Tag_SourceText: - stream >> st; - break; - case Tag_Context: - stream >> cx; - if ( cx == "" ) // for compatibility - cx = 0; - break; - case Tag_Comment: - stream >> cm; - break; - case Tag_Obsolete1: // obsolete - stream >> obs1; - break; - default: - h = 0; - st = 0; - cx = 0; - cm = 0; - tn = TQString::null; - return; - } - } -} - - -/*! - Constructs a copy of translator message \a m. -*/ - -TQTranslatorMessage::TQTranslatorMessage( const TQTranslatorMessage & m ) - : cx( m.cx ), st( m.st ), cm( m.cm ), tn( m.tn ) -{ - h = m.h; -} - - -/*! - Assigns message \a m to this translator message and returns a - reference to this translator message. -*/ - -TQTranslatorMessage & TQTranslatorMessage::operator=( - const TQTranslatorMessage & m ) -{ - h = m.h; - cx = m.cx; - st = m.st; - cm = m.cm; - tn = m.tn; - return *this; -} - - -/*! - \fn uint TQTranslatorMessage::hash() const - - Returns the hash value used internally to represent the lookup - key. This value is zero only if this translator message was - constructed from a stream containing invalid data. - - The hashing function is unspecified, but it will remain unchanged - in future versions of TQt. -*/ - -/*! - \fn const char *TQTranslatorMessage::context() const - - Returns the context for this message (e.g. "MyDialog"). - - \warning This may return 0 if the TQTranslator object is stripped - (compressed). -*/ - -/*! - \fn const char *TQTranslatorMessage::sourceText() const - - Returns the source text of this message (e.g. "&Save"). - - \warning This may return 0 if the TQTranslator object is stripped - (compressed). -*/ - -/*! - \fn const char *TQTranslatorMessage::comment() const - - Returns the comment for this message (e.g. "File|Save"). - - \warning This may return 0 if the TQTranslator object is stripped - (compressed). -*/ - -/*! - \fn void TQTranslatorMessage::setTranslation( const TQString & translation ) - - Sets the translation of the source text to \a translation. - - \sa translation() -*/ - -/*! - \fn TQString TQTranslatorMessage::translation() const - - Returns the translation of the source text (e.g., "&Sauvegarder"). - - \sa setTranslation() -*/ - -/*! - \enum TQTranslatorMessage::Prefix - - Let (\e h, \e c, \e s, \e m) be the extended key. The possible - prefixes are - - \value NoPrefix no prefix - \value Hash only (\e h) - \value HashContext only (\e h, \e c) - \value HashContextSourceText only (\e h, \e c, \e s) - \value HashContextSourceTextComment the whole extended key, (\e - h, \e c, \e s, \e m) - - \sa write() commonPrefix() -*/ - -/*! - Writes this translator message to the \a stream. If \a strip is - FALSE (the default), all the information in the message is - written. If \a strip is TRUE, only the part of the extended key - specified by \a prefix is written with the translation (\c - HashContextSourceTextComment by default). - - \sa commonPrefix() -*/ - -void TQTranslatorMessage::write( TQDataStream & stream, bool strip, - Prefix prefix ) const -{ - char tag; - - tag = (char)Tag_Translation; - stream.writeRawBytes( &tag, 1 ); - stream << tn; - - bool mustWriteHash = TRUE; - if ( !strip ) - prefix = HashContextSourceTextComment; - - switch ( prefix ) { - case HashContextSourceTextComment: - tag = (char)Tag_Comment; - stream.writeRawBytes( &tag, 1 ); - stream << cm; - // fall through - case HashContextSourceText: - tag = (char)Tag_SourceText; - stream.writeRawBytes( &tag, 1 ); - stream << st; - // fall through - case HashContext: - tag = (char)Tag_Context; - stream.writeRawBytes( &tag, 1 ); - stream << cx; - // fall through - default: - if ( mustWriteHash ) { - tag = (char)Tag_Hash; - stream.writeRawBytes( &tag, 1 ); - stream << h; - } - } - - tag = (char)Tag_End; - stream.writeRawBytes( &tag, 1 ); -} - - -/*! - Returns the widest lookup prefix that is common to this translator - message and to message \a m. - - For example, if the extended key is for this message is (71, - "PrintDialog", "Yes", "Print?") and that for \a m is (71, - "PrintDialog", "No", "Print?"), this function returns \c - HashContext. - - \sa write() -*/ - -TQTranslatorMessage::Prefix TQTranslatorMessage::commonPrefix( - const TQTranslatorMessage& m ) const -{ - if ( h != m.h ) - return NoPrefix; - if ( cx != m.cx ) - return Hash; - if ( st != m.st ) - return HashContext; - if ( cm != m.cm ) - return HashContextSourceText; - return HashContextSourceTextComment; -} - - -/*! - Returns TRUE if the extended key of this object is equal to that of - \a m; otherwise returns FALSE. -*/ - -bool TQTranslatorMessage::operator==( const TQTranslatorMessage& m ) const -{ - return h == m.h && cx == m.cx && st == m.st && cm == m.cm; -} - - -/*! - \fn bool TQTranslatorMessage::operator!=( const TQTranslatorMessage& m ) const - - Returns TRUE if the extended key of this object is different from - that of \a m; otherwise returns FALSE. -*/ - - -/*! - Returns TRUE if the extended key of this object is - lexicographically before than that of \a m; otherwise returns - FALSE. -*/ - -bool TQTranslatorMessage::operator<( const TQTranslatorMessage& m ) const -{ - return h != m.h ? h < m.h - : ( cx != m.cx ? cx < m.cx - : (st != m.st ? st < m.st : cm < m.cm) ); -} - - -/*! - \fn bool TQTranslatorMessage::operator<=( const TQTranslatorMessage& m ) const - - Returns TRUE if the extended key of this object is - lexicographically before that of \a m or if they are equal; - otherwise returns FALSE. -*/ - -/*! - \fn bool TQTranslatorMessage::operator>( const TQTranslatorMessage& m ) const - - Returns TRUE if the extended key of this object is - lexicographically after that of \a m; otherwise returns FALSE. -*/ - -/*! - \fn bool TQTranslatorMessage::operator>=( const TQTranslatorMessage& m ) const - - Returns TRUE if the extended key of this object is - lexicographically after that of \a m or if they are equal; - otherwise returns FALSE. -*/ - -#endif // TQT_NO_TRANSLATION diff --git a/src/kernel/tqclipboard_x11.cpp b/src/kernel/tqclipboard_x11.cpp index 5c78b7ee5..e20708f54 100644 --- a/src/kernel/tqclipboard_x11.cpp +++ b/src/kernel/tqclipboard_x11.cpp @@ -65,7 +65,7 @@ #ifndef TQT_NO_CLIPBOARD #include "ntqapplication.h" -#include "ntqeventloop.h" +#include "tqeventloop.h" #include "tqbitmap.h" #include "tqdatetime.h" #include "tqdragobject.h" diff --git a/src/kernel/tqdesktopwidget.h b/src/kernel/tqdesktopwidget.h new file mode 100644 index 000000000..201267708 --- /dev/null +++ b/src/kernel/tqdesktopwidget.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Definition of TQDesktopWidget class. +** +** 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 TQDESKTOPWIDGET_H +#define TQDESKTOPWIDGET_H + +#ifndef QT_H +#include "tqwidget.h" +#endif // QT_H + +class TQApplication; +class TQDesktopWidgetPrivate; /* Don't touch! */ + +class TQ_EXPORT TQDesktopWidget : public TQWidget +{ + TQ_OBJECT +public: + TQDesktopWidget(); + ~TQDesktopWidget(); + + bool isVirtualDesktop() const; + + int numScreens() const; + int primaryScreen() const; + + int screenNumber( TQWidget *widget = 0 ) const; // ### 4.0: const TQWidget* + int screenNumber( const TQPoint & ) const; + + TQWidget *screen( int screen = -1 ); + + const TQRect& screenGeometry( int screen = -1 ) const; + const TQRect& screenGeometry( TQWidget *widget ) const + { return screenGeometry( screenNumber( widget ) ); } + const TQRect& screenGeometry( const TQPoint &point ) const + { return screenGeometry( screenNumber( point ) ); } + + const TQRect& availableGeometry( int screen = -1 ) const; + const TQRect& availableGeometry( TQWidget *widget ) const + { return availableGeometry( screenNumber( widget ) ); } + const TQRect& availableGeometry( const TQPoint &point ) const + { return availableGeometry( screenNumber( point ) ); } + + void insertChild( TQObject * ); + + inline void emitResizedSignal(int value) { emit resized(value); } + +signals: + void resized( int ); + void workAreaResized( int ); + +protected: + void resizeEvent( TQResizeEvent *e ); + +private: + TQDesktopWidgetPrivate *d; + +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQDesktopWidget( const TQDesktopWidget & ); + TQDesktopWidget &operator=( const TQDesktopWidget & ); +#endif + + friend class TQApplication; +}; + +#endif //TQDESKTOPWIDGET_H diff --git a/src/kernel/tqdesktopwidget_x11.cpp b/src/kernel/tqdesktopwidget_x11.cpp new file mode 100644 index 000000000..5adc611bc --- /dev/null +++ b/src/kernel/tqdesktopwidget_x11.cpp @@ -0,0 +1,356 @@ +/**************************************************************************** +** +** Implementation of TQDesktopWidget class. +** +** 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 "tqdesktopwidget.h" +#include "ntqapplication.h" +#include "tqobjectlist.h" +#include "qt_x11_p.h" +#include + +// defined in tqwidget_x11.cpp +extern int qt_x11_create_desktop_on_screen; + +// defined in qapplication_x11.cpp +extern Atom qt_net_workarea; +extern bool qt_net_supports(Atom atom); + +// function to update the workarea of the screen +static bool qt_desktopwidget_workarea_dirty = TRUE; +void qt_desktopwidget_update_workarea() +{ + qt_desktopwidget_workarea_dirty = TRUE; +} + + +class TQSingleDesktopWidget : public TQWidget +{ +public: + TQSingleDesktopWidget(); + ~TQSingleDesktopWidget(); +}; + +TQSingleDesktopWidget::TQSingleDesktopWidget() + : TQWidget( 0, "desktop", WType_Desktop ) +{ +} + +TQSingleDesktopWidget::~TQSingleDesktopWidget() +{ + while ( children() ) + removeChild( children()->getFirst() ); +} + + +class TQDesktopWidgetPrivate +{ +public: + TQDesktopWidgetPrivate(); + ~TQDesktopWidgetPrivate(); + + void init(); + + bool use_xinerama; + int defaultScreen; + int screenCount; + + TQWidget **screens; + TQRect *rects; + TQRect *workareas; +}; + +TQDesktopWidgetPrivate::TQDesktopWidgetPrivate() + : use_xinerama(FALSE), defaultScreen(0), screenCount(1), + screens( 0 ), rects( 0 ), workareas( 0 ) +{ +} + +TQDesktopWidgetPrivate::~TQDesktopWidgetPrivate() +{ + if ( screens ) { + for ( int i = 0; i < screenCount; ++i ) { + if (i == defaultScreen) continue; + delete screens[i]; + screens[i] = 0; + } + + free(screens); + } + + if ( rects ) delete [] rects; + if ( workareas ) delete [] workareas; +} + +void TQDesktopWidgetPrivate::init() +{ + // get the screen count + int newScreenCount; + +#ifndef TQT_NO_XINERAMA + XineramaScreenInfo *xinerama_screeninfo = 0; + int unused; + use_xinerama = (XineramaQueryExtension(TQPaintDevice::x11AppDisplay(), + &unused, &unused) && + XineramaIsActive(TQPaintDevice::x11AppDisplay())); + + if (use_xinerama) { + xinerama_screeninfo = + XineramaQueryScreens(TQPaintDevice::x11AppDisplay(), &newScreenCount); + + if (xinerama_screeninfo) + defaultScreen = 0; + } else +#endif // TQT_NO_XINERAMA + { + defaultScreen = DefaultScreen(TQPaintDevice::x11AppDisplay()); + newScreenCount = ScreenCount(TQPaintDevice::x11AppDisplay()); + use_xinerama = false; + } + + delete [] rects; + rects = new TQRect[ newScreenCount ]; + delete [] workareas; + workareas = new TQRect[ newScreenCount ]; + + // get the geometry of each screen + int i, j, x, y, w, h; + for ( i = 0, j = 0; i < newScreenCount; i++ ) { + +#ifndef TQT_NO_XINERAMA + if (use_xinerama) { + x = xinerama_screeninfo[i].x_org; + y = xinerama_screeninfo[i].y_org; + w = xinerama_screeninfo[i].width; + h = xinerama_screeninfo[i].height; + } else +#endif // TQT_NO_XINERAMA + { + x = 0; + y = 0; + w = WidthOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), i)); + h = HeightOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), i)); + } + + workareas[i] = TQRect(); + rects[j].setRect(x, y, w, h); + + // overlapping? + if (j > 0 && rects[j-1].intersects(rects[j])) { + // pick the bigger one, ignore the other + if ((rects[j].width()*rects[j].height()) > + (rects[j-1].width()*rects[j-1].height())) + rects[j-1] = rects[j]; + } + else + j++; + } + + if (screens) { + // leaks TQWidget* pointers on purpose, can't delete them as pointer escapes + screens = (TQWidget**) realloc(screens, j * sizeof(TQWidget*)); + if (j > screenCount) + memset(&screens[screenCount], 0, (j-screenCount) * sizeof(TQWidget*)); + } + + screenCount = j; + +#ifndef TQT_NO_XINERAMA + if (use_xinerama && screenCount == 1) + use_xinerama = false; + + if (xinerama_screeninfo) + XFree(xinerama_screeninfo); +#endif // TQT_NO_XINERAMA + +} + +// the TQDesktopWidget itself will be created on the default screen +// as qt_x11_create_desktop_on_screen defaults to -1 +TQDesktopWidget::TQDesktopWidget() + : TQWidget( 0, "desktop", WType_Desktop ) +{ + d = new TQDesktopWidgetPrivate(); + + /* + we don't call d->init() here, since the initial resize event + will end up calling init() a second time, which is inefficient. + instead, for the sending of all posted event to the desktop + widget (including the initial resize event, which calls + d->init()). + */ + TQApplication::sendPostedEvents( this, 0 ); +} + +TQDesktopWidget::~TQDesktopWidget() +{ + delete d; +} + +bool TQDesktopWidget::isVirtualDesktop() const +{ + return d->use_xinerama; +} + +int TQDesktopWidget::primaryScreen() const +{ + return d->defaultScreen; +} + +int TQDesktopWidget::numScreens() const +{ + return d->screenCount; +} + +TQWidget *TQDesktopWidget::screen( int screen ) +{ + if (d->use_xinerama) + return this; + + if ( screen < 0 || screen >= d->screenCount ) + screen = d->defaultScreen; + + if ( ! d->screens ) { + d->screens = (TQWidget**) calloc( d->screenCount, sizeof(TQWidget*)); + d->screens[ d->defaultScreen ] = this; + } + + if ( ! d->screens[screen] || // not created yet + ! d->screens[screen]->isDesktop() ) { // reparented away + qt_x11_create_desktop_on_screen = screen; + d->screens[screen] = new TQSingleDesktopWidget; + qt_x11_create_desktop_on_screen = -1; + } + + return d->screens[screen]; +} + +const TQRect& TQDesktopWidget::availableGeometry( int screen ) const +{ + if ( qt_desktopwidget_workarea_dirty ) { + // the workareas are dirty, invalidate them + for ( int i = 0; i < d->screenCount; ++i ) + d->workareas[i] = TQRect(); + qt_desktopwidget_workarea_dirty = FALSE; + } + + if ( screen < 0 || screen >= d->screenCount ) + screen = d->defaultScreen; + + if ( d->workareas[screen].isValid() ) + return d->workareas[screen]; + + if ( ! isVirtualDesktop() && qt_net_supports( qt_net_workarea ) ) { + Atom ret; + int format, e; + unsigned char *data = 0; + unsigned long nitems, after; + + e = XGetWindowProperty( TQPaintDevice::x11AppDisplay(), + TQPaintDevice::x11AppRootWindow( screen ), + qt_net_workarea, 0, 4, False, XA_CARDINAL, + &ret, &format, &nitems, &after, &data ); + + if (e == Success && ret == XA_CARDINAL && + format == 32 && nitems == 4) { + long *workarea = (long *) data; + d->workareas[screen].setRect( workarea[0], workarea[1], + workarea[2], workarea[3] ); + } else { + d->workareas[screen] = screenGeometry(screen); + } + if ( data ) + XFree( data ); + } else { + d->workareas[screen] = screenGeometry(screen); + } + + return d->workareas[screen]; +} + +const TQRect& TQDesktopWidget::screenGeometry( int screen ) const +{ + if ( screen < 0 || screen >= d->screenCount ) + screen = d->defaultScreen; + + return d->rects[ screen ]; +} + +int TQDesktopWidget::screenNumber( TQWidget *widget ) const +{ + if ( !widget ) + return d->defaultScreen; + +#ifndef TQT_NO_XINERAMA + if (d->use_xinerama) { + // this is how we do it for xinerama + TQRect frame = widget->frameGeometry(); + if ( !widget->isTopLevel() ) + frame.moveTopLeft( widget->mapToGlobal( TQPoint( 0, 0 ) ) ); + + int maxSize = -1; + int maxScreen = -1; + + for ( int i = 0; i < d->screenCount; ++i ) { + TQRect sect = d->rects[i].intersect( frame ); + int size = sect.width() * sect.height(); + if ( size > maxSize && sect.width() > 0 && sect.height() > 0 ) { + maxSize = size; + maxScreen = i; + } + } + return maxScreen; + } +#endif // TQT_NO_XINERAMA + + return widget->x11Screen(); +} + +int TQDesktopWidget::screenNumber( const TQPoint &point ) const +{ + for ( int i = 0; i < d->screenCount; ++i ) { + if ( d->rects[i].contains( point ) ) + return i; + } + return -1; +} + +void TQDesktopWidget::resizeEvent( TQResizeEvent *event ) +{ + d->init(); + qt_desktopwidget_workarea_dirty = TRUE; + TQWidget::resizeEvent( event ); +} diff --git a/src/kernel/tqevent.cpp b/src/kernel/tqevent.cpp new file mode 100644 index 000000000..5f4894e92 --- /dev/null +++ b/src/kernel/tqevent.cpp @@ -0,0 +1,2579 @@ +/**************************************************************************** +** +** Implementation of event classes +** +** 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. +** +**********************************************************************/ + +#include "tqevent.h" +#include "ntqcursor.h" +#include "ntqapplication.h" + + +/*! + \class TQEvent tqevent.h + \brief The TQEvent class is the base class of all + event classes. Event objects contain event parameters. + + \ingroup events + \ingroup environment + + TQt's main event loop (TQApplication::exec()) fetches native window + system events from the event queue, translates them into TQEvents + and sends the translated events to TQObjects. + + In general, events come from the underlying window system + (spontaneous() returns TRUE) but it is also possible to manually + send events using TQApplication::sendEvent() and + TQApplication::postEvent() (spontaneous() returns FALSE). + + TQObjects receive events by having their TQObject::event() function + called. The function can be reimplemented in subclasses to + customize event handling and add additional event types; + TQWidget::event() is a notable example. By default, events are + dispatched to event handlers like TQObject::timerEvent() and + TQWidget::mouseMoveEvent(). TQObject::installEventFilter() allows an + object to intercept events destined for another object. + + The basic TQEvent contains only an event type parameter. + Subclasses of TQEvent contain additional parameters that describe + the particular event. + + \sa TQObject::event() TQObject::installEventFilter() + TQWidget::event() TQApplication::sendEvent() + TQApplication::postEvent() TQApplication::processEvents() +*/ + + +/*! + \enum TQt::ButtonState + + This enum type describes the state of the mouse and the modifier + buttons. + + \value NoButton used when the button state does not refer to any + button (see TQMouseEvent::button()). + \value LeftButton set if the left button is pressed, or if this + event refers to the left button. (The left button may be + the right button on left-handed mice.) + \value RightButton the right button. + \value MidButton the middle button. + \value HistoryBackButton history navigation back button. + \value HistoryForwardButton history navigation forward button. + \value ShiftButton a Shift key on the keyboard is also pressed. + \value ControlButton a Ctrl key on the keyboard is also pressed. + \value AltButton an Alt key on the keyboard is also pressed. + \value MetaButton a Meta key on the keyboard is also pressed. + \value Keypad a keypad button is pressed. + \value KeyButtonMask a mask for ShiftButton, ControlButton, + AltButton and MetaButton. + \value MouseButtonMask a mask for LeftButton, RightButton, MidButton, + HistoryBackButton and HistoryForwardButton. +*/ + +/*! + \enum TQEvent::Type + + This enum type defines the valid event types in TQt. The event + types and the specialized classes for each type are these: + + \value None Not an event. + \value Accessibility Accessibility information is requested + \value Timer Regular timer events, \l{TQTimerEvent}. + \value MouseButtonPress Mouse press, \l{TQMouseEvent}. + \value MouseButtonRelease Mouse release, \l{TQMouseEvent}. + \value MouseButtonDblClick Mouse press again, \l{TQMouseEvent}. + \value MouseMove Mouse move, \l{TQMouseEvent}. + \value KeyPress Key press (including Shift, for example), \l{TQKeyEvent}. + \value KeyRelease Key release, \l{TQKeyEvent}. + \value IMStart The start of input method composition, \l{TQIMEvent}. + \value IMCompose Input method composition is taking place, \l{TQIMEvent}. + \value IMEnd The end of input method composition, \l{TQIMEvent}. + \value FocusIn Widget gains keyboard focus, \l{TQFocusEvent}. + \value FocusOut Widget loses keyboard focus, \l{TQFocusEvent}. + \value Enter Mouse enters widget's boundaries. + \value Leave Mouse leaves widget's boundaries. + \value Paint Screen update necessary, \l{TQPaintEvent}. + \value Move Widget's position changed, \l{TQMoveEvent}. + \value Resize Widget's size changed, \l{TQResizeEvent}. + \value Show Widget was shown on screen, \l{TQShowEvent}. + \value Hide Widget was hidden, \l{TQHideEvent}. + \value ShowToParent A child widget has been shown. + \value HideToParent A child widget has been hidden. + \value Close Widget was closed (permanently), \l{TQCloseEvent}. + \value ShowNormal Widget should be shown normally (obsolete). + \value ShowMaximized Widget should be shown maximized (obsolete). + \value ShowMinimized Widget should be shown minimized (obsolete). + \value ShowFullScreen Widget should be shown full-screen (obsolete). + \value ShowWindowRequest Widget's window should be shown (obsolete). + \value DeferredDelete The object will be deleted after it has + cleaned up. + \value Accel Key press in child for shortcut key handling, \l{TQKeyEvent}. + \value Wheel Mouse wheel rolled, \l{TQWheelEvent}. + \value ContextMenu Context popup menu, \l{TQContextMenuEvent} + \value AccelOverride Key press in child, for overriding shortcut key handling, \l{TQKeyEvent}. + \value AccelAvailable internal. + \value WindowActivate Window was activated. + \value WindowDeactivate Window was deactivated. + \value CaptionChange Widget's caption changed. + \value IconChange Widget's icon changed. + \value ParentFontChange Font of the parent widget changed. + \value ApplicationFontChange Default application font changed. + \value PaletteChange Palette of the widget changed. + \value ParentPaletteChange Palette of the parent widget changed. + \value ApplicationPaletteChange Default application palette changed. + \value Clipboard Clipboard contents have changed. + \value SockAct Socket activated, used to implement \l{TQSocketNotifier}. + \value DragEnter A drag-and-drop enters widget, \l{TQDragEnterEvent}. + \value DragMove A drag-and-drop is in progress, \l{TQDragMoveEvent}. + \value DragLeave A drag-and-drop leaves widget, \l{TQDragLeaveEvent}. + \value Drop A drag-and-drop is completed, \l{TQDropEvent}. + \value DragResponse Internal event used by TQt on some platforms. + \value ChildInserted Object gets a child, \l{TQChildEvent}. + \value ChildRemoved Object loses a child, \l{TQChildEvent}. + \value LayoutHint Widget child has changed layout properties. + \value ActivateControl Internal event used by TQt on some platforms. + \value DeactivateControl Internal event used by TQt on some platforms. + \value LanguageChange The application translation changed, \l{TQTranslator} + \value LayoutDirectionChange The direction of layouts changed + \value LocaleChange The system locale changed + \value Quit Reserved. + \value Create Reserved. + \value Destroy Reserved. + \value Reparent Reserved. + \value Speech Reserved for speech input. + \value TabletMove A Wacom Tablet Move Event. + \value Style Internal use only + \value TabletPress A Wacom Tablet Press Event + \value TabletRelease A Wacom Tablet Release Event + \value OkRequest Internal event used by TQt on some platforms. + \value HelpRequest Internal event used by TQt on some platforms. + \value IconDrag Internal event used by TQt on some platforms when proxy icon is dragged. + \value WindowStateChange The window's state, i.e. minimized, + maximized or full-screen, has changed. See \l{TQWidget::windowState()}. + \value WindowBlocked The window is modally blocked + \value WindowUnblocked The window leaves modal blocking + + \value User User defined event. + \value MaxUser Last user event id. + + User events should have values between User and MaxUser inclusive. +*/ +/*! + \fn TQEvent::TQEvent( Type type ) + + Contructs an event object of type \a type. +*/ + +/*! + \fn TQEvent::Type TQEvent::type() const + + Returns the event type. +*/ + +/*! + \fn bool TQEvent::spontaneous() const + + Returns TRUE if the event originated outside the application, i.e. + it is a system event; otherwise returns FALSE. +*/ + + +/*! + \class TQTimerEvent tqevent.h + \brief The TQTimerEvent class contains parameters that describe a + timer event. + + \ingroup events + + Timer events are sent at regular intervals to objects that have + started one or more timers. Each timer has a unique identifier. A + timer is started with TQObject::startTimer(). + + The TQTimer class provides a high-level programming interface that + uses signals instead of events. It also provides one-shot timers. + + The event handler TQObject::timerEvent() receives timer events. + + \sa TQTimer, TQObject::timerEvent(), TQObject::startTimer(), + TQObject::killTimer(), TQObject::killTimers() +*/ + +/*! + \fn TQTimerEvent::TQTimerEvent( int timerId ) + + Constructs a timer event object with the timer identifier set to + \a timerId. +*/ + +/*! + \fn int TQTimerEvent::timerId() const + + Returns the unique timer identifier, which is the same identifier + as returned from TQObject::startTimer(). +*/ + + +/*! + \class TQMouseEvent tqevent.h + \ingroup events + + \brief The TQMouseEvent class contains parameters that describe a mouse event. + + Mouse events occur when a mouse button is pressed or released + inside a widget or when the mouse cursor is moved. + + Mouse move events will occur only when a mouse button is pressed + down, unless mouse tracking has been enabled with + TQWidget::setMouseTracking(). + + TQt automatically grabs the mouse when a mouse button is pressed + inside a widget; the widget will continue to receive mouse events + until the last mouse button is released. + + A mouse event contains a special accept flag that indicates + whether the receiver wants the event. You should call + TQMouseEvent::ignore() if the mouse event is not handled by your + widget. A mouse event is propagated up the parent widget chain + until a widget accepts it with TQMouseEvent::accept() or an event + filter consumes it. + + The functions pos(), x() and y() give the cursor position relative + to the widget that receives the mouse event. If you move the + widget as a result of the mouse event, use the global position + returned by globalPos() to avoid a shaking motion. + + The TQWidget::setEnabled() function can be used to enable or + disable mouse and keyboard events for a widget. + + The event handlers TQWidget::mousePressEvent(), + TQWidget::mouseReleaseEvent(), TQWidget::mouseDoubleClickEvent() and + TQWidget::mouseMoveEvent() receive mouse events. + + \sa TQWidget::setMouseTracking(), TQWidget::grabMouse(), + TQCursor::pos() +*/ + +/*! + \fn TQMouseEvent::TQMouseEvent( Type type, const TQPoint &pos, int button, int state ) + + Constructs a mouse event object. + + The \a type parameter must be one of \c TQEvent::MouseButtonPress, + \c TQEvent::MouseButtonRelease, \c TQEvent::MouseButtonDblClick or + \c TQEvent::MouseMove. + + The \a pos parameter specifies the position relative to the + receiving widget. \a button specifies the \link TQt::ButtonState + button\endlink that caused the event, which should be \c + TQt::NoButton (0), if \a type is \c MouseMove. \a state is the + \link TQt::ButtonState ButtonState\endlink at the time of the + event. + + The globalPos() is initialized to TQCursor::pos(), which may not be + appropriate. Use the other constructor to specify the global + position explicitly. +*/ + +TQMouseEvent::TQMouseEvent( Type type, const TQPoint &pos, int button, int state ) + : TQEvent(type), p(pos), b(button),s((ushort)state), accpt(TRUE){ + g = TQCursor::pos(); +} + + +/*! + \fn TQMouseEvent::TQMouseEvent( Type type, const TQPoint &pos, const TQPoint &globalPos, int button, int state ) + + Constructs a mouse event object. + + The \a type parameter must be \c TQEvent::MouseButtonPress, \c + TQEvent::MouseButtonRelease, \c TQEvent::MouseButtonDblClick or \c + TQEvent::MouseMove. + + The \a pos parameter specifies the position relative to the + receiving widget. \a globalPos is the position in absolute + coordinates. \a button specifies the \link TQt::ButtonState + button\endlink that caused the event, which should be \c + TQt::NoButton (0), if \a type is \c MouseMove. \a state is the + \link TQt::ButtonState ButtonState\endlink at the time of the + event. + +*/ + +/*! + \fn const TQPoint &TQMouseEvent::pos() const + + Returns the position of the mouse pointer relative to the widget + that received the event. + + If you move the widget as a result of the mouse event, use the + global position returned by globalPos() to avoid a shaking motion. + + \sa x(), y(), globalPos() +*/ + +/*! + \fn const TQPoint &TQMouseEvent::globalPos() const + + Returns the global position of the mouse pointer \e{at the time + of the event}. This is important on asynchronous window systems + like X11. Whenever you move your widgets around in response to + mouse events, globalPos() may differ a lot from the current + pointer position TQCursor::pos(), and from TQWidget::mapToGlobal( + pos() ). + + \sa globalX(), globalY() +*/ + +/*! + \fn int TQMouseEvent::x() const + + Returns the x-position of the mouse pointer, relative to the + widget that received the event. + + \sa y(), pos() +*/ + +/*! + \fn int TQMouseEvent::y() const + + Returns the y-position of the mouse pointer, relative to the + widget that received the event. + + \sa x(), pos() +*/ + +/*! + \fn int TQMouseEvent::globalX() const + + Returns the global x-position of the mouse pointer at the time of + the event. + + \sa globalY(), globalPos() +*/ + +/*! + \fn int TQMouseEvent::globalY() const + + Returns the global y-position of the mouse pointer at the time of + the event. + + \sa globalX(), globalPos() +*/ + +/*! + \fn ButtonState TQMouseEvent::button() const + + Returns the button that caused the event. + + Possible return values are \c LeftButton, \c RightButton, \c + MidButton and \c NoButton. + + Note that the returned value is always \c NoButton for mouse move + events. + + \sa state() TQt::ButtonState +*/ + + +/*! + \fn ButtonState TQMouseEvent::state() const + + Returns the button state (a combination of mouse buttons and + keyboard modifiers), i.e. what buttons and keys were being pressed + immediately before the event was generated. + + This means that if you have a \c TQEvent::MouseButtonPress or a \c + TQEvent::MouseButtonDblClick state() will \e not include the mouse + button that's pressed. But once the mouse button has been + released, the \c TQEvent::MouseButtonRelease event will have the + button() that was pressed. + + This value is mainly interesting for \c TQEvent::MouseMove; for the + other cases, button() is more useful. + + The returned value is \c LeftButton, \c RightButton, \c MidButton, + \c ShiftButton, \c ControlButton and \c AltButton OR'ed together. + + \sa button() stateAfter() TQt::ButtonState +*/ + +/*! + \fn ButtonState TQMouseEvent::stateAfter() const + + Returns the state of buttons after the event. + + \sa state() TQt::ButtonState +*/ +TQt::ButtonState TQMouseEvent::stateAfter() const +{ + return TQt::ButtonState(state()^button()); +} + + + +/*! + \fn bool TQMouseEvent::isAccepted() const + + Returns TRUE if the receiver of the event wants to keep the key; + otherwise returns FALSE. +*/ + +/*! + \fn void TQMouseEvent::accept() + + Sets the accept flag of the mouse event object. + + Setting the accept parameter indicates that the receiver of the + event wants the mouse event. Unwanted mouse events are sent to the + parent widget. + + The accept flag is set by default. + + \sa ignore() +*/ + + +/*! + \fn void TQMouseEvent::ignore() + + Clears the accept flag parameter of the mouse event object. + + Clearing the accept parameter indicates that the event receiver + does not want the mouse event. Unwanted mouse events are sent to + the parent widget. + + The accept flag is set by default. + + \sa accept() +*/ + + +/*! + \class TQWheelEvent tqevent.h + \brief The TQWheelEvent class contains parameters that describe a wheel event. + + \ingroup events + + Wheel events are sent to the widget under the mouse, and if that widget + does not handle the event they are sent to the focus widget. The rotation + distance is provided by delta(). The functions pos() and globalPos() return + the mouse pointer location at the time of the event. + + A wheel event contains a special accept flag that indicates + whether the receiver wants the event. You should call + TQWheelEvent::accept() if you handle the wheel event; otherwise it + will be sent to the parent widget. + + The TQWidget::setEnable() function can be used to enable or disable + mouse and keyboard events for a widget. + + The event handler TQWidget::wheelEvent() receives wheel events. + + \sa TQMouseEvent, TQWidget::grabMouse() +*/ + +/*! + \fn Orientation TQWheelEvent::orientation() const + + Returns the wheel's orientation. +*/ + +/*! + \fn TQWheelEvent::TQWheelEvent( const TQPoint &pos, int delta, int state, Orientation orient = Vertical ); + + Constructs a wheel event object. + + The globalPos() is initialized to TQCursor::pos(), i.e. \a pos, + which is usually (but not always) right. Use the other constructor + if you need to specify the global position explicitly. \a delta + contains the rotation distance, \a state holds the keyboard + modifier flags at the time of the event and \a orient holds the + wheel's orientation. + + \sa pos(), delta(), state() +*/ +#ifndef TQT_NO_WHEELEVENT +TQWheelEvent::TQWheelEvent( const TQPoint &pos, int delta, int state, Orientation orient ) + : TQEvent(Wheel), p(pos), d(delta), s((ushort)state), + accpt(TRUE), o(orient) +{ + g = TQCursor::pos(); +} +#endif +/*! + \fn TQWheelEvent::TQWheelEvent( const TQPoint &pos, const TQPoint& globalPos, int delta, int state, Orientation orient = Vertical ) + + Constructs a wheel event object. The position when the event + occurred is given in \a pos and \a globalPos. \a delta contains + the rotation distance, \a state holds the keyboard modifier flags + at the time of the event and \a orient holds the wheel's + orientation. + + \sa pos(), globalPos(), delta(), state() +*/ + +/*! + \fn int TQWheelEvent::delta() const + + Returns the distance that the wheel is rotated expressed in + multiples or divisions of the \e{wheel delta}, which is currently + defined to be 120. A positive value indicates that the wheel was + rotated forwards away from the user; a negative value indicates + that the wheel was rotated backwards toward the user. + + The \e{wheel delta} constant was defined to be 120 by wheel mouse + vendors to allow building finer-resolution wheels in the future, + including perhaps a freely rotating wheel with no notches. The + expectation is that such a device would send more messages per + rotation but with a smaller value in each message. +*/ + +/*! + \fn const TQPoint &TQWheelEvent::pos() const + + Returns the position of the mouse pointer, relative to the widget + that received the event. + + If you move your widgets around in response to mouse + events, use globalPos() instead of this function. + + \sa x(), y(), globalPos() +*/ + +/*! + \fn int TQWheelEvent::x() const + + Returns the x-position of the mouse pointer, relative to the + widget that received the event. + + \sa y(), pos() +*/ + +/*! + \fn int TQWheelEvent::y() const + + Returns the y-position of the mouse pointer, relative to the + widget that received the event. + + \sa x(), pos() +*/ + + +/*! + \fn const TQPoint &TQWheelEvent::globalPos() const + + Returns the global position of the mouse pointer \e{at the time + of the event}. This is important on asynchronous window systems + such as X11; whenever you move your widgets around in response to + mouse events, globalPos() can differ a lot from the current + pointer position TQCursor::pos(). + + \sa globalX(), globalY() +*/ + +/*! + \fn int TQWheelEvent::globalX() const + + Returns the global x-position of the mouse pointer at the time of + the event. + + \sa globalY(), globalPos() +*/ + +/*! + \fn int TQWheelEvent::globalY() const + + Returns the global y-position of the mouse pointer at the time of + the event. + + \sa globalX(), globalPos() +*/ + + +/*! + \fn ButtonState TQWheelEvent::state() const + + Returns the keyboard modifier flags of the event. + + The returned value is \c ShiftButton, \c ControlButton, and \c + AltButton OR'ed together. +*/ + +/*! + \fn bool TQWheelEvent::isAccepted() const + + Returns TRUE if the receiver of the event handles the wheel event; + otherwise returns FALSE. +*/ + +/*! + \fn void TQWheelEvent::accept() + + Sets the accept flag of the wheel event object. + + Setting the accept parameter indicates that the receiver of the + event wants the wheel event. Unwanted wheel events are sent to the + parent widget. + + The accept flag is set by default. + + \sa ignore() +*/ + +/*! + \fn void TQWheelEvent::ignore() + + Clears the accept flag parameter of the wheel event object. + + Clearing the accept parameter indicates that the event receiver + does not want the wheel event. Unwanted wheel events are sent to + the parent widget. The accept flag is set by default. + + \sa accept() +*/ + + +/*! + \enum TQt::Modifier + + This enum type describes the keyboard modifier keys supported by + TQt. + + \value SHIFT the Shift keys provided on all standard keyboards. + \value META the Meta keys. + \value CTRL the Ctrl keys. + \value ALT the normal Alt keys, but not e.g. AltGr. + \value MODIFIER_MASK is a mask of Shift, Ctrl, Alt and Meta. + \value UNICODE_ACCEL the accelerator is specified as a Unicode code + point, not as a TQt Key. +*/ + +/*! + \class TQKeyEvent tqevent.h + \brief The TQKeyEvent class contains describes a key event. + + \ingroup events + + Key events occur when a key is pressed or released when a widget + has keyboard input focus. + + A key event contains a special accept flag that indicates whether the + receiver wants the key event. You should call TQKeyEvent::ignore() if the + key press or release event is not handled by your widget. A key event is + propagated up the parent widget chain until a widget accepts it with + TQKeyEvent::accept() or an event filter consumes it. + Key events for multi media keys are ignored by default. You should call + TQKeyEvent::accept() if your widget handles those events. + + The TQWidget::setEnable() function can be used to enable or disable + mouse and keyboard events for a widget. + + The event handlers TQWidget::keyPressEvent() and + TQWidget::keyReleaseEvent() receive key events. + + \sa TQFocusEvent, TQWidget::grabKeyboard() +*/ + +/*! + \fn TQKeyEvent::TQKeyEvent( Type type, int key, int ascii, int state, + const TQString& text, bool autorep, ushort count ) + + Constructs a key event object. + + The \a type parameter must be \c TQEvent::KeyPress or \c + TQEvent::KeyRelease. If \a key is 0 the event is not a result of a + known key (e.g. it may be the result of a compose sequence or + keyboard macro). \a ascii is the ASCII code of the key that was + pressed or released. \a state holds the keyboard modifiers. \a + text is the Unicode text that the key generated. If \a autorep is + TRUE, isAutoRepeat() will be TRUE. \a count is the number of + single keys. + + The accept flag is set to TRUE. +*/ + +/*! + \fn int TQKeyEvent::key() const + + Returns the code of the key that was pressed or released. + + See \l TQt::Key for the list of keyboard codes. These codes are + independent of the underlying window system. + + A value of either 0 or Key_unknown means that the event is not + the result of a known key (e.g. it may be the result of a compose + sequence or a keyboard macro, or due to key event compression). + + Applications should not use the TQt latin 1 keycodes between 128 + and 255, but should rather use the TQKeyEvent::text(). This is + mainly for compatibility. + + \sa TQWidget::setKeyCompression() +*/ + +/*! + \fn int TQKeyEvent::ascii() const + + Returns the ASCII code of the key that was pressed or released. We + recommend using text() instead. + + \sa text() +*/ + +/*! + \fn TQString TQKeyEvent::text() const + + Returns the Unicode text that this key generated. The text returned + migth be empty, which is the case when pressing or + releasing modifying keys as Shift, Control, Alt and Meta. In these + cases key() will contain a valid value. + + \sa TQWidget::setKeyCompression() +*/ + +/*! + \fn ButtonState TQKeyEvent::state() const + + Returns the keyboard modifier flags that existed immediately + before the event occurred. + + The returned value is \c ShiftButton, \c ControlButton, \c AltButton + and \c MetaButton OR'ed together. + + \sa stateAfter() +*/ + +/*! + \fn ButtonState TQKeyEvent::stateAfter() const + + Returns the keyboard modifier flags that existed immediately after + the event occurred. + + \warning This function cannot be trusted. + + \sa state() +*/ +//###### We must check with XGetModifierMapping +TQt::ButtonState TQKeyEvent::stateAfter() const +{ + if ( key() == Key_Shift ) + return TQt::ButtonState(state()^ShiftButton); + if ( key() == Key_Control ) + return TQt::ButtonState(state()^ControlButton); + if ( key() == Key_Alt ) + return TQt::ButtonState(state()^AltButton); + if ( key() == Key_Meta ) + return TQt::ButtonState(state()^MetaButton); + return state(); +} + +/*! + \fn bool TQKeyEvent::isAccepted() const + + Returns TRUE if the receiver of the event wants to keep the key; + otherwise returns FALSE +*/ + +/*! + \fn void TQKeyEvent::accept() + + Sets the accept flag of the key event object. + + Setting the accept parameter indicates that the receiver of the + event wants the key event. Unwanted key events are sent to the + parent widget. + + The accept flag is set by default. + + \sa ignore() +*/ + +/*! + \fn bool TQKeyEvent::isAutoRepeat() const + + Returns TRUE if this event comes from an auto-repeating key and + FALSE if it comes from an initial key press. + + Note that if the event is a multiple-key compressed event that is + partly due to auto-repeat, this function could return either TRUE + or FALSE indeterminately. +*/ + +/*! + \fn int TQKeyEvent::count() const + + Returns the number of single keys for this event. If text() is not + empty, this is simply the length of the string. + + \sa TQWidget::setKeyCompression() +*/ + +/*! + \fn void TQKeyEvent::ignore() + + Clears the accept flag parameter of the key event object. + + Clearing the accept parameter indicates that the event receiver + does not want the key event. Unwanted key events are sent to the + parent widget. + + The accept flag is set by default. + + \sa accept() +*/ + +/*! + \enum TQt::Key + + The key names used by TQt. + + \value Key_Escape + \value Key_Tab + \value Key_Backtab + \value Key_Backspace + \value Key_Return + \value Key_Enter + \value Key_Insert + \value Key_Delete + \value Key_Pause + \value Key_Print + \value Key_SysReq + \value Key_Home + \value Key_End + \value Key_Left + \value Key_Up + \value Key_Right + \value Key_Down + \value Key_Prior + \value Key_Next + \value Key_Shift + \value Key_Control + \value Key_Meta + \value Key_Alt + \value Key_CapsLock + \value Key_NumLock + \value Key_ScrollLock + \value Key_Clear + \value Key_F1 + \value Key_F2 + \value Key_F3 + \value Key_F4 + \value Key_F5 + \value Key_F6 + \value Key_F7 + \value Key_F8 + \value Key_F9 + \value Key_F10 + \value Key_F11 + \value Key_F12 + \value Key_F13 + \value Key_F14 + \value Key_F15 + \value Key_F16 + \value Key_F17 + \value Key_F18 + \value Key_F19 + \value Key_F20 + \value Key_F21 + \value Key_F22 + \value Key_F23 + \value Key_F24 + \value Key_F25 + \value Key_F26 + \value Key_F27 + \value Key_F28 + \value Key_F29 + \value Key_F30 + \value Key_F31 + \value Key_F32 + \value Key_F33 + \value Key_F34 + \value Key_F35 + \value Key_Super_L + \value Key_Super_R + \value Key_Menu + \value Key_Hyper_L + \value Key_Hyper_R + \value Key_Help + \value Key_Space + \value Key_Any + \value Key_Exclam + \value Key_QuoteDbl + \value Key_NumberSign + \value Key_Dollar + \value Key_Percent + \value Key_Ampersand + \value Key_Apostrophe + \value Key_ParenLeft + \value Key_ParenRight + \value Key_Asterisk + \value Key_Plus + \value Key_Comma + \value Key_Minus + \value Key_Period + \value Key_Slash + \value Key_0 + \value Key_1 + \value Key_2 + \value Key_3 + \value Key_4 + \value Key_5 + \value Key_6 + \value Key_7 + \value Key_8 + \value Key_9 + \value Key_Colon + \value Key_Semicolon + \value Key_Less + \value Key_Equal + \value Key_Greater + \value Key_Question + \value Key_At + \value Key_A + \value Key_B + \value Key_C + \value Key_D + \value Key_E + \value Key_F + \value Key_G + \value Key_H + \value Key_I + \value Key_J + \value Key_K + \value Key_L + \value Key_M + \value Key_N + \value Key_O + \value Key_P + \value Key_Q + \value Key_R + \value Key_S + \value Key_T + \value Key_U + \value Key_V + \value Key_W + \value Key_X + \value Key_Y + \value Key_Z + \value Key_BracketLeft + \value Key_Backslash + \value Key_BracketRight + \value Key_AsciiCircum + \value Key_Underscore + \value Key_QuoteLeft + \value Key_BraceLeft + \value Key_Bar + \value Key_BraceRight + \value Key_AsciiTilde + + \value Key_nobreakspace + \value Key_exclamdown + \value Key_cent + \value Key_sterling + \value Key_currency + \value Key_yen + \value Key_brokenbar + \value Key_section + \value Key_diaeresis + \value Key_copyright + \value Key_ordfeminine + \value Key_guillemotleft + \value Key_notsign + \value Key_hyphen + \value Key_registered + \value Key_macron + \value Key_degree + \value Key_plusminus + \value Key_twosuperior + \value Key_threesuperior + \value Key_acute + \value Key_mu + \value Key_paragraph + \value Key_periodcentered + \value Key_cedilla + \value Key_onesuperior + \value Key_masculine + \value Key_guillemotright + \value Key_onequarter + \value Key_onehalf + \value Key_threequarters + \value Key_questiondown + \value Key_Agrave + \value Key_Aacute + \value Key_Acircumflex + \value Key_Atilde + \value Key_Adiaeresis + \value Key_Aring + \value Key_AE + \value Key_Ccedilla + \value Key_Egrave + \value Key_Eacute + \value Key_Ecircumflex + \value Key_Ediaeresis + \value Key_Igrave + \value Key_Iacute + \value Key_Icircumflex + \value Key_Idiaeresis + \value Key_ETH + \value Key_Ntilde + \value Key_Ograve + \value Key_Oacute + \value Key_Ocircumflex + \value Key_Otilde + \value Key_Odiaeresis + \value Key_multiply + \value Key_Ooblique + \value Key_Ugrave + \value Key_Uacute + \value Key_Ucircumflex + \value Key_Udiaeresis + \value Key_Yacute + \value Key_THORN + \value Key_ssharp + \value Key_agrave + \value Key_aacute + \value Key_acircumflex + \value Key_atilde + \value Key_adiaeresis + \value Key_aring + \value Key_ae + \value Key_ccedilla + \value Key_egrave + \value Key_eacute + \value Key_ecircumflex + \value Key_ediaeresis + \value Key_igrave + \value Key_iacute + \value Key_icircumflex + \value Key_idiaeresis + \value Key_eth + \value Key_ntilde + \value Key_ograve + \value Key_oacute + \value Key_ocircumflex + \value Key_otilde + \value Key_odiaeresis + \value Key_division + \value Key_oslash + \value Key_ugrave + \value Key_uacute + \value Key_ucircumflex + \value Key_udiaeresis + \value Key_yacute + \value Key_thorn + \value Key_ydiaeresis + + Multimedia keys + + \value Key_Back + \value Key_Forward + \value Key_Stop + \value Key_Refresh + + \value Key_VolumeDown + \value Key_VolumeMute + \value Key_VolumeUp + \value Key_BassBoost + \value Key_BassUp + \value Key_BassDown + \value Key_TrebleUp + \value Key_TrebleDown + + \value Key_MediaPlay + \value Key_MediaStop + \value Key_MediaPrev + \value Key_MediaNext + \value Key_MediaRecord + + \value Key_HomePage + \value Key_Favorites + \value Key_Search + \value Key_Standby + \value Key_OpenUrl + + \value Key_LaunchMail + \value Key_LaunchMedia + \value Key_Launch0 + \value Key_Launch1 + \value Key_Launch2 + \value Key_Launch3 + \value Key_Launch4 + \value Key_Launch5 + \value Key_Launch6 + \value Key_Launch7 + \value Key_Launch8 + \value Key_Launch9 + \value Key_LaunchA + \value Key_LaunchB + \value Key_LaunchC + \value Key_LaunchD + \value Key_LaunchE + \value Key_LaunchF + \value Key_MonBrightnessUp + \value Key_MonBrightnessDown + \value Key_KeyboardLightOnOff + \value Key_KeyboardBrightnessUp + \value Key_KeyboardBrightnessDown + + \value Key_MediaLast + + \value Key_unknown + + \value Key_Direction_L internal use only + \value Key_Direction_R internal use only + +*/ + + +/*! + \class TQFocusEvent tqevent.h + \brief The TQFocusEvent class contains event parameters for widget focus + events. + + \ingroup events + + Focus events are sent to widgets when the keyboard input focus + changes. Focus events occur due to mouse actions, keypresses (e.g. + Tab or Backtab), the window system, popup menus, keyboard + shortcuts or other application specific reasons. The reason for a + particular focus event is returned by reason() in the appropriate + event handler. + + The event handlers TQWidget::focusInEvent() and + TQWidget::focusOutEvent() receive focus events. + + Use setReason() to set the reason for all focus events, and + resetReason() to set the reason for all focus events to the reason + in force before the last setReason() call. + + \sa TQWidget::setFocus(), TQWidget::setFocusPolicy() +*/ + +/*! + \fn TQFocusEvent::TQFocusEvent( Type type ) + + Constructs a focus event object. + + The \a type parameter must be either \c TQEvent::FocusIn or \c + TQEvent::FocusOut. +*/ + + + +TQFocusEvent::Reason TQFocusEvent::m_reason = TQFocusEvent::Other; +TQFocusEvent::Reason TQFocusEvent::prev_reason = TQFocusEvent::Other; + + +/*! + \enum TQFocusEvent::Reason + + This enum specifies why the focus changed. + + \value Mouse because of a mouse action. + \value Tab because of a Tab press. + \value Backtab because of a Backtab press + (possibly including Shift/Control, e.g. Shift+Tab). + \value ActiveWindow because the window system made this window (in)active. + \value Popup because the application opened/closed a popup that grabbed/released focus. + \value Shortcut because of a keyboard shortcut. + \value Other any other reason, usually application-specific. + + See the \link focus.html keyboard focus overview\endlink for more + about focus. +*/ + +/*! + Returns the reason for this focus event. + + \sa setReason() + */ +TQFocusEvent::Reason TQFocusEvent::reason() +{ + return m_reason; +} + +/*! + Sets the reason for all future focus events to \a reason. + + \sa reason(), resetReason() + */ +void TQFocusEvent::setReason( Reason reason ) +{ + prev_reason = m_reason; + m_reason = reason; +} + +/*! + Resets the reason for all future focus events to the value before + the last setReason() call. + + \sa reason(), setReason() + */ +void TQFocusEvent::resetReason() +{ + m_reason = prev_reason; +} + +/*! + \fn bool TQFocusEvent::gotFocus() const + + Returns TRUE if the widget received the text input focus; + otherwise returns FALSE. +*/ + +/*! + \fn bool TQFocusEvent::lostFocus() const + + Returns TRUE if the widget lost the text input focus; otherwise + returns FALSE. +*/ + + +/*! + \class TQPaintEvent tqevent.h + \brief The TQPaintEvent class contains event parameters for paint events. + + \ingroup events + + Paint events are sent to widgets that need to update themselves, + for instance when part of a widget is exposed because a covering + widget is moved. + + The event contains a region() that needs to be updated, and a + rect() that is the bounding rectangle of that region. Both are + provided because many widgets can't make much use of region(), and + rect() can be much faster than region().boundingRect(). Painting + is clipped to region() during processing of a paint event. + + The erased() function returns TRUE if the region() has been + cleared to the widget's background (see + TQWidget::backgroundMode()), and FALSE if the region's contents are + arbitrary. + + \sa TQPainter TQWidget::update() TQWidget::repaint() + TQWidget::paintEvent() TQWidget::backgroundMode() TQRegion +*/ + +/*! + \fn TQPaintEvent::TQPaintEvent( const TQRegion &paintRegion, bool erased=TRUE ) + + Constructs a paint event object with the region that should be + updated. The region is given by \a paintRegion. If \a erased is + TRUE the region will be cleared before repainting. +*/ + +/*! + \fn TQPaintEvent::TQPaintEvent( const TQRect &paintRect, bool erased=TRUE ) + + Constructs a paint event object with the rectangle that should be + updated. The region is also given by \a paintRect. If \a erased is + TRUE the region will be cleared before repainting. +*/ + +/*! + \fn TQPaintEvent::TQPaintEvent( const TQRegion &paintRegion, const TQRect &paintRect, bool erased=TRUE ) + + Constructs a paint event object with the rectangle \a paintRect + that should be updated. The region is given by \a paintRegion. If + \a erased is TRUE the region will be cleared before repainting. +*/ + +/*! + \fn const TQRect &TQPaintEvent::rect() const + + Returns the rectangle that should be updated. + + \sa region(), TQPainter::setClipRect() +*/ + +/*! + \fn const TQRegion &TQPaintEvent::region() const + + Returns the region that should be updated. + + \sa rect(), TQPainter::setClipRegion() +*/ + +/*! + \fn bool TQPaintEvent::erased() const + + Returns TRUE if the paint event region (or rectangle) has been + erased with the widget's background; otherwise returns FALSE. +*/ + +/*! + \class TQMoveEvent tqevent.h + \brief The TQMoveEvent class contains event parameters for move events. + + \ingroup events + + Move events are sent to widgets that have been moved to a new position + relative to their parent. + + The event handler TQWidget::moveEvent() receives move events. + + \sa TQWidget::move(), TQWidget::setGeometry() +*/ + +/*! + \fn TQMoveEvent::TQMoveEvent( const TQPoint &pos, const TQPoint &oldPos ) + + Constructs a move event with the new and old widget positions, \a + pos and \a oldPos respectively. +*/ + +/*! + \fn const TQPoint &TQMoveEvent::pos() const + + Returns the new position of the widget. This excludes the window + frame for top level widgets. +*/ + +/*! + \fn const TQPoint &TQMoveEvent::oldPos() const + + Returns the old position of the widget. +*/ + + +/*! + \class TQResizeEvent tqevent.h + \brief The TQResizeEvent class contains event parameters for resize events. + + \ingroup events + + Resize events are sent to widgets that have been resized. + + The event handler TQWidget::resizeEvent() receives resize events. + + \sa TQWidget::resize(), TQWidget::setGeometry() +*/ + +/*! + \fn TQResizeEvent::TQResizeEvent( const TQSize &size, const TQSize &oldSize ) + + Constructs a resize event with the new and old widget sizes, \a + size and \a oldSize respectively. +*/ + +/*! + \fn const TQSize &TQResizeEvent::size() const + + Returns the new size of the widget, which is the same as + TQWidget::size(). +*/ + +/*! + \fn const TQSize &TQResizeEvent::oldSize() const + + Returns the old size of the widget. +*/ + + +/*! + \class TQCloseEvent tqevent.h + \brief The TQCloseEvent class contains parameters that describe a close event. + + \ingroup events + + Close events are sent to widgets that the user wants to close, + usually by choosing "Close" from the window menu, or by clicking + the `X' titlebar button. They are also sent when you call + TQWidget::close() to close a widget programmatically. + + Close events contain a flag that indicates whether the receiver + wants the widget to be closed or not. When a widget accepts the + close event, it is hidden (and destroyed if it was created with + the \c WDestructiveClose flag). If it refuses to accept the close + event nothing happens. (Under X11 it is possible that the window + manager will forcibly close the window; but at the time of writing + we are not aware of any window manager that does this.) + + The application's main widget -- TQApplication::mainWidget() -- + is a special case. When it accepts the close event, TQt leaves the + main event loop and the application is immediately terminated + (i.e. it returns from the call to TQApplication::exec() in the + main() function). + + The event handler TQWidget::closeEvent() receives close events. The + default implementation of this event handler accepts the close + event. If you do not want your widget to be hidden, or want some + special handing, you should reimplement the event handler. + + The \link simple-application.html#closeEvent closeEvent() in the + Application Walkthrough\endlink shows a close event handler that + asks whether to save a document before closing. + + If you want the widget to be deleted when it is closed, create it + with the \c WDestructiveClose widget flag. This is very useful for + independent top-level windows in a multi-window application. + + \l{TQObject}s emits the \link TQObject::destroyed() + destroyed()\endlink signal when they are deleted. + + If the last top-level window is closed, the + TQApplication::lastWindowClosed() signal is emitted. + + The isAccepted() function returns TRUE if the event's receiver has + agreed to close the widget; call accept() to agree to close the + widget and call ignore() if the receiver of this event does not + want the widget to be closed. + + \sa TQWidget::close(), TQWidget::hide(), TQObject::destroyed(), + TQApplication::setMainWidget(), TQApplication::lastWindowClosed(), + TQApplication::exec(), TQApplication::quit() +*/ + +/*! + \fn TQCloseEvent::TQCloseEvent() + + Constructs a close event object with the accept parameter flag set + to FALSE. + + \sa accept() +*/ + +/*! + \fn bool TQCloseEvent::isAccepted() const + + Returns TRUE if the receiver of the event has agreed to close the + widget; otherwise returns FALSE. + + \sa accept(), ignore() +*/ + +/*! + \fn void TQCloseEvent::accept() + + Sets the accept flag of the close event object. + + Setting the accept flag indicates that the receiver of this event + agrees to close the widget. + + The accept flag is \e not set by default. + + If you choose to accept in TQWidget::closeEvent(), the widget will + be hidden. If the widget's \c WDestructiveClose flag is set, it + will also be destroyed. + + \sa ignore(), TQWidget::hide() +*/ + +/*! + \fn void TQCloseEvent::ignore() + + Clears the accept flag of the close event object. + + Clearing the accept flag indicates that the receiver of this event + does not want the widget to be closed. + + The close event is constructed with the accept flag cleared. + + \sa accept() +*/ + +/*! + \class TQIconDragEvent tqevent.h + \brief The TQIconDragEvent class signals that a main icon drag has begun. + + \ingroup events + + Icon drag events are sent to widgets when the main icon of a window has been dragged away. + On Mac OS X this is fired when the proxy icon of a window is dragged off titlebar, in response to + this event is is normal to begin using drag and drop. +*/ + +/*! + \fn TQIconDragEvent::TQIconDragEvent() + + Constructs an icon drag event object with the accept parameter + flag set to FALSE. + + \sa accept() +*/ + +/*! + \fn bool TQIconDragEvent::isAccepted() const + + Returns TRUE if the receiver of the event has started a drag and + drop operation; otherwise returns FALSE. + + \sa accept(), ignore() +*/ + +/*! + \fn void TQIconDragEvent::accept() + + Sets the accept flag of the icon drag event object. + + Setting the accept flag indicates that the receiver of this event + has started a drag and drop oeration. + + The accept flag is \e not set by default. + + \sa ignore(), TQWidget::hide() +*/ + +/*! + \fn void TQIconDragEvent::ignore() + + Clears the accept flag of the icon drag object. + + Clearing the accept flag indicates that the receiver of this event + has not handled the icon drag as a result other events can be sent. + + The icon drag event is constructed with the accept flag cleared. + + \sa accept() +*/ + +/*! + \class TQContextMenuEvent tqevent.h + \brief The TQContextMenuEvent class contains parameters that describe a context menu event. + + \ingroup events + + Context menu events are sent to widgets when a user triggers a + context menu. What triggers this is platform dependent. For + example, on Windows, pressing the menu button or releasing the + right mouse button will cause this event to be sent. + + When this event occurs it is customary to show a TQPopupMenu with a + context menu, if this is relevant to the context. + + Context menu events contain a special accept flag that indicates + whether the receiver accepted the event. If the event handler does + not accept the event, then whatever triggered the event will be + handled as a regular input event if possible. + + \sa TQPopupMenu +*/ + +/*! + \fn TQContextMenuEvent::TQContextMenuEvent( Reason reason, const TQPoint &pos, const TQPoint &globalPos, int state ) + + Constructs a context menu event object with the accept parameter + flag set to FALSE. + + The \a reason parameter must be \c TQContextMenuEvent::Mouse or \c + TQContextMenuEvent::Keyboard. + + The \a pos parameter specifies the mouse position relative to the + receiving widget. \a globalPos is the mouse position in absolute + coordinates. \a state is the ButtonState at the time of the event. +*/ + + +/*! + \fn TQContextMenuEvent::TQContextMenuEvent( Reason reason, const TQPoint &pos, int state ) + + Constructs a context menu event object with the accept parameter + flag set to FALSE. + + The \a reason parameter must be \c TQContextMenuEvent::Mouse or \c + TQContextMenuEvent::Keyboard. + + The \a pos parameter specifies the mouse position relative to the + receiving widget. \a state is the ButtonState at the time of the + event. + + The globalPos() is initialized to TQCursor::pos(), which may not be + appropriate. Use the other constructor to specify the global + position explicitly. +*/ + +TQContextMenuEvent::TQContextMenuEvent( Reason reason, const TQPoint &pos, int state ) + : TQEvent( ContextMenu ), p( pos ), accpt(TRUE), consum(TRUE), + reas( reason ), s((ushort)state) +{ + gp = TQCursor::pos(); +} + +/*! + \fn const TQPoint &TQContextMenuEvent::pos() const + + Returns the position of the mouse pointer relative to the widget + that received the event. + + \sa x(), y(), globalPos() +*/ + +/*! + \fn int TQContextMenuEvent::x() const + + Returns the x-position of the mouse pointer, relative to the + widget that received the event. + + \sa y(), pos() +*/ + +/*! + \fn int TQContextMenuEvent::y() const + + Returns the y-position of the mouse pointer, relative to the + widget that received the event. + + \sa x(), pos() +*/ + +/*! + \fn const TQPoint &TQContextMenuEvent::globalPos() const + + Returns the global position of the mouse pointer at the time of + the event. + + \sa x(), y(), pos() +*/ + +/*! + \fn int TQContextMenuEvent::globalX() const + + Returns the global x-position of the mouse pointer at the time of + the event. + + \sa globalY(), globalPos() +*/ + +/*! + \fn int TQContextMenuEvent::globalY() const + + Returns the global y-position of the mouse pointer at the time of + the event. + + \sa globalX(), globalPos() +*/ + +/*! + \fn ButtonState TQContextMenuEvent::state() const + + Returns the button state (a combination of mouse buttons and + keyboard modifiers), i.e. what buttons and keys were being + pressed immediately before the event was generated. + + The returned value is \c LeftButton, \c RightButton, \c MidButton, + \c ShiftButton, \c ControlButton and \c AltButton OR'ed together. +*/ + +/*! + \fn bool TQContextMenuEvent::isConsumed() const + + Returns TRUE (which stops propagation of the event) if the + receiver has blocked the event; otherwise returns FALSE. + + \sa accept(), ignore(), consume() +*/ + +/*! + \fn void TQContextMenuEvent::consume() + + Sets the consume flag of the context event object. + + Setting the consume flag indicates that the receiver of this event + does not want the event to be propagated further (i.e. not sent to + parent classes.) + + The consumed flag is not set by default. + + \sa ignore() accept() +*/ + +/*! + \fn bool TQContextMenuEvent::isAccepted() const + + Returns TRUE if the receiver has processed the event; otherwise + returns FALSE. + + \sa accept(), ignore(), consume() +*/ + +/*! + \fn void TQContextMenuEvent::accept() + + Sets the accept flag of the context event object. + + Setting the accept flag indicates that the receiver of this event + has processed the event. Processing the event means you did + something with it and it will be implicitly consumed. + + The accept flag is not set by default. + + \sa ignore() consume() +*/ + +/*! + \fn void TQContextMenuEvent::ignore() + + Clears the accept flag of the context event object. + + Clearing the accept flag indicates that the receiver of this event + does not need to show a context menu. This will implicitly remove + the consumed flag as well. + + The accept flag is not set by default. + + \sa accept() consume() +*/ + +/*! + \enum TQContextMenuEvent::Reason + + This enum describes the reason the ContextMenuEvent was sent. The + values are: + + \value Mouse The mouse caused the event to be sent. Normally this + means the right mouse button was clicked, but this is platform + specific. + + \value Keyboard The keyboard caused this event to be sent. On + Windows this means the menu button was pressed. + + \value Other The event was sent by some other means (i.e. not by + the mouse or keyboard). +*/ + + +/*! + \fn TQContextMenuEvent::Reason TQContextMenuEvent::reason() const + + Returns the reason for this context event. +*/ + + +/*! + \class TQIMEvent tqevent.h + \brief The TQIMEvent class provides parameters for input method events. + + \ingroup events + + Input method events are sent to widgets when an input method is + used to enter text into a widget. Input methods are widely used to + enter text in Asian and other complex languages. + + The events are of interest to widgets that accept keyboard input + and want to be able to correctly handle complex languages. Text + input in such languages is usually a three step process. + + \list 1 + \i Starting to Compose
+ When the user presses the first key on a keyboard an input context + is created. This input context will contain a string with the + typed characters. + + \i Composing
+ With every new key pressed, the input method will try to create a + matching string for the text typed so far. While the input context + is active, the user can only move the cursor inside the string + belonging to this input context. + + \i Completing
+ At some point, e.g. when the user presses the Spacebar, they get + to this stage, where they can choose from a number of strings that + match the text they have typed so far. The user can press Enter to + confirm their choice or Escape to cancel the input; in either case + the input context will be closed. + \endlist + + Note that the particular key presses used for a given input + context may differ from those we've mentioned here, i.e. they may + not be Spacebar, Enter and Escape. + + These three stages are represented by three different types of + events. The IMStartEvent, IMComposeEvent and IMEndEvent. When a + new input context is created, an IMStartEvent will be sent to the + widget and delivered to the \l TQWidget::imStartEvent() function. + The widget can then update internal data structures to reflect + this. + + After this, an IMComposeEvent will be sent to the widget for + every key the user presses. It will contain the current + composition string the widget has to show and the current cursor + position within the composition string. This string is temporary + and can change with every key the user types, so the widget will + need to store the state before the composition started (the state + it had when it received the IMStartEvent). IMComposeEvents will be + delivered to the \l TQWidget::imComposeEvent() function. + + Usually, widgets try to mark the part of the text that is part of + the current composition in a way that is visible to the user. A + commonly used visual cue is to use a dotted underline. + + After the user has selected the final string, an IMEndEvent will + be sent to the widget. The event contains the final string the + user selected, and could be empty if they canceled the + composition. This string should be accepted as the final text the + user entered, and the intermediate composition string should be + cleared. These events are delivered to \l TQWidget::imEndEvent(). + + If the user clicks another widget, taking the focus out of the + widget where the composition is taking place the IMEndEvent will + be sent and the string it holds will be the result of the + composition up to that point (which may be an empty string). +*/ + +/*! + \fn TQIMEvent::TQIMEvent( Type type, const TQString &text, int cursorPosition ) + + Constructs a new TQIMEvent with the accept flag set to FALSE. \a + type can be one of TQEvent::IMStartEvent, TQEvent::IMComposeEvent + or TQEvent::IMEndEvent. \a text contains the current compostion + string and \a cursorPosition the current position of the cursor + inside \a text. +*/ + +/*! + \fn const TQString &TQIMEvent::text() const + + Returns the composition text. This is a null string for an + IMStartEvent, and contains the final accepted string (which may be + empty) in the IMEndEvent. +*/ + +/*! + \fn int TQIMEvent::cursorPos() const + + Returns the current cursor position inside the composition string. + Will return -1 for IMStartEvent and IMEndEvent. +*/ + +/*! + \fn int TQIMEvent::selectionLength() const + + Returns the number of characters in the composition string ( + starting at cursorPos() ) that should be marked as selected by the + input widget receiving the event. + Will return 0 for IMStartEvent and IMEndEvent. +*/ + +/*! + \fn bool TQIMEvent::isAccepted() const + + Returns TRUE if the receiver of the event processed the event; + otherwise returns FALSE. +*/ + +/*! + \fn void TQIMEvent::accept() + + Sets the accept flag of the input method event object. + + Setting the accept parameter indicates that the receiver of the + event processed the input method event. + + The accept flag is not set by default. + + \sa ignore() +*/ + + +/*! + \fn void TQIMEvent::ignore() + + Clears the accept flag parameter of the input method event object. + + Clearing the accept parameter indicates that the event receiver + does not want the input method event. + + The accept flag is cleared by default. + + \sa accept() +*/ + +/*! + \class TQTabletEvent tqevent.h + \brief The TQTabletEvent class contains parameters that describe a Tablet + event. + + \ingroup events + + Tablet Events are generated from a Wacom© tablet. Most of + the time you will want to deal with events from the tablet as if + they were events from a mouse, for example retrieving the position + with x(), y(), pos(), globalX(), globalY() and globalPos(). In + some situations you may wish to retrieve the extra information + provided by the tablet device driver, for example, you might want + to adjust color brightness based on pressure. TQTabletEvent allows + you to get the pressure(), the xTilt() and yTilt(), as well as the + type of device being used with device() (see \l{TabletDevice}). + + A tablet event contains a special accept flag that indicates + whether the receiver wants the event. You should call + TQTabletEvent::accept() if you handle the tablet event; otherwise + it will be sent to the parent widget. + + The TQWidget::setEnabled() function can be used to enable or + disable mouse and keyboard events for a widget. + + The event handler TQWidget::tabletEvent() receives all three types of tablet + events. TQt will first send a tabletEvent and then, if it is not accepted, + it will send a mouse event. This allows applications that don't utilize + tablets to use a tablet like a mouse while also enabling those who want to + use both tablets and mouses differently. + +*/ + +/*! + \enum TQTabletEvent::TabletDevice + + This enum defines what type of device is generating the event. + + \value NoDevice No device, or an unknown device. + \value Puck A Puck (a device that is similar to a flat mouse with + a transparent circle with cross-hairs). + \value Stylus A Stylus (the narrow end of the pen). + \value Eraser An Eraser (the broad end of the pen). + \omit + \value Menu A menu button was pressed (currently unimplemented). +*/ + +/*! + \fn TQTabletEvent::TQTabletEvent( Type t, const TQPoint &pos, + const TQPoint &globalPos, int device, + int pressure, int xTilt, int yTilt, + const TQPair &uId ) + Construct a tablet event of type \a t. The position of when the event occurred is given + int \a pos and \a globalPos. \a device contains the \link TabletDevice device type\endlink, + \a pressure contains the pressure exerted on the \a device, \a xTilt and \a yTilt contain + \a device's degree of tilt from the X and Y axis respectively. The \a uId contains an + event id. + + On Irix, \a globalPos will contain the high-resolution coordinates received from the + tablet device driver, instead of from the windowing system. + + \sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt() +*/ + +TQTabletEvent::TQTabletEvent( Type t, const TQPoint &pos, const TQPoint &globalPos, int device, + int pressure, int xTilt, int yTilt, + const TQPair &uId ) + : TQEvent( t ), + mPos( pos ), + mGPos( globalPos ), + mDev( device ), + mPress( pressure ), + mXT( xTilt ), + mYT( yTilt ), + mType( uId.first ), + mPhy( uId.second ), + mbAcc(TRUE) +{} + +/*! + \obsolete + \fn TQTabletEvent::TQTabletEvent( const TQPoint &pos, const TQPoint &globalPos, int device, int pressure, int xTilt, int yTilt, const TQPair &uId ) + + Constructs a tablet event object. The position when the event + occurred is is given in \a pos and \a globalPos. \a device + contains the \link TabletDevice device type\endlink, \a pressure + contains the pressure exerted on the \a device, \a xTilt and \a + yTilt contain the \a device's degrees of tilt from the X and Y + axis respectively. The \a uId contains an event id. + + On Irix, \a globalPos will contain the high-resolution coordinates + received from the tablet device driver, instead of from the + windowing system. + + \sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt() +*/ + +/*! + \fn TabletDevices TQTabletEvent::device() const + + Returns the type of device that generated the event. Useful if you + want one end of the pen to do something different than the other. + + \sa TabletDevice +*/ + +/*! + \fn int TQTabletEvent::pressure() const + + Returns the pressure that is exerted on the device. This number is + a value from 0 (no pressure) to 255 (maximum pressure). The + pressure is always scaled to be within this range no matter how + many pressure levels the underlying hardware supports. +*/ + +/*! + \fn int TQTabletEvent::xTilt() const + + Returns the difference from the perpendicular in the X Axis. + Positive values are towards the tablet's physical right. The angle + is in the range -60 to +60 degrees. + + \sa yTilt() +*/ + +/*! + \fn int TQTabletEvent::yTilt() const + + Returns the difference from the perpendicular in the Y Axis. + Positive values are towards the bottom of the tablet. The angle is + within the range -60 to +60 degrees. + + \sa xTilt() +*/ + +/*! + \fn const TQPoint &TQTabletEvent::pos() const + + Returns the position of the device, relative to the widget that + received the event. + + If you move widgets around in response to mouse events, use + globalPos() instead of this function. + + \sa x(), y(), globalPos() +*/ + +/*! + \fn int TQTabletEvent::x() const + + Returns the x-position of the device, relative to the widget that + received the event. + + \sa y(), pos() +*/ + +/*! + \fn int TQTabletEvent::y() const + + Returns the y-position of the device, relative to the widget that + received the event. + + \sa x(), pos() +*/ + +/*! + \fn const TQPoint &TQTabletEvent::globalPos() const + + Returns the global position of the device \e{at the time of the + event}. This is important on asynchronous windows systems like X11; + whenever you move your widgets around in response to mouse events, + globalPos() can differ significantly from the current position + TQCursor::pos(). + + \sa globalX(), globalY() +*/ + +/*! + \fn int TQTabletEvent::globalX() const + + Returns the global x-position of the mouse pointer at the time of + the event. + + \sa globalY(), globalPos() +*/ + +/*! + \fn int TQTabletEvent::globalY() const + + Returns the global y-position of the mouse pointer at the time of + the event. + + \sa globalX(), globalPos() +*/ + +/*! + \fn bool TQTabletEvent::isAccepted() const + + Returns TRUE if the receiver of the event handles the tablet + event; otherwise returns FALSE. +*/ + +/*! + \fn void TQTabletEvent::accept() + + Sets the accept flag of the tablet event object. + + Setting the accept flag indicates that the receiver of the event + wants the tablet event. Unwanted tablet events are sent to the + parent widget. + + The accept flag is set by default. + + \sa ignore() +*/ + +/*! + \fn void TQTabletEvent::ignore() + + Clears the accept flag parameter of the tablet event object. + + Clearing the accept flag indicates that the event receiver does + not want the tablet event. Unwanted tablet events are sent to the + parent widget. + + The accept flag is set by default. + + \sa accept() +*/ + +/*! + \fn TQPair TQTabletEvent::uniqueId() + + Returns a unique ID for the current device. It is possible to + generate a unique ID for any Wacom© device. This makes it + possible to differentiate between multiple devices being used at + the same time on the tablet. The \c first member contains a value + for the type, the \c second member contains a physical ID obtained + from the device. Each combination of these values is unique. Note: + for different platforms, the \c first value is different due to + different driver implementations. +*/ + +/*! + \class TQChildEvent tqevent.h + \brief The TQChildEvent class contains event parameters for child object + events. + + \ingroup events + + Child events are sent to objects when children are inserted or + removed. + + A \c ChildRemoved event is sent immediately, but a \c + ChildInserted event is \e posted (with TQApplication::postEvent()). + + Note that if a child is removed immediately after it is inserted, + the \c ChildInserted event may be suppressed, but the \c + ChildRemoved event will always be sent. In this case there will be + a \c ChildRemoved event without a corresponding \c ChildInserted + event. + + The handler for these events is TQObject::childEvent(). +*/ + +/*! + \fn TQChildEvent::TQChildEvent( Type type, TQObject *child ) + + Constructs a child event object. The \a child is the object that + is to be removed or inserted. + + The \a type parameter must be either \c TQEvent::ChildInserted or + \c TQEvent::ChildRemoved. +*/ + +/*! + \fn TQObject *TQChildEvent::child() const + + Returns the child widget that was inserted or removed. +*/ + +/*! + \fn bool TQChildEvent::inserted() const + + Returns TRUE if the widget received a new child; otherwise returns + FALSE. +*/ + +/*! + \fn bool TQChildEvent::removed() const + + Returns TRUE if the object lost a child; otherwise returns FALSE. +*/ + + + + +/*! + \class TQCustomEvent tqevent.h + \brief The TQCustomEvent class provides support for custom events. + + \ingroup events + + TQCustomEvent is a generic event class for user-defined events. + User defined events can be sent to widgets or other TQObject + instances using TQApplication::postEvent() or + TQApplication::sendEvent(). Subclasses of TQObject can easily + receive custom events by implementing the TQObject::customEvent() + event handler function. + + TQCustomEvent objects should be created with a type ID that + uniquely identifies the event type. To avoid clashes with the + TQt-defined events types, the value should be at least as large as + the value of the "User" entry in the TQEvent::Type enum. + + TQCustomEvent contains a generic void* data member that may be used + for transferring event-specific data to the receiver. Note that + since events are normally delivered asynchronously, the data + pointer, if used, must remain valid until the event has been + received and processed. + + TQCustomEvent can be used as-is for simple user-defined event + types, but normally you will want to make a subclass of it for + your event types. In a subclass, you can add data members that are + suitable for your event type. + + Example: + \code + class ColorChangeEvent : public TQCustomEvent + { + public: + ColorChangeEvent( TQColor color ) + : TQCustomEvent( 65432 ), c( color ) {} + TQColor color() const { return c; } + private: + TQColor c; + }; + + // To send an event of this custom event type: + + ColorChangeEvent* ce = new ColorChangeEvent( blue ); + TQApplication::postEvent( receiver, ce ); // TQt will delete it when done + + // To receive an event of this custom event type: + + void MyWidget::customEvent( TQCustomEvent * e ) + { + if ( e->type() == 65432 ) { // It must be a ColorChangeEvent + ColorChangeEvent* ce = (ColorChangeEvent*)e; + newColor = ce->color(); + } + } + \endcode + + \sa TQWidget::customEvent(), TQApplication::notify() +*/ + + +/*! + Constructs a custom event object with event type \a type. The + value of \a type must be at least as large as TQEvent::User. The + data pointer is set to 0. +*/ + +TQCustomEvent::TQCustomEvent( int type ) + : TQEvent( (TQEvent::Type)type ), d( 0 ) +{ +} + + +/*! + \fn TQCustomEvent::TQCustomEvent( Type type, void *data ) + + Constructs a custom event object with the event type \a type and a + pointer to \a data. (Note that any int value may safely be cast to + TQEvent::Type). +*/ + + +/*! + \fn void TQCustomEvent::setData( void* data ) + + Sets the generic data pointer to \a data. + + \sa data() +*/ + +/*! + \fn void *TQCustomEvent::data() const + + Returns a pointer to the generic event data. + + \sa setData() +*/ + + + +/*! + \fn TQDragMoveEvent::TQDragMoveEvent( const TQPoint& pos, Type type ) + + Creates a TQDragMoveEvent for which the mouse is at point \a pos, + and the event is of type \a type. + + \warning Do not create a TQDragMoveEvent yourself since these + objects rely on TQt's internal state. +*/ + +/*! + \fn void TQDragMoveEvent::accept( const TQRect & r ) + + The same as accept(), but also notifies that future moves will + also be acceptable if they remain within the rectangle \a r on the + widget: this can improve performance, but may also be ignored by + the underlying system. + + If the rectangle is \link TQRect::isEmpty() empty\endlink, then + drag move events will be sent continuously. This is useful if the + source is scrolling in a timer event. +*/ + +/*! + \fn void TQDragMoveEvent::ignore( const TQRect & r) + + The opposite of accept(const TQRect&), i.e. says that moves within + rectangle \a r are not acceptable (will be ignored). +*/ + +/*! + \fn TQRect TQDragMoveEvent::answerRect() const + + Returns the rectangle for which the acceptance of the move event + applies. +*/ + + + +/*! + \fn const TQPoint& TQDropEvent::pos() const + + Returns the position where the drop was made. +*/ + +/*! + \fn bool TQDropEvent::isAccepted () const + + Returns TRUE if the drop target accepts the event; otherwise + returns FALSE. +*/ + +/*! + \fn void TQDropEvent::accept(bool y=TRUE) + + Call this function to indicate whether the event provided data + which your widget processed. Set \a y to TRUE (the default) if + your widget could process the data, otherwise set \a y to FALSE. + To get the data, use encodedData(), or preferably, the decode() + methods of existing TQDragObject subclasses, such as + TQTextDrag::decode(), or your own subclasses. + + \sa acceptAction() +*/ + +/*! + \fn void TQDropEvent::acceptAction(bool y=TRUE) + + Call this to indicate that the action described by action() is + accepted (i.e. if \a y is TRUE, which is the default), not merely + the default copy action. If you call acceptAction(TRUE), there is + no need to also call accept(TRUE). +*/ + +/*! + \fn void TQDragMoveEvent::accept( bool y ) + \reimp + \internal + Remove in 3.0 +*/ + +/*! + \fn void TQDragMoveEvent::ignore() + \reimp + \internal + Remove in 3.0 +*/ + + +/*! + \enum TQDropEvent::Action + + This enum describes the action which a source requests that a + target perform with dropped data. + + \value Copy The default action. The source simply uses the data + provided in the operation. + \value Link The source should somehow create a link to the + location specified by the data. + \value Move The source should somehow move the object from the + location specified by the data to a new location. + \value Private The target has special knowledge of the MIME type, + which the source should respond to in a similar way to + a Copy. + \value UserAction The source and target can co-operate using + special actions. This feature is not currently + supported. + + The Link and Move actions only makes sense if the data is a + reference, for example, text/uri-list file lists (see TQUriDrag). +*/ + +/*! + \fn void TQDropEvent::setAction( Action a ) + + Sets the action to \a a. This is used internally, you should not + need to call this in your code: the \e source decides the action, + not the target. +*/ + +/*! + \fn Action TQDropEvent::action() const + + Returns the Action which the target is requesting to be performed + with the data. If your application understands the action and can + process the supplied data, call acceptAction(); if your + application can process the supplied data but can only perform the + Copy action, call accept(). +*/ + +/*! + \fn void TQDropEvent::ignore() + + The opposite of accept(), i.e. you have ignored the drop event. +*/ + +/*! + \fn bool TQDropEvent::isActionAccepted () const + + Returns TRUE if the drop action was accepted by the drop site; + otherwise returns FALSE. +*/ + + +/*! + \fn void TQDropEvent::setPoint (const TQPoint & np) + + Sets the drop to happen at point \a np. You do not normally need + to use this as it will be set internally before your widget + receives the drop event. +*/ // ### here too - what coordinate system? + + +/*! + \class TQDragEnterEvent tqevent.h + \brief The TQDragEnterEvent class provides an event which is sent to the widget when a drag and drop first drags onto the widget. + + \ingroup events + \ingroup draganddrop + + This event is always immediately followed by a TQDragMoveEvent, so + you only need to respond to one or the other event. This class + inherits most of its functionality from TQDragMoveEvent, which in + turn inherits most of its functionality from TQDropEvent. + + \sa TQDragLeaveEvent, TQDragMoveEvent, TQDropEvent +*/ + +/*! + \fn TQDragEnterEvent::TQDragEnterEvent (const TQPoint & pos) + + Constructs a TQDragEnterEvent entering at the given point, \a pos. + + \warning Do not create a TQDragEnterEvent yourself since these + objects rely on TQt's internal state. +*/ + +/*! + \class TQDragLeaveEvent tqevent.h + \brief The TQDragLeaveEvent class provides an event which is sent to the widget when a drag and drop leaves the widget. + + \ingroup events + \ingroup draganddrop + + This event is always preceded by a TQDragEnterEvent and a series of + \l{TQDragMoveEvent}s. It is not sent if a TQDropEvent is sent + instead. + + \sa TQDragEnterEvent, TQDragMoveEvent, TQDropEvent +*/ + +/*! + \fn TQDragLeaveEvent::TQDragLeaveEvent() + + Constructs a TQDragLeaveEvent. + + \warning Do not create a TQDragLeaveEvent yourself since these + objects rely on TQt's internal state. +*/ + +/*! + \class TQHideEvent tqevent.h + \brief The TQHideEvent class provides an event which is sent after a widget is hidden. + + \ingroup events + + This event is sent just before TQWidget::hide() returns, and also + when a top-level window has been hidden (iconified) by the user. + + If spontaneous() is TRUE the event originated outside the + application, i.e. the user hid the window using the window manager + controls, either by iconifying the window or by switching to + another virtual desktop where the window isn't visible. The window + will become hidden but not withdrawn. If the window was iconified, + TQWidget::isMinimized() returns TRUE. + + \sa TQShowEvent +*/ + +/*! + \fn TQHideEvent::TQHideEvent() + + Constructs a TQHideEvent. +*/ + +/*! + \class TQShowEvent tqevent.h + \brief The TQShowEvent class provides an event which is sent when a widget is shown. + + \ingroup events + + There are two kinds of show events: show events caused by the + window system (spontaneous) and internal show events. Spontaneous + show events are sent just after the window system shows the + window, including after a top-level window has been shown + (un-iconified) by the user. Internal show events are delivered + just before the widget becomes visible. + + \sa TQHideEvent +*/ + +/*! + \fn TQShowEvent::TQShowEvent() + + Constructs a TQShowEvent. +*/ + + +/*! + \fn TQByteArray TQDropEvent::data(const char* f) const + + \obsolete + + Use TQDropEvent::encodedData(). +*/ + + +/*! + Destroys the event. If it was \link + TQApplication::postEvent() posted \endlink, + it will be removed from the list of events to be posted. +*/ + +TQEvent::~TQEvent() +{ + if ( posted && tqApp ) + TQApplication::removePostedEvent( this ); +} diff --git a/src/kernel/tqevent.h b/src/kernel/tqevent.h new file mode 100644 index 000000000..f05fc2c94 --- /dev/null +++ b/src/kernel/tqevent.h @@ -0,0 +1,619 @@ +/**************************************************************************** +** +** Definition of event classes +** +** 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. +** +**********************************************************************/ + +#ifndef TQEVENT_H +#define TQEVENT_H + +#ifndef QT_H +#include "ntqwindowdefs.h" +#include "tqregion.h" +#include "ntqnamespace.h" +#include "tqmime.h" +#include "tqpair.h" +#endif // QT_H + +class TQ_EXPORT TQEvent: public TQt // event base class +{ +public: + enum Type { + + /* + If you get a strange compiler error on the line with None, + it's probably because you're also including X11 headers, + which #define the symbol None. Put the X11 includes after + the TQt includes to solve this problem. + */ + + None = 0, // invalid event + + + Timer = 1, // timer event + MouseButtonPress = 2, // mouse button pressed + MouseButtonRelease = 3, // mouse button released + MouseButtonDblClick = 4, // mouse button double click + MouseMove = 5, // mouse move + KeyPress = 6, // key pressed + KeyRelease = 7, // key released + FocusIn = 8, // keyboard focus received + FocusOut = 9, // keyboard focus lost + Enter = 10, // mouse enters widget + Leave = 11, // mouse leaves widget + Paint = 12, // paint widget + Move = 13, // move widget + Resize = 14, // resize widget + Create = 15, // after object creation + Destroy = 16, // during object destruction + Show = 17, // widget is shown + Hide = 18, // widget is hidden + Close = 19, // request to close widget + Quit = 20, // request to quit application + Reparent = 21, // widget has been reparented + ShowMinimized = 22, // widget is shown minimized + ShowNormal = 23, // widget is shown normal + WindowActivate = 24, // window was activated + WindowDeactivate = 25, // window was deactivated + ShowToParent = 26, // widget is shown to parent + HideToParent = 27, // widget is hidden to parent + ShowMaximized = 28, // widget is shown maximized + ShowFullScreen = 29, // widget is shown full-screen + Accel = 30, // accelerator event + Wheel = 31, // wheel event + AccelAvailable = 32, // accelerator available event + CaptionChange = 33, // caption changed + IconChange = 34, // icon changed + ParentFontChange = 35, // parent font changed + ApplicationFontChange = 36, // application font changed + ParentPaletteChange = 37, // parent palette changed + ApplicationPaletteChange = 38, // application palette changed + PaletteChange = 39, // widget palette changed + Clipboard = 40, // internal clipboard event + Speech = 42, // reserved for speech input + SockAct = 50, // socket activation + AccelOverride = 51, // accelerator override event + DeferredDelete = 52, // deferred delete event + DragEnter = 60, // drag moves into widget + DragMove = 61, // drag moves in widget + DragLeave = 62, // drag leaves or is cancelled + Drop = 63, // actual drop + DragResponse = 64, // drag accepted/rejected + ChildInserted = 70, // new child widget + ChildRemoved = 71, // deleted child widget + LayoutHint = 72, // child min/max size changed + ShowWindowRequest = 73, // widget's window should be mapped + WindowBlocked = 74, // window is about to be blocked modally + WindowUnblocked = 75, // windows modal blocking has ended + ActivateControl = 80, // ActiveX activation + DeactivateControl = 81, // ActiveX deactivation + ContextMenu = 82, // context popup menu + IMStart = 83, // input method composition start + IMCompose = 84, // input method composition + IMEnd = 85, // input method composition end + Accessibility = 86, // accessibility information is requested + TabletMove = 87, // Wacom tablet event + LocaleChange = 88, // the system locale changed + LanguageChange = 89, // the application language changed + LayoutDirectionChange = 90, // the layout direction changed + Style = 91, // internal style event + TabletPress = 92, // tablet press + TabletRelease = 93, // tablet release + OkRequest = 94, // CE (Ok) button pressed + HelpRequest = 95, // CE (?) button pressed + WindowStateChange = 96, // window state has changed + IconDrag = 97, // proxy icon dragged + MetaCall = 98, // meta method call (internal) + ThreadChange = 99, // thread changed + User = 1000, // first user event id + MaxUser = 65535 // last user event id + }; + + + TQEvent( Type type ) : t(type), posted(FALSE), spont(FALSE) {} + virtual ~TQEvent(); + Type type() const { return t; } + bool spontaneous() const { return spont; } +protected: + Type t; +private: + uint posted : 1; + uint spont : 1; + + + friend class TQApplication; + friend class TQAccelManager; + friend class TQBaseApplication; + friend class TQETWidget; +}; + + +class TQ_EXPORT TQTimerEvent : public TQEvent +{ +public: + TQTimerEvent( int timerId ) + : TQEvent(Timer), id(timerId) {} + int timerId() const { return id; } +protected: + int id; +}; + + +class TQ_EXPORT TQMouseEvent : public TQEvent +{ +public: + TQMouseEvent( Type type, const TQPoint &pos, int button, int state ); + + TQMouseEvent( Type type, const TQPoint &pos, const TQPoint&globalPos, + int button, int state ) + : TQEvent(type), p(pos), g(globalPos), b((ushort)button),s((ushort)state),accpt(TRUE) {}; + + const TQPoint &pos() const { return p; } + const TQPoint &globalPos() const { return g; } + int x() const { return p.x(); } + int y() const { return p.y(); } + int globalX() const { return g.x(); } + int globalY() const { return g.y(); } + ButtonState button() const { return (ButtonState) b; } + ButtonState state() const { return (ButtonState) s; } + ButtonState stateAfter() const; + bool isAccepted() const { return accpt; } + void accept() { accpt = TRUE; } + void ignore() { accpt = FALSE; } +protected: + TQPoint p; + TQPoint g; + ushort b; + ushort s; + uint accpt:1; +}; + + +#ifndef TQT_NO_WHEELEVENT +class TQ_EXPORT TQWheelEvent : public TQEvent +{ +public: + TQWheelEvent( const TQPoint &pos, int delta, int state, Orientation orient = Vertical ); + TQWheelEvent( const TQPoint &pos, const TQPoint& globalPos, int delta, int state, Orientation orient = Vertical ) + : TQEvent(Wheel), p(pos), g(globalPos), d(delta), s((ushort)state), + accpt(TRUE), o(orient) {} + int delta() const { return d; } + const TQPoint &pos() const { return p; } + const TQPoint &globalPos() const { return g; } + int x() const { return p.x(); } + int y() const { return p.y(); } + int globalX() const { return g.x(); } + int globalY() const { return g.y(); } + ButtonState state() const { return ButtonState(s); } + Orientation orientation() const { return o; } + bool isAccepted() const { return accpt; } + void accept() { accpt = TRUE; } + void ignore() { accpt = FALSE; } +protected: + TQPoint p; + TQPoint g; + int d; + ushort s; + bool accpt; + Orientation o; +}; +#endif + +class TQ_EXPORT TQTabletEvent : public TQEvent +{ +public: + enum TabletDevice { NoDevice = -1, Puck, Stylus, Eraser }; + TQTabletEvent( Type t, const TQPoint &pos, const TQPoint &globalPos, int device, + int pressure, int xTilt, int yTilt, const TQPair &uId ); + TQTabletEvent( const TQPoint &pos, const TQPoint &globalPos, int device, + int pressure, int xTilt, int yTilt, const TQPair &uId ) + : TQEvent( TabletMove ), mPos( pos ), mGPos( globalPos ), mDev( device ), + mPress( pressure ), mXT( xTilt ), mYT( yTilt ), mType( uId.first ), + mPhy( uId.second ), mbAcc(TRUE) + {} + int pressure() const { return mPress; } + int xTilt() const { return mXT; } + int yTilt() const { return mYT; } + const TQPoint &pos() const { return mPos; } + const TQPoint &globalPos() const { return mGPos; } + int x() const { return mPos.x(); } + int y() const { return mPos.y(); } + int globalX() const { return mGPos.x(); } + int globalY() const { return mGPos.y(); } + TabletDevice device() const { return TabletDevice(mDev); } + int isAccepted() const { return mbAcc; } + void accept() { mbAcc = TRUE; } + void ignore() { mbAcc = FALSE; } + TQPair uniqueId() { return TQPair( mType, mPhy); } +protected: + TQPoint mPos; + TQPoint mGPos; + int mDev, + mPress, + mXT, + mYT, + mType, + mPhy; + bool mbAcc; + +}; + +class TQ_EXPORT TQKeyEvent : public TQEvent +{ +public: + TQKeyEvent( Type type, int key, int ascii, int state, + const TQString& text=TQString::null, bool autorep=FALSE, ushort count=1 ) + : TQEvent(type), txt(text), k((ushort)key), s((ushort)state), + a((uchar)ascii), accpt(TRUE), autor(autorep), c(count) + { + if ( key >= Key_Back && key <= Key_MediaLast ) + accpt = FALSE; + } + int key() const { return k; } + int ascii() const { return a; } + ButtonState state() const { return ButtonState(s); } + ButtonState stateAfter() const; + bool isAccepted() const { return accpt; } + TQString text() const { return txt; } + bool isAutoRepeat() const { return autor; } + int count() const { return int(c); } + void accept() { accpt = TRUE; } + void ignore() { accpt = FALSE; } + +protected: + TQString txt; + ushort k, s; + uchar a; + uint accpt:1; + uint autor:1; + ushort c; +}; + + +class TQ_EXPORT TQFocusEvent : public TQEvent +{ +public: + + TQFocusEvent( Type type ) + : TQEvent(type) {} + + bool gotFocus() const { return type() == FocusIn; } + bool lostFocus() const { return type() == FocusOut; } + + enum Reason { Mouse, Tab, Backtab, ActiveWindow, Popup, Shortcut, Other }; + static Reason reason(); + static void setReason( Reason reason ); + static void resetReason(); + +private: + static Reason m_reason; + static Reason prev_reason; +}; + + +class TQ_EXPORT TQPaintEvent : public TQEvent +{ +public: + TQPaintEvent( const TQRegion& paintRegion, bool erased = TRUE) + : TQEvent(Paint), + rec(paintRegion.boundingRect()), + reg(paintRegion), + erase(erased){} + TQPaintEvent( const TQRect &paintRect, bool erased = TRUE ) + : TQEvent(Paint), + rec(paintRect), + reg(paintRect), + erase(erased){} + TQPaintEvent( const TQRegion &paintRegion, const TQRect &paintRect, bool erased = TRUE ) + : TQEvent(Paint), + rec(paintRect), + reg(paintRegion), + erase(erased){} + + const TQRect &rect() const { return rec; } + const TQRegion ®ion() const { return reg; } + bool erased() const { return erase; } +protected: + friend class TQApplication; + friend class TQBaseApplication; + TQRect rec; + TQRegion reg; + bool erase; +}; + + +class TQ_EXPORT TQMoveEvent : public TQEvent +{ +public: + TQMoveEvent( const TQPoint &pos, const TQPoint &oldPos ) + : TQEvent(Move), p(pos), oldp(oldPos) {} + const TQPoint &pos() const { return p; } + const TQPoint &oldPos()const { return oldp;} +protected: + TQPoint p, oldp; + friend class TQApplication; + friend class TQBaseApplication; +}; + + +class TQ_EXPORT TQResizeEvent : public TQEvent +{ +public: + TQResizeEvent( const TQSize &size, const TQSize &oldSize ) + : TQEvent(Resize), s(size), olds(oldSize) {} + const TQSize &size() const { return s; } + const TQSize &oldSize()const { return olds;} +protected: + TQSize s, olds; + friend class TQApplication; + friend class TQBaseApplication; +}; + + +class TQ_EXPORT TQCloseEvent : public TQEvent +{ +public: + TQCloseEvent() + : TQEvent(Close), accpt(FALSE) {} + bool isAccepted() const { return accpt; } + void accept() { accpt = TRUE; } + void ignore() { accpt = FALSE; } +protected: + bool accpt; +}; + + +class TQ_EXPORT TQIconDragEvent : public TQEvent +{ +public: + TQIconDragEvent() + : TQEvent(IconDrag), accpt(FALSE) {} + + bool isAccepted() const { return accpt; } + void accept() { accpt = TRUE; } + void ignore() { accpt = FALSE; } +protected: + bool accpt; +}; + +class TQ_EXPORT TQShowEvent : public TQEvent +{ +public: + TQShowEvent() + : TQEvent(Show) {} +}; + + +class TQ_EXPORT TQHideEvent : public TQEvent +{ +public: + TQHideEvent() + : TQEvent(Hide) {} +}; + +class TQ_EXPORT TQContextMenuEvent : public TQEvent +{ +public: + enum Reason { Mouse, Keyboard, Other }; + TQContextMenuEvent( Reason reason, const TQPoint &pos, const TQPoint &globalPos, int state ) + : TQEvent( ContextMenu ), p( pos ), gp( globalPos ), accpt( TRUE ), consum( TRUE ), + reas( reason ), s((ushort)state) {} + TQContextMenuEvent( Reason reason, const TQPoint &pos, int state ); + + int x() const { return p.x(); } + int y() const { return p.y(); } + int globalX() const { return gp.x(); } + int globalY() const { return gp.y(); } + + const TQPoint& pos() const { return p; } + const TQPoint& globalPos() const { return gp; } + + ButtonState state() const { return (ButtonState) s; } + bool isAccepted() const { return accpt; } + bool isConsumed() const { return consum; } + void consume() { accpt = FALSE; consum = TRUE; } + void accept() { accpt = TRUE; consum = TRUE; } + void ignore() { accpt = FALSE; consum = FALSE; } + + Reason reason() const { return Reason( reas ); } + +protected: + TQPoint p; + TQPoint gp; + bool accpt; + bool consum; + uint reas:8; + ushort s; +}; + + +class TQ_EXPORT TQIMEvent : public TQEvent +{ +public: + TQIMEvent( Type type, const TQString &text, int cursorPosition ) + : TQEvent(type), txt(text), cpos(cursorPosition), a(TRUE) {} + const TQString &text() const { return txt; } + int cursorPos() const { return cpos; } + bool isAccepted() const { return a; } + void accept() { a = TRUE; } + void ignore() { a = FALSE; } + int selectionLength() const; + +private: + TQString txt; + int cpos; + bool a; +}; + +class TQ_EXPORT TQIMComposeEvent : public TQIMEvent +{ +public: + TQIMComposeEvent( Type type, const TQString &text, int cursorPosition, + int selLength ) + : TQIMEvent( type, text, cursorPosition ), selLen( selLength ) { } + +private: + int selLen; + + friend class TQIMEvent; +}; + +inline int TQIMEvent::selectionLength() const +{ + if ( type() != IMCompose ) return 0; + TQIMComposeEvent *that = (TQIMComposeEvent *) this; + return that->selLen; +} + + +#ifndef TQT_NO_DRAGANDDROP + +// This class is rather closed at the moment. If you need to create your +// own DND event objects, write to qt-bugs@trolltech.com and we'll try to +// find a way to extend it so it covers your needs. + +class TQ_EXPORT TQDropEvent : public TQEvent, public TQMimeSource +{ +public: + TQDropEvent( const TQPoint& pos, Type typ=Drop ) + : TQEvent(typ), p(pos), + act(0), accpt(0), accptact(0), resv(0), + d(0) + {} + const TQPoint &pos() const { return p; } + bool isAccepted() const { return accpt || accptact; } + void accept(bool y=TRUE) { accpt = y; } + void ignore() { accpt = FALSE; } + + bool isActionAccepted() const { return accptact; } + void acceptAction(bool y=TRUE) { accptact = y; } + enum Action { Copy, Link, Move, Private, UserAction=100 }; + void setAction( Action a ) { act = (uint)a; } + Action action() const { return Action(act); } + + TQWidget* source() const; + const char* format( int n = 0 ) const; + TQByteArray encodedData( const char* ) const; + bool provides( const char* ) const; + + TQByteArray data(const char* f) const { return encodedData(f); } + + void setPoint( const TQPoint& np ) { p = np; } + +protected: + TQPoint p; + uint act:8; + uint accpt:1; + uint accptact:1; + uint resv:5; + void * d; +}; + + + +class TQ_EXPORT TQDragMoveEvent : public TQDropEvent +{ +public: + TQDragMoveEvent( const TQPoint& pos, Type typ=DragMove ) + : TQDropEvent(pos,typ), + rect( pos, TQSize( 1, 1 ) ) {} + TQRect answerRect() const { return rect; } + void accept( bool y=TRUE ) { TQDropEvent::accept(y); } + void accept( const TQRect & r) { accpt = TRUE; rect = r; } + void ignore( const TQRect & r) { accpt =FALSE; rect = r; } + void ignore() { TQDropEvent::ignore(); } + +protected: + TQRect rect; +}; + + +class TQ_EXPORT TQDragEnterEvent : public TQDragMoveEvent +{ +public: + TQDragEnterEvent( const TQPoint& pos ) : + TQDragMoveEvent(pos, DragEnter) { } +}; + + +/* An internal class */ +class TQ_EXPORT TQDragResponseEvent : public TQEvent +{ +public: + TQDragResponseEvent( bool accepted ) + : TQEvent(DragResponse), a(accepted) {} + bool dragAccepted() const { return a; } +protected: + bool a; +}; + + +class TQ_EXPORT TQDragLeaveEvent : public TQEvent +{ +public: + TQDragLeaveEvent() + : TQEvent(DragLeave) {} +}; + +#endif // TQT_NO_DRAGANDDROP + +class TQ_EXPORT TQChildEvent : public TQEvent +{ +public: + TQChildEvent( Type type, TQObject *child ) + : TQEvent(type), c(child) {} + TQObject *child() const { return c; } + bool inserted() const { return t == ChildInserted; } + bool removed() const { return t == ChildRemoved; } +protected: + TQObject *c; +}; + + +class TQ_EXPORT TQCustomEvent : public TQEvent +{ +public: + TQCustomEvent( int type ); + TQCustomEvent( Type type, void *data ) + : TQEvent(type), d(data) {}; + void *data() const { return d; } + void setData( void* data ) { d = data; } +private: + void *d; +}; + +#endif // TQEVENT_H diff --git a/src/kernel/tqeventloop.cpp b/src/kernel/tqeventloop.cpp new file mode 100644 index 000000000..4cbd98994 --- /dev/null +++ b/src/kernel/tqeventloop.cpp @@ -0,0 +1,423 @@ +/**************************************************************************** +** +** Implementation of TQEventLoop class +** +** 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 "tqeventloop_p.h" // includes qplatformdefs.h +#include "tqeventloop.h" +#include "ntqapplication.h" +#include "tqdatetime.h" + +#ifdef TQT_THREAD_SUPPORT +# include "tqthread.h" +# include "private/tqthreadinstance_p.h" +#endif + +/*! + \class TQEventLoop + \brief The TQEventLoop class manages the event queue. + + \ingroup application + \ingroup events + + It receives events from the window system and other sources. It + then sends them to TQApplication for processing and delivery. + + TQEventLoop allows the application programmer to have more control + over event delivery. Programs that perform long operations can + call either processOneEvent() or processEvents() with various + ProcessEvent values OR'ed together to control which events should + be delivered. + + TQEventLoop also allows the integration of an external event loop + with the TQt event loop. The Motif Extension included with TQt + includes a reimplementation of TQEventLoop for merging TQt and Motif + events together. + + To use your own instance of TQEventLoop or TQEventLoop subclass create + it before you create the TQApplication object. +*/ + +/*! \enum TQEventLoop::ProcessEvents + + This enum controls the types of events processed by the + processEvents() functions. + + \value AllEvents - All events are processed + \value ExcludeUserInput - Do not process user input events. + ( ButtonPress, KeyPress, etc. ) + \value ExcludeSocketNotifiers - Do not process socket notifier + events. + \value WaitForMore - Wait for events if no pending events + are available. + + \sa processEvents() +*/ + +/*! \enum TQEventLoop::ProcessEventsFlags + A \c typedef to allow various ProcessEvents values to be OR'ed together. + + \sa ProcessEvents + */ + +/*! + Creates a TQEventLoop object, this object becomes the global event loop object. + There can only be one event loop object. The TQEventLoop is usually constructed + by calling TQApplication::eventLoop(). To create your own event loop object create + it before you instantiate the TQApplication object. + + The \a parent and \a name arguments are passed on to the TQObject constructor. +*/ +TQEventLoop::TQEventLoop( TQObject *parent, const char *name ) + : TQObject( parent, name ) +{ +#if defined(QT_CHECK_STATE) + if ( TQApplication::currentEventLoop() ) + tqFatal( "TQEventLoop: there must be only one event loop object per thread. \nIf this is supposed to be the main GUI event loop, construct it before TQApplication." ); +#ifdef TQT_THREAD_SUPPORT + if (!TQThread::currentThreadObject()) { + tqFatal( "TQEventLoop: this object can only be used in threads constructed via TQThread." ); + } +#endif // TQT_THREAD_SUPPORT +#endif // QT_CHECK_STATE + + d = new TQEventLoopPrivate; + + init(); + +#ifdef TQT_THREAD_SUPPORT + TQThread* thread = TQThread::currentThreadObject(); + if (thread) { + if (thread->d) { + thread->d->eventLoop = this; + } + } +#else + TQApplication::eventloop = this; +#endif +} + +/*! + Destructs the TQEventLoop object. +*/ +TQEventLoop::~TQEventLoop() +{ + cleanup(); + delete d; +#ifdef TQT_THREAD_SUPPORT + TQThread* thread = TQThread::currentThreadObject(); + if (thread) { + if (thread->d) { + thread->d->eventLoop = 0; + } + } +#else + TQApplication::eventloop = 0; +#endif +} + +/*! + Enters the main event loop and waits until exit() is called, and + returns the value that was set to exit(). + + 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 TQApplication::quit(), exit(), processEvents() +*/ +int TQEventLoop::exec() +{ + d->reset(); + + enterLoop(); + + // cleanup + d->looplevel = 0; + d->quitnow = FALSE; + d->exitloop = FALSE; + d->shortcut = FALSE; + // don't reset quitcode! + + return d->quitcode; +} + +/*! \fn void TQEventLoop::exit( int retcode = 0 ) + + Tells the event loop to exit with a return code. + + After this function has been called, the event loop 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 TQApplication::quit(), exec() +*/ +void TQEventLoop::exit( int retcode ) +{ + if ( d->quitnow ) // preserve existing quitcode + return; + d->quitcode = retcode; + d->quitnow = TRUE; + d->exitloop = TRUE; + d->shortcut = TRUE; +} + + +/*! \fn int TQEventLoop::enterLoop() + + This function enters the main event loop (recursively). Do not call + it unless you really know what you are doing. + */ +int TQEventLoop::enterLoop() +{ + // save the current exitloop state + bool old_exitloop = d->exitloop; + d->exitloop = FALSE; + d->shortcut = FALSE; + + d->looplevel++; + while ( ! d->exitloop ) { + processEvents( AllEvents | WaitForMore ); + } + d->looplevel--; + + // restore the exitloop state, but if quitnow is TRUE, we need to keep + // exitloop set so that all other event loops drop out. + d->exitloop = old_exitloop || d->quitnow; + d->shortcut = d->quitnow; + + if ( d->looplevel < 1 ) { + d->quitnow = FALSE; + d->exitloop = FALSE; + d->shortcut = FALSE; + emit tqApp->aboutToQuit(); + + // send deferred deletes + TQApplication::sendPostedEvents( 0, TQEvent::DeferredDelete ); + } + + return d->looplevel; +} + +/*! \fn void TQEventLoop::exitLoop() + + This function exits from a recursive call to the main event loop. + Do not call it unless you really know what you are doing. +*/ +void TQEventLoop::exitLoop() +{ + d->exitloop = TRUE; + d->shortcut = TRUE; +} + +/*! \fn void TQEventLoop::loopLevel() const + + Returns the current loop level. +*/ +int TQEventLoop::loopLevel() const +{ + return d->looplevel; +} + +/*! + Process pending events that match \a flags for a maximum of \a + maxTime milliseconds, or until there are no more events to + process, which ever is shorter. + + This function is especially useful if you have a long running + operation and want to show its progress without allowing user + input, i.e. by using the \c ExcludeUserInput flag. + + NOTE: This function will not process events continuously; it + returns after all available events are processed. + + NOTE: Specifying the \c WaitForMore flag makes no sense and will + be ignored. +*/ +void TQEventLoop::processEvents( ProcessEventsFlags flags, int maxTime ) +{ + TQTime start = TQTime::currentTime(); + TQTime now; + while ( ! d->quitnow && processEvents( flags & ~WaitForMore ) ) { + now = TQTime::currentTime(); + if ( start.msecsTo( now ) > maxTime ) + break; + } +} + +/*! + \fn bool TQEventLoop::processEvents( ProcessEventsFlags flags ) + \overload + + Processes pending events that match \a flags until there are no + more events to process. + + This function is especially useful if you have a long running + operation and want to show its progress without allowing user + input, i.e. by using the \c ExcludeUserInput flag. + + If the \c WaitForMore flag is set in \a flags, the behavior of + this function is as follows: + + \list + + \i If events are available, this function returns after processing + them. + + \i If no events are available, this function will wait until more + are available and return after processing newly available events. + + \endlist + + If the \c WaitForMore flag is \e not set in \a flags, and no + events are available, this function will return immediately. + + NOTE: This function will not process events continuously; it + returns after all available events are processed. + + This function returns TRUE if an event was processed; otherwise it + returns FALSE. + + \sa ProcessEvents hasPendingEvents() +*/ + +/*! \fn bool TQEventLoop::hasPendingEvents() const + + Returns TRUE if there is an event waiting, otherwise it returns FALSE. +*/ + +/*! \fn void TQEventLoop::registerSocketNotifier( TQSocketNotifier *notifier ) + + Registers \a notifier with the event loop. Subclasses need to + reimplement this method to tie a socket notifier into another + event loop. Reimplementations \e MUST call the base + implementation. +*/ + +/*! \fn void TQEventLoop::unregisterSocketNotifier( TQSocketNotifier *notifier ) + + Unregisters \a notifier from the event loop. Subclasses need to + reimplement this method to tie a socket notifier into another + event loop. Reimplementations \e MUST call the base + implementation. +*/ + +/*! \fn void TQEventLoop::setSocketNotifierPending( TQSocketNotifier *notifier ) + + Marks \a notifier as pending. The socket notifier will be + activated the next time activateSocketNotifiers() is called. +*/ + +/*! \fn int TQEventLoop::activateSocketNotifiers() + + Activates all pending socket notifiers and returns the number of + socket notifiers that were activated. +*/ + +/*! \fn int TQEventLoop::activateTimers() + + Activates all TQt timers and returns the number of timers that were + activated. + + TQEventLoop subclasses that do their own timer handling need to + call this after the time returned by timeToWait() has elapsed. + + Note: This function is only useful on systems where \c select() is + used to block the eventloop. On Windows, this function always + returns 0. On MacOS X, this function always returns 0 when the + GUI is enabled. On MacOS X, this function returns the documented + value when the GUI is disabled. +*/ + +/*! \fn int TQEventLoop::timeToWait() const + + Returns the number of milliseconds that TQt needs to handle its + timers or -1 if there are no timers running. + + TQEventLoop subclasses that do their own timer handling need to use + this to make sure that TQt's timers continue to work. + + Note: This function is only useful on systems where \c select() is + used to block the eventloop. On Windows, this function always + returns -1. On MacOS X, this function always returns -1 when the + GUI is enabled. On MacOS X, this function returns the documented + value when the GUI is disabled. +*/ + +/*! \fn void TQEventLoop::wakeUp() + \threadsafe + + Wakes up the event loop. + + \sa awake() +*/ + +/*! \fn void TQEventLoop::awake() + + This signal is emitted after the event loop returns from a + function that could block. + + \sa wakeUp() aboutToBlock() +*/ + +/*! \fn void TQEventLoop::aboutToBlock() + + This signal is emitted before the event loop calls a function that + could block. + + \sa awake() +*/ + +#if !defined(TQ_WS_X11) +void TQEventLoop::appStartingUp(){} +void TQEventLoop::appClosingDown(){} +#endif // TQ_WS_X11 diff --git a/src/kernel/tqeventloop.h b/src/kernel/tqeventloop.h new file mode 100644 index 000000000..32848a53c --- /dev/null +++ b/src/kernel/tqeventloop.h @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Declaration of TQEventLoop class +** +** 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 TQEVENTLOOP_H +#define TQEVENTLOOP_H + +#ifndef QT_H +#include "tqobject.h" +#include "tqsocketnotifier.h" +#endif // QT_H + +#ifdef Q_QDOC +#else // Q_QDOC +#if defined(QT_USE_GLIBMAINLOOP) +#include +#endif // QT_USE_GLIBMAINLOOP +#endif // Q_QDOC + +class TQEventLoopPrivate; +class TQSocketNotifier; +class TQTimer; +#ifdef TQ_WS_MAC +struct timeval; //stdc struct +struct TimerInfo; //internal structure (tqeventloop_mac.cpp) +#endif + +#if defined(TQT_THREAD_SUPPORT) +class TQMutex; +#endif // TQT_THREAD_SUPPORT + + +class TQ_EXPORT TQEventLoop : public TQObject +{ + TQ_OBJECT + +public: + TQEventLoop( TQObject *parent = 0, const char *name = 0 ); + ~TQEventLoop(); + + enum ProcessEvents { + AllEvents = 0x00, + ExcludeUserInput = 0x01, + ExcludeSocketNotifiers = 0x02, + WaitForMore = 0x04 + }; + typedef uint ProcessEventsFlags; + + void processEvents( ProcessEventsFlags flags, int maxtime ); + virtual bool processEvents( ProcessEventsFlags flags ); + + virtual bool hasPendingEvents() const; + + virtual void registerSocketNotifier( TQSocketNotifier * ); + virtual void unregisterSocketNotifier( TQSocketNotifier * ); + void setSocketNotifierPending( TQSocketNotifier * ); + int activateSocketNotifiers(); + + int activateTimers(); + int timeToWait() const; + + virtual int exec(); + virtual void exit( int retcode = 0 ); + + virtual int enterLoop(); + virtual void exitLoop(); + virtual int loopLevel() const; + + virtual void wakeUp(); + + void setSingleToolkitEventHandling(bool enabled); + +signals: + void awake(); + void aboutToBlock(); + +private: +#if defined(TQ_WS_MAC) + friend TQMAC_PASCAL void qt_mac_select_timer_callbk(EventLoopTimerRef, void *); + int macHandleSelect(timeval *); + void macHandleTimer(TimerInfo *); +#endif // TQ_WS_MAC + + // internal initialization/cleanup - implemented in various platform specific files + void init(); + void cleanup(); + virtual void appStartingUp(); + virtual void appClosingDown(); + + // data for the default implementation - other implementations should not + // use/need this data + TQEventLoopPrivate *d; + + friend class TQApplication; + +#ifdef Q_QDOC +#else // Q_QDOC +#if defined(QT_USE_GLIBMAINLOOP) + + // glib main loop support + /* internal: used to fit glib-main-loop gsource concept */ +public: + bool gsourcePrepare(GSource *gs, int * timeout); + bool gsourceCheck(GSource * gs); + bool gsourceDispatch(GSource * gs); + + bool processX11Events(); + + // end glib main loop support + +#endif //QT_USE_GLIBMAINLOOP +#endif // Q_QDOC +}; + +#endif // TQEVENTLOOP_H diff --git a/src/kernel/tqeventloop_glib_p.h b/src/kernel/tqeventloop_glib_p.h new file mode 100644 index 000000000..b9a75241a --- /dev/null +++ b/src/kernel/tqeventloop_glib_p.h @@ -0,0 +1,119 @@ +/** +** TQt->glib main event loop integration by Norbert Frese 2005 +** code based on tqeventloop_p.h 3.3.5 +** +*/ + +/**************************************************************************** +** $Id: qt/tqeventloop_glib_p.h +** +** Definition of TQEventLoop class +** +** Copyright (C) 1992-2005 Trolltech AS. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef TQEVENTLOOP_GLIB_P_H +#define TQEVENTLOOP_GLIB_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. This header file may +// change from version to version without notice, or even be +// removed. +// +// We mean it. +// +// + +#ifndef QT_H +#include "qplatformdefs.h" +#endif // QT_H + +// SCO OpenServer redefines raise -> kill +#if defined(raise) +# undef raise +#endif + +#include "tqeventloop.h" +#include "ntqwindowdefs.h" + +class TQSocketNotifier; + +#include "tqptrlist.h" + +#include + +// uncomment this for main loop related debug-output + +// #define DEBUG_QT_GLIBMAINLOOP 1 + +// Wrapper for TQSocketNotifier Object and GPollFD + +struct TQSockNotGPollFD +{ + TQSocketNotifier *obj; + GPollFD gPollFD; + gushort events; // save events + bool pending; +}; + +class TQEventLoopPrivate +{ +public: + TQEventLoopPrivate(); + ~TQEventLoopPrivate(); + + void reset(); + + int looplevel; + int quitcode; + unsigned int quitnow : 1; + unsigned int exitloop : 1; + unsigned int shortcut : 1; + +#if defined(TQ_WS_X11) + int xfd; + GPollFD x_gPollFD; +#endif // TQ_WS_X11 + + int thread_pipe[2]; + GPollFD threadPipe_gPollFD; + TQPtrList sn_list; + + // pending socket notifiers list + TQPtrList sn_pending_list; + + // store flags for one iteration + uint pev_flags; + + // My GSource + GSource * gSource; + bool singletoolkit; + + // main context + GMainContext *ctx; + GMainLoop *mainloop; + bool ctx_is_default; +}; + +#endif // TQEVENTLOOP_GLIB_P_H diff --git a/src/kernel/tqeventloop_p.h b/src/kernel/tqeventloop_p.h new file mode 100644 index 000000000..f28cf1214 --- /dev/null +++ b/src/kernel/tqeventloop_p.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Definition of TQEventLoop class +** +** 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. +** +** 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 TQEVENTLOOP_P_H +#define TQEVENTLOOP_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. This header file may +// change from version to version without notice, or even be +// removed. +// +// We mean it. +// +// + +#if defined(QT_USE_GLIBMAINLOOP) +#include "tqeventloop_glib_p.h" // use a different header file!!! +#else + +#ifndef QT_H +#include "qplatformdefs.h" +#endif // QT_H + +// SCO OpenServer redefines raise -> kill +#if defined(raise) +# undef raise +#endif + +#include "ntqwindowdefs.h" + +class TQSocketNotifier; +#ifdef Q_OS_MAC +class TQMacSockNotPrivate; +#endif + +#if defined(Q_OS_UNIX) || defined (TQ_WS_WIN) +#include "tqptrlist.h" +#endif // Q_OS_UNIX || TQ_WS_WIN + +#if defined(Q_OS_UNIX) +struct TQSockNot +{ + TQSocketNotifier *obj; + int fd; + fd_set *queue; +}; + +class TQSockNotType +{ +public: + TQSockNotType(); + ~TQSockNotType(); + + TQPtrList *list; + fd_set select_fds; + fd_set enabled_fds; + fd_set pending_fds; + +}; +#endif // Q_OS_UNIX + +#if defined(TQ_WS_WIN) +struct TQSockNot { + TQSocketNotifier *obj; + int fd; +}; +#endif // TQ_WS_WIN + +class TQEventLoopPrivate +{ +public: + TQEventLoopPrivate() + { + reset(); + } + + void reset() { + looplevel = 0; + quitcode = 0; + quitnow = FALSE; + exitloop = FALSE; + shortcut = FALSE; + } + + int looplevel; + int quitcode; + unsigned int quitnow : 1; + unsigned int exitloop : 1; + unsigned int shortcut : 1; + +#if defined(TQ_WS_MAC) + uchar next_select_timer; + EventLoopTimerRef select_timer; +#endif + +#if defined(TQ_WS_X11) + int xfd; +#endif // TQ_WS_X11 + +#if defined(Q_OS_UNIX) + int thread_pipe[2]; + + // pending socket notifiers list + TQPtrList sn_pending_list; + // highest fd for all socket notifiers + int sn_highest; + // 3 socket notifier types - read, write and exception + TQSockNotType sn_vec[3]; +#endif + +#ifdef TQ_WS_WIN + // pending socket notifiers list + TQPtrList sn_pending_list; +#endif // TQ_WS_WIN + +}; + +#endif // !QT_USE_GLIBMAINLOOP + +#endif // TQEVENTLOOP_P_H diff --git a/src/kernel/tqeventloop_unix.cpp b/src/kernel/tqeventloop_unix.cpp new file mode 100644 index 000000000..8ab816426 --- /dev/null +++ b/src/kernel/tqeventloop_unix.cpp @@ -0,0 +1,594 @@ +/**************************************************************************** +** +** Implementation of TQEventLoop class +** +** 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. +** +**********************************************************************/ + +#include "tqeventloop_p.h" // includes qplatformdefs.h +#include "tqeventloop.h" +#include "ntqapplication.h" +#include "tqbitarray.h" +#include "tqmutex.h" +#include +#include + + +/***************************************************************************** + Timer handling; UNIX has no application timer support so we'll have to + make our own from scratch. + + NOTE: These functions are for internal use. TQObject::startTimer() and + TQObject::killTimer() are for public use. + The TQTimer class provides a high-level interface which translates + timer events into signals. + + qStartTimer( interval, obj ) + Starts a timer which will run until it is killed with qKillTimer() + Arguments: + int interval timer interval in milliseconds + TQObject *obj where to send the timer event + Returns: + int timer identifier, or zero if not successful + + qKillTimer( timerId ) + Stops a timer specified by a timer identifier. + Arguments: + int timerId timer identifier + Returns: + bool TRUE if successful + + qKillTimer( obj ) + Stops all timers that are sent to the specified object. + Arguments: + TQObject *obj object receiving timer events + Returns: + bool TRUE if successful + *****************************************************************************/ + +// +// Internal data structure for timers +// + +struct TimerInfo { // internal timer info + int id; // - timer identifier + timeval interval; // - timer interval + timeval timeout; // - when to sent event + TQObject *obj; // - object to receive event +}; + +typedef TQPtrList TimerList; // list of TimerInfo structs + +static TQBitArray *timerBitVec; // timer bit vector +static TimerList *timerList = 0; // timer list + +static void initTimers(); +void cleanupTimers(); +static timeval watchtime; // watch if time is turned back +timeval *qt_wait_timer(); +timeval *qt_wait_timer_max = 0; + +// +// Internal operator functions for timevals +// + +static inline bool operator<( const timeval &t1, const timeval &t2 ) +{ + return t1.tv_sec < t2.tv_sec || + (t1.tv_sec == t2.tv_sec && t1.tv_usec < t2.tv_usec); +} + +static inline bool operator==( const timeval &t1, const timeval &t2 ) +{ + return t1.tv_sec == t2.tv_sec && t1.tv_usec == t2.tv_usec; +} + +static inline timeval &operator+=( timeval &t1, const timeval &t2 ) +{ + t1.tv_sec += t2.tv_sec; + if ( (t1.tv_usec += t2.tv_usec) >= 1000000 ) { + t1.tv_sec++; + t1.tv_usec -= 1000000; + } + return t1; +} + +static inline timeval operator+( const timeval &t1, const timeval &t2 ) +{ + timeval tmp; + tmp.tv_sec = t1.tv_sec + t2.tv_sec; + if ( (tmp.tv_usec = t1.tv_usec + t2.tv_usec) >= 1000000 ) { + tmp.tv_sec++; + tmp.tv_usec -= 1000000; + } + return tmp; +} + +static inline timeval operator-( const timeval &t1, const timeval &t2 ) +{ + timeval tmp; + tmp.tv_sec = t1.tv_sec - t2.tv_sec; + if ( (tmp.tv_usec = t1.tv_usec - t2.tv_usec) < 0 ) { + tmp.tv_sec--; + tmp.tv_usec += 1000000; + } + return tmp; +} + + +// +// Internal functions for manipulating timer data structures. +// The timerBitVec array is used for keeping track of timer identifiers. +// + +static int allocTimerId() // find avail timer identifier +{ + int i = timerBitVec->size()-1; + while ( i >= 0 && (*timerBitVec)[i] ) + i--; + if ( i < 0 ) { + i = timerBitVec->size(); + timerBitVec->resize( 4 * i ); + for( int j=timerBitVec->size()-1; j > i; j-- ) + timerBitVec->clearBit( j ); + } + timerBitVec->setBit( i ); + return i+1; +} + +static void insertTimer( const TimerInfo *ti ) // insert timer info into list +{ + TimerInfo *t = timerList->first(); + int index = 0; +#if defined(QT_DEBUG) + int dangerCount = 0; +#endif + while ( t && t->timeout < ti->timeout ) { // list is sorted by timeout +#if defined(QT_DEBUG) + if ( t->obj == ti->obj ) + dangerCount++; +#endif + t = timerList->next(); + index++; + } + timerList->insert( index, ti ); // inserts sorted +#if defined(QT_DEBUG) + if ( dangerCount > 16 ) + tqDebug( "TQObject: %d timers now exist for object %s::%s", + dangerCount, ti->obj->className(), ti->obj->name() ); +#endif +} + +static inline void getTime( timeval &t ) // get time of day +{ + gettimeofday( &t, 0 ); + while ( t.tv_usec >= 1000000 ) { // NTP-related fix + t.tv_usec -= 1000000; + t.tv_sec++; + } + while ( t.tv_usec < 0 ) { + if ( t.tv_sec > 0 ) { + t.tv_usec += 1000000; + t.tv_sec--; + } else { + t.tv_usec = 0; + break; + } + } +} + +static void repairTimer( const timeval &time ) // repair broken timer +{ + timeval diff = watchtime - time; + TimerInfo *t = timerList->first(); + while ( t ) { // repair all timers + t->timeout = t->timeout - diff; + t = timerList->next(); + } +} + +// +// Timer activation functions (called from the event loop) +// + +/* + Returns the time to wait for the next timer, or null if no timers are + waiting. + + The result is bounded to qt_wait_timer_max if this exists. +*/ + +timeval *qt_wait_timer() +{ + static timeval tm; + bool first = TRUE; + timeval currentTime; + if ( timerList && timerList->count() ) { // there are waiting timers + getTime( currentTime ); + if ( first ) { + if ( currentTime < watchtime ) // clock was turned back + repairTimer( currentTime ); + first = FALSE; + watchtime = currentTime; + } + TimerInfo *t = timerList->first(); // first waiting timer + if ( currentTime < t->timeout ) { // time to wait + tm = t->timeout - currentTime; + } else { + tm.tv_sec = 0; // no time to wait + tm.tv_usec = 0; + } + if ( qt_wait_timer_max && *qt_wait_timer_max < tm ) + tm = *qt_wait_timer_max; + return &tm; + } + if ( qt_wait_timer_max ) { + tm = *qt_wait_timer_max; + return &tm; + } + return 0; // no timers +} + +// Timer initialization +static void initTimers() // initialize timers +{ + timerBitVec = new TQBitArray( 128 ); + TQ_CHECK_PTR( timerBitVec ); + int i = timerBitVec->size(); + while( i-- > 0 ) + timerBitVec->clearBit( i ); + timerList = new TimerList; + TQ_CHECK_PTR( timerList ); + timerList->setAutoDelete( TRUE ); + gettimeofday( &watchtime, 0 ); +} + +// Timer cleanup +void cleanupTimers() +{ + delete timerList; + timerList = 0; + delete timerBitVec; + timerBitVec = 0; +} + +// Main timer functions for starting and killing timers +int qStartTimer( int interval, TQObject *obj ) +{ + if ( !timerList ) // initialize timer data + initTimers(); + int id = allocTimerId(); // get free timer id + if ( id <= 0 || + id > (int)timerBitVec->size() || !obj )// cannot create timer + return 0; + timerBitVec->setBit( id-1 ); // set timer active + TimerInfo *t = new TimerInfo; // create timer + TQ_CHECK_PTR( t ); + t->id = id; + t->interval.tv_sec = interval/1000; + t->interval.tv_usec = (interval%1000)*1000; + timeval currentTime; + getTime( currentTime ); + t->timeout = currentTime + t->interval; + t->obj = obj; + insertTimer( t ); // put timer in list + return id; +} + +bool qKillTimer( int id ) +{ + TimerInfo *t; + if ( !timerList || id <= 0 || + id > (int)timerBitVec->size() || !timerBitVec->testBit( id-1 ) ) + return FALSE; // not init'd or invalid timer + t = timerList->first(); + while ( t && t->id != id ) // find timer info in list + t = timerList->next(); + if ( t ) { // id found + timerBitVec->clearBit( id-1 ); // set timer inactive + return timerList->remove(); + } + else // id not found + return FALSE; +} + +bool qKillTimer( TQObject *obj ) +{ + TimerInfo *t; + if ( !timerList ) // not initialized + return FALSE; + t = timerList->first(); + while ( t ) { // check all timers + if ( t->obj == obj ) { // object found + timerBitVec->clearBit( t->id-1 ); + timerList->remove(); + t = timerList->current(); + } else { + t = timerList->next(); + } + } + return TRUE; +} + +/***************************************************************************** + Socket notifier type + *****************************************************************************/ +TQSockNotType::TQSockNotType() + : list( 0 ) +{ + FD_ZERO( &select_fds ); + FD_ZERO( &enabled_fds ); + FD_ZERO( &pending_fds ); +} + +TQSockNotType::~TQSockNotType() +{ + if ( list ) + delete list; + list = 0; +} + +/***************************************************************************** + TQEventLoop implementations for UNIX + *****************************************************************************/ +void TQEventLoop::registerSocketNotifier( TQSocketNotifier *notifier ) +{ + int sockfd = notifier->socket(); + int type = notifier->type(); + if ( sockfd < 0 || sockfd >= FD_SETSIZE || type < 0 || type > 2 || notifier == 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQSocketNotifier: Internal error" ); +#endif + return; + } + + TQPtrList *list = d->sn_vec[type].list; + fd_set *fds = &d->sn_vec[type].enabled_fds; + TQSockNot *sn; + + if ( ! list ) { + // create new list, the TQSockNotType destructor will delete it for us + list = new TQPtrList; + TQ_CHECK_PTR( list ); + list->setAutoDelete( TRUE ); + d->sn_vec[type].list = list; + } + + sn = new TQSockNot; + TQ_CHECK_PTR( sn ); + sn->obj = notifier; + sn->fd = sockfd; + sn->queue = &d->sn_vec[type].pending_fds; + + if ( list->isEmpty() ) { + list->insert( 0, sn ); + } else { // sort list by fd, decreasing + TQSockNot *p = list->first(); + while ( p && p->fd > sockfd ) + p = list->next(); +#if defined(QT_CHECK_STATE) + if ( p && p->fd == sockfd ) { + static const char *t[] = { "read", "write", "exception" }; + tqWarning( "TQSocketNotifier: Multiple socket notifiers for " + "same socket %d and type %s", sockfd, t[type] ); + } +#endif + if ( p ) + list->insert( list->at(), sn ); + else + list->append( sn ); + } + + FD_SET( sockfd, fds ); + d->sn_highest = TQMAX( d->sn_highest, sockfd ); +} + +void TQEventLoop::unregisterSocketNotifier( TQSocketNotifier *notifier ) +{ + int sockfd = notifier->socket(); + int type = notifier->type(); + if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQSocketNotifier: Internal error" ); +#endif + return; + } + + TQPtrList *list = d->sn_vec[type].list; + fd_set *fds = &d->sn_vec[type].enabled_fds; + TQSockNot *sn; + if ( ! list ) + return; + sn = list->first(); + while ( sn && !(sn->obj == notifier && sn->fd == sockfd) ) + sn = list->next(); + if ( !sn ) // not found + return; + + FD_CLR( sockfd, fds ); // clear fd bit + FD_CLR( sockfd, sn->queue ); + d->sn_pending_list.removeRef( sn ); // remove from activation list + list->remove(); // remove notifier found above + + if ( d->sn_highest == sockfd ) { // find highest fd + d->sn_highest = -1; + for ( int i=0; i<3; i++ ) { + if ( d->sn_vec[i].list && ! d->sn_vec[i].list->isEmpty() ) + d->sn_highest = TQMAX( d->sn_highest, // list is fd-sorted + d->sn_vec[i].list->getFirst()->fd ); + } + } +} + +void TQEventLoop::setSocketNotifierPending( TQSocketNotifier *notifier ) +{ + int sockfd = notifier->socket(); + int type = notifier->type(); + if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQSocketNotifier: Internal error" ); +#endif + return; + } + + TQPtrList *list = d->sn_vec[type].list; + TQSockNot *sn; + if ( ! list ) + return; + sn = list->first(); + while ( sn && !(sn->obj == notifier && sn->fd == sockfd) ) + sn = list->next(); + if ( ! sn ) { // not found + return; + } + + // We choose a random activation order to be more fair under high load. + // If a constant order is used and a peer early in the list can + // saturate the IO, it might grab our attention completely. + // Also, if we're using a straight list, the callback routines may + // delete other entries from the list before those other entries are + // processed. + if ( ! FD_ISSET( sn->fd, sn->queue ) ) { + d->sn_pending_list.insert( (rand() & 0xff) % + (d->sn_pending_list.count()+1), sn ); + FD_SET( sn->fd, sn->queue ); + } +} + +void TQEventLoop::wakeUp() +{ + /* + Apparently, there is not consistency among different operating + systems on how to use FIONREAD. + + FreeBSD, Linux and Solaris all expect the 3rd argument to + ioctl() to be an int, which is normally 32-bit even on 64-bit + machines. + + IRIX, on the other hand, expects a size_t, which is 64-bit on + 64-bit machines. + + So, the solution is to use size_t initialized to zero to make + sure all bits are set to zero, preventing underflow with the + FreeBSD/Linux/Solaris ioctls. + */ + size_t nbytes = 0; + char c = 0; + if ( ::ioctl( d->thread_pipe[0], FIONREAD, (char*)&nbytes ) >= 0 && nbytes == 0 ) { + if (::write( d->thread_pipe[1], &c, 1 ) < 0) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQEventLoop: Internal error (failed thread pipe write)" ); +#endif + } + } +} + +int TQEventLoop::timeToWait() const +{ + timeval *tm = qt_wait_timer(); + if ( ! tm ) // no active timers + return -1; + return (tm->tv_sec*1000) + (tm->tv_usec/1000); +} + +int TQEventLoop::activateTimers() +{ + if ( !timerList || !timerList->count() ) // no timers + return 0; + bool first = TRUE; + timeval currentTime; + int n_act = 0, maxCount = timerList->count(); + TimerInfo *begin = 0; + TimerInfo *t; + + for ( ;; ) { + if ( ! maxCount-- ) + break; + getTime( currentTime ); // get current time + if ( first ) { + if ( currentTime < watchtime ) // clock was turned back + repairTimer( currentTime ); + first = FALSE; + watchtime = currentTime; + } + t = timerList->first(); + if ( !t || currentTime < t->timeout ) // no timer has expired + break; + if ( ! begin ) { + begin = t; + } else if ( begin == t ) { + // avoid sending the same timer multiple times + break; + } else if ( t->interval < begin->interval || t->interval == begin->interval ) { + begin = t; + } + timerList->take(); // unlink from list + t->timeout += t->interval; + if ( t->timeout < currentTime ) + t->timeout = currentTime + t->interval; + insertTimer( t ); // relink timer + if ( t->interval.tv_usec > 0 || t->interval.tv_sec > 0 ) + n_act++; + TQTimerEvent e( t->id ); + TQApplication::sendEvent( t->obj, &e ); // send event + if ( !timerList ) // sendEvent allows other threads to execute, therefore we must check for list existence when it returns! + return 0; + if ( timerList->findRef( begin ) == -1 ) + begin = 0; + } + return n_act; +} + +int TQEventLoop::activateSocketNotifiers() +{ + if ( d->sn_pending_list.isEmpty() ) + return 0; + + // activate entries + int n_act = 0; + TQEvent event( TQEvent::SockAct ); + TQPtrListIterator it( d->sn_pending_list ); + TQSockNot *sn; + while ( (sn=it.current()) ) { + ++it; + d->sn_pending_list.removeRef( sn ); + if ( FD_ISSET(sn->fd, sn->queue) ) { + FD_CLR( sn->fd, sn->queue ); + TQApplication::sendEvent( sn->obj, &event ); + n_act++; + } + } + + return n_act; +} diff --git a/src/kernel/tqeventloop_unix_glib.cpp b/src/kernel/tqeventloop_unix_glib.cpp new file mode 100644 index 000000000..200c9245d --- /dev/null +++ b/src/kernel/tqeventloop_unix_glib.cpp @@ -0,0 +1,750 @@ +/** +** TQt->glib main event loop integration by Norbert Frese 2005 +** code based on tqeventloop_unix.cpp 3.3.5 +** +*/ + +/**************************************************************************** +** $Id: qt/tqeventloop_unix_glib.cpp +** +** Implementation of TQEventLoop class +** +** Copyright (C) 2000-2005 Trolltech AS. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.TQPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for TQPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + + +#include "tqeventloop_glib_p.h" // includes qplatformdefs.h +#include "tqeventloop.h" +#include "ntqapplication.h" +#include "tqbitarray.h" +#include "tqmutex.h" + +#if defined(TQT_THREAD_SUPPORT) + #include "tqthread.h" +#endif + +#include +#include + +#include + +#ifdef TQT_THREAD_SUPPORT +#ifdef QT_USE_GLIBMAINLOOP +extern TQMutex *tqt_timerListMutex; +#endif // QT_USE_GLIBMAINLOOP +#endif // TQT_THREAD_SUPPORT + +/***************************************************************************** + Timer handling; UNIX has no application timer support so we'll have to + make our own from scratch. + + NOTE: These functions are for internal use. TQObject::startTimer() and + TQObject::killTimer() are for public use. + The TQTimer class provides a high-level interface which translates + timer events into signals. + + qStartTimer( interval, obj ) + Starts a timer which will run until it is killed with qKillTimer() + Arguments: + int interval timer interval in milliseconds + TQObject *obj where to send the timer event + Returns: + int timer identifier, or zero if not successful + + qKillTimer( timerId ) + Stops a timer specified by a timer identifier. + Arguments: + int timerId timer identifier + Returns: + bool TRUE if successful + + qKillTimer( obj ) + Stops all timers that are sent to the specified object. + Arguments: + TQObject *obj object receiving timer events + Returns: + bool TRUE if successful + *****************************************************************************/ + +// +// Internal data structure for timers +// + +struct TimerInfo { // internal timer info + int id; // - timer identifier + timeval interval; // - timer interval + timeval timeout; // - when to sent event + TQObject *obj; // - object to receive event +}; + +typedef TQPtrList TimerList; // list of TimerInfo structs + +static TQBitArray *timerBitVec; // timer bit vector +static TimerList *timerList = 0; // timer list + +static void initTimers(); +void cleanupTimers(); +static timeval watchtime; // watch if time is turned back +timeval *qt_wait_timer(); +timeval *qt_wait_timer_max = 0; + +// +// Internal operator functions for timevals +// + +static inline bool operator<( const timeval &t1, const timeval &t2 ) +{ + return (t1.tv_sec < t2.tv_sec) || ((t1.tv_sec == t2.tv_sec) && (t1.tv_usec < t2.tv_usec)); +} + +static inline bool operator==( const timeval &t1, const timeval &t2 ) +{ + return t1.tv_sec == t2.tv_sec && t1.tv_usec == t2.tv_usec; +} + +static inline timeval &operator+=( timeval &t1, const timeval &t2 ) +{ + t1.tv_sec += t2.tv_sec; + if ( (t1.tv_usec += t2.tv_usec) >= 1000000 ) { + t1.tv_sec++; + t1.tv_usec -= 1000000; + } + return t1; +} + +static inline timeval operator+( const timeval &t1, const timeval &t2 ) +{ + timeval tmp; + tmp.tv_sec = t1.tv_sec + t2.tv_sec; + if ( (tmp.tv_usec = t1.tv_usec + t2.tv_usec) >= 1000000 ) { + tmp.tv_sec++; + tmp.tv_usec -= 1000000; + } + return tmp; +} + +static inline timeval operator-( const timeval &t1, const timeval &t2 ) +{ + timeval tmp; + tmp.tv_sec = t1.tv_sec - t2.tv_sec; + if ( (tmp.tv_usec = t1.tv_usec - t2.tv_usec) < 0 ) { + tmp.tv_sec--; + tmp.tv_usec += 1000000; + } + return tmp; +} + + +// +// Internal functions for manipulating timer data structures. +// The timerBitVec array is used for keeping track of timer identifiers. +// + +static int allocTimerId() // find avail timer identifier +{ + int i = timerBitVec->size()-1; + while ( i >= 0 && (*timerBitVec)[i] ) { + i--; + } + if ( i < 0 ) { + i = timerBitVec->size(); + timerBitVec->resize( 4 * i ); + for( int j=timerBitVec->size()-1; j > i; j-- ) { + timerBitVec->clearBit( j ); + } + } + timerBitVec->setBit( i ); + return i+1; +} + +static void insertTimer( const TimerInfo *ti ) // insert timer info into list +{ +#if defined(TQT_THREAD_SUPPORT) + tqt_timerListMutex->lock(); +#endif + TimerInfo *t = timerList->first(); + int index = 0; +#if defined(QT_DEBUG) + int dangerCount = 0; +#endif + while ( t && t->timeout < ti->timeout ) { // list is sorted by timeout +#if defined(QT_DEBUG) + if ( t->obj == ti->obj ) { + dangerCount++; + } +#endif + t = timerList->next(); + index++; + } + timerList->insert( index, ti ); // inserts sorted +#if defined(QT_DEBUG) + if ( dangerCount > 16 ) { + tqDebug( "TQObject: %d timers now exist for object %s::%s", dangerCount, ti->obj->className(), ti->obj->name() ); + } +#endif +#if defined(TQT_THREAD_SUPPORT) + tqt_timerListMutex->unlock(); +#endif +} + +static inline void getTime( timeval &t ) // get time of day +{ + gettimeofday( &t, 0 ); + while ( t.tv_usec >= 1000000 ) { // NTP-related fix + t.tv_usec -= 1000000; + t.tv_sec++; + } + while ( t.tv_usec < 0 ) { + if ( t.tv_sec > 0 ) { + t.tv_usec += 1000000; + t.tv_sec--; + } + else { + t.tv_usec = 0; + break; + } + } +} + +static void repairTimer( const timeval &time ) // repair broken timer +{ +#if defined(TQT_THREAD_SUPPORT) + tqt_timerListMutex->lock(); +#endif + timeval diff = watchtime - time; + TimerInfo *t = timerList->first(); + while ( t ) { // repair all timers + t->timeout = t->timeout - diff; + t = timerList->next(); + } +#if defined(TQT_THREAD_SUPPORT) + tqt_timerListMutex->unlock(); +#endif +} + +// +// Timer activation functions (called from the event loop) +// + +/* + Returns the time to wait for the next timer, or null if no timers are + waiting. + + The result is bounded to qt_wait_timer_max if this exists. +*/ + +timeval *qt_wait_timer() +{ +#if defined(TQT_THREAD_SUPPORT) + tqt_timerListMutex->lock(); +#endif + static timeval tm; + bool first = TRUE; + timeval currentTime; + if ( timerList && timerList->count() ) { // there are waiting timers + getTime( currentTime ); + if ( first ) { + if ( currentTime < watchtime ) { // clock was turned back + repairTimer( currentTime ); + } + first = FALSE; + watchtime = currentTime; + } + TimerInfo *t = timerList->first(); // first waiting timer + if ( currentTime < t->timeout ) { // time to wait + tm = t->timeout - currentTime; + } + else { + tm.tv_sec = 0; // no time to wait + tm.tv_usec = 0; + } + if ( qt_wait_timer_max && *qt_wait_timer_max < tm ) { + tm = *qt_wait_timer_max; + } +#if defined(TQT_THREAD_SUPPORT) + tqt_timerListMutex->unlock(); +#endif + return &tm; + } + if ( qt_wait_timer_max ) { + tm = *qt_wait_timer_max; +#if defined(TQT_THREAD_SUPPORT) + tqt_timerListMutex->unlock(); +#endif + return &tm; + } +#if defined(TQT_THREAD_SUPPORT) + tqt_timerListMutex->unlock(); +#endif + return 0; // no timers +} + +// Timer initialization +static void initTimers() // initialize timers +{ + timerBitVec = new TQBitArray( 128 ); + TQ_CHECK_PTR( timerBitVec ); + int i = timerBitVec->size(); + while( i-- > 0 ) { + timerBitVec->clearBit( i ); + } + timerList = new TimerList; +#if defined(TQT_THREAD_SUPPORT) + tqt_timerListMutex = new TQMutex(true); +#endif + TQ_CHECK_PTR( timerList ); + timerList->setAutoDelete( TRUE ); + gettimeofday( &watchtime, 0 ); +} + +// Timer cleanup +void cleanupTimers() +{ + delete timerList; + timerList = 0; + delete timerBitVec; + timerBitVec = 0; +} + +// Main timer functions for starting and killing timers +int qStartTimer( int interval, TQObject *obj ) +{ +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->lock(); +#endif + if ( !timerList ) { // initialize timer data + initTimers(); +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->lock(); +#endif + } + int id = allocTimerId(); // get free timer id + if ( (id <= 0) || (id > (int)timerBitVec->size()) || (!obj) ) { // cannot create timer +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + return 0; + } + timerBitVec->setBit( id-1 ); // set timer active + TimerInfo *t = new TimerInfo; // create timer + TQ_CHECK_PTR( t ); + t->id = id; + t->interval.tv_sec = interval/1000; + t->interval.tv_usec = (interval%1000)*1000; + timeval currentTime; + getTime( currentTime ); + t->timeout = currentTime + t->interval; + t->obj = obj; + insertTimer( t ); // put timer in list +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + return id; +} + +bool qKillTimer( int id ) +{ +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->lock(); +#endif + TimerInfo *t; + if ( (!timerList) || (id <= 0) || (id > (int)timerBitVec->size()) || (!timerBitVec->testBit( id-1 )) ) { +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + return FALSE; // not init'd or invalid timer + } + t = timerList->first(); + while ( t && t->id != id ) { // find timer info in list + t = timerList->next(); + } + if ( t ) { // id found + bool ret; + timerBitVec->clearBit( id-1 ); // set timer inactive + ret = timerList->remove(); +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + return ret; + } + else { // id not found +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + return FALSE; + } +} + +bool qKillTimer( TQObject *obj ) +{ +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->lock(); +#endif + TimerInfo *t; + if ( !timerList ) { // not initialized +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + return FALSE; + } + t = timerList->first(); + while ( t ) { // check all timers + if ( t->obj == obj ) { // object found + timerBitVec->clearBit( t->id-1 ); + timerList->remove(); + t = timerList->current(); + } + else { + t = timerList->next(); + } + } +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + return TRUE; +} + + +TQEventLoopPrivate::TQEventLoopPrivate() { +#if defined(TQ_WS_X11) + xfd = -1; + x_gPollFD.fd = -1; + x_gPollFD.events = 0; + x_gPollFD.revents = 0; +#endif // TQ_WS_X11 + gSource = nullptr; + singletoolkit = TRUE; + ctx = nullptr; + mainloop = nullptr; + ctx_is_default = false; + reset(); +} + +TQEventLoopPrivate::~TQEventLoopPrivate() { + // +} + +void TQEventLoopPrivate::reset() { + looplevel = 0; + quitcode = 0; + quitnow = FALSE; + exitloop = FALSE; + shortcut = FALSE; +} + + +/***************************************************************************** + TQEventLoop implementations for Glib-Main-Loop + *****************************************************************************/ + + + + +void TQEventLoop::registerSocketNotifier( TQSocketNotifier *notifier ) +{ + int sockfd = notifier->socket(); + int type = notifier->type(); + if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQSocketNotifier: Internal error" ); +#endif + return; + } + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("register socket notifier %d\n", sockfd); +#endif + + TQPtrList *list = &d->sn_list; + TQSockNotGPollFD *sn; + + /* + if ( ! list ) { + // create new list, the TQSockNotType destructor will delete it for us + list = new TQPtrList; + TQ_CHECK_PTR( list ); + list->setAutoDelete( TRUE ); + d->sn_list = list; + } + */ + + gushort events=0; + switch (type) { + case 0: + events = G_IO_IN | G_IO_HUP; + break; + case 1: + events = G_IO_OUT; + break; + case 2: + events = G_IO_PRI | G_IO_ERR | G_IO_NVAL; + break; + } + + sn = new TQSockNotGPollFD; + TQ_CHECK_PTR( sn ); + sn->obj = notifier; + sn->gPollFD.fd = sockfd; + sn->gPollFD.events = events; + sn->events = events; // save events! + sn->pending = FALSE; + + list->append( sn ); + + g_source_add_poll(d->gSource, &sn->gPollFD); + +} + +void TQEventLoop::unregisterSocketNotifier( TQSocketNotifier *notifier ) +{ + int sockfd = notifier->socket(); + int type = notifier->type(); + if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQSocketNotifier: Internal error" ); +#endif + return; + } + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("unregister socket notifier %d\n", sockfd); +#endif + + TQPtrList *list = &d->sn_list; + TQSockNotGPollFD *sn; + if ( ! list ) { + return; + } + sn = list->first(); + while ( sn && !(sn->obj == notifier) ) { + sn = list->next(); + } + if ( !sn ) { // not found + return; + } + + d->sn_pending_list.removeRef( sn ); + list->remove(); // remove notifier found above + g_source_remove_poll(d->gSource, &sn->gPollFD); + + delete sn; // we don't autodelete - lets do it manually + +} + +void TQEventLoop::setSocketNotifierPending( TQSocketNotifier *notifier ) +{ + int sockfd = notifier->socket(); + int type = notifier->type(); + if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQSocketNotifier: Internal error" ); +#endif + return; + } + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("set socket notifier pending %d\n", sockfd); +#endif + + TQPtrList *list = &d->sn_list; + TQSockNotGPollFD *sn; + if ( ! list ) + return; + sn = list->first(); + while ( sn && !(sn->obj == notifier) ) + sn = list->next(); + if ( ! sn ) { // not found + return; + } + + // We choose a random activation order to be more fair under high load. + // If a constant order is used and a peer early in the list can + // saturate the IO, it might grab our attention completely. + // Also, if we're using a straight list, the callback routines may + // delete other entries from the list before those other entries are + // processed. + if ( !sn->pending ) { + d->sn_pending_list.insert( (rand() & 0xff) % + (d->sn_pending_list.count()+1), sn ); + sn->pending = TRUE; // add it only once! + } +} + +void TQEventLoop::wakeUp() +{ + /* + Apparently, there is not consistency among different operating + systems on how to use FIONREAD. + + FreeBSD, Linux and Solaris all expect the 3rd argument to + ioctl() to be an int, which is normally 32-bit even on 64-bit + machines. + + IRIX, on the other hand, expects a size_t, which is 64-bit on + 64-bit machines. + + So, the solution is to use size_t initialized to zero to make + sure all bits are set to zero, preventing underflow with the + FreeBSD/Linux/Solaris ioctls. + */ + size_t nbytes = 0; + char c = 0; + if ( ::ioctl( d->thread_pipe[0], FIONREAD, (char*)&nbytes ) >= 0 && nbytes == 0 ) { + if (::write( d->thread_pipe[1], &c, 1 ) < 0) { + // Failed! + } + } +} + +int TQEventLoop::timeToWait() const +{ + timeval *tm = qt_wait_timer(); + if ( !tm ) { // no active timers + return -1; + } + return (tm->tv_sec*1000) + (tm->tv_usec/1000); +} + +int TQEventLoop::activateTimers() +{ +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->lock(); +#endif + if ( !timerList || !timerList->count() ) { // no timers +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + return 0; + } + bool first = TRUE; + timeval currentTime; + int n_act = 0, maxCount = timerList->count(); + TimerInfo *begin = 0; + TimerInfo *t; + + for ( ;; ) { + if ( ! maxCount-- ) { + break; + } + getTime( currentTime ); // get current time + if ( first ) { + if ( currentTime < watchtime ) { // clock was turned back + repairTimer( currentTime ); + } + first = FALSE; + watchtime = currentTime; + } + t = timerList->first(); + if ( !t || currentTime < t->timeout ) { // no timer has expired + break; + } + if ( ! begin ) { + begin = t; + } + else if ( begin == t ) { + // avoid sending the same timer multiple times + break; + } + else if ( t->interval < begin->interval || t->interval == begin->interval ) { + begin = t; + } + timerList->take(); // unlink from list + t->timeout += t->interval; + if ( t->timeout < currentTime ) { + t->timeout = currentTime + t->interval; + } + insertTimer( t ); // relink timer + if ( t->interval.tv_usec > 0 || t->interval.tv_sec > 0 ) { + n_act++; + } +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + TQTimerEvent e( t->id ); +#if defined(TQT_THREAD_SUPPORT) + // Be careful...the current thread may not be the target object's thread! + if ((!t->obj) || + (TQThread::currentThreadObject() && TQThread::currentThreadObject()->threadPostedEventsDisabled()) || + (t->obj && t->obj->contextThreadObject() == TQThread::currentThreadObject())) { + TQApplication::sendEvent( t->obj, &e ); // send event + } + else { + TQApplication::postEvent( t->obj, new TQTimerEvent(e) ); // post event to correct thread + } +#else // defined(TQT_THREAD_SUPPORT) + TQApplication::sendEvent( t->obj, &e ); // send event +#endif // defined(TQT_THREAD_SUPPORT) +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->lock(); +#endif + if ( timerList->findRef( begin ) == -1 ) { + begin = 0; + } + } +#if defined(TQT_THREAD_SUPPORT) + if (tqt_timerListMutex) tqt_timerListMutex->unlock(); +#endif + return n_act; +} + +int TQEventLoop::activateSocketNotifiers() +{ + if ( d->sn_pending_list.isEmpty() ) { + return 0; + } + + // activate entries + int n_act = 0; + TQEvent event( TQEvent::SockAct ); + TQPtrListIterator it( d->sn_pending_list ); + TQSockNotGPollFD *sn; + while ( (sn=it.current()) ) { + ++it; + d->sn_pending_list.removeRef( sn ); + if ( sn->pending ) { +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("activate sn : send event fd=%d\n", sn->gPollFD.fd ); +#endif + sn->pending = FALSE; +#if defined(TQT_THREAD_SUPPORT) + // Be careful...the current thread may not be the target object's thread! + if ((!sn->obj) || + (TQThread::currentThreadObject() && TQThread::currentThreadObject()->threadPostedEventsDisabled()) || + (sn->obj && sn->obj->contextThreadObject() == TQThread::currentThreadObject())) { + TQApplication::sendEvent( sn->obj, &event ); // send event + } + else { + TQApplication::postEvent( sn->obj, new TQEvent(event) ); // post event to correct thread + } +#else // defined(TQT_THREAD_SUPPORT) + TQApplication::sendEvent( sn->obj, &event ); // send event +#endif // defined(TQT_THREAD_SUPPORT) + n_act++; + } + } + + return n_act; +} diff --git a/src/kernel/tqeventloop_x11.cpp b/src/kernel/tqeventloop_x11.cpp new file mode 100644 index 000000000..b90ce7456 --- /dev/null +++ b/src/kernel/tqeventloop_x11.cpp @@ -0,0 +1,425 @@ +/**************************************************************************** +** +** Implementation of TQEventLoop class +** +** 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. +** +**********************************************************************/ + +#include "tqeventloop_p.h" // includes qplatformdefs.h +#include "tqeventloop.h" +#include "ntqapplication.h" +#include "tqbitarray.h" +#include "tqcolor_p.h" +#include "qt_x11_p.h" + +#if defined(TQT_THREAD_SUPPORT) +# include "tqmutex.h" +#endif // TQT_THREAD_SUPPORT + +#include + + +// resolve the conflict between X11's FocusIn and TQEvent::FocusIn +#undef FocusOut +#undef FocusIn + +static const int XKeyPress = KeyPress; +static const int XKeyRelease = KeyRelease; +#undef KeyPress +#undef KeyRelease + +// from qapplication.cpp +extern bool tqt_is_gui_used; + +// from tqeventloop_unix.cpp +extern timeval *qt_wait_timer(); +extern void cleanupTimers(); + +// ### this needs to go away at some point... +typedef void (*VFPTR)(); +typedef TQValueList TQVFuncList; +void qt_install_preselect_handler( VFPTR ); +void qt_remove_preselect_handler( VFPTR ); +static TQVFuncList *qt_preselect_handler = 0; +void qt_install_postselect_handler( VFPTR ); +void qt_remove_postselect_handler( VFPTR ); +static TQVFuncList *qt_postselect_handler = 0; + +void qt_install_preselect_handler( VFPTR handler ) +{ + if ( !qt_preselect_handler ) + qt_preselect_handler = new TQVFuncList; + qt_preselect_handler->append( handler ); +} +void qt_remove_preselect_handler( VFPTR handler ) +{ + if ( qt_preselect_handler ) { + TQVFuncList::Iterator it = qt_preselect_handler->find( handler ); + if ( it != qt_preselect_handler->end() ) + qt_preselect_handler->remove( it ); + } +} +void qt_install_postselect_handler( VFPTR handler ) +{ + if ( !qt_postselect_handler ) + qt_postselect_handler = new TQVFuncList; + qt_postselect_handler->prepend( handler ); +} +void qt_remove_postselect_handler( VFPTR handler ) +{ + if ( qt_postselect_handler ) { + TQVFuncList::Iterator it = qt_postselect_handler->find( handler ); + if ( it != qt_postselect_handler->end() ) + qt_postselect_handler->remove( it ); + } +} + + +void TQEventLoop::init() +{ + // initialize the common parts of the event loop + pipe( d->thread_pipe ); + fcntl(d->thread_pipe[0], F_SETFD, FD_CLOEXEC); + fcntl(d->thread_pipe[1], F_SETFD, FD_CLOEXEC); + + d->sn_highest = -1; + + // intitialize the X11 parts of the event loop + d->xfd = -1; + if ( tqt_is_gui_used ) + d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() ); +} + +void TQEventLoop::cleanup() +{ + // cleanup the common parts of the event loop + close( d->thread_pipe[0] ); + close( d->thread_pipe[1] ); + cleanupTimers(); + + // cleanup the X11 parts of the event loop + d->xfd = -1; +} + +bool TQEventLoop::processEvents( ProcessEventsFlags flags ) +{ + // process events from the X server + XEvent event; + int nevents = 0; + +#if defined(TQT_THREAD_SUPPORT) + TQMutexLocker locker( TQApplication::tqt_mutex ); +#endif + + // handle gui and posted events + if ( tqt_is_gui_used ) { + TQApplication::sendPostedEvents(); + + if (TQApplication::isGuiThread()) { + // Two loops so that posted events accumulate + while ( XPending( TQPaintDevice::x11AppDisplay() ) ) { + // also flushes output buffer + while ( XPending( TQPaintDevice::x11AppDisplay() ) ) { + if ( d->shortcut ) { + return FALSE; + } + + XNextEvent( TQPaintDevice::x11AppDisplay(), &event ); + + if ( flags & ExcludeUserInput ) { + switch ( event.type ) { + case ButtonPress: + case ButtonRelease: + case MotionNotify: + case XKeyPress: + case XKeyRelease: + case EnterNotify: + case LeaveNotify: + continue; + + case ClientMessage: + { + // from qapplication_x11.cpp + extern Atom tqt_wm_protocols; + extern Atom tqt_wm_take_focus; + extern Atom qt_qt_scrolldone; + + // only keep the wm_take_focus and + // qt_qt_scrolldone protocols, discard all + // other client messages + if ( event.xclient.format != 32 ) + continue; + + if ( event.xclient.message_type == tqt_wm_protocols || + (Atom) event.xclient.data.l[0] == tqt_wm_take_focus ) + break; + if ( event.xclient.message_type == qt_qt_scrolldone ) + break; + } + + default: break; + } + } + + nevents++; + if ( tqApp->x11ProcessEvent( &event ) == 1 ) + return TRUE; + } + } + } + } + + if ( d->shortcut ) { + return FALSE; + } + + TQApplication::sendPostedEvents(); + + const uint exclude_all = ExcludeSocketNotifiers | 0x08; + // 0x08 == ExcludeTimers for X11 only + if ( nevents > 0 && ( flags & exclude_all ) == exclude_all && + ( flags & WaitForMore ) ) { + return TRUE; + } + + // don't block if exitLoop() or exit()/quit() has been called. + bool canWait = d->exitloop || d->quitnow ? FALSE : (flags & WaitForMore); + + // Process timers and socket notifiers - the common UNIX stuff + + // return the maximum time we can wait for an event. + static timeval zerotm; + timeval *tm = 0; + if ( ! ( flags & 0x08 ) ) { // 0x08 == ExcludeTimers for X11 only + tm = qt_wait_timer(); // wait for timer or X event + if ( !canWait ) { + if ( !tm ) + tm = &zerotm; + tm->tv_sec = 0; // no time to wait + tm->tv_usec = 0; + } + } + + int highest = 0; + if ( ! ( flags & ExcludeSocketNotifiers ) ) { + // return the highest fd we can wait for input on + if ( d->sn_highest >= 0 ) { // has socket notifier(s) + if ( d->sn_vec[0].list && ! d->sn_vec[0].list->isEmpty() ) + d->sn_vec[0].select_fds = d->sn_vec[0].enabled_fds; + else + FD_ZERO( &d->sn_vec[0].select_fds ); + + if ( d->sn_vec[1].list && ! d->sn_vec[1].list->isEmpty() ) + d->sn_vec[1].select_fds = d->sn_vec[1].enabled_fds; + else + FD_ZERO( &d->sn_vec[1].select_fds ); + + if ( d->sn_vec[2].list && ! d->sn_vec[2].list->isEmpty() ) + d->sn_vec[2].select_fds = d->sn_vec[2].enabled_fds; + else + FD_ZERO( &d->sn_vec[2].select_fds ); + } else { + FD_ZERO( &d->sn_vec[0].select_fds ); + + FD_ZERO( &d->sn_vec[1].select_fds ); + FD_ZERO( &d->sn_vec[2].select_fds ); + } + + highest = d->sn_highest; + } else { + FD_ZERO( &d->sn_vec[0].select_fds ); + FD_ZERO( &d->sn_vec[1].select_fds ); + FD_ZERO( &d->sn_vec[2].select_fds ); + } + + if ( tqt_is_gui_used && TQApplication::isGuiThread() ) { + // select for events on the event socket - only on X11 + FD_SET( d->xfd, &d->sn_vec[0].select_fds ); + highest = TQMAX( highest, d->xfd ); + } + + FD_SET( d->thread_pipe[0], &d->sn_vec[0].select_fds ); + highest = TQMAX( highest, d->thread_pipe[0] ); + + if ( canWait ) + emit aboutToBlock(); + + if ( qt_preselect_handler ) { + TQVFuncList::Iterator it, end = qt_preselect_handler->end(); + for ( it = qt_preselect_handler->begin(); it != end; ++it ) + (**it)(); + } + + // unlock the GUI mutex and select. when we return from this function, there is + // something for us to do +#if defined(TQT_THREAD_SUPPORT) + if ( locker.mutex() ) locker.mutex()->unlock(); + else return false; +#endif + + int nsel; + do { + nsel = select( highest + 1, + &d->sn_vec[0].select_fds, + &d->sn_vec[1].select_fds, + &d->sn_vec[2].select_fds, + tm ); + } while (nsel == -1 && (errno == EINTR || errno == EAGAIN)); + + // relock the GUI mutex before processing any pending events +#if defined(TQT_THREAD_SUPPORT) + if ( locker.mutex() ) locker.mutex()->lock(); + else return false; +#endif + + // we are awake, broadcast it + emit awake(); + emit tqApp->guiThreadAwake(); + + if (nsel == -1) { + if (errno == EBADF) { + // it seems a socket notifier has a bad fd... find out + // which one it is and disable it + fd_set fdset; + zerotm.tv_sec = zerotm.tv_usec = 0l; + + for (int type = 0; type < 3; ++type) { + TQPtrList *list = d->sn_vec[type].list; + if (!list) continue; + + TQSockNot *sn = list->first(); + while (sn) { + FD_ZERO(&fdset); + FD_SET(sn->fd, &fdset); + + int ret = -1; + do { + switch (type) { + case 0: // read + ret = select(sn->fd + 1, &fdset, 0, 0, &zerotm); + break; + case 1: // write + ret = select(sn->fd + 1, 0, &fdset, 0, &zerotm); + break; + case 2: // except + ret = select(sn->fd + 1, 0, 0, &fdset, &zerotm); + break; + } + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); + + if (ret == -1 && errno == EBADF) { + // disable the invalid socket notifier + static const char *t[] = { "Read", "Write", "Exception" }; + tqWarning("TQSocketNotifier: invalid socket %d and type '%s', disabling...", + sn->fd, t[type]); + sn->obj->setEnabled(FALSE); + } + + sn = list->next(); + } + } + } else { + // EINVAL... shouldn't happen, so let's complain to stderr + // and hope someone sends us a bug report + perror( "select" ); + } + } + + // some other thread woke us up... consume the data on the thread pipe so that + // select doesn't immediately return next time + if ( nsel > 0 && FD_ISSET( d->thread_pipe[0], &d->sn_vec[0].select_fds ) ) { + char c; + ::read( d->thread_pipe[0], &c, 1 ); + } + + if ( qt_postselect_handler ) { + TQVFuncList::Iterator it, end = qt_postselect_handler->end(); + for ( it = qt_postselect_handler->begin(); it != end; ++it ) + (**it)(); + } + + // activate socket notifiers + if ( ! ( flags & ExcludeSocketNotifiers ) && nsel > 0 && d->sn_highest >= 0 ) { + // if select says data is ready on any socket, then set the socket notifier + // to pending + int i; + for ( i=0; i<3; i++ ) { + if ( ! d->sn_vec[i].list ) + continue; + + TQPtrList *list = d->sn_vec[i].list; + TQSockNot *sn = list->first(); + while ( sn ) { + if ( FD_ISSET( sn->fd, &d->sn_vec[i].select_fds ) ) + setSocketNotifierPending( sn->obj ); + sn = list->next(); + } + } + + nevents += activateSocketNotifiers(); + } + + // activate timers + if ( ! ( flags & 0x08 ) ) { + // 0x08 == ExcludeTimers for X11 only + nevents += activateTimers(); + } + + // color approx. optimization - only on X11 + qt_reset_color_avail(); + + // return true if we handled events, false otherwise + return (nevents > 0); +} + +bool TQEventLoop::hasPendingEvents() const +{ + extern uint qGlobalPostedEventsCount(); // from qapplication.cpp + return ( qGlobalPostedEventsCount() || XPending( TQPaintDevice::x11AppDisplay() ) ); +} + +void TQEventLoop::appStartingUp() +{ + if ( tqt_is_gui_used ) + d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() ); +} + +void TQEventLoop::appClosingDown() +{ + d->xfd = -1; +} + +void TQEventLoop::setSingleToolkitEventHandling(bool enabled) { + // Do nothing +} diff --git a/src/kernel/tqeventloop_x11_glib.cpp b/src/kernel/tqeventloop_x11_glib.cpp new file mode 100644 index 000000000..f16fa1017 --- /dev/null +++ b/src/kernel/tqeventloop_x11_glib.cpp @@ -0,0 +1,684 @@ +/** +** TQt->glib main event loop integration by Norbert Frese 2005 +** code based on tqeventloop_x11.cpp 3.3.5 +** +*/ + +/**************************************************************************** +** $Id: qt/tqeventloop_x11_glib.cpp +** +** Implementation of TQEventLoop class +** +** Copyright (C) 2000-2005 Trolltech AS. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.TQPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition +** licenses for Unix/X11 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 +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for TQPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "tqeventloop_glib_p.h" // includes qplatformdefs.h +#include "tqeventloop.h" +#include "ntqapplication.h" +#include "tqbitarray.h" +#include "tqcolor_p.h" +#include "qt_x11_p.h" + +#if defined(TQT_THREAD_SUPPORT) +# include "tqmutex.h" +# include "tqthread.h" +#endif // TQT_THREAD_SUPPORT + +#include + +#include +#include + +// #define DEBUG_QT_GLIBMAINLOOP 1 + +// TQt-GSource Structure and Callbacks + +typedef struct { + GSource source; + TQEventLoop * tqeventLoop; +} TQtGSource; + +static gboolean qt_gsource_prepare ( GSource *source, gint *timeout ); +static gboolean qt_gsource_check ( GSource *source ); +static gboolean qt_gsource_dispatch ( GSource *source, GSourceFunc callback, gpointer user_data ); + +static GSourceFuncs qt_gsource_funcs = { + qt_gsource_prepare, + qt_gsource_check, + qt_gsource_dispatch, + NULL, + NULL, + NULL +}; + +// forward main loop callbacks to TQEventLoop methods! + +static gboolean qt_gsource_prepare ( GSource *source, gint *timeout ) +{ + TQtGSource * qtGSource = (TQtGSource*) source; + TQEventLoop* candidateEventLoop = qtGSource->tqeventLoop; + TQEventLoop* activeThreadEventLoop = TQApplication::eventLoop(); + + if (candidateEventLoop == activeThreadEventLoop) { + return candidateEventLoop->gsourcePrepare(source, timeout); + } + else { + // Prepare failed + return FALSE; + } +} + +static gboolean qt_gsource_check ( GSource *source ) +{ + TQtGSource * qtGSource = (TQtGSource*) source; + TQEventLoop* candidateEventLoop = qtGSource->tqeventLoop; + TQEventLoop* activeThreadEventLoop = TQApplication::eventLoop(); + + if (candidateEventLoop == activeThreadEventLoop) { + return candidateEventLoop->gsourceCheck(source); + } + else { + // Check failed + return FALSE; + } +} + +static gboolean qt_gsource_dispatch ( GSource *source, GSourceFunc callback, gpointer user_data ) +{ + Q_UNUSED(callback); + Q_UNUSED(user_data); + + TQtGSource * qtGSource = (TQtGSource*) source; + TQEventLoop* candidateEventLoop = qtGSource->tqeventLoop; + TQEventLoop* activeThreadEventLoop = TQApplication::eventLoop(); + + if (candidateEventLoop == activeThreadEventLoop) { + return candidateEventLoop->gsourceDispatch(source); + } + else { + // Dispatch failed + return FALSE; + } +} + + +// ------------------------------------------------- + +// resolve the conflict between X11's FocusIn and TQEvent::FocusIn +#undef FocusOut +#undef FocusIn + +static const int XKeyPress = KeyPress; +static const int XKeyRelease = KeyRelease; +#undef KeyPress +#undef KeyRelease + +// from qapplication.cpp +extern bool tqt_is_gui_used; + +// from tqeventloop_unix.cpp +extern timeval *qt_wait_timer(); +extern void cleanupTimers(); + +// ### this needs to go away at some point... +typedef void (*VFPTR)(); +typedef TQValueList TQVFuncList; +void qt_install_preselect_handler( VFPTR ); +void qt_remove_preselect_handler( VFPTR ); +static TQVFuncList *qt_preselect_handler = 0; +void qt_install_postselect_handler( VFPTR ); +void qt_remove_postselect_handler( VFPTR ); +static TQVFuncList *qt_postselect_handler = 0; + +void qt_install_preselect_handler( VFPTR handler ) +{ + if ( !qt_preselect_handler ) { + qt_preselect_handler = new TQVFuncList; + } + qt_preselect_handler->append( handler ); +} + +void qt_remove_preselect_handler( VFPTR handler ) +{ + if ( qt_preselect_handler ) { + TQVFuncList::Iterator it = qt_preselect_handler->find( handler ); + if ( it != qt_preselect_handler->end() ) { + qt_preselect_handler->remove( it ); + } + } +} + +void qt_install_postselect_handler( VFPTR handler ) +{ + if ( !qt_postselect_handler ) { + qt_postselect_handler = new TQVFuncList; + } + qt_postselect_handler->prepend( handler ); +} + +void qt_remove_postselect_handler( VFPTR handler ) +{ + if ( qt_postselect_handler ) { + TQVFuncList::Iterator it = qt_postselect_handler->find( handler ); + if ( it != qt_postselect_handler->end() ) { + qt_postselect_handler->remove( it ); + } + } +} + +void TQEventLoop::init() +{ + // initialize ProcessEventFlags (all events & wait for more) + d->pev_flags = AllEvents | WaitForMore; + + // initialize the common parts of the event loop + if (pipe( d->thread_pipe ) < 0) { + // Error! + } + fcntl(d->thread_pipe[0], F_SETFD, FD_CLOEXEC); + fcntl(d->thread_pipe[1], F_SETFD, FD_CLOEXEC); + + // intitialize the X11 parts of the event loop + d->xfd = -1; + if ( tqt_is_gui_used && TQApplication::isGuiThread() ) { + d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() ); + } + + // new main context for thread + d->ctx = g_main_context_new(); + g_main_context_push_thread_default(d->ctx); + d->ctx_is_default = true; + + // new GSource + TQtGSource * qtGSource = (TQtGSource*) g_source_new(&qt_gsource_funcs, sizeof(TQtGSource)); + g_source_set_can_recurse ((GSource*)qtGSource, TRUE); + qtGSource->tqeventLoop = this; + + // init main loop and attach gsource +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside init(1)\n"); +#endif + + d->mainloop = g_main_loop_new (d->ctx, 1); + g_source_attach( (GSource*)qtGSource, d->ctx ); + d->gSource = (GSource*)qtGSource; + + // poll for X11 events + if ( tqt_is_gui_used && TQApplication::isGuiThread() ) { + d->x_gPollFD.fd = d->xfd; + d->x_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR; + g_source_add_poll(d->gSource, &d->x_gPollFD); + } + + // poll thread-pipe + d->threadPipe_gPollFD.fd = d->thread_pipe[0]; + d->threadPipe_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR; + + g_source_add_poll(d->gSource, &d->threadPipe_gPollFD); + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside init(2)\n"); +#endif +} + +void TQEventLoop::cleanup() +{ + // cleanup the common parts of the event loop + close( d->thread_pipe[0] ); + close( d->thread_pipe[1] ); + cleanupTimers(); + + // cleanup the X11 parts of the event loop + d->xfd = -1; + + // stop polling the GSource + g_source_remove_poll(d->gSource, &d->threadPipe_gPollFD); + g_source_remove_poll(d->gSource, &d->x_gPollFD); + g_source_destroy(d->gSource); + + // unref the main loop + g_main_loop_unref(d->mainloop); + d->mainloop = nullptr; + + // unref the gsource + g_source_unref(d->gSource); + d->gSource = nullptr; + + // unref the main context + g_main_context_unref(d->ctx); + d->ctx = nullptr; +} + +bool TQEventLoop::processEvents( ProcessEventsFlags flags ) +{ +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside processEvents(1) looplevel=%d eventloop=%p d->ctx=%p this=%p\n", d->looplevel, TQApplication::eventLoop(), d->ctx, this ); fflush(stdout); +#endif + + ProcessEventsFlags save_flags; + int rval; + save_flags = d->pev_flags; + + d->pev_flags = flags; + + rval = g_main_context_iteration(d->ctx, flags & WaitForMore ? TRUE : FALSE); + + d->pev_flags = save_flags; + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside processEvents(2) looplevel=%d eventloop=%p d->ctx=%p this=%p rval=%d\n", d->looplevel, TQApplication::eventLoop(), d->ctx, this, rval ); fflush(stdout); +#endif + + return rval; // were events processed? +} + + +bool TQEventLoop::processX11Events() +{ + ProcessEventsFlags flags = d->pev_flags; + // process events from the X server + XEvent event; + int nevents = 0; + +#if defined(TQT_THREAD_SUPPORT) + TQMutexLocker locker( TQApplication::tqt_mutex ); +#endif + + // handle gui and posted events + if ( tqt_is_gui_used ) { + TQApplication::sendPostedEvents(); + + if (TQApplication::isGuiThread()) { + // Two loops so that posted events accumulate + while ( XPending( TQPaintDevice::x11AppDisplay() ) ) { + // also flushes output buffer + while ( XPending( TQPaintDevice::x11AppDisplay() ) ) { + if ( d->shortcut ) { + return FALSE; + } + + XNextEvent( TQPaintDevice::x11AppDisplay(), &event ); + + if ( flags & ExcludeUserInput ) { + switch ( event.type ) { + case ButtonPress: + case ButtonRelease: + case MotionNotify: + case XKeyPress: + case XKeyRelease: + case EnterNotify: + case LeaveNotify: + continue; + + case ClientMessage: + { + // from qapplication_x11.cpp + extern Atom tqt_wm_protocols; + extern Atom tqt_wm_take_focus; + extern Atom qt_qt_scrolldone; + + // only keep the wm_take_focus and + // qt_qt_scrolldone protocols, discard all + // other client messages + if ( event.xclient.format != 32 ) + continue; + + if ( event.xclient.message_type == tqt_wm_protocols || + (Atom) event.xclient.data.l[0] == tqt_wm_take_focus ) + break; + if ( event.xclient.message_type == qt_qt_scrolldone ) + break; + } + + default: break; + } + } + + nevents++; + if ( tqApp->x11ProcessEvent( &event ) == 1 ) { + return TRUE; + } + } + } + } + } + + if ( d->shortcut ) { + return FALSE; + } + + TQApplication::sendPostedEvents(); + + const uint exclude_all = ExcludeSocketNotifiers | 0x08; + // 0x08 == ExcludeTimers for X11 only + if ( nevents > 0 && ( flags & exclude_all ) == exclude_all && ( flags & WaitForMore ) ) { + return TRUE; + } + return FALSE; +} + + +bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout) +{ + Q_UNUSED(gs); + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourcePrepare(1)\n"); +#endif + + ProcessEventsFlags flags = d->pev_flags; + +#if defined(TQT_THREAD_SUPPORT) + TQMutexLocker locker( TQApplication::tqt_mutex ); +#endif + + // don't block if exitLoop() or exit()/quit() has been called. + bool canWait = d->exitloop || d->quitnow ? FALSE : (flags & WaitForMore); + + // Process timers and socket notifiers - the common UNIX stuff + + // return the maximum time we can wait for an event. + static timeval zerotm; + timeval *tm = 0; + if ( ! ( flags & 0x08 ) ) { // 0x08 == ExcludeTimers for X11 only + tm = qt_wait_timer(); // wait for timer or X event + if ( !canWait ) { + if ( !tm ) { + tm = &zerotm; + } + tm->tv_sec = 0; // no time to wait + tm->tv_usec = 0; + } + } + + // include or exclude SocketNotifiers (by setting or cleaning poll events) + if ( ! ( flags & ExcludeSocketNotifiers ) ) { + TQPtrListIterator it( d->sn_list ); + TQSockNotGPollFD *sn; + while ( (sn=it.current()) ) { + ++it; + sn->gPollFD.events = sn->events; // restore poll events + } + } + else { + TQPtrListIterator it( d->sn_list ); + TQSockNotGPollFD *sn; + while ( (sn=it.current()) ) { + ++it; + sn->gPollFD.events = 0; // delete poll events + } + } + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourcePrepare(2) canwait=%d\n", canWait); +#endif + + if ( canWait ) { + emit aboutToBlock(); + } + + if ( qt_preselect_handler ) { + TQVFuncList::Iterator it, end = qt_preselect_handler->end(); + for ( it = qt_preselect_handler->begin(); it != end; ++it ) + (**it)(); + } + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourcePrepare(2.1) canwait=%d\n", canWait); +#endif + + // do we have to dispatch events? + if (hasPendingEvents()) { + *timeout = 0; // no time to stay in poll +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourcePrepare(3a)\n"); +#endif + return FALSE; + } + + // stay in poll until something happens? + if (!tm) { // fixme + *timeout = -1; // wait forever +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourcePrepare(3b) timeout=%d \n", *timeout); +#endif + return FALSE; + } + + // else timeout >=0 + *timeout = tm->tv_sec * 1000 + tm->tv_usec/1000; + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourcePrepare(3c) timeout=%d \n", *timeout); +#endif + + return FALSE; +} + + +bool TQEventLoop::gsourceCheck(GSource *gs) { + Q_UNUSED(gs); + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourceCheck(1)\n"); +#endif + + // Socketnotifier events? + TQPtrList *list = &d->sn_list; + //if ( list ) { + TQSockNotGPollFD *sn = list->first(); + while ( sn ) { + if ( sn->gPollFD.revents ) { + return TRUE; + } + sn = list->next(); + } + //} + + if (d->x_gPollFD.revents) { +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourceCheck(2) xfd!\n"); +#endif + + return TRUE; // we got events! + } + if (d->threadPipe_gPollFD.revents) { +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourceCheck(2) threadpipe!!\n"); +#endif + + return TRUE; // we got events! + } + if (hasPendingEvents()) { +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourceCheck(2) pendingEvents!\n"); +#endif + + return TRUE; // we got more X11 events! + } + + // check if we have timers to activate? + timeval * tm = qt_wait_timer(); + if (tm && (tm->tv_sec == 0 && tm->tv_usec == 0 )) { +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourceCheck(2) qtwaittimer!\n"); +#endif + + return TRUE; + } + + // nothing to dispatch +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourceCheck(2) nothing to dispatch!\n"); +#endif + + return FALSE; +} + + +bool TQEventLoop::gsourceDispatch(GSource *gs) { + Q_UNUSED(gs); + + // relock the GUI mutex before processing any pending events +#if defined(TQT_THREAD_SUPPORT) + TQMutexLocker locker( TQApplication::tqt_mutex ); +#endif +#if defined(TQT_THREAD_SUPPORT) + if (locker.mutex()) locker.mutex()->lock(); +#endif + + int nevents=0; + ProcessEventsFlags flags = d->pev_flags; + +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourceDispatch(1)\n"); +#endif + + // we are awake, broadcast it + emit awake(); + emit tqApp->guiThreadAwake(); + + // some other thread woke us up... consume the data on the thread pipe so that + // select doesn't immediately return next time + + if ( d->threadPipe_gPollFD.revents) { + char c; + if (::read( d->thread_pipe[0], &c, 1 ) < 0) { + // Error! + } + } + + if ( qt_postselect_handler ) { + TQVFuncList::Iterator it, end = qt_postselect_handler->end(); + for ( it = qt_postselect_handler->begin(); it != end; ++it ) + (**it)(); + } + + // activate socket notifiers + if ( ! ( flags & ExcludeSocketNotifiers )) { + // if select says data is ready on any socket, then set the socket notifier + // to pending + // if ( &d->sn_list ) { + TQPtrList *list = &d->sn_list; + TQSockNotGPollFD *sn = list->first(); + while ( sn ) { + if ( sn->gPollFD.revents ) + setSocketNotifierPending( sn->obj ); + sn = list->next(); + } + // } + + if (TQApplication::isGuiThread()) { + nevents += activateSocketNotifiers(); + } + } + + // activate timers + if ( ! ( flags & 0x08 ) ) { + // 0x08 == ExcludeTimers for X11 only + if (TQApplication::isGuiThread()) { + nevents += activateTimers(); + } + } + + // return true if we handled events, false otherwise + //return (nevents > 0); + + // now process x11 events! +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("inside gsourceDispatch(2) hasPendingEvents=%d\n", hasPendingEvents()); +#endif + + if (hasPendingEvents()) { + // color approx. optimization - only on X11 + qt_reset_color_avail(); + +#if defined(TQT_THREAD_SUPPORT) + if (locker.mutex()) locker.mutex()->unlock(); +#endif + processX11Events(); + } + else { +#if defined(TQT_THREAD_SUPPORT) + if (locker.mutex()) locker.mutex()->unlock(); +#endif + } + + if (d->singletoolkit) { + return TRUE; // Eat the event + } + else { + return FALSE; // Pass the event on to GTK + } +} + +bool TQEventLoop::hasPendingEvents() const +{ +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( TQApplication::tqt_mutex ); +#endif // TQT_THREAD_SUPPORT + + extern uint qGlobalPostedEventsCount(); // from qapplication.cpp + return ( qGlobalPostedEventsCount() || ( (tqt_is_gui_used && TQApplication::isGuiThread()) ? XPending( TQPaintDevice::x11AppDisplay() ) : 0)); +} + +void TQEventLoop::appStartingUp() +{ + if ( tqt_is_gui_used ) { + d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() ); + if ( (d->x_gPollFD.fd == -1) && TQApplication::isGuiThread() ) { + d->x_gPollFD.fd = d->xfd; + d->x_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR; + g_source_add_poll(d->gSource, &d->x_gPollFD); + } + } +} + +void TQEventLoop::appClosingDown() +{ + d->xfd = -1; +} + +void TQEventLoop::setSingleToolkitEventHandling(bool enabled) { + d->singletoolkit = enabled; + + if (!d->singletoolkit) { + if (d->ctx_is_default) { + d->ctx_is_default = false; + g_main_context_pop_thread_default(d->ctx); + } + } + else { + if (!d->ctx_is_default) { + g_main_context_push_thread_default(d->ctx); + d->ctx_is_default = true; + } + } +} diff --git a/src/kernel/tqfontengine_x11.cpp b/src/kernel/tqfontengine_x11.cpp index 6363aac97..8002c42df 100644 --- a/src/kernel/tqfontengine_x11.cpp +++ b/src/kernel/tqfontengine_x11.cpp @@ -2264,6 +2264,8 @@ struct OTScripts { int flags; }; +// Refer to https://learn.microsoft.com/en-us/typography/opentype/spec/scripttags +// for OpenType language tags definition static const OTScripts ot_scripts [] = { // // European Alphabetic Scripts // Latin, @@ -2351,6 +2353,7 @@ static const OTScripts ot_scripts [] = { { FT_MAKE_TAG( 'c', 'a', 'n', 's' ), 0 }, // Mongolian, { FT_MAKE_TAG( 'm', 'o', 'n', 'g' ), 0 }, + // // Symbols // CurrencySymbols, { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, @@ -2370,13 +2373,26 @@ static const OTScripts ot_scripts [] = { { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, // Braille, { FT_MAKE_TAG( 'b', 'r', 'a', 'i' ), 0 }, -// Unicode, should be used - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 } - // ### where are these? -// { FT_MAKE_TAG( 'b', 'y', 'z', 'm' ), 0 }, -// { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, - // ### Hangul Jamo -// { FT_MAKE_TAG( 'j', 'a', 'm', 'o' ), 0 }, + +// Unicode + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, + +// Tagalog, + { FT_MAKE_TAG( 't', 'g', 'l', 'g' ), 0 }, +// Hanunoo, + { FT_MAKE_TAG( 'h', 'a', 'n', 'o' ), 0 }, +// Buhid, + { FT_MAKE_TAG( 'b', 'u', 'h', 'd' ), 0 }, +// Tagbanwa, + { FT_MAKE_TAG( 't', 'a', 'g', 'b' ), 0 }, + +// KatakanaHalfWidth, -- can't find it, use Katakana code + { FT_MAKE_TAG( 'k', 'a', 'n', 'a' ), 0 }, + +// Limbu, + { FT_MAKE_TAG( 'l', 'i', 'm', 'b' ), 0 }, +// TaiLe, + { FT_MAKE_TAG( 't', 'a', 'l', 'e' ), 0 } }; TQOpenType::TQOpenType(TQFontEngineXft *fe) @@ -2435,7 +2451,10 @@ TQOpenType::~TQOpenType() bool TQOpenType::checkScript(unsigned int script) { - assert(script < TQFont::NScripts); + if (script >= TQFont::NScripts || script >= sizeof(ot_scripts) / sizeof(OTScripts)) + { + return false; + } uint tag = ot_scripts[script].tag; int requirements = ot_scripts[script].flags; @@ -2477,7 +2496,11 @@ void TQOpenType::selectScript(unsigned int script, const Features *features) if (current_script == script) return; - assert(script < TQFont::NScripts); + if (script >= TQFont::NScripts || script >= sizeof(ot_scripts) / sizeof(OTScripts)) + { + return; + } + // find script in our list of supported scripts. uint tag = ot_scripts[script].tag; diff --git a/src/kernel/tqobject.h b/src/kernel/tqobject.h index cc67ba551..3ee1c6c19 100644 --- a/src/kernel/tqobject.h +++ b/src/kernel/tqobject.h @@ -45,7 +45,7 @@ #include "tqobjectdefs.h" #include "ntqwindowdefs.h" #include "tqstring.h" -#include "ntqevent.h" +#include "tqevent.h" #include "tqmutex.h" #include "ntqnamespace.h" #endif // QT_H diff --git a/src/kernel/tqsocketnotifier.cpp b/src/kernel/tqsocketnotifier.cpp index 1a6390893..b350403a5 100644 --- a/src/kernel/tqsocketnotifier.cpp +++ b/src/kernel/tqsocketnotifier.cpp @@ -40,8 +40,8 @@ #include "tqsocketnotifier.h" #include "ntqapplication.h" -#include "ntqevent.h" -#include "ntqeventloop.h" +#include "tqevent.h" +#include "tqeventloop.h" #include "qplatformdefs.h" #if defined(Q_OS_UNIX) diff --git a/src/kernel/tqthread.cpp b/src/kernel/tqthread.cpp index 27b2071ea..560577589 100644 --- a/src/kernel/tqthread.cpp +++ b/src/kernel/tqthread.cpp @@ -41,7 +41,7 @@ #include "qplatformdefs.h" #include "tqthread.h" -#include "ntqeventloop.h" +#include "tqeventloop.h" #include #ifndef QT_H diff --git a/src/kernel/tqtranslator.cpp b/src/kernel/tqtranslator.cpp new file mode 100644 index 000000000..f67c6d363 --- /dev/null +++ b/src/kernel/tqtranslator.cpp @@ -0,0 +1,1478 @@ +/**************************************************************************** +** +** Localization database support. +** +** Created : 980906 +** +** Copyright (C) 1998-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 "qplatformdefs.h" + +// POSIX Large File Support redefines open -> open64 +static inline int qt_open(const char *pathname, int flags, mode_t mode) +{ return ::open(pathname, flags, mode); } +#if defined(open) +# undef open +#endif + +// POSIX Large File Support redefines truncate -> truncate64 +#if defined(truncate) +# undef truncate +#endif + +#include "tqtranslator.h" + +#ifndef TQT_NO_TRANSLATION + +#include "tqfileinfo.h" +#include "tqwidgetlist.h" +#include "tqintdict.h" +#include "tqstring.h" +#include "ntqapplication.h" +#include "tqfile.h" +#include "tqbuffer.h" +#include "tqdatastream.h" +#include "tqmap.h" +#include "ntqtl.h" + +#if defined(Q_OS_UNIX) +#define QT_USE_MMAP +#endif + +// most of the headers below are already included in qplatformdefs.h +// also this lacks Large File support but that's probably irrelevant +#if defined(QT_USE_MMAP) +// for mmap +#include +#include +#include +#include +#include +// for htonl +#include +#endif + +#include + +/* +$ mcookie +3cb86418caef9c95cd211cbf60a1bddd +$ +*/ + +// magic number for the file +static const int MagicLength = 16; +static const uchar magic[MagicLength] = { + 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95, + 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd +}; + +static bool match( const char* found, const char* target ) +{ + // 0 means anything, "" means empty + return found == 0 || qstrcmp( found, target ) == 0; +} + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +/* + Yes, unfortunately, we have code here that depends on endianness. + The candidate is big endian (it comes from a .qm file) whereas the + target endianness depends on the system TQt is running on. +*/ +#ifdef Q_OS_TEMP +static int __cdecl cmp_uint32_little( const void* target, const void* candidate ) +#else +static int cmp_uint32_little( const void* target, const void* candidate ) +#endif +{ + const uchar* t = (const uchar*) target; + const uchar* c = (const uchar*) candidate; + return t[3] != c[0] ? (int) t[3] - (int) c[0] + : t[2] != c[1] ? (int) t[2] - (int) c[1] + : t[1] != c[2] ? (int) t[1] - (int) c[2] + : (int) t[0] - (int) c[3]; +} + +#ifdef Q_OS_TEMP +static int __cdecl cmp_uint32_big( const void* target, const void* candidate ) +#else +static int cmp_uint32_big( const void* target, const void* candidate ) +#endif +{ + const uchar* t = (const uchar*) target; + const uchar* c = (const uchar*) candidate; + return t[0] != c[0] ? (int) t[0] - (int) c[0] + : t[1] != c[1] ? (int) t[1] - (int) c[1] + : t[2] != c[2] ? (int) t[2] - (int) c[2] + : (int) t[3] - (int) c[3]; +} + +#if defined(Q_C_CALLBACKS) +} +#endif + +static int systemWordSize = 0; +static bool systemBigEndian; + +static uint elfHash( const char * name ) +{ + const uchar *k; + uint h = 0; + uint g; + + if ( name ) { + k = (const uchar *) name; + while ( *k ) { + h = ( h << 4 ) + *k++; + if ( (g = (h & 0xf0000000)) != 0 ) + h ^= g >> 24; + h &= ~g; + } + } + if ( !h ) + h = 1; + return h; +} + +extern bool qt_detectRTLLanguage(); + +class TQTranslatorPrivate { +public: + struct Offset { + Offset() + : h( 0 ), o( 0 ) { } + Offset( const TQTranslatorMessage& m, int offset ) + : h( m.hash() ), o( offset ) { } + + bool operator<( const Offset&k ) const { + return ( h != k.h ) ? h < k.h : o < k.o; + } + TQ_DUMMY_COMPARISON_OPERATOR(TQTranslatorPrivate::Offset) + uint h; + uint o; + }; + + enum { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69 }; + + TQTranslatorPrivate() : + unmapPointer( 0 ), unmapLength( 0 ), + messageArray( 0 ), offsetArray( 0 ), contextArray( 0 ) +#ifndef TQT_NO_TRANSLATION_BUILDER + , messages( 0 ) +#endif + { } + // TQTranslator must finalize this before deallocating it + + // for mmap'ed files, this is what needs to be unmapped. + char * unmapPointer; + unsigned int unmapLength; + + // for squeezed but non-file data, this is what needs to be deleted + TQByteArray * messageArray; + TQByteArray * offsetArray; + TQByteArray * contextArray; + +#ifndef TQT_NO_TRANSLATION_BUILDER + TQMap * messages; +#endif +#ifdef TQ_WS_WIN + int oldPermissionLookup; +#endif +}; + + +/*! + \class TQTranslator + + \brief The TQTranslator class provides internationalization support for text + output. + + \ingroup i18n + \ingroup environment + \mainclass + + An object of this class contains a set of TQTranslatorMessage + objects, each of which specifies a translation from a source + language to a target language. TQTranslator provides functions to + look up translations, add new ones, remove them, load and save + them, etc. + + The most common use of TQTranslator is to: load a translator file + created with \link linguist-manual.book TQt Linguist\endlink, + install it using TQApplication::installTranslator(), and use it via + TQObject::tr(). For example: + + \code + int main( int argc, char ** argv ) + { + TQApplication app( argc, argv ); + + TQTranslator translator( 0 ); + translator.load( "french.qm", "." ); + app.installTranslator( &translator ); + + MyWidget m; + app.setMainWidget( &m ); + m.show(); + + return app.exec(); + } + \endcode + Note that the translator must be created \e before the + application's main window. + + Most applications will never need to do anything else with this + class. The other functions provided by this class are useful for + applications that work on translator files. + + We call a translation a "messsage". For this reason, translation + files are sometimes referred to as "message files". + + It is possible to lookup a translation using findMessage() (as + tr() and TQApplication::translate() do) and contains(), to insert a + new translation messsage using insert(), and to remove one using + remove(). + + Translation tools often need more information than the bare source + text and translation, for example, context information to help + the translator. But end-user programs that are using translations + usually only need lookup. To cater for these different needs, + TQTranslator can use stripped translator files that use the minimum + of memory and which support little more functionality than + findMessage(). + + Thus, load() may not load enough information to make anything more + than findMessage() work. save() has an argument indicating + whether to save just this minimum of information or to save + everything. + + "Everything" means that for each translation item the following + information is kept: + + \list + \i The \e {translated text} - the return value from tr(). + \i The input key: + \list + \i The \e {source text} - usually the argument to tr(). + \i The \e context - usually the class name for the tr() caller. + \i The \e comment - a comment that helps disambiguate different uses + of the same text in the same context. + \endlist + \endlist + + The minimum for each item is just the information necessary for + findMessage() to return the right text. This may include the + source, context and comment, but usually it is just a hash value + and the translated text. + + For example, the "Cancel" in a dialog might have "Anuluj" when the + program runs in Polish (in this case the source text would be + "Cancel"). The context would (normally) be the dialog's class + name; there would normally be no comment, and the translated text + would be "Anuluj". + + But it's not always so simple. The Spanish version of a printer + dialog with settings for two-sided printing and binding would + probably require both "Activado" and "Activada" as translations + for "Enabled". In this case the source text would be "Enabled" in + both cases, and the context would be the dialog's class name, but + the two items would have disambiguating comments such as + "two-sided printing" for one and "binding" for the other. The + comment enables the translator to choose the appropriate gender + for the Spanish version, and enables TQt to distinguish between + translations. + + Note that when TQTranslator loads a stripped file, most functions + do not work. The functions that do work with stripped files are + explicitly documented as such. + + \sa TQTranslatorMessage TQApplication::installTranslator() + TQApplication::removeTranslator() TQObject::tr() TQApplication::translate() +*/ + +/*! + \enum TQTranslator::SaveMode + + This enum type defines how TQTranslator writes translation + files. There are two modes: + + \value Everything files are saved with all available information + \value Stripped files are saved with just enough information for + end-user applications + + Note that when TQTranslator loads a stripped file, most functions do + not work. The functions that do work with stripped files are + explicitly documented as such. +*/ + +#if defined(TQ_WS_WIN) +extern int qt_ntfs_permission_lookup; +#endif + +/*! + Constructs an empty message file object that is not connected to + any file. The object is called \a name with parent \a parent. +*/ + +TQTranslator::TQTranslator( TQObject * parent, const char * name ) + : TQObject( parent, name ) +{ + d = new TQTranslatorPrivate; +#if defined(TQ_WS_WIN) + d->oldPermissionLookup = qt_ntfs_permission_lookup; +#endif +} + + +/*! + Destroys the object and frees any allocated resources. +*/ + +TQTranslator::~TQTranslator() +{ + if ( tqApp ) + tqApp->removeTranslator( this ); + clear(); + delete d; +} + + +extern bool qt_detectRTLLanguage(); + +/*! + Loads \a filename, which may be an absolute file name or relative + to \a directory. The previous contents of this translator object + is discarded. Returns TRUE if the file is loaded successfully; + otherwise returns FALSE. + + If the full file name does not exist, other file names are tried + in the following order: + + \list 1 + \i File name with \a suffix appended (".qm" if the \a suffix is + TQString::null). + \i File name with text after a character in \a search_delimiters + stripped ("_." is the default for \a search_delimiters if it is + TQString::null). + \i File name stripped and \a suffix appended. + \i File name stripped further, etc. + \endlist + + For example, an application running in the fr_CA locale + (French-speaking Canada) might call load("foo.fr_ca", + "/opt/foolib"). load() would then try to open the first existing + readable file from this list: + + \list 1 + \i /opt/foolib/foo.fr_ca + \i /opt/foolib/foo.fr_ca.qm + \i /opt/foolib/foo.fr + \i /opt/foolib/foo.fr.qm + \i /opt/foolib/foo + \i /opt/foolib/foo.qm + \endlist + + \sa save() +*/ + +bool TQTranslator::load( const TQString & filename, const TQString & directory, + const TQString & search_delimiters, + const TQString & suffix ) +{ + clear(); + + TQString prefix; + + if ( filename[0] == '/' +#ifdef TQ_WS_WIN + || (filename[0] && filename[1] == ':') || filename[0] == '\\' +#endif + ) + prefix = TQString::fromLatin1( "" ); + else + prefix = directory; + + if ( prefix.length() ) { + if ( prefix[int(prefix.length()-1)] != '/' ) + prefix += TQChar( '/' ); + } + + TQString fname = filename; + TQString realname; + TQString delims; + delims = search_delimiters.isNull() ? + TQString::fromLatin1( "_." ) : search_delimiters; + +#if defined(TQ_WS_WIN) + qt_ntfs_permission_lookup--; +#endif + for ( ;; ) { + TQFileInfo fi; + + realname = prefix + fname; + fi.setFile( realname ); + if ( fi.isReadable() ) + break; + + realname += suffix.isNull() ? TQString::fromLatin1( ".qm" ) : suffix; + fi.setFile( realname ); + if ( fi.isReadable() ) + break; + + int rightmost = 0; + for ( int i = 0; i < (int)delims.length(); i++ ) { + int k = fname.findRev( delims[i] ); + if ( k > rightmost ) + rightmost = k; + } + + // no truncations? fail + if ( rightmost == 0 ) { +#if defined(TQ_WS_WIN) + if (d->oldPermissionLookup != qt_ntfs_permission_lookup) + qt_ntfs_permission_lookup++; +#endif + return FALSE; + } + + fname.truncate( rightmost ); + } +#if defined(TQ_WS_WIN) + if (d->oldPermissionLookup != qt_ntfs_permission_lookup) + qt_ntfs_permission_lookup++; +#endif + + // realname is now the fully qualified name of a readable file. + +#if defined(QT_USE_MMAP) + +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif +#ifndef MAP_FAILED +#define MAP_FAILED -1 +#endif + + int f; + + f = qt_open( TQFile::encodeName(realname), O_RDONLY, 0666 ); + if ( f < 0 ) { + // tqDebug( "can't open %s: %s", realname.ascii(), strerror( errno ) ); + return FALSE; + } + + struct stat st; + if ( fstat( f, &st ) ) { + // tqDebug( "can't stat %s: %s", realname.ascii(), strerror( errno ) ); + return FALSE; + } + char * tmp; + tmp = (char*)mmap( 0, st.st_size, // any address, whole file + PROT_READ, // read-only memory + MAP_FILE | MAP_PRIVATE, // swap-backed map from file + f, 0 ); // from offset 0 of f + if ( !tmp || tmp == (char*)MAP_FAILED ) { + // tqDebug( "can't mmap %s: %s", filename.ascii(), strerror( errno ) ); + return FALSE; + } + + ::close( f ); + + d->unmapPointer = tmp; + d->unmapLength = st.st_size; +#else + TQFile f( realname ); + if ( !f.exists() ) + return FALSE; + d->unmapLength = f.size(); + d->unmapPointer = new char[d->unmapLength]; + bool ok = FALSE; + if ( f.open(IO_ReadOnly) ) { + ok = d->unmapLength == + (uint)f.readBlock( d->unmapPointer, d->unmapLength ); + f.close(); + } + if ( !ok ) { + delete [] d->unmapPointer; + d->unmapPointer = 0; + return FALSE; + } +#endif + + return do_load( (const uchar *) d->unmapPointer, d->unmapLength ); +} + +/*! + \overload + \fn bool TQTranslator::load( const uchar *data, int len ) + + Loads the .qm file data \a data of length \a len into the + translator. Returns TRUE if the data is loaded successfully; + otherwise returns FALSE. + + The data is not copied. The caller must be able to guarantee that \a data + will not be deleted or modified. +*/ + +bool TQTranslator::do_load( const uchar *data, int len ) +{ + if ( len < MagicLength || memcmp( data, magic, MagicLength ) != 0 ) { + clear(); + return FALSE; + } + + TQByteArray array; + array.setRawData( (const char *) data, len ); + TQDataStream s( array, IO_ReadOnly ); + bool ok = TRUE; + + s.device()->at( MagicLength ); + + TQ_UINT8 tag = 0; + TQ_UINT32 blockLen = 0; + s >> tag >> blockLen; + while ( tag && blockLen ) { + if ( (TQ_UINT32) s.device()->at() + blockLen > (TQ_UINT32) len ) { + ok = FALSE; + break; + } + + if ( tag == TQTranslatorPrivate::Contexts && !d->contextArray ) { + d->contextArray = new TQByteArray; + d->contextArray->setRawData( array.data() + s.device()->at(), + blockLen ); + } else if ( tag == TQTranslatorPrivate::Hashes && !d->offsetArray ) { + d->offsetArray = new TQByteArray; + d->offsetArray->setRawData( array.data() + s.device()->at(), + blockLen ); + } else if ( tag == TQTranslatorPrivate::Messages && !d->messageArray ) { + d->messageArray = new TQByteArray; + d->messageArray->setRawData( array.data() + s.device()->at(), + blockLen ); + } + + if ( !s.device()->at(s.device()->at() + blockLen) ) { + ok = FALSE; + break; + } + tag = 0; + blockLen = 0; + if ( !s.atEnd() ) + s >> tag >> blockLen; + } + array.resetRawData( (const char *) data, len ); + + if ( tqApp && tqApp->translators && tqApp->translators->contains(this) ) + tqApp->setReverseLayout( qt_detectRTLLanguage() ); + return ok; +} + +#ifndef TQT_NO_TRANSLATION_BUILDER + +/*! + Saves this message file to \a filename, overwriting the previous + contents of \a filename. If \a mode is \c Everything (the + default), all the information is preserved. If \a mode is \c + Stripped, any information that is not necessary for findMessage() + is stripped away. + + \sa load() +*/ + +bool TQTranslator::save( const TQString & filename, SaveMode mode ) +{ + TQFile f( filename ); + if ( f.open( IO_WriteOnly ) ) { + squeeze( mode ); + + TQDataStream s( &f ); + s.writeRawBytes( (const char *)magic, MagicLength ); + TQ_UINT8 tag; + + if ( d->offsetArray != 0 ) { + tag = (TQ_UINT8) TQTranslatorPrivate::Hashes; + TQ_UINT32 oas = (TQ_UINT32) d->offsetArray->size(); + s << tag << oas; + s.writeRawBytes( d->offsetArray->data(), oas ); + } + if ( d->messageArray != 0 ) { + tag = (TQ_UINT8) TQTranslatorPrivate::Messages; + TQ_UINT32 mas = (TQ_UINT32) d->messageArray->size(); + s << tag << mas; + s.writeRawBytes( d->messageArray->data(), mas ); + } + if ( d->contextArray != 0 ) { + tag = (TQ_UINT8) TQTranslatorPrivate::Contexts; + TQ_UINT32 cas = (TQ_UINT32) d->contextArray->size(); + s << tag << cas; + s.writeRawBytes( d->contextArray->data(), cas ); + } + return TRUE; + } + return FALSE; +} + +#endif + +/*! + Empties this translator of all contents. + + This function works with stripped translator files. +*/ + +void TQTranslator::clear() +{ + if ( d->unmapPointer && d->unmapLength ) { +#if defined(QT_USE_MMAP) + munmap( d->unmapPointer, d->unmapLength ); +#else + delete [] d->unmapPointer; +#endif + d->unmapPointer = 0; + d->unmapLength = 0; + } + + if ( d->messageArray ) { + d->messageArray->resetRawData( d->messageArray->data(), + d->messageArray->size() ); + delete d->messageArray; + d->messageArray = 0; + } + if ( d->offsetArray ) { + d->offsetArray->resetRawData( d->offsetArray->data(), + d->offsetArray->size() ); + delete d->offsetArray; + d->offsetArray = 0; + } + if ( d->contextArray ) { + d->contextArray->resetRawData( d->contextArray->data(), + d->contextArray->size() ); + delete d->contextArray; + d->contextArray = 0; + } +#ifndef TQT_NO_TRANSLATION_BUILDER + delete d->messages; + d->messages = 0; +#endif + + if ( tqApp ) { + tqApp->setReverseLayout( qt_detectRTLLanguage() ); + + TQWidgetList *list = TQApplication::topLevelWidgets(); + TQWidgetListIt it( *list ); + TQWidget *w; + while ( ( w=it.current() ) != 0 ) { + ++it; + if (!w->isDesktop()) + tqApp->postEvent( w, new TQEvent( TQEvent::LanguageChange ) ); + } + delete list; + } +} + +#ifndef TQT_NO_TRANSLATION_BUILDER + +/*! + Converts this message file to the compact format used to store + message files on disk. + + You should never need to call this directly; save() and other + functions call it as necessary. \a mode is for internal use. + + \sa save() unsqueeze() +*/ + +void TQTranslator::squeeze( SaveMode mode ) +{ + if ( !d->messages ) { + if ( mode == Stripped ) + unsqueeze(); + else + return; + } + + TQMap * messages = d->messages; + + d->messages = 0; + clear(); + + d->messageArray = new TQByteArray; + d->offsetArray = new TQByteArray; + + TQMap offsets; + + TQDataStream ms( *d->messageArray, IO_WriteOnly ); + TQMap::Iterator it = messages->begin(), next; + int cpPrev = 0, cpNext = 0; + for ( it = messages->begin(); it != messages->end(); ++it ) { + cpPrev = cpNext; + next = it; + ++next; + if ( next == messages->end() ) + cpNext = 0; + else + cpNext = (int) it.key().commonPrefix( next.key() ); + offsets.replace( TQTranslatorPrivate::Offset(it.key(), + ms.device()->at()), (void*)0 ); + it.key().write( ms, mode == Stripped, + (TQTranslatorMessage::Prefix) TQMAX(cpPrev, cpNext + 1) ); + } + + d->offsetArray->resize( 0 ); + TQMap::Iterator offset; + offset = offsets.begin(); + TQDataStream ds( *d->offsetArray, IO_WriteOnly ); + while ( offset != offsets.end() ) { + TQTranslatorPrivate::Offset k = offset.key(); + ++offset; + ds << (TQ_UINT32)k.h << (TQ_UINT32)k.o; + } + + if ( mode == Stripped ) { + TQAsciiDict contextSet( 1511 ); + int baudelaire; + + for ( it = messages->begin(); it != messages->end(); ++it ) + contextSet.replace( it.key().context(), &baudelaire ); + + TQ_UINT16 hTableSize; + if ( contextSet.count() < 200 ) + hTableSize = ( contextSet.count() < 60 ) ? 151 : 503; + else if ( contextSet.count() < 2500 ) + hTableSize = ( contextSet.count() < 750 ) ? 1511 : 5003; + else + hTableSize = 15013; + + TQIntDict hDict( hTableSize ); + TQAsciiDictIterator c = contextSet; + while ( c.current() != 0 ) { + hDict.insert( (long) (elfHash(c.currentKey()) % hTableSize), + c.currentKey() ); + ++c; + } + + /* + The contexts found in this translator are stored in a hash + table to provide fast lookup. The context array has the + following format: + + TQ_UINT16 hTableSize; + TQ_UINT16 hTable[hTableSize]; + TQ_UINT8 contextPool[...]; + + The context pool stores the contexts as Pascal strings: + + TQ_UINT8 len; + TQ_UINT8 data[len]; + + Let's consider the look-up of context "FunnyDialog". A + hash value between 0 and hTableSize - 1 is computed, say h. + If hTable[h] is 0, "FunnyDialog" is not covered by this + translator. Else, we check in the contextPool at offset + 2 * hTable[h] to see if "FunnyDialog" is one of the + contexts stored there, until we find it or we meet the + empty string. + */ + d->contextArray = new TQByteArray; + d->contextArray->resize( 2 + (hTableSize << 1) ); + TQDataStream t( *d->contextArray, IO_WriteOnly ); + TQ_UINT16 *hTable = new TQ_UINT16[hTableSize]; + memset( hTable, 0, hTableSize * sizeof(TQ_UINT16) ); + + t << hTableSize; + t.device()->at( 2 + (hTableSize << 1) ); + t << (TQ_UINT16) 0; // the entry at offset 0 cannot be used + uint upto = 2; + + for ( int i = 0; i < hTableSize; i++ ) { + const char *con = hDict.find( i ); + if ( con == 0 ) { + hTable[i] = 0; + } else { + hTable[i] = (TQ_UINT16) ( upto >> 1 ); + do { + uint len = (uint) tqstrlen( con ); + len = TQMIN( len, 255 ); + t << (TQ_UINT8) len; + t.writeRawBytes( con, len ); + upto += 1 + len; + hDict.remove( i ); + } while ( (con = hDict.find(i)) != 0 ); + do { + t << (TQ_UINT8) 0; // empty string (at least one) + upto++; + } while ( (upto & 0x1) != 0 ); // offsets have to be even + } + } + t.device()->at( 2 ); + for ( int j = 0; j < hTableSize; j++ ) + t << hTable[j]; + delete [] hTable; + + if ( upto > 131072 ) { + tqWarning( "TQTranslator::squeeze: Too many contexts" ); + delete d->contextArray; + d->contextArray = 0; + } + } + delete messages; +} + + +/*! + Converts this message file into an easily modifiable data + structure, less compact than the format used in the files. + + You should never need to call this function; it is called by + insert() and friends as necessary. + + \sa squeeze() +*/ + +void TQTranslator::unsqueeze() +{ + if ( d->messages ) + return; + + d->messages = new TQMap; + if ( !d->messageArray ) + return; + + TQDataStream s( *d->messageArray, IO_ReadOnly ); + for ( ;; ) { + TQTranslatorMessage m( s ); + if ( m.hash() == 0 ) + break; + d->messages->insert( m, (void *) 0 ); + } +} + + +/*! + Returns TRUE if this message file contains a message with the key + (\a context, \a sourceText, \a comment); otherwise returns FALSE. + + This function works with stripped translator files. + + (This is is a one-liner that calls findMessage().) +*/ + +bool TQTranslator::contains( const char* context, const char* sourceText, + const char* comment ) const +{ + return !findMessage( context, sourceText, comment ).translation().isNull(); +} + + +/*! + Inserts \a message into this message file. + + This function does \e not work with stripped translator files. It + may appear to, but that is not dependable. + + \sa remove() +*/ + +void TQTranslator::insert( const TQTranslatorMessage& message ) +{ + unsqueeze(); + d->messages->remove( message ); // safer + d->messages->insert( message, (void *) 0 ); +} + + +/*! + \fn void TQTranslator::insert( const char *, const char *, const TQString & ) + \overload + \obsolete +*/ + +/*! + Removes \a message from this translator. + + This function works with stripped translator files. + + \sa insert() +*/ + +void TQTranslator::remove( const TQTranslatorMessage& message ) +{ + unsqueeze(); + d->messages->remove( message ); +} + + +/*! + \fn void TQTranslator::remove( const char *, const char * ) + \overload + \obsolete + + Removes the translation associated to the key (\a context, \a sourceText, + "") from this translator. +*/ +#endif + +/*! + \fn TQString TQTranslator::find( const char*, const char*, const char* ) const + \obsolete + + Please use findMessage() instead. + + Returns the translation for the key (\a context, \a sourceText, + \a comment) or TQString::null if there is none in this translator. +*/ + +/*! Returns the TQTranslatorMessage for the key + (\a context, \a sourceText, \a comment). If none is found, + also tries (\a context, \a sourceText, ""). +*/ + +TQTranslatorMessage TQTranslator::findMessage( const char* context, + const char* sourceText, + const char* comment ) const +{ + if ( context == 0 ) + context = ""; + if ( sourceText == 0 ) + sourceText = ""; + if ( comment == 0 ) + comment = ""; + +#ifndef TQT_NO_TRANSLATION_BUILDER + if ( d->messages ) { + TQMap::ConstIterator it; + + it = d->messages->find( TQTranslatorMessage(context, sourceText, + comment) ); + if ( it != d->messages->end() ) + return it.key(); + + if ( comment[0] ) { + it = d->messages->find( TQTranslatorMessage(context, sourceText, + "") ); + if ( it != d->messages->end() ) + return it.key(); + } + return TQTranslatorMessage(); + } +#endif + + if ( !d->offsetArray ) + return TQTranslatorMessage(); + + /* + Check if the context belongs to this TQTranslator. If many translators are + installed, this step is necessary. + */ + if ( d->contextArray ) { + TQ_UINT16 hTableSize = 0; + TQDataStream t( *d->contextArray, IO_ReadOnly ); + t >> hTableSize; + uint g = elfHash( context ) % hTableSize; + t.device()->at( 2 + (g << 1) ); + TQ_UINT16 off; + t >> off; + if ( off == 0 ) + return TQTranslatorMessage(); + t.device()->at( 2 + (hTableSize << 1) + (off << 1) ); + + TQ_UINT8 len; + char con[256]; + for ( ;; ) { + t >> len; + if ( len == 0 || t.atEnd() ) + return TQTranslatorMessage(); + t.readRawBytes( con, len ); + con[len] = '\0'; + if ( qstrcmp(con, context) == 0 ) + break; + } + } + + size_t numItems = d->offsetArray->size() / ( 2 * sizeof(TQ_UINT32) ); + if ( !numItems ) + return TQTranslatorMessage(); + + if ( systemWordSize == 0 ) + tqSysInfo( &systemWordSize, &systemBigEndian ); + + for ( ;; ) { + TQ_UINT32 h = elfHash( TQCString(sourceText) + comment ); + + char *r = (char *) bsearch( &h, d->offsetArray->data(), numItems, + 2 * sizeof(TQ_UINT32), + systemBigEndian ? cmp_uint32_big + : cmp_uint32_little ); + if ( r != 0 ) { + // go back on equal key + while ( r != d->offsetArray->data() && + cmp_uint32_big(r - 8, r) == 0 ) + r -= 8; + + TQDataStream s( *d->offsetArray, IO_ReadOnly ); + s.device()->at( r - d->offsetArray->data() ); + + TQ_UINT32 rh, ro; + s >> rh >> ro; + + TQDataStream ms( *d->messageArray, IO_ReadOnly ); + while ( rh == h ) { + ms.device()->at( ro ); + TQTranslatorMessage m( ms ); + if ( match(m.context(), context) + && match(m.sourceText(), sourceText) + && match(m.comment(), comment) ) + return m; + if ( s.atEnd() ) + break; + s >> rh >> ro; + } + } + if ( !comment[0] ) + break; + comment = ""; + } + return TQTranslatorMessage(); +} + +/*! + Returns TRUE if this translator is empty, otherwise returns FALSE. + This function works with stripped and unstripped translation files. +*/ +bool TQTranslator::isEmpty() const +{ + return !( d->unmapPointer || d->unmapLength || d->messageArray || + d->offsetArray || d->contextArray +#ifndef TQT_NO_TRANSLATION_BUILDER + || (d->messages && d->messages->count()) +#endif + ); +} + + +#ifndef TQT_NO_TRANSLATION_BUILDER + +/*! + Returns a list of the messages in the translator. This function is + rather slow. Because it is seldom called, it's optimized for + simplicity and small size, rather than speed. + + If you want to iterate over the list, you should iterate over a + copy, e.g. + \code + TQValueList list = myTranslator.messages(); + TQValueList::Iterator it = list.begin(); + while ( it != list.end() ) { + process_message( *it ); + ++it; + } + \endcode +*/ + +TQValueList TQTranslator::messages() const +{ + if ( d->messages ) + return d->messages->keys(); + + ((TQTranslator *) this)->unsqueeze(); + TQValueList result = d->messages->keys(); + delete d->messages; + d->messages = 0; + return result; +} + +#endif + +/*! + \class TQTranslatorMessage + + \brief The TQTranslatorMessage class contains a translator message and its + properties. + + \ingroup i18n + \ingroup environment + + This class is of no interest to most applications. It is useful + for translation tools such as \link linguist-manual.book TQt + Linguist\endlink. It is provided simply to make the API complete + and regular. + + For a TQTranslator object, a lookup key is a triple (\e context, \e + {source text}, \e comment) that uniquely identifies a message. An + extended key is a quadruple (\e hash, \e context, \e {source + text}, \e comment), where \e hash is computed from the source text + and the comment. Unless you plan to read and write messages + yourself, you need not worry about the hash value. + + TQTranslatorMessage stores this triple or quadruple and the relevant + translation if there is any. + + \sa TQTranslator +*/ + +/*! + Constructs a translator message with the extended key (0, 0, 0, 0) + and TQString::null as translation. +*/ + +TQTranslatorMessage::TQTranslatorMessage() + : h( 0 ), cx( 0 ), st( 0 ), cm( 0 ) +{ +} + + +/*! + Constructs an translator message with the extended key (\e h, \a + context, \a sourceText, \a comment), where \e h is computed from + \a sourceText and \a comment, and possibly with a \a translation. +*/ + +TQTranslatorMessage::TQTranslatorMessage( const char * context, + const char * sourceText, + const char * comment, + const TQString& translation ) + : cx( context ), st( sourceText ), cm( comment ), tn( translation ) +{ + // 0 means we don't know, "" means empty + if ( cx == (const char*)0 ) + cx = ""; + if ( st == (const char*)0 ) + st = ""; + if ( cm == (const char*)0 ) + cm = ""; + h = elfHash( st + cm ); +} + + +/*! + Constructs a translator message read from the \a stream. The + resulting message may have any combination of content. + + \sa TQTranslator::save() +*/ + +TQTranslatorMessage::TQTranslatorMessage( TQDataStream & stream ) + : cx( 0 ), st( 0 ), cm( 0 ) +{ + TQString str16; + char tag; + TQ_UINT8 obs1; + + for ( ;; ) { + tag = 0; + if ( !stream.atEnd() ) + stream.readRawBytes( &tag, 1 ); + switch( (Tag)tag ) { + case Tag_End: + if ( h == 0 ) + h = elfHash( st + cm ); + return; + case Tag_SourceText16: // obsolete + stream >> str16; + st = str16.latin1(); + break; + case Tag_Translation: + stream >> tn; + break; + case Tag_Context16: // obsolete + stream >> str16; + cx = str16.latin1(); + break; + case Tag_Hash: + stream >> h; + break; + case Tag_SourceText: + stream >> st; + break; + case Tag_Context: + stream >> cx; + if ( cx == "" ) // for compatibility + cx = 0; + break; + case Tag_Comment: + stream >> cm; + break; + case Tag_Obsolete1: // obsolete + stream >> obs1; + break; + default: + h = 0; + st = 0; + cx = 0; + cm = 0; + tn = TQString::null; + return; + } + } +} + + +/*! + Constructs a copy of translator message \a m. +*/ + +TQTranslatorMessage::TQTranslatorMessage( const TQTranslatorMessage & m ) + : cx( m.cx ), st( m.st ), cm( m.cm ), tn( m.tn ) +{ + h = m.h; +} + + +/*! + Assigns message \a m to this translator message and returns a + reference to this translator message. +*/ + +TQTranslatorMessage & TQTranslatorMessage::operator=( + const TQTranslatorMessage & m ) +{ + h = m.h; + cx = m.cx; + st = m.st; + cm = m.cm; + tn = m.tn; + return *this; +} + + +/*! + \fn uint TQTranslatorMessage::hash() const + + Returns the hash value used internally to represent the lookup + key. This value is zero only if this translator message was + constructed from a stream containing invalid data. + + The hashing function is unspecified, but it will remain unchanged + in future versions of TQt. +*/ + +/*! + \fn const char *TQTranslatorMessage::context() const + + Returns the context for this message (e.g. "MyDialog"). + + \warning This may return 0 if the TQTranslator object is stripped + (compressed). +*/ + +/*! + \fn const char *TQTranslatorMessage::sourceText() const + + Returns the source text of this message (e.g. "&Save"). + + \warning This may return 0 if the TQTranslator object is stripped + (compressed). +*/ + +/*! + \fn const char *TQTranslatorMessage::comment() const + + Returns the comment for this message (e.g. "File|Save"). + + \warning This may return 0 if the TQTranslator object is stripped + (compressed). +*/ + +/*! + \fn void TQTranslatorMessage::setTranslation( const TQString & translation ) + + Sets the translation of the source text to \a translation. + + \sa translation() +*/ + +/*! + \fn TQString TQTranslatorMessage::translation() const + + Returns the translation of the source text (e.g., "&Sauvegarder"). + + \sa setTranslation() +*/ + +/*! + \enum TQTranslatorMessage::Prefix + + Let (\e h, \e c, \e s, \e m) be the extended key. The possible + prefixes are + + \value NoPrefix no prefix + \value Hash only (\e h) + \value HashContext only (\e h, \e c) + \value HashContextSourceText only (\e h, \e c, \e s) + \value HashContextSourceTextComment the whole extended key, (\e + h, \e c, \e s, \e m) + + \sa write() commonPrefix() +*/ + +/*! + Writes this translator message to the \a stream. If \a strip is + FALSE (the default), all the information in the message is + written. If \a strip is TRUE, only the part of the extended key + specified by \a prefix is written with the translation (\c + HashContextSourceTextComment by default). + + \sa commonPrefix() +*/ + +void TQTranslatorMessage::write( TQDataStream & stream, bool strip, + Prefix prefix ) const +{ + char tag; + + tag = (char)Tag_Translation; + stream.writeRawBytes( &tag, 1 ); + stream << tn; + + bool mustWriteHash = TRUE; + if ( !strip ) + prefix = HashContextSourceTextComment; + + switch ( prefix ) { + case HashContextSourceTextComment: + tag = (char)Tag_Comment; + stream.writeRawBytes( &tag, 1 ); + stream << cm; + // fall through + case HashContextSourceText: + tag = (char)Tag_SourceText; + stream.writeRawBytes( &tag, 1 ); + stream << st; + // fall through + case HashContext: + tag = (char)Tag_Context; + stream.writeRawBytes( &tag, 1 ); + stream << cx; + // fall through + default: + if ( mustWriteHash ) { + tag = (char)Tag_Hash; + stream.writeRawBytes( &tag, 1 ); + stream << h; + } + } + + tag = (char)Tag_End; + stream.writeRawBytes( &tag, 1 ); +} + + +/*! + Returns the widest lookup prefix that is common to this translator + message and to message \a m. + + For example, if the extended key is for this message is (71, + "PrintDialog", "Yes", "Print?") and that for \a m is (71, + "PrintDialog", "No", "Print?"), this function returns \c + HashContext. + + \sa write() +*/ + +TQTranslatorMessage::Prefix TQTranslatorMessage::commonPrefix( + const TQTranslatorMessage& m ) const +{ + if ( h != m.h ) + return NoPrefix; + if ( cx != m.cx ) + return Hash; + if ( st != m.st ) + return HashContext; + if ( cm != m.cm ) + return HashContextSourceText; + return HashContextSourceTextComment; +} + + +/*! + Returns TRUE if the extended key of this object is equal to that of + \a m; otherwise returns FALSE. +*/ + +bool TQTranslatorMessage::operator==( const TQTranslatorMessage& m ) const +{ + return h == m.h && cx == m.cx && st == m.st && cm == m.cm; +} + + +/*! + \fn bool TQTranslatorMessage::operator!=( const TQTranslatorMessage& m ) const + + Returns TRUE if the extended key of this object is different from + that of \a m; otherwise returns FALSE. +*/ + + +/*! + Returns TRUE if the extended key of this object is + lexicographically before than that of \a m; otherwise returns + FALSE. +*/ + +bool TQTranslatorMessage::operator<( const TQTranslatorMessage& m ) const +{ + return h != m.h ? h < m.h + : ( cx != m.cx ? cx < m.cx + : (st != m.st ? st < m.st : cm < m.cm) ); +} + + +/*! + \fn bool TQTranslatorMessage::operator<=( const TQTranslatorMessage& m ) const + + Returns TRUE if the extended key of this object is + lexicographically before that of \a m or if they are equal; + otherwise returns FALSE. +*/ + +/*! + \fn bool TQTranslatorMessage::operator>( const TQTranslatorMessage& m ) const + + Returns TRUE if the extended key of this object is + lexicographically after that of \a m; otherwise returns FALSE. +*/ + +/*! + \fn bool TQTranslatorMessage::operator>=( const TQTranslatorMessage& m ) const + + Returns TRUE if the extended key of this object is + lexicographically after that of \a m or if they are equal; + otherwise returns FALSE. +*/ + +#endif // TQT_NO_TRANSLATION diff --git a/src/kernel/tqtranslator.h b/src/kernel/tqtranslator.h new file mode 100644 index 000000000..39f9faa36 --- /dev/null +++ b/src/kernel/tqtranslator.h @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Definition of the translator class +** +** Created : 980906 +** +** Copyright (C) 1998-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 TQTRANSLATOR_H +#define TQTRANSLATOR_H + +#ifndef QT_H +#include "tqobject.h" +#include "tqvaluelist.h" +#endif // QT_H + +#ifndef TQT_NO_TRANSLATION + +class TQTranslatorPrivate; + +class TQ_EXPORT TQTranslatorMessage +{ +public: + TQTranslatorMessage(); + TQTranslatorMessage( const char * context, + const char * sourceText, + const char * comment, + const TQString& translation = TQString::null ); + TQTranslatorMessage( TQDataStream & ); + TQTranslatorMessage( const TQTranslatorMessage & m ); + + TQTranslatorMessage & operator=( const TQTranslatorMessage & m ); + + uint hash() const { return h; } + const char *context() const { return cx; } + const char *sourceText() const { return st; } + const char *comment() const { return cm; } + + void setTranslation( const TQString & translation ) { tn = translation; } + TQString translation() const { return tn; } + + enum Prefix { NoPrefix, Hash, HashContext, HashContextSourceText, + HashContextSourceTextComment }; + void write( TQDataStream & s, bool strip = FALSE, + Prefix prefix = HashContextSourceTextComment ) const; + Prefix commonPrefix( const TQTranslatorMessage& ) const; + + bool operator==( const TQTranslatorMessage& m ) const; + bool operator!=( const TQTranslatorMessage& m ) const + { return !operator==( m ); } + bool operator<( const TQTranslatorMessage& m ) const; + bool operator<=( const TQTranslatorMessage& m ) const + { return !m.operator<( *this ); } + bool operator>( const TQTranslatorMessage& m ) const + { return m.operator<( *this ); } + bool operator>=( const TQTranslatorMessage& m ) const + { return !operator<( m ); } + +private: + uint h; + TQCString cx; + TQCString st; + TQCString cm; + TQString tn; + + enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16, + Tag_Hash, Tag_SourceText, Tag_Context, Tag_Comment, + Tag_Obsolete1 }; +}; + + +class TQ_EXPORT TQTranslator: public TQObject +{ + TQ_OBJECT +public: + TQTranslator( TQObject * parent = 0, const char * name = 0 ); + ~TQTranslator(); + +#ifndef TQT_NO_COMPAT + TQString find( const char *context, const char *sourceText, const char * comment = 0 ) const { + return findMessage( context, sourceText, comment ).translation(); + } +#endif + virtual TQTranslatorMessage findMessage( const char *, const char *, + const char * = 0 ) const; + + bool load( const TQString & filename, + const TQString & directory = TQString::null, + const TQString & search_delimiters = TQString::null, + const TQString & suffix = TQString::null ); + bool load( const uchar *data, int len ) { + clear(); + return do_load( data, len ); + } + + void clear(); + +#ifndef TQT_NO_TRANSLATION_BUILDER + enum SaveMode { Everything, Stripped }; + + bool save( const TQString & filename, SaveMode mode = Everything ); + + void insert( const TQTranslatorMessage& ); + void insert( const char *context, const char *sourceText, const TQString &translation ) { + insert( TQTranslatorMessage(context, sourceText, "", translation) ); + } + void remove( const TQTranslatorMessage& ); + void remove( const char *context, const char *sourceText ) { + remove( TQTranslatorMessage(context, sourceText, "") ); + } + bool contains( const char *, const char *, const char * comment = 0 ) const; + + void squeeze( SaveMode = Everything ); + void unsqueeze(); + + TQValueList messages() const; +#endif + + bool isEmpty() const; + +private: +#if defined(TQ_DISABLE_COPY) + TQTranslator( const TQTranslator & ); + TQTranslator &operator=( const TQTranslator & ); +#endif + + bool do_load( const uchar *data, int len ); + + TQTranslatorPrivate * d; +}; + +#endif // TQT_NO_TRANSLATION + +#endif diff --git a/src/kernel/tqwidget.cpp b/src/kernel/tqwidget.cpp index 65f97e615..6892af3b7 100644 --- a/src/kernel/tqwidget.cpp +++ b/src/kernel/tqwidget.cpp @@ -410,7 +410,7 @@ \endlist There are also some rather obscure events. They are listed in - \c ntqevent.h and you need to reimplement event() to handle them. + \c tqevent.h and you need to reimplement event() to handle them. The default implementation of event() handles Tab and Shift+Tab (to move the keyboard focus), and passes on most other events to one of the more specialized handlers above. @@ -6051,7 +6051,7 @@ const TQPixmap *TQWidget::backgroundPixmap() const { return erasePixmap(); } void TQWidget::setBackgroundPixmap( const TQPixmap &pm ) { setErasePixmap( pm ); } -// documentation in qdesktopwidget_win.cpp +// documentation in tqdesktopwidget_win.cpp void TQDesktopWidget::insertChild( TQObject *obj ) { if ( obj->isWidgetType() ) -- cgit v1.2.3