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

Abstract base class for text items. More...

#include <text_box_base.hpp>

Inheritance diagram for gui2::text_box_base:
Inheritance graph

Public Types

enum  state_t { ENABLED, DISABLED, FOCUSED }
 Note the order of the states must be the same as defined in settings.hpp. More...
 
- Public Types inherited from gui2::widget
enum  visibility { visibility::visible, visibility::hidden, visibility::invisible }
 Visibility settings done by the user. More...
 
enum  redraw_action { redraw_action::full, redraw_action::partly, redraw_action::none }
 Visibility set by the engine. More...
 
- Public Types inherited from gui2::event::dispatcher
enum  event_queue_type { pre = 1, child = 2, post = 4 }
 
enum  queue_position {
  front_pre_child, back_pre_child, front_child, back_child,
  front_post_child, back_post_child
}
 The position where to add a new callback in the signal handler. More...
 
enum  mouse_behavior { all, hit, none }
 The behavior of the mouse events. More...
 

Public Member Functions

 text_box_base (const implementation::builder_styled_widget &builder, const std::string &control_type)
 
 ~text_box_base ()
 
virtual void set_active (const bool active) override
 See styled_widget::set_active. More...
 
virtual bool get_active () const override
 See styled_widget::get_active. More...
 
virtual unsigned get_state () const override
 See styled_widget::get_state. More...
 
void set_maximum_length (const size_t maximum_length)
 
size_t get_length () const
 
virtual void set_value (const std::string &text)
 The set_value is virtual for the password_box class. More...
 
std::string get_value () const
 
const std::string & text () const
 
void set_text_changed_callback (std::function< void(text_box_base *textbox, const std::string text)> cb)
 Set the text_changed callback. More...
 
void set_selection (size_t start, int length)
 Sets or clears the text selection. More...
 
bool is_composing () const
 
void interrupt_composition ()
 
- Public Member Functions inherited from gui2::styled_widget
 styled_widget (const implementation::builder_styled_widget &builder, const std::string &control_type)
 Constructor. More...
 
virtual void set_members (const string_map &data)
 Sets the members of the styled_widget. More...
 
bool disable_click_dismiss () const override
 See widget::disable_click_dismiss. More...
 
virtual iteration::walker_basecreate_walker () override
 See widget::create_walker. More...
 
point get_config_minimum_size () const
 Gets the minimum size as defined in the config. More...
 
point get_config_default_size () const
 Gets the default size as defined in the config. More...
 
point get_config_maximum_size () const
 Gets the best size as defined in the config. More...
 
virtual unsigned get_characters_per_line () const
 Returns the number of characters per line. More...
 
virtual bool get_link_aware () const
 Returns whether the label should be link_aware, in in rendering and in searching for links with get_link. More...
 
virtual color_t get_link_color () const
 Returns the color string to be used with links. More...
 
virtual void layout_initialize (const bool full_initialization) override
 See widget::layout_initialize. More...
 
virtual void request_reduce_width (const unsigned maximum_width) override
 See widget::request_reduce_width. More...
 
virtual void request_reduce_height (const unsigned maximum_height) override
 See widget::request_reduce_height. More...
 
virtual void place (const point &origin, const point &size) override
 See widget::place. More...
 
virtual widgetfind_at (const point &coordinate, const bool must_be_active) override
 See widget::find_at. More...
 
virtual const widgetfind_at (const point &coordinate, const bool must_be_active) const override
 See widget::find_at. More...
 
widgetfind (const std::string &id, const bool must_be_active) override
 See widget::find. More...
 
const widgetfind (const std::string &id, const bool must_be_active) const override
 See widget::find. More...
 
bool get_use_tooltip_on_label_overflow () const
 
void set_use_tooltip_on_label_overflow (const bool use_tooltip=true)
 
const t_stringget_label () const
 
virtual void set_label (const t_string &label)
 
virtual void set_use_markup (bool use_markup)
 
bool get_use_markup () const
 
const t_stringtooltip () const
 
void set_tooltip (const t_string &tooltip)
 
const t_stringhelp_message () const
 
void set_help_message (const t_string &help_message)
 
std::vector< canvas > & get_canvases ()
 
canvasget_canvas (const unsigned index)
 
virtual void set_text_alignment (const PangoAlignment text_alignment)
 
PangoAlignment get_text_alignment () const
 
void set_text_ellipse_mode (const PangoEllipsizeMode ellipse_mode)
 
PangoEllipsizeMode get_text_ellipse_mode () const
 Get the text's ellipsize mode. More...
 
