2 #include <msp/core/refptr.h>
25 pointer_grabbed(false),
35 void Panel::set_layout(Layout *l)
37 l->set_container(*this);
42 Panel::Child *Panel::create_child(Widget *wdg)
44 return new Child(*this, wdg);
47 void Panel::raise(Widget &wdg)
49 for(list<Container::Child *>::iterator i=children.begin(); i!=children.end(); ++i)
50 if((*i)->widget==&wdg)
52 children.splice(children.end(), children, i);
56 throw hierarchy_error("widget not in panel");
59 Widget *Panel::get_final_input_focus() const
61 if(Panel *panel = dynamic_cast<Panel *>(input_focus))
63 Widget *focus = panel->get_final_input_focus();
70 void Panel::render_special(const Part &part) const
72 if(part.get_name()=="children")
74 for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
75 if((*i)->widget->is_visible())
76 (*i)->widget->render();
80 void Panel::button_press(int x, int y, unsigned btn)
84 const Geometry &cgeom = pointer_focus->get_geometry();
85 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
89 if(Widget *wdg = get_child_at(x, y))
91 set_pointer_focus(wdg);
92 if(wdg->is_focusable())
95 Container::button_press(x, y, btn);
99 void Panel::button_release(int x, int y, unsigned btn)
103 const Geometry &cgeom = pointer_focus->get_geometry();
104 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
107 Container::button_release(x, y, btn);
110 void Panel::pointer_motion(int x, int y)
114 const Geometry &cgeom = pointer_focus->get_geometry();
115 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
119 set_pointer_focus(get_child_at(x, y));
120 Container::pointer_motion(x, y);
124 void Panel::pointer_leave()
126 Container::pointer_leave();
127 set_pointer_focus(0);
130 void Panel::key_press(unsigned key, unsigned mod)
133 input_focus->key_press(key, mod);
136 void Panel::key_release(unsigned key, unsigned mod)
139 input_focus->key_release(key, mod);
142 void Panel::character(wchar_t ch)
145 input_focus->character(ch);
148 void Panel::focus_out()
154 void Panel::on_child_added(Widget &wdg)
157 layout->add_widget(wdg);
160 void Panel::on_child_removed(Widget &wdg)
163 layout->remove_widget(wdg);
166 void Panel::set_pointer_focus(Widget *wdg)
168 if(wdg!=pointer_focus)
171 pointer_focus->pointer_leave();
176 pointer_focus->pointer_enter();
180 void Panel::set_input_focus(Widget *wdg)
185 input_focus->focus_out();
192 input_focus->focus_in();
198 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
203 add("button", &Loader::child<Button>);
204 add("dropdown", &Loader::child<Dropdown>);
205 add("entry", &Loader::child<Entry>);
206 add("hslider", &Loader::child<HSlider>);
207 add("indicator", &Loader::child<Indicator>);
208 add("label", &Loader::child<Label>);
209 add("list", &Loader::child<List>);
210 add("panel", &Loader::panel);
211 add("table", &Loader::child<Table>);
212 add("toggle", &Loader::child<Toggle>);
213 add("vslider", &Loader::child<VSlider>);
217 void Panel::Loader::child(const string &n)
219 RefPtr<T> chl = new T();
222 wdg_map[n] = chl.release();
225 void Panel::Loader::panel(const string &n)
227 RefPtr<Panel> p = new Panel();
228 load_sub(*p, wdg_map);
230 wdg_map[n] = p.release();
234 Panel::Child::Child(Panel &p, Widget *w):
235 Container::Child(p, w)
237 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
238 widget->signal_request_focus.connect(sigc::mem_fun(this, &Child::request_focus));
239 widget->signal_grab_pointer.connect(sigc::mem_fun(this, &Child::grab_pointer));
240 widget->signal_ungrab_pointer.connect(sigc::mem_fun(this, &Child::ungrab_pointer));
243 Panel::Child::~Child()
245 visibility_changed(false);
248 void Panel::Child::visibility_changed(bool v)
252 Panel &panel = static_cast<Panel &>(container);
253 if(widget==panel.pointer_focus)
254 panel.set_pointer_focus(0);
255 if(widget==panel.input_focus)
256 panel.set_input_focus(0);
260 void Panel::Child::autosize_changed()
262 Panel &panel = static_cast<Panel &>(container);
264 panel.layout->update();
267 void Panel::Child::request_focus()
269 Panel &panel = static_cast<Panel &>(container);
270 panel.set_input_focus(widget);
271 if(panel.parent && panel.visible)
275 void Panel::Child::grab_pointer()
277 Panel &panel = static_cast<Panel &>(container);
278 if(!panel.pointer_grabbed)
280 panel.set_pointer_focus(widget);
281 panel.pointer_grabbed = true;
282 panel.signal_grab_pointer.emit();
286 void Panel::Child::ungrab_pointer()
288 Panel &panel = static_cast<Panel &>(container);
289 if(panel.pointer_grabbed && panel.pointer_focus==widget)
291 // XXX Should set to the widget under pointer
292 panel.set_pointer_focus(0);
293 panel.pointer_grabbed = false;
294 panel.signal_ungrab_pointer.emit();