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/actors/actor.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/object/base-handle.h>
28 #include <dali/public-api/dali-adaptor-common.h>
32 namespace Internal DALI_INTERNAL
38 } // namespace DALI_INTERNAL
41 * @brief Interface to the device's drag and drop.
43 * DragAndDrop class supports the drag and drop functionality for multi-window.
46 class DALI_ADAPTOR_API DragAndDrop : public BaseHandle
50 * @brief Enumeration for the drag event type in the target object
54 ENTER, ///< The drag object has entered the target object.
55 LEAVE, ///< The drag object has left the target object.
56 MOVE, ///< The drag object moves in the target object.
57 DROP ///< The drag object dropped in the target object.
61 * @brief Structure that contains information about the drag event information.
67 this->mimeType = nullptr;
70 DragEvent(DragType type, Dali::Vector2 position, const char* mimeType = nullptr, char* data = nullptr)
73 this->position = position;
74 this->mimeType = mimeType;
78 void SetAction(DragType type)
86 void SetPosition(Dali::Vector2 position)
88 this->position = position;
90 Dali::Vector2 GetPosition()
94 void SetMimeType(const char* mimeType)
96 this->mimeType = mimeType;
98 const char* GetMimeType()
102 void SetData(char* data)
106 char* GetData() const
112 DragType type{DragType::DROP}; ///< The drag event type.
113 Dali::Vector2 position; ///< The position of drag object.
114 const char* mimeType; ///< The mime type of drag object.
115 char* data{nullptr}; ///< The data of drag object.
119 * @brief Structure that contains information about the drag data information.
123 void SetMimeType(const char* mimeType)
125 this->mimeType = mimeType;
127 const char* GetMimeType() const
131 void SetData(const char* data)
135 const char* GetData() const
141 const char* mimeType{nullptr}; ///<The mime type of drag data.
142 const char* data{nullptr}; ///<The drag data.
145 using DragAndDropFunction = std::function<void(const DragEvent&)>;
148 * @brief Create an uninitialized DragAndDrop.
150 * this can be initialized with one of the derived DragAndDrop's New() methods
157 * This is non-virtual since derived Handle types must not contain data or virtual methods.
162 * @brief This copy constructor is required for (smart) pointer semantics.
164 DragAndDrop(const DragAndDrop& handle) = default;
167 * @brief Retrieve a handle to the DragAndDrop instance.
169 * @return A handle to the DragAndDrop
171 static DragAndDrop Get();
174 * @brief Start the drag operation.
176 * @param[in] source The drag source object.
177 * @param[in] shadow The shadow object for drag object.
178 * @param[in] dragData The data to send to target object.
179 * @return bool true if the drag operation is started successfully.
181 bool StartDragAndDrop(Dali::Actor source, Dali::Actor shadow, const DragData& dragData);
184 * @brief Add the listener for receiving the drag and drop events.
186 * @param[in] target The drop target object.
187 * @param[in] callback A drag and drop event callback.
188 * @return bool true if the listener is added successfully.
190 bool AddListener(Dali::Actor target, DragAndDropFunction callback);
193 * @brief Remove the listener.
195 * @param[in] target The drop target object.
196 * @return bool true if the listener is removed successfully.
198 bool RemoveListener(Dali::Actor target);
202 * @brief This constructor is used by Adaptor::GetDragAndDrop().
204 * @param[in] dnd A pointer to the DragAndDrop.
206 explicit DALI_INTERNAL DragAndDrop(Internal::Adaptor::DragAndDrop* dnd);
211 #endif // DALI_DRAG_AND_DROP_H