Remove unused code
[pspp-builds.git] / src / ui / gui / dialog-common.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 #include <config.h>
18
19 #include <libpspp/i18n.h>
20 #include "dialog-common.h"
21
22 #include "psppire-var-ptr.h"
23
24 #include "helper.h"
25
26
27 /* Returns FALSE if the variables represented by the union of the rows
28    currently selected by SOURCE widget, and contents of the DEST
29    widget, are of different types.
30
31    In other words, this function when passed as the argument to
32    psppire_selector_set_allow, ensures that the selector selects only
33    string  variables, or only numeric variables, not a mixture.
34 */
35 gboolean
36 homogeneous_types (GtkWidget *source, GtkWidget *dest)
37 {
38   gboolean ok;
39   GtkTreeIter iter;
40   gboolean retval = TRUE;
41
42   GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
43
44   PsppireDict *dict;
45   GtkTreeSelection *selection;
46   enum val_type type = -1;
47   GList *list, *l;
48
49   while (GTK_IS_TREE_MODEL_FILTER (model))
50     {
51       model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
52     }
53
54   dict = PSPPIRE_DICT (model);
55
56   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
57
58   list = gtk_tree_selection_get_selected_rows (selection, &model);
59
60   /* Iterate through the selection of the source treeview */
61   for (l = list; l ; l = l->next)
62     {
63       GtkTreePath *path = l->data;
64
65       GtkTreePath *fpath =
66         gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path);
67
68       gint *idx = gtk_tree_path_get_indices (fpath);
69
70       const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
71
72       gtk_tree_path_free (fpath);
73
74       if ( type != -1 )
75         {
76           if ( var_get_type (v) != type )
77             {
78               retval = FALSE;
79               break;
80             }
81         }
82
83       type = var_get_type (v);
84     }
85
86   g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
87   g_list_free (list);
88
89   if ( retval == FALSE )
90     return FALSE;
91
92   /* now deal with the dest widget */
93   model = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
94
95   for (ok = gtk_tree_model_get_iter_first (model, &iter);
96        ok;
97        ok = gtk_tree_model_iter_next (model, &iter))
98     {
99       const struct variable *v;
100       gtk_tree_model_get (model, &iter, 0, &v, -1);
101
102       if ( type != -1 )
103         {
104           if ( var_get_type (v) != type )
105             {
106               retval = FALSE;
107               break;
108             }
109         }
110
111       type = var_get_type (v);
112     }
113
114   return retval;
115 }
116
117
118
119 /* Returns true iff the variable selected by SOURCE is numeric */
120 gboolean
121 numeric_only (GtkWidget *source, GtkWidget *dest)
122 {
123   gboolean retval = TRUE;
124
125   GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));
126
127   PsppireDict *dict;
128   GtkTreeSelection *selection;
129   GList *list, *l;
130
131   while (GTK_IS_TREE_MODEL_FILTER (model))
132     {
133       model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
134     }
135
136   dict = PSPPIRE_DICT (model);
137
138   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));
139
140   list = gtk_tree_selection_get_selected_rows (selection, &model);
141
142   /* Iterate through the selection of the source treeview */
143   for (l = list; l ; l = l->next)
144     {
145       GtkTreePath *path = l->data;
146       GtkTreePath *fpath = gtk_tree_model_filter_convert_path_to_child_path
147         (GTK_TREE_MODEL_FILTER (model), path);
148
149       gint *idx = gtk_tree_path_get_indices (fpath);
150
151       const struct variable *v = psppire_dict_get_variable (dict, idx[0]);
152
153       gtk_tree_path_free (fpath);
154
155       if ( var_is_alpha (v))
156         {
157           retval = FALSE;
158           break;
159         }
160     }
161
162   g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
163   g_list_free (list);
164
165   return retval;
166 }
167