Here's a new set of patched for review.

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://keys.gnupg.net or any PGP keyserver for public key.

From ef7b72888aa4259c4435426677db571daa49ec0b Mon Sep 17 00:00:00 2001
From: John Darrington <j...@darrington.wattle.id.au>
Date: Mon, 23 Apr 2012 20:54:29 +0200
Subject: [PATCH 1/5] val_labs_equal: Accept null pointers

Instead of checking for NULL before calling val_labs_equal, put the onus
on the function itself to deal with null pointers and behave appropriately.
---
 src/data/value-labels.c          |    6 ++++++
 src/ui/gui/psppire-value-entry.c |    4 +---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/data/value-labels.c b/src/data/value-labels.c
index 0b2ae3f..679f4d1 100644
--- a/src/data/value-labels.c
+++ b/src/data/value-labels.c
@@ -362,6 +362,12 @@ val_labs_equal (const struct val_labs *a, const struct val_labs *b)
 {
   const struct val_lab *label;
 
+  if (a == b)
+    return true;
+
+  if ( ( a == NULL && b != NULL) || (b == NULL && a != NULL))
+    return false;
+
   if (val_labs_count (a) != val_labs_count (b) || a->width != b->width)
     return false;
 
diff --git a/src/ui/gui/psppire-value-entry.c b/src/ui/gui/psppire-value-entry.c
index 675df83..4acb4fe 100644
--- a/src/ui/gui/psppire-value-entry.c
+++ b/src/ui/gui/psppire-value-entry.c
@@ -310,9 +310,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;
 
-- 
1.7.2.5

From 6c046bf4d661798073bc97ce0cb807eed67fff12 Mon Sep 17 00:00:00 2001
From: John Darrington <j...@darrington.wattle.id.au>
Date: Mon, 23 Apr 2012 21:08:21 +0200
Subject: [PATCH 2/5] PsppireValueEntry: Clear the entry, when the underlying model changes.

Since the labels will have changed, the existing text is most likely
inappropriate.
---
 src/ui/gui/psppire-value-entry.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/ui/gui/psppire-value-entry.c b/src/ui/gui/psppire-value-entry.c
index 4acb4fe..85dbaa0 100644
--- a/src/ui/gui/psppire-value-entry.c
+++ b/src/ui/gui/psppire-value-entry.c
@@ -243,6 +243,7 @@ psppire_value_entry_refresh_model (PsppireValueEntry *obj)
 {
   GtkWidget *entry = gtk_bin_get_child (GTK_BIN (obj));
   GtkTreeModel *model;
+  GtkTreeModel *old_model;
 
   if (val_labs_count (obj->val_labs) > 0)
     {
@@ -270,6 +271,14 @@ psppire_value_entry_refresh_model (PsppireValueEntry *obj)
   else
     model = NULL;
 
+  old_model = gtk_combo_box_get_model (GTK_COMBO_BOX (obj));
+
+  if (old_model != model)
+    {
+      GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (obj)));
+      gtk_entry_set_text (entry, "");
+    }
+
   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);
-- 
1.7.2.5

From 4c2e195ca63240c1f6ad9b6b75d761f54ee94f77 Mon Sep 17 00:00:00 2001
From: John Darrington <j...@darrington.wattle.id.au>
Date: Mon, 23 Apr 2012 21:12:04 +0200
Subject: [PATCH 3/5] PsppireValueEntry: unref old model before setting the new one

---
 src/ui/gui/psppire-value-entry.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/ui/gui/psppire-value-entry.c b/src/ui/gui/psppire-value-entry.c
index 85dbaa0..44ad2d0 100644
--- a/src/ui/gui/psppire-value-entry.c
+++ b/src/ui/gui/psppire-value-entry.c
@@ -278,6 +278,8 @@ psppire_value_entry_refresh_model (PsppireValueEntry *obj)
       GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (obj)));
       gtk_entry_set_text (entry, "");
     }
+  else if (old_model)
+    g_object_unref (old_model);
 
   gtk_combo_box_set_model (GTK_COMBO_BOX (obj), model);
   gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (obj), COL_LABEL);
-- 
1.7.2.5

From 45af0b16f93d7e810659f827fc076e8e8601404a Mon Sep 17 00:00:00 2001
From: John Darrington <j...@darrington.wattle.id.au>
Date: Mon, 23 Apr 2012 21:38:17 +0200
Subject: [PATCH 4/5] PsppireValueEntry: Use gtk_combo_box_set_button_sensitivity instead of gtk_widget_sensitivity

