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