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.
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using System.ComponentModel;
22 using static Interop.InputMethod;
24 namespace Tizen.Uix.InputMethod
27 /// Enumeration for the key codes.
28 /// If keycode & 0xff000000 == 0x01000000 then this key code is directly encoded to 24-bit UCS character. The UCS value is keycode & 0x00ffffff.
29 /// Defines the list of keys supported by the system. Note that certain keys may not be available on all the devices.
31 /// <since_tizen> 4 </since_tizen>
35 /// The Backspace key.
59 /// The Scroll lock key.
63 /// The System Request key.
75 /* Cursor control & motion */
81 /// The Left directional key.
85 /// The Up directional key.
89 /// The Right directional key.
93 /// The Down directional key.
97 /// The Prior, Previous key.
109 /// The Page Down key.
131 /// The Execute, Run, Do key.
155 /// The Cancel, Stop, Abort, Exit key.
167 /// The character set switch key.
169 Mode_switch = 0xFF7E,
171 /// The Number Lock key.
177 /// The Numpad Space key.
181 /// The Numpad Tab key.
185 /// The Numpad Enter key.
189 /// The Numpad Function 1 key.
193 /// The Numpad Function 2 key.
197 /// The Numpad Function 3 key.
201 /// The Numpad Function 4 key.
205 /// The Numpad Home key.
209 /// The Numpad Left key.
213 /// The Numpad Up key.
217 /// The Numpad Right key.
221 /// The Numpad Down key.
225 /// The Numpad Prior, Previous key.
229 /// The Numpad Page Up key.
233 /// The Numpad Next key.
237 /// The Numpad Page Down key.
239 KPPage_Down = 0xFF9B,
241 /// The Numpad End key.
245 /// The Numpad Begin key.
249 /// The Numpad Insert key.
253 /// The Numpad Delete key.
257 /// The Numpad Equal key.
261 /// The Numpad Multiply key.
265 /// The Numpad Add key.
269 /// The Numpad Separator key.
271 KPSeparator = 0xFFAC,
273 /// The Numpad Subtract key.
277 /// The Numpad Decimal key.
281 /// The Numpad Divide key.
285 /// The Numpad 0 key.
289 /// The Numpad 1 key.
293 /// The Numpad 2 key.
297 /// The Numpad 3 key.
301 /// The Numpad 4 key.
305 /// The Numpad 5 key.
309 /// The Numpad 6 key.
313 /// The Numpad 7 key.
317 /// The Numpad 8 key.
321 /// The Numpad 9 key.
325 /* Auxiliary Functions */
327 /// The Function 1 key.
331 /// The Function 2 key.
335 /// The Function 3 key.
339 /// The Function 4 key.
343 /// The Function 5 key.
347 /// The Function 6 key.
351 /// The Function 7 key.
355 /// The Function 8 key.
359 /// The Function 9 key.
363 /// The Function 10 key.
367 /// The Function 11 key.
371 /// The Function 12 key.
375 /// The Function 13 key.
379 /// The Function 14 key.
383 /// The Function 15 key.
387 /// The Function 16 key.
391 /// The Function 17 key.
395 /// The Function 18 key.
399 /// The Function 19 key.
403 /// The Function 20 key.
407 /// The Function 21 key.
411 /// The Function 22 key.
415 /// The Function 23 key.
419 /// The Function 24 key.
423 /// The Function 25 key.
427 /// The Function 26 key.
431 /// The Function 27 key.
435 /// The Function 28 key.
439 /// The Function 29 key.
443 /// The Function 30 key.
447 /// The Function 31 key.
451 /// The Function 32 key.
455 /// The Function 33 key.
459 /// The Function 34 key.
463 /// The Function 35 key.
469 /// The Left Shift key.
473 /// The Right Shift key.
477 /// The Left Control key.
481 /// The Right Control key.
485 /// The Caps Lock key.
489 /// The Shift Lock key.
493 /// The Left Meta key.
497 /// The Right Meta key.
501 /// The Left Alt key.
505 /// The Right Alt key.
509 /// The Left Super key.
513 /// The Right Super key.
517 /// The Left Hyper key.
521 /// The Right Hyper key.
531 /// The Exclamation key.
535 /// The Quotedbl key.
539 /// The Number Sign key.
551 /// The Ampersand key.
555 /// The Apostrophe key.
559 /// The Parenleft key.
563 /// The Parenright key.
567 /// The Asterisk key.
635 /// The Semicolon key.
651 /// The Question key.
763 /// The Left Bracket key.
767 /// The Backslash key.
771 /// The Right Bracket key.
773 BracketRight = 0x05d,
775 /// The Circumflex key.
779 /// The Underscore key.
891 /// The Left Brace key.
899 /// The Right Brace key.
909 /// Enumeration for the key masks.
910 /// The key masks indicate which modifier keys are pressed down during the keyboard hit. The special MASK_RELEASED indicates the key release event.
912 /// <since_tizen> 4 </since_tizen>
916 /// Key press event without the modifier key.
920 /// The Shift key is pressed down.
924 /// The CapsLock key is pressed down.
928 /// The Control key is pressed down.
932 /// The Alt key is pressed down.
936 /// The Meta key is pressed down.
940 /// The Win key (between Control and Alt) is pressed down.
944 /// The Hyper key is pressed down.
948 /// The NumLock key is pressed down.
952 /// Key release event.
954 Released = (1 << 15),
958 /// This class contains the API's related to the IME (Input method editor).
960 /// <since_tizen> 4 </since_tizen>
961 public static class InputMethodEditor
963 private static ImeCallbackStructGCHandle _imeCallbackStructGCHandle = new ImeCallbackStructGCHandle();
964 private static event EventHandler<FocusedInEventArgs> _focusIn;
965 private static ImeFocusedInCb _imeFocusedInDelegate;
966 private static event EventHandler<FocusedOutEventArgs> _focusOut;
967 private static ImeFocusedOutCb _imeFocusedOutDelegate;
968 private static event EventHandler<SurroundingTextUpdatedEventArgs> _surroundingTextUpdated;
969 private static ImeSurroundingTextUpdatedCb _imeSurroundingTextUpdatedDelegate;
970 private static event EventHandler<EventArgs> _inputContextReset;
971 private static ImeInputContextResetCb _imeInputContextResetDelegate;
972 private static event EventHandler<CursorPositionUpdatedEventArgs> _cursorPositionUpdated;
973 private static ImeCursorPositionUpdatedCb _imeCursorPositionUpdatedDelegate;
974 private static event EventHandler<LanguageSetEventArgs> _langaugeSet;
975 private static ImeLanguageSetCb _imeLanguageSetDelegate;
976 private static event EventHandler<SetDataEventArgs> _imDataSet;
977 private static ImeImdataSetCb _imeDataSetDelegate;
978 private static event EventHandler<LayoutSetEventArgs> _layoutSet;
979 private static ImeLayoutSetCb _imeLayoutSetDelegate;
980 private static event EventHandler<ReturnKeySetEventArgs> _returnKeyTypeSet;
981 private static ImeReturnKeySetCb _imeReturnKeySetDelegate;
982 private static event EventHandler<ReturnKeyStateSetEventArgs> _returnKeyStateSet;
983 private static ImeReturnKeyStateSetCb _imeReturnKeyStateSetDelegate;
984 private static ImeProcessKeyEventCb _imeProcessKeyDelegate;
985 private static event EventHandler<DisplayLanguageChangedEventArgs> _displayLanguageChanged;
986 private static ImeDisplayLanguageChangedCb _imeDisplayLanguageChangedDelegate;
987 private static event EventHandler<RotationChangedEventArgs> _rotationDegreeChanged;
988 private static ImeRotationChangedCb _imeRotationChangedDelegate;
989 private static event EventHandler<AccessibilityStateChangedEventArgs> _accessibilityStateChanged;
990 private static ImeAccessibilityStateChangedCb _imeAccessibilityStateChangedDelegate;
991 private static event EventHandler<PredictionHintUpdatedEventArgs> _predictionHintUpdated;
992 private static ImePredictionHintSetCb _imePredictionHintSetDelegate;
993 private static event EventHandler<PredictionHintDataUpdatedEventArgs> _predictionHintDataUpdated;
994 private static ImePredictionHintDataSetCb _imePredictionHintDataSetDelegate;
995 private static event EventHandler<MimeTypeUpdateRequestedEventArgs> _mimeTypeUpdateRequested;
996 private static ImeMimeTypeSetRequestCb _imeMimeTypeSetRequestDelegate;
997 private static ImeLanguageRequestedCb _imeLanguageRequestedDelegate;
998 private static OutAction<string> _languageRequestedDelegate;
999 private static BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> _processKeyDelagate;
1000 private static ImeImdataRequestedCb _imeImDataRequestedDelegate;
1001 private static OutArrayAction<byte> _imDataRequestedDelegate;
1002 private static ImeGeometryRequestedCb _imeGeometryRequestedDelegate;
1003 private static OutAction<Rect> _geometryRequestedDelegate;
1004 private static ImeProcessKeyEventWithKeycodeCb _imeProcessKeyWithKeycodeDelegate;
1005 private static BoolAction<uint, KeyCode, KeyMask, InputMethodDeviceInformation> _processKeyWithKeycodeDelagate;
1006 private static event EventHandler<InputHintSetEventArgs> _inputHintSet;
1007 private static ImeInputHintSetCb _imeInputHintSetDelegate;
1008 private static Action _userCreate;
1009 private static Action _userTerminate;
1010 private static Action<ContextId, InputMethodContext> _userShow;
1011 private static Action<ContextId> _userHide;
1012 private static ImeCreateCb _create = (IntPtr userData) =>
1014 Log.Info(LogTag, "In Create Delegate");
1015 _userCreate?.Invoke();
1017 private static ImeTerminateCb _terminate = (IntPtr userData) =>
1019 Log.Info(LogTag, "In terminate Delegate");
1020 _userTerminate?.Invoke();
1021 _imeCallbackStructGCHandle.Dispose();
1023 private static ImeShowCb _show = (int contextId, IntPtr context, IntPtr userData) =>
1025 Log.Info(LogTag, "In Show Delegate");
1026 _userShow?.Invoke(new ContextId(contextId), new InputMethodContext(context));
1028 private static ImeHideCb _hide = (int contextId, IntPtr userData) =>
1030 Log.Info(LogTag, "In Hide Delegate");
1031 _userHide?.Invoke(new ContextId(contextId));
1035 /// Structure representing the ContextId.
1037 /// <since_tizen> 4 </since_tizen>
1038 public struct ContextId : IEquatable<ContextId>
1040 internal ContextId(int id)
1052 /// Compares whether the ContextIds are equal.
1054 /// <param name="other">The ContextId to compare with this instance.</param>
1055 /// <returns>true if the ContextIds is the same; otherwise, false.</returns>
1056 /// <since_tizen> 4 </since_tizen>
1057 public bool Equals(ContextId other)
1059 return this.Id == other.Id;
1064 /// Rectangle representing the position and size of the UI control.
1066 /// <since_tizen> 4 </since_tizen>
1070 /// The X position in the screen.
1072 /// <since_tizen> 4 </since_tizen>
1076 /// The Y position in the screen.
1078 /// <since_tizen> 4 </since_tizen>
1082 /// The window width.
1084 /// <since_tizen> 4 </since_tizen>
1088 /// The window height.
1090 /// <since_tizen> 4 </since_tizen>
1095 /// An action with 1 out parameter.
1097 /// <typeparam name="T">Generic Type.</typeparam>
1098 /// <param name="a">The out parameter.</param>
1099 /// <since_tizen> 4 </since_tizen>
1100 public delegate void OutAction<T>(out T a);
1103 /// An action with an array out parameter.
1105 /// <typeparam name="T">Generic Type.</typeparam>
1106 /// <param name="a">The out parameter 1.</param>
1107 /// <since_tizen> 4 </since_tizen>
1108 public delegate void OutArrayAction<T>(out T[] a);
1111 /// An action with 3 input parameters returning a bool.
1113 /// <typeparam name="T">Generic type for parameter 1.</typeparam>
1114 /// <typeparam name="T1">Generic type for parameter 2.</typeparam>
1115 /// <typeparam name="T2">Generic type for parameter 3.</typeparam>
1116 /// <param name="a">The input parameter 1.</param>
1117 /// <param name="b">The input parameter 2.</param>
1118 /// <param name="c">The input parameter 3.</param>
1119 /// <returns></returns>
1120 /// <since_tizen> 4 </since_tizen>
1121 public delegate bool BoolAction<T, T1, T2>(T a, T1 b, T2 c);
1124 /// An action with 4 input parameters returning a bool.
1126 /// <typeparam name="T">Generic type for parameter 1.</typeparam>
1127 /// <typeparam name="T1">Generic type for parameter 2.</typeparam>
1128 /// <typeparam name="T2">Generic type for parameter 3.</typeparam>
1129 /// <typeparam name="T3">Generic type for parameter 4.</typeparam>
1130 /// <param name="a">The input parameter 1.</param>
1131 /// <param name="b">The input parameter 2.</param>
1132 /// <param name="c">The input parameter 3.</param>
1133 /// <param name="d">The input parameter 4.</param>
1134 /// <returns></returns>
1135 /// <since_tizen> 10 </since_tizen>
1136 public delegate bool BoolAction<T, T1, T2, T3>(T a, T1 b, T2 c, T3 d);
1139 /// Called when an associated text input UI control has focus.
1141 /// <since_tizen> 4 </since_tizen>
1142 public static event EventHandler<FocusedInEventArgs> FocusedIn
1146 _imeFocusedInDelegate = (int contextId, IntPtr userData) =>
1148 FocusedInEventArgs args = new FocusedInEventArgs(contextId);
1149 _focusIn?.Invoke(null, args);
1151 ErrorCode error = ImeEventSetFocusedInCb(_imeFocusedInDelegate, IntPtr.Zero);
1152 if (error != ErrorCode.None)
1154 Log.Error(LogTag, "Add FocusedIn Failed with error " + error);
1168 /// Called when an associated text input UI control loses focus.
1170 /// <since_tizen> 4 </since_tizen>
1171 public static event EventHandler<FocusedOutEventArgs> FocusedOut
1175 _imeFocusedOutDelegate = (int contextId, IntPtr userData) =>
1177 FocusedOutEventArgs args = new FocusedOutEventArgs(contextId);
1178 _focusOut?.Invoke(null, args);
1180 ErrorCode error = ImeEventSetFocusedOutCb(_imeFocusedOutDelegate, IntPtr.Zero);
1181 if (error != ErrorCode.None)
1183 Log.Error(LogTag, "Add FocusedOut Failed with error " + error);
1197 /// Called when an associated text input UI control responds to a request with the surrounding text.
1199 /// <since_tizen> 4 </since_tizen>
1200 public static event EventHandler<SurroundingTextUpdatedEventArgs> SurroundingTextUpdated
1204 _imeSurroundingTextUpdatedDelegate = (int contextId, IntPtr text, int cursorPos, IntPtr userData) =>
1206 SurroundingTextUpdatedEventArgs args = new SurroundingTextUpdatedEventArgs(contextId, Marshal.PtrToStringAnsi(text), cursorPos);
1207 _surroundingTextUpdated?.Invoke(null, args);
1209 ErrorCode error = ImeEventSetSurroundingTextUpdatedCb(_imeSurroundingTextUpdatedDelegate, IntPtr.Zero);
1210 if (error != ErrorCode.None)
1212 Log.Error(LogTag, "Add SurroundingTextUpdated Failed with error " + error);
1216 _surroundingTextUpdated += value;
1221 _surroundingTextUpdated -= value;
1226 /// Called to reset the input context of an associated text input UI control.
1228 /// <since_tizen> 4 </since_tizen>
1229 public static event EventHandler<EventArgs> InputContextReset
1233 _imeInputContextResetDelegate = (IntPtr userData) =>
1235 _inputContextReset?.Invoke(null, EventArgs.Empty);
1237 ErrorCode error = ImeEventSetInputContextResetCb(_imeInputContextResetDelegate, IntPtr.Zero);
1238 if (error != ErrorCode.None)
1240 Log.Error(LogTag, "Add InputContextReset Failed with error " + error);
1244 _inputContextReset += value;
1249 _inputContextReset -= value;
1254 /// Called when the position of the cursor in an associated text input UI control changes.
1256 /// <since_tizen> 4 </since_tizen>
1257 public static event EventHandler<CursorPositionUpdatedEventArgs> CursorPositionUpdated
1261 _imeCursorPositionUpdatedDelegate = (int cursorPos, IntPtr userData) =>
1263 CursorPositionUpdatedEventArgs args = new CursorPositionUpdatedEventArgs(cursorPos);
1264 _cursorPositionUpdated?.Invoke(null, args);
1266 ErrorCode error = ImeEventSetCursorPositionUpdatedCb(_imeCursorPositionUpdatedDelegate, IntPtr.Zero);
1267 if (error != ErrorCode.None)
1269 Log.Error(LogTag, "Add CursorPositionUpdated Failed with error " + error);
1273 _cursorPositionUpdated += value;
1278 _cursorPositionUpdated -= value;
1283 /// Called to set the preferred language to the input panel.
1284 /// It will only be called when the client application changes the edit field's language attribute after the input panel is shown.
1286 /// <since_tizen> 4 </since_tizen>
1287 public static event EventHandler<LanguageSetEventArgs> LanguageSet
1291 _imeLanguageSetDelegate = (InputPanelLanguage language, IntPtr userData) =>
1293 LanguageSetEventArgs args = new LanguageSetEventArgs(language);
1294 _langaugeSet?.Invoke(null, args);
1296 ErrorCode error = ImeEventSetLanguageSetCb(_imeLanguageSetDelegate, IntPtr.Zero);
1297 if (error != ErrorCode.None)
1299 Log.Error(LogTag, "Add LanguageSet Failed with error " + error);
1303 _langaugeSet += value;
1308 _langaugeSet -= value;
1313 /// Called to set the application specific data to deliver to the input panel.
1315 /// <since_tizen> 4 </since_tizen>
1316 public static event EventHandler<SetDataEventArgs> DataSet
1320 _imeDataSetDelegate = (IntPtr data, uint dataLength, IntPtr userData) =>
1322 byte[] destination = new byte[dataLength];
1323 Marshal.Copy(data, destination, 0, (int)dataLength);
1324 SetDataEventArgs args = new SetDataEventArgs(destination, dataLength);
1325 _imDataSet?.Invoke(null, args);
1327 ErrorCode error = ImeEventSetImdataSetCb(_imeDataSetDelegate, IntPtr.Zero);
1328 if (error != ErrorCode.None)
1330 Log.Error(LogTag, "Add DataSet Failed with error " + error);
1334 _imDataSet += value;
1339 _imDataSet -= value;
1344 /// Called when an associated text input UI control requests the input panel to set its layout.
1345 /// It will only be called when the client application changes the edit field's layout attribute after the input panel is shown.
1347 /// <since_tizen> 4 </since_tizen>
1348 public static event EventHandler<LayoutSetEventArgs> LayoutSet
1352 _imeLayoutSetDelegate = (InputPanelLayout layout, IntPtr userData) =>
1354 LayoutSetEventArgs args = new LayoutSetEventArgs(layout);
1355 _layoutSet?.Invoke(null, args);
1357 ErrorCode error = ImeEventSetLayoutSetCb(_imeLayoutSetDelegate, IntPtr.Zero);
1358 if (error != ErrorCode.None)
1360 Log.Error(LogTag, "Add LayoutSet Failed with error " + error);
1364 _layoutSet += value;
1369 _layoutSet -= value;
1374 /// Called when an associated text input UI control requests the input panel to set the Return key label.
1375 /// The input panel can show the text or an image on the Return button, according to the Return key action.
1377 /// <since_tizen> 4 </since_tizen>
1378 public static event EventHandler<ReturnKeySetEventArgs> ReturnKeySet
1382 _imeReturnKeySetDelegate = (InputPanelReturnKey type, IntPtr userData) =>
1384 ReturnKeySetEventArgs args = new ReturnKeySetEventArgs(type);
1385 _returnKeyTypeSet?.Invoke(null, args);
1387 ErrorCode error = ImeEventSetReturnKeySetCb(_imeReturnKeySetDelegate, IntPtr.Zero);
1388 if (error != ErrorCode.None)
1390 Log.Error(LogTag, "Add ReturnKeySet Failed with error " + error);
1394 _returnKeyTypeSet += value;
1399 _returnKeyTypeSet -= value;
1404 /// Called when an associated text input UI control requests the input panel to enable or disable the Return key state.
1406 /// <since_tizen> 4 </since_tizen>
1407 public static event EventHandler<ReturnKeyStateSetEventArgs> ReturnKeyStateSet
1411 _imeReturnKeyStateSetDelegate = (bool state, IntPtr userData) =>
1413 ReturnKeyStateSetEventArgs args = new ReturnKeyStateSetEventArgs(state);
1414 _returnKeyStateSet?.Invoke(null, args);
1416 ErrorCode error = ImeEventSetReturnKeyStateSetCb(_imeReturnKeyStateSetDelegate, IntPtr.Zero);
1417 if (error != ErrorCode.None)
1419 Log.Error(LogTag, "Add ReturnKeyStateSet Failed with error " + error);
1423 _returnKeyStateSet += value;
1428 _returnKeyStateSet -= value;
1433 /// Called when the system display language is changed.
1435 /// <since_tizen> 4 </since_tizen>
1436 public static event EventHandler<DisplayLanguageChangedEventArgs> DisplayLanguageChanged
1440 _imeDisplayLanguageChangedDelegate = (IntPtr language, IntPtr userData) =>
1442 DisplayLanguageChangedEventArgs args = new DisplayLanguageChangedEventArgs(Marshal.PtrToStringAnsi(language));
1443 _displayLanguageChanged?.Invoke(null, args);
1445 ErrorCode error = ImeEventSetDisplayLanguageChangedCb(_imeDisplayLanguageChangedDelegate, IntPtr.Zero);
1446 if (error != ErrorCode.None)
1448 Log.Error(LogTag, "Add DisplayLanguageChanged Failed with error " + error);
1452 _displayLanguageChanged += value;
1457 _displayLanguageChanged -= value;
1462 /// Called when the device is rotated.
1464 /// <since_tizen> 4 </since_tizen>
1465 public static event EventHandler<RotationChangedEventArgs> RotationChanged
1469 _imeRotationChangedDelegate = (int degree, IntPtr userData) =>
1471 RotationChangedEventArgs args = new RotationChangedEventArgs(degree);
1472 _rotationDegreeChanged?.Invoke(null, args);
1474 ErrorCode error = ImeEventSetRotationChangedCb(_imeRotationChangedDelegate, IntPtr.Zero);
1475 if (error != ErrorCode.None)
1477 Log.Error(LogTag, "Add RotationChanged Failed with error " + error);
1481 _rotationDegreeChanged += value;
1486 _rotationDegreeChanged -= value;
1491 /// Called when Accessibility in settings application is on or off.
1493 /// <since_tizen> 4 </since_tizen>
1494 public static event EventHandler<AccessibilityStateChangedEventArgs> AccessibilityStateChanged
1498 _imeAccessibilityStateChangedDelegate = (bool state, IntPtr userData) =>
1500 AccessibilityStateChangedEventArgs args = new AccessibilityStateChangedEventArgs(state);
1501 _accessibilityStateChanged?.Invoke(null, args);
1503 ErrorCode error = ImeEventSetAccessibilityStateChangedCb(_imeAccessibilityStateChangedDelegate, IntPtr.Zero);
1504 if (error != ErrorCode.None)
1506 Log.Error(LogTag, "Add AccessibilityStateChanged Failed with error " + error);
1510 _accessibilityStateChanged += value;
1515 _accessibilityStateChanged -= value;
1520 /// Sets the languageRequested action.
1522 /// <param name="languageRequested">
1523 /// Called when an associated text input UI control requests the language from the input panel, requesting for language code.
1525 /// <since_tizen> 4 </since_tizen>
1526 public static void SetLanguageRequestedCallback(OutAction<string> languageRequested)
1528 _imeLanguageRequestedDelegate = (IntPtr userData, out IntPtr langCode) =>
1531 _languageRequestedDelegate(out language);
1532 langCode = (IntPtr)Marshal.StringToHGlobalAnsi(language);
1534 ErrorCode error = ImeEventSetLanguageRequestedCallbackCb(_imeLanguageRequestedDelegate, IntPtr.Zero);
1535 if (error != ErrorCode.None)
1537 Log.Error(LogTag, "Add SetLanguageRequestedCallback Failed with error " + error);
1539 _languageRequestedDelegate = languageRequested;
1543 /// Sets the processKey action.
1544 /// If the key event is from the external device, DeviceInfo will have its name, class, and subclass information.
1546 /// <param name="processKey">
1547 /// The action is called when the key event is received from the external devices or the SendKey function.
1548 /// This Event processes the key event before an associated text input UI control does.
1550 /// <since_tizen> 4 </since_tizen>
1551 public static void SetProcessKeyCallback(BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> processKey)
1553 _imeProcessKeyDelegate = (KeyCode keyCode, KeyMask keyMask, IntPtr devInfo, IntPtr userData) =>
1555 return _processKeyDelagate(keyCode, keyMask, new InputMethodDeviceInformation(devInfo));
1557 ErrorCode error = ImeEventSetProcessKeyEventCb(_imeProcessKeyDelegate, IntPtr.Zero);
1558 if (error != ErrorCode.None)
1560 Log.Error(LogTag, "Add ProcessKey Failed with error " + error);
1562 _processKeyDelagate = processKey;
1566 /// Sets the imDataRequested action.
1568 /// <param name="imDataRequested">
1569 /// Called when an associated text input UI control requests the application specific data from the input panel, requesting for data array and it's length.
1571 /// <since_tizen> 4 </since_tizen>
1572 public static void SetDataRequestedCallback(OutArrayAction<byte> imDataRequested)
1574 _imeImDataRequestedDelegate = (IntPtr userData, out IntPtr data, out uint dataLength) =>
1577 _imDataRequestedDelegate(out dataArr);
1578 data = Marshal.AllocHGlobal(dataArr.Length);
1579 Marshal.Copy(dataArr, 0, data, dataArr.Length);
1580 dataLength = (uint)dataArr.Length;
1582 ErrorCode error = ImeEventSetImdataRequestedCb(_imeImDataRequestedDelegate, IntPtr.Zero);
1583 if (error != ErrorCode.None)
1585 Log.Error(LogTag, "Add SetDataRequestedCallback Failed with error " + error);
1587 _imDataRequestedDelegate = imDataRequested;
1591 /// Sets the GeometryRequested action.
1593 /// <param name="geometryRequested">
1594 /// Called when an associated text input UI control requests the position and size from the input panel, requesting for x, y, w, h values.
1596 /// <since_tizen> 4 </since_tizen>
1597 public static void SetGeometryRequestedCallback(OutAction<Rect> geometryRequested)
1599 _imeGeometryRequestedDelegate = (IntPtr userData, out int x, out int y, out int w, out int h) =>
1601 Rect rect = new Rect();
1602 _geometryRequestedDelegate(out rect);
1608 ErrorCode error = ImeEventSetGeometryRequestedCallbackCb(_imeGeometryRequestedDelegate, IntPtr.Zero);
1609 if (error != ErrorCode.None)
1611 Log.Error(LogTag, "Add SetGeometryRequestedCallback Failed with error " + error);
1613 _geometryRequestedDelegate = geometryRequested;
1617 /// Runs the main loop of the IME application.
1618 /// This function starts to run the IME application's main loop.
1621 /// http://tizen.org/privilege/ime
1624 /// This API is a blocking call, as it starts the main loop of the application.
1626 /// <param name="create">This is called to initialize the IME application before the main loop starts up.</param>
1627 /// <param name="terminate">This is called when the IME application is terminated.</param>
1628 /// <param name="show">
1629 /// This is called when the IME application is shown.
1630 /// It provides the context information and the context ID.
1632 /// <param name="hide">
1633 /// This is called when the IME application is hidden.
1634 /// It provides the context ID.
1636 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1637 /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
1638 /// <since_tizen> 4 </since_tizen>
1639 public static void Run(Action create, Action terminate, Action<ContextId, InputMethodContext> show, Action<ContextId> hide)
1641 _userCreate = create;
1642 _userTerminate = terminate;
1645 _imeCallbackStructGCHandle._imeCallbackStruct.create = _create;
1646 _imeCallbackStructGCHandle._imeCallbackStruct.terminate = _terminate;
1647 _imeCallbackStructGCHandle._imeCallbackStruct.hide = _hide;
1648 _imeCallbackStructGCHandle._imeCallbackStruct.show = _show;
1650 ImeSetDotnetFlag(true);
1651 ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero);
1652 if (error != ErrorCode.None)
1654 Log.Error(LogTag, "Run Failed with error " + error);
1655 throw InputMethodExceptionFactory.CreateException(error);
1661 /// Sends a key event to the associated text input UI control.
1664 /// This function sends a key down or up event with the key mask to the client application. If forwardKey is true, this key event goes to the edit filed directly.
1665 /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field.
1668 /// http://tizen.org/privilege/ime
1670 /// <param name="keyCode">The key code to be sent.</param>
1671 /// <param name="keyMask">The modifier key mask.</param>
1672 /// <param name="forwardKey">The flag to send the key event directly to the edit field.</param>
1673 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1674 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1675 /// <since_tizen> 4 </since_tizen>
1676 public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false)
1678 ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey);
1679 if (error != ErrorCode.None)
1681 Log.Error(LogTag, "SendEvent Failed with error " + error);
1682 throw InputMethodExceptionFactory.CreateException(error);
1687 /// Sends the text to the associated text input UI control.
1690 /// http://tizen.org/privilege/ime
1692 /// <param name="str">The string to be committed.</param>
1693 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1694 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1695 /// <since_tizen> 4 </since_tizen>
1696 public static void CommitString(string str)
1698 ErrorCode error = ImeCommitString(str);
1699 if (error != ErrorCode.None)
1701 Log.Error(LogTag, "CommitString Failed with error " + error);
1702 throw InputMethodExceptionFactory.CreateException(error);
1707 /// Requests to show the pre-edit string.
1710 /// http://tizen.org/privilege/ime
1712 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1713 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1714 /// <since_tizen> 4 </since_tizen>
1715 public static void ShowPreEditString()
1717 ErrorCode error = ImeShowPreeditString();
1718 if (error != ErrorCode.None)
1720 Log.Error(LogTag, "ShowPreEditString Failed with error " + error);
1721 throw InputMethodExceptionFactory.CreateException(error);
1726 /// Requests to hide the pre-edit string.
1729 /// http://tizen.org/privilege/ime
1731 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1732 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1733 /// <since_tizen> 4 </since_tizen>
1734 public static void HidePreEditString()
1736 ErrorCode error = ImeHidePreeditString();
1737 if (error != ErrorCode.None)
1739 Log.Error(LogTag, "HidePreEditString Failed with error " + error);
1740 throw InputMethodExceptionFactory.CreateException(error);
1745 /// Updates a new pre-edit string.
1748 /// http://tizen.org/privilege/ime
1750 /// <param name="str">The string to be updated in pre-edit.</param>
1751 /// <param name="attrs">
1752 /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color, and reversal color.
1753 /// The attrs list can be empty if no attributes to set.
1755 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1756 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1757 /// <since_tizen> 4 </since_tizen>
1758 public static void UpdatePreEditString(string str, IEnumerable<PreEditAttribute> attrs)
1760 IntPtr einaList = IntPtr.Zero;
1761 foreach (PreEditAttribute attribute in attrs)
1763 IntPtr attr = IntPtr.Zero;
1764 ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct();
1765 imePreEditAttribute.start = attribute.Start;
1766 imePreEditAttribute.length = attribute.Length;
1767 imePreEditAttribute.type = (int)attribute.Type;
1768 imePreEditAttribute.value = attribute.Value;
1769 attr = Marshal.AllocHGlobal(Marshal.SizeOf(imePreEditAttribute));
1770 Marshal.WriteIntPtr(attr, IntPtr.Zero);
1771 Marshal.StructureToPtr(imePreEditAttribute, attr, false);
1772 einaList = Interop.EinaList.EinaListAppend(einaList, attr);
1774 ErrorCode error = ImeUpdatePreeditString(str, einaList);
1775 if (error != ErrorCode.None)
1777 Log.Error(LogTag, "UpdatePreEditString Failed with error " + error);
1778 throw InputMethodExceptionFactory.CreateException(error);
1783 /// Requests the surrounding text from the position of the cursor, asynchronously.
1786 /// http://tizen.org/privilege/ime
1788 /// <param name="maxLenBefore">The maximum length of the string to be retrieved before the cursor, -1 means unlimited.</param>
1789 /// <param name="maxLenAfter">The maximum length of the string to be retrieved after the cursor, -1 means unlimited.</param>
1790 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1791 /// <exception cref="InvalidOperationException">
1792 /// This can occur due to the following reasons:
1793 /// 1) The IME main loop has not started yet.
1794 /// 2) The necessary event is not set.
1797 /// The requested surrounding text can be received using the SurroundingTextUpdated event, only if it is set.
1798 /// </postcondition>
1799 /// <since_tizen> 4 </since_tizen>
1800 public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter)
1802 ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter);
1803 if (error != ErrorCode.None)
1805 Log.Error(LogTag, "RequestSurroundingText Failed with error " + error);
1806 throw InputMethodExceptionFactory.CreateException(error);
1811 /// Requests to delete the surrounding text.
1814 /// http://tizen.org/privilege/ime
1816 /// <param name="offset">The offset value from the cursor position.</param>
1817 /// <param name="len">The length of the text to delete.</param>
1818 /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
1819 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1820 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1821 /// <since_tizen> 4 </since_tizen>
1822 public static void DeleteSurroundingText(int offset, int len)
1824 ErrorCode error = ImeDeleteSurroundingText(offset, len);
1825 if (error != ErrorCode.None)
1827 Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error);
1828 throw InputMethodExceptionFactory.CreateException(error);
1833 /// Gets the surrounding text from the position of the cursor, synchronously.
1836 /// http://tizen.org/privilege/ime
1838 /// <param name="maxLenBefore">The maximum length of the string to be retrieved before the cursor, -1 means unlimited.</param>
1839 /// <param name="maxLenAfter">The maximum length of the string to be retrieved after the cursor, -1 means unlimited.</param>
1840 /// <param name="text">The surrounding text.</param>
1841 /// <param name="cursorPosition">The cursor position.</param>
1842 /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
1843 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1844 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1845 /// <since_tizen> 4 </since_tizen>
1846 public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition)
1849 ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition);
1850 if (error != ErrorCode.None)
1852 Log.Error(LogTag, "GetSurroundingText Failed with error " + error);
1853 throw InputMethodExceptionFactory.CreateException(error);
1855 text = Marshal.PtrToStringAnsi(txt);
1859 /// Requests to set the selection.
1862 /// http://tizen.org/privilege/ime
1864 /// <param name="start">The start cursor position in text (in characters not bytes).</param>
1865 /// <param name="end">The end cursor position in text (in characters not bytes).</param>
1866 /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
1867 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1868 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1869 /// <since_tizen> 4 </since_tizen>
1870 public static void SetSelection(int start, int end)
1872 ErrorCode error = ImeSetSelection(start, end);
1873 if (error != ErrorCode.None)
1875 Log.Error(LogTag, "SetSelection Failed with error " + error);
1876 throw InputMethodExceptionFactory.CreateException(error);
1881 /// This API returns the input panel main window.
1884 /// http://tizen.org/privilege/ime
1886 /// <returns>The input panel main window object on success, otherwise null.</returns>
1887 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1888 /// <exception cref="InvalidOperationException">
1889 /// This can occur due to the following reasons:
1890 /// 1) The IME main loop has not started yet.
1891 /// 2) Operation failed.
1893 /// <since_tizen> 4 </since_tizen>
1894 [Obsolete("Deprecated since API10. Will be removed in API12.")]
1895 public static EditorWindow GetMainWindow()
1897 EditorWindow._handle = ImeGetMainWindow();
1898 EditorWindow obj = new EditorWindow();
1899 ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
1900 if (error != ErrorCode.None)
1902 Log.Error(LogTag, "GetMainWindow Failed with error " + error);
1903 throw InputMethodExceptionFactory.CreateException(error);
1909 /// Sends the request to hide the IME.
1912 /// http://tizen.org/privilege/ime
1914 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1915 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1916 /// <since_tizen> 5 </since_tizen>
1917 public static void RequestHide()
1919 ErrorCode error = ImeRequestHide();
1920 if (error != ErrorCode.None)
1922 Log.Error(LogTag, "RequestHide Failed with error " + error);
1923 throw InputMethodExceptionFactory.CreateException(error);
1928 /// This API requests the InputMethodEditor to initialize.
1931 /// http://tizen.org/privilege/ime
1933 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1934 /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
1935 /// <since_tizen> 4 </since_tizen>
1936 [EditorBrowsable(EditorBrowsableState.Never)]
1937 public static void Create()
1939 ErrorCode error = ImeInitialize();
1940 Log.Info(LogTag, "ImeInitialize result : " + error);
1941 if (error != ErrorCode.None)
1943 Log.Error(LogTag, "ImeInitialize Failed with error " + error);
1944 throw InputMethodExceptionFactory.CreateException(error);
1947 error = ImePrepare();
1948 Log.Info(LogTag, "ImePrepare result : " + error);
1949 if (error != ErrorCode.None)
1951 Log.Error(LogTag, "ImePrepare Failed with error " + error);
1952 throw InputMethodExceptionFactory.CreateException(error);
1957 /// This API requests the InputMethodEditor to finalize.
1960 /// http://tizen.org/privilege/ime
1962 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1963 /// <since_tizen> 4 </since_tizen>
1964 [EditorBrowsable(EditorBrowsableState.Never)]
1965 public static void Destroy()
1967 ErrorCode error = ImeFinalize();
1968 Log.Info(LogTag, "ImeFinalize result : " + error);
1969 if (error != ErrorCode.None)
1971 Log.Error(LogTag, "ImeFinalize Failed with error " + error);
1972 throw InputMethodExceptionFactory.CreateException(error);
1977 /// Sets the floating mode to on or off.
1980 /// http://tizen.org/privilege/ime
1982 /// <param name="floatingMode"><c>true</c> to set the floating mode to on and <c>false</c> to set it to off.</param>
1983 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1984 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
1985 /// <since_tizen> 5 </since_tizen>
1986 public static void SetFloatingMode(bool floatingMode)
1988 ErrorCode error = ImeSetFloatingMode(floatingMode);
1989 if (error != ErrorCode.None)
1991 Log.Error(LogTag, "SetFloatingMode Failed with error " + error);
1992 throw InputMethodExceptionFactory.CreateException(error);
1997 /// Allows the floating input panel window to move along with the mouse pointer when the mouse is pressed.
2000 /// http://tizen.org/privilege/ime
2003 /// This function can be used in floating mode. If the floating mode is deactivated, calling this function has no effect.
2005 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2006 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2007 /// <since_tizen> 5 </since_tizen>
2008 public static void SetFloatingDragStart()
2010 ErrorCode error = ImeSetFloatingDragStart();
2011 if (error != ErrorCode.None)
2013 Log.Error(LogTag, "SetFloatingDragStart Failed with error " + error);
2014 throw InputMethodExceptionFactory.CreateException(error);
2019 /// Does not allow the movement of the floating input panel window with the mouse pointer when the mouse is pressed.
2022 /// http://tizen.org/privilege/ime
2025 /// This function can be used in floating mode. If the floating mode is deactivated, calling this function has no effect.
2027 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2028 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2029 /// <since_tizen> 5 </since_tizen>
2030 public static void SetFloatingDragEnd()
2032 ErrorCode error = ImeSetFloatingDragEnd();
2033 if (error != ErrorCode.None)
2035 Log.Error(LogTag, "SetFloatingDragEnd Failed with error " + error);
2036 throw InputMethodExceptionFactory.CreateException(error);
2041 /// Notifies the changed language of the input panel to the the associated text input UI control.
2044 /// http://tizen.org/privilege/ime
2047 /// LanguageRequestedCallback is raised after this API is called when the App requests changed language information.
2049 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2050 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2051 /// <since_tizen> 6 </since_tizen>
2052 public static void SendLanguageUpdated()
2054 ErrorCode error = ImeUpdateInputPanelEvent(ImeEventType.Language, 0);
2055 if (error != ErrorCode.None)
2057 Log.Error(LogTag, "SendLanguageUpdated Failed with error " + error);
2058 throw InputMethodExceptionFactory.CreateException(error);
2063 /// Sends the changed shift mode of the input panel to the the associated text input UI control.
2066 /// http://tizen.org/privilege/ime
2068 /// <param name="enable"><c>true</c> if shift button is clicked, otherwise <c>false</c>.</param>
2069 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2070 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2071 /// <since_tizen> 6 </since_tizen>
2072 public static void SendShiftModeUpdated(bool enable)
2074 ErrorCode error = ImeUpdateInputPanelEvent(ImeEventType.ShiftMode, enable ? (uint)ImeShiftMode.On : (uint)ImeShiftMode.Off);
2075 if (error != ErrorCode.None)
2077 Log.Error(LogTag, "SendInputPanelEvent Failed with error " + error);
2078 throw InputMethodExceptionFactory.CreateException(error);
2083 /// Notifies the changed geometry of input panel window to the associated text input UI control.
2086 /// http://tizen.org/privilege/ime
2088 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2089 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2090 /// <since_tizen> 6 </since_tizen>
2091 public static void SendCustomGeometryUpdated()
2093 ErrorCode error = ImeUpdateInputPanelEvent(ImeEventType.Geometry, 0);
2094 if (error != ErrorCode.None)
2096 Log.Error(LogTag, "SendCustomGeometryUpdated Failed with error " + error);
2097 throw InputMethodExceptionFactory.CreateException(error);
2102 /// Gets the selected text synchronously.
2105 /// http://tizen.org/privilege/ime
2107 /// <returns>The selected text.</returns>
2108 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2109 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2110 /// <since_tizen> 6 </since_tizen>
2111 public static string GetSelectedText()
2114 ErrorCode error = ImeGetSelectedText(out txt);
2115 if (error != ErrorCode.None)
2117 Log.Error(LogTag, "GetSelectedText Failed with error " + error);
2118 throw InputMethodExceptionFactory.CreateException(error);
2120 return Marshal.PtrToStringAnsi(txt);
2124 /// Called to set the prediction hint string to deliver to the input panel.
2126 /// <since_tizen> 6 </since_tizen>
2127 public static event EventHandler<PredictionHintUpdatedEventArgs> PredictionHintUpdated
2131 if (_imePredictionHintSetDelegate == null)
2133 _imePredictionHintSetDelegate = (IntPtr predictionHint, IntPtr userData) =>
2135 PredictionHintUpdatedEventArgs args = new PredictionHintUpdatedEventArgs(Marshal.PtrToStringAnsi(predictionHint));
2136 _predictionHintUpdated?.Invoke(null, args);
2138 ErrorCode error = ImeEventSetPredictionHintSetCb(_imePredictionHintSetDelegate, IntPtr.Zero);
2139 if (error != ErrorCode.None)
2141 Log.Error(LogTag, "Add PredictionHintUpdated Failed with error " + error);
2144 _predictionHintUpdated += value;
2148 _predictionHintUpdated -= value;
2153 /// Called to set the prediction hint key and value to deliver to the input panel.
2155 /// <since_tizen> 6 </since_tizen>
2156 public static event EventHandler<PredictionHintDataUpdatedEventArgs> PredictionHintDataUpdated
2160 if (_imePredictionHintDataSetDelegate == null)
2162 _imePredictionHintDataSetDelegate = (IntPtr key, IntPtr keyValue, IntPtr userData) =>
2164 PredictionHintDataUpdatedEventArgs args = new PredictionHintDataUpdatedEventArgs(Marshal.PtrToStringAnsi(key), Marshal.PtrToStringAnsi(keyValue));
2165 _predictionHintDataUpdated?.Invoke(null, args);
2168 ErrorCode error = ImeEventSetPredictionHintDataSetCb(_imePredictionHintDataSetDelegate, IntPtr.Zero);
2169 if (error != ErrorCode.None)
2171 Log.Error(LogTag, "Add PredictionHintDataUpdated Failed with error " + error);
2174 _predictionHintDataUpdated += value;
2178 _predictionHintDataUpdated -= value;
2183 /// Called when an associated text input UI control requests the text entry to set the MIME type.
2185 /// <since_tizen> 6 </since_tizen>
2186 public static event EventHandler<MimeTypeUpdateRequestedEventArgs> MimeTypeUpdateRequested
2190 if (_imeMimeTypeSetRequestDelegate == null)
2192 _imeMimeTypeSetRequestDelegate = (IntPtr mimeType, IntPtr userData) =>
2194 MimeTypeUpdateRequestedEventArgs args = new MimeTypeUpdateRequestedEventArgs(Marshal.PtrToStringAnsi(mimeType));
2195 _mimeTypeUpdateRequested?.Invoke(null, args);
2197 ErrorCode error = ImeEventSetMimeTypeSetRequestCb(_imeMimeTypeSetRequestDelegate, IntPtr.Zero);
2198 if (error != ErrorCode.None)
2200 Log.Error(LogTag, "Add MimeTypeUpdateRequested Failed with error " + error);
2203 _mimeTypeUpdateRequested += value;
2207 _mimeTypeUpdateRequested -= value;
2212 /// Sends a private command to the associated text input UI control.
2215 /// http://tizen.org/privilege/ime
2217 /// <param name="command">The UTF-8 string to be sent.</param>
2218 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2219 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2220 /// <since_tizen> 6 </since_tizen>
2221 public static void SendPrivateCommand(string command)
2223 ErrorCode error = ImeSendPrivateCommand(command);
2224 if (error != ErrorCode.None)
2226 Log.Error(LogTag, "SendPrivateCommand Failed with error " + error);
2227 throw InputMethodExceptionFactory.CreateException(error);
2232 /// Commits contents such as image to the associated text input UI control.
2235 /// http://tizen.org/privilege/ime
2237 /// <param name="content">The content URI to be sent.</param>
2238 /// <param name="description">The content description.</param>
2239 /// <param name="mimeType">The MIME type received from the MimeTypeSetRequest</param>
2240 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2241 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2242 /// <since_tizen> 6 </since_tizen>
2243 public static void CommitContent(string content, string description, string mimeType)
2245 ErrorCode error = ImeCommitContent(content, description, mimeType);
2246 if (error != ErrorCode.None)
2248 Log.Error(LogTag, "CommitContent Failed with error " + error);
2249 throw InputMethodExceptionFactory.CreateException(error);
2254 /// This API updates the given native input panel window's size information.
2255 /// The native window handle of NUI Window can be got by below code.
2256 /// var handle = new Window.SafeNativeWindowHandle();
2257 /// IntPtr nativeHandle = handle.DangerousGetHandle();
2260 /// http://tizen.org/privilege/ime
2262 /// <param name="window">The native window handle.</param>
2263 /// <param name="portraitWidth">The width in the portrait mode.</param>
2264 /// <param name="portraitHeight">The height in the portrait mode.</param>
2265 /// <param name="landscapeWidth">The width in the landscape mode.</param>
2266 /// <param name="landscapeHeight">The height in the landscape mode.</param>
2267 /// <exception cref="ArgumentException">This exception can be due to an invalid parameter.</exception>
2268 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2269 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2270 /// <since_tizen> 9 </since_tizen>
2271 public static void SetSize(IntPtr window, int portraitWidth, int portraitHeight, int landscapeWidth, int landscapeHeight)
2273 ErrorCode error = ImeSetNativeWindowSize(window, portraitWidth, portraitHeight, landscapeWidth, landscapeHeight);
2274 if (error != ErrorCode.None)
2276 Log.Error(LogTag, "SetSize Failed with error " + error);
2277 throw InputMethodExceptionFactory.CreateException(error);
2282 /// Sets the processKey action.
2283 /// If the key event is from the external device, DeviceInfo will have its name, class, and subclass information.
2285 /// <param name="processKey">
2286 /// <c>true</c> if the event was processed, otherwise the event was not processed and was forwarded to the client application.
2287 /// The first parameter is X11 key code and the second parameter is key symbol.
2288 /// The action is called when the key event is received from the external devices or the SendKey function.
2289 /// This Event processes the key event before an associated text input UI control does.
2291 /// <since_tizen> 10 </since_tizen>
2292 public static void SetProcessKeyCallback(BoolAction<uint, KeyCode, KeyMask, InputMethodDeviceInformation> processKey)
2294 _imeProcessKeyWithKeycodeDelegate = (uint keyCode, KeyCode keySymbol, KeyMask keyMask, IntPtr devInfo, IntPtr userData) =>
2296 return _processKeyWithKeycodeDelagate(keyCode, keySymbol, keyMask, new InputMethodDeviceInformation(devInfo));
2298 ErrorCode error = ImeEventSetProcessKeyEventWithKeycodeCb(_imeProcessKeyWithKeycodeDelegate, IntPtr.Zero);
2299 if (error != ErrorCode.None)
2301 Log.Error(LogTag, "Add ProcessKeyWithKeycode Failed with error " + error);
2303 _processKeyWithKeycodeDelagate = processKey;
2307 /// Updates the cursor position in the preedit string.
2310 /// http://tizen.org/privilege/ime
2312 /// <param name="position">The cursor position in the preedit string.</param>
2313 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2314 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2315 /// <since_tizen> 10 </since_tizen>
2316 public static void UpdatePreeditCursor(uint position)
2318 ErrorCode error = ImeUpdatePreeditCursor(position);
2319 if (error != ErrorCode.None)
2321 Log.Error(LogTag, "UpdatePreeditCursor Failed with error " + error);
2322 throw InputMethodExceptionFactory.CreateException(error);
2327 /// Sets whether candidate strings will be shown or not.
2330 /// http://tizen.org/privilege/ime
2332 /// <param name="visible"><c>true</c> to show candidate strings, <c>false</c> otherwise.</param>
2333 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
2334 /// <exception cref="InvalidOperationException">The IME main loop has not started yet.</exception>
2335 /// <since_tizen> 10 </since_tizen>
2336 public static void SetCandidateVisibilityState(bool visible)
2338 ErrorCode error = ImeSetCandidateVisibilityState(visible);
2339 if (error != ErrorCode.None)
2341 Log.Error(LogTag, "SetCandidateVisibilityState Failed with error " + error);
2342 throw InputMethodExceptionFactory.CreateException(error);
2347 /// Called when an associated text input UI control requests the input panel to set its input hint.
2348 /// It will only be called when the client application changes the edit field's input hint attribute after the input panel is shown.
2350 /// <seealso cref="InputHints"/>
2351 /// <since_tizen> 10 </since_tizen>
2352 public static event EventHandler<InputHintSetEventArgs> InputHintSet
2356 _imeInputHintSetDelegate = (InputHints hint, IntPtr userData) =>
2358 InputHintSetEventArgs args = new InputHintSetEventArgs(hint);
2359 _inputHintSet?.Invoke(null, args);
2361 ErrorCode error = ImeEventSetInputHintSetCb(_imeInputHintSetDelegate, IntPtr.Zero);
2362 if (error != ErrorCode.None)
2364 Log.Error(LogTag, "Add InputHintSet Failed with error " + error);
2368 _inputHintSet += value;
2373 _inputHintSet -= value;