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 &) const;
66 void set_active(bool);
68 virtual void render_special(const Part &, GL::Renderer &) const;
71 class MultiColumnItem: public Item
74 virtual void check_widths(std::vector<unsigned> &) const;
75 virtual void set_widths(const std::vector<unsigned> &);
78 virtual void on_style_change();
82 class BasicItem: public Item
88 BasicItem(const std::string &);
91 virtual void on_style_change();
99 virtual ~ItemFactory() { }
101 virtual void set_data(const ListData &) = 0;
102 virtual Item *create_item(unsigned) const = 0;
106 class TypedItemFactory: public ItemFactory
109 typedef typename I::ValueType ValueType;
111 const ListDataStore<ValueType> *data;
114 TypedItemFactory(const ListData &d)
117 virtual void set_data(const ListData &d)
119 if(const ListDataStore<ValueType> *ds = dynamic_cast<const ListDataStore<ValueType> *>(&d))
122 throw incompatible_data(typeid(ValueType));
125 virtual Item *create_item(unsigned i) const
127 return new I(data->get(i));
132 sigc::signal<void, unsigned> signal_item_selected;
137 DataObserver *observer;
138 ItemFactory *item_factory;
145 std::vector<Item *> items;
155 virtual const char *get_class() const { return "list"; }
158 virtual void autosize_special(const Part &, Geometry &) const;
161 void set_data(ListData &);
162 ListData &get_data() { return *data; }
163 const ListData &get_data() const { return *data; }
165 void items_changed();
171 ItemFactory *f = new TypedItemFactory<I>(*data);
176 Item *create_item(unsigned);
179 void set_view_size(unsigned);
182 void set_selected_index(int);
183 int get_selected_index() const { return sel_index; }
186 virtual void render_special(const Part &, GL::Renderer &) const;
189 virtual void button_press(int, int, unsigned);
191 virtual void on_geometry_change();
192 virtual void on_style_change();
194 void reposition_slider();
195 void item_autosize_changed();
196 void reposition_items();
197 void check_view_range();
198 void slider_value_changed(double);