/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Runtime.InteropServices; using System.Threading.Tasks; namespace ElmSharp.Accessible { /// /// Enumeration for ReadingStatus. /// public enum ReadingStatus { /// /// Unknown status /// Unknown, /// /// Cancelled status /// Cancelled, /// /// Stopped status /// Stoppped, /// /// Skipped status /// Skipped } /// /// AccessibleUtil provides a method to set the reading information. /// public static class AccessibleUtil { static void AtspiSignalCallback(IntPtr data, string say_signal) { GCHandle gch = GCHandle.FromIntPtr(data); TaskCompletionSource tcs = (TaskCompletionSource) gch.Target; if (say_signal.Equals("ReadingCancelled")) { tcs.SetResult(ReadingStatus.Cancelled); } else if (say_signal.Equals("ReadingStopped")) { tcs.SetResult(ReadingStatus.Stoppped); } else if (say_signal.Equals("ReadingSkipped")) { tcs.SetResult(ReadingStatus.Skipped); } else { tcs.SetException(new InvalidOperationException("unknown signal : " + say_signal)); } gch.Free(); } /// /// Reads given text by screen reader. /// /// The reading text. /// If true, reading can be discarded by subsequent reading requests, if false the reading must finish before next reading request can be started. /// Return a task with reading status. public static Task Say(string text, bool discardable) { var tcs = new TaskCompletionSource(); GCHandle gch = GCHandle.Alloc(tcs); Interop.Elementary.elm_atspi_bridge_utils_say(text, discardable, AtspiSignalCallback, GCHandle.ToIntPtr(gch)); return tcs.Task; } } }