8 Container::Container():
13 Container::~Container()
15 while(!children.empty())
16 delete children.front()->widget;
19 void Container::add(Widget &wdg)
22 children.push_back(create_child(&wdg));
26 void Container::remove(Widget &wdg)
28 for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
29 if((*i)->widget==&wdg)
34 on_child_removed(wdg);
38 throw InvalidState("That Widget is not in this Container");
41 Container::Child *Container::create_child(Widget *wdg)
43 return new Child(*this, wdg);
46 list<Widget *> Container::get_children() const
48 list<Widget *> result;
49 for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
50 result.push_back((*i)->widget);
54 Widget *Container::get_child_at(int x, int y)
56 for(list<Child *>::iterator i=children.end(); i!=children.begin();)
57 if((*--i)->widget->is_visible() && (*i)->widget->get_geometry().is_inside(x, y))
63 Widget *Container::get_descendant_at(int x, int y)
65 Widget *wdg = get_child_at(x, y);
66 if(Container *cont = dynamic_cast<Container *>(wdg))
68 const Geometry &cgeom = wdg->get_geometry();
69 Widget *wdg2 = cont->get_descendant_at(x-cgeom.x, y-cgeom.y);
76 void Container::button_press(int x, int y, unsigned btn)
80 const Geometry &cgeom = click_focus->get_geometry();
81 click_focus->button_press(x-cgeom.x, y-cgeom.y, btn);
85 if(Widget *wdg = get_child_at(x, y))
90 const Geometry &cgeom = wdg->get_geometry();
91 wdg->button_press(x-cgeom.x, y-cgeom.y, btn);
96 void Container::button_release(int x, int y, unsigned btn)
100 Widget *wdg = click_focus;
102 if(btn==click_button)
105 const Geometry &cgeom = wdg->get_geometry();
106 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
110 if(Widget *wdg = get_child_at(x, y))
112 const Geometry &cgeom = wdg->get_geometry();
113 wdg->button_release(x-cgeom.x, y-cgeom.y, btn);
118 void Container::pointer_motion(int x, int y)
122 const Geometry &cgeom = click_focus->get_geometry();
123 click_focus->pointer_motion(x-cgeom.x, y-cgeom.y);
127 Widget *wdg = get_child_at(x, y);
130 const Geometry &cgeom = wdg->get_geometry();
131 wdg->pointer_motion(x-cgeom.x, y-cgeom.y);
136 void Container::pointer_leave()
138 Widget::pointer_leave();
142 void Container::on_reparent()
144 for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
146 if(Container *c = dynamic_cast<Container *>((*i)->widget))
148 (*i)->widget->update_style();
153 Container::Child::Child(Container &c, Widget *w):
157 widget->signal_visibility_changed.connect(sigc::mem_fun(this, &Child::visibility_changed));
160 Container::Child::~Child()
162 if(widget==container.click_focus)
163 container.click_focus = 0;
166 void Container::Child::visibility_changed(bool v)
168 if(!v && widget==container.click_focus)
169 container.click_focus = 0;