separate sack integration test binary
[pspp] / src / ui / gui / psppire-value-entry.c
index c45db101bb7c2f958e357acd81824ba97c315631..f3d7f99a8e6b9db5948e743b155c8b42bb95a6c7 100644 (file)
@@ -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,
@@ -72,7 +78,10 @@ psppire_value_entry_set_property (GObject      *object,
       break;
 
     case PROP_FORMAT:
-      psppire_value_entry_set_format (obj, g_value_get_boxed (value));
+      {
+        const struct fmt_spec *f = g_value_get_boxed (value);
+        psppire_value_entry_set_format (obj, *f);
+      }
       break;
 
     case PROP_ENCODING:
@@ -137,6 +146,11 @@ psppire_value_entry_text_changed (GtkEntryBuffer *buffer,
   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)
@@ -149,6 +163,9 @@ on_realize (GtkWidget *w)
   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);
@@ -243,6 +260,16 @@ psppire_value_entry_class_init (PsppireValueEntryClass *class)
                       0, MAX_STRING,
                       0,
                       G_PARAM_READABLE | G_PARAM_WRITABLE));
+
+  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
@@ -341,7 +368,7 @@ psppire_value_entry_set_variable (PsppireValueEntry *obj,
   if (var != NULL)
     {
       psppire_value_entry_set_value_labels (obj, var_get_value_labels (var));
-      obj->format = *var_get_print_format (var);
+      obj->format = var_get_print_format (var);
       psppire_value_entry_set_encoding (obj, var_get_encoding (var));
     }
   else
@@ -362,7 +389,7 @@ psppire_value_entry_set_value_labels (PsppireValueEntry *obj,
       if (val_labs != NULL)
         {
           int width = val_labs_get_width (val_labs);
-          if (width != fmt_var_width (&obj->format))
+          if (width != fmt_var_width (obj->format))
             obj->format = fmt_default_for_width (width);
         }
 
@@ -380,12 +407,12 @@ psppire_value_entry_get_value_labels (const PsppireValueEntry *obj)
 
 void
 psppire_value_entry_set_format (PsppireValueEntry *obj,
-                                const struct fmt_spec *format)
+                                struct fmt_spec format)
 {
-  if (!fmt_equal (format, &obj->format))
+  if (!fmt_equal (format, obj->format))
     {
       obj->cur_value = NULL;
-      obj->format = *format;
+      obj->format = format;
 
       if (obj->val_labs
           && val_labs_get_width (obj->val_labs) != fmt_var_width (format))
@@ -395,10 +422,10 @@ psppire_value_entry_set_format (PsppireValueEntry *obj,
     }
 }
 
-const struct fmt_spec *
+struct fmt_spec
 psppire_value_entry_get_format (const PsppireValueEntry *obj)
 {
-  return &obj->format;
+  return obj->format;
 }
 
 void
@@ -420,17 +447,17 @@ psppire_value_entry_get_encoding (const PsppireValueEntry *obj)
 void
 psppire_value_entry_set_width (PsppireValueEntry *obj, int width)
 {
-  if (width != fmt_var_width (&obj->format))
+  if (width != fmt_var_width (obj->format))
     {
       struct fmt_spec format = fmt_default_for_width (width);
-      psppire_value_entry_set_format (obj, &format);
+      psppire_value_entry_set_format (obj, format);
     }
 }
 
 int
 psppire_value_entry_get_width (const PsppireValueEntry *obj)
 {
-  return fmt_var_width (&obj->format);
+  return fmt_var_width (obj->format);
 }
 
 void
@@ -442,6 +469,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);
@@ -453,7 +484,7 @@ psppire_value_entry_set_value (PsppireValueEntry *obj,
         }
     }
 
-  string = value_to_text__ (*value, &obj->format, obj->encoding);
+  string = value_to_text__ (*value, obj->format, obj->encoding);
   gtk_entry_set_text (entry, string);
   g_free (string);
 }
@@ -466,7 +497,7 @@ psppire_value_entry_get_value (PsppireValueEntry *obj,
   GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (obj)));
   GtkTreeIter iter;
 
-  g_return_val_if_fail (fmt_var_width (&obj->format) == width, FALSE);
+  g_return_val_if_fail (fmt_var_width (obj->format) == width, FALSE);
 
   if (obj->cur_value)
     {
@@ -489,7 +520,7 @@ psppire_value_entry_get_value (PsppireValueEntry *obj,
 
       new_text = gtk_entry_get_text (entry);
       return data_in_msg (ss_cstr (new_text), UTF8,
-                          obj->format.type,
+                          obj->format.type, settings_get_fmt_settings (),
                           value, width, obj->encoding);
     }
 }