3 This file is part of libmspgltk
4 Copyright © 2007-2011 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
9 #include <msp/core/refptr.h>
14 #include "indicator.h"
32 pointer_grabbed(false),
42 void Panel::set_layout(Layout *l)
44 l->set_container(*this);
49 Panel::Child *Panel::create_child(Widget *wdg)
51 return new Child(*this, wdg);
54 void Panel::raise(Widget &wdg)
56 for(list<Container::Child *>::iterator i=children.begin(); i!=children.end(); ++i)
57 if((*i)->widget==&wdg)
59 children.splice(children.end(), children, i);
63 throw InvalidState("That Widget is not in this Panel");
66 Widget *Panel::get_final_input_focus() const
68 if(Panel *panel = dynamic_cast<Panel *>(input_focus))
70 Widget *focus = panel->get_final_input_focus();
77 void Panel::render_special(const Part &part) const
79 if(part.get_name()=="children")
81 for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
82 if((*i)->widget->is_visible())
83 (*i)->widget->render();
87 void Panel::button_press(int x, int y, unsigned btn)
91 const Geometry &cgeom = pointer_focus->get_geometry();
92 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
96 if(Widget *wdg = get_child_at(x, y))
98 set_pointer_focus(wdg);
99 if(wdg->is_focusable())
100 set_input_focus(wdg);
102 Container::button_press(x, y, btn);
106 void Panel::button_release(int x, int y, unsigned btn)
110 const Geometry &cgeom = pointer_focus->get_geometry();
111 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
114 Container::button_release(x, y, btn);
117 void Panel::pointer_motion(int x, int y)
121 const Geometry &cgeom = pointer_focus->get_geometry();
122 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
126 set_pointer_focus(get_child_at(x, y));
127 Container::pointer_motion(x, y);
131 void Panel::pointer_leave()
133 Container::pointer_leave();
134 set_pointer_focus(0);
137 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
140 input_focus->key_press(key, mod, ch);
143 void Panel::key_release(unsigned key, unsigned mod)
146 input_focus->key_release(key, mod);
149 void Panel::focus_out()
155 void Panel::on_child_added(Widget &wdg)
158 layout->add_widget(wdg);
161 void Panel::on_child_removed(Widget &wdg)
164 layout->remove_widget(wdg);
167 void Panel::set_pointer_focus(Widget *wdg)
169 if(wdg!=pointer_focus)
172 pointer_focus->pointer_leave();
177 pointer_focus->pointer_enter();
181 void Panel::set_input_focus(Widget *wdg)
186 input_focus->focus_out();
193 input_focus->focus_in();
199 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
204 add("button", &Loader::child<Button>);
205 add("dropdown", &Loader::child<Dropdown>);
206 add("entry", &Loader::child<Entry>);
207 add("hslider", &Loader::child<HSlider>);
208 add("indicator", &Loader::child<Indicator>);
209 add("label", &Loader::child<Label>);
210 add("list", &Loader::child<List>);
211 add("panel", &Loader::panel);
212 add("table", &Loader::child<Table>);
213 add("toggle", &Loader::child<Toggle>);
214 add("vslider", &Loader::child<VSlider>);
218 void Panel::Loader::child(const string &n)
220 RefPtr<T> chl = new T();
223 wdg_map[n] = chl.release();
226 void Panel::Loader::panel(const string &n)
228 RefPtr<Panel> p = new Panel();
229 load_sub(*p, wdg_map);
231 wdg_map[n] = p.release();
235 Panel::Child::Child(Panel &p, Widget *w):
236 Container::Child(p, w)
238 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
239 widget->signal_request_focus.connect(sigc::mem_fun(this, &Child::request_focus));
240 widget->signal_grab_pointer.connect(sigc::mem_fun(this, &Child::grab_pointer));
241 widget->signal_ungrab_pointer.connect(sigc::mem_fun(this, &Child::ungrab_pointer));
244 Panel::Child::~Child()
246 visibility_changed(false);
249 void Panel::Child::visibility_changed(bool v)
253 Panel &panel = static_cast<Panel &>(container);
254 if(widget==panel.pointer_focus)
255 panel.set_pointer_focus(0);
256 if(widget==panel.input_focus)
257 panel.set_input_focus(0);
261 void Panel::Child::autosize_changed()
263 Panel &panel = static_cast<Panel &>(container);
265 panel.layout->update();
268 void Panel::Child::request_focus()
270 Panel &panel = static_cast<Panel &>(container);
271 panel.set_input_focus(widget);
272 if(panel.parent && panel.visible)
276 void Panel::Child::grab_pointer()
278 Panel &panel = static_cast<Panel &>(container);
279 if(!panel.pointer_grabbed)
281 panel.set_pointer_focus(widget);
282 panel.pointer_grabbed = true;
283 panel.signal_grab_pointer.emit();
287 void Panel::Child::ungrab_pointer()
289 Panel &panel = static_cast<Panel &>(container);
290 if(panel.pointer_grabbed && panel.pointer_focus==widget)
292 // XXX Should set to the widget under pointer
293 panel.set_pointer_focus(0);
294 panel.pointer_grabbed = false;
295 panel.signal_ungrab_pointer.emit();