From fb10c2494fa1da0d0837a23bf80c05fc7e136858 Mon Sep 17 00:00:00 2001 From: Inhong Date: Fri, 11 Jan 2019 15:57:29 +0900 Subject: [PATCH] [Inputmethod] Add missing APIs (#647) --- .../Interop/Interop.InputMethod.cs | 27 +++ .../Tizen.Uix.InputMethod/InputMethodEditor.cs | 188 +++++++++++++++++++++ .../MimeTypeUpdateRequestedEventArgs.cs | 37 ++++ .../PredictionHintDataUpdatedEventArgs.cs | 44 +++++ .../PredictionHintUpdatedEventArgs.cs | 37 ++++ 5 files changed, 333 insertions(+) create mode 100755 src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/MimeTypeUpdateRequestedEventArgs.cs create mode 100755 src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/PredictionHintDataUpdatedEventArgs.cs create mode 100755 src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/PredictionHintUpdatedEventArgs.cs diff --git a/src/Tizen.Uix.InputMethod/Interop/Interop.InputMethod.cs b/src/Tizen.Uix.InputMethod/Interop/Interop.InputMethod.cs index 92e528d..99d0be5 100755 --- a/src/Tizen.Uix.InputMethod/Interop/Interop.InputMethod.cs +++ b/src/Tizen.Uix.InputMethod/Interop/Interop.InputMethod.cs @@ -273,6 +273,24 @@ internal static partial class Interop [DllImport(Libraries.InputMethod, EntryPoint = "ime_update_input_panel_event")] internal static extern ErrorCode ImeUpdateInputPanelEvent(ImeEventType type, uint value); + [DllImport(Libraries.InputMethod, EntryPoint = "ime_get_selected_text")] + internal static extern ErrorCode ImeGetSelectedText(out IntPtr text); + + [DllImport(Libraries.InputMethod, EntryPoint = "ime_event_set_prediction_hint_set_cb")] + internal static extern ErrorCode ImeEventSetPredictionHintSetCb(ImePredictionHintSetCb callbackFunction, IntPtr userData); + + [DllImport(Libraries.InputMethod, EntryPoint = "ime_event_set_prediction_hint_data_set_cb")] + internal static extern ErrorCode ImeEventSetPredictionHintDataSetCb(ImePredictionHintDataSetCb callbackFunction, IntPtr userData); + + [DllImport(Libraries.InputMethod, EntryPoint = "ime_event_set_mime_type_set_request_cb")] + internal static extern ErrorCode ImeEventSetMimeTypeSetRequestCb(ImeMimeTypeSetRequestCb callbackFunction, IntPtr userData); + + [DllImport(Libraries.InputMethod, EntryPoint = "ime_send_private_command")] + internal static extern ErrorCode ImeSendPrivateCommand(string command); + + [DllImport(Libraries.InputMethod, EntryPoint = "ime_commit_content")] + internal static extern ErrorCode ImeCommitContent(string content, string description, string mimeType); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void ImeCreateCb(IntPtr userData); @@ -335,5 +353,14 @@ internal static partial class Interop [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void ImeAccessibilityStateChangedCb(bool state, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ImePredictionHintSetCb(IntPtr predictionHint, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ImePredictionHintDataSetCb(IntPtr key, IntPtr keyValue, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ImeMimeTypeSetRequestCb(IntPtr mimeType, IntPtr userData); } } diff --git a/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/InputMethodEditor.cs b/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/InputMethodEditor.cs index 2277209..f02f687 100755 --- a/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/InputMethodEditor.cs +++ b/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/InputMethodEditor.cs @@ -989,6 +989,12 @@ namespace Tizen.Uix.InputMethod private static ImeRotationChangedCb _imeRotationChangedDelegate; private static event EventHandler _accessibilityStateChanged; private static ImeAccessibilityStateChangedCb _imeAccessibilityStateChangedDelegate; + private static event EventHandler _predictionHintUpdated; + private static ImePredictionHintSetCb _imePredictionHintSetDelegate; + private static event EventHandler _predictionHintDataUpdated; + private static ImePredictionHintDataSetCb _imePredictionHintDataSetDelegate; + private static event EventHandler _mimeTypeUpdateRequested; + private static ImeMimeTypeSetRequestCb _imeMimeTypeSetRequestDelegate; private static ImeLanguageRequestedCb _imeLanguageRequestedDelegate; private static OutAction _languageRequestedDelegate; private static BoolAction _processKeyDelagate; @@ -2209,5 +2215,187 @@ namespace Tizen.Uix.InputMethod throw InputMethodExceptionFactory.CreateException(error); } } + + /// + /// Gets the selected text synchronously. + /// + /// + /// http://tizen.org/privilege/ime + /// + /// The selected text. + /// + /// This can occur due to the following reasons: + /// 1) The application does not have the privilege to call this function. + /// 2) The IME main loop has not started yet. + /// 3) Invalid parameter. + /// + /// 6 + public static string GetSelectedText() + { + IntPtr txt; + ErrorCode error = ImeGetSelectedText(out txt); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetSelectedText Failed with error " + error); + throw InputMethodExceptionFactory.CreateException(error); + } + return Marshal.PtrToStringAnsi(txt); + } + + /// + /// Called to set the prediction hint string to deliver to the input panel. + /// + /// 6 + public static event EventHandler PredictionHintUpdated + { + add + { + lock (thisLock) + { + if (_imePredictionHintSetDelegate == null) + { + _imePredictionHintSetDelegate = (IntPtr predictionHint, IntPtr userData) => + { + PredictionHintUpdatedEventArgs args = new PredictionHintUpdatedEventArgs(Marshal.PtrToStringAnsi(predictionHint)); + _predictionHintUpdated?.Invoke(null, args); + }; + ErrorCode error = ImeEventSetPredictionHintSetCb(_imePredictionHintSetDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add PredictionHintUpdated Failed with error " + error); + } + } + _predictionHintUpdated += value; + } + } + remove + { + lock (thisLock) + { + _predictionHintUpdated -= value; + } + } + } + + /// + /// Called to set the prediction hint key and value to deliver to the input panel. + /// + /// 6 + public static event EventHandler PredictionHintDataUpdated + { + add + { + lock (thisLock) + { + if (_imePredictionHintDataSetDelegate == null) + { + _imePredictionHintDataSetDelegate = (IntPtr key, IntPtr keyValue, IntPtr userData) => + { + PredictionHintDataUpdatedEventArgs args = new PredictionHintDataUpdatedEventArgs(Marshal.PtrToStringAnsi(key), Marshal.PtrToStringAnsi(keyValue)); + _predictionHintDataUpdated?.Invoke(null, args); + }; + + ErrorCode error = ImeEventSetPredictionHintDataSetCb(_imePredictionHintDataSetDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add PredictionHintDataUpdated Failed with error " + error); + } + } + _predictionHintDataUpdated += value; + } + } + remove + { + lock (thisLock) + { + _predictionHintDataUpdated -= value; + } + } + } + + /// + /// Called when an associated text input UI control requests the text entry to set the MIME type. + /// + /// 6 + public static event EventHandler MimeTypeUpdateRequested + { + add + { + lock (thisLock) + { + if (_imeMimeTypeSetRequestDelegate == null) + { + _imeMimeTypeSetRequestDelegate = (IntPtr mimeType, IntPtr userData) => + { + MimeTypeUpdateRequestedEventArgs args = new MimeTypeUpdateRequestedEventArgs(Marshal.PtrToStringAnsi(mimeType)); + _mimeTypeUpdateRequested?.Invoke(null, args); + }; + ErrorCode error = ImeEventSetMimeTypeSetRequestCb(_imeMimeTypeSetRequestDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add MimeTypeUpdateRequested Failed with error " + error); + } + } + _mimeTypeUpdateRequested += value; + } + } + remove + { + lock (thisLock) + { + _mimeTypeUpdateRequested -= value; + } + } + } + + /// + /// Sends a private command to the associated text input UI control. + /// + /// + /// http://tizen.org/privilege/ime + /// + /// The UTF-8 string to be sent. + /// + /// This can occur due to the following reasons: + /// 1) The application does not have the privilege to call this function. + /// 2) The IME main loop has not started yet. + /// 3) Invalid parameter. + /// + /// 6 + public static void SendPrivateCommand(string command) + { + ErrorCode error = ImeSendPrivateCommand(command); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SendPrivateCommand Failed with error " + error); + throw InputMethodExceptionFactory.CreateException(error); + } + } + + /// + /// Commits contents such as image to the associated text input UI control. + /// + /// + /// http://tizen.org/privilege/ime + /// + /// The content URI to be sent. + /// The content description. + /// The MIME type received from the MimeTypeSetRequest + /// + /// This can occur due to the following reasons: + /// 1) The application does not have the privilege to call this function. + /// 2) The IME main loop has not started yet. + /// 3) Invalid parameter. + /// + /// 6 + public static void CommitContent(string content, string description, string mimeType) + { + ErrorCode error = ImeCommitContent(content, description, mimeType); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "CommitContent Failed with error " + error); + throw InputMethodExceptionFactory.CreateException(error); + } + } } } diff --git a/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/MimeTypeUpdateRequestedEventArgs.cs b/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/MimeTypeUpdateRequestedEventArgs.cs new file mode 100755 index 0000000..1d52088 --- /dev/null +++ b/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/MimeTypeUpdateRequestedEventArgs.cs @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2018 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. +*/ + +namespace Tizen.Uix.InputMethod +{ + /// + /// This class contains the data related to the MimeTypeUpdateRequested event. + /// + /// 6 + public class MimeTypeUpdateRequestedEventArgs + { + internal MimeTypeUpdateRequestedEventArgs(string mimeType) + { + MimeType = mimeType; + } + + /// + /// The MIME type of entry. + /// + /// 6 + public string MimeType { get; } + } +} + diff --git a/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/PredictionHintDataUpdatedEventArgs.cs b/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/PredictionHintDataUpdatedEventArgs.cs new file mode 100755 index 0000000..741ecda --- /dev/null +++ b/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/PredictionHintDataUpdatedEventArgs.cs @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2018 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. +*/ + +namespace Tizen.Uix.InputMethod +{ + /// + /// This class contains the data related to the PredictionHintDataUpdated event. + /// + /// 6 + public class PredictionHintDataUpdatedEventArgs + { + internal PredictionHintDataUpdatedEventArgs(string key, string value) + { + Key = key; + Value = value; + } + + /// + /// The prediction hint key. + /// + /// 6 + public string Key { get; } + + /// + /// The prediction hint value. + /// + /// 6 + public string Value { get; } + } +} + diff --git a/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/PredictionHintUpdatedEventArgs.cs b/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/PredictionHintUpdatedEventArgs.cs new file mode 100755 index 0000000..b216c4e --- /dev/null +++ b/src/Tizen.Uix.InputMethod/Tizen.Uix.InputMethod/PredictionHintUpdatedEventArgs.cs @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2018 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. +*/ + +namespace Tizen.Uix.InputMethod +{ + /// + /// This class contains the data related to the PredictionHintUpdated event. + /// + /// 6 + public class PredictionHintUpdatedEventArgs + { + internal PredictionHintUpdatedEventArgs(string predictionHint) + { + PredictionHint = predictionHint; + } + + /// + /// The prediction hint to be set to the input panel + /// + /// 6 + public string PredictionHint { get; } + } +} + -- 2.7.4