From a6f175767e28411a36603b007065d4bf1c915075 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 7 Apr 2015 19:47:44 -0400 Subject: [PATCH] Changed the GTK+ new control system from using g_object_newv() to using g_object_new_valist() due to weird crashes. --- button_unix.c | 10 +++------- newcontrol_unix.c | 8 ++++++-- ui_unix.h | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/button_unix.c b/button_unix.c index 9c6fa2b9..986e81d3 100644 --- a/button_unix.c +++ b/button_unix.c @@ -23,18 +23,14 @@ static void defaultOnClicked(uiControl *c, void *data) uiControl *uiNewButton(const char *text) { struct button *b; - GParameter props[1]; GtkWidget *widget; 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, - 1, props, - FALSE, FALSE, FALSE, b); - g_value_unset(&(props[0].value)); // thanks to gregier in irc.gimp.net/#gtk+ + FALSE, FALSE, FALSE, b, + "label", text, + NULL); widget = GTK_WIDGET(uiControlHandle(b->c)); g_signal_connect(widget, "clicked", G_CALLBACK(onClicked), b); diff --git a/newcontrol_unix.c b/newcontrol_unix.c index 3123685c..87aa1057 100644 --- a/newcontrol_unix.c +++ b/newcontrol_unix.c @@ -60,12 +60,16 @@ static void singleContainerHide(uiControl *c) // 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; + va_list ap; 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; // TODO turn into bit field? diff --git a/ui_unix.h b/ui_unix.h index 19e8180c..06b6ed89 100644 --- a/ui_unix.h +++ b/ui_unix.h @@ -8,10 +8,11 @@ This file assumes that you have included and "ui.h" beforehand. It p #define __UI_UI_UNIX_H__ // 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 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); #endif