2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
19 using System.Threading.Tasks;
21 namespace ElmSharp.Accessible
24 /// Enumeration for ReadingStatus.
26 public enum ReadingStatus
47 /// AccessibleUtil provides a method to set the reading information.
49 public static class AccessibleUtil
52 static void AtspiSignalCallback(IntPtr data, string say_signal)
54 GCHandle gch = GCHandle.FromIntPtr(data);
55 TaskCompletionSource<ReadingStatus> tcs = (TaskCompletionSource<ReadingStatus>) gch.Target;
56 if (say_signal.Equals("ReadingCancelled"))
58 tcs.SetResult(ReadingStatus.Cancelled);
60 else if (say_signal.Equals("ReadingStopped"))
62 tcs.SetResult(ReadingStatus.Stoppped);
64 else if (say_signal.Equals("ReadingSkipped"))
66 tcs.SetResult(ReadingStatus.Skipped);
70 tcs.SetException(new InvalidOperationException("unknown signal : " + say_signal));
77 /// Reads given text by screen reader.
79 /// <param name="text">The reading text.</param>
80 /// <param name="discardable">If true, reading can be discarded by subsequent reading requests, if false the reading must finish before next reading request can be started.</param>
81 /// <returns>Return a task with reading status.</returns>
82 public static Task<ReadingStatus> Say(string text, bool discardable)
84 var tcs = new TaskCompletionSource<ReadingStatus>();
85 GCHandle gch = GCHandle.Alloc(tcs);
86 Interop.Elementary.elm_atspi_bridge_utils_say(text, discardable, AtspiSignalCallback, GCHandle.ToIntPtr(gch));