From 9028ae74fcdd020224ddcb3a3e98519608ca57b7 Mon Sep 17 00:00:00 2001 From: Kvaz1r Date: Sun, 11 Jul 2021 21:10:59 +0300 Subject: [PATCH] Fix and simplify wxRadioButton handling in wxUniv Reuse common functions that work correctly, while wxUniv-specific version of the code didn't pass RadioButton::Single unit test. Closes https://github.com/wxWidgets/wxWidgets/pull/2430 --- src/univ/radiobut.cpp | 44 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/src/univ/radiobut.cpp b/src/univ/radiobut.cpp index ec2ccd9994..bae966edb5 100644 --- a/src/univ/radiobut.cpp +++ b/src/univ/radiobut.cpp @@ -65,43 +65,17 @@ bool wxRadioButton::Create(wxWindow *parent, void wxRadioButton::OnCheck() { - // clear all others radio buttons in our group: for this we need to - // find the radio button which is the first in the group, i.e. the one - // with wxRB_GROUP style - const wxWindowList& siblings = GetParent()->GetChildren(); - wxWindowList::compatibility_iterator nodeStart = siblings.Find(this); - while ( nodeStart ) + // clear all the other radio buttons in our group + wxRadioButton* const last = GetLastInGroup(); + for ( wxRadioButton* radio = GetFirstInGroup(); + radio; + radio = radio->GetNextInGroup() ) { - // stop if we found a radio button with wxRB_GROUP style or it we - // are at the first control - if ( !nodeStart->GetPrevious() || - (nodeStart->GetData()->GetWindowStyle() & wxRB_GROUP) ) + if ( radio != this ) + radio->ClearValue(); + + if ( radio == last ) break; - - nodeStart = nodeStart->GetPrevious(); - } - - // now clear all radio buttons from the starting one until the next - // one with wxRB_GROUP style - while ( nodeStart ) - { - wxWindow *win = nodeStart->GetData(); - if ( win != this ) - { - wxRadioButton *btn = wxDynamicCast(win, wxRadioButton); - if ( btn ) - { - btn->ClearValue(); - } - } - - nodeStart = nodeStart->GetNext(); - if ( !nodeStart || - (nodeStart->GetData()->GetWindowStyle() & wxRB_GROUP) ) - { - // we reached the next group - break; - } } }