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>
13 #include "indicator.h"
27 Panel::Panel(const Resources &r):
38 while(!children.empty())
39 delete children.front();
42 void Panel::add(Widget &wdg)
44 set_parent(wdg, this);
45 children.push_back(&wdg);
48 void Panel::remove(Widget &wdg)
50 ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
58 void Panel::raise(Widget &wdg)
60 ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
64 children.push_back(&wdg);
68 void Panel::button_press(int x, int y, unsigned btn)
72 const Geometry &cgeom=pointer_focus->get_geometry();
73 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
75 else if(geom.is_inside_relative(x, y))
77 if(Widget *wdg=get_child_at(x, y))
79 set_pointer_focus(wdg, btn);
82 const Geometry &cgeom=wdg->get_geometry();
83 wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
88 void Panel::button_release(int x, int y, unsigned btn)
92 const Geometry &cgeom=pointer_focus->get_geometry();
93 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
96 set_pointer_focus(get_child_at(x, y), 0);
98 else if(geom.is_inside_relative(x, y))
100 if(Widget *wdg=get_child_at(x, y))
102 const Geometry &cgeom=wdg->get_geometry();
103 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
108 void Panel::pointer_motion(int x, int y)
112 const Geometry &cgeom=pointer_focus->get_geometry();
113 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
115 else if(geom.is_inside_relative(x, y))
117 Widget *wdg=get_child_at(x, y);
118 set_pointer_focus(wdg, 0);
121 const Geometry &cgeom=wdg->get_geometry();
122 wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
127 void Panel::pointer_leave()
129 set_pointer_focus(0, 0);
132 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
135 input_focus->key_press(key, mod, ch);
138 void Panel::key_release(unsigned key, unsigned mod)
141 input_focus->key_release(key, mod);
144 void Panel::focus_out()
149 void Panel::child_hidden(Widget &wdg)
151 if(&wdg==pointer_focus)
152 set_pointer_focus(0, 0);
155 void Panel::grab_pointer(Widget &wdg)
157 if(pointer_grab==0 || pointer_focus==&wdg)
158 set_pointer_focus(&wdg, 255);
160 throw InvalidState("Pointer is already grabbed");
163 void Panel::ungrab_pointer(Widget &wdg)
165 if(pointer_focus==&wdg)
166 set_pointer_focus(0, 0);
167 else if(pointer_grab>0)
168 throw Exception("Someone is trying to steal the pointer!");
171 void Panel::render_special(const Part &part) const
173 if(part.get_name()=="children")
175 for(ChildSeq::const_iterator i=children.begin(); i!=children.end(); ++i)
176 if((*i)->is_visible())
181 void Panel::set_pointer_focus(Widget *wdg, int grab)
184 throw InvalidParameterValue("Can't grab on null widget");
186 if(wdg!=pointer_focus)
189 pointer_focus->pointer_leave();
194 pointer_focus->pointer_enter();
200 void Panel::set_input_focus(Widget *wdg)
205 input_focus->focus_out();
210 input_focus->focus_in();
214 Widget *Panel::get_child_at(int x, int y)
216 for(ChildSeq::reverse_iterator i=children.rbegin(); i!=children.rend(); ++i)
217 if((*i)->is_visible() && (*i)->get_geometry().is_inside(x, y))
224 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
229 add("button", &Loader::child<Button>);
230 add("dropdown", &Loader::child<Dropdown>);
231 add("entry", &Loader::child<Entry>);
232 add("hslider", &Loader::child<HSlider>);
233 add("indicator", &Loader::child<Indicator>);
234 add("label", &Loader::child<Label>);
235 add("list", &Loader::child<List>);
236 add("panel", &Loader::panel);
237 add("table", &Loader::child<Table>);
238 add("toggle", &Loader::child<Toggle>);
239 add("vslider", &Loader::child<VSlider>);
243 void Panel::Loader::child(const string &n)
245 RefPtr<T> chl=new T(pnl.res);
248 wdg_map[n]=chl.release();
251 void Panel::Loader::panel(const string &n)
253 RefPtr<Panel> p=new Panel(pnl.res);
254 load_sub(*p, wdg_map);
256 wdg_map[n]=p.release();