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"
30 pointer_grabbed(false),
34 void Panel::raise(Widget &wdg)
36 for(list<Container::Child *>::iterator i=children.begin(); i!=children.end(); ++i)
37 if((*i)->widget==&wdg)
39 children.splice(children.end(), children, i);
43 throw InvalidState("That Widget is not in this Panel");
46 Widget *Panel::get_final_input_focus() const
48 if(Panel *panel = dynamic_cast<Panel *>(input_focus))
50 Widget *focus = panel->get_final_input_focus();
57 void Panel::button_press(int x, int y, unsigned btn)
61 const Geometry &cgeom = pointer_focus->get_geometry();
62 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
66 if(Widget *wdg = get_child_at(x, y))
68 set_pointer_focus(wdg);
69 if(wdg->is_focusable())
72 Container::button_press(x, y, btn);
76 void Panel::button_release(int x, int y, unsigned btn)
80 const Geometry &cgeom = pointer_focus->get_geometry();
81 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
84 Container::button_release(x, y, btn);
87 void Panel::pointer_motion(int x, int y)
91 const Geometry &cgeom = pointer_focus->get_geometry();
92 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
96 set_pointer_focus(get_child_at(x, y));
97 Container::pointer_motion(x, y);
101 void Panel::pointer_leave()
103 Container::pointer_leave();
104 set_pointer_focus(0);
107 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
110 input_focus->key_press(key, mod, ch);
113 void Panel::key_release(unsigned key, unsigned mod)
116 input_focus->key_release(key, mod);
119 void Panel::focus_out()
124 void Panel::render_special(const Part &part) const
126 if(part.get_name()=="children")
128 for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
129 if((*i)->widget->is_visible())
130 (*i)->widget->render();
134 Panel::Child *Panel::create_child(Widget *wdg)
136 return new Child(*this, wdg);
139 void Panel::set_pointer_focus(Widget *wdg)
141 if(wdg!=pointer_focus)
144 pointer_focus->pointer_leave();
149 pointer_focus->pointer_enter();
153 void Panel::set_input_focus(Widget *wdg)
158 input_focus->focus_out();
165 input_focus->focus_in();
171 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
176 add("button", &Loader::child<Button>);
177 add("dropdown", &Loader::child<Dropdown>);
178 add("entry", &Loader::child<Entry>);
179 add("hslider", &Loader::child<HSlider>);
180 add("indicator", &Loader::child<Indicator>);
181 add("label", &Loader::child<Label>);
182 add("list", &Loader::child<List>);
183 add("panel", &Loader::panel);
184 add("table", &Loader::child<Table>);
185 add("toggle", &Loader::child<Toggle>);
186 add("vslider", &Loader::child<VSlider>);
190 void Panel::Loader::child(const string &n)
192 RefPtr<T> chl = new T();
195 wdg_map[n] = chl.release();
198 void Panel::Loader::panel(const string &n)
200 RefPtr<Panel> p = new Panel();
201 load_sub(*p, wdg_map);
203 wdg_map[n] = p.release();
207 Panel::Child::Child(Panel &p, Widget *w):
208 Container::Child(p, w)
210 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
211 widget->signal_request_focus.connect(sigc::mem_fun(this, &Child::request_focus));
212 widget->signal_grab_pointer.connect(sigc::mem_fun(this, &Child::grab_pointer));
213 widget->signal_ungrab_pointer.connect(sigc::mem_fun(this, &Child::ungrab_pointer));
216 Panel::Child::~Child()
218 visibility_changed(false);
221 void Panel::Child::visibility_changed(bool v)
225 Panel &panel = static_cast<Panel &>(container);
226 if(widget==panel.pointer_focus)
227 panel.set_pointer_focus(0);
228 if(widget==panel.input_focus)
229 panel.set_input_focus(0);
233 void Panel::Child::request_focus()
235 Panel &panel = static_cast<Panel &>(container);
236 panel.set_input_focus(widget);
237 if(panel.parent && panel.visible)
241 void Panel::Child::grab_pointer()
243 Panel &panel = static_cast<Panel &>(container);
244 if(!panel.pointer_grabbed)
246 panel.set_pointer_focus(widget);
247 panel.pointer_grabbed = true;
248 panel.signal_grab_pointer.emit();
252 void Panel::Child::ungrab_pointer()
254 Panel &panel = static_cast<Panel &>(container);
255 if(panel.pointer_grabbed && panel.pointer_focus==widget)
257 // XXX Should set to the widget under pointer
258 panel.set_pointer_focus(0);
259 panel.pointer_grabbed = false;
260 panel.signal_ungrab_pointer.emit();