From 032cc528c8b1c88b3575e09dc6c69d51e9a1dc6f Mon Sep 17 00:00:00 2001 From: attila Date: Sat, 28 May 2022 22:03:21 +0200 Subject: [PATCH] DragAndDropContainer: Fix the escape key dismissing the drag operation --- .../mouse/juce_DragAndDropContainer.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp index 73b182bc20..e534e1909e 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp @@ -59,6 +59,7 @@ public: startTimer (200); setInterceptsMouseClicks (false, false); + setWantsKeyboardFocus (true); setAlwaysOnTop (true); } @@ -200,7 +201,12 @@ public: { if (key == KeyPress::escapeKey) { - dismissWithAnimation (true); + const auto wasVisible = isVisible(); + setVisible (false); + + if (wasVisible) + dismissWithAnimation (true); + deleteSelf(); return true; } @@ -466,8 +472,7 @@ void DragAndDropContainer::startDragging (const var& sourceDescription, dragImageComponent->setOpaque (true); dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks - | ComponentPeer::windowIsTemporary - | ComponentPeer::windowIgnoresKeyPresses); + | ComponentPeer::windowIsTemporary); } else { @@ -484,6 +489,7 @@ void DragAndDropContainer::startDragging (const var& sourceDescription, dragImageComponent->sourceDetails.localPosition = sourceComponent->getLocalPoint (nullptr, lastMouseDown); dragImageComponent->updateLocation (false, lastMouseDown); + dragImageComponent->grabKeyboardFocus(); #if JUCE_WINDOWS // Under heavy load, the layered window's paint callback can often be lost by the OS,