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>
19 Panel::Panel(const Resources &r):
30 while(!children.empty())
31 delete children.front();
34 void Panel::add(Widget &wdg)
36 set_parent(wdg, this);
37 children.push_back(&wdg);
40 void Panel::remove(Widget &wdg)
42 ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
50 void Panel::button_press(int x, int y, unsigned btn)
53 pointer_focus->button_press(x-geom.x, y-geom.y, btn);
54 else if(geom.is_inside(x, y))
56 if(Widget *wdg=get_child_at(x, y))
58 wdg->button_press(x-geom.x, y-geom.y, btn);
65 void Panel::button_release(int x, int y, unsigned btn)
69 pointer_focus->button_release(x-geom.x, y-geom.y, btn);
75 set_pointer_focus(get_child_at(x, y));
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);
94 wdg->pointer_motion(x-geom.x, y-geom.y);
98 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
101 input_focus->key_press(key, mod, ch);
104 void Panel::key_release(unsigned key, unsigned mod)
107 input_focus->key_release(key, mod);
110 void Panel::focus_out()
115 void Panel::render_part(const Part &part) const
117 if(part.get_name()=="children")
119 for(ChildSeq::const_iterator i=children.begin(); i!=children.end(); ++i)
120 if((*i)->is_visible())
124 Widget::render_part(part);
127 void Panel::set_pointer_focus(Widget *wdg)
129 if(wdg!=pointer_focus && pointer_grab==0)
132 pointer_focus->pointer_leave();
137 pointer_focus->pointer_enter();
141 void Panel::set_input_focus(Widget *wdg)
146 input_focus->focus_out();
151 input_focus->focus_in();
155 Widget *Panel::get_child_at(int x, int y)
157 for(ChildSeq::reverse_iterator i=children.rbegin(); i!=children.rend(); ++i)
158 if((*i)->is_visible() && (*i)->get_geometry().is_inside(x-geom.x, y-geom.y))
165 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
170 add("button", &Loader::child<Button>);
171 add("label", &Loader::child<Label>);
172 add("panel", &Loader::panel);
176 void Panel::Loader::child(const string &n)
178 RefPtr<T> chl=new T(pnl.res);
181 wdg_map[n]=chl.release();
184 void Panel::Loader::panel(const string &n)
186 RefPtr<Panel> p=new Panel(pnl.res);
187 load_sub(*p, wdg_map);
189 wdg_map[n]=p.release();