// 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 void TreeDestroyCountFuncNative(IntPtr tree_view, IntPtr path, int children, IntPtr user_data);

	internal class TreeDestroyCountFuncInvoker {

		TreeDestroyCountFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal TreeDestroyCountFuncInvoker (TreeDestroyCountFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal TreeDestroyCountFuncInvoker (TreeDestroyCountFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		void InvokeNative (Gtk.TreeView tree_view, Gtk.TreePath path, int children)
		{
			native_cb (tree_view == null ? IntPtr.Zero : tree_view.Handle, path == null ? IntPtr.Zero : path.Handle, children, __data);
		}
	}

	internal class TreeDestroyCountFuncWrapper {

		public void NativeCallback (IntPtr tree_view, IntPtr path, int children, IntPtr user_data)
		{
			try {
				managed (GLib.Object.GetObject(tree_view) as Gtk.TreeView, path == IntPtr.Zero ? null : (Gtk.TreePath) GLib.Opaque.GetOpaque (path, typeof (Gtk.TreePath), false), children);
				if (release_on_call)
					gch.Free ();
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		bool release_on_call = false;
		GCHandle gch;

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

		internal TreeDestroyCountFuncNative NativeDelegate;
		Gtk.TreeDestroyCountFunc managed;

		public TreeDestroyCountFuncWrapper (Gtk.TreeDestroyCountFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new TreeDestroyCountFuncNative (NativeCallback);
		}

		public static Gtk.TreeDestroyCountFunc GetManagedDelegate (TreeDestroyCountFuncNative native)
		{
			if (native == null)
				return null;
			TreeDestroyCountFuncWrapper wrapper = (TreeDestroyCountFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
