3 This file is part of libmspgltk
4 Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
9 #include <msp/core/refptr.h>
14 #include "indicator.h"
28 Panel::Panel(const Resources &r):
32 pointer_grabbed(false),
38 void Panel::raise(Widget &wdg)
40 for(list<Container::Child *>::iterator i=children.begin(); i!=children.end(); ++i)
41 if((*i)->widget==&wdg)
43 children.splice(children.end(), children, i);
47 throw InvalidState("That Widget is not in this Panel");
50 Widget *Panel::get_final_input_focus() const
52 if(Panel *panel = dynamic_cast<Panel *>(input_focus))
54 Widget *focus = panel->get_final_input_focus();
61 void Panel::button_press(int x, int y, unsigned btn)
65 const Geometry &cgeom = pointer_focus->get_geometry();
66 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
70 if(Widget *wdg = get_child_at(x, y))
72 set_pointer_focus(wdg);
73 if(wdg->is_focusable())
76 Container::button_press(x, y, btn);
80 void Panel::button_release(int x, int y, unsigned btn)
84 const Geometry &cgeom = pointer_focus->get_geometry();
85 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
88 Container::button_release(x, y, btn);
91 void Panel::pointer_motion(int x, int y)
95 const Geometry &cgeom = pointer_focus->get_geometry();
96 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
100 set_pointer_focus(get_child_at(x, y));
101 Container::pointer_motion(x, y);
105 void Panel::pointer_leave()
107 Container::pointer_leave();
108 set_pointer_focus(0);
111 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
114 input_focus->key_press(key, mod, ch);
117 void Panel::key_release(unsigned key, unsigned mod)
120 input_focus->key_release(key, mod);
123 void Panel::focus_out()
128 void Panel::render_special(const Part &part) const
130 if(part.get_name()=="children")
132 for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
133 if((*i)->widget->is_visible())
134 (*i)->widget->render();
138 Panel::Child *Panel::create_child(Widget *wdg)
140 return new Child(*this, wdg);
143 void Panel::set_pointer_focus(Widget *wdg)
145 if(wdg!=pointer_focus)
148 pointer_focus->pointer_leave();
153 pointer_focus->pointer_enter();
157 void Panel::set_input_focus(Widget *wdg)
162 input_focus->focus_out();
169 input_focus->focus_in();
175 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
180 add("button", &Loader::child<Button>);
181 add("dropdown", &Loader::child<Dropdown>);
182 add("entry", &Loader::child<Entry>);
183 add("hslider", &Loader::child<HSlider>);
184 add("indicator", &Loader::child<Indicator>);
185 add("label", &Loader::child<Label>);
186 add("list", &Loader::child<List>);
187 add("panel", &Loader::panel);
188 add("table", &Loader::child<Table>);
189 add("toggle", &Loader::child<Toggle>);
190 add("vslider", &Loader::child<VSlider>);
194 void Panel::Loader::child(const string &n)
196 RefPtr<T> chl = new T(pnl.res);
199 wdg_map[n] = chl.release();
202 void Panel::Loader::panel(const string &n)
204 RefPtr<Panel> p = new Panel(pnl.res);
205 load_sub(*p, wdg_map);
207 wdg_map[n] = p.release();
211 Panel::Child::Child(Panel &p, Widget *w):
212 Container::Child(p, w)
214 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
215 widget->signal_request_focus.connect(sigc::mem_fun(this, &Child::request_focus));
216 widget->signal_grab_pointer.connect(sigc::mem_fun(this, &Child::grab_pointer));
217 widget->signal_ungrab_pointer.connect(sigc::mem_fun(this, &Child::ungrab_pointer));
220 Panel::Child::~Child()
222 visibility_changed(false);
225 void Panel::Child::visibility_changed(bool v)
229 Panel &panel = static_cast<Panel &>(container);
230 if(widget==panel.pointer_focus)
231 panel.set_pointer_focus(0);
232 if(widget==panel.input_focus)
233 panel.set_input_focus(0);
237 void Panel::Child::request_focus()
239 Panel &panel = static_cast<Panel &>(container);
240 panel.set_input_focus(widget);
241 if(panel.parent && panel.visible)
245 void Panel::Child::grab_pointer()
247 Panel &panel = static_cast<Panel &>(container);
248 if(!panel.pointer_grabbed)
250 panel.set_pointer_focus(widget);
251 panel.pointer_grabbed = true;
252 panel.signal_grab_pointer.emit();
256 void Panel::Child::ungrab_pointer()
258 Panel &panel = static_cast<Panel &>(container);
259 if(panel.pointer_grabbed && panel.pointer_focus==widget)
261 // XXX Should set to the widget under pointer
262 panel.set_pointer_focus(0);
263 panel.pointer_grabbed = false;
264 panel.signal_ungrab_pointer.emit();