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
84 SimpleItem() = default;
86 virtual void on_style_change();
89 class MultiColumnItem: public Item
92 MultiColumnItem() = default;
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 &);
113 ItemFactory() = default;
115 virtual ~ItemFactory() = default;
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;
161 bool own_data = false;
162 DataObserver *observer = 0;
163 ItemFactory *item_factory = 0;
164 ViewMode view_mode = LIST;
166 int focus_index = -1;
167 unsigned first_row = 0;
168 unsigned max_scroll = 0;
169 unsigned view_rows = 5;
170 unsigned view_columns = 5;
171 const Part *items_part = 0;
172 bool ignore_slider_change = false;
173 bool dragging = false;
174 int drag_start_x = 0;
175 int drag_start_y = 0;
178 std::vector<Item *> items;
179 std::vector<Row> rows;
186 virtual const char *get_class() const { return "list"; }
189 virtual void autosize_special(const Part &, Geometry &) const;
192 void set_data(ListData &);
193 ListData &get_data() { return *data; }
194 const ListData &get_data() const { return *data; }
196 void items_changed();
202 ItemFactory *f = new TypedItemFactory<I>(*data);
207 Item *create_item(unsigned);
210 void set_view_mode(ViewMode);
211 void set_view_size(unsigned);
212 void set_view_size(unsigned, unsigned);
215 void set_selected_index(int);
216 int get_selected_index() const { return sel_index; }
218 void set_selected_item(Widget *);
220 virtual void rebuild_special(const Part &);
221 virtual void render_special(const Part &, GL::Renderer &) const;
224 virtual bool key_press(unsigned, unsigned);
225 virtual void button_press(int, int, unsigned);
226 virtual void touch_press(int, int, unsigned);
227 virtual void touch_release(int, int, unsigned);
228 virtual void touch_motion(int, int, unsigned);
229 virtual void focus_in();
230 virtual bool navigate(Navigation);
232 virtual void on_style_change();
234 void move_focus(Navigation, bool);
235 void set_focus_index(int);
237 void item_autosize_changed(Item *);
238 void reposition_items(bool);
239 unsigned last_to_first_row(unsigned) const;
240 unsigned item_index_to_row(unsigned) const;
241 void check_view_range();
242 void scroll_to_focus();
243 void slider_value_changed(double);
244 static void adjust_index(int &, int, int);
247 MSPGLTK_API void operator>>(const LexicalConverter &, List::ViewMode &);