mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-28 14:31:10 +00:00
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.
This commit is contained in:
parent
abd4754648
commit
553a9c292d
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -1,40 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2014 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_TOGGLE_BUTTON_PRIVATE_H__
|
||||
#define __GTK_TOGGLE_BUTTON_PRIVATE_H__
|
||||
|
||||
|
||||
#include <gtk/gtktogglebutton.h>
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void _gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
|
||||
gboolean is_active);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
#endif /* __GTK_TOGGLE_BUTTON_PRIVATE_H__ */
|
Loading…
Reference in New Issue
Block a user