virtual const std::string & get_control_type () const =0
 Returns the control_type of the styled_widget. More...
 
- Public Member Functions inherited from gui2::widget
 widget (const widget &)=delete
 
widgetoperator= (const widget &)=delete
 
 widget ()
 
 widget (const builder_widget &builder)
 Constructor. More...
 
virtual ~widget () override
 
void set_id (const std::string &id)
 
const std::string & id () const
 
windowget_window ()
 Get the parent window. More...
 
const windowget_window () const
 The constant version of get_window. More...
 
gridget_parent_grid ()
 Get the parent grid. More...
 
dialogs::modal_dialogdialog ()
 Returns the top-level dialog. More...
 
void set_parent (widget *parent)
 
widgetparent ()
 
virtual void demand_reduce_width (const unsigned maximum_width)
 Tries to reduce the width of a widget. More...
 
virtual void demand_reduce_height (const unsigned maximum_height)
 Tries to reduce the height of a widget. More...
 
point get_best_size () const
 Gets the best size for the widget. More...
 
virtual bool can_mouse_focus () const
 Whether the mouse move/click event go 'through' this widget. More...
 
virtual bool can_wrap () const
 Can the widget wrap. More...
 
virtual void set_origin (const point &origin)
 Sets the origin of the widget. More...
 
virtual void set_size (const point &size)
 Sets the size of the widget. More...
 
virtual void move (const int x_offset, const int y_offset)
 Moves a widget. More...
 
virtual void set_horizontal_alignment (const std::string &alignment)
 Sets the horizontal alignment of the widget within its parent grid. More...
 
virtual void set_vertical_alignment (const std::string &alignment)
 Sets the horizontal alignment of the widget within its parent grid. More...
 
virtual void layout_children ()
 Allows a widget to update its children. More...
 
point get_origin () const
 Returns the screen origin of the widget. More...
 
point get_size () const
 Returns the size of the widget. More...
 
SDL_Rect get_rectangle () const
 Gets the bounding rectangle of the widget on the screen. More...
 
int get_x () const
 
int get_y () const
 
unsigned get_width () const
 
unsigned get_height () const
 
void set_linked_group (const std::string &linked_group)
 
SDL_Rect calculate_blitting_rectangle (const int x_offset, const int y_offset)
 Calculates the blitting rectangle of the widget. More...
 
SDL_Rect calculate_clipping_rectangle (const int x_offset, const int y_offset)
 Calculates the clipping rectangle of the widget. More...
 
void draw_background (surface &frame_buffer, int x_offset, int y_offset)
 Draws the background of a widget. More...
 
void draw_children (surface &frame_buffer, int x_offset, int y_offset)
 Draws the children of a widget. More...
 
void draw_foreground (surface &frame_buffer, int x_offset, int y_offset)
 Draws the foreground of the widget. More...
 
void populate_dirty_list (window &caller, std::vector< widget * > &call_stack)
 Adds a widget to the dirty list if it is dirty. More...
 
SDL_Rect get_dirty_rectangle () const
 Gets the dirty rectangle of the widget. More...
 
virtual void set_visible_rectangle (const SDL_Rect &rectangle)
 Sets the visible rectangle for a widget. More...
 
void set_is_dirty (const bool is_dirty)
 
bool get_is_dirty () const
 
void set_visible (const visibility visible)
 
visibility get_visible () const
 
redraw_action get_drawing_action () const
 
void set_debug_border_mode (const unsigned debug_border_mode)
 
void set_debug_border_color (const color_t debug_border_color)
 
virtual bool has_widget (const widget &widget) const
 Does the widget contain the widget. More...
 
- Public Member Functions inherited from gui2::event_executor
 event_executor ()
 
virtual ~event_executor ()
 
void set_wants_mouse_hover (const bool hover=true)
 
bool wants_mouse_hover () const
 
void set_wants_mouse_left_double_click (const bool click=true)
 
bool wants_mouse_left_double_click () const
 
void set_wants_mouse_middle_double_click (const bool click=true)
 
bool wants_mouse_middle_double_click () const
 
event_executorset_wants_mouse_right_double_click (const bool click=true)
 
bool wants_mouse_right_double_click () const
 
- Public Member Functions inherited from gui2::event::dispatcher
 dispatcher ()
 
virtual ~dispatcher ()
 
void connect ()
 Connects the dispatcher to the event handler. More...
 
bool has_event (const ui_event event, const event_queue_type event_type)
 
bool fire (const ui_event event, widget &target)
 Fires an event which has no extra parameters. More...
 
bool fire (const ui_event event, widget &target, const point &coordinate)
 Fires an event which takes a coordinate parameter. More...
 
