1 #ifndef MSP_GLTK_WIDGET_H_
2 #define MSP_GLTK_WIDGET_H_
5 #include <msp/datafile/objectloader.h>
6 #include <msp/gl/renderer.h>
8 #include "inputmethod.h"
21 Base class for all widgets.
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;
43 sigc::signal<void, const Time::TimeDelta &> signal_request_animation;
44 sigc::signal<void> signal_rebuild_needed;
48 std::string style_name;
57 Time::TimeDelta anim_interval;
61 Widget(const Widget &);
62 Widget &operator=(const Widget &);
66 /// Returns the name of the widget class. Used for style lookup.
67 virtual const char *get_class() const { return "widget"; }
69 void set_position(int, int);
70 void set_size(unsigned, unsigned);
72 void autosize(Geometry &) const;
74 virtual void autosize_special(const Part &, Geometry &) const { };
76 void set_geometry(const Geometry &);
77 const Geometry &get_geometry() const { return geom; }
79 void map_coords_to_ancestor(int &, int &, const Widget &) const;
82 /** Sets the widget's parent Container. The widget must be unparented when
83 calling this function with a non-null parameter. */
84 void set_parent(Container *);
86 Container *get_parent() const { return parent; }
88 /** Finds the closest ancestor of a specific type. */
90 T *find_ancestor() const
92 for(Widget *w=parent; w; w=w->get_parent())
93 if(T *tw = dynamic_cast<T *>(w))
98 /** Sets the widget style. The name of the resource to be looked up is
99 constructed by concatenating the widget class and the style name with a
101 void set_style(const std::string &);
102 const Style &get_style() const { return *style; }
105 /** Gets a style object from the resource collection based on the class and
106 style names of the widget. */
110 void set_tooltip(const std::string &);
111 const std::string &get_tooltip() const { return tooltip; }
113 void set_visible(bool);
114 bool is_visible() const { return visible; }
115 InputType get_input_type() const { return input_type; }
116 bool is_focusable() const { return visible && input_type!=INPUT_NONE; }
118 void set_enabled(bool);
119 bool is_enabled() const { return !(state&DISABLED); }
122 void set_focusable(bool);
125 void set_state(State s) { set_state(s, s); }
126 void clear_state(State s) { set_state(s, NORMAL); }
127 void set_state(State, State);
129 State get_state() const { return state; }
132 void set_animation_interval(const Time::TimeDelta &);
133 void stop_animation();
135 const Time::TimeDelta &get_animation_interval() const { return anim_interval; }
139 virtual void rebuild_hierarchy();
141 virtual void rebuild_special(const Part &);
144 void render(GL::Renderer &) const;
146 virtual void render_special(const Part &, GL::Renderer &) const { }
150 virtual void button_press(int, int, unsigned) { }
151 virtual void button_release(int, int, unsigned) { }
152 virtual void pointer_motion(int, int) { }
153 virtual void pointer_enter();
154 virtual void pointer_leave();
155 virtual void touch_press(int, int, unsigned);
156 virtual void touch_release(int, int, unsigned);
157 virtual void touch_motion(int, int, unsigned);
158 virtual bool key_press(unsigned, unsigned) { return false; }
159 virtual bool key_release(unsigned, unsigned) { return false; }
160 virtual bool character(wchar_t) { return false; }
161 virtual void focus_in();
162 virtual void focus_out();
163 virtual bool navigate(Navigation) { return false; }
164 virtual void animate(const Time::TimeDelta &) { }
166 virtual void on_size_change() { on_geometry_change(); }
167 virtual void on_style_change() { }
168 virtual void on_reparent() { }
171 virtual void on_geometry_change() { }