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

	internal class TreeViewSearchPositionFuncInvoker {

		TreeViewSearchPositionFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal TreeViewSearchPositionFuncInvoker (TreeViewSearchPositionFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal TreeViewSearchPositionFuncInvoker (TreeViewSearchPositionFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

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

	internal class TreeViewSearchPositionFuncWrapper {

		public void NativeCallback (IntPtr tree_view, IntPtr search_dialog, IntPtr user_data)
		{
			try {
				managed (GLib.Object.GetObject(tree_view) as Gtk.TreeView, GLib.Object.GetObject(search_dialog) as Gtk.Widget);
				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 TreeViewSearchPositionFuncNative NativeDelegate;
		Gtk.TreeViewSearchPositionFunc managed;

		public TreeViewSearchPositionFuncWrapper (Gtk.TreeViewSearchPositionFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new TreeViewSearchPositionFuncNative (NativeCallback);
		}

		public static Gtk.TreeViewSearchPositionFunc GetManagedDelegate (TreeViewSearchPositionFuncNative native)
		{
			if (native == null)
				return null;
			TreeViewSearchPositionFuncWrapper wrapper = (TreeViewSearchPositionFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
