X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fentry.cpp;h=6d13ccdd0377eaaff11b29db0c27981d5b9cacc0;hb=7c1b1b44dc3726d6cdb4681f9d44189eb4102a5a;hp=af6fcc6d0fd31ed5cfdbdc03f4fda57e9db6c55c;hpb=608412d18b9c42871277911c11ae885a53d83990;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index af6fcc6..6d13ccd 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -57,7 +57,50 @@ void Entry::autosize_special(const Part &part, Geometry &ageom) const void Entry::set_text(const string &t) { text = t; - edit_pos = text.size(); + set_edit_position(text.size()); +} + +void Entry::insert(unsigned pos, const string &t) +{ + text.insert(pos, t); + + if(edit_pos>=pos) + edit_pos += t.size(); + if(selection_active && selection_pos>=pos) + selection_pos += t.size(); + + if(multiline) + check_view_range(); + + rebuild(); +} + +void Entry::erase(unsigned pos, unsigned len) +{ + text.erase(pos, len); + + if(edit_pos>=pos+len) + edit_pos -= len; + else if(edit_pos>=pos) + edit_pos = pos; + if(selection_active) + { + if(selection_pos>=pos+len) + selection_pos -= len; + else if(selection_pos>=pos) + selection_pos = pos; + } + + if(multiline) + check_view_range(); + + rebuild(); +} + +void Entry::set_edit_position(unsigned pos) +{ + edit_pos = min(pos, text.size()); + selection_active = false; if(multiline) check_view_range(); @@ -65,6 +108,19 @@ void Entry::set_text(const string &t) rebuild(); } +bool Entry::get_selection(unsigned &start, unsigned &end) const +{ + if(!selection_active) + return false; + + start = selection_pos; + end = edit_pos; + if(start>end) + swap(start, end); + + return true; +} + void Entry::set_edit_size(unsigned w, unsigned h) { edit_width = w; @@ -384,11 +440,7 @@ void Entry::check_view_range() if(!multiline || !text_part) return; - float font_size = style->get_font_size(); - unsigned line_spacing = static_cast(font_size*6/5); - - const Sides &margin = text_part->get_margin(); - visible_rows = max((geom.h-margin.top-margin.bottom)/line_spacing, 1U); + visible_rows = text.get_visible_lines(*text_part, geom, 0); unsigned row, col; text.offset_to_coords(edit_pos, row, col);