home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Venus 3.5 / EventHandlers.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-02  |  2.7 KB  |  82 lines  |  [TEXT/CWIE]

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *
  5.  *                        Event Handler Classes
  6.  *        
  7.  *
  8.  ***********************************************************************
  9.  */
  10.  
  11. #if 0
  12.                                 // Registering handler for the null events
  13.                                 // It's an abstract class. You need to subclass
  14.                                 // it and define your own null event handler
  15. class NullEventHandler
  16. {
  17.   friend class EventHandler;
  18.   const long event_timeout;                    // For WaitNextEvent, set pacing for null events
  19.   static NullEventHandler * first_handler;
  20.     // NullEventHandler * prev_handler;    // We don't chain null event handlers at
  21.                                         // present. But this is in case we will
  22.                                         // in the future
  23.  
  24.                                     // Takes the time (in ticks) when the null
  25.                                     // event was received. Return FALSE to
  26.                                     // quit
  27.   virtual Boolean handle_null_event(const long event_time) = 0;
  28.  
  29. public:
  30.                                     // No chaining at the moment
  31.   NullEventHandler(void)  : first_handler(this) {}
  32.   ~NullEventHandler(void) : first_handler(nil)   {}
  33. };
  34.  
  35. Events.h
  36.  
  37. #endif
  38.  
  39.                                     // Obviously this event handler assumes that an
  40.                                     // application has the _only_ one window
  41.                                     // to handle events for.
  42.                                     // It's a very primitive case, but that'll be
  43.                                     // enough
  44.                                     // It's kind of silly to define a class for the
  45.                                     // sake of only one method, loop(), which may well
  46.                                     // be just a regular function. It'll pay off later
  47.                                     // when we're going to have more than one window
  48.                                     // to take care of
  49. class ScreenWindow;
  50. class EventHandler
  51. {
  52.   EventRecord the_event;
  53.   const long event_timeout;                // waiting for the next event
  54.   ScreenWindow& serviced_window;
  55.   
  56.   static bool putback_pending;            // a buffer to store a put-back event
  57.   static EventRecord putback_event;        // (to be retrieved later)
  58.   
  59. public:
  60.                                       // A wrap around WaitNextEvent() to take care
  61.                                       // of put-back events, and to transparently
  62.                                       // process high-level events
  63.   static bool wait_next_event(EventRecord& event, const int timeout);
  64.   static void flush_side_events(void);    // Take care of a SIOUX console if any
  65.  
  66.  
  67.   EventHandler(ScreenWindow& window_to_serve, const long _event_timeout=5)
  68.     : serviced_window(window_to_serve), event_timeout(_event_timeout) {}
  69.   void loop(void);
  70.   
  71.   enum { mykind = 128 };                    // The kind of _my_ events
  72.   enum { zoom_requested, resize_requested, start_requested, open_picture, 
  73.            quit_requested };                    // My event modifiers
  74.   
  75.                                           // putting an event back into the "event queue"
  76.   static void put_back(const EventRecord& event);
  77.   static void put_back_my_event(const EventModifiers modifiers, const UInt32 message, const Point where);
  78.   static void put_back_my_event(const EventModifiers modifiers, const UInt32 message = 0);
  79. };
  80.  
  81.  
  82.