Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes

gui2::ttext_ Class Reference

Abstract base class for text items. More...

#include <text.hpp>

Inheritance diagram for gui2::ttext_:
Inheritance graph
[legend]
Collaboration diagram for gui2::ttext_:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ttext_ ()
void set_active (const bool active)
 Inherited from tcontrol.
bool get_active () const
 Inherited from tcontrol.
unsigned get_state () const
 Inherited from tcontrol.
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 tpassword_box class.
std::string get_value () const
const std::string & text () const
void set_text_changed_callback (boost::function< void(ttext_ *textbox, const std::string text) > cb)
 Set the text_changed callback.

Protected Member Functions

virtual void goto_end_of_line (const bool select=false)=0
 Moves the cursor to the end of the line.
void goto_end_of_data (const bool select=false)
 Moves the cursor to the end of all text.
virtual void goto_start_of_line (const bool select=false)=0
 Moves the cursor to the beginning of the line.
void goto_start_of_data (const bool select=false)
 Moves the cursor to the beginning of the data.
void select_all ()
 Selects all text.
void set_cursor (const size_t offset, const bool select)
 Moves the cursor at the wanted position.
virtual void insert_char (const Uint16 unicode)
 Inserts a character at the cursor.
virtual void delete_char (const bool before_cursor)=0
 Deletes the character.
virtual void delete_selection ()=0
 Deletes the current selection.
virtual void copy_selection (const bool mouse)
 Copies the current selection.
virtual void paste_selection (const bool mouse)
 Pastes the current selection.
gui2::tpoint get_cursor_position (const unsigned column, const unsigned line=0) const
tpoint get_column_line (const tpoint &position) const
void set_font_size (const unsigned font_size)
void set_font_style (const unsigned font_style)
void set_maximum_width (const int width)
void set_maximum_height (const int height)
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)
virtual void handle_key_default (bool &handled, SDLKey key, SDLMod modifier, Uint16 unicode)
 Default key handler if none of the above functions is called.

Private Types

enum  tstate { ENABLED, DISABLED, FOCUSSED, COUNT }
 

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

More...

Private Member Functions

void set_state (const tstate state)
virtual void handle_key_up_arrow (SDLMod modifier, bool &handled)=0
 Every key can have several behaviours.
virtual void handle_key_down_arrow (SDLMod modifier, bool &handled)=0
 Down arrow key pressed.
virtual void handle_key_clear_line (SDLMod modifier, bool &handled)=0
 Clears the current line.
virtual void handle_key_left_arrow (SDLMod modifier, bool &handled)
 Left arrow key pressed.
virtual void handle_key_right_arrow (SDLMod modifier, bool &handled)
 Right arrow key pressed.
virtual void handle_key_home (SDLMod modifier, bool &handled)
 Home key pressed.
virtual void handle_key_end (SDLMod modifier, bool &handled)
 End key pressed.
virtual void handle_key_backspace (SDLMod modifier, bool &handled)
 Backspace key pressed.
virtual void handle_key_delete (SDLMod modifier, bool &handled)
 Delete key pressed.
virtual void handle_key_page_up (SDLMod, bool &)
 Page up key.
virtual void handle_key_page_down (SDLMod, bool &)
 Page down key.
void signal_handler_middle_button_click (const event::tevent event, bool &handled)
void signal_handler_sdl_key_down (const event::tevent event, bool &handled, const SDLKey key, SDLMod modifier, const Uint16 unicode)
void signal_handler_receive_keyboard_focus (const event::tevent event)
void signal_handler_lose_keyboard_focus (const event::tevent event)

Private Attributes

tstate state_
 Current state of the widget.
font::ttext text_
 The text entered in the widget.
size_t selection_start_
 Start of the selected text.
int selection_length_
 Length of the selected text.
boost::function< void(ttext_
*textbox, const std::string
text) 
text_changed_callback_ )
 Text changed callback.

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.hpp.


Member Enumeration Documentation

enum gui2::ttext_::tstate [private]

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

Enumerator:
ENABLED 
DISABLED 
FOCUSSED 
COUNT 

Definition at line 197 of file text.hpp.


Constructor & Destructor Documentation

gui2::ttext_::ttext_ (  ) 

Member Function Documentation

void gui2::ttext_::copy_selection ( const bool  mouse  )  [protected, virtual]

Copies the current selection.

Definition at line 126 of file text.cpp.

References copy_to_clipboard(), selection_length_, selection_start_, editor::start(), utils::string_to_wstring(), text(), text_, and utils::wstring_to_string().

