// 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 bool AttrFilterFuncNative(IntPtr attribute, IntPtr user_data);

	internal class AttrFilterFuncInvoker {

		AttrFilterFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal AttrFilterFuncInvoker (AttrFilterFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal AttrFilterFuncInvoker (AttrFilterFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		bool InvokeNative (Pango.Attribute attribute)
		{
			bool __result = native_cb (attribute.Handle, __data);
			return __result;
		}
	}

	internal class AttrFilterFuncWrapper {

		public bool NativeCallback (IntPtr attribute, IntPtr user_data)
		{
			try {
				bool __ret = managed (Pango.Attribute.GetAttribute (attribute));
				if (release_on_call)
					gch.Free ();
				return __ret;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
				return false;
			}
		}

		bool release_on_call = false;
		GCHandle gch;

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

		internal AttrFilterFuncNative NativeDelegate;
		Pango.AttrFilterFunc managed;

		public AttrFilterFuncWrapper (Pango.AttrFilterFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new AttrFilterFuncNative (NativeCallback);
		}

		public static Pango.AttrFilterFunc GetManagedDelegate (AttrFilterFuncNative native)
		{
			if (native == null)
				return null;
			AttrFilterFuncWrapper wrapper = (AttrFilterFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
