+ class ItemFactory
+ {
+ protected:
+ ItemFactory() = default;
+ public:
+ virtual ~ItemFactory() = default;
+
+ virtual void set_data(const ListData &) = 0;
+ virtual Item *create_item(std::size_t) 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); }
+
+ void set_data(const ListData &d) override
+ {
+ if(const ListDataStore<ValueType> *ds = dynamic_cast<const ListDataStore<ValueType> *>(&d))
+ data = ds;
+ else
+ throw incompatible_data(typeid(ValueType));
+ }
+
+ Item *create_item(std::size_t i) const override
+ {
+ return new I(data->get(i));
+ }
+ };
+
+ struct Row
+ {
+ std::size_t first;
+ unsigned height;
+
+ Row(std::size_t f): first(f), height(0) { }
+ };
+
+public:
+ sigc::signal<void, std::size_t> signal_item_selected;
+ sigc::signal<void> signal_selection_cleared;
+
+private:
+ ListData *data = nullptr;
+ bool own_data = false;
+ DataObserver *observer = nullptr;
+ ItemFactory *item_factory = nullptr;
+ ViewMode view_mode = LIST;
+ std::size_t sel_index = INVALID_INDEX;
+ std::size_t focus_index = INVALID_INDEX;
+ std::size_t first_row = 0;
+ std::size_t max_scroll = 0;
+ unsigned view_rows = 5;
+ unsigned view_columns = 5;
+ const Part *items_part = nullptr;
+ bool ignore_slider_change = false;
+ bool dragging = false;
+ int drag_start_x = 0;
+ int drag_start_y = 0;
+
+ VSlider slider;
+ std::vector<Item *> items;
+ std::vector<Row> rows;
+
+public:
+ List();
+ List(ListData &);
+ virtual ~List();
+
+ const char *get_class() const override { return "list"; }
+
+private:
+ void autosize_special(const Part &, Geometry &) const override;
+
+public:
+ void set_data(ListData &);
+ ListData &get_data() { return *data; }
+ const ListData &get_data() const { return *data; }
+private:
+ void items_changed();
+
+public:
+ template<typename I>
+ void set_item_type()
+ {
+ ItemFactory *f = new TypedItemFactory<I>(*data);
+ delete item_factory;
+ item_factory = f;
+ }
+private:
+ Item *create_item(std::size_t);
+
+public:
+ void set_view_mode(ViewMode);
+ void set_view_size(unsigned);
+ void set_view_size(unsigned, unsigned);
+ void set_view_all();
+
+ void set_selected_index(std::size_t);