1 #pragma warning disable CS1591
3 using System.Runtime.InteropServices;
4 using System.Collections.Generic;
6 using System.ComponentModel;
7 namespace Efl { namespace Ui {
8 /// <summary>Efl Ui Selection class</summary>
9 [ISelectionNativeInherit]
10 public interface ISelection :
11 Efl.Eo.IWrapper, IDisposable
13 /// <summary>Set the selection data to the object</summary>
14 /// <param name="type">Selection Type</param>
15 /// <param name="format">Selection Format</param>
16 /// <param name="data">Selection data</param>
17 /// <param name="seat">Specified seat for multiple seats case.</param>
18 /// <returns>Future for tracking when the selection is lost</returns>
19 Eina.Future SetSelection( Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Eina.Slice data, uint seat);
20 /// <summary>Get the data from the object that has selection</summary>
21 /// <param name="type">Selection Type</param>
22 /// <param name="format">Selection Format</param>
23 /// <param name="data_func">Data ready function pointer</param>
24 /// <param name="seat">Specified seat for multiple seats case.</param>
25 /// <returns></returns>
26 void GetSelection( Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Efl.Ui.SelectionDataReady data_func, uint seat);
27 /// <summary>Clear the selection data from the object</summary>
28 /// <param name="type">Selection Type</param>
29 /// <param name="seat">Specified seat for multiple seats case.</param>
30 /// <returns></returns>
31 void ClearSelection( Efl.Ui.SelectionType type, uint seat);
32 /// <summary>Determine whether the selection data has owner</summary>
33 /// <param name="type">Selection type</param>
34 /// <param name="seat">Specified seat for multiple seats case.</param>
35 /// <returns>EINA_TRUE if there is object owns selection, otherwise EINA_FALSE</returns>
36 bool HasOwner( Efl.Ui.SelectionType type, uint seat);
37 System.Threading.Tasks.Task<Eina.Value> SetSelectionAsync( Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Eina.Slice data, uint seat, System.Threading.CancellationToken token=default(System.Threading.CancellationToken));
38 /// <summary>Called when display server's selection has changed</summary>
39 event EventHandler<Efl.Ui.ISelectionWmSelectionChangedEvt_Args> WmSelectionChangedEvt;
41 ///<summary>Event argument wrapper for event <see cref="Efl.Ui.ISelection.WmSelectionChangedEvt"/>.</summary>
42 public class ISelectionWmSelectionChangedEvt_Args : EventArgs {
43 ///<summary>Actual event payload.</summary>
44 public Efl.Ui.SelectionChanged arg { get; set; }
46 /// <summary>Efl Ui Selection class</summary>
47 sealed public class ISelectionConcrete :
52 ///<summary>Pointer to the native class description.</summary>
53 public System.IntPtr NativeClass {
55 if (((object)this).GetType() == typeof (ISelectionConcrete))
56 return Efl.Ui.ISelectionNativeInherit.GetEflClassStatic();
58 return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];
61 private EventHandlerList eventHandlers = new EventHandlerList();
62 private System.IntPtr handle;
63 ///<summary>Pointer to the native instance.</summary>
64 public System.IntPtr NativeHandle {
65 get { return handle; }
67 [System.Runtime.InteropServices.DllImport(efl.Libs.Elementary)] internal static extern System.IntPtr
68 efl_ui_selection_mixin_get();
69 ///<summary>Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.</summary>
70 private ISelectionConcrete(System.IntPtr raw)
73 RegisterEventProxies();
75 ///<summary>Destructor.</summary>
80 ///<summary>Releases the underlying native instance.</summary>
81 void Dispose(bool disposing)
83 if (handle != System.IntPtr.Zero) {
84 Efl.Eo.Globals.efl_unref(handle);
85 handle = System.IntPtr.Zero;
88 ///<summary>Releases the underlying native instance.</summary>
92 GC.SuppressFinalize(this);
94 ///<summary>Verifies if the given object is equal to this one.</summary>
95 public override bool Equals(object obj)
97 var other = obj as Efl.Object;
100 return this.NativeHandle == other.NativeHandle;
102 ///<summary>Gets the hash code for this object based on the native pointer it points to.</summary>
103 public override int GetHashCode()
105 return this.NativeHandle.ToInt32();
107 ///<summary>Turns the native pointer into a string representation.</summary>
108 public override String ToString()
110 return $"{this.GetType().Name}@[{this.NativeHandle.ToInt32():x}]";
112 private readonly object eventLock = new object();
113 private Dictionary<string, int> event_cb_count = new Dictionary<string, int>();
114 ///<summary>Adds a new event handler, registering it to the native event. For internal use only.</summary>
115 ///<param name="lib">The name of the native library definining the event.</param>
116 ///<param name="key">The name of the native event.</param>
117 ///<param name="evt_delegate">The delegate to be called on event raising.</param>
118 ///<returns>True if the delegate was successfully registered.</returns>
119 private bool AddNativeEventHandler(string lib, string key, Efl.EventCb evt_delegate) {
121 if (!event_cb_count.TryGetValue(key, out event_count))
122 event_cb_count[key] = event_count;
123 if (event_count == 0) {
124 IntPtr desc = Efl.EventDescription.GetNative(lib, key);
125 if (desc == IntPtr.Zero) {
126 Eina.Log.Error($"Failed to get native event {key}");
129 bool result = Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evt_delegate, System.IntPtr.Zero);
131 Eina.Log.Error($"Failed to add event proxy for event {key}");
134 Eina.Error.RaiseIfUnhandledException();
136 event_cb_count[key]++;
139 ///<summary>Removes the given event handler for the given event. For internal use only.</summary>
140 ///<param name="key">The name of the native event.</param>
141 ///<param name="evt_delegate">The delegate to be removed.</param>
142 ///<returns>True if the delegate was successfully registered.</returns>
143 private bool RemoveNativeEventHandler(string key, Efl.EventCb evt_delegate) {
145 if (!event_cb_count.TryGetValue(key, out event_count))
146 event_cb_count[key] = event_count;
147 if (event_count == 1) {
148 IntPtr desc = Efl.EventDescription.GetNative(efl.Libs.Elementary, key);
149 if (desc == IntPtr.Zero) {
150 Eina.Log.Error($"Failed to get native event {key}");
153 bool result = Efl.Eo.Globals.efl_event_callback_del(handle, desc, evt_delegate, System.IntPtr.Zero);
155 Eina.Log.Error($"Failed to remove event proxy for event {key}");
158 Eina.Error.RaiseIfUnhandledException();
159 } else if (event_count == 0) {
160 Eina.Log.Error($"Trying to remove proxy for event {key} when there is nothing registered.");
163 event_cb_count[key]--;
166 private static object WmSelectionChangedEvtKey = new object();
167 /// <summary>Called when display server's selection has changed</summary>
168 public event EventHandler<Efl.Ui.ISelectionWmSelectionChangedEvt_Args> WmSelectionChangedEvt
172 string key = "_EFL_UI_SELECTION_EVENT_WM_SELECTION_CHANGED";
173 if (AddNativeEventHandler(efl.Libs.Elementary, key, this.evt_WmSelectionChangedEvt_delegate)) {
174 eventHandlers.AddHandler(WmSelectionChangedEvtKey , value);
176 Eina.Log.Error($"Error adding proxy for event {key}");
181 string key = "_EFL_UI_SELECTION_EVENT_WM_SELECTION_CHANGED";
182 if (RemoveNativeEventHandler(key, this.evt_WmSelectionChangedEvt_delegate)) {
183 eventHandlers.RemoveHandler(WmSelectionChangedEvtKey , value);
185 Eina.Log.Error($"Error removing proxy for event {key}");
189 ///<summary>Method to raise event WmSelectionChangedEvt.</summary>
190 public void On_WmSelectionChangedEvt(Efl.Ui.ISelectionWmSelectionChangedEvt_Args e)
192 EventHandler<Efl.Ui.ISelectionWmSelectionChangedEvt_Args> evt;
194 evt = (EventHandler<Efl.Ui.ISelectionWmSelectionChangedEvt_Args>)eventHandlers[WmSelectionChangedEvtKey];
196 evt?.Invoke(this, e);
198 Efl.EventCb evt_WmSelectionChangedEvt_delegate;
199 private void on_WmSelectionChangedEvt_NativeCallback(System.IntPtr data, ref Efl.Event.NativeStruct evt)
201 Efl.Ui.ISelectionWmSelectionChangedEvt_Args args = new Efl.Ui.ISelectionWmSelectionChangedEvt_Args();
202 args.arg = evt.Info;;
204 On_WmSelectionChangedEvt(args);
205 } catch (Exception e) {
206 Eina.Log.Error(e.ToString());
207 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
211 ///<summary>Register the Eo event wrappers making the bridge to C# events. Internal usage only.</summary>
212 void RegisterEventProxies()
214 evt_WmSelectionChangedEvt_delegate = new Efl.EventCb(on_WmSelectionChangedEvt_NativeCallback);
216 /// <summary>Set the selection data to the object</summary>
217 /// <param name="type">Selection Type</param>
218 /// <param name="format">Selection Format</param>
219 /// <param name="data">Selection data</param>
220 /// <param name="seat">Specified seat for multiple seats case.</param>
221 /// <returns>Future for tracking when the selection is lost</returns>
222 public Eina.Future SetSelection( Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Eina.Slice data, uint seat) {
223 var _ret_var = Efl.Ui.ISelectionNativeInherit.efl_ui_selection_set_ptr.Value.Delegate(this.NativeHandle, type, format, data, seat);
224 Eina.Error.RaiseIfUnhandledException();
227 /// <summary>Get the data from the object that has selection</summary>
228 /// <param name="type">Selection Type</param>
229 /// <param name="format">Selection Format</param>
230 /// <param name="data_func">Data ready function pointer</param>
231 /// <param name="seat">Specified seat for multiple seats case.</param>
232 /// <returns></returns>
233 public void GetSelection( Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Efl.Ui.SelectionDataReady data_func, uint seat) {
234 GCHandle data_func_handle = GCHandle.Alloc(data_func);
235 Efl.Ui.ISelectionNativeInherit.efl_ui_selection_get_ptr.Value.Delegate(this.NativeHandle, type, format, GCHandle.ToIntPtr(data_func_handle), Efl.Ui.SelectionDataReadyWrapper.Cb, Efl.Eo.Globals.free_gchandle, seat);
236 Eina.Error.RaiseIfUnhandledException();
238 /// <summary>Clear the selection data from the object</summary>
239 /// <param name="type">Selection Type</param>
240 /// <param name="seat">Specified seat for multiple seats case.</param>
241 /// <returns></returns>
242 public void ClearSelection( Efl.Ui.SelectionType type, uint seat) {
243 Efl.Ui.ISelectionNativeInherit.efl_ui_selection_clear_ptr.Value.Delegate(this.NativeHandle, type, seat);
244 Eina.Error.RaiseIfUnhandledException();
246 /// <summary>Determine whether the selection data has owner</summary>
247 /// <param name="type">Selection type</param>
248 /// <param name="seat">Specified seat for multiple seats case.</param>
249 /// <returns>EINA_TRUE if there is object owns selection, otherwise EINA_FALSE</returns>
250 public bool HasOwner( Efl.Ui.SelectionType type, uint seat) {
251 var _ret_var = Efl.Ui.ISelectionNativeInherit.efl_ui_selection_has_owner_ptr.Value.Delegate(this.NativeHandle, type, seat);
252 Eina.Error.RaiseIfUnhandledException();
255 public System.Threading.Tasks.Task<Eina.Value> SetSelectionAsync( Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Eina.Slice data, uint seat, System.Threading.CancellationToken token=default(System.Threading.CancellationToken))
257 Eina.Future future = SetSelection( type, format, data, seat);
258 return Efl.Eo.Globals.WrapAsync(future, token);
260 private static IntPtr GetEflClassStatic()
262 return Efl.Ui.ISelectionConcrete.efl_ui_selection_mixin_get();
265 public class ISelectionNativeInherit : Efl.Eo.NativeClass{
266 public static Efl.Eo.NativeModule _Module = new Efl.Eo.NativeModule(efl.Libs.Elementary);
267 public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)
269 var descs = new System.Collections.Generic.List<Efl_Op_Description>();
270 var methods = Efl.Eo.Globals.GetUserMethods(type);
271 if (efl_ui_selection_set_static_delegate == null)
272 efl_ui_selection_set_static_delegate = new efl_ui_selection_set_delegate(selection_set);
273 if (methods.FirstOrDefault(m => m.Name == "SetSelection") != null)
274 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_selection_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_selection_set_static_delegate)});
275 if (efl_ui_selection_get_static_delegate == null)
276 efl_ui_selection_get_static_delegate = new efl_ui_selection_get_delegate(selection_get);
277 if (methods.FirstOrDefault(m => m.Name == "GetSelection") != null)
278 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_selection_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_selection_get_static_delegate)});
279 if (efl_ui_selection_clear_static_delegate == null)
280 efl_ui_selection_clear_static_delegate = new efl_ui_selection_clear_delegate(selection_clear);
281 if (methods.FirstOrDefault(m => m.Name == "ClearSelection") != null)
282 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_selection_clear"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_selection_clear_static_delegate)});
283 if (efl_ui_selection_has_owner_static_delegate == null)
284 efl_ui_selection_has_owner_static_delegate = new efl_ui_selection_has_owner_delegate(has_owner);
285 if (methods.FirstOrDefault(m => m.Name == "HasOwner") != null)
286 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_selection_has_owner"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_selection_has_owner_static_delegate)});
289 public override IntPtr GetEflClass()
291 return Efl.Ui.ISelectionConcrete.efl_ui_selection_mixin_get();
293 public static IntPtr GetEflClassStatic()
295 return Efl.Ui.ISelectionConcrete.efl_ui_selection_mixin_get();
299 [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.FutureMarshaler))] private delegate Eina.Future efl_ui_selection_set_delegate(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Eina.Slice data, uint seat);
302 [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.FutureMarshaler))] public delegate Eina.Future efl_ui_selection_set_api_delegate(System.IntPtr obj, Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Eina.Slice data, uint seat);
303 public static Efl.Eo.FunctionWrapper<efl_ui_selection_set_api_delegate> efl_ui_selection_set_ptr = new Efl.Eo.FunctionWrapper<efl_ui_selection_set_api_delegate>(_Module, "efl_ui_selection_set");
304 private static Eina.Future selection_set(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Eina.Slice data, uint seat)
306 Eina.Log.Debug("function efl_ui_selection_set was called");
307 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd);
308 if(wrapper != null) {
309 Eina.Future _ret_var = default( Eina.Future);
311 _ret_var = ((ISelectionConcrete)wrapper).SetSelection( type, format, data, seat);
312 } catch (Exception e) {
313 Eina.Log.Warning($"Callback error: {e.ToString()}");
314 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
318 return efl_ui_selection_set_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), type, format, data, seat);
321 private static efl_ui_selection_set_delegate efl_ui_selection_set_static_delegate;
324 private delegate void efl_ui_selection_get_delegate(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, IntPtr data_func_data, Efl.Ui.SelectionDataReadyInternal data_func, EinaFreeCb data_func_free_cb, uint seat);
327 public delegate void efl_ui_selection_get_api_delegate(System.IntPtr obj, Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, IntPtr data_func_data, Efl.Ui.SelectionDataReadyInternal data_func, EinaFreeCb data_func_free_cb, uint seat);
328 public static Efl.Eo.FunctionWrapper<efl_ui_selection_get_api_delegate> efl_ui_selection_get_ptr = new Efl.Eo.FunctionWrapper<efl_ui_selection_get_api_delegate>(_Module, "efl_ui_selection_get");
329 private static void selection_get(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, IntPtr data_func_data, Efl.Ui.SelectionDataReadyInternal data_func, EinaFreeCb data_func_free_cb, uint seat)
331 Eina.Log.Debug("function efl_ui_selection_get was called");
332 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd);
333 if(wrapper != null) {
334 Efl.Ui.SelectionDataReadyWrapper data_func_wrapper = new Efl.Ui.SelectionDataReadyWrapper(data_func, data_func_data, data_func_free_cb);
337 ((ISelectionConcrete)wrapper).GetSelection( type, format, data_func_wrapper.ManagedCb, seat);
338 } catch (Exception e) {
339 Eina.Log.Warning($"Callback error: {e.ToString()}");
340 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
343 efl_ui_selection_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), type, format, data_func_data, data_func, data_func_free_cb, seat);
346 private static efl_ui_selection_get_delegate efl_ui_selection_get_static_delegate;
349 private delegate void efl_ui_selection_clear_delegate(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, uint seat);
352 public delegate void efl_ui_selection_clear_api_delegate(System.IntPtr obj, Efl.Ui.SelectionType type, uint seat);
353 public static Efl.Eo.FunctionWrapper<efl_ui_selection_clear_api_delegate> efl_ui_selection_clear_ptr = new Efl.Eo.FunctionWrapper<efl_ui_selection_clear_api_delegate>(_Module, "efl_ui_selection_clear");
354 private static void selection_clear(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, uint seat)
356 Eina.Log.Debug("function efl_ui_selection_clear was called");
357 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd);
358 if(wrapper != null) {
361 ((ISelectionConcrete)wrapper).ClearSelection( type, seat);
362 } catch (Exception e) {
363 Eina.Log.Warning($"Callback error: {e.ToString()}");
364 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
367 efl_ui_selection_clear_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), type, seat);
370 private static efl_ui_selection_clear_delegate efl_ui_selection_clear_static_delegate;
373 [return: MarshalAs(UnmanagedType.U1)] private delegate bool efl_ui_selection_has_owner_delegate(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, uint seat);
376 [return: MarshalAs(UnmanagedType.U1)] public delegate bool efl_ui_selection_has_owner_api_delegate(System.IntPtr obj, Efl.Ui.SelectionType type, uint seat);
377 public static Efl.Eo.FunctionWrapper<efl_ui_selection_has_owner_api_delegate> efl_ui_selection_has_owner_ptr = new Efl.Eo.FunctionWrapper<efl_ui_selection_has_owner_api_delegate>(_Module, "efl_ui_selection_has_owner");
378 private static bool has_owner(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, uint seat)
380 Eina.Log.Debug("function efl_ui_selection_has_owner was called");
381 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd);
382 if(wrapper != null) {
383 bool _ret_var = default(bool);
385 _ret_var = ((ISelectionConcrete)wrapper).HasOwner( type, seat);
386 } catch (Exception e) {
387 Eina.Log.Warning($"Callback error: {e.ToString()}");
388 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
392 return efl_ui_selection_has_owner_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), type, seat);
395 private static efl_ui_selection_has_owner_delegate efl_ui_selection_has_owner_static_delegate;