1 #ifndef DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H
2 #define DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H
5 * Copyright (c) 2019 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/object/base-object.h>
27 #include <dali/public-api/math/vector2.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>
43 using DragAndDropDetectorPtr = IntrusivePtr< DragAndDropDetector >;
46 * This class listens to Drag & Drop events.
48 class DragAndDropDetector : public Dali::BaseObject, public ConnectionTracker
52 using DragAndDropSignal = Dali::Toolkit::DragAndDropDetector::DragAndDropSignal;
57 * @copydoc Toolkit::DragAndDropDetector::New()
59 static Dali::Toolkit::DragAndDropDetector New();
64 * @copydoc Dali::DragAndDropDetector::GetContent() const
66 const std::string& GetContent() const;
69 * @copydoc Dali::DragAndDropDetector::GetCurrentScreenPosition() const
71 const Vector2& GetCurrentScreenPosition() const;
74 * Attaches control to DragAndDropDetector.
75 * @param[in] control control that will be attached to DragAndDropDetector.
77 void Attach(Dali::Toolkit::Control& control);
80 * Detaches control to DragAndDropDetector.
81 * @param[in] control control that will be Detached from DragAndDropDetector.
83 void Detach(Dali::Toolkit::Control& control);
86 * Detaches all control attached to DragAndDropDetector.
91 * Returns the number of controls attached to the DragAndDropDetector.
93 uint32_t GetAttachedControlCount() const;
96 * Returns a control by index. An empty handle if the index is not valid.
98 Dali::Toolkit::Control GetAttachedControl(uint32_t index) const;
101 * Sets the dragged content.
102 * @param[in] content A string that represents the content that has been dropped.
104 void SetContent( const std::string& content );
107 * Clears the stored content.
112 * Sets the position the drop occurred.
114 void SetPosition( const Vector2& screenPosition );
117 * Called when a draggable object start drag.
119 void EmitStartedSignal(Dali::Toolkit::Control& control);
122 * Called when a draggable object enters other object.
124 void EmitEnteredSignal(Dali::Toolkit::Control& control);
127 * Called when a draggable object leaves other object.
129 void EmitExitedSignal(Dali::Toolkit::Control& control);
132 * Called when a draggable object leaves other object.
134 void EmitMovedSignal(Dali::Toolkit::Control& control);
137 * Is called when a drop actually occurs.
139 void EmitDroppedSignal(Dali::Toolkit::Control& control);
142 * Called when a draggable object drag ended.
144 void EmitEndedSignal(Dali::Toolkit::Control& control);
149 * @copydoc Dali::Toolkit::DragAndDropDetector::StartedSignal
151 DragAndDropSignal& StartedSignal()
153 return mStartedSignal;
157 * @copydoc Dali::Toolkit::DragAndDropDetector::EnteredSignal
159 DragAndDropSignal& EnteredSignal()
161 return mEnteredSignal;
165 * @copydoc Dali::Toolkit::DragAndDropDetector::ExitedSignal
167 DragAndDropSignal& ExitedSignal()
169 return mExitedSignal;
173 * @copydoc Dali::Toolkit::DragAndDropDetector::MovedSignal
175 DragAndDropSignal& MovedSignal()
181 * @copydoc Dali::Toolkit::DragAndDropDetector::DroppedSignal
183 DragAndDropSignal& DroppedSignal()
185 return mDroppedSignal;
189 * @copydoc Dali::Toolkit::DragAndDropDetector::DroppedSignal
191 DragAndDropSignal& EndedSignal()
197 bool OnDrag(Dali::Actor actor, const Dali::TouchData& data);
198 void OnPan(Dali::Actor actor, const PanGesture& gesture);
202 // Construction & Destruction
207 DragAndDropDetector();
212 virtual ~DragAndDropDetector();
215 DragAndDropDetector( const DragAndDropDetector& ) = delete;
216 DragAndDropDetector& operator=( DragAndDropDetector& );
220 std::string mContent; ///< The current Drag & drop content.
222 DragAndDropSignal mStartedSignal;
223 DragAndDropSignal mEnteredSignal;
224 DragAndDropSignal mExitedSignal;
225 DragAndDropSignal mMovedSignal;
226 DragAndDropSignal mDroppedSignal;
227 DragAndDropSignal mEndedSignal;
229 std::vector<Dali::Toolkit::Control> mControls; //controls attached by Attach interface for drag&drop
230 Dali::Toolkit::Control mDragControl; //the current drag control
231 Dali::Toolkit::Control mShadowControl; //a shadow control for indicating where the control is, same size as the dragged control
232 std::vector<uint32_t> mFirstEnter; //control id indicating if the cursor is enter
233 Dali::PanGestureDetector mPanGestureDetector; //pangesture for calculating the shadow actor position
235 Vector2 mLocalPosition;
236 Vector2 mDragLocalPosition;
237 Vector2 mScreenPosition; ///< The screen position of the drop location.
239 bool mPointDown; //bool flag to indicate if PointState::DOWN have been processed
242 } // namespace Internal
245 // Helpers for public-api forwarding methods
247 inline Internal::DragAndDropDetector& GetImplementation(Dali::Toolkit::DragAndDropDetector& detector)
249 DALI_ASSERT_ALWAYS( detector && "DragAndDropDetector handle is empty" );
251 BaseObject& handle = detector.GetBaseObject();
253 return static_cast<Internal::DragAndDropDetector&>(handle);
256 inline const Internal::DragAndDropDetector& GetImplementation(const Dali::Toolkit::DragAndDropDetector& detector)
258 DALI_ASSERT_ALWAYS( detector && "DragAndDropDetector handle is empty" );
260 const BaseObject& handle = detector.GetBaseObject();
262 return static_cast<const Internal::DragAndDropDetector&>(handle);
265 } // namespace Toolkit
269 #endif // DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H