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
This commit is contained in:
Kvaz1r 2021-07-11 21:10:59 +03:00 committed by Vadim Zeitlin
parent b39cf5da32
commit 9028ae74fc

View File

@ -65,43 +65,17 @@ bool wxRadioButton::Create(wxWindow *parent,
void wxRadioButton::OnCheck() void wxRadioButton::OnCheck()
{ {
// clear all others radio buttons in our group: for this we need to // clear all the other radio buttons in our group
// find the radio button which is the first in the group, i.e. the one wxRadioButton* const last = GetLastInGroup();
// with wxRB_GROUP style for ( wxRadioButton* radio = GetFirstInGroup();
const wxWindowList& siblings = GetParent()->GetChildren(); radio;
wxWindowList::compatibility_iterator nodeStart = siblings.Find(this); radio = radio->GetNextInGroup() )
while ( nodeStart )
{ {
// stop if we found a radio button with wxRB_GROUP style or it we if ( radio != this )
// are at the first control radio->ClearValue();
if ( !nodeStart->GetPrevious() ||
(nodeStart->GetData()->GetWindowStyle() & wxRB_GROUP) ) if ( radio == last )
break; 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;
}
} }
} }