Merge remote-tracking branch 'origin/master' into sheet
[pspp] / src / ui / gui / widgets.c
1 #include <config.h>
2
3 #include <gtksourceview/gtksource.h>
4
5 #include "widgets.h"
6
7 #include "gettext.h"
8
9 #include "psppire-dialog.h"
10 #include "psppire-selector.h"
11 #include "psppire-buttonbox.h"
12 #include "psppire-keypad.h"
13 #include "psppire-acr.h"
14 #include "psppire-dictview.h"
15 #include "psppire-var-view.h"
16 #include "psppire-val-chooser.h"
17 #include "psppire-checkbox-treeview.h"
18
19 #include "psppire-dialog-action-aggregate.h"
20 #include "psppire-dialog-action-autorecode.h"
21 #include "psppire-dialog-action-barchart.h"
22 #include "psppire-dialog-action-binomial.h"
23 #include "psppire-dialog-action-chisquare.h"
24 #include "psppire-dialog-action-compute.h"
25 #include "psppire-dialog-action-comments.h"
26 #include "psppire-dialog-action-correlation.h"
27 #include "psppire-dialog-action-count.h"
28 #include "psppire-dialog-action-crosstabs.h"
29 #include "psppire-dialog-action-descriptives.h"
30 #include "psppire-dialog-action-examine.h"
31 #include "psppire-dialog-action-flip.h"
32 #include "psppire-dialog-action-factor.h"
33 #include "psppire-dialog-action-frequencies.h"
34 #include "psppire-dialog-action-histogram.h"
35 #include "psppire-dialog-action-indep-samps.h"
36 #include "psppire-dialog-action-k-related.h"
37 #include "psppire-dialog-action-k-independent.h"
38 #include "psppire-dialog-action-1sks.h"
39 #include "psppire-dialog-action-kmeans.h"
40 #include "psppire-dialog-action-logistic.h"
41 #include "psppire-dialog-action-means.h"
42 #include "psppire-dialog-action-paired.h"
43 #include "psppire-dialog-action-oneway.h"
44 #include "psppire-means-layer.h"
45 #include "psppire-dialog-action-rank.h"
46 #include "psppire-dialog-action-recode-same.h"
47 #include "psppire-dialog-action-recode-different.h"
48 #include "psppire-dialog-action-regression.h"
49 #include "psppire-dialog-action-reliability.h"
50 #include "psppire-dialog-action-roc.h"
51 #include "psppire-dialog-action-runs.h"
52 #include "psppire-dialog-action-scatterplot.h"
53 #include "psppire-dialog-action-select.h"
54 #include "psppire-dialog-action-sort.h"
55 #include "psppire-dialog-action-split.h"
56 #include "psppire-dialog-action-tt1s.h"
57 #include "psppire-dialog-action-two-sample.h"
58 #include "psppire-dialog-action-univariate.h"
59 #include "psppire-dialog-action-var-info.h"
60 #include "psppire-dialog-action-weight.h"
61 #include "psppire-value-entry.h"
62
63 static  volatile GType kludge;
64
65
66 typedef GType (*get_type_func)(void);
67
68 static const get_type_func dialog_action_types[]=
69 {
70   psppire_dialog_action_1sks_get_type,
71   psppire_dialog_action_autorecode_get_type,
72   psppire_dialog_action_aggregate_get_type,
73   psppire_dialog_action_binomial_get_type,
74   psppire_dialog_action_barchart_get_type,
75   psppire_dialog_action_chisquare_get_type,
76   psppire_dialog_action_compute_get_type,
77   psppire_dialog_action_comments_get_type,
78   psppire_dialog_action_correlation_get_type,
79   psppire_dialog_action_count_get_type,
80   psppire_dialog_action_crosstabs_get_type,
81   psppire_dialog_action_descriptives_get_type,
82   psppire_dialog_action_examine_get_type,
83   psppire_dialog_action_factor_get_type,
84   psppire_dialog_action_flip_get_type,
85   psppire_dialog_action_frequencies_get_type,
86   psppire_dialog_action_histogram_get_type,
87   psppire_dialog_action_logistic_get_type,
88   psppire_dialog_action_kmeans_get_type,
89   psppire_dialog_action_k_independent_get_type,
90   psppire_dialog_action_k_related_get_type,
91   psppire_dialog_action_means_get_type,
92   psppire_dialog_action_oneway_get_type,
93   psppire_dialog_action_paired_get_type,
94   psppire_dialog_action_indep_samps_get_type,
95   psppire_dialog_action_var_info_get_type,
96   psppire_dialog_action_rank_get_type,
97   psppire_dialog_action_recode_same_get_type,
98   psppire_dialog_action_recode_different_get_type,
99   psppire_dialog_action_reliability_get_type,
100   psppire_dialog_action_regression_get_type,
101   psppire_dialog_action_roc_get_type,
102   psppire_dialog_action_runs_get_type,
103   psppire_dialog_action_scatterplot_get_type,
104   psppire_dialog_action_select_get_type,
105   psppire_dialog_action_sort_get_type,
106   psppire_dialog_action_split_get_type,
107   psppire_dialog_action_tt1s_get_type,
108   psppire_dialog_action_two_sample_get_type,
109   psppire_dialog_action_weight_get_type,
110   psppire_dialog_action_univariate_get_type
111 };
112
113
114 static void
115 preregister_actions (void)
116 {
117   int i;
118   for (i = 0; i < sizeof (dialog_action_types) / sizeof (dialog_action_types[0]); ++i)
119     {
120       get_type_func x = dialog_action_types[i];
121       x ();
122     }
123 }
124
125
126 static void
127 tx_string_to_double (const GValue *src, GValue *dest)
128 {
129   const gchar *str = g_value_get_string (src);
130   gdouble dble = g_strtod (str, NULL);
131   g_value_set_double (dest, dble);
132 }
133
134
135 static void
136 tx_string_to_int (const GValue *src, GValue *dest)
137 {
138   const gchar *str = g_value_get_string (src);
139   gint x = atoi (str);
140   g_value_set_int (dest, x);
141 }
142
143 static void
144 enum_to_string (const GValue *src, GValue *dest)
145 {
146   gint n = g_value_get_enum (src);
147   GType t = G_VALUE_TYPE (src);
148   GEnumClass *ec = g_type_class_ref (t);
149   GEnumValue *ev = g_enum_get_value (ec, n);
150
151   g_value_set_string (dest, gettext (ev->value_nick));
152 }
153
154
155
156 GType align_enum_type;
157 GType measure_enum_type;
158 GType role_enum_type;
159
160
161 extern const GEnumValue align[];
162 extern const GEnumValue measure[];
163 extern const GEnumValue role[];
164
165
166
167 static void
168 preregister_misc (void)
169 {
170   align_enum_type = g_enum_register_static ("PsppAlignment", align);
171   measure_enum_type = g_enum_register_static ("PsppMeasure", measure);
172   role_enum_type = g_enum_register_static ("PsppRole", role);
173
174   g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DOUBLE, tx_string_to_double);
175   g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, tx_string_to_int);
176
177   g_value_register_transform_func (measure_enum_type, G_TYPE_STRING, enum_to_string);
178   g_value_register_transform_func (align_enum_type, G_TYPE_STRING, enum_to_string);
179   g_value_register_transform_func (role_enum_type, G_TYPE_STRING, enum_to_string);
180 }
181
182
183 /* Any custom widgets which are to be used in GtkBuilder ui files
184    need to be preregistered, otherwise GtkBuilder refuses to
185    acknowledge their existence. */
186 void
187 preregister_widgets (void)
188 {
189   psppire_val_chooser_get_type ();
190   psppire_dialog_get_type ();
191   psppire_selector_get_type ();
192   psppire_buttonbox_get_type ();
193   psppire_keypad_get_type ();
194   psppire_acr_get_type ();
195   psppire_dict_view_get_type ();
196   psppire_var_view_get_type ();
197   psppire_value_entry_get_type ();
198   psppire_checkbox_treeview_get_type ();
199   psppire_means_layer_get_type ();
200
201   preregister_actions ();
202   preregister_misc ();
203
204   /* This seems to be necessary on Cygwin.
205      It ought not to be necessary.  Having it here can't do any harm. */
206   kludge = gtk_source_view_get_type ();
207 }