X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdropdown.cpp;fp=source%2Fdropdown.cpp;h=ef0fa22f97c8f150009988b3487c716b1e576cf2;hb=1597579a34a8d87d4dea0a0cdc0895e6247b6126;hp=8cc6187f2243a552b0943dde919dff6e6c0d18cb;hpb=0326f950dfb4457bf3e3044cd17aeaa46e56bdac;p=libs%2Fgltk.git diff --git a/source/dropdown.cpp b/source/dropdown.cpp index 8cc6187..ef0fa22 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -25,8 +25,7 @@ Dropdown::Dropdown(ListData &d): void Dropdown::init() { - // Necessary to have the parent container raise the dropdown on click - input_type = INPUT_TEXT; + input_type = INPUT_NAVIGATION; dropped = false; @@ -86,21 +85,27 @@ void Dropdown::button_press(int x, int y, unsigned btn) { Container::button_press(x, y, btn); if(!click_focus) - { - dropped = false; - list.set_visible(false); - clear_state(ACTIVE); - signal_ungrab_pointer.emit(); - } + close_list(); } else if(btn==1) + open_list(); +} + +bool Dropdown::navigate(Navigation nav) +{ + if(dropped) { - dropped = true; - list.set_visible(true); - resize_list(); - set_state(ACTIVE); - signal_grab_pointer.emit(); + if(nav==NAV_CANCEL) + close_list(); + else + list.navigate(nav); } + else if(nav==NAV_ACTIVATE) + open_list(); + else + return false; + + return true; } void Dropdown::on_geometry_change() @@ -116,6 +121,24 @@ void Dropdown::on_style_change() resize_list(); } +void Dropdown::open_list() +{ + dropped = true; + list.set_visible(true); + resize_list(); + set_state(ACTIVE); + set_input_focus(&list); + signal_grab_pointer.emit(); +} + +void Dropdown::close_list() +{ + dropped = false; + list.set_visible(false); + clear_state(ACTIVE); + signal_ungrab_pointer.emit(); +} + void Dropdown::list_autosize_changed() { if(dropped)