]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/entry.cpp
Use the public functions also in internal edit operations of Entry
[libs/gltk.git] / source / entry.cpp
index 70321dc5a68cf029128f07c52e9b06f44ea38f91..21064f728d151bbdd709ef8ab3869b85353c1e37 100644 (file)
@@ -252,25 +252,17 @@ bool Entry::key_press(unsigned key, unsigned mod)
                if(selection_active)
                        erase_selection();
                else if(edit_pos>0)
-               {
-                       text.erase(--edit_pos, 1);
-                       check_view_range();
-                       rebuild();
-               }
+                       erase(edit_pos-1, 1);
        }
        else if(key==Input::KEY_DELETE)
        {
                if(selection_active)
                        erase_selection();
                else
-                       text.erase(edit_pos, 1);
+                       erase(edit_pos, 1);
        }
        else if(key==Input::KEY_ENTER && multiline)
-       {
-               text.insert(edit_pos++, "\n");
-               check_view_range();
-               rebuild();
-       }
+               insert(edit_pos, "\n");
        else if(key==Input::KEY_END)
        {
                unsigned row, col;
@@ -303,9 +295,7 @@ bool Entry::character(wchar_t ch)
        {
                if(selection_active)
                        erase_selection();
-               text.insert(edit_pos, StringCodec::encode<StringCodec::Utf8>(StringCodec::ustring(1, ch)));
-               ++edit_pos;
-               rebuild();
+               insert(edit_pos, StringCodec::encode<StringCodec::Utf8>(StringCodec::ustring(1, ch)));
                return true;
        }
 
@@ -440,11 +430,7 @@ void Entry::check_view_range()
        if(!multiline || !text_part)
                return;
 
-       float font_size = style->get_font_size();
-       unsigned line_spacing = static_cast<unsigned>(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);