]> git.tdb.fi Git - libs/gltk.git/blob - source/widget.h
Remove unused code
[libs/gltk.git] / source / widget.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007-2009  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 Container;
19 class Part;
20 class Resources;
21 class Style;
22
23 /**
24 Base class for all widgets.  Derived classes should call update_style in 
25 constructor, because it can't be done correctly in the Widget constructor.
26 */
27 class Widget
28 {
29 public:
30         class Loader: public Msp::DataFile::Loader
31         {
32         protected:
33                 Widget &wdg;
34
35         public:
36                 Loader(Widget &);
37                 Widget &get_object() const { return wdg; }
38         private:
39                 void position(int, int);
40                 void size(unsigned, unsigned);
41                 void style(const std::string &);
42         };
43
44         sigc::signal<void, bool> signal_visibility_changed;
45         sigc::signal<void> signal_request_focus;
46         sigc::signal<void> signal_grab_pointer;
47         sigc::signal<void> signal_ungrab_pointer;
48
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         Container *parent;
57         std::string tooltip;
58
59         Widget(const Resources &);
60 public:
61         virtual ~Widget();
62
63         void set_position(int, int);
64         void set_size(unsigned, unsigned);
65         virtual void autosize() { }
66         void set_geometry(const Geometry &);
67         const Geometry &get_geometry() const { return geom; }
68
69         /**
70         Sets the widget style.  The final style name is constructed by concatenating
71         the widget class and the style name with a dash.
72         */
73         void set_style(const std::string &);
74         const Style &get_style() const { return *style; }
75
76         void set_tooltip(const std::string &);
77         const std::string &get_tooltip() const { return tooltip; }
78
79         void set_visible(bool);
80         bool is_visible() const { return visible; }
81         void set_focus();
82
83         void render() const;
84 protected:
85         virtual void render_special(const Part &) const { }
86
87 public:
88         // Events
89         virtual void button_press(int, int, unsigned) { }
90         virtual void button_release(int, int, unsigned) { }
91         virtual void pointer_motion(int, int) { }
92         virtual void pointer_enter();
93         virtual void pointer_leave();
94         virtual void key_press(unsigned, unsigned, wchar_t) { }
95         virtual void key_release(unsigned, unsigned) { }
96         virtual void focus_in();
97         virtual void focus_out();
98
99 protected:
100         /**
101         Returns the name of the widget class.  Used for style lookup.
102         */
103         virtual const char *get_class() const { return "widget"; }
104
105         /**
106         Gets a style object from the resource collection based on the class and
107         style names of the widget.
108         */
109         void update_style();
110
111         /**
112         Sets the widget's parent Panel.  The widget must be unparented when calling
113         this function with a nonzero parameter.
114         */
115         void set_parent(Container *);
116
117         /**
118         A helper function to set the parent of another widget.
119         */
120         void set_parent(Widget &, Container *);
121
122         // More events
123         virtual void on_geometry_change() { }
124         virtual void on_style_change() { }
125         virtual void on_reparent() { }
126 };
127
128 } // namespace GLtk
129 } // namespace Msp
130
131 #endif