3 This file is part of libmspgltk
4 Copyright © 2009-2011 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
15 Container::Container():
20 Container::~Container()
22 while(!children.empty())
23 delete children.front()->widget;
26 void Container::add(Widget &wdg)
29 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)
41 on_child_removed(wdg);
45 throw InvalidState("That Widget is not in this Container");
48 Container::Child *Container::create_child(Widget *wdg)
50 return new Child(*this, wdg);
53 list<Widget *> Container::get_children() const
55 list<Widget *> result;
56 for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
57 result.push_back((*i)->widget);
61 Widget *Container::get_child_at(int x, int y)
63 for(list<Child *>::iterator i=children.end(); i!=children.begin();)
64 if((*--i)->widget->is_visible() && (*i)->widget->get_geometry().is_inside(x, y))
70 Widget *Container::get_descendant_at(int x, int y)
72 Widget *wdg = get_child_at(x, y);
73 if(Container *cont = dynamic_cast<Container *>(wdg))
75 const Geometry &cgeom = wdg->get_geometry();
76 Widget *wdg2 = cont->get_descendant_at(x-cgeom.x, y-cgeom.y);
83 void Container::button_press(int x, int y, unsigned btn)
87 const Geometry &cgeom = click_focus->get_geometry();
88 click_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
92 if(Widget *wdg = get_child_at(x, y))
97 const Geometry &cgeom = wdg->get_geometry();
98 wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
103 void Container::button_release(int x, int y, unsigned btn)
107 Widget *wdg = click_focus;
109 if(btn==click_button)
112 const Geometry &cgeom = wdg->get_geometry();
113 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
117 if(Widget *wdg = get_child_at(x, y))
119 const Geometry &cgeom = wdg->get_geometry();
120 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
125 void Container::pointer_motion(int x, int y)
129 const Geometry &cgeom = click_focus->get_geometry();
130 click_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
134 Widget *wdg = get_child_at(x, y);
137 const Geometry &cgeom = wdg->get_geometry();
138 wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
143 void Container::pointer_leave()
145 Widget::pointer_leave();
149 void Container::on_reparent()
151 for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
153 if(Container *c = dynamic_cast<Container *>((*i)->widget))
155 (*i)->widget->update_style();
160 Container::Child::Child(Container &c, Widget *w):
164 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
167 Container::Child::~Child()
169 if(widget==container.click_focus)
170 container.click_focus = 0;
173 void Container::Child::visibility_changed(bool v)
175 if(!v && widget==container.click_focus)
176 container.click_focus = 0;