Browse Source

Added callbacks to DragAndDropContainer to be told when drag operations begin/end.

tags/2021-05-28
jules 11 years ago
parent
commit
c6ca8b05b1
2 changed files with 22 additions and 4 deletions
  1. +16
    -4
      modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp
  2. +6
    -0
      modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h

+ 16
- 4
modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp View File

@@ -69,6 +69,8 @@ public:
if (current->isInterestedInDragSource (sourceDetails)) if (current->isInterestedInDragSource (sourceDetails))
current->itemDragExit (sourceDetails); current->itemDragExit (sourceDetails);
} }
owner.dragOperationEnded();
} }
void paint (Graphics& g) override void paint (Graphics& g) override
@@ -164,14 +166,14 @@ public:
if (sourceDetails.sourceComponent == nullptr) if (sourceDetails.sourceComponent == nullptr)
{ {
delete this;
deleteSelf();
} }
else if (! isMouseButtonDownAnywhere()) else if (! isMouseButtonDownAnywhere())
{ {
if (mouseDragSource != nullptr) if (mouseDragSource != nullptr)
mouseDragSource->removeMouseListener (this); mouseDragSource->removeMouseListener (this);
delete this;
deleteSelf();
} }
} }
@@ -180,7 +182,7 @@ public:
if (key == KeyPress::escapeKey) if (key == KeyPress::escapeKey)
{ {
dismissWithAnimation (true); dismissWithAnimation (true);
delete this;
deleteSelf();
return true; return true;
} }
@@ -311,12 +313,17 @@ private:
&& ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown()) && ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
{ {
(new ExternalDragAndDropMessage (files, canMoveFiles))->post(); (new ExternalDragAndDropMessage (files, canMoveFiles))->post();
delete this;
deleteSelf();
} }
} }
} }
} }
void deleteSelf()
{
delete this;
}
void dismissWithAnimation (const bool shouldSnapBack) void dismissWithAnimation (const bool shouldSnapBack)
{ {
setVisible (true); setVisible (true);
@@ -449,6 +456,8 @@ void DragAndDropContainer::startDragging (const var& sourceDescription,
if (ComponentPeer* const peer = dragImageComponent->getPeer()) if (ComponentPeer* const peer = dragImageComponent->getPeer())
peer->performAnyPendingRepaintsNow(); peer->performAnyPendingRepaintsNow();
#endif #endif
dragOperationStarted();
} }
} }
@@ -473,6 +482,9 @@ bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const DragAndDr
return false; return false;
} }
void DragAndDropContainer::dragOperationStarted() {}
void DragAndDropContainer::dragOperationEnded() {}
//============================================================================== //==============================================================================
DragAndDropTarget::SourceDetails::SourceDetails (const var& desc, Component* comp, Point<int> pos) noexcept DragAndDropTarget::SourceDetails::SourceDetails (const var& desc, Component* comp, Point<int> pos) noexcept
: description (desc), : description (desc),


+ 6
- 0
modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h View File

@@ -165,6 +165,12 @@ protected:
virtual bool shouldDropFilesWhenDraggedExternally (const DragAndDropTarget::SourceDetails& sourceDetails, virtual bool shouldDropFilesWhenDraggedExternally (const DragAndDropTarget::SourceDetails& sourceDetails,
StringArray& files, bool& canMoveFiles); 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: private:
//============================================================================== //==============================================================================
class DragImageComponent; class DragImageComponent;


Loading…
Cancel
Save