2 #include <msp/core/refptr.h>
25 pointer_grabbed(false),
35 void Panel::set_layout(Layout *l)
37 l->set_container(*this);
42 void Panel::autosize()
48 Panel::Child *Panel::create_child(Widget *wdg)
50 return new Child(*this, wdg);
53 void Panel::raise(Widget &wdg)
55 for(list<Container::Child *>::iterator i=children.begin(); i!=children.end(); ++i)
56 if((*i)->widget==&wdg)
58 children.splice(children.end(), children, i);
62 throw hierarchy_error("widget not in panel");
65 Widget *Panel::get_final_input_focus() const
67 if(Panel *panel = dynamic_cast<Panel *>(input_focus))
69 Widget *focus = panel->get_final_input_focus();
76 void Panel::render_special(const Part &part, GL::Renderer &renderer) const
78 if(part.get_name()=="children")
80 for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
81 if((*i)->widget->is_visible())
82 (*i)->widget->render(renderer);
86 void Panel::button_press(int x, int y, unsigned btn)
90 const Geometry &cgeom = pointer_focus->get_geometry();
91 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
95 if(Widget *wdg = get_child_at(x, y))
97 set_pointer_focus(wdg);
98 if(wdg->is_focusable())
101 Container::button_press(x, y, btn);
105 void Panel::button_release(int x, int y, unsigned btn)
109 const Geometry &cgeom = pointer_focus->get_geometry();
110 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
113 Container::button_release(x, y, btn);
116 void Panel::pointer_motion(int x, int y)
120 const Geometry &cgeom = pointer_focus->get_geometry();
121 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
125 set_pointer_focus(get_child_at(x, y));
126 Container::pointer_motion(x, y);
130 void Panel::pointer_leave()
132 Container::pointer_leave();
133 set_pointer_focus(0);
136 void Panel::key_press(unsigned key, unsigned mod)
139 input_focus->key_press(key, mod);
142 void Panel::key_release(unsigned key, unsigned mod)
145 input_focus->key_release(key, mod);
148 void Panel::character(wchar_t ch)
151 input_focus->character(ch);
154 void Panel::focus_out()
160 void Panel::on_geometry_change()
166 void Panel::on_child_added(Widget &wdg)
170 layout->add_widget(wdg);
171 signal_autosize_changed.emit();
175 void Panel::on_child_removed(Widget &wdg)
179 layout->remove_widget(wdg);
180 signal_autosize_changed.emit();
184 void Panel::set_pointer_focus(Widget *wdg)
186 if(wdg!=pointer_focus)
189 pointer_focus->pointer_leave();
194 pointer_focus->pointer_enter();
198 void Panel::set_input_focus(Widget *wdg)
203 input_focus->focus_out();
210 input_focus->focus_in();
216 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
221 add("button", &Loader::child<Button>);
222 add("dropdown", &Loader::child<Dropdown>);
223 add("entry", &Loader::child<Entry>);
224 add("hslider", &Loader::child<HSlider>);
225 add("indicator", &Loader::child<Indicator>);
226 add("label", &Loader::child<Label>);
227 add("list", &Loader::child<List>);
228 add("panel", &Loader::panel);
229 add("table", &Loader::child<Table>);
230 add("toggle", &Loader::child<Toggle>);
231 add("vslider", &Loader::child<VSlider>);
235 void Panel::Loader::child(const string &n)
237 RefPtr<T> chl = new T();
240 wdg_map[n] = chl.release();
243 void Panel::Loader::panel(const string &n)
245 RefPtr<Panel> p = new Panel();
246 load_sub(*p, wdg_map);
248 wdg_map[n] = p.release();
252 Panel::Child::Child(Panel &p, Widget *w):
253 Container::Child(p, w)
255 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
256 widget->signal_request_focus.connect(sigc::mem_fun(this, &Child::request_focus));
257 widget->signal_grab_pointer.connect(sigc::mem_fun(this, &Child::grab_pointer));
258 widget->signal_ungrab_pointer.connect(sigc::mem_fun(this, &Child::ungrab_pointer));
261 Panel::Child::~Child()
263 visibility_changed(false);
266 void Panel::Child::visibility_changed(bool v)
270 Panel &panel = static_cast<Panel &>(container);
271 if(widget==panel.pointer_focus)
272 panel.set_pointer_focus(0);
273 if(widget==panel.input_focus)
274 panel.set_input_focus(0);
278 void Panel::Child::autosize_changed()
280 Panel &panel = static_cast<Panel &>(container);
282 panel.layout->update();
285 void Panel::Child::request_focus()
287 Panel &panel = static_cast<Panel &>(container);
288 panel.set_input_focus(widget);
289 if(panel.parent && panel.visible)
293 void Panel::Child::grab_pointer()
295 Panel &panel = static_cast<Panel &>(container);
296 if(!panel.pointer_grabbed)
298 panel.set_pointer_focus(widget);
299 panel.pointer_grabbed = true;
300 panel.signal_grab_pointer.emit();
304 void Panel::Child::ungrab_pointer()
306 Panel &panel = static_cast<Panel &>(container);
307 if(panel.pointer_grabbed && panel.pointer_focus==widget)
309 // XXX Should set to the widget under pointer
310 panel.set_pointer_focus(0);
311 panel.pointer_grabbed = false;
312 panel.signal_ungrab_pointer.emit();