1 #ifndef MSP_GLTK_LIST_H_
2 #define MSP_GLTK_LIST_H_
6 #include <sigc++/signal.h>
16 Thrown if a list's item type is incompatible with its data.
18 class incompatible_data: public std::logic_error
21 incompatible_data(const std::type_info &);
22 virtual ~incompatible_data() throw() { }
27 Shows a list of items, allowing the user to select one. A slider is included
28 to allow scrolling through a long list.
30 class List: virtual public Widget, private Container
33 class Loader: public DataFile::DerivedObjectLoader<List, Widget::Loader>
38 void item(const std::string &);
42 /// This exists to make disconnecting signals easier
43 class DataObserver: public sigc::trackable
51 void item_added(unsigned);
52 void item_removed(unsigned);
54 void refresh_item(unsigned);
58 class Item: public Container
61 virtual const char *get_class() const { return "listitem"; }
64 virtual void autosize_special(const Part &, Geometry &);
66 void set_active(bool);
68 virtual void render_special(const Part &, GL::Renderer &) const;
72 class BasicItem: public Item
78 BasicItem(const std::string &);
81 virtual void on_style_change();
89 virtual ~ItemFactory() { }
91 virtual void set_data(const ListData &) = 0;
92 virtual Item *create_item(unsigned) const = 0;
96 class TypedItemFactory: public ItemFactory
99 typedef typename I::ValueType ValueType;
101 const ListDataStore<ValueType> *data;
104 TypedItemFactory(const ListData &d)
107 virtual void set_data(const ListData &d)
109 if(const ListDataStore<ValueType> *ds = dynamic_cast<const ListDataStore<ValueType> *>(&d))
112 throw incompatible_data(typeid(ValueType));
115 virtual Item *create_item(unsigned i) const
117 return new I(data->get(i));
122 sigc::signal<void, unsigned> signal_item_selected;
127 DataObserver *observer;
128 ItemFactory *item_factory;
135 std::vector<Item *> items;
145 virtual const char *get_class() const { return "list"; }
148 virtual void autosize_special(const Part &, Geometry &);
151 void set_data(ListData &);
152 ListData &get_data() { return *data; }
153 const ListData &get_data() const { return *data; }
155 void items_changed();
161 ItemFactory *f = new TypedItemFactory<I>(*data);
166 Item *create_item(unsigned);
169 void set_view_size(unsigned);
172 void set_selected_index(int);
173 int get_selected_index() const { return sel_index; }
176 virtual void render_special(const Part &, GL::Renderer &) const;
179 virtual void button_press(int, int, unsigned);
181 virtual void on_geometry_change();
182 virtual void on_style_change();
184 void reposition_slider();
185 void item_autosize_changed(Item *);
186 void reposition_items();
187 void check_view_range();
188 void slider_value_changed(double);