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.
57 /// The scroll lock key
73 /* Cursor control & motion */
79 /// The left directional key
83 /// The up directional key
87 /// The right directional key
91 /// The down directional key
95 /// The prior, previous key
107 /// The page down key
129 /// The execute, run, do key
153 /// The cancel, stop, abort, exit key
165 /// The character set switch key
167 Mode_switch = 0xFF7E,
175 /// The Numpad space key
179 /// The Numpad tab key
183 /// The Numpad enter key
187 /// The Numpad function 1 key
191 /// The Numpad function 2 key
195 /// The Numpad function 3 key
199 /// The Numpad function 4 key
203 /// The Numpad home key
207 /// The Numpad left key
211 /// The Numpad up key
215 /// The Numpad right key
219 /// The Numpad down key
223 /// The Numpad prior, previous key
227 /// The Numpad page up key
231 /// The Numpad next key
235 /// The Numpad page down key
237 KPPage_Down = 0xFF9B,
239 /// The Numpad end key
243 /// The Numpad begin key
247 /// The Numpad insert key
251 /// The Numpad delete key
255 /// The Numpad equal key
259 /// The Numpad multiply key
263 /// The Numpad add key
267 /// The Numpad separator key
269 KPSeparator = 0xFFAC,
271 /// The Numpad subtract key
275 /// The Numpad decimal key
279 /// The Numpad divide key
323 /* Auxilliary Functions */
325 /// The function 1 key
329 /// The function 2 key
333 /// The function 3 key
337 /// The function 4 key
341 /// The function 5 key
345 /// The function 6 key
349 /// The function 7 key
353 /// The function 8 key
357 /// The function 9 key
361 /// The function 10 key
365 /// The function 11 key
369 /// The function 12 key
373 /// The function 13 key
377 /// The function 14 key
381 /// The function 15 key
385 /// The function 16 key
389 /// The function 17 key
393 /// The function 18 key
397 /// The function 19 key
401 /// The function 20 key
405 /// The function 21 key
409 /// The function 22 key
413 /// The function 23 key
417 /// The function 24 key
421 /// The function 25 key
425 /// The function 26 key
429 /// The function 27 key
433 /// The function 28 key
437 /// The function 29 key
441 /// The function 30 key
445 /// The function 31 key
449 /// The function 32 key
453 /// The function 33 key
457 /// The function 34 key
461 /// The function 35 key
467 /// The left shift key
471 /// The right shift key
475 /// The left control key
479 /// The right control key
483 /// The caps lock key
487 /// The shift lock key
491 /// The left meta key
495 /// The right meta key
503 /// The right alt key
507 /// The left super key
511 /// The right super key
515 /// The left hyper key
519 /// The right hyper key
529 /// The exclamation key
537 /// The number sign key
549 /// The ampersand key
553 /// The apostrophe key
557 /// The parenleft key
561 /// The parenright key
633 /// The semicolon key
761 /// The left bracket key
765 /// The backslash key
769 /// The right bracket key
771 BracketRight = 0x05d,
773 /// The circumflex key
777 /// The underscore key
889 /// The left brace key
897 /// The right brace key
907 /// Enumeration of the key masks.
908 /// The key masks indicate which modifier keys is pressed down during the keyboard hit.The special MASK_RELEASED indicates the key release event.
913 /// Key press event without modifier key
917 /// The Shift key is pressed down
921 /// The CapsLock key is pressed down
925 /// The Control key is pressed down
929 /// The Alt key is pressed down
933 /// The Meta key is pressed down
937 /// The Win (between Control and Alt) is pressed down
941 /// The Hyper key is pressed down
945 /// The NumLock key is pressed down
949 /// Key release event
951 Released = (1 << 15),
955 /// This class contains api's related to IME(Input method editor)
957 public static class InputMethodEditor
959 private static Object thisLock = new Object();
960 private static ImeCallbackStructGCHandle _imeCallbackStructGCHandle = new ImeCallbackStructGCHandle();
961 private static event EventHandler<FocusedInEventArgs> _focusIn;
962 private static ImeFocusedInCb _imeFocusedInDelegate;
963 private static event EventHandler<FocusedOutEventArgs> _focusOut;
964 private static ImeFocusedOutCb _imeFocusedOutDelegate;
965 private static event EventHandler<SurroundingTextUpdatedEventArgs> _surroundingTextUpdated;
966 private static ImeSurroundingTextUpdatedCb _imeSurroundingTextUpdatedDelegate;
967 private static event EventHandler<EventArgs> _inputContextReset;
968 private static ImeInputContextResetCb _imeInputContextResetDelegate;
969 private static event EventHandler<CursorPositionUpdatedEventArgs> _cursorPositionUpdated;
970 private static ImeCursorPositionUpdatedCb _imeCursorPositionUpdatedDelegate;
971 private static event EventHandler<LanguageSetEventArgs> _langaugeSet;
972 private static ImeLanguageSetCb _imeLanguageSetDelegate;
973 private static event EventHandler<SetDataEventArgs> _imDataSet;
974 private static ImeImdataSetCb _imeDataSetDelegate;
975 private static event EventHandler<LayoutSetEventArgs> _layoutSet;
976 private static ImeLayoutSetCb _imeLayoutSetDelegate;
977 private static event EventHandler<ReturnKeySetEventArgs> _returnKeyTypeSet;
978 private static ImeReturnKeySetCb _imeReturnKeySetDelegate;
979 private static event EventHandler<ReturnKeyStateSetEventArgs> _returnKeyStateSet;
980 private static ImeReturnKeyStateSetCb _imeReturnKeyStateSetDelegate;
981 private static ImeProcessKeyEventCb _imeProcessKeyDelegate;
982 private static event EventHandler<DisplayLanaguageChangedEventArgs> _displayLanaguageChanged;
983 private static ImeDisplayLanguageChangedCb _imeDisplayLanaguageChangedDelegate;
984 private static event EventHandler<RotationChangedEventArgs> _rotationDegreeChanged;
985 private static ImeRotationChangedCb _imeRotationChangedDelegate;
986 private static event EventHandler<AccessibilityStateChangedEventArgs> _accessibilityStateChanged;
987 private static ImeAccessibilityStateChangedCb _imeAccessibilityStateChangedDelegate;
988 private static ImeLanguageRequestedCb _imeLanguageRequestedDelegate;
989 private static OutAction<string> _languageRequestedDelegate;
990 private static BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> _processKeyDelagate;
991 private static ImeImdataRequestedCb _imeImDataRequestedDelegate;
992 private static OutArrayAction<byte> _imDataRequestedDelegate;
993 private static ImeGeometryRequestedCb _imeGeometryRequestedDelegate;
994 private static OutAction<Rect> _geometryRequestedDelegate;
995 private static Action _userCreate;
996 private static Action _userTerminate;
997 private static Action<ContextId, InputMethodContext> _userShow;
998 private static Action<ContextId> _userHide;
999 private static ImeCreateCb _create = (IntPtr userData) =>
1001 Log.Info(LogTag, "In Create Delegate");
1002 _userCreate?.Invoke();
1004 private static ImeTerminateCb _terminate = (IntPtr userData) =>
1006 Log.Info(LogTag, "In terminate Delegate");
1007 _userTerminate?.Invoke();
1008 _imeCallbackStructGCHandle.Dispose();
1010 private static ImeShowCb _show = (int contextId, IntPtr context, IntPtr userData) =>
1012 Log.Info(LogTag, "In Show Delegate");
1013 _userShow?.Invoke(new ContextId(contextId), new InputMethodContext(context));
1015 private static ImeHideCb _hide = (int contextId, IntPtr userData) =>
1017 Log.Info(LogTag, "In Hide Delegate");
1018 _userHide?.Invoke(new ContextId(contextId));
1022 /// Structure representing ContextId
1024 public struct ContextId : IEquatable<ContextId>
1026 internal ContextId(int id)
1037 public bool Equals(ContextId other)
1039 return this.Id == other.Id;
1044 /// rectangle representing the position and size of UI Control
1049 /// The x position in screen
1054 /// The y position in screen
1059 /// The window width
1064 /// The window height
1070 /// An Action with 1 out parameter
1072 /// <typeparam name="T">Generic Type</typeparam>
1073 /// <param name="a">The out parameter</param>
1074 public delegate void OutAction<T>(out T a);
1077 /// An Action with an array out parameter
1079 /// <typeparam name="T">Generic Type</typeparam>
1080 /// <param name="a">The out parameter 1</param>
1081 public delegate void OutArrayAction<T>(out T[] a);
1084 /// An Action with 3 Input Parameter returning a bool
1086 /// <typeparam name="T">Generic Type for Parameter 1</typeparam>
1087 /// <typeparam name="T1">Generic Type for Parameter 2</typeparam>
1088 /// <typeparam name="T2">Generic Type for Parameter 3</typeparam>
1089 /// <param name="a">The Input Parameter 1</param>
1090 /// <param name="b">The Input Parameter 2</param>
1091 /// <param name="c">The Input Parameter 3</param>
1092 /// <returns></returns>
1093 public delegate bool BoolAction<T, T1, T2>(T a, T1 b, T2 c);
1096 /// Called when an associated text input UI control has focus.
1098 public static event EventHandler<FocusedInEventArgs> FocusedIn
1104 _imeFocusedInDelegate = (int contextId, IntPtr userData) =>
1106 FocusedInEventArgs args = new FocusedInEventArgs(contextId);
1107 _focusIn?.Invoke(null, args);
1109 ErrorCode error = ImeEventSetFocusedInCb(_imeFocusedInDelegate, IntPtr.Zero);
1110 if (error != ErrorCode.None)
1112 Log.Error(LogTag, "Add FocusedIn Failed with error " + error);
1130 /// Called when an associated text input UI control loses focus.
1132 public static event EventHandler<FocusedOutEventArgs> FocusedOut
1138 _imeFocusedOutDelegate = (int contextId, IntPtr userData) =>
1140 FocusedOutEventArgs args = new FocusedOutEventArgs(contextId);
1141 _focusOut?.Invoke(null, args);
1143 ErrorCode error = ImeEventSetFocusedOutCb(_imeFocusedOutDelegate, IntPtr.Zero);
1144 if (error != ErrorCode.None)
1146 Log.Error(LogTag, "Add FocusedOut Failed with error " + error);
1164 /// Called when an associated text input UI control responds to a request with the surrounding text.
1166 public static event EventHandler<SurroundingTextUpdatedEventArgs> SurroundingTextUpdated
1172 _imeSurroundingTextUpdatedDelegate = (int contextId, IntPtr text, int cursorPos, IntPtr userData) =>
1174 SurroundingTextUpdatedEventArgs args = new SurroundingTextUpdatedEventArgs(contextId, Marshal.PtrToStringAnsi(text), cursorPos);
1175 _surroundingTextUpdated?.Invoke(null, args);
1177 ErrorCode error = ImeEventSetSurroundingTextUpdatedCb(_imeSurroundingTextUpdatedDelegate, IntPtr.Zero);
1178 if (error != ErrorCode.None)
1180 Log.Error(LogTag, "Add SurroundingTextUpdated Failed with error " + error);
1184 _surroundingTextUpdated += value;
1192 _surroundingTextUpdated -= value;
1198 /// Called to reset the input context of an associated text input UI control.
1200 public static event EventHandler<EventArgs> InputContextReset
1206 _imeInputContextResetDelegate = (IntPtr userData) =>
1208 _inputContextReset?.Invoke(null, EventArgs.Empty);
1210 ErrorCode error = ImeEventSetInputContextResetCb(_imeInputContextResetDelegate, IntPtr.Zero);
1211 if (error != ErrorCode.None)
1213 Log.Error(LogTag, "Add InputContextReset Failed with error " + error);
1217 _inputContextReset += value;
1225 _inputContextReset -= value;
1231 /// Called when the position of the cursor in an associated text input UI control changes.
1233 public static event EventHandler<CursorPositionUpdatedEventArgs> CursorPositionUpdated
1239 _imeCursorPositionUpdatedDelegate = (int cursorPos, IntPtr userData) =>
1241 CursorPositionUpdatedEventArgs args = new CursorPositionUpdatedEventArgs(cursorPos);
1242 _cursorPositionUpdated?.Invoke(null, args);
1244 ErrorCode error = ImeEventSetCursorPositionUpdatedCb(_imeCursorPositionUpdatedDelegate, IntPtr.Zero);
1245 if (error != ErrorCode.None)
1247 Log.Error(LogTag, "Add CursorPositionUpdated Failed with error " + error);
1251 _cursorPositionUpdated += value;
1259 _cursorPositionUpdated -= value;
1265 /// Called to set the preferred language to the input panel.
1266 /// It will be only called when the client application changes the edit field's language attribute after the input panel is shown.
1268 public static event EventHandler<LanguageSetEventArgs> LanguageSet
1274 _imeLanguageSetDelegate = (InputPanelLanguage language, IntPtr userData) =>
1276 LanguageSetEventArgs args = new LanguageSetEventArgs(language);
1277 _langaugeSet?.Invoke(null, args);
1279 ErrorCode error = ImeEventSetLanguageSetCb(_imeLanguageSetDelegate, IntPtr.Zero);
1280 if (error != ErrorCode.None)
1282 Log.Error(LogTag, "Add LanguageSet Failed with error " + error);
1286 _langaugeSet += value;
1294 _langaugeSet -= value;
1300 /// Called to set the application specific data to deliver to the input panel.
1302 public static event EventHandler<SetDataEventArgs> DataSet
1308 _imeDataSetDelegate = (IntPtr data, uint dataLength, IntPtr userData) =>
1310 byte[] destination = new byte[dataLength];
1311 Marshal.Copy(data, destination, 0, (int)dataLength);
1312 SetDataEventArgs args = new SetDataEventArgs(destination, dataLength);
1313 _imDataSet?.Invoke(null, args);
1315 ErrorCode error = ImeEventSetImdataSetCb(_imeDataSetDelegate, IntPtr.Zero);
1316 if (error != ErrorCode.None)
1318 Log.Error(LogTag, "Add DataSet Failed with error " + error);
1322 _imDataSet += value;
1330 _imDataSet -= value;
1336 /// Called when an associated text input UI control requests the input panel to set its layout.
1337 /// It will be only called when the client application changes the edit field's layout attribute after the input panel is shown.
1339 public static event EventHandler<LayoutSetEventArgs> LayoutSet
1345 _imeLayoutSetDelegate = (InputPanelLayout layout, IntPtr userData) =>
1347 LayoutSetEventArgs args = new LayoutSetEventArgs(layout);
1348 _layoutSet?.Invoke(null, args);
1350 ErrorCode error = ImeEventSetLayoutSetCb(_imeLayoutSetDelegate, IntPtr.Zero);
1351 if (error != ErrorCode.None)
1353 Log.Error(LogTag, "Add LayoutSet Failed with error " + error);
1357 _layoutSet += value;
1365 _layoutSet -= value;
1371 /// Called when an associated text input UI control requests the input panel to set the Return key label.
1372 /// The input panel can show text or image on the Return button according to the Return key action.
1374 public static event EventHandler<ReturnKeySetEventArgs> ReturnKeySet
1380 _imeReturnKeySetDelegate = (InputPanelReturnKey type, IntPtr userData) =>
1382 ReturnKeySetEventArgs args = new ReturnKeySetEventArgs(type);
1383 _returnKeyTypeSet?.Invoke(null, args);
1385 ErrorCode error = ImeEventSetReturnKeySetCb(_imeReturnKeySetDelegate, IntPtr.Zero);
1386 if (error != ErrorCode.None)
1388 Log.Error(LogTag, "Add ReturnKeySet Failed with error " + error);
1392 _returnKeyTypeSet += value;
1400 _returnKeyTypeSet -= value;
1406 /// Called when an associated text input UI control requests the input panel to enable or disable the Return key state.
1408 public static event EventHandler<ReturnKeyStateSetEventArgs> ReturnKeyStateSet
1414 _imeReturnKeyStateSetDelegate = (bool state, IntPtr userData) =>
1416 ReturnKeyStateSetEventArgs args = new ReturnKeyStateSetEventArgs(state);
1417 _returnKeyStateSet?.Invoke(null, args);
1419 ErrorCode error = ImeEventSetReturnKeyStateSetCb(_imeReturnKeyStateSetDelegate, IntPtr.Zero);
1420 if (error != ErrorCode.None)
1422 Log.Error(LogTag, "Add ReturnKeyStateSet Failed with error " + error);
1426 _returnKeyStateSet += value;
1434 _returnKeyStateSet -= value;
1440 /// Called when the system display language is changed.
1442 public static event EventHandler<DisplayLanaguageChangedEventArgs> DisplayLanaguageChanged
1448 _imeDisplayLanaguageChangedDelegate = (IntPtr language, IntPtr userData) =>
1450 DisplayLanaguageChangedEventArgs args = new DisplayLanaguageChangedEventArgs(Marshal.PtrToStringAnsi(language));
1451 _displayLanaguageChanged?.Invoke(null, args);
1453 ErrorCode error = ImeEventSetDisplayLanguageChangedCb(_imeDisplayLanaguageChangedDelegate, IntPtr.Zero);
1454 if (error != ErrorCode.None)
1456 Log.Error(LogTag, "Add DisplayLanaguageChanged Failed with error " + error);
1460 _displayLanaguageChanged += value;
1468 _displayLanaguageChanged -= value;
1474 /// Called when the device is rotated.
1476 public static event EventHandler<RotationChangedEventArgs> RotationChanged
1482 _imeRotationChangedDelegate = (int degree, IntPtr userData) =>
1484 RotationChangedEventArgs args = new RotationChangedEventArgs(degree);
1485 _rotationDegreeChanged?.Invoke(null, args);
1487 ErrorCode error = ImeEventSetRotationChangedCb(_imeRotationChangedDelegate, IntPtr.Zero);
1488 if (error != ErrorCode.None)
1490 Log.Error(LogTag, "Add RotationChanged Failed with error " + error);
1494 _rotationDegreeChanged += value;
1502 _rotationDegreeChanged -= value;
1508 /// Called when Accessibility in Settings application is on or off.
1510 public static event EventHandler<AccessibilityStateChangedEventArgs> AccessibilityStateChanged
1516 _imeAccessibilityStateChangedDelegate = (bool state, IntPtr userData) =>
1518 AccessibilityStateChangedEventArgs args = new AccessibilityStateChangedEventArgs(state);
1519 _accessibilityStateChanged?.Invoke(null, args);
1521 ErrorCode error = ImeEventSetAccessibilityStateChangedCb(_imeAccessibilityStateChangedDelegate, IntPtr.Zero);
1522 if (error != ErrorCode.None)
1524 Log.Error(LogTag, "Add AccessibilityStateChanged Failed with error " + error);
1528 _accessibilityStateChanged += value;
1536 _accessibilityStateChanged -= value;
1542 /// Sets the languageRequested Action
1544 /// <param name="languageRequested">
1545 /// Called when an associated text input UI control requests the language from the input panel, requesting for language code.
1547 public static void SetLanguageRequestedCallback(OutAction<string> languageRequested)
1549 _imeLanguageRequestedDelegate = (IntPtr userData, out IntPtr langCode) =>
1552 _languageRequestedDelegate(out langauage);
1553 char[] languageArray = langauage.ToCharArray();
1554 langCode = new IntPtr();
1555 Marshal.Copy(languageArray, 0, langCode, languageArray.Length);
1557 ErrorCode error = ImeEventSetLanguageRequestedCallbackCb(_imeLanguageRequestedDelegate, IntPtr.Zero);
1558 if (error != ErrorCode.None)
1560 Log.Error(LogTag, "Add SetLanguageRequestedCallback Failed with error " + error);
1562 _languageRequestedDelegate = languageRequested;
1566 /// Sets the processKey Action
1567 /// If the key event is from the external device, DeviceInfo will have its name, class and subclass information.
1569 /// <param name="processKey">
1570 /// The Action is alled when the key event is received from the external devices or SendKey function.
1571 /// This Event processes the key event before an associated text input UI control does.
1573 public static void SetProcessKeyCallback(BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> processKey)
1575 _imeProcessKeyDelegate = (KeyCode keyCode, KeyMask keyMask, IntPtr devInfo, IntPtr userData) =>
1577 return _processKeyDelagate(keyCode, keyMask, new InputMethodDeviceInformation(devInfo));
1579 ErrorCode error = ImeEventSetProcessKeyEventCb(_imeProcessKeyDelegate, IntPtr.Zero);
1580 if (error != ErrorCode.None)
1582 Log.Error(LogTag, "Add ProcessKey Failed with error " + error);
1584 _processKeyDelagate = processKey;
1588 /// Sets the imDataRequested Action
1590 /// <param name="imDataRequested">
1591 /// 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.
1593 public static void SetDataRequestedCallback(OutArrayAction<byte> imDataRequested)
1595 _imeImDataRequestedDelegate = (IntPtr userData, out IntPtr data, out uint dataLength) =>
1598 _imDataRequestedDelegate(out dataArr);
1599 data = new IntPtr();
1600 Marshal.Copy(dataArr, 0, data, dataArr.Length);
1601 dataLength = (uint)dataArr.Length;
1603 ErrorCode error = ImeEventSetImdataRequestedCb(_imeImDataRequestedDelegate, IntPtr.Zero);
1604 if (error != ErrorCode.None)
1606 Log.Error(LogTag, "Add SetDataRequestedCallback Failed with error " + error);
1608 _imDataRequestedDelegate = imDataRequested;
1612 /// Sets the GeometryRequested Action
1614 /// <param name="geometryRequested">
1615 /// Called when an associated text input UI control requests the position and size from the input panel, requesting for x,y,w,h values.
1617 public static void SetGeometryRequestedCallback(OutAction<Rect> geometryRequested)
1619 _imeGeometryRequestedDelegate = (IntPtr userData, out int x, out int y, out int w, out int h) =>
1621 Rect rect = new Rect();
1622 _geometryRequestedDelegate(out rect);
1628 ErrorCode error = ImeEventSetGeometryRequestedCallbackCb(_imeGeometryRequestedDelegate, IntPtr.Zero);
1629 if (error != ErrorCode.None)
1631 Log.Error(LogTag, "Add SetGeometryRequestedCallback Failed with error " + error);
1633 _geometryRequestedDelegate = geometryRequested;
1637 /// Runs the main loop of IME application.
1638 /// This function starts to run IME application's main loop.
1641 /// http://tizen.org/privilege/ime
1644 /// This API is a blocking call, as it starts the main loop of the application.
1646 /// <param name="create">This is called to initialize IME application before the main loop starts up</param>
1647 /// <param name="terminate">This is called when IME application is terminated</param>
1648 /// <param name="show">
1649 /// This is called when IME application is shown
1650 /// It provides the Context Inofrmation and the Context Id
1652 /// <param name="hide">
1653 /// This is called when IME application is hidden
1654 /// It provides the Context Id
1656 /// <exception cref="InvalidOperationException">
1657 /// This can occur due to the following reasons:
1658 /// 1) The application does not have the privilege to call this function
1659 /// 2) Operation failed
1661 public static void Run(Action create, Action terminate, Action<ContextId, InputMethodContext> show, Action<ContextId> hide)
1663 _userCreate = create;
1664 _userTerminate = terminate;
1667 _imeCallbackStructGCHandle._imeCallbackStruct.create = _create;
1668 _imeCallbackStructGCHandle._imeCallbackStruct.terminate = _terminate;
1669 _imeCallbackStructGCHandle._imeCallbackStruct.hide = _hide;
1670 _imeCallbackStructGCHandle._imeCallbackStruct.show = _show;
1672 ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero);
1673 if (error != ErrorCode.None)
1675 Log.Error(LogTag, "Run Failed with error " + error);
1676 throw InputMethodExceptionFactory.CreateException(error);
1682 /// Sends a key event to the associated text input UI control.
1685 /// 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.
1686 /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field.
1689 /// http://tizen.org/privilege/ime
1691 /// <param name="keyCode">The key code to be sent</param>
1692 /// <param name="keyMask">The modifier key mask</param>
1693 /// <param name="forwardKey">The flag to send the key event directly to the edit field</param>
1694 /// <exception cref="InvalidOperationException">
1695 /// This can occur due to the following reasons:
1696 /// 1) The application does not have the privilege to call this function
1697 /// 2) IME main loop isn't started yet
1699 public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false)
1701 ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey);
1702 if (error != ErrorCode.None)
1704 Log.Error(LogTag, "SendEvent Failed with error " + error);
1705 throw InputMethodExceptionFactory.CreateException(error);
1710 /// Sends the text to the associated text input UI control.
1713 /// http://tizen.org/privilege/ime
1715 /// <param name="str">The string to be committed</param>
1716 /// <exception cref="InvalidOperationException">
1717 /// This can occur due to the following reasons:
1718 /// 1) The application does not have the privilege to call this function
1719 /// 2) IME main loop isn't started yet
1721 public static void CommitString(string str)
1723 ErrorCode error = ImeCommitString(str);
1724 if (error != ErrorCode.None)
1726 Log.Error(LogTag, "CommitString Failed with error " + error);
1727 throw InputMethodExceptionFactory.CreateException(error);
1732 /// Requests to show preedit string.
1735 /// http://tizen.org/privilege/ime
1737 /// <exception cref="InvalidOperationException">
1738 /// This can occur due to the following reasons:
1739 /// 1) The application does not have the privilege to call this function
1740 /// 2) IME main loop isn't started yet
1742 public static void ShowPreEditString()
1744 ErrorCode error = ImeShowPreeditString();
1745 if (error != ErrorCode.None)
1747 Log.Error(LogTag, "ShowPreEditString Failed with error " + error);
1748 throw InputMethodExceptionFactory.CreateException(error);
1753 /// Requests to hide preedit string.
1756 /// http://tizen.org/privilege/ime
1758 /// <exception cref="InvalidOperationException">
1759 /// This can occur due to the following reasons:
1760 /// 1) The application does not have the privilege to call this function
1761 /// 2) IME main loop isn't started yet
1763 public static void HidePreEditString()
1765 ErrorCode error = ImeHidePreeditString();
1766 if (error != ErrorCode.None)
1768 Log.Error(LogTag, "HidePreEditString Failed with error " + error);
1769 throw InputMethodExceptionFactory.CreateException(error);
1774 /// Updates a new preedit string.
1777 /// http://tizen.org/privilege/ime
1779 /// <param name="str">The string to be updated in preedit</param>
1780 /// <param name="attrs">
1781 /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color and reversal color.
1782 /// The attrs list can be empty if no attributes to set
1784 /// <exception cref="InvalidOperationException">
1785 /// This can occur due to the following reasons:
1786 /// 1) The application does not have the privilege to call this function
1787 /// 2) IME main loop isn't started yet
1788 /// 3) Invalid Parameter
1790 public static void UpdatePreEditString(string str, IEnumerable<PreEditAttribute> attrs)
1792 IntPtr einaList = IntPtr.Zero;
1793 List<GCHandle> attributeHandleList = new List<GCHandle>();
1794 foreach (PreEditAttribute attribute in attrs)
1796 ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct();
1797 imePreEditAttribute.start = attribute.Start;
1798 imePreEditAttribute.length = attribute.Length;
1799 imePreEditAttribute.type = (int)attribute.Type;
1800 imePreEditAttribute.value = attribute.Value;
1801 GCHandle attributeHandle = GCHandle.Alloc(imePreEditAttribute, GCHandleType.Pinned);
1802 attributeHandleList.Add(attributeHandle);
1803 einaList = Interop.EinaList.EinaListAppend(einaList, attributeHandle.AddrOfPinnedObject());
1805 ErrorCode error = ImeUpdatePreeditString(str, einaList);
1806 foreach (GCHandle handle in attributeHandleList)
1810 if (error != ErrorCode.None)
1812 Log.Error(LogTag, "UpdatePreEditString Failed with error " + error);
1813 throw InputMethodExceptionFactory.CreateException(error);
1818 /// Requests the surrounding text from the position of the cursor, asynchronously.
1821 /// http://tizen.org/privilege/ime
1823 /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1824 /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1825 /// <exception cref="InvalidOperationException">
1826 /// This can occur due to the following reasons:
1827 /// 1) The application does not have the privilege to call this function
1828 /// 2) IME main loop isn't started yet
1831 /// The requested surrounding text can be received using the SurroundingTextUpdated Event, only if it is set.
1832 /// </postcondition>
1833 public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter)
1835 ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter);
1836 if (error != ErrorCode.None)
1838 Log.Error(LogTag, "RequestSurroundingText Failed with error " + error);
1839 throw InputMethodExceptionFactory.CreateException(error);
1844 /// Requests to delete surrounding text.
1847 /// http://tizen.org/privilege/ime
1849 /// <param name="offset">The offset value from the cursor position</param>
1850 /// <param name="len">The length of the text to delete</param>
1851 /// <exception cref="InvalidOperationException">
1852 /// This can occur due to the following reasons:
1853 /// 1) The application does not have the privilege to call this function
1854 /// 2) IME main loop isn't started yet
1855 /// 3) Invalid Parameter
1857 public static void DeleteSurroundingText(int offset, int len)
1859 ErrorCode error = ImeDeleteSurroundingText(offset, len);
1860 if (error != ErrorCode.None)
1862 Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error);
1863 throw InputMethodExceptionFactory.CreateException(error);
1868 /// Gets the surrounding text from the position of the cursor, synchronously.
1871 /// http://tizen.org/privilege/ime
1873 /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1874 /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1875 /// <param name="text">The surrounding text</param>
1876 /// <param name="cursorPosition">The cursor position</param>
1877 /// <exception cref="InvalidOperationException">
1878 /// This can occur due to the following reasons:
1879 /// 1) The application does not have the privilege to call this function
1880 /// 2) IME main loop isn't started yet
1881 /// 3) Invalid Parameter
1882 /// 4) Failed to obtain text due to out of memory
1884 public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition)
1887 ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition);
1888 if (error != ErrorCode.None)
1890 Log.Error(LogTag, "GetSurroundingText Failed with error " + error);
1891 throw InputMethodExceptionFactory.CreateException(error);
1893 text = Marshal.PtrToStringAnsi(txt);
1897 /// Requests to set selection.
1900 /// http://tizen.org/privilege/ime
1902 /// <param name="start">The start cursor position in text (in characters not bytes)</param>
1903 /// <param name="end">The end cursor position in text (in characters not bytes)</param>
1904 /// <exception cref="InvalidOperationException">
1905 /// This can occur due to the following reasons:
1906 /// 1) The application does not have the privilege to call this function
1907 /// 2) IME main loop isn't started yet
1908 /// 3) Invalid Parameter
1910 public static void SetSelection(int start, int end)
1912 ErrorCode error = ImeSetSelection(start, end);
1913 if (error != ErrorCode.None)
1915 Log.Error(LogTag, "SetSelection Failed with error " + error);
1916 throw InputMethodExceptionFactory.CreateException(error);
1921 /// This API returns the input panel main window.
1924 /// http://tizen.org/privilege/ime
1926 /// <returns>The input panel main window object on success, otherwise null</returns>
1927 /// <exception cref="InvalidOperationException">
1928 /// This can occur due to the following reasons:
1929 /// 1) The application does not have the privilege to call this function
1930 /// 2) IME main loop isn't started yet
1931 /// 3) Operation Failed
1933 public static EditorWindow GetMainWindow()
1935 EditorWindow._handle = ImeGetMainWindow();
1936 EditorWindow obj = new EditorWindow();
1937 ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
1938 if (error != ErrorCode.None)
1940 Log.Error(LogTag, "GetMainWindow Failed with error " + error);
1941 throw InputMethodExceptionFactory.CreateException(error);
1947 /// This API requests the InputMethodEditor to initialize
1950 /// http://tizen.org/privilege/ime
1952 /// <exception cref="InvalidOperationException">
1953 /// This can occur due to the following reasons:
1954 /// 1) The application does not have the privilege to call this function
1955 /// 2) Operation Failed
1957 public static void Create()
1959 ErrorCode error = ImeInitialize();
1960 Log.Info(LogTag, "ImeInitialize result : " + error);
1961 if (error != ErrorCode.None)
1963 Log.Error(LogTag, "ImeInitialize Failed with error " + error);
1964 throw InputMethodExceptionFactory.CreateException(error);
1967 error = ImePrepare();
1968 Log.Info(LogTag, "ImePrepare result : " + error);
1969 if (error != ErrorCode.None)
1971 Log.Error(LogTag, "ImePrepare Failed with error " + error);
1972 throw InputMethodExceptionFactory.CreateException(error);
1977 /// This API requests the InputMethodEditor to finalize
1980 /// http://tizen.org/privilege/ime
1982 /// <exception cref="InvalidOperationException">
1983 /// This can occur due to the following reasons:
1984 /// 1) The application does not have the privilege to call this function
1985 /// 2) Operation Failed
1987 public static void Destroy()
1989 ErrorCode error = ImeFinalize();
1990 Log.Info(LogTag, "ImeFinalize result : " + error);
1991 if (error != ErrorCode.None)
1993 Log.Error(LogTag, "ImeFinalize Failed with error " + error);
1994 throw InputMethodExceptionFactory.CreateException(error);