Release 4.0.0-preview1-00301
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Builder.cs
1 /*
2  * Copyright(c) 2017 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(NDalicPINVOKE.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                     NDalicPINVOKE.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         public class QuitEventArgs : EventArgs
76         {
77         }
78
79         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
80         private delegate void QuitEventCallbackDelegate();
81         private DaliEventHandler<object, QuitEventArgs> _builderQuitEventHandler;
82         private QuitEventCallbackDelegate _builderQuitEventCallbackDelegate;
83
84         public event DaliEventHandler<object, QuitEventArgs> Quit
85         {
86             add
87             {
88                 lock (this)
89                 {
90                     // Restricted to only one listener
91                     if (_builderQuitEventHandler == null)
92                     {
93                         _builderQuitEventHandler += value;
94
95                         _builderQuitEventCallbackDelegate = new QuitEventCallbackDelegate(OnQuit);
96                         this.QuitSignal().Connect(_builderQuitEventCallbackDelegate);
97                     }
98                 }
99             }
100
101             remove
102             {
103                 lock (this)
104                 {
105                     if (_builderQuitEventHandler != null)
106                     {
107                         this.QuitSignal().Disconnect(_builderQuitEventCallbackDelegate);
108                     }
109
110                     _builderQuitEventHandler -= value;
111                 }
112             }
113         }
114
115         // Callback for Builder QuitSignal
116         private void OnQuit()
117         {
118             QuitEventArgs e = new QuitEventArgs();
119
120             if (_builderQuitEventHandler != null)
121             {
122                 //here we send all data to user event handlers
123                 _builderQuitEventHandler(this, e);
124             }
125         }
126
127         ///
128         public void LoadFromFile(string fileName)
129         {
130             try
131             {
132                 string json = System.IO.File.ReadAllText(fileName);
133                 if (json.Length > 0)
134                 {
135                     LoadFromString(json);
136                 }
137                 else
138                 {
139                     throw new global::System.InvalidOperationException("Failed to load file " + fileName);
140
141                 }
142             }
143             catch (System.Exception e)
144             {
145                 NUILog.Error(e.Message);
146                 throw new global::System.InvalidOperationException("Failed to parse " + fileName);
147             }
148         }
149
150
151
152         public Builder() : this(NDalicPINVOKE.Builder_New(), true)
153         {
154             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155
156         }
157         public void LoadFromString(string data, Builder.UIFormat format)
158         {
159             NDalicPINVOKE.Builder_LoadFromString__SWIG_0(swigCPtr, data, (int)format);
160             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161         }
162
163         public void LoadFromString(string data)
164         {
165             NDalicPINVOKE.Builder_LoadFromString__SWIG_1(swigCPtr, data);
166             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167         }
168
169         public void AddConstants(PropertyMap map)
170         {
171             NDalicPINVOKE.Builder_AddConstants(swigCPtr, PropertyMap.getCPtr(map));
172             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173         }
174
175         public void AddConstant(string key, PropertyValue value)
176         {
177             NDalicPINVOKE.Builder_AddConstant(swigCPtr, key, PropertyValue.getCPtr(value));
178             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179         }
180
181         public PropertyMap GetConstants()
182         {
183             PropertyMap ret = new PropertyMap(NDalicPINVOKE.Builder_GetConstants(swigCPtr), false);
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185             return ret;
186         }
187
188         public PropertyValue GetConstant(string key)
189         {
190             PropertyValue ret = new PropertyValue(NDalicPINVOKE.Builder_GetConstant(swigCPtr, key), false);
191             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192             return ret;
193         }
194
195         public Animation CreateAnimation(string animationName)
196         {
197             Animation ret = new Animation(NDalicPINVOKE.Builder_CreateAnimation__SWIG_0(swigCPtr, animationName), true);
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199             return ret;
200         }
201
202         public Animation CreateAnimation(string animationName, PropertyMap map)
203         {
204             Animation ret = new Animation(NDalicPINVOKE.Builder_CreateAnimation__SWIG_1(swigCPtr, animationName, PropertyMap.getCPtr(map)), true);
205             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206             return ret;
207         }
208
209         public Animation CreateAnimation(string animationName, View sourceActor)
210         {
211             Animation ret = new Animation(NDalicPINVOKE.Builder_CreateAnimation__SWIG_2(swigCPtr, animationName, View.getCPtr(sourceActor)), true);
212             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213             return ret;
214         }
215
216         public Animation CreateAnimation(string animationName, PropertyMap map, View sourceActor)
217         {
218             Animation ret = new Animation(NDalicPINVOKE.Builder_CreateAnimation__SWIG_3(swigCPtr, animationName, PropertyMap.getCPtr(map), View.getCPtr(sourceActor)), true);
219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220             return ret;
221         }
222
223         public View Create(string templateName)
224         {
225             View ret = new View(NDalicPINVOKE.Builder_Create__SWIG_0(swigCPtr, templateName), true);
226             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227             return ret;
228         }
229
230         public BaseHandle Create(string templateName, PropertyMap map)
231         {
232             BaseHandle ret = new BaseHandle(NDalicPINVOKE.Builder_Create__SWIG_1(swigCPtr, templateName, PropertyMap.getCPtr(map)), true);
233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234             return ret;
235         }
236
237         public BaseHandle CreateFromJson(string json)
238         {
239             BaseHandle ret = new BaseHandle(NDalicPINVOKE.Builder_CreateFromJson(swigCPtr, json), true);
240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241             return ret;
242         }
243
244         public bool ApplyStyle(string styleName, Animatable handle)
245         {
246             bool ret = NDalicPINVOKE.Builder_ApplyStyle(swigCPtr, styleName, Animatable.getCPtr(handle));
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248             return ret;
249         }
250
251         public bool ApplyFromJson(Animatable handle, string json)
252         {
253             bool ret = NDalicPINVOKE.Builder_ApplyFromJson(swigCPtr, Animatable.getCPtr(handle), json);
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255             return ret;
256         }
257
258         public void AddViews(View toActor)
259         {
260             NDalicPINVOKE.Builder_AddActors__SWIG_0(swigCPtr, View.getCPtr(toActor));
261             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262         }
263
264         public void AddViews(string sectionName, View toActor)
265         {
266             NDalicPINVOKE.Builder_AddActors__SWIG_1(swigCPtr, sectionName, View.getCPtr(toActor));
267             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268         }
269
270         public void CreateRenderTask(string name)
271         {
272             NDalicPINVOKE.Builder_CreateRenderTask(swigCPtr, name);
273             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274         }
275
276         internal FrameBufferImage GetFrameBufferImage(string name)
277         {
278             FrameBufferImage ret = new FrameBufferImage(NDalicPINVOKE.Builder_GetFrameBufferImage(swigCPtr, name), true);
279             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280             return ret;
281         }
282
283         public Path GetPath(string name)
284         {
285             Path ret = new Path(NDalicPINVOKE.Builder_GetPath(swigCPtr, name), true);
286             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287             return ret;
288         }
289
290         internal PathConstrainer GetPathConstrainer(string pathConstrainerName)
291         {
292             PathConstrainer ret = new PathConstrainer(NDalicPINVOKE.Builder_GetPathConstrainer(swigCPtr, pathConstrainerName), true);
293             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294             return ret;
295         }
296
297         internal LinearConstrainer GetLinearConstrainer(string linearConstrainerName)
298         {
299             LinearConstrainer ret = new LinearConstrainer(NDalicPINVOKE.Builder_GetLinearConstrainer(swigCPtr, linearConstrainerName), true);
300             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301             return ret;
302         }
303
304         internal VoidSignal QuitSignal()
305         {
306             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Builder_QuitSignal(swigCPtr), false);
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308             return ret;
309         }
310
311         public enum UIFormat
312         {
313             JSON
314         }
315
316     }
317
318 }