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>
20 Panel::Panel(const Resources &r):
31 while(!children.empty())
32 delete children.front();
35 void Panel::add(Widget &wdg)
37 set_parent(wdg, this);
38 children.push_back(&wdg);
41 void Panel::remove(Widget &wdg)
43 ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
51 void Panel::button_press(int x, int y, unsigned btn)
54 pointer_focus->button_press(x-geom.x, y-geom.y, btn);
55 else if(geom.is_inside(x, y))
57 if(Widget *wdg=get_child_at(x, y))
59 set_pointer_focus(wdg, btn);
62 wdg->button_press(x-geom.x, y-geom.y, btn);
67 void Panel::button_release(int x, int y, unsigned btn)
71 pointer_focus->button_release(x-geom.x, y-geom.y, btn);
74 set_pointer_focus(get_child_at(x, y), 0);
76 else if(geom.is_inside(x, y))
78 if(Widget *wdg=get_child_at(x, y))
79 wdg->button_release(x-geom.x, y-geom.y, btn);
83 void Panel::pointer_motion(int x, int y)
86 pointer_focus->pointer_motion(x-geom.x, y-geom.y);
87 else if(geom.is_inside(x, y))
89 Widget *wdg=get_child_at(x, y);
90 set_pointer_focus(wdg, 0);
92 wdg->pointer_motion(x-geom.x, y-geom.y);
96 void Panel::pointer_leave()
98 set_pointer_focus(0, 0);
101 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
104 input_focus->key_press(key, mod, ch);
107 void Panel::key_release(unsigned key, unsigned mod)
110 input_focus->key_release(key, mod);
113 void Panel::focus_out()
118 void Panel::child_hidden(Widget &wdg)
120 if(&wdg==pointer_focus)
121 set_pointer_focus(0, 0);
124 void Panel::render_special(const Part &part) const
126 if(part.get_name()=="children")
128 for(ChildSeq::const_iterator i=children.begin(); i!=children.end(); ++i)
129 if((*i)->is_visible())
134 void Panel::set_pointer_focus(Widget *wdg, int grab)
137 throw InvalidParameterValue("Can't grab on null widget");
139 if(wdg!=pointer_focus)
142 pointer_focus->pointer_leave();
147 pointer_focus->pointer_enter();
153 void Panel::set_input_focus(Widget *wdg)
158 input_focus->focus_out();
163 input_focus->focus_in();
167 Widget *Panel::get_child_at(int x, int y)
169 for(ChildSeq::reverse_iterator i=children.rbegin(); i!=children.rend(); ++i)
170 if((*i)->is_visible() && (*i)->get_geometry().is_inside(x-geom.x, y-geom.y))
177 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
182 add("button", &Loader::child<Button>);
183 add("entry", &Loader::child<Entry>);
184 add("label", &Loader::child<Label>);
185 add("panel", &Loader::panel);
189 void Panel::Loader::child(const string &n)
191 RefPtr<T> chl=new T(pnl.res);
194 wdg_map[n]=chl.release();
197 void Panel::Loader::panel(const string &n)
199 RefPtr<Panel> p=new Panel(pnl.res);
200 load_sub(*p, wdg_map);
202 wdg_map[n]=p.release();