From b2f318a775ec2b9fbcaf2f7a90b75c9912dc2dce Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 19 Jan 2022 13:44:11 +0000 Subject: [PATCH] TreeView: Allow built-in mouse handling to be enabled/disabled for custom components --- modules/juce_gui_basics/widgets/juce_TreeView.cpp | 2 +- modules/juce_gui_basics/widgets/juce_TreeView.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.cpp b/modules/juce_gui_basics/widgets/juce_TreeView.cpp index 113bdcb2a2..b4ad49007b 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.cpp +++ b/modules/juce_gui_basics/widgets/juce_TreeView.cpp @@ -344,7 +344,7 @@ public: auto newComp = std::make_unique (*treeItem); addAndMakeVisible (*newComp); - newComp->addMouseListener (this, false); + newComp->addMouseListener (this, treeItem->customComponentUsesTreeViewMouseHandler()); componentsToKeep.insert (newComp.get()); itemComponents.push_back (std::move (newComp)); diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.h b/modules/juce_gui_basics/widgets/juce_TreeView.h index aa4547bbe6..85f57fc753 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.h +++ b/modules/juce_gui_basics/widgets/juce_TreeView.h @@ -363,6 +363,13 @@ public: /** Draws the line that extends vertically up towards one of its parents, or down to one of its children. */ virtual void paintVerticalConnectingLine (Graphics&, const Line& line); + /** This should return true if you want to use a custom component, and also use + the TreeView's built-in mouse handling support, enabling drag-and-drop, + itemClicked() and itemDoubleClicked(); return false if the component should + consume all mouse clicks. + */ + virtual bool customComponentUsesTreeViewMouseHandler() const { return false; } + /** Called when the user clicks on this item. If you're using createItemComponent() to create a custom component for the