Fix focus after disabling the currently focused control in wxMSW

Fix a regression since 23ddf26571: initial
focus was wrong in a dialog with radio button if the focused control was
disabled. This happened because m_winLastFocused didn't correspond to
the actual focus when we tried to find the next control to focus in this
case, as m_winLastFocused was changed by wxRadioButton::SetValue().

Don't change m_winLastFocused for the window which already has focus to
avoid this problem, and also because it was useless to do this anyhow.

Closes #18521.

Closes https://github.com/wxWidgets/wxWidgets/pull/1590
This commit is contained in:
Vadim Zeitlin
2019-10-05 19:43:04 +02:00
parent 4e5095e5a5
commit 321c1379df

View File

@@ -1023,8 +1023,16 @@ void wxWindowMSW::MSWUpdateUIState(int action, int state)
void wxWindowMSW::WXSetPendingFocus(wxWindow* win)
{
wxWindow * const focus = FindFocus();
for ( wxWindow* parent = this; parent; parent = parent->GetParent() )
{
// We shouldn't overwrite the pending focus if the window has the focus
// currently, as this would make its state inconsistent. And this would
// be useless anyhow, as we only remember pending focus in order to
// restore it properly when the window gets the focus back -- which is
// unnecessary if it has the focus already.
if ( !parent->IsDescendant(focus) )
parent->WXDoUpdatePendingFocus(win);
if ( parent->IsTopLevel() )