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 [SelectionNativeInherit]
10 public interface Selection :
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"></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.SelectionSelectionChangedEvt_Args> SelectionChangedEvt;
41 ///<summary>Event argument wrapper for event <see cref="Efl.Ui.Selection.SelectionChangedEvt"/>.</summary>
42 public class SelectionSelectionChangedEvt_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 SelectionConcrete :
52 ///<summary>Pointer to the native class description.</summary>
53 public System.IntPtr NativeClass {
55 if (((object)this).GetType() == typeof (SelectionConcrete))
56 return Efl.Ui.SelectionNativeInherit.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 public SelectionConcrete(System.IntPtr raw)
73 register_event_proxies();
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>Casts obj into an instance of this type.</summary>
95 public static SelectionConcrete static_cast(Efl.Object obj)
98 throw new System.ArgumentNullException("obj");
99 return new SelectionConcrete(obj.NativeHandle);
101 ///<summary>Verifies if the given object is equal to this one.</summary>
102 public override bool Equals(object obj)
104 var other = obj as Efl.Object;
107 return this.NativeHandle == other.NativeHandle;
109 ///<summary>Gets the hash code for this object based on the native pointer it points to.</summary>
110 public override int GetHashCode()
112 return this.NativeHandle.ToInt32();
114 ///<summary>Turns the native pointer into a string representation.</summary>
115 public override String ToString()
117 return $"{this.GetType().Name}@[{this.NativeHandle.ToInt32():x}]";
119 private readonly object eventLock = new object();
120 private Dictionary<string, int> event_cb_count = new Dictionary<string, int>();
121 private bool add_cpp_event_handler(string lib, string key, Efl.EventCb evt_delegate) {
123 if (!event_cb_count.TryGetValue(key, out event_count))
124 event_cb_count[key] = event_count;
125 if (event_count == 0) {
126 IntPtr desc = Efl.EventDescription.GetNative(lib, key);
127 if (desc == IntPtr.Zero) {
128 Eina.Log.Error($"Failed to get native event {key}");
131 bool result = Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evt_delegate, System.IntPtr.Zero);
133 Eina.Log.Error($"Failed to add event proxy for event {key}");
136 Eina.Error.RaiseIfUnhandledException();
138 event_cb_count[key]++;
141 private bool remove_cpp_event_handler(string key, Efl.EventCb evt_delegate) {
143 if (!event_cb_count.TryGetValue(key, out event_count))
144 event_cb_count[key] = event_count;
145 if (event_count == 1) {
146 IntPtr desc = Efl.EventDescription.GetNative(efl.Libs.Elementary, key);
147 if (desc == IntPtr.Zero) {
148 Eina.Log.Error($"Failed to get native event {key}");
151 bool result = Efl.Eo.Globals.efl_event_callback_del(handle, desc, evt_delegate, System.IntPtr.Zero);
153 Eina.Log.Error($"Failed to remove event proxy for event {key}");
156 Eina.Error.RaiseIfUnhandledException();
157 } else if (event_count == 0) {
158 Eina.Log.Error($"Trying to remove proxy for event {key} when there is nothing registered.");
161 event_cb_count[key]--;
164 private static object SelectionChangedEvtKey = new object();
165 /// <summary>Called when display server's selection has changed</summary>
166 public event EventHandler<Efl.Ui.SelectionSelectionChangedEvt_Args> SelectionChangedEvt
170 string key = "_EFL_UI_SELECTION_EVENT_SELECTION_CHANGED";
171 if (add_cpp_event_handler(efl.Libs.Elementary, key, this.evt_SelectionChangedEvt_delegate)) {
172 eventHandlers.AddHandler(SelectionChangedEvtKey , value);
174 Eina.Log.Error($"Error adding proxy for event {key}");
179 string key = "_EFL_UI_SELECTION_EVENT_SELECTION_CHANGED";
180 if (remove_cpp_event_handler(key, this.evt_SelectionChangedEvt_delegate)) {
181 eventHandlers.RemoveHandler(SelectionChangedEvtKey , value);
183 Eina.Log.Error($"Error removing proxy for event {key}");
187 ///<summary>Method to raise event SelectionChangedEvt.</summary>
188 public void On_SelectionChangedEvt(Efl.Ui.SelectionSelectionChangedEvt_Args e)
190 EventHandler<Efl.Ui.SelectionSelectionChangedEvt_Args> evt;
192 evt = (EventHandler<Efl.Ui.SelectionSelectionChangedEvt_Args>)eventHandlers[SelectionChangedEvtKey];
194 evt?.Invoke(this, e);
196 Efl.EventCb evt_SelectionChangedEvt_delegate;
197 private void on_SelectionChangedEvt_NativeCallback(System.IntPtr data, ref Efl.Event_StructInternal evt)
199 Efl.Ui.SelectionSelectionChangedEvt_Args args = new Efl.Ui.SelectionSelectionChangedEvt_Args();
200 args.arg = evt.Info;;
202 On_SelectionChangedEvt(args);
203 } catch (Exception e) {
204 Eina.Log.Error(e.ToString());
205 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
209 void register_event_proxies()
211 evt_SelectionChangedEvt_delegate = new Efl.EventCb(on_SelectionChangedEvt_NativeCallback);
213 /// <summary>Set the selection data to the object</summary>
214 /// <param name="type">Selection Type</param>
215 /// <param name="format">Selection Format</param>
216 /// <param name="data"></param>
217 /// <param name="seat">Specified seat for multiple seats case.</param>
218 /// <returns>Future for tracking when the selection is lost</returns>
219 public Eina.Future SetSelection( Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Eina.Slice data, uint seat) {
220 var _ret_var = Efl.Ui.SelectionNativeInherit.efl_ui_selection_set_ptr.Value.Delegate(this.NativeHandle, type, format, data, seat);
221 Eina.Error.RaiseIfUnhandledException();
224 /// <summary>Get the data from the object that has selection</summary>
225 /// <param name="type">Selection Type</param>
226 /// <param name="format">Selection Format</param>
227 /// <param name="data_func">Data ready function pointer</param>
228 /// <param name="seat">Specified seat for multiple seats case.</param>
229 /// <returns></returns>
230 public void GetSelection( Efl.Ui.SelectionType type, Efl.Ui.SelectionFormat format, Efl.Ui.SelectionDataReady data_func, uint seat) {
231 GCHandle data_func_handle = GCHandle.Alloc(data_func);
232 Efl.Ui.SelectionNativeInherit.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);
233 Eina.Error.RaiseIfUnhandledException();
235 /// <summary>Clear the selection data from the object</summary>
236 /// <param name="type">Selection Type</param>
237 /// <param name="seat">Specified seat for multiple seats case.</param>
238 /// <returns></returns>
239 public void ClearSelection( Efl.Ui.SelectionType type, uint seat) {
240 Efl.Ui.SelectionNativeInherit.efl_ui_selection_clear_ptr.Value.Delegate(this.NativeHandle, type, seat);
241 Eina.Error.RaiseIfUnhandledException();
243 /// <summary>Determine whether the selection data has owner</summary>
244 /// <param name="type">Selection type</param>
245 /// <param name="seat">Specified seat for multiple seats case.</param>
246 /// <returns>EINA_TRUE if there is object owns selection, otherwise EINA_FALSE</returns>
247 public bool HasOwner( Efl.Ui.SelectionType type, uint seat) {
248 var _ret_var = Efl.Ui.SelectionNativeInherit.efl_ui_selection_has_owner_ptr.Value.Delegate(this.NativeHandle, type, seat);
249 Eina.Error.RaiseIfUnhandledException();
252 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))
254 Eina.Future future = SetSelection( type, format, data, seat);
255 return Efl.Eo.Globals.WrapAsync(future, token);
258 public class SelectionNativeInherit : Efl.Eo.NativeClass{
259 public static Efl.Eo.NativeModule _Module = new Efl.Eo.NativeModule(efl.Libs.Elementary);
260 public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)
262 var descs = new System.Collections.Generic.List<Efl_Op_Description>();
263 if (efl_ui_selection_set_static_delegate == null)
264 efl_ui_selection_set_static_delegate = new efl_ui_selection_set_delegate(selection_set);
265 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)});
266 if (efl_ui_selection_get_static_delegate == null)
267 efl_ui_selection_get_static_delegate = new efl_ui_selection_get_delegate(selection_get);
268 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)});
269 if (efl_ui_selection_clear_static_delegate == null)
270 efl_ui_selection_clear_static_delegate = new efl_ui_selection_clear_delegate(selection_clear);
271 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)});
272 if (efl_ui_selection_has_owner_static_delegate == null)
273 efl_ui_selection_has_owner_static_delegate = new efl_ui_selection_has_owner_delegate(has_owner);
274 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)});
277 public override IntPtr GetEflClass()
279 return Efl.Ui.SelectionConcrete.efl_ui_selection_mixin_get();
281 public static IntPtr GetEflClassStatic()
283 return Efl.Ui.SelectionConcrete.efl_ui_selection_mixin_get();
287 [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);
290 [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);
291 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");
292 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)
294 Eina.Log.Debug("function efl_ui_selection_set was called");
295 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
296 if(wrapper != null) {
297 Eina.Future _ret_var = default( Eina.Future);
299 _ret_var = ((SelectionConcrete)wrapper).SetSelection( type, format, data, seat);
300 } catch (Exception e) {
301 Eina.Log.Warning($"Callback error: {e.ToString()}");
302 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
306 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);
309 private static efl_ui_selection_set_delegate efl_ui_selection_set_static_delegate;
312 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);
315 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);
316 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");
317 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)
319 Eina.Log.Debug("function efl_ui_selection_get was called");
320 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
321 if(wrapper != null) {
322 Efl.Ui.SelectionDataReadyWrapper data_func_wrapper = new Efl.Ui.SelectionDataReadyWrapper(data_func, data_func_data, data_func_free_cb);
325 ((SelectionConcrete)wrapper).GetSelection( type, format, data_func_wrapper.ManagedCb, seat);
326 } catch (Exception e) {
327 Eina.Log.Warning($"Callback error: {e.ToString()}");
328 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
331 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);
334 private static efl_ui_selection_get_delegate efl_ui_selection_get_static_delegate;
337 private delegate void efl_ui_selection_clear_delegate(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, uint seat);
340 public delegate void efl_ui_selection_clear_api_delegate(System.IntPtr obj, Efl.Ui.SelectionType type, uint seat);
341 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");
342 private static void selection_clear(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, uint seat)
344 Eina.Log.Debug("function efl_ui_selection_clear was called");
345 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
346 if(wrapper != null) {
349 ((SelectionConcrete)wrapper).ClearSelection( type, seat);
350 } catch (Exception e) {
351 Eina.Log.Warning($"Callback error: {e.ToString()}");
352 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
355 efl_ui_selection_clear_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), type, seat);
358 private static efl_ui_selection_clear_delegate efl_ui_selection_clear_static_delegate;
361 [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);
364 [return: MarshalAs(UnmanagedType.U1)] public delegate bool efl_ui_selection_has_owner_api_delegate(System.IntPtr obj, Efl.Ui.SelectionType type, uint seat);
365 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");
366 private static bool has_owner(System.IntPtr obj, System.IntPtr pd, Efl.Ui.SelectionType type, uint seat)
368 Eina.Log.Debug("function efl_ui_selection_has_owner was called");
369 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
370 if(wrapper != null) {
371 bool _ret_var = default(bool);
373 _ret_var = ((SelectionConcrete)wrapper).HasOwner( type, seat);
374 } catch (Exception e) {
375 Eina.Log.Warning($"Callback error: {e.ToString()}");
376 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
380 return efl_ui_selection_has_owner_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), type, seat);
383 private static efl_ui_selection_has_owner_delegate efl_ui_selection_has_owner_static_delegate;