d4656bf4a457bc811a08219df7624e32ce610ca1
[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 #include "psppire-scanf.h"
29
30 #include <gettext.h>
31 #define _(msgid) gettext (msgid)
32 #define N_(msgid) msgid
33
34
35 enum exclude_mode
36   {
37     EXCL_ANALYSIS,
38     EXCL_LISTWISE
39   };
40
41 struct tt_options_dialog
42 {
43   GtkWidget *dialog;
44   GtkWidget *box;
45   GtkWidget *confidence;
46   GtkSpinButton *conf_percent;
47   GtkToggleButton *analysis;
48   GtkToggleButton *listwise;
49
50   gdouble confidence_interval;
51   gboolean non_default_options;
52   enum exclude_mode excl;
53   GtkBuilder *xml;
54 };
55
56 struct tt_options_dialog *
57 tt_options_dialog_create (GtkWindow *parent)
58 {
59   struct tt_options_dialog *tto = xmalloc (sizeof (*tto));
60
61   tto->xml = builder_new ("t-test.ui");
62
63   tto->confidence =
64     psppire_scanf_new (_("Confidence Interval: %2d %%"), &tto->conf_percent);
65
66   tto->dialog = get_widget_assert (tto->xml, "options-dialog");
67
68   tto->box =   get_widget_assert (tto->xml, "vbox1");
69
70   tto->analysis = GTK_TOGGLE_BUTTON (get_widget_assert (tto->xml, "radiobutton1"));
71   tto->listwise = GTK_TOGGLE_BUTTON (get_widget_assert (tto->xml, "radiobutton2"));
72
73   gtk_widget_show (tto->confidence);
74
75   psppire_box_pack_start_defaults (GTK_BOX (tto->box), tto->confidence);
76
77   gtk_window_set_transient_for (GTK_WINDOW (tto->dialog), parent);
78
79   tto->confidence_interval = 95;
80   tto->excl = EXCL_ANALYSIS;
81
82   return tto;
83 }
84
85
86 void
87 tt_options_dialog_destroy (struct tt_options_dialog *tto)
88 {
89   gtk_container_remove (GTK_CONTAINER (tto->box), tto->confidence);
90   g_object_unref (tto->xml);
91   g_free (tto);
92 }
93
94
95 void
96 tt_options_dialog_run (struct tt_options_dialog *tto)
97 {
98   gint response;
99
100   if ( tto->excl == EXCL_ANALYSIS)
101     gtk_toggle_button_set_active (tto->analysis, TRUE);
102   else
103     gtk_toggle_button_set_active (tto->listwise, TRUE);
104
105   gtk_spin_button_set_value (tto->conf_percent, tto->confidence_interval);
106
107   response = psppire_dialog_run (PSPPIRE_DIALOG (tto->dialog));
108
109   if ( response == PSPPIRE_RESPONSE_CONTINUE)
110     {
111       tto->non_default_options = TRUE;
112
113       tto->confidence_interval = gtk_spin_button_get_value (tto->conf_percent);
114       if ( gtk_toggle_button_get_active (tto->analysis) )
115         tto->excl = EXCL_ANALYSIS;
116       else
117         tto->excl = EXCL_LISTWISE;
118     }
119 }
120
121 void
122 tt_options_dialog_append_syntax (const struct tt_options_dialog *tto, GString *str)
123 {
124   g_string_append (str, "\t/MISSING=");
125
126   if ( tto->excl == EXCL_ANALYSIS )
127     g_string_append (str, "ANALYSIS");
128   else
129     g_string_append (str, "LISTWISE");
130
131
132   g_string_append_printf (str, "\n\t/CRITERIA=CIN(%g)",
133                           tto->confidence_interval/100.0);
134 }