]> git.tdb.fi Git - libs/gltk.git/blob - source/list.h
Combine common parts of Column and Row into LinearArrangement
[libs/gltk.git] / source / list.h
1 #ifndef MSP_GLTK_LIST_H_
2 #define MSP_GLTK_LIST_H_
3
4 #include <sigc++/signal.h>
5 #include "container.h"
6 #include "label.h"
7 #include "listdata.h"
8 #include "vslider.h"
9
10 namespace Msp {
11 namespace GLtk {
12
13 /**
14 Shows a list of items, allowing the user to select one.  A slider is included
15 to allow scrolling through a long list.
16 */
17 class List: virtual public Widget, private Container
18 {
19 public:
20         class Loader: public DataFile::DerivedObjectLoader<List, Widget::Loader>
21         {
22         public:
23                 Loader(List &);
24         private:
25                 void item(const std::string &);
26         };
27
28 private:
29         /// This exists to make disconnecting signals easier
30         class DataObserver: public sigc::trackable
31         {
32         private:
33                 List &list;
34
35         public:
36                 DataObserver(List &);
37
38                 void item_added(unsigned);
39                 void item_removed(unsigned);
40                 void cleared();
41                 void refresh_strings();
42         };
43
44 protected:
45         class Item: public Container
46         {
47         public:
48                 virtual const char *get_class() const { return "listitem"; }
49
50                 virtual void autosize();
51                 void set_active(bool);
52
53                 virtual void render_special(const Part &, GL::Renderer &) const;
54         };
55
56 public:
57         class BasicItem: public Item
58         {
59         private:
60                 Label label;
61
62         public:
63                 BasicItem(const std::string &);
64
65         private:
66                 virtual void on_style_change();
67         };
68
69 public:
70         sigc::signal<void, unsigned> signal_item_selected;
71
72 private:
73         ListData *data;
74         bool own_data;
75         DataObserver *observer;
76         int sel_index;
77         unsigned first;
78         unsigned max_scroll;
79
80         VSlider slider;
81         std::vector<Item *> items;
82
83 public:
84         List();
85         List(ListData &);
86 private:
87         void init();
88 public:
89         virtual ~List();
90
91         virtual const char *get_class() const { return "list"; }
92
93         virtual void autosize();
94         void autosize_rows(unsigned);
95         void autosize_all();
96
97         void set_data(ListData &);
98         ListData &get_data() { return *data; }
99         const ListData &get_data() const { return *data; }
100 private:
101         void items_changed();
102 protected:
103         virtual Item *create_item(unsigned);
104 public:
105
106         void set_selected_index(int);
107         int get_selected_index() const { return sel_index; }
108
109 private:
110         virtual void render_special(const Part &, GL::Renderer &) const;
111
112 public:
113         virtual void button_press(int, int, unsigned);
114 private:
115         virtual void on_geometry_change();
116         virtual void on_style_change();
117
118         void reposition_slider();
119         void reposition_items();
120         void check_view_range();
121         void slider_value_changed(double);
122 };
123
124 } // namespace GLtk
125 } // namespace Msp
126
127 #endif