// 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 int RecentSortFuncNative(IntPtr a, IntPtr b, IntPtr user_data);

	internal class RecentSortFuncInvoker {

		RecentSortFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal RecentSortFuncInvoker (RecentSortFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal RecentSortFuncInvoker (RecentSortFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		int InvokeNative (Gtk.RecentInfo a, Gtk.RecentInfo b)
		{
			int __result = native_cb (a == null ? IntPtr.Zero : a.Handle, b == null ? IntPtr.Zero : b.Handle, __data);
			return __result;
		}
	}

	internal class RecentSortFuncWrapper {

		public int NativeCallback (IntPtr a, IntPtr b, IntPtr user_data)
		{
			try {
				int __ret = managed (a == IntPtr.Zero ? null : (Gtk.RecentInfo) GLib.Opaque.GetOpaque (a, typeof (Gtk.RecentInfo), false), b == IntPtr.Zero ? null : (Gtk.RecentInfo) GLib.Opaque.GetOpaque (b, typeof (Gtk.RecentInfo), false));
				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 RecentSortFuncNative NativeDelegate;
		Gtk.RecentSortFunc managed;

		public RecentSortFuncWrapper (Gtk.RecentSortFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new RecentSortFuncNative (NativeCallback);
		}

		public static Gtk.RecentSortFunc GetManagedDelegate (RecentSortFuncNative native)
		{
			if (native == null)
				return null;
			RecentSortFuncWrapper wrapper = (RecentSortFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
