]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add List::set_selected_index
authorMikko Rasa <tdb@tdb.fi>
Mon, 10 Mar 2008 10:59:14 +0000 (10:59 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 10 Mar 2008 10:59:14 +0000 (10:59 +0000)
Duplicate the List manipulation functions in Dropdown

source/dropdown.cpp
source/dropdown.h
source/list.cpp
source/list.h

index 4d18187a7fb28642934dd5a5aeb0adb0038e85b6..b25e5944d2548241e534bf78071d37dde44960c7 100644 (file)
@@ -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);
 }
index 49088e20f2dc8e01e6567f7b6eb69618f1febc0a..c9291f91e8d8c39929d0eca0b3bb829ca8e449a2 100644 (file)
@@ -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;
index 5665ef5dc264391f7020005d5635be43c30009d8..722e296edf9cae096b19e2c736f6075d439dc686 100644 (file)
@@ -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<static_cast<int>(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<n_visible && first+i<items.size()); ++i)
                {
index 77d7e9f49166ac53e62c5a06785e0e14bd12ed28..a13de52db627468bca5da9d9fd0c35c7996f13ef 100644 (file)
@@ -53,6 +53,7 @@ public:
        void remove(unsigned);
        void clear();
 
+       void set_selected_index(int);
        const std::string &get_selected() const;
        int get_selected_index() const { return sel_index; }