summaryrefslogtreecommitdiff
path: root/gtk/gtkradiobutton.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-04-09 22:38:30 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-04-09 22:38:30 -0400
commit58253d567fe90c8c74c65e8fd0fd18d4a1ab18c5 (patch)
treedd355fe9198a426dfbaddebf7d6c30ee1ba51196 /gtk/gtkradiobutton.c
parent3c9ada14fe903274ab33d6a80c1e0151bc4fd0b4 (diff)
downloadgtk+-58253d567fe90c8c74c65e8fd0fd18d4a1ab18c5.tar.gz
radiobutton: Fix selection on focus-in
We need to unselect the previously selected button to preserve radioness. Fixes: #2326
Diffstat (limited to 'gtk/gtkradiobutton.c')
-rw-r--r--gtk/gtkradiobutton.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c
index e853791142..4f1416826e 100644
--- a/gtk/gtkradiobutton.c
+++ b/gtk/gtkradiobutton.c
@@ -637,6 +637,7 @@ gtk_radio_button_focus (GtkWidget *widget,
GtkRadioButton *radio_button = GTK_RADIO_BUTTON (widget);
GtkRadioButtonPrivate *priv = gtk_radio_button_get_instance_private (radio_button);
GSList *tmp_slist;
+ GtkRadioButton *selected_button = NULL;
/* Radio buttons with draw_indicator unset focus "normally", since
* they look like buttons to the user.
@@ -644,6 +645,16 @@ gtk_radio_button_focus (GtkWidget *widget,
if (!gtk_check_button_get_draw_indicator (GTK_CHECK_BUTTON (widget)))
return GTK_WIDGET_CLASS (gtk_radio_button_parent_class)->focus (widget, direction);
+ /* Find the currently active button in the group */
+ tmp_slist = priv->group;
+ while (tmp_slist)
+ {
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tmp_slist->data)) &&
+ gtk_widget_get_visible (tmp_slist->data))
+ selected_button = tmp_slist->data;
+ tmp_slist = tmp_slist->next;
+ }
+
if (gtk_widget_is_focus (widget))
{
GPtrArray *child_array;
@@ -692,29 +703,15 @@ gtk_radio_button_focus (GtkWidget *widget,
{
gtk_widget_grab_focus (new_focus);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (new_focus), TRUE);
+ if (selected_button && selected_button != (GtkRadioButton *)new_focus)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (selected_button), FALSE);
}
g_ptr_array_free (child_array, TRUE);
-
return TRUE;
}
else
{
- GtkRadioButton *selected_button = NULL;
-
- /* We accept the focus if, we don't have the focus and
- * - we are the currently active button in the group
- * - there is no currently active radio button.
- */
- tmp_slist = priv->group;
- while (tmp_slist)
- {
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tmp_slist->data)) &&
- gtk_widget_get_visible (tmp_slist->data))
- selected_button = tmp_slist->data;
- tmp_slist = tmp_slist->next;
- }
-
if (selected_button && selected_button != radio_button)
return FALSE;