545d834c9e4fffeafd560ce0f946841ebe774dd6
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / InputGenerator.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
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// Enumeration of device type generated events.
23     /// </summary>
24     /// <since_tizen> preview </since_tizen>
25     public enum InputDeviceType
26     {
27         /// <summary>
28         /// Touch Screen device.
29         /// </summary>
30         TouchScreen = (1 << 0),
31
32         /// <summary>
33         /// Keyboard device.
34         /// </summary>
35         Keyboard = (1 << 1),
36
37         /// <summary>
38         /// Mouse Device.
39         /// </summary>
40         /// <remarks>
41         /// Since 3.0.
42         /// </remarks>
43         Pointer = (1 << 2),
44     }
45
46     /// <summary>
47     /// Enumeration of pointer event types.
48     /// </summary>
49     /// <since_tizen> preview </since_tizen>
50     public enum InputPointerType
51     {
52         /// <summary>
53         /// Mouse button press.
54         /// </summary>
55         MouseDown,
56
57         /// <summary>
58         /// Mouse button release.
59         /// </summary>
60         MouseUp,
61
62         /// <summary>
63         /// Mouse move
64         /// </summary>
65         Move,
66     }
67
68     /// <summary>
69     /// Enumeration of touch event types.
70     /// </summary>
71     /// <since_tizen> preview </since_tizen>
72     public enum InputTouchType
73     {
74         /// <summary>
75         /// Finger press. It is same a behavior put your finger on touch screen.
76         /// </summary>
77         Begin = 1,
78
79         /// <summary>
80         /// Finger move. It is same a behavior move your finger on touch screen.
81         /// </summary>
82         Update,
83
84         /// <summary>
85         /// Finger release. It is same a behavior release your finger on touch screen.
86         /// </summary>
87         End,
88     }
89
90     /// <summary>
91     /// InputGenerator provides functions to initialize/deinitialize input devices and to generation touch / key events.
92     /// </summary>
93     /// <privilege>
94     /// http://tizen.org/privilege/inputgenerator
95     /// </privilege>
96     /// <remarks>
97     /// This is not for use by third-party applications.
98     /// </remarks>
99     /// <since_tizen> preview </since_tizen>
100     public class InputGenerator : IDisposable
101     {
102         IntPtr _handle = IntPtr.Zero;
103         bool _isDisposed = false;
104
105         /// <summary>
106         /// Creates and initializes a new instance of the InputGenerator class.
107         /// </summary>
108         /// <param name="deviceType">The device type want to generate events</param>
109         /// <since_tizen> preview </since_tizen>
110         public InputGenerator(InputDeviceType deviceType)
111         {
112             _handle = Interop.Eutil.efl_util_input_initialize_generator((int)deviceType);
113         }
114
115         /// <summary>
116         /// Creates and initializes a new instance of the InputGenerator class with given name.
117         /// </summary>
118         /// <param name="deviceType">The device type want to generate events</param>
119         /// <param name="name">The device name (maximum 31 characters)</param>
120         /// <since_tizen> preview </since_tizen>
121         public InputGenerator(InputDeviceType deviceType, string name)
122         {
123             _handle = Interop.Eutil.efl_util_input_initialize_generator_with_name((int)deviceType, name);
124         }
125
126         /// <summary>
127         /// Destroys the InputGenerator object.
128         /// </summary>
129         ~InputGenerator()
130         {
131             Dispose(false);
132         }
133
134         /// <summary>
135         /// Destroys the current object.
136         /// </summary>
137         /// <since_tizen> preview </since_tizen>
138         public void Dispose()
139         {
140             Dispose(true);
141             GC.SuppressFinalize(this);
142         }
143
144         /// <summary>
145         /// Releases all the resources currently used by this instance.
146         /// </summary>
147         /// <param name="disposing">
148         /// true if the managed resources should be disposed,
149         /// otherwise false.
150         /// </param>
151         /// <since_tizen> preview </since_tizen>
152         protected virtual void Dispose(bool disposing)
153         {
154             if (_isDisposed)
155                 return;
156
157             if (disposing)
158             {
159                 Interop.Eutil.efl_util_input_deinitialize_generator(_handle);
160             }
161
162             _isDisposed = true;
163         }
164
165         /// <summary>
166         /// Generates all of key events using a opened device.
167         /// </summary>
168         /// <param name="key">The key name want to generate.</param>
169         /// <param name="pressed">The value that select key press or release. (0: release, 1: press)</param>
170         /// <since_tizen> preview </since_tizen>
171         public void GenerateKeyEvent(string key, int pressed)
172         {
173             Interop.Eutil.efl_util_input_generate_key(_handle, key, pressed);
174         }
175
176         /// <summary>
177         /// Generate a pointer event using a opened device
178         /// </summary>
179         /// <param name="buttons">The number of button.</param>
180         /// <param name="type">The pointer type.</param>
181         /// <param name="x">x coordination to move.</param>
182         /// <param name="y">y coordination to move.</param>
183         /// <since_tizen> preview </since_tizen>
184         public void GenerateMouseEvent(int buttons, InputPointerType type, int x, int y)
185         {
186             Interop.Eutil.efl_util_input_generate_pointer(_handle, buttons, (int)type, x, y);
187         }
188
189         /// <summary>
190         /// Generate a touch event using a opened device
191         /// </summary>
192         /// <param name="index">The index of touched finger.</param>
193         /// <param name="type">The touch type.</param>
194         /// <param name="x">The x axis of touch point.</param>
195         /// <param name="y">The y axis of touch point.</param>
196         /// <since_tizen> preview </since_tizen>
197         public void GenerateTouchEvent(int index, InputTouchType type, int x, int y)
198         {
199             Interop.Eutil.efl_util_input_generate_touch(_handle, index, (int)type, x, y);
200         }
201     }
202 }