1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2014 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;
50 while (GTK_IS_TREE_MODEL_FILTER (model))
52 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
55 dict = PSPPIRE_DICT (model);
57 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
59 list = gtk_tree_selection_get_selected_rows (selection, &model);
61 /* Iterate through the selection of the source treeview */
63 for (l = list; l ; l = l->next)
65 GtkTreePath *path = l->data;
68 gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path);
70 gint *idx = gtk_tree_path_get_indices (fpath);
72 const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
74 gtk_tree_path_free (fpath);
76 if (have_type && var_get_type (v) != type)
82 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);
102 if ( have_type && var_get_type (v) != type )
108 type = var_get_type (v);
117 /* Returns true iff the variable selected by SOURCE is numeric */
119 numeric_only (GtkWidget *source, GtkWidget *dest)
121 gboolean retval = TRUE;
123 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
126 GtkTreeSelection *selection;
129 while (GTK_IS_TREE_MODEL_FILTER (model))
131 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
134 dict = PSPPIRE_DICT (model);
136 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
138 list = gtk_tree_selection_get_selected_rows (selection, &model);
140 /* Iterate through the selection of the source treeview */
141 for (l = list; l ; l = l->next)
143 GtkTreePath *path = l->data;
144 GtkTreePath *fpath = gtk_tree_model_filter_convert_path_to_child_path
145 (GTK_TREE_MODEL_FILTER (model), path);
147 gint *idx = gtk_tree_path_get_indices (fpath);
149 const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
151 gtk_tree_path_free (fpath);
153 if ( var_is_alpha (v))
160 g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
167 A pair of functions intended to be used as callbacks for the "toggled" signal
168 of a GtkToggleButton widget. They make the sensitivity of W follow the status
172 set_sensitivity_from_toggle (GtkToggleButton *togglebutton, GtkWidget *w)
174 gboolean active = gtk_toggle_button_get_active (togglebutton);
176 gtk_widget_set_sensitive (w, active);
178 gtk_widget_grab_focus (w);
183 set_sensitivity_from_toggle_invert (GtkToggleButton *togglebutton,
186 gboolean active = gtk_toggle_button_get_active (togglebutton);
188 gtk_widget_set_sensitive (w, !active);