From 4f66e6c17635237ca970fa383a77a763b02f16b2 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Mon, 15 May 2017 09:00:45 +0200 Subject: [PATCH] PsppireValueEntry: Use a more reliable way to override parent property. Setting the property in the _new function doesn't work if the object is constructed via GtkBuilder for example. --- src/ui/gui/psppire-value-entry.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ui/gui/psppire-value-entry.c b/src/ui/gui/psppire-value-entry.c index 27c561339b..c45db101bb 100644 --- a/src/ui/gui/psppire-value-entry.c +++ b/src/ui/gui/psppire-value-entry.c @@ -154,6 +154,26 @@ on_realize (GtkWidget *w) GTK_WIDGET_CLASS (psppire_value_entry_parent_class)->realize (w); } + +/* + The "has-entry" property for the parent class (GTK_COMBO_BOX) is + a) Construct-only ; and b) defaults to FALSE. + We want it to default to TRUE. So we override it here. +*/ +static GObject* +my_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + GObject *o = + G_OBJECT_CLASS (psppire_value_entry_parent_class)->constructor + (type, n_construct_properties, construct_properties); + + g_object_set (o, "has-entry", TRUE, NULL); + + return o; +} + static void psppire_value_entry_class_init (PsppireValueEntryClass *class) { @@ -164,6 +184,7 @@ psppire_value_entry_class_init (PsppireValueEntryClass *class) gobject_class->finalize = psppire_value_entry_finalize; gobject_class->set_property = psppire_value_entry_set_property; gobject_class->get_property = psppire_value_entry_get_property; + gobject_class->constructor = my_constructor; widget_class->realize = on_realize; g_object_class_install_property ( @@ -248,7 +269,7 @@ psppire_value_entry_finalize (GObject *gobject) GtkWidget * psppire_value_entry_new (void) { - return GTK_WIDGET (g_object_new (PSPPIRE_TYPE_VALUE_ENTRY, "has-entry", TRUE, NULL)); + return GTK_WIDGET (g_object_new (PSPPIRE_TYPE_VALUE_ENTRY, NULL)); } static void -- 2.30.2