// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.

namespace AtkSharp {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	internal delegate void EventListenerInitNative();

	internal class EventListenerInitInvoker {

		EventListenerInitNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

		~EventListenerInitInvoker ()
		{
			if (__notify == null)
				return;
			__notify (__data);
		}

		internal EventListenerInitInvoker (EventListenerInitNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal EventListenerInitInvoker (EventListenerInitNative native_cb, IntPtr data) : this (native_cb, data, null) {}

		internal EventListenerInitInvoker (EventListenerInitNative native_cb, IntPtr data, GLib.DestroyNotify notify)
		{
			this.native_cb = native_cb;
			__data = data;
			__notify = notify;
		}

		internal Atk.EventListenerInit Handler {
			get {
				return new Atk.EventListenerInit(InvokeNative);
			}
		}

		void InvokeNative ()
		{
			native_cb ();
		}
	}

	internal class EventListenerInitWrapper {

		public void NativeCallback ()
		{
			try {
				managed ();
				if (release_on_call)
					gch.Free ();
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		bool release_on_call = false;
		GCHandle gch;

		public void PersistUntilCalled ()
		{
			release_on_call = true;
			gch = GCHandle.Alloc (this);
		}

		internal EventListenerInitNative NativeDelegate;
		Atk.EventListenerInit managed;

		public EventListenerInitWrapper (Atk.EventListenerInit managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new EventListenerInitNative (NativeCallback);
		}

		public static Atk.EventListenerInit GetManagedDelegate (EventListenerInitNative native)
		{
			if (native == null)
				return null;
			EventListenerInitWrapper wrapper = (EventListenerInitWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