Referenced by set_cursor(), and signal_handler_sdl_key_down().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void gui2::ttext_::delete_char ( const bool  before_cursor  )  [protected, pure virtual]

Deletes the character.

Parameters:
before_cursor If true it deletes the character before the cursor (backspace) else the character after the cursor (delete).

Implemented in gui2::tpassword_box, and gui2::ttext_box.

Referenced by handle_key_backspace(), and handle_key_delete().

Here is the caller graph for this function:

virtual void gui2::ttext_::delete_selection (  )  [protected, pure virtual]

Deletes the current selection.

Implemented in gui2::ttext_box.

Referenced by handle_key_backspace(), handle_key_delete(), insert_char(), paste_selection(), and signal_handler_sdl_key_down().

Here is the caller graph for this function:

bool gui2::ttext_::get_active (  )  const [inline, virtual]

Inherited from tcontrol.

Implements gui2::tcontrol.

Definition at line 54 of file text.hpp.

References state_.

Referenced by set_active().

Here is the caller graph for this function:

tpoint gui2::ttext_::get_column_line ( const tpoint position  )  const [inline, protected]

Definition at line 168 of file text.hpp.

References text_.

Referenced by gui2::ttext_box::handle_mouse_selection().

Here is the caller graph for this function:

gui2::tpoint gui2::ttext_::get_cursor_position ( const unsigned  column,
const unsigned  line = 0 
) const [inline, protected]

Definition at line 164 of file text.hpp.

References text_.

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

Here is the caller graph for this function:

size_t gui2::ttext_::get_length (  )  const [inline]

Definition at line 63 of file text.hpp.

References text_.

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

Here is the caller graph for this function:

size_t gui2::ttext_::get_selection_length (  )  const [inline, protected]
size_t gui2::ttext_::get_selection_start (  )  const [inline, protected]
unsigned gui2::ttext_::get_state (  )  const [inline, virtual]

Inherited from tcontrol.

Implements gui2::tcontrol.

Definition at line 57 of file text.hpp.

References state_.

std::string gui2::ttext_::get_value (  )  const [inline]
void gui2::ttext_::goto_end_of_data ( const bool  select = false  )  [inline, protected]

Moves the cursor to the end of all text.

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

Parameters:
select Select the text from the original cursor position till the end of the data?

Definition at line 103 of file text.hpp.

References set_cursor(), and text_.

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

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void gui2::ttext_::goto_end_of_line ( const bool  select = false  )  [protected, pure virtual]

Moves the cursor to the end of the line.

Parameters:
select Select the text from the original cursor position till the end of the line?

Implemented in gui2::ttext_box.

Referenced by handle_key_end().

Here is the caller graph for this function:

void gui2::ttext_::goto_start_of_data ( const bool  select = false  )  [inline, protected]

Moves the cursor to the beginning of the data.

Parameters:
select Select the text from the original cursor position till the beginning of the data?

Definition at line 120 of file text.hpp.

References set_cursor().

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

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void gui2::ttext_::goto_start_of_line ( const bool  select = false  )  [protected, pure virtual]

Moves the cursor to the beginning of the line.

Parameters:
select Select the text from the original cursor position till the beginning of the line?

Implemented in gui2::ttext_box.

Referenced by handle_key_home().

Here is the caller graph for this function:

void gui2::ttext_::handle_key_backspace ( SDLMod  modifier,
bool &  handled 
) [private, virtual]

Backspace key pressed.

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

Reimplemented in gui2::tpassword_box.

Definition at line 235 of file text.cpp.

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

Referenced by signal_handler_sdl_key_down().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void gui2::ttext_::handle_key_clear_line ( SDLMod  modifier,
bool &  handled 
) [private, pure virtual]

Clears the current line.

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

Implemented in gui2::ttext_box.

Referenced by signal_handler_sdl_key_down().

Here is the caller graph for this function:

void gui2::ttext_::handle_key_default ( bool &  handled,
SDLKey  key,
SDLMod  modifier,
Uint16  unicode 
) [protected, virtual]

Default key handler if none of the above functions is called.

Unmodified If invalid unicode it's ignored. Else if text selected the selected text is replaced with the unicode character send. Else the unicode character is inserted after the cursor. Control Ignored. Shift Ignored (already in the unicode value). Alt Ignored.

Reimplemented in gui2::ttext_box.

Definition at line 261 of file text.cpp.

References DBG_GUI_E, gui2::event::tdispatcher::fire(), insert_char(), LOG_SCOPE_HEADER, and gui2::event::NOTIFY_MODIFIED.

