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