Set up a new system for destroying controls on GTK+. Will migrate controls now.
This commit is contained in:
parent
dc2a6230c8
commit
f0055e948b
|
@ -10,8 +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 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, const char *firstProperty, ...);
|
extern void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, void (*onDestroy)(uiControl *), const char *firstProperty, ...);
|
||||||
|
|
||||||
struct uiSizingSys {
|
struct uiSizingSys {
|
||||||
// this structure currently left blank
|
// this structure currently left blank
|
||||||
|
|
|
@ -13,6 +13,8 @@ struct singleWidget {
|
||||||
gboolean userDisabled;
|
gboolean userDisabled;
|
||||||
gboolean containerDisabled;
|
gboolean containerDisabled;
|
||||||
gboolean canDestroy;
|
gboolean canDestroy;
|
||||||
|
void (*onDestroy)(uiControl *);
|
||||||
|
uiControl *onDestroyControl;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void singleDestroy(uiControl *c)
|
static void singleDestroy(uiControl *c)
|
||||||
|
@ -166,10 +168,11 @@ static void onDestroy(GtkWidget *widget, gpointer data)
|
||||||
if (!s->canDestroy)
|
if (!s->canDestroy)
|
||||||
// TODO switch to complain()
|
// TODO switch to complain()
|
||||||
g_error("trying to destroy control with singleWidget at %p before uiControlDestroy()", s);
|
g_error("trying to destroy control with singleWidget at %p before uiControlDestroy()", s);
|
||||||
|
(*(s->onDestroy))(s->onDestroyControl);
|
||||||
uiFree(s);
|
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;
|
singleWidget *s;
|
||||||
va_list ap;
|
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)
|
// - end user call works (shoudn't be in any container)
|
||||||
// - call in uiContainer works (both refs freed)
|
// - call in uiContainer works (both refs freed)
|
||||||
// this also ensures singleRemoveParent() works properly
|
// this also ensures singleRemoveParent() works properly
|
||||||
|
// TODO double-check this for new parenting rules
|
||||||
g_object_ref_sink(s->immediate);
|
g_object_ref_sink(s->immediate);
|
||||||
|
|
||||||
|
s->onDestroy = onDestroy;
|
||||||
|
s->onDestroyControl = c;
|
||||||
|
|
||||||
// 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;
|
||||||
c->Handle = singleHandle;
|
c->Handle = singleHandle;
|
||||||
|
|
Loading…
Reference in New Issue