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));
32 void Container::remove(Widget &wdg)
34 for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
35 if((*i)->widget==&wdg)
43 throw InvalidState("That Widget is not in this Container");
46 Container::Child *Container::create_child(Widget *wdg)
48 return new Child(*this, wdg);
51 list<Widget *> Container::get_children() const
53 list<Widget *> result;
54 for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
55 result.push_back((*i)->widget);
59 Widget *Container::get_child_at(int x, int y)
61 for(list<Child *>::iterator i=children.end(); i!=children.begin();)
62 if((*--i)->widget->is_visible() && (*i)->widget->get_geometry().is_inside(x, y))
68 Widget *Container::get_descendant_at(int x, int y)
70 Widget *wdg = get_child_at(x, y);
71 if(Container *cont = dynamic_cast<Container *>(wdg))
73 const Geometry &cgeom = wdg->get_geometry();
74 Widget *wdg2 = cont->get_descendant_at(x-cgeom.x, y-cgeom.y);
81 void Container::button_press(int x, int y, unsigned btn)
85 const Geometry &cgeom = click_focus->get_geometry();
86 click_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
90 if(Widget *wdg = get_child_at(x, y))
95 const Geometry &cgeom = wdg->get_geometry();
96 wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
101 void Container::button_release(int x, int y, unsigned btn)
105 Widget *wdg = click_focus;
107 if(btn==click_button)
110 const Geometry &cgeom = wdg->get_geometry();
111 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
115 if(Widget *wdg = get_child_at(x, y))
117 const Geometry &cgeom = wdg->get_geometry();
118 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
123 void Container::pointer_motion(int x, int y)
127 const Geometry &cgeom = click_focus->get_geometry();
128 click_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
132 Widget *wdg = get_child_at(x, y);
135 const Geometry &cgeom = wdg->get_geometry();
136 wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
141 void Container::pointer_leave()
143 Widget::pointer_leave();
147 void Container::on_reparent()
149 for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
151 if(Container *c = dynamic_cast<Container *>((*i)->widget))
153 (*i)->widget->update_style();
158 Container::Child::Child(Container &c, Widget *w):
162 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
165 Container::Child::~Child()
167 if(widget==container.click_focus)
168 container.click_focus = 0;
171 void Container::Child::visibility_changed(bool v)
173 if(!v && widget==container.click_focus)
174 container.click_focus = 0;