Referenced by signal_handler_sdl_key_down().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::handle_key_delete ( SDLMod  modifier,
bool &  handled 
) [private, virtual]

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.

Reimplemented in gui2::tpassword_box.

Definition at line 248 of file text.cpp.

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

Referenced by signal_handler_sdl_key_down().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void gui2::ttext_::handle_key_down_arrow ( SDLMod  modifier,
bool &  handled 
) [private, pure virtual]

Down arrow key pressed.

The behaviour is implementation defined.

Implemented in gui2::ttext_box.

Referenced by signal_handler_sdl_key_down().

Here is the caller graph for this function:

void gui2::ttext_::handle_key_end ( SDLMod  modifier,
bool &  handled 
) [private, virtual]

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 223 of file text.cpp.

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

Referenced by signal_handler_sdl_key_down().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::handle_key_home ( SDLMod  modifier,
bool &  handled 
) [private, virtual]

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 211 of file text.cpp.

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

Referenced by signal_handler_sdl_key_down().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::handle_key_left_arrow ( SDLMod  modifier,
bool &  handled 
) [private, virtual]

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 187 of file text.cpp.

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

Referenced by signal_handler_sdl_key_down().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void gui2::ttext_::handle_key_page_down ( SDLMod  ,
bool &   
) [inline, private, virtual]

Page down key.

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

Definition at line 362 of file text.hpp.

Referenced by signal_handler_sdl_key_down().

Here is the caller graph for this function:

virtual void gui2::ttext_::handle_key_page_up ( SDLMod  ,
bool &   
) [inline, private, virtual]

Page up key.

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

Definition at line 352 of file text.hpp.

Referenced by signal_handler_sdl_key_down().

Here is the caller graph for this function:

void gui2::ttext_::handle_key_right_arrow ( SDLMod  modifier,
bool &  handled 
) [private, virtual]

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 199 of file text.cpp.

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

Referenced by signal_handler_sdl_key_down().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void gui2::ttext_::handle_key_up_arrow ( SDLMod  modifier,
bool &  handled 
) [private, pure virtual]

Every key can have several behaviours.

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 behaviour is implementation defined.

Implemented in gui2::ttext_box.

Referenced by signal_handler_sdl_key_down().

Here is the caller graph for this function:

void gui2::ttext_::insert_char ( const Uint16  unicode  )  [protected, virtual]

Inserts a character at the cursor.

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

Parameters:
unicode The unicode value of the character to insert.

Reimplemented in gui2::tpassword_box.

Definition at line 113 of file text.cpp.

References delete_selection(), selection_start_, set_cursor(), gui2::twidget::set_dirty(), text_, and gui2::tcontrol::update_canvas().

Referenced by handle_key_default().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::paste_selection ( const bool  mouse  )  [protected, virtual]

Pastes the current selection.

Reimplemented in gui2::tpassword_box.

Definition at line 147 of file text.cpp.

References copy_from_clipboard(), delete_selection(), gui2::event::tdispatcher::fire(), gui2::event::NOTIFY_MODIFIED, selection_start_, gui2::twidget::set_dirty(), text(), text_, and gui2::tcontrol::update_canvas().

Referenced by signal_handler_middle_button_click(), and signal_handler_sdl_key_down().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::select_all (  )  [inline, protected]

Selects all text.

Definition at line 123 of file text.hpp.

References goto_end_of_data(), and selection_start_.

Referenced by gui2::ttext_box::signal_handler_left_button_double_click().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::set_active ( const bool  active  )  [inline, virtual]

Inherited from tcontrol.

Implements gui2::tcontrol.

Definition at line 50 of file text.hpp.

References DISABLED, ENABLED, get_active(), and set_state().

Here is the call graph for this function:

void gui2::ttext_::set_cursor ( const size_t  offset,
const bool  select 
) [protected]

Moves the cursor at the wanted position.

Parameters:
offset The wanted new cursor position.
select Select the text from the original cursor position till the new position?

Definition at line 86 of file text.cpp.

References copy_selection(), selection_length_, selection_start_, gui2::twidget::set_dirty(), text_, and gui2::tcontrol::update_canvas().

Referenced by gui2::ttext_box::delete_char(), gui2::ttext_box::delete_selection(), goto_end_of_data(), goto_start_of_data(), handle_key_left_arrow(), handle_key_right_arrow(), gui2::ttext_box::handle_mouse_selection(), and insert_char().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::set_ellipse_mode ( const PangoEllipsizeMode  ellipse_mode  )  [inline, protected]

