]> git.tdb.fi Git - libs/gltk.git/blob - source/widget.h
Enable loading of widgets from datafiles (not implemented for all widgets yet)
[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         private:
26                 void position(int, int);
27                 void size(unsigned, unsigned);
28                 void style(const std::string &);
29         };
30
31         virtual ~Widget() { }
32         void set_position(int, int);
33         void set_size(unsigned, unsigned);
34         void set_geometry(const Geometry &);
35         void set_style(const std::string &);
36         const Geometry &get_geometry() const { return geom; }
37         void render() const;
38         virtual void button_press(int, int, unsigned) { }
39         virtual void button_release(int, int, unsigned) { }
40         virtual void pointer_motion(int, int) { }
41         virtual void pointer_enter() { }
42         virtual void pointer_leave() { }
43         virtual void key_press(unsigned, unsigned, wchar_t) { }
44         virtual void key_release(unsigned, unsigned) { }
45         virtual void focus_in() { }
46         virtual void focus_out() { }
47 protected:
48         const Resources &res;
49         Geometry geom;
50         std::string style_name;
51         const Style *style;
52         State state;
53
54         Widget(const Resources &);
55         virtual const char *get_class() const { return "widget"; }
56         void update_style();
57         virtual void render_part(const Part &) const;
58         void render_graphic(const Part &) const;
59         void render_text(const Part &, const std::string &) const;
60 };
61
62 } // namespace GLtk
63 } // namespace Msp
64
65 #endif