From c6ca8b05b1377a039153d3adba544781c4eeb26b Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 7 Oct 2014 12:08:05 +0100 Subject: [PATCH] Added callbacks to DragAndDropContainer to be told when drag operations begin/end. --- .../mouse/juce_DragAndDropContainer.cpp | 20 +++++++++++++++---- .../mouse/juce_DragAndDropContainer.h | 6 ++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp index bea1a160ae..2e9c44b2c4 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp @@ -69,6 +69,8 @@ public: if (current->isInterestedInDragSource (sourceDetails)) current->itemDragExit (sourceDetails); } + + owner.dragOperationEnded(); } void paint (Graphics& g) override @@ -164,14 +166,14 @@ public: if (sourceDetails.sourceComponent == nullptr) { - delete this; + deleteSelf(); } else if (! isMouseButtonDownAnywhere()) { if (mouseDragSource != nullptr) mouseDragSource->removeMouseListener (this); - delete this; + deleteSelf(); } } @@ -180,7 +182,7 @@ public: if (key == KeyPress::escapeKey) { dismissWithAnimation (true); - delete this; + deleteSelf(); return true; } @@ -311,12 +313,17 @@ private: && ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown()) { (new ExternalDragAndDropMessage (files, canMoveFiles))->post(); - delete this; + deleteSelf(); } } } } + void deleteSelf() + { + delete this; + } + void dismissWithAnimation (const bool shouldSnapBack) { setVisible (true); @@ -449,6 +456,8 @@ void DragAndDropContainer::startDragging (const var& sourceDescription, if (ComponentPeer* const peer = dragImageComponent->getPeer()) peer->performAnyPendingRepaintsNow(); #endif + + dragOperationStarted(); } } @@ -473,6 +482,9 @@ bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const DragAndDr return false; } +void DragAndDropContainer::dragOperationStarted() {} +void DragAndDropContainer::dragOperationEnded() {} + //============================================================================== DragAndDropTarget::SourceDetails::SourceDetails (const var& desc, Component* comp, Point pos) noexcept : description (desc), diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h index 984375379b..072f35ee18 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h @@ -165,6 +165,12 @@ protected: virtual bool shouldDropFilesWhenDraggedExternally (const DragAndDropTarget::SourceDetails& sourceDetails, StringArray& files, bool& canMoveFiles); + /** Subclasses can override this to be told when a drag starts. */ + virtual void dragOperationStarted(); + + /** Subclasses can override this to be told when a drag finishes. */ + virtual void dragOperationEnded(); + private: //============================================================================== class DragImageComponent;