home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / Headers / Core / XEvent.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-24  |  13.6 KB  |  604 lines

  1. /*    XEvent.h
  2.  *
  3.  *        This contains the various declarations that are used to
  4.  *    send and receive events in my system. This creates three types
  5.  *    of message transmission mechanisms.
  6.  *
  7.  *        The first is the 'dispatch' method. A dispatch message will
  8.  *    send messages to the bottom of the event 'tree', and migrate
  9.  *    messages upwards until the message is handled. A broadcast
  10.  *    message is a message sent globally; this is a global resource.
  11.  *    And a send/receive pair allows a single sender to send to several
  12.  *    receivers. A receiver can be attached to one or more senders.
  13.  *
  14.  *        Messages are all identified by a single long word value,
  15.  *    customarly four char values, such as 'idle'. All messages have
  16.  *    a long-word argument (which has a meaning specific translation)
  17.  *    and a void pointer argument.
  18.  */
  19.  
  20. /*  YAAF - Yet another application framework
  21.  *  Copyright (C) 1997 William Edward Woody and In Phase Consulting
  22.  *  
  23.  *  This library is free software; you can redistribute it
  24.  *  and/or modify it under the terms of the GNU Library
  25.  *  General Public License as published by the Free Software
  26.  *  Foundation; either version 2 of the License, or any
  27.  *  later version.
  28.  *  
  29.  *  This library is distributed in the hope that it will be
  30.  *  useful, but WITHOUT ANY WARRANTY; without even the implied
  31.  *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
  32.  *  PURPOSE. See the GNU Library General Public License for
  33.  *  more details.
  34.  *  
  35.  *  You should have received a copy of the GNU Library General
  36.  *  Public License along with this library; if not, write to the
  37.  *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  38.  *  Boston, MA 02111-1307, USA.
  39.  *  
  40.  *  To contact the author, either e-mail me at
  41.  *  woody@alumni.caltech.edu, or write to us at
  42.  *  
  43.  *          William Edward Woody
  44.  *          In Phase Consulting
  45.  *          1545 Ard Eevin Avenue
  46.  *          Glendale, CA 91202
  47.  */
  48.  
  49. #ifndef __XEVENT_H__
  50. #define __XEVENT_H__
  51.  
  52. #include <XDynArray.h>
  53.  
  54. #if defined(__MWERKS__)
  55.     #if defined(macintosh)
  56.         #pragma options align=power
  57.     #endif
  58.     #if defined(__INTEL__)
  59.         #pragma pack(push,2)
  60.     #endif
  61. #endif
  62.  
  63. /************************************************************************/
  64. /*                                                                        */
  65. /*    Default menu commands                                                */
  66. /*                                                                        */
  67. /************************************************************************/
  68.  
  69. #define KDefaultMenu                128            // ResID of default menu
  70.  
  71.  
  72. #define    KMenuAboutMe                1
  73.  
  74. #define KMenuFileClose                2
  75. #define KMenuFileQuit                3
  76.  
  77. #define KMenuFileSave                13
  78. #define KMenuFileSaveAs                14
  79. #define KMenuFileRevert                15
  80.  
  81. #define KMenuEditUndo                4
  82. #define KMenuEditCut                5
  83. #define KMenuEditCopy                6
  84. #define KMenuEditPaste                7
  85. #define KMenuEditClear                8
  86.  
  87. #define KMenuWindowTile                9
  88. #define KMenuWindowCascade            10
  89. #define KMenuWindowArrange            11
  90. #define KMenuWindowList                12            // marker
  91.  
  92. /************************************************************************/
  93. /*                                                                        */
  94. /*    Internal broadcasted messages                                        */
  95. /*                                                                        */
  96. /************************************************************************/
  97.  
  98. /*    KEventPrePeriodic                        (broadcast)
  99.  *
  100.  *        This message is sent periodically to the entire system before
  101.  *    and after the event loop is executed; this gives the system a
  102.  *    change to do periodic things.
  103.  *
  104.  *        Arguments:
  105.  *            long arg        0
  106.  *            void *parg        NULL
  107.  */
  108.  
  109. #define    KEventPrePeriodic        'prei'
  110.  
  111. /*    KEventPostPeriodic                        (broadcast)
  112.  *
  113.  *        This message is sent periodically to the entire system before
  114.  *    and after the event loop is executed; this gives the system a
  115.  *    change to do periodic things.
  116.  *
  117.  *        Arguments:
  118.  *            long arg        0
  119.  *            void *parg        NULL
  120.  */
  121.  
  122. #define    KEventPostPeriodic        'post'
  123.  
  124. /*    KEventAppActivate
  125.  *
  126.  *        This message is broadcast when the application is activated.
  127.  *    When the application starts up, it is normally active; this (and
  128.  *    the one following) are sent to indicate when the application goes
  129.  *    inactive and back
  130.  *
  131.  *        Arguments:
  132.  *            long arg        0
  133.  *            void *parg        NULL
  134.  */
  135.  
  136. #define KEventAppActivate        'appa'
  137.  
  138. /*    KEventAppDeactivate
  139.  *
  140.  *        This is broadcast to indicate the application has been deactivated
  141.  *
  142.  *        Arguments:
  143.  *            long arg        0
  144.  *            void *parg        NULL
  145.  */
  146.  
  147. #define KEventAppDeactivate        'appd'
  148.  
  149. /*    KEventIdle                                (dispatch)
  150.  *
  151.  *        Idle event; this is the event sent to the current focus to
  152.  *    do idle events, like flashing a cursor
  153.  *
  154.  *        Arguments:
  155.  *            long arg        0
  156.  *            void *parg        NULL
  157.  */
  158.  
  159. #define KEventIdle                'idle'
  160.  
  161. /*    KEventDoMenuCommand                        (dispatch)
  162.  *
  163.  *        This is sent to the current focus when a menu event happens.
  164.  *    This should return 1 if the menu command is performed, and 0 if not.
  165.  *
  166.  *        Arguments:
  167.  *            long arg        menu command ID
  168.  *            void *parg        NULL
  169.  */
  170.  
  171. #define KEventDoMenuCommand        'menu'
  172.  
  173. /*    KEventGetMenuStatus                        (dispatch)
  174.  *
  175.  *        This is sent to the current focus to figure out what is the
  176.  *    current status of this menu item. This gets the checked state and
  177.  *    the enabled state of this menu command
  178.  *
  179.  *        Arguments:
  180.  *            long arg        menu command ID
  181.  *            void *parg        pointer to structure which contains flags
  182.  */
  183.  
  184. #define KEventGetMenuStatus        'msta'
  185.  
  186. struct XGSMenuStatusRecord {
  187.     bool                        enable;        /* true == enabled */
  188.     bool                        checked;    /* true == checked */
  189.     char                        checkchar;    /* if nonzero, alt checkmark */
  190. };
  191.  
  192. /*    KEventKey                                (dispatch)
  193.  *
  194.  *        This is a keyboard event. The various special keys are indicated
  195.  *    by setting the modifier flags correctly
  196.  *
  197.  *        Arguments:
  198.  *            long arg        hi word: modifiers, lo word: key code
  199.  *            void *parg        NULL
  200.  */
  201.  
  202. #define KEventKey                'key '
  203.  
  204. /*    KEventWindowName                        (dispatch)
  205.  *
  206.  *        This event is sent upwards when a window is renamed. This gives
  207.  *    the objects above which are maintaining a window menu to update it's
  208.  *    contents
  209.  *
  210.  *        Arguments:
  211.  *            long arg        0
  212.  *            void *parg        pointer to XGWindow class (window already renamed)
  213.  */
  214.  
  215. #define KEventWindowName        'namw'
  216.  
  217. /*    KEventWindowCreate                        (dispatch)
  218.  *
  219.  *        This event is sent when a window is created
  220.  *
  221.  *        Arguments:
  222.  *            long arg        0
  223.  *            void *parg        pointer to XGWindow class (window already created)
  224.  *
  225.  *        NOTE: 
  226.  *            return values:    If the window is not to be created, throw error
  227.  */
  228.  
  229. #define KEventWindowCreate        'crew'
  230.  
  231. /*    KEventWindowPreDestroy                    (dispatch)
  232.  *
  233.  *        This event is sent when a window is about to be destroyed
  234.  *
  235.  *        Arguments:
  236.  *            long arg        0
  237.  *            void *parg        pointer to XGWindow class (window not yet destroyed)
  238.  *
  239.  *        NOTE: 
  240.  *            return values:    If the window is not to be destroyed, throw error
  241.  */
  242.  
  243. #define KEventWindowPreDestroy    'pdsw'
  244.  
  245. /*    KEventWindowDestroy                        (dispatch)
  246.  *
  247.  *        This event is sent when the window is destroyed
  248.  *
  249.  *        Arguments:
  250.  *            long arg        0
  251.  *            void *parg        pointer to XGWindow class (window not yet destroyed)
  252.  */
  253.  
  254. #define KEventWindowDestroy        'desw'
  255.  
  256. /*    KEventDialogMessage
  257.  *
  258.  *        This is really not dispatched, but this is a dialog message.
  259.  *    This is a dialog message which specifies initialization, destruction,
  260.  *    or other messages specific to dialog processing.
  261.  *
  262.  *        Arguments:
  263.  *            long arg        see below
  264.  *            void *parg        NULL
  265.  */
  266.  
  267. #define KEventDialogMessage        'dlog'
  268.  
  269. #define KEventDMInitDialog        1
  270. #define KEventDMEndDialog        2
  271.  
  272.  
  273. /*    KEventWInternal                            (dispatch, WinOS only)
  274.  *
  275.  *        This indicates that either a scrollbar event or a control message
  276.  *    from a windows control was received.
  277.  *
  278.  *        In these cases, the message is stuffed into the structure specified
  279.  *    below, and the message is passed to the view which owns the scroll
  280.  *    bar or the control that was hit. This allows the WinOS version of the
  281.  *    windows library to translate the internal message into the YAAF
  282.  *    library message that I expect.
  283.  *
  284.  *        Arguments:
  285.  *            long arg        0
  286.  *            void *parg        pointer to message structure below
  287.  *
  288.  *        Windows messages which are handled in this way are:
  289.  *
  290.  *        WM_HSCROLL            Scrollbar message
  291.  *        WM_VSCROLL            Scrollbar message
  292.  *        WM_COMMAND            Miscellaneous control messages (that are not
  293.  *                                meuu or accelerator messages)
  294.  */
  295.  
  296. #if OPT_WINOS == 1
  297.  
  298. #define KEventWInternal            'wint'
  299.  
  300. struct XGSWInternalRecord {
  301.     HWND                        w;
  302.     UINT                        msg;
  303.     WPARAM                        wp;
  304.     LPARAM                        lp;
  305. };
  306.  
  307. #endif
  308.  
  309. /************************************************************************/
  310. /*                                                                        */
  311. /*    Event Constants                                                        */
  312. /*                                                                        */
  313. /************************************************************************/
  314.  
  315. /*
  316.  *    Keyboard modifier arguments
  317.  */
  318.  
  319. #define KKeyShift                0x0001
  320. #define KKeyControl                0x0002
  321.  
  322. #if OPT_MACOS == 1
  323. #    define KKeyCommand            0x0004
  324. #    define KKeyOption            0x0008
  325. #endif
  326.  
  327. #if OPT_WINOS == 1
  328. #    define KKeyMenu                0x0008
  329. #endif
  330.  
  331. #define    KKeyButton                0x0010
  332.  
  333. #if OPT_WINOS == 1
  334. #    define KKeyRButton            0x0020
  335. #    define KKeyMButton            0x0040
  336. #endif
  337.  
  338. #define KDoubleClick            0x0100
  339. #define KCapturedMouse            0x0200
  340. #define KSpecialKey                0x8000
  341.  
  342. /*
  343.  *    Special keys (if KSpecialKey bit set)
  344.  */
  345.  
  346. #define    KKeyUpCursor            128
  347. #define KKeyDownCursor            129
  348. #define KKeyLeftCursor            130
  349. #define KKeyRightCursor            131
  350. #define KKeyInsert                132
  351. #define KKeyDelete                133
  352. #define KKeyHome                134
  353. #define KKeyEnd                    135
  354. #define KKeyPageUp                136
  355. #define KKeyPageDown            137
  356. #define KKeyEscape                138
  357. #define KKeyHelp                139
  358. #define KKeyNumLock                140
  359. #define KKeyClear                141
  360.  
  361. #define KKeyF1                    160
  362. #define KKeyF2                    161
  363. #define KKeyF3                    162
  364. #define KKeyF4                    163
  365. #define KKeyF5                    164
  366. #define KKeyF6                    165
  367. #define KKeyF7                    166
  368. #define KKeyF8                    167
  369. #define KKeyF9                    168
  370. #define KKeyF10                    169
  371. #define KKeyF11                    170
  372. #define KKeyF12                    171
  373. #define KKeyF13                    172
  374. #define KKeyF14                    173
  375. #define KKeyF15                    174
  376.  
  377. /************************************************************************/
  378. /*                                                                        */
  379. /*    Dispatch Method                                                        */
  380. /*                                                                        */
  381. /************************************************************************/
  382.  
  383. /*
  384.  *    Forwards
  385.  */
  386.  
  387. class XGDispatch;
  388.  
  389. /*    XGFocus
  390.  *
  391.  *        This is the class which holds the focus for this object. Each
  392.  *    window and the main application are both descendant from the focus
  393.  *    object; this is the place from where messages are sent.
  394.  */
  395.  
  396. class XGFocus {
  397.     public:
  398.                                 XGFocus(XGDispatch *x);
  399.         virtual                    ~XGFocus();
  400.         
  401.         /*
  402.          *    Focus manipulation routines
  403.          */
  404.         
  405.         void                    _SetFocus(XGDispatch *x);
  406.         void                    _ClearFocus();
  407.         XGDispatch                *GetFocus()
  408.                                     {
  409.                                         return fFocus;
  410.                                     }
  411.         
  412.         /*
  413.          *    Send messages
  414.          */
  415.         
  416.         long                    SendDispatch(long m,long i,void *p);
  417.     private:
  418.         XGDispatch                *fDefault;
  419.         XGDispatch                *fFocus;
  420. };
  421.  
  422. /*    XGDispatch
  423.  *
  424.  *        This is the dispatch method.
  425.  */
  426.  
  427. class XGDispatch {
  428.     public:
  429.                                 XGDispatch();
  430.         virtual                    ~XGDispatch();
  431.         
  432.         /*
  433.          *    Focus
  434.          *
  435.          *        The focus is the first dispatch object to receive
  436.          *    *all* messages that are being dispatched to the XGDispatch
  437.          *    hierarchy. This is a global resource, though the window
  438.          *    management tools have a good go at it.
  439.          */
  440.         
  441.         virtual XGDispatch        *SetFocus(void);    /* Set focus to me */
  442.  
  443.         virtual bool            HasFocus(void);        /* Do I have focus? */
  444.         virtual void            GainFocus(void);    /* I've got focus */
  445.         virtual void            LoseFocus(void);    /* I no longer have it */
  446.         
  447.         /*
  448.          *    Default tree top
  449.          */
  450.         
  451.         static XGDispatch        *GetDefault(void)
  452.                                     {
  453.                                         return gDefault;
  454.                                     }
  455.         static void                SetDefault(XGDispatch *x)
  456.                                     {
  457.                                         gDefault = x;
  458.                                     }
  459.         
  460.         /*
  461.          *    Message dispatch
  462.          */
  463.         
  464.         virtual long            ReceiveDispatch(long,long,void *);
  465.         
  466.         /*
  467.          *    Magic internal stuff to initialize the focus pointers
  468.          */
  469.         
  470.         void                    _SetFocusDispatch(XGFocus *x)
  471.                                     {
  472.                                         fFocus = x;
  473.                                     }
  474.         static void                _SetCTorParentDispatch(XGDispatch *x)
  475.                                     {
  476.                                         gParent = x;
  477.                                     }
  478.     
  479.     private:
  480.         static XGDispatch        *gParent;
  481.         static XGDispatch        *gDefault;
  482.         XGDispatch                *fParent;
  483.         XGFocus                    *fFocus;
  484. };
  485.  
  486. /************************************************************************/
  487. /*                                                                        */
  488. /*    Broadcast Method                                                    */
  489. /*                                                                        */
  490. /************************************************************************/
  491.  
  492. /*    _PostRecord
  493.  *
  494.  *        This is how posts are actually stored
  495.  */
  496.  
  497. struct _PostRecord {
  498.     long            msg;
  499.     long            arg;
  500.     void            *parg;
  501. };
  502.  
  503. /*    XGBroadcast
  504.  *
  505.  *        This is a bit misnamed--this actually receives global broadcasts
  506.  */
  507.  
  508. class XGBroadcast {
  509.     public:
  510.                                 XGBroadcast(void);
  511.         virtual                    ~XGBroadcast();
  512.         
  513.         /*
  514.          *    Message dispatch
  515.          */
  516.         
  517.         virtual void            ReceiveBroadcast(long,long,void *);
  518.         static void                SendBroadcast(long,long,void *);
  519.         static void                PostBroadcast(long,long,void *);
  520.         
  521.         static void                _SendPost(void);
  522.     private:
  523.         static XGBroadcast        *gList;
  524.         XGBroadcast                *fNext;
  525.         
  526.         static XGDynArray<_PostRecord> gPostStack;
  527. };
  528.  
  529.  
  530. /************************************************************************/
  531. /*                                                                        */
  532. /*    Send/Recieve Methods                                                */
  533. /*                                                                        */
  534. /************************************************************************/
  535.  
  536. /*
  537.  *    Class forwards
  538.  */
  539.  
  540. class XGSend;
  541. class XGReceive;
  542.  
  543. /*    XGSend
  544.  *
  545.  *        This is part of a send/receive pair; this is the thing that
  546.  *    sends messages
  547.  */
  548.  
  549. class XGSend {
  550.     public:
  551.                                 XGSend(void);
  552.         virtual                    ~XGSend();
  553.         
  554.         /*
  555.          *    Receiver management
  556.          */
  557.         
  558.         void                    AddReceiver(XGReceive *);
  559.         void                    RemoveReceiver(XGReceive *);
  560.         
  561.         /*
  562.          *    Message dispatch
  563.          */
  564.         
  565.         void                    SendMessage(long,long,void *);
  566.         
  567.     private:
  568.         XGDynArray<XGReceive *>    fReceive;
  569. };
  570.  
  571. /*    XGReceive
  572.  *
  573.  *        Receiver
  574.  */
  575.  
  576. class XGReceive {
  577.     public:
  578.                                 XGReceive();
  579.         virtual                    ~XGReceive();
  580.         
  581.         /*
  582.          *    Receiver 
  583.          */
  584.         
  585.         virtual void            ReceiveMessage(long,long,void *);
  586.  
  587.     private:
  588.         XGDynArray<XGSend *>    fSend;
  589.     
  590.     friend class XGSend;
  591. };        
  592.  
  593. #if defined(__MWERKS__)
  594.     #if defined(macintosh)
  595.         #pragma options align=reset
  596.     #endif
  597.     #if defined(__INTEL__)
  598.         #pragma pack(pop)
  599.     #endif
  600. #endif
  601.  
  602.  
  603. #endif /* __XEVENT_H__ */
  604.