Make the missing value code do more work, so that its callers can do
[pspp-builds.git] / src / ui / gui / missing-val-dialog.c
index ec136cd0cf918a429ae0249ec34756c616e43c39..3495171037f9b4007cf02fd8e31a3adcea13d489 100644 (file)
@@ -1,7 +1,6 @@
-/* 
+/*
     PSPPIRE --- A Graphical User Interface for PSPP
     Copyright (C) 2005, 2006  Free Software Foundation
-    Written by John Darrington
 
     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
 /*  This module describes the behaviour of the Missing Values dialog box,
     used for input of the missing values in the variable sheet */
 
+#include <config.h>
+#include <gettext.h>
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+
 #include "helper.h"
 #include "missing-val-dialog.h"
 #include <data/missing-values.h>
 #include <data/variable.h>
 #include <data/data-in.h>
-#include "psppire-variable.h"
+
 
 #include <gtk/gtk.h>
 #include <glade/glade.h>
 
 #include <string.h>
 
-#define _(A) A
 
 /* A simple (sub) dialog box for displaying user input errors */
 static void
 err_dialog(const gchar *msg, GtkWindow *window)
 {
+  GtkWidget *hbox ;
   GtkWidget *label = gtk_label_new (msg);
 
   GtkWidget *dialog = 
@@ -60,7 +65,7 @@ err_dialog(const gchar *msg, GtkWindow *window)
                            G_CALLBACK (gtk_widget_destroy),
                            dialog);
 
-  GtkWidget *hbox = gtk_hbox_new(FALSE, 10);
+  hbox = gtk_hbox_new(FALSE, 10);
 
   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
                     hbox);
@@ -78,14 +83,14 @@ missing_val_dialog_accept(GtkWidget *w, gpointer data)
 {
   struct missing_val_dialog *dialog = data;
 
-  const struct fmt_spec *write_spec = psppire_variable_get_write_spec(dialog->pv);
+  const struct fmt_spec *write_spec = var_get_write_format (dialog->pv);
   
   if ( gtk_toggle_button_get_active(dialog->button_discrete))
     {
       gint nvals = 0;
       gint badvals = 0;
       gint i;
-      mv_set_type(&dialog->mvl, MV_NONE);
+      mv_clear(&dialog->mvl);
       for(i = 0 ; i < 3 ; ++i ) 
        {
          gchar *text = 
@@ -117,6 +122,7 @@ missing_val_dialog_accept(GtkWidget *w, gpointer data)
   
   if (gtk_toggle_button_get_active(dialog->button_range))
     {
+      gchar *discrete_text ;
       
       union value low_val ; 
       union value high_val;
@@ -141,11 +147,10 @@ missing_val_dialog_accept(GtkWidget *w, gpointer data)
          return;
        }
 
-      gchar *discrete_text = 
+      discrete_text = 
        g_strdup(gtk_entry_get_text(GTK_ENTRY(dialog->discrete)));
 
-
-      mv_set_type(&dialog->mvl, MV_NONE);
+      mv_clear(&dialog->mvl);
       mv_add_num_range(&dialog->mvl, low_val.f, high_val.f);
       
       if ( discrete_text && strlen(g_strstrip(discrete_text)) > 0 )
@@ -166,11 +171,11 @@ missing_val_dialog_accept(GtkWidget *w, gpointer data)
 
   
   if (gtk_toggle_button_get_active(dialog->button_none))
-    mv_set_type(&dialog->mvl, MV_NONE);
+    mv_clear(&dialog->mvl);
 
-  psppire_variable_set_missing(dialog->pv, &dialog->mvl);
+  var_set_missing_values (dialog->pv, &dialog->mvl);
 
-  gtk_widget_hide(dialog->window);
+  gtk_widget_hide (dialog->window);
 }
 
 
@@ -254,13 +259,15 @@ missing_val_dialog_create(GladeXML *xml)
 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, psppire_variable_get_missing(dialog->pv));
+  mv_copy (&dialog->mvl, var_get_missing_values (dialog->pv));
 
-  const struct fmt_spec *write_spec = psppire_variable_get_write_spec(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), "");
@@ -270,10 +277,11 @@ missing_val_dialog_show(struct missing_val_dialog *dialog)
   gtk_widget_set_sensitive(dialog->high, FALSE);      
   gtk_widget_set_sensitive(dialog->discrete, FALSE);   
 
-  gtk_widget_set_sensitive(GTK_WIDGET(dialog->button_range), 
-                          psppire_variable_get_type(dialog->pv) == NUMERIC);
+  gtk_widget_set_sensitive(GTK_WIDGET(dialog->button_range),
+                          var_is_numeric (dialog->pv));
 
-  for(i = 0 ; i < 3 ; ++i ) 
+
+  for(i = 0 ; i < 3 ; ++i )
     {
       gtk_entry_set_text(GTK_ENTRY(dialog->mv[i]), "");          
       gtk_widget_set_sensitive(dialog->mv[i], FALSE);
@@ -318,10 +326,11 @@ missing_val_dialog_show(struct missing_val_dialog *dialog)
        {
          if ( i < n)
            {
+             gchar *text ;
              union value value;
 
              mv_peek_value(&dialog->mvl, &value, i);
-             gchar *text = value_to_text(value, *write_spec);
+             text = value_to_text(value, *write_spec);
              gtk_entry_set_text(GTK_ENTRY(dialog->mv[i]), text);
              g_free(text);
            }