bool fire (const ui_event event, widget &target, const SDL_Keycode key, const SDL_Keymod modifier, const utf8::string &unicode)
 Fires an event which takes keyboard parameters. More...
 
bool fire (const ui_event event, widget &target, const point &pos, const point &distance)
 Fires an event which takes touch parameters. More...
 
bool fire (const ui_event event, widget &target, void *)
 Fires an event which takes notification parameters. More...
 
bool fire (const ui_event event, widget &target, message &msg)
 Fires an event which takes message parameters. More...
 
bool fire (const ui_event event, widget &target, const SDL_Event &sdlevent)
 Fires an event that's a raw SDL event. More...
 
bool fire (const ui_event event, widget &target, const std::string &text, int32_t start, int32_t len)
 Fires an event which takes text input parameters. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event, E >::value > 
connect_signal (const signal_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event, E >::value > 
disconnect_signal (const signal_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_mouse, E >::value > 
connect_signal (const signal_mouse_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_mouse. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_mouse, E >::value > 
disconnect_signal (const signal_mouse_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_mouse. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_keyboard, E >
::value > 
connect_signal (const signal_keyboard_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_keyboard. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_keyboard, E >
::value > 
disconnect_signal (const signal_keyboard_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_keyboard. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_touch, E >::value > 
connect_signal (const signal_touch_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_touch. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_touch, E >::value > 
disconnect_signal (const signal_touch_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_touch. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_notification, E >
::value > 
connect_signal (const signal_notification_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_notification. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_notification, E >
::value > 
disconnect_signal (const signal_notification_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_notification. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_message, E >
::value > 
connect_signal (const signal_message_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_message. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_message, E >
::value > 
disconnect_signal (const signal_message_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_message. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_raw_event, E >
::value > 
connect_signal (const signal_raw_event_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_raw_event. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_raw_event, E >
::value > 
disconnect_signal (const signal_raw_event_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_raw_event. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_text_input, E >
::value > 
connect_signal (const signal_text_input_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_text_input. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_text_input, E >
::value > 
disconnect_signal (const signal_text_input_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_text_input. More...
 
void capture_mouse ()
 Captures the mouse. More...
 
void release_mouse ()
 Releases the mouse capture. More...
 
void set_mouse_behavior (const mouse_behavior mouse_behavior)
 
mouse_behavior get_mouse_behavior () const
 
void set_want_keyboard_input (const bool want_keyboard_input)
 
bool get_want_keyboard_input () const
 
void register_hotkey (const hotkey::HOTKEY_COMMAND id, const hotkey_function &function)
 Registers a hotkey. More...
 
bool execute_hotkey (const hotkey::HOTKEY_COMMAND id)
 Executes a hotkey. More...
 

Protected Member Functions

virtual void goto_end_of_line (const bool select=false)=0
 Moves the cursor to the end of the line. More...
 
void goto_end_of_data (const bool select=false)
 Moves the cursor to the end of all text. More...
 
virtual void goto_start_of_line (const bool select=false)=0
 Moves the cursor to the beginning of the line. More...
 
void goto_start_of_data (const bool select=false)
 Moves the cursor to the beginning of the data. More...
 
void select_all ()
 Selects all text. More...
 
void set_cursor (const size_t offset, const bool select)
 Moves the cursor at the wanted position. More...
 
virtual void insert_char (const utf8::string &unicode)
 Inserts a character at the cursor. More...
 
virtual void delete_char (const bool before_cursor)=0
 Deletes the character. More...
 
virtual void delete_selection ()=0
 Deletes the current selection. More...
 
virtual void copy_selection (const bool mouse)
 Copies the current selection. More...
 
virtual void paste_selection (const bool mouse)
 Pastes the current selection. More...
 
point get_cursor_position (const unsigned column, const unsigned line=0) const
 
point get_column_line (const point &position) const
 
void set_font_size (const unsigned font_size)
 
void set_font_style (const font::pango_text::FONT_STYLE font_style)
 
void set_maximum_width (const int width)
 
void set_maximum_height (const int height, const bool multiline)
 
void set_ellipse_mode (const PangoEllipsizeMode ellipse_mode)
 
size_t get_selection_start () const
 
void set_selection_start (const size_t selection_start)
 
size_t get_selection_length () const
 
void set_selection_length (const int selection_length)
 
size_t get_composition_start () const
 
size_t get_composition_length () const
 
virtual void handle_commit (bool &handled, const utf8::string &unicode)
 
virtual void handle_editing (bool &handled, const utf8::string &unicode, int32_t start, int32_t len)
 
- Protected Member Functions inherited from gui2::styled_widget
virtual point calculate_best_size () const override
 See widget::calculate_best_size. More...
 
resolution_definition_ptr config ()
 
resolution_definition_const_ptr config () const
 
template<typename T >
std::shared_ptr< const
typename T::resolution > 
cast_config_to () const
 Casts the current resolution definition config to the respective type of a derived widget. More...
 
void set_config (resolution_definition_ptr config)
 
virtual void update_canvas ()
 Updates the canvas(ses). More...
 
int get_text_maximum_width () const
 Returns the maximum width available for the text. More...
 
int get_text_maximum_height () const
 Returns the maximum height available for the text. More...
 
virtual void impl_draw_background (surface &frame_buffer, int x_offset, int y_offset) override
 See widget::impl_draw_background. More...
 
virtual void impl_draw_foreground (surface &frame_buffer, int x_offset, int y_offset) override
 See widget::impl_draw_foreground. More...
 
std::string get_label_token (const point &position, const char *delimiters=" \n\r\t") const
 Exposes font::pango_text::get_token, for the text label of this styled_widget. More...
 
std::string get_label_link (const point &position) const
 
- Protected Member Functions inherited from gui2::widget
void set_layout_size (const point &size)
 
const pointlayout_size () const
 
void clear_layout_size ()
 Throws away layout_size_. More...
 

Private Member Functions

void set_state (const state_t state)
 
virtual void toggle_cursor_timer (bool enable)
 
virtual void cursor_timer_callback ()
 Implements blinking cursor functionality. More...
 
virtual void reset_cursor_state ()
 
virtual void handle_key_up_arrow (SDL_Keymod modifier, bool &handled)=0
 Every key can have several behaviors. More...
 
virtual void handle_key_down_arrow (SDL_Keymod modifier, bool &handled)=0
 Down arrow key pressed. More...
 
virtual void handle_key_clear_line (SDL_Keymod modifier, bool &handled)=0
 Clears the current line. More...
 
virtual void handle_key_left_arrow (SDL_Keymod modifier, bool &handled)
 Left arrow key pressed. More...
 
virtual void handle_key_right_arrow (SDL_Keymod modifier, bool &handled)
 Right arrow key pressed. More...
 
virtual void handle_key_home (SDL_Keymod modifier, bool &handled)
 Home key pressed. More...
 
virtual void handle_key_end (SDL_Keymod modifier, bool &handled)
 End key pressed. More...
 
virtual void handle_key_backspace (SDL_Keymod modifier, bool &handled)
 Backspace key pressed. More...
 
virtual void handle_key_delete (SDL_Keymod modifier, bool &handled)
 Delete key pressed. More...
 
virtual void handle_key_page_up (SDL_Keymod, bool &)
 Page up key. More...
 
virtual void handle_key_page_down (SDL_Keymod, bool &)
 Page down key. More...
 
virtual void handle_key_tab (SDL_Keymod, bool &)
 Tab key. More...
 
void signal_handler_middle_button_click (const event::ui_event event, bool &handled)
 
void signal_handler_sdl_key_down (const event::ui_event event, bool &handled, const SDL_Keycode key, SDL_Keymod modifier)
 
void signal_handler_sdl_text_input (const event::ui_event event, bool &handled, const utf8::string &unicode, int32_t start, int32_t len)
 
void signal_handler_receive_keyboard_focus (const event::ui_event event)
 
void signal_handler_lose_keyboard_focus (const event::ui_event event)
 

Private Attributes

state_t state_
 Current state of the widget. More...
 
font::pango_text text_
 The text entered in the widget. More...
 
std::string text_cached_
 Cached version of the text without any pending IME modifications. More...
 
size_t selection_start_
 Start of the selected text. More...
 
int selection_length_
 Length of the selected text. More...
 
bool ime_in_progress_
 
int ime_start_point_
 
int ime_cursor_
 
int ime_length_
 
size_t cursor_timer_
 
unsigned short cursor_alpha_
 
unsigned short cursor_blink_rate_ms_
 
std::function< void(text_box_base
*textbox, const std::string
text)> 
text_changed_callback_
 Text changed callback. More...
 

Detailed Description

Abstract base class for text items.

All other text classes should inherit from this base class.

The NOTIFY_MODIFIED event is send when the text is modified.

Todo:
Validate whether the NOTIFY_MODIFIED is always fired properly. The current implementation is added for some quick testing so some cases might be forgotten.

Common signal handlers:

Definition at line 46 of file text_box_base.hpp.

Member Enumeration Documentation

Note the order of the states must be the same as defined in settings.hpp.

Enumerator
ENABLED 
DISABLED 
FOCUSED 

Definition at line 277 of file text_box_base.hpp.

Constructor & Destructor Documentation

gui2::text_box_base::text_box_base ( const implementation::builder_styled_widget builder,
const std::string &  control_type 
)
gui2::text_box_base::~text_box_base ( )

Definition at line 70 of file text_box_base.cpp.

References toggle_cursor_timer().

Member Function Documentation

void gui2::text_box_base::copy_selection ( const bool  mouse)
protectedvirtual
void gui2::text_box_base::cursor_timer_callback ( )
privatevirtual
virtual void gui2::text_box_base::delete_char ( const bool  before_cursor)
protectedpure virtual

Deletes the character.

Parameters
before_cursorIf true it deletes the character before the cursor (backspace) else the character after the cursor (delete).

Implemented in gui2::text_box.

Referenced by handle_key_backspace(), and handle_key_delete().

virtual void gui2::text_box_base::delete_selection ( )
protectedpure virtual
bool gui2::text_box_base::get_active ( ) const
overridevirtual

See styled_widget::get_active.

Implements gui2::styled_widget.

Definition at line 82 of file text_box_base.cpp.

References DISABLED, and state_.

Referenced by set_active().

point gui2::text_box_base::get_column_line ( const point position) const
inlineprotected
size_t gui2::text_box_base::get_composition_length ( ) const
inlineprotected

Definition at line 262 of file text_box_base.hpp.

References ime_length_.

Referenced by gui2::text_box::update_canvas().

size_t gui2::text_box_base::get_composition_start ( ) const
inlineprotected

Definition at line 257 of file text_box_base.hpp.

References ime_start_point_.

Referenced by gui2::text_box::update_canvas().

point gui2::text_box_base::get_cursor_position ( const unsigned  column,
const unsigned  line = 0 
) const
inlineprotected
size_t gui2::text_box_base::get_length ( ) const
inline
size_t gui2::text_box_base::get_selection_length ( ) const
inlineprotected
size_t gui2::text_box_base::get_selection_start ( ) const
inlineprotected
unsigned gui2::text_box_base::get_state ( ) const
overridevirtual

See styled_widget::get_state.

Implements gui2::styled_widget.

Definition at line 87 of file text_box_base.cpp.

References state_.

std::string gui2::text_box_base::get_value ( ) const
inline
void gui2::text_box_base::goto_end_of_data ( const bool  select = false)
inlineprotected

Moves the cursor to the end of all text.

For a single line text this is the same as goto_end_of_line().

Parameters
selectSelect the text from the original cursor position till the end of the data?

Definition at line 137 of file text_box_base.hpp.

References font::pango_text::get_length(), set_cursor(), and text_.

Referenced by gui2::text_box::goto_end_of_line(), handle_key_end(), and select_all().

virtual void gui2::text_box_base::goto_end_of_line ( const bool  select = false)
protectedpure virtual

Moves the cursor to the end of the line.

Parameters
selectSelect the text from the original cursor position till the end of the line?

Implemented in gui2::text_box.

Referenced by handle_key_end().

void gui2::text_box_base::goto_start_of_data ( const bool  select = false)
inlineprotected

Moves the cursor to the beginning of the data.

Parameters
selectSelect the text from the original cursor position till the beginning of the data?

Definition at line 156 of file text_box_base.hpp.

References set_cursor().

Referenced by gui2::text_box::goto_start_of_line(), and handle_key_home().

virtual void gui2::text_box_base::goto_start_of_line ( const bool  select = false)
protectedpure virtual

Moves the cursor to the beginning of the line.

Parameters
selectSelect the text from the original cursor position till the beginning of the line?

Implemented in gui2::text_box.

Referenced by handle_key_home().

void gui2::text_box_base::handle_commit ( bool &  handled,
const utf8::string unicode 
)
protectedvirtual
void gui2::text_box_base::handle_editing ( bool &  handled,
const utf8::string unicode,
int32_t  start,
int32_t  len 
)
protectedvirtual
void gui2::text_box_base::handle_key_backspace ( SDL_Keymod  modifier,
bool &  handled 
)
privatevirtual

Backspace key pressed.

Unmodified Deletes the character before the cursor, ignored if at the beginning of the data. Control Ignored. Shift Ignored. Alt Ignored.

Definition at line 378 of file text_box_base.cpp.

References DBG_GUI_E, delete_char(), delete_selection(), gui2::event::dispatcher::fire(), LOG_SCOPE_HEADER, gui2::event::NOTIFY_MODIFIED, selection_length_, and selection_start_.

Referenced by signal_handler_sdl_key_down().

virtual void gui2::text_box_base::handle_key_clear_line ( SDL_Keymod  modifier,
bool &  handled 
)
privatepure virtual

Clears the current line.

Unmodified Clears the current line. Control Ignored. Shift Ignored. Alt Ignored.

Implemented in gui2::text_box.

void gui2::text_box_base::handle_key_delete ( SDL_Keymod  modifier,
bool &  handled 
)
privatevirtual

Delete key pressed.

Unmodified If there is a selection that's deleted. Else if not at the end of the data the character after the cursor is deleted. Else the key is ignored. ignored if at the beginning of the data. Control Ignored. Shift Ignored. Alt Ignored.

Definition at line 391 of file text_box_base.cpp.

References DBG_GUI_E, delete_char(), delete_selection(), gui2::event::dispatcher::fire(), font::pango_text::get_length(), LOG_SCOPE_HEADER, gui2::event::NOTIFY_MODIFIED, selection_length_, selection_start_, and text_.

Referenced by signal_handler_sdl_key_down().

virtual void gui2::text_box_base::handle_key_down_arrow ( SDL_Keymod  modifier,
bool &  handled 
)
privatepure virtual

Down arrow key pressed.

The behavior is implementation defined.

Implemented in gui2::text_box.

Referenced by signal_handler_sdl_key_down().

void gui2::text_box_base::handle_key_end ( SDL_Keymod  modifier,
bool &  handled 
)
privatevirtual

End key pressed.

Unmodified Moves the cursor a to the end of the line. Control Like unmodified but to the end of the data. Shift Selects the text while moving. Alt Ignored.

Definition at line 366 of file text_box_base.cpp.

References DBG_GUI_E, goto_end_of_data(), goto_end_of_line(), and LOG_SCOPE_HEADER.

Referenced by signal_handler_sdl_key_down().

void gui2::text_box_base::handle_key_home ( SDL_Keymod  modifier,
bool &  handled 
)
privatevirtual

Home key pressed.

Unmodified Moves the cursor a to the beginning of the line. Control Like unmodified but to the beginning of the data. Shift Selects the text while moving. Alt Ignored.

Definition at line 354 of file text_box_base.cpp.

References DBG_GUI_E, goto_start_of_data(), goto_start_of_line(), and LOG_SCOPE_HEADER.

Referenced by signal_handler_sdl_key_down().

void gui2::text_box_base::handle_key_left_arrow ( SDL_Keymod  modifier,
bool &  handled 
)
privatevirtual

Left arrow key pressed.

Unmodified Moves the cursor a character to the left. Control Like unmodified but a word instead of a letter at the time. Shift Selects the text while moving. Alt Ignored.

Todo:
implement the ctrl key.

Definition at line 330 of file text_box_base.cpp.

References DBG_GUI_E, LOG_SCOPE_HEADER, selection_length_, selection_start_, and set_cursor().

Referenced by signal_handler_sdl_key_down().

virtual void gui2::text_box_base::handle_key_page_down ( SDL_Keymod  ,
bool &   
)
inlineprivatevirtual

Page down key.

Unmodified Unhandled. Control Ignored. Shift Ignored. Alt Ignored.

Definition at line 470 of file text_box_base.hpp.

Referenced by signal_handler_sdl_key_down().

virtual void gui2::text_box_base::handle_key_page_up ( SDL_Keymod  ,
bool &   
)
inlineprivatevirtual

Page up key.

Unmodified Unhandled. Control Ignored. Shift Ignored. Alt Ignored.

Definition at line 458 of file text_box_base.hpp.

Referenced by signal_handler_sdl_key_down().

void gui2::text_box_base::handle_key_right_arrow ( SDL_Keymod  modifier,
bool &  handled 
)
privatevirtual

Right arrow key pressed.

Unmodified Moves the cursor a character to the right. Control Like unmodified but a word instead of a letter at the time. Shift Selects the text while moving. Alt Ignored.

Todo:
implement the ctrl key.

Definition at line 342 of file text_box_base.cpp.

References DBG_GUI_E, font::pango_text::get_length(), LOG_SCOPE_HEADER, selection_length_, selection_start_, set_cursor(), and text_.

Referenced by signal_handler_sdl_key_down().

virtual void gui2::text_box_base::handle_key_tab ( SDL_Keymod  ,
bool &   
)
inlineprivatevirtual

Tab key.

Unmodified Implementation defined. Control Implementation defined. Shift Implementation defined. Alt Implementation defined.

Reimplemented in gui2::text_box.

Definition at line 482 of file text_box_base.hpp.

virtual void gui2::text_box_base::handle_key_up_arrow ( SDL_Keymod  modifier,
bool &  handled 
)
privatepure virtual

Every key can have several behaviors.

Unmodified No modifier is pressed. Control The control key is pressed. Shift The shift key is pressed. Alt The alt key is pressed.

If modifiers together do something else as the sum of the modifiers it's listed separately eg.

Control Moves 10 steps at the time. Shift Selects the text. Control + Shift Inserts 42 in the text.

There are some predefined actions for results. Unhandled The key/modifier is ignored and also reported unhandled. Ignored The key/modifier is ignored and it's expected the inherited classes do the same. Implementation defined The key/modifier is ignored and it's expected the inherited classes will define some meaning to it. Up arrow key pressed.

The behavior is implementation defined.

Implemented in gui2::text_box.

Referenced by signal_handler_sdl_key_down().

void gui2::text_box_base::insert_char ( const utf8::string unicode)
protectedvirtual

Inserts a character at the cursor.

This function is preferred over set_text since it's optimized for updating the internal bookkeeping.

Parameters
unicodeThe unicode value of the character to insert.

Reimplemented in gui2::password_box.

Definition at line 156 of file text_box_base.cpp.

References delete_selection(), font::pango_text::insert_text(), selection_start_, set_cursor(), gui2::widget::set_is_dirty(), utf8::size(), text_, and gui2::styled_widget::update_canvas().

Referenced by handle_commit(), and gui2::password_box::insert_char().

void gui2::text_box_base::interrupt_composition ( )

Definition at line 169 of file text_box_base.cpp.

References ime_in_progress_, and ime_length_.

Referenced by signal_handler_sdl_key_down().

bool gui2::text_box_base::is_composing ( ) const
inline

Definition at line 268 of file text_box_base.hpp.

References ime_in_progress_.

void gui2::text_box_base::paste_selection ( const bool  mouse)
protectedvirtual
void gui2::text_box_base::reset_cursor_state ( )
privatevirtual
void gui2::text_box_base::select_all ( )
inlineprotected
void gui2::text_box_base::set_active ( const bool  active)
overridevirtual
void gui2::text_box_base::set_cursor ( const size_t  offset,
const bool  select 
)
protected
void gui2::text_box_base::set_ellipse_mode ( const PangoEllipsizeMode  ellipse_mode)
inlineprotected

Definition at line 238 of file text_box_base.hpp.

References font::pango_text::set_ellipse_mode(), and text_.

Referenced by gui2::text_box::update_canvas().

void gui2::text_box_base::set_font_size ( const unsigned  font_size)
inlineprotected

Definition at line 218 of file text_box_base.hpp.

References font::pango_text::set_font_size(), and text_.

Referenced by gui2::text_box::text_box().

void gui2::text_box_base::set_font_style ( const font::pango_text::FONT_STYLE  font_style)
inlineprotected

Definition at line 223 of file text_box_base.hpp.

References font::pango_text::set_font_style(), and text_.

Referenced by gui2::text_box::text_box().

void gui2::text_box_base::set_maximum_height ( const int  height,
const bool  multiline 
)
inlineprotected

Definition at line 233 of file text_box_base.hpp.

References font::pango_text::set_maximum_height(), and text_.

Referenced by gui2::text_box::place().

void gui2::text_box_base::set_maximum_length ( const size_t  maximum_length)
void gui2::text_box_base::set_maximum_width ( const int  width)
inlineprotected

Definition at line 228 of file text_box_base.hpp.

References font::pango_text::set_maximum_width(), and text_.

Referenced by gui2::text_box::place().

void gui2::text_box_base::set_selection ( size_t  start,
int  length 
)

Sets or clears the text selection.

Setting the selection range will re-position the cursor depending on the selection direction, specified by the length's sign. Selecting beyond the start or end of the text is safe; the final selection will be limited accordingly.

Note
The range extents are measured in Unicode characters, not bytes. Using byte offsets may produce unexpected results depending on the text contents.
Parameters
startStart offset, in characters.
lengthSelection length, in characters. If zero, the current selection is canceled. If negative, the selection extends towards the start of the text and the cursor will be re-positioned in that direction as well; otherwise the selection and cursor extend towards the end.

Definition at line 230 of file text_box_base.cpp.

References font::pango_text::get_length(), set_cursor(), set_selection_length(), set_selection_start(), editor::start(), text_, and gui2::styled_widget::update_canvas().

Referenced by gui2::dialogs::file_dialog::clear_input_text(), and gui2::dialogs::file_dialog::set_input_text().

void gui2::text_box_base::set_selection_length ( const int  selection_length)
protected
void gui2::text_box_base::set_selection_start ( const size_t  selection_start)
protected

Definition at line 214 of file text_box_base.cpp.

References selection_start_, and gui2::widget::set_is_dirty().

Referenced by set_selection().

void gui2::text_box_base::set_state ( const state_t  state)
private
void gui2::text_box_base::set_text_changed_callback ( std::function< void(text_box_base *textbox, const std::string text)>  cb)
inline
void gui2::text_box_base::set_value ( const std::string &  text)
virtual
void gui2::text_box_base::signal_handler_lose_keyboard_focus ( const event::ui_event  event)
private

Definition at line 610 of file text_box_base.cpp.

References DBG_GUI_E, ENABLED, LOG_HEADER, and set_state().

Referenced by text_box_base().

void gui2::text_box_base::signal_handler_middle_button_click ( const event::ui_event  event,
bool &  handled 
)
private

Definition at line 461 of file text_box_base.cpp.

References DBG_GUI_E, LOG_HEADER, and paste_selection().

Referenced by text_box_base().

void gui2::text_box_base::signal_handler_receive_keyboard_focus ( const event::ui_event  event)
private

Definition at line 603 of file text_box_base.cpp.

References DBG_GUI_E, FOCUSED, LOG_HEADER, and set_state().

Referenced by text_box_base().

void gui2::text_box_base::signal_handler_sdl_key_down ( const event::ui_event  event,
bool &  handled,
const SDL_Keycode  key,
SDL_Keymod  modifier 
)
private
void gui2::text_box_base::signal_handler_sdl_text_input ( const event::ui_event  event,
bool &  handled,
const utf8::string unicode,
int32_t  start,
int32_t  len 
)
private
const std::string& gui2::text_box_base::text ( ) const
inline
void gui2::text_box_base::toggle_cursor_timer ( bool  enable)
privatevirtual

Member Data Documentation

unsigned short gui2::text_box_base::cursor_alpha_
private

Definition at line 327 of file text_box_base.hpp.

Referenced by cursor_timer_callback(), and reset_cursor_state().

unsigned short gui2::text_box_base::cursor_blink_rate_ms_
private

Definition at line 328 of file text_box_base.hpp.

Referenced by reset_cursor_state(), and toggle_cursor_timer().

size_t gui2::text_box_base::cursor_timer_
private

Definition at line 325 of file text_box_base.hpp.

Referenced by toggle_cursor_timer().

int gui2::text_box_base::ime_cursor_
private

Definition at line 322 of file text_box_base.hpp.

Referenced by handle_editing().

bool gui2::text_box_base::ime_in_progress_
private
int gui2::text_box_base::ime_length_
private
int gui2::text_box_base::ime_start_point_
private

Definition at line 321 of file text_box_base.hpp.

Referenced by get_composition_start(), handle_commit(), and handle_editing().

int gui2::text_box_base::selection_length_
private

Length of the selected text.

  • positive selection_len_ means selection to the right.
  • negative selection_len_ means selection to the left.
  • selection_len_ == 0 means no selection.

Definition at line 317 of file text_box_base.hpp.

Referenced by copy_selection(), get_selection_length(), handle_commit(), handle_key_backspace(), handle_key_delete(), handle_key_left_arrow(), handle_key_right_arrow(), set_cursor(), set_maximum_length(), set_selection_length(), and set_value().

size_t gui2::text_box_base::selection_start_
private
state_t gui2::text_box_base::state_
private

Current state of the widget.

The state of the widget determines what to render and how the widget reacts to certain 'events'.

Definition at line 299 of file text_box_base.hpp.

Referenced by cursor_timer_callback(), get_active(), get_state(), and set_state().

font::pango_text gui2::text_box_base::text_
private
std::string gui2::text_box_base::text_cached_
private

Cached version of the text without any pending IME modifications.

Definition at line 305 of file text_box_base.hpp.

Referenced by handle_editing().

std::function<void(text_box_base* textbox, const std::string text)> gui2::text_box_base::text_changed_callback_
private

Text changed callback.

This callback is called in key_press after the key_press event has been handled by the styled_widget. The parameters to the function are:

  • The widget invoking the callback
  • The new text of the textbox.

Definition at line 503 of file text_box_base.hpp.

Referenced by handle_commit(), set_text_changed_callback(), and signal_handler_sdl_key_down().


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