ListBox drag&drop question

Hi, Julian.

Is it possible to know which mouse button initiated a drag&drop operation in ListBox? I need to allow only left-button to initiate draging.

No, there’s nothing built-in that would do that. I think you’d probably need to use your own custom list items if you need to do anything that specific.

You’re kidding. Right? :lol: That’s funny, really. I believe you are not going to complicate simple things.

This is your code from juce_ListBox.cpp

[code] void ListBoxRowComponent::mouseDrag (const MouseEvent& e)
if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
const SparseSet selectedRows (owner.getSelectedRows());

        if (selectedRows.size() > 0)
            const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));

            if (dragDescription.isNotEmpty())
                isDragging = true;

                DragAndDropContainer* const dragContainer
                    = DragAndDropContainer::findParentDragContainerFor (this);

                if (dragContainer != 0)
                    Image* dragImage = owner.createSnapshotOfSelectedRows();
                    dragImage->multiplyAllAlphas (0.6f);

                    dragContainer->startDragging (dragDescription, &owner, dragImage, true);
                    // to be able to do a drag-and-drop operation, the listbox needs to
                    // be inside a component which is also a DragAndDropContainer.


What prevents you from passing const MouseEvent& e argument to the getDragSourceDescription (selectedRows) function as a second reference paramenter to let a programmer know how a drag&drop operation is being invoked?

It is the matter of changing the function signature to this: virtual const String getDragSourceDescription (const SparseSet& currentlySelectedRows, const MouseEvent& e);

Is it an overhead? Is it something bad I’m asking for?
So, there are TableListBox, FileTreeComponent and TreeView classes that needs to be reviewed for the change.

It feels wrong to put the mouse information in there. If you need to know which mouse button or modifier key is down, I reckon your target should be asking a more abstract question - e.g. instead of the target asking “is the ctrl key down”, it should be asking the source whether the user is trying to do a “copy” or a “move”, so different sources can decide this in appropriate ways, maybe based on the mouse action, or maybe not.

Aha. I understand. You’re absolutely right. It really feels wrong.