Release 4.0.0-preview1-00337
[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 an EvasKey EventArgs
24     /// </summary>
25     public class EvasKeyEventArgs : EventArgs
26     {
27         IntPtr _nativeEventInfo;
28
29         /// <summary>
30         /// BackButton name in Platform
31         /// </summary>
32         public const string PlatformBackButtonName = "XF86Back";
33
34         /// <summary>
35         /// MenuButton name in Platform
36         /// </summary>
37         public const string PlatformMenuButtonName = "XF86Menu";
38
39         /// <summary>
40         /// HomeButton name in Platform
41         /// </summary>
42         public const string PlatformHomeButtonName = "XF86Home";
43
44         /// <summary>
45         /// Gets the name of Key
46         /// </summary>
47         public string KeyName { get; private set; }
48
49         /// <summary>
50         /// Sets or gets the flags.
51         /// </summary>
52         public EvasEventFlag Flags
53         {
54             get
55             {
56                 IntPtr offset = Marshal.OffsetOf<EvasEventKeyDown>("event_flags");
57                 return (EvasEventFlag)Marshal.ReadIntPtr(_nativeEventInfo, (int)offset);
58             }
59             set
60             {
61                 IntPtr offset = Marshal.OffsetOf<EvasEventKeyDown>("event_flags");
62                 Marshal.WriteIntPtr(_nativeEventInfo, (int)offset, (IntPtr)value);
63             }
64         }
65
66         EvasKeyEventArgs(IntPtr info)
67         {
68             _nativeEventInfo = info;
69             var evt = Marshal.PtrToStructure<EvasEventKeyDown>(info);
70             KeyName = evt.keyname;
71         }
72
73         /// <summary>
74         /// Creates and initializes a new instance of the EvasKeyEventArgs class.
75         /// </summary>
76         /// <param name="data">data info</param>
77         /// <param name="obj"> object </param>
78         /// <param name="info">information </param>
79         /// <returns>EvasKey eventArgs</returns>
80         static public EvasKeyEventArgs Create(IntPtr data, IntPtr obj, IntPtr info)
81         {
82             return new EvasKeyEventArgs(info);
83         }
84
85         /// <summary>
86         /// Event structure for Key Down event callbacks.
87         /// </summary>
88         [StructLayout(LayoutKind.Sequential)]
89         struct EvasEventKeyDown
90         {
91             /// <summary>
92             /// Name string of the key pressed
93             /// </summary>
94             public string keyname;
95
96             /// <summary>
97             /// Data to be passed to the event
98             /// </summary>
99             public IntPtr data;
100
101             /// <summary>
102             /// Modifier keys pressed during the event
103             /// </summary>
104             public IntPtr modifiers;
105
106             /// <summary>
107             /// Locks info
108             /// </summary>
109             public IntPtr locks;
110
111             /// <summary>
112             /// Logical key: (example, shift+1 == exclamation)
113             /// </summary>
114             public string key;
115
116             /// <summary>
117             /// UTF8 string if this keystroke has produced a visible string to be ADDED
118             /// </summary>
119             public string str;
120
121             /// <summary>
122             /// UTF8 string if this keystroke has modified a string in the middle of being composed - this string replaces the previous one
123             /// </summary>
124             public string compose;
125
126             public uint timestamp;
127
128             /// <summary>
129             /// Event_flags
130             /// </summary>
131             public EvasEventFlag event_flags;
132
133             /// <summary>
134             ///
135             /// </summary>
136             public IntPtr dev;
137
138             /// <summary>
139             /// Keycode
140             /// </summary>
141             public uint keycode;
142         };
143     }
144
145     /// <summary>
146     /// Flags for Events
147     /// </summary>
148     [Flags]
149     public enum EvasEventFlag
150     {
151         /// <summary>
152         /// No fancy flags set
153         /// </summary>
154         None = 0,
155
156         /// <summary>
157         ///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
158         /// </summary>
159         OnHold = 1,
160     }
161 }