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

namespace PangoSharp {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	internal delegate IntPtr AttrDataCopyFuncNative(IntPtr user_data);

	internal class AttrDataCopyFuncInvoker {

		AttrDataCopyFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal AttrDataCopyFuncInvoker (AttrDataCopyFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal AttrDataCopyFuncInvoker (AttrDataCopyFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

		internal Pango.AttrDataCopyFunc Handler {
			get {
				return new Pango.AttrDataCopyFunc(InvokeNative);
			}
		}

		IntPtr InvokeNative ()
		{
			IntPtr __result = native_cb (__data);
			return __result;
		}
	}

	internal class AttrDataCopyFuncWrapper {

		public IntPtr NativeCallback (IntPtr user_data)
		{
			try {
				IntPtr __ret = managed ();
				if (release_on_call)
					gch.Free ();
				return __ret;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: Above call does not return.
				throw;
			}
		}

		bool release_on_call = false;
		GCHandle gch;

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

		internal AttrDataCopyFuncNative NativeDelegate;
		Pango.AttrDataCopyFunc managed;

		public AttrDataCopyFuncWrapper (Pango.AttrDataCopyFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new AttrDataCopyFuncNative (NativeCallback);
		}

		public static Pango.AttrDataCopyFunc GetManagedDelegate (AttrDataCopyFuncNative native)
		{
			if (native == null)
				return null;
			AttrDataCopyFuncWrapper wrapper = (AttrDataCopyFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
