New file: builder-wrapper.h and builder-wrapper.c
[pspp-builds.git] / src / ui / gui / missing-val-dialog.c
index 8efbaf975d90acad6154da39b2aab9d53af24164..3e42036cb17260bf3c38c2c04d4ffa9cbd382c17 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2005, 2006, 2009  Free Software Foundation
+   Copyright (C) 2005, 2006, 2009, 2011, 2012  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
 #define N_(msgid) msgid
 
 
+#include "builder-wrapper.h"
 #include "helper.h"
 #include <data/format.h>
 #include "missing-val-dialog.h"
@@ -80,8 +81,6 @@ missing_val_dialog_accept (GtkWidget *w, gpointer data)
 {
   struct missing_val_dialog *dialog = data;
 
-  const struct fmt_spec *write_spec = var_get_write_format (dialog->pv);
-
   if ( gtk_toggle_button_get_active (dialog->button_discrete))
     {
       gint nvals = 0;
@@ -100,7 +99,7 @@ missing_val_dialog_accept (GtkWidget *w, gpointer data)
              continue;
            }
 
-         if ( text_to_value (text, &v, *write_spec))
+         if ( text_to_value (text, dialog->pv, &v))
            {
              nvals++;
              mv_add_value (&dialog->mvl, &v);
@@ -108,6 +107,7 @@ missing_val_dialog_accept (GtkWidget *w, gpointer data)
          else
              badvals++;
          g_free (text);
+         value_destroy (&v, var_get_width (dialog->pv));
        }
       if ( nvals == 0 || badvals > 0 )
        {
@@ -126,14 +126,16 @@ missing_val_dialog_accept (GtkWidget *w, gpointer data)
       const gchar *low_text = gtk_entry_get_text (GTK_ENTRY (dialog->low));
       const gchar *high_text = gtk_entry_get_text (GTK_ENTRY (dialog->high));
 
-      if ( text_to_value (low_text, &low_val, *write_spec)
+      if ( text_to_value (low_text, dialog->pv, &low_val)
           &&
-          text_to_value (high_text, &high_val, *write_spec) )
+          text_to_value (high_text, dialog->pv, &high_val))
        {
          if ( low_val.f > high_val.f )
            {
              err_dialog (_("Incorrect range specification"),
                          GTK_WINDOW (dialog->window));
+             value_destroy (&low_val, var_get_width (dialog->pv));
+             value_destroy (&high_val, var_get_width (dialog->pv));
              return ;
            }
        }
@@ -141,6 +143,8 @@ missing_val_dialog_accept (GtkWidget *w, gpointer data)
        {
          err_dialog (_("Incorrect range specification"),
                      GTK_WINDOW (dialog->window));
+         value_destroy (&low_val, var_get_width (dialog->pv));
+         value_destroy (&high_val, var_get_width (dialog->pv));
          return;
        }
 
@@ -150,18 +154,24 @@ missing_val_dialog_accept (GtkWidget *w, gpointer data)
       mv_clear (&dialog->mvl);
       mv_add_range (&dialog->mvl, low_val.f, high_val.f);
 
+      value_destroy (&low_val, var_get_width (dialog->pv));
+      value_destroy (&high_val, var_get_width (dialog->pv));
+
       if ( discrete_text && strlen (g_strstrip (discrete_text)) > 0 )
        {
          union value discrete_val;
-         if ( !text_to_value (discrete_text, &discrete_val,
-                             *write_spec))
+         if ( !text_to_value (discrete_text, 
+                              dialog->pv,
+                              &discrete_val))
            {
              err_dialog (_("Incorrect value for variable type"),
                         GTK_WINDOW (dialog->window) );
              g_free (discrete_text);
+             value_destroy (&discrete_val, var_get_width (dialog->pv));
              return;
            }
          mv_add_value (&dialog->mvl, &discrete_val);
+         value_destroy (&discrete_val, var_get_width (dialog->pv));
        }
       g_free (discrete_text);
     }
@@ -274,16 +284,12 @@ missing_val_dialog_create (GtkWindow *toplevel)
 void
 missing_val_dialog_show (struct missing_val_dialog *dialog)
 {
-  const struct fmt_spec *write_spec ;
-
   gint i;
   g_return_if_fail (dialog);
   g_return_if_fail (dialog->pv);
 
   mv_copy (&dialog->mvl, var_get_missing_values (dialog->pv));
 
-  write_spec = var_get_write_format (dialog->pv);
-
   /* Blank all entry boxes and make them insensitive */
   gtk_entry_set_text (GTK_ENTRY (dialog->low), "");
   gtk_entry_set_text (GTK_ENTRY (dialog->high), "");
@@ -309,8 +315,9 @@ missing_val_dialog_show (struct missing_val_dialog *dialog)
       gchar *high_text;
       mv_get_range (&dialog->mvl, &low.f, &high.f);
 
-      low_text = value_to_text (low, *write_spec);
-      high_text = value_to_text (high, *write_spec);
+
+      low_text = value_to_text (low, dialog->pv);
+      high_text = value_to_text (high, dialog->pv);
 
       gtk_entry_set_text (GTK_ENTRY (dialog->low), low_text);
       gtk_entry_set_text (GTK_ENTRY (dialog->high), high_text);
@@ -320,7 +327,7 @@ missing_val_dialog_show (struct missing_val_dialog *dialog)
       if ( mv_has_value (&dialog->mvl))
        {
          gchar *text;
-         text = value_to_text (*mv_get_value (&dialog->mvl, 0), *write_spec);
+         text = value_to_text (*mv_get_value (&dialog->mvl, 0), dialog->pv);
          gtk_entry_set_text (GTK_ENTRY (dialog->discrete), text);
          g_free (text);
        }
@@ -341,8 +348,7 @@ missing_val_dialog_show (struct missing_val_dialog *dialog)
            {
              gchar *text ;
 
-             text = value_to_text (*mv_get_value (&dialog->mvl, i),
-                                    *write_spec);
+             text = value_to_text (*mv_get_value (&dialog->mvl, i), dialog->pv);
              gtk_entry_set_text (GTK_ENTRY (dialog->mv[i]), text);
              g_free (text);
            }