// 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 AccelMapForeachNative(IntPtr data, IntPtr accel_path, uint accel_key, int accel_mods, bool changed);

	internal class AccelMapForeachInvoker {

		AccelMapForeachNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal AccelMapForeachInvoker (AccelMapForeachNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal AccelMapForeachInvoker (AccelMapForeachNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		void InvokeNative (IntPtr data, string accel_path, uint accel_key, Gdk.ModifierType accel_mods, bool changed)
		{
			IntPtr native_accel_path = GLib.Marshaller.StringToPtrGStrdup (accel_path);
			native_cb (__data, native_accel_path, accel_key, (int) accel_mods, changed);
			GLib.Marshaller.Free (native_accel_path);
		}
	}

	internal class AccelMapForeachWrapper {

		public void NativeCallback (IntPtr data, IntPtr accel_path, uint accel_key, int accel_mods, bool changed)
		{
			try {
				managed (data, GLib.Marshaller.Utf8PtrToString (accel_path), accel_key, (Gdk.ModifierType) accel_mods, changed);
				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 AccelMapForeachNative NativeDelegate;
		Gtk.AccelMapForeach managed;

		public AccelMapForeachWrapper (Gtk.AccelMapForeach managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new AccelMapForeachNative (NativeCallback);
		}

		public static Gtk.AccelMapForeach GetManagedDelegate (AccelMapForeachNative native)
		{
			if (native == null)
				return null;
			AccelMapForeachWrapper wrapper = (AccelMapForeachWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
