1 #ifndef DALI_DRAG_AND_DROP_DETECTOR_H
2 #define DALI_DRAG_AND_DROP_DETECTOR_H
5 * Copyright (c) 2020 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.
22 #include <dali/public-api/object/base-handle.h>
23 #include <dali/public-api/signals/dali-signal.h>
26 #include <dali-toolkit/public-api/dali-toolkit-common.h>
28 #include <dali-toolkit/public-api/controls/control.h>
34 namespace Internal DALI_INTERNAL
36 class DragAndDropDetector;
40 * @brief The DragAndDropDetector%s provides signals when draggable objects are dragged into other object.
42 * It provides signals for when the draggable object start drag, draggable object enters other object, moves around in other object,
43 * leaves other object, dropped into other object and finally when the drag ended.
45 * The basic usage is shown below:
51 * DragAndDropDetector detector = DragAndDropDetector::New();
53 * // Get notifications when the draggable item start drag
54 * detector.StartedSignal().Connect( &OnStarted );
56 * // Get notifications when the draggable item enters other item
57 * detector.EnteredSignal().Connect( &OnEntered );
59 * // Get notifications when the draggable item leaves other item
60 * detector.ExitedSignal().Connect( &OnExited );
62 * // Get notifications when the draggable item is moved within other item
63 * detector.MovedSignal().Connect( &OnMoved );
65 * // Get notifications when the draggable item is dropped
66 * detector.DroppedSignal().Connect( &OnDropped );
68 * // Get notifications when the draggable object drag ended
69 * detector.EndedSignal().Connect( &OnEnded );
72 * void OnStarted( Control control, DragAndDropDetector detector )
74 * // Query the new values
75 * std::cout << "Position = " << detector.GetCurrentScreenPosition() << std::endl;
78 * void OnEntered( Control control, DragAndDropDetector detector )
80 * // Change mode as required
83 * void OnExited( Control control, DragAndDropDetector detector )
85 * // Change mode as required
88 * void OnMoved( Control control, DragAndDropDetector detector )
90 * // Query the new values
91 * std::cout << "Position = " << detector.GetCurrentScreenPosition() << std::endl;
94 * void OnDropped( Control control, DragAndDropDetector detector )
96 * // Query the new values
97 * std::cout << "Position = " << detector.GetCurrentScreenPosition() << ", Content = " << detector.GetContent() << std::endl;
100 * void OnEnded( Control control, DragAndDropDetector detector )
102 * // Change mode as required
107 class DALI_TOOLKIT_API DragAndDropDetector : public BaseHandle
112 using DragAndDropSignal = Signal<void(Control, DragAndDropDetector)>; ///< Drag & Drop signal
115 * @brief Create an initialized DragAndDropDetector.
117 * @return A handle to a newly allocated Dali DragAndDropDetector
119 static DragAndDropDetector New();
122 * @brief Create an uninitialized handle.
124 * This can be initialized with DragAndDropDetector::New().
126 DragAndDropDetector();
131 * This is non-virtual since derived Handle types must not contain data or virtual methods.
133 ~DragAndDropDetector();
136 * @brief Returns the dropped content.
138 * @return A reference to the string representing the dropped content.
140 const std::string& GetContent() const;
143 * @brief Attaches a Control to the detector.
145 * @note You can attach several controls to a DragAndDropDetector.
146 * DragAndDropDetector will keep a handle to the control and keep it alive as long as
147 * DragAndDropDetector is deleted or Detach is called.
149 void Attach(Control control);
152 * @brief Detaches the attached control from the detector.
154 * @pre The specified control has been attached to the DragAndDropDetector.
156 void Detach(Control control);
159 * @brief Detaches all attached control from the detector.
161 * @pre At least one control has been attached to the DragAndDropDetector.
166 * @brief Returns the number of controls attached to the DragAndDropDetector.
168 * @pre The DragAndDropDetector has been initialized.
170 uint32_t GetAttachedControlCount() const;
173 * @brief Returns a control by index. An empty handle if the index is not valid.
175 * @pre The DragAndDropDetector has been initialized.
177 Control GetAttachedControl(uint32_t index) const;
180 * @brief Returns the current position of the dragged object.
182 * This is the dropped position when an object is dropped.
183 * @return The current screen position.
185 const Vector2& GetCurrentScreenPosition() const;
189 * @brief This is emitted when a dragged object start drag.
191 * A callback of the following type may be connected:
193 * void YourCallback( Control control, DragAndDropDetector detector );
195 * @return The signal to connect to.
197 DragAndDropSignal& StartedSignal();
200 * @brief This is emitted when a dragged object enters other object.
202 * A callback of the following type may be connected:
204 * void YourCallback( Control control, DragAndDropDetector detector );
206 * @return The signal to connect to.
208 DragAndDropSignal& EnteredSignal();
211 * @brief This is emitted when a dragged object leaves other object.
213 * A callback of the following type may be connected:
215 * void YourCallback( Control control, DragAndDropDetector detector );
217 * @return The signal to connect to.
219 DragAndDropSignal& ExitedSignal();
222 * @brief This is emitted when a dragged object is moved within other object.
224 * A callback of the following type may be connected:
226 * void YourCallback( Control control, DragAndDropDetector detector );
228 * @return The signal to connect to.
230 DragAndDropSignal& MovedSignal();
233 * @brief This is emitted when a dragged object is dropped within other object.
235 * A callback of the following type may be connected:
237 * void YourCallback( Control control, DragAndDropDetector detector );
239 * @return The signal to connect to.
241 DragAndDropSignal& DroppedSignal();
244 * @brief This is emitted when a dragged object drag ended.
246 * A callback of the following type may be connected:
248 * void YourCallback( Control control, DragAndDropDetector detector );
250 * @return The signal to connect to.
252 DragAndDropSignal& EndedSignal();
254 public: // Not intended for application developers
256 * @brief This constructor is used by DragAndDropDetector::Get().
258 * @param[in] detector A pointer to the drag and drop detector.
260 explicit DALI_INTERNAL DragAndDropDetector(Internal::DragAndDropDetector* detector);
263 } // namespace Toolkit
267 #endif // DALI_DRAG_AND_DROP_DETECTOR_H