1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 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 <libpspp/i18n.h>
20 #include "dialog-common.h"
22 #include "psppire-var-ptr.h"
27 /* Returns FALSE if the variables represented by the union of the rows
28 currently selected by SOURCE widget, and contents of the DEST
29 widget, are of different types.
31 In other words, this function when passed as the argument to
32 psppire_selector_set_allow, ensures that the selector selects only
33 string variables, or only numeric variables, not a mixture.
36 homogeneous_types (GtkWidget *source, GtkWidget *dest)
40 gboolean retval = TRUE;
42 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
45 GtkTreeSelection *selection;
46 enum val_type type = -1;
49 while (GTK_IS_TREE_MODEL_FILTER (model))
51 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
54 dict = PSPPIRE_DICT (model);
56 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
58 list = gtk_tree_selection_get_selected_rows (selection, &model);
60 /* Iterate through the selection of the source treeview */
61 for (l = list; l ; l = l->next)
63 GtkTreePath *path = l->data;
66 gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path);
68 gint *idx = gtk_tree_path_get_indices (fpath);
70 const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
72 gtk_tree_path_free (fpath);
76 if ( var_get_type (v) != type )
83 type = var_get_type (v);
86 g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
89 if ( retval == FALSE )
92 /* now deal with the dest widget */
93 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
95 for (ok = gtk_tree_model_get_iter_first (model, &iter);
97 ok = gtk_tree_model_iter_next (model, &iter))
99 const struct variable *v;
100 gtk_tree_model_get (model, &iter, 0, &v, -1);
104 if ( var_get_type (v) != type )
111 type = var_get_type (v);
119 /* Returns true iff the variable selected by SOURCE is numeric */
121 numeric_only (GtkWidget *source, GtkWidget *dest)
123 gboolean retval = TRUE;
125 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
128 GtkTreeSelection *selection;
131 while (GTK_IS_TREE_MODEL_FILTER (model))
133 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
136 dict = PSPPIRE_DICT (model);
138 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
140 list = gtk_tree_selection_get_selected_rows (selection, &model);
142 /* Iterate through the selection of the source treeview */
143 for (l = list; l ; l = l->next)
145 GtkTreePath *path = l->data;
146 GtkTreePath *fpath = gtk_tree_model_filter_convert_path_to_child_path
147 (GTK_TREE_MODEL_FILTER (model), path);
149 gint *idx = gtk_tree_path_get_indices (fpath);
151 const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
153 gtk_tree_path_free (fpath);
155 if ( var_is_alpha (v))
162 g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
169 A pair of functions intended to be used as callbacks for the "toggled" signal
170 of a GtkToggleButton widget. They make the sensitivity of W follow the status
174 set_sensitivity_from_toggle (GtkToggleButton *togglebutton, GtkWidget *w)
176 gboolean active = gtk_toggle_button_get_active (togglebutton);
178 gtk_widget_set_sensitive (w, active);
180 gtk_widget_grab_focus (w);
185 set_sensitivity_from_toggle_invert (GtkToggleButton *togglebutton,
188 gboolean active = gtk_toggle_button_get_active (togglebutton);
190 gtk_widget_set_sensitive (w, !active);