pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] var-type-dialog: Avoid static variables.


From: Ben Pfaff
Subject: [PATCH 1/2] var-type-dialog: Avoid static variables.
Date: Fri, 13 Jul 2012 00:00:23 -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 |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/ui/gui/var-type-dialog.c b/src/ui/gui/var-type-dialog.c
index ea3d2e0..359ca34 100644
--- a/src/ui/gui/var-type-dialog.c
+++ b/src/ui/gui/var-type-dialog.c
@@ -31,13 +31,6 @@
 #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);
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]