From a45c6a892ca8e3dd275138607700ceacd7d2504f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 4 Apr 2012 22:30:30 +0000 Subject: [PATCH] Fix wxRadioButtons without explicit wxRB_GROUP styles in wxGTK. If two radio buttons are created consecutively, they should be part of the same radio group, even if wxRB_GROUP hadn't been explicitly used for the first of them. Do this is for consistency with wxMSW and also because the alternative behaviour doesn't make much sense. Also stop iterating too far backwards when searching for the group to be used for a new radio button and add comments explaining what's going on here. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71091 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/radiobut.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index a8c0a8b8a6..73aedb99ad 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -63,6 +63,9 @@ bool wxRadioButton::Create( wxWindow *parent, return false; } + // Check if this radio button should be put into an existing group. This + // shouldn't be done if it's given a style to explicitly start a new group + // or if it's not meant to be a part of a group at all. GSList* radioButtonGroup = NULL; if (!HasFlag(wxRB_GROUP) && !HasFlag(wxRB_SINGLE)) { @@ -71,10 +74,22 @@ bool wxRadioButton::Create( wxWindow *parent, for (; node; node = node->GetPrevious()) { wxWindow *child = node->GetData(); - if (child->HasFlag(wxRB_GROUP) && wxIsKindOf(child, wxRadioButton)) + + // We stop at the first previous radio button in any case as it + // wouldn't make sense to put this button in a group with another + // one if there is a radio button that is not part of the same + // group between them. + if (wxIsKindOf(child, wxRadioButton)) { - radioButtonGroup = gtk_radio_button_get_group( - GTK_RADIO_BUTTON(child->m_widget)); + // Any preceding radio button can be used to get its group, not + // necessarily one with wxRB_GROUP style, but exclude + // wxRB_SINGLE ones as their group should never be shared. + if (!child->HasFlag(wxRB_SINGLE)) + { + radioButtonGroup = gtk_radio_button_get_group( + GTK_RADIO_BUTTON(child->m_widget)); + } + break; } } -- 2.47.2