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:
parent
b39cf5da32
commit
9028ae74fc
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user