The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
gui2::event::distributor Class Reference

The event handler class for the widget library. More...

#include <distributor.hpp>

Inheritance diagram for gui2::event::distributor:
Inheritance graph

Classes

class  layer
 

Public Member Functions

 distributor (widget &owner, const dispatcher::queue_position queue_position)
 
 ~distributor ()
 
void initialize_state ()
 Initializes the state of the keyboard and mouse. More...
 
void keyboard_capture (widget *widget)
 Captures the keyboard input. More...
 
void keyboard_add_to_chain (widget *widget)
 Adds the widget to the keyboard chain. More...
 
void keyboard_remove_from_chain (widget *widget)
 Remove the widget from the keyboard chain. More...
 
widgetkeyboard_focus () const
 Return the widget currently capturing keyboard input. More...
 
- Public Member Functions inherited from gui2::event::mouse_button< T >
 mouse_button (const std::string &name_, widget &owner, const dispatcher::queue_position queue_position)
 
void initialize_state (const bool is_down)
 Initializes the state of the button. More...
 
- Public Member Functions inherited from gui2::event::mouse_motion
 mouse_motion (widget &owner, const dispatcher::queue_position queue_position)
 
 ~mouse_motion ()
 
void capture_mouse (const bool capture=true)
 Captures the mouse input. More...
 

Private Member Functions

void signal_handler_sdl_key_down (const SDL_Keycode key, const SDL_Keymod modifier, const utf8::string &unicode)
 Set of functions that handle certain events and sends them to the proper widget. More...
 
void signal_handler_sdl_text_input (const utf8::string &unicode, int32_t start, int32_t len)
 
void signal_handler_sdl_text_editing (const utf8::string &unicode, int32_t start, int32_t len)
 
template<typename Fcn , typename P1 , typename P2 , typename P3 >
void signal_handler_keyboard_internal (event::ui_event evt, P1 &&p1, P2 &&p2, P3 &&p3)
 
void signal_handler_notify_removal (dispatcher &widget, const ui_event event)
 

Private Attributes

layer layer_
 
widgetkeyboard_focus_
 The widget that holds the keyboard focus_. More...
 
std::vector< widget * > keyboard_focus_chain_
 Fall back keyboard focus_ items. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gui2::event::mouse_motion
void start_hover_timer (widget *widget, const point &coordinate)
 Starts the hover timer. More...
 
void stop_hover_timer ()
 Stops the current hover timer. More...
 
void mouse_enter (widget *mouse_over)
 Called when the mouse enters a widget. More...
 
void mouse_leave ()
 Called when the mouse leaves the current widget. More...
 
- Protected Attributes inherited from gui2::event::mouse_button< T >
uint32_t last_click_stamp_
 The time of the last click used for double clicking. More...
 
widgetlast_clicked_widget_
 The widget the last click was on, used for double clicking. More...
 
widgetfocus_
 If the mouse isn't captured we need to verify the up is on the same widget as the down so we send a proper click, also needed to send the up to the right widget. More...
 
- Protected Attributes inherited from gui2::event::mouse_motion
widgetmouse_focus_
 The widget that currently has the mouse focus_. More...
 
bool mouse_captured_
 Did the current widget capture the focus_? More...
 
widgetowner_
 The widget that owns us. More...
 
size_t hover_timer_
 The timer for the hover event. More...
 
widgethover_widget_
 The widget which should get the hover event. More...
 
point hover_position_
 The anchor point of the hover event. More...
 
bool hover_shown_
 Has the hover been shown for the widget? More...
 

Detailed Description

The event handler class for the widget library.

Definition at line 259 of file distributor.hpp.

Constructor & Destructor Documentation

gui2::event::distributor::distributor ( widget owner,
const dispatcher::queue_position  queue_position 
)
gui2::event::distributor::~distributor ( )

Member Function Documentation

void gui2::event::distributor::initialize_state ( )

Initializes the state of the keyboard and mouse.

Needed after initialization and reactivation.

Definition at line 590 of file distributor.cpp.

References gui2::event::init_mouse_location(), and gui2::event::mouse_button< T >::initialize_state().

Referenced by distributor().

void gui2::event::distributor::keyboard_add_to_chain ( widget widget)

Adds the widget to the keyboard chain.

Parameters
widgetThe widget to add to the chain. The widget should be valid widget, which hasn't been added to the chain yet.

Definition at line 625 of file distributor.cpp.

References gui2::event::find(), and keyboard_focus_chain_.

void gui2::event::distributor::keyboard_capture ( widget widget)

Captures the keyboard input.

