Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / PreFocusChangeSignal.cs
1 /*
2  * Copyright (c) 2017 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 Tizen.NUI.BaseComponents;
19
20 using System;
21
22 namespace Tizen.NUI
23 {
24
25     internal delegate IntPtr SwigDelegatePreFocusChangeSignal(IntPtr current, IntPtr proposed, View.FocusDirection direction);
26
27     internal class PreFocusChangeSignal : global::System.IDisposable
28     {
29         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30         protected bool swigCMemOwn;
31
32         internal PreFocusChangeSignal(global::System.IntPtr cPtr, bool cMemoryOwn)
33         {
34             swigCMemOwn = cMemoryOwn;
35             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36         }
37
38         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PreFocusChangeSignal obj)
39         {
40             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
41         }
42
43         //A Flag to check who called Dispose(). (By User or DisposeQueue)
44         private bool isDisposeQueued = false;
45         //A Flat to check if it is already disposed.
46         protected bool disposed = false;
47
48
49         ~PreFocusChangeSignal()
50         {
51             if (!isDisposeQueued)
52             {
53                 isDisposeQueued = true;
54                 DisposeQueue.Instance.Add(this);
55             }
56         }
57
58         public void Dispose()
59         {
60             //Throw excpetion if Dispose() is called in separate thread.
61             if (!Window.IsInstalled())
62             {
63                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
64             }
65
66             if (isDisposeQueued)
67             {
68                 Dispose(DisposeTypes.Implicit);
69             }
70             else
71             {
72                 Dispose(DisposeTypes.Explicit);
73                 System.GC.SuppressFinalize(this);
74             }
75         }
76
77         protected virtual void Dispose(DisposeTypes type)
78         {
79             if (disposed)
80             {
81                 return;
82             }
83
84             if (type == DisposeTypes.Explicit)
85             {
86                 //Called by User
87                 //Release your own managed resources here.
88                 //You should release all of your own disposable objects here.
89
90             }
91
92             //Release your own unmanaged resources here.
93             //You should not access any managed member here except static instance.
94             //because the execution order of Finalizes is non-deterministic.
95
96             if (swigCPtr.Handle != global::System.IntPtr.Zero)
97             {
98                 if (swigCMemOwn)
99                 {
100                     swigCMemOwn = false;
101                     NDalicManualPINVOKE.delete_PreFocusChangeSignal(swigCPtr);
102                 }
103                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
104             }
105
106             disposed = true;
107         }
108
109         public bool Empty()
110         {
111             bool ret = NDalicManualPINVOKE.PreFocusChangeSignal_Empty(swigCPtr);
112             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113             return ret;
114         }
115
116         public uint GetConnectionCount()
117         {
118             uint ret = NDalicManualPINVOKE.PreFocusChangeSignal_GetConnectionCount(swigCPtr);
119             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120             return ret;
121         }
122
123         public void Connect(FocusManager.PreFocusChangeEventCallback func)
124         {
125             NDalicManualPINVOKE.PreFocusChangeSignal_Connect(swigCPtr, func);
126             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127         }
128
129         public void Disconnect(System.Delegate func)
130         {
131             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func);
132             {
133                 NDalicManualPINVOKE.PreFocusChangeSignal_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
134                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
135             }
136         }
137
138         public View Emit(View arg1, View arg2, View.FocusDirection arg3)
139         {
140             View ret = new View(NDalicManualPINVOKE.PreFocusChangeSignal_Emit(swigCPtr, View.getCPtr(arg1), View.getCPtr(arg2), (int)arg3), true);
141             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142             return ret;
143         }
144
145         public PreFocusChangeSignal() : this(NDalicManualPINVOKE.new_PreFocusChangeSignal(), true)
146         {
147             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148         }
149
150     }
151
152 }