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:
Vadim Zeitlin
2019-03-11 13:43:01 +01:00
parent 324c58d9e2
commit 23ddf26571
6 changed files with 103 additions and 20 deletions

View File

@@ -576,6 +576,14 @@ public:
// Return true if the button was clicked, false otherwise.
static bool MSWClickButtonIfPossible(wxButton* btn);
// This method is used for handling wxRadioButton-related complications,
// see wxRadioButton::SetValue(). It calls WXDoUpdatePendingFocus() for
// this window and all its parents up to the enclosing TLW, recursively.
void WXSetPendingFocus(wxWindow* win);
// Should be overridden by all classes storing the "last focused" window.
virtual void WXDoUpdatePendingFocus(wxWindow* WXUNUSED(win)) {}
protected:
// this allows you to implement standard control borders without
// repeating the code in different classes that are not derived from