]> git.tdb.fi Git - libs/gltk.git/blob - source/dropdown.h
2de7a87afc2126210c52cd81cec1cc96dee30394
[libs/gltk.git] / source / dropdown.h
1 #ifndef MSP_GLTK_DROPDOWN_H_
2 #define MSP_GLTK_DROPDOWN_H_
3
4 #include <sigc++/signal.h>
5 #include "list.h"
6 #include "mspgltk_api.h"
7 #include "text.h"
8 #include "widget.h"
9
10 namespace Msp {
11 namespace GLtk {
12
13 class List;
14
15 class MSPGLTK_API Dropdown: virtual public Widget, private Container
16 {
17 public:
18         class MSPGLTK_API Loader: public DataFile::DerivedObjectLoader<Dropdown, Widget::Loader>
19         {
20         public:
21                 Loader(Dropdown &);
22         private:
23                 void item(const std::string &);
24         };
25
26         sigc::signal<void, unsigned> signal_item_selected;
27
28 private:
29         List list;
30         bool dropped;
31         Text text;
32
33 public:
34         Dropdown();
35         Dropdown(ListData &);
36 private:
37         void init();
38
39 public:
40         virtual const char *get_class() const { return "dropdown"; }
41
42 private:
43         virtual void autosize_special(const Part &, Geometry &) const;
44
45 public:
46         void set_data(ListData &d) { list.set_data(d); }
47         ListData &get_data() { return list.get_data(); }
48         const ListData &get_data() const { return list.get_data(); }
49
50         template<typename T>
51         void set_item_type() { list.set_item_type<T>(); }
52
53         void set_selected_index(int i) { list.set_selected_index(i); }
54         int get_selected_index() const { return list.get_selected_index(); }
55
56 private:
57         virtual void rebuild_special(const Part &);
58         virtual void render_special(const Part &, GL::Renderer &) const;
59
60 public:
61         virtual void button_press(int, int, unsigned);
62         virtual bool navigate(Navigation);
63 private:
64         virtual void on_size_change();
65         virtual void on_style_change();
66
67         void open_list();
68         void close_list();
69         void list_autosize_changed();
70         void resize_list();
71         void list_item_selected(unsigned);
72         void list_selection_cleared();
73 };
74
75 } // namespace GLtk
76 } // namespace Msp
77
78 #endif