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 /* Auxiliary 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<DisplayLanguageChangedEventArgs> _displayLanguageChanged;
983 private static ImeDisplayLanguageChangedCb _imeDisplayLanguageChangedDelegate;
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)
1038 /// compare whether ContextId are equal
1040 public bool Equals(ContextId other)
1042 return this.Id == other.Id;
1047 /// rectangle representing the position and size of UI Control
1052 /// The x position in screen
1057 /// The y position in screen
1062 /// The window width
1067 /// The window height
1073 /// An Action with 1 out parameter
1075 /// <typeparam name="T">Generic Type</typeparam>
1076 /// <param name="a">The out parameter</param>
1077 public delegate void OutAction<T>(out T a);
1080 /// An Action with an array out parameter
1082 /// <typeparam name="T">Generic Type</typeparam>
1083 /// <param name="a">The out parameter 1</param>
1084 public delegate void OutArrayAction<T>(out T[] a);
1087 /// An Action with 3 Input Parameter returning a bool
1089 /// <typeparam name="T">Generic Type for Parameter 1</typeparam>
1090 /// <typeparam name="T1">Generic Type for Parameter 2</typeparam>
1091 /// <typeparam name="T2">Generic Type for Parameter 3</typeparam>
1092 /// <param name="a">The Input Parameter 1</param>
1093 /// <param name="b">The Input Parameter 2</param>
1094 /// <param name="c">The Input Parameter 3</param>
1095 /// <returns></returns>
1096 public delegate bool BoolAction<T, T1, T2>(T a, T1 b, T2 c);
1099 /// Called when an associated text input UI control has focus.
1101 public static event EventHandler<FocusedInEventArgs> FocusedIn
1107 _imeFocusedInDelegate = (int contextId, IntPtr userData) =>
1109 FocusedInEventArgs args = new FocusedInEventArgs(contextId);
1110 _focusIn?.Invoke(null, args);
1112 ErrorCode error = ImeEventSetFocusedInCb(_imeFocusedInDelegate, IntPtr.Zero);
1113 if (error != ErrorCode.None)
1115 Log.Error(LogTag, "Add FocusedIn Failed with error " + error);
1133 /// Called when an associated text input UI control loses focus.
1135 public static event EventHandler<FocusedOutEventArgs> FocusedOut
1141 _imeFocusedOutDelegate = (int contextId, IntPtr userData) =>
1143 FocusedOutEventArgs args = new FocusedOutEventArgs(contextId);
1144 _focusOut?.Invoke(null, args);
1146 ErrorCode error = ImeEventSetFocusedOutCb(_imeFocusedOutDelegate, IntPtr.Zero);
1147 if (error != ErrorCode.None)
1149 Log.Error(LogTag, "Add FocusedOut Failed with error " + error);
1167 /// Called when an associated text input UI control responds to a request with the surrounding text.
1169 public static event EventHandler<SurroundingTextUpdatedEventArgs> SurroundingTextUpdated
1175 _imeSurroundingTextUpdatedDelegate = (int contextId, IntPtr text, int cursorPos, IntPtr userData) =>
1177 SurroundingTextUpdatedEventArgs args = new SurroundingTextUpdatedEventArgs(contextId, Marshal.PtrToStringAnsi(text), cursorPos);
1178 _surroundingTextUpdated?.Invoke(null, args);
1180 ErrorCode error = ImeEventSetSurroundingTextUpdatedCb(_imeSurroundingTextUpdatedDelegate, IntPtr.Zero);
1181 if (error != ErrorCode.None)
1183 Log.Error(LogTag, "Add SurroundingTextUpdated Failed with error " + error);
1187 _surroundingTextUpdated += value;
1195 _surroundingTextUpdated -= value;
1201 /// Called to reset the input context of an associated text input UI control.
1203 public static event EventHandler<EventArgs> InputContextReset
1209 _imeInputContextResetDelegate = (IntPtr userData) =>
1211 _inputContextReset?.Invoke(null, EventArgs.Empty);
1213 ErrorCode error = ImeEventSetInputContextResetCb(_imeInputContextResetDelegate, IntPtr.Zero);
1214 if (error != ErrorCode.None)
1216 Log.Error(LogTag, "Add InputContextReset Failed with error " + error);
1220 _inputContextReset += value;
1228 _inputContextReset -= value;
1234 /// Called when the position of the cursor in an associated text input UI control changes.
1236 public static event EventHandler<CursorPositionUpdatedEventArgs> CursorPositionUpdated
1242 _imeCursorPositionUpdatedDelegate = (int cursorPos, IntPtr userData) =>
1244 CursorPositionUpdatedEventArgs args = new CursorPositionUpdatedEventArgs(cursorPos);
1245 _cursorPositionUpdated?.Invoke(null, args);
1247 ErrorCode error = ImeEventSetCursorPositionUpdatedCb(_imeCursorPositionUpdatedDelegate, IntPtr.Zero);
1248 if (error != ErrorCode.None)
1250 Log.Error(LogTag, "Add CursorPositionUpdated Failed with error " + error);
1254 _cursorPositionUpdated += value;
1262 _cursorPositionUpdated -= value;
1268 /// Called to set the preferred language to the input panel.
1269 /// It will be only called when the client application changes the edit field's language attribute after the input panel is shown.
1271 public static event EventHandler<LanguageSetEventArgs> LanguageSet
1277 _imeLanguageSetDelegate = (InputPanelLanguage language, IntPtr userData) =>
1279 LanguageSetEventArgs args = new LanguageSetEventArgs(language);
1280 _langaugeSet?.Invoke(null, args);
1282 ErrorCode error = ImeEventSetLanguageSetCb(_imeLanguageSetDelegate, IntPtr.Zero);
1283 if (error != ErrorCode.None)
1285 Log.Error(LogTag, "Add LanguageSet Failed with error " + error);
1289 _langaugeSet += value;
1297 _langaugeSet -= value;
1303 /// Called to set the application specific data to deliver to the input panel.
1305 public static event EventHandler<SetDataEventArgs> DataSet
1311 _imeDataSetDelegate = (IntPtr data, uint dataLength, IntPtr userData) =>
1313 byte[] destination = new byte[dataLength];
1314 Marshal.Copy(data, destination, 0, (int)dataLength);
1315 SetDataEventArgs args = new SetDataEventArgs(destination, dataLength);
1316 _imDataSet?.Invoke(null, args);
1318 ErrorCode error = ImeEventSetImdataSetCb(_imeDataSetDelegate, IntPtr.Zero);
1319 if (error != ErrorCode.None)
1321 Log.Error(LogTag, "Add DataSet Failed with error " + error);
1325 _imDataSet += value;
1333 _imDataSet -= value;
1339 /// Called when an associated text input UI control requests the input panel to set its layout.
1340 /// It will be only called when the client application changes the edit field's layout attribute after the input panel is shown.
1342 public static event EventHandler<LayoutSetEventArgs> LayoutSet
1348 _imeLayoutSetDelegate = (InputPanelLayout layout, IntPtr userData) =>
1350 LayoutSetEventArgs args = new LayoutSetEventArgs(layout);
1351 _layoutSet?.Invoke(null, args);
1353 ErrorCode error = ImeEventSetLayoutSetCb(_imeLayoutSetDelegate, IntPtr.Zero);
1354 if (error != ErrorCode.None)
1356 Log.Error(LogTag, "Add LayoutSet Failed with error " + error);
1360 _layoutSet += value;
1368 _layoutSet -= value;
1374 /// Called when an associated text input UI control requests the input panel to set the Return key label.
1375 /// The input panel can show text or image on the Return button according to the Return key action.
1377 public static event EventHandler<ReturnKeySetEventArgs> ReturnKeySet
1383 _imeReturnKeySetDelegate = (InputPanelReturnKey type, IntPtr userData) =>
1385 ReturnKeySetEventArgs args = new ReturnKeySetEventArgs(type);
1386 _returnKeyTypeSet?.Invoke(null, args);
1388 ErrorCode error = ImeEventSetReturnKeySetCb(_imeReturnKeySetDelegate, IntPtr.Zero);
1389 if (error != ErrorCode.None)
1391 Log.Error(LogTag, "Add ReturnKeySet Failed with error " + error);
1395 _returnKeyTypeSet += value;
1403 _returnKeyTypeSet -= value;
1409 /// Called when an associated text input UI control requests the input panel to enable or disable the Return key state.
1411 public static event EventHandler<ReturnKeyStateSetEventArgs> ReturnKeyStateSet
1417 _imeReturnKeyStateSetDelegate = (bool state, IntPtr userData) =>
1419 ReturnKeyStateSetEventArgs args = new ReturnKeyStateSetEventArgs(state);
1420 _returnKeyStateSet?.Invoke(null, args);
1422 ErrorCode error = ImeEventSetReturnKeyStateSetCb(_imeReturnKeyStateSetDelegate, IntPtr.Zero);
1423 if (error != ErrorCode.None)
1425 Log.Error(LogTag, "Add ReturnKeyStateSet Failed with error " + error);
1429 _returnKeyStateSet += value;
1437 _returnKeyStateSet -= value;
1443 /// Called when the system display Language is changed.
1445 public static event EventHandler<DisplayLanguageChangedEventArgs> DisplayLanguageChanged
1451 _imeDisplayLanguageChangedDelegate = (IntPtr language, IntPtr userData) =>
1453 DisplayLanguageChangedEventArgs args = new DisplayLanguageChangedEventArgs(Marshal.PtrToStringAnsi(language));
1454 _displayLanguageChanged?.Invoke(null, args);
1456 ErrorCode error = ImeEventSetDisplayLanguageChangedCb(_imeDisplayLanguageChangedDelegate, IntPtr.Zero);
1457 if (error != ErrorCode.None)
1459 Log.Error(LogTag, "Add DisplayLanguageChanged Failed with error " + error);
1463 _displayLanguageChanged += value;
1471 _displayLanguageChanged -= value;
1477 /// Called when the device is rotated.
1479 public static event EventHandler<RotationChangedEventArgs> RotationChanged
1485 _imeRotationChangedDelegate = (int degree, IntPtr userData) =>
1487 RotationChangedEventArgs args = new RotationChangedEventArgs(degree);
1488 _rotationDegreeChanged?.Invoke(null, args);
1490 ErrorCode error = ImeEventSetRotationChangedCb(_imeRotationChangedDelegate, IntPtr.Zero);
1491 if (error != ErrorCode.None)
1493 Log.Error(LogTag, "Add RotationChanged Failed with error " + error);
1497 _rotationDegreeChanged += value;
1505 _rotationDegreeChanged -= value;
1511 /// Called when Accessibility in Settings application is on or off.
1513 public static event EventHandler<AccessibilityStateChangedEventArgs> AccessibilityStateChanged
1519 _imeAccessibilityStateChangedDelegate = (bool state, IntPtr userData) =>
1521 AccessibilityStateChangedEventArgs args = new AccessibilityStateChangedEventArgs(state);
1522 _accessibilityStateChanged?.Invoke(null, args);
1524 ErrorCode error = ImeEventSetAccessibilityStateChangedCb(_imeAccessibilityStateChangedDelegate, IntPtr.Zero);
1525 if (error != ErrorCode.None)
1527 Log.Error(LogTag, "Add AccessibilityStateChanged Failed with error " + error);
1531 _accessibilityStateChanged += value;
1539 _accessibilityStateChanged -= value;
1545 /// Sets the languageRequested Action
1547 /// <param name="languageRequested">
1548 /// Called when an associated text input UI control requests the language from the input panel, requesting for language code.
1550 public static void SetLanguageRequestedCallback(OutAction<string> languageRequested)
1552 _imeLanguageRequestedDelegate = (IntPtr userData, out IntPtr langCode) =>
1555 _languageRequestedDelegate(out langauage);
1556 char[] languageArray = langauage.ToCharArray();
1557 langCode = new IntPtr();
1558 Marshal.Copy(languageArray, 0, langCode, languageArray.Length);
1560 ErrorCode error = ImeEventSetLanguageRequestedCallbackCb(_imeLanguageRequestedDelegate, IntPtr.Zero);
1561 if (error != ErrorCode.None)
1563 Log.Error(LogTag, "Add SetLanguageRequestedCallback Failed with error " + error);
1565 _languageRequestedDelegate = languageRequested;
1569 /// Sets the processKey Action
1570 /// If the key event is from the external device, DeviceInfo will have its name, class and subclass information.
1572 /// <param name="processKey">
1573 /// The Action is alled when the key event is received from the external devices or SendKey function.
1574 /// This Event processes the key event before an associated text input UI control does.
1576 public static void SetProcessKeyCallback(BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> processKey)
1578 _imeProcessKeyDelegate = (KeyCode keyCode, KeyMask keyMask, IntPtr devInfo, IntPtr userData) =>
1580 return _processKeyDelagate(keyCode, keyMask, new InputMethodDeviceInformation(devInfo));
1582 ErrorCode error = ImeEventSetProcessKeyEventCb(_imeProcessKeyDelegate, IntPtr.Zero);
1583 if (error != ErrorCode.None)
1585 Log.Error(LogTag, "Add ProcessKey Failed with error " + error);
1587 _processKeyDelagate = processKey;
1591 /// Sets the imDataRequested Action
1593 /// <param name="imDataRequested">
1594 /// 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.
1596 public static void SetDataRequestedCallback(OutArrayAction<byte> imDataRequested)
1598 _imeImDataRequestedDelegate = (IntPtr userData, out IntPtr data, out uint dataLength) =>
1601 _imDataRequestedDelegate(out dataArr);
1602 data = new IntPtr();
1603 Marshal.Copy(dataArr, 0, data, dataArr.Length);
1604 dataLength = (uint)dataArr.Length;
1606 ErrorCode error = ImeEventSetImdataRequestedCb(_imeImDataRequestedDelegate, IntPtr.Zero);
1607 if (error != ErrorCode.None)
1609 Log.Error(LogTag, "Add SetDataRequestedCallback Failed with error " + error);
1611 _imDataRequestedDelegate = imDataRequested;
1615 /// Sets the GeometryRequested Action
1617 /// <param name="geometryRequested">
1618 /// Called when an associated text input UI control requests the position and size from the input panel, requesting for x,y,w,h values.
1620 public static void SetGeometryRequestedCallback(OutAction<Rect> geometryRequested)
1622 _imeGeometryRequestedDelegate = (IntPtr userData, out int x, out int y, out int w, out int h) =>
1624 Rect rect = new Rect();
1625 _geometryRequestedDelegate(out rect);
1631 ErrorCode error = ImeEventSetGeometryRequestedCallbackCb(_imeGeometryRequestedDelegate, IntPtr.Zero);
1632 if (error != ErrorCode.None)
1634 Log.Error(LogTag, "Add SetGeometryRequestedCallback Failed with error " + error);
1636 _geometryRequestedDelegate = geometryRequested;
1640 /// Runs the main loop of IME application.
1641 /// This function starts to run IME application's main loop.
1644 /// http://tizen.org/privilege/ime
1647 /// This API is a blocking call, as it starts the main loop of the application.
1649 /// <param name="create">This is called to initialize IME application before the main loop starts up</param>
1650 /// <param name="terminate">This is called when IME application is terminated</param>
1651 /// <param name="show">
1652 /// This is called when IME application is shown
1653 /// It provides the Context Information and the Context Id
1655 /// <param name="hide">
1656 /// This is called when IME application is hidden
1657 /// It provides the Context Id
1659 /// <exception cref="InvalidOperationException">
1660 /// This can occur due to the following reasons:
1661 /// 1) The application does not have the privilege to call this function
1662 /// 2) Operation failed
1664 public static void Run(Action create, Action terminate, Action<ContextId, InputMethodContext> show, Action<ContextId> hide)
1666 _userCreate = create;
1667 _userTerminate = terminate;
1670 _imeCallbackStructGCHandle._imeCallbackStruct.create = _create;
1671 _imeCallbackStructGCHandle._imeCallbackStruct.terminate = _terminate;
1672 _imeCallbackStructGCHandle._imeCallbackStruct.hide = _hide;
1673 _imeCallbackStructGCHandle._imeCallbackStruct.show = _show;
1675 ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero);
1676 if (error != ErrorCode.None)
1678 Log.Error(LogTag, "Run Failed with error " + error);
1679 throw InputMethodExceptionFactory.CreateException(error);
1685 /// Sends a key event to the associated text input UI control.
1688 /// 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.
1689 /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field.
1692 /// http://tizen.org/privilege/ime
1694 /// <param name="keyCode">The key code to be sent</param>
1695 /// <param name="keyMask">The modifier key mask</param>
1696 /// <param name="forwardKey">The flag to send the key event directly to the edit field</param>
1697 /// <exception cref="InvalidOperationException">
1698 /// This can occur due to the following reasons:
1699 /// 1) The application does not have the privilege to call this function
1700 /// 2) IME main loop isn't started yet
1702 public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false)
1704 ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey);
1705 if (error != ErrorCode.None)
1707 Log.Error(LogTag, "SendEvent Failed with error " + error);
1708 throw InputMethodExceptionFactory.CreateException(error);
1713 /// Sends the text to the associated text input UI control.
1716 /// http://tizen.org/privilege/ime
1718 /// <param name="str">The string to be committed</param>
1719 /// <exception cref="InvalidOperationException">
1720 /// This can occur due to the following reasons:
1721 /// 1) The application does not have the privilege to call this function
1722 /// 2) IME main loop isn't started yet
1724 public static void CommitString(string str)
1726 ErrorCode error = ImeCommitString(str);
1727 if (error != ErrorCode.None)
1729 Log.Error(LogTag, "CommitString Failed with error " + error);
1730 throw InputMethodExceptionFactory.CreateException(error);
1735 /// Requests to show preedit string.
1738 /// http://tizen.org/privilege/ime
1740 /// <exception cref="InvalidOperationException">
1741 /// This can occur due to the following reasons:
1742 /// 1) The application does not have the privilege to call this function
1743 /// 2) IME main loop isn't started yet
1745 public static void ShowPreEditString()
1747 ErrorCode error = ImeShowPreeditString();
1748 if (error != ErrorCode.None)
1750 Log.Error(LogTag, "ShowPreEditString Failed with error " + error);
1751 throw InputMethodExceptionFactory.CreateException(error);
1756 /// Requests to hide preedit string.
1759 /// http://tizen.org/privilege/ime
1761 /// <exception cref="InvalidOperationException">
1762 /// This can occur due to the following reasons:
1763 /// 1) The application does not have the privilege to call this function
1764 /// 2) IME main loop isn't started yet
1766 public static void HidePreEditString()
1768 ErrorCode error = ImeHidePreeditString();
1769 if (error != ErrorCode.None)
1771 Log.Error(LogTag, "HidePreEditString Failed with error " + error);
1772 throw InputMethodExceptionFactory.CreateException(error);
1777 /// Updates a new preedit string.
1780 /// http://tizen.org/privilege/ime
1782 /// <param name="str">The string to be updated in preedit</param>
1783 /// <param name="attrs">
1784 /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color and reversal color.
1785 /// The attrs list can be empty if no attributes to set
1787 /// <exception cref="InvalidOperationException">
1788 /// This can occur due to the following reasons:
1789 /// 1) The application does not have the privilege to call this function
1790 /// 2) IME main loop isn't started yet
1791 /// 3) Invalid Parameter
1793 public static void UpdatePreEditString(string str, IEnumerable<PreEditAttribute> attrs)
1795 IntPtr einaList = IntPtr.Zero;
1796 List<GCHandle> attributeHandleList = new List<GCHandle>();
1797 foreach (PreEditAttribute attribute in attrs)
1799 ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct();
1800 imePreEditAttribute.start = attribute.Start;
1801 imePreEditAttribute.length = attribute.Length;
1802 imePreEditAttribute.type = (int)attribute.Type;
1803 imePreEditAttribute.value = attribute.Value;
1804 GCHandle attributeHandle = GCHandle.Alloc(imePreEditAttribute, GCHandleType.Pinned);
1805 attributeHandleList.Add(attributeHandle);
1806 einaList = Interop.EinaList.EinaListAppend(einaList, attributeHandle.AddrOfPinnedObject());
1808 ErrorCode error = ImeUpdatePreeditString(str, einaList);
1809 foreach (GCHandle handle in attributeHandleList)
1813 if (error != ErrorCode.None)
1815 Log.Error(LogTag, "UpdatePreEditString Failed with error " + error);
1816 throw InputMethodExceptionFactory.CreateException(error);
1821 /// Requests the surrounding text from the position of the cursor, asynchronously.
1824 /// http://tizen.org/privilege/ime
1826 /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1827 /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1828 /// <exception cref="InvalidOperationException">
1829 /// This can occur due to the following reasons:
1830 /// 1) The application does not have the privilege to call this function
1831 /// 2) IME main loop isn't started yet
1834 /// The requested surrounding text can be received using the SurroundingTextUpdated Event, only if it is set.
1835 /// </postcondition>
1836 public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter)
1838 ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter);
1839 if (error != ErrorCode.None)
1841 Log.Error(LogTag, "RequestSurroundingText Failed with error " + error);
1842 throw InputMethodExceptionFactory.CreateException(error);
1847 /// Requests to delete surrounding text.
1850 /// http://tizen.org/privilege/ime
1852 /// <param name="offset">The offset value from the cursor position</param>
1853 /// <param name="len">The length of the text to delete</param>
1854 /// <exception cref="InvalidOperationException">
1855 /// This can occur due to the following reasons:
1856 /// 1) The application does not have the privilege to call this function
1857 /// 2) IME main loop isn't started yet
1858 /// 3) Invalid Parameter
1860 public static void DeleteSurroundingText(int offset, int len)
1862 ErrorCode error = ImeDeleteSurroundingText(offset, len);
1863 if (error != ErrorCode.None)
1865 Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error);
1866 throw InputMethodExceptionFactory.CreateException(error);
1871 /// Gets the surrounding text from the position of the cursor, synchronously.
1874 /// http://tizen.org/privilege/ime
1876 /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1877 /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1878 /// <param name="text">The surrounding text</param>
1879 /// <param name="cursorPosition">The cursor position</param>
1880 /// <exception cref="InvalidOperationException">
1881 /// This can occur due to the following reasons:
1882 /// 1) The application does not have the privilege to call this function
1883 /// 2) IME main loop isn't started yet
1884 /// 3) Invalid Parameter
1885 /// 4) Failed to obtain text due to out of memory
1887 public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition)
1890 ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition);
1891 if (error != ErrorCode.None)
1893 Log.Error(LogTag, "GetSurroundingText Failed with error " + error);
1894 throw InputMethodExceptionFactory.CreateException(error);
1896 text = Marshal.PtrToStringAnsi(txt);
1900 /// Requests to set selection.
1903 /// http://tizen.org/privilege/ime
1905 /// <param name="start">The start cursor position in text (in characters not bytes)</param>
1906 /// <param name="end">The end cursor position in text (in characters not bytes)</param>
1907 /// <exception cref="InvalidOperationException">
1908 /// This can occur due to the following reasons:
1909 /// 1) The application does not have the privilege to call this function
1910 /// 2) IME main loop isn't started yet
1911 /// 3) Invalid Parameter
1913 public static void SetSelection(int start, int end)
1915 ErrorCode error = ImeSetSelection(start, end);
1916 if (error != ErrorCode.None)
1918 Log.Error(LogTag, "SetSelection Failed with error " + error);
1919 throw InputMethodExceptionFactory.CreateException(error);
1924 /// This API returns the input panel main window.
1927 /// http://tizen.org/privilege/ime
1929 /// <returns>The input panel main window object on success, otherwise null</returns>
1930 /// <exception cref="InvalidOperationException">
1931 /// This can occur due to the following reasons:
1932 /// 1) The application does not have the privilege to call this function
1933 /// 2) IME main loop isn't started yet
1934 /// 3) Operation Failed
1936 public static EditorWindow GetMainWindow()
1938 EditorWindow._handle = ImeGetMainWindow();
1939 EditorWindow obj = new EditorWindow();
1940 ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
1941 if (error != ErrorCode.None)
1943 Log.Error(LogTag, "GetMainWindow Failed with error " + error);
1944 throw InputMethodExceptionFactory.CreateException(error);
1950 /// This API requests the InputMethodEditor to initialize
1953 /// http://tizen.org/privilege/ime
1955 /// <exception cref="InvalidOperationException">
1956 /// This can occur due to the following reasons:
1957 /// 1) The application does not have the privilege to call this function
1958 /// 2) Operation Failed
1960 public static void Create()
1962 ErrorCode error = ImeInitialize();
1963 Log.Info(LogTag, "ImeInitialize result : " + error);
1964 if (error != ErrorCode.None)
1966 Log.Error(LogTag, "ImeInitialize Failed with error " + error);
1967 throw InputMethodExceptionFactory.CreateException(error);
1970 error = ImePrepare();
1971 Log.Info(LogTag, "ImePrepare result : " + error);
1972 if (error != ErrorCode.None)
1974 Log.Error(LogTag, "ImePrepare Failed with error " + error);
1975 throw InputMethodExceptionFactory.CreateException(error);
1980 /// This API requests the InputMethodEditor to finalize
1983 /// http://tizen.org/privilege/ime
1985 /// <exception cref="InvalidOperationException">
1986 /// This can occur due to the following reasons:
1987 /// 1) The application does not have the privilege to call this function
1988 /// 2) Operation Failed
1990 public static void Destroy()
1992 ErrorCode error = ImeFinalize();
1993 Log.Info(LogTag, "ImeFinalize result : " + error);
1994 if (error != ErrorCode.None)
1996 Log.Error(LogTag, "ImeFinalize Failed with error " + error);
1997 throw InputMethodExceptionFactory.CreateException(error);