7b308c0e3f6b7ac348c0a49865dbdff11100223b
[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-variable-sheet.h"
83 #include <ssw-sheet.h>
84
85
86 static  volatile GType kludge;
87
88
89 typedef GType (*get_type_func)(void);
90
91 static const get_type_func dialog_action_types[]=
92 {
93   psppire_dialog_action_1sks_get_type,
94   psppire_dialog_action_autorecode_get_type,
95   psppire_dialog_action_aggregate_get_type,
96   psppire_dialog_action_binomial_get_type,
97   psppire_dialog_action_barchart_get_type,
98   psppire_dialog_action_chisquare_get_type,
99   psppire_dialog_action_compute_get_type,
100   psppire_dialog_action_comments_get_type,
101   psppire_dialog_action_correlation_get_type,
102   psppire_dialog_action_count_get_type,
103   psppire_dialog_action_crosstabs_get_type,
104   psppire_dialog_action_descriptives_get_type,
105   psppire_dialog_action_examine_get_type,
106   psppire_dialog_action_factor_get_type,
107   psppire_dialog_action_flip_get_type,
108   psppire_dialog_action_frequencies_get_type,
109   psppire_dialog_action_histogram_get_type,
110   psppire_dialog_action_logistic_get_type,
111   psppire_dialog_action_kmeans_get_type,
112   psppire_dialog_action_k_independent_get_type,
113   psppire_dialog_action_k_related_get_type,
114   psppire_dialog_action_means_get_type,
115   psppire_dialog_action_oneway_get_type,
116   psppire_dialog_action_paired_get_type,
117   psppire_dialog_action_indep_samps_get_type,
118   psppire_dialog_action_var_info_get_type,
119   psppire_dialog_action_rank_get_type,
120   psppire_dialog_action_recode_same_get_type,
121   psppire_dialog_action_recode_different_get_type,
122   psppire_dialog_action_reliability_get_type,
123   psppire_dialog_action_regression_get_type,
124   psppire_dialog_action_roc_get_type,
125   psppire_dialog_action_runs_get_type,
126   psppire_dialog_action_scatterplot_get_type,
127   psppire_dialog_action_select_get_type,
128   psppire_dialog_action_sort_get_type,
129   psppire_dialog_action_split_get_type,
130   psppire_dialog_action_tt1s_get_type,
131   psppire_dialog_action_two_sample_get_type,
132   psppire_dialog_action_weight_get_type,
133   psppire_dialog_action_univariate_get_type
134 };
135
136
137 static void
138 preregister_actions (void)
139 {
140   int i;
141   for (i = 0; i < sizeof (dialog_action_types) / sizeof (dialog_action_types[0]); ++i)
142     {
143       get_type_func x = dialog_action_types[i];
144       x ();
145     }
146 }
147
148
149 static void
150 tx_string_to_double (const GValue *src, GValue *dest)
151 {
152   const gchar *str = g_value_get_string (src);
153   gdouble dble = g_strtod (str, NULL);
154   g_value_set_double (dest, dble);
155 }
156
157
158 static void
159 tx_string_to_int (const GValue *src, GValue *dest)
160 {
161   const gchar *str = g_value_get_string (src);
162   gint x = atoi (str);
163   g_value_set_int (dest, x);
164 }
165
166 static void
167 enum_to_string (const GValue *src, GValue *dest)
168 {
169   gint n = g_value_get_enum (src);
170   GType t = G_VALUE_TYPE (src);
171   GEnumClass *ec = g_type_class_ref (t);
172   GEnumValue *ev = g_enum_get_value (ec, n);
173
174   g_value_set_string (dest, gettext (ev->value_nick));
175 }
176
177
178
179 extern GType align_enum_type;
180 extern GType measure_enum_type;
181 extern GType role_enum_type;
182
183
184 extern const GEnumValue align[];
185 extern const GEnumValue measure[];
186 extern const GEnumValue role[];
187
188
189
190 static void
191 preregister_misc (void)
192 {
193   align_enum_type = g_enum_register_static ("PsppAlignment", align);
194   measure_enum_type = g_enum_register_static ("PsppMeasure", measure);
195   role_enum_type = g_enum_register_static ("PsppRole", role);
196
197   g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DOUBLE, tx_string_to_double);
198   g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, tx_string_to_int);
199
200   g_value_register_transform_func (measure_enum_type, G_TYPE_STRING, enum_to_string);
201   g_value_register_transform_func (align_enum_type, G_TYPE_STRING, enum_to_string);
202   g_value_register_transform_func (role_enum_type, G_TYPE_STRING, enum_to_string);
203 }
204
205
206 /* Any custom widgets which are to be used in GtkBuilder ui files
207    need to be preregistered, otherwise GtkBuilder refuses to
208    acknowledge their existence. */
209 void
210 preregister_widgets (void)
211 {
212   psppire_val_chooser_get_type ();
213   psppire_dialog_get_type ();
214   psppire_selector_get_type ();
215   psppire_button_box_get_type ();
216   psppire_keypad_get_type ();
217   psppire_acr_get_type ();
218   psppire_dict_view_get_type ();
219   psppire_var_view_get_type ();
220   psppire_value_entry_get_type ();
221   psppire_checkbox_treeview_get_type ();
222   psppire_means_layer_get_type ();
223   ssw_sheet_get_type ();
224   psppire_data_sheet_get_type ();
225   psppire_var_sheet_header_get_type ();
226   psppire_variable_sheet_get_type ();
227
228   preregister_actions ();
229   preregister_misc ();
230
231   /* This seems to be necessary on Cygwin.
232      It ought not to be necessary.  Having it here can't do any harm. */
233   kludge = gtk_source_view_get_type ();
234 }