Merge 'master' into 'psppsheet'.
[pspp] / src / ui / gui / t-test-paired-samples.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2011, 2012  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 #include <config.h>
19 #include <gtk/gtk.h>
20
21 #include "t-test-options.h"
22 #include "t-test-paired-samples.h"
23
24 #include "psppire-data-window.h"
25 #include "psppire-selector.h"
26 #include "psppire-var-view.h"
27
28 #include "psppire-dict.h"
29
30 #include "dialog-common.h"
31 #include "psppire-dialog.h"
32
33 #include "executor.h"
34
35 #include "helper.h"
36
37 #include "psppire-var-ptr.h"
38
39 #include "paired-dialog.h"
40
41 #include <gettext.h>
42 #define _(msgid) gettext (msgid)
43 #define N_(msgid) msgid
44
45
46 static void
47 refresh (void *aux)
48 {
49 }
50
51
52 static gboolean
53 valid (void *aux)
54 {
55   return TRUE;
56 }
57
58 static gchar *
59 generate_syntax (const struct paired_samples_dialog *d, const struct tt_options_dialog *opt)
60 {
61   gchar *text = NULL;
62   GString *str =   g_string_new ("T-TEST \n\tPAIRS = ");
63
64   psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->pairs_treeview), 0, str);
65
66   g_string_append (str, " WITH ");
67
68   psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->pairs_treeview), 1, str);
69
70   g_string_append (str, " (PAIRED)");
71   g_string_append (str, "\n");
72
73   tt_options_dialog_append_syntax (opt, str);
74
75   g_string_append (str, ".\n");
76
77   text = str->str;
78   g_string_free (str, FALSE);
79
80   return text;
81 }
82
83 /* Pops up the dialog box */
84 void
85 t_test_paired_samples_dialog (PsppireDataWindow *de)
86 {
87   gint response;
88   struct paired_samples_dialog *tt_d = two_sample_dialog_create (de);
89   struct tt_options_dialog *opts = tt_options_dialog_create (GTK_WINDOW (de));
90
91   GtkWidget *bb = gtk_hbutton_box_new ();
92   GtkWidget *opt = gtk_button_new_with_mnemonic (_("O_ptions..."));
93   gtk_box_pack_start (GTK_BOX (bb), opt, TRUE, TRUE, 5);
94
95   gtk_widget_show_all (bb);
96   two_sample_dialog_add_widget (tt_d, bb);
97   
98   g_signal_connect_swapped (opt, "clicked", G_CALLBACK (tt_options_dialog_run), opts);
99
100   tt_d->refresh = refresh;
101   tt_d->valid = valid;
102   tt_d->aux = opts;
103
104   gtk_window_set_title (GTK_WINDOW (tt_d->dialog), _("Paired Samples T Test"));
105
106   response = psppire_dialog_run (PSPPIRE_DIALOG (tt_d->dialog));
107
108   switch (response)
109     {
110     case GTK_RESPONSE_OK:
111       g_free (execute_syntax_string (de, generate_syntax (tt_d, opts)));
112       break;
113     case PSPPIRE_RESPONSE_PASTE:
114       g_free (paste_syntax_to_window (generate_syntax (tt_d, opts)));
115       break;
116     default:
117       break;
118     }
119
120   two_sample_dialog_destroy (tt_d);
121   tt_options_dialog_destroy (opts);
122 }