From 71d10e750a0fb03c63c32b162c6e103600abe656 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 12 Sep 2017 10:59:51 +0100 Subject: [PATCH] Fixed a bug where PopupMenus were being dismissed when opening a submenu using touch input --- .../juce_gui_basics/menus/juce_PopupMenu.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index b5d8c19f73..6c92b07e02 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -1027,6 +1027,13 @@ public: void timerCallback() override { + #if JUCE_WINDOWS + // touch and pen devices on Windows send an offscreen mouse move after mouse up events + // but we don't want to forward these on as they will dismiss the menu + if ((source.isTouch() || source.isPen()) && ! isValidMousePosition()) + return; + #endif + if (window.windowIsStillValid()) handleMousePosition (source.getScreenPosition().roundToInt()); } @@ -1218,6 +1225,20 @@ private: return true; } + #if JUCE_WINDOWS + bool isValidMousePosition() + { + auto screenPos = source.getScreenPosition(); + auto localPos = (window.activeSubMenu == nullptr) ? window.getLocalPoint (nullptr, screenPos) + : window.activeSubMenu->getLocalPoint (nullptr, screenPos); + + if (localPos.x < 0 && localPos.y < 0) + return false; + + return true; + } + #endif + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MouseSourceState) };