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