From 881aabf63e279f72d3d4fc8f31a09a6925739769 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 17 Aug 2019 21:51:30 +0200 Subject: [PATCH] Fix dismissing wxComboCtrl popup When wxComboCtrl popup window is dismissed we need to hide it but calling ShowWindow() Win API directly from WM_ACTIVATE event handler causes some side effects like calling the handler again (under Win 7) or setting the focus improperly (under Win 10). To avoid these problems we should postpone hiding. Closes #18376. --- src/common/combocmn.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index cd7970cbea..6490f761a0 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -549,6 +549,9 @@ public: #endif private: +#if USES_GENERICTLW + void HideOnDeactivate(); +#endif // USES_GENERICTLW wxComboCtrlBase* m_combo; wxDECLARE_EVENT_TABLE(); @@ -586,11 +589,23 @@ void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event ) if ( !event.GetActive() ) { // Tell combo control that we are dismissed. - m_combo->HidePopup(true); - +#ifdef __WXMSW__ + // We need to hide the popup but calling ::ShowWindow() directly from WM_ACTIVATE + // event handler causes some side effects like calling this handler again (Win 7) + // or setting the focus improperly (Win 10), so postpone it slightly. + // See wxPopupTransientWindow::MSWHandleMessage(). + CallAfter(&wxComboPopupWindowEvtHandler::HideOnDeactivate); +#else + HideOnDeactivate(); +#endif __WXMSW__ / !__WXMSW__ event.Skip(); } } + +void wxComboPopupWindowEvtHandler::HideOnDeactivate() +{ + m_combo->HidePopup(true); +} #endif