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/>. */
18 #include "dialog-common.h"
23 /* Append the names of selected variables to STRING.
24 TREEVIEW is the treeview containing the variables.
25 DICT is the dictionary for those variables.
28 append_variable_names (GString *string,
29 PsppireDict *dict, GtkTreeView *treeview)
34 GtkTreeModel *list_store =
35 gtk_tree_view_get_model (treeview);
37 if ( gtk_tree_model_get_iter_first (list_store, &iter) )
43 GtkTreePath *path = gtk_tree_model_get_path (list_store, &iter);
45 gtk_tree_model_get_value (list_store, &iter, 0, &value);
47 var = psppire_dict_get_variable (dict, g_value_get_int (&value));
48 g_value_unset (&value);
50 g_string_append (string, " ");
51 g_string_append (string, var_get_name (var));
53 gtk_tree_path_free (path);
56 while (gtk_tree_model_iter_next (list_store, &iter));
65 get_selected_variable (GtkTreeModel *treemodel,
72 GtkTreePath *path = gtk_tree_model_get_path (treemodel, iter);
74 gtk_tree_model_get_value (treemodel, iter, 0, &value);
76 gtk_tree_path_free (path);
78 var = psppire_dict_get_variable (dict, g_value_get_int (&value));
80 g_value_unset (&value);
88 /* A (*GtkTreeCellDataFunc) function.
89 This function expects TREEMODEL to hold G_TYPE_INT. The ints it holds
90 are the indices of the variables in the dictionary, which DATA points to.
91 It renders the name of the variable into CELL.
94 cell_var_name (GtkTreeViewColumn *tree_column,
95 GtkCellRenderer *cell,
96 GtkTreeModel *tree_model,
100 PsppireDict *dict = data;
101 struct variable *var;
104 var = get_selected_variable (tree_model, iter, dict);
106 name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL);
107 g_object_set (cell, "text", name, NULL);
113 /* Set a model for DEST, which is an GtkListStore of g_int's
114 whose values are the indices into DICT */
116 set_dest_model (GtkTreeView *dest, PsppireDict *dict)
118 GtkTreeViewColumn *col;
119 GtkListStore *dest_list = gtk_list_store_new (1, G_TYPE_INT);
120 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
122 gtk_tree_view_set_model (GTK_TREE_VIEW (dest), GTK_TREE_MODEL (dest_list));
124 col = gtk_tree_view_column_new_with_attributes ("Var",
130 gtk_tree_view_column_set_cell_data_func (col, renderer,
134 /* FIXME: make this a value in terms of character widths */
135 g_object_set (col, "min-width", 100, NULL);
137 gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
139 gtk_tree_view_append_column (GTK_TREE_VIEW (dest), col);
144 /* Returns FALSE if the variables represented by the union of the rows
145 currently selected by SOURCE widget, and contents of the DEST
146 widget, are of different types.
148 In other words, this function when passed as the argument to
149 psppire_selector_set_allow, ensures that the selector selects only
150 string variables, or only numeric variables, not a mixture.
153 homogeneous_types (GtkWidget *source, GtkWidget *dest)
157 gboolean retval = TRUE;
159 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
162 GtkTreeSelection *selection;
163 enum val_type type = -1;
166 while (GTK_IS_TREE_MODEL_FILTER (model))
168 model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
171 dict = PSPPIRE_DICT (model);
173 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
175 list = gtk_tree_selection_get_selected_rows (selection, &model);
177 /* Iterate through the selection of the source treeview */
178 for (l = list; l ; l = l->next)
180 GtkTreePath *path = l->data;
184 const struct variable *v;
186 fpath = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path);
188 idx = gtk_tree_path_get_indices (fpath);
190 v = psppire_dict_get_variable (dict, idx[0]);
194 if ( var_get_type (v) != type )
201 type = var_get_type (v);
204 g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
207 if ( retval == FALSE )
210 /* now deal with the dest widget */
211 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
213 for (ok = gtk_tree_model_get_iter_first (model, &iter);
215 ok = gtk_tree_model_iter_next (model, &iter))
218 const struct variable *v;
219 gtk_tree_model_get (model, &iter, 0, &idx, -1);
221 v = psppire_dict_get_variable (dict, idx);
225 if ( var_get_type (v) != type )
232 type = var_get_type (v);