// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.

namespace Gtk {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	public partial class ActionObservableAdapter : GLib.GInterfaceAdapter, Gtk.IActionObservable {

		[StructLayout (LayoutKind.Sequential)]
		struct GtkActionObservableInterface {
			public RegisterObserverNativeDelegate RegisterObserver;
			public UnregisterObserverNativeDelegate UnregisterObserver;
		}

		static GtkActionObservableInterface iface;

		static ActionObservableAdapter ()
		{
			GLib.GType.Register (_gtype, typeof (ActionObservableAdapter));
			iface.RegisterObserver = new RegisterObserverNativeDelegate (RegisterObserver_cb);
			iface.UnregisterObserver = new UnregisterObserverNativeDelegate (UnregisterObserver_cb);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void RegisterObserverNativeDelegate (IntPtr inst, IntPtr action_name, IntPtr observer);

		static void RegisterObserver_cb (IntPtr inst, IntPtr action_name, IntPtr observer)
		{
			try {
				IActionObservableImplementor __obj = GLib.Object.GetObject (inst, false) as IActionObservableImplementor;
				__obj.RegisterObserver (GLib.Marshaller.Utf8PtrToString (action_name), Gtk.ActionObserverAdapter.GetObject (observer, false));
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void UnregisterObserverNativeDelegate (IntPtr inst, IntPtr action_name, IntPtr observer);

		static void UnregisterObserver_cb (IntPtr inst, IntPtr action_name, IntPtr observer)
		{
			try {
				IActionObservableImplementor __obj = GLib.Object.GetObject (inst, false) as IActionObservableImplementor;
				__obj.UnregisterObserver (GLib.Marshaller.Utf8PtrToString (action_name), Gtk.ActionObserverAdapter.GetObject (observer, false));
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		static int class_offset = 2 * IntPtr.Size;

		static void Initialize (IntPtr ptr, IntPtr data)
		{
			IntPtr ifaceptr = new IntPtr (ptr.ToInt64 () + class_offset);
			GtkActionObservableInterface native_iface = (GtkActionObservableInterface) Marshal.PtrToStructure (ifaceptr, typeof (GtkActionObservableInterface));
			native_iface.RegisterObserver = iface.RegisterObserver;
			native_iface.UnregisterObserver = iface.UnregisterObserver;
			Marshal.StructureToPtr (native_iface, ifaceptr, false);
		}

		GLib.Object implementor;

		public ActionObservableAdapter ()
		{
			InitHandler = new GLib.GInterfaceInitHandler (Initialize);
		}

		public ActionObservableAdapter (IActionObservableImplementor implementor)
		{
			if (implementor == null)
				throw new ArgumentNullException ("implementor");
			else if (!(implementor is GLib.Object))
				throw new ArgumentException ("implementor must be a subclass of GLib.Object");
			this.implementor = implementor as GLib.Object;
		}

		public ActionObservableAdapter (IntPtr handle)
		{
			if (!_gtype.IsInstance (handle))
				throw new ArgumentException ("The gobject doesn't implement the GInterface of this adapter", "handle");
			implementor = GLib.Object.GetObject (handle);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_gtk_action_observable_get_type();
		static d_gtk_action_observable_get_type gtk_action_observable_get_type = FuncLoader.LoadFunction<d_gtk_action_observable_get_type>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_action_observable_get_type"));

		private static GLib.GType _gtype = new GLib.GType (gtk_action_observable_get_type ());

		public static GLib.GType GType {
			get {
				return _gtype;
			}
		}

		public override GLib.GType GInterfaceGType {
			get {
				return _gtype;
			}
		}

		public override IntPtr Handle {
			get {
				return implementor.Handle;
			}
		}

		public IntPtr OwnedHandle {
			get {
				return implementor.OwnedHandle;
			}
		}

		public static IActionObservable GetObject (IntPtr handle, bool owned)
		{
			GLib.Object obj = GLib.Object.GetObject (handle, owned);
			return GetObject (obj);
		}

		public static IActionObservable GetObject (GLib.Object obj)
		{
			if (obj == null)
				return null;
			else if (obj is IActionObservableImplementor)
				return new ActionObservableAdapter (obj as IActionObservableImplementor);
			else if (obj as IActionObservable == null)
				return new ActionObservableAdapter (obj.Handle);
			else
				return obj as IActionObservable;
		}

		public IActionObservableImplementor Implementor {
			get {
				return implementor as IActionObservableImplementor;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_gtk_action_observable_register_observer(IntPtr raw, IntPtr action_name, IntPtr observer);
		static d_gtk_action_observable_register_observer gtk_action_observable_register_observer = FuncLoader.LoadFunction<d_gtk_action_observable_register_observer>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_action_observable_register_observer"));

		public void RegisterObserver(string action_name, Gtk.IActionObserver observer) {
			IntPtr native_action_name = GLib.Marshaller.StringToPtrGStrdup (action_name);
			gtk_action_observable_register_observer(Handle, native_action_name, observer == null ? IntPtr.Zero : ((observer is GLib.Object) ? (observer as GLib.Object).Handle : (observer as Gtk.ActionObserverAdapter).Handle));
			GLib.Marshaller.Free (native_action_name);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_gtk_action_observable_unregister_observer(IntPtr raw, IntPtr action_name, IntPtr observer);
		static d_gtk_action_observable_unregister_observer gtk_action_observable_unregister_observer = FuncLoader.LoadFunction<d_gtk_action_observable_unregister_observer>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_action_observable_unregister_observer"));

		public void UnregisterObserver(string action_name, Gtk.IActionObserver observer) {
			IntPtr native_action_name = GLib.Marshaller.StringToPtrGStrdup (action_name);
			gtk_action_observable_unregister_observer(Handle, native_action_name, observer == null ? IntPtr.Zero : ((observer is GLib.Object) ? (observer as GLib.Object).Handle : (observer as Gtk.ActionObserverAdapter).Handle));
			GLib.Marshaller.Free (native_action_name);
		}

#endregion
	}
}
