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/>. */
22 #include "psppire-conf.h"
23 #include "dict-display.h"
25 #include "psppire-dict.h"
26 #include "psppire-dictview.h"
27 #include "psppire-var-ptr.h"
28 #include "psppire-var-view.h"
29 #include "psppire-select-dest.h"
30 #include <libpspp/i18n.h>
32 #include <data/variable.h>
33 #include <data/format.h>
35 #define _(msgid) gettext (msgid)
36 #define N_(msgid) msgid
39 get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter,
40 GtkTreeModel **model, GtkTreeIter *iter
45 while (GTK_IS_TREE_MODEL_FILTER (*model))
47 GtkTreeIter parent_iter = *iter;
48 GtkTreeModelFilter *parent_model = GTK_TREE_MODEL_FILTER (*model);
50 *model = gtk_tree_model_filter_get_model (parent_model);
52 gtk_tree_model_filter_convert_iter_to_child_iter (parent_model,
57 g_assert (PSPPIRE_IS_DICT (*model));
62 insert_source_row_into_entry (GtkTreeIter iter,
72 GtkTreeIter dict_iter;
74 g_return_if_fail (GTK_IS_ENTRY(dest));
76 get_base_model (model, &iter, &dict, &dict_iter);
78 path = gtk_tree_model_get_path (GTK_TREE_MODEL (dict), &dict_iter);
80 idx = gtk_tree_path_get_indices (path);
82 var = psppire_dict_get_variable (PSPPIRE_DICT (dict), *idx);
84 gtk_tree_path_free (path);
86 gtk_entry_set_text (GTK_ENTRY (dest), var_get_name (var));
91 insert_source_row_into_tree_view (GtkTreeIter iter,
98 GtkTreeIter dest_iter;
99 GtkTreeIter dict_iter;
101 GtkTreeModel *destmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
103 const struct variable *var;
106 get_base_model (model, &iter, &dict, &dict_iter);
108 path = gtk_tree_model_get_path (dict, &dict_iter);
110 row = gtk_tree_path_get_indices (path);
112 var = psppire_dict_get_variable (PSPPIRE_DICT (dict), *row);
114 gtk_list_store_append (GTK_LIST_STORE (destmodel), &dest_iter);
116 gtk_list_store_set (GTK_LIST_STORE (destmodel), &dest_iter, 0, var, -1);
118 gtk_tree_path_free (path);
124 is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter,
125 PsppireSelector *selector)
128 GtkTreeIter dict_iter;
130 struct variable *var;
134 GtkWidget *entry = NULL;
135 const gchar *text = NULL;
137 g_object_get (selector, "dest-widget", &entry, NULL);
139 text = gtk_entry_get_text (GTK_ENTRY (entry));
141 get_base_model (model, iter, &dict, &dict_iter);
143 path = gtk_tree_model_get_path (dict, &dict_iter);
145 indeces = gtk_tree_path_get_indices (path);
147 dict_index = indeces [0];
149 var = psppire_dict_get_variable (PSPPIRE_DICT (dict), dict_index);
151 gtk_tree_path_free (path);
153 result = ( 0 == strcmp (text, var_get_name (var) ));
159 is_currently_in_varview (GtkTreeModel *model, GtkTreeIter *iter, PsppireSelector *sel)
161 gboolean ret = false;
163 /* First, fetch the variable from the source */
165 PsppireDictView *dv = PSPPIRE_DICT_VIEW (sel->source);
167 GtkTreePath *path = gtk_tree_model_get_path (model, iter);
169 gint *idx = gtk_tree_path_get_indices (path);
171 const struct variable *var = psppire_dict_get_variable (dv->dict, *idx);
174 /* Now test if that variable exists in the destination */
178 g_value_init (&value, PSPPIRE_VAR_PTR_TYPE);
179 g_value_set_boxed (&value, var);
181 ret = psppire_select_dest_widget_contains_var (PSPPIRE_SELECT_DEST_WIDGET (sel->dest), &value);
183 g_value_unset (&value);