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