1 #pragma warning disable CS1591
3 using System.Runtime.InteropServices;
4 using System.Collections.Generic;
6 using System.ComponentModel;
8 /// <summary>Common interface for objects that have a (single) content.
9 /// This is used for the default content part of widgets, as well as for individual parts through <see cref="Efl.Part"/>.</summary>
10 [ContentNativeInherit]
11 public interface Content :
12 Efl.Eo.IWrapper, IDisposable
14 /// <summary>Swallowed sub-object contained in this object.</summary>
15 /// <returns>The object to swallow.</returns>
16 Efl.Gfx.Entity GetContent();
17 /// <summary>Swallowed sub-object contained in this object.</summary>
18 /// <param name="content">The object to swallow.</param>
19 /// <returns><c>true</c> on success, <c>false</c> otherwise</returns>
20 bool SetContent( Efl.Gfx.Entity content);
21 /// <summary>Unswallow the object in the current container and return it.</summary>
22 /// <returns>Unswallowed object</returns>
23 Efl.Gfx.Entity UnsetContent();
24 /// <summary>Sent after the content is set or unset using the current content object.</summary>
25 event EventHandler<Efl.ContentContentChangedEvt_Args> ContentChangedEvt;
26 /// <summary>Swallowed sub-object contained in this object.</summary>
27 /// <value>The object to swallow.</value>
28 Efl.Gfx.Entity Content {
33 ///<summary>Event argument wrapper for event <see cref="Efl.Content.ContentChangedEvt"/>.</summary>
34 public class ContentContentChangedEvt_Args : EventArgs {
35 ///<summary>Actual event payload.</summary>
36 public Efl.Gfx.Entity arg { get; set; }
38 /// <summary>Common interface for objects that have a (single) content.
39 /// This is used for the default content part of widgets, as well as for individual parts through <see cref="Efl.Part"/>.</summary>
40 sealed public class ContentConcrete :
45 ///<summary>Pointer to the native class description.</summary>
46 public System.IntPtr NativeClass {
48 if (((object)this).GetType() == typeof (ContentConcrete))
49 return Efl.ContentNativeInherit.GetEflClassStatic();
51 return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];
54 private EventHandlerList eventHandlers = new EventHandlerList();
55 private System.IntPtr handle;
56 ///<summary>Pointer to the native instance.</summary>
57 public System.IntPtr NativeHandle {
58 get { return handle; }
60 [System.Runtime.InteropServices.DllImport(efl.Libs.Efl)] internal static extern System.IntPtr
61 efl_content_interface_get();
62 ///<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>
63 public ContentConcrete(System.IntPtr raw)
66 register_event_proxies();
68 ///<summary>Destructor.</summary>
73 ///<summary>Releases the underlying native instance.</summary>
74 void Dispose(bool disposing)
76 if (handle != System.IntPtr.Zero) {
77 Efl.Eo.Globals.efl_unref(handle);
78 handle = System.IntPtr.Zero;
81 ///<summary>Releases the underlying native instance.</summary>
85 GC.SuppressFinalize(this);
87 ///<summary>Casts obj into an instance of this type.</summary>
88 public static ContentConcrete static_cast(Efl.Object obj)
91 throw new System.ArgumentNullException("obj");
92 return new ContentConcrete(obj.NativeHandle);
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 private bool add_cpp_event_handler(string lib, string key, Efl.EventCb evt_delegate) {
116 if (!event_cb_count.TryGetValue(key, out event_count))
117 event_cb_count[key] = event_count;
118 if (event_count == 0) {
119 IntPtr desc = Efl.EventDescription.GetNative(lib, key);
120 if (desc == IntPtr.Zero) {
121 Eina.Log.Error($"Failed to get native event {key}");
124 bool result = Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evt_delegate, System.IntPtr.Zero);
126 Eina.Log.Error($"Failed to add event proxy for event {key}");
129 Eina.Error.RaiseIfUnhandledException();
131 event_cb_count[key]++;
134 private bool remove_cpp_event_handler(string key, Efl.EventCb evt_delegate) {
136 if (!event_cb_count.TryGetValue(key, out event_count))
137 event_cb_count[key] = event_count;
138 if (event_count == 1) {
139 IntPtr desc = Efl.EventDescription.GetNative(efl.Libs.Efl, key);
140 if (desc == IntPtr.Zero) {
141 Eina.Log.Error($"Failed to get native event {key}");
144 bool result = Efl.Eo.Globals.efl_event_callback_del(handle, desc, evt_delegate, System.IntPtr.Zero);
146 Eina.Log.Error($"Failed to remove event proxy for event {key}");
149 Eina.Error.RaiseIfUnhandledException();
150 } else if (event_count == 0) {
151 Eina.Log.Error($"Trying to remove proxy for event {key} when there is nothing registered.");
154 event_cb_count[key]--;
157 private static object ContentChangedEvtKey = new object();
158 /// <summary>Sent after the content is set or unset using the current content object.</summary>
159 public event EventHandler<Efl.ContentContentChangedEvt_Args> ContentChangedEvt
163 string key = "_EFL_CONTENT_EVENT_CONTENT_CHANGED";
164 if (add_cpp_event_handler(efl.Libs.Efl, key, this.evt_ContentChangedEvt_delegate)) {
165 eventHandlers.AddHandler(ContentChangedEvtKey , value);
167 Eina.Log.Error($"Error adding proxy for event {key}");
172 string key = "_EFL_CONTENT_EVENT_CONTENT_CHANGED";
173 if (remove_cpp_event_handler(key, this.evt_ContentChangedEvt_delegate)) {
174 eventHandlers.RemoveHandler(ContentChangedEvtKey , value);
176 Eina.Log.Error($"Error removing proxy for event {key}");
180 ///<summary>Method to raise event ContentChangedEvt.</summary>
181 public void On_ContentChangedEvt(Efl.ContentContentChangedEvt_Args e)
183 EventHandler<Efl.ContentContentChangedEvt_Args> evt;
185 evt = (EventHandler<Efl.ContentContentChangedEvt_Args>)eventHandlers[ContentChangedEvtKey];
187 evt?.Invoke(this, e);
189 Efl.EventCb evt_ContentChangedEvt_delegate;
190 private void on_ContentChangedEvt_NativeCallback(System.IntPtr data, ref Efl.Event_StructInternal evt)
192 Efl.ContentContentChangedEvt_Args args = new Efl.ContentContentChangedEvt_Args();
193 args.arg = new Efl.Gfx.EntityConcrete(evt.Info);
195 On_ContentChangedEvt(args);
196 } catch (Exception e) {
197 Eina.Log.Error(e.ToString());
198 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
202 void register_event_proxies()
204 evt_ContentChangedEvt_delegate = new Efl.EventCb(on_ContentChangedEvt_NativeCallback);
206 /// <summary>Swallowed sub-object contained in this object.</summary>
207 /// <returns>The object to swallow.</returns>
208 public Efl.Gfx.Entity GetContent() {
209 var _ret_var = Efl.ContentNativeInherit.efl_content_get_ptr.Value.Delegate(this.NativeHandle);
210 Eina.Error.RaiseIfUnhandledException();
213 /// <summary>Swallowed sub-object contained in this object.</summary>
214 /// <param name="content">The object to swallow.</param>
215 /// <returns><c>true</c> on success, <c>false</c> otherwise</returns>
216 public bool SetContent( Efl.Gfx.Entity content) {
217 var _ret_var = Efl.ContentNativeInherit.efl_content_set_ptr.Value.Delegate(this.NativeHandle, content);
218 Eina.Error.RaiseIfUnhandledException();
221 /// <summary>Unswallow the object in the current container and return it.</summary>
222 /// <returns>Unswallowed object</returns>
223 public Efl.Gfx.Entity UnsetContent() {
224 var _ret_var = Efl.ContentNativeInherit.efl_content_unset_ptr.Value.Delegate(this.NativeHandle);
225 Eina.Error.RaiseIfUnhandledException();
228 /// <summary>Swallowed sub-object contained in this object.</summary>
229 /// <value>The object to swallow.</value>
230 public Efl.Gfx.Entity Content {
231 get { return GetContent(); }
232 set { SetContent( value); }
235 public class ContentNativeInherit : Efl.Eo.NativeClass{
236 public static Efl.Eo.NativeModule _Module = new Efl.Eo.NativeModule(efl.Libs.Efl);
237 public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)
239 var descs = new System.Collections.Generic.List<Efl_Op_Description>();
240 if (efl_content_get_static_delegate == null)
241 efl_content_get_static_delegate = new efl_content_get_delegate(content_get);
242 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_content_get"), func = Marshal.GetFunctionPointerForDelegate(efl_content_get_static_delegate)});
243 if (efl_content_set_static_delegate == null)
244 efl_content_set_static_delegate = new efl_content_set_delegate(content_set);
245 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_content_set"), func = Marshal.GetFunctionPointerForDelegate(efl_content_set_static_delegate)});
246 if (efl_content_unset_static_delegate == null)
247 efl_content_unset_static_delegate = new efl_content_unset_delegate(content_unset);
248 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_content_unset"), func = Marshal.GetFunctionPointerForDelegate(efl_content_unset_static_delegate)});
251 public override IntPtr GetEflClass()
253 return Efl.ContentConcrete.efl_content_interface_get();
255 public static IntPtr GetEflClassStatic()
257 return Efl.ContentConcrete.efl_content_interface_get();
261 [return:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] private delegate Efl.Gfx.Entity efl_content_get_delegate(System.IntPtr obj, System.IntPtr pd);
264 [return:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] public delegate Efl.Gfx.Entity efl_content_get_api_delegate(System.IntPtr obj);
265 public static Efl.Eo.FunctionWrapper<efl_content_get_api_delegate> efl_content_get_ptr = new Efl.Eo.FunctionWrapper<efl_content_get_api_delegate>(_Module, "efl_content_get");
266 private static Efl.Gfx.Entity content_get(System.IntPtr obj, System.IntPtr pd)
268 Eina.Log.Debug("function efl_content_get was called");
269 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
270 if(wrapper != null) {
271 Efl.Gfx.Entity _ret_var = default(Efl.Gfx.Entity);
273 _ret_var = ((Content)wrapper).GetContent();
274 } catch (Exception e) {
275 Eina.Log.Warning($"Callback error: {e.ToString()}");
276 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
280 return efl_content_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)));
283 private static efl_content_get_delegate efl_content_get_static_delegate;
286 [return: MarshalAs(UnmanagedType.U1)] private delegate bool efl_content_set_delegate(System.IntPtr obj, System.IntPtr pd, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] Efl.Gfx.Entity content);
289 [return: MarshalAs(UnmanagedType.U1)] public delegate bool efl_content_set_api_delegate(System.IntPtr obj, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] Efl.Gfx.Entity content);
290 public static Efl.Eo.FunctionWrapper<efl_content_set_api_delegate> efl_content_set_ptr = new Efl.Eo.FunctionWrapper<efl_content_set_api_delegate>(_Module, "efl_content_set");
291 private static bool content_set(System.IntPtr obj, System.IntPtr pd, Efl.Gfx.Entity content)
293 Eina.Log.Debug("function efl_content_set was called");
294 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
295 if(wrapper != null) {
296 bool _ret_var = default(bool);
298 _ret_var = ((Content)wrapper).SetContent( content);
299 } catch (Exception e) {
300 Eina.Log.Warning($"Callback error: {e.ToString()}");
301 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
305 return efl_content_set_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), content);
308 private static efl_content_set_delegate efl_content_set_static_delegate;
311 [return:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] private delegate Efl.Gfx.Entity efl_content_unset_delegate(System.IntPtr obj, System.IntPtr pd);
314 [return:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.MarshalTest<Efl.Gfx.EntityConcrete, Efl.Eo.NonOwnTag>))] public delegate Efl.Gfx.Entity efl_content_unset_api_delegate(System.IntPtr obj);
315 public static Efl.Eo.FunctionWrapper<efl_content_unset_api_delegate> efl_content_unset_ptr = new Efl.Eo.FunctionWrapper<efl_content_unset_api_delegate>(_Module, "efl_content_unset");
316 private static Efl.Gfx.Entity content_unset(System.IntPtr obj, System.IntPtr pd)
318 Eina.Log.Debug("function efl_content_unset was called");
319 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);
320 if(wrapper != null) {
321 Efl.Gfx.Entity _ret_var = default(Efl.Gfx.Entity);
323 _ret_var = ((Content)wrapper).UnsetContent();
324 } catch (Exception e) {
325 Eina.Log.Warning($"Callback error: {e.ToString()}");
326 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
330 return efl_content_unset_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)));
333 private static efl_content_unset_delegate efl_content_unset_static_delegate;