/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.ComponentModel; using static Interop.InputMethod; namespace Tizen.Uix.InputMethod { /// /// Enumeration for the key codes. /// If keycode & 0xff000000 == 0x01000000 then this key code is directly encoded to 24-bit UCS character. The UCS value is keycode & 0x00ffffff. /// Defines the list of keys supported by the system. Note that certain keys may not be available on all the devices. /// /// 4 public enum KeyCode { /// /// The Backspace key. /// BackSpace = 0xFF08, /// /// The Tab key. /// Tab = 0xFF09, /// /// The Linefeed key. /// Linefeed = 0xFF0A, /// /// The Clear key. /// Clear = 0xFF0B, /// /// The Return key. /// Return = 0xFF0D, /// /// The Pause key. /// Pause = 0xFF13, /// /// The Scroll lock key. /// ScrollLock = 0xFF14, /// /// The System Request key. /// SysReq = 0xFF15, /// /// The Escape key. /// Escape = 0xFF1B, /// /// The Delete key. /// Delete = 0xFFFF, /* Cursor control & motion */ /// /// The Home key. /// Home = 0xFF50, /// /// The Left directional key. /// Left = 0xFF51, /// /// The Up directional key. /// Up = 0xFF52, /// /// The Right directional key. /// Right = 0xFF53, /// /// The Down directional key. /// Down = 0xFF54, /// /// The Prior, Previous key. /// Prior = 0xFF55, /// /// The Page Up key. /// Page_Up = 0xFF55, /// /// The Next key. /// Next = 0xFF56, /// /// The Page Down key. /// Page_Down = 0xFF56, /// /// The End key. /// End = 0xFF57, /// /// The Begin key. /// Begin = 0xFF58, /* Misc Functions */ /// /// The Select key. /// Select = 0xFF60, /// /// The Print key. /// Print = 0xFF61, /// /// The Execute, Run, Do key. /// Execute = 0xFF62, /// /// The Insert key. /// Insert = 0xFF63, /// /// The Undo key. /// Undo = 0xFF65, /// /// The Redo key. /// Redo = 0xFF66, /// /// The Menu key. /// Menu = 0xFF67, /// /// The Find key. /// Find = 0xFF68, /// /// The Cancel, Stop, Abort, Exit key. /// Cancel = 0xFF69, /// /// The Help key. /// Help = 0xFF6A, /// /// The Break key. /// Break = 0xFF6B, /// /// The character set switch key. /// Mode_switch = 0xFF7E, /// /// The Number Lock key. /// Num_Lock = 0xFF7F, /* Keypad */ /// /// The Numpad Space key. /// KPSpace = 0xFF80, /// /// The Numpad Tab key. /// KPTab = 0xFF89, /// /// The Numpad Enter key. /// KPEnter = 0xFF8D, /// /// The Numpad Function 1 key. /// KPF1 = 0xFF91, /// /// The Numpad Function 2 key. /// KPF2 = 0xFF92, /// /// The Numpad Function 3 key. /// KPF3 = 0xFF93, /// /// The Numpad Function 4 key. /// KPF4 = 0xFF94, /// /// The Numpad Home key. /// KPHome = 0xFF95, /// /// The Numpad Left key. /// KPLeft = 0xFF96, /// /// The Numpad Up key. /// KPUp = 0xFF97, /// /// The Numpad Right key. /// KPRight = 0xFF98, /// /// The Numpad Down key. /// KPDown = 0xFF99, /// /// The Numpad Prior, Previous key. /// KPPrior = 0xFF9A, /// /// The Numpad Page Up key. /// KPPage_Up = 0xFF9A, /// /// The Numpad Next key. /// KPNext = 0xFF9B, /// /// The Numpad Page Down key. /// KPPage_Down = 0xFF9B, /// /// The Numpad End key. /// KPEnd = 0xFF9C, /// /// The Numpad Begin key. /// KPBegin = 0xFF9D, /// /// The Numpad Insert key. /// KPInsert = 0xFF9E, /// /// The Numpad Delete key. /// KPDelete = 0xFF9F, /// /// The Numpad Equal key. /// KPEqual = 0xFFBD, /// /// The Numpad Multiply key. /// KPMultiply = 0xFFAA, /// /// The Numpad Add key. /// KPAdd = 0xFFAB, /// /// The Numpad Separator key. /// KPSeparator = 0xFFAC, /// /// The Numpad Subtract key. /// KPSubtract = 0xFFAD, /// /// The Numpad Decimal key. /// KPDecimal = 0xFFAE, /// /// The Numpad Divide key. /// KPDivide = 0xFFAF, /// /// The Numpad 0 key. /// KP0 = 0xFFB0, /// /// The Numpad 1 key. /// KP1 = 0xFFB1, /// /// The Numpad 2 key. /// KP2 = 0xFFB2, /// /// The Numpad 3 key. /// KP3 = 0xFFB3, /// /// The Numpad 4 key. /// KP4 = 0xFFB4, /// /// The Numpad 5 key. /// KP5 = 0xFFB5, /// /// The Numpad 6 key. /// KP6 = 0xFFB6, /// /// The Numpad 7 key. /// KP7 = 0xFFB7, /// /// The Numpad 8 key. /// KP8 = 0xFFB8, /// /// The Numpad 9 key. /// KP9 = 0xFFB9, /* Auxiliary Functions */ /// /// The Function 1 key. /// F1 = 0xFFBE, /// /// The Function 2 key. /// F2 = 0xFFBF, /// /// The Function 3 key. /// F3 = 0xFFC0, /// /// The Function 4 key. /// F4 = 0xFFC1, /// /// The Function 5 key. /// F5 = 0xFFC2, /// /// The Function 6 key. /// F6 = 0xFFC3, /// /// The Function 7 key. /// F7 = 0xFFC4, /// /// The Function 8 key. /// F8 = 0xFFC5, /// /// The Function 9 key. /// F9 = 0xFFC6, /// /// The Function 10 key. /// F10 = 0xFFC7, /// /// The Function 11 key. /// F11 = 0xFFC8, /// /// The Function 12 key. /// F12 = 0xFFC9, /// /// The Function 13 key. /// F13 = 0xFFCA, /// /// The Function 14 key. /// F14 = 0xFFCB, /// /// The Function 15 key. /// F15 = 0xFFCC, /// /// The Function 16 key. /// F16 = 0xFFCD, /// /// The Function 17 key. /// F17 = 0xFFCE, /// /// The Function 18 key. /// F18 = 0xFFCF, /// /// The Function 19 key. /// F19 = 0xFFD0, /// /// The Function 20 key. /// F20 = 0xFFD1, /// /// The Function 21 key. /// F21 = 0xFFD2, /// /// The Function 22 key. /// F22 = 0xFFD3, /// /// The Function 23 key. /// F23 = 0xFFD4, /// /// The Function 24 key. /// F24 = 0xFFD5, /// /// The Function 25 key. /// F25 = 0xFFD6, /// /// The Function 26 key. /// F26 = 0xFFD7, /// /// The Function 27 key. /// F27 = 0xFFD8, /// /// The Function 28 key. /// F28 = 0xFFD9, /// /// The Function 29 key. /// F29 = 0xFFDA, /// /// The Function 30 key. /// F30 = 0xFFDB, /// /// The Function 31 key. /// F31 = 0xFFDC, /// /// The Function 32 key. /// F32 = 0xFFDD, /// /// The Function 33 key. /// F33 = 0xFFDE, /// /// The Function 34 key. /// F34 = 0xFFDF, /// /// The Function 35 key. /// F35 = 0xFFE0, /* Modifier keys */ /// /// The Left Shift key. /// ShiftL = 0xFFE1, /// /// The Right Shift key. /// ShiftR = 0xFFE2, /// /// The Left Control key. /// ControlL = 0xFFE3, /// /// The Right Control key. /// ControlR = 0xFFE4, /// /// The Caps Lock key. /// CapsLock = 0xFFE5, /// /// The Shift Lock key. /// ShiftLock = 0xFFE6, /// /// The Left Meta key. /// MetaL = 0xFFE7, /// /// The Right Meta key. /// MetaR = 0xFFE8, /// /// The Left Alt key. /// AltL = 0xFFE9, /// /// The Right Alt key. /// AltR = 0xFFEA, /// /// The Left Super key. /// SuperL = 0xFFEB, /// /// The Right Super key. /// SuperR = 0xFFEC, /// /// The Left Hyper key. /// HyperL = 0xFFED, /// /// The Right Hyper key. /// HyperR = 0xFFEE, /* Latin 1 */ /// /// The Space key. /// Space = 0x020, /// /// The Exclamation key. /// Exclam = 0x021, /// /// The Quotedbl key. /// Quotedbl = 0x022, /// /// The Number Sign key. /// NumberSign = 0x023, /// /// The Dollar key. /// Dollar = 0x024, /// /// The Percent key. /// Percent = 0x025, /// /// The Ampersand key. /// Ampersand = 0x026, /// /// The Apostrophe key. /// Apostrophe = 0x027, /// /// The Parenleft key. /// Parenleft = 0x028, /// /// The Parenright key. /// Parenright = 0x029, /// /// The Asterisk key. /// Asterisk = 0x02a, /// /// The Plus key. /// Plus = 0x02b, /// /// The Comma key. /// Comma = 0x02c, /// /// The Minus key. /// Minus = 0x02d, /// /// The Period key. /// Period = 0x02e, /// /// The Slash key. /// Slash = 0x02f, /// /// The 0 key. /// Keypad0 = 0x030, /// /// The 1 key. /// Keypad1 = 0x031, /// /// The 2 key. /// Keypad2 = 0x032, /// /// The 3 key. /// Keypad3 = 0x033, /// /// The 4 key. /// Keypad4 = 0x034, /// /// The 5 key. /// Keypad5 = 0x035, /// /// The 6 key. /// Keypad6 = 0x036, /// /// The 7 key. /// Keypad7 = 0x037, /// /// The 8 key. /// Keypad8 = 0x038, /// /// The 9 key. /// Keypad9 = 0x039, /// /// The Colon key. /// Colon = 0x03a, /// /// The Semicolon key. /// Semicolon = 0x03b, /// /// The Less key. /// Less = 0x03c, /// /// The Equal key. /// Equal = 0x03d, /// /// The Greater key. /// Greater = 0x03e, /// /// The Question key. /// Question = 0x03f, /// /// The At key. /// At = 0x040, /// /// The A key. /// KeypadA = 0x041, /// /// The B key. /// KeypadB = 0x042, /// /// The C key. /// KeypadC = 0x043, /// /// The D key. /// KeypadD = 0x044, /// /// The E key. /// KeypadE = 0x045, /// /// The F key. /// KeypadF = 0x046, /// /// The G key. /// KeypadG = 0x047, /// /// The H key. /// KeypadH = 0x048, /// /// The I key. /// KeypadI = 0x049, /// /// The J key. /// KeypadJ = 0x04a, /// /// The K key. /// KeypadK = 0x04b, /// /// The L key. /// KeypadL = 0x04c, /// /// The M key. /// KeypadM = 0x04d, /// /// The N key. /// KeypadN = 0x04e, /// /// The O key. /// KeypadO = 0x04f, /// /// The P key. /// KeypadP = 0x050, /// /// The Q key. /// KeypadQ = 0x051, /// /// The R key. /// KeypadR = 0x052, /// /// The S key. /// KeypadS = 0x053, /// /// The T key. /// KeypadT = 0x054, /// /// The U key. /// KeypadU = 0x055, /// /// The V key. /// KeypadV = 0x056, /// /// The W key. /// KeypadW = 0x057, /// /// The X key. /// KeypadX = 0x058, /// /// The Y key. /// KeypadY = 0x059, /// /// The Z key. /// KeypadZ = 0x05a, /// /// The Left Bracket key. /// BracketLeft = 0x05b, /// /// The Backslash key. /// Backslash = 0x05c, /// /// The Right Bracket key. /// BracketRight = 0x05d, /// /// The Circumflex key. /// AsciiCircum = 0x05e, /// /// The Underscore key. /// Underscore = 0x05f, /// /// The Grave key. /// Grave = 0x060, /// /// The a key. /// Keypada = 0x061, /// /// The b key. /// Keypadb = 0x062, /// /// The c key. /// Keypadc = 0x063, /// /// The d key. /// Keypadd = 0x064, /// /// The e key. /// Keypade = 0x065, /// /// The f key. /// Keypadf = 0x066, /// /// The g key. /// Keypadg = 0x067, /// /// The h key. /// Keypadh = 0x068, /// /// The i key. /// Keypadi = 0x069, /// /// The j key. /// Keypadj = 0x06a, /// /// The k key. /// Keypadk = 0x06b, /// /// The l key. /// Keypadl = 0x06c, /// /// The m key. /// Keypadm = 0x06d, /// /// The n key. /// Keypadn = 0x06e, /// /// The o key. /// Keypado = 0x06f, /// /// The p key. /// Keypadp = 0x070, /// /// The q key. /// Keypadq = 0x071, /// /// The r key. /// Keypadr = 0x072, /// /// The s key. /// Keypads = 0x073, /// /// The t key. /// Keypadt = 0x074, /// /// The u key. /// Keypadu = 0x075, /// /// The v key. /// Keypadv = 0x076, /// /// The w key. /// Keypadw = 0x077, /// /// The x key. /// Keypadx = 0x078, /// /// The y key. /// Keypady = 0x079, /// /// The z key. /// Keypadz = 0x07a, /// /// The Left Brace key. /// BraceLeft = 0x07b, /// /// The Bar key. /// Bar = 0x07c, /// /// The Right Brace key. /// BraceRight = 0x07d, /// /// The Tilde key. /// AsciiTilde = 0x07e, }; /// /// Enumeration for the key masks. /// The key masks indicate which modifier keys are pressed down during the keyboard hit. The special MASK_RELEASED indicates the key release event. /// /// 4 public enum KeyMask { /// /// Key press event without the modifier key. /// Pressed = 0, /// /// The Shift key is pressed down. /// Shift = (1 << 0), /// /// The CapsLock key is pressed down. /// CapsLock = (1 << 1), /// /// The Control key is pressed down. /// Control = (1 << 2), /// /// The Alt key is pressed down. /// Alt = (1 << 3), /// /// The Meta key is pressed down. /// Meta = (1 << 4), /// /// The Win key (between Control and Alt) is pressed down. /// Win = (1 << 5), /// /// The Hyper key is pressed down. /// Hyper = (1 << 6), /// /// The NumLock key is pressed down. /// NumLock = (1 << 7), /// /// Key release event. /// Released = (1 << 15), } /// /// This class contains the API's related to the IME (Input method editor). /// /// 4 public static class InputMethodEditor { private static ImeCallbackStructGCHandle _imeCallbackStructGCHandle = new ImeCallbackStructGCHandle(); private static event EventHandler _focusIn; private static ImeFocusedInCb _imeFocusedInDelegate; private static event EventHandler _focusOut; private static ImeFocusedOutCb _imeFocusedOutDelegate; private static event EventHandler _surroundingTextUpdated; private static ImeSurroundingTextUpdatedCb _imeSurroundingTextUpdatedDelegate; private static event EventHandler _inputContextReset; private static ImeInputContextResetCb _imeInputContextResetDelegate; private static event EventHandler _cursorPositionUpdated; private static ImeCursorPositionUpdatedCb _imeCursorPositionUpdatedDelegate; private static event EventHandler _langaugeSet; private static ImeLanguageSetCb _imeLanguageSetDelegate; private static event EventHandler _imDataSet; private static ImeImdataSetCb _imeDataSetDelegate; private static event EventHandler _layoutSet; private static ImeLayoutSetCb _imeLayoutSetDelegate; private static event EventHandler _returnKeyTypeSet; private static ImeReturnKeySetCb _imeReturnKeySetDelegate; private static event EventHandler _returnKeyStateSet; private static ImeReturnKeyStateSetCb _imeReturnKeyStateSetDelegate; private static ImeProcessKeyEventCb _imeProcessKeyDelegate; private static event EventHandler _displayLanguageChanged; private static ImeDisplayLanguageChangedCb _imeDisplayLanguageChangedDelegate; private static event EventHandler _rotationDegreeChanged; private static ImeRotationChangedCb _imeRotationChangedDelegate; private static event EventHandler _accessibilityStateChanged; private static ImeAccessibilityStateChangedCb _imeAccessibilityStateChangedDelegate; private static event EventHandler _predictionHintUpdated; private static ImePredictionHintSetCb _imePredictionHintSetDelegate; private static event EventHandler _predictionHintDataUpdated; private static ImePredictionHintDataSetCb _imePredictionHintDataSetDelegate; private static event EventHandler _mimeTypeUpdateRequested; private static ImeMimeTypeSetRequestCb _imeMimeTypeSetRequestDelegate; private static ImeLanguageRequestedCb _imeLanguageRequestedDelegate; private static OutAction _languageRequestedDelegate; private static BoolAction _processKeyDelagate; private static ImeImdataRequestedCb _imeImDataRequestedDelegate; private static OutArrayAction _imDataRequestedDelegate; private static ImeGeometryRequestedCb _imeGeometryRequestedDelegate; private static OutAction _geometryRequestedDelegate; private static ImeProcessKeyEventWithKeycodeCb _imeProcessKeyWithKeycodeDelegate; private static BoolAction _processKeyWithKeycodeDelagate; private static event EventHandler _inputHintSet; private static ImeInputHintSetCb _imeInputHintSetDelegate; private static Action _userCreate; private static Action _userTerminate; private static Action _userShow; private static Action _userHide; private static ImeCreateCb _create = (IntPtr userData) => { Log.Info(LogTag, "In Create Delegate"); _userCreate?.Invoke(); }; private static ImeTerminateCb _terminate = (IntPtr userData) => { Log.Info(LogTag, "In terminate Delegate"); _userTerminate?.Invoke(); _imeCallbackStructGCHandle.Dispose(); }; private static ImeShowCb _show = (int contextId, IntPtr context, IntPtr userData) => { Log.Info(LogTag, "In Show Delegate"); _userShow?.Invoke(new ContextId(contextId), new InputMethodContext(context)); }; private static ImeHideCb _hide = (int contextId, IntPtr userData) => { Log.Info(LogTag, "In Hide Delegate"); _userHide?.Invoke(new ContextId(contextId)); }; /// /// Structure representing the ContextId. /// /// 4 public struct ContextId : IEquatable { internal ContextId(int id) { Id = id; } internal int Id { get; private set; } /// /// Compares whether the ContextIds are equal. /// /// The ContextId to compare with this instance. /// true if the ContextIds is the same; otherwise, false. /// 4 public bool Equals(ContextId other) { return this.Id == other.Id; } } /// /// Rectangle representing the position and size of the UI control. /// /// 4 public struct Rect { /// /// The X position in the screen. /// /// 4 public int x; /// /// The Y position in the screen. /// /// 4 public int y; /// /// The window width. /// /// 4 public int w; /// /// The window height. /// /// 4 public int h; } /// /// An action with 1 out parameter. /// /// Generic Type. /// The out parameter. /// 4 public delegate void OutAction(out T a); /// /// An action with an array out parameter. /// /// Generic Type. /// The out parameter 1. /// 4 public delegate void OutArrayAction(out T[] a); /// /// An action with 3 input parameters returning a bool. /// /// Generic type for parameter 1. /// Generic type for parameter 2. /// Generic type for parameter 3. /// The input parameter 1. /// The input parameter 2. /// The input parameter 3. /// /// 4 public delegate bool BoolAction(T a, T1 b, T2 c); /// /// An action with 4 input parameters returning a bool. /// /// Generic type for parameter 1. /// Generic type for parameter 2. /// Generic type for parameter 3. /// Generic type for parameter 4. /// The input parameter 1. /// The input parameter 2. /// The input parameter 3. /// The input parameter 4. /// /// 10 public delegate bool BoolAction(T a, T1 b, T2 c, T3 d); /// /// Called when an associated text input UI control has focus. /// /// 4 public static event EventHandler FocusedIn { add { _imeFocusedInDelegate = (int contextId, IntPtr userData) => { FocusedInEventArgs args = new FocusedInEventArgs(contextId); _focusIn?.Invoke(null, args); }; ErrorCode error = ImeEventSetFocusedInCb(_imeFocusedInDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add FocusedIn Failed with error " + error); } else { _focusIn += value; } } remove { _focusIn -= value; } } /// /// Called when an associated text input UI control loses focus. /// /// 4 public static event EventHandler FocusedOut { add { _imeFocusedOutDelegate = (int contextId, IntPtr userData) => { FocusedOutEventArgs args = new FocusedOutEventArgs(contextId); _focusOut?.Invoke(null, args); }; ErrorCode error = ImeEventSetFocusedOutCb(_imeFocusedOutDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add FocusedOut Failed with error " + error); } else { _focusOut += value; } } remove { _focusOut -= value; } } /// /// Called when an associated text input UI control responds to a request with the surrounding text. /// /// 4 public static event EventHandler SurroundingTextUpdated { add { _imeSurroundingTextUpdatedDelegate = (int contextId, IntPtr text, int cursorPos, IntPtr userData) => { SurroundingTextUpdatedEventArgs args = new SurroundingTextUpdatedEventArgs(contextId, Marshal.PtrToStringAnsi(text), cursorPos); _surroundingTextUpdated?.Invoke(null, args); }; ErrorCode error = ImeEventSetSurroundingTextUpdatedCb(_imeSurroundingTextUpdatedDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add SurroundingTextUpdated Failed with error " + error); } else { _surroundingTextUpdated += value; } } remove { _surroundingTextUpdated -= value; } } /// /// Called to reset the input context of an associated text input UI control. /// /// 4 public static event EventHandler InputContextReset { add { _imeInputContextResetDelegate = (IntPtr userData) => { _inputContextReset?.Invoke(null, EventArgs.Empty); }; ErrorCode error = ImeEventSetInputContextResetCb(_imeInputContextResetDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add InputContextReset Failed with error " + error); } else { _inputContextReset += value; } } remove { _inputContextReset -= value; } } /// /// Called when the position of the cursor in an associated text input UI control changes. /// /// 4 public static event EventHandler CursorPositionUpdated { add { _imeCursorPositionUpdatedDelegate = (int cursorPos, IntPtr userData) => { CursorPositionUpdatedEventArgs args = new CursorPositionUpdatedEventArgs(cursorPos); _cursorPositionUpdated?.Invoke(null, args); }; ErrorCode error = ImeEventSetCursorPositionUpdatedCb(_imeCursorPositionUpdatedDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add CursorPositionUpdated Failed with error " + error); } else { _cursorPositionUpdated += value; } } remove { _cursorPositionUpdated -= value; } } /// /// Called to set the preferred language to the input panel. /// It will only be called when the client application changes the edit field's language attribute after the input panel is shown. /// /// 4 public static event EventHandler LanguageSet { add { _imeLanguageSetDelegate = (InputPanelLanguage language, IntPtr userData) => { LanguageSetEventArgs args = new LanguageSetEventArgs(language); _langaugeSet?.Invoke(null, args); }; ErrorCode error = ImeEventSetLanguageSetCb(_imeLanguageSetDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add LanguageSet Failed with error " + error); } else { _langaugeSet += value; } } remove { _langaugeSet -= value; } } /// /// Called to set the application specific data to deliver to the input panel. /// /// 4 public static event EventHandler DataSet { add { _imeDataSetDelegate = (IntPtr data, uint dataLength, IntPtr userData) => { byte[] destination = new byte[dataLength]; Marshal.Copy(data, destination, 0, (int)dataLength); SetDataEventArgs args = new SetDataEventArgs(destination, dataLength); _imDataSet?.Invoke(null, args); }; ErrorCode error = ImeEventSetImdataSetCb(_imeDataSetDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add DataSet Failed with error " + error); } else { _imDataSet += value; } } remove { _imDataSet -= value; } } /// /// Called when an associated text input UI control requests the input panel to set its layout. /// It will only be called when the client application changes the edit field's layout attribute after the input panel is shown. /// /// 4 public static event EventHandler LayoutSet { add { _imeLayoutSetDelegate = (InputPanelLayout layout, IntPtr userData) => { LayoutSetEventArgs args = new LayoutSetEventArgs(layout); _layoutSet?.Invoke(null, args); }; ErrorCode error = ImeEventSetLayoutSetCb(_imeLayoutSetDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add LayoutSet Failed with error " + error); } else { _layoutSet += value; } } remove { _layoutSet -= value; } } /// /// Called when an associated text input UI control requests the input panel to set the Return key label. /// The input panel can show the text or an image on the Return button, according to the Return key action. /// /// 4 public static event EventHandler ReturnKeySet { add { _imeReturnKeySetDelegate = (InputPanelReturnKey type, IntPtr userData) => { ReturnKeySetEventArgs args = new ReturnKeySetEventArgs(type); _returnKeyTypeSet?.Invoke(null, args); }; ErrorCode error = ImeEventSetReturnKeySetCb(_imeReturnKeySetDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add ReturnKeySet Failed with error " + error); } else { _returnKeyTypeSet += value; } } remove { _returnKeyTypeSet -= value; } } /// /// Called when an associated text input UI control requests the input panel to enable or disable the Return key state. /// /// 4 public static event EventHandler ReturnKeyStateSet { add { _imeReturnKeyStateSetDelegate = (bool state, IntPtr userData) => { ReturnKeyStateSetEventArgs args = new ReturnKeyStateSetEventArgs(state); _returnKeyStateSet?.Invoke(null, args); }; ErrorCode error = ImeEventSetReturnKeyStateSetCb(_imeReturnKeyStateSetDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add ReturnKeyStateSet Failed with error " + error); } else { _returnKeyStateSet += value; } } remove { _returnKeyStateSet -= value; } } /// /// Called when the system display language is changed. /// /// 4 public static event EventHandler DisplayLanguageChanged { add { _imeDisplayLanguageChangedDelegate = (IntPtr language, IntPtr userData) => { DisplayLanguageChangedEventArgs args = new DisplayLanguageChangedEventArgs(Marshal.PtrToStringAnsi(language)); _displayLanguageChanged?.Invoke(null, args); }; ErrorCode error = ImeEventSetDisplayLanguageChangedCb(_imeDisplayLanguageChangedDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add DisplayLanguageChanged Failed with error " + error); } else { _displayLanguageChanged += value; } } remove { _displayLanguageChanged -= value; } } /// /// Called when the device is rotated. /// /// 4 public static event EventHandler RotationChanged { add { _imeRotationChangedDelegate = (int degree, IntPtr userData) => { RotationChangedEventArgs args = new RotationChangedEventArgs(degree); _rotationDegreeChanged?.Invoke(null, args); }; ErrorCode error = ImeEventSetRotationChangedCb(_imeRotationChangedDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add RotationChanged Failed with error " + error); } else { _rotationDegreeChanged += value; } } remove { _rotationDegreeChanged -= value; } } /// /// Called when Accessibility in settings application is on or off. /// /// 4 public static event EventHandler AccessibilityStateChanged { add { _imeAccessibilityStateChangedDelegate = (bool state, IntPtr userData) => { AccessibilityStateChangedEventArgs args = new AccessibilityStateChangedEventArgs(state); _accessibilityStateChanged?.Invoke(null, args); }; ErrorCode error = ImeEventSetAccessibilityStateChangedCb(_imeAccessibilityStateChangedDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add AccessibilityStateChanged Failed with error " + error); } else { _accessibilityStateChanged += value; } } remove { _accessibilityStateChanged -= value; } } /// /// Sets the languageRequested action. /// /// /// Called when an associated text input UI control requests the language from the input panel, requesting for language code. /// /// 4 public static void SetLanguageRequestedCallback(OutAction languageRequested) { _imeLanguageRequestedDelegate = (IntPtr userData, out IntPtr langCode) => { string language; _languageRequestedDelegate(out language); langCode = (IntPtr)Marshal.StringToHGlobalAnsi(language); }; ErrorCode error = ImeEventSetLanguageRequestedCallbackCb(_imeLanguageRequestedDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add SetLanguageRequestedCallback Failed with error " + error); } _languageRequestedDelegate = languageRequested; } /// /// Sets the processKey action. /// If the key event is from the external device, DeviceInfo will have its name, class, and subclass information. /// /// /// The action is called when the key event is received from the external devices or the SendKey function. /// This Event processes the key event before an associated text input UI control does. /// /// 4 public static void SetProcessKeyCallback(BoolAction processKey) { _imeProcessKeyDelegate = (KeyCode keyCode, KeyMask keyMask, IntPtr devInfo, IntPtr userData) => { return _processKeyDelagate(keyCode, keyMask, new InputMethodDeviceInformation(devInfo)); }; ErrorCode error = ImeEventSetProcessKeyEventCb(_imeProcessKeyDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add ProcessKey Failed with error " + error); } _processKeyDelagate = processKey; } /// /// Sets the imDataRequested action. /// /// /// 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. /// /// 4 public static void SetDataRequestedCallback(OutArrayAction imDataRequested) { _imeImDataRequestedDelegate = (IntPtr userData, out IntPtr data, out uint dataLength) => { byte[] dataArr; _imDataRequestedDelegate(out dataArr); data = Marshal.AllocHGlobal(dataArr.Length); Marshal.Copy(dataArr, 0, data, dataArr.Length); dataLength = (uint)dataArr.Length; }; ErrorCode error = ImeEventSetImdataRequestedCb(_imeImDataRequestedDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add SetDataRequestedCallback Failed with error " + error); } _imDataRequestedDelegate = imDataRequested; } /// /// Sets the GeometryRequested action. /// /// /// Called when an associated text input UI control requests the position and size from the input panel, requesting for x, y, w, h values. /// /// 4 public static void SetGeometryRequestedCallback(OutAction geometryRequested) { _imeGeometryRequestedDelegate = (IntPtr userData, out int x, out int y, out int w, out int h) => { Rect rect = new Rect(); _geometryRequestedDelegate(out rect); x = rect.x; y = rect.y; w = rect.w; h = rect.h; }; ErrorCode error = ImeEventSetGeometryRequestedCallbackCb(_imeGeometryRequestedDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add SetGeometryRequestedCallback Failed with error " + error); } _geometryRequestedDelegate = geometryRequested; } /// /// Runs the main loop of the IME application. /// This function starts to run the IME application's main loop. /// /// /// http://tizen.org/privilege/ime /// /// /// This API is a blocking call, as it starts the main loop of the application. /// /// This is called to initialize the IME application before the main loop starts up. /// This is called when the IME application is terminated. /// /// This is called when the IME application is shown. /// It provides the context information and the context ID. /// /// /// This is called when the IME application is hidden. /// It provides the context ID. /// /// This exception can be due to permission denied. /// This exception can be due to operation failed. /// 4 public static void Run(Action create, Action terminate, Action show, Action hide) { _userCreate = create; _userTerminate = terminate; _userShow = show; _userHide = hide; _imeCallbackStructGCHandle._imeCallbackStruct.create = _create; _imeCallbackStructGCHandle._imeCallbackStruct.terminate = _terminate; _imeCallbackStructGCHandle._imeCallbackStruct.hide = _hide; _imeCallbackStructGCHandle._imeCallbackStruct.show = _show; ImeSetDotnetFlag(true); ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Run Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Sends a key event to the associated text input UI control. /// /// /// This function sends a key down or up event with the key mask to the client application. If forwardKey is true, this key event goes to the edit filed directly. /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field. /// /// /// http://tizen.org/privilege/ime /// /// The key code to be sent. /// The modifier key mask. /// The flag to send the key event directly to the edit field. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 4 public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false) { ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey); if (error != ErrorCode.None) { Log.Error(LogTag, "SendEvent Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Sends the text to the associated text input UI control. /// /// /// http://tizen.org/privilege/ime /// /// The string to be committed. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 4 public static void CommitString(string str) { ErrorCode error = ImeCommitString(str); if (error != ErrorCode.None) { Log.Error(LogTag, "CommitString Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Requests to show the pre-edit string. /// /// /// http://tizen.org/privilege/ime /// /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 4 public static void ShowPreEditString() { ErrorCode error = ImeShowPreeditString(); if (error != ErrorCode.None) { Log.Error(LogTag, "ShowPreEditString Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Requests to hide the pre-edit string. /// /// /// http://tizen.org/privilege/ime /// /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 4 public static void HidePreEditString() { ErrorCode error = ImeHidePreeditString(); if (error != ErrorCode.None) { Log.Error(LogTag, "HidePreEditString Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Updates a new pre-edit string. /// /// /// http://tizen.org/privilege/ime /// /// The string to be updated in pre-edit. /// /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color, and reversal color. /// The attrs list can be empty if no attributes to set. /// /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 4 public static void UpdatePreEditString(string str, IEnumerable attrs) { IntPtr einaList = IntPtr.Zero; foreach (PreEditAttribute attribute in attrs) { IntPtr attr = IntPtr.Zero; ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct(); imePreEditAttribute.start = attribute.Start; imePreEditAttribute.length = attribute.Length; imePreEditAttribute.type = (int)attribute.Type; imePreEditAttribute.value = attribute.Value; attr = Marshal.AllocHGlobal(Marshal.SizeOf(imePreEditAttribute)); Marshal.WriteIntPtr(attr, IntPtr.Zero); Marshal.StructureToPtr(imePreEditAttribute, attr, false); einaList = Interop.EinaList.EinaListAppend(einaList, attr); } ErrorCode error = ImeUpdatePreeditString(str, einaList); if (error != ErrorCode.None) { Log.Error(LogTag, "UpdatePreEditString Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Requests the surrounding text from the position of the cursor, asynchronously. /// /// /// http://tizen.org/privilege/ime /// /// The maximum length of the string to be retrieved before the cursor, -1 means unlimited. /// The maximum length of the string to be retrieved after the cursor, -1 means unlimited. /// This exception can be due to permission denied. /// /// This can occur due to the following reasons: /// 1) The IME main loop has not started yet. /// 2) The necessary event is not set. /// /// /// The requested surrounding text can be received using the SurroundingTextUpdated event, only if it is set. /// /// 4 public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter) { ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter); if (error != ErrorCode.None) { Log.Error(LogTag, "RequestSurroundingText Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Requests to delete the surrounding text. /// /// /// http://tizen.org/privilege/ime /// /// The offset value from the cursor position. /// The length of the text to delete. /// This exception can be due to an invalid parameter. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 4 public static void DeleteSurroundingText(int offset, int len) { ErrorCode error = ImeDeleteSurroundingText(offset, len); if (error != ErrorCode.None) { Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Gets the surrounding text from the position of the cursor, synchronously. /// /// /// http://tizen.org/privilege/ime /// /// The maximum length of the string to be retrieved before the cursor, -1 means unlimited. /// The maximum length of the string to be retrieved after the cursor, -1 means unlimited. /// The surrounding text. /// The cursor position. /// This exception can be due to out of memory. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 4 public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition) { IntPtr txt; ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition); if (error != ErrorCode.None) { Log.Error(LogTag, "GetSurroundingText Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } text = Marshal.PtrToStringAnsi(txt); } /// /// Requests to set the selection. /// /// /// http://tizen.org/privilege/ime /// /// The start cursor position in text (in characters not bytes). /// The end cursor position in text (in characters not bytes). /// This exception can be due to an invalid parameter. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 4 public static void SetSelection(int start, int end) { ErrorCode error = ImeSetSelection(start, end); if (error != ErrorCode.None) { Log.Error(LogTag, "SetSelection Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// This API returns the input panel main window. /// /// /// http://tizen.org/privilege/ime /// /// The input panel main window object on success, otherwise null. /// This exception can be due to permission denied. /// /// This can occur due to the following reasons: /// 1) The IME main loop has not started yet. /// 2) Operation failed. /// /// 4 [Obsolete("Deprecated since API10. Will be removed in API12.")] public static EditorWindow GetMainWindow() { EditorWindow._handle = ImeGetMainWindow(); EditorWindow obj = new EditorWindow(); ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult(); if (error != ErrorCode.None) { Log.Error(LogTag, "GetMainWindow Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } return obj; } /// /// Sends the request to hide the IME. /// /// /// http://tizen.org/privilege/ime /// /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 5 public static void RequestHide() { ErrorCode error = ImeRequestHide(); if (error != ErrorCode.None) { Log.Error(LogTag, "RequestHide Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// This API requests the InputMethodEditor to initialize. /// /// /// http://tizen.org/privilege/ime /// /// This exception can be due to permission denied. /// This exception can be due to operation failed. /// 4 [EditorBrowsable(EditorBrowsableState.Never)] public static void Create() { ErrorCode error = ImeInitialize(); Log.Info(LogTag, "ImeInitialize result : " + error); if (error != ErrorCode.None) { Log.Error(LogTag, "ImeInitialize Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } error = ImePrepare(); Log.Info(LogTag, "ImePrepare result : " + error); if (error != ErrorCode.None) { Log.Error(LogTag, "ImePrepare Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// This API requests the InputMethodEditor to finalize. /// /// /// http://tizen.org/privilege/ime /// /// This exception can be due to permission denied. /// 4 [EditorBrowsable(EditorBrowsableState.Never)] public static void Destroy() { ErrorCode error = ImeFinalize(); Log.Info(LogTag, "ImeFinalize result : " + error); if (error != ErrorCode.None) { Log.Error(LogTag, "ImeFinalize Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Sets the floating mode to on or off. /// /// /// http://tizen.org/privilege/ime /// /// true to set the floating mode to on and false to set it to off. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 5 public static void SetFloatingMode(bool floatingMode) { ErrorCode error = ImeSetFloatingMode(floatingMode); if (error != ErrorCode.None) { Log.Error(LogTag, "SetFloatingMode Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Allows the floating input panel window to move along with the mouse pointer when the mouse is pressed. /// /// /// http://tizen.org/privilege/ime /// /// /// This function can be used in floating mode. If the floating mode is deactivated, calling this function has no effect. /// /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 5 public static void SetFloatingDragStart() { ErrorCode error = ImeSetFloatingDragStart(); if (error != ErrorCode.None) { Log.Error(LogTag, "SetFloatingDragStart Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Does not allow the movement of the floating input panel window with the mouse pointer when the mouse is pressed. /// /// /// http://tizen.org/privilege/ime /// /// /// This function can be used in floating mode. If the floating mode is deactivated, calling this function has no effect. /// /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 5 public static void SetFloatingDragEnd() { ErrorCode error = ImeSetFloatingDragEnd(); if (error != ErrorCode.None) { Log.Error(LogTag, "SetFloatingDragEnd Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Notifies the changed language of the input panel to the the associated text input UI control. /// /// /// http://tizen.org/privilege/ime /// /// /// LanguageRequestedCallback is raised after this API is called when the App requests changed language information. /// /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 6 public static void SendLanguageUpdated() { ErrorCode error = ImeUpdateInputPanelEvent(ImeEventType.Language, 0); if (error != ErrorCode.None) { Log.Error(LogTag, "SendLanguageUpdated Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Sends the changed shift mode of the input panel to the the associated text input UI control. /// /// /// http://tizen.org/privilege/ime /// /// true if shift button is clicked, otherwise false. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 6 public static void SendShiftModeUpdated(bool enable) { ErrorCode error = ImeUpdateInputPanelEvent(ImeEventType.ShiftMode, enable ? (uint)ImeShiftMode.On : (uint)ImeShiftMode.Off); if (error != ErrorCode.None) { Log.Error(LogTag, "SendInputPanelEvent Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Notifies the changed geometry of input panel window to the associated text input UI control. /// /// /// http://tizen.org/privilege/ime /// /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 6 public static void SendCustomGeometryUpdated() { ErrorCode error = ImeUpdateInputPanelEvent(ImeEventType.Geometry, 0); if (error != ErrorCode.None) { Log.Error(LogTag, "SendCustomGeometryUpdated Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Gets the selected text synchronously. /// /// /// http://tizen.org/privilege/ime /// /// The selected text. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 6 public static string GetSelectedText() { IntPtr txt; ErrorCode error = ImeGetSelectedText(out txt); if (error != ErrorCode.None) { Log.Error(LogTag, "GetSelectedText Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } return Marshal.PtrToStringAnsi(txt); } /// /// Called to set the prediction hint string to deliver to the input panel. /// /// 6 public static event EventHandler PredictionHintUpdated { add { if (_imePredictionHintSetDelegate == null) { _imePredictionHintSetDelegate = (IntPtr predictionHint, IntPtr userData) => { PredictionHintUpdatedEventArgs args = new PredictionHintUpdatedEventArgs(Marshal.PtrToStringAnsi(predictionHint)); _predictionHintUpdated?.Invoke(null, args); }; ErrorCode error = ImeEventSetPredictionHintSetCb(_imePredictionHintSetDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add PredictionHintUpdated Failed with error " + error); } } _predictionHintUpdated += value; } remove { _predictionHintUpdated -= value; } } /// /// Called to set the prediction hint key and value to deliver to the input panel. /// /// 6 public static event EventHandler PredictionHintDataUpdated { add { if (_imePredictionHintDataSetDelegate == null) { _imePredictionHintDataSetDelegate = (IntPtr key, IntPtr keyValue, IntPtr userData) => { PredictionHintDataUpdatedEventArgs args = new PredictionHintDataUpdatedEventArgs(Marshal.PtrToStringAnsi(key), Marshal.PtrToStringAnsi(keyValue)); _predictionHintDataUpdated?.Invoke(null, args); }; ErrorCode error = ImeEventSetPredictionHintDataSetCb(_imePredictionHintDataSetDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add PredictionHintDataUpdated Failed with error " + error); } } _predictionHintDataUpdated += value; } remove { _predictionHintDataUpdated -= value; } } /// /// Called when an associated text input UI control requests the text entry to set the MIME type. /// /// 6 public static event EventHandler MimeTypeUpdateRequested { add { if (_imeMimeTypeSetRequestDelegate == null) { _imeMimeTypeSetRequestDelegate = (IntPtr mimeType, IntPtr userData) => { MimeTypeUpdateRequestedEventArgs args = new MimeTypeUpdateRequestedEventArgs(Marshal.PtrToStringAnsi(mimeType)); _mimeTypeUpdateRequested?.Invoke(null, args); }; ErrorCode error = ImeEventSetMimeTypeSetRequestCb(_imeMimeTypeSetRequestDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add MimeTypeUpdateRequested Failed with error " + error); } } _mimeTypeUpdateRequested += value; } remove { _mimeTypeUpdateRequested -= value; } } /// /// Sends a private command to the associated text input UI control. /// /// /// http://tizen.org/privilege/ime /// /// The UTF-8 string to be sent. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 6 public static void SendPrivateCommand(string command) { ErrorCode error = ImeSendPrivateCommand(command); if (error != ErrorCode.None) { Log.Error(LogTag, "SendPrivateCommand Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Commits contents such as image to the associated text input UI control. /// /// /// http://tizen.org/privilege/ime /// /// The content URI to be sent. /// The content description. /// The MIME type received from the MimeTypeSetRequest /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 6 public static void CommitContent(string content, string description, string mimeType) { ErrorCode error = ImeCommitContent(content, description, mimeType); if (error != ErrorCode.None) { Log.Error(LogTag, "CommitContent Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// This API updates the given native input panel window's size information. /// The native window handle of NUI Window can be got by below code. /// var handle = new Window.SafeNativeWindowHandle(); /// IntPtr nativeHandle = handle.DangerousGetHandle(); /// /// /// http://tizen.org/privilege/ime /// /// The native window handle. /// The width in the portrait mode. /// The height in the portrait mode. /// The width in the landscape mode. /// The height in the landscape mode. /// This exception can be due to an invalid parameter. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 9 public static void SetSize(IntPtr window, int portraitWidth, int portraitHeight, int landscapeWidth, int landscapeHeight) { ErrorCode error = ImeSetNativeWindowSize(window, portraitWidth, portraitHeight, landscapeWidth, landscapeHeight); if (error != ErrorCode.None) { Log.Error(LogTag, "SetSize Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Sets the processKey action. /// If the key event is from the external device, DeviceInfo will have its name, class, and subclass information. /// /// /// true if the event was processed, otherwise the event was not processed and was forwarded to the client application. /// The first parameter is X11 key code and the second parameter is key symbol. /// The action is called when the key event is received from the external devices or the SendKey function. /// This Event processes the key event before an associated text input UI control does. /// /// 10 public static void SetProcessKeyCallback(BoolAction processKey) { _imeProcessKeyWithKeycodeDelegate = (uint keyCode, KeyCode keySymbol, KeyMask keyMask, IntPtr devInfo, IntPtr userData) => { return _processKeyWithKeycodeDelagate(keyCode, keySymbol, keyMask, new InputMethodDeviceInformation(devInfo)); }; ErrorCode error = ImeEventSetProcessKeyEventWithKeycodeCb(_imeProcessKeyWithKeycodeDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add ProcessKeyWithKeycode Failed with error " + error); } _processKeyWithKeycodeDelagate = processKey; } /// /// Updates the cursor position in the preedit string. /// /// /// http://tizen.org/privilege/ime /// /// The cursor position in the preedit string. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 10 public static void UpdatePreeditCursor(uint position) { ErrorCode error = ImeUpdatePreeditCursor(position); if (error != ErrorCode.None) { Log.Error(LogTag, "UpdatePreeditCursor Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Sets whether candidate strings will be shown or not. /// /// /// http://tizen.org/privilege/ime /// /// true to show candidate strings, false otherwise. /// This exception can be due to permission denied. /// The IME main loop has not started yet. /// 10 public static void SetCandidateVisibilityState(bool visible) { ErrorCode error = ImeSetCandidateVisibilityState(visible); if (error != ErrorCode.None) { Log.Error(LogTag, "SetCandidateVisibilityState Failed with error " + error); throw InputMethodExceptionFactory.CreateException(error); } } /// /// Called when an associated text input UI control requests the input panel to set its input hint. /// It will only be called when the client application changes the edit field's input hint attribute after the input panel is shown. /// /// /// 10 public static event EventHandler InputHintSet { add { _imeInputHintSetDelegate = (InputHints hint, IntPtr userData) => { InputHintSetEventArgs args = new InputHintSetEventArgs(hint); _inputHintSet?.Invoke(null, args); }; ErrorCode error = ImeEventSetInputHintSetCb(_imeInputHintSetDelegate, IntPtr.Zero); if (error != ErrorCode.None) { Log.Error(LogTag, "Add InputHintSet Failed with error " + error); } else { _inputHintSet += value; } } remove { _inputHintSet -= value; } } } }