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