Fix bug with wxRadioButton state changing unexpectedly in wxMSW
In wxMSW, a focused wxRadioButton is always checked, which meant that checking a wxRadioButton while focus was not in the window containing it and later giving the focus to that window could uncheck it by giving focus to another wxRadioButton that had had it previously. Fix this by adding WXSetPendingFocus() to wxMSW wxWindow and calling it from wxRadioButton::SetValue() to ensure that when the focus is regained, it goes to the newly checked radio button and not some other one. This replaces the previously used, for the same purpose, wxMSW-specific wxTopLevelWindow::SetLastFocus(), so while this solution is not exactly pretty, it's not worse than we had before, while being more generic. Also add a unit test checking that things work correctly in the scenario described above. Closes https://github.com/wxWidgets/wxWidgets/pull/1257 Closes #18341.
This commit is contained in:
@@ -1026,6 +1026,17 @@ void wxWindowMSW::MSWUpdateUIState(int action, int state)
|
||||
::SendMessage(GetHwnd(), WM_CHANGEUISTATE, MAKEWPARAM(action, state), 0);
|
||||
}
|
||||
|
||||
void wxWindowMSW::WXSetPendingFocus(wxWindow* win)
|
||||
{
|
||||
for ( wxWindow* parent = this; parent; parent = parent->GetParent() )
|
||||
{
|
||||
parent->WXDoUpdatePendingFocus(win);
|
||||
|
||||
if ( parent->IsTopLevel() )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// scrolling stuff
|
||||
// ---------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user