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

namespace GtkSharp {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	internal delegate bool FontFilterFuncNative(IntPtr family, IntPtr face, IntPtr data);

	internal class FontFilterFuncInvoker {

		FontFilterFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal FontFilterFuncInvoker (FontFilterFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal FontFilterFuncInvoker (FontFilterFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

		internal Gtk.FontFilterFunc Handler {
			get {
				return new Gtk.FontFilterFunc(InvokeNative);
			}
		}

		bool InvokeNative (Pango.FontFamily family, Pango.FontFace face)
		{
			bool __result = native_cb (family == null ? IntPtr.Zero : family.Handle, face == null ? IntPtr.Zero : face.Handle, __data);
			return __result;
		}
	}

	internal class FontFilterFuncWrapper {

		public bool NativeCallback (IntPtr family, IntPtr face, IntPtr data)
		{
			try {
				bool __ret = managed (GLib.Object.GetObject(family) as Pango.FontFamily, GLib.Object.GetObject(face) as Pango.FontFace);
				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 FontFilterFuncNative NativeDelegate;
		Gtk.FontFilterFunc managed;

		public FontFilterFuncWrapper (Gtk.FontFilterFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new FontFilterFuncNative (NativeCallback);
		}

		public static Gtk.FontFilterFunc GetManagedDelegate (FontFilterFuncNative native)
		{
			if (native == null)
				return null;
			FontFilterFuncWrapper wrapper = (FontFilterFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
