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
22 #include "dialog-common.h"
27 /* Append the names of selected variables to STRING.
28 TREEVIEW is the treeview containing the variables.
29 DICT is the dictionary for those variables.
32 append_variable_names (GString *string,
33 PsppireDict *dict, GtkTreeView *treeview)
38 GtkTreeModel *list_store =
39 gtk_tree_view_get_model (treeview);
41 if ( gtk_tree_model_get_iter_first (list_store, &iter) )
47 GtkTreePath *path = gtk_tree_model_get_path (list_store, &iter);
49 gtk_tree_model_get_value (list_store, &iter, 0, &value);
51 var = psppire_dict_get_variable (dict, g_value_get_int (&value));
52 g_value_unset (&value);
54 g_string_append (string, " ");
55 g_string_append (string, var_get_name (var));
57 gtk_tree_path_free (path);
60 while (gtk_tree_model_iter_next (list_store, &iter));
69 get_selected_variable (GtkTreeModel *treemodel,
76 GtkTreePath *path = gtk_tree_model_get_path (treemodel, iter);
78 gtk_tree_model_get_value (treemodel, iter, 0, &value);
80 gtk_tree_path_free (path);
82 var = psppire_dict_get_variable (dict, g_value_get_int (&value));
84 g_value_unset (&value);
92 /* A (*GtkTreeCellDataFunc) function.
93 This function expects TREEMODEL to hold G_TYPE_INT. The ints it holds
94 are the indices of the variables in the dictionary, which DATA points to.
95 It renders the name of the variable into CELL.
98 cell_var_name (GtkTreeViewColumn *tree_column,
99 GtkCellRenderer *cell,
100 GtkTreeModel *tree_model,
104 PsppireDict *dict = data;
105 struct variable *var;
108 var = get_selected_variable (tree_model, iter, dict);
110 name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL);
111 g_object_set (cell, "text", name, NULL);
117 /* Set a model for DEST, which is an GtkListStore of g_int's
118 whose values are the indices into DICT */
120 set_dest_model (GtkTreeView *dest, PsppireDict *dict)
122 GtkTreeViewColumn *col;
123 GtkListStore *dest_list = gtk_list_store_new (1, G_TYPE_INT);
124 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
126 gtk_tree_view_set_model (GTK_TREE_VIEW (dest), GTK_TREE_MODEL (dest_list));
128 col = gtk_tree_view_column_new_with_attributes ("Var",
134 gtk_tree_view_column_set_cell_data_func (col, renderer,
138 /* FIXME: make this a value in terms of character widths */
139 g_object_set (col, "min-width", 100, NULL);
141 gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
143 gtk_tree_view_append_column (GTK_TREE_VIEW(dest), col);