16 #define GETTEXT_DOMAIN "wesnoth-lib"
30 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
31 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
33 using namespace std::chrono_literals;
43 , selection_length_(0)
45 , ime_composing_(false)
49 , cursor_blink_rate_(750ms)
50 , text_changed_callback_()
57 connect_signal<event::MIDDLE_BUTTON_CLICK>(std::bind(
62 connect_signal<event::SDL_KEY_DOWN>(std::bind(
65 connect_signal<event::SDL_TEXT_EDITING>(std::bind(&
text_box_base::handle_editing,
this, std::placeholders::_3, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7));
67 connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(std::bind(
69 connect_signal<event::LOSE_KEYBOARD_FOCUS>(
72 connect_signal<event::MOUSE_ENTER>(
74 connect_signal<event::MOUSE_LEAVE>(
105 if(maximum_length == 0) {
167 cursor_pos = plain_text_len;
183 if(text_length < text_cached_length) {
195 SDL_StartTextInput();
259 if(
start >= text_size) {
270 const int sel_start = std::min<std::size_t>(
start, std::numeric_limits<int>::max());
271 const int sel_max_length = std::min<std::size_t>(text_size -
start, std::numeric_limits<int>::max());
273 const bool backwards = length < 0;
275 if(backwards && -length > sel_start) {
277 }
else if(!backwards && length > sel_max_length) {
278 length = sel_max_length;
364 set_cursor(offset, (modifier & KMOD_SHIFT) != 0);
376 set_cursor(offset, (modifier & KMOD_SHIFT) != 0);
385 if(modifier & KMOD_CTRL) {
397 if(modifier & KMOD_CTRL) {
444 if(unicode.size() > 1 || unicode[0] != 0) {
464 if(unicode.size() > 1 || unicode[0] != 0) {
480 SDL_SetTextInputRect(&
rect);
523 const SDL_Keycode key,
539 const SDL_Keycode modifier_key = KMOD_GUI;
543 const SDL_Keycode modifier_key = KMOD_CTRL;
573 if(!(modifier & modifier_key)) {
615 if(!(modifier & modifier_key)) {
626 if( !(modifier & modifier_key) ) {
639 if( !(modifier & modifier_key) || !
is_editable() ) {
660 if(!
is_composing() || (modifier & (KMOD_CTRL | KMOD_ALT | KMOD_GUI | KMOD_SHIFT))) {
std::size_t get_length() const
Gets the length of the text in bytes.
pango_text & set_maximum_length(const std::size_t maximum_length)
unsigned insert_text(const unsigned offset, const std::string &text, const bool use_markup=false)
Inserts UTF-8 text.
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
const std::string & text() const
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
virtual void handle_key_backspace(SDL_Keymod modifier, bool &handled)
Backspace key pressed.
virtual void handle_commit(bool &handled, const std::string &unicode)
virtual bool get_active() const override
See styled_widget::get_active.
virtual unsigned get_state() const override
See styled_widget::get_state.
std::function< void(text_box_base *textbox, const std::string text)> text_changed_callback_
Text changed callback.
void update_mouse_cursor(bool enable)
virtual void goto_start_of_line(const bool select=false)=0
Moves the cursor to the beginning of the line.
virtual void handle_key_delete(SDL_Keymod modifier, bool &handled)
Delete key pressed.
virtual void insert_char(const std::string &unicode)
Inserts a character at the cursor.
virtual void handle_editing(bool &handled, const std::string &unicode, int32_t start, int32_t length)
SDL_TEXTEDITING handler.
void set_state(const state_t state)
std::chrono::milliseconds cursor_blink_rate_
virtual void copy_selection()
Copies the current selection.
virtual void handle_key_left_arrow(SDL_Keymod modifier, bool &handled)
Left arrow key pressed.
virtual void toggle_cursor_timer(bool enable)
state_t state_
Current state of the widget.
virtual void goto_end_of_line(const bool select=false)=0
Moves the cursor to the end of the line.
void signal_handler_mouse_leave(const event::ui_event event, bool &handled)
void set_selection(std::size_t start, int length)
Sets or clears the text selection.
std::size_t selection_start_
Start of the selected text.
size_t get_composition_length() const
Get length of composition text by IME.
virtual void handle_key_enter(SDL_Keymod, bool &)
Enter key.
int selection_length_
Length of the selected text.
unsigned short cursor_alpha_
std::size_t cursor_timer_
virtual void handle_key_up_arrow(SDL_Keymod modifier, bool &handled)=0
Every key can have several behaviors.
const std::string & text() const
point get_cursor_position(const unsigned column, const unsigned line=0) const
void signal_handler_mouse_enter(const event::ui_event event, bool &handled)
virtual void handle_key_tab(SDL_Keymod, bool &)
Tab key.
std::string text_cached_
Cached version of the text without any pending IME modifications.
void set_font_family(font::family_class fclass)
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
virtual void paste_selection()
Pastes the current selection.
state_t
Note the order of the states must be the same as defined in settings.hpp.
font::pango_text text_
The text entered in the widget.
void signal_handler_lose_keyboard_focus(const event::ui_event event)
void signal_handler_sdl_key_down(const event::ui_event event, bool &handled, const SDL_Keycode key, SDL_Keymod modifier)
virtual void handle_key_right_arrow(SDL_Keymod modifier, bool &handled)
Right arrow key pressed.
virtual void handle_key_clear_line(SDL_Keymod modifier, bool &handled)=0
Clears the current line.
void set_selection_start(const std::size_t selection_start)
virtual void set_cursor(const std::size_t offset, const bool select)
Moves the cursor at the wanted position.
virtual void handle_key_page_up(SDL_Keymod, bool &)
Page up key.
void interrupt_composition()
virtual void handle_key_home(SDL_Keymod modifier, bool &handled)
Home key pressed.
bool is_editable() const
Check whether text can be edited or not.
virtual void handle_key_down_arrow(SDL_Keymod modifier, bool &handled)=0
Down arrow key pressed.
void signal_handler_receive_keyboard_focus(const event::ui_event event)
virtual void goto_end_of_data(const bool select=false)
Moves the cursor to the end of all text.
void signal_handler_middle_button_click(const event::ui_event event, bool &handled)
virtual void handle_key_end(SDL_Keymod modifier, bool &handled)
End key pressed.
virtual void handle_key_page_down(SDL_Keymod, bool &)
Page down key.
virtual void set_active(const bool active) override
See styled_widget::set_active.
void set_selection_length(const int selection_length)
bool is_composing() const
bool editable_
If this text_box_base is editable.
virtual void goto_start_of_data(const bool select=false)
Moves the cursor to the beginning of the data.
virtual void cursor_timer_callback()
Implements blinking cursor functionality.
virtual void reset_cursor_state()
void set_maximum_length(const std::size_t maximum_length)
virtual void delete_selection()=0
Deletes the current selection.
virtual void delete_char(const bool before_cursor)=0
Deletes the character.
void select_all()
Selects all text.
Define the common log macros for the gui toolkit.
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
void copy_to_clipboard(const std::string &text)
Copies text to the clipboard.
std::string copy_from_clipboard()
Copies text from the clipboard.
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
ui_event
The event sent to the dispatcher.
std::size_t add_timer(const std::chrono::milliseconds &interval, const std::function< void(std::size_t id)> &callback, const bool repeat)
Adds a new timer.
bool remove_timer(const std::size_t id)
Removes a timer.
std::vector< window * > open_window_stack
Keeps track of any open windows of any type (modal, non-modal, or tooltip) in the order in which they...
resolution_definition_ptr get_control(const std::string &control_type, const std::string &definition)
Returns the appropriate config data for a widget instance fom the active GUI definition.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
std::string & insert(std::string &str, const std::size_t pos, const std::string &insert)
Insert a UTF-8 string at the specified position.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
An abstract description of a rectangle with integer coordinates.
Contains the gui2 timer routines.