[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / EvasKeyEventArgs.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 using System;
18 using System.Runtime.InteropServices;
19
20 namespace ElmSharp
21 {
22     /// <summary>
23     /// The EvasKeyEventArgs is a EvasKey EventArgs.
24     /// </summary>
25     /// <since_tizen> preview </since_tizen>
26     public class EvasKeyEventArgs : EventArgs
27     {
28         IntPtr _nativeEventInfo;
29
30         /// <summary>
31         /// BackButton name in platform.
32         /// </summary>
33         /// <since_tizen> preview </since_tizen>
34         public const string PlatformBackButtonName = "XF86Back";
35
36         /// <summary>
37         /// MenuButton name in platform.
38         /// </summary>
39         /// <since_tizen> preview </since_tizen>
40         public const string PlatformMenuButtonName = "XF86Menu";
41
42         /// <summary>
43         /// HomeButton name in platform.
44         /// </summary>
45         /// <since_tizen> preview </since_tizen>
46         public const string PlatformHomeButtonName = "XF86Home";
47
48         /// <summary>
49         /// Gets the name of the key.
50         /// </summary>
51         /// <since_tizen> preview </since_tizen>
52         public string KeyName { get; private set; }
53
54         /// <summary>
55         /// Sets or gets the flags.
56         /// </summary>
57         /// <since_tizen> preview </since_tizen>
58         public EvasEventFlag Flags
59         {
60             get
61             {
62                 IntPtr offset = Marshal.OffsetOf<EvasEventKeyDown>("event_flags");
63                 return (EvasEventFlag)Marshal.ReadIntPtr(_nativeEventInfo, (int)offset);
64             }
65             set
66             {
67                 IntPtr offset = Marshal.OffsetOf<EvasEventKeyDown>("event_flags");
68                 Marshal.WriteIntPtr(_nativeEventInfo, (int)offset, (IntPtr)value);
69             }
70         }
71
72         EvasKeyEventArgs(IntPtr info)
73         {
74             _nativeEventInfo = info;
75             var evt = Marshal.PtrToStructure<EvasEventKeyDown>(info);
76             KeyName = evt.keyname;
77         }
78
79         /// <summary>
80         /// Creates and initializes a new instance of the EvasKeyEventArgs class.
81         /// </summary>
82         /// <param name="data">The data information.</param>
83         /// <param name="obj">The object.</param>
84         /// <param name="info">The information.</param>
85         /// <returns>EvasKey eventArgs.</returns>
86         /// <since_tizen> preview </since_tizen>
87         static public EvasKeyEventArgs Create(IntPtr data, IntPtr obj, IntPtr info)
88         {
89             return new EvasKeyEventArgs(info);
90         }
91
92         /// <summary>
93         /// Event structure for Key Down event callbacks.
94         /// </summary>
95         [StructLayout(LayoutKind.Sequential)]
96         struct EvasEventKeyDown
97         {
98             /// <summary>
99             /// Name string of the key pressed.
100             /// </summary>
101             public string keyname;
102
103             /// <summary>
104             /// Data to be passed to the event.
105             /// </summary>
106             public IntPtr data;
107
108             /// <summary>
109             /// Modifier keys pressed during the event.
110             /// </summary>
111             public IntPtr modifiers;
112
113             /// <summary>
114             /// Locks information.
115             /// </summary>
116             public IntPtr locks;
117
118             /// <summary>
119             /// Logical key: (example, shift+1 == exclamation).
120             /// </summary>
121             public string key;
122
123             /// <summary>
124             /// UTF-8 string, if this keystroke has produced a visible string to be added.
125             /// </summary>
126             public string str;
127
128             /// <summary>
129             /// UTF-8 string, if this keystroke has modified a string in the middle of being composed - this string replaces the previous one.
130             /// </summary>
131             public string compose;
132
133             public uint timestamp;
134
135             /// <summary>
136             /// Event_flags.
137             /// </summary>
138             public EvasEventFlag event_flags;
139
140             /// <summary>
141             ///
142             /// </summary>
143             public IntPtr dev;
144
145             /// <summary>
146             /// Keycode.
147             /// </summary>
148             public uint keycode;
149         };
150     }
151
152     /// <summary>
153     /// Flags for the events.
154     /// </summary>
155     /// <since_tizen> preview </since_tizen>
156     [Flags]
157     public enum EvasEventFlag
158     {
159         /// <summary>
160         /// No fancy flags set.
161         /// </summary>
162         None = 0,
163
164         /// <summary>
165         /// This event is being delivered but should be put "on hold" until the on hold flag is unset. The event should be used for informational purposes and maybe some indications visually, but not actually perform anything.
166         /// </summary>
167         OnHold = 1,
168     }
169 }