1 #ifndef MSP_GLTK_LIST_H_
2 #define MSP_GLTK_LIST_H_
6 #include <sigc++/signal.h>
10 #include "mspgltk_api.h"
17 Thrown if a list's item type is incompatible with its data.
19 class MSPGLTK_API incompatible_data: public std::logic_error
22 incompatible_data(const std::type_info &);
23 virtual ~incompatible_data() throw() { }
28 Shows a list of items, allowing the user to select one. A slider is included
29 to allow scrolling through a long list.
31 class MSPGLTK_API List: virtual public Widget, private Container
40 class Loader: public DataFile::DerivedObjectLoader<List, Widget::Loader>
45 void item(const std::string &);
49 /// This exists to make disconnecting signals easier
50 class DataObserver: public sigc::trackable
58 void item_added(unsigned);
59 void item_removed(unsigned);
61 void refresh_item(unsigned);
65 class Item: virtual public Widget, protected Container
71 virtual const char *get_class() const { return "listitem"; }
74 virtual void autosize_special(const Part &, Geometry &) const;
76 void set_active(bool);
78 virtual void render_special(const Part &, GL::Renderer &) const;
81 class SimpleItem: public Item
86 virtual void on_style_change();
89 class MultiColumnItem: public Item
94 virtual void check_widths(std::vector<unsigned> &) const;
95 virtual void set_widths(const std::vector<unsigned> &);
97 virtual void on_style_change();
101 class BasicItem: public SimpleItem
107 BasicItem(const std::string &);
115 virtual ~ItemFactory() { }
117 virtual void set_data(const ListData &) = 0;
118 virtual Item *create_item(unsigned) const = 0;
122 class TypedItemFactory: public ItemFactory
125 typedef typename I::ValueType ValueType;
127 const ListDataStore<ValueType> *data;
130 TypedItemFactory(const ListData &d)
133 virtual void set_data(const ListData &d)
135 if(const ListDataStore<ValueType> *ds = dynamic_cast<const ListDataStore<ValueType> *>(&d))
138 throw incompatible_data(typeid(ValueType));
141 virtual Item *create_item(unsigned i) const
143 return new I(data->get(i));
152 Row(unsigned f): first(f), height(0) { }
156 sigc::signal<void, unsigned> signal_item_selected;
157 sigc::signal<void> signal_selection_cleared;
162 DataObserver *observer;
163 ItemFactory *item_factory;
170 unsigned view_columns;
171 const Part *items_part;
172 bool ignore_slider_change;
178 std::vector<Item *> items;
179 std::vector<Row> rows;
189 virtual const char *get_class() const { return "list"; }
192 virtual void autosize_special(const Part &, Geometry &) const;
195 void set_data(ListData &);
196 ListData &get_data() { return *data; }
197 const ListData &get_data() const { return *data; }
199 void items_changed();
205 ItemFactory *f = new TypedItemFactory<I>(*data);
210 Item *create_item(unsigned);
213 void set_view_mode(ViewMode);
214 void set_view_size(unsigned);
215 void set_view_size(unsigned, unsigned);
218 void set_selected_index(int);
219 int get_selected_index() const { return sel_index; }
221 void set_selected_item(Widget *);
223 virtual void rebuild_special(const Part &);
224 virtual void render_special(const Part &, GL::Renderer &) const;
227 virtual bool key_press(unsigned, unsigned);
228 virtual void button_press(int, int, unsigned);
229 virtual void touch_press(int, int, unsigned);
230 virtual void touch_release(int, int, unsigned);
231 virtual void touch_motion(int, int, unsigned);
232 virtual void focus_in();
233 virtual bool navigate(Navigation);
235 virtual void on_style_change();
237 void move_focus(Navigation, bool);
238 void set_focus_index(int);
240 void item_autosize_changed(Item *);
241 void reposition_items(bool);
242 unsigned last_to_first_row(unsigned) const;
243 unsigned item_index_to_row(unsigned) const;
244 void check_view_range();
245 void scroll_to_focus();
246 void slider_value_changed(double);
247 static void adjust_index(int &, int, int);
250 MSPGLTK_API void operator>>(const LexicalConverter &, List::ViewMode &);