[NUI] Change all CallingConvention to `Cdecl`
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Utility / Builder.cs
1 /*
2  * Copyright(c) 2021 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 using System;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
21
22 namespace Tizen.NUI
23 {
24     internal class Builder : BaseHandle
25     {
26         internal Builder(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
27         {
28         }
29
30
31         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
32         {
33             Interop.Builder.DeleteBuilder(swigCPtr);
34         }
35
36         public class QuitEventArgs : EventArgs
37         {
38         }
39
40         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
41         private delegate void QuitEventCallbackDelegate();
42         private DaliEventHandler<object, QuitEventArgs> builderQuitEventHandler;
43         private QuitEventCallbackDelegate builderQuitEventCallbackDelegate;
44         private VoidSignal quitSignal;
45
46         public event DaliEventHandler<object, QuitEventArgs> Quit
47         {
48             add
49             {
50                 // Restricted to only one listener
51                 if (builderQuitEventHandler == null)
52                 {
53                     builderQuitEventHandler += value;
54
55                     builderQuitEventCallbackDelegate = new QuitEventCallbackDelegate(OnQuit);
56                     quitSignal = this.QuitSignal();
57                     quitSignal?.Connect(builderQuitEventCallbackDelegate);
58                 }
59             }
60
61             remove
62             {
63                 if (builderQuitEventHandler != null)
64                 {
65                     quitSignal?.Disconnect(builderQuitEventCallbackDelegate);
66                 }
67
68                 builderQuitEventHandler -= value;
69             }
70         }
71
72         // Callback for Builder QuitSignal
73         private void OnQuit()
74         {
75             QuitEventArgs e = new QuitEventArgs();
76
77             if (builderQuitEventHandler != null)
78             {
79                 //here we send all data to user event handlers
80                 builderQuitEventHandler(this, e);
81             }
82         }
83
84         ///
85         public void LoadFromFile(string fileName)
86         {
87             try
88             {
89                 string json = System.IO.File.ReadAllText(fileName);
90                 if (json.Length > 0)
91                 {
92                     LoadFromString(json);
93                 }
94                 else
95                 {
96                     throw new global::System.InvalidOperationException("Failed to load file " + fileName);
97
98                 }
99             }
100             catch (System.Exception e)
101             {
102                 NUILog.Error(e.Message);
103                 throw new global::System.InvalidOperationException("Failed to parse " + fileName);
104             }
105         }
106
107         public Builder() : this(Interop.Builder.New(), true)
108         {
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110         }
111
112         public void LoadFromString(string data, Builder.UIFormat format)
113         {
114             Interop.Builder.LoadFromString(SwigCPtr, data, (int)format);
115             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116         }
117
118         public void LoadFromString(string data)
119         {
120             Interop.Builder.LoadFromString(SwigCPtr, data);
121             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122         }
123
124         public void AddConstants(PropertyMap map)
125         {
126             Interop.Builder.AddConstants(SwigCPtr, PropertyMap.getCPtr(map));
127             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128         }
129
130         public void AddConstant(string key, PropertyValue value)
131         {
132             Interop.Builder.AddConstant(SwigCPtr, key, PropertyValue.getCPtr(value));
133             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134         }
135
136         public PropertyMap GetConstants()
137         {
138             PropertyMap ret = new PropertyMap(Interop.Builder.GetConstants(SwigCPtr), false);
139             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140             return ret;
141         }
142
143         public PropertyValue GetConstant(string key)
144         {
145             PropertyValue ret = new PropertyValue(Interop.Builder.GetConstant(SwigCPtr, key), false);
146             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147             return ret;
148         }
149
150         public Animation CreateAnimation(string animationName)
151         {
152             Animation ret = new Animation(Interop.Builder.CreateAnimation(SwigCPtr, animationName), true);
153             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154             return ret;
155         }
156
157         public Animation CreateAnimation(string animationName, PropertyMap map)
158         {
159             Animation ret = new Animation(Interop.Builder.CreateAnimationWithPropertyMap(SwigCPtr, animationName, PropertyMap.getCPtr(map)), true);
160             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161             return ret;
162         }
163
164         public Animation CreateAnimation(string animationName, View sourceActor)
165         {
166             Animation ret = new Animation(Interop.Builder.CreateAnimationWithView(SwigCPtr, animationName, View.getCPtr(sourceActor)), true);
167             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168             return ret;
169         }
170
171         public Animation CreateAnimation(string animationName, PropertyMap map, View sourceActor)
172         {
173             Animation ret = new Animation(Interop.Builder.CreateAnimation(SwigCPtr, animationName, PropertyMap.getCPtr(map), View.getCPtr(sourceActor)), true);
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175             return ret;
176         }
177
178         public View Create(string templateName)
179         {
180             View ret = new View(Interop.Builder.Create(SwigCPtr, templateName), true);
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182             return ret;
183         }
184
185         public BaseHandle Create(string templateName, PropertyMap map)
186         {
187             BaseHandle ret = new BaseHandle(Interop.Builder.Create(SwigCPtr, templateName, PropertyMap.getCPtr(map)), true);
188             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189             return ret;
190         }
191
192         public BaseHandle CreateFromJson(string json)
193         {
194             BaseHandle ret = new BaseHandle(Interop.Builder.CreateFromJson(SwigCPtr, json), true);
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196             return ret;
197         }
198
199         public bool ApplyStyle(string styleName, Animatable handle)
200         {
201             bool ret = Interop.Builder.ApplyStyle(SwigCPtr, styleName, Animatable.getCPtr(handle));
202             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203             return ret;
204         }
205
206         public bool ApplyFromJson(Animatable handle, string json)
207         {
208             bool ret = Interop.Builder.ApplyFromJson(SwigCPtr, Animatable.getCPtr(handle), json);
209             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210             return ret;
211         }
212
213         public void AddViews(View toActor)
214         {
215             Interop.Builder.AddActors(SwigCPtr, View.getCPtr(toActor));
216             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217         }
218
219         public void AddViews(string sectionName, View toActor)
220         {
221             Interop.Builder.AddActors(SwigCPtr, sectionName, View.getCPtr(toActor));
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223         }
224
225         public void CreateRenderTask(string name)
226         {
227             Interop.Builder.CreateRenderTask(SwigCPtr, name);
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229         }
230
231         public Path GetPath(string name)
232         {
233             Path ret = new Path(Interop.Builder.GetPath(SwigCPtr, name), true);
234             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235             return ret;
236         }
237
238         internal PathConstrainer GetPathConstrainer(string pathConstrainerName)
239         {
240             PathConstrainer ret = new PathConstrainer(Interop.Builder.GetPathConstrainer(SwigCPtr, pathConstrainerName), true);
241             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242             return ret;
243         }
244
245         internal LinearConstrainer GetLinearConstrainer(string linearConstrainerName)
246         {
247             LinearConstrainer ret = new LinearConstrainer(Interop.Builder.GetLinearConstrainer(SwigCPtr, linearConstrainerName), true);
248             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249             return ret;
250         }
251
252         internal VoidSignal QuitSignal()
253         {
254             VoidSignal ret = new VoidSignal(Interop.Builder.QuitSignal(SwigCPtr), false);
255             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256             return ret;
257         }
258
259         public enum UIFormat
260         {
261             JSON
262         }
263     }
264 }