1 #ifndef DALI_DRAG_AND_DROP_H
2 #define DALI_DRAG_AND_DROP_H
5 * Copyright (c) 2022 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/adaptor-framework/window.h>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/object/base-handle.h>
29 #include <dali/public-api/dali-adaptor-common.h>
33 namespace Internal DALI_INTERNAL
39 } // namespace DALI_INTERNAL
42 * @brief Interface to the device's drag and drop.
44 * DragAndDrop class supports the drag and drop functionality for multi-window.
47 class DALI_ADAPTOR_API DragAndDrop : public BaseHandle
51 * @brief Enumeration for the drag source event type in the source object
53 enum class SourceEventType
55 START, ///< Drag and drop is started.
56 CANCEL, ///< Drag and drop is cancelled.
57 ACCEPT, ///< Drag and drop is accepted.
58 FINISH ///< Drag and drop is finished.
62 * @brief Enumeration for the drag event type in the target object
66 ENTER, ///< The drag object has entered the target object.
67 LEAVE, ///< The drag object has left the target object.
68 MOVE, ///< The drag object moves in the target object.
69 DROP ///< The drag object dropped in the target object.
73 * @brief Structure that contains information about the drag event information.
79 this->mimeType = nullptr;
82 DragEvent(DragType type, Dali::Vector2 position, const char* mimeType = nullptr, char* data = nullptr)
85 this->position = position;
86 this->mimeType = mimeType;
90 void SetAction(DragType type)
98 void SetPosition(Dali::Vector2 position)
100 this->position = position;
102 Dali::Vector2 GetPosition()
106 void SetMimeType(const char* mimeType)
108 this->mimeType = mimeType;
110 const char* GetMimeType()
114 void SetData(char* data)
118 char* GetData() const
124 DragType type{DragType::DROP}; ///< The drag event type.
125 Dali::Vector2 position; ///< The position of drag object.
126 const char* mimeType; ///< The mime type of drag object.
127 char* data{nullptr}; ///< The data of drag object.
131 * @brief Structure that contains information about the drag data information.
135 void SetMimeType(const char* mimeType)
137 this->mimeType = mimeType;
139 const char* GetMimeType() const
143 void SetData(const char* data)
147 const char* GetData() const
153 const char* mimeType{nullptr}; ///<The mime type of drag data.
154 const char* data{nullptr}; ///<The drag data.
157 using DragAndDropFunction = std::function<void(const DragEvent&)>;
158 using SourceFunction = std::function<void(enum SourceEventType)>;
161 * @brief Create an uninitialized DragAndDrop.
163 * this can be initialized with one of the derived DragAndDrop's New() methods
170 * This is non-virtual since derived Handle types must not contain data or virtual methods.
175 * @brief This copy constructor is required for (smart) pointer semantics.
177 DragAndDrop(const DragAndDrop& handle) = default;
180 * @brief Retrieve a handle to the DragAndDrop instance.
182 * @return A handle to the DragAndDrop
184 static DragAndDrop Get();
187 * @brief Start the drag operation.
189 * @param[in] source The drag source object.
190 * @param[in] shadowWindow The shadow window for drag object.
191 * @param[in] dragData The data to send to target object.
192 * @param[in] callback The drag source event callback.
193 * @return bool true if the drag operation is started successfully.
195 bool StartDragAndDrop(Dali::Actor source, Dali::Window shadowWindow, const DragData& dragData, Dali::DragAndDrop::SourceFunction callback);
198 * @brief Add the listener for receiving the drag and drop events.
200 * @param[in] target The drop target object.
201 * @param[in] callback A drag and drop event callback.
202 * @return bool true if the listener is added successfully.
204 bool AddListener(Dali::Actor target, DragAndDropFunction callback);
207 * @brief Remove the listener.
209 * @param[in] target The drop target object.
210 * @return bool true if the listener is removed successfully.
212 bool RemoveListener(Dali::Actor target);
216 * @brief This constructor is used by Adaptor::GetDragAndDrop().
218 * @param[in] dnd A pointer to the DragAndDrop.
220 explicit DALI_INTERNAL DragAndDrop(Internal::Adaptor::DragAndDrop* dnd);
225 #endif // DALI_DRAG_AND_DROP_H