From 58072c431397149af846efc492802f28ea762443 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 10 Nov 2002 00:47:11 +0000 Subject: [PATCH] setting one radio button to TRUE should reset all the others in the same group to FALSE git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17795 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/radiobut.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/msw/radiobut.cpp b/src/msw/radiobut.cpp index f3a54ab99d..d3729c2951 100644 --- a/src/msw/radiobut.cpp +++ b/src/msw/radiobut.cpp @@ -108,6 +108,56 @@ void wxRadioButton::SetValue(bool value) // BST_CHECKED is defined as 1, BST_UNCHECKED as 0, so we can just pass // value as is (we don't use BST_XXX here as they're not defined for Win16) (void)::SendMessage(GetHwnd(), BM_SETCHECK, (WPARAM)value, 0L); + + // 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::Node *nodeThis = siblings.Find(this); + wxCHECK_RET( nodeThis, _T("radio button not a child of its parent?") ); + + // turn off all radio buttons before this one + for ( wxWindowList::Node *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 all after this one + for ( wxWindowList::Node *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); + } + } } bool wxRadioButton::GetValue() const