Persist dialog box widget settings.
[pspp] / src / ui / gui / psppire-dialog-action-frequencies.c
index 6f8049009eb5524361e167854042d3797fed555c..490a735f53b7cd7cbda8739b802f04c518887123 100644 (file)
@@ -1,18 +1,18 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-Copyright (C) 2012  Free Software Foundation
+   Copyright (C) 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
-             the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
+   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
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-     This program is distributed in the hope that it will be useful,
-     but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 
 #include <config.h>
@@ -27,7 +27,7 @@ This program is free software: you can redistribute it and/or modify
 
 #include "psppire-dialog.h"
 #include "builder-wrapper.h"
-#include "checkbox-treeview.h"
+#include "psppire-checkbox-treeview.h"
 #include "psppire-dict.h"
 #include "libpspp/str.h"
 
@@ -178,6 +178,10 @@ on_charts_clicked (PsppireDialogActionFrequencies *fd)
 
   g_signal_emit_by_name (fd->pie, "toggled");
 
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd->bar), fd->charts_opts_draw_bar);
+  g_signal_emit_by_name (fd->bar, "toggled");
+
   ret = psppire_dialog_run (PSPPIRE_DIALOG (fd->charts_dialog));
 
   if ( ret == PSPPIRE_RESPONSE_CONTINUE )
@@ -198,6 +202,9 @@ on_charts_clicked (PsppireDialogActionFrequencies *fd)
        fd->charts_opts_draw_pie = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->pie));
        fd->charts_opts_pie_include_missing
           = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->pie_include_missing));
+
+
+       fd->charts_opts_draw_bar = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->bar));
     }
 }
 
@@ -252,7 +259,13 @@ psppire_dialog_action_frequencies_activate (GtkAction * a)
   PsppireDialogActionFrequencies *act = PSPPIRE_DIALOG_ACTION_FREQUENCIES (a);
   PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
 
-  GtkBuilder *xml = builder_new ("frequencies.ui");
+  GHashTable *thing = psppire_dialog_action_get_pointer (pda);
+  GtkBuilder *xml = g_hash_table_lookup (thing, a);
+  if (!xml)
+    {
+      xml = builder_new ("frequencies.ui");
+      g_hash_table_insert (thing, a, xml);
+    }
 
   GtkWidget *stats_treeview = get_widget_assert (xml, "stats-treeview");
   GtkWidget *tables_button = get_widget_assert (xml, "tables-button");
@@ -263,7 +276,7 @@ psppire_dialog_action_frequencies_activate (GtkAction * a)
 
   act->stat_vars = get_widget_assert (xml, "var-treeview");
 
-  put_checkbox_items_in_treeview (GTK_TREE_VIEW (stats_treeview),
+  psppire_checkbox_treeview_populate (PSPPIRE_CHECKBOX_TREEVIEW (stats_treeview),
                                   B_FS_DEFAULT, N_FREQUENCY_STATS, stats);
 
   act->stats = gtk_tree_view_get_model (GTK_TREE_VIEW (stats_treeview));
@@ -295,6 +308,7 @@ psppire_dialog_action_frequencies_activate (GtkAction * a)
   act->charts_opts_draw_normal = false;
   act->charts_opts_scale = FRQ_FREQ;
   act->charts_opts_draw_pie = false;
+  act->charts_opts_draw_bar = false;
   act->charts_opts_pie_include_missing = false;
 
   act->freqs = get_widget_assert (xml, "freqs");
@@ -317,9 +331,7 @@ psppire_dialog_action_frequencies_activate (GtkAction * a)
   act->pie =  (get_widget_assert (xml, "pie"));
   act->pie_include_missing = get_widget_assert (xml, "pie-include-missing");
 
-
-  g_object_unref (xml);
-
+  act->bar =  (get_widget_assert (xml, "bar"));
 
   act->tables_opts_order = FRQ_AVALUE;
   act->tables_opts_table = FRQ_TABLE;
@@ -461,6 +473,21 @@ generate_syntax (PsppireDialogAction * a)
         ds_put_c_format (&str, " MAX(%.15g)", fd->charts_opts_max);
     }
 
+
+  if (fd->charts_opts_draw_bar)
+    {
+      ds_put_cstr (&str, "\n\t/BARCHART=");
+
+      if (fd->charts_opts_scale == FRQ_PERCENT)
+        ds_put_cstr (&str, " PERCENT");
+
+      if (fd->charts_opts_use_min)
+        ds_put_c_format (&str, " MIN(%.15g)", fd->charts_opts_min);
+      if (fd->charts_opts_use_max)
+        ds_put_c_format (&str, " MAX(%.15g)", fd->charts_opts_max);
+    }
+
+
   ds_put_cstr (&str, ".\n");
 
   text = ds_steal_cstr (&str);
@@ -473,10 +500,7 @@ generate_syntax (PsppireDialogAction * a)
 static void
 psppire_dialog_action_frequencies_class_init (PsppireDialogActionFrequenciesClass *class)
 {
-  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
-
-  action_class->activate = psppire_dialog_action_frequencies_activate;
-
+  psppire_dialog_action_set_activation (class, psppire_dialog_action_frequencies_activate);
   PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
 }