Reimplement the variable info dialog.
[pspp] / src / ui / gui / widgets.c
1 /*
2 PSPP - a program for statistical analysis.
3 Copyright (C) 2017 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <config.h>
20
21 #include <gtksourceview/gtksource.h>
22
23 #include "widgets.h"
24
25 #include "gettext.h"
26
27 #include "psppire-dialog.h"
28 #include "psppire-selector.h"
29 #include "psppire-buttonbox.h"
30 #include "psppire-keypad.h"
31 #include "psppire-acr.h"
32 #include "psppire-dictview.h"
33 #include "psppire-var-view.h"
34 #include "psppire-val-chooser.h"
35 #include "psppire-checkbox-treeview.h"
36
37 #include "psppire-dialog-action-aggregate.h"
38 #include "psppire-dialog-action-autorecode.h"
39 #include "psppire-dialog-action-barchart.h"
40 #include "psppire-dialog-action-binomial.h"
41 #include "psppire-dialog-action-chisquare.h"
42 #include "psppire-dialog-action-compute.h"
43 #include "psppire-dialog-action-comments.h"
44 #include "psppire-dialog-action-correlation.h"
45 #include "psppire-dialog-action-count.h"
46 #include "psppire-dialog-action-crosstabs.h"
47 #include "psppire-dialog-action-descriptives.h"
48 #include "psppire-dialog-action-examine.h"
49 #include "psppire-dialog-action-flip.h"
50 #include "psppire-dialog-action-factor.h"
51 #include "psppire-dialog-action-frequencies.h"
52 #include "psppire-dialog-action-histogram.h"
53 #include "psppire-dialog-action-indep-samps.h"
54 #include "psppire-dialog-action-k-related.h"
55 #include "psppire-dialog-action-k-independent.h"
56 #include "psppire-dialog-action-1sks.h"
57 #include "psppire-dialog-action-kmeans.h"
58 #include "psppire-dialog-action-logistic.h"
59 #include "psppire-dialog-action-means.h"
60 #include "psppire-dialog-action-paired.h"
61 #include "psppire-dialog-action-oneway.h"
62 #include "psppire-means-layer.h"
63 #include "psppire-dialog-action-rank.h"
64 #include "psppire-dialog-action-recode-same.h"
65 #include "psppire-dialog-action-recode-different.h"
66 #include "psppire-dialog-action-regression.h"
67 #include "psppire-dialog-action-reliability.h"
68 #include "psppire-dialog-action-roc.h"
69 #include "psppire-dialog-action-runs.h"
70 #include "psppire-dialog-action-scatterplot.h"
71 #include "psppire-dialog-action-select.h"
72 #include "psppire-dialog-action-sort.h"
73 #include "psppire-dialog-action-split.h"
74 #include "psppire-dialog-action-tt1s.h"
75 #include "psppire-dialog-action-two-sample.h"
76 #include "psppire-dialog-action-univariate.h"
77 #include "psppire-dialog-action-var-info.h"
78 #include "psppire-dialog-action-weight.h"
79 #include "psppire-value-entry.h"
80 #include "psppire-data-sheet.h"
81 #include "psppire-var-sheet-header.h"
82 #include "psppire-var-info.h"
83 #include "psppire-variable-sheet.h"
84 #include <ssw-sheet.h>
85
86
87 static  volatile GType kludge;
88
89
90 typedef GType (*get_type_func)(void);
91
92 static const get_type_func dialog_action_types[]=
93 {
94   psppire_dialog_action_1sks_get_type,
95   psppire_dialog_action_autorecode_get_type,
96   psppire_dialog_action_aggregate_get_type,
97   psppire_dialog_action_binomial_get_type,
98   psppire_dialog_action_barchart_get_type,
99   psppire_dialog_action_chisquare_get_type,
100   psppire_dialog_action_compute_get_type,
101   psppire_dialog_action_comments_get_type,
102   psppire_dialog_action_correlation_get_type,
103   psppire_dialog_action_count_get_type,
104   psppire_dialog_action_crosstabs_get_type,
105   psppire_dialog_action_descriptives_get_type,
106   psppire_dialog_action_examine_get_type,
107   psppire_dialog_action_factor_get_type,
108   psppire_dialog_action_flip_get_type,
109   psppire_dialog_action_frequencies_get_type,
110   psppire_dialog_action_histogram_get_type,
111   psppire_dialog_action_logistic_get_type,
112   psppire_dialog_action_kmeans_get_type,
113   psppire_dialog_action_k_independent_get_type,
114   psppire_dialog_action_k_related_get_type,
115   psppire_dialog_action_means_get_type,
116   psppire_dialog_action_oneway_get_type,
117   psppire_dialog_action_paired_get_type,
118   psppire_dialog_action_indep_samps_get_type,
119   psppire_dialog_action_var_info_get_type,
120   psppire_dialog_action_rank_get_type,
121   psppire_dialog_action_recode_same_get_type,
122   psppire_dialog_action_recode_different_get_type,
123   psppire_dialog_action_reliability_get_type,
124   psppire_dialog_action_regression_get_type,
125   psppire_dialog_action_roc_get_type,
126   psppire_dialog_action_runs_get_type,
127   psppire_dialog_action_scatterplot_get_type,
128   psppire_dialog_action_select_get_type,
129   psppire_dialog_action_sort_get_type,
130   psppire_dialog_action_split_get_type,
131   psppire_dialog_action_tt1s_get_type,
132   psppire_dialog_action_two_sample_get_type,
133   psppire_dialog_action_weight_get_type,
134   psppire_dialog_action_univariate_get_type
135 };
136
137
138 static void
139 preregister_actions (void)
140 {
141   int i;
142   for (i = 0; i < sizeof (dialog_action_types) / sizeof (dialog_action_types[0]); ++i)
143     {
144       get_type_func x = dialog_action_types[i];
145       x ();
146     }
147 }
148
149
150 static void
151 tx_string_to_double (const GValue *src, GValue *dest)
152 {
153   const gchar *str = g_value_get_string (src);
154   gdouble dble = g_strtod (str, NULL);
155   g_value_set_double (dest, dble);
156 }
157
158
159 static void
160 tx_string_to_int (const GValue *src, GValue *dest)
161 {
162   const gchar *str = g_value_get_string (src);
163   gint x = atoi (str);
164   g_value_set_int (dest, x);
165 }
166
167 static void
168 enum_to_string (const GValue *src, GValue *dest)
169 {
170   gint n = g_value_get_enum (src);
171   GType t = G_VALUE_TYPE (src);
172   GEnumClass *ec = g_type_class_ref (t);
173   GEnumValue *ev = g_enum_get_value (ec, n);
174
175   g_value_set_string (dest, gettext (ev->value_nick));
176 }
177
178
179
180 extern GType align_enum_type;
181 extern GType measure_enum_type;
182 extern GType role_enum_type;
183
184
185 extern const GEnumValue align[];
186 extern const GEnumValue measure[];
187 extern const GEnumValue role[];
188
189
190
191 static void
192 preregister_misc (void)
193 {
194   align_enum_type = g_enum_register_static ("PsppAlignment", align);
195   measure_enum_type = g_enum_register_static ("PsppMeasure", measure);
196   role_enum_type = g_enum_register_static ("PsppRole", role);
197
198   g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DOUBLE, tx_string_to_double);
199   g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, tx_string_to_int);
200
201   g_value_register_transform_func (measure_enum_type, G_TYPE_STRING, enum_to_string);
202   g_value_register_transform_func (align_enum_type, G_TYPE_STRING, enum_to_string);
203   g_value_register_transform_func (role_enum_type, G_TYPE_STRING, enum_to_string);
204 }
205
206
207 /* Any custom widgets which are to be used in GtkBuilder ui files
208    need to be preregistered, otherwise GtkBuilder refuses to
209    acknowledge their existence. */
210 void
211 preregister_widgets (void)
212 {
213   psppire_val_chooser_get_type ();
214   psppire_dialog_get_type ();
215   psppire_selector_get_type ();
216   psppire_button_box_get_type ();
217   psppire_keypad_get_type ();
218   psppire_acr_get_type ();
219   psppire_dict_view_get_type ();
220   psppire_var_view_get_type ();
221   psppire_value_entry_get_type ();
222   psppire_checkbox_treeview_get_type ();
223   psppire_means_layer_get_type ();
224   ssw_sheet_get_type ();
225   psppire_data_sheet_get_type ();
226   psppire_var_sheet_header_get_type ();
227   psppire_variable_sheet_get_type ();
228   psppire_var_info_get_type ();
229
230   preregister_actions ();
231   preregister_misc ();
232
233   /* This seems to be necessary on Cygwin.
234      It ought not to be necessary.  Having it here can't do any harm. */
235   kludge = gtk_source_view_get_type ();
236 }