X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=4c1713a022306d4b7670ef3953be2a62457f85a9;hb=5f73de83d46138faa2b4c1b0a725d0a705988388;hp=751f173d0c234a36a10c340987112fa6a7dd1605;hpb=474578fd04355c3247e8f9f6383d17e37c2c3015;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index 751f173..4c1713a 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -5,8 +5,8 @@ #include "entry.h" #include "graphic.h" #include "part.h" +#include "slider.h" #include "style.h" -#include "vslider.h" using namespace std; @@ -56,7 +56,11 @@ void Entry::autosize_special(const Part &part, Geometry &ageom) const void Entry::set_text(const string &t) { - text = t; + if(t!=text.get()) + { + text = t; + signal_text_changed.emit(text.get()); + } set_edit_position(text.size()); } @@ -80,7 +84,7 @@ void Entry::insert(unsigned pos, const string &t) if(multiline) check_view_range(); - rebuild(); + mark_rebuild(); } void Entry::erase(unsigned pos, unsigned len) @@ -110,7 +114,7 @@ void Entry::erase(unsigned pos, unsigned len) if(multiline) check_view_range(); - rebuild(); + mark_rebuild(); } bool Entry::get_selection(unsigned &start, unsigned &end) const @@ -154,7 +158,7 @@ void Entry::set_multiline(bool m) add(*slider); slider->set_step(1); slider->signal_value_changed.connect(sigc::mem_fun(this, &Entry::slider_value_changed)); - rebuild(); + mark_rebuild(); } check_view_range(); } @@ -265,14 +269,20 @@ bool Entry::key_press(unsigned key, unsigned mod) if(selection_active) erase_selection(true); else if(edit_pos>0) - erase(edit_pos-1, 1); + { + unsigned start_pos = text.move_offset(edit_pos, -1); + erase(start_pos, edit_pos-start_pos); + } } else if(key==Input::KEY_DELETE) { if(selection_active) erase_selection(true); else - erase(edit_pos, 1); + { + unsigned end_pos = text.move_offset(edit_pos, 1); + erase(edit_pos, end_pos-edit_pos); + } } else if(key==Input::KEY_ENTER && multiline) insert(edit_pos, "\n"); @@ -288,6 +298,18 @@ bool Entry::key_press(unsigned key, unsigned mod) 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; + text.offset_to_coords(edit_pos, row, col); + set_edit_position(text.coords_to_offset((row0) - set_edit_position(edit_pos-1, select); - } + set_edit_position(text.move_offset(edit_pos, -1), select); else if(nav==NAV_RIGHT) - { - if(edit_pos0 ? text.coords_to_offset(row-1, col) : 0), select); } + else + throw invalid_argument("Entry::move_edit_position"); } void Entry::set_edit_position(unsigned ep, bool select) @@ -411,7 +429,7 @@ void Entry::set_edit_position(unsigned ep, bool select) if(multiline) check_view_range(); - rebuild(); + mark_rebuild(); } void Entry::erase_selection(bool emit_change) @@ -428,18 +446,21 @@ void Entry::erase_selection(bool emit_change) void Entry::check_cursor_blink() { + const Part *cursor_part = style->get_part("cursor"); + bool has_blink = (cursor_part && cursor_part->get_graphic(ACTIVE|FOCUS)!=cursor_part->get_graphic(NORMAL|FOCUS)); + cursor_blink = (state&FOCUS); - if((state&FOCUS) && style) + if((state&FOCUS) && style && has_blink) { - const Part *cursor_part = style->get_part("cursor"); - if(cursor_part && cursor_part->get_graphic(ACTIVE|FOCUS)!=cursor_part->get_graphic(NORMAL|FOCUS)) - { - set_animation_interval(Time::sec/2); - return; - } + set_animation_interval(Time::sec/2); + mark_rebuild(); + } + else + { + if(has_blink) + mark_rebuild(); + stop_animation(); } - - stop_animation(); } void Entry::check_view_range() @@ -458,11 +479,15 @@ void Entry::check_view_range() else if(row>=first_row+visible_rows) first_row = row+1-visible_rows; + unsigned scroll = max(text.get_n_lines(), visible_rows)-visible_rows; + if(first_row>scroll) + first_row = scroll; + if(first_row!=old_first_row) signal_scroll_position_changed.emit(first_row); - unsigned scroll = max(text.get_n_lines(), visible_rows)-visible_rows; slider->set_range(0, scroll); + slider->set_page_size(visible_rows); slider->set_value(scroll-first_row); } @@ -474,6 +499,7 @@ void Entry::slider_value_changed(double value) 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(); } }