Binding for DragAndDrop Window APIs
[platform/core/uifw/dali-csharp-binder.git] / dali-csharp-binder / dali-adaptor / drag-and-drop-wrap.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #define SWIGSTDCALL
19
20 // INCLUDES
21 #include <dali-csharp-binder/common/common.h>
22 #include <dali/devel-api/adaptor-framework/drag-and-drop.h>
23 #include <dali/integration-api/debug.h>
24
25 using namespace Dali;
26
27 /* Callback for returning strings to C# without leaking memory */
28 typedef char * (SWIGSTDCALL* SWIG_CSharpStringHelperCallback)(const char *);
29 extern SWIG_CSharpStringHelperCallback SWIG_csharp_string_callback;
30
31 static char mimeTypeEmptyMsg[] = "Mime Type is Empty!";
32 static char dataEmptyMsg[] = "Data is Empty!";
33 static const char * nullExceptMsg = "Attempt to dereference null Dali::Adaptor::DragAndDrop";
34
35 using DnDCallback = void(SWIGSTDCALL *)(const Dali::DragAndDrop::DragEvent&);
36 DnDCallback dndCallback;
37
38 using SourceCallback = void(SWIGSTDCALL *)(enum Dali::DragAndDrop::SourceEventType);
39 SourceCallback sourceCallback;
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 SWIGEXPORT void *SWIGSTDCALL CSharp_Dali_DragAndDrop_New__SWIG_0() {
46   void *jresult = nullptr;
47   Dali::DragAndDrop result;
48   try {
49       result = Dali::DragAndDrop::Get();
50       jresult = new Dali::DragAndDrop((const Dali::DragAndDrop &)result);
51
52   } CALL_CATCH_EXCEPTION(0);
53
54  return jresult;
55 }
56
57 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_DragAndDrop_StartDragAndDrop(void * argDnD, void * argSource, void * argShadowWindow, void * argMimeType, char * argData, void * argSourceCallback) {
58   Dali::DragAndDrop *dnd = (Dali::DragAndDrop *)argDnD;
59
60   if (!dnd) {
61     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
62     return false;
63   }
64
65   Dali::Actor *pSource;
66   Dali::Window *pShadow;
67   Dali::Actor source;
68   Dali::Window shadow;
69
70   pSource = (Dali::Actor *)argSource;
71   if (!pSource) {
72     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
73     return false;
74   }
75
76   pShadow = (Dali::Window *)argShadowWindow;
77   if (!pShadow) {
78     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
79     return false;
80   }
81
82   source = *pSource;
83   shadow = *pShadow;
84
85   Dali::DragAndDrop::DragData dragData;
86   dragData.SetMimeType((const char*)argMimeType);
87   dragData.SetData(argData);
88
89   bool result = false;
90   {
91     try {
92       sourceCallback = (SourceCallback)argSourceCallback;
93       result = dnd->StartDragAndDrop(source, shadow, dragData, sourceCallback);
94     }
95     CALL_CATCH_EXCEPTION(0);
96   }
97   return result;
98 }
99
100 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_DragAndDrop_AddListener(void * jarg1, void * jarg2, void * jarg3) {
101   Dali::DragAndDrop *dnd = (Dali::DragAndDrop *)jarg1;
102   if (!dnd) {
103     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
104     return false;
105   }
106
107   Dali::Actor *argp2;
108   Dali::Actor target;
109
110   argp2 = (Dali::Actor *)jarg2;
111   if (!argp2) {
112     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
113     return false;
114   }
115
116   target = *argp2;
117   bool result = false;
118   {
119     try {
120       dndCallback = (DnDCallback)jarg3;
121       result = dnd->AddListener(target, dndCallback);
122     }
123     CALL_CATCH_EXCEPTION(0);
124   }
125   return result;
126 }
127
128 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_DragAndDrop_RemoveListener(void * argDnD, void * argTarget, void * argCallback) {
129   Dali::DragAndDrop *dnd = (Dali::DragAndDrop *)argDnD;
130   if (!dnd) {
131     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
132     return false;
133   }
134
135   Dali::Actor *pTarget;
136   Dali::Actor target;
137
138   pTarget = (Dali::Actor *)argTarget;
139   if (!pTarget) {
140     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
141     return false;
142   }
143
144   target = *pTarget;
145   bool result = false;
146   {
147     try {
148       //TODO: use argCallback to remove target listener
149       result = dnd->RemoveListener(target);
150     }
151     CALL_CATCH_EXCEPTION(0);
152   }
153   return result;
154 }
155
156 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_DragAndDrop_Window_AddListener(void * argDnD, void * argTarget, void * argCallback) {
157   Dali::DragAndDrop *dnd = (Dali::DragAndDrop *)argDnD;
158   if (!dnd) {
159     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
160     return false;
161   }
162
163   Dali::Window *pTarget;
164   Dali::Window target;
165
166   pTarget = (Dali::Window *)argTarget;
167   if (!pTarget) {
168     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
169     return false;
170   }
171
172   target = *pTarget;
173   bool result = false;
174   {
175     try {
176       dndCallback = (DnDCallback)argCallback;
177       result = dnd->AddListener(target, dndCallback);
178     }
179     CALL_CATCH_EXCEPTION(0);
180   }
181   return result;
182 }
183
184 SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_DragAndDrop_Window_RemoveListener(void * argDnD, void * argTarget, void * argCallback) {
185   Dali::DragAndDrop *dnd = (Dali::DragAndDrop *)argDnD;
186   if (!dnd) {
187     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
188     return false;
189   }
190
191   Dali::Window *pTarget;
192   Dali::Window target;
193
194   pTarget = (Dali::Window *)argTarget;
195   if (!pTarget) {
196     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
197     return false;
198   }
199
200   target = *pTarget;
201   bool result = false;
202   {
203     try {
204       //TODO: use argCallback to remove target listener
205       result = dnd->RemoveListener(target);
206     }
207     CALL_CATCH_EXCEPTION(0);
208   }
209   return result;
210 }
211
212 SWIGEXPORT int SWIGSTDCALL CSharp_Dali_DragEvent_GetAction(void * jarg) {
213   int jresult;
214   Dali::DragAndDrop::DragEvent *dragEvent = (Dali::DragAndDrop::DragEvent *)jarg;
215
216   if (!dragEvent) {
217     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
218     return 0;
219   }
220   {
221     try {
222       jresult = (int)((Dali::DragAndDrop::DragEvent &)*dragEvent).GetAction();
223     }
224     CALL_CATCH_EXCEPTION(0);
225   }
226
227   return jresult;
228 }
229
230 SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_DragEvent_GetPosition(void * jarg) {
231   void * jresult = nullptr;
232   Dali::DragAndDrop::DragEvent *dragEvent = (Dali::DragAndDrop::DragEvent *)jarg;
233   Dali::Vector2 result;
234
235   if (!dragEvent) {
236     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
237     return 0;
238   }
239   {
240     try {
241       result = ((Dali::DragAndDrop::DragEvent &)*dragEvent).GetPosition();
242     }
243     CALL_CATCH_EXCEPTION(0);
244   }
245
246   jresult = new Dali::Vector2((const Dali::Vector2 &)result);
247   return jresult;
248 }
249
250 SWIGEXPORT char * SWIGSTDCALL CSharp_Dali_DragEvent_GetMimeType(void * argDragEvent) {
251   char * jresult = nullptr;
252   Dali::DragAndDrop::DragEvent *dragEvent = (Dali::DragAndDrop::DragEvent *)argDragEvent;
253   std::string result;
254
255   if (!dragEvent) {
256     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
257     return 0;
258   }
259   {
260     try {
261       const char* mimeType = ((Dali::DragAndDrop::DragEvent &)*dragEvent).GetMimeType();
262       if (mimeType != nullptr)
263       {
264         result = mimeType;
265       }
266       else
267       {
268         result = mimeTypeEmptyMsg;
269       }
270     }
271     CALL_CATCH_EXCEPTION(0);
272   }
273
274   jresult = SWIG_csharp_string_callback((&result)->c_str());
275   return jresult;
276 }
277
278 SWIGEXPORT char * SWIGSTDCALL CSharp_Dali_DragEvent_GetData(void * argDragEvent) {
279   char * jresult = nullptr;
280   Dali::DragAndDrop::DragEvent *dragEvent = (Dali::DragAndDrop::DragEvent *)argDragEvent;
281   std::string result;
282
283   if (!dragEvent) {
284     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, nullExceptMsg, 0);
285     return 0;
286   }
287   {
288     try {
289       const char* data = ((Dali::DragAndDrop::DragEvent &)*dragEvent).GetData();
290       if (data != nullptr)
291       {
292         result = data;
293       }
294       else
295       {
296         result = dataEmptyMsg;
297       }
298     }
299     CALL_CATCH_EXCEPTION(0);
300   }
301
302   jresult = SWIG_csharp_string_callback((&result)->c_str());
303   return jresult;
304 }
305
306 #ifdef __cplusplus
307 } // end extern "C"
308 #endif