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-means-layer.h"
28 #include "psppire-var-ptr.h"
29 #include "psppire-var-view.h"
30 #include "psppire-select-dest.h"
31 #include <libpspp/i18n.h>
33 #include <data/variable.h>
34 #include <data/format.h>
36 #define _(msgid) gettext (msgid)
37 #define N_(msgid) msgid
41 get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter,
42 GtkTreeModel **model, GtkTreeIter *iter)
49 while (! PSPPIRE_IS_DICT (*model))
51 GtkTreeIter parent_iter;
55 if (GTK_IS_TREE_MODEL_FILTER (*model))
57 GtkTreeModelFilter *parent_model = GTK_TREE_MODEL_FILTER (*model);
59 *model = gtk_tree_model_filter_get_model (parent_model);
62 gtk_tree_model_filter_convert_iter_to_child_iter (parent_model,
66 else if (GTK_IS_TREE_MODEL_SORT (*model))
68 GtkTreeModelSort *parent_model = GTK_TREE_MODEL_SORT (*model);
70 *model = gtk_tree_model_sort_get_model (parent_model);
73 gtk_tree_model_sort_convert_iter_to_child_iter (parent_model,
82 insert_source_row_into_entry (GtkTreeIter iter,
92 GtkTreeIter dict_iter;
94 g_return_if_fail (GTK_IS_ENTRY(dest));
96 get_base_model (model, &iter, &dict, &dict_iter);
98 path = gtk_tree_model_get_path (GTK_TREE_MODEL (dict), &dict_iter);
100 idx = gtk_tree_path_get_indices (path);
102 var = psppire_dict_get_variable (PSPPIRE_DICT (dict), *idx);
104 gtk_tree_path_free (path);
106 gtk_entry_set_text (GTK_ENTRY (dest), var_get_name (var));
112 insert_source_row_into_tree_model (GtkTreeIter source_iter,
113 GtkTreeModel *dest_model,
114 GtkTreeModel *source_model,
118 GtkTreeIter dest_iter;
119 GtkTreeIter dict_iter;
122 const struct variable *var;
125 get_base_model (source_model, &source_iter, &dict, &dict_iter);
127 path = gtk_tree_model_get_path (dict, &dict_iter);
129 row = gtk_tree_path_get_indices (path);
131 var = psppire_dict_get_variable (PSPPIRE_DICT (dict), *row);
133 gtk_list_store_append (GTK_LIST_STORE (dest_model), &dest_iter);
135 gtk_list_store_set (GTK_LIST_STORE (dest_model), &dest_iter, 0, var, -1);
137 gtk_tree_path_free (path);
143 insert_source_row_into_tree_view (GtkTreeIter iter,
148 GtkTreeModel *destmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
150 insert_source_row_into_tree_model (iter, destmodel, model, data);
155 insert_source_row_into_layers (GtkTreeIter iter,
160 GtkTreeModel *destmodel = psppire_means_layer_get_model (PSPPIRE_MEANS_LAYER (dest));
162 insert_source_row_into_tree_model (iter, destmodel, model, data);
164 psppire_means_layer_update (PSPPIRE_MEANS_LAYER (dest));
171 is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter,
172 PsppireSelector *selector)
175 GtkTreeIter dict_iter;
177 struct variable *var;
181 GtkWidget *entry = NULL;
182 const gchar *text = NULL;
184 g_object_get (selector, "dest-widget", &entry, NULL);
186 text = gtk_entry_get_text (GTK_ENTRY (entry));
188 get_base_model (model, iter, &dict, &dict_iter);
190 path = gtk_tree_model_get_path (dict, &dict_iter);
192 indeces = gtk_tree_path_get_indices (path);
194 dict_index = indeces [0];
196 var = psppire_dict_get_variable (PSPPIRE_DICT (dict), dict_index);
198 gtk_tree_path_free (path);
200 result = (0 == strcmp (text, var_get_name (var)));
206 is_currently_in_varview (GtkTreeModel *model, GtkTreeIter *iter, PsppireSelector *sel)
208 gboolean ret = false;
210 /* First, fetch the variable from the source */
212 PsppireDictView *dv = PSPPIRE_DICT_VIEW (sel->source);
214 GtkTreePath *path = gtk_tree_model_get_path (model, iter);
216 gint *idx = gtk_tree_path_get_indices (path);
218 const struct variable *var = psppire_dict_get_variable (dv->dict, *idx);
221 /* Now test if that variable exists in the destination */
225 g_value_init (&value, PSPPIRE_VAR_PTR_TYPE);
226 g_value_set_boxed (&value, var);
228 ret = psppire_select_dest_widget_contains_var (PSPPIRE_SELECT_DEST_WIDGET (sel->dest), &value);
230 g_value_unset (&value);