X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-value-entry.c;h=650fed8c144e2cdd0d2654f669cf4e4c71c6868d;hb=bf62643ef9f4f991acd777b26aa747adc7886d8f;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..650fed8c14 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 { @@ -48,6 +48,12 @@ enum PROP_WIDTH }; +enum {EDIT_DONE, /* Emitted when the entry has changed and is ready to be fetched */ + n_SIGNALS}; + +static guint signals [n_SIGNALS]; + + static void psppire_value_entry_set_property (GObject *object, guint prop_id, @@ -129,15 +135,71 @@ 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_entry_activate (GtkWidget *w) +{ + g_signal_emit (w, signals [EDIT_DONE], 0); +} + +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); + + g_signal_connect_swapped (entry, "activate", + G_CALLBACK (on_entry_activate), w); + + gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE); + + 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) { - 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; + gobject_class->constructor = my_constructor; + widget_class->realize = on_realize; g_object_class_install_property ( gobject_class, PROP_SHOW_VALUE_LABEL, @@ -195,30 +257,26 @@ psppire_value_entry_class_init (PsppireValueEntryClass *class) 0, MAX_STRING, 0, G_PARAM_READABLE | G_PARAM_WRITABLE)); -} -static void -psppire_value_entry_text_changed (GtkEntryBuffer *buffer, - GParamSpec *pspec, - PsppireValueEntry *obj) -{ - obj->cur_value = NULL; + signals [EDIT_DONE] = + g_signal_new ("edit-done", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); } 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 @@ -241,7 +299,6 @@ psppire_value_entry_new (void) 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 +337,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 +376,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; @@ -411,6 +466,10 @@ psppire_value_entry_set_value (PsppireValueEntry *obj, gchar *string; obj->cur_value = NULL; + + if (value == NULL) + return; + if (obj->show_value_label) { struct val_lab *vl = val_labs_lookup (obj->val_labs, value);