[NUI] Modify Instance bug of Application (#1370)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / ComponentApplication.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Runtime.InteropServices;
5
6 namespace Tizen.NUI
7 {
8     class ComponentApplication : Application
9     {
10         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
11         private List<NUIFrameComponent> _frameComponentList;
12
13         internal ComponentApplication(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
14         {
15             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
16             _frameComponentList = new List<NUIFrameComponent>();
17         }
18
19         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ComponentApplication obj)
20         {
21             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
22         }
23
24         protected override void Dispose(DisposeTypes type)
25         {
26             if (disposed)
27             {
28                 return;
29             }
30
31             //Release your own unmanaged resources here.
32             //You should not access any managed member here except static instance.
33             //because the execution order of Finalizes is non-deterministic.
34             if (swigCPtr.Handle != global::System.IntPtr.Zero)
35             {
36                 if (swigCMemOwn)
37                 {
38                     swigCMemOwn = false;
39                     Interop.ComponentApplication.delete_ComponentApplication(swigCPtr);
40                 }
41                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
42             }
43             base.Dispose(type);
44         }
45
46         public static ComponentApplication NewComponentApplication(string[] args, string stylesheet)
47         {
48             ComponentApplication ret = New(args, stylesheet);
49             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
50             _instance = ret;
51             return ret;
52         }
53
54         public static ComponentApplication New(string[] args, string stylesheet)
55         {
56             int argc = args.Length;
57             string argvStr = string.Join(" ", args);
58
59             IntPtr widgetIntPtr = Interop.ComponentApplication.ComponentApplication_New(argc, argvStr, stylesheet);
60
61             ComponentApplication ret = new ComponentApplication(widgetIntPtr, false);
62
63             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
64
65             return ret;
66         }
67
68         internal ComponentApplication(ComponentApplication componentApplication) : this(Interop.ComponentApplication.new_ComponentApplication__SWIG_1(ComponentApplication.getCPtr(componentApplication)), true)
69         {
70             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71         }
72
73         internal ComponentApplication Assign(ComponentApplication componentApplication)
74         {
75             ComponentApplication ret = new ComponentApplication(Interop.ComponentApplication.ComponentApplication_Assign(swigCPtr, ComponentApplication.getCPtr(componentApplication)), false);
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77             return ret;
78         }
79
80                 
81         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
82         private delegate IntPtr NUIComponentApplicationCreatenativeEventCallbackDelegate(IntPtr data);
83
84                 public delegate IntPtr CreateNativeEventHandler(IntPtr data);
85                 private CreateNativeEventHandler _applicationCreateNativeEventHandler;
86         private NUIComponentApplicationCreatenativeEventCallbackDelegate _applicationCreateNativeEventCallbackDelegate;
87                 
88
89         /**
90           * @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
91           *  provided by the user. Initialized signal is emitted when application is initialised
92           */
93         public event CreateNativeEventHandler CreateNative
94         {
95             add
96             {
97                 lock (this)
98                 {
99                     // Restricted to only one listener
100                     if (_applicationCreateNativeEventHandler == null)
101                     {
102                         _applicationCreateNativeEventHandler += value;
103
104                         _applicationCreateNativeEventCallbackDelegate = new NUIComponentApplicationCreatenativeEventCallbackDelegate(OnApplicationCreateNative);
105                         Connect(_applicationCreateNativeEventCallbackDelegate);
106                     }
107                 }
108             }
109
110             remove
111             {
112                 lock (this)
113                 {
114                     if (_applicationCreateNativeEventHandler != null)
115                     {
116                         Disconnect(_applicationCreateNativeEventCallbackDelegate);
117                     }
118
119                     _applicationCreateNativeEventHandler -= value;
120                 }
121             }
122         }
123
124
125         public void Connect(System.Delegate func)
126         {
127             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func);
128             {
129                 Interop.ComponentApplication.ComponentApplication_CreateNativeSignal_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
130                 if (NDalicPINVOKE.SWIGPendingException.Pending)
131                 {
132                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133                 }
134             }
135         }
136
137         public void Disconnect(System.Delegate func)
138         {
139             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
140             {
141                 Interop.ComponentApplication.ComponentApplication_CreateNativeSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
142                 if (NDalicPINVOKE.SWIGPendingException.Pending)
143                 {
144                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145                 }
146             }
147         }
148
149         internal ApplicationSignal CreateNativeSignal()
150         {
151             ApplicationSignal ret = new ApplicationSignal(Interop.ComponentApplication.ComponentApplication_CreateNativeSignal(swigCPtr), false);
152             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153             return ret;
154         }
155                 
156
157                 
158                 // Callback for Application InitSignal
159                 private IntPtr OnApplicationCreateNative(IntPtr data)
160         {
161             IntPtr ptr = IntPtr.Zero;
162                 
163                         if (_applicationCreateNativeEventHandler != null)
164                         {
165                                 ptr = _applicationCreateNativeEventHandler.Invoke(data);
166                         }
167                     return ptr;
168                 }
169
170         internal void RegisterFrameComponent(NUIFrameComponent nuiFrameComponent)
171         {
172             _frameComponentList.Add(nuiFrameComponent);
173         }
174
175         internal int GetFrameComponentCount()
176         {
177             return _frameComponentList.Count;
178         }
179
180
181     }
182
183
184 }