Release 4.0.0-preview1-00258
[platform/core/csapi/tizenfx.git] / src / Tizen.Uix.InputMethod / Tizen.Uix.InputMethod / InputMethodEditor.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17
18 using System;
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using static Interop.InputMethod;
22
23 namespace Tizen.Uix.InputMethod
24 {
25     /// <summary>
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.
29     /// </summary>
30     public enum KeyCode
31     {
32         /// <summary>
33         /// The backspace key
34         /// </summary>
35         BackSpace = 0xFF08,
36         /// <summary>
37         /// The tab key
38         /// </summary>
39         Tab = 0xFF09,
40         /// <summary>
41         /// The linefeed key
42         /// </summary>
43         Linefeed = 0xFF0A,
44         /// <summary>
45         /// The clear key
46         /// </summary>
47         Clear = 0xFF0B,
48         /// <summary>
49         /// The return key
50         /// </summary>
51         Return = 0xFF0D,
52         /// <summary>
53         /// The pause key
54         /// </summary>
55         Pause = 0xFF13,
56         /// <summary>
57         /// The scroll lock key
58         /// </summary>
59         ScrollLock = 0xFF14,
60         /// <summary>
61         /// The sys req key
62         /// </summary>
63         SysReq = 0xFF15,
64         /// <summary>
65         /// The escape key
66         /// </summary>
67         Escape = 0xFF1B,
68         /// <summary>
69         /// The delete key
70         /// </summary>
71         Delete = 0xFFFF,
72
73         /* Cursor control & motion */
74         /// <summary>
75         /// The home key
76         /// </summary>
77         Home = 0xFF50,
78         /// <summary>
79         /// The left directional key
80         /// </summary>
81         Left = 0xFF51,
82         /// <summary>
83         /// The up directional key
84         /// </summary>
85         Up = 0xFF52,
86         /// <summary>
87         /// The right directional key
88         /// </summary>
89         Right = 0xFF53,
90         /// <summary>
91         /// The down directional key
92         /// </summary>
93         Down = 0xFF54,
94         /// <summary>
95         /// The prior, previous key
96         /// </summary>
97         Prior = 0xFF55,
98         /// <summary>
99         /// The page up key
100         /// </summary>
101         Page_Up = 0xFF55,
102         /// <summary>
103         /// The next key
104         /// </summary>
105         Next = 0xFF56,
106         /// <summary>
107         /// The page down key
108         /// </summary>
109         Page_Down = 0xFF56,
110         /// <summary>
111         /// The end key
112         /// </summary>
113         End = 0xFF57,
114         /// <summary>
115         /// The begin key
116         /// </summary>
117         Begin = 0xFF58,
118
119         /* Misc Functions */
120         /// <summary>
121         /// The select key
122         /// </summary>
123         Select = 0xFF60,
124         /// <summary>
125         /// The print key
126         /// </summary>
127         Print = 0xFF61,
128         /// <summary>
129         /// The execute, run, do key
130         /// </summary>
131         Execute = 0xFF62,
132         /// <summary>
133         /// The insert key
134         /// </summary>
135         Insert = 0xFF63,
136         /// <summary>
137         /// The undo key
138         /// </summary>
139         Undo = 0xFF65,
140         /// <summary>
141         /// The redo key
142         /// </summary>
143         Redo = 0xFF66,
144         /// <summary>
145         /// The menu key
146         /// </summary>
147         Menu = 0xFF67,
148         /// <summary>
149         /// The find key
150         /// </summary>
151         Find = 0xFF68,
152         /// <summary>
153         /// The cancel, stop, abort, exit key
154         /// </summary>
155         Cancel = 0xFF69,
156         /// <summary>
157         /// The help key
158         /// </summary>
159         Help = 0xFF6A,
160         /// <summary>
161         /// The break key
162         /// </summary>
163         Break = 0xFF6B,
164         /// <summary>
165         /// The character set switch key
166         /// </summary>
167         Mode_switch = 0xFF7E,
168         /// <summary>
169         /// The num lock key
170         /// </summary>
171         Num_Lock = 0xFF7F,
172
173         /* Keypad */
174         /// <summary>
175         /// The Numpad space key
176         /// </summary>
177         KPSpace = 0xFF80,
178         /// <summary>
179         /// The Numpad tab key
180         /// </summary>
181         KPTab = 0xFF89,
182         /// <summary>
183         /// The Numpad enter key
184         /// </summary>
185         KPEnter = 0xFF8D,
186         /// <summary>
187         /// The Numpad function 1 key
188         /// </summary>
189         KPF1 = 0xFF91,
190         /// <summary>
191         /// The Numpad function 2 key
192         /// </summary>
193         KPF2 = 0xFF92,
194         /// <summary>
195         /// The Numpad function 3 key
196         /// </summary>
197         KPF3 = 0xFF93,
198         /// <summary>
199         /// The Numpad function 4 key
200         /// </summary>
201         KPF4 = 0xFF94,
202         /// <summary>
203         /// The Numpad home key
204         /// </summary>
205         KPHome = 0xFF95,
206         /// <summary>
207         /// The Numpad left key
208         /// </summary>
209         KPLeft = 0xFF96,
210         /// <summary>
211         /// The Numpad up key
212         /// </summary>
213         KPUp = 0xFF97,
214         /// <summary>
215         /// The Numpad right key
216         /// </summary>
217         KPRight = 0xFF98,
218         /// <summary>
219         /// The Numpad down key
220         /// </summary>
221         KPDown = 0xFF99,
222         /// <summary>
223         /// The Numpad prior, previous key
224         /// </summary>
225         KPPrior = 0xFF9A,
226         /// <summary>
227         /// The Numpad page up key
228         /// </summary>
229         KPPage_Up = 0xFF9A,
230         /// <summary>
231         /// The Numpad next key
232         /// </summary>
233         KPNext = 0xFF9B,
234         /// <summary>
235         /// The Numpad page down key
236         /// </summary>
237         KPPage_Down = 0xFF9B,
238         /// <summary>
239         /// The Numpad end key
240         /// </summary>
241         KPEnd = 0xFF9C,
242         /// <summary>
243         /// The Numpad begin key
244         /// </summary>
245         KPBegin = 0xFF9D,
246         /// <summary>
247         /// The Numpad insert key
248         /// </summary>
249         KPInsert = 0xFF9E,
250         /// <summary>
251         /// The Numpad delete key
252         /// </summary>
253         KPDelete = 0xFF9F,
254         /// <summary>
255         /// The Numpad equal key
256         /// </summary>
257         KPEqual = 0xFFBD,
258         /// <summary>
259         /// The Numpad multiply key
260         /// </summary>
261         KPMultiply = 0xFFAA,
262         /// <summary>
263         /// The Numpad add key
264         /// </summary>
265         KPAdd = 0xFFAB,
266         /// <summary>
267         /// The Numpad separator key
268         /// </summary>
269         KPSeparator = 0xFFAC,
270         /// <summary>
271         /// The Numpad subtract key
272         /// </summary>
273         KPSubtract = 0xFFAD,
274         /// <summary>
275         /// The Numpad decimal key
276         /// </summary>
277         KPDecimal = 0xFFAE,
278         /// <summary>
279         /// The Numpad divide key
280         /// </summary>
281         KPDivide = 0xFFAF,
282         /// <summary>
283         /// The Numpad 0 key
284         /// </summary>
285         KP0 = 0xFFB0,
286         /// <summary>
287         /// The Numpad 1 key
288         /// </summary>
289         KP1 = 0xFFB1,
290         /// <summary>
291         /// The Numpad 2 key
292         /// </summary>
293         KP2 = 0xFFB2,
294         /// <summary>
295         /// The Numpad 3 key
296         /// </summary>
297         KP3 = 0xFFB3,
298         /// <summary>
299         /// The Numpad 4 key
300         /// </summary>
301         KP4 = 0xFFB4,
302         /// <summary>
303         /// The Numpad 5 key
304         /// </summary>
305         KP5 = 0xFFB5,
306         /// <summary>
307         /// The Numpad 6 key
308         /// </summary>
309         KP6 = 0xFFB6,
310         /// <summary>
311         /// The Numpad 7 key
312         /// </summary>
313         KP7 = 0xFFB7,
314         /// <summary>
315         /// The Numpad 8 key
316         /// </summary>
317         KP8 = 0xFFB8,
318         /// <summary>
319         /// The Numpad 9 key
320         /// </summary>
321         KP9 = 0xFFB9,
322
323         /* Auxilliary Functions */
324         /// <summary>
325         /// The function 1 key
326         /// </summary>
327         F1 = 0xFFBE,
328         /// <summary>
329         /// The function 2 key
330         /// </summary>
331         F2 = 0xFFBF,
332         /// <summary>
333         /// The function 3 key
334         /// </summary>
335         F3 = 0xFFC0,
336         /// <summary>
337         /// The function 4 key
338         /// </summary>
339         F4 = 0xFFC1,
340         /// <summary>
341         /// The function 5 key
342         /// </summary>
343         F5 = 0xFFC2,
344         /// <summary>
345         /// The function 6 key
346         /// </summary>
347         F6 = 0xFFC3,
348         /// <summary>
349         /// The function 7 key
350         /// </summary>
351         F7 = 0xFFC4,
352         /// <summary>
353         /// The function 8 key
354         /// </summary>
355         F8 = 0xFFC5,
356         /// <summary>
357         /// The function 9 key
358         /// </summary>
359         F9 = 0xFFC6,
360         /// <summary>
361         /// The function 10 key
362         /// </summary>
363         F10 = 0xFFC7,
364         /// <summary>
365         /// The function 11 key
366         /// </summary>
367         F11 = 0xFFC8,
368         /// <summary>
369         /// The function 12 key
370         /// </summary>
371         F12 = 0xFFC9,
372         /// <summary>
373         /// The function 13 key
374         /// </summary>
375         F13 = 0xFFCA,
376         /// <summary>
377         /// The function 14 key
378         /// </summary>
379         F14 = 0xFFCB,
380         /// <summary>
381         /// The function 15 key
382         /// </summary>
383         F15 = 0xFFCC,
384         /// <summary>
385         /// The function 16 key
386         /// </summary>
387         F16 = 0xFFCD,
388         /// <summary>
389         /// The function 17 key
390         /// </summary>
391         F17 = 0xFFCE,
392         /// <summary>
393         /// The function 18 key
394         /// </summary>
395         F18 = 0xFFCF,
396         /// <summary>
397         /// The function 19 key
398         /// </summary>
399         F19 = 0xFFD0,
400         /// <summary>
401         /// The function 20 key
402         /// </summary>
403         F20 = 0xFFD1,
404         /// <summary>
405         /// The function 21 key
406         /// </summary>
407         F21 = 0xFFD2,
408         /// <summary>
409         /// The function 22 key
410         /// </summary>
411         F22 = 0xFFD3,
412         /// <summary>
413         /// The function 23 key
414         /// </summary>
415         F23 = 0xFFD4,
416         /// <summary>
417         /// The function 24 key
418         /// </summary>
419         F24 = 0xFFD5,
420         /// <summary>
421         /// The function 25 key
422         /// </summary>
423         F25 = 0xFFD6,
424         /// <summary>
425         /// The function 26 key
426         /// </summary>
427         F26 = 0xFFD7,
428         /// <summary>
429         /// The function 27 key
430         /// </summary>
431         F27 = 0xFFD8,
432         /// <summary>
433         /// The function 28 key
434         /// </summary>
435         F28 = 0xFFD9,
436         /// <summary>
437         /// The function 29 key
438         /// </summary>
439         F29 = 0xFFDA,
440         /// <summary>
441         /// The function 30 key
442         /// </summary>
443         F30 = 0xFFDB,
444         /// <summary>
445         /// The function 31 key
446         /// </summary>
447         F31 = 0xFFDC,
448         /// <summary>
449         /// The function 32 key
450         /// </summary>
451         F32 = 0xFFDD,
452         /// <summary>
453         /// The function 33 key
454         /// </summary>
455         F33 = 0xFFDE,
456         /// <summary>
457         /// The function 34 key
458         /// </summary>
459         F34 = 0xFFDF,
460         /// <summary>
461         /// The function 35 key
462         /// </summary>
463         F35 = 0xFFE0,
464
465         /* Modifier keys */
466         /// <summary>
467         /// The left shift key
468         /// </summary>
469         ShiftL = 0xFFE1,
470         /// <summary>
471         /// The right shift key
472         /// </summary>
473         ShiftR = 0xFFE2,
474         /// <summary>
475         /// The left control key
476         /// </summary>
477         ControlL = 0xFFE3,
478         /// <summary>
479         /// The right control key
480         /// </summary>
481         ControlR = 0xFFE4,
482         /// <summary>
483         /// The caps lock key
484         /// </summary>
485         CapsLock = 0xFFE5,
486         /// <summary>
487         /// The shift lock key
488         /// </summary>
489         ShiftLock = 0xFFE6,
490         /// <summary>
491         /// The left meta key
492         /// </summary>
493         MetaL = 0xFFE7,
494         /// <summary>
495         /// The right meta key
496         /// </summary>
497         MetaR = 0xFFE8,
498         /// <summary>
499         /// The left alt key
500         /// </summary>
501         AltL = 0xFFE9,
502         /// <summary>
503         /// The right alt key
504         /// </summary>
505         AltR = 0xFFEA,
506         /// <summary>
507         /// The left super key
508         /// </summary>
509         SuperL = 0xFFEB,
510         /// <summary>
511         /// The right super key
512         /// </summary>
513         SuperR = 0xFFEC,
514         /// <summary>
515         /// The left hyper key
516         /// </summary>
517         HyperL = 0xFFED,
518         /// <summary>
519         /// The right hyper key
520         /// </summary>
521         HyperR = 0xFFEE,
522
523         /* Latin 1 */
524         /// <summary>
525         /// The space key
526         /// </summary>
527         Space = 0x020,
528         /// <summary>
529         /// The exclamation key
530         /// </summary>
531         Exclam = 0x021,
532         /// <summary>
533         /// The quotedbl key
534         /// </summary>
535         Quotedbl = 0x022,
536         /// <summary>
537         /// The number sign key
538         /// </summary>
539         NumberSign = 0x023,
540         /// <summary>
541         /// The dollar key
542         /// </summary>
543         Dollar = 0x024,
544         /// <summary>
545         /// The percent key
546         /// </summary>
547         Percent = 0x025,
548         /// <summary>
549         /// The ampersand key
550         /// </summary>
551         Ampersand = 0x026,
552         /// <summary>
553         /// The apostrophe key
554         /// </summary>
555         Apostrophe = 0x027,
556         /// <summary>
557         /// The parenleft key
558         /// </summary>
559         Parenleft = 0x028,
560         /// <summary>
561         /// The parenright key
562         /// </summary>
563         Parenright = 0x029,
564         /// <summary>
565         /// The asterisk key
566         /// </summary>
567         Asterisk = 0x02a,
568         /// <summary>
569         /// The plus key
570         /// </summary>
571         Plus = 0x02b,
572         /// <summary>
573         /// The comma key
574         /// </summary>
575         Comma = 0x02c,
576         /// <summary>
577         /// The minus key
578         /// </summary>
579         Minus = 0x02d,
580         /// <summary>
581         /// The period key
582         /// </summary>
583         Period = 0x02e,
584         /// <summary>
585         /// The slash key
586         /// </summary>
587         Slash = 0x02f,
588         /// <summary>
589         /// The 0 key
590         /// </summary>
591         Keypad0 = 0x030,
592         /// <summary>
593         /// The 1 key
594         /// </summary>
595         Keypad1 = 0x031,
596         /// <summary>
597         /// The 2 key
598         /// </summary>
599         Keypad2 = 0x032,
600         /// <summary>
601         /// The 3 key
602         /// </summary>
603         Keypad3 = 0x033,
604         /// <summary>
605         /// The 4 key
606         /// </summary>
607         Keypad4 = 0x034,
608         /// <summary>
609         /// The 5 key
610         /// </summary>
611         Keypad5 = 0x035,
612         /// <summary>
613         /// The 6 key
614         /// </summary>
615         Keypad6 = 0x036,
616         /// <summary>
617         /// The 7 key
618         /// </summary>
619         Keypad7 = 0x037,
620         /// <summary>
621         /// The 8 key
622         /// </summary>
623         Keypad8 = 0x038,
624         /// <summary>
625         /// The 9 key
626         /// </summary>
627         Keypad9 = 0x039,
628         /// <summary>
629         /// The colon key
630         /// </summary>
631         Colon = 0x03a,
632         /// <summary>
633         /// The semicolon key
634         /// </summary>
635         Semicolon = 0x03b,
636         /// <summary>
637         /// The less key
638         /// </summary>
639         Less = 0x03c,
640         /// <summary>
641         /// The equal key
642         /// </summary>
643         Equal = 0x03d,
644         /// <summary>
645         /// The greater key
646         /// </summary>
647         Greater = 0x03e,
648         /// <summary>
649         /// The question key
650         /// </summary>
651         Question = 0x03f,
652         /// <summary>
653         /// The at key
654         /// </summary>
655         At = 0x040,
656         /// <summary>
657         /// The A key
658         /// </summary>
659         KeypadA = 0x041,
660         /// <summary>
661         /// The B key
662         /// </summary>
663         KeypadB = 0x042,
664         /// <summary>
665         /// The C key
666         /// </summary>
667         KeypadC = 0x043,
668         /// <summary>
669         /// The D key
670         /// </summary>
671         KeypadD = 0x044,
672         /// <summary>
673         /// The E key
674         /// </summary>
675         KeypadE = 0x045,
676         /// <summary>
677         /// The F key
678         /// </summary>
679         KeypadF = 0x046,
680         /// <summary>
681         /// The G key
682         /// </summary>
683         KeypadG = 0x047,
684         /// <summary>
685         /// The H key
686         /// </summary>
687         KeypadH = 0x048,
688         /// <summary>
689         /// The I key
690         /// </summary>
691         KeypadI = 0x049,
692         /// <summary>
693         /// The J key
694         /// </summary>
695         KeypadJ = 0x04a,
696         /// <summary>
697         /// The K key
698         /// </summary>
699         KeypadK = 0x04b,
700         /// <summary>
701         /// The L key
702         /// </summary>
703         KeypadL = 0x04c,
704         /// <summary>
705         /// The M key
706         /// </summary>
707         KeypadM = 0x04d,
708         /// <summary>
709         /// The N key
710         /// </summary>
711         KeypadN = 0x04e,
712         /// <summary>
713         /// The O key
714         /// </summary>
715         KeypadO = 0x04f,
716         /// <summary>
717         /// The P key
718         /// </summary>
719         KeypadP = 0x050,
720         /// <summary>
721         /// The Q key
722         /// </summary>
723         KeypadQ = 0x051,
724         /// <summary>
725         /// The R key
726         /// </summary>
727         KeypadR = 0x052,
728         /// <summary>
729         /// The S key
730         /// </summary>
731         KeypadS = 0x053,
732         /// <summary>
733         /// The T key
734         /// </summary>
735         KeypadT = 0x054,
736         /// <summary>
737         /// The U key
738         /// </summary>
739         KeypadU = 0x055,
740         /// <summary>
741         /// The V key
742         /// </summary>
743         KeypadV = 0x056,
744         /// <summary>
745         /// The W key
746         /// </summary>
747         KeypadW = 0x057,
748         /// <summary>
749         /// The X key
750         /// </summary>
751         KeypadX = 0x058,
752         /// <summary>
753         /// The Y key
754         /// </summary>
755         KeypadY = 0x059,
756         /// <summary>
757         /// The Z key
758         /// </summary>
759         KeypadZ = 0x05a,
760         /// <summary>
761         /// The left bracket key
762         /// </summary>
763         BracketLeft = 0x05b,
764         /// <summary>
765         /// The backslash key
766         /// </summary>
767         Backslash = 0x05c,
768         /// <summary>
769         /// The right bracket key
770         /// </summary>
771         BracketRight = 0x05d,
772         /// <summary>
773         /// The circumflex key
774         /// </summary>
775         AsciiCircum = 0x05e,
776         /// <summary>
777         /// The underscore key
778         /// </summary>
779         Underscore = 0x05f,
780         /// <summary>
781         /// The grave key
782         /// </summary>
783         Grave = 0x060,
784         /// <summary>
785         /// The a key
786         /// </summary>
787         Keypada = 0x061,
788         /// <summary>
789         /// The b key
790         /// </summary>
791         Keypadb = 0x062,
792         /// <summary>
793         /// The c key
794         /// </summary>
795         Keypadc = 0x063,
796         /// <summary>
797         /// The d key
798         /// </summary>
799         Keypadd = 0x064,
800         /// <summary>
801         /// The e key
802         /// </summary>
803         Keypade = 0x065,
804         /// <summary>
805         /// The f key
806         /// </summary>
807         Keypadf = 0x066,
808         /// <summary>
809         /// The g key
810         /// </summary>
811         Keypadg = 0x067,
812         /// <summary>
813         /// The h key
814         /// </summary>
815         Keypadh = 0x068,
816         /// <summary>
817         /// The i key
818         /// </summary>
819         Keypadi = 0x069,
820         /// <summary>
821         /// The j key
822         /// </summary>
823         Keypadj = 0x06a,
824         /// <summary>
825         /// The k key
826         /// </summary>
827         Keypadk = 0x06b,
828         /// <summary>
829         /// The l key
830         /// </summary>
831         Keypadl = 0x06c,
832         /// <summary>
833         /// The m key
834         /// </summary>
835         Keypadm = 0x06d,
836         /// <summary>
837         /// The n key
838         /// </summary>
839         Keypadn = 0x06e,
840         /// <summary>
841         /// The o key
842         /// </summary>
843         Keypado = 0x06f,
844         /// <summary>
845         /// The p key
846         /// </summary>
847         Keypadp = 0x070,
848         /// <summary>
849         /// The q key
850         /// </summary>
851         Keypadq = 0x071,
852         /// <summary>
853         /// The r key
854         /// </summary>
855         Keypadr = 0x072,
856         /// <summary>
857         /// The s key
858         /// </summary>
859         Keypads = 0x073,
860         /// <summary>
861         /// The t key
862         /// </summary>
863         Keypadt = 0x074,
864         /// <summary>
865         /// The u key
866         /// </summary>
867         Keypadu = 0x075,
868         /// <summary>
869         /// The v key
870         /// </summary>
871         Keypadv = 0x076,
872         /// <summary>
873         /// The w key
874         /// </summary>
875         Keypadw = 0x077,
876         /// <summary>
877         /// The x key
878         /// </summary>
879         Keypadx = 0x078,
880         /// <summary>
881         /// The y key
882         /// </summary>
883         Keypady = 0x079,
884         /// <summary>
885         /// The z key
886         /// </summary>
887         Keypadz = 0x07a,
888         /// <summary>
889         /// The left brace key
890         /// </summary>
891         BraceLeft = 0x07b,
892         /// <summary>
893         /// The bar key
894         /// </summary>
895         Bar = 0x07c,
896         /// <summary>
897         /// The right brace key
898         /// </summary>
899         BraceRight = 0x07d,
900         /// <summary>
901         /// The tilde key
902         /// </summary>
903         AsciiTilde = 0x07e,
904     };
905
906     /// <summary>
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.
909     /// </summary>
910     public enum KeyMask
911     {
912         /// <summary>
913         /// Key press event without modifier key
914         /// </summary>
915         Pressed = 0,
916         /// <summary>
917         /// The Shift key is pressed down
918         /// </summary>
919         Shift = (1 << 0),
920         /// <summary>
921         /// The CapsLock key is pressed down
922         /// </summary>
923         CapsLock = (1 << 1),
924         /// <summary>
925         /// The Control key is pressed down
926         /// </summary>
927         Control = (1 << 2),
928         /// <summary>
929         /// The Alt key is pressed down
930         /// </summary>
931         Alt = (1 << 3),
932         /// <summary>
933         /// The Meta key is pressed down
934         /// </summary>
935         Meta = (1 << 4),
936         /// <summary>
937         /// The Win (between Control and Alt) is pressed down
938         /// </summary>
939         Win = (1 << 5),
940         /// <summary>
941         /// The Hyper key is pressed down
942         /// </summary>
943         Hyper = (1 << 6),
944         /// <summary>
945         /// The NumLock key is pressed down
946         /// </summary>
947         NumLock = (1 << 7),
948         /// <summary>
949         /// Key release event
950         /// </summary>
951         Released = (1 << 15),
952     }
953
954     /// <summary>
955     /// This class contains api's related to IME(Input method editor)
956     /// </summary>
957     public static class InputMethodEditor
958     {
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) =>
1000         {
1001             Log.Info(LogTag, "In Create Delegate");
1002             _userCreate?.Invoke();
1003         };
1004         private static ImeTerminateCb _terminate = (IntPtr userData) =>
1005         {
1006             Log.Info(LogTag, "In terminate Delegate");
1007             _userTerminate?.Invoke();
1008             _imeCallbackStructGCHandle.Dispose();
1009         };
1010         private static ImeShowCb _show = (int contextId, IntPtr context, IntPtr userData) =>
1011         {
1012             Log.Info(LogTag, "In Show Delegate");
1013             _userShow?.Invoke(new ContextId(contextId), new InputMethodContext(context));
1014         };
1015         private static ImeHideCb _hide = (int contextId, IntPtr userData) =>
1016         {
1017             Log.Info(LogTag, "In Hide Delegate");
1018             _userHide?.Invoke(new ContextId(contextId));
1019         };
1020
1021         /// <summary>
1022         /// Structure representing ContextId
1023         /// </summary>
1024         public struct ContextId : IEquatable<ContextId>
1025         {
1026             internal ContextId(int id)
1027             {
1028                 Id = id;
1029             }
1030
1031             internal int Id
1032             {
1033                 get;
1034                 private set;
1035             }
1036
1037             public bool Equals(ContextId other)
1038             {
1039                 return this.Id == other.Id;
1040             }
1041         }
1042
1043         /// <summary>
1044         /// rectangle representing the position and size of UI Control
1045         /// </summary>
1046         public struct Rect
1047         {
1048             /// <summary>
1049             /// The x position in screen
1050             /// </summary>
1051             public int x;
1052
1053             /// <summary>
1054             /// The y position in screen
1055             /// </summary>
1056             public int y;
1057
1058             /// <summary>
1059             /// The window width
1060             /// </summary>
1061             public int w;
1062
1063             /// <summary>
1064             /// The window height
1065             /// </summary>
1066             public int h;
1067         }
1068
1069         /// <summary>
1070         /// An Action with 1 out parameter
1071         /// </summary>
1072         /// <typeparam name="T">Generic Type</typeparam>
1073         /// <param name="a">The out parameter</param>
1074         public delegate void OutAction<T>(out T a);
1075
1076         /// <summary>
1077         /// An Action with an array out parameter
1078         /// </summary>
1079         /// <typeparam name="T">Generic Type</typeparam>
1080         /// <param name="a">The out parameter 1</param>
1081         public delegate void OutArrayAction<T>(out T[] a);
1082
1083         /// <summary>
1084         /// An Action with 3 Input Parameter returning a bool
1085         /// </summary>
1086         /// <typeparam name="T">Generic Type for Parameter 1</typeparam>
1087         /// <typeparam name="T1">Generic Type for Parameter 2</typeparam>
1088         /// <typeparam name="T2">Generic Type for Parameter 3</typeparam>
1089         /// <param name="a">The Input Parameter 1</param>
1090         /// <param name="b">The Input Parameter 2</param>
1091         /// <param name="c">The Input Parameter 3</param>
1092         /// <returns></returns>
1093         public delegate bool BoolAction<T, T1, T2>(T a, T1 b, T2 c);
1094
1095         /// <summary>
1096         /// Called when an associated text input UI control has focus.
1097         /// </summary>
1098         public static event EventHandler<FocusedInEventArgs> FocusedIn
1099         {
1100             add
1101             {
1102                 lock (thisLock)
1103                 {
1104                     _imeFocusedInDelegate = (int contextId, IntPtr userData) =>
1105                     {
1106                         FocusedInEventArgs args = new FocusedInEventArgs(contextId);
1107                         _focusIn?.Invoke(null, args);
1108                     };
1109                     ErrorCode error = ImeEventSetFocusedInCb(_imeFocusedInDelegate, IntPtr.Zero);
1110                     if (error != ErrorCode.None)
1111                     {
1112                         Log.Error(LogTag, "Add FocusedIn Failed with error " + error);
1113                     }
1114                     else
1115                     {
1116                         _focusIn += value;
1117                     }
1118                 }
1119             }
1120             remove
1121             {
1122                 lock (thisLock)
1123                 {
1124                     _focusIn -= value;
1125                 }
1126             }
1127         }
1128
1129         /// <summary>
1130         /// Called when an associated text input UI control loses focus.
1131         /// </summary>
1132         public static event EventHandler<FocusedOutEventArgs> FocusedOut
1133         {
1134             add
1135             {
1136                 lock (thisLock)
1137                 {
1138                     _imeFocusedOutDelegate = (int contextId, IntPtr userData) =>
1139                     {
1140                         FocusedOutEventArgs args = new FocusedOutEventArgs(contextId);
1141                         _focusOut?.Invoke(null, args);
1142                     };
1143                     ErrorCode error = ImeEventSetFocusedOutCb(_imeFocusedOutDelegate, IntPtr.Zero);
1144                     if (error != ErrorCode.None)
1145                     {
1146                         Log.Error(LogTag, "Add FocusedOut Failed with error " + error);
1147                     }
1148                     else
1149                     {
1150                         _focusOut += value;
1151                     }
1152                 }
1153             }
1154             remove
1155             {
1156                 lock (thisLock)
1157                 {
1158                     _focusOut -= value;
1159                 }
1160             }
1161         }
1162
1163         /// <summary>
1164         /// Called when an associated text input UI control responds to a request with the surrounding text.
1165         /// </summary>
1166         public static event EventHandler<SurroundingTextUpdatedEventArgs> SurroundingTextUpdated
1167         {
1168             add
1169             {
1170                 lock (thisLock)
1171                 {
1172                     _imeSurroundingTextUpdatedDelegate = (int contextId, IntPtr text, int cursorPos, IntPtr userData) =>
1173                     {
1174                         SurroundingTextUpdatedEventArgs args = new SurroundingTextUpdatedEventArgs(contextId, Marshal.PtrToStringAnsi(text), cursorPos);
1175                         _surroundingTextUpdated?.Invoke(null, args);
1176                     };
1177                     ErrorCode error = ImeEventSetSurroundingTextUpdatedCb(_imeSurroundingTextUpdatedDelegate, IntPtr.Zero);
1178                     if (error != ErrorCode.None)
1179                     {
1180                         Log.Error(LogTag, "Add SurroundingTextUpdated Failed with error " + error);
1181                     }
1182                     else
1183                     {
1184                         _surroundingTextUpdated += value;
1185                     }
1186                 }
1187             }
1188             remove
1189             {
1190                 lock (thisLock)
1191                 {
1192                     _surroundingTextUpdated -= value;
1193                 }
1194             }
1195         }
1196
1197         /// <summary>
1198         /// Called to reset the input context of an associated text input UI control.
1199         /// </summary>
1200         public static event EventHandler<EventArgs> InputContextReset
1201         {
1202             add
1203             {
1204                 lock (thisLock)
1205                 {
1206                     _imeInputContextResetDelegate = (IntPtr userData) =>
1207                     {
1208                         _inputContextReset?.Invoke(null, EventArgs.Empty);
1209                     };
1210                     ErrorCode error = ImeEventSetInputContextResetCb(_imeInputContextResetDelegate, IntPtr.Zero);
1211                     if (error != ErrorCode.None)
1212                     {
1213                         Log.Error(LogTag, "Add InputContextReset Failed with error " + error);
1214                     }
1215                     else
1216                     {
1217                         _inputContextReset += value;
1218                     }
1219                 }
1220             }
1221             remove
1222             {
1223                 lock (thisLock)
1224                 {
1225                     _inputContextReset -= value;
1226                 }
1227             }
1228         }
1229
1230         /// <summary>
1231         /// Called when the position of the cursor in an associated text input UI control changes.
1232         /// </summary>
1233         public static event EventHandler<CursorPositionUpdatedEventArgs> CursorPositionUpdated
1234         {
1235             add
1236             {
1237                 lock (thisLock)
1238                 {
1239                     _imeCursorPositionUpdatedDelegate = (int cursorPos, IntPtr userData) =>
1240                     {
1241                         CursorPositionUpdatedEventArgs args = new CursorPositionUpdatedEventArgs(cursorPos);
1242                         _cursorPositionUpdated?.Invoke(null, args);
1243                     };
1244                     ErrorCode error = ImeEventSetCursorPositionUpdatedCb(_imeCursorPositionUpdatedDelegate, IntPtr.Zero);
1245                     if (error != ErrorCode.None)
1246                     {
1247                         Log.Error(LogTag, "Add CursorPositionUpdated Failed with error " + error);
1248                     }
1249                     else
1250                     {
1251                         _cursorPositionUpdated += value;
1252                     }
1253                 }
1254             }
1255             remove
1256             {
1257                 lock (thisLock)
1258                 {
1259                     _cursorPositionUpdated -= value;
1260                 }
1261             }
1262         }
1263
1264         /// <summary>
1265         /// Called to set the preferred language to the input panel.
1266         /// It will be only called when the client application changes the edit field's language attribute after the input panel is shown.
1267         /// </summary>
1268         public static event EventHandler<LanguageSetEventArgs> LanguageSet
1269         {
1270             add
1271             {
1272                 lock (thisLock)
1273                 {
1274                     _imeLanguageSetDelegate = (InputPanelLanguage language, IntPtr userData) =>
1275                     {
1276                         LanguageSetEventArgs args = new LanguageSetEventArgs(language);
1277                         _langaugeSet?.Invoke(null, args);
1278                     };
1279                     ErrorCode error = ImeEventSetLanguageSetCb(_imeLanguageSetDelegate, IntPtr.Zero);
1280                     if (error != ErrorCode.None)
1281                     {
1282                         Log.Error(LogTag, "Add LanguageSet Failed with error " + error);
1283                     }
1284                     else
1285                     {
1286                         _langaugeSet += value;
1287                     }
1288                 }
1289             }
1290             remove
1291             {
1292                 lock (thisLock)
1293                 {
1294                     _langaugeSet -= value;
1295                 }
1296             }
1297         }
1298
1299         /// <summary>
1300         /// Called to set the application specific data to deliver to the input panel.
1301         /// </summary>
1302         public static event EventHandler<SetDataEventArgs> DataSet
1303         {
1304             add
1305             {
1306                 lock (thisLock)
1307                 {
1308                     _imeDataSetDelegate = (IntPtr data, uint dataLength, IntPtr userData) =>
1309                     {
1310                         byte[] destination = new byte[dataLength];
1311                         Marshal.Copy(data, destination, 0, (int)dataLength);
1312                         SetDataEventArgs args = new SetDataEventArgs(destination, dataLength);
1313                         _imDataSet?.Invoke(null, args);
1314                     };
1315                     ErrorCode error = ImeEventSetImdataSetCb(_imeDataSetDelegate, IntPtr.Zero);
1316                     if (error != ErrorCode.None)
1317                     {
1318                         Log.Error(LogTag, "Add DataSet Failed with error " + error);
1319                     }
1320                     else
1321                     {
1322                         _imDataSet += value;
1323                     }
1324                 }
1325             }
1326             remove
1327             {
1328                 lock (thisLock)
1329                 {
1330                     _imDataSet -= value;
1331                 }
1332             }
1333         }
1334
1335         /// <summary>
1336         /// Called when an associated text input UI control requests the input panel to set its layout.
1337         /// It will be only called when the client application changes the edit field's layout attribute after the input panel is shown.
1338         /// </summary>
1339         public static event EventHandler<LayoutSetEventArgs> LayoutSet
1340         {
1341             add
1342             {
1343                 lock (thisLock)
1344                 {
1345                     _imeLayoutSetDelegate = (InputPanelLayout layout, IntPtr userData) =>
1346                     {
1347                         LayoutSetEventArgs args = new LayoutSetEventArgs(layout);
1348                         _layoutSet?.Invoke(null, args);
1349                     };
1350                     ErrorCode error = ImeEventSetLayoutSetCb(_imeLayoutSetDelegate, IntPtr.Zero);
1351                     if (error != ErrorCode.None)
1352                     {
1353                         Log.Error(LogTag, "Add LayoutSet Failed with error " + error);
1354                     }
1355                     else
1356                     {
1357                         _layoutSet += value;
1358                     }
1359                 }
1360             }
1361             remove
1362             {
1363                 lock (thisLock)
1364                 {
1365                     _layoutSet -= value;
1366                 }
1367             }
1368         }
1369
1370         /// <summary>
1371         /// Called when an associated text input UI control requests the input panel to set the Return key label.
1372         /// The input panel can show text or image on the Return button according to the Return key action.
1373         /// </summary>
1374         public static event EventHandler<ReturnKeySetEventArgs> ReturnKeySet
1375         {
1376             add
1377             {
1378                 lock (thisLock)
1379                 {
1380                     _imeReturnKeySetDelegate = (InputPanelReturnKey type, IntPtr userData) =>
1381                     {
1382                         ReturnKeySetEventArgs args = new ReturnKeySetEventArgs(type);
1383                         _returnKeyTypeSet?.Invoke(null, args);
1384                     };
1385                     ErrorCode error = ImeEventSetReturnKeySetCb(_imeReturnKeySetDelegate, IntPtr.Zero);
1386                     if (error != ErrorCode.None)
1387                     {
1388                         Log.Error(LogTag, "Add ReturnKeySet Failed with error " + error);
1389                     }
1390                     else
1391                     {
1392                         _returnKeyTypeSet += value;
1393                     }
1394                 }
1395             }
1396             remove
1397             {
1398                 lock (thisLock)
1399                 {
1400                     _returnKeyTypeSet -= value;
1401                 }
1402             }
1403         }
1404
1405         /// <summary>
1406         /// Called when an associated text input UI control requests the input panel to enable or disable the Return key state.
1407         /// </summary>
1408         public static event EventHandler<ReturnKeyStateSetEventArgs> ReturnKeyStateSet
1409         {
1410             add
1411             {
1412                 lock (thisLock)
1413                 {
1414                     _imeReturnKeyStateSetDelegate = (bool state, IntPtr userData) =>
1415                     {
1416                         ReturnKeyStateSetEventArgs args = new ReturnKeyStateSetEventArgs(state);
1417                         _returnKeyStateSet?.Invoke(null, args);
1418                     };
1419                     ErrorCode error = ImeEventSetReturnKeyStateSetCb(_imeReturnKeyStateSetDelegate, IntPtr.Zero);
1420                     if (error != ErrorCode.None)
1421                     {
1422                         Log.Error(LogTag, "Add ReturnKeyStateSet Failed with error " + error);
1423                     }
1424                     else
1425                     {
1426                         _returnKeyStateSet += value;
1427                     }
1428                 }
1429             }
1430             remove
1431             {
1432                 lock (thisLock)
1433                 {
1434                     _returnKeyStateSet -= value;
1435                 }
1436             }
1437         }
1438
1439         /// <summary>
1440         /// Called when the system display Language is changed.
1441         /// </summary>
1442         public static event EventHandler<DisplayLanguageChangedEventArgs> DisplayLanguageChanged
1443         {
1444             add
1445             {
1446                 lock (thisLock)
1447                 {
1448                     _imeDisplayLanguageChangedDelegate = (IntPtr language, IntPtr userData) =>
1449                     {
1450                         DisplayLanguageChangedEventArgs args = new DisplayLanguageChangedEventArgs(Marshal.PtrToStringAnsi(language));
1451                         _displayLanguageChanged?.Invoke(null, args);
1452                     };
1453                     ErrorCode error = ImeEventSetDisplayLanguageChangedCb(_imeDisplayLanguageChangedDelegate, IntPtr.Zero);
1454                     if (error != ErrorCode.None)
1455                     {
1456                         Log.Error(LogTag, "Add DisplayLanguageChanged Failed with error " + error);
1457                     }
1458                     else
1459                     {
1460                         _displayLanguageChanged += value;
1461                     }
1462                 }
1463             }
1464             remove
1465             {
1466                 lock (thisLock)
1467                 {
1468                     _displayLanguageChanged -= value;
1469                 }
1470             }
1471         }
1472
1473         /// <summary>
1474         /// Called when the device is rotated.
1475         /// </summary>
1476         public static event EventHandler<RotationChangedEventArgs> RotationChanged
1477         {
1478             add
1479             {
1480                 lock (thisLock)
1481                 {
1482                     _imeRotationChangedDelegate = (int degree, IntPtr userData) =>
1483                     {
1484                         RotationChangedEventArgs args = new RotationChangedEventArgs(degree);
1485                         _rotationDegreeChanged?.Invoke(null, args);
1486                     };
1487                     ErrorCode error = ImeEventSetRotationChangedCb(_imeRotationChangedDelegate, IntPtr.Zero);
1488                     if (error != ErrorCode.None)
1489                     {
1490                         Log.Error(LogTag, "Add RotationChanged Failed with error " + error);
1491                     }
1492                     else
1493                     {
1494                         _rotationDegreeChanged += value;
1495                     }
1496                 }
1497             }
1498             remove
1499             {
1500                 lock (thisLock)
1501                 {
1502                     _rotationDegreeChanged -= value;
1503                 }
1504             }
1505         }
1506
1507         /// <summary>
1508         /// Called when Accessibility in Settings application is on or off.
1509         /// </summary>
1510         public static event EventHandler<AccessibilityStateChangedEventArgs> AccessibilityStateChanged
1511         {
1512             add
1513             {
1514                 lock (thisLock)
1515                 {
1516                     _imeAccessibilityStateChangedDelegate = (bool state, IntPtr userData) =>
1517                     {
1518                         AccessibilityStateChangedEventArgs args = new AccessibilityStateChangedEventArgs(state);
1519                         _accessibilityStateChanged?.Invoke(null, args);
1520                     };
1521                     ErrorCode error = ImeEventSetAccessibilityStateChangedCb(_imeAccessibilityStateChangedDelegate, IntPtr.Zero);
1522                     if (error != ErrorCode.None)
1523                     {
1524                         Log.Error(LogTag, "Add AccessibilityStateChanged Failed with error " + error);
1525                     }
1526                     else
1527                     {
1528                         _accessibilityStateChanged += value;
1529                     }
1530                 }
1531             }
1532             remove
1533             {
1534                 lock (thisLock)
1535                 {
1536                     _accessibilityStateChanged -= value;
1537                 }
1538             }
1539         }
1540
1541         /// <summary>
1542         /// Sets the languageRequested Action
1543         /// </summary>
1544         /// <param name="languageRequested">
1545         /// Called when an associated text input UI control requests the language from the input panel, requesting for language code.
1546         /// </param>
1547         public static void SetLanguageRequestedCallback(OutAction<string> languageRequested)
1548         {
1549             _imeLanguageRequestedDelegate = (IntPtr userData, out IntPtr langCode) =>
1550             {
1551                 string langauage;
1552                 _languageRequestedDelegate(out langauage);
1553                 char[] languageArray = langauage.ToCharArray();
1554                 langCode = new IntPtr();
1555                 Marshal.Copy(languageArray, 0, langCode, languageArray.Length);
1556             };
1557             ErrorCode error = ImeEventSetLanguageRequestedCallbackCb(_imeLanguageRequestedDelegate, IntPtr.Zero);
1558             if (error != ErrorCode.None)
1559             {
1560                 Log.Error(LogTag, "Add SetLanguageRequestedCallback Failed with error " + error);
1561             }
1562             _languageRequestedDelegate = languageRequested;
1563         }
1564
1565         /// <summary>
1566         /// Sets the processKey Action
1567         /// If the key event is from the external device, DeviceInfo will have its name, class and subclass information.
1568         /// </summary>
1569         /// <param name="processKey">
1570         /// The Action is alled when the key event is received from the external devices or SendKey function.
1571         /// This Event processes the key event before an associated text input UI control does.
1572         /// </param>
1573         public static void SetProcessKeyCallback(BoolAction<KeyCode, KeyMask, InputMethodDeviceInformation> processKey)
1574         {
1575             _imeProcessKeyDelegate = (KeyCode keyCode, KeyMask keyMask, IntPtr devInfo, IntPtr userData) =>
1576             {
1577                 return _processKeyDelagate(keyCode, keyMask, new InputMethodDeviceInformation(devInfo));
1578             };
1579             ErrorCode error = ImeEventSetProcessKeyEventCb(_imeProcessKeyDelegate, IntPtr.Zero);
1580             if (error != ErrorCode.None)
1581             {
1582                 Log.Error(LogTag, "Add ProcessKey Failed with error " + error);
1583             }
1584             _processKeyDelagate = processKey;
1585         }
1586
1587         /// <summary>
1588         /// Sets the imDataRequested Action
1589         /// </summary>
1590         /// <param name="imDataRequested">
1591         /// Called when an associated text input UI control requests the application specific data from the input panel, requesting for data array and it's length.
1592         /// </param>
1593         public static void SetDataRequestedCallback(OutArrayAction<byte> imDataRequested)
1594         {
1595             _imeImDataRequestedDelegate = (IntPtr userData, out IntPtr data, out uint dataLength) =>
1596             {
1597                 byte[] dataArr;
1598                 _imDataRequestedDelegate(out dataArr);
1599                 data = new IntPtr();
1600                 Marshal.Copy(dataArr, 0, data, dataArr.Length);
1601                 dataLength = (uint)dataArr.Length;
1602             };
1603             ErrorCode error = ImeEventSetImdataRequestedCb(_imeImDataRequestedDelegate, IntPtr.Zero);
1604             if (error != ErrorCode.None)
1605             {
1606                 Log.Error(LogTag, "Add SetDataRequestedCallback Failed with error " + error);
1607             }
1608             _imDataRequestedDelegate = imDataRequested;
1609         }
1610
1611         /// <summary>
1612         /// Sets the GeometryRequested Action
1613         /// </summary>
1614         /// <param name="geometryRequested">
1615         /// Called when an associated text input UI control requests the position and size from the input panel, requesting for x,y,w,h values.
1616         /// </param>
1617         public static void SetGeometryRequestedCallback(OutAction<Rect> geometryRequested)
1618         {
1619             _imeGeometryRequestedDelegate = (IntPtr userData, out int x, out int y, out int w, out int h) =>
1620             {
1621                 Rect rect = new Rect();
1622                 _geometryRequestedDelegate(out rect);
1623                 x = rect.x;
1624                 y = rect.y;
1625                 w = rect.w;
1626                 h = rect.h;
1627             };
1628             ErrorCode error = ImeEventSetGeometryRequestedCallbackCb(_imeGeometryRequestedDelegate, IntPtr.Zero);
1629             if (error != ErrorCode.None)
1630             {
1631                 Log.Error(LogTag, "Add SetGeometryRequestedCallback Failed with error " + error);
1632             }
1633             _geometryRequestedDelegate = geometryRequested;
1634         }
1635
1636         /// <summary>
1637         /// Runs the main loop of IME application.
1638         /// This function starts to run IME application's main loop.
1639         /// </summary>
1640         /// <privilege>
1641         /// http://tizen.org/privilege/ime
1642         /// </privilege>
1643         /// <remarks>
1644         /// This API is a blocking call, as it starts the main loop of the application.
1645         /// </remarks>
1646         /// <param name="create">This is called to initialize IME application before the main loop starts up</param>
1647         /// <param name="terminate">This is called when IME application is terminated</param>
1648         /// <param name="show">
1649         /// This is called when IME application is shown
1650         /// It provides the Context Inofrmation and the Context Id
1651         /// </param>
1652         /// <param name="hide">
1653         /// This is called when IME application is hidden
1654         /// It provides the Context Id
1655         /// </param>
1656         /// <exception cref="InvalidOperationException">
1657         /// This can occur due to the following reasons:
1658         /// 1) The application does not have the privilege to call this function
1659         /// 2) Operation failed
1660         /// </exception>
1661         public static void Run(Action create, Action terminate, Action<ContextId, InputMethodContext> show, Action<ContextId> hide)
1662         {
1663             _userCreate = create;
1664             _userTerminate = terminate;
1665             _userShow = show;
1666             _userHide = hide;
1667             _imeCallbackStructGCHandle._imeCallbackStruct.create = _create;
1668             _imeCallbackStructGCHandle._imeCallbackStruct.terminate = _terminate;
1669             _imeCallbackStructGCHandle._imeCallbackStruct.hide = _hide;
1670             _imeCallbackStructGCHandle._imeCallbackStruct.show = _show;
1671
1672             ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero);
1673             if (error != ErrorCode.None)
1674             {
1675                 Log.Error(LogTag, "Run Failed with error " + error);
1676                 throw InputMethodExceptionFactory.CreateException(error);
1677             }
1678
1679         }
1680
1681         /// <summary>
1682         /// Sends a key event to the associated text input UI control.
1683         /// </summary>
1684         /// <remarks>
1685         /// This function sends key down or up event with key mask to the client application. If forwardKey is true, this key event goes to the edit filed directly.
1686         /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field.
1687         /// </remarks>
1688         /// <privilege>
1689         /// http://tizen.org/privilege/ime
1690         /// </privilege>
1691         /// <param name="keyCode">The key code to be sent</param>
1692         /// <param name="keyMask">The modifier key mask</param>
1693         /// <param name="forwardKey">The flag to send the key event directly to the edit field</param>
1694         /// <exception cref="InvalidOperationException">
1695         /// This can occur due to the following reasons:
1696         /// 1) The application does not have the privilege to call this function
1697         /// 2) IME main loop isn't started yet
1698         /// </exception>
1699         public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false)
1700         {
1701             ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey);
1702             if (error != ErrorCode.None)
1703             {
1704                 Log.Error(LogTag, "SendEvent Failed with error " + error);
1705                 throw InputMethodExceptionFactory.CreateException(error);
1706             }
1707         }
1708
1709         /// <summary>
1710         /// Sends the text to the associated text input UI control.
1711         /// </summary>
1712         /// <privilege>
1713         /// http://tizen.org/privilege/ime
1714         /// </privilege>
1715         /// <param name="str">The string to be committed</param>
1716         /// <exception cref="InvalidOperationException">
1717         /// This can occur due to the following reasons:
1718         /// 1) The application does not have the privilege to call this function
1719         /// 2) IME main loop isn't started yet
1720         /// </exception>
1721         public static void CommitString(string str)
1722         {
1723             ErrorCode error = ImeCommitString(str);
1724             if (error != ErrorCode.None)
1725             {
1726                 Log.Error(LogTag, "CommitString Failed with error " + error);
1727                 throw InputMethodExceptionFactory.CreateException(error);
1728             }
1729         }
1730
1731         /// <summary>
1732         /// Requests to show preedit string.
1733         /// </summary>
1734         /// <privilege>
1735         /// http://tizen.org/privilege/ime
1736         /// </privilege>
1737         /// <exception cref="InvalidOperationException">
1738         /// This can occur due to the following reasons:
1739         /// 1) The application does not have the privilege to call this function
1740         /// 2) IME main loop isn't started yet
1741         /// </exception>
1742         public static void ShowPreEditString()
1743         {
1744             ErrorCode error = ImeShowPreeditString();
1745             if (error != ErrorCode.None)
1746             {
1747                 Log.Error(LogTag, "ShowPreEditString Failed with error " + error);
1748                 throw InputMethodExceptionFactory.CreateException(error);
1749             }
1750         }
1751
1752         /// <summary>
1753         /// Requests to hide preedit string.
1754         /// </summary>
1755         /// <privilege>
1756         /// http://tizen.org/privilege/ime
1757         /// </privilege>
1758         /// <exception cref="InvalidOperationException">
1759         /// This can occur due to the following reasons:
1760         /// 1) The application does not have the privilege to call this function
1761         /// 2) IME main loop isn't started yet
1762         /// </exception>
1763         public static void HidePreEditString()
1764         {
1765             ErrorCode error = ImeHidePreeditString();
1766             if (error != ErrorCode.None)
1767             {
1768                 Log.Error(LogTag, "HidePreEditString Failed with error " + error);
1769                 throw InputMethodExceptionFactory.CreateException(error);
1770             }
1771         }
1772
1773         /// <summary>
1774         /// Updates a new preedit string.
1775         /// </summary>
1776         /// <privilege>
1777         /// http://tizen.org/privilege/ime
1778         /// </privilege>
1779         /// <param name="str">The string to be updated in preedit</param>
1780         /// <param name="attrs">
1781         /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color and reversal color.
1782         /// The attrs list can be empty if no attributes to set
1783         /// </param>
1784         /// <exception cref="InvalidOperationException">
1785         /// This can occur due to the following reasons:
1786         /// 1) The application does not have the privilege to call this function
1787         /// 2) IME main loop isn't started yet
1788         /// 3) Invalid Parameter
1789         /// </exception>
1790         public static void UpdatePreEditString(string str, IEnumerable<PreEditAttribute> attrs)
1791         {
1792             IntPtr einaList = IntPtr.Zero;
1793             List<GCHandle> attributeHandleList = new List<GCHandle>();
1794             foreach (PreEditAttribute attribute in attrs)
1795             {
1796                 ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct();
1797                 imePreEditAttribute.start = attribute.Start;
1798                 imePreEditAttribute.length = attribute.Length;
1799                 imePreEditAttribute.type = (int)attribute.Type;
1800                 imePreEditAttribute.value = attribute.Value;
1801                 GCHandle attributeHandle = GCHandle.Alloc(imePreEditAttribute, GCHandleType.Pinned);
1802                 attributeHandleList.Add(attributeHandle);
1803                 einaList = Interop.EinaList.EinaListAppend(einaList, attributeHandle.AddrOfPinnedObject());
1804             }
1805             ErrorCode error = ImeUpdatePreeditString(str, einaList);
1806             foreach (GCHandle handle in attributeHandleList)
1807             {
1808                 handle.Free();
1809             }
1810             if (error != ErrorCode.None)
1811             {
1812                 Log.Error(LogTag, "UpdatePreEditString Failed with error " + error);
1813                 throw InputMethodExceptionFactory.CreateException(error);
1814             }
1815         }
1816
1817         /// <summary>
1818         /// Requests the surrounding text from the position of the cursor, asynchronously.
1819         /// </summary>
1820         /// <privilege>
1821         /// http://tizen.org/privilege/ime
1822         /// </privilege>
1823         /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1824         /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1825         /// <exception cref="InvalidOperationException">
1826         /// This can occur due to the following reasons:
1827         /// 1) The application does not have the privilege to call this function
1828         /// 2) IME main loop isn't started yet
1829         /// </exception>
1830         /// <postcondition>
1831         /// The requested surrounding text can be received using the SurroundingTextUpdated Event, only if it is set.
1832         /// </postcondition>
1833         public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter)
1834         {
1835             ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter);
1836             if (error != ErrorCode.None)
1837             {
1838                 Log.Error(LogTag, "RequestSurroundingText Failed with error " + error);
1839                 throw InputMethodExceptionFactory.CreateException(error);
1840             }
1841         }
1842
1843         /// <summary>
1844         /// Requests to delete surrounding text.
1845         /// </summary>
1846         /// <privilege>
1847         /// http://tizen.org/privilege/ime
1848         /// </privilege>
1849         /// <param name="offset">The offset value from the cursor position</param>
1850         /// <param name="len">The length of the text to delete</param>
1851         /// <exception cref="InvalidOperationException">
1852         /// This can occur due to the following reasons:
1853         /// 1) The application does not have the privilege to call this function
1854         /// 2) IME main loop isn't started yet
1855         /// 3) Invalid Parameter
1856         /// </exception>
1857         public static void DeleteSurroundingText(int offset, int len)
1858         {
1859             ErrorCode error = ImeDeleteSurroundingText(offset, len);
1860             if (error != ErrorCode.None)
1861             {
1862                 Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error);
1863                 throw InputMethodExceptionFactory.CreateException(error);
1864             }
1865         }
1866
1867         /// <summary>
1868         /// Gets the surrounding text from the position of the cursor, synchronously.
1869         /// </summary>
1870         /// <privilege>
1871         /// http://tizen.org/privilege/ime
1872         /// </privilege>
1873         /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1874         /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1875         /// <param name="text">The surrounding text</param>
1876         /// <param name="cursorPosition">The cursor position</param>
1877         /// <exception cref="InvalidOperationException">
1878         /// This can occur due to the following reasons:
1879         /// 1) The application does not have the privilege to call this function
1880         /// 2) IME main loop isn't started yet
1881         /// 3) Invalid Parameter
1882         /// 4) Failed to obtain text due to out of memory
1883         /// </exception>
1884         public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition)
1885         {
1886             IntPtr txt;
1887             ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition);
1888             if (error != ErrorCode.None)
1889             {
1890                 Log.Error(LogTag, "GetSurroundingText Failed with error " + error);
1891                 throw InputMethodExceptionFactory.CreateException(error);
1892             }
1893             text = Marshal.PtrToStringAnsi(txt);
1894         }
1895
1896         /// <summary>
1897         /// Requests to set selection.
1898         /// </summary>
1899         /// <privilege>
1900         /// http://tizen.org/privilege/ime
1901         /// </privilege>
1902         /// <param name="start">The start cursor position in text (in characters not bytes)</param>
1903         /// <param name="end">The end cursor position in text (in characters not bytes)</param>
1904         /// <exception cref="InvalidOperationException">
1905         /// This can occur due to the following reasons:
1906         /// 1) The application does not have the privilege to call this function
1907         /// 2) IME main loop isn't started yet
1908         /// 3) Invalid Parameter
1909         /// </exception>
1910         public static void SetSelection(int start, int end)
1911         {
1912             ErrorCode error = ImeSetSelection(start, end);
1913             if (error != ErrorCode.None)
1914             {
1915                 Log.Error(LogTag, "SetSelection Failed with error " + error);
1916                 throw InputMethodExceptionFactory.CreateException(error);
1917             }
1918         }
1919
1920         /// <summary>
1921         /// This API returns the input panel main window.
1922         /// </summary>
1923         /// <privilege>
1924         /// http://tizen.org/privilege/ime
1925         /// </privilege>
1926         /// <returns>The input panel main window object on success, otherwise null</returns>
1927         /// <exception cref="InvalidOperationException">
1928         /// This can occur due to the following reasons:
1929         /// 1) The application does not have the privilege to call this function
1930         /// 2) IME main loop isn't started yet
1931         /// 3) Operation Failed
1932         /// </exception>
1933         public static EditorWindow GetMainWindow()
1934         {
1935             EditorWindow._handle = ImeGetMainWindow();
1936             EditorWindow obj = new EditorWindow();
1937             ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
1938             if (error != ErrorCode.None)
1939             {
1940                 Log.Error(LogTag, "GetMainWindow Failed with error " + error);
1941                 throw InputMethodExceptionFactory.CreateException(error);
1942             }
1943             return obj;
1944         }
1945
1946         /// <summary>
1947         /// This API requests the InputMethodEditor to initialize
1948         /// </summary>
1949         /// <privilege>
1950         /// http://tizen.org/privilege/ime
1951         /// </privilege>
1952         /// <exception cref="InvalidOperationException">
1953         /// This can occur due to the following reasons:
1954         /// 1) The application does not have the privilege to call this function
1955         /// 2) Operation Failed
1956         /// </exception>
1957         public static void Create()
1958         {
1959             ErrorCode error = ImeInitialize();
1960             Log.Info(LogTag, "ImeInitialize result : " + error);
1961             if (error != ErrorCode.None)
1962             {
1963                 Log.Error(LogTag, "ImeInitialize Failed with error " + error);
1964                 throw InputMethodExceptionFactory.CreateException(error);
1965             }
1966
1967             error = ImePrepare();
1968             Log.Info(LogTag, "ImePrepare result : " + error);
1969             if (error != ErrorCode.None)
1970             {
1971                 Log.Error(LogTag, "ImePrepare Failed with error " + error);
1972                 throw InputMethodExceptionFactory.CreateException(error);
1973             }
1974         }
1975
1976         /// <summary>
1977         /// This API requests the InputMethodEditor to finalize
1978         /// </summary>
1979         /// <privilege>
1980         /// http://tizen.org/privilege/ime
1981         /// </privilege>
1982         /// <exception cref="InvalidOperationException">
1983         /// This can occur due to the following reasons:
1984         /// 1) The application does not have the privilege to call this function
1985         /// 2) Operation Failed
1986         /// </exception>
1987         public static void Destroy()
1988         {
1989             ErrorCode error = ImeFinalize();
1990             Log.Info(LogTag, "ImeFinalize result : " + error);
1991             if (error != ErrorCode.None)
1992             {
1993                 Log.Error(LogTag, "ImeFinalize Failed with error " + error);
1994                 throw InputMethodExceptionFactory.CreateException(error);
1995             }
1996         }
1997     }
1998 }