Whitespace changes only: Remove trailing whitespace
[pspp] / src / ui / gui / t-test-options.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2007, 2012, 2015  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 "builder-wrapper.h"
25 #include "helper.h"
26 #include "t-test-options.h"
27
28 #include "widget-io.h"
29 #include "psppire-scanf.h"
30
31 #include <gettext.h>
32 #define _(msgid) gettext (msgid)
33 #define N_(msgid) msgid
34
35
36 enum exclude_mode
37   {
38     EXCL_ANALYSIS,
39     EXCL_LISTWISE
40   };
41
42 struct tt_options_dialog
43 {
44   GtkWidget *dialog;
45   GtkWidget *box;
46   GtkWidget *confidence;
47   GtkSpinButton *conf_percent;
48   GtkToggleButton *analysis;
49   GtkToggleButton *listwise;
50
51   gdouble confidence_interval;
52   gboolean non_default_options;
53   enum exclude_mode excl;
54   GtkBuilder *xml;
55 };
56
57 struct tt_options_dialog *
58 tt_options_dialog_create (GtkWindow *parent)
59 {
60   struct tt_options_dialog *tto = xmalloc (sizeof (*tto));
61
62   tto->xml = builder_new ("t-test.ui");
63
64   tto->confidence =
65     psppire_scanf_new (_("Con_fidence Interval: %2d %%"), &tto->conf_percent);
66
67   g_object_set (tto->confidence,
68                 "use-underline", TRUE,
69                 "mnemonic-widget", psppire_scanf_get_child (PSPPIRE_SCANF (tto->confidence), 0),
70                 NULL);
71
72   tto->dialog = get_widget_assert (tto->xml, "options-dialog");
73
74   tto->box =   get_widget_assert (tto->xml, "vbox1");
75
76   tto->analysis = GTK_TOGGLE_BUTTON (get_widget_assert (tto->xml, "radiobutton1"));
77   tto->listwise = GTK_TOGGLE_BUTTON (get_widget_assert (tto->xml, "radiobutton2"));
78
79   gtk_widget_show (tto->confidence);
80
81   psppire_box_pack_start_defaults (GTK_BOX (tto->box), tto->confidence);
82
83   gtk_window_set_transient_for (GTK_WINDOW (tto->dialog), parent);
84
85   tto->confidence_interval = 95;
86   tto->excl = EXCL_ANALYSIS;
87
88   return tto;
89 }
90
91
92 void
93 tt_options_dialog_destroy (struct tt_options_dialog *tto)
94 {
95   if (tto == NULL)
96     return;
97   gtk_container_remove (GTK_CONTAINER (tto->box), tto->confidence);
98   g_object_unref (tto->xml);
99   g_free (tto);
100 }
101
102
103 void
104 tt_options_dialog_run (struct tt_options_dialog *tto)
105 {
106   gint response;
107
108   if ( tto->excl == EXCL_ANALYSIS)
109     gtk_toggle_button_set_active (tto->analysis, TRUE);
110   else
111     gtk_toggle_button_set_active (tto->listwise, TRUE);
112
113   gtk_spin_button_set_value (tto->conf_percent, tto->confidence_interval);
114
115   response = psppire_dialog_run (PSPPIRE_DIALOG (tto->dialog));
116
117   if ( response == PSPPIRE_RESPONSE_CONTINUE)
118     {
119       tto->non_default_options = TRUE;
120
121       tto->confidence_interval = gtk_spin_button_get_value (tto->conf_percent);
122       if ( gtk_toggle_button_get_active (tto->analysis) )
123         tto->excl = EXCL_ANALYSIS;
124       else
125         tto->excl = EXCL_LISTWISE;
126     }
127 }
128
129 void
130 tt_options_dialog_append_syntax (const struct tt_options_dialog *tto, GString *str)
131 {
132   struct string dss;
133   ds_init_empty (&dss);
134
135   ds_put_cstr (&dss, "\t/MISSING=");
136
137   if (tto->excl == EXCL_ANALYSIS)
138     ds_put_cstr (&dss, "ANALYSIS");
139   else
140     ds_put_cstr (&dss, "LISTWISE");
141
142   ds_put_c_format (&dss, "\n\t/CRITERIA=CI(%g)",
143                    tto->confidence_interval/100.0);
144
145   g_string_append (str, ds_cstr (&dss));
146
147   ds_destroy (&dss);
148 }