I just upgraded from JUCE 6.0.7 to JUCE 6.1.2.
First of all congratulations on the new release.
But it seems there was added a breaking change to the TreeView class, when you create your own custom TreeViewItems using createItemComponent().
The breaking change is:
The TreeView now adds a mouseListener to the created custom component. It did not do that before. And as a result I can no longer control the mouse behaviour through my custom component. In my case I do NOT want items to get selected on right-click. Before I could do that using my custom component. But because the TreeView now adds a mouseListener, that does no longer work.
Here is the change, which introduced the mouseListener (it was in the Added VoiceOver (macOS) and Narrator (Windows) commit). The screenshot is from the file “juce_TreeView.cpp”:
Would it be possible to make that optional?
I.e. add a function “doNotAddMouseListenerToCustomComponents()” or similar
Then I could decide myself, if I want the TreeView to listen to mouse events on my custom component, or not.
After this fix, the functions TreeViewItem::itemClicked() and TreeViewItem::itemDoubleClicked() are no longer called if a custom component is returned in createItemComponent(). How can I restore/implement that functionality?
If I revert to newComp->addMouseListener (this, true);, the tree works as expected, but then there is a conflict with @alatar’s needs.
what you should do is override “mouseDown” and "mouseDoubleClick"in the custom component you are creating. That way the custom component gets notified, when you click the mouse and you can handle it from there. I.e. you move your mouse handling from the TreeVieItem class to you custom component class.
Thanks for your response. Your solution works indeed. Also, as you pointed out in a different post, I can pass a reference to the TreeViewItem and call itemClicked() and itemDoubleClicked() from my custom component.
However, it is not just the functionality to click on items that gets lost after this change, it is also the ability to drag and drop items, select multiple items according to modifier keys, etc. This functionality is part of the TreeViewItem already, and in my case, it is a behaviour that I expect in any item of a tree (custom component or not). So having to implement it again in my custom item components does not seem very elegant.
Do you have other suggestions of how I can approach this? What I need is a tree like the one in the DemoRunner, but with labels that I can use to edit the text.