home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / hpp.z / WEVENT.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-27  |  6.7 KB  |  208 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by Watcom International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of Watcom International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. /*************************************************************************
  12.  *
  13.  * WEventGenerator -- Base Event class
  14.  *
  15.  *************************************************************************/
  16. #ifndef _WEVENT_HPP_INCLUDED
  17. #define _WEVENT_HPP_INCLUDED
  18.  
  19. #ifndef _WNO_PRAGMA_PUSH
  20. #pragma pack(push,4);
  21. #pragma enum int;
  22. #endif
  23.  
  24. #ifndef _WLLIST_HPP_INCLUDED
  25. #include "wllist.hpp"
  26. #endif
  27.  
  28. #undef WEVENT_DEF
  29. #define WEVENT_DEF( name ) W ## name
  30.  
  31. enum WEventID {
  32.     #include "weventl.hpp"
  33.  
  34.     WEVENT_DEF( MarkerEvent ),
  35.     WLastEvent = WMarkerEvent - 1
  36. };
  37.  
  38. #undef WEVENT_DEF
  39.  
  40. class  WObject;
  41. struct WEventData;
  42.  
  43. /* Define a generic callback type */
  44.  
  45. typedef WBool WCMDEF (WObject::*WEventHandler)( WObject *source,
  46.                                                 WEventData *event );
  47.  
  48.  
  49. /* Define a struct for setting multiple events */
  50.  
  51. struct WEventHandlerList {
  52.     WEventID        eventID;
  53.     WEventHandler   eventHandler;
  54.     WObject        *object;
  55.     void           *userData;
  56. };
  57.  
  58. /* The event class -- an object must inherit from this class
  59.    to be able to set and invoke events */
  60.  
  61. class WCMCLASS WEventGenerator : public WObject {
  62.  
  63.     WDeclareSubclass( WEventGenerator, WObject );
  64.  
  65.     public:
  66.  
  67.         struct event_data {
  68.             wllist_link         link;
  69.             WEventID            id;
  70.             WObject *           object;
  71.             WEventHandler       handler;
  72.             WLong               returns;
  73.             void *              userdata;
  74.         };
  75.  
  76.     protected:
  77.  
  78.         /**************************************************************
  79.          * Constructors and destructors
  80.          **************************************************************/
  81.  
  82.         WEventGenerator();
  83.  
  84.         virtual ~WEventGenerator();
  85.  
  86.         /**************************************************************
  87.          * Properties
  88.          **************************************************************/
  89.  
  90.     public:
  91.  
  92.         /**************************************************************
  93.          * Methods
  94.          **************************************************************/
  95.  
  96.         // CallEventHandler
  97.  
  98.         virtual WBool CallEventHandler( WEventID id,
  99.                                         WObject * object,
  100.                                         WEventData * eventData=NULL,
  101.                                         WLong * retval=NULL,
  102.                                         WInt indexToStartAt=0 ) const;
  103.  
  104.         // EventID
  105.  
  106.         static WEventID EventID( const WChar * name );
  107.  
  108.         // HasEventHandler
  109.  
  110.         virtual WBool HasEventHandler( WEventID id ) const;
  111.  
  112.         // RemoveAllEventHandlers
  113.  
  114.         virtual WBool RemoveAllEventHandlers();
  115.  
  116.         // RemoveEventHandler
  117.  
  118.         virtual WBool RemoveEventHandler( WEventID id,
  119.                                           WBool removeAll=FALSE,
  120.                                           WInt * index=NULL );
  121.         virtual WBool RemoveEventHandler( WEventID id,
  122.                                           WObject * object,
  123.                                           WEventHandler handler,
  124.                                           WInt * index=NULL );
  125.  
  126.         // RemoveEventHandlerList
  127.         //
  128.         //    Remove several events at once from a null-terminated
  129.         //    array of events.  If no object is passed, uses "this"
  130.         //    by default.
  131.  
  132.         WBool RemoveEventHandlerList( WEventHandlerList * list,
  133.                                       WObject * object=NULL );
  134.  
  135.         // SetEventHandlerList
  136.         //
  137.         //    Set several events at once from a null-terminated
  138.         //    array of events.  If no object is passed, uses "this"
  139.         //    by default.
  140.  
  141.         WBool SetEventHandlerList( WEventHandlerList * list,
  142.                                    WObject * object=NULL );
  143.  
  144.         /**************************************************************
  145.          * Item Properties
  146.          **************************************************************/
  147.  
  148.         virtual WBool SetEventHandler( WEventID id, WObject * object,
  149.                                        WEventHandler handler,
  150.                                        void * userdata=NULL,
  151.                                        WInt * index=NULL );
  152.  
  153.         virtual WBool GetEventHandler( WEventID id, WObject ** object,
  154.                                        WEventHandler * handler,
  155.                                        void ** userdata=NULL,
  156.                                        WEventHandler current=NULL ) const;
  157.         /**************************************************************
  158.          * Cache
  159.          **************************************************************/
  160.  
  161.         // FlushCache
  162.  
  163.         static void FlushCache();
  164.  
  165.         // CacheSize
  166.  
  167.         static WULong GetCacheSize();
  168.         static WBool SetCacheSize( WULong newSize );
  169.  
  170.         /**************************************************************
  171.          * Others
  172.          **************************************************************/
  173.  
  174.     protected:
  175.  
  176.         virtual event_data * FindEvent( WEventID id ) const;
  177.  
  178.         virtual WBool FastCallEventHandler( event_data *first,
  179.                                             WObject * object,
  180.                                             WEventData * eventData=NULL,
  181.                                             WLong * retval=NULL,
  182.                                             WInt indexToStartAt=0 ) const;
  183.  
  184.         enum WEventNotice {
  185.             WEventNoticeAdd,
  186.             WEventNoticeRemove,
  187.             WEventNoticeRemoveAll
  188.         };
  189.  
  190.         virtual void EventNotice( WEventID id, WEventNotice type );
  191.  
  192.         /**************************************************************
  193.          * Data members
  194.          **************************************************************/
  195.  
  196.     private:
  197.  
  198.         WULong                  _bitfield : 32;
  199.         wllist_header           _events;
  200. };
  201.  
  202. #ifndef _WNO_PRAGMA_PUSH
  203. #pragma enum pop;
  204. #pragma pack(pop);
  205. #endif
  206.  
  207. #endif // _WEVENT_HPP_INCLUDED
  208.