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