The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dispatcher.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef GUI_WIDGETS_AUXILIARY_EVENT_DISPATCHER_HPP_INCLUDED
16 #define GUI_WIDGETS_AUXILIARY_EVENT_DISPATCHER_HPP_INCLUDED
17 
20 #include "sdl/compat.hpp"
22 
23 #include <SDL_events.h>
24 
25 #include "utils/functional.hpp"
26 #include <boost/mpl/int.hpp>
27 #include <boost/utility/enable_if.hpp>
28 
29 #include <map>
30 
31 namespace gui2
32 {
33 
34 struct tpoint;
35 class twidget;
36 
37 namespace event
38 {
39 
40 struct tmessage;
41 
42 /**
43  * Callback function signature.
44  *
45  * There are several kinds of callback signature, this only has the parameters
46  * shared by all callbacks.
47  *
48  * This function is used for the callbacks in tset_event.
49  */
50 typedef std::function<void(
51  tdispatcher& dispatcher, const tevent event, bool& handled, bool& halt)>
53 
54 /**
55  * Callback function signature.
56  *
57  * This function is used for the callbacks in tset_event_mouse.
58  */
59 typedef std::function<void(tdispatcher& dispatcher,
60  const tevent event,
61  bool& handled,
62  bool& halt,
63  const tpoint& coordinate)> tsignal_mouse_function;
64 
65 /**
66  * Callback function signature.
67  *
68  * This function is used for the callbacks in tset_event_keyboard.
69  */
70 typedef std::function<void(tdispatcher& dispatcher,
71  const tevent event,
72  bool& handled,
73  bool& halt,
74  const SDLKey key,
75  const SDLMod modifier,
76  const utf8::string& unicode)>
78 
79 /**
80  * Callback function signature.
81  *
82  * This function is used for the callbacks in tset_event_notification.
83  * Added the dummy void* parameter which will be nullptr to get a different
84  * signature as tsignal_function's callback.
85  */
86 typedef std::function<void(tdispatcher& dispatcher,
87  const tevent event,
88  bool& handled,
89  bool& halt,
91 
92 /**
93  * Callback function signature.
94  *
95  * This function is used for the callbacks in tset_message_notification.
96  */
97 typedef std::function<void(tdispatcher& dispatcher,
98  const tevent event,
99  bool& handled,
100  bool& halt,
102 
103 /** Hotkey function handler signature. */
104 typedef std::function<bool(tdispatcher& dispatcher,
106 
107 /**
108  * Base class for event handling.
109  *
110  * A dispatcher has slots for events, when an event arrives it looks for the
111  * functions that registered themselves for that event and calls their
112  * callbacks.
113  *
114  * This class is a base class for all widgets[1], what a widget does on a
115  * callback can differ greatly, an image might ignore all events a window can
116  * track the mouse location and fire MOUSE_ENTER and MOUSE_LEAVE events to the
117  * widgets involved.
118  *
119  * [1] Not really sure whether it will be a base clase for a twidget or
120  * tcontrol yet.
121  */
123 {
125 
126 public:
127  tdispatcher();
128  virtual ~tdispatcher();
129 
130  /**
131  * Connects the dispatcher to the event handler.
132  *
133  * When a dispatcher is connected to the event handler it will get the
134  * events directly from the event handler. This is wanted for top level
135  * items like windows but not for most other widgets.
136  *
137  * So a window can call connect to register itself, it will automatically
138  * disconnect upon destruction.
139  */
140  void connect();
141 
142  /**
143  * Determines whether the location is inside an active widget.
144  *
145  * This is used to see whether a mouse event is inside the widget.
146  *
147  * @param coordinate The coordinate to test whether inside the
148  * widget.
149  *
150  * @result True if inside an active widget, false
151  * otherwise.
152  */
153  virtual bool is_at(const tpoint& coordinate) const = 0;
154 
155  enum tevent_type {
156  pre = 1,
157  child = 2,
158  post = 4
159  };
160 
161  bool has_event(const tevent event, const tevent_type event_type);
162 
163  /** Fires an event which has no extra parameters. */
164  bool fire(const tevent event, twidget& target);
165 
166  /**
167  * Fires an event which takes a coordinate parameter.
168  *
169  * @param event The event to fire.
170  * @param target The widget that should receive the event.
171  * @param coordinate The mouse position for the event.
172  */
173  bool fire(const tevent event, twidget& target, const tpoint& coordinate);
174 
175  /**
176  * Fires an event which takes keyboard parameters.
177  *
178  * @param event The event to fire.
179  * @param target The widget that should receive the event.
180  * @param key The SDL key code of the key pressed.
181  * @param modifier The SDL key modifiers used.
182  * @param unicode The unicode value for the key pressed.
183  */
184  bool fire(const tevent event,
185  twidget& target,
186  const SDLKey key,
187  const SDLMod modifier,
188  const utf8::string& unicode);
189 
190  /**
191  * Fires an event which takes notification parameters.
192  *
193  * @note the void* parameter is a dummy needed for SFINAE.
194  *
195  * @param event The event to fire.
196  * @param target The widget that should receive the event.
197  */
198  bool fire(const tevent event, twidget& target, void*);
199 
200  /**
201  * Fires an event which takes message parameters.
202  *
203  * @param event The event to fire.
204  * @param target The widget that should receive the event.
205  * Normally this is the window holding the
206  * widget.
207  * @param message The extra information needed for a window
208  * (or another widget in the chain) to handle
209  * the message.
210  */
211  bool fire(const tevent event, twidget& target, tmessage& message);
212 
213  /**
214  * The position where to add a new callback in the signal handler.
215  *
216  * The signal handler has three callback queues:
217  * * pre_child These callbacks are called before a container widget sends it
218  * to the child items. Widgets without children should also use this
219  * queue.
220  * * child The callbacks for the proper child widget(s) are called.
221  * * post_child The callbacks for the parent container to be called after
222  * the child.
223  *
224  * For every queue it's possible to add a new event in the front or in the
225  * back.
226  *
227  * Whether all three queues are executed depend on the whether the
228  * callbacks modify the handled and halt flag.
229  * * When the halt flag is set execution of the current queue stops, when
230  * doing so the handled flag must be set as well.
231  * * When the handled flag is set the events in that queue are executed and
232  * no more queues afterwards.
233  *
234  * Here are some use case examples.
235  * A button that plays a sound and executes an optional user callback:
236  * * The buttons internal click handler is invoked and sets the handled
237  * flag
238  * * The callback installed by the user is in the same queue and gets
239  * executed afterwards.
240  *
241  * A toggle button may or may not be toggled:
242  * * The user inserts a callback, that validates whether the action is
243  * allowed, if not allowed it sets the halt flag (and handled), else
244  * leaves the flags untouched.
245  * * The normal buttons toggle function then might get invoked and if so
246  * sets the handled flag.
247  * * Optionally there is another user callback invoked at this point.
248  */
249  enum tposition {
256  };
257 
258  /**
259  * Connect a signal for callback in tset_event.
260  *
261  * The function uses some boost magic to avoid registering the wrong
262  * function, but the common way to use this function is:
263  * widget->connect_signal<EVENT_ID>(
264  * std::bind(&tmy_dialog::my_member, this));
265  * This allows simply adding a member of a dialog to be used as a callback
266  * for widget without a lot of magic. Note most widgets probably will get a
267  * callback like
268  * connect_signal_mouse_left_click(const tsignal_function& callback)
269  * which hides this function for the average use.
270  *
271  * @tparam E The event the callback needs to react to.
272  * @param signal The callback function.
273  * @param position The position to place the callback.
274  */
275  template <tevent E>
276  typename boost::enable_if<boost::mpl::has_key<tset_event,
277  boost::mpl::int_<E> > >::type
278  connect_signal(const tsignal_function& signal,
279  const tposition position = back_child)
280  {
281  signal_queue_.connect_signal(E, position, signal);
282  }
283 
284  /**
285  * Disconnect a signal for callback in tset_event.
286  *
287  * @tparam E The event the callback was used for.
288  * @param signal The callback function.
289  * @param position The place where the function was added.
290  * Needed remove the event from the right
291  * place. (The function doesn't care whether
292  * was added in front or back.)
293  */
294  template <tevent E>
295  typename boost::enable_if<boost::mpl::has_key<tset_event,
296  boost::mpl::int_<E> > >::type
297  disconnect_signal(const tsignal_function& signal,
298  const tposition position = back_child)
299  {
300  signal_queue_.disconnect_signal(E, position, signal);
301  }
302 
303  /**
304  * Connect a signal for callback in tset_event_mouse.
305  *
306  * @tparam E The event the callback needs to react to.
307  * @param signal The callback function.
308  * @param position The position to place the callback.
309  */
310  template <tevent E>
311  typename boost::enable_if<boost::mpl::has_key<tset_event_mouse,
312  boost::mpl::int_<E> > >::type
313  connect_signal(const tsignal_mouse_function& signal,
314  const tposition position = back_child)
315  {
316  signal_mouse_queue_.connect_signal(E, position, signal);
317  }
318 
319  /**
320  * Disconnect a signal for callback in tset_event_mouse.
321  *
322  * @tparam E The event the callback was used for.
323  * @param signal The callback function.
324  * @param position The place where the function was added.
325  * Needed remove the event from the right
326  * place. (The function doesn't care whether
327  * was added in front or back.)
328  */
329  template <tevent E>
330  typename boost::enable_if<boost::mpl::has_key<tset_event_mouse,
331  boost::mpl::int_<E> > >::type
332  disconnect_signal(const tsignal_mouse_function& signal,
333  const tposition position = back_child)
334  {
335  signal_mouse_queue_.disconnect_signal(E, position, signal);
336  }
337 
338  /**
339  * Connect a signal for callback in tset_event_keyboard.
340  *
341  * @tparam E The event the callback needs to react to.
342  * @param signal The callback function.
343  * @param position The position to place the callback.
344  */
345  template <tevent E>
346  typename boost::enable_if<boost::mpl::has_key<tset_event_keyboard,
347  boost::mpl::int_<E> > >::type
349  const tposition position = back_child)
350  {
351  signal_keyboard_queue_.connect_signal(E, position, signal);
352  }
353 
354  /**
355  * Disconnect a signal for callback in tset_event_keyboard.
356  *
357  * @tparam E The event the callback was used for.
358  * @param signal The callback function.
359  * @param position The place where the function was added.
360  * Needed remove the event from the right
361  * place. (The function doesn't care whether
362  * was added in front or back.)
363  */
364  template <tevent E>
365  typename boost::enable_if<boost::mpl::has_key<tset_event_keyboard,
366  boost::mpl::int_<E> > >::type
368  const tposition position = back_child)
369  {
370  signal_keyboard_queue_.disconnect_signal(E, position, signal);
371  }
372 
373  /**
374  * Connect a signal for callback in tset_event_notification.
375  *
376  * @tparam E The event the callback needs to react to.
377  * @param signal The callback function.
378  * @param position The position to place the callback. Since
379  * the message is send to a widget directly
380  * the pre and post positions make no sense
381  * and shouldn't be used.
382  */
383  template <tevent E>
384  typename boost::enable_if<boost::mpl::has_key<tset_event_notification,
385  boost::mpl::int_<E> > >::type
386  connect_signal(const tsignal_notification_function& signal,
387  const tposition position = back_child)
388  {
389  signal_notification_queue_.connect_signal(E, position, signal);
390  }
391 
392  /**
393  * Disconnect a signal for callback in tset_event_notification.
394  *
395  * @tparam E The event the callback was used for.
396  * @param signal The callback function.
397  * @param position The place where the function was added.
398  * Needed remove the event from the right
399  * place. (The function doesn't care whether
400  * was added in front or back, but it needs
401  * to know the proper queue so it's save to
402  * add with front_child and remove with
403  * back_child. But it's not save to add with
404  * front_child and remove with
405  * front_pre_child)
406  */
407  template <tevent E>
408  typename boost::enable_if<boost::mpl::has_key<tset_event_notification,
409  boost::mpl::int_<E> > >::type
410  disconnect_signal(const tsignal_notification_function& signal,
411  const tposition position = back_child)
412  {
413  signal_notification_queue_.disconnect_signal(E, position, signal);
414  }
415 
416  /**
417  * Connect a signal for callback in tset_event_message.
418  *
419  * @tparam E The event the callback needs to react to.
420  * @param signal The callback function.
421  * @param position The position to place the callback. Since
422  * the message is send to a widget directly
423  * the pre and post positions make no sense
424  * and shouldn't be used.
425  */
426  template <tevent E>
427  typename boost::enable_if<boost::mpl::has_key<tset_event_message,
428  boost::mpl::int_<E> > >::type
429  connect_signal(const tsignal_message_function& signal,
430  const tposition position = back_child)
431  {
432  signal_message_queue_.connect_signal(E, position, signal);
433  }
434 
435  /**
436  * Disconnect a signal for callback in tset_event_message.
437  *
438  * @tparam E The event the callback was used for.
439  * @param signal The callback function.
440  * @param position The place where the function was added.
441  * Needed remove the event from the right
442  * place. (The function doesn't care whether
443  * was added in front or back, but it needs
444  * to know the proper queue so it's save to
445  * add with front_child and remove with
446  * back_child. But it's not save to add with
447  * front_child and remove with
448  * front_pre_child)
449  */
450  template <tevent E>
451  typename boost::enable_if<boost::mpl::has_key<tset_event_message,
452  boost::mpl::int_<E> > >::type
453  disconnect_signal(const tsignal_message_function& signal,
454  const tposition position = back_child)
455  {
456  signal_message_queue_.disconnect_signal(E, position, signal);
457  }
458 
459  /**
460  * The behavior of the mouse events.
461  *
462  * Normally for mouse events there's first checked whether a dispatcher has
463  * captured the mouse if so it gets the event.
464  * If not the dispatcher is searched from the back to the front in the
465  * layers and its behavior is checked.
466  * * none The event is never send to the layer and goes on the the next
467  * layer. This is used for tooltips who might cover a button but a click
468  * on the tooltips should still click the button.
469  * * all The event is always send to this layer and stops the search for a
470  * next layer.
471  * * hit If the mouse is inside the dispatcher area the event is send and
472  * no longer searched further. If not inside tests the last layer.
473  *
474  * If after these tests no dispatcher is found the event is ignored.
475  */
480  };
481 
482  /** Captures the mouse. */
484  {
486  }
487 
488  /** Releases the mouse capture. */
490  {
492  }
493 
494  /***** ***** ***** setters/getters ***** ***** *****/
495 
496  void set_mouse_behavior(const tmouse_behavior mouse_behavior)
497  {
498  mouse_behavior_ = mouse_behavior;
499  }
500 
502  {
503  return mouse_behavior_;
504  }
505 
506  void set_want_keyboard_input(const bool want_keyboard_input)
507  {
508  want_keyboard_input_ = want_keyboard_input;
509  }
510 
512  {
513  return want_keyboard_input_;
514  }
515 
516  /** Helper struct to generate the various signal types. */
517  template <class T>
518  struct tsignal
519  {
521  {
522  }
523 
524  std::vector<T> pre_child;
525  std::vector<T> child;
526  std::vector<T> post_child;
527  };
528 
529  /** Helper struct to generate the various event queues. */
530  template <class T>
532  {
534  {
535  }
536 
537  std::map<tevent, tsignal<T> > queue;
538 
540  const tposition position,
541  const T& signal)
542  {
543  switch(position) {
544  case front_pre_child:
545  queue[event].pre_child.insert(
546  queue[event].pre_child.begin(), signal);
547  break;
548  case back_pre_child:
549  queue[event].pre_child.push_back(signal);
550  break;
551 
552  case front_child:
553  queue[event]
554  .child.insert(queue[event].child.begin(), signal);
555  break;
556  case back_child:
557  queue[event].child.push_back(signal);
558  break;
559 
560  case front_post_child:
561  queue[event].post_child.insert(
562  queue[event].post_child.begin(), signal);
563  break;
564  case back_post_child:
565  queue[event].post_child.push_back(signal);
566  break;
567  }
568  }
569 
571  const tposition position,
572  const T& signal)
573  {
574  /*
575  * The function doesn't differentiate between front and back
576  * position so fall down from front to back.
577  */
578  switch(position) {
579  case front_pre_child:
580  case back_pre_child: {
581  tsignal<T>& signal_queue = queue[event];
582  for(typename std::vector<T>::iterator itor
583  = signal_queue.child.begin();
584  itor != signal_queue.child.end();
585  ++itor) {
586 
587  if(signal.target_type() == itor->target_type()) {
588  signal_queue.child.erase(itor);
589  return;
590  }
591  }
592  } break;
593 
594  case front_child:
595  case back_child: {
596  tsignal<T>& signal_queue = queue[event];
597  for(typename std::vector<T>::iterator itor
598  = signal_queue.child.begin();
599  itor != signal_queue.child.end();
600  ++itor) {
601 
602  if(signal.target_type() == itor->target_type()) {
603  signal_queue.child.erase(itor);
604  return;
605  }
606  }
607  } break;
608 
609  case front_post_child:
610  case back_post_child: {
611  tsignal<T>& signal_queue = queue[event];
612  for(typename std::vector<T>::iterator itor
613  = signal_queue.child.begin();
614  itor != signal_queue.child.end();
615  ++itor) {
616 
617  if(signal.target_type() == itor->target_type()) {
618  signal_queue.child.erase(itor);
619  return;
620  }
621  }
622  } break;
623  }
624  }
625  };
626 
627  /**
628  * Registers a hotkey.
629  *
630  * @todo add a static function register_global_hotkey.
631  *
632  * Once that's done execute_hotkey will first try to execute a global
633  * hotkey and if that fails tries the hotkeys in this dispatcher.
634  *
635  * @param id The hotkey to register.
636  * @param function The callback function to call.
637  */
639  const thotkey_function& function);
640 
641  /**
642  * Executes a hotkey.
643  *
644  * @param id The hotkey to execute.
645  *
646  * @returns true if the hotkey is handled, false
647  * otherwise.
648  */
649  bool execute_hotkey(const hotkey::HOTKEY_COMMAND id);
650 
651 private:
652  /** The mouse behavior for the dispatcher. */
654 
655  /**
656  * Does the dispatcher want to receive keyboard input.
657  *
658  * @todo The entire mouse and keyboard handling can use a code review to
659  * seen whether it might be combined in one flag field. At the moment the
660  * keyboard doesn't look whether a dialog has the mouse focus before
661  * sending the event, so maybe we should add an active dispatcher to keep
662  * track of it. But since at the moment there are only non-modal windows
663  * and tooltips it's not a problem.
664  */
666 
667  /** Signal queue for callbacks in tset_event. */
669 
670  /** Signal queue for callbacks in tset_event_mouse. */
672 
673  /** Signal queue for callbacks in tset_event_keyboard. */
675 
676  /** Signal queue for callbacks in tset_event_notification. */
678 
679  /** Signal queue for callbacks in tset_event_message. */
681 
682  /** Are we connected to the event handler. */
684 
685  /** The registered hotkeys for this dispatcher. */
686  std::map<hotkey::HOTKEY_COMMAND, thotkey_function> hotkeys_;
687 };
688 
689 /***** ***** ***** ***** ***** Common helpers ***** ***** ***** ***** *****/
690 
691 /*
692  * These helpers can be used to easily add callbacks to a dispatcher (widget).
693  * This is just a list of common ones all others can be used as well.
694  */
695 
696 /**
697  * Connects the signal for 'snooping' on the keypress.
698  *
699  * This callback is called before the widget itself allowing you to either
700  * snoop on the input or filter it.
701  */
702 inline void
704  const tsignal_keyboard_function& signal)
705 {
707 }
708 
709 /** Connects a signal handler for a left mouse button click. */
711  const tsignal_function& signal)
712 {
713  dispatcher.connect_signal<LEFT_BUTTON_CLICK>(signal);
714 }
715 
716 /** Disconnects a signal handler for a left mouse button click. */
718  const tsignal_function& signal)
719 {
720  dispatcher.disconnect_signal<LEFT_BUTTON_CLICK>(signal);
721 }
722 
723 /** Connects a signal handler for getting a notification upon modification. */
724 inline void
726  const tsignal_notification_function& signal)
727 {
728  dispatcher.connect_signal<event::NOTIFY_MODIFIED>(signal);
729 }
730 
731 } // namespace event
732 
733 } // namespace gui2
734 
735 #endif
tsignal_queue< tsignal_notification_function > signal_notification_queue_
Signal queue for callbacks in tset_event_notification.
Definition: dispatcher.hpp:677
boost::enable_if< boost::mpl::has_key< tset_event_mouse, boost::mpl::int_< E > > >::type connect_signal(const tsignal_mouse_function &signal, const tposition position=back_child)
Connect a signal for callback in tset_event_mouse.
Definition: dispatcher.hpp:313
void connect_signal_pre_key_press(tdispatcher &dispatcher, const tsignal_keyboard_function &signal)
Connects the signal for 'snooping' on the keypress.
Definition: dispatcher.hpp:703
boost::enable_if< boost::mpl::has_key< tset_event_message, boost::mpl::int_< E > > >::type disconnect_signal(const tsignal_message_function &signal, const tposition position=back_child)
Disconnect a signal for callback in tset_event_message.
Definition: dispatcher.hpp:453
#define SDLMod
Definition: compat.hpp:30
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
void connect_signal(const tevent event, const tposition position, const T &signal)
Definition: dispatcher.hpp:539
Helper struct to generate the various event queues.
Definition: dispatcher.hpp:531
boost::enable_if< boost::mpl::has_key< tset_event_keyboard, boost::mpl::int_< E > > >::type connect_signal(const tsignal_keyboard_function &signal, const tposition position=back_child)
Connect a signal for callback in tset_event_keyboard.
Definition: dispatcher.hpp:348
boost::mpl::set< boost::mpl::int_< DRAW >, boost::mpl::int_< CLOSE_WINDOW >, boost::mpl::int_< MOUSE_ENTER >, boost::mpl::int_< MOUSE_LEAVE >, boost::mpl::int_< LEFT_BUTTON_DOWN >, boost::mpl::int_< LEFT_BUTTON_UP >, boost::mpl::int_< LEFT_BUTTON_CLICK >, boost::mpl::int_< LEFT_BUTTON_DOUBLE_CLICK >, boost::mpl::int_< MIDDLE_BUTTON_DOWN >, boost::mpl::int_< MIDDLE_BUTTON_UP >, boost::mpl::int_< MIDDLE_BUTTON_CLICK >, boost::mpl::int_< MIDDLE_BUTTON_DOUBLE_CLICK >, boost::mpl::int_< RIGHT_BUTTON_DOWN >, boost::mpl::int_< RIGHT_BUTTON_UP >, boost::mpl::int_< RIGHT_BUTTON_CLICK >, boost::mpl::int_< RIGHT_BUTTON_DOUBLE_CLICK > > tset_event
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:209
boost::mpl::set< boost::mpl::int_< SDL_VIDEO_RESIZE >, boost::mpl::int_< SDL_MOUSE_MOTION >, boost::mpl::int_< MOUSE_MOTION >, boost::mpl::int_< SDL_LEFT_BUTTON_DOWN >, boost::mpl::int_< SDL_LEFT_BUTTON_UP >, boost::mpl::int_< SDL_MIDDLE_BUTTON_DOWN >, boost::mpl::int_< SDL_MIDDLE_BUTTON_UP >, boost::mpl::int_< SDL_RIGHT_BUTTON_DOWN >, boost::mpl::int_< SDL_RIGHT_BUTTON_UP >, boost::mpl::int_< SHOW_TOOLTIP >, boost::mpl::int_< SHOW_HELPTIP >, boost::mpl::int_< SDL_WHEEL_UP >, boost::mpl::int_< SDL_WHEEL_DOWN >, boost::mpl::int_< SDL_WHEEL_LEFT >, boost::mpl::int_< SDL_WHEEL_RIGHT > > tset_event_mouse
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:230
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
void connect_signal_notify_modified(tdispatcher &dispatcher, const tsignal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.hpp:725
void set_want_keyboard_input(const bool want_keyboard_input)
Definition: dispatcher.hpp:506
boost::enable_if< boost::mpl::has_key< tset_event, boost::mpl::int_< E > > >::type disconnect_signal(const tsignal_function &signal, const tposition position=back_child)
Disconnect a signal for callback in tset_event.
Definition: dispatcher.hpp:297
void connect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:710
void register_hotkey(const hotkey::HOTKEY_COMMAND id, const thotkey_function &function)
Registers a hotkey.
Definition: dispatcher.cpp:303
std::function< bool(tdispatcher &dispatcher, hotkey::HOTKEY_COMMAND id)> thotkey_function
Hotkey function handler signature.
Definition: dispatcher.hpp:105
Base class for event handling.
Definition: dispatcher.hpp:122
tmouse_behavior mouse_behavior_
The mouse behavior for the dispatcher.
Definition: dispatcher.hpp:653
void capture_mouse()
Captures the mouse.
Definition: dispatcher.hpp:483
boost::enable_if< boost::mpl::has_key< tset_event, boost::mpl::int_< E > > >::type connect_signal(const tsignal_function &signal, const tposition position=back_child)
Connect a signal for callback in tset_event.
Definition: dispatcher.hpp:278
std::function< void(tdispatcher &dispatcher, const tevent event, bool &handled, bool &halt, const SDLKey key, const SDLMod modifier, const utf8::string &unicode)> tsignal_keyboard_function
Callback function signature.
Definition: dispatcher.hpp:77
boost::mpl::set< boost::mpl::int_< MESSAGE_SHOW_TOOLTIP >, boost::mpl::int_< MESSAGE_SHOW_HELPTIP >, boost::mpl::int_< REQUEST_PLACEMENT > > tset_event_message
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:267
bool connected_
Are we connected to the event handler.
Definition: dispatcher.hpp:683
#define SDLKey
Definition: compat.hpp:29
void disconnect_signal(const tevent event, const tposition position, const T &signal)
Definition: dispatcher.hpp:570
A left mouse button click event for a widget.
Definition: handler.hpp:84
std::map< hotkey::HOTKEY_COMMAND, thotkey_function > hotkeys_
The registered hotkeys for this dispatcher.
Definition: dispatcher.hpp:686
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
std::function< void(tdispatcher &dispatcher, const tevent event, bool &handled, bool &halt, tmessage &message)> tsignal_message_function
Callback function signature.
Definition: dispatcher.hpp:101
tsignal_queue< tsignal_message_function > signal_message_queue_
Signal queue for callbacks in tset_event_message.
Definition: dispatcher.hpp:680
bool want_keyboard_input_
Does the dispatcher want to receive keyboard input.
Definition: dispatcher.hpp:665
boost::enable_if< boost::mpl::has_key< tset_event_mouse, boost::mpl::int_< E > > >::type disconnect_signal(const tsignal_mouse_function &signal, const tposition position=back_child)
Disconnect a signal for callback in tset_event_mouse.
Definition: dispatcher.hpp:332
void release_mouse()
Releases the mouse capture.
Definition: dispatcher.hpp:489
std::function< void(tdispatcher &dispatcher, const tevent event, bool &handled, bool &halt, const tpoint &coordinate)> tsignal_mouse_function
Callback function signature.
Definition: dispatcher.hpp:63
bool fire(const tevent event, twidget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:144
bool execute_hotkey(const hotkey::HOTKEY_COMMAND id)
Executes a hotkey.
Definition: dispatcher.cpp:309
Compatibility layer for using SDL 1.2 and 2.0.
boost::enable_if< boost::mpl::has_key< tset_event_notification, boost::mpl::int_< E > > >::type connect_signal(const tsignal_notification_function &signal, const tposition position=back_child)
Connect a signal for callback in tset_event_notification.
Definition: dispatcher.hpp:386
tsignal_queue< tsignal_mouse_function > signal_mouse_queue_
Signal queue for callbacks in tset_event_mouse.
Definition: dispatcher.hpp:671
void connect()
Connects the dispatcher to the event handler.
Definition: dispatcher.cpp:49
std::function< void(tdispatcher &dispatcher, const tevent event, bool &handled, bool &halt)> tsignal_function
Callback function signature.
Definition: dispatcher.hpp:40
tsignal_queue< tsignal_keyboard_function > signal_keyboard_queue_
Signal queue for callbacks in tset_event_keyboard.
Definition: dispatcher.hpp:674
void release_mouse(tdispatcher *dispatcher)
Releases a captured mouse.
Definition: handler.cpp:808
tposition
The position where to add a new callback in the signal handler.
Definition: dispatcher.hpp:249
Send by a widget to notify others its contents or state are modified.
Definition: handler.hpp:133
tevent
The event send to the dispatcher.
Definition: handler.hpp:54
tmouse_behavior get_mouse_behavior() const
Definition: dispatcher.hpp:501
void set_mouse_behavior(const tmouse_behavior mouse_behavior)
Definition: dispatcher.hpp:496
Helper struct to generate the various signal types.
Definition: dispatcher.hpp:518
virtual bool is_at(const tpoint &coordinate) const =0
Determines whether the location is inside an active widget.
std::map< tevent, tsignal< T > > queue
Definition: dispatcher.hpp:537
std::map< std::string, tfilter >::iterator itor
Definition: filter.cpp:199
boost::mpl::set< boost::mpl::int_< NOTIFY_REMOVAL >, boost::mpl::int_< NOTIFY_MODIFIED >, boost::mpl::int_< RECEIVE_KEYBOARD_FOCUS >, boost::mpl::int_< LOSE_KEYBOARD_FOCUS >, boost::mpl::int_< NOTIFY_REMOVE_TOOLTIP >, boost::mpl::int_< SDL_ACTIVATE > > tset_event_notification
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:254
boost::enable_if< boost::mpl::has_key< tset_event_notification, boost::mpl::int_< E > > >::type disconnect_signal(const tsignal_notification_function &signal, const tposition position=back_child)
Disconnect a signal for callback in tset_event_notification.
Definition: dispatcher.hpp:410
boost::enable_if< boost::mpl::has_key< tset_event_keyboard, boost::mpl::int_< E > > >::type disconnect_signal(const tsignal_keyboard_function &signal, const tposition position=back_child)
Disconnect a signal for callback in tset_event_keyboard.
Definition: dispatcher.hpp:367
Holds a 2D point.
Definition: point.hpp:24
void disconnect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Disconnects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:717
void capture_mouse(tdispatcher *dispatcher)
Captures the mouse.
Definition: handler.cpp:801
The message callbacks hold a reference to a message.
Definition: message.hpp:45
std::function< void(tdispatcher &dispatcher, const tevent event, bool &handled, bool &halt, void *)> tsignal_notification_function
Callback function signature.
Definition: dispatcher.hpp:90
tmouse_behavior
The behavior of the mouse events.
Definition: dispatcher.hpp:476
bool has_event(const tevent event, const tevent_type event_type)
Definition: dispatcher.cpp:56
cl_event event
Definition: glew.h:3070
Base class for all widgets.
Definition: widget.hpp:49
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
tsignal_queue< tsignal_function > signal_queue_
Signal queue for callbacks in tset_event.
Definition: dispatcher.hpp:668
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
bool get_want_keyboard_input() const
Definition: dispatcher.hpp:511
A SDL key down event.
Definition: handler.hpp:126
std::string string
GLenum target
Definition: glew.h:5190
boost::mpl::set< boost::mpl::int_< SDL_KEY_DOWN > > tset_event_keyboard
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:238
boost::enable_if< boost::mpl::has_key< tset_event_message, boost::mpl::int_< E > > >::type connect_signal(const tsignal_message_function &signal, const tposition position=back_child)
Connect a signal for callback in tset_event_message.
Definition: dispatcher.hpp:429