Drag & Drop stopped working when switching to JUCE 7

I switched from JUCE 6 to 7 and my drag & drop stopped working.
In my own code I do the following:

    addChildComponent(&m_drag_cursor_component);
    m_drag_cursor_component.setAlwaysOnTop(true);
    m_drag_cursor_component.setBounds(x, y, drag_item_width, drag_item_height);

    m_drag_cursor_component.setVisible(true);
    jassert(m_drag_cursor_component.isShowing() || m_drag_cursor_component.isOnDesktop());
    jassert(isShowing() || isOnDesktop());

    DragAndDropContainer* dragC = DragAndDropContainer::findParentDragContainerFor(&m_drag_cursor_component);
    jassert(!dragC->isDragAndDropActive());    
    dragC->startDragging("description string", &m_drag_cursor_component);

And I get the crash on that last line of code. I get the assertion failure in:

juce_Component.cpp:
    void Component::grabKeyboardFocus()
        jassert (isShowing() || isOnDesktop());

What’s changed so that the above doesn’t work anymore? How to fix that?

My initial tests are telling me that for some reason DragAndDropContainer::DragImageComponent is not showing and that is causing the assertion failure.

That component is created by startDragging() method.

The problem turned out to be that when you return “false” from:

bool DragAndDropTarget::shouldDrawDragImageWhenOver()

JUCE stops at assertion failure when dragging. The previous version of JUCE happily dragged the object without any assertion issues.

Thank you for reporting this.

This issue is caused by a change that makes the DragImageComponent grab the keyboard focus so that the drag operation can be dismissed by the escape key.

I don’t know every detail about the implementation that you are using, so could you maybe see if your problem goes away by applying this patch?

drag-and-drop.patch (1.5 KB)

1 Like

I already made a work-around by changing other things in my code. I wouldn’t want to change it back as it’s not once again properly working code with the expected behaviour of the latest version of JUCE.

We have released a fix for this issue, which is now also part of the 7.0.2 release.

1 Like