Hot Door CORE  0.7.0
Adobe® Illustrator® Plug-in Library
hdicoreDispatcher.h
Go to the documentation of this file.
1 
7 #ifndef __HDI_CORE_DISPATCHER__
8 #define __HDI_CORE_DISPATCHER__
9 
10 #include <vector>
11 
12 #include "hdicoreTypes.h"
13 
14 namespace hdi
15 {
16  namespace core
17  {
18  class Annotator;
19  class Callback;
20  class Message;
21  class Notifier;
22  class Timer;
23  class ToolMessage;
24 
29  class Dispatcher
30  {
31  public:
32  typedef std::vector< Notifier* > NotifierVector;
33 
37  enum Error
38  {
39  NoDispatchError = 0,
40  UnhandledMessageError = 10, // Not a "real error", just that a received message was not handled
41  UnknownMessageTypeError = 20,
42  RedundantMessageReceivedError = 30
43  };
44 
49  {
50  // ==== Locale independent keys ====
51  CommandKey = 10, // Only useful on Mac
52  OptionKey = 20,
53  AltKey = OptionKey,
54  ControlKey = 30,
55  ShiftKey = 40,
56  CapsLockKey = 50,
57 
58  SpaceKey = 110,
59  TabKey = 100,
60  ReturnKey = 120, // Same as enter key; no way to differentiate on all platforms
61 
62  EscapeKey = 200,
63  ClearKey = 210,
64  DeleteKey = 220,
65  ForwardDeleteKey= 230,
66 
67  UpArrowKey = 300,
68  DownArrowKey = 310,
69  LeftArrowKey = 320,
70  RightArrowKey = 330,
71 
72  HomeKey = 400,
73  EndKey = 410,
74  PageUpKey = 420,
75  PageDownKey = 430,
76  HelpKey = 440,
77 
78  F1Key = 500,
79  F2Key = 510,
80  F3Key = 520,
81  F4Key = 530,
82  F5Key = 540,
83  F6Key = 550,
84  F7Key = 560,
85  F8Key = 570,
86  F9Key = 580,
87  F10Key = 590,
88  F11Key = 600,
89  F12Key = 610,
90  F13Key = 620,
91  F14Key = 630,
92  F15Key = 640,
93  F16Key = 650,
94  F17Key = 660,
95  F18Key = 670,
96  F19Key = 680,
97  F20Key = 690,
98 
99  NumPad0Key = 800,
100  NumPad1Key = 810,
101  NumPad2Key = 820,
102  NumPad3Key = 830,
103  NumPad4Key = 840,
104  NumPad5Key = 850,
105  NumPad6Key = 860,
106  NumPad7Key = 870,
107  NumPad8Key = 880,
108  NumPad9Key = 890,
109 
110  NumPadDecimalKey = 1000,
111  NumPadPlusKey = 1010,
112  NumPadMinusKey = 1020,
113  NumPadMultiplyKey = 1030,
114  NumPadDivideKey = 1040,
115  // ==== End locale independent keys ====
116 
117  // ==== Locale dependent keys ====
118  LD_0Key = 2010,
119  LD_1Key = 2020,
120  LD_2Key = 2030,
121  LD_3Key = 2040,
122  LD_4Key = 2050,
123  LD_5Key = 2060,
124  LD_6Key = 2070,
125  LD_7Key = 2080,
126  LD_8Key = 2090,
127  LD_9Key = 2100,
128 
129  LD_AKey = 2110,
130  LD_BKey = 2120,
131  LD_CKey = 2130,
132  LD_DKey = 2140,
133  LD_EKey = 2150,
134  LD_FKey = 2160,
135  LD_GKey = 2170,
136  LD_HKey = 2180,
137  LD_IKey = 2190,
138  LD_JKey = 2200,
139  LD_KKey = 2210,
140  LD_LKey = 2220,
141  LD_MKey = 2230,
142  LD_NKey = 2240,
143  LD_OKey = 2250,
144  LD_PKey = 2260,
145  LD_QKey = 2270,
146  LD_RKey = 2280,
147  LD_SKey = 2290,
148  LD_TKey = 2300,
149  LD_UKey = 2310,
150  LD_VKey = 2320,
151  LD_WKey = 2330,
152  LD_XKey = 2340,
153  LD_YKey = 2350,
154  LD_ZKey = 2360,
155 
156  LD_SlashKey = 2370, // "/" on US keyboard
157  LD_BackslashKey = 2380, // "\" on US keyboard
158 
159  LD_CommaKey = 2390, // "," on US keyboard
160  LD_PeriodKey = 2400, // "." on US keyboard
161  LD_SemicolonKey = 2410, // ";" on US keyboard
162 
163  LD_MinusKey = 2420, // "-" on US keyboard
164  LD_EqualKey = 2430, // "=" on US keyboard
165 
166  LD_LeftBracketKey = 2440, // "[" on US keyboard
167  LD_RightBracketKey = 2450, // "]" on US keyboard
168 
169  LD_GraveKey = 2460, // "`" on US keyboard
170  LD_QuoteKey = 2470 // "'" on US keyboard
171  // ==== End locale dependent keys ====
172  };
173 
188  bool registerMessageCallback(const MessageType type_, const Callback& callback_);
189 
211  const std::string& caller_,
212  const std::string& selector_,
213  const Callback& callback_
214  );
215 
223  void unregisterMessageCallback(const MessageType type_);
224 
236  void unregisterMessageCallback(const std::string& caller_, const std::string& selector_);
237 
252  Error message(const MessageType type_, void* const msg_);
253 
273  Error message(const std::string& caller_, const std::string& selector_, void* const msg_);
274 
292  Message* const lastMessage();
293 
308  ToolMessage* const lastToolMessage();
309 
321  void registerNotifier(const Notifier& notifier_);
322 
333  NotifierVector registeredNotifiersOfType(const NotifierType type_);
334 
343  bool unregisterNotifier(const Notifier& notifier_);
344 
353  void registerTimer(const Timer& timer_);
354 
363  bool unregisterTimer(const Timer& timer_);
364 
373  void scheduleCallback(const Callback& callback_, const double delay_ = 0.0);
374 
383  void registerAnnotator(const Annotator& annotator_);
384 
393  bool unregisterAnnotator(const Annotator& annotator_);
394 
412  uint32_t addKeypressMonitor(const VirtualKey key_, const Callback& cb_);
413 
424  bool getKeypressMonitor(
425  const VirtualKey key_,
426  uint32_t& id__,
427  std::auto_ptr<Callback>& cb__
428  ) const;
429 
437  void removeKeypressMonitor(const uint32_t id_);
438 
439 
440  private:
441  // Only Plugin can construct a Dispatcher object
442  friend class Plugin;
443 
447  void* __data;
448 
454  Dispatcher();
455 
461  Dispatcher(const Dispatcher&);
462 
468  ~Dispatcher();
469 
475  Dispatcher& operator=(const Dispatcher&);
476  };
477  }
478 }
479 
480 #endif
481 // __HDI_CORE_DISPATCHER__
void removeKeypressMonitor(const uint32_t id_)
Removes a keypress monitor previously created with addKeypressMonitor()
bool registerMessageCallback(const MessageType type_, const Callback &callback_)
Registers a new callback for a given message type.
bool getKeypressMonitor(const VirtualKey key_, uint32_t &id__, std::auto_ptr< Callback > &cb__) const
Gets an existing keypress monitor, if any.
Message *const lastMessage()
Gets a Message object that wraps around the last message data received.
Error message(const MessageType type_, void *const msg_)
Notifies the dispatcher of an incoming message, causing it to call the appropriate callback or return...
bool unregisterAnnotator(const Annotator &annotator_)
Unregisters a given annotator.
void registerNotifier(const Notifier &notifier_)
Registers a Notifier object for a given Illustrator notifier subscription.
Base plugin class; the heart of any plugin project.
Definition: hdicorePlugin.h:40
Deals with annotator registration and drawing callbacks.
Definition: hdicoreAnnotator.h:26
Deals with timer registration and callbacks.
Definition: hdicoreTimer.h:28
bool unregisterNotifier(const Notifier &notifier_)
Unregisters a given notifier.
uint32_t addKeypressMonitor(const VirtualKey key_, const Callback &cb_)
Creates an Illustrator-wide keypress monitor that calls a callback when a specific key down event has...
Base class for templated __Callback class.
Definition: hdicoreCallback.h:67
VirtualKey
Describes which keys can be monitored for presses at anytime.
Definition: hdicoreDispatcher.h:48
Header file for a wide variety of necessary typedefs, enums, and forwards declarations.
Error
Describes a variety of dispatch-related errors.
Definition: hdicoreDispatcher.h:37
Received for ToolEditMessageType, ToolTrackMessageType, ToolMouseDownMessageType, ToolMouseDragMessag...
Definition: hdicoreMessage.h:1404
Definition: hdicoreaiArray.h:12
ToolMessage *const lastToolMessage()
Gets the last tool message received, regardless of whether subsequent non-tool messages have been rec...
void registerAnnotator(const Annotator &annotator_)
Registers an Annotator object.
bool unregisterTimer(const Timer &timer_)
Unregisters a given timer.
Base class for all *Message subclasses.
Definition: hdicoreMessage.h:34
Acts as a receiver for specific notifications, passing them along to caller-supplied callbacks...
Definition: hdicoreNotifier.h:21
void registerTimer(const Timer &timer_)
Registers a Timer object.
Class through which all messages ultimately pass; holds registered callbacks for messages, notifiers, timers, etc. and calls them at the proper time.
Definition: hdicoreDispatcher.h:29
void unregisterMessageCallback(const MessageType type_)
Unregisters a callback for a given message type.
void scheduleCallback(const Callback &callback_, const double delay_=0.0)
Executes a given callback after a delay.
NotifierVector registeredNotifiersOfType(const NotifierType type_)
Gets registered notifiers by their type.