Merge remote-tracking branch 'origin/master' into sheet
[pspp] / src / ui / gui / widgets.c
1 #include <config.h>
2
3 #include <gtksourceview/gtksourceview.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-vbuttonbox.h"
12 #include "psppire-hbuttonbox.h"
13 #include "psppire-keypad.h"
14 #include "psppire-acr.h"
15 #include "psppire-dictview.h"
16 #include "psppire-var-view.h"
17 #include "psppire-val-chooser.h"
18 #include "psppire-checkbox-treeview.h"
19
20 #include "psppire-dialog-action-aggregate.h"
21 #include "psppire-dialog-action-autorecode.h"
22 #include "psppire-dialog-action-barchart.h"
23 #include "psppire-dialog-action-binomial.h"
24 #include "psppire-dialog-action-chisquare.h"
25 #include "psppire-dialog-action-compute.h"
26 #include "psppire-dialog-action-comments.h"
27 #include "psppire-dialog-action-correlation.h"
28 #include "psppire-dialog-action-count.h"
29 #include "psppire-dialog-action-crosstabs.h"
30 #include "psppire-dialog-action-descriptives.h"
31 #include "psppire-dialog-action-examine.h"
32 #include "psppire-dialog-action-flip.h"
33 #include "psppire-dialog-action-factor.h"
34 #include "psppire-dialog-action-frequencies.h"
35 #include "psppire-dialog-action-histogram.h"
36 #include "psppire-dialog-action-indep-samps.h"
37 #include "psppire-dialog-action-k-related.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_related_get_type,
90   psppire_dialog_action_means_get_type,
91   psppire_dialog_action_oneway_get_type,
92   psppire_dialog_action_paired_get_type,
93   psppire_dialog_action_indep_samps_get_type,
94   psppire_dialog_action_var_info_get_type,
95   psppire_dialog_action_rank_get_type,
96   psppire_dialog_action_recode_same_get_type,
97   psppire_dialog_action_recode_different_get_type,
98   psppire_dialog_action_reliability_get_type,
99   psppire_dialog_action_regression_get_type,
100   psppire_dialog_action_roc_get_type,
101   psppire_dialog_action_runs_get_type,
102   psppire_dialog_action_scatterplot_get_type,
103   psppire_dialog_action_select_get_type,
104   psppire_dialog_action_sort_get_type,
105   psppire_dialog_action_split_get_type,
106   psppire_dialog_action_tt1s_get_type,
107   psppire_dialog_action_two_sample_get_type,
108   psppire_dialog_action_weight_get_type,
109   psppire_dialog_action_univariate_get_type
110 };
111
112
113 static void
114 preregister_actions (void)
115 {
116   int i;
117   for (i = 0; i < sizeof (dialog_action_types) / sizeof (dialog_action_types[0]); ++i)
118     {
119       get_type_func x = dialog_action_types[i];
120       x ();
121     }
122 }
123
124
125 static void
126 tx_string_to_double (const GValue *src, GValue *dest)
127 {
128   const gchar *str = g_value_get_string (src);
129   gdouble dble = g_strtod (str, NULL);
130   g_value_set_double (dest, dble);
131 }
132
133
134 static void
135 tx_string_to_int (const GValue *src, GValue *dest)
136 {
137   const gchar *str = g_value_get_string (src);
138   gint x = atoi (str);
139   g_value_set_int (dest, x);
140 }
141
142 static void
143 enum_to_string (const GValue *src, GValue *dest)
144 {
145   gint n = g_value_get_enum (src);
146   GType t = G_VALUE_TYPE (src);
147   GEnumClass *ec = g_type_class_ref (t);
148   GEnumValue *ev = g_enum_get_value (ec, n);
149
150   g_value_set_string (dest, gettext (ev->value_nick));
151 }
152
153
154
155 GType align_enum_type;
156 GType measure_enum_type;
157 GType role_enum_type;
158
159
160 extern const GEnumValue align[];
161 extern const GEnumValue measure[];
162 extern const GEnumValue role[];
163
164
165
166 static void
167 preregister_misc (void)
168 {
169   align_enum_type = g_enum_register_static ("PsppAlignment", align);
170   measure_enum_type = g_enum_register_static ("PsppMeasure", measure);
171   role_enum_type = g_enum_register_static ("PsppRole", role);
172
173   g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DOUBLE, tx_string_to_double);
174   g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, tx_string_to_int);
175   
176   g_value_register_transform_func (measure_enum_type, G_TYPE_STRING, enum_to_string);
177   g_value_register_transform_func (align_enum_type, G_TYPE_STRING, enum_to_string);
178   g_value_register_transform_func (role_enum_type, G_TYPE_STRING, enum_to_string);
179 }
180
181
182 /* Any custom widgets which are to be used in GtkBuilder ui files
183    need to be preregistered, otherwise GtkBuilder refuses to 
184    acknowledge their existence. */
185 void
186 preregister_widgets (void)
187 {
188   psppire_val_chooser_get_type ();
189   psppire_dialog_get_type ();
190   psppire_selector_get_type ();
191   psppire_vbutton_box_get_type ();
192   psppire_hbutton_box_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 }