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 static Interop.InputMethod;
23 namespace Tizen.Uix.InputMethod
26 /// Enumeration for the key codes.
27 /// If keycode & 0xff000000 == 0x01000000 then this key code is directly encoded to 24-bit UCS character. The UCS value is keycode & 0x00ffffff.
28 /// Defines the list of keys supported by the system. Note that certain keys may not be available on all the devices.
30 /// <since_tizen> 4 </since_tizen>
34 /// The Backspace key.
58 /// The Scroll lock key.
62 /// The System Request key.
74 /* Cursor control & motion */
80 /// The Left directional key.
84 /// The Up directional key.
88 /// The Right directional key.
92 /// The Down directional key.
96 /// The Prior, Previous key.
108 /// The Page Down key.
130 /// The Execute, Run, Do key.
154 /// The Cancel, Stop, Abort, Exit key.
166 /// The character set switch key.
168 Mode_switch = 0xFF7E,
170 /// The Number Lock key.
176 /// The Numpad Space key.
180 /// The Numpad Tab key.
184 /// The Numpad Enter key.
188 /// The Numpad Function 1 key.
192 /// The Numpad Function 2 key.
196 /// The Numpad Function 3 key.
200 /// The Numpad Function 4 key.
204 /// The Numpad Home key.
208 /// The Numpad Left key.
212 /// The Numpad Up key.
216 /// The Numpad Right key.
220 /// The Numpad Down key.
224 /// The Numpad Prior, Previous key.
228 /// The Numpad Page Up key.
232 /// The Numpad Next key.
236 /// The Numpad Page Down key.
238 KPPage_Down = 0xFF9B,
240 /// The Numpad End key.
244 /// The Numpad Begin key.
248 /// The Numpad Insert key.
252 /// The Numpad Delete key.
256 /// The Numpad Equal key.
260 /// The Numpad Multiply key.
264 /// The Numpad Add key.
268 /// The Numpad Separator key.
270 KPSeparator = 0xFFAC,
272 /// The Numpad Subtract key.
276 /// The Numpad Decimal key.
280 /// The Numpad Divide key.
284 /// The Numpad 0 key.
288 /// The Numpad 1 key.
292 /// The Numpad 2 key.
296 /// The Numpad 3 key.
300 /// The Numpad 4 key.
304 /// The Numpad 5 key.
308 /// The Numpad 6 key.
312 /// The Numpad 7 key.
316 /// The Numpad 8 key.
320 /// The Numpad 9 key.
324 /* Auxiliary Functions */
326 /// The Function 1 key.
330 /// The Function 2 key.
334 /// The Function 3 key.
338 /// The Function 4 key.
342 /// The Function 5 key.
346 /// The Function 6 key.
350 /// The Function 7 key.
354 /// The Function 8 key.
358 /// The Function 9 key.
362 /// The Function 10 key.
366 /// The Function 11 key.
370 /// The Function 12 key.
374 /// The Function 13 key.
378 /// The Function 14 key.
382 /// The Function 15 key.
386 /// The Function 16 key.
390 /// The Function 17 key.
394 /// The Function 18 key.
398 /// The Function 19 key.
402 /// The Function 20 key.
406 /// The Function 21 key.
410 /// The Function 22 key.
414 /// The Function 23 key.
418 /// The Function 24 key.
422 /// The Function 25 key.
426 /// The Function 26 key.
430 /// The Function 27 key.
434 /// The Function 28 key.
438 /// The Function 29 key.
442 /// The Function 30 key.
446 /// The Function 31 key.
450 /// The Function 32 key.
454 /// The Function 33 key.
458 /// The Function 34 key.
462 /// The Function 35 key.
468 /// The Left Shift key.
472 /// The Right Shift key.
476 /// The Left Control key.
480 /// The Right Control key.
484 /// The Caps Lock key.
488 /// The Shift Lock key.
492 /// The Left Meta key.
496 /// The Right Meta key.
500 /// The Left Alt key.
504 /// The Right Alt key.
508 /// The Left Super key.
512 /// The Right Super key.
516 /// The Left Hyper key.
520 /// The Right Hyper key.
530 /// The Exclamation key.
534 /// The Quotedbl key.
538 /// The Number Sign key.
550 /// The Ampersand key.
554 /// The Apostrophe key.
558 /// The Parenleft key.
562 /// The Parenright key.
566 /// The Asterisk key.
634 /// The Semicolon key.
650 /// The Question key.
762 /// The Left Bracket key.
766 /// The Backslash key.
770 /// The Right Bracket key.
772 BracketRight = 0x05d,
774 /// The Circumflex key.
778 /// The Underscore key.
890 /// The Left Brace key.
898 /// The Right Brace key.
908 /// Enumeration for the key masks.
909 /// The key masks indicate which modifier keys are pressed down during the keyboard hit. The special MASK_RELEASED indicates the key release event.
911 /// <since_tizen> 4 </since_tizen>
915 /// Key press event without the modifier key.
919 /// The Shift key is pressed down.
923 /// The CapsLock key is pressed down.
927 /// The Control key is pressed down.
931 /// The Alt key is pressed down.
935 /// The Meta key is pressed down.
939 /// The Win key (between Control and Alt) is pressed down.
943 /// The Hyper key is pressed down.
947 /// The NumLock key is pressed down.
951 /// Key release event.
953 Released = (1 << 15),
957 /// This class contains the API's related to the IME (Input method editor).
959 /// <since_tizen> 4 </since_tizen>
960 public static class InputMethodEditor
962 private static Object thisLock = new Object();
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 ImeLanguageRequestedCb _imeLanguageRequestedDelegate;
992 private static OutAction<string> _languageRequestedDelegate;
993 private static BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> _processKeyDelagate;
994 private static ImeImdataRequestedCb _imeImDataRequestedDelegate;
995 private static OutArrayAction<byte> _imDataRequestedDelegate;
996 private static ImeGeometryRequestedCb _imeGeometryRequestedDelegate;
997 private static OutAction<Rect> _geometryRequestedDelegate;
998 private static Action _userCreate;
999 private static Action _userTerminate;
1000 private static Action<ContextId, InputMethodContext> _userShow;
1001 private static Action<ContextId> _userHide;
1002 private static ImeCreateCb _create = (IntPtr userData) =>
1004 Log.Info(LogTag, "In Create Delegate");
1005 _userCreate?.Invoke();
1007 private static ImeTerminateCb _terminate = (IntPtr userData) =>
1009 Log.Info(LogTag, "In terminate Delegate");
1010 _userTerminate?.Invoke();
1011 _imeCallbackStructGCHandle.Dispose();
1013 private static ImeShowCb _show = (int contextId, IntPtr context, IntPtr userData) =>
1015 Log.Info(LogTag, "In Show Delegate");
1016 _userShow?.Invoke(new ContextId(contextId), new InputMethodContext(context));
1018 private static ImeHideCb _hide = (int contextId, IntPtr userData) =>
1020 Log.Info(LogTag, "In Hide Delegate");
1021 _userHide?.Invoke(new ContextId(contextId));
1025 /// Structure representing the ContextId.
1027 /// <since_tizen> 4 </since_tizen>
1028 public struct ContextId : IEquatable<ContextId>
1030 internal ContextId(int id)
1042 /// Compares whether the ContextIds are equal.
1044 /// <since_tizen> 4 </since_tizen>
1045 public bool Equals(ContextId other)
1047 return this.Id == other.Id;
1052 /// Rectangle representing the position and size of the UI control.
1054 /// <since_tizen> 4 </since_tizen>
1058 /// The X position in the screen.
1060 /// <since_tizen> 4 </since_tizen>
1064 /// The Y position in the screen.
1066 /// <since_tizen> 4 </since_tizen>
1070 /// The window width.
1072 /// <since_tizen> 4 </since_tizen>
1076 /// The window height.
1078 /// <since_tizen> 4 </since_tizen>
1083 /// An action with 1 out parameter.
1085 /// <typeparam name="T">Generic Type.</typeparam>
1086 /// <param name="a">The out parameter.</param>
1087 /// <since_tizen> 4 </since_tizen>
1088 public delegate void OutAction<T>(out T a);
1091 /// An action with an array out parameter.
1093 /// <typeparam name="T">Generic Type.</typeparam>
1094 /// <param name="a">The out parameter 1.</param>
1095 /// <since_tizen> 4 </since_tizen>
1096 public delegate void OutArrayAction<T>(out T[] a);
1099 /// An action with 3 input parameters returning a bool.
1101 /// <typeparam name="T">Generic type for parameter 1.</typeparam>
1102 /// <typeparam name="T1">Generic type for parameter 2.</typeparam>
1103 /// <typeparam name="T2">Generic type for parameter 3.</typeparam>
1104 /// <param name="a">The input parameter 1.</param>
1105 /// <param name="b">The input parameter 2.</param>
1106 /// <param name="c">The input parameter 3.</param>
1107 /// <returns></returns>
1108 /// <since_tizen> 4 </since_tizen>
1109 public delegate bool BoolAction<T, T1, T2>(T a, T1 b, T2 c);
1112 /// Called when an associated text input UI control has focus.
1114 /// <since_tizen> 4 </since_tizen>
1115 public static event EventHandler<FocusedInEventArgs> FocusedIn
1121 _imeFocusedInDelegate = (int contextId, IntPtr userData) =>
1123 FocusedInEventArgs args = new FocusedInEventArgs(contextId);
1124 _focusIn?.Invoke(null, args);
1126 ErrorCode error = ImeEventSetFocusedInCb(_imeFocusedInDelegate, IntPtr.Zero);
1127 if (error != ErrorCode.None)
1129 Log.Error(LogTag, "Add FocusedIn Failed with error " + error);
1147 /// Called when an associated text input UI control loses focus.
1149 /// <since_tizen> 4 </since_tizen>
1150 public static event EventHandler<FocusedOutEventArgs> FocusedOut
1156 _imeFocusedOutDelegate = (int contextId, IntPtr userData) =>
1158 FocusedOutEventArgs args = new FocusedOutEventArgs(contextId);
1159 _focusOut?.Invoke(null, args);
1161 ErrorCode error = ImeEventSetFocusedOutCb(_imeFocusedOutDelegate, IntPtr.Zero);
1162 if (error != ErrorCode.None)
1164 Log.Error(LogTag, "Add FocusedOut Failed with error " + error);
1182 /// Called when an associated text input UI control responds to a request with the surrounding text.
1184 /// <since_tizen> 4 </since_tizen>
1185 public static event EventHandler<SurroundingTextUpdatedEventArgs> SurroundingTextUpdated
1191 _imeSurroundingTextUpdatedDelegate = (int contextId, IntPtr text, int cursorPos, IntPtr userData) =>
1193 SurroundingTextUpdatedEventArgs args = new SurroundingTextUpdatedEventArgs(contextId, Marshal.PtrToStringAnsi(text), cursorPos);
1194 _surroundingTextUpdated?.Invoke(null, args);
1196 ErrorCode error = ImeEventSetSurroundingTextUpdatedCb(_imeSurroundingTextUpdatedDelegate, IntPtr.Zero);
1197 if (error != ErrorCode.None)
1199 Log.Error(LogTag, "Add SurroundingTextUpdated Failed with error " + error);
1203 _surroundingTextUpdated += value;
1211 _surroundingTextUpdated -= value;
1217 /// Called to reset the input context of an associated text input UI control.
1219 /// <since_tizen> 4 </since_tizen>
1220 public static event EventHandler<EventArgs> InputContextReset
1226 _imeInputContextResetDelegate = (IntPtr userData) =>
1228 _inputContextReset?.Invoke(null, EventArgs.Empty);
1230 ErrorCode error = ImeEventSetInputContextResetCb(_imeInputContextResetDelegate, IntPtr.Zero);
1231 if (error != ErrorCode.None)
1233 Log.Error(LogTag, "Add InputContextReset Failed with error " + error);
1237 _inputContextReset += value;
1245 _inputContextReset -= value;
1251 /// Called when the position of the cursor in an associated text input UI control changes.
1253 /// <since_tizen> 4 </since_tizen>
1254 public static event EventHandler<CursorPositionUpdatedEventArgs> CursorPositionUpdated
1260 _imeCursorPositionUpdatedDelegate = (int cursorPos, IntPtr userData) =>
1262 CursorPositionUpdatedEventArgs args = new CursorPositionUpdatedEventArgs(cursorPos);
1263 _cursorPositionUpdated?.Invoke(null, args);
1265 ErrorCode error = ImeEventSetCursorPositionUpdatedCb(_imeCursorPositionUpdatedDelegate, IntPtr.Zero);
1266 if (error != ErrorCode.None)
1268 Log.Error(LogTag, "Add CursorPositionUpdated Failed with error " + error);
1272 _cursorPositionUpdated += value;
1280 _cursorPositionUpdated -= value;
1286 /// Called to set the preferred language to the input panel.
1287 /// It will only be called when the client application changes the edit field's language attribute after the input panel is shown.
1289 /// <since_tizen> 4 </since_tizen>
1290 public static event EventHandler<LanguageSetEventArgs> LanguageSet
1296 _imeLanguageSetDelegate = (InputPanelLanguage language, IntPtr userData) =>
1298 LanguageSetEventArgs args = new LanguageSetEventArgs(language);
1299 _langaugeSet?.Invoke(null, args);
1301 ErrorCode error = ImeEventSetLanguageSetCb(_imeLanguageSetDelegate, IntPtr.Zero);
1302 if (error != ErrorCode.None)
1304 Log.Error(LogTag, "Add LanguageSet Failed with error " + error);
1308 _langaugeSet += value;
1316 _langaugeSet -= value;
1322 /// Called to set the application specific data to deliver to the input panel.
1324 /// <since_tizen> 4 </since_tizen>
1325 public static event EventHandler<SetDataEventArgs> DataSet
1331 _imeDataSetDelegate = (IntPtr data, uint dataLength, IntPtr userData) =>
1333 byte[] destination = new byte[dataLength];
1334 Marshal.Copy(data, destination, 0, (int)dataLength);
1335 SetDataEventArgs args = new SetDataEventArgs(destination, dataLength);
1336 _imDataSet?.Invoke(null, args);
1338 ErrorCode error = ImeEventSetImdataSetCb(_imeDataSetDelegate, IntPtr.Zero);
1339 if (error != ErrorCode.None)
1341 Log.Error(LogTag, "Add DataSet Failed with error " + error);
1345 _imDataSet += value;
1353 _imDataSet -= value;
1359 /// Called when an associated text input UI control requests the input panel to set its layout.
1360 /// It will only be called when the client application changes the edit field's layout attribute after the input panel is shown.
1362 /// <since_tizen> 4 </since_tizen>
1363 public static event EventHandler<LayoutSetEventArgs> LayoutSet
1369 _imeLayoutSetDelegate = (InputPanelLayout layout, IntPtr userData) =>
1371 LayoutSetEventArgs args = new LayoutSetEventArgs(layout);
1372 _layoutSet?.Invoke(null, args);
1374 ErrorCode error = ImeEventSetLayoutSetCb(_imeLayoutSetDelegate, IntPtr.Zero);
1375 if (error != ErrorCode.None)
1377 Log.Error(LogTag, "Add LayoutSet Failed with error " + error);
1381 _layoutSet += value;
1389 _layoutSet -= value;
1395 /// Called when an associated text input UI control requests the input panel to set the Return key label.
1396 /// The input panel can show the text or an image on the Return button, according to the Return key action.
1398 /// <since_tizen> 4 </since_tizen>
1399 public static event EventHandler<ReturnKeySetEventArgs> ReturnKeySet
1405 _imeReturnKeySetDelegate = (InputPanelReturnKey type, IntPtr userData) =>
1407 ReturnKeySetEventArgs args = new ReturnKeySetEventArgs(type);
1408 _returnKeyTypeSet?.Invoke(null, args);
1410 ErrorCode error = ImeEventSetReturnKeySetCb(_imeReturnKeySetDelegate, IntPtr.Zero);
1411 if (error != ErrorCode.None)
1413 Log.Error(LogTag, "Add ReturnKeySet Failed with error " + error);
1417 _returnKeyTypeSet += value;
1425 _returnKeyTypeSet -= value;
1431 /// Called when an associated text input UI control requests the input panel to enable or disable the Return key state.
1433 /// <since_tizen> 4 </since_tizen>
1434 public static event EventHandler<ReturnKeyStateSetEventArgs> ReturnKeyStateSet
1440 _imeReturnKeyStateSetDelegate = (bool state, IntPtr userData) =>
1442 ReturnKeyStateSetEventArgs args = new ReturnKeyStateSetEventArgs(state);
1443 _returnKeyStateSet?.Invoke(null, args);
1445 ErrorCode error = ImeEventSetReturnKeyStateSetCb(_imeReturnKeyStateSetDelegate, IntPtr.Zero);
1446 if (error != ErrorCode.None)
1448 Log.Error(LogTag, "Add ReturnKeyStateSet Failed with error " + error);
1452 _returnKeyStateSet += value;
1460 _returnKeyStateSet -= value;
1466 /// Called when the system display language is changed.
1468 /// <since_tizen> 4 </since_tizen>
1469 public static event EventHandler<DisplayLanguageChangedEventArgs> DisplayLanguageChanged
1475 _imeDisplayLanguageChangedDelegate = (IntPtr language, IntPtr userData) =>
1477 DisplayLanguageChangedEventArgs args = new DisplayLanguageChangedEventArgs(Marshal.PtrToStringAnsi(language));
1478 _displayLanguageChanged?.Invoke(null, args);
1480 ErrorCode error = ImeEventSetDisplayLanguageChangedCb(_imeDisplayLanguageChangedDelegate, IntPtr.Zero);
1481 if (error != ErrorCode.None)
1483 Log.Error(LogTag, "Add DisplayLanguageChanged Failed with error " + error);
1487 _displayLanguageChanged += value;
1495 _displayLanguageChanged -= value;
1501 /// Called when the device is rotated.
1503 /// <since_tizen> 4 </since_tizen>
1504 public static event EventHandler<RotationChangedEventArgs> RotationChanged
1510 _imeRotationChangedDelegate = (int degree, IntPtr userData) =>
1512 RotationChangedEventArgs args = new RotationChangedEventArgs(degree);
1513 _rotationDegreeChanged?.Invoke(null, args);
1515 ErrorCode error = ImeEventSetRotationChangedCb(_imeRotationChangedDelegate, IntPtr.Zero);
1516 if (error != ErrorCode.None)
1518 Log.Error(LogTag, "Add RotationChanged Failed with error " + error);
1522 _rotationDegreeChanged += value;
1530 _rotationDegreeChanged -= value;
1536 /// Called when Accessibility in settings application is on or off.
1538 /// <since_tizen> 4 </since_tizen>
1539 public static event EventHandler<AccessibilityStateChangedEventArgs> AccessibilityStateChanged
1545 _imeAccessibilityStateChangedDelegate = (bool state, IntPtr userData) =>
1547 AccessibilityStateChangedEventArgs args = new AccessibilityStateChangedEventArgs(state);
1548 _accessibilityStateChanged?.Invoke(null, args);
1550 ErrorCode error = ImeEventSetAccessibilityStateChangedCb(_imeAccessibilityStateChangedDelegate, IntPtr.Zero);
1551 if (error != ErrorCode.None)
1553 Log.Error(LogTag, "Add AccessibilityStateChanged Failed with error " + error);
1557 _accessibilityStateChanged += value;
1565 _accessibilityStateChanged -= value;
1571 /// Sets the languageRequested action.
1573 /// <param name="languageRequested">
1574 /// Called when an associated text input UI control requests the language from the input panel, requesting for language code.
1576 /// <since_tizen> 4 </since_tizen>
1577 public static void SetLanguageRequestedCallback(OutAction<string> languageRequested)
1579 _imeLanguageRequestedDelegate = (IntPtr userData, out IntPtr langCode) =>
1582 _languageRequestedDelegate(out langauage);
1583 char[] languageArray = langauage.ToCharArray();
1584 langCode = new IntPtr();
1585 Marshal.Copy(languageArray, 0, langCode, languageArray.Length);
1587 ErrorCode error = ImeEventSetLanguageRequestedCallbackCb(_imeLanguageRequestedDelegate, IntPtr.Zero);
1588 if (error != ErrorCode.None)
1590 Log.Error(LogTag, "Add SetLanguageRequestedCallback Failed with error " + error);
1592 _languageRequestedDelegate = languageRequested;
1596 /// Sets the processKey action.
1597 /// If the key event is from the external device, DeviceInfo will have its name, class, and subclass information.
1599 /// <param name="processKey">
1600 /// The action is called when the key event is received from the external devices or the SendKey function.
1601 /// This Event processes the key event before an associated text input UI control does.
1603 /// <since_tizen> 4 </since_tizen>
1604 public static void SetProcessKeyCallback(BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> processKey)
1606 _imeProcessKeyDelegate = (KeyCode keyCode, KeyMask keyMask, IntPtr devInfo, IntPtr userData) =>
1608 return _processKeyDelagate(keyCode, keyMask, new InputMethodDeviceInformation(devInfo));
1610 ErrorCode error = ImeEventSetProcessKeyEventCb(_imeProcessKeyDelegate, IntPtr.Zero);
1611 if (error != ErrorCode.None)
1613 Log.Error(LogTag, "Add ProcessKey Failed with error " + error);
1615 _processKeyDelagate = processKey;
1619 /// Sets the imDataRequested action.
1621 /// <param name="imDataRequested">
1622 /// 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.
1624 /// <since_tizen> 4 </since_tizen>
1625 public static void SetDataRequestedCallback(OutArrayAction<byte> imDataRequested)
1627 _imeImDataRequestedDelegate = (IntPtr userData, out IntPtr data, out uint dataLength) =>
1630 _imDataRequestedDelegate(out dataArr);
1631 data = new IntPtr();
1632 Marshal.Copy(dataArr, 0, data, dataArr.Length);
1633 dataLength = (uint)dataArr.Length;
1635 ErrorCode error = ImeEventSetImdataRequestedCb(_imeImDataRequestedDelegate, IntPtr.Zero);
1636 if (error != ErrorCode.None)
1638 Log.Error(LogTag, "Add SetDataRequestedCallback Failed with error " + error);
1640 _imDataRequestedDelegate = imDataRequested;
1644 /// Sets the GeometryRequested action.
1646 /// <param name="geometryRequested">
1647 /// Called when an associated text input UI control requests the position and size from the input panel, requesting for x, y, w, h values.
1649 /// <since_tizen> 4 </since_tizen>
1650 public static void SetGeometryRequestedCallback(OutAction<Rect> geometryRequested)
1652 _imeGeometryRequestedDelegate = (IntPtr userData, out int x, out int y, out int w, out int h) =>
1654 Rect rect = new Rect();
1655 _geometryRequestedDelegate(out rect);
1661 ErrorCode error = ImeEventSetGeometryRequestedCallbackCb(_imeGeometryRequestedDelegate, IntPtr.Zero);
1662 if (error != ErrorCode.None)
1664 Log.Error(LogTag, "Add SetGeometryRequestedCallback Failed with error " + error);
1666 _geometryRequestedDelegate = geometryRequested;
1670 /// Runs the main loop of the IME application.
1671 /// This function starts to run the IME application's main loop.
1674 /// http://tizen.org/privilege/ime
1677 /// This API is a blocking call, as it starts the main loop of the application.
1679 /// <param name="create">This is called to initialize the IME application before the main loop starts up.</param>
1680 /// <param name="terminate">This is called when the IME application is terminated.</param>
1681 /// <param name="show">
1682 /// This is called when the IME application is shown.
1683 /// It provides the context information and the context ID.
1685 /// <param name="hide">
1686 /// This is called when the IME application is hidden.
1687 /// It provides the context ID.
1689 /// <exception cref="InvalidOperationException">
1690 /// This can occur due to the following reasons:
1691 /// 1) The application does not have the privilege to call this function.
1692 /// 2) Operation failed.
1694 /// <since_tizen> 4 </since_tizen>
1695 public static void Run(Action create, Action terminate, Action<ContextId, InputMethodContext> show, Action<ContextId> hide)
1697 _userCreate = create;
1698 _userTerminate = terminate;
1701 _imeCallbackStructGCHandle._imeCallbackStruct.create = _create;
1702 _imeCallbackStructGCHandle._imeCallbackStruct.terminate = _terminate;
1703 _imeCallbackStructGCHandle._imeCallbackStruct.hide = _hide;
1704 _imeCallbackStructGCHandle._imeCallbackStruct.show = _show;
1706 ImeSetDotnetFlag(true);
1707 ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero);
1708 if (error != ErrorCode.None)
1710 Log.Error(LogTag, "Run Failed with error " + error);
1711 throw InputMethodExceptionFactory.CreateException(error);
1717 /// Sends a key event to the associated text input UI control.
1720 /// 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.
1721 /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field.
1724 /// http://tizen.org/privilege/ime
1726 /// <param name="keyCode">The key code to be sent.</param>
1727 /// <param name="keyMask">The modifier key mask.</param>
1728 /// <param name="forwardKey">The flag to send the key event directly to the edit field.</param>
1729 /// <exception cref="InvalidOperationException">
1730 /// This can occur due to the following reasons:
1731 /// 1) The application does not have the privilege to call this function.
1732 /// 2) The IME main loop isn't started yet.
1734 /// <since_tizen> 4 </since_tizen>
1735 public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false)
1737 ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey);
1738 if (error != ErrorCode.None)
1740 Log.Error(LogTag, "SendEvent Failed with error " + error);
1741 throw InputMethodExceptionFactory.CreateException(error);
1746 /// Sends the text to the associated text input UI control.
1749 /// http://tizen.org/privilege/ime
1751 /// <param name="str">The string to be committed.</param>
1752 /// <exception cref="InvalidOperationException">
1753 /// This can occur due to the following reasons:
1754 /// 1) The application does not have the privilege to call this function.
1755 /// 2) The IME main loop isn't started yet.
1757 /// <since_tizen> 4 </since_tizen>
1758 public static void CommitString(string str)
1760 ErrorCode error = ImeCommitString(str);
1761 if (error != ErrorCode.None)
1763 Log.Error(LogTag, "CommitString Failed with error " + error);
1764 throw InputMethodExceptionFactory.CreateException(error);
1769 /// Requests to show the pre-edit string.
1772 /// http://tizen.org/privilege/ime
1774 /// <exception cref="InvalidOperationException">
1775 /// This can occur due to the following reasons:
1776 /// 1) The application does not have the privilege to call this function.
1777 /// 2) The IME main loop isn't started yet.
1779 /// <since_tizen> 4 </since_tizen>
1780 public static void ShowPreEditString()
1782 ErrorCode error = ImeShowPreeditString();
1783 if (error != ErrorCode.None)
1785 Log.Error(LogTag, "ShowPreEditString Failed with error " + error);
1786 throw InputMethodExceptionFactory.CreateException(error);
1791 /// Requests to hide the pre-edit string.
1794 /// http://tizen.org/privilege/ime
1796 /// <exception cref="InvalidOperationException">
1797 /// This can occur due to the following reasons:
1798 /// 1) The application does not have the privilege to call this function.
1799 /// 2) The IME main loop isn't started yet.
1801 /// <since_tizen> 4 </since_tizen>
1802 public static void HidePreEditString()
1804 ErrorCode error = ImeHidePreeditString();
1805 if (error != ErrorCode.None)
1807 Log.Error(LogTag, "HidePreEditString Failed with error " + error);
1808 throw InputMethodExceptionFactory.CreateException(error);
1813 /// Updates a new pre-edit string.
1816 /// http://tizen.org/privilege/ime
1818 /// <param name="str">The string to be updated in pre-edit.</param>
1819 /// <param name="attrs">
1820 /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color, and reversal color.
1821 /// The attrs list can be empty if no attributes to set.
1823 /// <exception cref="InvalidOperationException">
1824 /// This can occur due to the following reasons:
1825 /// 1) The application does not have the privilege to call this function.
1826 /// 2) The IME main loop isn't started yet.
1827 /// 3) Invalid parameter.
1829 /// <since_tizen> 4 </since_tizen>
1830 public static void UpdatePreEditString(string str, IEnumerable<PreEditAttribute> attrs)
1832 IntPtr einaList = IntPtr.Zero;
1833 List<GCHandle> attributeHandleList = new List<GCHandle>();
1834 foreach (PreEditAttribute attribute in attrs)
1836 ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct();
1837 imePreEditAttribute.start = attribute.Start;
1838 imePreEditAttribute.length = attribute.Length;
1839 imePreEditAttribute.type = (int)attribute.Type;
1840 imePreEditAttribute.value = attribute.Value;
1841 GCHandle attributeHandle = GCHandle.Alloc(imePreEditAttribute, GCHandleType.Pinned);
1842 attributeHandleList.Add(attributeHandle);
1843 einaList = Interop.EinaList.EinaListAppend(einaList, attributeHandle.AddrOfPinnedObject());
1845 ErrorCode error = ImeUpdatePreeditString(str, einaList);
1846 foreach (GCHandle handle in attributeHandleList)
1850 if (error != ErrorCode.None)
1852 Log.Error(LogTag, "UpdatePreEditString Failed with error " + error);
1853 throw InputMethodExceptionFactory.CreateException(error);
1858 /// Requests the surrounding text from the position of the cursor, asynchronously.
1861 /// http://tizen.org/privilege/ime
1863 /// <param name="maxLenBefore">The maximum length of the string to be retrieved before the cursor, -1 means unlimited.</param>
1864 /// <param name="maxLenAfter">The maximum length of the string to be retrieved after the cursor, -1 means unlimited.</param>
1865 /// <exception cref="InvalidOperationException">
1866 /// This can occur due to the following reasons:
1867 /// 1) The application does not have the privilege to call this function.
1868 /// 2) The IME main loop isn't started yet.
1871 /// The requested surrounding text can be received using the SurroundingTextUpdated event, only if it is set.
1872 /// </postcondition>
1873 /// <since_tizen> 4 </since_tizen>
1874 public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter)
1876 ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter);
1877 if (error != ErrorCode.None)
1879 Log.Error(LogTag, "RequestSurroundingText Failed with error " + error);
1880 throw InputMethodExceptionFactory.CreateException(error);
1885 /// Requests to delete the surrounding text.
1888 /// http://tizen.org/privilege/ime
1890 /// <param name="offset">The offset value from the cursor position.</param>
1891 /// <param name="len">The length of the text to delete.</param>
1892 /// <exception cref="InvalidOperationException">
1893 /// This can occur due to the following reasons:
1894 /// 1) The application does not have the privilege to call this function.
1895 /// 2) The IME main loop isn't started yet.
1896 /// 3) Invalid parameter.
1898 /// <since_tizen> 4 </since_tizen>
1899 public static void DeleteSurroundingText(int offset, int len)
1901 ErrorCode error = ImeDeleteSurroundingText(offset, len);
1902 if (error != ErrorCode.None)
1904 Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error);
1905 throw InputMethodExceptionFactory.CreateException(error);
1910 /// Gets the surrounding text from the position of the cursor, synchronously.
1913 /// http://tizen.org/privilege/ime
1915 /// <param name="maxLenBefore">The maximum length of the string to be retrieved before the cursor, -1 means unlimited.</param>
1916 /// <param name="maxLenAfter">The maximum length of the string to be retrieved after the cursor, -1 means unlimited.</param>
1917 /// <param name="text">The surrounding text.</param>
1918 /// <param name="cursorPosition">The cursor position.</param>
1919 /// <exception cref="InvalidOperationException">
1920 /// This can occur due to the following reasons:
1921 /// 1) The application does not have the privilege to call this function.
1922 /// 2) The IME main loop isn't started yet.
1923 /// 3) Invalid parameter.
1924 /// 4) Failed to obtain text due to out of memory.
1926 /// <since_tizen> 4 </since_tizen>
1927 public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition)
1930 ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition);
1931 if (error != ErrorCode.None)
1933 Log.Error(LogTag, "GetSurroundingText Failed with error " + error);
1934 throw InputMethodExceptionFactory.CreateException(error);
1936 text = Marshal.PtrToStringAnsi(txt);
1940 /// Requests to set the selection.
1943 /// http://tizen.org/privilege/ime
1945 /// <param name="start">The start cursor position in text (in characters not bytes).</param>
1946 /// <param name="end">The end cursor position in text (in characters not bytes).</param>
1947 /// <exception cref="InvalidOperationException">
1948 /// This can occur due to the following reasons:
1949 /// 1) The application does not have the privilege to call this function.
1950 /// 2) The IME main loop isn't started yet.
1951 /// 3) Invalid parameter.
1953 /// <since_tizen> 4 </since_tizen>
1954 public static void SetSelection(int start, int end)
1956 ErrorCode error = ImeSetSelection(start, end);
1957 if (error != ErrorCode.None)
1959 Log.Error(LogTag, "SetSelection Failed with error " + error);
1960 throw InputMethodExceptionFactory.CreateException(error);
1965 /// This API returns the input panel main window.
1968 /// http://tizen.org/privilege/ime
1970 /// <returns>The input panel main window object on success, otherwise null.</returns>
1971 /// <exception cref="InvalidOperationException">
1972 /// This can occur due to the following reasons:
1973 /// 1) The application does not have the privilege to call this function.
1974 /// 2) The IME main loop isn't started yet.
1975 /// 3) Operation failed.
1977 /// <since_tizen> 4 </since_tizen>
1978 public static EditorWindow GetMainWindow()
1980 EditorWindow._handle = ImeGetMainWindow();
1981 EditorWindow obj = new EditorWindow();
1982 ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
1983 if (error != ErrorCode.None)
1985 Log.Error(LogTag, "GetMainWindow Failed with error " + error);
1986 throw InputMethodExceptionFactory.CreateException(error);
1992 /// This API requests the InputMethodEditor to initialize.
1995 /// http://tizen.org/privilege/ime
1997 /// <exception cref="InvalidOperationException">
1998 /// This can occur due to the following reasons:
1999 /// 1) The application does not have the privilege to call this function.
2000 /// 2) Operation failed.
2002 /// <since_tizen> 4 </since_tizen>
2003 public static void Create()
2005 ErrorCode error = ImeInitialize();
2006 Log.Info(LogTag, "ImeInitialize result : " + error);
2007 if (error != ErrorCode.None)
2009 Log.Error(LogTag, "ImeInitialize Failed with error " + error);
2010 throw InputMethodExceptionFactory.CreateException(error);
2013 error = ImePrepare();
2014 Log.Info(LogTag, "ImePrepare result : " + error);
2015 if (error != ErrorCode.None)
2017 Log.Error(LogTag, "ImePrepare Failed with error " + error);
2018 throw InputMethodExceptionFactory.CreateException(error);
2023 /// This API requests the InputMethodEditor to finalize.
2026 /// http://tizen.org/privilege/ime
2028 /// <exception cref="InvalidOperationException">
2029 /// This can occur due to the following reasons:
2030 /// 1) The application does not have the privilege to call this function.
2031 /// 2) Operation failed.
2033 /// <since_tizen> 4 </since_tizen>
2034 public static void Destroy()
2036 ErrorCode error = ImeFinalize();
2037 Log.Info(LogTag, "ImeFinalize result : " + error);
2038 if (error != ErrorCode.None)
2040 Log.Error(LogTag, "ImeFinalize Failed with error " + error);
2041 throw InputMethodExceptionFactory.CreateException(error);