Spring loaded drag and drop

If I’m using DragAndDropContainer/Target and want to open a folder (essentially) if the user mouses over it while dragging is there a nice way to do this? Or shall I just get into doing some kind of global mouse listener thing? I don’t get mouseMove events on my folder while a drag operation is happening.

The process I want is:

  1. User starts dragging object A
  2. User moves mouse over object B triggering a new folder to open, and potentially object A to be hidden or deleted.
  3. User drops object A into the new folder which is rendered in another location.

This is a common behaviour in windows and macos you’ll have probably used without thinking too hard about it.


I’ve made it work with a timer for now, querying the global mouse position. However when it opens the folder the drag and drop operation hangs. Anyone know how to stop the debugger while I’m still holding the mouse down so I can debug drag and drop target :slight_smile: :slight_smile:

Ah this is because DragImageComponent secretly gets the component under the mouse to use as a source of mouse events (why!?) so if you delete it, even though you didn’t pass it to startDragging then the drag and drop stops working?

    DragImageComponent (const ScaledImage& im,
                        const var& desc,
                        Component* const sourceComponent,
                        const MouseInputSource* draggingSource,
                        DragAndDropContainer& ddc,
                        Point<int> offset)
        : sourceDetails (desc, sourceComponent, Point<int>()),
          image (im),
          owner (ddc),
          mouseDragSource (draggingSource->getComponentUnderMouse()),
          imageOffset (transformOffsetCoordinates (sourceComponent, offset)),
          originalInputSourceIndex (draggingSource->getIndex()),
          originalInputSourceType (draggingSource->getType())

        if (mouseDragSource == nullptr)
            mouseDragSource = sourceComponent;

        mouseDragSource->addMouseListener (this, false);

        startTimer (200);

        setInterceptsMouseClicks (false, false);
        setAlwaysOnTop (true);

This is either undocumented behaviour or a bug?