Made destroy functions on the Unix backend take a void * instead of storing the uiControl *.
This commit is contained in:
parent
d7d35e9853
commit
ccba4aef46
1
TODO.md
1
TODO.md
|
@ -19,7 +19,6 @@
|
|||
- add an example of events to each of the new controls guides
|
||||
- verify that uiParentSetMainControl() does indeed not update
|
||||
- settle differences between intmax_t and uintmax_t
|
||||
- make Unix destroy functions take void *data as an argument
|
||||
- settle onDestroy/destroy naming
|
||||
- clean up Unix lifetiming code
|
||||
|
||||
|
|
|
@ -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.
|
||||
// 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 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.
|
||||
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 {
|
||||
// this structure currently left blank
|
||||
|
|
|
@ -21,9 +21,9 @@ static void defaultOnClicked(uiButton *b, void *data)
|
|||
// 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);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ uiButton *uiNewButton(const char *text)
|
|||
b = uiNew(struct button);
|
||||
|
||||
uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON,
|
||||
FALSE, FALSE, onDestroy,
|
||||
FALSE, FALSE, onDestroy, b,
|
||||
"label", text,
|
||||
NULL);
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ static void defaultOnToggled(uiCheckbox *c, void *data)
|
|||
// 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);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
|
|||
c = uiNew(struct checkbox);
|
||||
|
||||
uiUnixNewControl(uiControl(c), GTK_TYPE_CHECK_BUTTON,
|
||||
FALSE, FALSE, onDestroy,
|
||||
FALSE, FALSE, onDestroy, c,
|
||||
"label", text,
|
||||
NULL);
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ struct 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);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ uiEntry *uiNewEntry(void)
|
|||
e = uiNew(struct entry);
|
||||
|
||||
uiUnixNewControl(uiControl(e), GTK_TYPE_ENTRY,
|
||||
FALSE, FALSE, onDestroy,
|
||||
FALSE, FALSE, onDestroy, e,
|
||||
NULL);
|
||||
|
||||
e->widget = WIDGET(e);
|
||||
|
|
|
@ -7,9 +7,9 @@ struct 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);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ uiLabel *uiNewLabel(const char *text)
|
|||
l = uiNew(struct label);
|
||||
|
||||
uiUnixNewControl(uiControl(l), GTK_TYPE_LABEL,
|
||||
FALSE, FALSE, onDestroy,
|
||||
FALSE, FALSE, onDestroy, l,
|
||||
"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+)
|
||||
// TODO yalign 0?
|
||||
|
|
|
@ -13,8 +13,8 @@ struct singleWidget {
|
|||
gboolean userDisabled;
|
||||
gboolean containerDisabled;
|
||||
gboolean canDestroy;
|
||||
void (*onDestroy)(uiControl *);
|
||||
uiControl *onDestroyControl;
|
||||
void (*onDestroy)(void *);
|
||||
void *onDestroyData;
|
||||
};
|
||||
|
||||
static void singleDestroy(uiControl *c)
|
||||
|
@ -22,7 +22,7 @@ static void singleDestroy(uiControl *c)
|
|||
singleWidget *s = (singleWidget *) (c->Internal);
|
||||
|
||||
// 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
|
||||
s->canDestroy = TRUE;
|
||||
// then actually destroy
|
||||
|
@ -175,7 +175,7 @@ static void onDestroy(GtkWidget *widget, gpointer data)
|
|||
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;
|
||||
va_list ap;
|
||||
|
@ -211,7 +211,7 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool
|
|||
g_object_ref_sink(s->immediate);
|
||||
|
||||
s->onDestroy = destroy;
|
||||
s->onDestroyControl = c;
|
||||
s->onDestroyData = onDestroyData;
|
||||
|
||||
// assign s later; we still need it for one more thing
|
||||
c->Destroy = singleDestroy;
|
||||
|
|
|
@ -11,9 +11,9 @@ struct tab {
|
|||
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;
|
||||
|
||||
for (i = 0; i < t->len; i++)
|
||||
|
@ -70,7 +70,7 @@ uiTab *uiNewTab(void)
|
|||
t = uiNew(struct tab);
|
||||
|
||||
uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK,
|
||||
FALSE, FALSE, onDestroy,
|
||||
FALSE, FALSE, onDestroy, t,
|
||||
NULL);
|
||||
|
||||
t->widget = WIDGET(t);
|
||||
|
|
Loading…
Reference in New Issue