[AT-SPI] Override IsProxy in ProxyAccessible
[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/actors/actor.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <functional>
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()
66     {
67       this->mimeType = nullptr;
68       this->data = nullptr;
69     }
70     DragEvent(DragType type, Dali::Vector2 position, const char* mimeType = nullptr, char* data = nullptr)
71     {
72       this->type     = type;
73       this->position = position;
74       this->mimeType = mimeType;
75       this->data     = data;
76     }
77
78     void SetAction(DragType type)
79     {
80       this->type = type;
81     }
82     DragType GetAction()
83     {
84       return type;
85     }
86     void SetPosition(Dali::Vector2 position)
87     {
88       this->position = position;
89     }
90     Dali::Vector2 GetPosition()
91     {
92       return position;
93     }
94     void SetMimeType(const char* mimeType)
95     {
96       this->mimeType = mimeType;
97     }
98     const char* GetMimeType()
99     {
100       return mimeType;
101     }
102     void SetData(char* data)
103     {
104       this->data = data;
105     }
106     char* GetData() const
107     {
108       return data;
109     }
110
111   private:
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.
116   };
117
118   /**
119    * @brief Structure that contains information about the drag data information.
120    */
121   struct DragData
122   {
123      void SetMimeType(const char* mimeType)
124      {
125        this->mimeType = mimeType;
126      }
127      const char* GetMimeType() const
128      {
129        return mimeType;
130      }
131      void SetData(const char* data)
132      {
133        this->data = data;
134      }
135      const char* GetData() const
136      {
137        return data;
138      }
139
140   private:
141      const char* mimeType{nullptr}; ///<The mime type of drag data.
142      const char* data{nullptr};     ///<The drag data.
143   };
144
145   using DragAndDropFunction = std::function<void(const DragEvent&)>;
146
147   /**
148    * @brief Create an uninitialized DragAndDrop.
149    *
150    * this can be initialized with one of the derived DragAndDrop's New() methods
151    */
152   DragAndDrop();
153
154   /**
155    * @brief Destructor.
156    *
157    * This is non-virtual since derived Handle types must not contain data or virtual methods.
158    */
159   ~DragAndDrop();
160
161   /**
162    * @brief This copy constructor is required for (smart) pointer semantics.
163    */
164   DragAndDrop(const DragAndDrop& handle) = default;
165
166   /**
167    * @brief Retrieve a handle to the DragAndDrop instance.
168    *
169    * @return A handle to the DragAndDrop
170    */
171   static DragAndDrop Get();
172
173   /**
174    * @brief Start the drag operation.
175    *
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.
180    */
181   bool StartDragAndDrop(Dali::Actor source, Dali::Actor shadow, const DragData& dragData);
182
183   /**
184    * @brief Add the listener for receiving the drag and drop events.
185    *
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.
189    */
190   bool AddListener(Dali::Actor target, DragAndDropFunction callback);
191
192   /**
193    * @brief Remove the listener.
194    *
195    * @param[in] target The drop target object.
196    * @return bool true if the listener is removed successfully.
197    */
198   bool RemoveListener(Dali::Actor target);
199
200 public:
201   /**
202    * @brief This constructor is used by Adaptor::GetDragAndDrop().
203    *
204    * @param[in] dnd A pointer to the DragAndDrop.
205    */
206   explicit DALI_INTERNAL DragAndDrop(Internal::Adaptor::DragAndDrop* dnd);
207 };
208
209 } // namespace Dali
210
211 #endif // DALI_DRAG_AND_DROP_H