home *** CD-ROM | disk | FTP | other *** search
- /* XEvent.h
- *
- * This contains the various declarations that are used to
- * send and receive events in my system. This creates three types
- * of message transmission mechanisms.
- *
- * The first is the 'dispatch' method. A dispatch message will
- * send messages to the bottom of the event 'tree', and migrate
- * messages upwards until the message is handled. A broadcast
- * message is a message sent globally; this is a global resource.
- * And a send/receive pair allows a single sender to send to several
- * receivers. A receiver can be attached to one or more senders.
- *
- * Messages are all identified by a single long word value,
- * customarly four char values, such as 'idle'. All messages have
- * a long-word argument (which has a meaning specific translation)
- * and a void pointer argument.
- */
-
- /* YAAF - Yet another application framework
- * Copyright (C) 1997 William Edward Woody and In Phase Consulting
- *
- * This library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Library
- * General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or any
- * later version.
- *
- * This library is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Library General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Library General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * To contact the author, either e-mail me at
- * woody@alumni.caltech.edu, or write to us at
- *
- * William Edward Woody
- * In Phase Consulting
- * 1545 Ard Eevin Avenue
- * Glendale, CA 91202
- */
-
- #ifndef __XEVENT_H__
- #define __XEVENT_H__
-
- #include <XDynArray.h>
-
- #if defined(__MWERKS__)
- #if defined(macintosh)
- #pragma options align=power
- #endif
- #if defined(__INTEL__)
- #pragma pack(push,2)
- #endif
- #endif
-
- /************************************************************************/
- /* */
- /* Default menu commands */
- /* */
- /************************************************************************/
-
- #define KDefaultMenu 128 // ResID of default menu
-
-
- #define KMenuAboutMe 1
-
- #define KMenuFileClose 2
- #define KMenuFileQuit 3
-
- #define KMenuFileSave 13
- #define KMenuFileSaveAs 14
- #define KMenuFileRevert 15
-
- #define KMenuEditUndo 4
- #define KMenuEditCut 5
- #define KMenuEditCopy 6
- #define KMenuEditPaste 7
- #define KMenuEditClear 8
-
- #define KMenuWindowTile 9
- #define KMenuWindowCascade 10
- #define KMenuWindowArrange 11
- #define KMenuWindowList 12 // marker
-
- /************************************************************************/
- /* */
- /* Internal broadcasted messages */
- /* */
- /************************************************************************/
-
- /* KEventPrePeriodic (broadcast)
- *
- * This message is sent periodically to the entire system before
- * and after the event loop is executed; this gives the system a
- * change to do periodic things.
- *
- * Arguments:
- * long arg 0
- * void *parg NULL
- */
-
- #define KEventPrePeriodic 'prei'
-
- /* KEventPostPeriodic (broadcast)
- *
- * This message is sent periodically to the entire system before
- * and after the event loop is executed; this gives the system a
- * change to do periodic things.
- *
- * Arguments:
- * long arg 0
- * void *parg NULL
- */
-
- #define KEventPostPeriodic 'post'
-
- /* KEventAppActivate
- *
- * This message is broadcast when the application is activated.
- * When the application starts up, it is normally active; this (and
- * the one following) are sent to indicate when the application goes
- * inactive and back
- *
- * Arguments:
- * long arg 0
- * void *parg NULL
- */
-
- #define KEventAppActivate 'appa'
-
- /* KEventAppDeactivate
- *
- * This is broadcast to indicate the application has been deactivated
- *
- * Arguments:
- * long arg 0
- * void *parg NULL
- */
-
- #define KEventAppDeactivate 'appd'
-
- /* KEventIdle (dispatch)
- *
- * Idle event; this is the event sent to the current focus to
- * do idle events, like flashing a cursor
- *
- * Arguments:
- * long arg 0
- * void *parg NULL
- */
-
- #define KEventIdle 'idle'
-
- /* KEventDoMenuCommand (dispatch)
- *
- * This is sent to the current focus when a menu event happens.
- * This should return 1 if the menu command is performed, and 0 if not.
- *
- * Arguments:
- * long arg menu command ID
- * void *parg NULL
- */
-
- #define KEventDoMenuCommand 'menu'
-
- /* KEventGetMenuStatus (dispatch)
- *
- * This is sent to the current focus to figure out what is the
- * current status of this menu item. This gets the checked state and
- * the enabled state of this menu command
- *
- * Arguments:
- * long arg menu command ID
- * void *parg pointer to structure which contains flags
- */
-
- #define KEventGetMenuStatus 'msta'
-
- struct XGSMenuStatusRecord {
- bool enable; /* true == enabled */
- bool checked; /* true == checked */
- char checkchar; /* if nonzero, alt checkmark */
- };
-
- /* KEventKey (dispatch)
- *
- * This is a keyboard event. The various special keys are indicated
- * by setting the modifier flags correctly
- *
- * Arguments:
- * long arg hi word: modifiers, lo word: key code
- * void *parg NULL
- */
-
- #define KEventKey 'key '
-
- /* KEventWindowName (dispatch)
- *
- * This event is sent upwards when a window is renamed. This gives
- * the objects above which are maintaining a window menu to update it's
- * contents
- *
- * Arguments:
- * long arg 0
- * void *parg pointer to XGWindow class (window already renamed)
- */
-
- #define KEventWindowName 'namw'
-
- /* KEventWindowCreate (dispatch)
- *
- * This event is sent when a window is created
- *
- * Arguments:
- * long arg 0
- * void *parg pointer to XGWindow class (window already created)
- *
- * NOTE:
- * return values: If the window is not to be created, throw error
- */
-
- #define KEventWindowCreate 'crew'
-
- /* KEventWindowPreDestroy (dispatch)
- *
- * This event is sent when a window is about to be destroyed
- *
- * Arguments:
- * long arg 0
- * void *parg pointer to XGWindow class (window not yet destroyed)
- *
- * NOTE:
- * return values: If the window is not to be destroyed, throw error
- */
-
- #define KEventWindowPreDestroy 'pdsw'
-
- /* KEventWindowDestroy (dispatch)
- *
- * This event is sent when the window is destroyed
- *
- * Arguments:
- * long arg 0
- * void *parg pointer to XGWindow class (window not yet destroyed)
- */
-
- #define KEventWindowDestroy 'desw'
-
- /* KEventDialogMessage
- *
- * This is really not dispatched, but this is a dialog message.
- * This is a dialog message which specifies initialization, destruction,
- * or other messages specific to dialog processing.
- *
- * Arguments:
- * long arg see below
- * void *parg NULL
- */
-
- #define KEventDialogMessage 'dlog'
-
- #define KEventDMInitDialog 1
- #define KEventDMEndDialog 2
-
-
- /* KEventWInternal (dispatch, WinOS only)
- *
- * This indicates that either a scrollbar event or a control message
- * from a windows control was received.
- *
- * In these cases, the message is stuffed into the structure specified
- * below, and the message is passed to the view which owns the scroll
- * bar or the control that was hit. This allows the WinOS version of the
- * windows library to translate the internal message into the YAAF
- * library message that I expect.
- *
- * Arguments:
- * long arg 0
- * void *parg pointer to message structure below
- *
- * Windows messages which are handled in this way are:
- *
- * WM_HSCROLL Scrollbar message
- * WM_VSCROLL Scrollbar message
- * WM_COMMAND Miscellaneous control messages (that are not
- * meuu or accelerator messages)
- */
-
- #if OPT_WINOS == 1
-
- #define KEventWInternal 'wint'
-
- struct XGSWInternalRecord {
- HWND w;
- UINT msg;
- WPARAM wp;
- LPARAM lp;
- };
-
- #endif
-
- /************************************************************************/
- /* */
- /* Event Constants */
- /* */
- /************************************************************************/
-
- /*
- * Keyboard modifier arguments
- */
-
- #define KKeyShift 0x0001
- #define KKeyControl 0x0002
-
- #if OPT_MACOS == 1
- # define KKeyCommand 0x0004
- # define KKeyOption 0x0008
- #endif
-
- #if OPT_WINOS == 1
- # define KKeyMenu 0x0008
- #endif
-
- #define KKeyButton 0x0010
-
- #if OPT_WINOS == 1
- # define KKeyRButton 0x0020
- # define KKeyMButton 0x0040
- #endif
-
- #define KDoubleClick 0x0100
- #define KCapturedMouse 0x0200
- #define KSpecialKey 0x8000
-
- /*
- * Special keys (if KSpecialKey bit set)
- */
-
- #define KKeyUpCursor 128
- #define KKeyDownCursor 129
- #define KKeyLeftCursor 130
- #define KKeyRightCursor 131
- #define KKeyInsert 132
- #define KKeyDelete 133
- #define KKeyHome 134
- #define KKeyEnd 135
- #define KKeyPageUp 136
- #define KKeyPageDown 137
- #define KKeyEscape 138
- #define KKeyHelp 139
- #define KKeyNumLock 140
- #define KKeyClear 141
-
- #define KKeyF1 160
- #define KKeyF2 161
- #define KKeyF3 162
- #define KKeyF4 163
- #define KKeyF5 164
- #define KKeyF6 165
- #define KKeyF7 166
- #define KKeyF8 167
- #define KKeyF9 168
- #define KKeyF10 169
- #define KKeyF11 170
- #define KKeyF12 171
- #define KKeyF13 172
- #define KKeyF14 173
- #define KKeyF15 174
-
- /************************************************************************/
- /* */
- /* Dispatch Method */
- /* */
- /************************************************************************/
-
- /*
- * Forwards
- */
-
- class XGDispatch;
-
- /* XGFocus
- *
- * This is the class which holds the focus for this object. Each
- * window and the main application are both descendant from the focus
- * object; this is the place from where messages are sent.
- */
-
- class XGFocus {
- public:
- XGFocus(XGDispatch *x);
- virtual ~XGFocus();
-
- /*
- * Focus manipulation routines
- */
-
- void _SetFocus(XGDispatch *x);
- void _ClearFocus();
- XGDispatch *GetFocus()
- {
- return fFocus;
- }
-
- /*
- * Send messages
- */
-
- long SendDispatch(long m,long i,void *p);
- private:
- XGDispatch *fDefault;
- XGDispatch *fFocus;
- };
-
- /* XGDispatch
- *
- * This is the dispatch method.
- */
-
- class XGDispatch {
- public:
- XGDispatch();
- virtual ~XGDispatch();
-
- /*
- * Focus
- *
- * The focus is the first dispatch object to receive
- * *all* messages that are being dispatched to the XGDispatch
- * hierarchy. This is a global resource, though the window
- * management tools have a good go at it.
- */
-
- virtual XGDispatch *SetFocus(void); /* Set focus to me */
-
- virtual bool HasFocus(void); /* Do I have focus? */
- virtual void GainFocus(void); /* I've got focus */
- virtual void LoseFocus(void); /* I no longer have it */
-
- /*
- * Default tree top
- */
-
- static XGDispatch *GetDefault(void)
- {
- return gDefault;
- }
- static void SetDefault(XGDispatch *x)
- {
- gDefault = x;
- }
-
- /*
- * Message dispatch
- */
-
- virtual long ReceiveDispatch(long,long,void *);
-
- /*
- * Magic internal stuff to initialize the focus pointers
- */
-
- void _SetFocusDispatch(XGFocus *x)
- {
- fFocus = x;
- }
- static void _SetCTorParentDispatch(XGDispatch *x)
- {
- gParent = x;
- }
-
- private:
- static XGDispatch *gParent;
- static XGDispatch *gDefault;
- XGDispatch *fParent;
- XGFocus *fFocus;
- };
-
- /************************************************************************/
- /* */
- /* Broadcast Method */
- /* */
- /************************************************************************/
-
- /* _PostRecord
- *
- * This is how posts are actually stored
- */
-
- struct _PostRecord {
- long msg;
- long arg;
- void *parg;
- };
-
- /* XGBroadcast
- *
- * This is a bit misnamed--this actually receives global broadcasts
- */
-
- class XGBroadcast {
- public:
- XGBroadcast(void);
- virtual ~XGBroadcast();
-
- /*
- * Message dispatch
- */
-
- virtual void ReceiveBroadcast(long,long,void *);
- static void SendBroadcast(long,long,void *);
- static void PostBroadcast(long,long,void *);
-
- static void _SendPost(void);
- private:
- static XGBroadcast *gList;
- XGBroadcast *fNext;
-
- static XGDynArray<_PostRecord> gPostStack;
- };
-
-
- /************************************************************************/
- /* */
- /* Send/Recieve Methods */
- /* */
- /************************************************************************/
-
- /*
- * Class forwards
- */
-
- class XGSend;
- class XGReceive;
-
- /* XGSend
- *
- * This is part of a send/receive pair; this is the thing that
- * sends messages
- */
-
- class XGSend {
- public:
- XGSend(void);
- virtual ~XGSend();
-
- /*
- * Receiver management
- */
-
- void AddReceiver(XGReceive *);
- void RemoveReceiver(XGReceive *);
-
- /*
- * Message dispatch
- */
-
- void SendMessage(long,long,void *);
-
- private:
- XGDynArray<XGReceive *> fReceive;
- };
-
- /* XGReceive
- *
- * Receiver
- */
-
- class XGReceive {
- public:
- XGReceive();
- virtual ~XGReceive();
-
- /*
- * Receiver
- */
-
- virtual void ReceiveMessage(long,long,void *);
-
- private:
- XGDynArray<XGSend *> fSend;
-
- friend class XGSend;
- };
-
- #if defined(__MWERKS__)
- #if defined(macintosh)
- #pragma options align=reset
- #endif
- #if defined(__INTEL__)
- #pragma pack(pop)
- #endif
- #endif
-
-
- #endif /* __XEVENT_H__ */
-