---
 src/ui/gui/psppire-value-entry.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/ui/gui/psppire-value-entry.c b/src/ui/gui/psppire-value-entry.c
index 44ad2d0..efe92da 100644
--- a/src/ui/gui/psppire-value-entry.c
+++ b/src/ui/gui/psppire-value-entry.c
@@ -219,6 +219,9 @@ psppire_value_entry_init (PsppireValueEntry *obj)
 
   g_signal_connect (buffer, "notify::text",
                     G_CALLBACK (psppire_value_entry_text_changed), obj);
+
+  gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (obj), COL_LABEL);
+  gtk_combo_box_set_button_sensitivity (GTK_COMBO_BOX (obj), GTK_SENSITIVITY_AUTO);
 }
 
 static void
@@ -241,7 +244,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;
 
@@ -282,8 +284,7 @@ psppire_value_entry_refresh_model (PsppireValueEntry *obj)
     g_object_unref (old_model);
 
   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);
+
 }
 
 void
-- 
1.7.2.5

From 42bb1b46b3054be7272c65c9b1bf4339f2399c60 Mon Sep 17 00:00:00 2001
From: John Darrington <j...@darrington.wattle.id.au>
Date: Mon, 23 Apr 2012 21:40:17 +0200
Subject: [PATCH 5/5] ROC Dialog: Use PsppireValueEntry as the state value entry widget

---
 src/ui/gui/psppire-dialog-action-roc.c |   81 +++++++++++++++++++++++---------
 src/ui/gui/roc.ui                      |    4 +-
 src/ui/gui/widgets.c                   |    2 +
 3 files changed, 63 insertions(+), 24 deletions(-)

diff --git a/src/ui/gui/psppire-dialog-action-roc.c b/src/ui/gui/psppire-dialog-action-roc.c
index fc0bb7b..babd4b3 100644
--- a/src/ui/gui/psppire-dialog-action-roc.c
+++ b/src/ui/gui/psppire-dialog-action-roc.c
@@ -18,6 +18,7 @@
 #include <config.h>
 
 #include "psppire-dialog-action-roc.h"
+#include "psppire-value-entry.h"
 
 #include "dialog-common.h"
 #include <ui/syntax-gen.h>
@@ -37,8 +38,12 @@ G_DEFINE_TYPE (PsppireDialogActionRoc, psppire_dialog_action_roc, PSPPIRE_TYPE_D
 static gboolean
 dialog_state_valid (gpointer data)
 {
+  int width;
+  gboolean result ;
+  union value val;
   PsppireDialogActionRoc *rd = data;
-  const gchar *text;
+  const gchar *var_name;
+  const struct variable *var;
 
   GtkTreeModel *liststore =
     gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
@@ -46,18 +51,24 @@ dialog_state_valid (gpointer data)
   if  (gtk_tree_model_iter_n_children (liststore, NULL) < 1)
     return FALSE;
 
-  
-  text = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
-  if ( 0 == strcmp ("", text))
-    return FALSE;
+  var_name = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
 
+  var = psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION (rd)->dict, var_name);
 
-  text = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
-  if ( 0 == strcmp ("", text))
+  if ( var == NULL)
     return FALSE;
 
+  width = var_get_width (var);
+  value_init (&val, width);
+
+  result = psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (rd->state_value), &val, width);
+  
+  if (var_is_value_missing (var, &val, MV_SYSTEM))
+      result = FALSE;
+  
+  value_destroy (&val, width);
 
-  return TRUE;
+  return result;
 }
 
 static void
@@ -85,7 +96,7 @@ refresh (PsppireDialogAction *rd_)
   gtk_list_store_clear (GTK_LIST_STORE (liststore));
 
   gtk_entry_set_text (GTK_ENTRY (rd->state_variable), "");
-  gtk_entry_set_text (GTK_ENTRY (rd->state_value), "");
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (rd->state_value), NULL);
 
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->curve),          TRUE);
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->reference),      FALSE);
@@ -94,6 +105,23 @@ refresh (PsppireDialogAction *rd_)
 }
 
 static void
