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);