Definition at line 183 of file text.hpp.

References text_.

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

Here is the caller graph for this function:

void gui2::ttext_::set_font_size ( const unsigned  font_size  )  [inline, protected]

Definition at line 171 of file text.hpp.

References text_.

Referenced by gui2::ttext_box::load_config_extra().

Here is the caller graph for this function:

void gui2::ttext_::set_font_style ( const unsigned  font_style  )  [inline, protected]

Definition at line 174 of file text.hpp.

References text_.

Referenced by gui2::ttext_box::load_config_extra().

Here is the caller graph for this function:

void gui2::ttext_::set_maximum_height ( const int  height  )  [inline, protected]

Definition at line 180 of file text.hpp.

References text_.

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

Here is the caller graph for this function:

void gui2::ttext_::set_maximum_length ( const size_t  maximum_length  ) 

Definition at line 55 of file text.cpp.

References selection_length_, selection_start_, gui2::twidget::set_dirty(), text_, and gui2::tcontrol::update_canvas().

Referenced by gui2::tmp_method_selection::pre_show().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::set_maximum_width ( const int  width  )  [inline, protected]

Definition at line 177 of file text.hpp.

References text_.

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

Here is the caller graph for this function:

void gui2::ttext_::set_selection_length ( const int  selection_length  )  [protected]

Definition at line 171 of file text.cpp.

References selection_length_, and gui2::twidget::set_dirty().

Referenced by gui2::ttext_box::delete_char(), gui2::tpassword_box::post_function(), and gui2::tpassword_box::pre_function().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::set_selection_start ( const size_t  selection_start  )  [protected]

Definition at line 163 of file text.cpp.

References selection_start_, and gui2::twidget::set_dirty().

Referenced by gui2::tpassword_box::post_function(), and gui2::tpassword_box::pre_function().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::set_state ( const tstate  state  )  [private]

Definition at line 179 of file text.cpp.

References gui2::twidget::set_dirty(), and state_.

Referenced by set_active(), signal_handler_lose_keyboard_focus(), and signal_handler_receive_keyboard_focus().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::set_text_changed_callback ( boost::function< void(ttext_ *textbox, const std::string text) >  cb  )  [inline]

Set the text_changed callback.

Definition at line 79 of file text.hpp.

References text_changed_callback_.

Referenced by gui2::tdata_manage::pre_show().

Here is the caller graph for this function:

void gui2::ttext_::set_value ( const std::string &  text  )  [virtual]

The set_value is virtual for the tpassword_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::tpassword_box.

Definition at line 73 of file text.cpp.

References selection_length_, selection_start_, gui2::twidget::set_dirty(), text_, and gui2::tcontrol::update_canvas().

Referenced by gui2::tlobby_main::chat_input_keypress_callback(), gui2::ttext_box::delete_selection(), gui2::ttext_box::handle_key_clear_line(), gui2::ttext_box::history_down(), gui2::ttext_box::history_up(), gui2::tmp_method_selection::pre_show(), and gui2::tlobby_main::send_message_button_callback().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::signal_handler_lose_keyboard_focus ( const event::tevent  event  )  [private]

Definition at line 422 of file text.cpp.

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

Referenced by ttext_().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::signal_handler_middle_button_click ( const event::tevent  event,
bool &  handled 
) [private]

Definition at line 273 of file text.cpp.

References DBG_GUI_E, LOG_HEADER, and paste_selection().

Referenced by ttext_().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::signal_handler_receive_keyboard_focus ( const event::tevent  event  )  [private]

Definition at line 415 of file text.cpp.

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

Referenced by ttext_().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::ttext_::signal_handler_sdl_key_down ( const event::tevent  event,
bool &  handled,
const SDLKey  key,
SDLMod  modifier,
const Uint16  unicode 
) [private]
const std::string& gui2::ttext_::text (  )  const [inline]

Definition at line 76 of file text.hpp.

References text_.

Referenced by gui2::contains(), copy_selection(), gui2::ttext_box::delete_selection(), gui2::tpassword_box::handle_key_delete(), paste_selection(), and signal_handler_sdl_key_down().

Here is the caller graph for this function:


Member Data Documentation

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 222 of file text.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().

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 207 of file text.hpp.

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

font::ttext gui2::ttext_::text_ [private]
boost::function< void (ttext_* textbox, const std::string text) gui2::ttext_::text_changed_callback_) [private]

Text changed callback.

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

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

Definition at line 390 of file text.hpp.

Referenced by set_text_changed_callback(), and signal_handler_sdl_key_down().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:23:28 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs