Ensuring that Registry.Unregister is called from the most derived class before the...
[platform/core/csapi/nui.git] / 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             if (swigCPtr.Handle != global::System.IntPtr.Zero)
59             {
60                 if (swigCMemOwn)
61                 {
62                     swigCMemOwn = false;
63
64                     //Unreference this instance from Registry.
65                     Registry.Unregister(this);
66
67                     NDalicPINVOKE.delete_Builder(swigCPtr);
68                 }
69                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
70             }
71
72             base.Dispose(type);
73         }
74
75
76
77         public class QuitEventArgs : EventArgs
78         {
79         }
80
81         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
82         private delegate void QuitEventCallbackDelegate();
83         private DaliEventHandler<object, QuitEventArgs> _builderQuitEventHandler;
84         private QuitEventCallbackDelegate _builderQuitEventCallbackDelegate;
85
86         public event DaliEventHandler<object, QuitEventArgs> Quit
87         {
88             add
89             {
90                 lock (this)
91                 {
92                     // Restricted to only one listener
93                     if (_builderQuitEventHandler == null)
94                     {
95                         _builderQuitEventHandler += value;
96
97                         _builderQuitEventCallbackDelegate = new QuitEventCallbackDelegate(OnQuit);
98                         this.QuitSignal().Connect(_builderQuitEventCallbackDelegate);
99                     }
100                 }
101             }
102
103             remove
104             {
105                 lock (this)
106                 {
107                     if (_builderQuitEventHandler != null)
108                     {
109                         this.QuitSignal().Disconnect(_builderQuitEventCallbackDelegate);
110                     }
111
112                     _builderQuitEventHandler -= value;
113                 }
114             }
115         }
116
117         // Callback for Builder QuitSignal
118         private void OnQuit()
119         {
120             QuitEventArgs e = new QuitEventArgs();
121
122             if (_builderQuitEventHandler != null)
123             {
124                 //here we send all data to user event handlers
125                 _builderQuitEventHandler(this, e);
126             }
127         }
128
129         ///
130         public void LoadFromFile(string fileName)
131         {
132             try
133             {
134                 string json = System.IO.File.ReadAllText(fileName);
135                 if (json.Length > 0)
136                 {
137                     LoadFromString(json);
138                 }
139                 else
140                 {
141                     throw new global::System.InvalidOperationException("Failed to load file " + fileName);
142
143                 }
144             }
145             catch (System.Exception e)
146             {
147                 throw new global::System.InvalidOperationException("Failed to parse " + fileName);
148             }
149         }
150
151
152
153         public Builder() : this(NDalicPINVOKE.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             NDalicPINVOKE.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             NDalicPINVOKE.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             NDalicPINVOKE.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             NDalicPINVOKE.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(NDalicPINVOKE.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(NDalicPINVOKE.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(NDalicPINVOKE.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(NDalicPINVOKE.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(NDalicPINVOKE.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(NDalicPINVOKE.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 BaseHandle Create(string templateName)
225         {
226             BaseHandle ret = new BaseHandle(NDalicPINVOKE.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(NDalicPINVOKE.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(NDalicPINVOKE.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 = NDalicPINVOKE.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 = NDalicPINVOKE.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             NDalicPINVOKE.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             NDalicPINVOKE.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             NDalicPINVOKE.Builder_CreateRenderTask(swigCPtr, name);
274             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275         }
276
277         internal FrameBufferImage GetFrameBufferImage(string name)
278         {
279             FrameBufferImage ret = new FrameBufferImage(NDalicPINVOKE.Builder_GetFrameBufferImage(swigCPtr, name), true);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         public Path GetPath(string name)
285         {
286             Path ret = new Path(NDalicPINVOKE.Builder_GetPath(swigCPtr, name), true);
287             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288             return ret;
289         }
290
291         internal PathConstrainer GetPathConstrainer(string pathConstrainerName)
292         {
293             PathConstrainer ret = new PathConstrainer(NDalicPINVOKE.Builder_GetPathConstrainer(swigCPtr, pathConstrainerName), true);
294             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295             return ret;
296         }
297
298         internal LinearConstrainer GetLinearConstrainer(string linearConstrainerName)
299         {
300             LinearConstrainer ret = new LinearConstrainer(NDalicPINVOKE.Builder_GetLinearConstrainer(swigCPtr, linearConstrainerName), true);
301             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302             return ret;
303         }
304
305         internal VoidSignal QuitSignal()
306         {
307             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Builder_QuitSignal(swigCPtr), false);
308             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309             return ret;
310         }
311
312         public enum UIFormat
313         {
314             JSON
315         }
316
317     }
318
319 }