+ /// This exists to make disconnecting signals easier
+ class DataObserver: public sigc::trackable
+ {
+ private:
+ List &list;
+
+ public:
+ DataObserver(List &);
+
+ void item_added(unsigned);
+ void item_removed(unsigned);
+ void cleared();
+ void refresh_item(unsigned);
+ };
+
+public:
+ class Item: public Container
+ {
+ public:
+ virtual const char *get_class() const { return "listitem"; }
+
+ protected:
+ virtual void autosize_special(const Part &, Geometry &) const;
+ public:
+ void set_active(bool);
+
+ virtual void render_special(const Part &, GL::Renderer &) const;
+ };
+
+ class MultiColumnItem: public Item
+ {
+ protected:
+ virtual void check_widths(std::vector<unsigned> &) const;
+ virtual void set_widths(const std::vector<unsigned> &);
+
+ private:
+ virtual void on_style_change();
+ };
+
+private:
+ class BasicItem: public Item
+ {
+ private:
+ Label label;
+
+ public:
+ BasicItem(const std::string &);
+
+ private:
+ virtual void on_style_change();
+ };
+
+ class ItemFactory
+ {
+ protected:
+ ItemFactory() { }
+ public:
+ virtual ~ItemFactory() { }
+
+ virtual void set_data(const ListData &) = 0;
+ virtual Item *create_item(unsigned) const = 0;
+ };
+
+ template<typename I>
+ class TypedItemFactory: public ItemFactory
+ {
+ private:
+ typedef typename I::ValueType ValueType;
+
+ const ListDataStore<ValueType> *data;
+
+ public:
+ TypedItemFactory(const ListData &d)
+ { set_data(d); }
+
+ virtual void set_data(const ListData &d)
+ {
+ if(const ListDataStore<ValueType> *ds = dynamic_cast<const ListDataStore<ValueType> *>(&d))
+ data = ds;
+ else
+ throw incompatible_data(typeid(ValueType));
+ }
+
+ virtual Item *create_item(unsigned i) const
+ {
+ return new I(data->get(i));
+ }
+ };
+
+public:
+ sigc::signal<void, unsigned> signal_item_selected;
+ sigc::signal<void> signal_selection_cleared;
+
+private:
+ ListData *data;
+ bool own_data;
+ DataObserver *observer;
+ ItemFactory *item_factory;