1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17
18 #include <config.h>
19 #include <gettext.h>
20 #include <gtk/gtk.h>
21
22 #include "psppire-conf.h"
23 #include "dict-display.h"
24
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>
32 #include "helper.h"
33 #include <data/variable.h>
34 #include <data/format.h>
35
36 #define _(msgid) gettext (msgid)
37 #define N_(msgid) msgid
38
39
40 void
41 get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter,
42 GtkTreeModel **model, GtkTreeIter *iter)
43 {
44 *model = top_model;
45
46 if (iter)
47 *iter = *top_iter;
48
49 while (! PSPPIRE_IS_DICT (*model))
50 {
51 GtkTreeIter parent_iter;
52 if (iter)
53 parent_iter = *iter;
54
55 if (GTK_IS_TREE_MODEL_FILTER (*model))
56 {
Lock()57 GtkTreeModelFilter *parent_model = GTK_TREE_MODEL_FILTER (*model);
Unlock()58
59 *model = gtk_tree_model_filter_get_model (parent_model);
60
61 if (iter)
62 gtk_tree_model_filter_convert_iter_to_child_iter (parent_model,
63 iter,
64 &parent_iter);
65 }
66 else if (GTK_IS_TREE_MODEL_SORT (*model))
67 {
68 GtkTreeModelSort *parent_model = GTK_TREE_MODEL_SORT (*model);
CondVar(Mutex * mu)69
70 *model = gtk_tree_model_sort_get_model (parent_model);
71
72 if (iter)
73 gtk_tree_model_sort_convert_iter_to_child_iter (parent_model,
74 iter,
Wait()75 &parent_iter);
76 }
77 }
78 }
79
Signal()80
81 void
82 insert_source_row_into_entry (GtkTreeIter iter,
83 GtkWidget *dest,
84 GtkTreeModel *model,
85 gpointer data
86 )
87 {
88 GtkTreePath *path;
89 GtkTreeModel *dict;
90 gint *idx;
91 struct variable *var;
92 GtkTreeIter dict_iter;
93
94 g_return_if_fail (GTK_IS_ENTRY(dest));
95
96 get_base_model (model, &iter, &dict, &dict_iter);
97
98 path = gtk_tree_model_get_path (GTK_TREE_MODEL (dict), &dict_iter);
99
100 idx = gtk_tree_path_get_indices (path);
101
102 var = psppire_dict_get_variable (PSPPIRE_DICT (dict), *idx);
103
104 gtk_tree_path_free (path);
105
106 gtk_entry_set_text (GTK_ENTRY (dest), var_get_name (var));
107 }
108
109
110
111 static void
112 insert_source_row_into_tree_model (GtkTreeIter source_iter,
113 GtkTreeModel *dest_model,
114 GtkTreeModel *source_model,
115 gpointer data)
116 {
117 GtkTreePath *path;
118 GtkTreeIter dest_iter;
Snappy_Uncompress(const char * input,size_t length,char * output)119 GtkTreeIter dict_iter;
120 gint *row ;
121
122 const struct variable *var;
123 GtkTreeModel *dict;
124
125 get_base_model (source_model, &source_iter, &dict, &dict_iter);
126
127 path = gtk_tree_model_get_path (dict, &dict_iter);
128
129 row = gtk_tree_path_get_indices (path);
130
GetHeapProfile(void (* func)(void *,const char *,int),void * arg)131 var = psppire_dict_get_variable (PSPPIRE_DICT (dict), *row);
132
133 gtk_list_store_append (GTK_LIST_STORE (dest_model), &dest_iter);
134
135 gtk_list_store_set (GTK_LIST_STORE (dest_model), &dest_iter, 0, var, -1);
136
137 gtk_tree_path_free (path);
AcceleratedCRC32C(uint32_t crc,const char * buf,size_t size)138 }
139
140
141
142 void
143 insert_source_row_into_tree_view (GtkTreeIter iter,
144 GtkWidget *dest,
145 GtkTreeModel *model,
146 gpointer data)
147 {
148 GtkTreeModel *destmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
149
150 insert_source_row_into_tree_model (iter, destmodel, model, data);
151 }
152
153
154 void
155 insert_source_row_into_layers (GtkTreeIter iter,
156 GtkWidget *dest,
157 GtkTreeModel *model,
158 gpointer data)
159 {
160 GtkTreeModel *destmodel = psppire_means_layer_get_model (PSPPIRE_MEANS_LAYER (dest));
161
162 insert_source_row_into_tree_model (iter, destmodel, model, data);
163
164 psppire_means_layer_update (PSPPIRE_MEANS_LAYER (dest));
165 }
166
167
168
169
170 gboolean
171 is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter,
172 PsppireSelector *selector)
173 {
174 gboolean result;
175 GtkTreeIter dict_iter;
176 GtkTreeModel *dict;
177 struct variable *var;
178 gint dict_index;
179 gint *indeces;
180 GtkTreePath *path;
181 GtkWidget *entry = NULL;
182 const gchar *text = NULL;
183
184 g_object_get (selector, "dest-widget", &entry, NULL);
185
186 text = gtk_entry_get_text (GTK_ENTRY (entry));
187
188 get_base_model (model, iter, &dict, &dict_iter);
189
190 path = gtk_tree_model_get_path (dict, &dict_iter);
191
192 indeces = gtk_tree_path_get_indices (path);
193
194 dict_index = indeces [0];
195
196 var = psppire_dict_get_variable (PSPPIRE_DICT (dict), dict_index);
197
198 gtk_tree_path_free (path);
199
200 result = (0 == strcmp (text, var_get_name (var)));
201
202 return result;
203 }
204
205 gboolean
206 is_currently_in_varview (GtkTreeModel *model, GtkTreeIter *iter, PsppireSelector *sel)
207 {
208 gboolean ret = false;
209
210 /* First, fetch the variable from the source */
211
212 PsppireDictView *dv = PSPPIRE_DICT_VIEW (sel->source);
213
214 GtkTreePath *path = gtk_tree_model_get_path (model, iter);
215
216 gint *idx = gtk_tree_path_get_indices (path);
217
218 const struct variable *var = psppire_dict_get_variable (dv->dict, *idx);
219
220
221 /* Now test if that variable exists in the destination */
222
223 GValue value = {0};
224
225 g_value_init (&value, PSPPIRE_VAR_PTR_TYPE);
226 g_value_set_boxed (&value, var);
227
228 ret = psppire_select_dest_widget_contains_var (PSPPIRE_SELECT_DEST_WIDGET (sel->dest), &value);
229
230 g_value_unset (&value);
231
232 return ret ;
233 }
234
235