[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Builder.cs
1 /*
2  * Copyright(c) 2019 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         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27
28         internal Builder(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Builder.Builder_SWIGUpcast(cPtr), cMemoryOwn)
29         {
30             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31         }
32
33         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Builder obj)
34         {
35             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
36         }
37
38         protected override void Dispose(DisposeTypes type)
39         {
40             if (disposed)
41             {
42                 return;
43             }
44
45             //Release your own unmanaged resources here.
46             //You should not access any managed member here except static instance.
47             //because the execution order of Finalizes is non-deterministic.
48             if (swigCPtr.Handle != global::System.IntPtr.Zero)
49             {
50                 if (swigCMemOwn)
51                 {
52                     swigCMemOwn = false;
53                     Interop.Builder.delete_Builder(swigCPtr);
54                 }
55                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
56             }
57
58             base.Dispose(type);
59         }
60
61         /// <since_tizen> 3 </since_tizen>
62         public class QuitEventArgs : EventArgs
63         {
64         }
65
66         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
67         private delegate void QuitEventCallbackDelegate();
68         private DaliEventHandler<object, QuitEventArgs> _builderQuitEventHandler;
69         private QuitEventCallbackDelegate _builderQuitEventCallbackDelegate;
70
71         public event DaliEventHandler<object, QuitEventArgs> Quit
72         {
73             add
74             {
75                 lock (this)
76                 {
77                     // Restricted to only one listener
78                     if (_builderQuitEventHandler == null)
79                     {
80                         _builderQuitEventHandler += value;
81
82                         _builderQuitEventCallbackDelegate = new QuitEventCallbackDelegate(OnQuit);
83                         this.QuitSignal().Connect(_builderQuitEventCallbackDelegate);
84                     }
85                 }
86             }
87
88             remove
89             {
90                 lock (this)
91                 {
92                     if (_builderQuitEventHandler != null)
93                     {
94                         this.QuitSignal().Disconnect(_builderQuitEventCallbackDelegate);
95                     }
96
97                     _builderQuitEventHandler -= value;
98                 }
99             }
100         }
101
102         // Callback for Builder QuitSignal
103         private void OnQuit()
104         {
105             QuitEventArgs e = new QuitEventArgs();
106
107             if (_builderQuitEventHandler != null)
108             {
109                 //here we send all data to user event handlers
110                 _builderQuitEventHandler(this, e);
111             }
112         }
113
114         ///
115         public void LoadFromFile(string fileName)
116         {
117             try
118             {
119                 string json = System.IO.File.ReadAllText(fileName);
120                 if (json.Length > 0)
121                 {
122                     LoadFromString(json);
123                 }
124                 else
125                 {
126                     throw new global::System.InvalidOperationException("Failed to load file " + fileName);
127
128                 }
129             }
130             catch (System.Exception e)
131             {
132                 NUILog.Error(e.Message);
133                 throw new global::System.InvalidOperationException("Failed to parse " + fileName);
134             }
135         }
136
137         public Builder() : this(Interop.Builder.Builder_New(), true)
138         {
139             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140         }
141
142         public void LoadFromString(string data, Builder.UIFormat format)
143         {
144             Interop.Builder.Builder_LoadFromString__SWIG_0(swigCPtr, data, (int)format);
145             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146         }
147
148         public void LoadFromString(string data)
149         {
150             Interop.Builder.Builder_LoadFromString__SWIG_1(swigCPtr, data);
151             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152         }
153
154         public void AddConstants(PropertyMap map)
155         {
156             Interop.Builder.Builder_AddConstants(swigCPtr, PropertyMap.getCPtr(map));
157             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158         }
159
160         public void AddConstant(string key, PropertyValue value)
161         {
162             Interop.Builder.Builder_AddConstant(swigCPtr, key, PropertyValue.getCPtr(value));
163             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164         }
165
166         public PropertyMap GetConstants()
167         {
168             PropertyMap ret = new PropertyMap(Interop.Builder.Builder_GetConstants(swigCPtr), false);
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170             return ret;
171         }
172
173         public PropertyValue GetConstant(string key)
174         {
175             PropertyValue ret = new PropertyValue(Interop.Builder.Builder_GetConstant(swigCPtr, key), false);
176             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177             return ret;
178         }
179
180         public Animation CreateAnimation(string animationName)
181         {
182             Animation ret = new Animation(Interop.Builder.Builder_CreateAnimation__SWIG_0(swigCPtr, animationName), true);
183             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184             return ret;
185         }
186
187         public Animation CreateAnimation(string animationName, PropertyMap map)
188         {
189             Animation ret = new Animation(Interop.Builder.Builder_CreateAnimation__SWIG_1(swigCPtr, animationName, PropertyMap.getCPtr(map)), true);
190             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191             return ret;
192         }
193
194         public Animation CreateAnimation(string animationName, View sourceActor)
195         {
196             Animation ret = new Animation(Interop.Builder.Builder_CreateAnimation__SWIG_2(swigCPtr, animationName, View.getCPtr(sourceActor)), true);
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198             return ret;
199         }
200
201         public Animation CreateAnimation(string animationName, PropertyMap map, View sourceActor)
202         {
203             Animation ret = new Animation(Interop.Builder.Builder_CreateAnimation__SWIG_3(swigCPtr, animationName, PropertyMap.getCPtr(map), View.getCPtr(sourceActor)), true);
204             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205             return ret;
206         }
207
208         public View Create(string templateName)
209         {
210             View ret = new View(Interop.Builder.Builder_Create__SWIG_0(swigCPtr, templateName), true);
211             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212             return ret;
213         }
214
215         public BaseHandle Create(string templateName, PropertyMap map)
216         {
217             BaseHandle ret = new BaseHandle(Interop.Builder.Builder_Create__SWIG_1(swigCPtr, templateName, PropertyMap.getCPtr(map)), true);
218             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219             return ret;
220         }
221
222         public BaseHandle CreateFromJson(string json)
223         {
224             BaseHandle ret = new BaseHandle(Interop.Builder.Builder_CreateFromJson(swigCPtr, json), true);
225             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226             return ret;
227         }
228
229         public bool ApplyStyle(string styleName, Animatable handle)
230         {
231             bool ret = Interop.Builder.Builder_ApplyStyle(swigCPtr, styleName, Animatable.getCPtr(handle));
232             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233             return ret;
234         }
235
236         public bool ApplyFromJson(Animatable handle, string json)
237         {
238             bool ret = Interop.Builder.Builder_ApplyFromJson(swigCPtr, Animatable.getCPtr(handle), json);
239             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240             return ret;
241         }
242
243         public void AddViews(View toActor)
244         {
245             Interop.Builder.Builder_AddActors__SWIG_0(swigCPtr, View.getCPtr(toActor));
246             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247         }
248
249         public void AddViews(string sectionName, View toActor)
250         {
251             Interop.Builder.Builder_AddActors__SWIG_1(swigCPtr, sectionName, View.getCPtr(toActor));
252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253         }
254
255         public void CreateRenderTask(string name)
256         {
257             Interop.Builder.Builder_CreateRenderTask(swigCPtr, name);
258             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259         }
260
261         public Path GetPath(string name)
262         {
263             Path ret = new Path(Interop.Builder.Builder_GetPath(swigCPtr, name), true);
264             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265             return ret;
266         }
267
268         internal PathConstrainer GetPathConstrainer(string pathConstrainerName)
269         {
270             PathConstrainer ret = new PathConstrainer(Interop.Builder.Builder_GetPathConstrainer(swigCPtr, pathConstrainerName), true);
271             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272             return ret;
273         }
274
275         internal LinearConstrainer GetLinearConstrainer(string linearConstrainerName)
276         {
277             LinearConstrainer ret = new LinearConstrainer(Interop.Builder.Builder_GetLinearConstrainer(swigCPtr, linearConstrainerName), true);
278             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279             return ret;
280         }
281
282         internal VoidSignal QuitSignal()
283         {
284             VoidSignal ret = new VoidSignal(Interop.Builder.Builder_QuitSignal(swigCPtr), false);
285             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286             return ret;
287         }
288
289         /// <since_tizen> 3 </since_tizen>
290         public enum UIFormat
291         {
292             JSON
293         }
294     }
295 }