1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2009, 2010, 2011 Free Software Foundation
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.
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.
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/>. */
19 #include "dialog-common.h"
20 #include <ui/syntax-gen.h>
21 #include <libpspp/str.h>
23 #include "roc-dialog.h"
24 #include "psppire-selector.h"
25 #include "psppire-dictview.h"
26 #include "psppire-dialog.h"
28 #include "psppire-data-window.h"
29 #include "psppire-var-view.h"
37 #define _(msgid) gettext (msgid)
38 #define N_(msgid) msgid
45 GtkWidget *test_variables;
46 GtkWidget *state_variable;
47 GtkWidget *state_value;
51 GtkWidget *standard_error;
52 GtkWidget *coordinates;
56 static char * generate_syntax (const struct roc *rd);
60 refresh (struct roc *rd)
62 GtkTreeModel *liststore =
63 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
64 gtk_list_store_clear (GTK_LIST_STORE (liststore));
66 gtk_entry_set_text (GTK_ENTRY (rd->state_variable), "");
67 gtk_entry_set_text (GTK_ENTRY (rd->state_value), "");
69 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->curve), TRUE);
70 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->reference), FALSE);
71 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->standard_error), FALSE);
72 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->coordinates), FALSE);
77 dialog_state_valid (gpointer data)
79 struct roc *rd = data;
82 GtkTreeModel *liststore =
83 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
85 if (gtk_tree_model_iter_n_children (liststore, NULL) < 1)
89 text = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
90 if ( 0 == strcmp ("", text))
94 text = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
95 if ( 0 == strcmp ("", text))
103 on_curve_button_toggle (GtkCheckButton *curve, struct roc *rd)
105 if ( !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (curve)))
107 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->reference)))
108 g_object_set (rd->reference, "inconsistent", TRUE, NULL);
109 g_object_set (rd->reference, "sensitive", FALSE, NULL);
113 g_object_set (rd->reference, "inconsistent", FALSE, NULL);
114 g_object_set (rd->reference, "sensitive", TRUE, NULL);
119 /* Pops up the Roc dialog box */
121 roc_dialog (PsppireDataWindow *de)
126 GtkBuilder *xml = builder_new ("roc.ui");
129 GtkWidget *dialog = get_widget_assert (xml, "roc-dialog");
130 GtkWidget *source = get_widget_assert (xml, "dict-view");
132 rd.test_variables = get_widget_assert (xml, "psppire-var-view1");
133 rd.state_variable = get_widget_assert (xml, "entry1");
134 rd.state_value = get_widget_assert (xml, "entry2");
136 rd.curve = get_widget_assert (xml, "curve");
137 rd.reference = get_widget_assert (xml, "reference-line");
138 rd.standard_error = get_widget_assert (xml, "standard-error");
139 rd.coordinates = get_widget_assert (xml, "co-ordinates");
142 g_object_get (de->data_editor, "var-store", &vs, NULL);
144 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
146 g_object_get (vs, "dictionary", &rd.dict, NULL);
147 g_object_set (source, "model", rd.dict, NULL);
149 g_signal_connect (rd.curve, "toggled", G_CALLBACK (on_curve_button_toggle), &rd);
151 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &rd);
153 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
154 dialog_state_valid, &rd);
156 psppire_selector_set_allow (PSPPIRE_SELECTOR (get_widget_assert (xml, "dep-selector")),
159 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
163 case GTK_RESPONSE_OK:
164 g_free (execute_syntax_string (de, generate_syntax (&rd)));
166 case PSPPIRE_RESPONSE_PASTE:
167 g_free (paste_syntax_to_window (generate_syntax (&rd)));
173 g_object_unref (xml);
180 generate_syntax (const struct roc *rd)
183 const gchar *var_name = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
184 GString *string = g_string_new ("ROC");
186 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->test_variables), 0, string);
188 g_string_append (string, " BY ");
190 g_string_append (string, var_name);
192 g_string_append (string, " (");
194 const gchar *value = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
196 const struct variable *var = psppire_dict_lookup_var (rd->dict, var_name);
198 g_return_val_if_fail (var, NULL);
200 if ( var_is_alpha (var))
204 syntax_gen_string (&xx, ss_cstr (value));
205 g_string_append (string, ds_cstr (&xx));
209 g_string_append (string, value);
211 g_string_append (string, ")");
214 /* The /PLOT subcommand */
215 g_string_append (string, "\n\t/PLOT ");
216 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->curve)))
218 g_string_append (string, "CURVE");
219 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->reference)))
220 g_string_append (string, " (REFERENCE)");
223 g_string_append (string, "NONE");
226 /* The /PRINT subcommand */
227 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error)) ||
228 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates)) )
230 g_string_append (string, "\n\t/PRINT");
232 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error)))
233 g_string_append (string, " SE");
235 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates)))
236 g_string_append (string, " COORDINATES");
239 g_string_append (string, ".\n");
243 g_string_free (string, FALSE);