+
+ // if we set the value of one radio button we also must clear all the other
+ // buttons in the same group: Windows doesn't do it automatically
+ if ( value )
+ {
+ const wxWindowList& siblings = GetParent()->GetChildren();
+ wxWindowList::compatibility_iterator nodeThis = siblings.Find(this);
+ wxCHECK_RET( nodeThis, _T("radio button not a child of its parent?") );
+
+ // if it's not the first item of the group ...
+ if ( !HasFlag(wxRB_GROUP) )
+ {
+ // ... turn off all radio buttons before it
+ for ( wxWindowList::compatibility_iterator nodeBefore = nodeThis->GetPrevious();
+ nodeBefore;
+ nodeBefore = nodeBefore->GetPrevious() )
+ {
+ wxRadioButton *btn = wxDynamicCast(nodeBefore->GetData(),
+ wxRadioButton);
+ if ( !btn )
+ {
+ // the radio buttons in a group must be consecutive, so
+ // there are no more of them
+ break;
+ }
+
+ btn->SetValue(FALSE);
+
+ if ( btn->HasFlag(wxRB_GROUP) )
+ {
+ // even if there are other radio buttons before this one,
+ // they're not in the same group with us
+ break;
+ }
+ }
+ }
+
+ // ... and also turn off all buttons after this one
+ for ( wxWindowList::compatibility_iterator nodeAfter = nodeThis->GetNext();
+ nodeAfter;
+ nodeAfter = nodeAfter->GetNext() )
+ {
+ wxRadioButton *btn = wxDynamicCast(nodeAfter->GetData(),
+ wxRadioButton);
+
+ if ( !btn || btn->HasFlag(wxRB_GROUP) )
+ {
+ // no more buttons or the first button of the next group
+ break;
+ }
+
+ btn->SetValue(FALSE);
+ }
+ }