var-type-dialog: Change entries to spin buttons, add validation.
[pspp] / src / ui / gui / var-type-dialog.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2     Copyright (C) 2005, 2006, 2010, 2011, 2012  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17
18 /*  This module describes the behaviour of the Variable Type dialog box used
19     for inputing the variable type in the var sheet */
20
21 #include <config.h>
22
23 #include <gtk/gtk.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "data/data-out.h"
28 #include "data/settings.h"
29 #include "data/variable.h"
30 #include "libpspp/message.h"
31 #include "ui/gui/builder-wrapper.h"
32 #include "ui/gui/var-type-dialog.h"
33
34 static const struct fmt_spec date_format[] =
35   {
36     {FMT_DATE,  11, 0},
37     {FMT_DATE,   9, 0},
38     {FMT_ADATE, 10, 0},
39     {FMT_ADATE, 8, 0},
40     {FMT_EDATE, 10, 0},
41     {FMT_EDATE, 8, 0},
42     {FMT_SDATE, 10, 0},
43     {FMT_SDATE, 8, 0},
44     {FMT_JDATE, 5, 0},
45     {FMT_JDATE, 7, 0},
46     {FMT_QYR, 8, 0},
47     {FMT_QYR, 6, 0},
48     {FMT_MOYR, 8, 0},
49     {FMT_MOYR, 6, 0},
50     {FMT_WKYR, 10, 0},
51     {FMT_WKYR, 8, 0},
52     {FMT_DATETIME, 17, 0},
53     {FMT_DATETIME, 20, 0}
54   };
55
56
57 static const struct fmt_spec dollar_format[] =
58   {
59     {FMT_DOLLAR, 2, 0},
60     {FMT_DOLLAR, 3, 0},
61     {FMT_DOLLAR, 4, 0},
62     {FMT_DOLLAR, 7, 2},
63     {FMT_DOLLAR, 6, 0},
64     {FMT_DOLLAR, 9, 2},
65     {FMT_DOLLAR, 8, 0},
66     {FMT_DOLLAR, 11, 2},
67     {FMT_DOLLAR, 12, 0},
68     {FMT_DOLLAR, 15, 2},
69     {FMT_DOLLAR, 16, 0},
70     {FMT_DOLLAR, 19, 2}
71   };
72
73 static const int cc_format[] =
74   {
75     FMT_CCA,
76     FMT_CCB,
77     FMT_CCC,
78     FMT_CCD,
79     FMT_CCE,
80   };
81
82
83 static int find_format (const struct fmt_spec *target,
84                         const struct fmt_spec formats[], int n_formats);
85 static int find_format_type (int target, const int types[], int n_types);
86
87 static void select_treeview_at_index (GtkTreeView *, int index);
88
89 static void update_width_decimals (const struct var_type_dialog *);
90 static void refresh_active_button (struct var_type_dialog *);
91 static void on_active_button_change (GtkToggleButton *,
92                                      struct var_type_dialog *);
93 static void on_width_changed (GtkEntry *, struct var_type_dialog *);
94 static void on_decimals_changed (GtkEntry *, struct var_type_dialog *);
95
96 /* callback for when any of the radio buttons are toggled */
97 static void
98 on_toggle (GtkToggleButton *togglebutton, gpointer dialog_)
99 {
100   struct var_type_dialog *dialog = dialog_;
101
102   if ( gtk_toggle_button_get_active (togglebutton) == TRUE)
103     refresh_active_button (dialog);
104 }
105
106 static void
107 refresh_active_button (struct var_type_dialog *dialog)
108 {
109   int i;
110
111   for (i = 0; i < num_BUTTONS; i++)
112     {
113       GtkToggleButton *toggle = GTK_TOGGLE_BUTTON (dialog->radioButton[i]);
114
115       if (gtk_toggle_button_get_active (toggle))
116         {
117           if (dialog->active_button != i)
118             {
119               dialog->active_button = i;
120               on_active_button_change (toggle, dialog);
121             }
122           return;
123         }
124     }
125
126   g_return_if_reached ();
127 }
128
129 static void
130 update_adj_ranges (struct var_type_dialog *dialog)
131 {
132   enum fmt_type type = dialog->fmt_l.type;
133   const enum fmt_use use = FMT_FOR_OUTPUT;
134   int min_w = fmt_min_width (type, use);
135   int max_w = fmt_max_width (type, use);
136   int max_d = fmt_max_decimals (type, max_w, use);
137
138   g_object_set (dialog->adj_width,
139                 "lower", (double) min_w,
140                 "upper", (double) max_w,
141                 NULL);
142
143   g_object_set (dialog->adj_decimals,
144                 "lower", 0.0,
145                 "upper", (double) max_d,
146                 NULL);
147 }
148
149 /* callback for when any of the radio buttons are toggled */
150 static void
151 on_active_button_change (GtkToggleButton *togglebutton,
152                          struct var_type_dialog *dialog)
153 {
154   enum widgets {
155     W_WIDTH          = 1 << 0,
156     W_DECIMALS       = 1 << 1,
157     W_DATE_FORMATS   = 1 << 2,
158     W_DOLLAR_FORMATS = 1 << 3,
159     W_CC_FORMATS     = 1 << 4,
160   };
161
162   enum widgets widgets;
163   int indx;
164
165   switch (dialog->active_button)
166     {
167     case BUTTON_NUMERIC:
168     case BUTTON_COMMA:
169     case BUTTON_DOT:
170     case BUTTON_SCIENTIFIC:
171       widgets = W_WIDTH | W_DECIMALS;
172       break;
173
174     case BUTTON_STRING:
175       widgets = W_WIDTH;
176       break;
177
178     case BUTTON_DATE:
179       widgets = W_DATE_FORMATS;
180       break;
181
182     case BUTTON_DOLLAR:
183       widgets = W_DOLLAR_FORMATS;
184       break;
185
186     case BUTTON_CUSTOM:
187       widgets = W_CC_FORMATS | W_WIDTH | W_DECIMALS;
188       break;
189
190     default:
191       /* No button active */
192       return;
193     }
194
195   gtk_widget_set_visible (dialog->width_decimals, (widgets & W_WIDTH) != 0);
196   gtk_widget_set_visible (dialog->entry_width, (widgets & W_WIDTH) != 0);
197   gtk_widget_set_visible (dialog->entry_decimals, (widgets & W_DECIMALS) != 0);
198   gtk_widget_set_visible (dialog->label_decimals, (widgets & W_DECIMALS) != 0);
199   gtk_widget_set_visible (dialog->date_format_list,
200                           (widgets & W_DATE_FORMATS) != 0);
201   gtk_widget_set_visible (dialog->custom_currency_hbox,
202                           (widgets & W_CC_FORMATS) != 0);
203   gtk_widget_set_visible (dialog->dollar_window,
204                           (widgets & W_DOLLAR_FORMATS) != 0);
205
206   dialog->fmt_l = *var_get_print_format (dialog->pv);
207
208   switch (dialog->active_button)
209     {
210     case BUTTON_NUMERIC:
211       dialog->fmt_l.type = FMT_F;
212       break;
213     case BUTTON_COMMA:
214       dialog->fmt_l.type = FMT_COMMA;
215       break;
216     case BUTTON_DOT:
217       dialog->fmt_l.type = FMT_DOT;
218       break;
219     case BUTTON_SCIENTIFIC:
220       dialog->fmt_l.type = FMT_E;
221       break;
222     case BUTTON_STRING:
223       dialog->fmt_l.type = FMT_A;
224       break;
225     case BUTTON_DATE:
226       indx = find_format (&dialog->fmt_l, date_format,
227                           sizeof date_format / sizeof *date_format);
228       select_treeview_at_index (dialog->date_format_treeview, indx);
229       dialog->fmt_l = date_format[indx];
230       break;
231     case BUTTON_DOLLAR:
232       indx = find_format (&dialog->fmt_l, dollar_format,
233                           sizeof dollar_format / sizeof *dollar_format);
234       select_treeview_at_index (dialog->dollar_treeview, indx);
235       dialog->fmt_l = dollar_format[indx];
236       break;
237     case BUTTON_CUSTOM:
238       indx = find_format_type (dialog->fmt_l.type, cc_format,
239                                sizeof cc_format / sizeof *cc_format);
240       select_treeview_at_index (dialog->custom_treeview, indx);
241       dialog->fmt_l.type = cc_format[indx];
242       break;
243     }
244
245   fmt_fix_output (&dialog->fmt_l);
246   update_adj_ranges (dialog);
247   update_width_decimals (dialog);
248 }
249
250
251
252 static gint on_var_type_ok_clicked (GtkWidget *w, gpointer data);
253 static gint hide_dialog (GtkWidget *w,  gpointer data);
254
255
256 static void
257 add_to_group (GtkWidget *w, gpointer data)
258 {
259   GtkSizeGroup *sg = data;
260
261   gtk_size_group_add_widget (sg, w);
262 }
263
264 /* Set the local width and decimals entry boxes to reflec the local format */
265 static void
266 update_width_decimals (const struct var_type_dialog *dialog)
267 {
268   gtk_adjustment_set_value (dialog->adj_width, dialog->fmt_l.w);
269   gtk_adjustment_set_value (dialog->adj_decimals, dialog->fmt_l.d);
270 }
271
272 static void
273 on_width_changed (GtkEntry *entry, struct var_type_dialog *dialog)
274 {
275   int w = atoi (gtk_entry_get_text (GTK_ENTRY (dialog->entry_width)));
276   fmt_change_width (&dialog->fmt_l, w, FMT_FOR_OUTPUT);
277   update_width_decimals (dialog);
278 }
279
280 static void
281 on_decimals_changed (GtkEntry *entry, struct var_type_dialog *dialog)
282 {
283   int d = atoi (gtk_entry_get_text (GTK_ENTRY (dialog->entry_decimals)));
284   fmt_change_decimals (&dialog->fmt_l, d, FMT_FOR_OUTPUT);
285   update_width_decimals (dialog);
286 }
287
288 /* Callback for when the custom treeview row is changed.
289    It sets dialog box to reflect the selected format */
290 static void
291 preview_custom (GtkWidget *w, gpointer data)
292 {
293   const gchar *text ;
294
295   struct var_type_dialog *dialog = data;
296
297   if ( dialog->active_button != BUTTON_CUSTOM )
298     return;
299
300   text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_decimals));
301   dialog->fmt_l.d = atoi (text);
302
303   text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_width));
304   dialog->fmt_l.w = atoi (text);
305
306   msg_disable ();
307   if ( ! fmt_check_output (&dialog->fmt_l))
308     {
309       gtk_label_set_text (GTK_LABEL (dialog->label_psample), "---");
310       gtk_label_set_text (GTK_LABEL (dialog->label_nsample), "---");
311     }
312   else
313     {
314       gchar *sample_text;
315       union value v;
316       v.f = 1234.56;
317
318       sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l));
319       gtk_label_set_text (GTK_LABEL (dialog->label_psample), sample_text);
320       g_free (sample_text);
321
322       v.f = -v.f;
323       sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l));
324       gtk_label_set_text (GTK_LABEL (dialog->label_nsample), sample_text);
325       g_free (sample_text);
326     }
327   msg_enable ();
328 }
329
330 static gint
331 get_index_from_treeview (GtkTreeView *treeview)
332 {
333   GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
334   GtkTreeModel *model;
335   GtkTreePath *path;
336   GtkTreeIter iter;
337   gint index;
338
339   gtk_tree_selection_get_selected (selection, &model, &iter);
340   path = gtk_tree_model_get_path (model, &iter);
341   if (!path || gtk_tree_path_get_depth (path) < 1)
342     index = 0;
343   else
344     index = gtk_tree_path_get_indices (path)[0];
345   gtk_tree_path_free (path);
346
347   return index;
348 }
349
350 /* Callback for when a date treeview row is changed.
351    It sets the fmt_l_spec to reflect the selected format */
352 static void
353 set_date_format_from_treeview (GtkTreeView *treeview,
354                                struct var_type_dialog *dialog)
355 {
356   dialog->fmt_l = date_format[get_index_from_treeview (treeview)];
357 }
358
359 /* Callback for when a dollar treeview row is changed.
360    It sets the fmt_l_spec to reflect the selected format */
361 static void
362 set_dollar_format_from_treeview (GtkTreeView *treeview,
363                                  struct var_type_dialog *dialog)
364 {
365   dialog->fmt_l = dollar_format[get_index_from_treeview (treeview)];
366 }
367
368 /* Callback for when a treeview row is changed.
369    It sets the type of the fmt_l to reflect the selected type */
370 static void
371 set_custom_format_from_treeview (GtkTreeView *treeview,
372                                  struct var_type_dialog *dialog)
373 {
374   dialog->fmt_l.type = cc_format[get_index_from_treeview (treeview)];
375   update_adj_ranges (dialog);
376   fmt_fix_output (&dialog->fmt_l);
377   update_width_decimals (dialog);
378 }
379
380 /* Create the structure */
381 struct var_type_dialog *
382 var_type_dialog_create (GtkWindow *toplevel)
383 {
384   gint i;
385   struct var_type_dialog *dialog = g_malloc (sizeof (struct var_type_dialog));
386
387   GtkBuilder *xml = builder_new ("var-type-dialog.ui");
388
389   dialog->window = get_widget_assert (xml,"var_type_dialog");
390   dialog->active_button = -1;
391
392
393   g_signal_connect (dialog->window, "delete-event",
394                     G_CALLBACK (gtk_widget_hide_on_delete), NULL);
395
396   gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
397                                 toplevel);
398
399   dialog->radioButton[BUTTON_NUMERIC] =
400     get_widget_assert (xml,"radiobutton1");
401   dialog->radioButton[BUTTON_COMMA] =
402     get_widget_assert (xml,"radiobutton2");
403   dialog->radioButton[BUTTON_DOT] =
404     get_widget_assert (xml,"radiobutton3");
405   dialog->radioButton[BUTTON_SCIENTIFIC] =
406     get_widget_assert (xml,"radiobutton4");
407   dialog->radioButton[BUTTON_DATE] =
408     get_widget_assert (xml,"radiobutton5");
409   dialog->radioButton[BUTTON_DOLLAR] =
410     get_widget_assert (xml,"radiobutton6");
411   dialog->radioButton[BUTTON_CUSTOM] =
412     get_widget_assert (xml,"radiobutton7");
413   dialog->radioButton[BUTTON_STRING] =
414     get_widget_assert (xml,"radiobutton8");
415
416
417   dialog->date_format_list = get_widget_assert (xml, "scrolledwindow4");
418   dialog->width_decimals = get_widget_assert (xml, "width_decimals");
419   dialog->label_decimals = get_widget_assert (xml, "decimals_label");
420   dialog->entry_decimals = get_widget_assert (xml, "decimals_entry");
421   dialog->adj_decimals = gtk_spin_button_get_adjustment (
422     GTK_SPIN_BUTTON (dialog->entry_decimals));
423
424   dialog->label_psample = get_widget_assert (xml, "psample_label");
425   dialog->label_nsample = get_widget_assert (xml, "nsample_label");
426
427
428   dialog->entry_width = get_widget_assert (xml,"width_entry");
429   dialog->adj_width = gtk_spin_button_get_adjustment (
430     GTK_SPIN_BUTTON (dialog->entry_width));
431   dialog->custom_currency_hbox = get_widget_assert (xml,
432                                                    "custom_currency_hbox");
433
434   dialog->dollar_window = get_widget_assert (xml, "dollar_window");
435   dialog->dollar_treeview =
436     GTK_TREE_VIEW (get_widget_assert (xml, "dollar_treeview"));
437
438   dialog->custom_treeview =
439     GTK_TREE_VIEW (get_widget_assert (xml, "custom_treeview"));
440
441
442   dialog->ok = get_widget_assert (xml,"var_type_ok");
443
444
445   {
446   GtkTreeIter iter;
447   GtkListStore *list_store ;
448
449   GtkTreeViewColumn *column;
450   GtkCellRenderer *renderer ;
451
452   /* The "middle_box" is a vbox with serveral children.
453      However only one child is ever shown at a time.
454      We need to make sure that they all have the same width, to avoid
455      upleasant resizing effects */
456   GtkSizeGroup *sizeGroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
457
458   gtk_container_foreach (GTK_CONTAINER (get_widget_assert (xml, "middle_box")),
459                         add_to_group, sizeGroup);
460
461
462   for (i = 0 ; i < num_BUTTONS; ++i )
463     g_signal_connect (dialog->radioButton[i], "toggled",
464                       G_CALLBACK (on_toggle), dialog);
465
466   /* Populate the date format tree view */
467   dialog->date_format_treeview = GTK_TREE_VIEW (get_widget_assert (xml,
468                                               "date_format_list_view"));
469
470   renderer = gtk_cell_renderer_text_new ();
471
472   column = gtk_tree_view_column_new_with_attributes ("Title",
473                                                      renderer,
474                                                      "text",
475                                                      0,
476                                                      NULL);
477
478   gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->date_format_treeview),
479                                column);
480
481
482   list_store = gtk_list_store_new (1, G_TYPE_STRING);
483
484   for ( i = 0 ; i < sizeof (date_format) / sizeof (date_format[0]) ; ++i )
485     {
486       const struct fmt_spec *f = &date_format[i];
487       gtk_list_store_append (list_store, &iter);
488       gtk_list_store_set (list_store, &iter,
489                           0, fmt_date_template (f->type, f->w),
490                           -1);
491     }
492
493   gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->date_format_treeview),
494                           GTK_TREE_MODEL (list_store));
495
496   g_object_unref (list_store);
497
498   g_signal_connect (dialog->date_format_treeview, "cursor-changed",
499                    G_CALLBACK (set_date_format_from_treeview), dialog);
500
501
502   /* populate the dollar treeview */
503
504   renderer = gtk_cell_renderer_text_new ();
505
506   column = gtk_tree_view_column_new_with_attributes ("Title",
507                                                      renderer,
508                                                      "text",
509                                                      0,
510                                                      NULL);
511
512   gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->dollar_treeview),
513                                column);
514
515
516   list_store = gtk_list_store_new (1, G_TYPE_STRING);
517
518   for ( i = 0 ; i < sizeof (dollar_format)/sizeof (dollar_format[0]) ; ++i )
519     {
520       char *template = settings_dollar_template (&dollar_format[i]);
521       gtk_list_store_append (list_store, &iter);
522       gtk_list_store_set (list_store, &iter,
523                           0, template,
524                           -1);
525       free (template);
526     }
527
528   gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->dollar_treeview),
529                           GTK_TREE_MODEL (list_store));
530
531   g_object_unref (list_store);
532
533   g_signal_connect (dialog->dollar_treeview,
534                    "cursor-changed",
535                    G_CALLBACK (set_dollar_format_from_treeview), dialog);
536
537   g_signal_connect_swapped (dialog->dollar_treeview,
538                    "cursor-changed",
539                    G_CALLBACK (update_width_decimals), dialog);
540
541
542   /* populate the custom treeview */
543
544   renderer = gtk_cell_renderer_text_new ();
545
546   column = gtk_tree_view_column_new_with_attributes ("Title",
547                                                      renderer,
548                                                      "text",
549                                                      0,
550                                                      NULL);
551
552   gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->custom_treeview),
553                                column);
554
555
556   list_store = gtk_list_store_new (1, G_TYPE_STRING);
557
558   for ( i = 0 ; i < 5 ; ++i )
559     {
560       enum fmt_type cc_fmts[5] = {FMT_CCA, FMT_CCB, FMT_CCC, FMT_CCD, FMT_CCE};
561       gtk_list_store_append (list_store, &iter);
562       gtk_list_store_set (list_store, &iter,
563                           0, fmt_name (cc_fmts[i]),
564                           -1);
565     }
566
567   gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->custom_treeview),
568                           GTK_TREE_MODEL (list_store));
569
570   g_object_unref (list_store);
571
572
573   g_signal_connect (dialog->custom_treeview,
574                    "cursor-changed",
575                    G_CALLBACK (set_custom_format_from_treeview), dialog);
576
577
578   g_signal_connect (dialog->custom_treeview,
579                    "cursor-changed",
580                    G_CALLBACK (preview_custom), dialog);
581
582
583   g_signal_connect (dialog->entry_width, "changed",
584                     G_CALLBACK (on_width_changed), dialog);
585   g_signal_connect (dialog->entry_decimals, "changed",
586                     G_CALLBACK (on_decimals_changed), dialog);
587
588   g_signal_connect (dialog->entry_width,
589                    "changed",
590                    G_CALLBACK (preview_custom), dialog);
591
592
593   g_signal_connect (dialog->entry_decimals,
594                    "changed",
595                    G_CALLBACK (preview_custom), dialog);
596
597
598   /* Connect to the OK button */
599   g_signal_connect (dialog->ok, "clicked", G_CALLBACK (on_var_type_ok_clicked),
600                    dialog);
601
602
603   /* And the cancel button */
604   g_signal_connect (get_widget_assert (xml, "var_type_cancel") , "clicked",
605                     G_CALLBACK (hide_dialog),
606                     dialog);
607   }
608
609   g_object_unref (xml);
610
611   return dialog;
612 }
613
614
615 /* Set a particular button to be active */
616 void
617 var_type_dialog_set_active_button (struct var_type_dialog *dialog, gint b)
618 {
619   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radioButton[b]),
620                                TRUE);
621 }
622
623
624
625 static void
626 select_treeview_at_index (GtkTreeView *treeview, int index)
627 {
628   GtkTreePath *path;
629
630   path = gtk_tree_path_new_from_indices (index, -1);
631   gtk_tree_view_set_cursor (treeview, path, 0, 0);
632   gtk_tree_path_free (path);
633 }
634
635 static int
636 find_format (const struct fmt_spec *target,
637              const struct fmt_spec formats[], int n_formats)
638 {
639   int i;
640
641   for (i = 0; i < n_formats; i++)
642     if (fmt_equal (target, &formats[i]))
643       return i;
644
645   return 0;
646 }
647
648 static int
649 find_format_type (int target, const int types[], int n_types)
650 {
651   int i;
652
653   for (i = 0; i < n_types; i++)
654     if (target == types[i])
655       return i;
656
657   return 0;
658 }
659
660 /* Set up the state of the dialog box to match the variable VAR */
661 static void
662 var_type_dialog_set_state (struct var_type_dialog *dialog)
663 {
664   int button;
665
666   g_assert (dialog);
667   g_assert (dialog->pv);
668
669   /* Populate the radio button states */
670   switch (var_get_print_format (dialog->pv)->type)
671     {
672     default:
673     case FMT_F:
674       button = BUTTON_NUMERIC;
675       break;
676     case FMT_A:
677       button = BUTTON_STRING;
678       break;
679     case FMT_COMMA:
680       button = BUTTON_COMMA;
681       break;
682     case FMT_DOT:
683       button = BUTTON_DOT;
684       break;
685     case FMT_DOLLAR:
686       button = BUTTON_DOLLAR;
687       break;
688     case FMT_DATE:
689     case FMT_EDATE:
690     case FMT_SDATE:
691     case FMT_ADATE:
692     case FMT_JDATE:
693     case FMT_QYR:
694     case FMT_MOYR:
695     case FMT_WKYR:
696     case FMT_DATETIME:
697     case FMT_TIME:
698     case FMT_DTIME:
699     case FMT_WKDAY:
700     case FMT_MONTH:
701       button = BUTTON_DATE;
702       break;
703     case FMT_CCA:
704     case FMT_CCB:
705     case FMT_CCC:
706     case FMT_CCD:
707     case FMT_CCE:
708       button = BUTTON_CUSTOM;
709       break;
710     }
711
712   var_type_dialog_set_active_button (dialog, button);
713   refresh_active_button (dialog);
714   on_active_button_change (GTK_TOGGLE_BUTTON (dialog->radioButton[button]),
715                            dialog);
716 }
717
718
719 /* Popup the dialog box */
720 void
721 var_type_dialog_show (struct var_type_dialog *dialog)
722 {
723   var_type_dialog_set_state (dialog);
724
725   gtk_widget_show (dialog->window);
726 }
727
728 /* Callbacks for the Variable Type Dialog Box */
729
730 /* Callback for when the var type dialog is closed using the OK button.
731    It sets the appropriate variable accordingly. */
732 static gint
733 on_var_type_ok_clicked (GtkWidget *w, gpointer data)
734 {
735   struct var_type_dialog *dialog = data;
736
737   var_set_width (dialog->pv, fmt_var_width (&dialog->fmt_l));
738   var_set_both_formats (dialog->pv, &dialog->fmt_l);
739
740   gtk_widget_hide (dialog->window);
741
742   return FALSE;
743 }
744
745
746
747 static gint
748 hide_dialog (GtkWidget *w,  gpointer data)
749 {
750   struct var_type_dialog *dialog = data;
751
752   gtk_widget_hide (dialog->window);
753
754   return FALSE;
755 }
756