]> git.tdb.fi Git - libs/gltk.git/commitdiff
Enable loading dropdown items from datafile
authorMikko Rasa <tdb@tdb.fi>
Wed, 27 Feb 2008 12:25:30 +0000 (12:25 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 27 Feb 2008 12:25:30 +0000 (12:25 +0000)
Add a missing range check to List

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

index bc44f27c3ec774a4b982ea9ab72c5dbf5bf40e71..5f49b9ef33396dea8cd8141d92dcfe52386f9cfd 100644 (file)
@@ -116,5 +116,17 @@ void Dropdown::list_item_selected(unsigned index, const std::string &item)
        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<Dropdown &>(wdg).append(str);
+}
+
 } // namespace GLtk
 } // namespace Msp
index 825b8002d2427bfd6e8f426785fb91f61020d1ea..d1a2609772fbe85047664f33a599c9c9d008d009 100644 (file)
@@ -18,6 +18,15 @@ class List;
 
 class Dropdown: public Widget
 {
+public:
+       class Loader: public Widget::Loader
+       {
+       public:
+               Loader(Dropdown &);
+       private:
+               void item(const std::string &);
+       };
+
 private:
        List *list;
        std::string text;
index 4f8b27c649a909ddd8fabd7ce7c7db1f273d2c30..5665ef5dc264391f7020005d5635be43c30009d8 100644 (file)
@@ -98,7 +98,7 @@ void List::button_press(int x, int y, unsigned btn)
                        y+=items_part->get_margin().top;
 
                unsigned i=(geom.h-1-y)/row_height;
-               if(i<n_visible)
+               if(i<n_visible && first+i<items.size())
                {
                        sel_index=first+i;