15 #ifndef GUI_WIDGETS_AUXILIARY_EVENT_DISPATCHER_PRIVATE_HPP_INCLUDED
16 #define GUI_WIDGETS_AUXILIARY_EVENT_DISPATCHER_PRIVATE_HPP_INCLUDED
22 #include <SDL_events.h>
24 #include <boost/mpl/for_each.hpp>
48 #define IMPLEMENT_EVENT_SIGNAL(SET, FUNCTION, QUEUE) \
63 static typename boost::enable_if<boost::is_same<F, FUNCTION>, \
64 tdispatcher::tsignal<FUNCTION> >::type& \
65 event_signal(tdispatcher& dispatcher, const tevent event) \
67 return dispatcher.QUEUE.queue[event]; \
84 static typename boost::enable_if<boost::mpl::has_key<SET, K>, \
85 tdispatcher::tsignal<FUNCTION> >::type& \
86 event_signal(tdispatcher& dispatcher, const tevent event) \
88 return dispatcher.QUEUE.queue[event]; \
103 #define IMPLEMENT_EVENT_SIGNAL_WRAPPER(TYPE) \
104 IMPLEMENT_EVENT_SIGNAL(tset_event_##TYPE, \
105 tsignal_##TYPE##_function, \
106 signal_##TYPE##_queue_)
113 #undef IMPLEMENT_EVENT_SIGNAL_WRAPPER
114 #undef IMPLEMENT_EVENT_SIGNAL
152 && !event_signal<T>(
dispatcher_, event).pre_child.empty()) {
177 template <
bool done = true>
180 template <
typename itor,
typename end,
typename E,
typename F>
191 template <
typename itor,
typename end,
typename E,
typename F>
195 typedef typename boost::mpl::apply1<boost::mpl::identity<>, item>
::type
198 boost::value_initialized<arg>
x;
202 return functor.template oper<item>(
event);
206 static_cast<titor*>(
nullptr),
207 static_cast<end*>(
nullptr),
236 template <
typename sequence,
typename E,
typename F>
243 static_cast<begin*>(
nullptr), static_cast<end*>(
nullptr), event, functor);
298 inline std::vector<std::pair<twidget*, tevent> >
304 std::vector<std::pair<twidget*, tevent> >
result;
306 while(widget != dispatcher) {
307 widget = widget->
parent();
314 result.push_back(std::make_pair(widget, event));
331 inline std::vector<std::pair<twidget*, tevent> >
339 assert(!widget->has_event(event,
343 return std::vector<std::pair<twidget*, tevent> >();
347 #pragma warning(push)
348 #pragma warning(disable : 4706)
368 inline std::vector<std::pair<twidget*, tevent> >
375 assert(widget == dispatcher);
377 std::vector<std::pair<twidget*, tevent> >
result;
380 while((widget = widget->parent())) {
383 if(widget->has_event(event,
387 result.insert(result.begin(), std::make_pair(widget, event));
403 template <
class T,
class F>
405 std::vector<std::pair<twidget*, tevent> >& event_chain,
410 bool handled =
false;
414 for(std::vector<std::pair<twidget*, tevent> >::reverse_iterator ritor_widget
415 = event_chain.rbegin();
416 ritor_widget != event_chain.rend();
420 = tdispatcher_implementation::event_signal<T>(
421 *ritor_widget->first, ritor_widget->second);
427 functor(*
itor, *dispatcher, ritor_widget->second, handled, halt);
443 = tdispatcher_implementation::event_signal<T>(*widget,
event);
463 for(std::vector<std::pair<twidget*, tevent> >::
iterator itor_widget
464 = event_chain.begin();
465 itor_widget != event_chain.end();
469 = tdispatcher_implementation::event_signal<T>(
470 *itor_widget->first, itor_widget->second);
476 functor(*
itor, *dispatcher, itor_widget->second, handled, halt);
489 assert(handled ==
false);
518 template <
class T,
class F>
525 std::vector<std::pair<twidget*, tevent> > event_chain
526 = implementation::build_event_chain<T>(
event, dispatcher, widget);
528 return implementation::fire_event<T>(
543 std::vector<std::pair<twidget*, tevent> > event_chain;
545 while(w != dispatcher) {
549 if((w->*wants_double_click)()) {
555 event_chain.push_back(std::make_pair(w, double_click));
562 event_chain.push_back(std::make_pair(w, click));
567 if((widget->*wants_double_click)()) {
568 return implementation::fire_event<T>(
569 double_click, event_chain, dispatcher, widget,
functor);
571 return implementation::fire_event<T>(
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.
#define IMPLEMENT_EVENT_SIGNAL_WRAPPER(TYPE)
Small helper macro to wrap IMPLEMENT_EVENT_SIGNAL.
GLuint GLuint GLsizei GLenum type
itor second functor(surf, f[1])
#define IMPLEMENT_EVENT_SIGNAL(SET, FUNCTION, QUEUE)
Helper macro to implement the various event_signal functions.
std::vector< T > post_child
static bool execute(itor *, end *, E event, F functor)
Specialized class when itor == end.
std::vector< std::pair< twidget *, tevent > > build_event_chain< tsignal_message_function >(const tevent event, twidget *dispatcher, twidget *widget)
Build the event chain for tsignal_message_function.
Base class for event handling.
A class inherited from ttext_box that displays its input as stars.
tdispatcher::tevent_type event_type_
GLubyte GLubyte GLubyte GLubyte w
thas_handler(const tdispatcher::tevent_type event_type, tdispatcher &dispatcher)
Constructor.
std::function< void(tdispatcher &dispatcher, const tevent event, bool &handled, bool &halt)> tsignal_function
Callback function signature.
bool fire_event_double_click(twidget *dispatcher, twidget *widget, F functor)
tevent
The event send to the dispatcher.
Helper struct to generate the various signal types.
std::vector< std::pair< twidget *, tevent > > build_event_chain(const tevent event, twidget *dispatcher, twidget *widget)
Build the event chain.
A helper class to find out whether dispatcher has an handler for a certain event. ...
std::map< std::string, tfilter >::iterator itor
tdispatcher & dispatcher_
GLint GLint GLint GLint GLint x
bool fire_event(const tevent event, std::vector< std::pair< twidget *, tevent > > &event_chain, twidget *dispatcher, twidget *widget, F functor)
Helper function for fire_event.
bool fire_event(const tevent event, twidget *dispatcher, twidget *widget, F functor)
Fires an event.
std::vector< std::pair< twidget *, tevent > > build_event_chain< tsignal_notification_function >(const tevent event, twidget *dispatcher, twidget *widget)
Build the event chain for tsignal_notification_function.
static bool execute(itor *, end *, E, F)
bool has_event(const tevent event, const tevent_type event_type)
bool find(E event, F functor)
Tests whether an event handler is available.
bool oper(tevent event)
Tests whether a handler for an event is available.
GLsizei GLenum GLuint GLuint GLsizei char * message
std::vector< T > pre_child
Contains the implementation details for lexical_cast and shouldn't be used directly.