3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_GLTK_WIDGET_H_
9 #define MSP_GLTK_WIDGET_H_
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.
30 class Loader: public Msp::DataFile::Loader
37 Widget &get_object() const { return wdg; }
39 void position(int, int);
40 void size(unsigned, unsigned);
41 void style(const std::string &);
47 std::string style_name;
53 Widget(const Resources &);
56 void set_position(int, int);
57 void set_size(unsigned, unsigned);
58 void set_geometry(const Geometry &);
61 Sets the widget style. The final style name is constructed by concatenating
62 the widget class and the style name with a dash.
64 void set_style(const std::string &);
66 void set_visible(bool);
69 const Geometry &get_geometry() const { return geom; }
70 bool is_visible() const { return visible; }
74 void render_graphic(const Part &) const;
75 void render_text(const Part &, const std::string &) const;
76 virtual void render_special(const Part &) const { }
80 virtual void button_press(int, int, unsigned) { }
81 virtual void button_release(int, int, unsigned) { }
82 virtual void pointer_motion(int, int) { }
83 virtual void pointer_enter();
84 virtual void pointer_leave();
85 virtual void key_press(unsigned, unsigned, wchar_t) { }
86 virtual void key_release(unsigned, unsigned) { }
87 virtual void focus_in();
88 virtual void focus_out();
92 Returns the name of the widget class. Used for style lookup.
94 virtual const char *get_class() const { return "widget"; }
97 Gets a style object from the resource collection based on the class and
98 style names of the widget.
103 Sets the widget's parent Panel. The widget must be unparented when calling
104 this function with a nonzero parameter.
106 void set_parent(Panel *);
109 A helper function to set the parent of another widget.
111 void set_parent(Widget &, Panel *);
114 virtual void on_geometry_change() { }
115 virtual void on_style_change() { }
116 virtual void on_reparent() { }