Convert to utf8 in data_out function.
[pspp-builds.git] / src / ui / gui / dict-display.c
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 <libpspp/i18n.h>
27 #include "helper.h"
28 #include <data/variable.h>
29 #include <data/format.h>
30
31 #define _(msgid) gettext (msgid)
32 #define N_(msgid) msgid
33
34 static void
35 get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter,
36                 GtkTreeModel **model, GtkTreeIter *iter
37                 )
38 {
39   *model = top_model;
40   *iter = *top_iter;
41   while (GTK_IS_TREE_MODEL_FILTER (*model))
42     {
43       GtkTreeIter parent_iter = *iter;
44       GtkTreeModelFilter *parent_model = GTK_TREE_MODEL_FILTER (*model);
45
46       *model = gtk_tree_model_filter_get_model (parent_model);
47
48       gtk_tree_model_filter_convert_iter_to_child_iter (parent_model,
49                                                         iter,
50                                                         &parent_iter);
51     }
52
53   g_assert (PSPPIRE_IS_DICT (*model));
54 }
55
56
57
58 void
59 insert_source_row_into_entry (GtkTreeIter iter,
60                               GtkWidget *dest,
61                               GtkTreeModel *model,
62                               gpointer data
63                               )
64 {
65   GtkTreePath *path;
66   GtkTreeModel *dict;
67   gint *idx;
68   struct variable *var;
69   GtkTreeIter dict_iter;
70
71   g_return_if_fail (GTK_IS_ENTRY(dest));
72
73   get_base_model (model, &iter, &dict, &dict_iter);
74
75   path = gtk_tree_model_get_path (GTK_TREE_MODEL (dict), &dict_iter);
76
77   idx = gtk_tree_path_get_indices (path);
78
79   var =  psppire_dict_get_variable (PSPPIRE_DICT (dict), *idx);
80
81   gtk_tree_path_free (path);
82
83   gtk_entry_set_text (GTK_ENTRY (dest),  var_get_name (var));
84 }
85
86
87
88 void
89 insert_source_row_into_tree_view (GtkTreeIter iter,
90                                   GtkWidget *dest,
91                                   GtkTreeModel *model,
92                                   gpointer data
93                                   )
94 {
95   GtkTreePath *path;
96   GtkTreeIter dest_iter;
97   GtkTreeIter dict_iter;
98   gint *row ;
99   GtkTreeModel *destmodel = gtk_tree_view_get_model ( GTK_TREE_VIEW (dest));
100
101   GtkTreeModel *dict;
102
103
104   get_base_model (model, &iter, &dict, &dict_iter);
105
106   path = gtk_tree_model_get_path (dict, &dict_iter);
107
108   row = gtk_tree_path_get_indices (path);
109
110   gtk_list_store_append (GTK_LIST_STORE (destmodel),  &dest_iter);
111   gtk_list_store_set (GTK_LIST_STORE (destmodel), &dest_iter, 0, *row, -1);
112
113   gtk_tree_path_free (path);
114 }
115
116
117 gboolean
118 is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter,
119                        PsppireSelector *selector)
120 {
121   gboolean result;
122   GtkTreeIter dict_iter;
123   GtkTreeModel *dict;
124   struct variable *var;
125   gint dict_index;
126   gint *indeces;
127   GtkTreePath *path;
128   const gchar *text =  gtk_entry_get_text (GTK_ENTRY (selector->dest));
129
130   get_base_model (model, iter, &dict, &dict_iter);
131
132   path = gtk_tree_model_get_path (dict, &dict_iter);
133
134   indeces = gtk_tree_path_get_indices (path);
135
136   dict_index = indeces [0];
137
138   var = psppire_dict_get_variable (PSPPIRE_DICT (dict), dict_index);
139
140   gtk_tree_path_free (path);
141
142   result = ( 0 == strcmp (text, var_get_name (var) ));
143
144   return result;
145 }
146
147
148