/*
* 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 the ReadingStatus.
///
/// preview
public enum ReadingStatus
{
///
/// Unknown status.
///
Unknown,
///
/// Cancelled status.
///
Cancelled,
///
/// Stopped status.
///
Stoppped,
///
/// Skipped status.
///
Skipped
}
///
/// AccessibleUtil provides a method to set the reading information.
///
/// preview
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 the given text by a screen reader.
///
/// The reading text.
/// If true, reading can be discarded by subsequent reading requests. If false, reading must be finished before the next reading request can be started.
/// Return a task with the reading status.
/// preview
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;
}
}
}