Change many %g format specifiers to %.*g with precision DBL_DIG + 1.
[pspp] / src / ui / gui / psppire-val-chooser.c
index 59225e274484828b8b176d73aaabe1e296c0c351..c2c273542cbb7c7872dd3b67f92027d01cc30782 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2011  Free Software Foundation
+   Copyright (C) 2011, 2014  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
@@ -16,7 +16,9 @@
 
 #include <config.h>
 
+#include <float.h>
 #include <gtk/gtk.h>
+#include "dialog-common.h"
 #include "psppire-val-chooser.h"
 
 #include "libpspp/str.h"
@@ -325,23 +327,15 @@ static GtkWidget * simple_entry (struct layout *l, struct range_widgets *rw)
 
 static struct layout range_opt[n_VAL_CHOOSER_BUTTONS]= 
   {
-    {N_("Value:"),                    simple_entry, simple_set },
-    {N_("System Missing"),            NULL,         sysmis_set },
-    {N_("System or User Missing"),    NULL,         missing_set},
-    {N_("Range:"),                    range_entry,  range_set  },
-    {N_("Range, LOWEST thru value"),  simple_entry, lo_up_set  },
-    {N_("Range, value thru HIGHEST"), simple_entry, hi_down_set},
-    {N_("All other values"),          NULL,         else_set   }
+    {N_("_Value:"),                    simple_entry, simple_set },
+    {N_("_System Missing"),            NULL,         sysmis_set },
+    {N_("System _or User Missing"),    NULL,         missing_set},
+    {N_("_Range:"),                    range_entry,  range_set  },
+    {N_("Range, _LOWEST thru value"),  simple_entry, lo_up_set  },
+    {N_("Range, value thru _HIGHEST"), simple_entry, hi_down_set},
+    {N_("_All other values"),          NULL,         else_set   }
   };
 
-static void
-set_sensitivity_from_toggle (GtkToggleButton *togglebutton,  GtkWidget *w)
-{
-  gboolean active = gtk_toggle_button_get_active (togglebutton);
-
-  gtk_widget_set_sensitive (w, active);
-}
-
 static void
 psppire_val_chooser_init (PsppireValChooser *vr)
 {
@@ -359,21 +353,25 @@ psppire_val_chooser_init (PsppireValChooser *vr)
     {
       struct layout *l = &range_opt[i];
       vr->rw[i].label = GTK_LABEL (gtk_label_new (gettext (l->label)));
+      gtk_label_set_use_underline (vr->rw[i].label, TRUE);
       vr->rw[i].rb = GTK_TOGGLE_BUTTON (gtk_radio_button_new (group));
-
-      gtk_widget_set_sensitive (GTK_WIDGET (vr->rw[i].label), FALSE);
-      g_signal_connect (vr->rw[i].rb, "toggled", G_CALLBACK (set_sensitivity_from_toggle), vr->rw[i].label);
+      gtk_label_set_mnemonic_widget (vr->rw[i].label, GTK_WIDGET (vr->rw[i].rb));
 
       gtk_misc_set_alignment (GTK_MISC (vr->rw[i].label), 0, 0.5);
 
       group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (vr->rw[i].rb));
 
-      gtk_table_attach_defaults (GTK_TABLE (table), GTK_WIDGET (vr->rw[i].rb), 0, 1,
-                                row, row + 1);
-
-
-      gtk_table_attach_defaults (GTK_TABLE (table), GTK_WIDGET (vr->rw[i].label), 1, 2,
-                                row, row + 1);
+      /* Attach the buttons */
+      gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (vr->rw[i].rb),
+                       0, 1,   row, row + 1,
+                       0, GTK_EXPAND | GTK_FILL,
+                       0, 0);
+
+      /* Attach the labels */
+      gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (vr->rw[i].label),
+                       1, 2,   row, row + 1,
+                       GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
+                       0, 0);
       ++row;
 
       if (l->fill)
