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
39 class Loader: public DataFile::DerivedObjectLoader<List, Widget::Loader>
44 void item(const std::string &);
48 /// This exists to make disconnecting signals easier
49 class DataObserver: public sigc::trackable
57 void item_added(unsigned);
58 void item_removed(unsigned);
60 void refresh_item(unsigned);
64 class Item: virtual public Widget, protected Container
70 virtual const char *get_class() const { return "listitem"; }
73 virtual void autosize_special(const Part &, Geometry &) const;
75 void set_active(bool);
77 virtual void render_special(const Part &, GL::Renderer &) const;
80 class SimpleItem: public Item
85 virtual void on_style_change();
88 class MultiColumnItem: public Item
93 virtual void check_widths(std::vector<unsigned> &) const;
94 virtual void set_widths(const std::vector<unsigned> &);
96 virtual void on_style_change();
100 class BasicItem: public SimpleItem
106 BasicItem(const std::string &);
114 virtual ~ItemFactory() { }
116 virtual void set_data(const ListData &) = 0;
117 virtual Item *create_item(unsigned) const = 0;
121 class TypedItemFactory: public ItemFactory
124 typedef typename I::ValueType ValueType;
126 const ListDataStore<ValueType> *data;
129 TypedItemFactory(const ListData &d)
132 virtual void set_data(const ListData &d)
134 if(const ListDataStore<ValueType> *ds = dynamic_cast<const ListDataStore<ValueType> *>(&d))
137 throw incompatible_data(typeid(ValueType));
140 virtual Item *create_item(unsigned i) const
142 return new I(data->get(i));
151 Row(unsigned f): first(f), height(0) { }
155 sigc::signal<void, unsigned> signal_item_selected;
156 sigc::signal<void> signal_selection_cleared;
161 DataObserver *observer;
162 ItemFactory *item_factory;
169 unsigned view_columns;
170 const Part *items_part;
171 bool ignore_slider_change;
177 std::vector<Item *> items;
178 std::vector<Row> rows;
188 virtual const char *get_class() const { return "list"; }
191 virtual void autosize_special(const Part &, Geometry &) const;
194 void set_data(ListData &);
195 ListData &get_data() { return *data; }
196 const ListData &get_data() const { return *data; }
198 void items_changed();
204 ItemFactory *f = new TypedItemFactory<I>(*data);
209 Item *create_item(unsigned);
212 void set_view_mode(ViewMode);
213 void set_view_size(unsigned);
214 void set_view_size(unsigned, unsigned);
217 void set_selected_index(int);
218 int get_selected_index() const { return sel_index; }
220 void set_selected_item(Widget *);
222 virtual void rebuild_special(const Part &);
223 virtual void render_special(const Part &, GL::Renderer &) const;
226 virtual bool key_press(unsigned, unsigned);
227 virtual void button_press(int, int, unsigned);
228 virtual void touch_press(int, int, unsigned);
229 virtual void touch_release(int, int, unsigned);
230 virtual void touch_motion(int, int, unsigned);
231 virtual void focus_in();
232 virtual bool navigate(Navigation);
234 virtual void on_style_change();
236 void move_focus(Navigation, bool);
237 void set_focus_index(int);
239 void item_autosize_changed(Item *);
240 void reposition_items(bool);
241 unsigned last_to_first_row(unsigned) const;
242 unsigned item_index_to_row(unsigned) const;
243 void check_view_range();
244 void scroll_to_focus();
245 void slider_value_changed(double);
246 static void adjust_index(int &, int, int);
249 void operator>>(const LexicalConverter &, List::ViewMode &);