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"
26 /* A (*GtkTreeCellDataFunc) function.
27 This function expects TREEMODEL to hold G_TYPE_BOXED, which is a pointer to a variable.
28 It renders the name of the variable into CELL.
31 XXX_cell_var_name (GtkTreeViewColumn *tree_column,
32 GtkCellRenderer *cell,
33 GtkTreeModel *treemodel,
37 const struct variable *var;
40 GtkTreePath *path = gtk_tree_model_get_path (treemodel, iter);
42 gtk_tree_model_get_value (treemodel, iter, 0, &value);
44 gtk_tree_path_free (path);
46 var = g_value_get_boxed (&value);
48 g_value_unset (&value);
50 g_object_set (cell, "text", var_get_name (var), NULL);
55 /* Returns FALSE if the variables represented by the union of the rows
56 currently selected by SOURCE widget, and contents of the DEST
57 widget, are of different types.
59 In other words, this function when passed as the argument to
60 psppire_selector_set_allow, ensures that the selector selects only
61 string variables, or only numeric variables, not a mixture.
64 homogeneous_types (GtkWidget *source, GtkWidget *dest)
68 gboolean retval = TRUE;
70 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
73 GtkTreeSelection *selection;
74 enum val_type type = -1;
77 while (GTK_IS_TREE_MODEL_FILTER (model))
79 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
82 dict = PSPPIRE_DICT (model);
84 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
86 list = gtk_tree_selection_get_selected_rows (selection, &model);
88 /* Iterate through the selection of the source treeview */
89 for (l = list; l ; l = l->next)
91 GtkTreePath *path = l->data;
94 gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path);
96 gint *idx = gtk_tree_path_get_indices (fpath);
98 const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
100 gtk_tree_path_free (fpath);
104 if ( var_get_type (v) != type )
111 type = var_get_type (v);
114 g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
117 if ( retval == FALSE )
120 /* now deal with the dest widget */
121 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
123 for (ok = gtk_tree_model_get_iter_first (model, &iter);
125 ok = gtk_tree_model_iter_next (model, &iter))
127 const struct variable *v;
128 gtk_tree_model_get (model, &iter, 0, &v, -1);
132 if ( var_get_type (v) != type )
139 type = var_get_type (v);
147 /* Returns true iff the variable selected by SOURCE is numeric */
149 numeric_only (GtkWidget *source, GtkWidget *dest)
151 gboolean retval = TRUE;
153 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
156 GtkTreeSelection *selection;
159 while (GTK_IS_TREE_MODEL_FILTER (model))
161 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
164 dict = PSPPIRE_DICT (model);
166 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
168 list = gtk_tree_selection_get_selected_rows (selection, &model);
170 /* Iterate through the selection of the source treeview */
171 for (l = list; l ; l = l->next)
173 GtkTreePath *path = l->data;
174 GtkTreePath *fpath = gtk_tree_model_filter_convert_path_to_child_path
175 (GTK_TREE_MODEL_FILTER (model), path);
177 gint *idx = gtk_tree_path_get_indices (fpath);
179 const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
181 gtk_tree_path_free (fpath);
183 if ( var_is_alpha (v))
190 g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);