[NUI] remove "_" and refactoring naming to pascal case.
[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
27         internal Builder(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Builder.Upcast(cPtr), cMemoryOwn)
28         {
29         }
30
31
32         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
33         {
34             Interop.Builder.DeleteBuilder(swigCPtr);
35         }
36
37         /// <since_tizen> 3 </since_tizen>
38         public class QuitEventArgs : EventArgs
39         {
40         }
41
42         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
43         private delegate void QuitEventCallbackDelegate();
44         private DaliEventHandler<object, QuitEventArgs> _builderQuitEventHandler;
45         private QuitEventCallbackDelegate _builderQuitEventCallbackDelegate;
46
47         public event DaliEventHandler<object, QuitEventArgs> Quit
48         {
49             add
50             {
51                 lock (this)
52                 {
53                     // Restricted to only one listener
54                     if (_builderQuitEventHandler == null)
55                     {
56                         _builderQuitEventHandler += value;
57
58                         _builderQuitEventCallbackDelegate = new QuitEventCallbackDelegate(OnQuit);
59                         this.QuitSignal().Connect(_builderQuitEventCallbackDelegate);
60                     }
61                 }
62             }
63
64             remove
65             {
66                 lock (this)
67                 {
68                     if (_builderQuitEventHandler != null)
69                     {
70                         this.QuitSignal().Disconnect(_builderQuitEventCallbackDelegate);
71                     }
72
73                     _builderQuitEventHandler -= value;
74                 }
75             }
76         }
77
78         // Callback for Builder QuitSignal
79         private void OnQuit()
80         {
81             QuitEventArgs e = new QuitEventArgs();
82
83             if (_builderQuitEventHandler != null)
84             {
85                 //here we send all data to user event handlers
86                 _builderQuitEventHandler(this, e);
87             }
88         }
89
90         ///
91         public void LoadFromFile(string fileName)
92         {
93             try
94             {
95                 string json = System.IO.File.ReadAllText(fileName);
96                 if (json.Length > 0)
97                 {
98                     LoadFromString(json);
99                 }
100                 else
101                 {
102                     throw new global::System.InvalidOperationException("Failed to load file " + fileName);
103
104                 }
105             }
106             catch (System.Exception e)
107             {
108                 NUILog.Error(e.Message);
109                 throw new global::System.InvalidOperationException("Failed to parse " + fileName);
110             }
111         }
112
113         public Builder() : this(Interop.Builder.New(), true)
114         {
115             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116         }
117
118         public void LoadFromString(string data, Builder.UIFormat format)
119         {
120             Interop.Builder.LoadFromString(swigCPtr, data, (int)format);
121             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122         }
123
124         public void LoadFromString(string data)
125         {
126             Interop.Builder.LoadFromString(swigCPtr, data);
127             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128         }
129
130         public void AddConstants(PropertyMap map)
131         {
132             Interop.Builder.AddConstants(swigCPtr, PropertyMap.getCPtr(map));
133             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134         }
135
136         public void AddConstant(string key, PropertyValue value)
137         {
138             Interop.Builder.AddConstant(swigCPtr, key, PropertyValue.getCPtr(value));
139             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140         }
141
142         public PropertyMap GetConstants()
143         {
144             PropertyMap ret = new PropertyMap(Interop.Builder.GetConstants(swigCPtr), false);
145             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146             return ret;
147         }
148
149         public PropertyValue GetConstant(string key)
150         {
151             PropertyValue ret = new PropertyValue(Interop.Builder.GetConstant(swigCPtr, key), false);
152             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153             return ret;
154         }
155
156         public Animation CreateAnimation(string animationName)
157         {
158             Animation ret = new Animation(Interop.Builder.CreateAnimation(swigCPtr, animationName), true);
159             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160             return ret;
161         }
162
163         public Animation CreateAnimation(string animationName, PropertyMap map)
164         {
165             Animation ret = new Animation(Interop.Builder.CreateAnimationWithPropertyMap(swigCPtr, animationName, PropertyMap.getCPtr(map)), true);
166             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167             return ret;
168         }
169
170         public Animation CreateAnimation(string animationName, View sourceActor)
171         {
172             Animation ret = new Animation(Interop.Builder.CreateAnimationWithView(swigCPtr, animationName, View.getCPtr(sourceActor)), true);
173             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174             return ret;
175         }
176
177         public Animation CreateAnimation(string animationName, PropertyMap map, View sourceActor)
178         {
179             Animation ret = new Animation(Interop.Builder.CreateAnimation(swigCPtr, animationName, PropertyMap.getCPtr(map), View.getCPtr(sourceActor)), true);
180             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181             return ret;
182         }
183
184         public View Create(string templateName)
185         {
186             View ret = new View(Interop.Builder.Create(swigCPtr, templateName), true);
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188             return ret;
189         }
190
191         public BaseHandle Create(string templateName, PropertyMap map)
192         {
193             BaseHandle ret = new BaseHandle(Interop.Builder.Create(swigCPtr, templateName, PropertyMap.getCPtr(map)), true);
194             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195             return ret;
196         }
197
198         public BaseHandle CreateFromJson(string json)
199         {
200             BaseHandle ret = new BaseHandle(Interop.Builder.CreateFromJson(swigCPtr, json), true);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202             return ret;
203         }
204
205         public bool ApplyStyle(string styleName, Animatable handle)
206         {
207             bool ret = Interop.Builder.ApplyStyle(swigCPtr, styleName, Animatable.getCPtr(handle));
208             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209             return ret;
210         }
211
212         public bool ApplyFromJson(Animatable handle, string json)
213         {
214             bool ret = Interop.Builder.ApplyFromJson(swigCPtr, Animatable.getCPtr(handle), json);
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216             return ret;
217         }
218
219         public void AddViews(View toActor)
220         {
221             Interop.Builder.AddActors(swigCPtr, View.getCPtr(toActor));
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223         }
224
225         public void AddViews(string sectionName, View toActor)
226         {
227             Interop.Builder.AddActors(swigCPtr, sectionName, View.getCPtr(toActor));
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229         }
230
231         public void CreateRenderTask(string name)
232         {
233             Interop.Builder.CreateRenderTask(swigCPtr, name);
234             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235         }
236
237         public Path GetPath(string name)
238         {
239             Path ret = new Path(Interop.Builder.GetPath(swigCPtr, name), true);
240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241             return ret;
242         }
243
244         internal PathConstrainer GetPathConstrainer(string pathConstrainerName)
245         {
246             PathConstrainer ret = new PathConstrainer(Interop.Builder.GetPathConstrainer(swigCPtr, pathConstrainerName), true);
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248             return ret;
249         }
250
251         internal LinearConstrainer GetLinearConstrainer(string linearConstrainerName)
252         {
253             LinearConstrainer ret = new LinearConstrainer(Interop.Builder.GetLinearConstrainer(swigCPtr, linearConstrainerName), true);
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255             return ret;
256         }
257
258         internal VoidSignal QuitSignal()
259         {
260             VoidSignal ret = new VoidSignal(Interop.Builder.QuitSignal(swigCPtr), false);
261             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262             return ret;
263         }
264
265         /// <since_tizen> 3 </since_tizen>
266         public enum UIFormat
267         {
268             JSON
269         }
270     }
271 }