void ttext_box::delete_char(const bool before_cursor) { if(before_cursor) { set_cursor(get_selection_start() - 1, false); } set_selection_length(1); delete_selection(); }
void ttext_box::update_canvas() { /***** Gather the info *****/ // Set the cursor info. const unsigned start = get_selection_start(); const int length = get_selection_length(); set_maximum_length(max_input_length_); PangoEllipsizeMode ellipse_mode = PANGO_ELLIPSIZE_NONE; if(!can_wrap()) { if((start + length) > (get_length() / 2)) { ellipse_mode = PANGO_ELLIPSIZE_START; } else { ellipse_mode = PANGO_ELLIPSIZE_END; } } set_ellipse_mode(ellipse_mode); // Set the selection info unsigned start_offset = 0; unsigned end_offset = 0; if(length == 0) { // No nothing. } else if(length > 0) { start_offset = get_cursor_position(start).x; end_offset = get_cursor_position(start + length).x; } else { start_offset = get_cursor_position(start + length).x; end_offset = get_cursor_position(start).x; } /***** Set in all canvases *****/ const int max_width = get_text_maximum_width(); const int max_height = get_text_maximum_height(); for(auto & tmp : canvas()) { tmp.set_variable("text", variant(get_value())); tmp.set_variable("text_x_offset", variant(text_x_offset_)); tmp.set_variable("text_y_offset", variant(text_y_offset_)); tmp.set_variable("text_maximum_width", variant(max_width)); tmp.set_variable("text_maximum_height", variant(max_height)); tmp.set_variable("cursor_offset", variant(get_cursor_position(start + length).x)); tmp.set_variable("selection_offset", variant(start_offset)); tmp.set_variable("selection_width", variant(end_offset - start_offset)); tmp.set_variable("text_wrap_mode", variant(ellipse_mode)); } }
void tpassword_box::pre_function() { // ttext_box::set_value() will reset the selection, // we therefore have to remember it size_t selection_start = get_selection_start(); size_t selection_length = get_selection_length(); // Tell ttext_box the actual input of this box ttext_box::set_value(real_value_); // Restore the selection set_selection_start(selection_start); set_selection_length(selection_length); }
void tpassword_box::handle_key_delete(SDLMod /*modifier*/, bool& handled) { pre_function(); // Copy & paste from ttext_::handle_key_delete() DBG_GUI_E << LOG_SCOPE_HEADER << '\n'; handled = true; if(get_selection_length() != 0) { delete_selection(); } else if (get_selection_start() < get_text_length(text())) { delete_char(false); } post_function(); }
void tpassword_box::post_function() { // See above size_t selection_start = get_selection_start(); size_t selection_length = get_selection_length(); // Get the input back and make ttext_box forget it real_value_ = get_value(); ttext_box::set_value(std::string(get_text_length(real_value_), '*')); // See above set_selection_start(selection_start); set_selection_length(selection_length); // Why do the selection functions not update // the canvas? update_canvas(); set_dirty(true); }
void ttext_box::delete_selection() { if(get_selection_length() == 0) { return; } // If we have a negative range change it to a positive range. // This makes the rest of the algoritms easier. int len = get_selection_length(); unsigned start = get_selection_start(); if(len < 0) { len = -len; start -= len; } utf8::string tmp = get_value(); set_value(utf8::erase(tmp, start, len)); set_cursor(start, false); }