X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-value-entry.c;h=731b6b3fb16e688a90738fda591ca4472a035d7c;hb=7ef0d7851bafb01ad78c03d66d344fa3ea6f31c6;hp=4cc8be9871acb1f9c90e151626e407709e2f8101;hpb=b03ff6adc04a5b79617c4fa386c424f994a18bfe;p=pspp diff --git a/src/ui/gui/psppire-value-entry.c b/src/ui/gui/psppire-value-entry.c index 4cc8be9871..731b6b3fb1 100644 --- a/src/ui/gui/psppire-value-entry.c +++ b/src/ui/gui/psppire-value-entry.c @@ -28,7 +28,7 @@ static void psppire_value_entry_finalize (GObject *); G_DEFINE_TYPE (PsppireValueEntry, psppire_value_entry, - GTK_TYPE_COMBO_BOX_ENTRY); + GTK_TYPE_COMBO_BOX); enum { @@ -129,15 +129,42 @@ psppire_value_entry_get_property (GObject *object, } } +static void +psppire_value_entry_text_changed (GtkEntryBuffer *buffer, + GParamSpec *pspec, + PsppireValueEntry *obj) +{ + obj->cur_value = NULL; +} + + +static void +on_realize (GtkWidget *w) +{ + GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (w))); + GtkEntryBuffer *buffer = gtk_entry_get_buffer (entry); + + gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (w), COL_LABEL); + + g_signal_connect (buffer, "notify::text", + G_CALLBACK (psppire_value_entry_text_changed), w); + + gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE); + + GTK_WIDGET_CLASS (psppire_value_entry_parent_class)->realize (w); +} + static void psppire_value_entry_class_init (PsppireValueEntryClass *class) { - GObjectClass *gobject_class; - gobject_class = G_OBJECT_CLASS (class); + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (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; + widget_class->realize = on_realize; g_object_class_install_property ( gobject_class, PROP_SHOW_VALUE_LABEL, @@ -197,28 +224,14 @@ psppire_value_entry_class_init (PsppireValueEntryClass *class) G_PARAM_READABLE | G_PARAM_WRITABLE)); } -static void -psppire_value_entry_text_changed (GtkEntryBuffer *buffer, - GParamSpec *pspec, - PsppireValueEntry *obj) -{ - obj->cur_value = NULL; -} - static void psppire_value_entry_init (PsppireValueEntry *obj) { - GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (obj))); - GtkEntryBuffer *buffer = gtk_entry_get_buffer (entry); - obj->show_value_label = true; obj->val_labs = NULL; obj->format = F_8_0; obj->encoding = NULL; obj->cur_value = NULL; - - g_signal_connect (buffer, "notify::text", - G_CALLBACK (psppire_value_entry_text_changed), obj); } static void @@ -235,13 +248,12 @@ psppire_value_entry_finalize (GObject *gobject) GtkWidget * psppire_value_entry_new (void) { - return GTK_WIDGET (g_object_new (PSPPIRE_TYPE_VALUE_ENTRY, NULL)); + return GTK_WIDGET (g_object_new (PSPPIRE_TYPE_VALUE_ENTRY, "has-entry", TRUE, NULL)); } static void psppire_value_entry_refresh_model (PsppireValueEntry *obj) { - GtkWidget *entry = gtk_bin_get_child (GTK_BIN (obj)); GtkTreeModel *model; GtkTreeModel *old_model; @@ -280,8 +292,8 @@ psppire_value_entry_refresh_model (PsppireValueEntry *obj) } gtk_combo_box_set_model (GTK_COMBO_BOX (obj), model); - gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (obj), COL_LABEL); - gtk_widget_set_sensitive (entry, model != NULL); + if (model != NULL) + g_object_unref (model); } void @@ -319,9 +331,7 @@ void psppire_value_entry_set_value_labels (PsppireValueEntry *obj, const struct val_labs *val_labs) { - if (val_labs != NULL - ? obj->val_labs == NULL || !val_labs_equal (obj->val_labs, val_labs) - : obj->val_labs != NULL) + if (!val_labs_equal (obj->val_labs, val_labs)) { obj->cur_value = NULL;