2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2007 Free Software Foundation
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "dict-display.h"
27 #include "psppire-dict.h"
29 #include <data/variable.h>
31 #define _(msgid) gettext (msgid)
32 #define N_(msgid) msgid
35 /* A GtkTreeModelFilterVisibleFunc to filter lines in the treeview */
37 filter_variables (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
39 var_predicate_func *predicate = data;
41 PsppireDict *dict = PSPPIRE_DICT (model);
43 GtkTreePath *path = gtk_tree_model_get_path (model, iter);
45 gint *idx = gtk_tree_path_get_indices (path);
47 var = psppire_dict_get_variable (dict, *idx);
49 gtk_tree_path_free (path);
51 return predicate (var);
54 /* Sets up TREEVIEW to display the variables of DICT.
55 MODE is the selection mode for TREEVIEW.
56 PREDICATE determines which variables should be visible, or NULL if
57 all are to be visible.
60 attach_dictionary_to_treeview (GtkTreeView *treeview, PsppireDict *dict,
61 GtkSelectionMode mode,
62 var_predicate_func *predicate
65 GtkTreeViewColumn *col;
67 GtkTreeSelection *selection =
68 gtk_tree_view_get_selection (treeview);
70 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
75 model = gtk_tree_model_filter_new (GTK_TREE_MODEL (dict),
78 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model),
85 model = GTK_TREE_MODEL (dict);
88 gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), model);
92 col = gtk_tree_view_column_new_with_attributes (_("Var"),
98 /* FIXME: make this a value in terms of character widths */
99 g_object_set (col, "min-width", 100, NULL);
101 gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
103 gtk_tree_view_append_column (treeview, col);
105 gtk_tree_selection_set_mode (selection, mode);
110 insert_source_row_into_entry (GtkTreeIter iter,
118 struct variable *var;
119 GtkTreeIter dict_iter;
122 g_return_if_fail (GTK_IS_ENTRY(dest));
125 if ( GTK_IS_TREE_MODEL_FILTER (model))
127 dict = PSPPIRE_DICT (gtk_tree_model_filter_get_model
128 (GTK_TREE_MODEL_FILTER(model)));
129 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER
135 dict = PSPPIRE_DICT (model);
140 path = gtk_tree_model_get_path (GTK_TREE_MODEL (dict), &dict_iter);
142 idx = gtk_tree_path_get_indices (path);
144 var = psppire_dict_get_variable (dict, *idx);
146 gtk_tree_path_free (path);
148 name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL);
149 gtk_entry_set_text (GTK_ENTRY (dest), name);
156 insert_source_row_into_tree_view (GtkTreeIter iter,
162 GtkTreeIter dest_iter;
163 GtkTreeIter dict_iter;
165 GtkTreeModel *destmodel = gtk_tree_view_get_model ( GTK_TREE_VIEW (dest));
169 if ( GTK_IS_TREE_MODEL_FILTER (model))
171 dict = PSPPIRE_DICT (gtk_tree_model_filter_get_model
172 (GTK_TREE_MODEL_FILTER(model)));
173 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER
179 dict = PSPPIRE_DICT (model);
184 path = gtk_tree_model_get_path (GTK_TREE_MODEL (dict), &dict_iter);
186 row = gtk_tree_path_get_indices (path);
188 gtk_list_store_append (GTK_LIST_STORE (destmodel), &dest_iter);
189 gtk_list_store_set (GTK_LIST_STORE (destmodel), &dest_iter, 0, *row, -1);
191 gtk_tree_path_free (path);
196 is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter,
197 PsppireSelector *selector)
201 GtkTreeIter dict_iter;
203 struct variable *var;
207 const gchar *text = gtk_entry_get_text (GTK_ENTRY (selector->dest));
210 if ( GTK_IS_TREE_MODEL_FILTER (model))
212 dict = PSPPIRE_DICT (gtk_tree_model_filter_get_model
213 (GTK_TREE_MODEL_FILTER(model)));
214 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER
220 dict = PSPPIRE_DICT (model);
225 path = gtk_tree_model_get_path (GTK_TREE_MODEL(dict),
228 indeces = gtk_tree_path_get_indices (path);
230 dict_index = indeces [0];
232 var = psppire_dict_get_variable (dict, dict_index);
234 gtk_tree_path_free (path);
236 name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL);
237 result = ( 0 == strcmp (text, name));