1 #ifndef MSP_GLTK_WIDGET_H_
2 #define MSP_GLTK_WIDGET_H_
5 #include <msp/datafile/objectloader.h>
6 #include <msp/gl/renderer.h>
20 Base class for all widgets. Derived classes should call update_style in
21 constructor, because it can't be done correctly in the Widget constructor.
25 friend class Container;
28 class Loader: public DataFile::ObjectLoader<Widget>
33 void position(int, int);
34 void size(unsigned, unsigned);
35 void style(const std::string &);
38 sigc::signal<void, bool> signal_visibility_changed;
39 sigc::signal<void> signal_autosize_changed;
40 sigc::signal<void> signal_request_focus;
41 sigc::signal<void> signal_grab_pointer;
42 sigc::signal<void> signal_ungrab_pointer;
46 std::string style_name;
53 std::list<CachedPart> cached_parts;
59 /// Returns the name of the widget class. Used for style lookup.
60 virtual const char *get_class() const { return "widget"; }
62 void set_position(int, int);
63 void set_size(unsigned, unsigned);
64 virtual void autosize();
65 void set_geometry(const Geometry &);
66 const Geometry &get_geometry() const { return geom; }
69 /** Sets the widget's parent Container. The widget must be unparented when
70 calling this function with a non-null parameter. */
71 void set_parent(Container *);
73 Container *get_parent() const { return parent; }
75 /** Sets the widget style. The name of the resource to be looked up is
76 constructed by concatenating the widget class and the style name with a
78 void set_style(const std::string &);
79 const Style &get_style() const { return *style; }
82 /** Gets a style object from the resource collection based on the class and
83 style names of the widget. */
87 void set_tooltip(const std::string &);
88 const std::string &get_tooltip() const { return tooltip; }
90 void set_visible(bool);
91 bool is_visible() const { return visible; }
92 void set_focusable(bool);
93 bool is_focusable() const { return focusable; }
97 void set_state(State s) { set_state(s, s); }
98 void clear_state(State s) { set_state(s, NORMAL); }
99 void set_state(State, State);
102 virtual void rebuild_special(const Part &, CachedPart &) { }
105 void render(GL::Renderer &) const;
107 virtual void render_special(const Part &, GL::Renderer &) const { }
111 virtual void button_press(int, int, unsigned) { }
112 virtual void button_release(int, int, unsigned) { }
113 virtual void pointer_motion(int, int) { }
114 virtual void pointer_enter();
115 virtual void pointer_leave();
116 virtual void key_press(unsigned, unsigned) { }
117 virtual void key_release(unsigned, unsigned) { }
118 virtual void character(wchar_t) { }
119 virtual void focus_in();
120 virtual void focus_out();
122 virtual void on_geometry_change() { }
123 virtual void on_style_change() { }
124 virtual void on_reparent() { }