]> git.tdb.fi Git - libs/gltk.git/blob - source/panel.h
Adjust things to conform to changes in other libraries
[libs/gltk.git] / source / panel.h
1 #ifndef MSP_GLTK_PANEL_H_
2 #define MSP_GLTK_PANEL_H_
3
4 #include <msp/core/typeregistry.h>
5 #include "container.h"
6 #include "layout.h"
7
8 namespace Msp {
9 namespace GLtk {
10
11 /**
12 Panels are containers for other widgets.  Panel styles should have a special
13 part "children" to render the child widgets.  All properties of this part are
14 ignored.
15 */
16 class Panel: public Container
17 {
18 public:
19         class Loader: public DataFile::DerivedObjectLoader<Panel, Widget::Loader>
20         {
21         public:
22                 typedef std::map<std::string, Widget *> WidgetMap;
23
24         protected:
25                 template<typename T>
26                 struct AddChildType
27                 {
28                         void operator()(const std::string &, Loader &) const;
29                 };
30
31                 WidgetMap &wdg_map;
32                 Widget *last_widget;
33
34         public:
35                 Loader(Panel &, WidgetMap &);
36
37         private:
38                 Layout &get_layout();
39                 Widget &get_last_widget();
40                 template<typename T>
41                 void arrangement();
42                 template<typename T>
43                 void child(const std::string &);
44                 void constraint(Layout::ConstraintType, const std::string &);
45                 void expand(bool, bool);
46                 void ghost(bool);
47                 void gravity(int, int);
48                 void grid(unsigned);
49                 void layout();
50                 template<typename T>
51                 void unnamed_child();
52
53                 friend class Panel;
54         };
55
56 private:
57         template<typename T>
58         class ArrangedLoader: public DataFile::Loader
59         {
60         private:
61                 typename T::Loader arr_loader;
62
63         public:
64                 ArrangedLoader(Loader &, T &);
65         };
66
67 protected:
68         std::vector<Widget *> nav_order;
69         Layout *layout;
70
71         static TypeRegistry<Loader::AddChildType, Loader &> widget_registry;
72         static bool widget_registry_init_done;
73
74         Panel(const Panel &);
75         Panel &operator=(const Panel &);
76 public:
77         Panel();
78         virtual ~Panel();
79
80         template<typename T>
81         static void register_child_type(const std::string &);
82
83         virtual const char *get_class() const { return "panel"; }
84
85         void set_layout(Layout *);
86         Layout *get_layout() { return layout; }
87
88 protected:
89         virtual void autosize_special(const Part &, Geometry &) const;
90         virtual void render_special(const Part &, GL::Renderer &) const;
91
92 public:
93         virtual bool navigate(Navigation);
94 protected:
95         Widget *find_next_child(int, int, int, int, int) const;
96         static int compute_delta(int, int, int, int, int);
97
98         virtual void on_size_change();
99         virtual void on_child_added(Widget &);
100         virtual void on_child_removed(Widget &);
101 };
102
103
104 template<typename T>
105 void Panel::register_child_type(const std::string &name)
106 {
107         widget_registry.register_type<T>(name);
108 }
109
110
111 template<typename T>
112 void Panel::Loader::child(const std::string &n)
113 {
114         unnamed_child<T>();
115         wdg_map[n] = last_widget;
116 }
117
118 template<typename T>
119 void Panel::Loader::unnamed_child()
120 {
121         RefPtr<T> chl = new T();
122         load_sub(*chl);
123         obj.add(*chl.get());
124         last_widget = chl.release();
125 }
126
127
128 template<typename T>
129 void Panel::Loader::AddChildType<T>::operator()(const std::string &kwd, Loader &ldr) const
130 {
131         ldr.add(kwd, &Loader::child<T>);
132         ldr.add(kwd, &Loader::unnamed_child<T>);
133 }
134
135 } // namespace GLtk
136 } // namespace Msp
137
138 #endif