X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdropdown.cpp;h=8cc6187f2243a552b0943dde919dff6e6c0d18cb;hb=4b52d16bc895f9d969383d7a7d6a3558c1972cc5;hp=7dc0d3550bcaf7d8953ec2a8b5d1013355ad69fd;hpb=1d6cebd9f1795a22d6be47a7a049496b89de46f7;p=libs%2Fgltk.git diff --git a/source/dropdown.cpp b/source/dropdown.cpp index 7dc0d35..8cc6187 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -25,11 +25,16 @@ Dropdown::Dropdown(ListData &d): void Dropdown::init() { + // Necessary to have the parent container raise the dropdown on click + input_type = INPUT_TEXT; + dropped = false; add(list); + list.set_visible(false); list.set_view_all(); list.signal_item_selected.connect(sigc::mem_fun(this, &Dropdown::list_item_selected)); + list.signal_selection_cleared.connect(sigc::mem_fun(this, &Dropdown::list_selection_cleared)); list.signal_autosize_changed.connect(sigc::mem_fun(this, &Dropdown::list_autosize_changed)); } @@ -61,13 +66,6 @@ void Dropdown::autosize_special(const Part &part, Geometry &ageom) const } } -void Dropdown::set_selected_index(int index) -{ - list.set_selected_index(index); - if(index<0) - text.set(string()); -} - void Dropdown::rebuild_special(const Part &part) { if(part.get_name()=="text") @@ -90,6 +88,7 @@ void Dropdown::button_press(int x, int y, unsigned btn) if(!click_focus) { dropped = false; + list.set_visible(false); clear_state(ACTIVE); signal_ungrab_pointer.emit(); } @@ -97,6 +96,7 @@ void Dropdown::button_press(int x, int y, unsigned btn) else if(btn==1) { dropped = true; + list.set_visible(true); resize_list(); set_state(ACTIVE); signal_grab_pointer.emit(); @@ -105,18 +105,21 @@ void Dropdown::button_press(int x, int y, unsigned btn) void Dropdown::on_geometry_change() { - resize_list(); + if(dropped) + resize_list(); } void Dropdown::on_style_change() { text.set_style(style); - resize_list(); + if(dropped) + resize_list(); } void Dropdown::list_autosize_changed() { - resize_list(); + if(dropped) + resize_list(); signal_autosize_changed.emit(); } @@ -168,6 +171,11 @@ void Dropdown::list_item_selected(unsigned index) rebuild(); } +void Dropdown::list_selection_cleared() +{ + text.set(string()); +} + Dropdown::Loader::Loader(Dropdown &d): DataFile::DerivedObjectLoader(d)