More proper cleanup work. This just leaves the tabs...

This commit is contained in:
Pietro Gagliardi 2015-04-18 12:22:15 -04:00
parent 160ffed7e2
commit d3ffe2270b
2 changed files with 19 additions and 4 deletions

View File

@ -143,11 +143,14 @@ static void parentDestroy(uiParent *pp)
{ {
uipParent *p = uipParent(pp->Internal); uipParent *p = uipParent(pp->Internal);
p->canDestroy = TRUE; // first, destroy the main control
if (p->mainControl != NULL) { if (p->mainControl != NULL) {
uiControlDestroy(p->mainControl); uiControlDestroy(p->mainControl);
p->mainControl = NULL; p->mainControl = NULL;
} }
// now we can mark the parent as ready to be destroyed
p->canDestroy = TRUE;
// finally, destroy the parent
gtk_widget_destroy(GTK_WIDGET(p)); gtk_widget_destroy(GTK_WIDGET(p));
} }

View File

@ -10,16 +10,17 @@ struct window {
int (*onClosing)(uiWindow *, void *); int (*onClosing)(uiWindow *, void *);
void *onClosingData; void *onClosingData;
int margined; int margined;
gboolean canDestroy;
}; };
static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data) static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
{ {
struct window *w = (struct window *) data; struct window *w = (struct window *) data;
// return exact values just in case // manually destroy the window ourselves; don't let the delete-event handler do it
if ((*(w->onClosing))(uiWindow(w), w->onClosingData)) if ((*(w->onClosing))(uiWindow(w), w->onClosingData))
return FALSE; uiWindowDestroy(uiWindow(w));
return TRUE; return TRUE; // don't continue to the default delete-event handler; we destroyed the window by now
} }
static int defaultOnClosing(uiWindow *w, void *data) static int defaultOnClosing(uiWindow *w, void *data)
@ -31,13 +32,24 @@ static void onDestroy(GtkWidget *widget, gpointer data)
{ {
struct window *w = (struct window *) data; struct window *w = (struct window *) data;
if (!w->canDestroy)
// TODO switch to complain()
g_error("attempt to dispose uiWindow at %p before uiWindowDestroy()", w);
uiFree(w); uiFree(w);
} }
// TODO should we change the GtkWindow's child first?
static void windowDestroy(uiWindow *ww) static void windowDestroy(uiWindow *ww)
{ {
struct window *w = (struct window *) ww; struct window *w = (struct window *) ww;
// first, hide the window to prevent our cleanup from being noticed
gtk_widget_hide(w->widget);
// next, destroy the content uiParent
uiParentDestroy(w->content);
// now that we cleaned up properly, we can mark our window as ready to be destroyed
w->canDestroy = TRUE;
// finally, destroy the window
gtk_widget_destroy(w->widget); gtk_widget_destroy(w->widget);
} }