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 of the key codes.
27 /// If keycode & 0xff000000 == 0x01000000 then this key code is directly encoded 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 devices.
30 /// <since_tizen> 4 </since_tizen>
58 /// The scroll lock 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,
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
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
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
538 /// The number sign key
550 /// The ampersand key
554 /// The apostrophe key
558 /// The parenleft key
562 /// The parenright key
634 /// The semicolon 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 of the key masks.
909 /// The key masks indicate which modifier keys is 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 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 (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 api's related to 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 ContextId
1027 /// <since_tizen> 4 </since_tizen>
1028 public struct ContextId : IEquatable<ContextId>
1030 internal ContextId(int id)
1042 /// compare whether ContextId 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 UI Control
1054 /// <since_tizen> 4 </since_tizen>
1058 /// The x position in screen
1060 /// <since_tizen> 4 </since_tizen>
1064 /// The y position in 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 Parameter 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 be only 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 be only 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 text or 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 alled when the key event is received from the external devices or 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 IME application.
1671 /// This function starts to run 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 IME application before the main loop starts up</param>
1680 /// <param name="terminate">This is called when IME application is terminated</param>
1681 /// <param name="show">
1682 /// This is called when IME application is shown
1683 /// It provides the Context Information and the Context Id
1685 /// <param name="hide">
1686 /// This is called when 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 ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero);
1707 if (error != ErrorCode.None)
1709 Log.Error(LogTag, "Run Failed with error " + error);
1710 throw InputMethodExceptionFactory.CreateException(error);
1716 /// Sends a key event to the associated text input UI control.
1719 /// This function sends key down or up event with key mask to the client application. If forwardKey is true, this key event goes to the edit filed directly.
1720 /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field.
1723 /// http://tizen.org/privilege/ime
1725 /// <param name="keyCode">The key code to be sent</param>
1726 /// <param name="keyMask">The modifier key mask</param>
1727 /// <param name="forwardKey">The flag to send the key event directly to the edit field</param>
1728 /// <exception cref="InvalidOperationException">
1729 /// This can occur due to the following reasons:
1730 /// 1) The application does not have the privilege to call this function
1731 /// 2) IME main loop isn't started yet
1733 /// <since_tizen> 4 </since_tizen>
1734 public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false)
1736 ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey);
1737 if (error != ErrorCode.None)
1739 Log.Error(LogTag, "SendEvent Failed with error " + error);
1740 throw InputMethodExceptionFactory.CreateException(error);
1745 /// Sends the text to the associated text input UI control.
1748 /// http://tizen.org/privilege/ime
1750 /// <param name="str">The string to be committed</param>
1751 /// <exception cref="InvalidOperationException">
1752 /// This can occur due to the following reasons:
1753 /// 1) The application does not have the privilege to call this function
1754 /// 2) IME main loop isn't started yet
1756 /// <since_tizen> 4 </since_tizen>
1757 public static void CommitString(string str)
1759 ErrorCode error = ImeCommitString(str);
1760 if (error != ErrorCode.None)
1762 Log.Error(LogTag, "CommitString Failed with error " + error);
1763 throw InputMethodExceptionFactory.CreateException(error);
1768 /// Requests to show preedit string.
1771 /// http://tizen.org/privilege/ime
1773 /// <exception cref="InvalidOperationException">
1774 /// This can occur due to the following reasons:
1775 /// 1) The application does not have the privilege to call this function
1776 /// 2) IME main loop isn't started yet
1778 /// <since_tizen> 4 </since_tizen>
1779 public static void ShowPreEditString()
1781 ErrorCode error = ImeShowPreeditString();
1782 if (error != ErrorCode.None)
1784 Log.Error(LogTag, "ShowPreEditString Failed with error " + error);
1785 throw InputMethodExceptionFactory.CreateException(error);
1790 /// Requests to hide preedit string.
1793 /// http://tizen.org/privilege/ime
1795 /// <exception cref="InvalidOperationException">
1796 /// This can occur due to the following reasons:
1797 /// 1) The application does not have the privilege to call this function
1798 /// 2) IME main loop isn't started yet
1800 /// <since_tizen> 4 </since_tizen>
1801 public static void HidePreEditString()
1803 ErrorCode error = ImeHidePreeditString();
1804 if (error != ErrorCode.None)
1806 Log.Error(LogTag, "HidePreEditString Failed with error " + error);
1807 throw InputMethodExceptionFactory.CreateException(error);
1812 /// Updates a new preedit string.
1815 /// http://tizen.org/privilege/ime
1817 /// <param name="str">The string to be updated in preedit</param>
1818 /// <param name="attrs">
1819 /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color and reversal color.
1820 /// The attrs list can be empty if no attributes to set
1822 /// <exception cref="InvalidOperationException">
1823 /// This can occur due to the following reasons:
1824 /// 1) The application does not have the privilege to call this function
1825 /// 2) IME main loop isn't started yet
1826 /// 3) Invalid Parameter
1828 /// <since_tizen> 4 </since_tizen>
1829 public static void UpdatePreEditString(string str, IEnumerable<PreEditAttribute> attrs)
1831 IntPtr einaList = IntPtr.Zero;
1832 List<GCHandle> attributeHandleList = new List<GCHandle>();
1833 foreach (PreEditAttribute attribute in attrs)
1835 ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct();
1836 imePreEditAttribute.start = attribute.Start;
1837 imePreEditAttribute.length = attribute.Length;
1838 imePreEditAttribute.type = (int)attribute.Type;
1839 imePreEditAttribute.value = attribute.Value;
1840 GCHandle attributeHandle = GCHandle.Alloc(imePreEditAttribute, GCHandleType.Pinned);
1841 attributeHandleList.Add(attributeHandle);
1842 einaList = Interop.EinaList.EinaListAppend(einaList, attributeHandle.AddrOfPinnedObject());
1844 ErrorCode error = ImeUpdatePreeditString(str, einaList);
1845 foreach (GCHandle handle in attributeHandleList)
1849 if (error != ErrorCode.None)
1851 Log.Error(LogTag, "UpdatePreEditString Failed with error " + error);
1852 throw InputMethodExceptionFactory.CreateException(error);
1857 /// Requests the surrounding text from the position of the cursor, asynchronously.
1860 /// http://tizen.org/privilege/ime
1862 /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1863 /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1864 /// <exception cref="InvalidOperationException">
1865 /// This can occur due to the following reasons:
1866 /// 1) The application does not have the privilege to call this function
1867 /// 2) IME main loop isn't started yet
1870 /// The requested surrounding text can be received using the SurroundingTextUpdated Event, only if it is set.
1871 /// </postcondition>
1872 /// <since_tizen> 4 </since_tizen>
1873 public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter)
1875 ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter);
1876 if (error != ErrorCode.None)
1878 Log.Error(LogTag, "RequestSurroundingText Failed with error " + error);
1879 throw InputMethodExceptionFactory.CreateException(error);
1884 /// Requests to delete surrounding text.
1887 /// http://tizen.org/privilege/ime
1889 /// <param name="offset">The offset value from the cursor position</param>
1890 /// <param name="len">The length of the text to delete</param>
1891 /// <exception cref="InvalidOperationException">
1892 /// This can occur due to the following reasons:
1893 /// 1) The application does not have the privilege to call this function
1894 /// 2) IME main loop isn't started yet
1895 /// 3) Invalid Parameter
1897 /// <since_tizen> 4 </since_tizen>
1898 public static void DeleteSurroundingText(int offset, int len)
1900 ErrorCode error = ImeDeleteSurroundingText(offset, len);
1901 if (error != ErrorCode.None)
1903 Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error);
1904 throw InputMethodExceptionFactory.CreateException(error);
1909 /// Gets the surrounding text from the position of the cursor, synchronously.
1912 /// http://tizen.org/privilege/ime
1914 /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1915 /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1916 /// <param name="text">The surrounding text</param>
1917 /// <param name="cursorPosition">The cursor position</param>
1918 /// <exception cref="InvalidOperationException">
1919 /// This can occur due to the following reasons:
1920 /// 1) The application does not have the privilege to call this function
1921 /// 2) IME main loop isn't started yet
1922 /// 3) Invalid Parameter
1923 /// 4) Failed to obtain text due to out of memory
1925 /// <since_tizen> 4 </since_tizen>
1926 public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition)
1929 ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition);
1930 if (error != ErrorCode.None)
1932 Log.Error(LogTag, "GetSurroundingText Failed with error " + error);
1933 throw InputMethodExceptionFactory.CreateException(error);
1935 text = Marshal.PtrToStringAnsi(txt);
1939 /// Requests to set selection.
1942 /// http://tizen.org/privilege/ime
1944 /// <param name="start">The start cursor position in text (in characters not bytes)</param>
1945 /// <param name="end">The end cursor position in text (in characters not bytes)</param>
1946 /// <exception cref="InvalidOperationException">
1947 /// This can occur due to the following reasons:
1948 /// 1) The application does not have the privilege to call this function
1949 /// 2) IME main loop isn't started yet
1950 /// 3) Invalid Parameter
1952 /// <since_tizen> 4 </since_tizen>
1953 public static void SetSelection(int start, int end)
1955 ErrorCode error = ImeSetSelection(start, end);
1956 if (error != ErrorCode.None)
1958 Log.Error(LogTag, "SetSelection Failed with error " + error);
1959 throw InputMethodExceptionFactory.CreateException(error);
1964 /// This API returns the input panel main window.
1967 /// http://tizen.org/privilege/ime
1969 /// <returns>The input panel main window object on success, otherwise null</returns>
1970 /// <exception cref="InvalidOperationException">
1971 /// This can occur due to the following reasons:
1972 /// 1) The application does not have the privilege to call this function
1973 /// 2) IME main loop isn't started yet
1974 /// 3) Operation Failed
1976 /// <since_tizen> 4 </since_tizen>
1977 public static EditorWindow GetMainWindow()
1979 EditorWindow._handle = ImeGetMainWindow();
1980 EditorWindow obj = new EditorWindow();
1981 ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
1982 if (error != ErrorCode.None)
1984 Log.Error(LogTag, "GetMainWindow Failed with error " + error);
1985 throw InputMethodExceptionFactory.CreateException(error);
1991 /// This API requests the InputMethodEditor to initialize
1994 /// http://tizen.org/privilege/ime
1996 /// <exception cref="InvalidOperationException">
1997 /// This can occur due to the following reasons:
1998 /// 1) The application does not have the privilege to call this function
1999 /// 2) Operation Failed
2001 /// <since_tizen> 4 </since_tizen>
2002 public static void Create()
2004 ErrorCode error = ImeInitialize();
2005 Log.Info(LogTag, "ImeInitialize result : " + error);
2006 if (error != ErrorCode.None)
2008 Log.Error(LogTag, "ImeInitialize Failed with error " + error);
2009 throw InputMethodExceptionFactory.CreateException(error);
2012 error = ImePrepare();
2013 Log.Info(LogTag, "ImePrepare result : " + error);
2014 if (error != ErrorCode.None)
2016 Log.Error(LogTag, "ImePrepare Failed with error " + error);
2017 throw InputMethodExceptionFactory.CreateException(error);
2022 /// This API requests the InputMethodEditor to finalize
2025 /// http://tizen.org/privilege/ime
2027 /// <exception cref="InvalidOperationException">
2028 /// This can occur due to the following reasons:
2029 /// 1) The application does not have the privilege to call this function
2030 /// 2) Operation Failed
2032 /// <since_tizen> 4 </since_tizen>
2033 public static void Destroy()
2035 ErrorCode error = ImeFinalize();
2036 Log.Info(LogTag, "ImeFinalize result : " + error);
2037 if (error != ErrorCode.None)
2039 Log.Error(LogTag, "ImeFinalize Failed with error " + error);
2040 throw InputMethodExceptionFactory.CreateException(error);