From f0055e948b9667638bcb26cad5067d1cc110e951 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 18 Apr 2015 12:30:25 -0400 Subject: [PATCH] Set up a new system for destroying controls on GTK+. Will migrate controls now. --- ui_unix.h | 3 ++- unix/newcontrol.c | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ui_unix.h b/ui_unix.h index 3911416b..9dcb5f40 100644 --- a/ui_unix.h +++ b/ui_unix.h @@ -10,8 +10,9 @@ This file assumes that you have included and "ui.h" beforehand. It p // uiUnixNewControl() creates a new uiControl with the given GTK+ control inside, storing it in the uiControl at c. // The second parameter is the type of the control, as passed to the first argument of g_object_new(). // 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, const char *firstProperty, ...); +extern void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*onDestroy)(uiControl *), const char *firstProperty, ...); struct uiSizingSys { // this structure currently left blank diff --git a/unix/newcontrol.c b/unix/newcontrol.c index 1ddd84a3..a4ed8192 100644 --- a/unix/newcontrol.c +++ b/unix/newcontrol.c @@ -13,6 +13,8 @@ struct singleWidget { gboolean userDisabled; gboolean containerDisabled; gboolean canDestroy; + void (*onDestroy)(uiControl *); + uiControl *onDestroyControl; }; static void singleDestroy(uiControl *c) @@ -166,10 +168,11 @@ 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, const char *firstProperty, ...) +void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*onDestroy)(uiControl *), const char *firstProperty, ...) { singleWidget *s; va_list ap; @@ -201,8 +204,12 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool // - end user call works (shoudn't be in any container) // - call in uiContainer works (both refs freed) // this also ensures singleRemoveParent() works properly + // TODO double-check this for new parenting rules g_object_ref_sink(s->immediate); + s->onDestroy = onDestroy; + s->onDestroyControl = c; + // assign s later; we still need it for one more thing c->Destroy = singleDestroy; c->Handle = singleHandle;