From: Vadim Zeitlin Date: Thu, 24 Feb 2005 16:58:14 +0000 (+0000) Subject: fix for SetValue() losing effect after focus change (patch 1150911) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f469584d643a59dab4545bb95020bf6188af1d69 fix for SetValue() losing effect after focus change (patch 1150911) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32351 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/radiobut.cpp b/src/msw/radiobut.cpp index c49c960045..e88d6d7829 100644 --- a/src/msw/radiobut.cpp +++ b/src/msw/radiobut.cpp @@ -168,6 +168,12 @@ void wxRadioButton::SetValue(bool value) // buttons in the same group: Windows doesn't do it automatically if ( m_isChecked ) { + // If another radiobutton in the group currently has the focus, we have to + // set it to this radiobutton, else the old readiobutton will be reselected + // automatically, if a parent window loses the focus and regains it. + bool shouldSetFocus = false; + wxWindow* pFocusWnd = FindFocus(); + const wxWindowList& siblings = GetParent()->GetChildren(); wxWindowList::compatibility_iterator nodeThis = siblings.Find(this); wxCHECK_RET( nodeThis, _T("radio button not a child of its parent?") ); @@ -190,6 +196,9 @@ void wxRadioButton::SetValue(bool value) if (btn) { + if (btn == pFocusWnd) + shouldSetFocus = true; + btn->SetValue(false); if ( btn->HasFlag(wxRB_GROUP) ) @@ -217,8 +226,15 @@ void wxRadioButton::SetValue(bool value) } if (btn) + { + if (btn == pFocusWnd) + shouldSetFocus = true; + btn->SetValue(false); + } } + if (shouldSetFocus) + SetFocus(); } }