+on_state_var_changed (GtkAction *a)
+{
+  PsppireDialogActionRoc *act = PSPPIRE_DIALOG_ACTION_ROC (a);
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+
+  const gchar *var_name = gtk_entry_get_text (GTK_ENTRY(act->state_variable));
+
+  const struct variable *var =
+    psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(act)->dict, var_name);
+
+  if ( var == NULL)
+    return;
+
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (act->state_value), var);
+}
+
+static void
 psppire_dialog_action_roc_activate (GtkAction *a)
 {
   PsppireDialogActionRoc *act = PSPPIRE_DIALOG_ACTION_ROC (a);
@@ -102,7 +130,6 @@ psppire_dialog_action_roc_activate (GtkAction *a)
   GtkBuilder *xml = builder_new ("roc.ui");
   pda->dialog = get_widget_assert   (xml, "roc-dialog");
   pda->source = get_widget_assert   (xml, "dict-view");
-  pda->source = get_widget_assert   (xml, "dict-view");
 
   act->test_variables    = get_widget_assert   (xml, "psppire-var-view1");
   act->state_variable    = get_widget_assert   (xml, "entry1");
@@ -113,6 +140,9 @@ psppire_dialog_action_roc_activate (GtkAction *a)
   act->standard_error = get_widget_assert   (xml, "standard-error");
   act->coordinates    = get_widget_assert   (xml, "co-ordinates");
 
+  g_signal_connect_swapped (act->state_variable, "changed",
+			    G_CALLBACK (on_state_var_changed), act);
+
   g_object_unref (xml);
 
   g_signal_connect (act->curve, "toggled",
@@ -145,23 +175,30 @@ generate_syntax (PsppireDialogAction *a)
 
   g_string_append (string, " (");
   {
-    const gchar *value = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
+    const struct variable *var =
+      psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(rd)->dict, var_name);
+
+    union value val;
+    value_init (&val, var_get_width (var));
 
-    const struct variable *var = psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(rd)->dict, var_name);
+    psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (rd->state_value),
+				   &val, var_get_width (var));
 
     g_return_val_if_fail (var, NULL);
 
-    if ( var_is_alpha (var))
-      {
-	struct string str;
-	ds_init_empty (&str);
-	syntax_gen_string (&str, ss_cstr (value));
-	g_string_append (string, ds_cstr (&str));
-	ds_destroy (&str);
-      }
-    else
-      g_string_append (string, value);
+    {
+      struct string str;
+      ds_init_empty (&str);
+      
+      syntax_gen_value (&str, &val, var_get_width (var),
+			var_get_print_format (var));
+      
+      g_string_append (string, ds_cstr (&str));
+      ds_destroy (&str);
+    }
+    value_destroy (&val, var_get_width (var));
   }
+
   g_string_append (string, ")");
 
 
diff --git a/src/ui/gui/roc.ui b/src/ui/gui/roc.ui
index 87f0c98..6b195b2 100644
--- a/src/ui/gui/roc.ui
+++ b/src/ui/gui/roc.ui
@@ -1,3 +1,4 @@
+
 <?xml version="1.0"?>
 <interface>
   <requires lib="psppire" version="2054.17080"/>
@@ -180,10 +181,9 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkEntry" id="entry2">
+                      <object class="PsppireValueEntry" id="entry2">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <property name="invisible_char">&#x2022;</property>
                       </object>
                       <packing>
                         <property name="position">1</property>
diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c
index ed8328a..8c64f52 100644
--- a/src/ui/gui/widgets.c
+++ b/src/ui/gui/widgets.c
@@ -23,6 +23,7 @@
 #include "psppire-dialog-action-roc.h"
 #include "psppire-dialog-action-sort.h"
 #include "psppire-dialog-action-var-info.h"
+#include "psppire-value-entry.h"
 
 
 /* Any custom widgets which are to be used in GtkBuilder ui files
@@ -40,6 +41,7 @@ preregister_widgets (void)
   psppire_acr_get_type ();
   psppire_dict_view_get_type ();
   psppire_var_view_get_type ();
+  psppire_value_entry_get_type ();
 
   psppire_dialog_action_correlation_get_type ();
   psppire_dialog_action_descriptives_get_type ();
-- 
1.7.2.5

Attachment: signature.asc
Description: Digital signature

_______________________________________________
pspp-dev mailing list
pspp-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/pspp-dev

Reply via email to