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 factory interface</summary>
10 public interface Factory :
13 Efl.Eo.IWrapper, IDisposable
15 /// <summary>Create a UI object from the necessary properties in the specified model.</summary>
16 /// <param name="model">Efl model</param>
17 /// <param name="parent">Efl canvas</param>
18 /// <returns>Created UI object</returns>
19 Eina.Future Create( Efl.Model model, Efl.Gfx.Entity parent);
20 /// <summary>Release a UI object and disconnect from models.</summary>
21 /// <param name="ui_view">Efl canvas</param>
22 /// <returns></returns>
23 void Release( Efl.Gfx.Entity ui_view);
24 System.Threading.Tasks.Task<Eina.Value> CreateAsync( Efl.Model model, Efl.Gfx.Entity parent, System.Threading.CancellationToken token=default(System.Threading.CancellationToken));
25 /// <summary>Event triggered when an item has been successfully created.</summary>
26 event EventHandler<Efl.Ui.FactoryCreatedEvt_Args> CreatedEvt;
28 ///<summary>Event argument wrapper for event <see cref="Efl.Ui.Factory.CreatedEvt"/>.</summary>
29 public class FactoryCreatedEvt_Args : EventArgs {
30 ///<summary>Actual event payload.</summary>
31 public Efl.Ui.FactoryItemCreatedEvent arg { get; set; }
33 /// <summary>Efl UI factory interface</summary>
34 sealed public class FactoryConcrete :
37 , Efl.Ui.FactoryBind, Efl.Ui.PropertyBind
39 ///<summary>Pointer to the native class description.</summary>
40 public System.IntPtr NativeClass {
42 if (((object)this).GetType() == typeof (FactoryConcrete))
43 return Efl.Ui.FactoryNativeInherit.GetEflClassStatic();
45 return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];
48 private EventHandlerList eventHandlers = new EventHandlerList();
49 private System.IntPtr handle;
50 ///<summary>Pointer to the native instance.</summary>
51 public System.IntPtr NativeHandle {
52 get { return handle; }
54 [System.Runtime.InteropServices.DllImport(efl.Libs.Efl)] internal static extern System.IntPtr
55 efl_ui_factory_interface_get();
56 ///<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>
57 public FactoryConcrete(System.IntPtr raw)
60 register_event_proxies();
62 ///<summary>Destructor.</summary>
67 ///<summary>Releases the underlying native instance.</summary>
68 void Dispose(bool disposing)
70 if (handle != System.IntPtr.Zero) {
71 Efl.Eo.Globals.efl_unref(handle);
72 handle = System.IntPtr.Zero;
75 ///<summary>Releases the underlying native instance.</summary>
79 GC.SuppressFinalize(this);
81 ///<summary>Casts obj into an instance of this type.</summary>
82 public static FactoryConcrete static_cast(Efl.Object obj)
85 throw new System.ArgumentNullException("obj");
86 return new FactoryConcrete(obj.NativeHandle);
88 ///<summary>Verifies if the given object is equal to this one.</summary>
89 public override bool Equals(object obj)
91 var other = obj as Efl.Object;
94 return this.NativeHandle == other.NativeHandle;
96 ///<summary>Gets the hash code for this object based on the native pointer it points to.</summary>
97 public override int GetHashCode()
99 return this.NativeHandle.ToInt32();
101 ///<summary>Turns the native pointer into a string representation.</summary>
102 public override String ToString()
104 return $"{this.GetType().Name}@[{this.NativeHandle.ToInt32():x}]";
106 private readonly object eventLock = new object();
107 private Dictionary<string, int> event_cb_count = new Dictionary<string, int>();
108 private bool add_cpp_event_handler(string lib, string key, Efl.EventCb evt_delegate) {
110 if (!event_cb_count.TryGetValue(key, out event_count))
111 event_cb_count[key] = event_count;
112 if (event_count == 0) {
113 IntPtr desc = Efl.EventDescription.GetNative(lib, key);
114 if (desc == IntPtr.Zero) {
115 Eina.Log.Error($"Failed to get native event {key}");
118 bool result = Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evt_delegate, System.IntPtr.Zero);
120 Eina.Log.Error($"Failed to add event proxy for event {key}");
123 Eina.Error.RaiseIfUnhandledException();
125 event_cb_count[key]++;
128 private bool remove_cpp_event_handler(string key, Efl.EventCb evt_delegate) {
130 if (!event_cb_count.TryGetValue(key, out event_count))
131 event_cb_count[key] = event_count;
132 if (event_count == 1) {
133 IntPtr desc = Efl.EventDescription.GetNative(efl.Libs.Efl, key);
134 if (desc == IntPtr.Zero) {
135 Eina.Log.Error($"Failed to get native event {key}");
138 bool result = Efl.Eo.Globals.efl_event_callback_del(handle, desc, evt_delegate, System.IntPtr.Zero);
140 Eina.Log.Error($"Failed to remove event proxy for event {key}");
143 Eina.Error.RaiseIfUnhandledException();
144 } else if (event_count == 0) {
145 Eina.Log.Error($"Trying to remove proxy for event {key} when there is nothing registered.");
148 event_cb_count[key]--;
151 private static object CreatedEvtKey = new object();
152 /// <summary>Event triggered when an item has been successfully created.</summary>
153 public event EventHandler<Efl.Ui.FactoryCreatedEvt_Args> CreatedEvt
157 string key = "_EFL_UI_FACTORY_EVENT_CREATED";
158 if (add_cpp_event_handler(efl.Libs.Efl, key, this.evt_CreatedEvt_delegate)) {
159 eventHandlers.AddHandler(CreatedEvtKey , value);
161 Eina.Log.Error($"Error adding proxy for event {key}");
166 string key = "_EFL_UI_FACTORY_EVENT_CREATED";
167 if (remove_cpp_event_handler(key, this.evt_CreatedEvt_delegate)) {
168 eventHandlers.RemoveHandler(CreatedEvtKey , value);
170 Eina.Log.Error($"Error removing proxy for event {key}");
174 ///<summary>Method to raise event CreatedEvt.</summary>
175 public void On_CreatedEvt(Efl.Ui.FactoryCreatedEvt_Args e)
177 EventHandler<Efl.Ui.FactoryCreatedEvt_Args> evt;
179 evt = (EventHandler<Efl.Ui.FactoryCreatedEvt_Args>)eventHandlers[CreatedEvtKey];
181 evt?.Invoke(this, e);
183 Efl.EventCb evt_CreatedEvt_delegate;
184 private void on_CreatedEvt_NativeCallback(System.IntPtr data, ref Efl.Event_StructInternal evt)
186 Efl.Ui.FactoryCreatedEvt_Args args = new Efl.Ui.FactoryCreatedEvt_Args();
187 args.arg = evt.Info;;
190 } catch (Exception e) {
191 Eina.Log.Error(e.ToString());
192 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
196 void register_event_proxies()
198 evt_CreatedEvt_delegate = new Efl.EventCb(on_CreatedEvt_NativeCallback);
200 /// <summary>Create a UI object from the necessary properties in the specified model.</summary>
201 /// <param name="model">Efl model</param>
202 /// <param name="parent">Efl canvas</param>
203 /// <returns>Created UI object</returns>
204 public Eina.Future Create( Efl.Model model, Efl.Gfx.Entity parent) {
205 var _ret_var = Efl.Ui.FactoryNativeInherit.efl_ui_factory_create_ptr.Value.Delegate(this.NativeHandle, model, parent);
206 Eina.Error.RaiseIfUnhandledException();
209 /// <summary>Release a UI object and disconnect from models.</summary>
210 /// <param name="ui_view">Efl canvas</param>
211 /// <returns></returns>
212 public void Release( Efl.Gfx.Entity ui_view) {
213 Efl.Ui.FactoryNativeInherit.efl_ui_factory_release_ptr.Value.Delegate(this.NativeHandle, ui_view);
214 Eina.Error.RaiseIfUnhandledException();
216 /// <summary>bind the factory with the given key string. when the data is ready or changed, factory create the object and bind the data to the key action and process promised work. Note: the input <see cref="Efl.Ui.Factory"/> need to be <see cref="Efl.Ui.PropertyBind.PropertyBind"/> at least once.</summary>
217 /// <param name="key">Key string for bind model property data</param>
218 /// <param name="factory"><see cref="Efl.Ui.Factory"/> for create and bind model property data</param>
219 /// <returns></returns>
220 public void FactoryBind( System.String key, Efl.Ui.Factory factory) {
221 Efl.Ui.FactoryBindNativeInherit.efl_ui_factory_bind_ptr.Value.Delegate(this.NativeHandle, key, factory);
222 Eina.Error.RaiseIfUnhandledException();
224 /// <summary>bind property data with the given key string. when the data is ready or changed, bind the data to the key action and process promised work.</summary>
225 /// <param name="key">key string for bind model property data</param>
226 /// <param name="property">Model property name</param>
227 /// <returns></returns>
228 public void PropertyBind( System.String key, System.String property) {
229 Efl.Ui.PropertyBindNativeInherit.efl_ui_property_bind_ptr.Value.Delegate(this.NativeHandle, key, property);
230 Eina.Error.RaiseIfUnhandledException();
232 public System.Threading.Tasks.Task<Eina.Value> CreateAsync( Efl.Model model, Efl.Gfx.Entity parent, System.Threading.CancellationToken token=default(System.Threading.CancellationToken))
234 Eina.Future future = Create( model, parent);
235 return Efl.Eo.Globals.WrapAsync(future, token);
238 public class FactoryNativeInherit : Efl.Eo.NativeClass{
239 public static Efl.Eo.NativeModule _Module = new Efl.Eo.NativeModule(efl.Libs.Efl);
240 public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)
242 var descs = new System.Collections.Generic.List<Efl_Op_Description>();
243 if (efl_ui_factory_create_static_delegate == null)
244 efl_ui_factory_create_static_delegate = new efl_ui_factory_create_delegate(create);
245 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_factory_create"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_factory_create_static_delegate)});
246 if (efl_ui_factory_release_static_delegate == null)
247 efl_ui_factory_release_static_delegate = new efl_ui_factory_release_delegate(release);
248 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_factory_release"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_factory_release_static_delegate)});
249 if (efl_ui_factory_bind_static_delegate == null)
250 efl_ui_factory_bind_static_delegate = new efl_ui_factory_bind_delegate(factory_bind);
251 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_factory_bind"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_factory_bind_static_delegate)});
252 if (efl_ui_property_bind_static_delegate == null)
253 efl_ui_property_bind_static_delegate = new efl_ui_property_bind_delegate(property_bind);
254 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_property_bind"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_property_bind_static_delegate)});
257 public override IntPtr GetEflClass()
259 return Efl.Ui.FactoryConcrete.efl_ui_factory_interface_get();
261 public static IntPtr GetEflClassStatic()
263 return Efl.Ui.FactoryConcrete.efl_ui_factory_interface_get();
267 [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.FutureMarshaler))] private delegate Eina.Future efl_ui_factory_create_delegate(System.IntPtr obj, System.IntPtr pd, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.ModelConcrete, Efl.Eo.NonOwnTag>))] Efl.Model model, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] Efl.Gfx.Entity parent);
270 [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.FutureMarshaler))] public delegate Eina.Future efl_ui_factory_create_api_delegate(System.IntPtr obj, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.ModelConcrete, Efl.Eo.NonOwnTag>))] Efl.Model model, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] Efl.Gfx.Entity parent);
271 public static Efl.Eo.FunctionWrapper<efl_ui_factory_create_api_delegate> efl_ui_factory_create_ptr = new Efl.Eo.FunctionWrapper<efl_ui_factory_create_api_delegate>(_Module, "efl_ui_factory_create");
272 private static Eina.Future create(System.IntPtr obj, System.IntPtr pd, Efl.Model model, Efl.Gfx.Entity parent)
274 Eina.Log.Debug("function efl_ui_factory_create was called");
275 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
276 if(wrapper != null) {
277 Eina.Future _ret_var = default( Eina.Future);
279 _ret_var = ((Factory)wrapper).Create( model, parent);
280 } catch (Exception e) {
281 Eina.Log.Warning($"Callback error: {e.ToString()}");
282 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
286 return efl_ui_factory_create_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), model, parent);
289 private static efl_ui_factory_create_delegate efl_ui_factory_create_static_delegate;
292 private delegate void efl_ui_factory_release_delegate(System.IntPtr obj, System.IntPtr pd, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] Efl.Gfx.Entity ui_view);
295 public delegate void efl_ui_factory_release_api_delegate(System.IntPtr obj, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] Efl.Gfx.Entity ui_view);
296 public static Efl.Eo.FunctionWrapper<efl_ui_factory_release_api_delegate> efl_ui_factory_release_ptr = new Efl.Eo.FunctionWrapper<efl_ui_factory_release_api_delegate>(_Module, "efl_ui_factory_release");
297 private static void release(System.IntPtr obj, System.IntPtr pd, Efl.Gfx.Entity ui_view)
299 Eina.Log.Debug("function efl_ui_factory_release was called");
300 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
301 if(wrapper != null) {
304 ((Factory)wrapper).Release( ui_view);
305 } catch (Exception e) {
306 Eina.Log.Warning($"Callback error: {e.ToString()}");
307 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
310 efl_ui_factory_release_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), ui_view);
313 private static efl_ui_factory_release_delegate efl_ui_factory_release_static_delegate;
316 private delegate void efl_ui_factory_bind_delegate(System.IntPtr obj, System.IntPtr pd, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))] System.String key, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Ui.FactoryConcrete, Efl.Eo.NonOwnTag>))] Efl.Ui.Factory factory);
319 public delegate void efl_ui_factory_bind_api_delegate(System.IntPtr obj, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))] System.String key, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Ui.FactoryConcrete, Efl.Eo.NonOwnTag>))] Efl.Ui.Factory factory);
320 public static Efl.Eo.FunctionWrapper<efl_ui_factory_bind_api_delegate> efl_ui_factory_bind_ptr = new Efl.Eo.FunctionWrapper<efl_ui_factory_bind_api_delegate>(_Module, "efl_ui_factory_bind");
321 private static void factory_bind(System.IntPtr obj, System.IntPtr pd, System.String key, Efl.Ui.Factory factory)
323 Eina.Log.Debug("function efl_ui_factory_bind was called");
324 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
325 if(wrapper != null) {
328 ((Factory)wrapper).FactoryBind( key, factory);
329 } catch (Exception e) {
330 Eina.Log.Warning($"Callback error: {e.ToString()}");
331 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
334 efl_ui_factory_bind_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), key, factory);
337 private static efl_ui_factory_bind_delegate efl_ui_factory_bind_static_delegate;
340 private delegate void efl_ui_property_bind_delegate(System.IntPtr obj, System.IntPtr pd, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))] System.String key, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))] System.String property);
343 public delegate void efl_ui_property_bind_api_delegate(System.IntPtr obj, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))] System.String key, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))] System.String property);
344 public static Efl.Eo.FunctionWrapper<efl_ui_property_bind_api_delegate> efl_ui_property_bind_ptr = new Efl.Eo.FunctionWrapper<efl_ui_property_bind_api_delegate>(_Module, "efl_ui_property_bind");
345 private static void property_bind(System.IntPtr obj, System.IntPtr pd, System.String key, System.String property)
347 Eina.Log.Debug("function efl_ui_property_bind was called");
348 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
349 if(wrapper != null) {
352 ((Factory)wrapper).PropertyBind( key, property);
353 } catch (Exception e) {
354 Eina.Log.Warning($"Callback error: {e.ToString()}");
355 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
358 efl_ui_property_bind_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), key, property);
361 private static efl_ui_property_bind_delegate efl_ui_property_bind_static_delegate;
364 namespace Efl { namespace Ui {
365 /// <summary>EFL Ui Factory event structure provided when an item was just created.</summary>
366 [StructLayout(LayoutKind.Sequential)]
367 public struct FactoryItemCreatedEvent
369 /// <summary>The model already set on the new item.</summary>
370 public Efl.Model Model;
371 /// <summary>The item that was just created.</summary>
372 public Efl.Gfx.Entity Item;
373 ///<summary>Constructor for FactoryItemCreatedEvent.</summary>
374 public FactoryItemCreatedEvent(
375 Efl.Model Model=default(Efl.Model),
376 Efl.Gfx.Entity Item=default(Efl.Gfx.Entity) )
381 public static implicit operator FactoryItemCreatedEvent(IntPtr ptr)
383 var tmp = (FactoryItemCreatedEvent_StructInternal)Marshal.PtrToStructure(ptr, typeof(FactoryItemCreatedEvent_StructInternal));
384 return FactoryItemCreatedEvent_StructConversion.ToManaged(tmp);
387 ///<summary>Internal wrapper for struct FactoryItemCreatedEvent.</summary>
388 [StructLayout(LayoutKind.Sequential)]
389 public struct FactoryItemCreatedEvent_StructInternal
391 ///<summary>Internal wrapper for field Model</summary>
392 public System.IntPtr Model;
393 ///<summary>Internal wrapper for field Item</summary>
394 public System.IntPtr Item;
395 ///<summary>Implicit conversion to the internal/marshalling representation.</summary>
396 public static implicit operator FactoryItemCreatedEvent(FactoryItemCreatedEvent_StructInternal struct_)
398 return FactoryItemCreatedEvent_StructConversion.ToManaged(struct_);
400 ///<summary>Implicit conversion to the managed representation.</summary>
401 public static implicit operator FactoryItemCreatedEvent_StructInternal(FactoryItemCreatedEvent struct_)
403 return FactoryItemCreatedEvent_StructConversion.ToInternal(struct_);
406 /// <summary>Conversion class for struct FactoryItemCreatedEvent</summary>
407 public static class FactoryItemCreatedEvent_StructConversion
409 internal static FactoryItemCreatedEvent_StructInternal ToInternal(FactoryItemCreatedEvent _external_struct)
411 var _internal_struct = new FactoryItemCreatedEvent_StructInternal();
413 _internal_struct.Model = _external_struct.Model.NativeHandle;
414 _internal_struct.Item = _external_struct.Item.NativeHandle;
416 return _internal_struct;
419 internal static FactoryItemCreatedEvent ToManaged(FactoryItemCreatedEvent_StructInternal _internal_struct)
421 var _external_struct = new FactoryItemCreatedEvent();
424 _external_struct.Model = (Efl.ModelConcrete) System.Activator.CreateInstance(typeof(Efl.ModelConcrete), new System.Object[] {_internal_struct.Model});
425 Efl.Eo.Globals.efl_ref(_internal_struct.Model);
428 _external_struct.Item = (Efl.Gfx.EntityConcrete) System.Activator.CreateInstance(typeof(Efl.Gfx.EntityConcrete), new System.Object[] {_internal_struct.Item});
429 Efl.Eo.Globals.efl_ref(_internal_struct.Item);
432 return _external_struct;