From a15bb12ad172ccf872d20728e601f22b0db1daee Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 6 May 2015 01:31:06 -0400 Subject: [PATCH] Implemented proper bin destruction on the GTK+ backend. --- unix/bin.c | 7 ++++++- unix/tab.c | 2 ++ unix/window.c | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/unix/bin.c b/unix/bin.c index fe719b9f..1b87c5cb 100644 --- a/unix/bin.c +++ b/unix/bin.c @@ -104,9 +104,14 @@ void binSetParent(uiContainer *c, uintptr_t osParent) { struct bin *b = (struct bin *) c; GtkWidget *widget; - GtkContainer *newContainer; + GtkContainer *newContainer, *oldContainer; widget = GTK_WIDGET(uiControlHandle(uiControl(b))); + if (osParent == 0) { + oldContainer = GTK_CONTAINER(gtk_widget_get_parent(widget)); + gtk_container_remove(oldContainer, widget); + return; + } newContainer = GTK_CONTAINER(osParent); gtk_container_add(newContainer, widget); } diff --git a/unix/tab.c b/unix/tab.c index f387db1a..471eef5d 100644 --- a/unix/tab.c +++ b/unix/tab.c @@ -27,6 +27,7 @@ static void onDestroy(void *data) // we need to remove them from the tab first; see below for (i = 0; i < t->pages->len; i++) { p = &g_array_index(t->pages, struct tabPage, i); + // this does the job of binSetParent() gtk_container_remove(t->container, p->binWidget); uiControlDestroy(uiControl(p->bin)); } @@ -75,6 +76,7 @@ static void tabDeletePage(uiTab *tt, uintmax_t n) // why? simple: both gtk_notebook_remove_tab() and gtk_widget_destroy() call gtk_container_remove() // we need to remove them from the tab first, though, otherwise they won't really be destroyed properly // (the GtkNotebook will still have the tab in it because its reference ISN'T destroyed, and we crash resizing a bin that no longer exists + // this also does the job of binSetParent() gtk_container_remove(t->container, p->binWidget); uiControlDestroy(uiControl(p->bin)); diff --git a/unix/window.c b/unix/window.c index f839edf1..fe8cbfcb 100644 --- a/unix/window.c +++ b/unix/window.c @@ -46,7 +46,8 @@ static void windowDestroy(uiControl *c) // first hide ourselves gtk_widget_hide(w->widget); // now destroy the bin - // the bin has no parent, so we can just call uiControlDestroy() + // we need to remove the bin from its parent first + binSetParent(w->bin, 0); uiControlDestroy(uiControl(w->bin)); // now destroy the menus, if any if (w->menubar != NULL)