[dali_2.3.38] Merge branch 'devel/master'
[platform/core/uifw/dali-csharp-binder.git] / dali-csharp-binder / dali-toolkit / internal-visual-property-get-set-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 // EXTERNAL INCLUDES
19 #include <dali/dali.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali-toolkit/devel-api/controls/control-devel.h>
22 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali/integration-api/debug.h>
25 #include <string>
26
27 // INTERNAL INCLUDES
28 #include <dali-csharp-binder/common/common.h>
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34
35   typedef char *(SWIGSTDCALL *SWIG_CSharpStringHelperCallback)(const char *);
36   extern SWIG_CSharpStringHelperCallback SWIG_csharp_string_callback;
37
38   enum InternalPropertyReturnType
39   {
40     NO_ERROR = 0,
41     ERROR_UNKNOWN = 1,
42     ERROR_IMPOSSIBLE_SET = 2,
43   };
44
45   // Update visual property by Action::UPDATE_PROPERTY.
46
47   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_View_InternalUpdateVisualPropertyBool(void *view, int visualIndex, int visualPropertyIndex, bool valBool)
48   {
49     Dali::Toolkit::Control *pControl = (Dali::Toolkit::Control *)view;
50
51     if (!pControl)
52     {
53       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
54       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
55     }
56
57     try
58     {
59       Dali::Property::Map tempMap;
60       tempMap.Insert(visualPropertyIndex, valBool);
61       Dali::Toolkit::DevelControl::DoAction(*pControl, visualIndex, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, std::move(tempMap));
62     }
63     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
64
65     return (int)InternalPropertyReturnType::NO_ERROR;
66   }
67
68   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_View_InternalUpdateVisualPropertyFloat(void *view, int visualIndex, int visualPropertyIndex, float valFloat)
69   {
70     Dali::Toolkit::Control *pControl = (Dali::Toolkit::Control *)view;
71
72     if (!pControl)
73     {
74       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
75       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
76     }
77
78     try
79     {
80       Dali::Property::Map tempMap;
81       tempMap.Insert(visualPropertyIndex, valFloat);
82       Dali::Toolkit::DevelControl::DoAction(*pControl, visualIndex, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, std::move(tempMap));
83     }
84     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
85
86     return (int)InternalPropertyReturnType::NO_ERROR;
87   }
88
89   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_View_InternalUpdateVisualPropertyInt(void *view, int visualIndex, int visualPropertyIndex, int valInt)
90   {
91     Dali::Toolkit::Control *pControl = (Dali::Toolkit::Control *)view;
92
93     if (!pControl)
94     {
95       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
96       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
97     }
98
99     try
100     {
101       Dali::Property::Map tempMap;
102       tempMap.Insert(visualPropertyIndex, valInt);
103       Dali::Toolkit::DevelControl::DoAction(*pControl, visualIndex, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, std::move(tempMap));
104     }
105     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
106
107     return (int)InternalPropertyReturnType::NO_ERROR;
108   }
109
110   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_View_InternalUpdateVisualPropertyIntPair(void *view, int visualIndex, int visualPropertyIndex, int valInt1, int valInt2)
111   {
112     Dali::Toolkit::Control *pControl  = (Dali::Toolkit::Control *)view;
113
114     if (!pControl)
115     {
116       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
117       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
118     }
119
120     try
121     {
122       Dali::Property::Array tempArray;
123       tempArray.Add(Dali::Property::Value(valInt1));
124       tempArray.Add(Dali::Property::Value(valInt2));
125       Dali::Property::Map tempMap;
126       tempMap.Insert(visualPropertyIndex, std::move(tempArray));
127       Dali::Toolkit::DevelControl::DoAction(*pControl, visualIndex, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, std::move(tempMap));
128     }
129     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
130
131     return (int)InternalPropertyReturnType::NO_ERROR;
132   }
133
134   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_View_InternalUpdateVisualPropertyString(void *view, int visualIndex, int visualPropertyIndex, char* valString)
135   {
136     Dali::Toolkit::Control *pControl  = (Dali::Toolkit::Control *)view;
137
138     if (!pControl)
139     {
140       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
141       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
142     }
143
144     if (!valString)
145     {
146       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "valString1 is null!");
147       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
148     }
149
150     try
151     {
152       Dali::Property::Map tempMap;
153       tempMap.Insert(visualPropertyIndex, std::move(valString));
154       Dali::Toolkit::DevelControl::DoAction(*pControl, visualIndex, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, std::move(tempMap));
155     }
156     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
157
158     return (int)InternalPropertyReturnType::NO_ERROR;
159   }
160
161   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_View_InternalUpdateVisualPropertyStringPair(void *view, int visualIndex, int visualPropertyIndex, char* valString1, char* valString2)
162   {
163     Dali::Toolkit::Control *pControl  = (Dali::Toolkit::Control *)view;
164
165     if (!pControl)
166     {
167       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
168       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
169     }
170
171     if (!valString1)
172     {
173       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "valString1 is null!");
174       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
175     }
176
177     if (!valString2)
178     {
179       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "valString2 is null!");
180       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
181     }
182
183     try
184     {
185       Dali::Property::Array tempArray;
186       tempArray.Add(Dali::Property::Value(valString1));
187       tempArray.Add(Dali::Property::Value(valString2));
188       Dali::Property::Map tempMap;
189       tempMap.Insert(visualPropertyIndex, std::move(tempArray));
190       Dali::Toolkit::DevelControl::DoAction(*pControl, visualIndex, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, std::move(tempMap));
191     }
192     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
193
194     return (int)InternalPropertyReturnType::NO_ERROR;
195   }
196
197   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_View_InternalUpdateVisualPropertyVector4(void *view, int visualIndex, int visualPropertyIndex, void *vector4)
198   {
199     Dali::Toolkit::Control *pControl = (Dali::Toolkit::Control *)view;
200     const Dali::Vector4 *pVector4 = (const Dali::Vector4 *)vector4;
201
202     if (!pControl)
203     {
204       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
205       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
206     }
207     if (!pVector4)
208     {
209       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "vector4 is null!");
210       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
211     }
212
213     try
214     {
215       Dali::Property::Map tempMap;
216       tempMap.Insert(visualPropertyIndex, *pVector4);
217       Dali::Toolkit::DevelControl::DoAction(*pControl, visualIndex, Dali::Toolkit::DevelVisual::Action::UPDATE_PROPERTY, std::move(tempMap));
218     }
219     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
220
221     return (int)InternalPropertyReturnType::NO_ERROR;
222   }
223
224   // Other Actions witch is not Action::UPDATE_PROPERTY.
225
226   SWIGEXPORT void SWIGSTDCALL CSharp_Dali_View_DoActionWithEmptyAttributes(void *view, int visualIndex, int actionId)
227   {
228     Dali::Toolkit::Control *pControl  = (Dali::Toolkit::Control *)view;
229
230     if (!pControl) {
231       SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Toolkit::Control & type is null", 0);
232       return;
233     }
234     {
235       try {
236         Dali::Toolkit::DevelControl::DoAction(*pControl, visualIndex, actionId, Dali::Property::Value());
237       } CALL_CATCH_EXCEPTION();
238     }
239   }
240
241   SWIGEXPORT void SWIGSTDCALL CSharp_Dali_View_DoActionWithSingleIntAttributes(void *view, int visualIndex, int actionId, int actionValue)
242   {
243     Dali::Toolkit::Control *pControl  = (Dali::Toolkit::Control *)view;
244
245     if (!pControl) {
246       SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Toolkit::Control & type is null", 0);
247       return;
248     }
249     {
250       try {
251         Dali::Toolkit::DevelControl::DoAction(*pControl, visualIndex, actionId, Dali::Property::Value(actionValue));
252       } CALL_CATCH_EXCEPTION();
253     }
254   }
255
256   // Get value from visual
257   // NOTE : Control.GetProperty(visualIndex) is not enought because it cannot get custom registed visual.
258   // NOTE : Currently, there is no way to get value from visual directly. We need to use CreatePropertyMap.
259
260   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_Actor_InternalRetrievingVisualPropertyInt(void *view, int visualIndex, int visualPropertyIndex, int *valInt)
261   {
262     Dali::Toolkit::Control *pControl  = (Dali::Toolkit::Control *)view;
263
264     if (!pControl)
265     {
266       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
267       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
268     }
269     if (!valInt)
270     {
271       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "valInt is null!");
272       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
273     }
274
275     try
276     {
277       Dali::Toolkit::Internal::Control& internalControl = Dali::Toolkit::Internal::GetImplementation(*pControl);
278       Dali::Toolkit::Visual::Base       visualBase      = Dali::Toolkit::DevelControl::GetVisual(internalControl, visualIndex);
279       if(visualBase)
280       {
281         Dali::Property::Map tempMap;
282         visualBase.CreatePropertyMap(tempMap);
283         Dali::Property::Value* retValuePtr = tempMap.Find(visualPropertyIndex);
284         if(retValuePtr)
285         {
286           *valInt = retValuePtr->Get<int>();
287         }
288       }
289     }
290     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
291
292     return (int)InternalPropertyReturnType::NO_ERROR;
293   }
294
295   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_Actor_InternalRetrievingVisualPropertyString(void *view, int visualIndex, int visualPropertyIndex, char** valString)
296   {
297     Dali::Toolkit::Control *pControl  = (Dali::Toolkit::Control *)view;
298
299     if (!pControl)
300     {
301       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
302       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
303     }
304     if (!valString)
305     {
306       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "valString is null!");
307       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
308     }
309
310     try
311     {
312       // Copy inputed initialized string.
313       // Note : C# side inputed string reference count become reduced.
314       // So, If we want to keep life when we fail to get result,
315       // We should re-convert by SWIG_csharp_string_callback.
316       std::string temp = (*valString == nullptr) ? "" : *valString;
317
318       Dali::Toolkit::Internal::Control& internalControl = Dali::Toolkit::Internal::GetImplementation(*pControl);
319       Dali::Toolkit::Visual::Base       visualBase      = Dali::Toolkit::DevelControl::GetVisual(internalControl, visualIndex);
320       if(visualBase)
321       {
322         Dali::Property::Map tempMap;
323         visualBase.CreatePropertyMap(tempMap);
324         Dali::Property::Value* retValuePtr = tempMap.Find(visualPropertyIndex);
325         if(retValuePtr)
326         {
327           //typemap in
328           temp = retValuePtr->Get<std::string>();
329         }
330       }
331
332       //Typemap argout in c++ file.
333       //This will convert c++ string to c# string
334       *valString = SWIG_csharp_string_callback(temp.c_str());
335     }
336     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
337
338     return (int)InternalPropertyReturnType::NO_ERROR;
339   }
340
341   SWIGEXPORT int SWIGSTDCALL CSharp_Dali_Actor_InternalRetrievingVisualPropertyVector4(void *view, int visualIndex, int visualPropertyIndex, void *vector4)
342   {
343     Dali::Toolkit::Control *pControl  = (Dali::Toolkit::Control *)view;
344     Dali::Vector4 *pVector4 = (Dali::Vector4 *)vector4;
345
346     if (!pControl)
347     {
348       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "view is null!");
349       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
350     }
351     if (!pVector4)
352     {
353       SWIG_EXCEPTION_WITH_FILE_AND_LINE(SWIG_CSharpArgumentNullException, "vector4 is null!");
354       return (int)InternalPropertyReturnType::ERROR_UNKNOWN;
355     }
356
357     try
358     {
359       Dali::Toolkit::Internal::Control& internalControl = Dali::Toolkit::Internal::GetImplementation(*pControl);
360       Dali::Toolkit::Visual::Base       visualBase      = Dali::Toolkit::DevelControl::GetVisual(internalControl, visualIndex);
361       if(visualBase)
362       {
363         Dali::Property::Map tempMap;
364         visualBase.CreatePropertyMap(tempMap);
365         Dali::Property::Value* retValuePtr = tempMap.Find(visualPropertyIndex);
366         if(retValuePtr)
367         {
368           *pVector4 = retValuePtr->Get<Dali::Vector4>();
369         }
370       }
371     }
372     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);
373
374     return (int)InternalPropertyReturnType::NO_ERROR;
375   }
376 #ifdef __cplusplus
377 }
378 #endif