// 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 FocusHandlerNative(IntPtr objekt, bool focus_in);

	internal class FocusHandlerInvoker {

		FocusHandlerNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal FocusHandlerInvoker (FocusHandlerNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal FocusHandlerInvoker (FocusHandlerNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		void InvokeNative (Atk.Object objekt, bool focus_in)
		{
			native_cb (objekt == null ? IntPtr.Zero : objekt.Handle, focus_in);
		}
	}

	internal class FocusHandlerWrapper {

		public void NativeCallback (IntPtr objekt, bool focus_in)
		{
			try {
				managed (GLib.Object.GetObject(objekt) as Atk.Object, focus_in);
				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 FocusHandlerNative NativeDelegate;
		Atk.FocusHandler managed;

		public FocusHandlerWrapper (Atk.FocusHandler managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new FocusHandlerNative (NativeCallback);
		}

		public static Atk.FocusHandler GetManagedDelegate (FocusHandlerNative native)
		{
			if (native == null)
				return null;
			FocusHandlerWrapper wrapper = (FocusHandlerWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
