// 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 ListBoxSortFuncNative(IntPtr row1, IntPtr row2, IntPtr user_data);

	internal class ListBoxSortFuncInvoker {

		ListBoxSortFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal ListBoxSortFuncInvoker (ListBoxSortFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal ListBoxSortFuncInvoker (ListBoxSortFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		int InvokeNative (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2)
		{
			int __result = native_cb (row1 == null ? IntPtr.Zero : row1.Handle, row2 == null ? IntPtr.Zero : row2.Handle, __data);
			return __result;
		}
	}

	internal class ListBoxSortFuncWrapper {

		public int NativeCallback (IntPtr row1, IntPtr row2, IntPtr user_data)
		{
			try {
				int __ret = managed (GLib.Object.GetObject(row1) as Gtk.ListBoxRow, GLib.Object.GetObject(row2) as Gtk.ListBoxRow);
				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 ListBoxSortFuncNative NativeDelegate;
		Gtk.ListBoxSortFunc managed;

		public ListBoxSortFuncWrapper (Gtk.ListBoxSortFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new ListBoxSortFuncNative (NativeCallback);
		}

		public static Gtk.ListBoxSortFunc GetManagedDelegate (ListBoxSortFuncNative native)
		{
			if (native == null)
				return null;
			ListBoxSortFuncWrapper wrapper = (ListBoxSortFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
