Fix apparent activation loss after hiding previous popup

Commit 58d4b0e209 introduced a regression:
if a previous popup still existed when the new one was shown, dismissing
the second popup would result in the owner window losing its "active"
appearance.

This was due to the fact that ::GetActiveWindow() still returned the
former popup when it was about to be dismissed, so it was too early to
call it in WM_NCACTIVATE handler. Do it now in DismissOnDeactivate()
itself which is both simpler and more correct.
This commit is contained in:
Vadim Zeitlin
2019-04-02 18:13:27 +02:00
parent 1f64877ca4
commit 9f95e86e76
2 changed files with 8 additions and 9 deletions

View File

@@ -152,7 +152,7 @@ public:
WXLPARAM lParam) wxOVERRIDE; WXLPARAM lParam) wxOVERRIDE;
private: private:
void DismissOnDeactivate(WXHWND hwndActive); void DismissOnDeactivate();
wxDECLARE_DYNAMIC_CLASS(wxPopupTransientWindow); wxDECLARE_DYNAMIC_CLASS(wxPopupTransientWindow);
wxDECLARE_NO_COPY_CLASS(wxPopupTransientWindow); wxDECLARE_NO_COPY_CLASS(wxPopupTransientWindow);

View File

@@ -192,7 +192,7 @@ void wxPopupTransientWindow::Dismiss()
Hide(); Hide();
} }
void wxPopupTransientWindow::DismissOnDeactivate(WXHWND hwndActive) void wxPopupTransientWindow::DismissOnDeactivate()
{ {
// Hide the window automatically when it loses activation. // Hide the window automatically when it loses activation.
Dismiss(); Dismiss();
@@ -203,7 +203,7 @@ void wxPopupTransientWindow::DismissOnDeactivate(WXHWND hwndActive)
wxWindow* const owner = MSWGetOwner(); wxWindow* const owner = MSWGetOwner();
if ( owner ) if ( owner )
{ {
if ( hwndActive != GetHwndOf(owner) ) if ( ::GetActiveWindow() != GetHwndOf(owner) )
{ {
::SendMessage(GetHwndOf(owner), WM_NCACTIVATE, FALSE, 0); ::SendMessage(GetHwndOf(owner), WM_NCACTIVATE, FALSE, 0);
} }
@@ -218,18 +218,17 @@ wxPopupTransientWindow::MSWHandleMessage(WXLRESULT *result,
{ {
switch ( message ) switch ( message )
{ {
case WM_NCACTIVATE: case WM_ACTIVATE:
if ( !wParam ) if ( wParam == WA_INACTIVE )
{ {
// We need to dismiss this window, however doing it directly // We need to dismiss this window, however doing it directly
// from here seems to confuse ::ShowWindow(), which ends up // from here seems to confuse ::ShowWindow(), which ends up
// calling this handler, and may result in losing activation // calling this handler, and may result in losing activation
// entirely, so postpone it slightly. // entirely, so postpone it slightly.
// //
// Note that we do use the currently active window, just in // Also note that the active window hasn't changed yet, so we
// case it changes between now and the next idle event. // postpone calling it until DismissOnDeactivate() is executed.
CallAfter(&wxPopupTransientWindow::DismissOnDeactivate, CallAfter(&wxPopupTransientWindow::DismissOnDeactivate);
::GetActiveWindow());
} }
break; break;
} }