// 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 TreeViewMappingFuncNative(IntPtr tree_view, IntPtr path, IntPtr user_data);

	internal class TreeViewMappingFuncInvoker {

		TreeViewMappingFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal TreeViewMappingFuncInvoker (TreeViewMappingFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal TreeViewMappingFuncInvoker (TreeViewMappingFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

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

	internal class TreeViewMappingFuncWrapper {

		public void NativeCallback (IntPtr tree_view, IntPtr path, 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));
				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 TreeViewMappingFuncNative NativeDelegate;
		Gtk.TreeViewMappingFunc managed;

		public TreeViewMappingFuncWrapper (Gtk.TreeViewMappingFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new TreeViewMappingFuncNative (NativeCallback);
		}

		public static Gtk.TreeViewMappingFunc GetManagedDelegate (TreeViewMappingFuncNative native)
		{
			if (native == null)
				return null;
			TreeViewMappingFuncWrapper wrapper = (TreeViewMappingFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
