More Unix control destruction fixups. Now to finally hook together the tab fixup.

This commit is contained in:
Pietro Gagliardi 2015-04-18 13:38:19 -04:00
parent 38b118f033
commit 2434e8d004
3 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -12,7 +12,7 @@ This file assumes that you have included <gtk/gtk.h> 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

View File

@ -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