The Battle for Wesnoth  1.19.0-dev
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:

Public Types

enum  state_t { ENABLED , DISABLED , FOCUSED , HOVERED }
 Note the order of the states must be the same as defined in settings.hpp. More...
 
- Public Types inherited from gui2::widget
enum class  visibility { visible , hidden , invisible }
 Visibility settings done by the user. More...
 
enum class  redraw_action { full , partly , none }
 Visibility set by the engine. More...
 
enum class  debug_border { none , outline , fill }
 
- 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 class  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 std::size_t maximum_length)
 
std::size_t get_length () const
 Wrapper function, returns length of the text in pango column offsets. More...
 
std::vector< std::string > get_lines ()
 Wrapper function, returns a vector with the lines. More...
 
unsigned get_lines_count () const
 Wrapper function, return number of lines. More...
 
int get_byte_offset (const unsigned column) const
 Wrapper function, returns corrected column offset from pango. More...
 
void set_highlight_area (const unsigned start_offset, const unsigned end_offset, const color_t &color)
 Wrapper function, sets the area between column start and end offset to be highlighted in a specific color. More...
 
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 (std::size_t start, int length)
 Sets or clears the text selection. More...
 
void set_editable (bool editable)
 
bool is_editable ()
 
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 widget_item &data)
 Sets the members of the styled_widget. More...
 
bool disable_click_dismiss () const override
 See widget::disable_click_dismiss. More...
 
virtual iteration::walker_ptr create_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 &text)
 
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 type of this 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...
 
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...
 
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
 Calculates the blitting rectangle of the widget. More...
 
SDL_Rect calculate_clipping_rectangle () const
 Calculates the clipping rectangle of the widget. More...
 
bool draw_background ()
 Draws the background of a widget. More...
 
void draw_children ()
 Draws the children of a widget. More...
 
bool draw_foreground ()
 Draws the foreground of the widget. 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 queue_redraw ()
 Indicates that this widget should be redrawn. More...
 
void queue_redraw (const rect &region)
 Indicate that specific region of the screen should be redrawn. More...
 
void set_visible (const visibility visible)
 
visibility get_visible () const
 
redraw_action get_drawing_action () const
 
void set_debug_border_mode (const debug_border 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...
 
void disconnect ()
 Disconnects the dispatcher from the event handler. More...
 
bool is_connected () const
 Return whether the dispatcher is currently connected. 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 std::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-motion parameters. More...
 
bool fire (const ui_event event, widget &target, const point &center, float dTheta, float dDist, uint8_t numFingers)
 Fires an event which takes touch-gesture 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, const 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, typename F >
void connect_signal (const F &func, const queue_position position=back_child)
 Adds a callback to the appropriate queue based on event type. More...
 
template<ui_event E, typename F >
void disconnect_signal (const F &func, const queue_position position=back_child)
 Removes a callback from the appropriate queue based on event type. 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...
 
- Public Member Functions inherited from enable_lua_ptr< widget >
 enable_lua_ptr (widget *tp)
 

Protected Member Functions

size_t get_composition_length () const
 Get length of composition text by IME. More...
 
virtual void goto_end_of_line (const bool select=false)=0
 Moves the cursor to the end of the line. More...
 
virtual 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...
 
virtual 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...
 
virtual void set_cursor (const std::size_t offset, const bool select)
 Moves the cursor at the wanted position. More...
 
virtual void insert_char (const std::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
 
font::family_class get_font_family ()
 
void set_font_family (font::family_class fclass)
 
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)
 
std::size_t get_selection_start () const
 
void set_selection_start (const std::size_t selection_start)
 
std::size_t get_selection_length () const
 
void set_selection_length (const int selection_length)
 
std::size_t get_composition_start () const
 
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_commit (bool &handled, const std::string &unicode)
 
virtual void handle_editing (bool &handled, const std::string &unicode, int32_t start, int32_t length)
 SDL_TEXTEDITING handler. More...
 
- Protected Member Functions inherited from gui2::styled_widget
virtual point calculate_best_size () const override
 See widget::calculate_best_size. More...
 
resolution_definition_ptr get_config ()
 
resolution_definition_const_ptr get_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...
 
unsigned int get_text_font_size () const
 Resolves and returns the text_font_size. 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 bool impl_draw_background () override
 See widget::impl_draw_background. More...
 
virtual bool impl_draw_foreground () 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 ()
 
void update_mouse_cursor (bool enable)
 
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_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...
 
virtual void handle_key_enter (SDL_Keymod, bool &)
 Enter 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 std::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)
 
