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"
25 Panel::Panel(const Resources &r):
36 while(!children.empty())
37 delete children.front();
40 void Panel::add(Widget &wdg)
42 set_parent(wdg, this);
43 children.push_back(&wdg);
46 void Panel::remove(Widget &wdg)
48 ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
56 void Panel::button_press(int x, int y, unsigned btn)
60 const Geometry &cgeom=pointer_focus->get_geometry();
61 pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
63 else if(geom.is_inside_relative(x, y))
65 if(Widget *wdg=get_child_at(x, y))
67 set_pointer_focus(wdg, btn);
70 const Geometry &cgeom=wdg->get_geometry();
71 wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
76 void Panel::button_release(int x, int y, unsigned btn)
80 const Geometry &cgeom=pointer_focus->get_geometry();
81 pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn);
84 set_pointer_focus(get_child_at(x, y), 0);
86 else if(geom.is_inside_relative(x, y))
88 if(Widget *wdg=get_child_at(x, y))
90 const Geometry &cgeom=wdg->get_geometry();
91 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
96 void Panel::pointer_motion(int x, int y)
100 const Geometry &cgeom=pointer_focus->get_geometry();
101 pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
103 else if(geom.is_inside_relative(x, y))
105 Widget *wdg=get_child_at(x, y);
106 set_pointer_focus(wdg, 0);
109 const Geometry &cgeom=wdg->get_geometry();
110 wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
115 void Panel::pointer_leave()
117 set_pointer_focus(0, 0);
120 void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
123 input_focus->key_press(key, mod, ch);
126 void Panel::key_release(unsigned key, unsigned mod)
129 input_focus->key_release(key, mod);
132 void Panel::focus_out()
137 void Panel::child_hidden(Widget &wdg)
139 if(&wdg==pointer_focus)
140 set_pointer_focus(0, 0);
143 void Panel::render_special(const Part &part) const
145 if(part.get_name()=="children")
147 for(ChildSeq::const_iterator i=children.begin(); i!=children.end(); ++i)
148 if((*i)->is_visible())
153 void Panel::set_pointer_focus(Widget *wdg, int grab)
156 throw InvalidParameterValue("Can't grab on null widget");
158 if(wdg!=pointer_focus)
161 pointer_focus->pointer_leave();
166 pointer_focus->pointer_enter();
172 void Panel::set_input_focus(Widget *wdg)
177 input_focus->focus_out();
182 input_focus->focus_in();
186 Widget *Panel::get_child_at(int x, int y)
188 for(ChildSeq::reverse_iterator i=children.rbegin(); i!=children.rend(); ++i)
189 if((*i)->is_visible() && (*i)->get_geometry().is_inside(x, y))
196 Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
201 add("button", &Loader::child<Button>);
202 add("entry", &Loader::child<Entry>);
203 add("hslider", &Loader::child<HSlider>);
204 add("indicator", &Loader::child<Indicator>);
205 add("label", &Loader::child<Label>);
206 add("list", &Loader::child<List>);
207 add("panel", &Loader::panel);
208 add("toggle", &Loader::child<Toggle>);
209 add("vslider", &Loader::child<VSlider>);
213 void Panel::Loader::child(const string &n)
215 RefPtr<T> chl=new T(pnl.res);
218 wdg_map[n]=chl.release();
221 void Panel::Loader::panel(const string &n)
223 RefPtr<Panel> p=new Panel(pnl.res);
224 load_sub(*p, wdg_map);
226 wdg_map[n]=p.release();