X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=16954a70f5774858b34b86622de200abe2a4376b;hb=4b52d16bc895f9d969383d7a7d6a3558c1972cc5;hp=44a169aad7f60283188bc84a3c82c92d2ad56bb8;hpb=729cb06f85e2888a7ac1e72375380257936106c9;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index 44a169a..16954a7 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -25,6 +25,7 @@ Entry::Entry(const string &t): slider(0), got_key_press(false) { + input_type = INPUT_TEXT; set_text(t); } @@ -47,22 +48,7 @@ void Entry::autosize_special(const Part &part, Geometry &ageom) const ageom.h = max(ageom.h, line_height+margin.top+margin.bottom); } else if(part.get_name()=="slider" && multiline) - { - Geometry sgeom = part.get_geometry(); - if(!sgeom.w || !sgeom.h) - { - Geometry wgeom; - slider->autosize(wgeom); - if(!sgeom.w) - sgeom.w = wgeom.w; - if(!sgeom.h) - sgeom.h = wgeom.h; - } - - const Sides &margin = part.get_margin(); - ageom.w = max(ageom.w, sgeom.w+margin.left+margin.right); - ageom.h = max(ageom.h, sgeom.h+margin.top+margin.bottom); - } + autosize_child(*slider, part, ageom); } void Entry::set_text(const string &t) @@ -94,7 +80,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)); - reposition_slider(); + rebuild(); } check_view_range(); } @@ -122,6 +108,14 @@ void Entry::rebuild_special(const Part &part) 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()=="slider") + { + if(multiline) + { + reposition_child(*slider, part); + Widget::rebuild_special(part); + } + } else Widget::rebuild_special(part); } @@ -132,7 +126,7 @@ void Entry::render_special(const Part &part, GL::Renderer &renderer) const slider->render(renderer); } -void Entry::key_press(unsigned key, unsigned) +bool Entry::key_press(unsigned key, unsigned) { got_key_press = true; if(key==Input::KEY_LEFT) @@ -177,16 +171,23 @@ void Entry::key_press(unsigned key, unsigned) else signal_enter.emit(); } + else + return false; + + return true; } -void Entry::character(wchar_t ch) +bool Entry::character(wchar_t ch) { if(got_key_press && ch>=' ') { text.insert(edit_pos, StringCodec::encode(StringCodec::ustring(1, ch))); ++edit_pos; rebuild(); + return true; } + + return false; } void Entry::focus_out() @@ -197,8 +198,6 @@ void Entry::focus_out() void Entry::on_geometry_change() { - reposition_slider(); - if(multiline) check_view_range(); } @@ -215,8 +214,6 @@ void Entry::on_style_change() text_part = style->get_part("text"); - reposition_slider(); - if(multiline) check_view_range(); } @@ -228,29 +225,6 @@ void Entry::set_edit_position(unsigned ep) rebuild(); } -void Entry::reposition_slider() -{ - if(!style || !slider) - return; - - if(const Part *slider_part = style->get_part("slider")) - { - Geometry sgeom = slider_part->get_geometry(); - if(!sgeom.w || !sgeom.h) - { - Geometry wgeom; - slider->autosize(wgeom); - if(!sgeom.w) - sgeom.w = wgeom.w; - if(!sgeom.h) - sgeom.h = wgeom.h; - } - - slider_part->get_alignment().apply(sgeom, geom, slider_part->get_margin()); - slider->set_geometry(sgeom); - } -} - void Entry::check_view_range() { if(!multiline || !text_part)