void signal_handler_mouse_enter (const event::ui_event event, bool &handled)
 
void signal_handler_mouse_leave (const event::ui_event event, bool &handled)
 

Private Attributes

state_t state_
 Current state of the widget. More...
 
font::pango_text text_
 The text entered in the widget. More...
 
font::family_class font_family_
 font family More...
 
std::string text_cached_
 Cached version of the text without any pending IME modifications. More...
 
std::size_t selection_start_
 Start of the selected text. More...
 
int selection_length_
 Length of the selected text. More...
 
bool editable_
 If this text_box_base is editable. More...
 
bool ime_composing_
 
int ime_start_point_
 
std::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 43 of file text_box_base.hpp.

Member Enumeration Documentation

◆ state_t

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

Enumerator
ENABLED 
DISABLED 
FOCUSED 
HOVERED 

Definition at line 335 of file text_box_base.hpp.

Constructor & Destructor Documentation

◆ text_box_base()

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

◆ ~text_box_base()

gui2::text_box_base::~text_box_base ( )

Definition at line 79 of file text_box_base.cpp.

References toggle_cursor_timer(), and update_mouse_cursor().

Member Function Documentation

◆ copy_selection()

void gui2::text_box_base::copy_selection ( const bool  mouse)
protectedvirtual

◆ cursor_timer_callback()

void gui2::text_box_base::cursor_timer_callback ( )
privatevirtual

◆ delete_char()

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, and gui2::multiline_text.

Referenced by handle_key_backspace(), and handle_key_delete().

◆ delete_selection()

virtual void gui2::text_box_base::delete_selection ( )
protectedpure virtual

◆ get_active()

bool gui2::text_box_base::get_active ( ) const
overridevirtual

See styled_widget::get_active.

Implements gui2::styled_widget.

Definition at line 92 of file text_box_base.cpp.

References DISABLED, and state_.

Referenced by set_active().

◆ get_byte_offset()

int gui2::text_box_base::get_byte_offset ( const unsigned  column) const
inline

Wrapper function, returns corrected column offset from pango.

See font::pango_text::get_byte_offset.

Definition at line 95 of file text_box_base.hpp.

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

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

◆ get_column_line()

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

◆ get_composition_length()

size_t gui2::text_box_base::get_composition_length ( ) const
protected

◆ get_composition_start()

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

◆ get_cursor_position()

point gui2::text_box_base::get_cursor_position ( const unsigned  column,
const unsigned  line = 0 
) const
inlineprotected

◆ get_font_family()

font::family_class gui2::text_box_base::get_font_family ( )
inlineprotected

Definition at line 270 of file text_box_base.hpp.

References font_family_.

Referenced by gui2::multiline_text::update_offsets().

◆ get_length()

std::size_t gui2::text_box_base::get_length ( ) const
inline

◆ get_lines()

std::vector<std::string> gui2::text_box_base::get_lines ( )
inline

Wrapper function, returns a vector with the lines.

See font::pango_text::get_lines.

Definition at line 77 of file text_box_base.hpp.

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

Referenced by gui2::multiline_text::get_line_end_offset().

◆ get_lines_count()

unsigned gui2::text_box_base::get_lines_count ( ) const
inline

◆ get_selection_length()

std::size_t gui2::text_box_base::get_selection_length ( ) const
inlineprotected

