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 Object thisLock = new Object();
964 private static ImeCallbackStructGCHandle _imeCallbackStructGCHandle = new ImeCallbackStructGCHandle();
965 private static event EventHandler<FocusedInEventArgs> _focusIn;
966 private static ImeFocusedInCb _imeFocusedInDelegate;
967 private static event EventHandler<FocusedOutEventArgs> _focusOut;
968 private static ImeFocusedOutCb _imeFocusedOutDelegate;
969 private static event EventHandler<SurroundingTextUpdatedEventArgs> _surroundingTextUpdated;
970 private static ImeSurroundingTextUpdatedCb _imeSurroundingTextUpdatedDelegate;
971 private static event EventHandler<EventArgs> _inputContextReset;
972 private static ImeInputContextResetCb _imeInputContextResetDelegate;
973 private static event EventHandler<CursorPositionUpdatedEventArgs> _cursorPositionUpdated;
974 private static ImeCursorPositionUpdatedCb _imeCursorPositionUpdatedDelegate;
975 private static event EventHandler<LanguageSetEventArgs> _langaugeSet;
976 private static ImeLanguageSetCb _imeLanguageSetDelegate;
977 private static event EventHandler<SetDataEventArgs> _imDataSet;
978 private static ImeImdataSetCb _imeDataSetDelegate;
979 private static event EventHandler<LayoutSetEventArgs> _layoutSet;
980 private static ImeLayoutSetCb _imeLayoutSetDelegate;
981 private static event EventHandler<ReturnKeySetEventArgs> _returnKeyTypeSet;
982 private static ImeReturnKeySetCb _imeReturnKeySetDelegate;
983 private static event EventHandler<ReturnKeyStateSetEventArgs> _returnKeyStateSet;
984 private static ImeReturnKeyStateSetCb _imeReturnKeyStateSetDelegate;
985 private static ImeProcessKeyEventCb _imeProcessKeyDelegate;
986 private static event EventHandler<DisplayLanguageChangedEventArgs> _displayLanguageChanged;
987 private static ImeDisplayLanguageChangedCb _imeDisplayLanguageChangedDelegate;
988 private static event EventHandler<RotationChangedEventArgs> _rotationDegreeChanged;
989 private static ImeRotationChangedCb _imeRotationChangedDelegate;
990 private static event EventHandler<AccessibilityStateChangedEventArgs> _accessibilityStateChanged;
991 private static ImeAccessibilityStateChangedCb _imeAccessibilityStateChangedDelegate;
992 private static ImeLanguageRequestedCb _imeLanguageRequestedDelegate;
993 private static OutAction<string> _languageRequestedDelegate;
994 private static BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> _processKeyDelagate;
995 private static ImeImdataRequestedCb _imeImDataRequestedDelegate;
996 private static OutArrayAction<byte> _imDataRequestedDelegate;
997 private static ImeGeometryRequestedCb _imeGeometryRequestedDelegate;
998 private static OutAction<Rect> _geometryRequestedDelegate;
999 private static Action _userCreate;
1000 private static Action _userTerminate;
1001 private static Action<ContextId, InputMethodContext> _userShow;
1002 private static Action<ContextId> _userHide;
1003 private static ImeCreateCb _create = (IntPtr userData) =>
1005 Log.Info(LogTag, "In Create Delegate");
1006 _userCreate?.Invoke();
1008 private static ImeTerminateCb _terminate = (IntPtr userData) =>
1010 Log.Info(LogTag, "In terminate Delegate");
1011 _userTerminate?.Invoke();
1012 _imeCallbackStructGCHandle.Dispose();
1014 private static ImeShowCb _show = (int contextId, IntPtr context, IntPtr userData) =>
1016 Log.Info(LogTag, "In Show Delegate");
1017 _userShow?.Invoke(new ContextId(contextId), new InputMethodContext(context));
1019 private static ImeHideCb _hide = (int contextId, IntPtr userData) =>
1021 Log.Info(LogTag, "In Hide Delegate");
1022 _userHide?.Invoke(new ContextId(contextId));
1026 /// Structure representing the ContextId.
1028 /// <since_tizen> 4 </since_tizen>
1029 public struct ContextId : IEquatable<ContextId>
1031 internal ContextId(int id)
1043 /// Compares whether the ContextIds are equal.
1045 /// <param name="other">The ContextIds to test for equality.</param>
1046 /// <returns>true if the ContextIds is the same; otherwise, false.</returns>
1047 /// <since_tizen> 4 </since_tizen>
1048 public bool Equals(ContextId other)
1050 return this.Id == other.Id;
1055 /// Rectangle representing the position and size of the UI control.
1057 /// <since_tizen> 4 </since_tizen>
1061 /// The X position in the screen.
1063 /// <since_tizen> 4 </since_tizen>
1067 /// The Y position in the screen.
1069 /// <since_tizen> 4 </since_tizen>
1073 /// The window width.
1075 /// <since_tizen> 4 </since_tizen>
1079 /// The window height.
1081 /// <since_tizen> 4 </since_tizen>
1086 /// An action with 1 out parameter.
1088 /// <typeparam name="T">Generic Type.</typeparam>
1089 /// <param name="a">The out parameter.</param>
1090 /// <since_tizen> 4 </since_tizen>
1091 public delegate void OutAction<T>(out T a);
1094 /// An action with an array out parameter.
1096 /// <typeparam name="T">Generic Type.</typeparam>
1097 /// <param name="a">The out parameter 1.</param>
1098 /// <since_tizen> 4 </since_tizen>
1099 public delegate void OutArrayAction<T>(out T[] a);
1102 /// An action with 3 input parameters returning a bool.
1104 /// <typeparam name="T">Generic type for parameter 1.</typeparam>
1105 /// <typeparam name="T1">Generic type for parameter 2.</typeparam>
1106 /// <typeparam name="T2">Generic type for parameter 3.</typeparam>
1107 /// <param name="a">The input parameter 1.</param>
1108 /// <param name="b">The input parameter 2.</param>
1109 /// <param name="c">The input parameter 3.</param>
1110 /// <returns></returns>
1111 /// <since_tizen> 4 </since_tizen>
1112 public delegate bool BoolAction<T, T1, T2>(T a, T1 b, T2 c);
1115 /// Called when an associated text input UI control has focus.
1117 /// <since_tizen> 4 </since_tizen>
1118 public static event EventHandler<FocusedInEventArgs> FocusedIn
1124 _imeFocusedInDelegate = (int contextId, IntPtr userData) =>
1126 FocusedInEventArgs args = new FocusedInEventArgs(contextId);
1127 _focusIn?.Invoke(null, args);
1129 ErrorCode error = ImeEventSetFocusedInCb(_imeFocusedInDelegate, IntPtr.Zero);
1130 if (error != ErrorCode.None)
1132 Log.Error(LogTag, "Add FocusedIn Failed with error " + error);
1150 /// Called when an associated text input UI control loses focus.
1152 /// <since_tizen> 4 </since_tizen>
1153 public static event EventHandler<FocusedOutEventArgs> FocusedOut
1159 _imeFocusedOutDelegate = (int contextId, IntPtr userData) =>
1161 FocusedOutEventArgs args = new FocusedOutEventArgs(contextId);
1162 _focusOut?.Invoke(null, args);
1164 ErrorCode error = ImeEventSetFocusedOutCb(_imeFocusedOutDelegate, IntPtr.Zero);
1165 if (error != ErrorCode.None)
1167 Log.Error(LogTag, "Add FocusedOut Failed with error " + error);
1185 /// Called when an associated text input UI control responds to a request with the surrounding text.
1187 /// <since_tizen> 4 </since_tizen>
1188 public static event EventHandler<SurroundingTextUpdatedEventArgs> SurroundingTextUpdated
1194 _imeSurroundingTextUpdatedDelegate = (int contextId, IntPtr text, int cursorPos, IntPtr userData) =>
1196 SurroundingTextUpdatedEventArgs args = new SurroundingTextUpdatedEventArgs(contextId, Marshal.PtrToStringAnsi(text), cursorPos);
1197 _surroundingTextUpdated?.Invoke(null, args);
1199 ErrorCode error = ImeEventSetSurroundingTextUpdatedCb(_imeSurroundingTextUpdatedDelegate, IntPtr.Zero);
1200 if (error != ErrorCode.None)
1202 Log.Error(LogTag, "Add SurroundingTextUpdated Failed with error " + error);
1206 _surroundingTextUpdated += value;
1214 _surroundingTextUpdated -= value;
1220 /// Called to reset the input context of an associated text input UI control.
1222 /// <since_tizen> 4 </since_tizen>
1223 public static event EventHandler<EventArgs> InputContextReset
1229 _imeInputContextResetDelegate = (IntPtr userData) =>
1231 _inputContextReset?.Invoke(null, EventArgs.Empty);
1233 ErrorCode error = ImeEventSetInputContextResetCb(_imeInputContextResetDelegate, IntPtr.Zero);
1234 if (error != ErrorCode.None)
1236 Log.Error(LogTag, "Add InputContextReset Failed with error " + error);
1240 _inputContextReset += value;
1248 _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
1263 _imeCursorPositionUpdatedDelegate = (int cursorPos, IntPtr userData) =>
1265 CursorPositionUpdatedEventArgs args = new CursorPositionUpdatedEventArgs(cursorPos);
1266 _cursorPositionUpdated?.Invoke(null, args);
1268 ErrorCode error = ImeEventSetCursorPositionUpdatedCb(_imeCursorPositionUpdatedDelegate, IntPtr.Zero);
1269 if (error != ErrorCode.None)
1271 Log.Error(LogTag, "Add CursorPositionUpdated Failed with error " + error);
1275 _cursorPositionUpdated += value;
1283 _cursorPositionUpdated -= value;
1289 /// Called to set the preferred language to the input panel.
1290 /// It will only be called when the client application changes the edit field's language attribute after the input panel is shown.
1292 /// <since_tizen> 4 </since_tizen>
1293 public static event EventHandler<LanguageSetEventArgs> LanguageSet
1299 _imeLanguageSetDelegate = (InputPanelLanguage language, IntPtr userData) =>
1301 LanguageSetEventArgs args = new LanguageSetEventArgs(language);
1302 _langaugeSet?.Invoke(null, args);
1304 ErrorCode error = ImeEventSetLanguageSetCb(_imeLanguageSetDelegate, IntPtr.Zero);
1305 if (error != ErrorCode.None)
1307 Log.Error(LogTag, "Add LanguageSet Failed with error " + error);
1311 _langaugeSet += value;
1319 _langaugeSet -= value;
1325 /// Called to set the application specific data to deliver to the input panel.
1327 /// <since_tizen> 4 </since_tizen>
1328 public static event EventHandler<SetDataEventArgs> DataSet
1334 _imeDataSetDelegate = (IntPtr data, uint dataLength, IntPtr userData) =>
1336 byte[] destination = new byte[dataLength];
1337 Marshal.Copy(data, destination, 0, (int)dataLength);
1338 SetDataEventArgs args = new SetDataEventArgs(destination, dataLength);
1339 _imDataSet?.Invoke(null, args);
1341 ErrorCode error = ImeEventSetImdataSetCb(_imeDataSetDelegate, IntPtr.Zero);
1342 if (error != ErrorCode.None)
1344 Log.Error(LogTag, "Add DataSet Failed with error " + error);
1348 _imDataSet += value;
1356 _imDataSet -= value;
1362 /// Called when an associated text input UI control requests the input panel to set its layout.
1363 /// It will only be called when the client application changes the edit field's layout attribute after the input panel is shown.
1365 /// <since_tizen> 4 </since_tizen>
1366 public static event EventHandler<LayoutSetEventArgs> LayoutSet
1372 _imeLayoutSetDelegate = (InputPanelLayout layout, IntPtr userData) =>
1374 LayoutSetEventArgs args = new LayoutSetEventArgs(layout);
1375 _layoutSet?.Invoke(null, args);
1377 ErrorCode error = ImeEventSetLayoutSetCb(_imeLayoutSetDelegate, IntPtr.Zero);
1378 if (error != ErrorCode.None)
1380 Log.Error(LogTag, "Add LayoutSet Failed with error " + error);
1384 _layoutSet += value;
1392 _layoutSet -= value;
1398 /// Called when an associated text input UI control requests the input panel to set the Return key label.
1399 /// The input panel can show the text or an image on the Return button, according to the Return key action.
1401 /// <since_tizen> 4 </since_tizen>
1402 public static event EventHandler<ReturnKeySetEventArgs> ReturnKeySet
1408 _imeReturnKeySetDelegate = (InputPanelReturnKey type, IntPtr userData) =>
1410 ReturnKeySetEventArgs args = new ReturnKeySetEventArgs(type);
1411 _returnKeyTypeSet?.Invoke(null, args);
1413 ErrorCode error = ImeEventSetReturnKeySetCb(_imeReturnKeySetDelegate, IntPtr.Zero);
1414 if (error != ErrorCode.None)
1416 Log.Error(LogTag, "Add ReturnKeySet Failed with error " + error);
1420 _returnKeyTypeSet += value;
1428 _returnKeyTypeSet -= value;
1434 /// Called when an associated text input UI control requests the input panel to enable or disable the Return key state.
1436 /// <since_tizen> 4 </since_tizen>
1437 public static event EventHandler<ReturnKeyStateSetEventArgs> ReturnKeyStateSet
1443 _imeReturnKeyStateSetDelegate = (bool state, IntPtr userData) =>
1445 ReturnKeyStateSetEventArgs args = new ReturnKeyStateSetEventArgs(state);
1446 _returnKeyStateSet?.Invoke(null, args);
1448 ErrorCode error = ImeEventSetReturnKeyStateSetCb(_imeReturnKeyStateSetDelegate, IntPtr.Zero);
1449 if (error != ErrorCode.None)
1451 Log.Error(LogTag, "Add ReturnKeyStateSet Failed with error " + error);
1455 _returnKeyStateSet += value;
1463 _returnKeyStateSet -= value;
1469 /// Called when the system display language is changed.
1471 /// <since_tizen> 4 </since_tizen>
1472 public static event EventHandler<DisplayLanguageChangedEventArgs> DisplayLanguageChanged
1478 _imeDisplayLanguageChangedDelegate = (IntPtr language, IntPtr userData) =>
1480 DisplayLanguageChangedEventArgs args = new DisplayLanguageChangedEventArgs(Marshal.PtrToStringAnsi(language));
1481 _displayLanguageChanged?.Invoke(null, args);
1483 ErrorCode error = ImeEventSetDisplayLanguageChangedCb(_imeDisplayLanguageChangedDelegate, IntPtr.Zero);
1484 if (error != ErrorCode.None)
1486 Log.Error(LogTag, "Add DisplayLanguageChanged Failed with error " + error);
1490 _displayLanguageChanged += value;
1498 _displayLanguageChanged -= value;
1504 /// Called when the device is rotated.
1506 /// <since_tizen> 4 </since_tizen>
1507 public static event EventHandler<RotationChangedEventArgs> RotationChanged
1513 _imeRotationChangedDelegate = (int degree, IntPtr userData) =>
1515 RotationChangedEventArgs args = new RotationChangedEventArgs(degree);
1516 _rotationDegreeChanged?.Invoke(null, args);
1518 ErrorCode error = ImeEventSetRotationChangedCb(_imeRotationChangedDelegate, IntPtr.Zero);
1519 if (error != ErrorCode.None)
1521 Log.Error(LogTag, "Add RotationChanged Failed with error " + error);
1525 _rotationDegreeChanged += value;
1533 _rotationDegreeChanged -= value;
1539 /// Called when Accessibility in settings application is on or off.
1541 /// <since_tizen> 4 </since_tizen>
1542 public static event EventHandler<AccessibilityStateChangedEventArgs> AccessibilityStateChanged
1548 _imeAccessibilityStateChangedDelegate = (bool state, IntPtr userData) =>
1550 AccessibilityStateChangedEventArgs args = new AccessibilityStateChangedEventArgs(state);
1551 _accessibilityStateChanged?.Invoke(null, args);
1553 ErrorCode error = ImeEventSetAccessibilityStateChangedCb(_imeAccessibilityStateChangedDelegate, IntPtr.Zero);
1554 if (error != ErrorCode.None)
1556 Log.Error(LogTag, "Add AccessibilityStateChanged Failed with error " + error);
1560 _accessibilityStateChanged += value;
1568 _accessibilityStateChanged -= value;
1574 /// Sets the languageRequested action.
1576 /// <param name="languageRequested">
1577 /// Called when an associated text input UI control requests the language from the input panel, requesting for language code.
1579 /// <since_tizen> 4 </since_tizen>
1580 public static void SetLanguageRequestedCallback(OutAction<string> languageRequested)
1582 _imeLanguageRequestedDelegate = (IntPtr userData, out IntPtr langCode) =>
1585 _languageRequestedDelegate(out langauage);
1586 char[] languageArray = langauage.ToCharArray();
1587 langCode = new IntPtr();
1588 Marshal.Copy(languageArray, 0, langCode, languageArray.Length);
1590 ErrorCode error = ImeEventSetLanguageRequestedCallbackCb(_imeLanguageRequestedDelegate, IntPtr.Zero);
1591 if (error != ErrorCode.None)
1593 Log.Error(LogTag, "Add SetLanguageRequestedCallback Failed with error " + error);
1595 _languageRequestedDelegate = languageRequested;
1599 /// Sets the processKey action.
1600 /// If the key event is from the external device, DeviceInfo will have its name, class, and subclass information.
1602 /// <param name="processKey">
1603 /// The action is called when the key event is received from the external devices or the SendKey function.
1604 /// This Event processes the key event before an associated text input UI control does.
1606 /// <since_tizen> 4 </since_tizen>
1607 public static void SetProcessKeyCallback(BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> processKey)
1609 _imeProcessKeyDelegate = (KeyCode keyCode, KeyMask keyMask, IntPtr devInfo, IntPtr userData) =>
1611 return _processKeyDelagate(keyCode, keyMask, new InputMethodDeviceInformation(devInfo));
1613 ErrorCode error = ImeEventSetProcessKeyEventCb(_imeProcessKeyDelegate, IntPtr.Zero);
1614 if (error != ErrorCode.None)
1616 Log.Error(LogTag, "Add ProcessKey Failed with error " + error);
1618 _processKeyDelagate = processKey;
1622 /// Sets the imDataRequested action.
1624 /// <param name="imDataRequested">
1625 /// 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.
1627 /// <since_tizen> 4 </since_tizen>
1628 public static void SetDataRequestedCallback(OutArrayAction<byte> imDataRequested)
1630 _imeImDataRequestedDelegate = (IntPtr userData, out IntPtr data, out uint dataLength) =>
1633 _imDataRequestedDelegate(out dataArr);
1634 data = new IntPtr();
1635 Marshal.Copy(dataArr, 0, data, dataArr.Length);
1636 dataLength = (uint)dataArr.Length;
1638 ErrorCode error = ImeEventSetImdataRequestedCb(_imeImDataRequestedDelegate, IntPtr.Zero);
1639 if (error != ErrorCode.None)
1641 Log.Error(LogTag, "Add SetDataRequestedCallback Failed with error " + error);
1643 _imDataRequestedDelegate = imDataRequested;
1647 /// Sets the GeometryRequested action.
1649 /// <param name="geometryRequested">
1650 /// Called when an associated text input UI control requests the position and size from the input panel, requesting for x, y, w, h values.
1652 /// <since_tizen> 4 </since_tizen>
1653 public static void SetGeometryRequestedCallback(OutAction<Rect> geometryRequested)
1655 _imeGeometryRequestedDelegate = (IntPtr userData, out int x, out int y, out int w, out int h) =>
1657 Rect rect = new Rect();
1658 _geometryRequestedDelegate(out rect);
1664 ErrorCode error = ImeEventSetGeometryRequestedCallbackCb(_imeGeometryRequestedDelegate, IntPtr.Zero);
1665 if (error != ErrorCode.None)
1667 Log.Error(LogTag, "Add SetGeometryRequestedCallback Failed with error " + error);
1669 _geometryRequestedDelegate = geometryRequested;
1673 /// Runs the main loop of the IME application.
1674 /// This function starts to run the IME application's main loop.
1677 /// http://tizen.org/privilege/ime
1680 /// This API is a blocking call, as it starts the main loop of the application.
1682 /// <param name="create">This is called to initialize the IME application before the main loop starts up.</param>
1683 /// <param name="terminate">This is called when the IME application is terminated.</param>
1684 /// <param name="show">
1685 /// This is called when the IME application is shown.
1686 /// It provides the context information and the context ID.
1688 /// <param name="hide">
1689 /// This is called when the IME application is hidden.
1690 /// It provides the context ID.
1692 /// <exception cref="InvalidOperationException">
1693 /// This can occur due to the following reasons:
1694 /// 1) The application does not have the privilege to call this function.
1695 /// 2) Operation failed.
1697 /// <since_tizen> 4 </since_tizen>
1698 public static void Run(Action create, Action terminate, Action<ContextId, InputMethodContext> show, Action<ContextId> hide)
1700 _userCreate = create;
1701 _userTerminate = terminate;
1704 _imeCallbackStructGCHandle._imeCallbackStruct.create = _create;
1705 _imeCallbackStructGCHandle._imeCallbackStruct.terminate = _terminate;
1706 _imeCallbackStructGCHandle._imeCallbackStruct.hide = _hide;
1707 _imeCallbackStructGCHandle._imeCallbackStruct.show = _show;
1709 ImeSetDotnetFlag(true);
1710 ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero);
1711 if (error != ErrorCode.None)
1713 Log.Error(LogTag, "Run Failed with error " + error);
1714 throw InputMethodExceptionFactory.CreateException(error);
1720 /// Sends a key event to the associated text input UI control.
1723 /// 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.
1724 /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field.
1727 /// http://tizen.org/privilege/ime
1729 /// <param name="keyCode">The key code to be sent.</param>
1730 /// <param name="keyMask">The modifier key mask.</param>
1731 /// <param name="forwardKey">The flag to send the key event directly to the edit field.</param>
1732 /// <exception cref="InvalidOperationException">
1733 /// This can occur due to the following reasons:
1734 /// 1) The application does not have the privilege to call this function.
1735 /// 2) The IME main loop isn't started yet.
1737 /// <since_tizen> 4 </since_tizen>
1738 public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false)
1740 ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey);
1741 if (error != ErrorCode.None)
1743 Log.Error(LogTag, "SendEvent Failed with error " + error);
1744 throw InputMethodExceptionFactory.CreateException(error);
1749 /// Sends the text to the associated text input UI control.
1752 /// http://tizen.org/privilege/ime
1754 /// <param name="str">The string to be committed.</param>
1755 /// <exception cref="InvalidOperationException">
1756 /// This can occur due to the following reasons:
1757 /// 1) The application does not have the privilege to call this function.
1758 /// 2) The IME main loop isn't started yet.
1760 /// <since_tizen> 4 </since_tizen>
1761 public static void CommitString(string str)
1763 ErrorCode error = ImeCommitString(str);
1764 if (error != ErrorCode.None)
1766 Log.Error(LogTag, "CommitString Failed with error " + error);
1767 throw InputMethodExceptionFactory.CreateException(error);
1772 /// Requests to show the pre-edit string.
1775 /// http://tizen.org/privilege/ime
1777 /// <exception cref="InvalidOperationException">
1778 /// This can occur due to the following reasons:
1779 /// 1) The application does not have the privilege to call this function.
1780 /// 2) The IME main loop isn't started yet.
1782 /// <since_tizen> 4 </since_tizen>
1783 public static void ShowPreEditString()
1785 ErrorCode error = ImeShowPreeditString();
1786 if (error != ErrorCode.None)
1788 Log.Error(LogTag, "ShowPreEditString Failed with error " + error);
1789 throw InputMethodExceptionFactory.CreateException(error);
1794 /// Requests to hide the pre-edit string.
1797 /// http://tizen.org/privilege/ime
1799 /// <exception cref="InvalidOperationException">
1800 /// This can occur due to the following reasons:
1801 /// 1) The application does not have the privilege to call this function.
1802 /// 2) The IME main loop isn't started yet.
1804 /// <since_tizen> 4 </since_tizen>
1805 public static void HidePreEditString()
1807 ErrorCode error = ImeHidePreeditString();
1808 if (error != ErrorCode.None)
1810 Log.Error(LogTag, "HidePreEditString Failed with error " + error);
1811 throw InputMethodExceptionFactory.CreateException(error);
1816 /// Updates a new pre-edit string.
1819 /// http://tizen.org/privilege/ime
1821 /// <param name="str">The string to be updated in pre-edit.</param>
1822 /// <param name="attrs">
1823 /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color, and reversal color.
1824 /// The attrs list can be empty if no attributes to set.
1826 /// <exception cref="InvalidOperationException">
1827 /// This can occur due to the following reasons:
1828 /// 1) The application does not have the privilege to call this function.
1829 /// 2) The IME main loop isn't started yet.
1830 /// 3) Invalid parameter.
1832 /// <since_tizen> 4 </since_tizen>
1833 public static void UpdatePreEditString(string str, IEnumerable<PreEditAttribute> attrs)
1835 IntPtr einaList = IntPtr.Zero;
1836 List<GCHandle> attributeHandleList = new List<GCHandle>();
1837 foreach (PreEditAttribute attribute in attrs)
1839 ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct();
1840 imePreEditAttribute.start = attribute.Start;
1841 imePreEditAttribute.length = attribute.Length;
1842 imePreEditAttribute.type = (int)attribute.Type;
1843 imePreEditAttribute.value = attribute.Value;
1844 GCHandle attributeHandle = GCHandle.Alloc(imePreEditAttribute, GCHandleType.Pinned);
1845 attributeHandleList.Add(attributeHandle);
1846 einaList = Interop.EinaList.EinaListAppend(einaList, attributeHandle.AddrOfPinnedObject());
1848 ErrorCode error = ImeUpdatePreeditString(str, einaList);
1849 foreach (GCHandle handle in attributeHandleList)
1853 if (error != ErrorCode.None)
1855 Log.Error(LogTag, "UpdatePreEditString Failed with error " + error);
1856 throw InputMethodExceptionFactory.CreateException(error);
1861 /// Requests the surrounding text from the position of the cursor, asynchronously.
1864 /// http://tizen.org/privilege/ime
1866 /// <param name="maxLenBefore">The maximum length of the string to be retrieved before the cursor, -1 means unlimited.</param>
1867 /// <param name="maxLenAfter">The maximum length of the string to be retrieved after the cursor, -1 means unlimited.</param>
1868 /// <exception cref="InvalidOperationException">
1869 /// This can occur due to the following reasons:
1870 /// 1) The application does not have the privilege to call this function.
1871 /// 2) The IME main loop isn't started yet.
1874 /// The requested surrounding text can be received using the SurroundingTextUpdated event, only if it is set.
1875 /// </postcondition>
1876 /// <since_tizen> 4 </since_tizen>
1877 public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter)
1879 ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter);
1880 if (error != ErrorCode.None)
1882 Log.Error(LogTag, "RequestSurroundingText Failed with error " + error);
1883 throw InputMethodExceptionFactory.CreateException(error);
1888 /// Requests to delete the surrounding text.
1891 /// http://tizen.org/privilege/ime
1893 /// <param name="offset">The offset value from the cursor position.</param>
1894 /// <param name="len">The length of the text to delete.</param>
1895 /// <exception cref="InvalidOperationException">
1896 /// This can occur due to the following reasons:
1897 /// 1) The application does not have the privilege to call this function.
1898 /// 2) The IME main loop isn't started yet.
1899 /// 3) Invalid parameter.
1901 /// <since_tizen> 4 </since_tizen>
1902 public static void DeleteSurroundingText(int offset, int len)
1904 ErrorCode error = ImeDeleteSurroundingText(offset, len);
1905 if (error != ErrorCode.None)
1907 Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error);
1908 throw InputMethodExceptionFactory.CreateException(error);
1913 /// Gets the surrounding text from the position of the cursor, synchronously.
1916 /// http://tizen.org/privilege/ime
1918 /// <param name="maxLenBefore">The maximum length of the string to be retrieved before the cursor, -1 means unlimited.</param>
1919 /// <param name="maxLenAfter">The maximum length of the string to be retrieved after the cursor, -1 means unlimited.</param>
1920 /// <param name="text">The surrounding text.</param>
1921 /// <param name="cursorPosition">The cursor position.</param>
1922 /// <exception cref="InvalidOperationException">
1923 /// This can occur due to the following reasons:
1924 /// 1) The application does not have the privilege to call this function.
1925 /// 2) The IME main loop isn't started yet.
1926 /// 3) Invalid parameter.
1927 /// 4) Failed to obtain text due to out of memory.
1929 /// <since_tizen> 4 </since_tizen>
1930 public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition)
1933 ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition);
1934 if (error != ErrorCode.None)
1936 Log.Error(LogTag, "GetSurroundingText Failed with error " + error);
1937 throw InputMethodExceptionFactory.CreateException(error);
1939 text = Marshal.PtrToStringAnsi(txt);
1943 /// Requests to set the selection.
1946 /// http://tizen.org/privilege/ime
1948 /// <param name="start">The start cursor position in text (in characters not bytes).</param>
1949 /// <param name="end">The end cursor position in text (in characters not bytes).</param>
1950 /// <exception cref="InvalidOperationException">
1951 /// This can occur due to the following reasons:
1952 /// 1) The application does not have the privilege to call this function.
1953 /// 2) The IME main loop isn't started yet.
1954 /// 3) Invalid parameter.
1956 /// <since_tizen> 4 </since_tizen>
1957 public static void SetSelection(int start, int end)
1959 ErrorCode error = ImeSetSelection(start, end);
1960 if (error != ErrorCode.None)
1962 Log.Error(LogTag, "SetSelection Failed with error " + error);
1963 throw InputMethodExceptionFactory.CreateException(error);
1968 /// This API returns the input panel main window.
1971 /// http://tizen.org/privilege/ime
1973 /// <returns>The input panel main window object on success, otherwise null.</returns>
1974 /// <exception cref="InvalidOperationException">
1975 /// This can occur due to the following reasons:
1976 /// 1) The application does not have the privilege to call this function.
1977 /// 2) The IME main loop isn't started yet.
1978 /// 3) Operation failed.
1980 /// <since_tizen> 4 </since_tizen>
1981 public static EditorWindow GetMainWindow()
1983 EditorWindow._handle = ImeGetMainWindow();
1984 EditorWindow obj = new EditorWindow();
1985 ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
1986 if (error != ErrorCode.None)
1988 Log.Error(LogTag, "GetMainWindow Failed with error " + error);
1989 throw InputMethodExceptionFactory.CreateException(error);
1995 /// Sends the request to hide the IME.
1998 /// http://tizen.org/privilege/ime
2000 /// <exception cref="InvalidOperationException">
2001 /// This can occur due to the following reasons:
2002 /// 1) The application does not have the privilege to call this function.
2003 /// 2) The IME main loop has not yet started.
2005 /// <since_tizen> 5 </since_tizen>
2006 public static void RequestHide()
2008 ErrorCode error = ImeRequestHide();
2009 if (error != ErrorCode.None)
2011 Log.Error(LogTag, "RequestHide Failed with error " + error);
2012 throw InputMethodExceptionFactory.CreateException(error);
2017 /// This API requests the InputMethodEditor to initialize.
2020 /// http://tizen.org/privilege/ime
2022 /// <exception cref="InvalidOperationException">
2023 /// This can occur due to the following reasons:
2024 /// 1) The application does not have the privilege to call this function.
2025 /// 2) Operation failed.
2027 /// <since_tizen> 4 </since_tizen>
2028 [EditorBrowsable(EditorBrowsableState.Never)]
2029 public static void Create()
2031 ErrorCode error = ImeInitialize();
2032 Log.Info(LogTag, "ImeInitialize result : " + error);
2033 if (error != ErrorCode.None)
2035 Log.Error(LogTag, "ImeInitialize Failed with error " + error);
2036 throw InputMethodExceptionFactory.CreateException(error);
2039 error = ImePrepare();
2040 Log.Info(LogTag, "ImePrepare result : " + error);
2041 if (error != ErrorCode.None)
2043 Log.Error(LogTag, "ImePrepare Failed with error " + error);
2044 throw InputMethodExceptionFactory.CreateException(error);
2049 /// This API requests the InputMethodEditor to finalize.
2052 /// http://tizen.org/privilege/ime
2054 /// <exception cref="InvalidOperationException">
2055 /// This can occur due to the following reasons:
2056 /// 1) The application does not have the privilege to call this function.
2057 /// 2) Operation failed.
2059 /// <since_tizen> 4 </since_tizen>
2060 [EditorBrowsable(EditorBrowsableState.Never)]
2061 public static void Destroy()
2063 ErrorCode error = ImeFinalize();
2064 Log.Info(LogTag, "ImeFinalize result : " + error);
2065 if (error != ErrorCode.None)
2067 Log.Error(LogTag, "ImeFinalize Failed with error " + error);
2068 throw InputMethodExceptionFactory.CreateException(error);
2073 /// Sets the floating mode to on or off.
2076 /// http://tizen.org/privilege/ime
2078 /// <param name="floating_mode"><c>true</c> to set the floating mode to on and <c>false</c> to set it to off.</param>
2079 /// <exception cref="InvalidOperationException">
2080 /// This can occur due to the following reasons:
2081 /// 1) The application does not have the privilege to call this function.
2082 /// 2) The IME main loop has not yet started.
2084 /// <since_tizen> 5 </since_tizen>
2085 public static void SetFloatingMode(bool floating_mode)
2087 ErrorCode error = ImeSetFloatingMode(floating_mode);
2088 if (error != ErrorCode.None)
2090 Log.Error(LogTag, "SetFloatingMode Failed with error " + error);
2091 throw InputMethodExceptionFactory.CreateException(error);
2096 /// Allows the floating input panel window to move along with the mouse pointer when the mouse is pressed.
2099 /// http://tizen.org/privilege/ime
2102 /// This function can be used in floating mode. If the floating mode is deactivated, calling this function has no effect.
2104 /// <exception cref="InvalidOperationException">
2105 /// This can occur due to the following reasons:
2106 /// 1) The application does not have the privilege to call this function.
2107 /// 2) The IME main loop has not yet started.
2109 /// <since_tizen> 5 </since_tizen>
2110 public static void SetFloatingDragStart()
2112 ErrorCode error = ImeSetFloatingDragStart();
2113 if (error != ErrorCode.None)
2115 Log.Error(LogTag, "SetFloatingDragStart Failed with error " + error);
2116 throw InputMethodExceptionFactory.CreateException(error);
2121 /// Does not allow the movement of the floating input panel window with the mouse pointer when the mouse is pressed.
2124 /// http://tizen.org/privilege/ime
2127 /// This function can be used in floating mode. If the floating mode is deactivated, calling this function has no effect.
2129 /// <exception cref="InvalidOperationException">
2130 /// This can occur due to the following reasons:
2131 /// 1) The application does not have the privilege to call this function.
2132 /// 2) The IME main loop has not yet started.
2134 /// <since_tizen> 5 </since_tizen>
2135 public static void SetFloatingDragEnd()
2137 ErrorCode error = ImeSetFloatingDragEnd();
2138 if (error != ErrorCode.None)
2140 Log.Error(LogTag, "SetFloatingDragEnd Failed with error " + error);
2141 throw InputMethodExceptionFactory.CreateException(error);
2146 /// Notifies the changed language of the input panel to the the associated text input UI control.
2149 /// http://tizen.org/privilege/ime
2152 /// LanguageRequestedCallback is raised after this API is called when the App requests changed language information.
2154 /// <exception cref="InvalidOperationException">
2155 /// This can occur due to the following reasons:
2156 /// 1) The application does not have the privilege to call this function.
2157 /// 2) The IME main loop has not yet started.
2159 /// <since_tizen> 6 </since_tizen>
2160 public static void SendLanguageUpdated()
2162 ErrorCode error = ImeUpdateInputPanelEvent(ImeEventType.Language, 0);
2163 if (error != ErrorCode.None)
2165 Log.Error(LogTag, "SendLanguageUpdated Failed with error " + error);
2166 throw InputMethodExceptionFactory.CreateException(error);
2171 /// Sends the changed shift mode of the input panel to the the associated text input UI control.
2174 /// http://tizen.org/privilege/ime
2176 /// <param name="enable"><c>true</c> if shift button is clicked, otherwise <c>false</c>.</param>
2177 /// <exception cref="InvalidOperationException">
2178 /// This can occur due to the following reasons:
2179 /// 1) The application does not have the privilege to call this function.
2180 /// 2) The IME main loop has not yet started.
2182 /// <since_tizen> 6 </since_tizen>
2183 public static void SendShiftModeUpdated(bool enable)
2185 ErrorCode error = ImeUpdateInputPanelEvent(ImeEventType.ShiftMode, enable ? (uint)ImeShiftMode.On : (uint)ImeShiftMode.Off);
2186 if (error != ErrorCode.None)
2188 Log.Error(LogTag, "SendInputPanelEvent Failed with error " + error);
2189 throw InputMethodExceptionFactory.CreateException(error);
2194 /// Notifies the changed geometry of input panel window to the associated text input UI control.
2197 /// http://tizen.org/privilege/ime
2199 /// <exception cref="InvalidOperationException">
2200 /// This can occur due to the following reasons:
2201 /// 1) The application does not have the privilege to call this function.
2202 /// 2) The IME main loop has not yet started.
2204 /// <since_tizen> 6 </since_tizen>
2205 public static void SendCustomGeometryUpdated()
2207 ErrorCode error = ImeUpdateInputPanelEvent(ImeEventType.Geometry, 0);
2208 if (error != ErrorCode.None)
2210 Log.Error(LogTag, "SendCustomGeometryUpdated Failed with error " + error);
2211 throw InputMethodExceptionFactory.CreateException(error);