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