From 19821db2a32fb58db3293c95c8ed231db9a7863b Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 27 Apr 2021 19:08:36 +0100 Subject: [PATCH] HWNDComponentPeer: Dismiss modals when windows are moved This change ensures that popup menus will be dismissed when hosted plugin windows are moved, even when these plugin views are themselves hosted inside JUCE views, like those used in the AudioPluginHost. --- .../native/juce_win32_Windowing.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index f18b890f43..e0b66211a3 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -4160,7 +4160,7 @@ private: void windowShouldDismissModals (HWND originator) { - if (isAncestor (originator, hwnd)) + if (component.isShowing() && isAncestor (originator, hwnd)) sendInputAttemptWhenModalMessage(); } @@ -4190,6 +4190,7 @@ private: constexpr UINT events[] { WM_MOVE, WM_SIZE, + WM_WINDOWPOSCHANGING, WM_NCPOINTERDOWN, WM_NCLBUTTONDOWN, WM_NCRBUTTONDOWN, @@ -4198,6 +4199,17 @@ private: if (std::find (std::begin (events), std::end (events), info->message) == std::end (events)) return; + if (info->message == WM_WINDOWPOSCHANGING) + { + const auto* windowPos = reinterpret_cast (info->lParam); + const auto windowPosFlags = windowPos->flags; + + constexpr auto maskToCheck = SWP_NOMOVE | SWP_NOSIZE; + + if ((windowPosFlags & maskToCheck) == maskToCheck) + return; + } + // windowMayDismissModals could affect the number of active ComponentPeer instances for (auto i = ComponentPeer::getNumPeers(); --i >= 0;) if (i < ComponentPeer::getNumPeers())