+ if(t.empty())
+ return;
+
+ text.insert(pos, t);
+
+ unsigned old_edit_pos = edit_pos;
+ if(edit_pos>=pos)
+ edit_pos += t.size();
+ if(selection_active && selection_pos>=pos)
+ selection_pos += t.size();
+
+ signal_text_changed.emit(text.get());
+ if(edit_pos!=old_edit_pos)
+ signal_edit_position_changed.emit(edit_pos);
+
+ if(multiline)
+ check_view_range();
+
+ rebuild();
+}
+
+void Entry::erase(unsigned pos, unsigned len)
+{
+ if(!len)
+ return;
+
+ text.erase(pos, len);
+
+ unsigned old_edit_pos = edit_pos;
+ 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;
+ }
+
+ signal_text_changed.emit(text.get());
+ if(edit_pos!=old_edit_pos)
+ signal_edit_position_changed.emit(edit_pos);
+
+ if(multiline)
+ check_view_range();
+
+ 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::translate_position(unsigned pos, unsigned &row, unsigned &col) const
+{
+ text.offset_to_coords(pos, row, col);
+}
+
+unsigned Entry::translate_position(unsigned row, unsigned col) const
+{
+ return text.coords_to_offset(row, col);
+}
+
+void Entry::set_edit_size(unsigned w, unsigned h)
+{
+ edit_width = w;
+ edit_height = h;
+ signal_autosize_changed.emit();
+}
+
+void Entry::set_multiline(bool m)
+{
+ multiline = m;
+ if(multiline)
+ {
+ if(!slider)
+ {
+ slider = new VSlider;
+ add(*slider);
+ slider->set_step(1);
+ slider->signal_value_changed.connect(sigc::mem_fun(this, &Entry::slider_value_changed));
+ rebuild();
+ }
+ check_view_range();
+ }
+}
+
+void Entry::rebuild_special(const Part &part)
+{
+ if(part.get_name()=="text")
+ text.build(part, state, geom, first_row, part_cache);
+ else if(part.get_name()=="cursor")
+ {
+ State cursor_state = (cursor_blink ? ACTIVE : NORMAL);
+ const Graphic *graphic = part.get_graphic(state|cursor_state);
+ if(!text_part || !graphic || !graphic->get_texture())
+ return;
+
+ unsigned row, col;
+ text.offset_to_coords(edit_pos, row, col);
+
+ if(row<first_row || row>=first_row+visible_rows)
+ return;
+
+ 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);
+ graphic->build(part.get_geometry().w, part.get_geometry().h, bld);
+ }
+ else if(part.get_name()=="selection")
+ {
+ if(!selection_active)
+ return;
+
+ const Graphic *graphic = part.get_graphic(state);
+ if(!text_part || !graphic || !graphic->get_texture())
+ return;
+
+ unsigned start, end;
+ get_selection(start, end);
+
+ unsigned row, col;
+ text.offset_to_coords(start, row, col);
+ unsigned end_row, end_col;
+ text.offset_to_coords(end, end_row, end_col);
+
+ if(end_row<first_row || row>=first_row+visible_rows)
+ return;
+
+ if(row<first_row)
+ {
+ row = first_row;
+ col = 0;
+ }
+
+ if(end_row>=first_row+visible_rows)
+ {
+ end_row = first_row+visible_rows-1;
+ end_col = text.get_line_length(end_row);
+ }
+
+ while(row<=end_row)
+ {
+ unsigned 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);
+ graphic->build(egeom.x-rgeom.x, part.get_geometry().h, bld);
+ }
+
+ ++row;
+ col = 0;
+ }
+ }
+ else if(part.get_name()=="slider")
+ {
+ if(multiline)
+ {
+ reposition_child(*slider, part);
+ Widget::rebuild_special(part);
+ }
+ }
+ else
+ Widget::rebuild_special(part);
+}
+
+void Entry::render_special(const Part &part, GL::Renderer &renderer) const
+{
+ if(part.get_name()=="slider" && multiline)
+ slider->render(renderer);
+}
+
+void Entry::touch_press(int x, int y, unsigned finger)
+{
+ if(finger==0)
+ set_focus();
+ Widget::touch_press(x, y, finger);
+}
+
+bool Entry::key_press(unsigned key, unsigned mod)
+{
+ got_key_press = true;
+ if(key==Input::KEY_BACKSPACE)
+ {
+ if(selection_active)
+ erase_selection(true);
+ else if(edit_pos>0)
+ erase(edit_pos-1, 1);
+ }
+ else if(key==Input::KEY_DELETE)
+ {
+ if(selection_active)
+ erase_selection(true);
+ else
+ erase(edit_pos, 1);
+ }
+ else if(key==Input::KEY_ENTER && multiline)
+ insert(edit_pos, "\n");
+ else if(key==Input::KEY_END)
+ {
+ unsigned 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;
+ 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_LEFT && mod==MOD_SHIFT)
+ move_edit_position(NAV_LEFT, true);
+ else if(key==Input::KEY_RIGHT && mod==MOD_SHIFT)
+ move_edit_position(NAV_RIGHT, true);
+ else if(key==Input::KEY_UP && mod==MOD_SHIFT && multiline)
+ move_edit_position(NAV_UP, true);
+ else if(key==Input::KEY_DOWN && mod==MOD_SHIFT && multiline)
+ move_edit_position(NAV_DOWN, true);
+ else
+ return false;
+
+ return true;
+}
+
+bool Entry::character(wchar_t ch)
+{
+ if(got_key_press && ch>=' ' && ch!=0x7F)
+ {
+ if(selection_active)
+ erase_selection(false);
+ insert(edit_pos, StringCodec::encode<StringCodec::Utf8>(StringCodec::ustring(1, ch)));
+ return true;
+ }
+
+ return false;
+}
+
+void Entry::focus_in()
+{
+ cursor_blink = true;
+ Widget::focus_in();
+ check_cursor_blink();
+}
+
+void Entry::focus_out()
+{
+ Widget::focus_out();
+ got_key_press = false;
+ check_cursor_blink();
+}
+
+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;
+
+ return true;
+}
+
+void Entry::animate(const Time::TimeDelta &)
+{
+ cursor_blink = !cursor_blink;
+ rebuild();
+}
+
+void Entry::on_geometry_change()
+{
+ if(multiline)
+ check_view_range();
+}
+
+void Entry::on_style_change()
+{
+ text.set_style(style);
+
+ if(!style)
+ {
+ text_part = 0;
+ return;
+ }
+
+ text_part = style->get_part("text");
+
+ if(multiline)
+ check_view_range();
+
+ check_cursor_blink();
+}
+
+void Entry::move_edit_position(Navigation nav, bool select)
+{
+ if(nav==NAV_LEFT)