Release 4.0.0-preview1-00051
[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<CursorPositionitionUpdatedEventArgs> _cursorPositionUpdated;
970         private static ImeCursorPositionitionUpdatedCb _imeCursorPositionitionUpdatedDelegate;
971         private static event EventHandler<LanguageSetEventArgs> _langaugeSet;
972         private static ImeLanguageSetCb _imeLanguageSetDelegate;
973         private static event EventHandler<SetDataEventArgs> _imDataSet;
974         private static ImeImdataSetCb _imeDataSetDelegate;
975         private static event EventHandler<LayoutSetEventArgs> _layoutSet;
976         private static ImeLayoutSetCb _imeLayoutSetDelegate;
977         private static event EventHandler<ReturnKeySetEventArgs> _returnKeyTypeSet;
978         private static ImeReturnKeySetCb _imeReturnKeySetDelegate;
979         private static event EventHandler<ReturnKeyStateSetEventArgs> _returnKeyStateSet;
980         private static ImeReturnKeyStateSetCb _imeReturnKeyStateSetDelegate;
981         private static ImeProcessKeyEventCb _imeProcessKeyDelegate;
982         private static event EventHandler<DisplayLanaguageChangedEventArgs> _displayLanaguageChanged;
983         private static ImeDisplayLanguageChangedCb _imeDisplayLanaguageChangedDelegate;
984         private static event EventHandler<RotationChangedEventArgs> _rotationDegreeChanged;
985         private static ImeRotationChangedCb _imeRotationChangedDelegate;
986         private static event EventHandler<AccessibilityStateChangedEventArgs> _accessibilityStateChanged;
987         private static ImeAccessibilityStateChangedCb _imeAccessibilityStateChangedDelegate;
988         private static event EventHandler<OptionWindowCreatedEventArgs> _optionWindowCreated;
989         private static ImeOptionWindowCreatedCb _imeOptionWindowCreatedDelegate;
990         private static event EventHandler<OptionWindowDestroyedEventArgs> _optionWindowDestroyed;
991         private static ImeOptionWindowDestroyedCb _imeOptionWindowDestroyedDelegate;
992         private static ImeLanguageRequestedCb _imeLanguageRequestedDelegate;
993         private static OutAction<string> _languageRequestedDelegate;
994         private static BoolAction<KeyCode, KeyMask, VoiceControlDeviceInformation> _processKeyDelagate;
995         private static ImeImdataRequestedCb _imeImDataRequestedDelegate;
996         private static OutArrayAction<byte> _imDataRequestedDelegate;
997         private static ImeGeometryRequestedCb _imeGeometryRequestedDelegate;
998         private static OutAction<Rect> _geometryRequestedDelegate;
999         private static Action _userCreate;
1000         private static Action _userTerminate;
1001         private static Action<ContextId, InputMethodContext> _userShow;
1002         private static Action<ContextId> _userHide;
1003         private static ImeCreateCb _create = (IntPtr userData) =>
1004         {
1005             Log.Info(LogTag, "In Create Delegate");
1006             _userCreate?.Invoke();
1007         };
1008         private static ImeTerminateCb _terminate = (IntPtr userData) =>
1009         {
1010             Log.Info(LogTag, "In terminate Delegate");
1011             _userTerminate?.Invoke();
1012             _imeCallbackStructGCHandle.Dispose();
1013         };
1014         private static ImeShowCb _show = (int contextId, IntPtr context, IntPtr userData) =>
1015         {
1016             Log.Info(LogTag, "In Show Delegate");
1017             _userShow?.Invoke(new ContextId(contextId), new InputMethodContext(context));
1018         };
1019         private static ImeHideCb _hide = (int contextId, IntPtr userData) =>
1020         {
1021             Log.Info(LogTag, "In Hide Delegate");
1022             _userHide?.Invoke(new ContextId(contextId));
1023         };
1024
1025         /// <summary>
1026         /// Structure representing ContextId
1027         /// </summary>
1028         public struct ContextId : IEquatable<ContextId>
1029         {
1030             internal ContextId(int id)
1031             {
1032                 Id = id;
1033             }
1034
1035             internal int Id
1036             {
1037                 get;
1038                 private set;
1039             }
1040
1041             public bool Equals(ContextId other)
1042             {
1043                 return this.Id == other.Id;
1044             }
1045         }
1046
1047         /// <summary>
1048         /// rectangle representing the position and size of UI Control
1049         /// </summary>
1050         public struct Rect
1051         {
1052             /// <summary>
1053             /// The x position in screen
1054             /// </summary>
1055             public int x;
1056
1057             /// <summary>
1058             /// The y position in screen
1059             /// </summary>
1060             public int y;
1061
1062             /// <summary>
1063             /// The window width
1064             /// </summary>
1065             public int w;
1066
1067             /// <summary>
1068             /// The window height
1069             /// </summary>
1070             public int h;
1071         }
1072
1073         /// <summary>
1074         /// An Action with 1 out parameter
1075         /// </summary>
1076         /// <typeparam name="T">Generic Type</typeparam>
1077         /// <param name="a">The out parameter</param>
1078         public delegate void OutAction<T>(out T a);
1079
1080         /// <summary>
1081         /// An Action with an array out parameter
1082         /// </summary>
1083         /// <typeparam name="T">Generic Type</typeparam>
1084         /// <param name="a">The out parameter 1</param>
1085         public delegate void OutArrayAction<T>(out T[] a);
1086
1087         /// <summary>
1088         /// An Action with 3 Input Parameter returning a bool
1089         /// </summary>
1090         /// <typeparam name="T">Generic Type for Parameter 1</typeparam>
1091         /// <typeparam name="T1">Generic Type for Parameter 2</typeparam>
1092         /// <typeparam name="T2">Generic Type for Parameter 3</typeparam>
1093         /// <param name="a">The Input Parameter 1</param>
1094         /// <param name="b">The Input Parameter 2</param>
1095         /// <param name="c">The Input Parameter 3</param>
1096         /// <returns></returns>
1097         public delegate bool BoolAction<T, T1, T2>(T a, T1 b, T2 c);
1098
1099         /// <summary>
1100         /// Called when an associated text input UI control has focus.
1101         /// </summary>
1102         public static event EventHandler<FocusedInEventArgs> FocusedIn
1103         {
1104             add
1105             {
1106                 lock (thisLock)
1107                 {
1108                     _imeFocusedInDelegate = (int contextId, IntPtr userData) =>
1109                     {
1110                         FocusedInEventArgs args = new FocusedInEventArgs(contextId);
1111                         _focusIn?.Invoke(null, args);
1112                     };
1113                     ErrorCode error = ImeEventSetFocusedInCb(_imeFocusedInDelegate, IntPtr.Zero);
1114                     if (error != ErrorCode.None)
1115                     {
1116                         Log.Error(LogTag, "Add FocusedIn Failed with error " + error);
1117                     }
1118                     else
1119                     {
1120                         _focusIn += value;
1121                     }
1122                 }
1123             }
1124             remove
1125             {
1126                 lock (thisLock)
1127                 {
1128                     _focusIn -= value;
1129                 }
1130             }
1131         }
1132
1133         /// <summary>
1134         /// Called when an associated text input UI control loses focus.
1135         /// </summary>
1136         public static event EventHandler<FocusedOutEventArgs> FocusedOut
1137         {
1138             add
1139             {
1140                 lock (thisLock)
1141                 {
1142                     _imeFocusedOutDelegate = (int contextId, IntPtr userData) =>
1143                     {
1144                         FocusedOutEventArgs args = new FocusedOutEventArgs(contextId);
1145                         _focusOut?.Invoke(null, args);
1146                     };
1147                     ErrorCode error = ImeEventSetFocusedOutCb(_imeFocusedOutDelegate, IntPtr.Zero);
1148                     if (error != ErrorCode.None)
1149                     {
1150                         Log.Error(LogTag, "Add FocusedOut Failed with error " + error);
1151                     }
1152                     else
1153                     {
1154                         _focusOut += value;
1155                     }
1156                 }
1157             }
1158             remove
1159             {
1160                 lock (thisLock)
1161                 {
1162                     _focusOut -= value;
1163                 }
1164             }
1165         }
1166
1167         /// <summary>
1168         /// Called when an associated text input UI control responds to a request with the surrounding text.
1169         /// </summary>
1170         public static event EventHandler<SurroundingTextUpdatedEventArgs> SurroundingTextUpdated
1171         {
1172             add
1173             {
1174                 lock (thisLock)
1175                 {
1176                     _imeSurroundingTextUpdatedDelegate = (int contextId, IntPtr text, int cursorPos, IntPtr userData) =>
1177                     {
1178                         SurroundingTextUpdatedEventArgs args = new SurroundingTextUpdatedEventArgs(contextId, Marshal.PtrToStringAnsi(text), cursorPos);
1179                         _surroundingTextUpdated?.Invoke(null, args);
1180                     };
1181                     ErrorCode error = ImeEventSetSurroundingTextUpdatedCb(_imeSurroundingTextUpdatedDelegate, IntPtr.Zero);
1182                     if (error != ErrorCode.None)
1183                     {
1184                         Log.Error(LogTag, "Add SurroundingTextUpdated Failed with error " + error);
1185                     }
1186                     else
1187                     {
1188                         _surroundingTextUpdated += value;
1189                     }
1190                 }
1191             }
1192             remove
1193             {
1194                 lock (thisLock)
1195                 {
1196                     _surroundingTextUpdated -= value;
1197                 }
1198             }
1199         }
1200
1201         /// <summary>
1202         /// Called to reset the input context of an associated text input UI control.
1203         /// </summary>
1204         public static event EventHandler<EventArgs> InputContextReset
1205         {
1206             add
1207             {
1208                 lock (thisLock)
1209                 {
1210                     _imeInputContextResetDelegate = (IntPtr userData) =>
1211                     {
1212                         _inputContextReset?.Invoke(null, EventArgs.Empty);
1213                     };
1214                     ErrorCode error = ImeEventSetInputContextResetCb(_imeInputContextResetDelegate, IntPtr.Zero);
1215                     if (error != ErrorCode.None)
1216                     {
1217                         Log.Error(LogTag, "Add InputContextReset Failed with error " + error);
1218                     }
1219                     else
1220                     {
1221                         _inputContextReset += value;
1222                     }
1223                 }
1224             }
1225             remove
1226             {
1227                 lock (thisLock)
1228                 {
1229                     _inputContextReset -= value;
1230                 }
1231             }
1232         }
1233
1234         /// <summary>
1235         /// Called when the position of the cursor in an associated text input UI control changes.
1236         /// </summary>
1237         public static event EventHandler<CursorPositionitionUpdatedEventArgs> CursorPositionitionUpdated
1238         {
1239             add
1240             {
1241                 lock (thisLock)
1242                 {
1243                     _imeCursorPositionitionUpdatedDelegate = (int cursorPos, IntPtr userData) =>
1244                     {
1245                         CursorPositionitionUpdatedEventArgs args = new CursorPositionitionUpdatedEventArgs(cursorPos);
1246                         _cursorPositionUpdated?.Invoke(null, args);
1247                     };
1248                     ErrorCode error = ImeEventSetCursorPositionitionUpdatedCb(_imeCursorPositionitionUpdatedDelegate, IntPtr.Zero);
1249                     if (error != ErrorCode.None)
1250                     {
1251                         Log.Error(LogTag, "Add CursorPositionitionUpdated Failed with error " + error);
1252                     }
1253                     else
1254                     {
1255                         _cursorPositionUpdated += value;
1256                     }
1257                 }
1258             }
1259             remove
1260             {
1261                 lock (thisLock)
1262                 {
1263                     _cursorPositionUpdated -= value;
1264                 }
1265             }
1266         }
1267
1268         /// <summary>
1269         /// Called to set the preferred language to the input panel.
1270         /// It will be only called when the client application changes the edit field's language attribute after the input panel is shown.
1271         /// </summary>
1272         public static event EventHandler<LanguageSetEventArgs> LanguageSet
1273         {
1274             add
1275             {
1276                 lock (thisLock)
1277                 {
1278                     _imeLanguageSetDelegate = (InputPanelLanguage language, IntPtr userData) =>
1279                     {
1280                         LanguageSetEventArgs args = new LanguageSetEventArgs(language);
1281                         _langaugeSet?.Invoke(null, args);
1282                     };
1283                     ErrorCode error = ImeEventSetLanguageSetCb(_imeLanguageSetDelegate, IntPtr.Zero);
1284                     if (error != ErrorCode.None)
1285                     {
1286                         Log.Error(LogTag, "Add LanguageSet Failed with error " + error);
1287                     }
1288                     else
1289                     {
1290                         _langaugeSet += value;
1291                     }
1292                 }
1293             }
1294             remove
1295             {
1296                 lock (thisLock)
1297                 {
1298                     _langaugeSet -= value;
1299                 }
1300             }
1301         }
1302
1303         /// <summary>
1304         /// Called to set the application specific data to deliver to the input panel.
1305         /// </summary>
1306         public static event EventHandler<SetDataEventArgs> DataSet
1307         {
1308             add
1309             {
1310                 lock (thisLock)
1311                 {
1312                     _imeDataSetDelegate = (IntPtr data, uint dataLength, IntPtr userData) =>
1313                     {
1314                         byte[] destination = new byte[dataLength];
1315                         Marshal.Copy(data, destination, 0, (int)dataLength);
1316                         SetDataEventArgs args = new SetDataEventArgs(destination, dataLength);
1317                         _imDataSet?.Invoke(null, args);
1318                     };
1319                     ErrorCode error = ImeEventSetImdataSetCb(_imeDataSetDelegate, IntPtr.Zero);
1320                     if (error != ErrorCode.None)
1321                     {
1322                         Log.Error(LogTag, "Add DataSet Failed with error " + error);
1323                     }
1324                     else
1325                     {
1326                         _imDataSet += value;
1327                     }
1328                 }
1329             }
1330             remove
1331             {
1332                 lock (thisLock)
1333                 {
1334                     _imDataSet -= value;
1335                 }
1336             }
1337         }
1338
1339         /// <summary>
1340         /// Called when an associated text input UI control requests the input panel to set its layout.
1341         /// It will be only called when the client application changes the edit field's layout attribute after the input panel is shown.
1342         /// </summary>
1343         public static event EventHandler<LayoutSetEventArgs> LayoutSet
1344         {
1345             add
1346             {
1347                 lock (thisLock)
1348                 {
1349                     _imeLayoutSetDelegate = (InputPanelLayout layout, IntPtr userData) =>
1350                     {
1351                         LayoutSetEventArgs args = new LayoutSetEventArgs(layout);
1352                         _layoutSet?.Invoke(null, args);
1353                     };
1354                     ErrorCode error = ImeEventSetLayoutSetCb(_imeLayoutSetDelegate, IntPtr.Zero);
1355                     if (error != ErrorCode.None)
1356                     {
1357                         Log.Error(LogTag, "Add LayoutSet Failed with error " + error);
1358                     }
1359                     else
1360                     {
1361                         _layoutSet += value;
1362                     }
1363                 }
1364             }
1365             remove
1366             {
1367                 lock (thisLock)
1368                 {
1369                     _layoutSet -= value;
1370                 }
1371             }
1372         }
1373
1374         /// <summary>
1375         /// Called when an associated text input UI control requests the input panel to set the Return key label.
1376         /// The input panel can show text or image on the Return button according to the Return key action.
1377         /// </summary>
1378         public static event EventHandler<ReturnKeySetEventArgs> ReturnKeySet
1379         {
1380             add
1381             {
1382                 lock (thisLock)
1383                 {
1384                     _imeReturnKeySetDelegate = (InputPanelReturnKey type, IntPtr userData) =>
1385                     {
1386                         ReturnKeySetEventArgs args = new ReturnKeySetEventArgs(type);
1387                         _returnKeyTypeSet?.Invoke(null, args);
1388                     };
1389                     ErrorCode error = ImeEventSetReturnKeySetCb(_imeReturnKeySetDelegate, IntPtr.Zero);
1390                     if (error != ErrorCode.None)
1391                     {
1392                         Log.Error(LogTag, "Add ReturnKeySet Failed with error " + error);
1393                     }
1394                     else
1395                     {
1396                         _returnKeyTypeSet += value;
1397                     }
1398                 }
1399             }
1400             remove
1401             {
1402                 lock (thisLock)
1403                 {
1404                     _returnKeyTypeSet -= value;
1405                 }
1406             }
1407         }
1408
1409         /// <summary>
1410         /// Called when an associated text input UI control requests the input panel to enable or disable the Return key state.
1411         /// </summary>
1412         public static event EventHandler<ReturnKeyStateSetEventArgs> ReturnKeyStateSet
1413         {
1414             add
1415             {
1416                 lock (thisLock)
1417                 {
1418                     _imeReturnKeyStateSetDelegate = (bool state, IntPtr userData) =>
1419                     {
1420                         ReturnKeyStateSetEventArgs args = new ReturnKeyStateSetEventArgs(state);
1421                         _returnKeyStateSet?.Invoke(null, args);
1422                     };
1423                     ErrorCode error = ImeEventSetReturnKeyStateSetCb(_imeReturnKeyStateSetDelegate, IntPtr.Zero);
1424                     if (error != ErrorCode.None)
1425                     {
1426                         Log.Error(LogTag, "Add ReturnKeyStateSet Failed with error " + error);
1427                     }
1428                     else
1429                     {
1430                         _returnKeyStateSet += value;
1431                     }
1432                 }
1433             }
1434             remove
1435             {
1436                 lock (thisLock)
1437                 {
1438                     _returnKeyStateSet -= value;
1439                 }
1440             }
1441         }
1442
1443         /// <summary>
1444         /// Called when the system display language is changed.
1445         /// </summary>
1446         public static event EventHandler<DisplayLanaguageChangedEventArgs> DisplayLanaguageChanged
1447         {
1448             add
1449             {
1450                 lock (thisLock)
1451                 {
1452                     _imeDisplayLanaguageChangedDelegate = (IntPtr language, IntPtr userData) =>
1453                     {
1454                         DisplayLanaguageChangedEventArgs args = new DisplayLanaguageChangedEventArgs(Marshal.PtrToStringAnsi(language));
1455                         _displayLanaguageChanged?.Invoke(null, args);
1456                     };
1457                     ErrorCode error = ImeEventSetDisplayLanguageChangedCb(_imeDisplayLanaguageChangedDelegate, IntPtr.Zero);
1458                     if (error != ErrorCode.None)
1459                     {
1460                         Log.Error(LogTag, "Add DisplayLanaguageChanged Failed with error " + error);
1461                     }
1462                     else
1463                     {
1464                         _displayLanaguageChanged += value;
1465                     }
1466                 }
1467             }
1468             remove
1469             {
1470                 lock (thisLock)
1471                 {
1472                     _displayLanaguageChanged -= value;
1473                 }
1474             }
1475         }
1476
1477         /// <summary>
1478         /// Called when the device is rotated.
1479         /// </summary>
1480         public static event EventHandler<RotationChangedEventArgs> RotationChanged
1481         {
1482             add
1483             {
1484                 lock (thisLock)
1485                 {
1486                     _imeRotationChangedDelegate = (int degree, IntPtr userData) =>
1487                     {
1488                         RotationChangedEventArgs args = new RotationChangedEventArgs(degree);
1489                         _rotationDegreeChanged?.Invoke(null, args);
1490                     };
1491                     ErrorCode error = ImeEventSetRotationChangedCb(_imeRotationChangedDelegate, IntPtr.Zero);
1492                     if (error != ErrorCode.None)
1493                     {
1494                         Log.Error(LogTag, "Add RotationChanged Failed with error " + error);
1495                     }
1496                     else
1497                     {
1498                         _rotationDegreeChanged += value;
1499                     }
1500                 }
1501             }
1502             remove
1503             {
1504                 lock (thisLock)
1505                 {
1506                     _rotationDegreeChanged -= value;
1507                 }
1508             }
1509         }
1510
1511         /// <summary>
1512         /// Called when Accessibility in Settings application is on or off.
1513         /// </summary>
1514         public static event EventHandler<AccessibilityStateChangedEventArgs> AccessibilityStateChanged
1515         {
1516             add
1517             {
1518                 lock (thisLock)
1519                 {
1520                     _imeAccessibilityStateChangedDelegate = (bool state, IntPtr userData) =>
1521                     {
1522                         AccessibilityStateChangedEventArgs args = new AccessibilityStateChangedEventArgs(state);
1523                         _accessibilityStateChanged?.Invoke(null, args);
1524                     };
1525                     ErrorCode error = ImeEventSetAccessibilityStateChangedCb(_imeAccessibilityStateChangedDelegate, IntPtr.Zero);
1526                     if (error != ErrorCode.None)
1527                     {
1528                         Log.Error(LogTag, "Add AccessibilityStateChanged Failed with error " + error);
1529                     }
1530                     else
1531                     {
1532                         _accessibilityStateChanged += value;
1533                     }
1534                 }
1535             }
1536             remove
1537             {
1538                 lock (thisLock)
1539                 {
1540                     _accessibilityStateChanged -= value;
1541                 }
1542             }
1543         }
1544
1545         /// <summary>
1546         /// Called to create the option window.
1547         /// </summary>
1548         /// <remarks>
1549         /// if Input panel requests to open the option window, type will be OptionWindowType.Keyboard.
1550         /// And if Settings application requests to open it, type will be OptionWindowType.SettingApplication.
1551         /// </remarks>
1552         public static event EventHandler<OptionWindowCreatedEventArgs> OptionWindowCreated
1553         {
1554             add
1555             {
1556                 lock (thisLock)
1557                 {
1558                     _imeOptionWindowCreatedDelegate = (IntPtr window, OptionWindowType type, IntPtr userData) =>
1559                     {
1560                         OptionWindow._handle = window;
1561                         OptionWindowCreatedEventArgs args = new OptionWindowCreatedEventArgs(new OptionWindow(), type);
1562                         _optionWindowCreated?.Invoke(null, args);
1563                     };
1564                     ErrorCode error = ImeEventSetOptionWindowCreatedCb(_imeOptionWindowCreatedDelegate, IntPtr.Zero);
1565                     if (error != ErrorCode.None)
1566                     {
1567                         Log.Error(LogTag, "Add OptionWindowCreated Failed with error " + error);
1568                     }
1569                     else
1570                     {
1571                         _optionWindowCreated += value;
1572                     }
1573                 }
1574             }
1575             remove
1576             {
1577                 lock (thisLock)
1578                 {
1579                     _optionWindowCreated -= value;
1580                 }
1581             }
1582         }
1583
1584         /// <summary>
1585         /// Called to destroy the option window.
1586         /// </summary>
1587         public static event EventHandler<OptionWindowDestroyedEventArgs> OptionWindowDestroyed
1588         {
1589             add
1590             {
1591                 lock (thisLock)
1592                 {
1593                     _imeOptionWindowDestroyedDelegate = (IntPtr window, IntPtr userData) =>
1594                     {
1595                         OptionWindow._handle = window;
1596                         OptionWindowDestroyedEventArgs args = new OptionWindowDestroyedEventArgs(new OptionWindow());
1597                         _optionWindowDestroyed?.Invoke(null, args);
1598                     };
1599                     ErrorCode error = ImeEventSetOptionWindowDestroyedCb(_imeOptionWindowDestroyedDelegate, IntPtr.Zero);
1600                     if (error != ErrorCode.None)
1601                     {
1602                         Log.Error(LogTag, "Add OptionWindowDestroyed Failed with error " + error);
1603                     }
1604                     else
1605                     {
1606                         _optionWindowDestroyed += value;
1607                     }
1608                 }
1609             }
1610             remove
1611             {
1612                 lock (thisLock)
1613                 {
1614                     _optionWindowDestroyed -= value;
1615                 }
1616             }
1617         }
1618
1619         /// <summary>
1620         /// Sets the languageRequested Action
1621         /// </summary>
1622         /// <param name="languageRequested">
1623         /// Called when an associated text input UI control requests the language from the input panel, requesting for language code.
1624         /// </param>
1625         public static void SetLanguageRequestedCallback(OutAction<string> languageRequested)
1626         {
1627             _imeLanguageRequestedDelegate = (IntPtr userData, out IntPtr langCode) =>
1628             {
1629                 string langauage;
1630                 _languageRequestedDelegate(out langauage);
1631                 char[] languageArray = langauage.ToCharArray();
1632                 langCode = new IntPtr();
1633                 Marshal.Copy(languageArray, 0, langCode, languageArray.Length);
1634             };
1635             ErrorCode error = ImeEventSetLanguageRequestedCallbackCb(_imeLanguageRequestedDelegate, IntPtr.Zero);
1636             if (error != ErrorCode.None)
1637             {
1638                 Log.Error(LogTag, "Add SetLanguageRequestedCallback Failed with error " + error);
1639             }
1640             _languageRequestedDelegate = languageRequested;
1641         }
1642
1643         /// <summary>
1644         /// Sets the processKey Action
1645         /// If the key event is from the external device, DeviceInfo will have its name, class and subclass information.
1646         /// </summary>
1647         /// <param name="processKey">
1648         /// The Action is alled when the key event is received from the external devices or SendKey function.
1649         /// This Event processes the key event before an associated text input UI control does.
1650         /// </param>
1651         public static void SetProcessKeyCallback(BoolAction<KeyCode, KeyMask, VoiceControlDeviceInformation> processKey)
1652         {
1653             _imeProcessKeyDelegate = (KeyCode keyCode, KeyMask keyMask, IntPtr devInfo, IntPtr userData) =>
1654             {
1655                 return _processKeyDelagate(keyCode, keyMask, new VoiceControlDeviceInformation(devInfo));
1656             };
1657             ErrorCode error = ImeEventSetProcessKeyEventCb(_imeProcessKeyDelegate, IntPtr.Zero);
1658             if (error != ErrorCode.None)
1659             {
1660                 Log.Error(LogTag, "Add ProcessKey Failed with error " + error);
1661             }
1662             _processKeyDelagate = processKey;
1663         }
1664
1665         /// <summary>
1666         /// Sets the imDataRequested Action
1667         /// </summary>
1668         /// <param name="imDataRequested">
1669         /// 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.
1670         /// </param>
1671         public static void SetDataRequestedCallback(OutArrayAction<byte> imDataRequested)
1672         {
1673             _imeImDataRequestedDelegate = (IntPtr userData, out IntPtr data, out uint dataLength) =>
1674             {
1675                 byte[] dataArr;
1676                 _imDataRequestedDelegate(out dataArr);
1677                 data = new IntPtr();
1678                 Marshal.Copy(dataArr, 0, data, dataArr.Length);
1679                 dataLength = (uint)dataArr.Length;
1680             };
1681             ErrorCode error = ImeEventSetImdataRequestedCb(_imeImDataRequestedDelegate, IntPtr.Zero);
1682             if (error != ErrorCode.None)
1683             {
1684                 Log.Error(LogTag, "Add SetDataRequestedCallback Failed with error " + error);
1685             }
1686             _imDataRequestedDelegate = imDataRequested;
1687         }
1688
1689         /// <summary>
1690         /// Sets the GeometryRequested Action
1691         /// </summary>
1692         /// <param name="geometryRequested">
1693         /// Called when an associated text input UI control requests the position and size from the input panel, requesting for x,y,w,h values.
1694         /// </param>
1695         public static void SetGeometryRequestedCallback(OutAction<Rect> geometryRequested)
1696         {
1697             _imeGeometryRequestedDelegate = (IntPtr userData, out int x, out int y, out int w, out int h) =>
1698             {
1699                 Rect rect = new Rect();
1700                 _geometryRequestedDelegate(out rect);
1701                 x = rect.x;
1702                 y = rect.y;
1703                 w = rect.w;
1704                 h = rect.h;
1705             };
1706             ErrorCode error = ImeEventSetGeometryRequestedCallbackCb(_imeGeometryRequestedDelegate, IntPtr.Zero);
1707             if (error != ErrorCode.None)
1708             {
1709                 Log.Error(LogTag, "Add SetGeometryRequestedCallback Failed with error " + error);
1710             }
1711             _geometryRequestedDelegate = geometryRequested;
1712         }
1713
1714         /// <summary>
1715         /// Runs the main loop of IME application.
1716         /// This function starts to run IME application's main loop.
1717         /// </summary>
1718         /// <privilege>
1719         /// http://tizen.org/privilege/ime
1720         /// </privilege>
1721         /// <remarks>
1722         /// This API is a blocking call, as it starts the main loop of the application.
1723         /// </remarks>
1724         /// <param name="create">This is called to initialize IME application before the main loop starts up</param>
1725         /// <param name="terminate">This is called when IME application is terminated</param>
1726         /// <param name="show">
1727         /// This is called when IME application is shown
1728         /// It provides the Context Inofrmation and the Context Id
1729         /// </param>
1730         /// <param name="hide">
1731         /// This is called when IME application is hidden
1732         /// It provides the Context Id
1733         /// </param>
1734         /// <exception cref="InvalidOperationException">
1735         /// This can occur due to the following reasons:
1736         /// 1) The application does not have the privilege to call this function
1737         /// 2) Operation failed
1738         /// </exception>
1739         public static void Run(Action create, Action terminate, Action<ContextId, InputMethodContext> show, Action<ContextId> hide)
1740         {
1741             _userCreate = create;
1742             _userTerminate = terminate;
1743             _userShow = show;
1744             _userHide = hide;
1745             _imeCallbackStructGCHandle._imeCallbackStruct.create = _create;
1746             _imeCallbackStructGCHandle._imeCallbackStruct.terminate = _terminate;
1747             _imeCallbackStructGCHandle._imeCallbackStruct.hide = _hide;
1748             _imeCallbackStructGCHandle._imeCallbackStruct.show = _show;
1749
1750             ErrorCode error = ImeRun(ref _imeCallbackStructGCHandle._imeCallbackStruct, IntPtr.Zero);
1751             if (error != ErrorCode.None)
1752             {
1753                 Log.Error(LogTag, "Run Failed with error " + error);
1754                 throw InputMethodExceptionFactory.CreateException(error);
1755             }
1756
1757         }
1758
1759         /// <summary>
1760         /// Sends a key event to the associated text input UI control.
1761         /// </summary>
1762         /// <remarks>
1763         /// 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.
1764         /// And if forwardKey is false, the ProcessKey event receives the key event before the edit field.
1765         /// </remarks>
1766         /// <privilege>
1767         /// http://tizen.org/privilege/ime
1768         /// </privilege>
1769         /// <param name="keyCode">The key code to be sent</param>
1770         /// <param name="keyMask">The modifier key mask</param>
1771         /// <param name="forwardKey">The flag to send the key event directly to the edit field</param>
1772         /// <exception cref="InvalidOperationException">
1773         /// This can occur due to the following reasons:
1774         /// 1) The application does not have the privilege to call this function
1775         /// 2) IME main loop isn't started yet
1776         /// </exception>
1777         public static void SendKeyEvent(KeyCode keyCode, KeyMask keyMask, bool forwardKey = false)
1778         {
1779             ErrorCode error = ImeSendKeyEvent(keyCode, keyMask, forwardKey);
1780             if (error != ErrorCode.None)
1781             {
1782                 Log.Error(LogTag, "SendEvent Failed with error " + error);
1783                 throw InputMethodExceptionFactory.CreateException(error);
1784             }
1785         }
1786
1787         /// <summary>
1788         /// Sends the text to the associated text input UI control.
1789         /// </summary>
1790         /// <privilege>
1791         /// http://tizen.org/privilege/ime
1792         /// </privilege>
1793         /// <param name="str">The string to be committed</param>
1794         /// <exception cref="InvalidOperationException">
1795         /// This can occur due to the following reasons:
1796         /// 1) The application does not have the privilege to call this function
1797         /// 2) IME main loop isn't started yet
1798         /// </exception>
1799         public static void CommitString(string str)
1800         {
1801             ErrorCode error = ImeCommitString(str);
1802             if (error != ErrorCode.None)
1803             {
1804                 Log.Error(LogTag, "CommitString Failed with error " + error);
1805                 throw InputMethodExceptionFactory.CreateException(error);
1806             }
1807         }
1808
1809         /// <summary>
1810         /// Requests to show preedit string.
1811         /// </summary>
1812         /// <privilege>
1813         /// http://tizen.org/privilege/ime
1814         /// </privilege>
1815         /// <exception cref="InvalidOperationException">
1816         /// This can occur due to the following reasons:
1817         /// 1) The application does not have the privilege to call this function
1818         /// 2) IME main loop isn't started yet
1819         /// </exception>
1820         public static void ShowPreEditString()
1821         {
1822             ErrorCode error = ImeShowPreeditString();
1823             if (error != ErrorCode.None)
1824             {
1825                 Log.Error(LogTag, "ShowPreEditString Failed with error " + error);
1826                 throw InputMethodExceptionFactory.CreateException(error);
1827             }
1828         }
1829
1830         /// <summary>
1831         /// Requests to hide preedit string.
1832         /// </summary>
1833         /// <privilege>
1834         /// http://tizen.org/privilege/ime
1835         /// </privilege>
1836         /// <exception cref="InvalidOperationException">
1837         /// This can occur due to the following reasons:
1838         /// 1) The application does not have the privilege to call this function
1839         /// 2) IME main loop isn't started yet
1840         /// </exception>
1841         public static void HidePreEditString()
1842         {
1843             ErrorCode error = ImeHidePreeditString();
1844             if (error != ErrorCode.None)
1845             {
1846                 Log.Error(LogTag, "HidePreEditString Failed with error " + error);
1847                 throw InputMethodExceptionFactory.CreateException(error);
1848             }
1849         }
1850
1851         /// <summary>
1852         /// Updates a new preedit string.
1853         /// </summary>
1854         /// <privilege>
1855         /// http://tizen.org/privilege/ime
1856         /// </privilege>
1857         /// <param name="str">The string to be updated in preedit</param>
1858         /// <param name="attrs">
1859         /// The list which has ime_preedit_attribute lists, strings can be composed of multiple string attributes: underline, highlight color and reversal color.
1860         /// The attrs list can be empty if no attributes to set
1861         /// </param>
1862         /// <exception cref="InvalidOperationException">
1863         /// This can occur due to the following reasons:
1864         /// 1) The application does not have the privilege to call this function
1865         /// 2) IME main loop isn't started yet
1866         /// 3) Invalid Parameter
1867         /// </exception>
1868         public static void UpdatePreEditString(string str, IEnumerable<PreEditAttribute> attrs)
1869         {
1870             IntPtr einaList = IntPtr.Zero;
1871             List<GCHandle> attributeHandleList = new List<GCHandle>();
1872             foreach (PreEditAttribute attribute in attrs)
1873             {
1874                 ImePreEditAttributeStruct imePreEditAttribute = new ImePreEditAttributeStruct();
1875                 imePreEditAttribute.start = attribute.Start;
1876                 imePreEditAttribute.length = attribute.Length;
1877                 imePreEditAttribute.type = (int)attribute.Type;
1878                 imePreEditAttribute.value = attribute.Value;
1879                 GCHandle attributeHandle = GCHandle.Alloc(imePreEditAttribute, GCHandleType.Pinned);
1880                 attributeHandleList.Add(attributeHandle);
1881                 einaList = Interop.EinaList.EinaListAppend(einaList, attributeHandle.AddrOfPinnedObject());
1882             }
1883             ErrorCode error = ImeUpdatePreeditString(str, einaList);
1884             foreach (GCHandle handle in attributeHandleList)
1885             {
1886                 handle.Free();
1887             }
1888             if (error != ErrorCode.None)
1889             {
1890                 Log.Error(LogTag, "UpdatePreEditString Failed with error " + error);
1891                 throw InputMethodExceptionFactory.CreateException(error);
1892             }
1893         }
1894
1895         /// <summary>
1896         /// Requests the surrounding text from the position of the cursor, asynchronously.
1897         /// </summary>
1898         /// <privilege>
1899         /// http://tizen.org/privilege/ime
1900         /// </privilege>
1901         /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1902         /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1903         /// <exception cref="InvalidOperationException">
1904         /// This can occur due to the following reasons:
1905         /// 1) The application does not have the privilege to call this function
1906         /// 2) IME main loop isn't started yet
1907         /// </exception>
1908         /// <postcondition>
1909         /// The requested surrounding text can be received using the SurroundingTextUpdated Event, only if it is set.
1910         /// </postcondition>
1911         public static void RequestSurroundingText(int maxLenBefore, int maxLenAfter)
1912         {
1913             ErrorCode error = ImeRequestSurroundingText(maxLenBefore, maxLenAfter);
1914             if (error != ErrorCode.None)
1915             {
1916                 Log.Error(LogTag, "RequestSurroundingText Failed with error " + error);
1917                 throw InputMethodExceptionFactory.CreateException(error);
1918             }
1919         }
1920
1921         /// <summary>
1922         /// Requests to delete surrounding text.
1923         /// </summary>
1924         /// <privilege>
1925         /// http://tizen.org/privilege/ime
1926         /// </privilege>
1927         /// <param name="offset">The offset value from the cursor position</param>
1928         /// <param name="len">The length of the text to delete</param>
1929         /// <exception cref="InvalidOperationException">
1930         /// This can occur due to the following reasons:
1931         /// 1) The application does not have the privilege to call this function
1932         /// 2) IME main loop isn't started yet
1933         /// 3) Invalid Parameter
1934         /// </exception>
1935         public static void DeleteSurroundingText(int offset, int len)
1936         {
1937             ErrorCode error = ImeDeleteSurroundingText(offset, len);
1938             if (error != ErrorCode.None)
1939             {
1940                 Log.Error(LogTag, "DeleteSurroundingText Failed with error " + error);
1941                 throw InputMethodExceptionFactory.CreateException(error);
1942             }
1943         }
1944
1945         /// <summary>
1946         /// Gets the surrounding text from the position of the cursor, synchronously.
1947         /// </summary>
1948         /// <privilege>
1949         /// http://tizen.org/privilege/ime
1950         /// </privilege>
1951         /// <param name="maxLenBefore">The maximum length of string to be retrieved before the cursor, -1 means unlimited</param>
1952         /// <param name="maxLenAfter">The maximum length of string to be retrieved after the cursor, -1 means unlimited</param>
1953         /// <param name="text">The surrounding text</param>
1954         /// <param name="cursorPosition">The cursor position</param>
1955         /// <exception cref="InvalidOperationException">
1956         /// This can occur due to the following reasons:
1957         /// 1) The application does not have the privilege to call this function
1958         /// 2) IME main loop isn't started yet
1959         /// 3) Invalid Parameter
1960         /// 4) Failed to obtain text due to out of memory
1961         /// </exception>
1962         public static void GetSurroundingText(int maxLenBefore, int maxLenAfter, out string text, out int cursorPosition)
1963         {
1964             IntPtr txt;
1965             ErrorCode error = ImeGetSurroundingText(maxLenBefore, maxLenAfter, out txt, out cursorPosition);
1966             if (error != ErrorCode.None)
1967             {
1968                 Log.Error(LogTag, "GetSurroundingText Failed with error " + error);
1969                 throw InputMethodExceptionFactory.CreateException(error);
1970             }
1971             text = Marshal.PtrToStringAnsi(txt);
1972         }
1973
1974         /// <summary>
1975         /// Requests to set selection.
1976         /// </summary>
1977         /// <privilege>
1978         /// http://tizen.org/privilege/ime
1979         /// </privilege>
1980         /// <param name="start">The start cursor position in text (in characters not bytes)</param>
1981         /// <param name="end">The end cursor position in text (in characters not bytes)</param>
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) IME main loop isn't started yet
1986         /// 3) Invalid Parameter
1987         /// </exception>
1988         public static void SetSelection(int start, int end)
1989         {
1990             ErrorCode error = ImeSetSelection(start, end);
1991             if (error != ErrorCode.None)
1992             {
1993                 Log.Error(LogTag, "SetSelection Failed with error " + error);
1994                 throw InputMethodExceptionFactory.CreateException(error);
1995             }
1996         }
1997
1998         /// <summary>
1999         /// This API returns the input panel main window.
2000         /// </summary>
2001         /// <privilege>
2002         /// http://tizen.org/privilege/ime
2003         /// </privilege>
2004         /// <returns>The input panel main window object on success, otherwise null</returns>
2005         /// <exception cref="InvalidOperationException">
2006         /// This can occur due to the following reasons:
2007         /// 1) The application does not have the privilege to call this function
2008         /// 2) IME main loop isn't started yet
2009         /// 3) Operation Failed
2010         /// </exception>
2011         public static EditorWindow GetMainWindow()
2012         {
2013             EditorWindow._handle = ImeGetMainWindow();
2014             EditorWindow obj = new EditorWindow();
2015             ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
2016             if (error != ErrorCode.None)
2017             {
2018                 Log.Error(LogTag, "GetMainWindow Failed with error " + error);
2019                 throw InputMethodExceptionFactory.CreateException(error);
2020             }
2021             return obj;
2022         }
2023
2024         /// <summary>
2025         /// This API requests the InputMethodEditor to initialize
2026         /// </summary>
2027         /// <privilege>
2028         /// http://tizen.org/privilege/ime
2029         /// </privilege>
2030         /// <exception cref="InvalidOperationException">
2031         /// This can occur due to the following reasons:
2032         /// 1) The application does not have the privilege to call this function
2033         /// 2) Operation Failed
2034         /// </exception>
2035         public static void Create()
2036         {
2037             ErrorCode error = ImeInitialize();
2038             Log.Info(LogTag, "ImeInitialize result : " + error);
2039             if (error != ErrorCode.None)
2040             {
2041                 Log.Error(LogTag, "ImeInitialize Failed with error " + error);
2042                 throw InputMethodExceptionFactory.CreateException(error);
2043             }
2044
2045             error = ImePrepare();
2046             Log.Info(LogTag, "ImePrepare result : " + error);
2047             if (error != ErrorCode.None)
2048             {
2049                 Log.Error(LogTag, "ImePrepare Failed with error " + error);
2050                 throw InputMethodExceptionFactory.CreateException(error);
2051             }
2052         }
2053
2054         /// <summary>
2055         /// This API requests the InputMethodEditor to finalize
2056         /// </summary>
2057         /// <privilege>
2058         /// http://tizen.org/privilege/ime
2059         /// </privilege>
2060         /// <exception cref="InvalidOperationException">
2061         /// This can occur due to the following reasons:
2062         /// 1) The application does not have the privilege to call this function
2063         /// 2) Operation Failed
2064         /// </exception>
2065         public static void Destroy()
2066         {
2067             ErrorCode error = ImeFinalize();
2068             Log.Info(LogTag, "ImeFinalize result : " + error);
2069             if (error != ErrorCode.None)
2070             {
2071                 Log.Error(LogTag, "ImeFinalize Failed with error " + error);
2072                 throw InputMethodExceptionFactory.CreateException(error);
2073             }
2074         }
2075
2076         /// <summary>
2077         /// Requests to create an option window from the input panel.
2078         /// The input panel can call this function to open the option window. This function calls OptionWindowCreated Event with OptionWindowType.Keyboard.
2079         /// </summary>
2080         /// <privilege>
2081         /// http://tizen.org/privilege/ime
2082         /// </privilege>
2083         /// <exception cref="InvalidOperationException">
2084         /// This can occur due to the following reasons:
2085         /// 1) The application does not have the privilege to call this function
2086         /// 2) Operation failed
2087         /// 3) IME main loop isn't started yet
2088         /// 4) OptionWindowCreated event has not been set
2089         /// </exception>
2090         /// <precondition>
2091         /// OptionWindowCreated and OptionWindowDestroyed event should be set
2092         /// </precondition>
2093         public static void CreateOptionWindow()
2094         {
2095             ErrorCode error = ImeCreateOptionWindow();
2096             if (error != ErrorCode.None)
2097             {
2098                 Log.Error(LogTag, "CreapteOptionWindow Failed with error " + error);
2099                 throw InputMethodExceptionFactory.CreateException(error);
2100             }
2101         }
2102
2103         /// <summary>
2104         /// Requests to destroy an option window.
2105         /// The input panel can call this function to close the option window which is created from either the input panel or Settings application.
2106         /// </summary>
2107         /// <privilege>
2108         /// http://tizen.org/privilege/ime
2109         /// </privilege>
2110         /// <param name="window">The option window to destroy</param>
2111         /// <exception cref="InvalidOperationException">
2112         /// This can occur due to the following reasons:
2113         /// 1) The application does not have the privilege to call this function
2114         /// 2) Invalid Parameter
2115         /// 3) IME main loop isn't started yet
2116         /// </exception>
2117         /// <precondition>
2118         /// OptionWindowDestroyed Event must be set.
2119         /// </precondition>
2120         /// <postcondition>
2121         /// This function triggers the OptionWindowDestroyed Event if it is set.
2122         /// </postcondition>
2123         public static void DestroyOptionWindow(OptionWindow window)
2124         {
2125             ErrorCode error = ImeDestroyOptionWindow(window);
2126             if (error != ErrorCode.None)
2127             {
2128                 Log.Error(LogTag, "DestroyOptionWindow Failed with error " + error);
2129                 throw InputMethodExceptionFactory.CreateException(error);
2130             }
2131         }
2132     }
2133 }