From: John Darrington <john@darrington.wattle.id.au>
Date: Fri, 23 Nov 2012 18:49:03 +0000 (+0100)
Subject: Refactoring: common function set_sensitivity from toggle
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ad4b27b32995ab6d61167029b66c80411c25962;p=pspp

Refactoring: common function set_sensitivity from toggle

Many dialog boxes have a signal handler to set the sensitivity
of a widget, according to the state of a toggle button.  Until
now, they had all written their own.
---

diff --git a/src/ui/gui/binomial-dialog.c b/src/ui/gui/binomial-dialog.c
index ee3fbd7bf2..8f1df37f49 100644
--- a/src/ui/gui/binomial-dialog.c
+++ b/src/ui/gui/binomial-dialog.c
@@ -42,14 +42,6 @@ struct binomial_dialog
   GtkWidget *cutpoint_entry;
 };
 
-static void
-set_sensitivity (GtkToggleButton *button, GtkWidget *w)
-{
-  gboolean state = gtk_toggle_button_get_active (button);
-  gtk_widget_set_sensitive (w, state);
-}
-
-
 static gboolean
 get_proportion (const struct binomial_dialog *bin_d, double *prop)
 {
@@ -171,7 +163,7 @@ binomial_dialog (PsppireDataWindow *dw)
 		"predicate", var_is_numeric,
 		NULL);
 
-  g_signal_connect (bin_d.cutpoint_button, "toggled", G_CALLBACK (set_sensitivity),
+  g_signal_connect (bin_d.cutpoint_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle),
 		    bin_d.cutpoint_entry);
 
   g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh),  &bin_d);
diff --git a/src/ui/gui/chi-square-dialog.c b/src/ui/gui/chi-square-dialog.c
index dfa39f06eb..c67923ca28 100644
--- a/src/ui/gui/chi-square-dialog.c
+++ b/src/ui/gui/chi-square-dialog.c
@@ -46,14 +46,6 @@ struct chisquare_dialog
   GtkListStore *expected_list;
 };
 
-static void
-set_sensitivity (GtkToggleButton *button, GtkWidget *w)
-{
-  gboolean state = gtk_toggle_button_get_active (button);
-  gtk_widget_set_sensitive (w, state);
-}
-
-
 static gboolean
 dialog_state_valid (gpointer data)
 {
@@ -201,14 +193,14 @@ chisquare_dialog (PsppireDataWindow *dw)
 		NULL);
 
 
-  g_signal_connect (csd.range_button, "toggled", G_CALLBACK (set_sensitivity), 
+  g_signal_connect (csd.range_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle), 
 		    range_table);
 
 
-  g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity), 
+  g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle), 
 		    values_acr);
 
-  g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity), 
+  g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle), 
 		    expected_value_entry);
 
 
diff --git a/src/ui/gui/dialog-common.c b/src/ui/gui/dialog-common.c
index c61cb14a64..416be46f44 100644
--- a/src/ui/gui/dialog-common.c
+++ b/src/ui/gui/dialog-common.c
@@ -165,3 +165,28 @@ numeric_only (GtkWidget *source, GtkWidget *dest)
   return retval;
 }
 
+/*
+  A pair of functions intended to be used as callbacks for the "toggled" signal
+  of a GtkToggleButton widget.  They make the sensitivity of W follow the status
+  of the togglebutton.
+*/
+void
+set_sensitivity_from_toggle (GtkToggleButton *togglebutton,  GtkWidget *w)
+{
+  gboolean active = gtk_toggle_button_get_active (togglebutton);
+
+  gtk_widget_set_sensitive (w, active);
+}
+
+/* */
+void
+set_sensitivity_from_toggle_invert (GtkToggleButton *togglebutton,
+				    GtkWidget *w)
+{
+  gboolean active = gtk_toggle_button_get_active (togglebutton);
+
+  gtk_widget_set_sensitive (w, !active);
+}
+
+
+
diff --git a/src/ui/gui/dialog-common.h b/src/ui/gui/dialog-common.h
index 328904acfc..d32082477d 100644
--- a/src/ui/gui/dialog-common.h
+++ b/src/ui/gui/dialog-common.h
@@ -54,5 +54,13 @@ gboolean homogeneous_types (GtkWidget *source, GtkWidget *dest);
 */
 gboolean numeric_only (GtkWidget *source, GtkWidget *dest);
 
