]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/entry.cpp
Use nullptr instead of 0 for pointers
[libs/gltk.git] / source / entry.cpp
index 1c66f9885fe8e5058a0ef0ae20e40ec3d83e1013..5aadbc262d355805e3b4fe338714a2a0bb8d4311 100644 (file)
@@ -13,20 +13,7 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Entry::Entry(const string &t):
-       text(),
-       multiline(false),
-       edit_width(10),
-       edit_height(1),
-       edit_pos(0),
-       first_row(0),
-       visible_rows(1),
-       text_part(0),
-       slider(0),
-       got_key_press(false),
-       cursor_blink(true),
-       selection_active(false),
-       selection_pos(0)
+Entry::Entry(const string &t)
 {
        input_type = INPUT_TEXT;
        set_text(t);
@@ -161,7 +148,7 @@ void Entry::rebuild_special(const Part &part)
                Geometry rgeom = text.coords_to_geometry(*text_part, geom, first_row, row, col);
 
                GL::MeshBuilder bld(part_cache.create_mesh(part, *graphic->get_texture()));
-               bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
+               bld.transform(GL::Matrix::translation(rgeom.x, rgeom.y, 0));
                graphic->build(part.get_geometry().w, part.get_geometry().h, bld);
        }
        else if(part.get_name()=="selection")
@@ -205,7 +192,7 @@ void Entry::rebuild_special(const Part &part)
                                Geometry egeom = text.coords_to_geometry(*text_part, geom, first_row, row, ec);
 
                                GL::MeshBuilder bld(part_cache.create_mesh(part, *graphic->get_texture()));
-                               bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
+                               bld.transform(GL::Matrix::translation(rgeom.x, rgeom.y, 0));
                                graphic->build(egeom.x-rgeom.x, part.get_geometry().h, bld);
                        }
 
@@ -332,8 +319,6 @@ bool Entry::navigate(Navigation nav)
 {
        if(nav==NAV_LEFT || nav==NAV_RIGHT || ((nav==NAV_DOWN || nav==NAV_UP) && multiline))
                move_edit_position(nav, false);
-       else if(nav==NAV_ACCEPT && !signal_enter.empty())
-               signal_enter.emit();
        else
                return false;
 
@@ -358,7 +343,7 @@ void Entry::on_style_change()
 
        if(!style)
        {
-               text_part = 0;
+               text_part = nullptr;
                return;
        }
 
@@ -395,6 +380,7 @@ void Entry::move_edit_position(Navigation nav, bool select)
 void Entry::adjust_edit_position_for_change(unsigned pos, int change)
 {
        unsigned old_edit_pos = edit_pos;
+       unsigned old_select_pos = selection_pos;
 
        if(change>0)
        {
@@ -413,10 +399,17 @@ void Entry::adjust_edit_position_for_change(unsigned pos, int change)
 
        if(edit_pos!=old_edit_pos)
                signal_edit_position_changed.emit(edit_pos);
+       if(selection_active && (edit_pos!=old_edit_pos || selection_pos!=old_select_pos))
+       {
+               unsigned start, end;
+               if(get_selection(start, end))
+                       signal_selection_changed.emit(start, end);
+       }
 }
 
 void Entry::set_edit_position(unsigned ep, bool select)
 {
+       bool selection_was_active = selection_active;
        if(select && !selection_active)
                selection_pos = edit_pos;
        selection_active = select;
@@ -425,7 +418,14 @@ void Entry::set_edit_position(unsigned ep, bool select)
        edit_pos = min(ep, text.size());
 
        if(edit_pos!=old_edit_pos)
+       {
                signal_edit_position_changed.emit(edit_pos);
+               unsigned start, end;
+               if(get_selection(start, end))
+                       signal_selection_changed.emit(start, end);
+               else if(selection_was_active)
+                       signal_selection_changed.emit(edit_pos, edit_pos);
+       }
 
        if(multiline)
                check_view_range();
@@ -468,7 +468,7 @@ void Entry::check_view_range()
        if(!multiline || !text_part)
                return;
 
-       visible_rows = text.get_visible_lines(*text_part, geom, 0);
+       visible_rows = text.get_visible_lines(*text_part, geom, nullptr);
 
        unsigned row, col;
        text.offset_to_coords(edit_pos, row, col);