// 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
	[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
	internal delegate void ClipboardTargetsReceivedFuncNative(IntPtr clipboard, IntPtr atoms, int n_atoms, IntPtr data);

	internal class ClipboardTargetsReceivedFuncInvoker {

		ClipboardTargetsReceivedFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal ClipboardTargetsReceivedFuncInvoker (ClipboardTargetsReceivedFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal ClipboardTargetsReceivedFuncInvoker (ClipboardTargetsReceivedFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		void InvokeNative (Gtk.Clipboard clipboard, Gdk.Atom atoms, int n_atoms)
		{
			native_cb (clipboard == null ? IntPtr.Zero : clipboard.Handle, atoms == null ? IntPtr.Zero : atoms.Handle, n_atoms, __data);
		}
	}

	internal class ClipboardTargetsReceivedFuncWrapper {

		public void NativeCallback (IntPtr clipboard, IntPtr atoms, int n_atoms, IntPtr data)
		{
			try {
				managed (GLib.Object.GetObject(clipboard) as Gtk.Clipboard, atoms == IntPtr.Zero ? null : (Gdk.Atom) GLib.Opaque.GetOpaque (atoms, typeof (Gdk.Atom), false), n_atoms);
				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 ClipboardTargetsReceivedFuncNative NativeDelegate;
		Gtk.ClipboardTargetsReceivedFunc managed;

		public ClipboardTargetsReceivedFuncWrapper (Gtk.ClipboardTargetsReceivedFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new ClipboardTargetsReceivedFuncNative (NativeCallback);
		}

		public static Gtk.ClipboardTargetsReceivedFunc GetManagedDelegate (ClipboardTargetsReceivedFuncNative native)
		{
			if (native == null)
				return null;
			ClipboardTargetsReceivedFuncWrapper wrapper = (ClipboardTargetsReceivedFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
