[NUI] Format all files
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Accessibility / Accessibility.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.ComponentModel;
20 using System.Runtime.InteropServices;
21 using Tizen.NUI.BaseComponents;
22 using System.Diagnostics.CodeAnalysis;
23 #if (NUI_DEBUG_ON)
24 using tlog = Tizen.Log;
25 #endif
26
27 namespace Tizen.NUI.Accessibility
28 {
29     /// <summary>
30     /// Accessibility provides Dali-ATSPI interface which has funtionality of Screen-Reader and general accessibility
31     /// </summary>
32     // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
33     [SuppressMessage("Microsoft.Design", "CA1724: Type names should not match namespaces")]
34     [SuppressMessage("Microsoft.Design", "CA1001:Types that own disposable fields should be disposable", Justification = "This is a singleton class and is not disposed")]
35     [EditorBrowsable(EditorBrowsableState.Never)]
36     public class Accessibility
37     {
38         #region Constructor, Distructor, Dispose
39         private Accessibility()
40         {
41             dummy = new View();
42             dummy.Name = "dali-atspi-singleton";
43         }
44         /// <summary>
45         /// destructor. This is HiddenAPI. recommended not to use in public.
46         /// </summary>
47         ~Accessibility()
48         {
49             Tizen.Log.Debug("NUI", $"Accessibility is destroyed\n");
50         }
51         #endregion Constructor, Distructor, Dispose
52
53
54         #region Property
55         /// <summary>
56         /// Instance for singleton
57         /// </summary>
58         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
59         [EditorBrowsable(EditorBrowsableState.Never)]
60         public static Accessibility Instance
61         {
62             get => accessibility;
63         }
64         #endregion Property
65
66
67         #region Method
68         /// <summary>
69         /// Get the current status
70         /// </summary>
71         /// <returns>Current enabled status</returns>
72         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         static public bool GetStatus()
75         {
76             return true;
77         }
78
79         /// <summary>
80         /// Start to speak
81         /// </summary>
82         /// <param name="sentence">Content to be spoken</param>
83         /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
84         /// <returns></returns>
85         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
86         [EditorBrowsable(EditorBrowsableState.Never)]
87         public bool Say(string sentence, bool discardable)
88         {
89             IntPtr callbackIntPtr = IntPtr.Zero;
90             if (sayFinishedEventHandler != null)
91             {
92                 callback = SayFinishedEventCallback;
93                 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
94             }
95             bool ret = Interop.Accessibility.Say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
96             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97             return ret;
98         }
99
100         /// <summary>
101         /// To make Say be paused or resumed
102         /// </summary>
103         /// <param name="pause">true to be paused, false to be resumed</param>
104         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public void PauseResume(bool pause)
107         {
108             Interop.Accessibility.PauseResume(View.getCPtr(dummy), pause);
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110         }
111         #endregion Method
112
113
114         #region Event, Enum, Struct, ETC
115         /// <summary>
116         ///  Say Finished event arguments
117         /// </summary>
118         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
119         [EditorBrowsable(EditorBrowsableState.Never)]
120         public class SayFinishedEventArgs : EventArgs
121         {
122             /// <summary>
123             /// The state of Say finished
124             /// </summary>
125             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
126             [EditorBrowsable(EditorBrowsableState.Never)]
127             public SayFinishedState State
128             {
129                 private set;
130                 get;
131             }
132
133             internal SayFinishedEventArgs(int result)
134             {
135                 State = (SayFinishedState)(result);
136                 tlog.Fatal(tag, $"SayFinishedEventArgs Constructor! State={State}");
137             }
138         }
139
140         /// <summary>
141         /// Enum of Say finished event argument status
142         /// </summary>
143         [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState instead!")]
144         [EditorBrowsable(EditorBrowsableState.Never)]
145         public enum SayFinishedStates
146         {
147             /// <summary>
148             /// Invalid
149             /// </summary>
150             [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState.Invalid instead!")]
151             [EditorBrowsable(EditorBrowsableState.Never)]
152             Invalid = -1,
153             /// <summary>
154             /// Cancelled
155             /// </summary>
156             [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState.Invalid instead!")]
157             [EditorBrowsable(EditorBrowsableState.Never)]
158             Cancelled = 1,
159             /// <summary>
160             /// Stopped
161             /// </summary>
162             [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState.Invalid instead!")]
163             [EditorBrowsable(EditorBrowsableState.Never)]
164             Stopped = 2,
165             /// <summary>
166             /// Skipped
167             /// </summary>
168             [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState.Invalid instead!")]
169             [EditorBrowsable(EditorBrowsableState.Never)]
170             Skipped = 3
171         }
172
173         /// <summary>
174         /// Enum of Say finished event argument status
175         /// </summary>
176         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
177         [EditorBrowsable(EditorBrowsableState.Never)]
178         public enum SayFinishedState
179         {
180             /// <summary>
181             /// Invalid
182             /// </summary>
183             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
184             [EditorBrowsable(EditorBrowsableState.Never)]
185             Invalid = -1,
186             /// <summary>
187             /// Cancelled
188             /// </summary>
189             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
190             [EditorBrowsable(EditorBrowsableState.Never)]
191             Cancelled = 1,
192             /// <summary>
193             /// Stopped
194             /// </summary>
195             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
196             [EditorBrowsable(EditorBrowsableState.Never)]
197             Stopped = 2,
198             /// <summary>
199             /// Skipped
200             /// </summary>
201             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
202             [EditorBrowsable(EditorBrowsableState.Never)]
203             Skipped = 3,
204             /// <summary>
205             /// Paused
206             /// </summary>
207             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
208             [EditorBrowsable(EditorBrowsableState.Never)]
209             Paused = 4,
210             /// <summary>
211             /// Resumed
212             /// </summary>
213             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
214             [EditorBrowsable(EditorBrowsableState.Never)]
215             Resumed = 5
216         }
217
218         /// <summary>
219         /// When Say is finished, this event is triggered
220         /// </summary>
221         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
222         [EditorBrowsable(EditorBrowsableState.Never)]
223         public event EventHandler<SayFinishedEventArgs> SayFinished
224         {
225             add => sayFinishedEventHandler += value;
226             remove => sayFinishedEventHandler -= value;
227         }
228         #endregion Event, Enum, Struct, ETC
229
230
231         #region Internal
232         internal void PauseResume(View target, bool pause)
233         {
234             Interop.Accessibility.PauseResume(View.getCPtr(target), pause);
235             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236         }
237
238         internal bool Say(View target, string sentence, bool discardable)
239         {
240             IntPtr callbackIntPtr = IntPtr.Zero;
241             if (sayFinishedEventHandler != null)
242             {
243                 callback = SayFinishedEventCallback;
244                 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
245             }
246             bool ret = Interop.Accessibility.Say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248             return ret;
249         }
250         #endregion Internal
251
252
253         #region Private
254         private static readonly Accessibility accessibility = new Accessibility();
255
256         private event EventHandler<SayFinishedEventArgs> sayFinishedEventHandler;
257
258         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
259         private delegate void SayFinishedEventCallbackType(int result);
260
261         private SayFinishedEventCallbackType callback = null;
262
263         private void SayFinishedEventCallback(int result)
264         {
265             tlog.Fatal(tag, $"sayFinishedEventCallback(res={result}) called!");
266             sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
267         }
268
269         private View dummy;
270
271         private static string tag = "NUITEST";
272         #endregion Private
273     }
274 }