3 This file is part of libmspgltk
4 Copyright © 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
15 Container::Container(const Resources &r):
21 Container::~Container()
23 while(!children.empty())
24 delete children.front()->widget;
27 void Container::add(Widget &wdg)
29 set_parent(wdg, this);
30 children.push_back(create_child(&wdg));
33 void Container::remove(Widget &wdg)
35 for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
36 if((*i)->widget==&wdg)
44 throw InvalidState("That Widget is not in this Container");
47 list<Widget *> Container::get_children() const
49 list<Widget *> result;
50 for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
51 result.push_back((*i)->widget);
55 Widget *Container::get_child_at(int x, int y)
57 for(list<Child *>::iterator i=children.end(); i!=children.begin();)
58 if((*--i)->widget->is_visible() && (*i)->widget->get_geometry().is_inside(x, y))
64 Widget *Container::get_descendant_at(int x, int y)
66 Widget *wdg=get_child_at(x, y);
67 if(Container *cont=dynamic_cast<Container *>(wdg))
69 const Geometry &cgeom=wdg->get_geometry();
70 return cont->get_descendant_at(x-cgeom.x, y-cgeom.y);
75 void Container::button_press(int x, int y, unsigned btn)
79 const Geometry &cgeom=click_focus->get_geometry();
80 click_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
84 if(Widget *wdg=get_child_at(x, y))
89 const Geometry &cgeom=wdg->get_geometry();
90 wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
95 void Container::button_release(int x, int y, unsigned btn)
99 Widget *wdg=click_focus;
101 if(btn==click_button)
104 const Geometry &cgeom=wdg->get_geometry();
105 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
109 if(Widget *wdg=get_child_at(x, y))
111 const Geometry &cgeom=wdg->get_geometry();
112 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
117 void Container::pointer_motion(int x, int y)
121 const Geometry &cgeom=click_focus->get_geometry();
122 click_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
126 Widget *wdg=get_child_at(x, y);
129 const Geometry &cgeom=wdg->get_geometry();
130 wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
135 void Container::pointer_leave()
137 Widget::pointer_leave();
141 Container::Child *Container::create_child(Widget *wdg)
143 return new Child(*this, wdg);
147 Container::Child::Child(Container &c, Widget *w):
151 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
154 Container::Child::~Child()
156 if(widget==container.click_focus)
157 container.click_focus=0;
160 void Container::Child::visibility_changed(bool v)
162 if(!v && widget==container.click_focus)
163 container.click_focus=0;