]> git.tdb.fi Git - libs/gltk.git/blob - source/widget.h
Reorder class members
[libs/gltk.git] / source / widget.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GLTK_WIDGET_H_
9 #define MSP_GLTK_WIDGET_H_
10
11 #include <string>
12 #include "geometry.h"
13 #include "state.h"
14
15 namespace Msp {
16 namespace GLtk {
17
18 class Part;
19 class Resources;
20 class Style;
21
22 /**
23 Base class for all widgets.  Derived classes should call update_style in 
24 constructor, because it can't be done correctly in the Widget constructor.
25 */
26 class Widget
27 {
28 public:
29         class Loader: public Msp::DataFile::Loader
30         {
31         protected:
32                 Widget &wdg;
33
34         public:
35                 Loader(Widget &);
36                 Widget &get_object() const { return wdg; }
37         private:
38                 void position(int, int);
39                 void size(unsigned, unsigned);
40                 void style(const std::string &);
41         };
42
43 protected:
44         const Resources &res;
45         Geometry geom;
46         std::string style_name;
47         const Style *style;
48         State state;
49         bool visible;
50
51         Widget(const Resources &);
52 public:
53         virtual ~Widget() { }
54         void set_position(int, int);
55         void set_size(unsigned, unsigned);
56         void set_geometry(const Geometry &);
57
58         /**
59         Sets the widget style.  The final style name is constructed by concatenating
60         the widget class and the style name with a dash.
61         */
62         void set_style(const std::string &);
63
64         const Geometry &get_geometry() const { return geom; }
65         bool is_visible() const { return visible; }
66
67         void render() const;
68 protected:
69         virtual void render_part(const Part &) const;
70         void render_graphic(const Part &) const;
71         void render_text(const Part &, const std::string &) const;
72
73 public:
74         // Events
75         virtual void button_press(int, int, unsigned) { }
76         virtual void button_release(int, int, unsigned) { }
77         virtual void pointer_motion(int, int) { }
78         virtual void pointer_enter() { }
79         virtual void pointer_leave() { }
80         virtual void key_press(unsigned, unsigned, wchar_t) { }
81         virtual void key_release(unsigned, unsigned) { }
82         virtual void focus_in() { }
83         virtual void focus_out() { }
84
85 protected:
86         /**
87         Returns the name of the widget class.  Used for style lookup.
88         */
89         virtual const char *get_class() const { return "widget"; }
90
91         void update_style();
92 };
93
94 } // namespace GLtk
95 } // namespace Msp
96
97 #endif