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