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;
133 sigc::signal<void> signal_selection_cleared;
138 DataObserver *observer;
139 ItemFactory *item_factory;
145 bool ignore_slider_change;
151 std::vector<Item *> items;
161 virtual const char *get_class() const { return "list"; }
164 virtual void autosize_special(const Part &, Geometry &) const;
167 void set_data(ListData &);
168 ListData &get_data() { return *data; }
169 const ListData &get_data() const { return *data; }
171 void items_changed();
177 ItemFactory *f = new TypedItemFactory<I>(*data);
182 Item *create_item(unsigned);
185 void set_view_size(unsigned);
188 void set_selected_index(int);
189 int get_selected_index() const { return sel_index; }
191 void set_selected_item(Widget *);
193 virtual void rebuild_special(const Part &);
194 virtual void render_special(const Part &, GL::Renderer &) const;
197 virtual bool key_press(unsigned, unsigned);
198 virtual void button_press(int, int, unsigned);
199 virtual void touch_press(int, int, unsigned);
200 virtual void touch_release(int, int, unsigned);
201 virtual void touch_motion(int, int, unsigned);
202 virtual void focus_in();
203 virtual bool navigate(Navigation);
205 void move_focus(Navigation, bool);
206 void set_focus_index(int);
208 void item_autosize_changed(Item *);
209 unsigned last_to_first(unsigned) const;
210 void check_view_range();
211 void scroll_to_focus();
212 void slider_value_changed(double);
213 static void adjust_index(int &, int, int);