Follow formatting NUI
[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.delete_ComponentApplication(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.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.new_ComponentApplication__SWIG_1(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.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                 lock (this)
96                 {
97                     // Restricted to only one listener
98                     if (_applicationCreateNativeEventHandler == null)
99                     {
100                         _applicationCreateNativeEventHandler += value;
101
102                         _applicationCreateNativeEventCallbackDelegate = new NUIComponentApplicationCreatenativeEventCallbackDelegate(OnApplicationCreateNative);
103                         Connect(_applicationCreateNativeEventCallbackDelegate);
104                     }
105                 }
106             }
107
108             remove
109             {
110                 lock (this)
111                 {
112                     if (_applicationCreateNativeEventHandler != null)
113                     {
114                         Disconnect(_applicationCreateNativeEventCallbackDelegate);
115                     }
116
117                     _applicationCreateNativeEventHandler -= value;
118                 }
119             }
120         }
121
122
123         public void Connect(System.Delegate func)
124         {
125             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func);
126             {
127                 Interop.ComponentApplication.ComponentApplication_CreateNativeSignal_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
128                 if (NDalicPINVOKE.SWIGPendingException.Pending)
129                 {
130                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131                 }
132             }
133         }
134
135         public void Disconnect(System.Delegate func)
136         {
137             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
138             {
139                 Interop.ComponentApplication.ComponentApplication_CreateNativeSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
140                 if (NDalicPINVOKE.SWIGPendingException.Pending)
141                 {
142                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143                 }
144             }
145         }
146
147         internal ApplicationSignal CreateNativeSignal()
148         {
149             ApplicationSignal ret = new ApplicationSignal(Interop.ComponentApplication.ComponentApplication_CreateNativeSignal(swigCPtr), false);
150             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151             return ret;
152         }
153
154         // Callback for Application InitSignal
155         private IntPtr OnApplicationCreateNative()
156         {
157             IntPtr handle = IntPtr.Zero;
158
159             if (_applicationCreateNativeEventHandler != null)
160             {
161                 handle = _applicationCreateNativeEventHandler.Invoke();
162             }
163
164             return handle;
165         }
166
167     }
168
169
170 }