// 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 ClipboardReceivedFuncNative(IntPtr clipboard, IntPtr selection_data, IntPtr data);

	internal class ClipboardReceivedFuncInvoker {

		ClipboardReceivedFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal ClipboardReceivedFuncInvoker (ClipboardReceivedFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal ClipboardReceivedFuncInvoker (ClipboardReceivedFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		void InvokeNative (Gtk.Clipboard clipboard, Gtk.SelectionData selection_data)
		{
			native_cb (clipboard == null ? IntPtr.Zero : clipboard.Handle, selection_data == null ? IntPtr.Zero : selection_data.Handle, __data);
		}
	}

	internal class ClipboardReceivedFuncWrapper {

		public void NativeCallback (IntPtr clipboard, IntPtr selection_data, IntPtr data)
		{
			try {
				managed (GLib.Object.GetObject(clipboard) as Gtk.Clipboard, selection_data == IntPtr.Zero ? null : (Gtk.SelectionData) GLib.Opaque.GetOpaque (selection_data, typeof (Gtk.SelectionData), 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 ClipboardReceivedFuncNative NativeDelegate;
		Gtk.ClipboardReceivedFunc managed;

		public ClipboardReceivedFuncWrapper (Gtk.ClipboardReceivedFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new ClipboardReceivedFuncNative (NativeCallback);
		}

		public static Gtk.ClipboardReceivedFunc GetManagedDelegate (ClipboardReceivedFuncNative native)
		{
			if (native == null)
				return null;
			ClipboardReceivedFuncWrapper wrapper = (ClipboardReceivedFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
