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:
@@ -100,9 +100,12 @@ public:
|
||||
// event handlers
|
||||
void OnActivate(wxActivateEvent& event);
|
||||
|
||||
// called by wxWindow whenever it gets focus
|
||||
void SetLastFocus(wxWindow *win) { m_winLastFocused = win; }
|
||||
wxWindow *GetLastFocus() const { return m_winLastFocused; }
|
||||
// called from wxWidgets code itself only when the pending focus, i.e. the
|
||||
// element which should get focus when this TLW is activated again, changes
|
||||
virtual void WXDoUpdatePendingFocus(wxWindow* win) wxOVERRIDE
|
||||
{
|
||||
m_winLastFocused = win;
|
||||
}
|
||||
|
||||
// translate wxWidgets flags to Windows ones
|
||||
virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const wxOVERRIDE;
|
||||
|
Reference in New Issue
Block a user