Local Drag & Drop switching to external when leaving the window


I need to implement drag and drop in order to allow the user to drag an item between several components, and also to the external world.

I can do both individually, but I can’t figure out how to use performExternalDragDropOfFiles in combination with the local D&D to switch to external drag & drop when the mouse cursor is leaving the Juce window.

I almost succeeded by calling performExternalDragDropOfFiles from itemDragExit in my main component, but I get an exception when I release the mouse button inside DragAndDropContainer::updateLocation, the currentlyOverComp = newTargetComp assignment crashes because currentlyOverComp is invalid (referenced object = 0xfeeefeee). However this weak reference was correct just before, the call to lastTarget->itemDragExit (details) succeeded. The thing is, I am calling performExternalDragDropOfFiles from this ItemDragExit call (implemented in the main component), and it seems that something is making the currentlyOverComp invalid during this ItemDragExit call. However currentlyOverComp is pointing to my main component which is still alive…

So, I guess that I am probably not using properly the whole drag & drop mechanism in such situation (starting internal D&D and switching to external D&D when leaving the main window).

Any advise?


OK, I got it!

It’s quite easy finally, I just had to override DragAndDropContainer::shouldDropFilesWhenDraggedExternally instead of using DragAndDropContainer::performExternalDragDropOfFiles :slight_smile: