[NUI] Change all CallingConvention to `Cdecl`
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Accessibility / Accessibility.cs
index 32db140..77ac711 100755 (executable)
@@ -30,35 +30,38 @@ namespace Tizen.NUI.Accessibility
     [SuppressMessage("Microsoft.Design", "CA1724: Type names should not match namespaces")]
     [SuppressMessage("Microsoft.Design", "CA1001:Types that own disposable fields should be disposable", Justification = "This is a singleton class and is not disposed")]
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class Accessibility
+    public static class Accessibility
     {
-        #region Constructor, Destructor, Dispose
-        private Accessibility()
+        #region Constructor
+        [SuppressMessage("Microsoft.Performance", "CA1810: Initialize reference type static fields inline", Justification = "Need to call native code")]
+        static Accessibility()
         {
-            dummy = new View();
-            dummy.Name = "dali-atspi-singleton";
-        }
-        /// <summary>
-        /// destructor. This is HiddenAPI. recommended not to use in public.
-        /// </summary>
-        ~Accessibility()
-        {
-            Tizen.Log.Debug("NUI", $"Accessibility is destroyed\n");
-        }
-        #endregion Constructor, Destructor, Dispose
+            enabledSignalHandler = () =>
+            {
+                Enabled?.Invoke(typeof(Accessibility), EventArgs.Empty);
+            };
 
+            disabledSignalHandler = () =>
+            {
+                Disabled?.Invoke(typeof(Accessibility), EventArgs.Empty);
+            };
 
-        #region Property
-        /// <summary>
-        /// Instance for singleton
-        /// </summary>
-        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public static Accessibility Instance
-        {
-            get => accessibility;
+            screenReaderEnabledSignalHandler = () =>
+            {
+                ScreenReaderEnabled?.Invoke(typeof(Accessibility), EventArgs.Empty);
+            };
+
+            screenReaderDisabledSignalHandler = () =>
+            {
+                ScreenReaderDisabled?.Invoke(typeof(Accessibility), EventArgs.Empty);
+            };
+
+            Interop.Accessibility.RegisterEnabledDisabledSignalHandler(enabledSignalHandler, disabledSignalHandler);
+            Interop.Accessibility.RegisterScreenReaderEnabledDisabledSignalHandler(screenReaderEnabledSignalHandler, screenReaderDisabledSignalHandler);
         }
+        #endregion Constructor
 
+        #region Property
         /// <summary>
         /// Flag to check whether the state of Accessibility is enabled or not.
         /// </summary>
@@ -75,21 +78,25 @@ namespace Tizen.NUI.Accessibility
             }
         }
 
-        #endregion Property
-
-
-        #region Method
         /// <summary>
-        /// Get the current status
+        /// Flag to check whether the state of Screen Reader is enabled or not.
         /// </summary>
-        /// <returns>Current enabled status</returns>
-        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        /// <remarks>
+        /// Getter returns true if Screen Reader is enabled, false otherwise.
+        /// </remarks>
+        /// This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        static public bool GetStatus()
+        public static bool IsScreenReaderEnabled
         {
-            return true;
+            get
+            {
+                return (bool)Interop.Accessibility.IsScreenReaderEnabled();
+            }
         }
 
+        #endregion Property
+
+        #region Method
         /// <summary>
         /// Start to speak
         /// </summary>
@@ -98,15 +105,10 @@ namespace Tizen.NUI.Accessibility
         /// <returns></returns>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool Say(string sentence, bool discardable)
+        public static bool Say(string sentence, bool discardable)
         {
-            IntPtr callbackIntPtr = IntPtr.Zero;
-            if (sayFinishedEventHandler != null)
-            {
-                callback = SayFinishedEventCallback;
-                callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
-            }
-            bool ret = Interop.Accessibility.Say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
+            bool ret = Interop.Accessibility.Say(sentence, discardable, Marshal.GetFunctionPointerForDelegate<Delegate>(callback));
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -117,9 +119,9 @@ namespace Tizen.NUI.Accessibility
         /// <param name="pause">true to be paused, false to be resumed</param>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void PauseResume(bool pause)
+        public static void PauseResume(bool pause)
         {
-            Interop.Accessibility.PauseResume(View.getCPtr(dummy), pause);
+            Interop.Accessibility.PauseResume(pause);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -129,9 +131,9 @@ namespace Tizen.NUI.Accessibility
         /// <param name="alsoNonDiscardable">whether to cancel non-discardable readings as well</param>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void StopReading(bool alsoNonDiscardable)
+        public static void StopReading(bool alsoNonDiscardable)
         {
-            Interop.Accessibility.StopReading(View.getCPtr(dummy), alsoNonDiscardable);
+            Interop.Accessibility.StopReading(alsoNonDiscardable);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -141,9 +143,9 @@ namespace Tizen.NUI.Accessibility
         /// <param name="suppress">whether to suppress reading of screen-reader</param>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool SuppressScreenReader(bool suppress)
+        public static bool SuppressScreenReader(bool suppress)
         {
-            bool ret = Interop.Accessibility.SuppressScreenReader(View.getCPtr(dummy), suppress);
+            bool ret = Interop.Accessibility.SuppressScreenReader(suppress);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -180,7 +182,7 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View GetHighlightFrameView()
+        public static View GetHighlightFrameView()
         {
             var ptr = Interop.ControlDevel.DaliAccessibilityAccessibleGetHighlightActor();
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -194,7 +196,7 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void SetHighlightFrameView(View view)
+        public static void SetHighlightFrameView(View view)
         {
             Interop.ControlDevel.DaliAccessibilityAccessibleSetHighlightActor(View.getCPtr(view));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -205,13 +207,13 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View GetCurrentlyHighlightedView()
+        public static View GetCurrentlyHighlightedView()
         {
             var ptr = Interop.ControlDevel.DaliAccessibilityAccessibleGetCurrentlyHighlightedActor();
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            if (ptr == IntPtr.Zero)
-                return null;
-            return new View(ptr, true);
+
+            return dummyHandle.GetInstanceSafely<View>(ptr);
         }
 
         /// <summary>
@@ -219,12 +221,11 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool ClearCurrentlyHighlightedView()
+        public static bool ClearCurrentlyHighlightedView()
         {
-            using (View view = GetCurrentlyHighlightedView())
-            {
-                return view?.ClearAccessibilityHighlight() ?? false;
-            }
+            var view = GetCurrentlyHighlightedView();
+
+            return view?.ClearAccessibilityHighlight() ?? false;
         }
         #endregion Method
 
@@ -280,53 +281,60 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public event EventHandler<SayFinishedEventArgs> SayFinished
-        {
-            add => sayFinishedEventHandler += value;
-            remove => sayFinishedEventHandler -= value;
-        }
-        #endregion Event, Enum, Struct, ETC
+        public static event EventHandler<SayFinishedEventArgs> SayFinished;
 
+        /// <summary>
+        /// Triggered whenever the value of IsEnabled would change from false to true
+        /// </summary>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static event EventHandler Enabled;
 
-        #region Internal
-        internal void PauseResume(View target, bool pause)
-        {
-            Interop.Accessibility.PauseResume(View.getCPtr(target), pause);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
+        /// <summary>
+        /// Triggered whenever the value of IsEnabled would change from true to false
+        /// </summary>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static event EventHandler Disabled;
 
-        internal bool Say(View target, string sentence, bool discardable)
-        {
-            IntPtr callbackIntPtr = IntPtr.Zero;
-            if (sayFinishedEventHandler != null)
-            {
-                callback = SayFinishedEventCallback;
-                callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
-            }
-            bool ret = Interop.Accessibility.Say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
-        }
-        #endregion Internal
+        /// <summary>
+        /// Triggered whenever the value of IsScreenReaderEnabled would change from false to true
+        /// </summary>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static event EventHandler ScreenReaderEnabled;
 
+        /// <summary>
+        /// Triggered whenever the value of IsScreenReaderEnabled would change from true to false
+        /// </summary>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static event EventHandler ScreenReaderDisabled;
 
-        #region Private
-        private static readonly Accessibility accessibility = new Accessibility();
+        #endregion Event, Enum, Struct, ETC
 
-        private event EventHandler<SayFinishedEventArgs> sayFinishedEventHandler;
+        #region Private
 
-        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void SayFinishedEventCallbackType(int result);
 
-        private SayFinishedEventCallbackType callback = null;
+        private static SayFinishedEventCallbackType callback = SayFinishedEventCallback;
+
+        private static Interop.Accessibility.EnabledDisabledSignalHandler enabledSignalHandler = null;
+
+        private static Interop.Accessibility.EnabledDisabledSignalHandler disabledSignalHandler = null;
+
+        private static Interop.Accessibility.EnabledDisabledSignalHandler screenReaderEnabledSignalHandler = null;
+
+        private static Interop.Accessibility.EnabledDisabledSignalHandler screenReaderDisabledSignalHandler = null;
 
-        private void SayFinishedEventCallback(int result)
+        private static void SayFinishedEventCallback(int result)
         {
             NUILog.Debug($"sayFinishedEventCallback(res={result}) called!");
-            sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
+            SayFinished?.Invoke(typeof(Accessibility), new SayFinishedEventArgs(result));
         }
 
-        private View dummy;
+        private static BaseHandle dummyHandle = new BaseHandle();
 
         #endregion Private
     }