2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using System.ComponentModel;
22 using static Interop.InputMethod;
24 namespace Tizen.Uix.InputMethod
27 /// Enumeration of the key codes.
28 /// If keycode & 0xff000000 == 0x01000000 then this key code is directly encoded 24-bit UCS character.The UCS value is keycode & 0x00ffffff.
29 /// Defines the list of keys supported by the system.Note that certain keys may not be available on all devices.
31 /// <since_tizen> 4 </since_tizen>
59 /// The scroll lock key
75 /* Cursor control & motion */
81 /// The left directional key
85 /// The up directional key
89 /// The right directional key
93 /// The down directional key
97 /// The prior, previous key
109 /// The page down key
131 /// The execute, run, do key
155 /// The cancel, stop, abort, exit key
167 /// The character set switch key
169 Mode_switch = 0xFF7E,
177 /// The Numpad space key
181 /// The Numpad tab key
185 /// The Numpad enter key
189 /// The Numpad function 1 key
193 /// The Numpad function 2 key
197 /// The Numpad function 3 key
201 /// The Numpad function 4 key
205 /// The Numpad home key
209 /// The Numpad left key
213 /// The Numpad up key
217 /// The Numpad right key
221 /// The Numpad down key
225 /// The Numpad prior, previous key
229 /// The Numpad page up key
233 /// The Numpad next key
237 /// The Numpad page down key
239 KPPage_Down = 0xFF9B,
241 /// The Numpad end key
245 /// The Numpad begin key
249 /// The Numpad insert key
253 /// The Numpad delete key
257 /// The Numpad equal key
261 /// The Numpad multiply key
265 /// The Numpad add key
269 /// The Numpad separator key
271 KPSeparator = 0xFFAC,
273 /// The Numpad subtract key
277 /// The Numpad decimal key
281 /// The Numpad divide key
325 /* Auxiliary Functions */
327 /// The function 1 key
331 /// The function 2 key
335 /// The function 3 key
339 /// The function 4 key
343 /// The function 5 key
347 /// The function 6 key
351 /// The function 7 key
355 /// The function 8 key
359 /// The function 9 key
363 /// The function 10 key
367 /// The function 11 key
371 /// The function 12 key
375 /// The function 13 key
379 /// The function 14 key
383 /// The function 15 key
387 /// The function 16 key
391 /// The function 17 key
395 /// The function 18 key
399 /// The function 19 key
403 /// The function 20 key
407 /// The function 21 key
411 /// The function 22 key
415 /// The function 23 key
419 /// The function 24 key
423 /// The function 25 key
427 /// The function 26 key
431 /// The function 27 key
435 /// The function 28 key
439 /// The function 29 key
443 /// The function 30 key
447 /// The function 31 key
451 /// The function 32 key
455 /// The function 33 key
459 /// The function 34 key
463 /// The function 35 key
469 /// The left shift key
473 /// The right shift key
477 /// The left control key
481 /// The right control key
485 /// The caps lock key
489 /// The shift lock key
493 /// The left meta key
497 /// The right meta key
505 /// The right alt key
509 /// The left super key
513 /// The right super key
517 /// The left hyper key
521 /// The right hyper key
531 /// The exclamation key
539 /// The number sign key
551 /// The ampersand key
555 /// The apostrophe key
559 /// The parenleft key
563 /// The parenright key
635 /// The semicolon key
763 /// The left bracket key
767 /// The backslash key
771 /// The right bracket key
773 BracketRight = 0x05d,
775 /// The circumflex key
779 /// The underscore key
891 /// The left brace key
899 /// The right brace key
909 /// Enumeration of the key masks.
910 /// The key masks indicate which modifier keys is pressed down during the keyboard hit.The special MASK_RELEASED indicates the key release event.
912 /// <since_tizen> 4 </since_tizen>
916 /// Key press event without modifier key
920 /// The Shift key is pressed down
924 /// The CapsLock key is pressed down
928 /// The Control key is pressed down
932 /// The Alt key is pressed down
936 /// The Meta key is pressed down
940 /// The Win (between Control and Alt) is pressed down
944 /// The Hyper key is pressed down
948 /// The NumLock key is pressed down
952 /// Key release event
954 Released = (1 << 15),
958 /// This class contains api's related to IME(Input method editor)
960 /// <since_tizen> 4 </since_tizen>
961 public static class InputMethodEditor
963 private static Object thisLock = new Object();
964 private static ImeCallbackStructGCHandle _imeCallbackStructGCHandle = new ImeCallbackStructGCHandle();
965 private static event EventHandler<FocusedInEventArgs> _focusIn;
966 private static ImeFocusedInCb _imeFocusedInDelegate;
967 private static event EventHandler<FocusedOutEventArgs> _focusOut;
968 private static ImeFocusedOutCb _imeFocusedOutDelegate;
969 private static event EventHandler<SurroundingTextUpdatedEventArgs> _surroundingTextUpdated;
970 private static ImeSurroundingTextUpdatedCb _imeSurroundingTextUpdatedDelegate;
971 private static event EventHandler<EventArgs> _inputContextReset;
972 private static ImeInputContextResetCb _imeInputContextResetDelegate;
973 private static event EventHandler<CursorPositionUpdatedEventArgs> _cursorPositionUpdated;
974 private static ImeCursorPositionUpdatedCb _imeCursorPositionUpdatedDelegate;
975 private static event EventHandler<LanguageSetEventArgs> _langaugeSet;
976 private static ImeLanguageSetCb _imeLanguageSetDelegate;
977 private static event EventHandler<SetDataEventArgs> _imDataSet;
978 private static ImeImdataSetCb _imeDataSetDelegate;
979 private static event EventHandler<LayoutSetEventArgs> _layoutSet;
980 private static ImeLayoutSetCb _imeLayoutSetDelegate;
981 private static event EventHandler<ReturnKeySetEventArgs> _returnKeyTypeSet;
982 private static ImeReturnKeySetCb _imeReturnKeySetDelegate;
983 private static event EventHandler<ReturnKeyStateSetEventArgs> _returnKeyStateSet;
984 private static ImeReturnKeyStateSetCb _imeReturnKeyStateSetDelegate;
985 private static ImeProcessKeyEventCb _imeProcessKeyDelegate;
986 private static event EventHandler<DisplayLanguageChangedEventArgs> _displayLanguageChanged;
987 private static ImeDisplayLanguageChangedCb _imeDisplayLanguageChangedDelegate;
988 private static event EventHandler<RotationChangedEventArgs> _rotationDegreeChanged;
989 private static ImeRotationChangedCb _imeRotationChangedDelegate;
990 private static event EventHandler<AccessibilityStateChangedEventArgs> _accessibilityStateChanged;
991 private static ImeAccessibilityStateChangedCb _imeAccessibilityStateChangedDelegate;
992 private static ImeLanguageRequestedCb _imeLanguageRequestedDelegate;
993 private static OutAction<string> _languageRequestedDelegate;
994 private static BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> _processKeyDelagate;
995 private static ImeImdataRequestedCb _imeImDataRequestedDelegate;
996 private static OutArrayAction<byte> _imDataRequestedDelegate;
997 private static ImeGeometryRequestedCb _imeGeometryRequestedDelegate;
998 private static OutAction<Rect> _geometryRequestedDelegate;
999 private static Action _userCreate;
1000 private static Action _userTerminate;
1001 private static Action<ContextId, InputMethodContext> _userShow;
1002 private static Action<ContextId> _userHide;
1003 private static ImeCreateCb _create = (IntPtr userData) =>
1005 Log.Info(LogTag, "In Create Delegate");
1006 _userCreate?.Invoke();
1008 private static ImeTerminateCb _terminate = (IntPtr userData) =>
1010 Log.Info(LogTag, "In terminate Delegate");
1011 _userTerminate?.Invoke();
1012 _imeCallbackStructGCHandle.Dispose();
1014 private static ImeShowCb _show = (int contextId, IntPtr context, IntPtr userData) =>
1016 Log.Info(LogTag, "In Show Delegate");
1017 _userShow?.Invoke(new ContextId(contextId), new InputMethodContext(context));
1019 private static ImeHideCb _hide = (int contextId, IntPtr userData) =>
1021 Log.Info(LogTag, "In Hide Delegate");
1022 _userHide?.Invoke(new ContextId(contextId));
1026 /// Structure representing ContextId
1028 /// <since_tizen> 4 </since_tizen>
1029 public struct ContextId : IEquatable<ContextId>
1031 internal ContextId(int id)
1043 /// compare whether ContextId are equal
1045 /// <since_tizen> 4 </since_tizen>
1046 public bool Equals(ContextId other)
1048 return this.Id == other.Id;
1053 /// rectangle representing the position and size of UI Control
1055 /// <since_tizen> 4 </since_tizen>
1059 /// The x position in screen
1061 /// <since_tizen> 4 </since_tizen>
1065 /// The y position in screen
1067 /// <since_tizen> 4 </since_tizen>
1071 /// The window width
1073 /// <since_tizen> 4 </since_tizen>
1077 /// The window height
1079 /// <since_tizen> 4 </since_tizen>
1084 /// An Action with 1 out parameter
1086 /// <typeparam name="T">Generic Type</typeparam>
1087 /// <param name="a">The out parameter</param>
1088 /// <since_tizen> 4 </since_tizen>
1089 public delegate void OutAction<T>(out T a);
1092 /// An Action with an array out parameter
1094 /// <typeparam name="T">Generic Type</typeparam>
1095 /// <param name="a">The out parameter 1</param>
1096 /// <since_tizen> 4 </since_tizen>
1097 public delegate void OutArrayAction<T>(out T[] a);
1100 /// An Action with 3 Input Parameter returning a bool
1102 /// <typeparam name="T">Generic Type for Parameter 1</typeparam>
1103 /// <typeparam name="T1">Generic Type for Parameter 2</typeparam>
1104 /// <typeparam name="T2">Generic Type for Parameter 3</typeparam>
1105 /// <param name="a">The Input Parameter 1</param>
1106 /// <param name="b">The Input Parameter 2</param>
1107 /// <param name="c">The Input Parameter 3</param>
1108 /// <returns></returns>
1109 /// <since_tizen> 4 </since_tizen>
1110 public delegate bool BoolAction<T, T1, T2>(T a, T1 b, T2 c);
1113 /// Called when an associated text input UI control has focus.
1115 /// <since_tizen> 4 </since_tizen>
1116 public static event EventHandler<FocusedInEventArgs> FocusedIn
1122 _imeFocusedInDelegate = (int contextId, IntPtr userData) =>
1124 FocusedInEventArgs args = new FocusedInEventArgs(contextId);
1125 _focusIn?.Invoke(null, args);
1127 ErrorCode error = ImeEventSetFocusedInCb(_imeFocusedInDelegate, IntPtr.Zero);
1128 if (error != ErrorCode.None)
1130 Log.Error(LogTag, "Add FocusedIn Failed with error " + error);
1148 /// Called when an associated text input UI control loses focus.
1150 /// <since_tizen> 4 </since_tizen>
1151 public static event EventHandler<FocusedOutEventArgs> FocusedOut
1157 _imeFocusedOutDelegate = (int contextId, IntPtr userData) =>
1159 FocusedOutEventArgs args = new FocusedOutEventArgs(contextId);
1160 _focusOut?.Invoke(null, args);
1162 ErrorCode error = ImeEventSetFocusedOutCb(_imeFocusedOutDelegate, IntPtr.Zero);
1163 if (error != ErrorCode.None)
1165 Log.Error(LogTag, "Add FocusedOut Failed with error " + error);
1183 /// Called when an associated text input UI control responds to a request with the surrounding text.
1185 /// <since_tizen> 4 </since_tizen>
1186 public static event EventHandler<SurroundingTextUpdatedEventArgs> SurroundingTextUpdated
1192 _imeSurroundingTextUpdatedDelegate = (int contextId, IntPtr text, int cursorPos, IntPtr userData) =>
1194 SurroundingTextUpdatedEventArgs args = new SurroundingTextUpdatedEventArgs(contextId, Marshal.PtrToStringAnsi(text), cursorPos);
1195 _surroundingTextUpdated?.Invoke(null, args);
1197 ErrorCode error = ImeEventSetSurroundingTextUpdatedCb(_imeSurroundingTextUpdatedDelegate, IntPtr.Zero);
1198 if (error != ErrorCode.None)
1200 Log.Error(LogTag, "Add SurroundingTextUpdated Failed with error " + error);
1204 _surroundingTextUpdated += value;
1212 _surroundingTextUpdated -= value;
1218 /// Called to reset the input context of an associated text input UI control.
1220 /// <since_tizen> 4 </since_tizen>
1221 public static event EventHandler<EventArgs> InputContextReset
1227 _imeInputContextResetDelegate = (IntPtr userData) =>
1229 _inputContextReset?.Invoke(null, EventArgs.Empty);
1231 ErrorCode error = ImeEventSetInputContextResetCb(_imeInputContextResetDelegate, IntPtr.Zero);
1232 if (error != ErrorCode.None)
1234 Log.Error(LogTag, "Add InputContextReset Failed with error " + error);
1238 _inputContextReset += value;
1246 _inputContextReset -= value;
1252 /// Called when the position of the cursor in an associated text input UI control changes.
1254 /// <since_tizen> 4 </since_tizen>
1255 public static event EventHandler<CursorPositionUpdatedEventArgs> CursorPositionUpdated
1261 _imeCursorPositionUpdatedDelegate = (int cursorPos, IntPtr userData) =>
1263 CursorPositionUpdatedEventArgs args = new CursorPositionUpdatedEventArgs(cursorPos);
1264 _cursorPositionUpdated?.Invoke(null, args);
1266 ErrorCode error = ImeEventSetCursorPositionUpdatedCb(_imeCursorPositionUpdatedDelegate, IntPtr.Zero);
1267 if (error != ErrorCode.None)
1269 Log.Error(LogTag, "Add CursorPositionUpdated Failed with error " + error);
1273 _cursorPositionUpdated += value;
1281 _cursorPositionUpdated -= value;
1287 /// Called to set the preferred language to the input panel.
1288 /// It will be only called when the client application changes the edit field's language attribute after the input panel is shown.
1290 /// <since_tizen> 4 </since_tizen>
1291 public static event EventHandler<LanguageSetEventArgs> LanguageSet
1297 _imeLanguageSetDelegate = (InputPanelLanguage language, IntPtr userData) =>
1299 LanguageSetEventArgs args = new LanguageSetEventArgs(language);
1300 _langaugeSet?.Invoke(null, args);
1302 ErrorCode error = ImeEventSetLanguageSetCb(_imeLanguageSetDelegate, IntPtr.Zero);
1303 if (error != ErrorCode.None)
1305 Log.Error(LogTag, "Add LanguageSet Failed with error " + error);
1309 _langaugeSet += value;
1317 _langaugeSet -= value;
1323 /// Called to set the application specific data to deliver to the input panel.
1325 /// <since_tizen> 4 </since_tizen>
1326 public static event EventHandler<SetDataEventArgs> DataSet
1332 _imeDataSetDelegate = (IntPtr data, uint dataLength, IntPtr userData) =>
1334 byte[] destination = new byte[dataLength];
1335 Marshal.Copy(data, destination, 0, (int)dataLength);
1336 SetDataEventArgs args = new SetDataEventArgs(destination, dataLength);
1337 _imDataSet?.Invoke(null, args);
1339 ErrorCode error = ImeEventSetImdataSetCb(_imeDataSetDelegate, IntPtr.Zero);
1340 if (error != ErrorCode.None)
1342 Log.Error(LogTag, "Add DataSet Failed with error " + error);
1346 _imDataSet += value;
1354 _imDataSet -= value;
1360 /// Called when an associated text input UI control requests the input panel to set its layout.
1361 /// It will be only called when the client application changes the edit field's layout attribute after the input panel is shown.
1363 /// <since_tizen> 4 </since_tizen>
1364 public static event EventHandler<LayoutSetEventArgs> LayoutSet
1370 _imeLayoutSetDelegate = (InputPanelLayout layout, IntPtr userData) =>
1372 LayoutSetEventArgs args = new LayoutSetEventArgs(layout);
1373 _layoutSet?.Invoke(null, args);
1375 ErrorCode error = ImeEventSetLayoutSetCb(_imeLayoutSetDelegate, IntPtr.Zero);
1376 if (error != ErrorCode.None)
1378 Log.Error(LogTag, "Add LayoutSet Failed with error " + error);
1382 _layoutSet += value;
1390 _layoutSet -= value;
1396 /// Called when an associated text input UI control requests the input panel to set the Return key label.
1397 /// The input panel can show text or image on the Return button according to the Return key action.
1399 /// <since_tizen> 4 </since_tizen>
1400 public static event EventHandler<ReturnKeySetEventArgs> ReturnKeySet
1406 _imeReturnKeySetDelegate = (InputPanelReturnKey type, IntPtr userData) =>
1408 ReturnKeySetEventArgs args = new ReturnKeySetEventArgs(type);
1409 _returnKeyTypeSet?.Invoke(null, args);
1411 ErrorCode error = ImeEventSetReturnKeySetCb(_imeReturnKeySetDelegate, IntPtr.Zero);
1412 if (error != ErrorCode.None)
1414 Log.Error(LogTag, "Add ReturnKeySet Failed with error " + error);
1418 _returnKeyTypeSet += value;
1426 _returnKeyTypeSet -= value;
1432 /// Called when an associated text input UI control requests the input panel to enable or disable the Return key state.
1434 /// <since_tizen> 4 </since_tizen>
1435 public static event EventHandler<ReturnKeyStateSetEventArgs> ReturnKeyStateSet
1441 _imeReturnKeyStateSetDelegate = (bool state, IntPtr userData) =>
1443 ReturnKeyStateSetEventArgs args = new ReturnKeyStateSetEventArgs(state);
1444 _returnKeyStateSet?.Invoke(null, args);
1446 ErrorCode error = ImeEventSetReturnKeyStateSetCb(_imeReturnKeyStateSetDelegate, IntPtr.Zero);
1447 if (error != ErrorCode.None)
1449 Log.Error(LogTag, "Add ReturnKeyStateSet Failed with error " + error);
1453 _returnKeyStateSet += value;
1461 _returnKeyStateSet -= value;
1467 /// Called when the system display Language is changed.
1469 /// <since_tizen> 4 </since_tizen>
1470 public static event EventHandler<DisplayLanguageChangedEventArgs> DisplayLanguageChanged
1476 _imeDisplayLanguageChangedDelegate = (IntPtr language, IntPtr userData) =>
1478 DisplayLanguageChangedEventArgs args = new DisplayLanguageChangedEventArgs(Marshal.PtrToStringAnsi(language));
1479 _displayLanguageChanged?.Invoke(null, args);
1481 ErrorCode error = ImeEventSetDisplayLanguageChangedCb(_imeDisplayLanguageChangedDelegate, IntPtr.Zero);
1482 if (error != ErrorCode.None)
1484 Log.Error(LogTag, "Add DisplayLanguageChanged Failed with error " + error);
1488 _displayLanguageChanged += value;
1496 _displayLanguageChanged -= value;
1502 /// Called when the device is rotated.
1504 /// <since_tizen> 4 </since_tizen>
1505 public static event EventHandler<RotationChangedEventArgs> RotationChanged
1511 _imeRotationChangedDelegate = (int degree, IntPtr userData) =>
1513 RotationChangedEventArgs args = new RotationChangedEventArgs(degree);
1514 _rotationDegreeChanged?.Invoke(null, args);
1516 ErrorCode error = ImeEventSetRotationChangedCb(_imeRotationChangedDelegate, IntPtr.Zero);
1517 if (error != ErrorCode.None)
1519 Log.Error(LogTag, "Add RotationChanged Failed with error " + error);
1523 _rotationDegreeChanged += value;
1531 _rotationDegreeChanged -= value;
1537 /// Called when Accessibility in Settings application is on or off.
1539 /// <since_tizen> 4 </since_tizen>
1540 public static event EventHandler<AccessibilityStateChangedEventArgs> AccessibilityStateChanged
1546 _imeAccessibilityStateChangedDelegate = (bool state, IntPtr userData) =>
1548 AccessibilityStateChangedEventArgs args = new AccessibilityStateChangedEventArgs(state);
1549 _accessibilityStateChanged?.Invoke(null, args);
1551 ErrorCode error = ImeEventSetAccessibilityStateChangedCb(_imeAccessibilityStateChangedDelegate, IntPtr.Zero);
1552 if (error != ErrorCode.None)
1554 Log.Error(LogTag, "Add AccessibilityStateChanged Failed with error " + error);
1558 _accessibilityStateChanged += value;
1566 _accessibilityStateChanged -= value;
1572 /// Sets the languageRequested Action
1574 /// <param name="languageRequested">
1575 /// Called when an associated text input UI control requests the language from the input panel, requesting for language code.
1577 /// <since_tizen> 4 </since_tizen>
1578 public static void SetLanguageRequestedCallback(OutAction<string> languageRequested)
1580 _imeLanguageRequestedDelegate = (IntPtr userData, out IntPtr langCode) =>
1583 _languageRequestedDelegate(out langauage);
1584 char[] languageArray = langauage.ToCharArray();
1585 langCode = new IntPtr();
1586 Marshal.Copy(languageArray, 0, langCode, languageArray.Length);
1588 ErrorCode error = ImeEventSetLanguageRequestedCallbackCb(_imeLanguageRequestedDelegate, IntPtr.Zero);
1589 if (error != ErrorCode.None)
1591 Log.Error(LogTag, "Add SetLanguageRequestedCallback Failed with error " + error);
1593 _languageRequestedDelegate = languageRequested;
1597 /// Sets the processKey Action
1598 /// If the key event is from the external device, DeviceInfo will have its name, class and subclass information.
1600 /// <param name="processKey">
1601 /// The Action is alled when the key event is received from the external devices or SendKey function.
1602 /// This Event processes the key event before an associated text input UI control does.
1604 /// <since_tizen> 4 </since_tizen>
1605 public static void SetProcessKeyCallback(BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> processKey)
1607 _imeProcessKeyDelegate = (KeyCode keyCode, KeyMask keyMask, IntPtr devInfo, IntPtr userData) =>
1609 return _processKeyDelagate(keyCode, keyMask, new InputMethodDeviceInformation(devInfo));
1611 ErrorCode error = ImeEventSetProcessKeyEventCb(_imeProcessKeyDelegate, IntPtr.Zero);
1612 if (error != ErrorCode.None)
1614 Log.Error(LogTag, "Add ProcessKey Failed with error " + error);
1616 _processKeyDelagate = processKey;
1620 /// Sets the imDataRequested Action
1622 /// <param name="imDataRequested">
1623 /// 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.
1625 /// <since_tizen> 4 </since_tizen>
1626 public static void SetDataRequestedCallback(OutArrayAction<byte> imDataRequested)
1628 _imeImDataRequestedDelegate = (IntPtr userData, out IntPtr data, out uint dataLength) =>
1631 _imDataRequestedDelegate(out dataArr);
1632 data = new IntPtr();
1633 Marshal.Copy(dataArr, 0, data, dataArr.Length);
1634 dataLength = (uint)dataArr.Length;
1636 ErrorCode error = ImeEventSetImdataRequestedCb(_imeImDataRequestedDelegate, IntPtr.Zero);
1637 if (error != ErrorCode.None)
1639 Log.Error(LogTag, "Add SetDataRequestedCallback Failed with error " + error);
1641 _imDataRequestedDelegate = imDataRequested;
1645 /// Sets the GeometryRequested Action
1647 /// <param name="geometryRequested">
1648 /// Called when an associated text input UI control requests the position and size from the input panel, requesting for x,y,w,h values.
1650 /// <since_tizen> 4 </since_tizen>
1651 public static void SetGeometryRequestedCallback(OutAction<Rect> geometryRequested)
1653 _imeGeometryRequestedDelegate = (IntPtr userData, out int x, out int y, out int w, out int h) =>
1655 Rect rect = new Rect();
1656 _geometryRequestedDelegate(out rect);
1662 ErrorCode error = ImeEventSetGeometryRequestedCallbackCb(_imeGeometryRequestedDelegate, IntPtr.Zero);
1663 if (error != ErrorCode.None)
1665 Log.Error(LogTag, "Add SetGeometryRequestedCallback Failed with error " + error);
1667 _geometryRequestedDelegate = geometryRequested;
1671 /// Runs the main loop of IME application.
1672 /// This function starts to run IME application's main loop.
1675 /// http://tizen.org/privilege/ime
1678 /// This API is a blocking call, as it starts the main loop of the application.
1680 /// <param name="create">This is called to initialize IME application before the main loop starts up</param>
1681 /// <param name="terminate">This is called when IME application is terminated</param>
1682 /// <param name="show">
1683 /// This is called when IME application is shown
1684 /// It provides the Context Information and the Context Id
1686 /// <param name="hide">
1687 /// This is called when IME application is hidden
1688 /// It provides the Context Id
1690 /// <exception cref="InvalidOperationException">
1691 /// This can occur due to the following reasons:
1692 /// 1) The application does not have the privilege to call this function
1693 /// 2) Operation failed
1695 /// <since_tizen> 4 </since_tizen>
1696 public static void Run(Action create, Action terminate, Action<ContextId, InputMethodContext> show, Action<ContextId> hide)
1698 _userCreate = create;
1699 _userTerminate = terminate;
1702 _imeCallbackStructGCHandle._imeCallbackStruct.create = _create;
1703 _imeCallbackStructGCHandle._imeCallbackStruct.terminate = _terminate;
1704 _imeCallbackStructGCHandle._imeCallbackStruct.hide = _hide;
1705 _imeCallbackStructGCHandle._imeCallbackStruct.show = _show;
1707 ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero);
1708 if (error != ErrorCode.None)
1710 Log.Error(LogTag, "Run Failed with error " + error);
1711 throw InputMethodExceptionFactory.CreateException(error);
1717 /// Sends a key event to the associated text input UI control.
1720 /// This function sends 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.
1721 /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field.
1724 /// http://tizen.org/privilege/ime
1726 /// <param name="keyCode">The key code to be sent</param>
1727 /// <param name="keyMask">The modifier key mask</param>
1728 /// <param name="forwardKey">The flag to send the key event directly to the edit field</param>
1729 /// <exception cref="InvalidOperationException">
1730 /// This can occur due to the following reasons:
1731 /// 1) The application does not have the privilege to call this function
1732 /// 2) IME main loop isn't started yet
1734 /// <since_tizen> 4 </since_tizen>
1735 public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false)
1737 ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey);
1738 if (error != ErrorCode.None)
1740 Log.Error(LogTag, "SendEvent Failed with error " + error);
1741 throw InputMethodExceptionFactory.CreateException(error);
1746 /// Sends the text to the associated text input UI control.
1749 /// http://tizen.org/privilege/ime
1751 /// <param name="str">The string to be committed</param>
1752 /// <exception cref="InvalidOperationException">
1753 /// This can occur due to the following reasons:
1754 /// 1) The application does not have the privilege to call this function
1755 /// 2) IME main loop isn't started yet
1757 /// <since_tizen> 4 </since_tizen>
1758 public static void CommitString(string str)
1760 ErrorCode error = ImeCommitString(str);
1761 if (error != ErrorCode.None)
1763 Log.Error(LogTag, "CommitString Failed with error " + error);
1764 throw InputMethodExceptionFactory.CreateException(error);
1769 /// Requests to show preedit string.
1772 /// http://tizen.org/privilege/ime
1774 /// <exception cref="InvalidOperationException">
1775 /// This can occur due to the following reasons:
1776 /// 1) The application does not have the privilege to call this function
1777 /// 2) IME main loop isn't started yet
1779 /// <since_tizen> 4 </since_tizen>
1780 public static void ShowPreEditString()
1782 ErrorCode error = ImeShowPreeditString();
1783 if (error != ErrorCode.None)
1785 Log.Error(LogTag, "ShowPreEditString Failed with error " + error);
1786 throw InputMethodExceptionFactory.CreateException(error);
1791 /// Requests to hide preedit string.
1794 /// http://tizen.org/privilege/ime
1796 /// <exception cref="InvalidOperationException">
1797 /// This can occur due to the following reasons:
1798 /// 1) The application does not have the privilege to call this function
1799 /// 2) IME main loop isn't started yet
1801 /// <since_tizen> 4 </since_tizen>
1802 public static void HidePreEditString()
1804 ErrorCode error = ImeHidePreeditString();
1805 if (error != ErrorCode.None)
1807 Log.Error(LogTag, "HidePreEditString Failed with error " + error);
1808 throw InputMethodExceptionFactory.CreateException(error);
1813 /// Updates a new preedit string.
1816 /// http://tizen.org/privilege/ime
1818 /// <param name="str">The string to be updated in preedit</param>
1819 /// <param name="attrs">
1820 /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color and reversal color.
1821 /// The attrs list can be empty if no attributes to set
1823 /// <exception cref="InvalidOperationException">
1824 /// This can occur due to the following reasons:
1825 /// 1) The application does not have the privilege to call this function
1826 /// 2) IME main loop isn't started yet
1827 /// 3) Invalid Parameter
1829 /// <since_tizen> 4 </since_tizen>
1830 public static void UpdatePreEditString(string str, IEnumerable<PreEditAttribute> attrs)
1832 IntPtr einaList = IntPtr.Zero;
1833 List<GCHandle> attributeHandleList = new List<GCHandle>();
1834 foreach (PreEditAttribute attribute in attrs)
1836 ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct();
1837 imePreEditAttribute.start = attribute.Start;
1838 imePreEditAttribute.length = attribute.Length;
1839 imePreEditAttribute.type = (int)attribute.Type;
1840 imePreEditAttribute.value = attribute.Value;
1841 GCHandle attributeHandle = GCHandle.Alloc(imePreEditAttribute, GCHandleType.Pinned);
1842 attributeHandleList.Add(attributeHandle);
1843 einaList = Interop.EinaList.EinaListAppend(einaList, attributeHandle.AddrOfPinnedObject());
1845 ErrorCode error = ImeUpdatePreeditString(str, einaList);
1846 foreach (GCHandle handle in attributeHandleList)
1850 if (error != ErrorCode.None)
1852 Log.Error(LogTag, "UpdatePreEditString Failed with error " + error);
1853 throw InputMethodExceptionFactory.CreateException(error);
1858 /// Requests the surrounding text from the position of the cursor, asynchronously.
1861 /// http://tizen.org/privilege/ime
1863 /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1864 /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1865 /// <exception cref="InvalidOperationException">
1866 /// This can occur due to the following reasons:
1867 /// 1) The application does not have the privilege to call this function
1868 /// 2) IME main loop isn't started yet
1871 /// The requested surrounding text can be received using the SurroundingTextUpdated Event, only if it is set.
1872 /// </postcondition>
1873 /// <since_tizen> 4 </since_tizen>
1874 public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter)
1876 ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter);
1877 if (error != ErrorCode.None)
1879 Log.Error(LogTag, "RequestSurroundingText Failed with error " + error);
1880 throw InputMethodExceptionFactory.CreateException(error);
1885 /// Requests to delete surrounding text.
1888 /// http://tizen.org/privilege/ime
1890 /// <param name="offset">The offset value from the cursor position</param>
1891 /// <param name="len">The length of the text to delete</param>
1892 /// <exception cref="InvalidOperationException">
1893 /// This can occur due to the following reasons:
1894 /// 1) The application does not have the privilege to call this function
1895 /// 2) IME main loop isn't started yet
1896 /// 3) Invalid Parameter
1898 /// <since_tizen> 4 </since_tizen>
1899 public static void DeleteSurroundingText(int offset, int len)
1901 ErrorCode error = ImeDeleteSurroundingText(offset, len);
1902 if (error != ErrorCode.None)
1904 Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error);
1905 throw InputMethodExceptionFactory.CreateException(error);
1910 /// Gets the surrounding text from the position of the cursor, synchronously.
1913 /// http://tizen.org/privilege/ime
1915 /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1916 /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1917 /// <param name="text">The surrounding text</param>
1918 /// <param name="cursorPosition">The cursor position</param>
1919 /// <exception cref="InvalidOperationException">
1920 /// This can occur due to the following reasons:
1921 /// 1) The application does not have the privilege to call this function
1922 /// 2) IME main loop isn't started yet
1923 /// 3) Invalid Parameter
1924 /// 4) Failed to obtain text due to out of memory
1926 /// <since_tizen> 4 </since_tizen>
1927 public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition)
1930 ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition);
1931 if (error != ErrorCode.None)
1933 Log.Error(LogTag, "GetSurroundingText Failed with error " + error);
1934 throw InputMethodExceptionFactory.CreateException(error);
1936 text = Marshal.PtrToStringAnsi(txt);
1940 /// Requests to set selection.
1943 /// http://tizen.org/privilege/ime
1945 /// <param name="start">The start cursor position in text (in characters not bytes)</param>
1946 /// <param name="end">The end cursor position in text (in characters not bytes)</param>
1947 /// <exception cref="InvalidOperationException">
1948 /// This can occur due to the following reasons:
1949 /// 1) The application does not have the privilege to call this function
1950 /// 2) IME main loop isn't started yet
1951 /// 3) Invalid Parameter
1953 /// <since_tizen> 4 </since_tizen>
1954 public static void SetSelection(int start, int end)
1956 ErrorCode error = ImeSetSelection(start, end);
1957 if (error != ErrorCode.None)
1959 Log.Error(LogTag, "SetSelection Failed with error " + error);
1960 throw InputMethodExceptionFactory.CreateException(error);
1965 /// This API returns the input panel main window.
1968 /// http://tizen.org/privilege/ime
1970 /// <returns>The input panel main window object on success, otherwise null</returns>
1971 /// <exception cref="InvalidOperationException">
1972 /// This can occur due to the following reasons:
1973 /// 1) The application does not have the privilege to call this function
1974 /// 2) IME main loop isn't started yet
1975 /// 3) Operation Failed
1977 /// <since_tizen> 4 </since_tizen>
1978 public static EditorWindow GetMainWindow()
1980 EditorWindow._handle = ImeGetMainWindow();
1981 EditorWindow obj = new EditorWindow();
1982 ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
1983 if (error != ErrorCode.None)
1985 Log.Error(LogTag, "GetMainWindow Failed with error " + error);
1986 throw InputMethodExceptionFactory.CreateException(error);
1992 /// This API requests the InputMethodEditor to initialize
1995 /// http://tizen.org/privilege/ime
1997 /// <exception cref="InvalidOperationException">
1998 /// This can occur due to the following reasons:
1999 /// 1) The application does not have the privilege to call this function
2000 /// 2) Operation Failed
2002 /// <since_tizen> 4 </since_tizen>
2003 [EditorBrowsable(EditorBrowsableState.Never)]
2004 public static void Create()
2006 ErrorCode error = ImeInitialize();
2007 Log.Info(LogTag, "ImeInitialize result : " + error);
2008 if (error != ErrorCode.None)
2010 Log.Error(LogTag, "ImeInitialize Failed with error " + error);
2011 throw InputMethodExceptionFactory.CreateException(error);
2014 error = ImePrepare();
2015 Log.Info(LogTag, "ImePrepare result : " + error);
2016 if (error != ErrorCode.None)
2018 Log.Error(LogTag, "ImePrepare Failed with error " + error);
2019 throw InputMethodExceptionFactory.CreateException(error);
2024 /// This API requests the InputMethodEditor to finalize
2027 /// http://tizen.org/privilege/ime
2029 /// <exception cref="InvalidOperationException">
2030 /// This can occur due to the following reasons:
2031 /// 1) The application does not have the privilege to call this function
2032 /// 2) Operation Failed
2034 /// <since_tizen> 4 </since_tizen>
2035 [EditorBrowsable(EditorBrowsableState.Never)]
2036 public static void Destroy()
2038 ErrorCode error = ImeFinalize();
2039 Log.Info(LogTag, "ImeFinalize result : " + error);
2040 if (error != ErrorCode.None)
2042 Log.Error(LogTag, "ImeFinalize Failed with error " + error);
2043 throw InputMethodExceptionFactory.CreateException(error);