The Battle for Wesnoth  1.19.0-dev
Functions
gui2::event::implementation Namespace Reference

Functions

template<event_category C>
std::vector< std::pair< widget *, ui_event > > build_event_chain (const ui_event event, widget *dispatcher, widget *w)
 Build the event chain. More...
 
template<>
std::vector< std::pair< widget *, ui_event > > build_event_chain< event_category::notification > (const ui_event event, widget *dispatcher, widget *w)
 Build the event chain for signal_notification. More...
 
template<>
std::vector< std::pair< widget *, ui_event > > build_event_chain< event_category::message > (const ui_event event, widget *dispatcher, widget *w)
 Build the event chain for signal_message. More...
 
template<event_category C, typename... F>
bool fire_event (const ui_event event, const std::vector< std::pair< widget *, ui_event >> &event_chain, widget *dispatcher, widget *w, F &&... params)
 Helper function for fire_event. More...
 

Function Documentation

◆ build_event_chain()

template<event_category C>
std::vector<std::pair<widget*, ui_event> > gui2::event::implementation::build_event_chain ( const ui_event  event,
widget dispatcher,
widget w 
)

Build the event chain.

The event chain is a chain of events starting from the first parent of the widget until (and including) the wanted parent. For all these widgets it will be tested whether they have either a pre or post handler for the event. This ways there will be list of widgets to try to send the events to. If there's no line from widget to parent the result is undefined. (If widget == dispatcher the result will always be empty.)

Precondition
dispatcher != nullptr
widget != nullptr
Parameters
eventThe event to test.
dispatcherThe final widget to test, this is also the dispatcher the sends the event.
wThe widget should parent(s) to check.
Returns
The list of widgets with a handler. The order will be (assuming all have a handler):
  • container 2
  • container 1
  • dispatcher

Definition at line 140 of file dispatcher_private.hpp.

References gui2::event::dispatcher::post, gui2::event::dispatcher::pre, and w.

◆ build_event_chain< event_category::message >()

template<>
std::vector<std::pair<widget*, ui_event> > gui2::event::implementation::build_event_chain< event_category::message > ( const ui_event  event,
widget dispatcher,
widget w 
)

Build the event chain for signal_message.

This function expects that the widget sending it is also the receiver. This assumption might change, but is valid for now. The function doesn't build an event chain from dispatcher to widget but from widget to its toplevel item (the first one without a parent) which we call window.

Precondition
dispatcher == widget
Returns
The list of widgets with a handler. The order will be (assuming all have a handler):
  • window
  • container 1
  • container 2

Definition at line 140 of file dispatcher_private.hpp.

◆ build_event_chain< event_category::notification >()

template<>
std::vector<std::pair<widget*, ui_event> > gui2::event::implementation::build_event_chain< event_category::notification > ( const ui_event  event,
widget dispatcher,
widget w 
)

Build the event chain for signal_notification.

The notification is only send to the receiver it returns an empty chain. Since the pre and post queues are unused, it validates whether they are empty (using asserts).

Returns
An empty vector.

Definition at line 140 of file dispatcher_private.hpp.

◆ fire_event()

template<event_category C, typename... F>
bool gui2::event::implementation::fire_event ( const ui_event  event,
const std::vector< std::pair< widget *, ui_event >> &  event_chain,
widget dispatcher,
widget w,
F &&...  params 
)