From f9d80c32d665cbdc58747ce8e50abdd620fa37c8 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 9 Apr 2022 15:00:57 +0200 Subject: [PATCH] Allow to destroy Widgets when removing them from a container This is useful when the container uses manage()d Widgets, which are otherwise not destroyed. --- libs/gtkmm2ext/gtkmm2ext/utils.h | 2 +- libs/gtkmm2ext/utils.cc | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/gtkmm2ext/gtkmm2ext/utils.h b/libs/gtkmm2ext/gtkmm2ext/utils.h index c3e4f40228..9f14c667b5 100644 --- a/libs/gtkmm2ext/gtkmm2ext/utils.h +++ b/libs/gtkmm2ext/gtkmm2ext/utils.h @@ -139,7 +139,7 @@ namespace Gtkmm2ext { LIBGTKMM2EXT_API int physical_screen_height (Glib::RefPtr); LIBGTKMM2EXT_API int physical_screen_width (Glib::RefPtr); - LIBGTKMM2EXT_API void container_clear (Gtk::Container&); + LIBGTKMM2EXT_API void container_clear (Gtk::Container&, bool and_delete = false); /* C++ API for rounded rectangles */ diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc index 304bc361af..7ac9459a6c 100644 --- a/libs/gtkmm2ext/utils.cc +++ b/libs/gtkmm2ext/utils.cc @@ -667,12 +667,15 @@ Gtkmm2ext::physical_screen_width (Glib::RefPtr win) } void -Gtkmm2ext::container_clear (Gtk::Container& c) +Gtkmm2ext::container_clear (Gtk::Container& c, bool and_delete) { list children = c.get_children(); for (list::iterator child = children.begin(); child != children.end(); ++child) { (*child)->hide (); c.remove (**child); + if (and_delete) { + delete *child; + } } }