X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdropdown.cpp;h=b25e5944d2548241e534bf78071d37dde44960c7;hb=f21a56605f3534cb24e5912cd4f4ee28279dcddd;hp=bc44f27c3ec774a4b982ea9ab72c5dbf5bf40e71;hpb=95210598ff214bbc8d05657aeffc4ce7801f211a;p=libs%2Fgltk.git diff --git a/source/dropdown.cpp b/source/dropdown.cpp index bc44f27..b25e594 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -18,6 +18,7 @@ namespace GLtk { Dropdown::Dropdown(const Resources &r): Widget(r), list(new List(res)), + dropped(false), list_active(false) { list->signal_item_selected.connect(sigc::mem_fun(this, &Dropdown::list_item_selected)); @@ -35,6 +36,36 @@ void Dropdown::append(const string &item) list->append(item); } +void Dropdown::insert(unsigned i, const string &v) +{ + list->insert(i, v); +} + +void Dropdown::remove(unsigned i) +{ + list->remove(i); +} + +void Dropdown::clear() +{ + list->clear(); +} + +void Dropdown::set_selected_index(int i) +{ + list->set_selected_index(i); +} + +const string &Dropdown::get_selected() const +{ + return list->get_selected(); +} + +int Dropdown::get_selected_index() const +{ + return list->get_selected_index(); +} + void Dropdown::button_press(int x, int y, unsigned btn) { if(list->get_geometry().is_inside(x, y)) @@ -43,14 +74,16 @@ void Dropdown::button_press(int x, int y, unsigned btn) list->button_press(x-lgeom.x, y-lgeom.y, btn); list_active=true; } - else if(state==ACTIVE) + else if(dropped) { - state=HOVER; + dropped=false; + state&=~ACTIVE; parent->ungrab_pointer(*this); } else if(btn==1) { - state=ACTIVE; + dropped=true; + state|=ACTIVE; if(parent) { @@ -79,23 +112,11 @@ void Dropdown::pointer_motion(int x, int y) } } -void Dropdown::pointer_enter() -{ - if(state==NORMAL) - state=HOVER; -} - -void Dropdown::pointer_leave() -{ - if(state==HOVER) - state=NORMAL; -} - void Dropdown::render_special(const Part &part) const { if(part.get_name()=="text") render_text(part, text); - else if(part.get_name()=="list" && state==ACTIVE) + else if(part.get_name()=="list" && dropped) list->render(); } @@ -108,13 +129,29 @@ void Dropdown::list_item_selected(unsigned index, const std::string &item) { text=item; - list_active=false; - state=NORMAL; - if(parent) - parent->ungrab_pointer(*this); + if(dropped) + { + list_active=false; + dropped=false; + state&=~ACTIVE; + if(parent) + parent->ungrab_pointer(*this); + } signal_item_selected.emit(index, item); } + +Dropdown::Loader::Loader(Dropdown &d): + Widget::Loader(d) +{ + add("item", &Loader::item); +} + +void Dropdown::Loader::item(const string &str) +{ + static_cast(wdg).append(str); +} + } // namespace GLtk } // namespace Msp