+/*
+  A pair of functions intended to be used as callbacks for the "toggled" signal
+  of a GtkToggleButton widget.  They make the sensitivity of W follow the status
+  of the togglebutton.
+*/
+void set_sensitivity_from_toggle (GtkToggleButton *togglebutton,  GtkWidget *w);
+void set_sensitivity_from_toggle_invert (GtkToggleButton *togglebutton,  GtkWidget *w);
+
 
 #endif
diff --git a/src/ui/gui/psppire-dialog-action-logistic.c b/src/ui/gui/psppire-dialog-action-logistic.c
index d93a2f5b0c..0426931e85 100644
--- a/src/ui/gui/psppire-dialog-action-logistic.c
+++ b/src/ui/gui/psppire-dialog-action-logistic.c
@@ -41,16 +41,6 @@ psppire_dialog_action_logistic_class_init (PsppireDialogActionLogisticClass *cla
 
 G_DEFINE_TYPE (PsppireDialogActionLogistic, psppire_dialog_action_logistic, PSPPIRE_TYPE_DIALOG_ACTION);
 
-static void
-set_sensitivity_from_toggle (GtkToggleButton *togglebutton,  gpointer data)
-{
-  GtkWidget *w = data;
-  gboolean active = gtk_toggle_button_get_active (togglebutton);
-
-  gtk_widget_set_sensitive (w, active);
-}
-
-
 static gboolean
 dialog_state_valid (gpointer data)
 {
diff --git a/src/ui/gui/psppire-val-chooser.c b/src/ui/gui/psppire-val-chooser.c
index 680e147b62..01d694e27e 100644
--- a/src/ui/gui/psppire-val-chooser.c
+++ b/src/ui/gui/psppire-val-chooser.c
@@ -17,6 +17,7 @@
 #include <config.h>
 
 #include <gtk/gtk.h>
+#include "dialog-common.h"
 #include "psppire-val-chooser.h"
 
 #include "libpspp/str.h"
@@ -334,14 +335,6 @@ static struct layout range_opt[n_VAL_CHOOSER_BUTTONS]=
     {N_("_All other values"),          NULL,         else_set   }
   };
 
-static void
-set_sensitivity_from_toggle (GtkToggleButton *togglebutton,  GtkWidget *w)
-{
-  gboolean active = gtk_toggle_button_get_active (togglebutton);
-
-  gtk_widget_set_sensitive (w, active);
-}
-
 static void
 psppire_val_chooser_init (PsppireValChooser *vr)
 {
diff --git a/src/ui/gui/select-cases-dialog.c b/src/ui/gui/select-cases-dialog.c
index be0a957f6c..c03906a6a8 100644
--- a/src/ui/gui/select-cases-dialog.c
+++ b/src/ui/gui/select-cases-dialog.c
@@ -60,27 +60,6 @@ struct select_cases_dialog
 static gchar * generate_syntax (const struct select_cases_dialog *scd);
 
 
-static void
-set_sensitivity_from_toggle (GtkToggleButton *togglebutton,  gpointer data)
-{
-  GtkWidget *w = data;
-  gboolean active = gtk_toggle_button_get_active (togglebutton);
-
-  gtk_widget_set_sensitive (w, active);
-}
-
-static void
-set_sensitivity_from_toggle_invert (GtkToggleButton *togglebutton,
-				    gpointer data)
-{
-  GtkWidget *w = data;
-  gboolean active = gtk_toggle_button_get_active (togglebutton);
-
-  gtk_widget_set_sensitive (w, !active);
-}
-
-
-
 static const gchar label1[]=N_("Approximately %3d%% of all cases.");
 static const gchar label2[]=N_("Exactly %3d cases from the first %3d cases.");