- if (handle != System.IntPtr.Zero)
- {
- IntPtr h = handle;
- handle = IntPtr.Zero;
-
- IntPtr gcHandlePtr = IntPtr.Zero;
- if (eoEvents.Count != 0)
- {
- GCHandle gcHandle = GCHandle.Alloc(eoEvents);
- gcHandlePtr = GCHandle.ToIntPtr(gcHandle);
- }
-
- if (disposing)
- {
- Efl.Eo.Globals.efl_mono_native_dispose(h, gcHandlePtr);
- }
- else
- {
- Monitor.Enter(Efl.All.InitLock);
- if (Efl.All.MainLoopInitialized)
- {
- Efl.Eo.Globals.efl_mono_thread_safe_native_dispose(h, gcHandlePtr);
- }
-
- Monitor.Exit(Efl.All.InitLock);
- }
- }
-
- }
-
- ///<summary>Releases the underlying native instance.</summary>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>Verifies if the given object is equal to this one.</summary>
- /// <param name="instance">The object to compare to.</param>
- /// <returns>True if both objects point to the same native object.</returns>
- public override bool Equals(object instance)
- {
- var other = instance as Efl.Object;
- if (other == null)
- {
- return false;
- }
- return this.NativeHandle == other.NativeHandle;
- }
-
- /// <summary>Gets the hash code for this object based on the native pointer it points to.</summary>
- /// <returns>The value of the pointer, to be used as the hash code of this object.</returns>
- public override int GetHashCode()
- {
- return this.NativeHandle.ToInt32();
- }
-
- /// <summary>Turns the native pointer into a string representation.</summary>
- /// <returns>A string with the type and the native pointer for this object.</returns>
- public override String ToString()
- {
- return $"{this.GetType().Name}@[{this.NativeHandle.ToInt32():x}]";
- }
-
- ///<summary>Adds a new event handler, registering it to the native event. For internal use only.</summary>
- ///<param name="lib">The name of the native library definining the event.</param>
- ///<param name="key">The name of the native event.</param>
- ///<param name="evtCaller">Delegate to be called by native code on event raising.</param>
- ///<param name="evtDelegate">Managed delegate that will be called by evtCaller on event raising.</param>
- private void AddNativeEventHandler(string lib, string key, Efl.EventCb evtCaller, object evtDelegate)
- {
- IntPtr desc = Efl.EventDescription.GetNative(lib, key);
- if (desc == IntPtr.Zero)
- {
- Eina.Log.Error($"Failed to get native event {key}");
- }
-
- if (eoEvents.ContainsKey((desc, evtDelegate)))
- {
- Eina.Log.Warning($"Event proxy for event {key} already registered!");
- return;
- }
-
- IntPtr evtCallerPtr = Marshal.GetFunctionPointerForDelegate(evtCaller);
- if (!Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evtCallerPtr, IntPtr.Zero))
- {
- Eina.Log.Error($"Failed to add event proxy for event {key}");
- return;
- }
-
- eoEvents[(desc, evtDelegate)] = (evtCallerPtr, evtCaller);
- Eina.Error.RaiseIfUnhandledException();
- }
-
- ///<summary>Removes the given event handler for the given event. For internal use only.</summary>
- ///<param name="lib">The name of the native library definining the event.</param>
- ///<param name="key">The name of the native event.</param>
- ///<param name="evtDelegate">The delegate to be removed.</param>
- private void RemoveNativeEventHandler(string lib, string key, object evtDelegate)
- {
- IntPtr desc = Efl.EventDescription.GetNative(lib, key);
- if (desc == IntPtr.Zero)
- {
- Eina.Log.Error($"Failed to get native event {key}");
- return;
- }
-
- var evtPair = (desc, evtDelegate);
- if (eoEvents.TryGetValue(evtPair, out var caller))
- {
- if (!Efl.Eo.Globals.efl_event_callback_del(handle, desc, caller.evtCallerPtr, IntPtr.Zero))
- {
- Eina.Log.Error($"Failed to remove event proxy for event {key}");
- return;
- }
-
- eoEvents.Remove(evtPair);
- Eina.Error.RaiseIfUnhandledException();
- }
- else
- {
- Eina.Log.Error($"Trying to remove proxy for event {key} when it is nothing registered.");
- }