]> git.tdb.fi Git - libs/gltk.git/blob - source/panel.h
Add a Layout class to automatically position widgets within a Panel
[libs/gltk.git] / source / panel.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GLTK_PANEL_H_
9 #define MSP_GLTK_PANEL_H_
10
11 #include "container.h"
12
13 namespace Msp {
14 namespace GLtk {
15
16 class Layout;
17
18 /**
19 Panels are containers for other widgets.  Panel styles should have a special
20 part "children" to render the child widgets.  All properties of this part are
21 ignored.
22 */
23 class Panel: public Container
24 {
25 public:
26         class Loader: public Widget::Loader
27         {
28         public:
29                 typedef std::map<std::string, Widget *> WidgetMap;
30
31         private:
32                 Panel &pnl;
33                 WidgetMap &wdg_map;
34         
35         public:
36                 Loader(Panel &, WidgetMap &);
37         private:
38                 template<typename T>
39                 void child(const std::string &);
40                 void panel(const std::string &);
41         };
42
43 protected:
44         struct Child: public Container::Child
45         {
46                 Child(Panel &, Widget *);
47                 virtual ~Child();
48
49                 void visibility_changed(bool);
50                 void autosize_changed();
51                 void request_focus();
52                 void grab_pointer();
53                 void ungrab_pointer();
54                 void raise();
55         };
56
57         Layout *layout;
58         Widget *pointer_focus;
59         bool pointer_grabbed;
60         Widget *input_focus;
61
62         Panel(const Panel &);
63         Panel &operator=(const Panel &);
64 public:
65         Panel();
66         virtual ~Panel();
67
68         virtual const char *get_class() const { return "panel"; }
69
70         void set_layout(Layout *);
71
72 protected:
73         virtual Child *create_child(Widget *);
74
75 public:
76         void raise(Widget &);
77         Widget *get_input_focus() const { return input_focus; }
78         Widget *get_final_input_focus() const;
79
80 protected:
81         virtual void render_special(const Part &) const;
82
83 public:
84         virtual void button_press(int, int, unsigned);
85         virtual void button_release(int, int, unsigned);
86         virtual void pointer_motion(int, int);
87         virtual void pointer_leave();
88         virtual void key_press(unsigned, unsigned, wchar_t);
89         virtual void key_release(unsigned, unsigned);
90         virtual void focus_out();
91 protected:
92         virtual void on_child_added(Widget &);
93         virtual void on_child_removed(Widget &);
94
95         void set_pointer_focus(Widget *);
96         void set_input_focus(Widget *);
97 };
98
99 } // namespace GLtk
100 } // namespace Msp
101
102 #endif