1 #ifndef __DALI_DRAG_AND_DROP_DETECTOR_H__
2 #define __DALI_DRAG_AND_DROP_DETECTOR_H__
5 * Copyright (c) 2018 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.
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/signals/dali-signal.h>
27 #include <dali-toolkit/public-api/dali-toolkit-common.h>
29 #include <dali-toolkit/public-api/controls/control.h>
37 namespace Internal DALI_INTERNAL
39 class DragAndDropDetector;
43 * @brief The DragAndDropDetector%s provides signals when draggable objects are dragged into other object.
45 * It provides signals for when the draggable object start drag, draggable object enters other object, moves around in other object,
46 * leaves other object, dropped into other object and finally when the drag ended.
48 * The basic usage is shown below:
54 * DragAndDropDetector detector = DragAndDropDetector::New();
56 * // Get notifications when the draggable item start drag
57 * detector.StartedSignal().Connect( &OnStarted );
59 * // Get notifications when the draggable item enters other item
60 * detector.EnteredSignal().Connect( &OnEntered );
62 * // Get notifications when the draggable item leaves other item
63 * detector.ExitedSignal().Connect( &OnExited );
65 * // Get notifications when the draggable item is moved within other item
66 * detector.MovedSignal().Connect( &OnMoved );
68 * // Get notifications when the draggable item is dropped
69 * detector.DroppedSignal().Connect( &OnDropped );
71 * // Get notifications when the draggable object drag ended
72 * detector.EndedSignal().Connect( &OnEnded );
75 * void OnStarted( Control control, DragAndDropDetector detector )
77 * // Query the new values
78 * std::cout << "Position = " << detector.GetCurrentScreenPosition() << std::endl;
81 * void OnEntered( Control control, DragAndDropDetector detector )
83 * // Change mode as required
86 * void OnExited( Control control, DragAndDropDetector detector )
88 * // Change mode as required
91 * void OnMoved( Control control, DragAndDropDetector detector )
93 * // Query the new values
94 * std::cout << "Position = " << detector.GetCurrentScreenPosition() << std::endl;
97 * void OnDropped( Control control, DragAndDropDetector detector )
99 * // Query the new values
100 * std::cout << "Position = " << detector.GetCurrentScreenPosition() << ", Content = " << detector.GetContent() << std::endl;
103 * void OnEnded( Control control, DragAndDropDetector detector )
105 * // Change mode as required
110 class DALI_TOOLKIT_API DragAndDropDetector : public BaseHandle
116 using DragAndDropSignal = Signal< void ( Control, DragAndDropDetector ) >; ///< Drag & Drop signal
119 * @brief Create an initialized DragAndDropDetector.
121 * @return A handle to a newly allocated Dali DragAndDropDetector
123 static DragAndDropDetector New();
126 * @brief Create an uninitialized handle.
128 * This can be initialized with DragAndDropDetector::New().
130 DragAndDropDetector();
135 * This is non-virtual since derived Handle types must not contain data or virtual methods.
137 ~DragAndDropDetector();
140 * @brief Returns the dropped content.
142 * @return A reference to the string representing the dropped content.
144 const std::string& GetContent() const;
147 * @brief Attaches a Control to the detector.
149 * @note You can attach several controls to a DragAndDropDetector.
150 * DragAndDropDetector will keep a handle to the control and keep it alive as long as
151 * DragAndDropDetector is deleted or Detach is called.
153 void Attach(Control control);
156 * @brief Detaches the attached control from the detector.
158 * @pre The specified control has been attached to the DragAndDropDetector.
160 void Detach(Control control);
163 * @brief Detaches all attached control from the detector.
165 * @pre At least one control has been attached to the DragAndDropDetector.
170 * @brief Returns the number of controls attached to the DragAndDropDetector.
172 * @pre The DragAndDropDetector has been initialized.
174 uint32_t GetAttachedControlCount() const;
177 * @brief Returns a control by index. An empty handle if the index is not valid.
179 * @pre The DragAndDropDetector has been initialized.
181 Control GetAttachedControl(uint32_t index) const;
184 * @brief Returns the current position of the dragged object.
186 * This is the dropped position when an object is dropped.
187 * @return The current screen position.
189 const Vector2& GetCurrentScreenPosition() const;
193 * @brief This is emitted when a dragged object start drag.
195 * A callback of the following type may be connected:
197 * void YourCallback( Control control, DragAndDropDetector detector );
199 * @return The signal to connect to.
201 DragAndDropSignal& StartedSignal();
204 * @brief This is emitted when a dragged object enters other object.
206 * A callback of the following type may be connected:
208 * void YourCallback( Control control, DragAndDropDetector detector );
210 * @return The signal to connect to.
212 DragAndDropSignal& EnteredSignal();
215 * @brief This is emitted when a dragged object leaves other object.
217 * A callback of the following type may be connected:
219 * void YourCallback( Control control, DragAndDropDetector detector );
221 * @return The signal to connect to.
223 DragAndDropSignal& ExitedSignal();
226 * @brief This is emitted when a dragged object is moved within other object.
228 * A callback of the following type may be connected:
230 * void YourCallback( Control control, DragAndDropDetector detector );
232 * @return The signal to connect to.
234 DragAndDropSignal& MovedSignal();
237 * @brief This is emitted when a dragged object is dropped within other object.
239 * A callback of the following type may be connected:
241 * void YourCallback( Control control, DragAndDropDetector detector );
243 * @return The signal to connect to.
245 DragAndDropSignal& DroppedSignal();
248 * @brief This is emitted when a dragged object drag ended.
250 * A callback of the following type may be connected:
252 * void YourCallback( Control control, DragAndDropDetector detector );
254 * @return The signal to connect to.
256 DragAndDropSignal& EndedSignal();
258 public: // Not intended for application developers
261 * @brief This constructor is used by DragAndDropDetector::Get().
263 * @param[in] detector A pointer to the drag and drop detector.
265 explicit DALI_INTERNAL DragAndDropDetector( Internal::DragAndDropDetector* detector );
268 } // namespace Toolkit
272 #endif // __DALI_DRAG_AND_DROP_DETECTOR_H__