From b7beb421535e743dbcb717fadb42218dd16bb38d Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 16 Feb 2023 15:16:29 +0000 Subject: [PATCH] DragAndDropContainer: Avoid out-parameters --- .../mouse/juce_DragAndDropContainer.cpp | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp index d2b5bb268f..e4911ac1bc 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp @@ -98,12 +98,12 @@ public: // (note: use a local copy of this in case the callback runs // a modal loop and deletes this object before the method completes) auto details = sourceDetails; - DragAndDropTarget* finalTarget = nullptr; auto wasVisible = isVisible(); setVisible (false); - Component* unused; - finalTarget = findTarget (e.getScreenPosition(), details.localPosition, unused); + const auto [finalTarget, unused, localPosition] = findTarget (e.getScreenPosition()); + ignoreUnused (unused); + details.localPosition = localPosition; if (wasVisible) // fade the component and remove it - it'll be deleted later by the timer callback dismissWithAnimation (finalTarget == nullptr); @@ -133,8 +133,8 @@ public: setNewScreenPos (screenPos); - Component* newTargetComp; - auto* newTarget = findTarget (screenPos, details.localPosition, newTargetComp); + const auto [newTarget, newTargetComp, localPosition] = findTarget (screenPos); + details.localPosition = localPosition; setVisible (newTarget == nullptr || newTarget->shouldDrawDragImageWhenOver()); @@ -288,8 +288,7 @@ private: return getLocalPoint (sourceComponent, offsetInSource) - getLocalPoint (sourceComponent, Point()); } - DragAndDropTarget* findTarget (Point screenPos, Point& relativePos, - Component*& resultComponent) const + std::tuple> findTarget (Point screenPos) const { auto* hit = getParentComponent(); @@ -305,20 +304,13 @@ private: while (hit != nullptr) { if (auto* ddt = dynamic_cast (hit)) - { if (ddt->isInterestedInDragSource (details)) - { - relativePos = hit->getLocalPoint (nullptr, screenPos); - resultComponent = hit; - return ddt; - } - } + return std::tuple (ddt, hit, hit->getLocalPoint (nullptr, screenPos)); hit = hit->getParentComponent(); } - resultComponent = nullptr; - return nullptr; + return {}; } void setNewScreenPos (Point screenPos)