From 2434e8d004f695ad9c269c0aa5fc6ae9dfad7db7 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 18 Apr 2015 13:38:19 -0400 Subject: [PATCH] More Unix control destruction fixups. Now to finally hook together the tab fixup. --- TODO.md | 1 + ui_unix.h | 2 +- unix/newcontrol.c | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index 0a0fe5ac..9752943a 100644 --- a/TODO.md +++ b/TODO.md @@ -20,6 +20,7 @@ - verify that uiParentSetMainControl() does indeed not update - settle differences between intmax_t and uintmax_t - make destroy functions take the control as an argument +- settle onDestroy/destroy naming ultimately: - make everything vtable-based diff --git a/ui_unix.h b/ui_unix.h index 9dcb5f40..8e6ed405 100644 --- a/ui_unix.h +++ b/ui_unix.h @@ -12,7 +12,7 @@ This file assumes that you have included and "ui.h" beforehand. It p // The two scrolledWindow parameters allow placing scrollbars on the new control. // The destroy parameter is for a function that should be called when destroying the widget. // The firstProperty parameter and beyond allow passing construct properties to the new control, as with g_object_new(); end this list with NULL. -extern void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*onDestroy)(uiControl *), const char *firstProperty, ...); +extern void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*destroy)(uiControl *), const char *firstProperty, ...); struct uiSizingSys { // this structure currently left blank diff --git a/unix/newcontrol.c b/unix/newcontrol.c index a4ed8192..15e260fe 100644 --- a/unix/newcontrol.c +++ b/unix/newcontrol.c @@ -21,7 +21,11 @@ static void singleDestroy(uiControl *c) { singleWidget *s = (singleWidget *) (c->Internal); + // first call the widget's own destruction code + (*(s->onDestroy))(s->onDestroyControl); + // then mark that we are ready to be destroyed s->canDestroy = TRUE; + // then actually destroy gtk_widget_destroy(s->immediate); } @@ -168,11 +172,10 @@ static void onDestroy(GtkWidget *widget, gpointer data) if (!s->canDestroy) // TODO switch to complain() g_error("trying to destroy control with singleWidget at %p before uiControlDestroy()", s); - (*(s->onDestroy))(s->onDestroyControl); uiFree(s); } -void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*onDestroy)(uiControl *), const char *firstProperty, ...) +void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*destroy)(uiControl *), const char *firstProperty, ...) { singleWidget *s; va_list ap; @@ -207,7 +210,7 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool // TODO double-check this for new parenting rules g_object_ref_sink(s->immediate); - s->onDestroy = onDestroy; + s->onDestroy = destroy; s->onDestroyControl = c; // assign s later; we still need it for one more thing