Removed some calls to deprecated Gtk functions
[pspp-builds.git] / src / ui / gui / t-test-options.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2007  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 #include <config.h>
20 #include <gtk/gtk.h>
21
22 #include "psppire-dialog.h"
23 #include <gl/xalloc.h>
24 #include "helper.h"
25 #include "t-test-options.h"
26
27 #include "widget-io.h"
28
29 #include <gettext.h>
30 #define _(msgid) gettext (msgid)
31 #define N_(msgid) msgid
32
33
34 enum exclude_mode
35   {
36     EXCL_ANALYSIS,
37     EXCL_LISTWISE
38   };
39
40 struct tt_options_dialog
41 {
42   GtkWidget *dialog;
43   GtkWidget *box;
44   GtkWidget *confidence;
45   GtkSpinButton *conf_percent;
46   GtkToggleButton *analysis;
47   GtkToggleButton *listwise;
48
49   gdouble confidence_interval;
50   gboolean non_default_options;
51   enum exclude_mode excl;
52 };
53
54 struct tt_options_dialog *
55 tt_options_dialog_create (GtkBuilder *xml, GtkWindow *parent)
56 {
57   struct tt_options_dialog *tto = xmalloc (sizeof (*tto));
58
59   tto->confidence =
60     widget_scanf (_("Confidence Interval: %2d %%"),
61                   &tto->conf_percent);
62
63   tto->dialog = get_widget_assert (xml, "options-dialog");
64
65   tto->box =   get_widget_assert (xml, "vbox1");
66
67   tto->analysis = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "radiobutton1"));
68   tto->listwise = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "radiobutton2"));
69
70   gtk_widget_show (tto->confidence);
71
72   psppire_box_pack_start_defaults (GTK_BOX (tto->box), tto->confidence);
73
74   gtk_window_set_transient_for (GTK_WINDOW (tto->dialog), parent);
75
76   tto->confidence_interval = 95;
77   tto->excl = EXCL_ANALYSIS;
78
79   return tto;
80 }
81
82
83 void
84 tt_options_dialog_destroy (struct tt_options_dialog *tto)
85 {
86   gtk_container_remove (GTK_CONTAINER (tto->box), tto->confidence);
87   g_free (tto);
88 }
89
90
91 void
92 tt_options_dialog_run (struct tt_options_dialog *tto)
93 {
94   gint response;
95
96   if ( tto->excl == EXCL_ANALYSIS)
97     gtk_toggle_button_set_active (tto->analysis, TRUE);
98   else
99     gtk_toggle_button_set_active (tto->listwise, TRUE);
100
101   gtk_spin_button_set_value (tto->conf_percent, tto->confidence_interval);
102
103   response = psppire_dialog_run (PSPPIRE_DIALOG (tto->dialog));
104
105   if ( response == PSPPIRE_RESPONSE_CONTINUE)
106     {
107       tto->non_default_options = TRUE;
108
109       tto->confidence_interval = gtk_spin_button_get_value (tto->conf_percent);
110       if ( gtk_toggle_button_get_active (tto->analysis) )
111         tto->excl = EXCL_ANALYSIS;
112       else
113         tto->excl = EXCL_LISTWISE;
114     }
115 }
116
117 void
118 tt_options_dialog_append_syntax (struct tt_options_dialog *tto, GString *str)
119 {
120   g_string_append (str, "\t/MISSING=");
121
122   if ( tto->excl == EXCL_ANALYSIS )
123     g_string_append (str, "ANALYSIS");
124   else
125     g_string_append (str, "LISTWISE");
126
127
128   g_string_append_printf (str, "\n\t/CRITERIA=CIN(%g)",
129                           tto->confidence_interval/100.0);
130 }