16 #define GETTEXT_DOMAIN "wesnoth-lib"
34 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
35 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
47 , max_input_length_(builder.max_input_length)
52 , link_aware_(builder.link_aware)
53 , hint_text_(builder.hint_text)
54 , hint_image_(builder.hint_image)
56 set_wants_mouse_left_double_click();
58 connect_signal<event::MOUSE_MOTION>(std::bind(
60 connect_signal<event::LEFT_BUTTON_DOWN>(std::bind(
62 connect_signal<event::LEFT_BUTTON_UP>(std::bind(
64 connect_signal<event::LEFT_BUTTON_DOUBLE_CLICK>(std::bind(
67 const auto conf = cast_config_to<multiline_text_definition>();
70 set_font_size(get_text_font_size());
71 set_font_style(conf->text_font_style);
112 unsigned comp_start_offset = 0;
113 unsigned comp_end_offset = 0;
115 if(edit_length == 0) {
117 }
else if(edit_length > 0) {
126 unsigned start_offset = 0;
127 unsigned end_offset = 0;
129 start_offset =
start;
130 end_offset = start_offset;
131 }
else if(length > 0) {
132 start_offset =
start;
133 end_offset =
start + length;
135 start_offset =
start + length;
143 unsigned byte_pos =
start + length;
156 tmp.set_variable(
"text_maximum_width",
wfl::variant(max_width));
157 tmp.set_variable(
"text_maximum_height",
wfl::variant(max_height));
159 tmp.set_variable(
"text_wrap_mode",
wfl::variant(PANGO_ELLIPSIZE_NONE));
163 tmp.set_variable(
"highlight_start",
wfl::variant(start_offset));
164 tmp.set_variable(
"highlight_end",
wfl::variant(end_offset));
166 tmp.set_variable(
"cursor_offset_x",
wfl::variant(cpos.x));
167 tmp.set_variable(
"cursor_offset_y",
wfl::variant(cpos.y));
169 tmp.set_variable(
"composition_offset",
wfl::variant(comp_start_offset));
170 tmp.set_variable(
"composition_width",
wfl::variant(comp_end_offset - comp_start_offset));
219 if(mouse < text_offset
240 return (
line->start_index +
line->length);
244 return get_line(line_no)->start_index;
249 const auto conf = cast_config_to<multiline_text_definition>();
306 if(modifier & KMOD_CTRL) {
307 if(!(modifier & KMOD_SHIFT)) {
320 if (
is_editable() && !(modifier & (KMOD_CTRL | KMOD_ALT | KMOD_GUI))) {
351 offset = std::min(offset - line_start + next_line_start, next_line_end) +
get_selection_length();
354 set_cursor(offset, (modifier & KMOD_SHIFT) != 0);
378 offset = std::min(offset - line_start + prev_line_start, prev_line_end) +
get_selection_length();
382 set_cursor(offset, (modifier & KMOD_SHIFT) != 0);
425 DBG_GUI_E <<
"Clicked Link:\"" << link <<
"\"";
472 load_resolutions<resolution>(cfg);
477 , text_x_offset(cfg[
"text_x_offset"])
478 , text_y_offset(cfg[
"text_y_offset"])
492 builder_multiline_text::builder_multiline_text(
const config& cfg)
494 , history(cfg[
"history"])
495 , max_input_length(cfg[
"max_input_length"].to_size_t())
496 , hint_text(cfg[
"hint_text"].t_str())
497 , hint_image(cfg[
"hint_image"])
498 , editable(cfg[
"editable"].to_bool(true))
499 , wrap(cfg[
"wrap"].to_bool(true))
500 , link_aware(cfg[
"link_aware"].to_bool(false))
506 auto widget = std::make_unique<multiline_text>(*
this);
516 DBG_GUI_G <<
"Window builder: placed text box '" <<
id
517 <<
"' with definition '" <<
definition <<
"'.";
A config object defines a single node in a WML file, with access to child nodes.
@ yes_no_buttons
Shows a yes and no button.
@ auto_close
Enables auto close.
void handle_key_down_arrow(SDL_Keymod, bool &handled) override
Inherited from text_box_base.
bool dragging_
Is the mouse in dragging mode, this affects selection in mouse move.
unsigned text_y_offset_
The y offset in the widget where the text starts.
unsigned text_x_offset_
The x offset in the widget where the text starts.
virtual void place(const point &origin, const point &size) override
See widget::place.
bool link_aware_
Whether the text area is link aware, rendering links with special formatting and handling click event...
void set_link_aware(bool l)
bool history_up()
Goes one item up in the history.
void delete_selection() override
Inherited from text_box_base.
unsigned text_height_
The height of the text itself.
void signal_handler_mouse_motion(const event::ui_event event, bool &handled, const point &coordinate)
void update_offsets()
Updates text_x_offset_ and text_y_offset_.
void handle_key_enter(SDL_Keymod modifier, bool &handled) override
Inherited from text_box_base.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
virtual bool get_link_aware() const override
See styled_widget::get_link_aware.
bool history_down()
Goes one item down in the history.
unsigned get_line_end_offset(unsigned line_no)
Utility function to calculate the offset of the end of the line.
void handle_mouse_selection(point mouse, const bool start_selection)
std::string hint_text_
Helper text to display (such as "Search") if the text box is empty.
void signal_handler_left_button_down(const event::ui_event event, bool &handled)
void delete_char(const bool before_cursor) override
Inherited from text_box_base.
virtual void update_canvas() override
See styled_widget::update_canvas.
std::string hint_image_
Image (such as a magnifying glass) that accompanies the help text.
void handle_key_tab(SDL_Keymod modifier, bool &handled) override
Inherited from text_box_base.
unsigned get_line_start_offset(unsigned line_no)
Utility function to calculate the offset of the end of the line.
void handle_key_clear_line(SDL_Keymod modifier, bool &handled) override
Inherited from text_box_base.
std::size_t max_input_length_
The maximum length of the text input.
void signal_handler_left_button_double_click(const event::ui_event event, bool &handled)
void update_layout()
Update layout.
void set_cursor(const std::size_t offset, const bool select) override
Inherited from text_box_base.
void handle_key_up_arrow(SDL_Keymod, bool &handled) override
Inherited from text_box_base.
void insert_char(const std::string &unicode) override
Inherited from text_box_base.
text_history history_
The history text for this widget.
void signal_handler_left_button_up(const event::ui_event event, bool &handled)
Abstract base class for text items.
std::size_t get_length() const
Wrapper function, returns length of the text in pango column offsets.
point get_column_line(const point &position) const
point get_cursor_pos_from_index(const unsigned offset) const
Wrapper function, return the cursor position given the byte index.
std::string get_value() const
std::size_t get_composition_start() const
size_t get_composition_length() const
Get length of composition text by IME.
point get_cursor_position(const unsigned column, const unsigned line=0) const
unsigned get_lines_count() const
Wrapper function, return number of lines.
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
std::size_t get_selection_length() const
PangoLayoutLine * get_line(int index)
Wrapper function, returns the line corresponding to index.
void set_maximum_height(const int height, const bool multiline)
font::family_class get_font_family()
void set_maximum_width(const int width)
bool is_editable() const
Check whether text can be edited or not.
std::size_t get_selection_start() const
void set_selection_length(const int selection_length)
void set_maximum_length(const std::size_t maximum_length)
int get_line_number(const unsigned offset)
Wrapper function, return the line number given the byte index.
void select_all()
Selects all text.
std::string down(const std::string &text="")
One step down in the history.
std::string up(const std::string &text="")
One step up in the history.
void keyboard_capture(widget *widget)
void mouse_capture(const bool capture=true)
static std::string _(const char *str)
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.
bool open_object([[maybe_unused]] const std::string &path_or_url)
constexpr bool open_object_is_supported()
Returns whether open_object() is supported/implemented for the current platform.
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
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.
int get_max_height(unsigned size, font::family_class fclass, pango_text::FONT_STYLE style)
Returns the maximum glyph height of a font, in pixels.
constexpr float get_line_spacing_factor()
ui_event
The event sent to the dispatcher.
point get_mouse_position()
Returns the current mouse position.
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
@ OK
Dialog was closed with the OK button.
Contains the implementation details for lexical_cast and shouldn't be used directly.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::string & erase(std::string &str, const std::size_t start, const std::size_t len)
Erases a portion of a UTF-8 string.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
Desktop environment interaction functions.
virtual std::unique_ptr< widget > build() const override
resolution(const config &cfg)
multiline_text_definition(const config &cfg)
std::vector< state_definition > state
std::string missing_mandatory_wml_tag(const std::string §ion, const std::string &tag)
Returns a standard message for a missing wml child (tag).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WML_CHILD(cfg, key, message)