@@ -455,7 +453,7 @@ old_value_to_string (const GValue *src, GValue *dest)
     {
     case OV_NUMERIC:
       {
-       gchar *text = g_strdup_printf ("%g", ov->v.v);
+       gchar *text = g_strdup_printf ("%.*g", DBL_DIG + 1, ov->v.v);
        g_value_set_string (dest, text);
        g_free (text);
       }
@@ -479,10 +477,10 @@ old_value_to_string (const GValue *src, GValue *dest)
 
        g_unichar_to_utf8 (0x2013, en_dash);
 
-       text = g_strdup_printf ("%g %s %g",
-                                      ov->v.range[0],
-                                      en_dash,
-                                      ov->v.range[1]);
+       text = g_strdup_printf ("%.*g %s %.*g",
+                                DBL_DIG + 1, ov->v.range[0],
+                                en_dash,
+                                DBL_DIG + 1, ov->v.range[1]);
        g_value_set_string (dest, text);
        g_free (text);
       }
@@ -494,9 +492,9 @@ old_value_to_string (const GValue *src, GValue *dest)
 
        g_unichar_to_utf8 (0x2013, en_dash);
 
-       text = g_strdup_printf ("LOWEST %s %g",
+       text = g_strdup_printf ("LOWEST %s %.*g",
                                en_dash,
-                               ov->v.range[1]);
+                               DBL_DIG + 1, ov->v.range[1]);
 
        g_value_set_string (dest, text);
        g_free (text);
@@ -509,8 +507,8 @@ old_value_to_string (const GValue *src, GValue *dest)
 
        g_unichar_to_utf8 (0x2013, en_dash);
 
-       text = g_strdup_printf ("%g %s HIGHEST",
-                               ov->v.range[0],
+       text = g_strdup_printf ("%.*g %s HIGHEST",
+                               DBL_DIG + 1, ov->v.range[0],
                                en_dash);
 
        g_value_set_string (dest, text);
@@ -546,46 +544,46 @@ old_value_get_type (void)
 
 /* Generate a syntax fragment for NV and append it to STR */
 void
-old_value_append_syntax (GString *str, const struct old_value *ov)
+old_value_append_syntax (struct string *str, const struct old_value *ov)
 {
   switch (ov->type)
     {
     case OV_NUMERIC:
-      g_string_append_printf (str, "%g", ov->v.v);
+      ds_put_c_format (str, "%.*g", DBL_DIG + 1, ov->v.v);
       break;
     case OV_STRING:
       {
        struct string ds = DS_EMPTY_INITIALIZER;
        syntax_gen_string (&ds, ss_cstr (ov->v.s));
-       g_string_append (str, ds_cstr (&ds));
+       ds_put_cstr (str, ds_cstr (&ds));
        ds_destroy (&ds);
       }
       break;
     case OV_MISSING:
-      g_string_append (str, "MISSING");
+      ds_put_cstr (str, "MISSING");
       break;
     case OV_SYSMIS:
-      g_string_append (str, "SYSMIS");
+      ds_put_cstr (str, "SYSMIS");
       break;
     case OV_ELSE:
-      g_string_append (str, "ELSE");
+      ds_put_cstr (str, "ELSE");
       break;
     case OV_RANGE:
-      g_string_append_printf (str, "%g THRU %g",
-                             ov->v.range[0],
-                             ov->v.range[1]);
+      ds_put_c_format (str, "%.*g THRU %.*g",
+                       DBL_DIG + 1, ov->v.range[0],
+                       DBL_DIG + 1, ov->v.range[1]);
       break;
     case OV_LOW_UP:
-      g_string_append_printf (str, "LOWEST THRU %g",
-                             ov->v.range[1]);
+      ds_put_c_format (str, "LOWEST THRU %*gg",
+                       DBL_DIG + 1, ov->v.range[1]);
       break;
     case OV_HIGH_DOWN:
-      g_string_append_printf (str, "%g THRU HIGHEST",
-                             ov->v.range[0]);
+      ds_put_c_format (str, "%.*g THRU HIGHEST",
+                       DBL_DIG + 1, ov->v.range[0]);
       break;
     default:
       g_warning ("Invalid type in old recode value");
-      g_string_append (str, "???");
+      ds_put_cstr (str, "???");
       break;
     };
 }
@@ -615,7 +613,7 @@ psppire_val_chooser_get_status (PsppireValChooser *vr, struct old_value *ov)
 static gchar *
 num_to_string (gdouble x)
 {
-  return g_strdup_printf ("%g", x);
+  return g_strdup_printf ("%.*g", DBL_DIG + 1, x);
 }