"custom" Drag and drop on list box items

Hi Jules & community !

I have a simple ListBox with custom components inside. Drag and drop is working fine, but I’d like to do “custom” stuff when the drag operation is starting.
I tried to overload the mouseDown and mouseDrag methods of juce::Component, both inside my custom component and in the listBox itself…but the methods never get called

virtual void mouseDown(const juce::MouseEvent &e ) { DBG("Mouse down"); } virtual void mouseDrag(const juce::MouseEvent &e ) { DBG("Mouse drag"); }

I guess that’s pretty normal because otherwise, the ListBox default behaviour wouldn’t work …but I’m also sure there is a way to do this.
I tried to mess around with setInterceptMouseClicks but no luck so far.

What’s the standard, juce, way to do this ?

Or isn’t there any standard way maybe ? :frowning:

If you have a custom comp, then the mouseDown and up methods will certainly be called for it. If it’s not working then you must have just done something wrong somewhere.

Are you sure ? The clicks seem to be intercepted by the ListBox :

The method

is called but the event doesn’t seem to be forwarded by my own component …

A parent doesn’t have to forward mouse clicks to its children! If your custom component is clicked, it’ll get the event directly.

Well it doesn’t get called …probably my mistake. I can’t find where but I found a much better solution :
In listBoxModel, both :

listBoxItemClicked (int row, const MouseEvent &e) getDragSourceDescription (const SparseSet< int > &currentlySelectedRows)

can be overloaded and get called respectively when clicking on an item, and when dragging an item !

Hey friend,
I have one doubt to ask you, where i have custom component in ListBox,
And I want my custom component to call listBoxItemClicked and other methods of ListBox,
do u have any idea to do so? or just have to have forward events to do so ?

[quote=“acn”]Hey friend,
I have one doubt to ask you, where i have custom component in ListBox,
And I want my custom component to call listBoxItemClicked and other methods of ListBox,
do u have any idea to do so? or just have to have forward events to do so ?[/quote]

Sorry but I’m not sure I understand what you mean ?!
If you have a class derived from ListBoxModel, you just have to override “listBoxItemClicked (int row, const MouseEvent &e)” and it’s gonna work. Or did you mean something else ?

Thanks dinaiz for your reply and interest. :smiley:

Well ListBox has custom component inside, and You are right It just need listBoxItemClicked(row, e) and other need to be implemented, These all were working fine till ListBox had no custom component inside, when ListBoxItem is represented by that custom component It has to forward that events and selection and other things like it should… That is what custom component was missing, But i finally figured it out that how it all work,

ListBox->SelectItemBasedOnModifierKey(row, e.mods) need to be called with proper Boolean tests. Thanks for your reply.
Also I mentioned Complete problem here . . .http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=8129 . . . and solution too which worked for me.

Also According to selected components in ListBox DragImage is built and implemented startDragAndDrop Method to customize DragDrop also. It all work fine now. :slight_smile:

Have Fun.
AnC

Going to go out on a limb here and say both ListBox, and TableListBox need a MAJOR OVERHAUL.

Can’t argue with that, there’s some pretty old code in those classes.

I would like to see ListBox and TableListBox combined into a single abstract class, where ListBox is just a special case of TableListBox with one column (and the header optionally hidden).

Furthermore, there should be a stock Juce TableListBox, but also a native listbox. Specifically, it would be nice to see a TableListBox for iOS that uses UITableListView (or whatever it is called). This would grant all of the correct behaviors for devices. I imagine something similar could be done for android.

I would like to see ListBox and TableListBox combined into a single abstract class, where ListBox is just a special case of TableListBox with one column (and the header optionally hidden).

Furthermore, there should be a stock Juce TableListBox, but also a native listbox. Specifically, it would be nice to see a TableListBox for iOS that uses UITableListView (or whatever it is called). This would grant all of the correct behaviors for devices. I imagine something similar could be done for android.[/quote]

Amen !

We talked about this in the #Juce IRC channel…it should be easy enough to just make a new set of classes, keep the old one for compatibility, and try to keep the TableListBoxModel the same so switching is as painless as possible.