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 SimpleItem: public Item
74 virtual void on_style_change();
77 class MultiColumnItem: public Item
80 virtual void check_widths(std::vector<unsigned> &) const;
81 virtual void set_widths(const std::vector<unsigned> &);
84 virtual void on_style_change();
88 class BasicItem: public SimpleItem
94 BasicItem(const std::string &);
102 virtual ~ItemFactory() { }
104 virtual void set_data(const ListData &) = 0;
105 virtual Item *create_item(unsigned) const = 0;
109 class TypedItemFactory: public ItemFactory
112 typedef typename I::ValueType ValueType;
114 const ListDataStore<ValueType> *data;
117 TypedItemFactory(const ListData &d)
120 virtual void set_data(const ListData &d)
122 if(const ListDataStore<ValueType> *ds = dynamic_cast<const ListDataStore<ValueType> *>(&d))
125 throw incompatible_data(typeid(ValueType));
128 virtual Item *create_item(unsigned i) const
130 return new I(data->get(i));
139 Row(unsigned f): first(f), height(0) { }
143 sigc::signal<void, unsigned> signal_item_selected;
144 sigc::signal<void> signal_selection_cleared;
149 DataObserver *observer;
150 ItemFactory *item_factory;
156 const Part *items_part;
157 bool ignore_slider_change;
163 std::vector<Item *> items;
164 std::vector<Row> rows;
174 virtual const char *get_class() const { return "list"; }
177 virtual void autosize_special(const Part &, Geometry &) const;
180 void set_data(ListData &);
181 ListData &get_data() { return *data; }
182 const ListData &get_data() const { return *data; }
184 void items_changed();
190 ItemFactory *f = new TypedItemFactory<I>(*data);
195 Item *create_item(unsigned);
198 void set_view_size(unsigned);
201 void set_selected_index(int);
202 int get_selected_index() const { return sel_index; }
204 void set_selected_item(Widget *);
206 virtual void rebuild_special(const Part &);
207 virtual void render_special(const Part &, GL::Renderer &) const;
210 virtual bool key_press(unsigned, unsigned);
211 virtual void button_press(int, int, unsigned);
212 virtual void touch_press(int, int, unsigned);
213 virtual void touch_release(int, int, unsigned);
214 virtual void touch_motion(int, int, unsigned);
215 virtual void focus_in();
216 virtual bool navigate(Navigation);
218 virtual void on_style_change();
220 void move_focus(Navigation, bool);
221 void set_focus_index(int);
223 void item_autosize_changed(Item *);
224 void reposition_items(bool);
225 unsigned last_to_first_row(unsigned) const;
226 unsigned item_index_to_row(unsigned) const;
227 void check_view_range();
228 void scroll_to_focus();
229 void slider_value_changed(double);
230 static void adjust_index(int &, int, int);