FileDragAndDropTarget will not work


is there any sample code, showing how to implement an application accepting dragged files from another process (finder, explorer, etc.)? I tried to inherit a component from FileDragAndDropTarget and implemented isInterestedInFileDrag(…) and filesDropped(…), but both methods will never be called.

I can’t find any documentation explaining this.

Thanks in advance,

The JUCE demo project in the examples folder has plenty of examples of how to do this.

That might be right. I.e. there is the Plugin Host App which implements the FileDragAndDropTarget. But, I can’t see why it works. My code implements the FileDragAndDropTarget in the same way, without success.

There must be more and the demo does not explain what.

The plugin host is quite a large and complex app, you’d be better off looking at something simpler like the “MDIDemo” in the JUCE demo. It’d also help if you could post your code here so we can see what might be going wrong.

the Widgets.cpp in the JUCE DEMO app contains everything you need to know. Look at around line 1090, the DragAndDropDemoTarget code is what you want to read.

Thanks for the hints!

As a summary for all others, having the same challenge, I’ll try to point out what the solution is:

  • use a parent component, which must be public inherited from DragAndDropContainer
  • use a child component, which must be public inherited from DragAndDropTarget and FileDragAndDropTarget and implement all necessary methods.

Possible pitfall: forget the keyword public, when declaring the base classes. I did it; it compiles, but it doesn’t work - grrr…

Possible improvement suggestion: wouldn’t it be possible to derive FileDragAndDropTarget from DragAndDropTarget inside the Juce framework? And of course TextDragAndDropTarget too. Multiple inheritance shouldn’t be a problem here - or? The documentation of FileDragAndDropTarget does nothing tell about the necessity of deriving from DragAndDropTarget. By doing this inside the framework, a developer must not think about it anymore.

Did you see that hint in DragAndDropTarget’s docs:

Note: If all that you need to do is to respond to files being drag-and-dropped from the operating system onto your component, you don’t need any of these classes: instead see the FileDragAndDropTarget class.

Maybe try that approach again, now that you found the problem with private inheritance…

Good luck