var-type-dialog: Avoid static variables.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 13 Jul 2012 06:32:19 +0000 (23:32 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 13 Jul 2012 06:32:19 +0000 (23:32 -0700)
I guess these static variables were OK when there was only one
datasheet and therefore only one dialog, but now there can be more
than one of each.

src/ui/gui/var-type-dialog.c

index ea3d2e098a23c5eb464fea1ab596e6c09e4460cc..359ca348a5cc24f90edf1381e5f4eeafeee3a46e 100644 (file)
 #include "ui/gui/builder-wrapper.h"
 #include "ui/gui/var-type-dialog.h"
 
-struct tgs
-{
-  struct var_type_dialog *dialog;
-  gint button;
-};
-
-
 struct format_opt {
   gchar desc[21];
   struct fmt_spec spec;
@@ -102,14 +95,22 @@ static void select_treeview_from_format_type (GtkTreeView *treeview,
 
 /* callback for when any of the radio buttons are toggled */
 static void
-on_toggle_1 (GtkToggleButton *togglebutton, gpointer user_data)
+on_toggle_1 (GtkToggleButton *togglebutton, gpointer dialog_)
 {
-  struct tgs *tgs = user_data;
+  GtkWidget *widget = GTK_WIDGET (togglebutton);
+  struct var_type_dialog *dialog = dialog_;
+  int i;
 
   if ( gtk_toggle_button_get_active (togglebutton) == FALSE)
     return ;
 
-  tgs->dialog->active_button = tgs->button;
+  for (i = 0; i < num_BUTTONS; i++)
+    if (widget == dialog->radioButton[i])
+      {
+        dialog->active_button = i;
+        return;
+      }
+  g_return_if_reached ();
 }
 
 static void update_width_decimals (const struct var_type_dialog *dialog);
@@ -384,7 +385,6 @@ var_type_dialog_create (GtkWindow *toplevel)
   GtkTreeViewColumn *column;
   GtkCellRenderer *renderer ;
 
-  static struct tgs tgs[num_BUTTONS];
   /* The "middle_box" is a vbox with serveral children.
      However only one child is ever shown at a time.
      We need to make sure that they all have the same width, to avoid
@@ -397,10 +397,8 @@ var_type_dialog_create (GtkWindow *toplevel)
 
   for (i = 0 ; i < num_BUTTONS; ++i )
     {
-      tgs[i].dialog = dialog;
-      tgs[i].button = i;
       g_signal_connect (dialog->radioButton[i], "toggled",
-                      G_CALLBACK (on_toggle_1), &tgs[i]);
+                      G_CALLBACK (on_toggle_1), dialog);
 
       g_signal_connect (dialog->radioButton[i], "toggled",
                       G_CALLBACK (on_toggle_2), dialog);