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 Widget *wdg2 = cont->get_descendant_at(x-cgeom.x, y-cgeom.y);
77 void Container::button_press(int x, int y, unsigned btn)
81 const Geometry &cgeom = click_focus->get_geometry();
82 click_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
86 if(Widget *wdg = get_child_at(x, y))
91 const Geometry &cgeom = wdg->get_geometry();
92 wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
97 void Container::button_release(int x, int y, unsigned btn)
101 Widget *wdg = click_focus;
103 if(btn==click_button)
106 const Geometry &cgeom = wdg->get_geometry();
107 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
111 if(Widget *wdg = get_child_at(x, y))
113 const Geometry &cgeom = wdg->get_geometry();
114 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
119 void Container::pointer_motion(int x, int y)
123 const Geometry &cgeom = click_focus->get_geometry();
124 click_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
128 Widget *wdg = get_child_at(x, y);
131 const Geometry &cgeom = wdg->get_geometry();
132 wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
137 void Container::pointer_leave()
139 Widget::pointer_leave();
143 Container::Child *Container::create_child(Widget *wdg)
145 return new Child(*this, wdg);
149 Container::Child::Child(Container &c, Widget *w):
153 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
156 Container::Child::~Child()
158 if(widget==container.click_focus)
159 container.click_focus = 0;
162 void Container::Child::visibility_changed(bool v)
164 if(!v && widget==container.click_focus)
165 container.click_focus = 0;