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"
26 Panel::Panel(const Resources &r):
37 while(!children.empty())
38 delete children.front();
41 void Panel::add(Widget &wdg)
43 set_parent(wdg, this);
44 children.push_back(&wdg);
47 void Panel::remove(Widget &wdg)
49 ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
57 void Panel::raise(Widget &wdg)
59 ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
63 children.push_back(&wdg);
67 void Panel::button_press(int x, int y, unsigned btn)
71 const Geometry &cgeom=pointer_focus->get_geometry();
72 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
74 else if(geom.is_inside_relative(x, y))
76 if(Widget *wdg=get_child_at(x, y))
78 set_pointer_focus(wdg, btn);
81 const Geometry &cgeom=wdg->get_geometry();
82 wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
87 void Panel::button_release(int x, int y, unsigned btn)
91 const Geometry &cgeom=pointer_focus->get_geometry();
92 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
95 set_pointer_focus(get_child_at(x, y), 0);
97 else if(geom.is_inside_relative(x, y))
99 if(Widget *wdg=get_child_at(x, y))
101 const Geometry &cgeom=wdg->get_geometry();
102 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
107 void Panel::pointer_motion(int x, int y)
111 const Geometry &cgeom=pointer_focus->get_geometry();
112 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
114 else if(geom.is_inside_relative(x, y))
116 Widget *wdg=get_child_at(x, y);
117 set_pointer_focus(wdg, 0);
120 const Geometry &cgeom=wdg->get_geometry();
121 wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
126 void Panel::pointer_leave()
128 set_pointer_focus(0, 0);
131 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
134 input_focus->key_press(key, mod, ch);
137 void Panel::key_release(unsigned key, unsigned mod)
140 input_focus->key_release(key, mod);
143 void Panel::focus_out()
148 void Panel::child_hidden(Widget &wdg)
150 if(&wdg==pointer_focus)
151 set_pointer_focus(0, 0);
154 void Panel::grab_pointer(Widget &wdg)
156 if(pointer_grab==0 || pointer_focus==&wdg)
157 set_pointer_focus(&wdg, 255);
159 throw InvalidState("Pointer is already grabbed");
162 void Panel::ungrab_pointer(Widget &wdg)
164 if(pointer_focus==&wdg)
165 set_pointer_focus(0, 0);
166 else if(pointer_grab>0)
167 throw Exception("Someone is trying to steal the pointer!");
170 void Panel::render_special(const Part &part) const
172 if(part.get_name()=="children")
174 for(ChildSeq::const_iterator i=children.begin(); i!=children.end(); ++i)
175 if((*i)->is_visible())
180 void Panel::set_pointer_focus(Widget *wdg, int grab)
183 throw InvalidParameterValue("Can't grab on null widget");
185 if(wdg!=pointer_focus)
188 pointer_focus->pointer_leave();
193 pointer_focus->pointer_enter();
199 void Panel::set_input_focus(Widget *wdg)
204 input_focus->focus_out();
209 input_focus->focus_in();
213 Widget *Panel::get_child_at(int x, int y)
215 for(ChildSeq::reverse_iterator i=children.rbegin(); i!=children.rend(); ++i)
216 if((*i)->is_visible() && (*i)->get_geometry().is_inside(x, y))
223 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
228 add("button", &Loader::child<Button>);
229 add("dropdown", &Loader::child<Dropdown>);
230 add("entry", &Loader::child<Entry>);
231 add("hslider", &Loader::child<HSlider>);
232 add("indicator", &Loader::child<Indicator>);
233 add("label", &Loader::child<Label>);
234 add("list", &Loader::child<List>);
235 add("panel", &Loader::panel);
236 add("toggle", &Loader::child<Toggle>);
237 add("vslider", &Loader::child<VSlider>);
241 void Panel::Loader::child(const string &n)
243 RefPtr<T> chl=new T(pnl.res);
246 wdg_map[n]=chl.release();
249 void Panel::Loader::panel(const string &n)
251 RefPtr<Panel> p=new Panel(pnl.res);
252 load_sub(*p, wdg_map);
254 wdg_map[n]=p.release();