◆ get_selection_start()

std::size_t gui2::text_box_base::get_selection_start ( ) const
inlineprotected

◆ get_state()

unsigned gui2::text_box_base::get_state ( ) const
overridevirtual

See styled_widget::get_state.

Implements gui2::styled_widget.

Definition at line 97 of file text_box_base.cpp.

References state_.

◆ get_value()

std::string gui2::text_box_base::get_value ( ) const
inline

◆ goto_end_of_data()

virtual void gui2::text_box_base::goto_end_of_data ( const bool  select = false)
inlineprotectedvirtual

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?

Reimplemented in gui2::multiline_text.

Definition at line 189 of file text_box_base.hpp.

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

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

◆ goto_end_of_line()

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, and gui2::multiline_text.

Referenced by handle_key_end().

◆ goto_start_of_data()

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

Moves the cursor to the beginning of the data.

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

Reimplemented in gui2::multiline_text.

Definition at line 208 of file text_box_base.hpp.

References set_cursor().

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

◆ goto_start_of_line()

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, and gui2::multiline_text.

Referenced by handle_key_home().

◆ handle_commit()

void gui2::text_box_base::handle_commit ( bool &  handled,
const std::string &  unicode 
)
protectedvirtual

◆ handle_editing()

void gui2::text_box_base::handle_editing ( bool &  handled,
const std::string &  unicode,
int32_t  start,
int32_t  len 
)
protectedvirtual

◆ handle_key_backspace()

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 416 of file text_box_base.cpp.

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

Referenced by signal_handler_sdl_key_down().

◆ handle_key_clear_line()

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, and gui2::multiline_text.

Referenced by signal_handler_sdl_key_down().

◆ handle_key_delete()

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 434 of file text_box_base.cpp.

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

Referenced by signal_handler_sdl_key_down().

◆ handle_key_down_arrow()

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::multiline_text, and gui2::text_box.

Referenced by signal_handler_sdl_key_down().

◆ handle_key_end()

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 404 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().

◆ handle_key_enter()

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

Enter key.

Unmodified Handled by Window. Control Implementation defined. Shift Implementation defined. Alt Implementation defined.

Reimplemented in gui2::multiline_text.

Definition at line 560 of file text_box_base.hpp.

Referenced by signal_handler_sdl_key_down().

◆ handle_key_home()

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 392 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().

◆ handle_key_left_arrow()

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

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.

Reimplemented in gui2::multiline_text.

Definition at line 368 of file text_box_base.cpp.

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

Referenced by gui2::multiline_text::handle_key_left_arrow(), and signal_handler_sdl_key_down().

◆ handle_key_page_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 536 of file text_box_base.hpp.

Referenced by signal_handler_sdl_key_down().

◆ handle_key_page_up()

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 524 of file text_box_base.hpp.

Referenced by signal_handler_sdl_key_down().

◆ handle_key_right_arrow()

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

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.

Reimplemented in gui2::multiline_text.

Definition at line 380 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 gui2::multiline_text::handle_key_right_arrow(), and signal_handler_sdl_key_down().

◆ handle_key_tab()

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, and gui2::multiline_text.

Definition at line 548 of file text_box_base.hpp.

Referenced by signal_handler_sdl_key_down().

◆ handle_key_up_arrow()

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::multiline_text, and gui2::text_box.

Referenced by signal_handler_sdl_key_down().

◆ insert_char()

