[gtk/wip/otte/listview: 1/94] togglebutton: Don't emit clicked during set_active()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 1/94] togglebutton: Don't emit clicked during set_active()
- Date: Sat, 26 Oct 2019 08:01:31 +0000 (UTC)
commit 801a3064bcefdf88e5b5c516e299878120e7665d
Author: Benjamin Otte <otte redhat com>
Date: Sat Oct 26 07:00:24 2019 +0200
togglebutton: Don't emit clicked during set_active()
set_active() is meant to set the state of the property, which happens
during setup.
The clicked signal is emitting events from user actions.
It is impossible to use Togglebuttons for MVC applications as long as it
does that.
gtk/gtkradiobutton.c | 25 +++++--------------------
gtk/gtktogglebutton.c | 30 ++++++++++--------------------
gtk/gtktogglebuttonprivate.h | 40 ----------------------------------------
3 files changed, 15 insertions(+), 80 deletions(-)
---
diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c
index 313be232b7..344cde3b89 100644
--- a/gtk/gtkradiobutton.c
+++ b/gtk/gtkradiobutton.c
@@ -27,7 +27,6 @@
#include "gtkradiobutton.h"
#include "gtkwidgetprivate.h"
-#include "gtktogglebuttonprivate.h"
#include "gtkcheckbuttonprivate.h"
#include "gtklabel.h"
#include "gtkmarshalers.h"
@@ -242,7 +241,7 @@ gtk_radio_button_init (GtkRadioButton *radio_button)
gtk_widget_set_receives_default (GTK_WIDGET (radio_button), FALSE);
- _gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), TRUE);
priv->group = g_slist_prepend (NULL, radio_button);
@@ -729,9 +728,6 @@ gtk_radio_button_clicked (GtkButton *button)
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
GtkToggleButton *tmp_button;
GSList *tmp_list;
- gint toggled;
-
- toggled = FALSE;
g_object_ref (GTK_WIDGET (button));
@@ -753,17 +749,13 @@ gtk_radio_button_clicked (GtkButton *button)
}
if (tmp_button)
- {
- toggled = TRUE;
- _gtk_toggle_button_set_active (toggle_button,
- !gtk_toggle_button_get_active (toggle_button));
- }
+ gtk_toggle_button_set_active (toggle_button,
+ !gtk_toggle_button_get_active (toggle_button));
}
else
{
- toggled = TRUE;
- _gtk_toggle_button_set_active (toggle_button,
- !gtk_toggle_button_get_active (toggle_button));
+ gtk_toggle_button_set_active (toggle_button,
+ !gtk_toggle_button_get_active (toggle_button));
tmp_list = priv->group;
while (tmp_list)
@@ -779,13 +771,6 @@ gtk_radio_button_clicked (GtkButton *button)
}
}
- if (toggled)
- {
- gtk_toggle_button_toggled (toggle_button);
-
- g_object_notify (G_OBJECT (toggle_button), "active");
- }
-
gtk_widget_queue_draw (GTK_WIDGET (button));
g_object_unref (button);
diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c
index b9984aacbf..ad70b984ab 100644
--- a/gtk/gtktogglebutton.c
+++ b/gtk/gtktogglebutton.c
@@ -24,7 +24,7 @@
#include "config.h"
-#include "gtktogglebuttonprivate.h"
+#include "gtktogglebutton.h"
#include "gtkbuttonprivate.h"
#include "gtkintl.h"
@@ -293,8 +293,9 @@ gtk_toggle_button_get_property (GObject *object,
*
* Sets the status of the toggle button. Set to %TRUE if you want the
* GtkToggleButton to be “pressed in”, and %FALSE to raise it.
- * This action causes the #GtkToggleButton::toggled signal and the
- * #GtkButton::clicked signal to be emitted.
+ *
+ * If the status of the button changes, this action causes the
+ * #GtkToggleButton::toggled signal to be emitted.
*/
void
gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
@@ -306,18 +307,8 @@ gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
is_active = is_active != FALSE;
- if (priv->active != is_active)
- {
- g_signal_emit_by_name (toggle_button, "clicked");
- g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_ACTIVE]);
- }
-}
-
-void
-_gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
- gboolean is_active)
-{
- GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
+ if (priv->active == is_active)
+ return;
priv->active = is_active;
@@ -326,6 +317,9 @@ _gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
else
gtk_widget_unset_state_flags (GTK_WIDGET (toggle_button), GTK_STATE_FLAG_CHECKED);
+ gtk_toggle_button_toggled (toggle_button);
+
+ g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_ACTIVE]);
}
/**
@@ -387,11 +381,7 @@ gtk_toggle_button_clicked (GtkButton *button)
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
- _gtk_toggle_button_set_active (toggle_button, !priv->active);
-
- gtk_toggle_button_toggled (toggle_button);
-
- g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_ACTIVE]);
+ gtk_toggle_button_set_active (toggle_button, !priv->active);
if (GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked)
GTK_BUTTON_CLASS (gtk_toggle_button_parent_class)->clicked (button);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]