Made destroy functions on the Unix backend take a void * instead of storing the uiControl *.

This commit is contained in:
Pietro Gagliardi 2015-04-18 17:14:19 -04:00
parent d7d35e9853
commit ccba4aef46
8 changed files with 22 additions and 23 deletions

View File

@ -19,7 +19,6 @@
- add an example of events to each of the new controls guides - add an example of events to each of the new controls guides
- verify that uiParentSetMainControl() does indeed not update - verify that uiParentSetMainControl() does indeed not update
- settle differences between intmax_t and uintmax_t - settle differences between intmax_t and uintmax_t
- make Unix destroy functions take void *data as an argument
- settle onDestroy/destroy naming - settle onDestroy/destroy naming
- clean up Unix lifetiming code - clean up Unix lifetiming code

View File

@ -10,9 +10,9 @@ This file assumes that you have included <gtk/gtk.h> and "ui.h" beforehand. It p
// uiUnixNewControl() creates a new uiControl with the given GTK+ control inside, storing it in the uiControl at c. // 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 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 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 destroy parameters are 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. // 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 (*destroy)(uiControl *), const char *firstProperty, ...); extern void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*destroy)(void *), void *onDestroyData, const char *firstProperty, ...);
struct uiSizingSys { struct uiSizingSys {
// this structure currently left blank // this structure currently left blank

View File

@ -21,9 +21,9 @@ static void defaultOnClicked(uiButton *b, void *data)
// do nothing // do nothing
} }
static void onDestroy(uiControl *c) static void onDestroy(void *data)
{ {
struct button *b = (struct button *) c; struct button *b = (struct button *) data;
uiFree(b); uiFree(b);
} }
@ -57,7 +57,7 @@ uiButton *uiNewButton(const char *text)
b = uiNew(struct button); b = uiNew(struct button);
uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON, uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON,
FALSE, FALSE, onDestroy, FALSE, FALSE, onDestroy, b,
"label", text, "label", text,
NULL); NULL);

View File

@ -24,9 +24,9 @@ static void defaultOnToggled(uiCheckbox *c, void *data)
// do nothing // do nothing
} }
static void onDestroy(uiControl *cc) static void onDestroy(void *data)
{ {
struct checkbox *c = (struct checkbox *) cc; struct checkbox *c = (struct checkbox *) data;
uiFree(c); uiFree(c);
} }
@ -81,7 +81,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
c = uiNew(struct checkbox); c = uiNew(struct checkbox);
uiUnixNewControl(uiControl(c), GTK_TYPE_CHECK_BUTTON, uiUnixNewControl(uiControl(c), GTK_TYPE_CHECK_BUTTON,
FALSE, FALSE, onDestroy, FALSE, FALSE, onDestroy, c,
"label", text, "label", text,
NULL); NULL);

View File

@ -7,9 +7,9 @@ struct entry {
GtkEntry *entry; GtkEntry *entry;
}; };
static void onDestroy(uiControl *c) static void onDestroy(void *data)
{ {
struct entry *e = (struct entry *) c; struct entry *e = (struct entry *) data;
uiFree(e); uiFree(e);
} }
@ -35,7 +35,7 @@ uiEntry *uiNewEntry(void)
e = uiNew(struct entry); e = uiNew(struct entry);
uiUnixNewControl(uiControl(e), GTK_TYPE_ENTRY, uiUnixNewControl(uiControl(e), GTK_TYPE_ENTRY,
FALSE, FALSE, onDestroy, FALSE, FALSE, onDestroy, e,
NULL); NULL);
e->widget = WIDGET(e); e->widget = WIDGET(e);

View File

@ -7,9 +7,9 @@ struct label {
GtkLabel *label; GtkLabel *label;
}; };
static void onDestroy(uiControl *c) static void onDestroy(void *data)
{ {
struct label *l = (struct label *) c; struct label *l = (struct label *) data;
uiFree(l); uiFree(l);
} }
@ -36,7 +36,7 @@ uiLabel *uiNewLabel(const char *text)
l = uiNew(struct label); l = uiNew(struct label);
uiUnixNewControl(uiControl(l), GTK_TYPE_LABEL, uiUnixNewControl(uiControl(l), GTK_TYPE_LABEL,
FALSE, FALSE, onDestroy, FALSE, FALSE, onDestroy, l,
"label", text, "label", text,
"xalign", 0.0, // note: must be a float constant, otherwise the ... will turn it into an int and we get segfaults on some platforms (thanks ebassi in irc.gimp.net/#gtk+) "xalign", 0.0, // note: must be a float constant, otherwise the ... will turn it into an int and we get segfaults on some platforms (thanks ebassi in irc.gimp.net/#gtk+)
// TODO yalign 0? // TODO yalign 0?

View File

@ -13,8 +13,8 @@ struct singleWidget {
gboolean userDisabled; gboolean userDisabled;
gboolean containerDisabled; gboolean containerDisabled;
gboolean canDestroy; gboolean canDestroy;
void (*onDestroy)(uiControl *); void (*onDestroy)(void *);
uiControl *onDestroyControl; void *onDestroyData;
}; };
static void singleDestroy(uiControl *c) static void singleDestroy(uiControl *c)
@ -22,7 +22,7 @@ static void singleDestroy(uiControl *c)
singleWidget *s = (singleWidget *) (c->Internal); singleWidget *s = (singleWidget *) (c->Internal);
// first call the widget's own destruction code // first call the widget's own destruction code
(*(s->onDestroy))(s->onDestroyControl); (*(s->onDestroy))(s->onDestroyData);
// then mark that we are ready to be destroyed // then mark that we are ready to be destroyed
s->canDestroy = TRUE; s->canDestroy = TRUE;
// then actually destroy // then actually destroy
@ -175,7 +175,7 @@ static void onDestroy(GtkWidget *widget, gpointer data)
uiFree(s); uiFree(s);
} }
void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*destroy)(uiControl *), const char *firstProperty, ...) void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*destroy)(void *), void *onDestroyData, const char *firstProperty, ...)
{ {
singleWidget *s; singleWidget *s;
va_list ap; va_list ap;
@ -211,7 +211,7 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool
g_object_ref_sink(s->immediate); g_object_ref_sink(s->immediate);
s->onDestroy = destroy; s->onDestroy = destroy;
s->onDestroyControl = c; s->onDestroyData = onDestroyData;
// assign s later; we still need it for one more thing // assign s later; we still need it for one more thing
c->Destroy = singleDestroy; c->Destroy = singleDestroy;

View File

@ -11,9 +11,9 @@ struct tab {
uintmax_t cap; uintmax_t cap;
}; };
static void onDestroy(uiControl *c) static void onDestroy(void *data)
{ {
struct tab *t = (struct tab *) c; struct tab *t = (struct tab *) data;
uintmax_t i; uintmax_t i;
for (i = 0; i < t->len; i++) for (i = 0; i < t->len; i++)
@ -70,7 +70,7 @@ uiTab *uiNewTab(void)
t = uiNew(struct tab); t = uiNew(struct tab);
uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK, uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK,
FALSE, FALSE, onDestroy, FALSE, FALSE, onDestroy, t,
NULL); NULL);
t->widget = WIDGET(t); t->widget = WIDGET(t);