[dali_2.3.25] Merge branch '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 <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>
26 #include <functional>
27
28 // INTERNAL INCLUDES
29 #include <dali/public-api/dali-adaptor-common.h>
30
31 namespace Dali
32 {
33 namespace Internal DALI_INTERNAL
34 {
35 namespace Adaptor
36 {
37 class DragAndDrop;
38 }
39 } // namespace DALI_INTERNAL
40
41 /**
42  * @brief Interface to the device's drag and drop.
43  *
44  * DragAndDrop class supports the drag and drop functionality for multi-window.
45  */
46
47 class DALI_ADAPTOR_API DragAndDrop : public BaseHandle
48 {
49 public:
50   /**
51    * @brief Enumeration for the drag source event type in the source object
52    */
53   enum class SourceEventType
54   {
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.
59   };
60
61   /**
62    * @brief Enumeration for the drag event type in the target object
63    */
64   enum class DragType
65   {
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.
70   };
71
72   /**
73    * @brief Structure that contains information about the drag event information.
74    */
75   struct DragEvent
76   {
77     DragEvent()
78     {
79       this->mimeType = nullptr;
80       this->data = nullptr;
81     }
82     DragEvent(DragType type, Dali::Vector2 position, const char* mimeType = nullptr, char* data = nullptr)
83     {
84       this->type     = type;
85       this->position = position;
86       this->mimeType = mimeType;
87       this->data     = data;
88     }
89
90     void SetAction(DragType type)
91     {
92       this->type = type;
93     }
94     DragType GetAction()
95     {
96       return type;
97     }
98     void SetPosition(Dali::Vector2 position)
99     {
100       this->position = position;
101     }
102     Dali::Vector2 GetPosition()
103     {
104       return position;
105     }
106     void SetMimeType(const char* mimeType)
107     {
108       this->mimeType = mimeType;
109     }
110     const char* GetMimeType()
111     {
112       return mimeType;
113     }
114     void SetData(char* data)
115     {
116       this->data = data;
117     }
118     char* GetData() const
119     {
120       return data;
121     }
122
123   private:
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.
128   };
129
130   /**
131    * @brief Structure that contains information about the drag data information.
132    */
133   struct DragData
134   {
135      void SetMimeType(const char* mimeType)
136      {
137        this->mimeType = mimeType;
138      }
139      const char* GetMimeType() const
140      {
141        return mimeType;
142      }
143      void SetData(const char* data)
144      {
145        this->data = data;
146      }
147      const char* GetData() const
148      {
149        return data;
150      }
151
152   private:
153      const char* mimeType{nullptr}; ///<The mime type of drag data.
154      const char* data{nullptr};     ///<The drag data.
155   };
156
157   using DragAndDropFunction = std::function<void(const DragEvent&)>;
158   using SourceFunction = std::function<void(enum SourceEventType)>;
159
160   /**
161    * @brief Create an uninitialized DragAndDrop.
162    *
163    * this can be initialized with one of the derived DragAndDrop's New() methods
164    */
165   DragAndDrop();
166
167   /**
168    * @brief Destructor.
169    *
170    * This is non-virtual since derived Handle types must not contain data or virtual methods.
171    */
172   ~DragAndDrop();
173
174   /**
175    * @brief This copy constructor is required for (smart) pointer semantics.
176    */
177   DragAndDrop(const DragAndDrop& handle) = default;
178
179   /**
180    * @brief Retrieve a handle to the DragAndDrop instance.
181    *
182    * @return A handle to the DragAndDrop
183    */
184   static DragAndDrop Get();
185
186   /**
187    * @brief Start the drag operation.
188    *
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.
194    */
195   bool StartDragAndDrop(Dali::Actor source, Dali::Window shadowWindow, const DragData& dragData, Dali::DragAndDrop::SourceFunction callback);
196
197   /**
198    * @brief Add the listener for receiving the drag and drop events.
199    *
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.
203    */
204   bool AddListener(Dali::Actor target, DragAndDropFunction callback);
205
206   /**
207    * @brief Remove the listener.
208    *
209    * @param[in] target The drop target object.
210    * @return bool true if the listener is removed successfully.
211    */
212   bool RemoveListener(Dali::Actor target);
213
214   /**
215    * @brief Add the listener for receiving the drag and drop events.
216    *
217    * @param[in] target The drop target object.
218    * @param[in] callback A drag and drop event callback.
219    * @return bool true if the listener is added successfully.
220    */
221   bool AddListener(Dali::Window target, DragAndDropFunction callback);
222
223   /**
224    * @brief Remove the listener.
225    *
226    * @param[in] target The drop target object.
227    * @return bool true if the listener is removed successfully.
228    */
229   bool RemoveListener(Dali::Window target);
230
231 public:
232   /**
233    * @brief This constructor is used by Adaptor::GetDragAndDrop().
234    *
235    * @param[in] dnd A pointer to the DragAndDrop.
236    */
237   explicit DALI_INTERNAL DragAndDrop(Internal::Adaptor::DragAndDrop* dnd);
238 };
239
240 } // namespace Dali
241
242 #endif // DALI_DRAG_AND_DROP_H