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

  1. /****************************************************************************
  2. ** $Id:  qt/qevent.h   3.0.0   edited Sep 17 14:38 $
  3. **
  4. ** Definition of event classes
  5. **
  6. ** Created : 931029
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the kernel module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QEVENT_H
  39. #define QEVENT_H
  40.  
  41. #ifndef QT_H
  42. #include "qwindowdefs.h"
  43. #include "qregion.h"
  44. #include "qnamespace.h"
  45. #include "qmime.h"
  46. #include "qpair.h"
  47. #endif // QT_H
  48.  
  49. class Q_EXPORT QEvent: public Qt        // event base class
  50. {
  51. public:
  52.     enum Type {
  53.  
  54.     // NOTE: if you get a strange compiler error on the line with "None",
  55.     //       it's probably because you're trying to include X11, which
  56.     //     has a mess of #defines in it.  Put the messy X11 includes
  57.     //     *AFTER* the nice clean Qt includes.
  58.  
  59.     None = 0,                // invalid event
  60.  
  61.  
  62.     Timer = 1,                // timer event
  63.     MouseButtonPress = 2,            // mouse button pressed
  64.     MouseButtonRelease = 3,            // mouse button released
  65.     MouseButtonDblClick= 4,            // mouse button double click
  66.     MouseMove = 5,                // mouse move
  67.     KeyPress = 6,                // key pressed
  68.     KeyRelease = 7,                // key released
  69.     FocusIn = 8,                // keyboard focus received
  70.     FocusOut = 9,                // keyboard focus lost
  71.     Enter = 10,                // mouse enters widget
  72.     Leave = 11,                // mouse leaves widget
  73.     Paint = 12,                // paint widget
  74.     Move = 13,                // move widget
  75.     Resize = 14,                // resize widget
  76.     Create = 15,                // after object creation
  77.     Destroy = 16,                // during object destruction
  78.     Show = 17,                // widget is shown
  79.     Hide = 18,                // widget is hidden
  80.     Close = 19,                // request to close widget
  81.     Quit = 20,                // request to quit application
  82.     Reparent = 21,                // widget has been reparented
  83.     ShowMinimized = 22,                   // widget is shown minimized
  84.     ShowNormal = 23,                   // widget is shown normal
  85.     WindowActivate = 24,                   // window was activated
  86.     WindowDeactivate = 25,                   // window was deactivated
  87.     ShowToParent = 26,                   // widget is shown to parent
  88.     HideToParent = 27,                   // widget is hidden to parent
  89.     ShowMaximized = 28,                   // widget is shown maximized
  90.     ShowFullScreen = 29,            // widget is shown full-screen
  91.     Accel = 30,                // accelerator event
  92.     Wheel = 31,                // wheel event
  93.     AccelAvailable = 32,            // accelerator available event
  94.     CaptionChange = 33,            // caption changed
  95.     IconChange = 34,            // icon changed
  96.     ParentFontChange = 35,            // parent font changed
  97.     ApplicationFontChange = 36,        // application font changed
  98.     ParentPaletteChange = 37,        // parent palette changed
  99.     ApplicationPaletteChange = 38,        // application palette changed
  100.     PaletteChange = 39,            // widget palette changed
  101.     Clipboard = 40,                // internal clipboard event
  102.     Speech = 42,                // reserved for speech input
  103.     SockAct = 50,                // socket activation
  104.     AccelOverride = 51,            // accelerator override event
  105.     DeferredDelete = 52,            // deferred delete event
  106.     DragEnter = 60,                // drag moves into widget
  107.     DragMove = 61,                // drag moves in widget
  108.     DragLeave = 62,                // drag leaves or is cancelled
  109.     Drop = 63,                // actual drop
  110.     DragResponse = 64,            // drag accepted/rejected
  111.     ChildInserted = 70,            // new child widget
  112.     ChildRemoved = 71,            // deleted child widget
  113.     LayoutHint = 72,            // child min/max size changed
  114.     ShowWindowRequest = 73,            // widget's window should be mapped
  115.     ActivateControl = 80,            // ActiveX activation
  116.     DeactivateControl = 81,            // ActiveX deactivation
  117.     ContextMenu = 82,                       // context popup menu
  118.     IMStart = 83,                // input method composition start
  119.     IMCompose = 84,                // input method composition
  120.     IMEnd = 85,                // input method composition end
  121.     Accessibility = 86,            // accessibility information is requested
  122.     Tablet = 87,                // Wacom Tablet Event
  123.     User = 1000,                // first user event id
  124.     MaxUser  = 65535                        // last user event id
  125.     };
  126.  
  127.  
  128.     QEvent( Type type ) : t(type), posted(FALSE), spont(FALSE) {}
  129.     virtual ~QEvent();
  130.     Type  type() const    { return t; }
  131.     bool spontaneous() const     { return spont; }
  132. protected:
  133.     Type  t;
  134. private:
  135.     uint posted : 1;
  136.     uint spont : 1;
  137.  
  138.  
  139.     friend class QApplication;
  140.     friend class QBaseApplication;
  141.     friend class QETWidget;
  142. };
  143.  
  144.  
  145. class Q_EXPORT QTimerEvent : public QEvent
  146. {
  147. public:
  148.     QTimerEvent( int timerId )
  149.     : QEvent(Timer), id(timerId) {}
  150.     int      timerId()    const    { return id; }
  151. protected:
  152.     int      id;
  153. };
  154.  
  155.  
  156. class Q_EXPORT QMouseEvent : public QEvent
  157. {
  158. public:
  159.     QMouseEvent( Type type, const QPoint &pos, int button, int state );
  160.  
  161.     QMouseEvent( Type type, const QPoint &pos, const QPoint&globalPos,
  162.          int button, int state )
  163.     : QEvent(type), p(pos), g(globalPos), b((ushort)button),s((ushort)state),accpt(TRUE) {};
  164.  
  165.     const QPoint &pos() const    { return p; }
  166.     const QPoint &globalPos() const { return g; }
  167.     int       x()        const    { return p.x(); }
  168.     int       y()        const    { return p.y(); }
  169.     int       globalX()    const    { return g.x(); }
  170.     int       globalY()    const    { return g.y(); }
  171.     ButtonState button() const    { return (ButtonState) b; }
  172.     ButtonState state()    const    { return (ButtonState) s; }
  173.     ButtonState stateAfter() const;
  174.     bool   isAccepted() const    { return accpt; }
  175.     void   accept()        { accpt = TRUE; }
  176.     void   ignore()        { accpt = FALSE; }
  177. protected:
  178.     QPoint p;
  179.     QPoint g;
  180.     ushort b;
  181.     ushort s;
  182.     uint   accpt:1;
  183. };
  184.  
  185.  
  186. #ifndef QT_NO_WHEELEVENT
  187. class Q_EXPORT QWheelEvent : public QEvent
  188. {
  189. public:
  190.     QWheelEvent( const QPoint &pos, int delta, int state, Orientation orient = Vertical );
  191.     QWheelEvent( const QPoint &pos, const QPoint& globalPos, int delta, int state, Orientation orient = Vertical  )
  192.     : QEvent(Wheel), p(pos), g(globalPos), d(delta), s((ushort)state),
  193.       accpt(TRUE), o(orient) {}
  194.     int       delta()    const    { return d; }
  195.     const QPoint &pos() const    { return p; }
  196.     const QPoint &globalPos() const    { return g; }
  197.     int       x()        const    { return p.x(); }
  198.     int       y()        const    { return p.y(); }
  199.     int       globalX()    const    { return g.x(); }
  200.     int       globalY()    const    { return g.y(); }
  201.     ButtonState state()    const    { return ButtonState(s); }
  202.     Orientation orientation()     const     { return o; }
  203.     bool   isAccepted() const    { return accpt; }
  204.     void   accept()        { accpt = TRUE; }
  205.     void   ignore()        { accpt = FALSE; }
  206. protected:
  207.     QPoint p;
  208.     QPoint g;
  209.     int d;
  210.     ushort s;
  211.     bool   accpt;
  212.     Orientation o;
  213. };
  214. #endif
  215.  
  216. class Q_EXPORT QTabletEvent : public QEvent
  217. {
  218. public:
  219.     enum TabletDevice { NoDevice = -1, Puck, Stylus, Eraser };
  220.     QTabletEvent( const QPoint &pos, int device, int pressure, int xTilt, 
  221.                   int yTilt, const QPair<int,int> &uId )
  222.     : QEvent( Tablet ), mPos( pos ), mDev( device ), mPress( pressure ),
  223.       mXT( xTilt ), mYT( yTilt ), mType( uId.first ), mPhy( uId.second )
  224.     {}
  225.     QTabletEvent( const QPoint &pos, const QPoint &globalPos, int device,
  226.           int pressure, int xTilt, int yTilt, const QPair<int,int> &uId )
  227.     : QEvent( Tablet ), mPos( pos ), mGPos( globalPos ), mDev( device ),
  228.       mPress( pressure ), mXT( xTilt ), mYT( yTilt ), mType( uId.first ),
  229.       mPhy( uId.second )
  230.     {}
  231.     int pressure()    const { return mPress; }
  232.     int xTilt()        const { return mXT; }
  233.     int yTilt()        const { return mYT; }
  234.     const QPoint &pos()    const { return mPos; }
  235.     const QPoint &globalPos() const { return mGPos; }
  236.     int x()        const { return mPos.x(); }
  237.     int y()        const { return mPos.y(); }
  238.     int globalX()    const { return mGPos.x(); }
  239.     int globalY()    const { return mGPos.y(); }
  240.     TabletDevice device()     const { return TabletDevice(mDev); }
  241.     int isAccepted() const { return mbAcc; }
  242.     void accept() { mbAcc = TRUE; }
  243.     void ignore() { mbAcc = FALSE; }
  244.     QPair<int,int> uniqueId() { return QPair<int,int>( mType, mPhy); }
  245. protected:
  246.     QPoint mPos;
  247.     QPoint mGPos;
  248.     int mDev,
  249.         mPress,
  250.         mXT,
  251.         mYT,
  252.         mType,
  253.     mPhy;
  254.     bool mbAcc;
  255.     
  256. };
  257.  
  258. class Q_EXPORT QKeyEvent : public QEvent
  259. {
  260. public:
  261.     QKeyEvent( Type type, int key, int ascii, int state,
  262.         const QString& text=QString::null, bool autorep=FALSE, ushort count=1 )
  263.     : QEvent(type), txt(text), k((ushort)key), s((ushort)state),
  264.         a((uchar)ascii), accpt(TRUE), autor(autorep), c(count) {}
  265.     int       key()    const    { return k; }
  266.     int       ascii()    const    { return a; }
  267.     ButtonState state()    const    { return ButtonState(s); }
  268.     ButtonState stateAfter() const;
  269.     bool   isAccepted() const    { return accpt; }
  270.     QString text()      const   { return txt; }
  271.     bool   isAutoRepeat() const    { return autor; }
  272.     int   count() const    { return int(c); }
  273.     void   accept()        { accpt = TRUE; }
  274.     void   ignore()        { accpt = FALSE; }
  275.  
  276. protected:
  277.     QString txt;
  278.     ushort k, s;
  279.     uchar  a;
  280.     uint   accpt:1;
  281.     uint   autor:1;
  282.     ushort c;
  283. };
  284.  
  285.  
  286. class Q_EXPORT QFocusEvent : public QEvent
  287. {
  288. public:
  289.  
  290.     QFocusEvent( Type type )
  291.     : QEvent(type) {}
  292.  
  293.     bool   gotFocus()    const { return type() == FocusIn; }
  294.     bool   lostFocus()    const { return type() == FocusOut; }
  295.  
  296.     enum Reason { Mouse, Tab, Backtab, ActiveWindow, Popup, Shortcut, Other };
  297.     static Reason reason();
  298.     static void setReason( Reason reason );
  299.     static void resetReason();
  300.  
  301. private:
  302.     static Reason m_reason;
  303.     static Reason prev_reason;
  304. };
  305.  
  306.  
  307. class Q_EXPORT QPaintEvent : public QEvent
  308. {
  309. public:
  310.     QPaintEvent( const QRegion& paintRegion, bool erased = TRUE)
  311.     : QEvent(Paint),
  312.       rec(paintRegion.boundingRect()),
  313.       reg(paintRegion),
  314.       erase(erased){}
  315.     QPaintEvent( const QRect &paintRect, bool erased = TRUE )
  316.     : QEvent(Paint),
  317.       rec(paintRect),
  318.       reg(paintRect),
  319.       erase(erased){}
  320.     const QRect &rect() const      { return rec; }
  321.     const QRegion ®ion() const { return reg; }
  322.     bool erased() const { return erase; }
  323. protected:
  324.     friend class QApplication;
  325.     friend class QBaseApplication;
  326.     QRect rec;
  327.     QRegion reg;
  328.     bool erase;
  329. };
  330.  
  331.  
  332. class Q_EXPORT QMoveEvent : public QEvent
  333. {
  334. public:
  335.     QMoveEvent( const QPoint &pos, const QPoint &oldPos )
  336.     : QEvent(Move), p(pos), oldp(oldPos) {}
  337.     const QPoint &pos()      const { return p; }
  338.     const QPoint &oldPos()const { return oldp;}
  339. protected:
  340.     QPoint p, oldp;
  341.     friend class QApplication;
  342.     friend class QBaseApplication;
  343. };
  344.  
  345.  
  346. class Q_EXPORT QResizeEvent : public QEvent
  347. {
  348. public:
  349.     QResizeEvent( const QSize &size, const QSize &oldSize )
  350.     : QEvent(Resize), s(size), olds(oldSize) {}
  351.     const QSize &size()      const { return s; }
  352.     const QSize &oldSize()const { return olds;}
  353. protected:
  354.     QSize s, olds;
  355.     friend class QApplication;
  356.     friend class QBaseApplication;
  357. };
  358.  
  359.  
  360. class Q_EXPORT QCloseEvent : public QEvent
  361. {
  362. public:
  363.     QCloseEvent()
  364.     : QEvent(Close), accpt(FALSE) {}
  365.     bool   isAccepted() const    { return accpt; }
  366.     void   accept()        { accpt = TRUE; }
  367.     void   ignore()        { accpt = FALSE; }
  368. protected:
  369.     bool   accpt;
  370. };
  371.  
  372.  
  373. class Q_EXPORT QShowEvent : public QEvent
  374. {
  375. public:
  376.     QShowEvent()
  377.     : QEvent(Show) {}
  378. };
  379.  
  380.  
  381. class Q_EXPORT QHideEvent : public QEvent
  382. {
  383. public:
  384.     QHideEvent()
  385.     : QEvent(Hide) {}
  386. };
  387.  
  388. class Q_EXPORT QContextMenuEvent : public QEvent
  389. {
  390. public:
  391.     enum Reason { Mouse, Keyboard, Other };
  392.     QContextMenuEvent( Reason reason, const QPoint &pos, const QPoint &globalPos, int state )
  393.     : QEvent( ContextMenu ), p( pos ), gp( globalPos ), accpt( FALSE ), consum(FALSE),
  394.     reas( reason ), s((ushort)state) {}
  395.     QContextMenuEvent( Reason reason, const QPoint &pos, int state );
  396.  
  397.     int        x() const { return p.x(); }
  398.     int        y() const { return p.y(); }
  399.     int        globalX() const { return gp.x(); }
  400.     int        globalY() const { return gp.y(); }
  401.  
  402.     const QPoint&   pos() const { return p; }
  403.     const QPoint&   globalPos() const { return gp; }
  404.  
  405.     ButtonState state()    const    { return (ButtonState) s; }
  406.     bool    isAccepted() const    { return accpt; }
  407.     bool    isConsumed() const  { return consum; }
  408.     void    consume()           { consum = TRUE; }
  409.     void    accept()        { accpt = TRUE; consum = TRUE; }
  410.     void    ignore()        { accpt = FALSE; consum = FALSE; }
  411.  
  412.     Reason  reason() const { return Reason( reas ); }
  413.  
  414. protected:
  415.     QPoint  p;
  416.     QPoint  gp;
  417.     bool    accpt;
  418.     bool    consum;
  419.     uint    reas:8;
  420.     ushort s;
  421. };
  422.  
  423.  
  424. class Q_EXPORT QIMEvent : public QEvent
  425. {
  426. public:
  427.     QIMEvent( Type type, const QString &text, int cursorPosition )
  428.     : QEvent(type), txt(text), cpos(cursorPosition), a(FALSE) {}
  429.     const QString &text() const { return txt; }
  430.     int cursorPos() const { return cpos; }
  431.     bool isAccepted() const { return a; }
  432.     void accept() { a = TRUE; }
  433.     void ignore() { a = FALSE; }
  434. private:
  435.     QString txt;
  436.     int cpos;
  437.     bool a;
  438. };
  439.  
  440.  
  441. #ifndef QT_NO_DRAGANDDROP
  442.  
  443. // This class is rather closed at the moment.  If you need to create your
  444. // own DND event objects, write to qt-bugs@trolltech.com and we'll try to
  445. // find a way to extend it so it covers your needs.
  446.  
  447. class Q_EXPORT QDropEvent : public QEvent, public QMimeSource
  448. {
  449. public:
  450.     QDropEvent( const QPoint& pos, Type typ=Drop )
  451.     : QEvent(typ), p(pos),
  452.       act(0), accpt(0), accptact(0), resv(0),
  453.       d(0)
  454.     {}
  455.     const QPoint &pos() const    { return p; }
  456.     bool isAccepted() const    { return accpt || accptact; }
  457.     void accept(bool y=TRUE)    { accpt = y; }
  458.     void ignore()        { accpt = FALSE; }
  459.  
  460.     bool isActionAccepted() const { return accptact; }
  461.     void acceptAction(bool y=TRUE) { accptact = y; }
  462.     enum Action { Copy, Link, Move, Private, UserAction=100 };
  463.     void setAction( Action a ) { act = (uint)a; }
  464.     Action action() const { return Action(act); }
  465.  
  466.     QWidget* source() const;
  467.     const char* format( int n = 0 ) const;
  468.     QByteArray encodedData( const char* ) const;
  469.     bool provides( const char* ) const;
  470.  
  471.     QByteArray data(const char* f) const { return encodedData(f); }
  472.  
  473.     void setPoint( const QPoint& np ) { p = np; }
  474.  
  475. protected:
  476.     QPoint p;
  477.     uint act:8;
  478.     uint accpt:1;
  479.     uint accptact:1;
  480.     uint resv:5;
  481.     void * d;
  482. };
  483.  
  484.  
  485.  
  486. class Q_EXPORT QDragMoveEvent : public QDropEvent
  487. {
  488. public:
  489.     QDragMoveEvent( const QPoint& pos, Type typ=DragMove )
  490.     : QDropEvent(pos,typ),
  491.       rect( pos, QSize( 1, 1 ) ) {}
  492.     QRect answerRect() const { return rect; }
  493.     void accept( bool y=TRUE ) { QDropEvent::accept(y); }
  494.     void accept( const QRect & r) { accpt = TRUE; rect = r; }
  495.     void ignore( const QRect & r) { accpt =FALSE; rect = r; }
  496.     void ignore()        { QDropEvent::ignore(); }
  497.  
  498. protected:
  499.     QRect rect;
  500. };
  501.  
  502.  
  503. class Q_EXPORT QDragEnterEvent : public QDragMoveEvent
  504. {
  505. public:
  506.     QDragEnterEvent( const QPoint& pos ) :
  507.     QDragMoveEvent(pos, DragEnter) { }
  508. };
  509.  
  510.  
  511. /* An internal class */
  512. class Q_EXPORT QDragResponseEvent : public QEvent
  513. {
  514. public:
  515.     QDragResponseEvent( bool accepted )
  516.     : QEvent(DragResponse), a(accepted) {}
  517.     bool   dragAccepted() const    { return a; }
  518. protected:
  519.     bool a;
  520. };
  521.  
  522.  
  523. class Q_EXPORT QDragLeaveEvent : public QEvent
  524. {
  525. public:
  526.     QDragLeaveEvent()
  527.     : QEvent(DragLeave) {}
  528. };
  529.  
  530. #endif // QT_NO_DRAGANDDROP
  531.  
  532. class Q_EXPORT QChildEvent : public QEvent
  533. {
  534. public:
  535.     QChildEvent( Type type, QObject *child )
  536.     : QEvent(type), c(child) {}
  537.     QObject *child() const    { return c; }
  538.     bool inserted() const { return t == ChildInserted; }
  539.     bool removed() const { return t == ChildRemoved; }
  540. protected:
  541.     QObject *c;
  542. };
  543.  
  544.  
  545. class Q_EXPORT QCustomEvent : public QEvent
  546. {
  547. public:
  548.     QCustomEvent( int type );
  549.     QCustomEvent( Type type, void *data )
  550.     : QEvent(type), d(data) {};
  551.     void       *data()    const    { return d; }
  552.     void    setData( void* data )    { d = data; }
  553. private:
  554.     void       *d;
  555. };
  556.  
  557. #endif // QEVENT_H
  558.