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"
30 pointer_grabbed(false),
34 Panel::Child *Panel::create_child(Widget *wdg)
36 return new Child(*this, wdg);
39 void Panel::raise(Widget &wdg)
41 for(list<Container::Child *>::iterator i=children.begin(); i!=children.end(); ++i)
42 if((*i)->widget==&wdg)
44 children.splice(children.end(), children, i);
48 throw InvalidState("That Widget is not in this Panel");
51 Widget *Panel::get_final_input_focus() const
53 if(Panel *panel = dynamic_cast<Panel *>(input_focus))
55 Widget *focus = panel->get_final_input_focus();
62 void Panel::render_special(const Part &part) const
64 if(part.get_name()=="children")
66 for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
67 if((*i)->widget->is_visible())
68 (*i)->widget->render();
72 void Panel::button_press(int x, int y, unsigned btn)
76 const Geometry &cgeom = pointer_focus->get_geometry();
77 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
81 if(Widget *wdg = get_child_at(x, y))
83 set_pointer_focus(wdg);
84 if(wdg->is_focusable())
87 Container::button_press(x, y, btn);
91 void Panel::button_release(int x, int y, unsigned btn)
95 const Geometry &cgeom = pointer_focus->get_geometry();
96 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
99 Container::button_release(x, y, btn);
102 void Panel::pointer_motion(int x, int y)
106 const Geometry &cgeom = pointer_focus->get_geometry();
107 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
111 set_pointer_focus(get_child_at(x, y));
112 Container::pointer_motion(x, y);
116 void Panel::pointer_leave()
118 Container::pointer_leave();
119 set_pointer_focus(0);
122 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
125 input_focus->key_press(key, mod, ch);
128 void Panel::key_release(unsigned key, unsigned mod)
131 input_focus->key_release(key, mod);
134 void Panel::focus_out()
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();