From: Mikko Rasa Date: Mon, 10 Mar 2008 10:59:14 +0000 (+0000) Subject: Add List::set_selected_index X-Git-Tag: 0.9~10 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f21a56605f3534cb24e5912cd4f4ee28279dcddd;p=libs%2Fgltk.git Add List::set_selected_index Duplicate the List manipulation functions in Dropdown --- diff --git a/source/dropdown.cpp b/source/dropdown.cpp index 4d18187..b25e594 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -36,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)) @@ -99,11 +129,14 @@ void Dropdown::list_item_selected(unsigned index, const std::string &item) { text=item; - list_active=false; - dropped=false; - state&=~ACTIVE; - 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); } diff --git a/source/dropdown.h b/source/dropdown.h index 49088e2..c9291f9 100644 --- a/source/dropdown.h +++ b/source/dropdown.h @@ -40,10 +40,18 @@ public: ~Dropdown(); void append(const std::string &); + void insert(unsigned, const std::string &); + void remove(unsigned); + void clear(); + + void set_selected_index(int); + const std::string &get_selected() const; + int get_selected_index() const; virtual void button_press(int, int, unsigned); virtual void button_release(int, int, unsigned); virtual void pointer_motion(int, int); + private: virtual const char *get_class() const { return "dropdown"; } virtual void render_special(const Part &) const; diff --git a/source/list.cpp b/source/list.cpp index 5665ef5..722e296 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -73,6 +73,19 @@ void List::clear() sel_index=-1; } +void List::set_selected_index(int i) +{ + if(i<0) + sel_index=-1; + else if(i(items.size())) + { + sel_index=i; + signal_item_selected.emit(sel_index, items[sel_index]); + } + else + throw InvalidParameterValue("Index out of range"); +} + const string &List::get_selected() const { if(sel_index<0) @@ -137,6 +150,7 @@ void List::render_special(const Part &part) const Geometry pgeom=geom; pgeom.h=row_height; + pgeom.w-=margin.left+margin.right; for(unsigned i=0; (i