Drag and Drop to child component


#1

Hello,
I want to make a simple drag and drop in my plugin from external apps, so in my plugin editor I have a button which when pressed sets a component visible. That component has a drag target in it and I would like to drag and drop to that target in that component, but it wont accept dragging.
When I add just that drag target directly to my plugin editor everything works correctly,but when it is in other component it wont work. How could I solve this or bypass it?
Best regards,
Cila.


#2

Anyone? :cold_sweat:


#3

I assume you do the right thing already, but when moving into another component, maybe you forgot to adapt the bounds of the drop target or something similar…?

But we can only guess without seeing code… maybe you can separate the interesting parts out?


#5

Gladly!
Lets start from component and its child.
I have basic custom component autogenerated juce class here:

`class Settings  : public Component`
    {
    public:
      


     Settings ();
    ~Settings();        

    //[UserMethods]     -- You can add your own custom methods in this section.
    //[/UserMethods]

    void paint (Graphics& g) override;
    void resized() override;



private:
    //[UserVariables]   -- You can add your own custom variables in this section.
	dragTarget target;
    //[/UserVariables]
//==============================================================================
ScopedPointer<Label> newSoundPad1;


//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Settings)
};

It is GUI component where I have one label and one custom component which will be dragTarget.
I didn’t derive this class from DragAndDropContainer since it said that it is used for draging components inside of window,but I only need external files to be dragged here.
In .cpp file of this class everything is basically autogenerated except that I addAndMakeVisible my dragTarget component and set its bounds.

Thats it for Settings class,now for dragTarget.

class dragTarget    : public Component,                   
                    public FileDragAndDropTarget,
                    public TextDragAndDropTarget

I derive it from this classes.
Got those private attributes:

private:
    String message;
    bool somethingIsBeingDraggedOver;

and pretty much all methods are copied from widgets part od Juce demo,except the part with draging other components,but I have tried that too if it works but no.

 //==============================================================================
        // These methods implement the FileDragAndDropTarget interface, and allow our component
        // to accept drag-and-drop of files..

        bool isInterestedInFileDrag (const StringArray& /*files*/) override
        {
            // normally you'd check these files to see if they're something that you're
            // interested in before returning true, but for the demo, we'll say yes to anything..
			
            return true;
        }

        void fileDragEnter (const StringArray& /*files*/, int /*x*/, int /*y*/) override
        {
			fileGot = false;
			somethingIsBeingDraggedOver = true;
            repaint();
        }

        void fileDragMove (const StringArray& /*files*/, int /*x*/, int /*y*/) override
        {
        }

        void fileDragExit (const StringArray& /*files*/) override
        {
            somethingIsBeingDraggedOver = false;
            repaint();
        }

        void filesDropped (const StringArray& files, int /*x*/, int /*y*/) override
        {
            message =files.joinIntoString ("\n");
			fileGot = true;
            somethingIsBeingDraggedOver = false;
            repaint();
        }

        //==============================================================================
        // These methods implement the TextDragAndDropTarget interface, and allow our component
        // to accept drag-and-drop of text..

        bool isInterestedInTextDrag (const String& /*text*/) override
        {
            return true;
        }

        void textDragEnter (const String& /*text*/, int /*x*/, int /*y*/) override
        {
            somethingIsBeingDraggedOver = true;
            repaint();
        }

        void textDragMove (const String& /*text*/, int /*x*/, int /*y*/) override
        {
        }

        void textDragExit (const String& /*text*/) override
        {
            somethingIsBeingDraggedOver = false;
            repaint();
        }

        void textDropped (const String& text, int /*x*/, int /*y*/) override
        {
            message = "Text dropped:\n" + text;

            somethingIsBeingDraggedOver = false;
            repaint();

paint function draws red square around component when something is being dragged over.

Now in my processor editor class:

I create one private

Settings settings;

Then in constructor:

addAndMakeVisible(settings);

in resize method I set its bounds and thats it.

When I try to drag file,cursor shows undraggable when over my settings component and with behavior like that I cant pass dragged file to its child.

If in my editor class I make one dragTarget,add and make it visible,set its bounds,then when dragging over that dragTarget component cursor shows ok and files get dropped on right place.
I have tried also with setInterceptMouseClicks but nothing.

I would like to figure this out somehow so that I wont need to have those targets in my processor editor directly.

Best regards,
Cila.