d6b1bcd58c3b60bc5bb17705da7c18c4121d4105
[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   gchar *name;
71
72   g_return_if_fail (GTK_IS_ENTRY(dest));
73
74   get_base_model (model, &iter, &dict, &dict_iter);
75
76   path = gtk_tree_model_get_path (GTK_TREE_MODEL (dict), &dict_iter);
77
78   idx = gtk_tree_path_get_indices (path);
79
80   var =  psppire_dict_get_variable (PSPPIRE_DICT (dict), *idx);
81
82   gtk_tree_path_free (path);
83
84   name = recode_string (UTF8, psppire_dict_encoding (PSPPIRE_DICT (dict)),
85                         var_get_name (var), -1);
86   gtk_entry_set_text (GTK_ENTRY (dest),  name);
87   g_free (name);
88 }
89
90
91
92 void
93 insert_source_row_into_tree_view (GtkTreeIter iter,
94                                   GtkWidget *dest,
95                                   GtkTreeModel *model,
96                                   gpointer data
97                                   )
98 {
99   GtkTreePath *path;
100   GtkTreeIter dest_iter;
101   GtkTreeIter dict_iter;
102   gint *row ;
103   GtkTreeModel *destmodel = gtk_tree_view_get_model ( GTK_TREE_VIEW (dest));
104
105   GtkTreeModel *dict;
106
107
108   get_base_model (model, &iter, &dict, &dict_iter);
109
110   path = gtk_tree_model_get_path (dict, &dict_iter);
111
112   row = gtk_tree_path_get_indices (path);
113
114   gtk_list_store_append (GTK_LIST_STORE (destmodel),  &dest_iter);
115   gtk_list_store_set (GTK_LIST_STORE (destmodel), &dest_iter, 0, *row, -1);
116
117   gtk_tree_path_free (path);
118 }
119
120
121 gboolean
122 is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter,
123                        PsppireSelector *selector)
124 {
125   gboolean result;
126   gchar *name;
127   GtkTreeIter dict_iter;
128   GtkTreeModel *dict;
129   struct variable *var;
130   gint dict_index;
131   gint *indeces;
132   GtkTreePath *path;
133   const gchar *text =   gtk_entry_get_text (GTK_ENTRY (selector->dest));
134
135   get_base_model (model, iter, &dict, &dict_iter);
136
137   path = gtk_tree_model_get_path (dict, &dict_iter);
138
139   indeces = gtk_tree_path_get_indices (path);
140
141   dict_index = indeces [0];
142
143   var = psppire_dict_get_variable (PSPPIRE_DICT (dict), dict_index);
144
145   gtk_tree_path_free (path);
146
147   name = recode_string (UTF8, psppire_dict_encoding (PSPPIRE_DICT (dict)),
148                         var_get_name (var), -1);
149   result = ( 0 == strcmp (text, name));
150   g_free (name);
151
152   return result;
153 }
154
155
156