Merge "DALi Version 2.1.10" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / drag-and-drop.h
1 #ifndef DALI_DRAG_AND_DROP_H
2 #define DALI_DRAG_AND_DROP_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <functional>
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>
26
27 // INTERNAL INCLUDES
28 #include <dali/public-api/dali-adaptor-common.h>
29
30 namespace Dali
31 {
32 namespace Internal DALI_INTERNAL
33 {
34 namespace Adaptor
35 {
36 class DragAndDrop;
37 }
38 } // namespace DALI_INTERNAL
39
40 /**
41  * @brief Interface to the device's drag and drop.
42  *
43  * DragAndDrop class supports the drag and drop functionality for multi-window.
44  */
45
46 class DALI_ADAPTOR_API DragAndDrop : public BaseHandle
47 {
48 public:
49   /**
50    * @brief Enumeration for the drag event type in the target object
51    */
52   enum class DragType
53   {
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.
58   };
59
60   /**
61    * @brief Structure that contains information about the drag event information.
62    */
63   struct DragEvent
64   {
65     DragEvent() { this->data = nullptr; }
66     DragEvent(DragType type, Dali::Vector2 position, char* data = nullptr)
67     {
68       this->type = type;
69       this->position = position;
70       this->data = data;
71     }
72
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; }
79
80   private:
81     DragType type; ///< The drag event type.
82     Dali::Vector2 position; ///< The position of drag object.
83     char* data; ///< The data of drag object.
84   };
85
86   using DragAndDropFunction      = std::function<void(const DragEvent&)>;
87
88   /**
89    * @brief Create an uninitialized DragAndDrop.
90    *
91    * this can be initialized with one of the derived DragAndDrop's New() methods
92    */
93   DragAndDrop();
94
95   /**
96    * @brief Destructor.
97    *
98    * This is non-virtual since derived Handle types must not contain data or virtual methods.
99    */
100   ~DragAndDrop();
101
102   /**
103    * @brief This copy constructor is required for (smart) pointer semantics.
104    */
105   DragAndDrop(const DragAndDrop& handle) = default;
106
107   /**
108    * @brief Retrieve a handle to the DragAndDrop instance.
109    *
110    * @return A handle to the DragAndDrop
111    */
112   static DragAndDrop Get();
113
114   /**
115    * @brief Start the drag operation.
116    *
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.
121    */
122   bool StartDragAndDrop(Dali::Actor source, Dali::Actor shadow, const std::string& dragData);
123
124   /**
125    * @brief Add the listener for receiving the drag and drop events.
126    *
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.
130    */
131   bool AddListener(Dali::Actor target, DragAndDropFunction callback);
132
133 public:
134   /**
135    * @brief This constructor is used by Adaptor::GetDragAndDrop().
136    *
137    * @param[in] dnd A pointer to the DragAndDrop.
138    */
139   explicit DALI_INTERNAL DragAndDrop(Internal::Adaptor::DragAndDrop* dnd);
140 };
141
142 } // namespace Dali
143
144 #endif // DALI_DRAG_AND_DROP_H