Changed the GTK+ new control system from using g_object_newv() to using g_object_new_valist() due to weird crashes.

This commit is contained in:
Pietro Gagliardi 2015-04-07 19:47:44 -04:00
parent 84c55e185d
commit a6f175767e
3 changed files with 12 additions and 11 deletions

View File

@ -23,18 +23,14 @@ static void defaultOnClicked(uiControl *c, void *data)
uiControl *uiNewButton(const char *text) uiControl *uiNewButton(const char *text)
{ {
struct button *b; struct button *b;
GParameter props[1];
GtkWidget *widget; GtkWidget *widget;
b = uiNew(struct button); b = uiNew(struct button);
props[0].name = "label";
g_value_init(&(props[0].value), G_TYPE_STRING);
g_value_set_string(&(props[0].value), text);
b->c = uiUnixNewControl(GTK_TYPE_BUTTON, b->c = uiUnixNewControl(GTK_TYPE_BUTTON,
1, props, FALSE, FALSE, FALSE, b,
FALSE, FALSE, FALSE, b); "label", text,
g_value_unset(&(props[0].value)); // thanks to gregier in irc.gimp.net/#gtk+ NULL);
widget = GTK_WIDGET(uiControlHandle(b->c)); widget = GTK_WIDGET(uiControlHandle(b->c));
g_signal_connect(widget, "clicked", G_CALLBACK(onClicked), b); g_signal_connect(widget, "clicked", G_CALLBACK(onClicked), b);

View File

@ -60,12 +60,16 @@ static void singleContainerHide(uiControl *c)
// TODO connect free function // TODO connect free function
uiControl *uiUnixNewControl(GType type, guint nConstructParams, GParameter *constructParams, gboolean inScrolledWindow, gboolean needsViewport, gboolean scrolledWindowHasBorder, void *data) uiControl *uiUnixNewControl(GType type, gboolean inScrolledWindow, gboolean needsViewport, gboolean scrolledWindowHasBorder, void *data, const char *firstProperty, ...)
{ {
uiSingleWidgetControl *c; uiSingleWidgetControl *c;
va_list ap;
c = uiNew(uiSingleWidgetControl); c = uiNew(uiSingleWidgetControl);
c->widget = GTK_WIDGET(g_object_newv(type, nConstructParams, constructParams));
va_start(ap, firstProperty);
c->widget = GTK_WIDGET(g_object_new_valist(type, firstProperty, ap));
va_end(ap);
c->immediate = c->widget; c->immediate = c->widget;
// TODO turn into bit field? // TODO turn into bit field?

View File

@ -8,10 +8,11 @@ This file assumes that you have included <gtk/gtk.h> and "ui.h" beforehand. It p
#define __UI_UI_UNIX_H__ #define __UI_UI_UNIX_H__
// uiUnixNewControl() creates a new uiControl with the given GTK+ control inside. // uiUnixNewControl() creates a new uiControl with the given GTK+ control inside.
// The first three parameters are used for creating the control itself and are the same as passed to g_object_newv(). // The first parameter is the type of the control, as passed to the first argument of g_object_new().
// The three scrolledWindow parameters allow placing scrollbars on the new control. // The three scrolledWindow parameters allow placing scrollbars on the new control.
// The data parameter can be accessed with uiUnixControlData(). // The data parameter can be accessed with uiUnixControlData().
extern uiControl *uiUnixNewControl(GType type, guint nConstructParams, GParameter *constructParams, gboolean inScrolledWindow, gboolean needsViewport, gboolean scrolledWindowHasBorder, void *data); // The firstProperty parameter and beyond allow passing construct properties to the new control, as with g_object_new(); end this list with NULL.
extern uiControl *uiUnixNewControl(GType type, gboolean inScrolledWindow, gboolean needsViewport, gboolean scrolledWindowHasBorder, void *data, const char *firstProperty, ...);
extern void *uiUnixControlData(uiControl *c); extern void *uiUnixControlData(uiControl *c);
#endif #endif