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.
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/actors/actor.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.
65 DragEvent() { this->data = nullptr; }
66 DragEvent(DragType type, Dali::Vector2 position, char* data = nullptr)
69 this->position = position;
73 void SetAction(DragType type) { this->type = type; }
74 DragType GetAction() { return type; }
75 void SetPosition(Dali::Vector2 position) { this->position = position; }
76 Dali::Vector2 GetPosition() { return position; }
77 void SetData(char* data) { this->data = data; }
78 char* GetData() { return data; }
81 DragType type; ///< The drag event type.
82 Dali::Vector2 position; ///< The position of drag object.
83 char* data; ///< The data of drag object.
86 using DragAndDropFunction = std::function<void(const DragEvent&)>;
89 * @brief Create an uninitialized DragAndDrop.
91 * this can be initialized with one of the derived DragAndDrop's New() methods
98 * This is non-virtual since derived Handle types must not contain data or virtual methods.
103 * @brief This copy constructor is required for (smart) pointer semantics.
105 DragAndDrop(const DragAndDrop& handle) = default;
108 * @brief Retrieve a handle to the DragAndDrop instance.
110 * @return A handle to the DragAndDrop
112 static DragAndDrop Get();
115 * @brief Start the drag operation.
117 * @param[in] source The drag source object.
118 * @param[in] shadow The shadow object for drag object.
119 * @param[in] dragData The data to send to target object.
120 * @return bool true if the drag operation is started successfully.
122 bool StartDragAndDrop(Dali::Actor source, Dali::Actor shadow, const std::string& dragData);
125 * @brief Add the listener for receiving the drag and drop events.
127 * @param[in] target The drop target object.
128 * @param[in] callback A drag and drop event callback.
129 * @return bool true if the listener is added successfully.
131 bool AddListener(Dali::Actor target, DragAndDropFunction callback);
135 * @brief This constructor is used by Adaptor::GetDragAndDrop().
137 * @param[in] dnd A pointer to the DragAndDrop.
139 explicit DALI_INTERNAL DragAndDrop(Internal::Adaptor::DragAndDrop* dnd);
144 #endif // DALI_DRAG_AND_DROP_H