16 #define GETTEXT_DOMAIN "wesnoth-lib"
32 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
33 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
35 using namespace std::chrono_literals;
45 , selection_length_(0)
47 , ime_composing_(false)
51 , cursor_blink_rate_(750ms)
58 connect_signal<event::MIDDLE_BUTTON_CLICK>(std::bind(
63 connect_signal<event::SDL_KEY_DOWN>(std::bind(
66 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));
68 connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(std::bind(
70 connect_signal<event::LOSE_KEYBOARD_FOCUS>(
73 connect_signal<event::MOUSE_ENTER>(
75 connect_signal<event::MOUSE_LEAVE>(
106 if(maximum_length == 0) {
175 cursor_pos = plain_text_len;
191 if(text_length < text_cached_length) {
203 SDL_StartTextInput();
267 if(
start >= text_size) {
278 const int sel_start = std::min<std::size_t>(
start, std::numeric_limits<int>::max());
279 const int sel_max_length = std::min<std::size_t>(text_size -
start, std::numeric_limits<int>::max());
281 const bool backwards = length < 0;
283 if(backwards && -length > sel_start) {
285 }
else if(!backwards && length > sel_max_length) {
286 length = sel_max_length;
374 set_cursor(offset, (modifier & KMOD_SHIFT) != 0);
386 set_cursor(offset, (modifier & KMOD_SHIFT) != 0);
395 if(modifier & KMOD_CTRL) {
407 if(modifier & KMOD_CTRL) {
454 if(unicode.size() > 1 || unicode[0] != 0) {
470 if(unicode.size() > 1 || unicode[0] != 0) {
486 SDL_SetTextInputRect(&
rect);
529 const SDL_Keycode key,
545 const SDL_Keycode modifier_key = KMOD_GUI;
549 const SDL_Keycode modifier_key = KMOD_CTRL;
579 if(!(modifier & modifier_key)) {
621 if(!(modifier & modifier_key)) {
632 if( !(modifier & modifier_key) ) {
645 if( !(modifier & modifier_key) || !
is_editable() ) {
666 if(!
is_composing() || (modifier & (KMOD_CTRL | KMOD_ALT | KMOD_GUI | KMOD_SHIFT))) {
Helper class to encapsulate the management of a PangoAttrList.
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.
void apply_attributes(const font::attribute_list &attrs)
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
const std::string & text() const
Base class for event handling.
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.
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)
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 c...
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.
void add_attribute_bg_color(attribute_list &list, unsigned offset_start, unsigned offset_end, const color_t &color)
Mark a specific portion of text for highlighting.
ui_event
The event sent to the dispatcher.
std::vector< dispatcher * > & get_all_dispatchers()
Gets all event dispatchers in the Z order.
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.
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::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(std::string_view str)
Length in characters of a UTF-8 string.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
The basic class for representing 8-bit RGB or RGBA colour values.
An abstract description of a rectangle with integer coordinates.
Contains the gui2 timer routines.