X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=b2c78004b233b6ad9243e781639a6756a417387e;hb=HEAD;hp=f75f2005bc2cdd880d4960cf26b6f1db2cde6cf1;hpb=b391f4b774d17c53dfd9062fc7c7a6b14f72f926;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index f75f200..b2c7800 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -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); @@ -64,7 +51,7 @@ void Entry::set_text(const string &t) set_edit_position(text.size()); } -void Entry::insert(unsigned pos, const string &t) +void Entry::insert(size_t pos, const string &t) { if(t.empty()) return; @@ -79,7 +66,7 @@ void Entry::insert(unsigned pos, const string &t) mark_rebuild(); } -void Entry::erase(unsigned pos, unsigned len) +void Entry::erase(size_t pos, size_t len) { if(!len) return; @@ -94,7 +81,7 @@ void Entry::erase(unsigned pos, unsigned len) mark_rebuild(); } -bool Entry::get_selection(unsigned &start, unsigned &end) const +bool Entry::get_selection(size_t &start, size_t &end) const { if(!selection_active) return false; @@ -107,12 +94,12 @@ bool Entry::get_selection(unsigned &start, unsigned &end) const return true; } -void Entry::translate_position(unsigned pos, unsigned &row, unsigned &col) const +void Entry::translate_position(size_t pos, size_t &row, size_t &col) const { text.offset_to_coords(pos, row, col); } -unsigned Entry::translate_position(unsigned row, unsigned col) const +size_t Entry::translate_position(size_t row, size_t col) const { return text.coords_to_offset(row, col); } @@ -131,8 +118,9 @@ void Entry::set_multiline(bool m) { if(!slider) { - slider = new VSlider; - add(*slider); + unique_ptr s = make_unique(); + slider = s.get(); + add(move(s)); slider->set_step(1); slider->signal_value_changed.connect(sigc::mem_fun(this, &Entry::slider_value_changed)); mark_rebuild(); @@ -152,7 +140,7 @@ void Entry::rebuild_special(const Part &part) if(!text_part || !graphic || !graphic->get_texture()) return; - unsigned row, col; + size_t row, col; text.offset_to_coords(edit_pos, row, col); if(row=first_row+visible_rows) @@ -161,7 +149,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") @@ -173,12 +161,12 @@ void Entry::rebuild_special(const Part &part) if(!text_part || !graphic || !graphic->get_texture()) return; - unsigned start, end; + size_t start, end; get_selection(start, end); - unsigned row, col; + size_t row, col; text.offset_to_coords(start, row, col); - unsigned end_row, end_col; + size_t end_row, end_col; text.offset_to_coords(end, end_row, end_col); if(end_row=first_row+visible_rows) @@ -198,14 +186,14 @@ void Entry::rebuild_special(const Part &part) while(row<=end_row) { - unsigned ec = (row==end_row ? end_col : text.get_line_length(row)); + size_t ec = (row==end_row ? end_col : text.get_line_length(row)); if(ec>col) { Geometry rgeom = text.coords_to_geometry(*text_part, geom, first_row, row, col); 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); } @@ -247,7 +235,7 @@ bool Entry::key_press(unsigned key, unsigned mod) erase_selection(true); else if(edit_pos>0) { - unsigned start_pos = text.move_offset(edit_pos, -1); + size_t start_pos = text.move_offset(edit_pos, -1); erase(start_pos, edit_pos-start_pos); } } @@ -257,7 +245,7 @@ bool Entry::key_press(unsigned key, unsigned mod) erase_selection(true); else { - unsigned end_pos = text.move_offset(edit_pos, 1); + size_t end_pos = text.move_offset(edit_pos, 1); erase(edit_pos, end_pos-edit_pos); } } @@ -265,25 +253,25 @@ bool Entry::key_press(unsigned key, unsigned mod) insert(edit_pos, "\n"); else if(key==Input::KEY_END) { - unsigned row, col; + size_t row, col; text.offset_to_coords(edit_pos, row, col); set_edit_position(text.coords_to_offset(row, text.get_line_length(row)), mod==MOD_SHIFT); } else if(key==Input::KEY_HOME) { - unsigned row, col; + size_t row, col; text.offset_to_coords(edit_pos, row, col); set_edit_position(text.coords_to_offset(row, 0), mod==MOD_SHIFT); } else if(key==Input::KEY_PGUP) { - unsigned row, col; + size_t row, col; text.offset_to_coords(edit_pos, row, col); set_edit_position(text.coords_to_offset((rowget_part("text"); + text_part = style->find_part("text"); if(multiline) check_view_range(); @@ -378,13 +364,13 @@ void Entry::move_edit_position(Navigation nav, bool select) set_edit_position(text.move_offset(edit_pos, 1), select); else if(nav==NAV_DOWN) { - unsigned row, col; + size_t row, col; text.offset_to_coords(edit_pos, row, col); set_edit_position(text.coords_to_offset(row+1, col), select); } else if(nav==NAV_UP) { - unsigned row, col; + size_t row, col; text.offset_to_coords(edit_pos, row, col); set_edit_position((row>0 ? text.coords_to_offset(row-1, col) : 0), select); } @@ -392,10 +378,10 @@ void Entry::move_edit_position(Navigation nav, bool select) throw invalid_argument("Entry::move_edit_position"); } -void Entry::adjust_edit_position_for_change(unsigned pos, int change) +void Entry::adjust_edit_position_for_change(size_t pos, ptrdiff_t change) { - unsigned old_edit_pos = edit_pos; - unsigned old_select_pos = selection_pos; + size_t old_edit_pos = edit_pos; + size_t old_select_pos = selection_pos; if(change>0) { @@ -407,35 +393,35 @@ void Entry::adjust_edit_position_for_change(unsigned pos, int change) else if(change<0) { if(edit_pos>=pos) - edit_pos -= min(edit_pos-pos, -change); + edit_pos -= min(edit_pos-pos, -change); if(selection_active && selection_pos>=pos) - selection_pos -= min(selection_pos-pos, -change); + selection_pos -= min(selection_pos-pos, -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; + size_t start, end; if(get_selection(start, end)) signal_selection_changed.emit(start, end); } } -void Entry::set_edit_position(unsigned ep, bool select) +void Entry::set_edit_position(size_t ep, bool select) { bool selection_was_active = selection_active; if(select && !selection_active) selection_pos = edit_pos; selection_active = select; - unsigned old_edit_pos = edit_pos; + size_t old_edit_pos = edit_pos; edit_pos = min(ep, text.size()); if(edit_pos!=old_edit_pos) { signal_edit_position_changed.emit(edit_pos); - unsigned start, end; + size_t start, end; if(get_selection(start, end)) signal_selection_changed.emit(start, end); else if(selection_was_active) @@ -449,7 +435,7 @@ void Entry::set_edit_position(unsigned ep, bool select) void Entry::erase_selection(bool emit_change) { - unsigned start, end; + size_t start, end; if(!get_selection(start, end)) return; @@ -461,7 +447,7 @@ void Entry::erase_selection(bool emit_change) void Entry::check_cursor_blink() { - const Part *cursor_part = style->get_part("cursor"); + const Part *cursor_part = style->find_part("cursor"); bool has_blink = (cursor_part && cursor_part->get_graphic(ACTIVE|FOCUS)!=cursor_part->get_graphic(NORMAL|FOCUS)); cursor_blink = (state&FOCUS); @@ -483,18 +469,18 @@ 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; + size_t row, col; text.offset_to_coords(edit_pos, row, col); - unsigned old_first_row = first_row; + size_t old_first_row = first_row; if(first_row>row) first_row = row; else if(row>=first_row+visible_rows) first_row = row+1-visible_rows; - unsigned scroll = max(text.get_n_lines(), visible_rows)-visible_rows; + size_t scroll = max(text.get_n_lines(), visible_rows)-visible_rows; if(first_row>scroll) first_row = scroll; @@ -510,8 +496,8 @@ void Entry::slider_value_changed(double value) { if(text.get_n_lines()>visible_rows) { - unsigned old_first_row = first_row; - first_row = text.get_n_lines()-visible_rows-static_cast(value); + size_t old_first_row = first_row; + first_row = text.get_n_lines()-visible_rows-static_cast(value); if(first_row!=old_first_row) signal_scroll_position_changed.emit(first_row); mark_rebuild();