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 void Panel::button_press(int x, int y, unsigned btn)
54 const Geometry &cgeom=pointer_focus->get_geometry();
55 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
59 if(Widget *wdg=get_child_at(x, y))
61 set_pointer_focus(wdg);
64 Container::button_press(x, y, btn);
68 void Panel::button_release(int x, int y, unsigned btn)
72 const Geometry &cgeom=pointer_focus->get_geometry();
73 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
76 Container::button_release(x, y, btn);
79 void Panel::pointer_motion(int x, int y)
83 const Geometry &cgeom=pointer_focus->get_geometry();
84 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
88 set_pointer_focus(get_child_at(x, y));
89 Container::pointer_motion(x, y);
93 void Panel::pointer_leave()
95 Container::pointer_leave();
99 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
102 input_focus->key_press(key, mod, ch);
105 void Panel::key_release(unsigned key, unsigned mod)
108 input_focus->key_release(key, mod);
111 void Panel::focus_out()
116 void Panel::render_special(const Part &part) const
118 if(part.get_name()=="children")
120 for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
121 if((*i)->widget->is_visible())
122 (*i)->widget->render();
126 Panel::Child *Panel::create_child(Widget *wdg)
128 return new Child(*this, wdg);
131 void Panel::set_pointer_focus(Widget *wdg)
133 if(wdg!=pointer_focus)
136 pointer_focus->pointer_leave();
141 pointer_focus->pointer_enter();
145 void Panel::set_input_focus(Widget *wdg)
150 input_focus->focus_out();
157 input_focus->focus_in();
163 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
168 add("button", &Loader::child<Button>);
169 add("dropdown", &Loader::child<Dropdown>);
170 add("entry", &Loader::child<Entry>);
171 add("hslider", &Loader::child<HSlider>);
172 add("indicator", &Loader::child<Indicator>);
173 add("label", &Loader::child<Label>);
174 add("list", &Loader::child<List>);
175 add("panel", &Loader::panel);
176 add("table", &Loader::child<Table>);
177 add("toggle", &Loader::child<Toggle>);
178 add("vslider", &Loader::child<VSlider>);
182 void Panel::Loader::child(const string &n)
184 RefPtr<T> chl=new T(pnl.res);
187 wdg_map[n]=chl.release();
190 void Panel::Loader::panel(const string &n)
192 RefPtr<Panel> p=new Panel(pnl.res);
193 load_sub(*p, wdg_map);
195 wdg_map[n]=p.release();
199 Panel::Child::Child(Panel &p, Widget *w):
200 Container::Child(p, w)
202 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
203 widget->signal_request_focus.connect(sigc::mem_fun(this, &Child::request_focus));
204 widget->signal_grab_pointer.connect(sigc::mem_fun(this, &Child::grab_pointer));
205 widget->signal_ungrab_pointer.connect(sigc::mem_fun(this, &Child::ungrab_pointer));
208 Panel::Child::~Child()
210 visibility_changed(false);
213 void Panel::Child::visibility_changed(bool v)
217 Panel &panel=static_cast<Panel &>(container);
218 if(widget==panel.pointer_focus)
219 panel.set_pointer_focus(0);
220 if(widget==panel.input_focus)
221 panel.set_input_focus(0);
225 void Panel::Child::request_focus()
227 static_cast<Panel &>(container).set_input_focus(widget);
230 void Panel::Child::grab_pointer()
232 Panel &panel=static_cast<Panel &>(container);
233 if(!panel.pointer_grabbed)
235 panel.set_pointer_focus(widget);
236 panel.pointer_grabbed=true;
237 panel.signal_grab_pointer.emit();
241 void Panel::Child::ungrab_pointer()
243 Panel &panel=static_cast<Panel &>(container);
244 if(panel.pointer_grabbed && panel.pointer_focus==widget)
246 // XXX Should set to the widget under pointer
247 panel.set_pointer_focus(0);
248 panel.pointer_grabbed=false;
249 panel.signal_ungrab_pointer.emit();