Parameters
widgetThe widget which should capture the keyboard. Sending nullptr releases the capturing.

Definition at line 606 of file distributor.cpp.

References DBG_GUI_E, gui2::event::dispatcher::fire(), keyboard_focus_, LOG_HEADER, gui2::event::LOSE_KEYBOARD_FOCUS, gui2::event::mouse_motion::owner_, and gui2::event::RECEIVE_KEYBOARD_FOCUS.

widget * gui2::event::distributor::keyboard_focus ( ) const

Return the widget currently capturing keyboard input.

Definition at line 601 of file distributor.cpp.

References keyboard_focus_.

void gui2::event::distributor::keyboard_remove_from_chain ( widget widget)

Remove the widget from the keyboard chain.

Parameters
widgetThe widget to be removed from the chain.

Definition at line 635 of file distributor.cpp.

References gui2::event::find(), keyboard_focus_chain_, and w.

template<typename Fcn , typename P1 , typename P2 , typename P3 >
void gui2::event::distributor::signal_handler_keyboard_internal ( event::ui_event  evt,
P1 &&  p1,
P2 &&  p2,
P3 &&  p3 
)
private
Todo:
Test whether recursion protection is needed.
Todo:
Make sure we're not in the event chain.

No idea why we're here, but needs to be fixed, otherwise we keep calling this function recursively upon unhandled events...

Probably added to make sure the window can grab the events and handle + block them when needed, this is no longer needed with the chain.

Definition at line 647 of file distributor.cpp.

References DBG_GUI_E, gui2::event::dispatcher::fire(), gui2::styled_widget::get_active(), keyboard_focus_, keyboard_focus_chain_, LOG_HEADER, and gui2::event::mouse_motion::owner_.

void gui2::event::distributor::signal_handler_notify_removal ( dispatcher widget,
const ui_event  event 
)
private
Todo:
Evaluate whether moving the cleanup parts in the subclasses.

It might be cleaner to do it that way, but creates extra small functions...

Definition at line 726 of file distributor.cpp.

References DBG_GUI_E, gui2::event::find(), gui2::event::mouse_button< T >::focus_, gui2::event::mouse_motion::hover_widget_, keyboard_focus_, keyboard_focus_chain_, gui2::event::mouse_button< T >::last_clicked_widget_, LOG_HEADER, gui2::event::mouse_motion::mouse_focus_, gui2::event::mouse_motion::stop_hover_timer(), and w.

Referenced by distributor(), and ~distributor().

void gui2::event::distributor::signal_handler_sdl_key_down ( const SDL_Keycode  key,
const SDL_Keymod  modifier,
const utf8::string unicode 
)
private

Set of functions that handle certain events and sends them to the proper widget.

These functions are called by the SDL event handling functions.

Definition at line 711 of file distributor.cpp.

References gui2::event::SDL_KEY_DOWN.

Referenced by distributor(), and ~distributor().

void gui2::event::distributor::signal_handler_sdl_text_editing ( const utf8::string unicode,
int32_t  start,
int32_t  len 
)
private

Definition at line 721 of file distributor.cpp.

References gui2::event::SDL_TEXT_EDITING, and editor::start().

Referenced by distributor(), and ~distributor().

void gui2::event::distributor::signal_handler_sdl_text_input ( const utf8::string unicode,
int32_t  start,
int32_t  len 
)
private

Definition at line 716 of file distributor.cpp.

References gui2::event::SDL_TEXT_INPUT, and editor::start().

Referenced by distributor(), and ~distributor().

Member Data Documentation

widget* gui2::event::distributor::keyboard_focus_
private

The widget that holds the keyboard focus_.

Definition at line 336 of file distributor.hpp.

Referenced by keyboard_capture(), keyboard_focus(), signal_handler_keyboard_internal(), and signal_handler_notify_removal().

std::vector<widget*> gui2::event::distributor::keyboard_focus_chain_
private

Fall back keyboard focus_ items.

When the focused widget didn't handle the keyboard event (or no handler for the keyboard focus_) it is send all widgets in this vector. The order is from rbegin() to rend(). If the keyboard_focus_ is in the vector it won't get the event twice. The first item added to the vector should be the window, so it will be the last handler and can dispatch the hotkeys registered.

Definition at line 348 of file distributor.hpp.

Referenced by keyboard_add_to_chain(), keyboard_remove_from_chain(), signal_handler_keyboard_internal(), and signal_handler_notify_removal().

layer gui2::event::distributor::layer_
private

Definition at line 315 of file distributor.hpp.


The documentation for this class was generated from the following files: