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