Revert "[NUI] Fix Dispose warning error[CA1001] (#2130)"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Accessibility / Accessibility.cs
1 /*
2  * Copyright(c) 2019 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 global::System;
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21 using Tizen.NUI.BaseComponents;
22 #if (NUI_DEBUG_ON)
23 using tlog = Tizen.Log;
24 #endif
25
26 namespace Tizen.NUI.Accessibility
27 {
28     /// <summary>
29     /// Accessibility provides Dali-ATSPI interface which has funtionality of Screen-Reader and general accessibility
30     /// </summary>
31     // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
32     [EditorBrowsable(EditorBrowsableState.Never)]
33     public class Accessibility
34     {
35         #region Constructor, Distructor, Dispose
36         private Accessibility()
37         {
38             dummy = new View();
39             dummy.Name = "dali-atspi-singleton";
40         }
41         /// <summary>
42         /// destructor. This is HiddenAPI. recommended not to use in public.
43         /// </summary>
44         ~Accessibility()
45         {
46         }
47         #endregion Constructor, Distructor, Dispose
48
49
50         #region Property
51         /// <summary>
52         /// Instance for singleton
53         /// </summary>
54         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         public static Accessibility Instance
57         {
58             get => _accessibility;
59         }
60         #endregion Property
61
62
63         #region Method
64         /// <summary>
65         /// Get the current status
66         /// </summary>
67         /// <returns>Current enabled status</returns>
68         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
69         [EditorBrowsable(EditorBrowsableState.Never)]
70         static public bool GetStatus()
71         {
72             return true;
73         }
74
75         /// <summary>
76         /// Start to speak
77         /// </summary>
78         /// <param name="sentence">Content to be spoken</param>
79         /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
80         /// <returns></returns>
81         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
82         [EditorBrowsable(EditorBrowsableState.Never)]
83         public bool Say(string sentence, bool discardable)
84         {
85             IntPtr callbackIntPtr = IntPtr.Zero;
86             if (_sayFinishedEventHandler != null)
87             {
88                 callback = _sayFinishedEventCallback;
89                 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
90             }
91             bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
92             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93             return ret;
94         }
95
96         /// <summary>
97         /// To make Say be paused or resumed
98         /// </summary>
99         /// <param name="pause">true to be paused, false to be resumed</param>
100         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
101         [EditorBrowsable(EditorBrowsableState.Never)]
102         public void PauseResume(bool pause)
103         {
104             Interop.Accessibility.accessibility_pause_resume(View.getCPtr(dummy), pause);
105             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
106         }
107         #endregion Method
108
109
110         #region Event, Enum, Struct, ETC
111         /// <summary>
112         ///  Say Finished event arguments
113         /// </summary>
114         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
115         [EditorBrowsable(EditorBrowsableState.Never)]
116         public class SayFinishedEventArgs : EventArgs
117         {
118             /// <summary>
119             /// The state of Say finished
120             /// </summary>
121             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
122             [EditorBrowsable(EditorBrowsableState.Never)]
123             public SayFinishedStates State
124             {
125                 private set;
126                 get;
127             }
128
129             internal SayFinishedEventArgs(int result)
130             {
131                 State = (SayFinishedStates)(result);
132                 tlog.Fatal(tag, $"SayFinishedEventArgs Constructor! State={State}");
133             }
134         }
135
136         /// <summary>
137         /// Enum of Say finished event argument status
138         /// </summary>
139         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
140         [EditorBrowsable(EditorBrowsableState.Never)]
141         public enum SayFinishedStates
142         {
143             /// <summary>
144             /// Invalid
145             /// </summary>
146             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
147             [EditorBrowsable(EditorBrowsableState.Never)]
148             Invalid = -1,
149             /// <summary>
150             /// Cancelled
151             /// </summary>
152             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
153             [EditorBrowsable(EditorBrowsableState.Never)]
154             Cancelled = 1,
155             /// <summary>
156             /// Stopped
157             /// </summary>
158             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
159             [EditorBrowsable(EditorBrowsableState.Never)]
160             Stopped = 2,
161             /// <summary>
162             /// Skipped
163             /// </summary>
164             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
165             [EditorBrowsable(EditorBrowsableState.Never)]
166             Skipped = 3
167         }
168
169         /// <summary>
170         /// When Say is finished, this event is triggered
171         /// </summary>
172         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
173         [EditorBrowsable(EditorBrowsableState.Never)]
174         public event EventHandler<SayFinishedEventArgs> SayFinished
175         {
176             add => _sayFinishedEventHandler += value;
177             remove => _sayFinishedEventHandler -= value;
178         }
179         #endregion Event, Enum, Struct, ETC
180
181
182         #region Internal
183         internal void PauseResume(View target, bool pause)
184         {
185             Interop.Accessibility.accessibility_pause_resume(View.getCPtr(target), pause);
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187         }
188
189         internal bool Say(View target, string sentence, bool discardable)
190         {
191             IntPtr callbackIntPtr = IntPtr.Zero;
192             if (_sayFinishedEventHandler != null)
193             {
194                 callback = _sayFinishedEventCallback;
195                 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
196             }
197             bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199             return ret;
200         }
201         #endregion Internal
202
203
204         #region Private
205         private static readonly Accessibility _accessibility = new Accessibility();
206
207         private event EventHandler<SayFinishedEventArgs> _sayFinishedEventHandler;
208
209         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
210         private delegate void _sayFinishedEventCallbackType(int result);
211
212         private _sayFinishedEventCallbackType callback = null;
213
214         private void _sayFinishedEventCallback(int result)
215         {
216             tlog.Fatal(tag, $"_sayFinishedEventCallback(res={result}) called!");
217             _sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
218         }
219
220         private View dummy;
221
222         private static string tag = "NUITEST";
223         #endregion Private
224     }
225 }