// 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 bool StylePropertyParserNative(IntPtr str1ng, IntPtr value, out IntPtr error);

	internal class StylePropertyParserInvoker {

		StylePropertyParserNative native_cb;
		IntPtr __data;
		GLib.DestroyNotify __notify;

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

		internal StylePropertyParserInvoker (StylePropertyParserNative native_cb) : this (native_cb, IntPtr.Zero, null) {}

		internal StylePropertyParserInvoker (StylePropertyParserNative native_cb, IntPtr data) : this (native_cb, data, null) {}

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

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

		bool InvokeNative (string str1ng, GLib.Value value)
		{
			IntPtr native_str1ng = GLib.Marshaller.StringToPtrGStrdup (str1ng);
			IntPtr native_value = GLib.Marshaller.StructureToPtrAlloc (value);
			IntPtr error = IntPtr.Zero;
			bool __result = native_cb (native_str1ng, native_value, out error);
			GLib.Marshaller.Free (native_str1ng);
			Marshal.FreeHGlobal (native_value);
			return __result;
		}
	}

	internal class StylePropertyParserWrapper {

		public bool NativeCallback (IntPtr str1ng, IntPtr value, out IntPtr error)
		{
			error = IntPtr.Zero;

			try {
				bool __ret = managed (GLib.Marshaller.Utf8PtrToString (str1ng), (GLib.Value) Marshal.PtrToStructure (value, typeof (GLib.Value)));
				if (release_on_call)
					gch.Free ();
				return __ret;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
				return false;
			}
		}

		bool release_on_call = false;
		GCHandle gch;

		public void PersistUntilCalled ()
		{
			release_on_call = true;
			gch = GCHandle.Alloc (this);
		}

		internal StylePropertyParserNative NativeDelegate;
		Gtk.StylePropertyParser managed;

		public StylePropertyParserWrapper (Gtk.StylePropertyParser managed)
		{
			this.managed = managed;
			if (managed != null)
				NativeDelegate = new StylePropertyParserNative (NativeCallback);
		}

		public static Gtk.StylePropertyParser GetManagedDelegate (StylePropertyParserNative native)
		{
			if (native == null)
				return null;
			StylePropertyParserWrapper wrapper = (StylePropertyParserWrapper) native.Target;
			if (wrapper == null)
				return null;
			return wrapper.managed;
		}
	}
#endregion
}
