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