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>
12 #include "indicator.h"
24 Panel::Panel(const Resources &r):
35 while(!children.empty())
36 delete children.front();
39 void Panel::add(Widget &wdg)
41 set_parent(wdg, this);
42 children.push_back(&wdg);
45 void Panel::remove(Widget &wdg)
47 ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
55 void Panel::button_press(int x, int y, unsigned btn)
59 const Geometry &cgeom=pointer_focus->get_geometry();
60 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
62 else if(geom.is_inside_relative(x, y))
64 if(Widget *wdg=get_child_at(x, y))
66 set_pointer_focus(wdg, btn);
69 const Geometry &cgeom=wdg->get_geometry();
70 wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
75 void Panel::button_release(int x, int y, unsigned btn)
79 const Geometry &cgeom=pointer_focus->get_geometry();
80 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
83 set_pointer_focus(get_child_at(x, y), 0);
85 else if(geom.is_inside_relative(x, y))
87 if(Widget *wdg=get_child_at(x, y))
89 const Geometry &cgeom=wdg->get_geometry();
90 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
95 void Panel::pointer_motion(int x, int y)
99 const Geometry &cgeom=pointer_focus->get_geometry();
100 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
102 else if(geom.is_inside_relative(x, y))
104 Widget *wdg=get_child_at(x, y);
105 set_pointer_focus(wdg, 0);
108 const Geometry &cgeom=wdg->get_geometry();
109 wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
114 void Panel::pointer_leave()
116 set_pointer_focus(0, 0);
119 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
122 input_focus->key_press(key, mod, ch);
125 void Panel::key_release(unsigned key, unsigned mod)
128 input_focus->key_release(key, mod);
131 void Panel::focus_out()
136 void Panel::child_hidden(Widget &wdg)
138 if(&wdg==pointer_focus)
139 set_pointer_focus(0, 0);
142 void Panel::render_special(const Part &part) const
144 if(part.get_name()=="children")
146 for(ChildSeq::const_iterator i=children.begin(); i!=children.end(); ++i)
147 if((*i)->is_visible())
152 void Panel::set_pointer_focus(Widget *wdg, int grab)
155 throw InvalidParameterValue("Can't grab on null widget");
157 if(wdg!=pointer_focus)
160 pointer_focus->pointer_leave();
165 pointer_focus->pointer_enter();
171 void Panel::set_input_focus(Widget *wdg)
176 input_focus->focus_out();
181 input_focus->focus_in();
185 Widget *Panel::get_child_at(int x, int y)
187 for(ChildSeq::reverse_iterator i=children.rbegin(); i!=children.rend(); ++i)
188 if((*i)->is_visible() && (*i)->get_geometry().is_inside(x, y))
195 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
200 add("button", &Loader::child<Button>);
201 add("entry", &Loader::child<Entry>);
202 add("hslider", &Loader::child<HSlider>);
203 add("indicator", &Loader::child<Indicator>);
204 add("label", &Loader::child<Label>);
205 add("list", &Loader::child<List>);
206 add("panel", &Loader::panel);
207 add("vslider", &Loader::child<VSlider>);
211 void Panel::Loader::child(const string &n)
213 RefPtr<T> chl=new T(pnl.res);
216 wdg_map[n]=chl.release();
219 void Panel::Loader::panel(const string &n)
221 RefPtr<Panel> p=new Panel(pnl.res);
222 load_sub(*p, wdg_map);
224 wdg_map[n]=p.release();