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