Container::~Container()
{
+ // Clear children here while members are still valid
while(!children.empty())
- delete children.front()->widget;
+ {
+ if(children.back()->own_widget)
+ /* Avoid destroying the unique_ptr for the widget from within its own
+ reset() function */
+ unique_ptr<Widget> w = move(children.back()->own_widget);
+ else
+ children.pop_back();
+ }
}
-void Container::add(Widget &wdg)
+void Container::add(unique_ptr<Widget> wdg)
{
- wdg.set_parent(this);
- children.push_back(make_unique<Child>(*this, &wdg));
- if(wdg.get_animation_interval())
- check_animation_interval();
- children_rebuild_needed = true;
- signal_rebuild_needed.emit();
- on_child_added(wdg);
+ add_child(*wdg).own_widget = move(wdg);
}
void Container::remove(Widget &wdg)
if(i==children.end())
throw hierarchy_error("widget not in container");
+ unique_ptr<Widget> owned = move((*i)->own_widget);
if(&wdg==saved_input_focus)
saved_input_focus = nullptr;
wdg.set_parent(nullptr);
on_child_removed(wdg);
}
+Container::Child &Container::add_child(Widget &wdg)
+{
+ wdg.set_parent(this);
+ children.push_back(make_unique<Child>(*this, &wdg));
+ if(wdg.get_animation_interval())
+ check_animation_interval();
+ children_rebuild_needed = true;
+ signal_rebuild_needed.emit();
+ on_child_added(wdg);
+ return *children.back();
+}
+
Geometry Container::determine_child_geometry(const Widget &child, const Part &part) const
{
Geometry pgeom = part.get_geometry();
widget->signal_rebuild_needed.connect(sigc::mem_fun(this, &Child::rebuild_needed));
}
+Container::Child::Child(Container &c, unique_ptr<Widget> w):
+ Child(c, w.get())
+{
+ own_widget = move(w);
+}
+
Container::Child::~Child()
{
visibility_changed(false);