// 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 ColorSelectionChangePaletteFuncNative(IntPtr colors, int n_colors);

	internal class ColorSelectionChangePaletteFuncInvoker {

		ColorSelectionChangePaletteFuncNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal ColorSelectionChangePaletteFuncInvoker (ColorSelectionChangePaletteFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal ColorSelectionChangePaletteFuncInvoker (ColorSelectionChangePaletteFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		void InvokeNative (Gdk.Color colors, int n_colors)
		{
			IntPtr native_colors = GLib.Marshaller.StructureToPtrAlloc (colors);
			native_cb (native_colors, n_colors);
			Marshal.FreeHGlobal (native_colors);
		}
	}

	internal class ColorSelectionChangePaletteFuncWrapper {

		public void NativeCallback (IntPtr colors, int n_colors)
		{
			try {
				managed (Gdk.Color.New (colors), n_colors);
				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 ColorSelectionChangePaletteFuncNative NativeDelegate;
		Gtk.ColorSelectionChangePaletteFunc managed;

		public ColorSelectionChangePaletteFuncWrapper (Gtk.ColorSelectionChangePaletteFunc managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new ColorSelectionChangePaletteFuncNative (NativeCallback);
		}

		public static Gtk.ColorSelectionChangePaletteFunc GetManagedDelegate (ColorSelectionChangePaletteFuncNative native)
		{
			if (native == null)
				return null;
			ColorSelectionChangePaletteFuncWrapper wrapper = (ColorSelectionChangePaletteFuncWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
