3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/core/refptr.h>
22 Panel::Panel(const Resources &r):
33 while(!children.empty())
34 delete children.front();
37 void Panel::add(Widget &wdg)
39 set_parent(wdg, this);
40 children.push_back(&wdg);
43 void Panel::remove(Widget &wdg)
45 ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
53 void Panel::button_press(int x, int y, unsigned btn)
56 pointer_focus->button_press(x-geom.x, y-geom.y, btn);
57 else if(geom.is_inside(x, y))
59 if(Widget *wdg=get_child_at(x, y))
61 set_pointer_focus(wdg, btn);
64 wdg->button_press(x-geom.x, y-geom.y, btn);
69 void Panel::button_release(int x, int y, unsigned btn)
73 pointer_focus->button_release(x-geom.x, y-geom.y, btn);
76 set_pointer_focus(get_child_at(x, y), 0);
78 else if(geom.is_inside(x, y))
80 if(Widget *wdg=get_child_at(x, y))
81 wdg->button_release(x-geom.x, y-geom.y, btn);
85 void Panel::pointer_motion(int x, int y)
88 pointer_focus->pointer_motion(x-geom.x, y-geom.y);
89 else if(geom.is_inside(x, y))
91 Widget *wdg=get_child_at(x, y);
92 set_pointer_focus(wdg, 0);
94 wdg->pointer_motion(x-geom.x, y-geom.y);
98 void Panel::pointer_leave()
100 set_pointer_focus(0, 0);
103 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
106 input_focus->key_press(key, mod, ch);
109 void Panel::key_release(unsigned key, unsigned mod)
112 input_focus->key_release(key, mod);
115 void Panel::focus_out()
120 void Panel::child_hidden(Widget &wdg)
122 if(&wdg==pointer_focus)
123 set_pointer_focus(0, 0);
126 void Panel::render_special(const Part &part) const
128 if(part.get_name()=="children")
130 for(ChildSeq::const_iterator i=children.begin(); i!=children.end(); ++i)
131 if((*i)->is_visible())
136 void Panel::set_pointer_focus(Widget *wdg, int grab)
139 throw InvalidParameterValue("Can't grab on null widget");
141 if(wdg!=pointer_focus)
144 pointer_focus->pointer_leave();
149 pointer_focus->pointer_enter();
155 void Panel::set_input_focus(Widget *wdg)
160 input_focus->focus_out();
165 input_focus->focus_in();
169 Widget *Panel::get_child_at(int x, int y)
171 for(ChildSeq::reverse_iterator i=children.rbegin(); i!=children.rend(); ++i)
172 if((*i)->is_visible() && (*i)->get_geometry().is_inside(x-geom.x, y-geom.y))
179 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
184 add("button", &Loader::child<Button>);
185 add("entry", &Loader::child<Entry>);
186 add("hslider", &Loader::child<HSlider>);
187 add("label", &Loader::child<Label>);
188 add("panel", &Loader::panel);
189 add("vslider", &Loader::child<VSlider>);
193 void Panel::Loader::child(const string &n)
195 RefPtr<T> chl=new T(pnl.res);
198 wdg_map[n]=chl.release();
201 void Panel::Loader::panel(const string &n)
203 RefPtr<Panel> p=new Panel(pnl.res);
204 load_sub(*p, wdg_map);
206 wdg_map[n]=p.release();