+ if(t!=text.get())
+ {
+ text = t;
+ signal_text_changed.emit(text.get());
+ }
+ set_edit_position(text.size());
+}
+
+void Entry::insert(unsigned pos, const string &t)
+{
+ if(t.empty())
+ return;
+
+ text.insert(pos, t);
+ signal_text_changed.emit(text.get());
+
+ adjust_edit_position_for_change(pos, t.size());
+ if(multiline)
+ check_view_range();
+
+ mark_rebuild();
+}
+
+void Entry::erase(unsigned pos, unsigned len)
+{
+ if(!len)
+ return;
+
+ text.erase(pos, len);
+ signal_text_changed.emit(text.get());
+
+ adjust_edit_position_for_change(pos, -len);
+ if(multiline)
+ check_view_range();
+
+ mark_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));
+ mark_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.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")
+ {
+ 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.transform(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);