home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / EVENTHAN.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  5.5 KB  |  173 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1992, 1993 by Borland International
  3. //   include\owl\eventhan.h
  4. //   TEventHandler and related classes & macros
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_EVENTHAN_H)
  7. #define __OWL_EVENTHAN_H
  8.  
  9. #include <limits.h>
  10. #include <owl\signatur.h>
  11. #include <owl\dispatch.h>
  12.  
  13. #if defined(__TRACE) || defined(__WARN)
  14.   //
  15.   // class/operator which converts a Windows message to its string equivalent
  16.   //
  17.   class _EXPCLASS ostream;
  18.   class _OWLCLASS MsgName {
  19.     public:
  20.       friend ostream& operator <<(ostream& os, const MsgName& msg);
  21.       MsgName(UINT msg) : Message(msg) {}
  22.     private:
  23.       UINT Message;
  24.   };
  25. #endif
  26.  
  27. #if defined(OWLRTFAR)
  28.   #define __RTFAR  far
  29. #else
  30.   #define __RTFAR
  31. #endif
  32.  
  33. //
  34. // messages defined for OWL use - the top of the user range of ids is reserved
  35. //
  36. #define WM_OWLLAST        0x7FFF
  37. #define WM_OWLFIRST       (WM_OWLLAST - 0x03FF)
  38.  
  39. #define WM_COMMAND_ENABLE (WM_OWLLAST - 0)
  40. #define WM_CHILDINVALID   (WM_OWLLAST - 1)
  41. #define WM_OWLDOCUMENT    (WM_OWLLAST - 2)
  42. #define WM_OWLVIEW        (WM_OWLLAST - 3)
  43. #define WM_OWLNOTIFY      (WM_OWLLAST - 4)
  44. #define WM_OWLPREPROCMENU (WM_OWLLAST - 5)
  45. #define WM_OWLCANCLOSE    (WM_OWLLAST - 6)
  46. #define WM_VBXNAME        (WM_OWLLAST - 7)
  47. #define WM_VBXBASE        (WM_OWLLAST - 7 - 256)
  48.  
  49. template <class T> class TResponseTableEntry;  // forward declaration
  50. typedef TResponseTableEntry<GENERIC>  TGenericTableEntry;
  51.  
  52. //
  53. //  class TEventHandler
  54. //  ----- -------------
  55. //  base class from which to derive classes that can handle events
  56. //
  57. class _OWLCLASS __rtti TEventHandler {
  58.   public:
  59.     class TEventInfo {
  60.       public:
  61.         const UINT                  Msg;
  62.         const UINT                  Id;
  63.         GENERIC*                    Object;
  64.         TGenericTableEntry __RTFAR* Entry;
  65.  
  66.         TEventInfo(UINT msg, UINT id = 0) : Msg(msg), Id(id) {Entry = 0;}
  67.     };
  68.     typedef BOOL(*TEqualOperator)(TGenericTableEntry __RTFAR&, TEventInfo&);
  69.  
  70.     //
  71.     // searches the list of response table entries looking for a match
  72.     //
  73.     // since class TEventHandler doesn't have any entries, this routine just
  74.     // returns FALSE
  75.     //
  76.     virtual BOOL     Find(TEventInfo& info, TEqualOperator op = 0);
  77.  
  78.     virtual LRESULT  Dispatch(TEventInfo& info, WPARAM wp, LPARAM lp = 0);
  79.  
  80.   protected:
  81.     BOOL             SearchEntries(TGenericTableEntry __RTFAR* entries,
  82.                                    TEventInfo& info,
  83.                                    TEqualOperator op);
  84. };
  85.  
  86. //
  87. //  template class TResponseTableEntry
  88. //  -------- ----- -------------------
  89. //  entries into a response table
  90. //
  91. template <class T> class TResponseTableEntry {
  92.   public:
  93.     typedef void (T::*PMF)();
  94.  
  95.     union {
  96.       UINT          Msg;
  97.       UINT          NotifyCode;
  98.     };
  99.     UINT            Id;
  100.     TAnyDispatcher  Dispatcher;
  101.     PMF             Pmf;
  102. };
  103.  
  104. //
  105. // macros to declare a response table
  106. //
  107. #define DECLARE_RESPONSE_TABLE(cls)\
  108.   private:\
  109.     static TResponseTableEntry< cls > __RTFAR __entries[];\
  110.     typedef TResponseTableEntry< cls >::PMF   TMyPMF;\
  111.     typedef cls                               TMyClass;\
  112.   public:\
  113.     BOOL  Find(TEventInfo&, TEqualOperator = 0)
  114.  
  115. #define END_RESPONSE_TABLE\
  116.   {0, 0, 0, 0}}
  117.  
  118. #define DEFINE_RESPONSE_TABLE_ENTRIES(cls)\
  119.   TResponseTableEntry< cls > __RTFAR  cls::__entries[] = {
  120.  
  121. //
  122. // macro to define a response table for a class with no base response tables
  123. //
  124. // you use it like this:
  125. //    DEFINE_RESPONSE_TABLE(cls)
  126. //      EV_WM_PAINT,
  127. //      EV_WM_LBUTTONDOWN,
  128. //    END_RESPONSE_TABLE;
  129. //
  130. #define DEFINE_RESPONSE_TABLE(cls)\
  131.   BOOL  cls::Find(TEventInfo& eventInfo, TEqualOperator equal)\
  132.       {eventInfo.Object = (GENERIC*)this;\
  133.        return SearchEntries((TGenericTableEntry __RTFAR*)__entries, eventInfo, equal);}\
  134.   DEFINE_RESPONSE_TABLE_ENTRIES(cls)
  135.  
  136. //
  137. // macro to define a response table for a class with one base. use this macro
  138. // exactly like macro DEFINE_RESPONSE_TABLE
  139. //
  140. #define DEFINE_RESPONSE_TABLE1(cls, base)\
  141.   BOOL  cls::Find(TEventInfo& eventInfo, TEqualOperator equal)\
  142.       {eventInfo.Object = (GENERIC*)this;\
  143.        return SearchEntries((TGenericTableEntry __RTFAR*)__entries, eventInfo, equal) ||\
  144.               base::Find(eventInfo, equal);}\
  145.   DEFINE_RESPONSE_TABLE_ENTRIES(cls)
  146.  
  147. //
  148. // macro to define a response table for a class with two bases. use this macro
  149. // exactly like macro DEFINE_RESPONSE_TABLE
  150. //
  151. #define DEFINE_RESPONSE_TABLE2(cls, base1, base2)\
  152.   BOOL  cls::Find(TEventInfo& eventInfo, TEqualOperator equal)\
  153.       {eventInfo.Object = (GENERIC*)this;\
  154.        return SearchEntries((TGenericTableEntry __RTFAR*)__entries, eventInfo, equal) ||\
  155.               base1::Find(eventInfo, equal) ||\
  156.               base2::Find(eventInfo, equal);}\
  157.   DEFINE_RESPONSE_TABLE_ENTRIES(cls)
  158.  
  159. //
  160. // macro to define a response table for a class with three bases. use this macro
  161. // exactly like macro DEFINE_RESPONSE_TABLE
  162. //
  163. #define DEFINE_RESPONSE_TABLE3(cls, base1, base2, base3)\
  164.   BOOL  cls::Find(TEventInfo& eventInfo, TEqualOperator equal)\
  165.       {eventInfo.Object = (GENERIC*)this;\
  166.        return SearchEntries((TGenericTableEntry __RTFAR*)__entries, eventInfo, equal) ||\
  167.               base1::Find(eventInfo, equal) ||\
  168.               base2::Find(eventInfo, equal) ||\
  169.               base3::Find(eventInfo, equal);}\
  170.   DEFINE_RESPONSE_TABLE_ENTRIES(cls)
  171.  
  172. #endif  // __OWL_EVENTHAN_H
  173.