1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2009 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 <language/syntax-string-source.h>
21 #include <ui/syntax-gen.h>
22 #include <libpspp/str.h>
24 #include "roc-dialog.h"
25 #include "psppire-selector.h"
26 #include "psppire-dictview.h"
27 #include "psppire-dialog.h"
29 #include "psppire-data-window.h"
30 #include "psppire-var-view.h"
38 #define _(msgid) gettext (msgid)
39 #define N_(msgid) msgid
46 GtkWidget *test_variables;
47 GtkWidget *state_variable;
48 GtkWidget *state_value;
52 GtkWidget *standard_error;
53 GtkWidget *coordinates;
57 static char * generate_syntax (const struct roc *rd);
61 refresh (struct roc *rd)
63 GtkTreeModel *liststore =
64 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
65 gtk_list_store_clear (GTK_LIST_STORE (liststore));
67 gtk_entry_set_text (GTK_ENTRY (rd->state_variable), "");
68 gtk_entry_set_text (GTK_ENTRY (rd->state_value), "");
70 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->curve), TRUE);
71 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->reference), FALSE);
72 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->standard_error), FALSE);
73 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->coordinates), FALSE);
78 dialog_state_valid (gpointer data)
80 struct roc *rd = data;
83 GtkTreeModel *liststore =
84 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
86 if (gtk_tree_model_iter_n_children (liststore, NULL) < 1)
90 text = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
91 if ( 0 == strcmp ("", text))
95 text = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
96 if ( 0 == strcmp ("", text))
104 on_curve_button_toggle (GtkCheckButton *curve, struct roc *rd)
106 if ( !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (curve)))
108 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->reference)))
109 g_object_set (rd->reference, "inconsistent", TRUE, NULL);
110 g_object_set (rd->reference, "sensitive", FALSE, NULL);
114 g_object_set (rd->reference, "inconsistent", FALSE, NULL);
115 g_object_set (rd->reference, "sensitive", TRUE, NULL);
120 /* Pops up the Roc dialog box */
122 roc_dialog (PsppireDataWindow *de)
127 GtkBuilder *xml = builder_new ("roc.ui");
130 GtkWidget *dialog = get_widget_assert (xml, "roc-dialog");
131 GtkWidget *source = get_widget_assert (xml, "dict-view");
133 rd.test_variables = get_widget_assert (xml, "psppire-var-view1");
134 rd.state_variable = get_widget_assert (xml, "entry1");
135 rd.state_value = get_widget_assert (xml, "entry2");
137 rd.curve = get_widget_assert (xml, "curve");
138 rd.reference = get_widget_assert (xml, "reference-line");
139 rd.standard_error = get_widget_assert (xml, "standard-error");
140 rd.coordinates = get_widget_assert (xml, "co-ordinates");
143 g_object_get (de->data_editor, "var-store", &vs, NULL);
145 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
147 g_object_get (vs, "dictionary", &rd.dict, NULL);
148 g_object_set (source, "model", rd.dict, NULL);
150 g_signal_connect (rd.curve, "toggled", G_CALLBACK (on_curve_button_toggle), &rd);
152 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &rd);
154 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
155 dialog_state_valid, &rd);
157 psppire_selector_set_allow (PSPPIRE_SELECTOR (get_widget_assert (xml, "dep-selector")),
160 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
164 case GTK_RESPONSE_OK:
166 gchar *syntax = generate_syntax (&rd);
168 struct getl_interface *sss = create_syntax_string_source (syntax);
169 execute_syntax (sss);
174 case PSPPIRE_RESPONSE_PASTE:
176 gchar *syntax = generate_syntax (&rd);
177 paste_syntax_to_window (syntax);
186 g_object_unref (xml);
193 generate_syntax (const struct roc *rd)
196 const gchar *var_name = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
197 GString *string = g_string_new ("ROC");
199 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->test_variables), 0, string);
201 g_string_append (string, " BY ");
203 g_string_append (string, var_name);
205 g_string_append (string, " (");
207 const gchar *value = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
209 const struct variable *var = psppire_dict_lookup_var (rd->dict, var_name);
211 g_return_val_if_fail (var, NULL);
213 if ( var_is_alpha (var))
217 syntax_gen_string (&xx, ss_cstr (value));
218 g_string_append (string, ds_cstr (&xx));
222 g_string_append (string, value);
224 g_string_append (string, ")");
227 /* The /PLOT subcommand */
228 g_string_append (string, "\n\t/PLOT ");
229 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->curve)))
231 g_string_append (string, "CURVE");
232 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->reference)))
233 g_string_append (string, " (REFERENCE)");
236 g_string_append (string, "NONE");
239 /* The /PRINT subcommand */
240 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error)) ||
241 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates)) )
243 g_string_append (string, "\n\t/PRINT");
245 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error)))
246 g_string_append (string, " SE");
248 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates)))
249 g_string_append (string, " COORDINATES");
252 g_string_append (string, ".\n");
256 g_string_free (string, FALSE);