InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IEventDispatcher.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: ?
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __IEventDispatcher__
25 #define __IEventDispatcher__
26 
27 #include "IPMUnknown.h"
28 #include "ShuksanID.h"
29 #include "IEvent.h"
30 
31 class IEventHandler;
32 class IEventWatcher;
33 
38 class IEventDispatcher : public IPMUnknown {
39 public:
41  enum { kDefaultIID = IID_IEVENTDISPATCHER };
42 
44  enum PushWhere { kPushOnTop, kPushOnBottom };
45 
51  virtual void Push(IEventHandler *newHandler, PushWhere pushWhere = kPushOnTop ) = 0;
52 
56  virtual void Remove(IEventHandler *ehToRemove) = 0;
57 
62  virtual IEventHandler *Peek(int32 ehIndex = 0) const = 0;
63 
67  virtual int32 Depth() const = 0;
68 
72  virtual void Init() = 0;
73 
77  virtual void CleanUp() = 0;
78 
84  virtual bool16 DispatchEvent(IEvent *theEvent, IEvent::SystemHandledState initialState = IEvent::kShouldCall) = 0;
85 
86 #define ITERATOR_ACCESS_TO_EventTypeList 0
87 #if 0 //VC can't cope with this
88  //Essentially a way of declaring classes derived from IEventDispatcher as
89  //friends of class EventTypeList--Hence if class EventTypeList gets reimplemented
90  //so must, e.g., CEventDispatcher.
91  class EventTypeList;
92  protected: static uint32 GetEventTypeListContents( EventTypeList l){ return l.fContents;}
93 #endif
94 
95 
96 public:
97  class EventTypeList {
98 #if 0 //VC can't cope with this
99  friend uint32 IEventDispatcher::GetEventTypeListContents( EventTypeList l);
100 #endif
101  public:
102  enum {kMaxEventTypeValue = 31};
103  EventTypeList(){
104  fContents = kAllEventTypes;
105  }
107  fContents = 1<<t;
108  }
110  fContents = 1<<t1 | 1<<t2;
111  }
113  fContents = 1<<t1 | 1<<t2 | 1<<t3;
114  }
115  EventTypeList& Add( IEvent::EventType t){ //you can chain Add calls if interested in more than 3 event types
116  fContents |= 1<<t;
117  return *this;
118  }
119  EventTypeList& operator|=(EventTypeList l){ fContents |= l.fContents; return *this;}
120  EventTypeList& operator&=(EventTypeList l){ fContents &= l.fContents; return *this;}
121  EventTypeList operator~() const { return EventTypeList(kAllEventTypes & ~fContents);}
122  //could be nonmember friend inline EventTypeList operator~( const EventTypeList& l){ return EventTypeList(~l.fContents);}
123  bool16 Contains(IEvent::EventType t){ return (fContents & (1<<t)) != 0;}
124  bool16 Empty(){ return fContents == 0;}
125 #if ITERATOR_ACCESS_TO_EventTypeList
126  class const_iterator {
127  public:
128  const_iterator() {}
129  const_iterator(const EventTypeList::const_iterator& x) : next(x.next), rest(x.rest) {}
130  IEvent::EventType operator * () const { return static_cast<IEvent::EventType>(next);}
131  const_iterator& operator++()
132  {
133  do{
134  ++next;
135  }while( (rest >>= 1) && !(rest&1));
136  return *this;
137  }
138  const_iterator operator++(int) {const_iterator old(*this); operator++(); return old;}
139  friend bool operator==(const_iterator x, const_iterator y) { return x.rest == y.rest;}
140  friend bool operator!=(const_iterator x, const_iterator y) { return x.rest != y.rest;}
141 
142  private:
143  const_iterator(uint32 contents) : next(0), rest(contents)
144  {
145  if(!(rest&1))
146  ++*this;
147  }
148  friend class EventTypeList;
149  uint32 next;
150  uint32 rest;
151 
152  };
153  const_iterator begin() const { return const_iterator(fContents);}
154  const_iterator end() const {return const_iterator(0);}
155 #endif
156 
157  private:
158  EventTypeList(uint32 contents) : fContents(contents){}
159 //VC can't cope with this: static const uint32 kAllEventTypes = (uint32(1)<<IEvent::kEndOfEventTypes) - 2;// subtract 1 to turn on all the bits, subtract another 1 to turn off the low order one
160  enum {kAllEventTypes = (uint32(1)<<IEvent::kEndOfEventTypes) - 2};// subtract 1 to turn on all the bits, subtract another 1 to turn off the low order one
161  uint32 fContents;
162  };
163 
164  virtual void AddEventWatcher( IEventWatcher *newWatcher, EventTypeList interest) = 0;
165  virtual void AddEventWatcher( IEventWatcher *newWatcher, IEvent::EventType interest) = 0;
166  virtual void RemoveEventWatcher( IEventWatcher *newWatcher, EventTypeList interest) = 0;
167  virtual void RemoveEventWatcher( IEventWatcher *newWatcher, IEvent::EventType interest) = 0;
168  virtual void StopAllEventWatchers() = 0;
169 
170 };
171 
172 
173 #endif // __IEventDispatcher__