2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
25 /// The EcoreEventType is a type of EcoreEvent.
26 /// It includes some predefined instance.
28 /// <since_tizen> preview </since_tizen>
29 [Obsolete("This has been deprecated in API12")]
30 public class EcoreEventType
33 /// Key down Ecore event type.
35 /// <since_tizen> preview </since_tizen>
36 [Obsolete("This has been deprecated in API12")]
37 public static readonly EcoreEventType KeyDown = new EcoreEventType(Interop.Libraries.EcoreInput, "ECORE_EVENT_KEY_DOWN");
39 /// Key Up Ecore event type.
41 /// <since_tizen> preview </since_tizen>
42 [Obsolete("This has been deprecated in API12")]
43 public static readonly EcoreEventType KeyUp = new EcoreEventType(Interop.Libraries.EcoreInput, "ECORE_EVENT_KEY_UP");
45 /// Mouse Button Down Ecore event type.
47 /// <since_tizen> preview </since_tizen>
48 [Obsolete("This has been deprecated in API12")]
49 public static readonly EcoreEventType MouseButtonDown = new EcoreEventType(Interop.Libraries.EcoreInput, "ECORE_EVENT_MOUSE_BUTTON_DOWN");
51 /// Mouse Button Up Ecore event type.
53 /// <since_tizen> preview </since_tizen>
54 [Obsolete("This has been deprecated in API12")]
55 public static readonly EcoreEventType MouseButtonUp = new EcoreEventType(Interop.Libraries.EcoreInput, "ECORE_EVENT_MOUSE_BUTTON_UP");
57 /// Mouse Button Cancel Ecore event type.
59 /// <since_tizen> preview </since_tizen>
60 [Obsolete("This has been deprecated in API12")]
61 public static readonly EcoreEventType MouseButtonCancel = new EcoreEventType(Interop.Libraries.EcoreInput, "ECORE_EVENT_MOUSE_BUTTON_CANCEL");
63 /// Mouse Move Ecore event type.
65 /// <since_tizen> preview </since_tizen>
66 [Obsolete("This has been deprecated in API12")]
67 public static readonly EcoreEventType MouseMove = new EcoreEventType(Interop.Libraries.EcoreInput, "ECORE_EVENT_MOUSE_MOVE");
69 /// Mouse Wheel Ecore event type.
71 /// <since_tizen> preview </since_tizen>
72 [Obsolete("This has been deprecated in API12")]
73 public static readonly EcoreEventType MouseWheel = new EcoreEventType(Interop.Libraries.EcoreInput, "ECORE_EVENT_MOUSE_WHEEL");
75 /// Mouse In Ecore event type.
77 /// <since_tizen> preview </since_tizen>
78 [Obsolete("This has been deprecated in API12")]
79 public static readonly EcoreEventType MouseIn = new EcoreEventType(Interop.Libraries.EcoreInput, "ECORE_EVENT_MOUSE_IN");
81 /// Mouse Out Ecore event type.
83 /// <since_tizen> preview </since_tizen>
84 [Obsolete("This has been deprecated in API12")]
85 public static readonly EcoreEventType MouseOut = new EcoreEventType(Interop.Libraries.EcoreInput, "ECORE_EVENT_MOUSE_OUT");
89 private int _typeValue;
91 private EcoreEventType(string lib, string name)
99 /// Gets the value associated with the specified type.
101 /// <returns>The value of type.</returns>
102 /// <since_tizen> preview </since_tizen>
103 [Obsolete("This has been deprecated in API12")]
104 public int GetValue()
108 IntPtr hDll = Interop.Libdl.LoadLibrary(_lib);
109 if (hDll != IntPtr.Zero)
111 IntPtr pValue = Interop.Libdl.GetProcAddress(hDll, _name);
112 if (pValue != IntPtr.Zero)
114 _typeValue = Marshal.ReadInt32(pValue);
116 Interop.Libdl.FreeLibrary(hDll);
124 /// The EcoreEvent is a class to help create events that are being notified of events.
126 /// <typeparam name="TEventArgs">Kinds of EventArgs.</typeparam>
127 /// <since_tizen> preview </since_tizen>
128 [Obsolete("This has been deprecated in API12")]
129 public class EcoreEvent<TEventArgs> : IDisposable where TEventArgs : EventArgs
132 /// EventInfoParser delegate of the EcoreEvent class.
134 /// <param name="data">IntPtr</param>
135 /// <param name="type">EcoreEventType</param>
136 /// <param name="info">IntPtr</param>
137 /// <returns></returns>
138 /// <since_tizen> preview </since_tizen>
139 [Obsolete("This has been deprecated in API12")]
140 public delegate TEventArgs EventInfoParser(IntPtr data, EcoreEventType type, IntPtr info);
142 private bool _disposed = false;
143 private EcoreEventType _eventType;
144 private readonly EventInfoParser _parser;
145 private readonly List<NativeCallback> _nativeCallbacks = new List<NativeCallback>();
148 /// Creates and initializes a new instance of the EcoreEvent class.
150 /// <param name="type">EcoreEventType</param>
151 /// <since_tizen> preview </since_tizen>
152 [Obsolete("This has been deprecated in API12")]
153 public EcoreEvent(EcoreEventType type) : this(type, null)
158 /// Creates and initializes a new instance of the EcoreEvent class.
160 /// <param name="type">EcoreEventType</param>
161 /// <param name="parser">EventInfoParser</param>
162 /// <since_tizen> preview </since_tizen>
163 [Obsolete("This has been deprecated in API12")]
164 public EcoreEvent(EcoreEventType type, EventInfoParser parser)
171 /// Destructor for the EcoreEvent class.
178 private struct NativeCallback
180 public Interop.Ecore.EcoreEventCallback callback;
181 public IntPtr nativeHandler;
182 public EventHandler<TEventArgs> eventHandler;
186 /// On Event Handler of the EcoreEvent.
188 /// <since_tizen> preview </since_tizen>
189 [Obsolete("This has been deprecated in API12")]
190 public event EventHandler<TEventArgs> On
194 EventHandler<TEventArgs> handler = value;
195 var cb = new Interop.Ecore.EcoreEventCallback((data, type, info) =>
197 TEventArgs ea = _parser == null ? (TEventArgs)EventArgs.Empty : _parser(data, _eventType, info);
201 IntPtr hNative = Interop.Ecore.ecore_event_handler_add(_eventType.GetValue(), cb, IntPtr.Zero);
202 _nativeCallbacks.Add(new NativeCallback { callback = cb, eventHandler = handler, nativeHandler = hNative });
206 EventHandler<TEventArgs> handler = value;
207 var callbacks = _nativeCallbacks.Where(cb => cb.eventHandler == handler).ToList();
208 foreach (var cb in callbacks)
210 Interop.Ecore.ecore_event_handler_del(cb.nativeHandler);
211 _nativeCallbacks.Remove(cb);
217 /// Releases all the resources currently used by this instance.
219 /// <param name="disposing">
220 /// true if the managed resources should be disposed,
223 /// <since_tizen> preview </since_tizen>
224 [Obsolete("This has been deprecated in API12")]
225 protected virtual void Dispose(bool disposing)
231 // Place holder to dispose managed state (managed objects).
233 foreach (var cb in _nativeCallbacks)
235 Interop.Ecore.ecore_event_handler_del(cb.nativeHandler);
237 _nativeCallbacks.Clear();
243 /// Destroys the current object.
245 /// <since_tizen> preview </since_tizen>
246 [Obsolete("This has been deprecated in API12")]
247 public void Dispose()
250 GC.SuppressFinalize(this);
255 /// The event class for EcoreEvent.
257 /// <since_tizen> preview </since_tizen>
258 [Obsolete("This has been deprecated in API12")]
259 public class EcoreEvent : EcoreEvent<EventArgs>
262 /// Creates and initializes a new instance of the EcoreEvent class.
264 /// <param name="type">EcoreEventType</param>
265 /// <since_tizen> preview </since_tizen>
266 [Obsolete("This has been deprecated in API12")]
267 public EcoreEvent(EcoreEventType type) : base(type)