1 #ifndef DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H
2 #define DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/object/base-object.h>
30 #include <dali-toolkit/devel-api/drag-drop-detector/drag-and-drop-detector.h>
31 #include <dali/public-api/events/pan-gesture-detector.h>
32 #include <dali/public-api/events/pan-gesture.h>
40 using DragAndDropDetectorPtr = IntrusivePtr<DragAndDropDetector>;
43 * This class listens to Drag & Drop events.
45 class DragAndDropDetector : public Dali::BaseObject, public ConnectionTracker
48 using DragAndDropSignal = Dali::Toolkit::DragAndDropDetector::DragAndDropSignal;
53 * @copydoc Toolkit::DragAndDropDetector::New()
55 static Dali::Toolkit::DragAndDropDetector New();
60 * @copydoc Dali::DragAndDropDetector::GetContent() const
62 const std::string& GetContent() const;
65 * @copydoc Dali::DragAndDropDetector::GetCurrentScreenPosition() const
67 const Vector2& GetCurrentScreenPosition() const;
70 * Attaches control to DragAndDropDetector.
71 * @param[in] control control that will be attached to DragAndDropDetector.
73 void Attach(Dali::Toolkit::Control& control);
76 * Detaches control to DragAndDropDetector.
77 * @param[in] control control that will be Detached from DragAndDropDetector.
79 void Detach(Dali::Toolkit::Control& control);
82 * Detaches all control attached to DragAndDropDetector.
87 * Returns the number of controls attached to the DragAndDropDetector.
89 uint32_t GetAttachedControlCount() const;
92 * Returns a control by index. An empty handle if the index is not valid.
94 Dali::Toolkit::Control GetAttachedControl(uint32_t index) const;
97 * Sets the dragged content.
98 * @param[in] content A string that represents the content that has been dropped.
100 void SetContent(const std::string& content);
103 * Clears the stored content.
108 * Sets the position the drop occurred.
110 void SetPosition(const Vector2& screenPosition);
113 * Called when a draggable object start drag.
115 void EmitStartedSignal(Dali::Toolkit::Control& control);
118 * Called when a draggable object enters other object.
120 void EmitEnteredSignal(Dali::Toolkit::Control& control);
123 * Called when a draggable object leaves other object.
125 void EmitExitedSignal(Dali::Toolkit::Control& control);
128 * Called when a draggable object leaves other object.
130 void EmitMovedSignal(Dali::Toolkit::Control& control);
133 * Is called when a drop actually occurs.
135 void EmitDroppedSignal(Dali::Toolkit::Control& control);
138 * Called when a draggable object drag ended.
140 void EmitEndedSignal(Dali::Toolkit::Control& control);
144 * @copydoc Dali::Toolkit::DragAndDropDetector::StartedSignal
146 DragAndDropSignal& StartedSignal()
148 return mStartedSignal;
152 * @copydoc Dali::Toolkit::DragAndDropDetector::EnteredSignal
154 DragAndDropSignal& EnteredSignal()
156 return mEnteredSignal;
160 * @copydoc Dali::Toolkit::DragAndDropDetector::ExitedSignal
162 DragAndDropSignal& ExitedSignal()
164 return mExitedSignal;
168 * @copydoc Dali::Toolkit::DragAndDropDetector::MovedSignal
170 DragAndDropSignal& MovedSignal()
176 * @copydoc Dali::Toolkit::DragAndDropDetector::DroppedSignal
178 DragAndDropSignal& DroppedSignal()
180 return mDroppedSignal;
184 * @copydoc Dali::Toolkit::DragAndDropDetector::DroppedSignal
186 DragAndDropSignal& EndedSignal()
192 bool OnDrag(Dali::Actor actor, const Dali::TouchEvent& data);
193 void OnPan(Dali::Actor actor, const PanGesture& gesture);
196 // Construction & Destruction
201 DragAndDropDetector();
206 virtual ~DragAndDropDetector();
209 DragAndDropDetector(const DragAndDropDetector&) = delete;
210 DragAndDropDetector& operator =(DragAndDropDetector&);
213 std::string mContent; ///< The current Drag & drop content.
215 DragAndDropSignal mStartedSignal;
216 DragAndDropSignal mEnteredSignal;
217 DragAndDropSignal mExitedSignal;
218 DragAndDropSignal mMovedSignal;
219 DragAndDropSignal mDroppedSignal;
220 DragAndDropSignal mEndedSignal;
222 std::vector<Dali::Toolkit::Control> mControls; //controls attached by Attach interface for drag&drop
223 Dali::Toolkit::Control mDragControl; //the current drag control
224 Dali::Toolkit::Control mShadowControl; //a shadow control for indicating where the control is, same size as the dragged control
225 std::vector<uint32_t> mFirstEnter; //control id indicating if the cursor is enter
226 Dali::PanGestureDetector mPanGestureDetector; //pangesture for calculating the shadow actor position
228 Vector2 mLocalPosition;
229 Vector2 mDragLocalPosition;
230 Vector2 mScreenPosition; ///< The screen position of the drop location.
232 bool mPointDown; //bool flag to indicate if PointState::DOWN have been processed
235 } // namespace Internal
237 // Helpers for public-api forwarding methods
239 inline Internal::DragAndDropDetector& GetImplementation(Dali::Toolkit::DragAndDropDetector& detector)
241 DALI_ASSERT_ALWAYS(detector && "DragAndDropDetector handle is empty");
243 BaseObject& handle = detector.GetBaseObject();
245 return static_cast<Internal::DragAndDropDetector&>(handle);
248 inline const Internal::DragAndDropDetector& GetImplementation(const Dali::Toolkit::DragAndDropDetector& detector)
250 DALI_ASSERT_ALWAYS(detector && "DragAndDropDetector handle is empty");
252 const BaseObject& handle = detector.GetBaseObject();
254 return static_cast<const Internal::DragAndDropDetector&>(handle);
257 } // namespace Toolkit
261 #endif // DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H