]> git.tdb.fi Git - libs/gltk.git/blob - source/widget.h
557df434adcd34f98d858324ab753e8271b9a1a5
[libs/gltk.git] / source / widget.h
1 #ifndef MSP_GLTK_WIDGET_H_
2 #define MSP_GLTK_WIDGET_H_
3
4 #include <string>
5 #include "geometry.h"
6 #include "state.h"
7
8 namespace Msp {
9 namespace GLtk {
10
11 class Part;
12 class Resources;
13 class Style;
14
15 class Widget
16 {
17 public:
18         class Loader: public Msp::DataFile::Loader
19         {
20         protected:
21                 Widget &wdg;
22
23         public:
24                 Loader(Widget &);
25                 Widget &get_object() const { return wdg; }
26         private:
27                 void position(int, int);
28                 void size(unsigned, unsigned);
29                 void style(const std::string &);
30         };
31
32         virtual ~Widget() { }
33         void set_position(int, int);
34         void set_size(unsigned, unsigned);
35         void set_geometry(const Geometry &);
36         void set_style(const std::string &);
37         const Geometry &get_geometry() const { return geom; }
38         bool is_visible() const { return visible; }
39         void render() const;
40         virtual void button_press(int, int, unsigned) { }
41         virtual void button_release(int, int, unsigned) { }
42         virtual void pointer_motion(int, int) { }
43         virtual void pointer_enter() { }
44         virtual void pointer_leave() { }
45         virtual void key_press(unsigned, unsigned, wchar_t) { }
46         virtual void key_release(unsigned, unsigned) { }
47         virtual void focus_in() { }
48         virtual void focus_out() { }
49 protected:
50         const Resources &res;
51         Geometry geom;
52         std::string style_name;
53         const Style *style;
54         State state;
55         bool visible;
56
57         Widget(const Resources &);
58         virtual const char *get_class() const { return "widget"; }
59         void update_style();
60         virtual void render_part(const Part &) const;
61         void render_graphic(const Part &) const;
62         void render_text(const Part &, const std::string &) const;
63 };
64
65 } // namespace GLtk
66 } // namespace Msp
67
68 #endif