The Battle for Wesnoth  1.19.13+dev
text_box_base.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2025
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
20 #include "cursor.hpp"
21 #include "desktop/clipboard.hpp"
22 #include "font/attributes.hpp"
24 #include "gui/core/log.hpp"
25 #include "gui/core/timer.hpp"
26 #include "gui/widgets/window.hpp"
28 
29 #ifdef __ANDROID__
30 #include <SDL2/SDL_keyboard.h>
31 #endif
32 
33 #include <functional>
34 #include <limits>
35 
36 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
37 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
38 
39 using namespace std::chrono_literals;
40 
41 namespace gui2
42 {
43 
44 text_box_base::text_box_base(const implementation::builder_styled_widget& builder, const std::string& control_type)
45  : styled_widget(builder, control_type)
46  , state_(ENABLED)
47  , text_()
48  , selection_start_(0)
49  , selection_length_(0)
50  , editable_(true)
51  , ime_composing_(false)
52  , ime_start_point_(0)
53  , cursor_timer_(0)
54  , cursor_alpha_(0)
55  , cursor_blink_rate_(750ms)
56 {
57  set_font_family(get_config()->text_font_family);
58 
59 #ifdef __unix__
60  // pastes on UNIX systems.
61  connect_signal<event::MIDDLE_BUTTON_CLICK>(std::bind(
62  &text_box_base::signal_handler_middle_button_click, this, std::placeholders::_2, std::placeholders::_3));
63 
64 #endif
65 
66  connect_signal<event::SDL_KEY_DOWN>(std::bind(
67  &text_box_base::signal_handler_sdl_key_down, this, std::placeholders::_2, std::placeholders::_3, std::placeholders::_5, std::placeholders::_6));
68  connect_signal<event::SDL_TEXT_INPUT>(std::bind(&text_box_base::handle_commit, this, std::placeholders::_3, std::placeholders::_5));
69  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));
70 
71  connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(std::bind(
72  &text_box_base::signal_handler_receive_keyboard_focus, this, std::placeholders::_2));
73  connect_signal<event::LOSE_KEYBOARD_FOCUS>(
74  std::bind(&text_box_base::signal_handler_lose_keyboard_focus, this, std::placeholders::_2));
75 
76  connect_signal<event::MOUSE_ENTER>(
77  std::bind(&text_box_base::signal_handler_mouse_enter, this, std::placeholders::_2, std::placeholders::_3));
78  connect_signal<event::MOUSE_LEAVE>(
79  std::bind(&text_box_base::signal_handler_mouse_leave, this, std::placeholders::_2, std::placeholders::_3));
80 
81  toggle_cursor_timer(true);
82 }
83 
85 {
86  toggle_cursor_timer(false);
87  update_mouse_cursor(false);
88 }
89 
90 void text_box_base::set_active(const bool active)
91 {
92  if(get_active() != active) {
93  set_state(active ? ENABLED : DISABLED);
94  }
95 }
96 
98 {
99  return state_ != DISABLED;
100 }
101 
102 unsigned text_box_base::get_state() const
103 {
104  return state_;
105 }
106 
107 void text_box_base::set_maximum_length(const std::size_t maximum_length)
108 {
109  if(maximum_length == 0) {
110  return;
111  }
112 
113  const bool need_update = text_.get_length() > maximum_length;
114 
115  text_.set_maximum_length(maximum_length);
116 
117  if(need_update) {
118  if(selection_start_ > maximum_length) {
119  selection_start_ = maximum_length;
120  selection_length_ = 0;
121  } else if(selection_start_ + selection_length_ > maximum_length) {
122  selection_length_ = maximum_length - selection_start_;
123  }
124  update_canvas();
125  queue_redraw();
126  }
127 }
128 
129 void text_box_base::set_highlight_area(const unsigned start_offset, const unsigned end_offset, const color_t& color)
130 {
131  font::attribute_list attrs;
132  add_attribute_bg_color(attrs, start_offset, end_offset, color);
133  text_.apply_attributes(attrs);
134 }
135 
136 void text_box_base::set_value(const std::string& text)
137 {
138  if(text != text_.text()) {
140 
141  // default to put the cursor at the end of the buffer.
143  selection_length_ = 0;
144  update_canvas();
145  queue_redraw();
146  }
147 }
148 
149 void text_box_base::set_cursor(const std::size_t offset, const bool select)
150 {
152 
153  if(select) {
154  selection_length_ = (selection_start_ == offset) ? 0 : -static_cast<int>(selection_start_ - offset);
155  } else {
156  selection_start_ = (offset <= text_.get_length()) ? offset : 0;
157  selection_length_ = 0;
158  }
159 
160  update_canvas();
161  queue_redraw();
162 }
163 
164 void text_box_base::insert_char(const std::string& unicode)
165 {
166  if(!editable_)
167  {
168  return;
169  }
170 
172 
174  // Update status
175  std::size_t plain_text_len = utf8::size(plain_text());
176  std::size_t cursor_pos = selection_start_ + utf8::size(unicode);
177  if (get_use_markup() && (selection_start_ + utf8::size(unicode) > plain_text_len + 1)) {
178  cursor_pos = plain_text_len;
179  }
180  set_cursor(cursor_pos, false);
181  update_canvas();
182  queue_redraw();
183  }
184 }
185 
187 {
188  if(!is_composing()) {
189  return 0;
190  }
191 
192  std::size_t text_length = utf8::size(text_.text());
193  std::size_t text_cached_length = utf8::size(text_cached_);
194  if(text_length < text_cached_length) {
195  return 0;
196  }
197 
199 }
200 
202 {
203  ime_composing_ = false;
204 #ifndef __ANDROID__
205  // We need to inform the IME that text input is no longer in progress.
206  SDL_StopTextInput();
207  SDL_StartTextInput();
208 #endif
209 }
210 
212 {
213  if(selection_length_ == 0) {
214  return;
215  }
216 
217  unsigned end, start = selection_start_;
218  const std::string txt = get_use_markup() ? plain_text() : text_.text();
219 
220  if(selection_length_ > 0) {
221  end = utf8::index(txt, start + selection_length_);
222  start = utf8::index(txt, start);
223  } else {
224  // inverse selection: selection_start_ is in fact the end
225  end = utf8::index(txt, start);
227  }
229 }
230 
232 {
233  if(!editable_)
234  {
235  return;
236  }
237 
238  const std::string& text = desktop::clipboard::copy_from_clipboard();
239  if(text.empty()) {
240  return;
241  }
242 
244 
246 
247  update_canvas();
248  queue_redraw();
249  fire(event::NOTIFY_MODIFIED, *this, nullptr);
250 }
251 
252 void text_box_base::set_selection_start(const std::size_t selection_start)
253 {
254  if(selection_start != selection_start_) {
255  selection_start_ = selection_start;
256  queue_redraw();
257  }
258 }
259 
260 void text_box_base::set_selection_length(const int selection_length)
261 {
262  if(selection_length != selection_length_) {
263  selection_length_ = selection_length;
264  queue_redraw();
265  }
266 }
267 
268 void text_box_base::set_selection(std::size_t start, int length)
269 {
270  const std::size_t text_size = text_.get_length();
271 
272  if(start >= text_size) {
273  start = text_size;
274  }
275 
276  if(length == 0) {
277  set_cursor(start, false);
278  return;
279  }
280 
281  // The text pos/size type differs in both signedness and size with the
282  // selection length. Such is life.
283  const int sel_start = std::min<std::size_t>(start, std::numeric_limits<int>::max());
284  const int sel_max_length = std::min<std::size_t>(text_size - start, std::numeric_limits<int>::max());
285 
286  const bool backwards = length < 0;
287 
288  if(backwards && -length > sel_start) {
289  length = -sel_start;
290  } else if(!backwards && length > sel_max_length) {
291  length = sel_max_length;
292  }
293 
295  set_selection_length(length);
296 
297  update_canvas();
298 }
299 
301 {
302  if(state != state_) {
303  state_ = state;
304  queue_redraw();
305  }
306 }
307 
309 {
310  if(cursor_blink_rate_ == 0ms) {
311  return;
312  }
313 
314  if(cursor_timer_) {
316  }
317 
318  cursor_timer_ = enable
320  : 0;
321 }
322 
324 {
325  unsigned was_alpha = cursor_alpha_;
326  switch(state_) {
327  case DISABLED:
328  cursor_alpha_ = 0;
329  return;
330  case ENABLED:
331  cursor_alpha_ = 255;
332  return;
333  default:
334  // FIXME: very hacky way to check if the widget's owner is the top window
335  // back() on an empty vector is UB and was causing a crash when run on Wayland (see #7104 on github)
336  const auto& dispatchers = event::get_all_dispatchers();
337  if(!dispatchers.empty() && static_cast<event::dispatcher*>(get_window()) != dispatchers.back()) {
338  cursor_alpha_ = 0;
339  } else {
340  cursor_alpha_ = (~cursor_alpha_) & 0xFF;
341  }
342  }
343 
344  if(was_alpha == cursor_alpha_) {
345  return;
346  }
347 
348  for(auto& tmp : get_canvases()) {
349  tmp.set_variable("cursor_alpha", wfl::variant(cursor_alpha_));
350  }
351 
352  queue_redraw();
353 }
354 
356 {
357  if(cursor_blink_rate_ == 0ms) {
358  return;
359  }
360 
361  cursor_alpha_ = 255;
362 
363  for(auto& tmp : get_canvases()) {
364  tmp.set_variable("cursor_alpha", wfl::variant(cursor_alpha_));
365  }
366 
367  // Restart the blink timer.
368  toggle_cursor_timer(true);
369 }
370 
371 void text_box_base::handle_key_left_arrow(SDL_Keymod modifier, bool& handled)
372 {
373  /** @todo implement the ctrl key. */
375 
376  handled = true;
377  const int offset = selection_start_ - 1 + selection_length_;
378  if(offset >= 0) {
379  set_cursor(offset, (modifier & KMOD_SHIFT) != 0);
380  }
381 }
382 
383 void text_box_base::handle_key_right_arrow(SDL_Keymod modifier, bool& handled)
384 {
385  /** @todo implement the ctrl key. */
387 
388  handled = true;
389  const std::size_t offset = selection_start_ + 1 + selection_length_;
390  if(offset <= (get_use_markup() ? utf8::size(plain_text()) : text_.get_length())) {
391  set_cursor(offset, (modifier & KMOD_SHIFT) != 0);
392  }
393 }
394 
395 void text_box_base::handle_key_home(SDL_Keymod modifier, bool& handled)
396 {
398 
399  handled = true;
400  if(modifier & KMOD_CTRL) {
401  goto_start_of_data((modifier & KMOD_SHIFT) != 0);
402  } else {
403  goto_start_of_line((modifier & KMOD_SHIFT) != 0);
404  }
405 }
406 
407 void text_box_base::handle_key_end(SDL_Keymod modifier, bool& handled)
408 {
410 
411  handled = true;
412  if(modifier & KMOD_CTRL) {
413  goto_end_of_data((modifier & KMOD_SHIFT) != 0);
414  } else {
415  goto_end_of_line((modifier & KMOD_SHIFT) != 0);
416  }
417 }
418 
419 void text_box_base::handle_key_backspace(SDL_Keymod /*modifier*/, bool& handled)
420 {
422 
423  handled = true;
424  if(selection_length_ != 0) {
426  } else if(selection_start_) {
427  delete_char(true);
428  if(is_composing()) {
429  if(get_composition_length() == 0) {
430  ime_composing_ = false;
431  }
432  }
433  }
434  fire(event::NOTIFY_MODIFIED, *this, nullptr);
435 }
436 
437 void text_box_base::handle_key_delete(SDL_Keymod /*modifier*/, bool& handled)
438 {
440 
441  handled = true;
442  if(selection_length_ != 0) {
444  } else if(selection_start_ < text_.get_length()) {
445  delete_char(false);
446  if(is_composing()) {
447  if(get_composition_length() == 0) {
448  ime_composing_ = false;
449  }
450  }
451  }
452  fire(event::NOTIFY_MODIFIED, *this, nullptr);
453 }
454 
455 void text_box_base::handle_commit(bool& handled, const std::string& unicode)
456 {
458 
459  if(unicode.size() > 1 || unicode[0] != 0) {
460  handled = true;
461  if(is_composing()) {
463  ime_composing_ = false;
464  }
465  insert_char(unicode);
466  fire(event::NOTIFY_MODIFIED, *this, nullptr);
467  }
468 }
469 
470 /**
471  * SDL_TEXTEDITING handler. See example at https://wiki.libsdl.org/Tutorials/TextInput
472  */
473 void text_box_base::handle_editing(bool& handled, const std::string& unicode, int32_t start, int32_t len)
474 {
475  if(unicode.size() > 1 || unicode[0] != 0) {
476  handled = true;
477  std::size_t new_len = utf8::size(unicode);
478  if(!is_composing()) {
479  ime_composing_ = true;
482  text_cached_ = text_.text();
483  rect rect = get_rectangle();
484  if(new_len > 0) {
486  rect.w = get_cursor_position(ime_start_point_ + new_len).x - rect.x;
487  } else {
488  rect.x += get_cursor_position(ime_start_point_ + new_len).x;
490  }
491  SDL_SetTextInputRect(&rect);
492  }
493 
494 #ifdef __unix__
495  // In SDL_TextEditingEvent, size of editing_text is limited
496  // If length of composition text is more than the limit,
497  // Linux (ibus) implementation of SDL separates it into multiple
498  // SDL_TextEditingEvent.
499  // start is start position of the separated event in entire composition text
500  if(start == 0) {
502  }
504 #else
505  std::string new_text(text_cached_);
506  utf8::insert(new_text, ime_start_point_, unicode);
507  text_.set_text(new_text, get_use_markup());
508 
509 #endif
510  int maximum_length = text_.get_length();
511 
512  // Update status
513  set_cursor(std::min(maximum_length, ime_start_point_ + start), false);
514  if(len > 0) {
515  set_cursor(std::min(maximum_length, ime_start_point_ + start + len), true);
516  }
517  update_canvas();
518  queue_redraw();
519  }
520 }
521 
523  bool& handled)
524 {
525  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
526 
527  paste_selection();
528 
529  handled = true;
530 }
531 
533  bool& handled,
534  const SDL_Keycode key,
535  SDL_Keymod modifier)
536 {
537 
538  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
539 
540 /*
541  * For copy, cut and paste we use a different key on the MAC. Even for 'select
542  * all', contradicting the comment in widgets/textbox.cpp:495.
543  *
544  * The reason for that is, by coupling 'select all' to the behavior for copy,
545  * cut and paste, the text box behavior as a whole gets consistent with default
546  * macOS hotkey idioms.
547  */
548 #ifdef __APPLE__
549  // Idiomatic modifier key in macOS computers.
550  const SDL_Keycode modifier_key = KMOD_GUI;
551 #else
552  // Idiomatic modifier key in Microsoft desktop environments. Common in
553  // GNU/Linux as well, to some extent.
554  const SDL_Keycode modifier_key = KMOD_CTRL;
555 #endif
556 
557  switch(key) {
558 
559  case SDLK_LEFT:
560  handle_key_left_arrow(modifier, handled);
561  break;
562 
563  case SDLK_RIGHT:
564  handle_key_right_arrow(modifier, handled);
565  break;
566 
567  case SDLK_UP:
568  handle_key_up_arrow(modifier, handled);
569  break;
570 
571  case SDLK_DOWN:
572  handle_key_down_arrow(modifier, handled);
573  break;
574 
575  case SDLK_PAGEUP:
576  handle_key_page_up(modifier, handled);
577  break;
578 
579  case SDLK_PAGEDOWN:
580  handle_key_page_down(modifier, handled);
581  break;
582 
583  case SDLK_a:
584  if(!(modifier & modifier_key)) {
585  return;
586  }
587 
588  select_all();
589  break;
590 
591  case SDLK_HOME:
592  handle_key_home(modifier, handled);
593  break;
594 
595  case SDLK_END:
596  handle_key_end(modifier, handled);
597  break;
598 
599  case SDLK_BACKSPACE:
600  if (!is_editable())
601  {
602  return;
603  }
604 
605  handle_key_backspace(modifier, handled);
606  break;
607 
608  case SDLK_u:
609  if( !(modifier & KMOD_CTRL) || !is_editable() ) {
610  return;
611  }
612 
613  handle_key_clear_line(modifier, handled);
614  break;
615 
616  case SDLK_DELETE:
617  if (!is_editable())
618  {
619  return;
620  }
621 
622  handle_key_delete(modifier, handled);
623  break;
624 
625  case SDLK_c:
626  if(!(modifier & modifier_key)) {
627  return;
628  }
629 
630  // atm we don't care whether there is something to copy or paste
631  // if nothing is there we still don't want to be chained.
632  copy_selection();
633  handled = true;
634  break;
635 
636  case SDLK_x:
637  if( !(modifier & modifier_key) ) {
638  return;
639  }
640 
641  copy_selection();
642 
643  if ( is_editable() ) {
645  }
646  handled = true;
647  break;
648 
649  case SDLK_v:
650  if( !(modifier & modifier_key) || !is_editable() ) {
651  return;
652  }
653 
654  paste_selection();
655  handled = true;
656  break;
657 
658  case SDLK_RETURN:
659  case SDLK_KP_ENTER:
660 
661 // TODO: check if removing the following check causes any side effects
662 // To be removed if there aren't any text rendering problems.
663 // if(!is_composing()) {
664 // return;
665 // }
666 
667  handle_key_enter(modifier, handled);
668  break;
669 
670  case SDLK_ESCAPE:
671  if(!is_composing() || (modifier & (KMOD_CTRL | KMOD_ALT | KMOD_GUI | KMOD_SHIFT))) {
672  return;
673  }
675  handled = true;
676  break;
677 
678  case SDLK_TAB:
679  handle_key_tab(modifier, handled);
680  break;
681 
682  default:
683  return;
684  }
685 }
686 
688 {
689  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
690  SDL_StartTextInput();
692 }
693 
695 {
696  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
697  SDL_StopTextInput();
699 }
700 
702  bool& handled)
703 {
704  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
705  if(state_ != FOCUSED) {
707  }
708 
709  update_mouse_cursor(true);
710 
711  handled = true;
712 }
713 
715  bool& handled)
716 {
717  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
718 
719  if(state_ != FOCUSED) {
721  }
722 
723  update_mouse_cursor(false);
724 
725  handled = true;
726 }
727 
729 {
730  // Someone else may set the mouse cursor for us to something unusual (e.g.
731  // the WAIT cursor) so we ought to mess with that only if it's set to
732  // NORMAL or IBEAM.
733 
734  if(enable && cursor::get() == cursor::NORMAL) {
736  } else if(!enable && cursor::get() == cursor::IBEAM) {
738  }
739 }
740 
741 
742 } // namespace gui2
Helper class to encapsulate the management of a PangoAttrList.
Definition: attributes.hpp:28
std::size_t get_length() const
Gets the length of the text in bytes.
Definition: text.hpp:304
pango_text & set_maximum_length(const std::size_t maximum_length)
Definition: text.cpp:482
unsigned insert_text(const unsigned offset, const std::string &text, const bool use_markup=false)
Inserts UTF-8 text.
Definition: text.cpp:169
void apply_attributes(const font::attribute_list &attrs)
Definition: text.cpp:324
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
Definition: text.cpp:333
const std::string & text() const
Definition: text.hpp:322
Base class for event handling.
Definition: dispatcher.hpp:150
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:74
std::vector< canvas > & get_canvases()
virtual void update_canvas()
Updates the canvas(ses).
resolution_definition_ptr get_config()
bool get_use_markup() const
std::size_t get_composition_length() const
Get length of composition text by IME.
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.
std::string plain_text()
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.
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.
void queue_redraw()
Indicates that this widget should be redrawn.
Definition: widget.cpp:464
window * get_window()
Get the parent window.
Definition: widget.cpp:117
rect get_rectangle() const
Gets the bounding rectangle of the widget on the screen.
Definition: widget.cpp:321
Define the common log macros for the gui toolkit.
#define DBG_GUI_E
Definition: log.hpp:35
This file contains the window object, this object is a top level container which has the event manage...
CURSOR_TYPE get()
Definition: cursor.cpp:218
@ NORMAL
Definition: cursor.hpp:28
@ IBEAM
Definition: cursor.hpp:28
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:178
void copy_to_clipboard(const std::string &text)
Copies text to the clipboard.
Definition: clipboard.cpp:27
std::string copy_from_clipboard()
Copies text from the clipboard.
Definition: clipboard.cpp:32
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.
Definition: attributes.cpp:135
ui_event
The event sent to the dispatcher.
Definition: handler.hpp:115
@ NOTIFY_MODIFIED
Definition: handler.hpp:175
std::vector< dispatcher * > & get_all_dispatchers()
Gets all event dispatchers in the Z order.
Definition: handler.cpp:886
Generic file dialog.
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.
Definition: timer.cpp:123
bool remove_timer(const std::size_t id)
Removes a timer.
Definition: timer.cpp:164
std::string & insert(std::string &str, const std::size_t pos, const std::string &insert)
Insert a UTF-8 string at the specified position.
Definition: unicode.cpp:98
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
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.
Definition: unicode.cpp:70
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:61
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:49
#define LOG_HEADER
#define LOG_SCOPE_HEADER
Contains the gui2 timer routines.