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