Merge "Purge underscored header file barriers" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / drag-drop-detector / drag-and-drop-detector-impl.h
1 #ifndef DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H
2 #define DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23 #include <vector>
24 #include <algorithm>
25
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/public-api/math/vector2.h>
28
29 // INTERNAL INCLUDES
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>
33
34 namespace Dali
35 {
36
37 namespace Toolkit
38 {
39
40 namespace Internal
41 {
42
43 using DragAndDropDetectorPtr = IntrusivePtr< DragAndDropDetector >;
44
45 /**
46  * This class listens to Drag & Drop events.
47  */
48 class DragAndDropDetector : public Dali::BaseObject, public ConnectionTracker
49 {
50 public:
51
52   using DragAndDropSignal = Dali::Toolkit::DragAndDropDetector::DragAndDropSignal;
53
54   // Creation
55
56   /**
57    * @copydoc Toolkit::DragAndDropDetector::New()
58    */
59   static Dali::Toolkit::DragAndDropDetector New();
60
61   // Public API
62
63   /**
64    * @copydoc Dali::DragAndDropDetector::GetContent() const
65    */
66   const std::string& GetContent() const;
67
68   /**
69    * @copydoc Dali::DragAndDropDetector::GetCurrentScreenPosition() const
70    */
71   const Vector2& GetCurrentScreenPosition() const;
72
73   /**
74    * Attaches control to DragAndDropDetector.
75    * @param[in] control  control that will be attached to DragAndDropDetector.
76    */
77   void Attach(Dali::Toolkit::Control& control);
78
79   /**
80    * Detaches control to DragAndDropDetector.
81    * @param[in] control  control that will be Detached from DragAndDropDetector.
82    */
83   void Detach(Dali::Toolkit::Control& control);
84
85   /**
86    * Detaches all control attached to DragAndDropDetector.
87    */
88   void DetachAll();
89
90   /**
91    * Returns the number of controls attached to the DragAndDropDetector.
92    */
93   uint32_t GetAttachedControlCount() const;
94
95   /**
96    * Returns a control by index. An empty handle if the index is not valid.
97    */
98   Dali::Toolkit::Control GetAttachedControl(uint32_t index) const;
99
100   /**
101    * Sets the dragged content.
102    * @param[in] content  A string that represents the content that has been dropped.
103    */
104   void SetContent( const std::string& content );
105
106   /**
107    * Clears the stored content.
108    */
109   void ClearContent();
110
111   /**
112    * Sets the position the drop occurred.
113    */
114   void SetPosition( const Vector2& screenPosition );
115
116   /**
117    * Called when a draggable object start drag.
118    */
119   void EmitStartedSignal(Dali::Toolkit::Control& control);
120
121   /**
122    * Called when a draggable object enters other object.
123    */
124   void EmitEnteredSignal(Dali::Toolkit::Control& control);
125
126   /**
127    * Called when a draggable object leaves other object.
128    */
129   void EmitExitedSignal(Dali::Toolkit::Control& control);
130
131   /**
132    * Called when a draggable object leaves other object.
133    */
134   void EmitMovedSignal(Dali::Toolkit::Control& control);
135
136   /**
137    * Is called when a drop actually occurs.
138    */
139   void EmitDroppedSignal(Dali::Toolkit::Control& control);
140
141   /**
142    * Called when a draggable object drag ended.
143    */
144   void EmitEndedSignal(Dali::Toolkit::Control& control);
145
146 public: // Signals
147
148   /**
149    * @copydoc Dali::Toolkit::DragAndDropDetector::StartedSignal
150    */
151   DragAndDropSignal& StartedSignal()
152   {
153     return mStartedSignal;
154   }
155
156   /**
157    * @copydoc Dali::Toolkit::DragAndDropDetector::EnteredSignal
158    */
159   DragAndDropSignal& EnteredSignal()
160   {
161     return mEnteredSignal;
162   }
163
164   /**
165    * @copydoc Dali::Toolkit::DragAndDropDetector::ExitedSignal
166    */
167   DragAndDropSignal& ExitedSignal()
168   {
169     return mExitedSignal;
170   }
171
172   /**
173    * @copydoc Dali::Toolkit::DragAndDropDetector::MovedSignal
174    */
175   DragAndDropSignal& MovedSignal()
176   {
177     return mMovedSignal;
178   }
179
180   /**
181    * @copydoc Dali::Toolkit::DragAndDropDetector::DroppedSignal
182    */
183   DragAndDropSignal& DroppedSignal()
184   {
185     return mDroppedSignal;
186   }
187
188   /**
189    * @copydoc Dali::Toolkit::DragAndDropDetector::DroppedSignal
190    */
191   DragAndDropSignal& EndedSignal()
192   {
193     return mEndedSignal;
194   }
195
196 public:
197   bool OnDrag(Dali::Actor actor, const Dali::TouchData& data);
198   void OnPan(Dali::Actor actor, const PanGesture& gesture);
199
200 private:
201
202   // Construction & Destruction
203
204   /**
205    * Constructor.
206    */
207   DragAndDropDetector();
208
209   /**
210    * Destructor.
211    */
212   virtual ~DragAndDropDetector();
213
214   // Undefined
215   DragAndDropDetector( const DragAndDropDetector& ) = delete;
216   DragAndDropDetector& operator=( DragAndDropDetector& );
217
218 private:
219
220   std::string mContent;    ///< The current Drag & drop content.
221
222   DragAndDropSignal mStartedSignal;
223   DragAndDropSignal mEnteredSignal;
224   DragAndDropSignal mExitedSignal;
225   DragAndDropSignal mMovedSignal;
226   DragAndDropSignal mDroppedSignal;
227   DragAndDropSignal mEndedSignal;
228
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
234
235   Vector2 mLocalPosition;
236   Vector2 mDragLocalPosition;
237   Vector2 mScreenPosition; ///< The screen position of the drop location.
238
239   bool mPointDown; //bool flag to indicate if PointState::DOWN have been processed
240 };
241
242 } // namespace Internal
243
244
245 // Helpers for public-api forwarding methods
246
247 inline Internal::DragAndDropDetector& GetImplementation(Dali::Toolkit::DragAndDropDetector& detector)
248 {
249   DALI_ASSERT_ALWAYS( detector && "DragAndDropDetector handle is empty" );
250
251   BaseObject& handle = detector.GetBaseObject();
252
253   return static_cast<Internal::DragAndDropDetector&>(handle);
254 }
255
256 inline const Internal::DragAndDropDetector& GetImplementation(const Dali::Toolkit::DragAndDropDetector& detector)
257 {
258   DALI_ASSERT_ALWAYS( detector && "DragAndDropDetector handle is empty" );
259
260   const BaseObject& handle = detector.GetBaseObject();
261
262   return static_cast<const Internal::DragAndDropDetector&>(handle);
263 }
264
265 } // namespace Toolkit
266
267 } // namespace Dali
268
269 #endif // DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H