void gui2::text_box_base::insert_char ( const std::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, and gui2::multiline_text.

Definition at line 169 of file text_box_base.cpp.

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

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

◆ interrupt_composition()

void gui2::text_box_base::interrupt_composition ( )

Definition at line 202 of file text_box_base.cpp.

References ime_composing_.

Referenced by signal_handler_sdl_key_down().

◆ is_composing()

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

◆ is_editable()

bool gui2::text_box_base::is_editable ( )
inline

◆ paste_selection()

void gui2::text_box_base::paste_selection ( const bool  mouse)
protectedvirtual

◆ reset_cursor_state()

void gui2::text_box_base::reset_cursor_state ( )
privatevirtual

◆ select_all()

void gui2::text_box_base::select_all ( )
inlineprotected

◆ set_active()

void gui2::text_box_base::set_active ( const bool  active)
overridevirtual

◆ set_cursor()

void gui2::text_box_base::set_cursor ( const std::size_t  offset,
const bool  select 
)
protectedvirtual

◆ set_editable()

void gui2::text_box_base::set_editable ( bool  editable)
inline

◆ set_ellipse_mode()

void gui2::text_box_base::set_ellipse_mode ( const PangoEllipsizeMode  ellipse_mode)
inlineprotected

Definition at line 301 of file text_box_base.hpp.

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

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

◆ set_font_family()

void gui2::text_box_base::set_font_family ( font::family_class  fclass)
inlineprotected

Definition at line 275 of file text_box_base.hpp.

References font_family_, font::pango_text::set_family_class(), and text_.

Referenced by text_box_base().

◆ set_font_size()

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

Definition at line 281 of file text_box_base.hpp.

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

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

◆ set_font_style()

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

Definition at line 286 of file text_box_base.hpp.

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

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

◆ set_highlight_area()

void gui2::text_box_base::set_highlight_area ( const unsigned  start_offset,
const unsigned  end_offset,
const color_t color 
)
inline

Wrapper function, sets the area between column start and end offset to be highlighted in a specific color.

See font::pango_text::set_highlight_area.

Definition at line 105 of file text_box_base.hpp.

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

◆ set_maximum_height()

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

◆ set_maximum_length()

void gui2::text_box_base::set_maximum_length ( const std::size_t  maximum_length)

◆ set_maximum_width()

void gui2::text_box_base::set_maximum_width ( const int  width)
inlineprotected

◆ set_selection()

void gui2::text_box_base::set_selection ( std::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 267 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 handle_commit(), and gui2::dialogs::screenshot_notification::pre_show().

◆ set_selection_length()

void gui2::text_box_base::set_selection_length ( const int  selection_length)
protected

◆ set_selection_start()

void gui2::text_box_base::set_selection_start ( const std::size_t  selection_start)
protected

Definition at line 251 of file text_box_base.cpp.

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

Referenced by set_selection().

◆ set_state()

void gui2::text_box_base::set_state ( const state_t  state)
private

◆ set_text_changed_callback()

void gui2::text_box_base::set_text_changed_callback ( std::function< void(text_box_base *textbox, const std::string text)>  cb)
inline

◆ set_value()

void gui2::text_box_base::set_value ( const std::string &  text)
virtual

The set_value is virtual for the password_box class.

That class overrides the set_value function to replace it with asterisk. There might be more generic way to do it when more classes are needed.

Reimplemented in gui2::password_box.

Definition at line 124 of file text_box_base.cpp.

References font::pango_text::get_length(), gui2::widget::queue_redraw(), selection_length_, selection_start_, font::pango_text::set_text(), font::pango_text::text(), text(), text_, and gui2::styled_widget::update_canvas().

Referenced by gui2::chatbox::chat_input_keypress_callback(), gui2::multiline_text::clear(), gui2::text_box::clear(), gui2::multiline_text::delete_selection(), gui2::text_box::delete_selection(), gui2::dialogs::mp_options_helper::display_custom_options(), gui2::multiline_text::handle_key_clear_line(), gui2::text_box::handle_key_clear_line(), gui2::multiline_text::history_down(), gui2::text_box::history_down(), gui2::multiline_text::history_up(), gui2::text_box::history_up(), gui2::dialogs::mp_login::load_password(), gui2::dialogs::preferences_dialog::on_friends_list_select(), gui2::dialogs::mp_connect::on_server_select(), gui2::dialogs::addon_auth::pre_show(), gui2::dialogs::editor_edit_pbl::pre_show(), gui2::dialogs::game_cache_options::pre_show(), gui2::dialogs::game_version::pre_show(), gui2::dialogs::mp_match_history::pre_show(), gui2::dialogs::mp_method_selection::pre_show(), gui2::dialogs::screenshot_notification::pre_show(), gui2::dialogs::wml_message_base::pre_show(), gui2::spinner::set_value(), and gui2::password_box::set_value().

◆ signal_handler_lose_keyboard_focus()

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

Definition at line 700 of file text_box_base.cpp.

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

Referenced by text_box_base().

◆ signal_handler_middle_button_click()

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

Definition at line 523 of file text_box_base.cpp.

References DBG_GUI_E, LOG_HEADER, and paste_selection().

Referenced by text_box_base().

◆ signal_handler_mouse_enter()

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

Definition at line 707 of file text_box_base.cpp.

References DBG_GUI_E, FOCUSED, HOVERED, LOG_HEADER, set_state(), state_, and update_mouse_cursor().

Referenced by text_box_base().

◆ signal_handler_mouse_leave()

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

Definition at line 721 of file text_box_base.cpp.

References DBG_GUI_E, ENABLED, FOCUSED, LOG_HEADER, set_state(), state_, and update_mouse_cursor().

Referenced by text_box_base().

◆ signal_handler_receive_keyboard_focus()

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

Definition at line 693 of file text_box_base.cpp.

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

Referenced by text_box_base().

◆ signal_handler_sdl_key_down()

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

◆ signal_handler_sdl_text_input()

void gui2::text_box_base::signal_handler_sdl_text_input ( const event::ui_event  event,
bool &  handled,
const std::string &  unicode,
int32_t  start,
int32_t  len 
)
private

◆ text()

const std::string& gui2::text_box_base::text ( ) const
inline

◆ toggle_cursor_timer()

void gui2::text_box_base::toggle_cursor_timer ( bool  enable)
privatevirtual

◆ update_mouse_cursor()

void gui2::text_box_base::update_mouse_cursor ( bool  enable)
private

Member Data Documentation

◆ cursor_alpha_

unsigned short gui2::text_box_base::cursor_alpha_
private

Definition at line 392 of file text_box_base.hpp.

Referenced by cursor_timer_callback(), and reset_cursor_state().

◆ cursor_blink_rate_ms_

unsigned short gui2::text_box_base::cursor_blink_rate_ms_
private

Definition at line 393 of file text_box_base.hpp.

Referenced by reset_cursor_state(), and toggle_cursor_timer().

◆ cursor_timer_

std::size_t gui2::text_box_base::cursor_timer_
private

Definition at line 390 of file text_box_base.hpp.

Referenced by toggle_cursor_timer().

◆ editable_

bool gui2::text_box_base::editable_
private

If this text_box_base is editable.

Definition at line 384 of file text_box_base.hpp.

Referenced by insert_char(), is_editable(), paste_selection(), and set_editable().

◆ font_family_

font::family_class gui2::text_box_base::font_family_
private

font family

Definition at line 366 of file text_box_base.hpp.

Referenced by get_font_family(), and set_font_family().

◆ ime_composing_

bool gui2::text_box_base::ime_composing_
private

◆ ime_start_point_

int gui2::text_box_base::ime_start_point_
private

Definition at line 388 of file text_box_base.hpp.

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

◆ selection_length_

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 381 of file text_box_base.hpp.

Referenced by copy_selection(), get_selection_length(), 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().

◆ selection_start_

std::size_t gui2::text_box_base::selection_start_
private

◆ state_

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 360 of file text_box_base.hpp.

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

◆ text_

font::pango_text gui2::text_box_base::text_
private

◆ text_cached_

std::string gui2::text_box_base::text_cached_
private

Cached version of the text without any pending IME modifications.

Definition at line 369 of file text_box_base.hpp.

Referenced by get_composition_length(), and handle_editing().

◆ text_changed_callback_

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 582 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: