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.
24 friend class Container;
27 class Loader: public DataFile::ObjectLoader<Widget>
32 void position(int, int);
33 void size(unsigned, unsigned);
34 void style(const std::string &);
37 sigc::signal<void, bool> signal_visibility_changed;
38 sigc::signal<void> signal_autosize_changed;
39 sigc::signal<void> signal_request_focus;
40 sigc::signal<void> signal_grab_pointer;
41 sigc::signal<void> signal_ungrab_pointer;
45 std::string style_name;
56 Widget(const Widget &);
57 Widget &operator=(const Widget &);
61 /// Returns the name of the widget class. Used for style lookup.
62 virtual const char *get_class() const { return "widget"; }
64 void set_position(int, int);
65 void set_size(unsigned, unsigned);
67 void autosize(Geometry &) const;
69 virtual void autosize_special(const Part &, Geometry &) const { };
71 void set_geometry(const Geometry &);
72 const Geometry &get_geometry() const { return geom; }
74 void map_coords_to_ancestor(int &, int &, const Widget &) const;
77 /** Sets the widget's parent Container. The widget must be unparented when
78 calling this function with a non-null parameter. */
79 void set_parent(Container *);
81 Container *get_parent() const { return parent; }
83 /** Finds the closest ancestor of a specific type. */
85 T *find_ancestor() const
87 for(Widget *w=parent; w; w=w->get_parent())
88 if(T *tw = dynamic_cast<T *>(w))
93 /** Sets the widget style. The name of the resource to be looked up is
94 constructed by concatenating the widget class and the style name with a
96 void set_style(const std::string &);
97 const Style &get_style() const { return *style; }
100 /** Gets a style object from the resource collection based on the class and
101 style names of the widget. */
105 void set_tooltip(const std::string &);
106 const std::string &get_tooltip() const { return tooltip; }
108 void set_visible(bool);
109 bool is_visible() const { return visible; }
110 void set_focusable(bool);
111 bool is_focusable() const { return focusable; }
113 void set_enabled(bool);
114 bool is_enabled() const { return !(state&DISABLED); }
117 void set_state(State s) { set_state(s, s); }
118 void clear_state(State s) { set_state(s, NORMAL); }
119 void set_state(State, State);
121 State get_state() const { return state; }
125 virtual void rebuild_special(const Part &);
128 void render(GL::Renderer &) const;
130 virtual void render_special(const Part &, GL::Renderer &) const { }
134 virtual void button_press(int, int, unsigned) { }
135 virtual void button_release(int, int, unsigned) { }
136 virtual void pointer_motion(int, int) { }
137 virtual void pointer_enter();
138 virtual void pointer_leave();
139 virtual void key_press(unsigned, unsigned) { }
140 virtual void key_release(unsigned, unsigned) { }
141 virtual void character(wchar_t) { }
142 virtual void focus_in();
143 virtual void focus_out();
145 virtual void on_geometry_change() { }
146 virtual void on_style_change() { }
147 virtual void on_reparent() { }