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

namespace Atk {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	public partial class HypertextAdapter : GLib.GInterfaceAdapter, Atk.IHypertext {

		[StructLayout (LayoutKind.Sequential)]
		struct AtkHypertextIface {
			public GetLinkNativeDelegate GetLink;
			public GetNLinksNativeDelegate GetNLinks;
			public GetLinkIndexNativeDelegate GetLinkIndex;
			IntPtr LinkSelected;
		}

		static AtkHypertextIface iface;

		static HypertextAdapter ()
		{
			GLib.GType.Register (_gtype, typeof (HypertextAdapter));
			iface.GetLink = new GetLinkNativeDelegate (GetLink_cb);
			iface.GetNLinks = new GetNLinksNativeDelegate (GetNLinks_cb);
			iface.GetLinkIndex = new GetLinkIndexNativeDelegate (GetLinkIndex_cb);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr GetLinkNativeDelegate (IntPtr inst, int link_index);

		static IntPtr GetLink_cb (IntPtr inst, int link_index)
		{
			try {
				IHypertextImplementor __obj = GLib.Object.GetObject (inst, false) as IHypertextImplementor;
				Atk.Hyperlink __result;
				__result = __obj.GetLink (link_index);
				return __result == null ? IntPtr.Zero : __result.Handle;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate int GetNLinksNativeDelegate (IntPtr inst);

		static int GetNLinks_cb (IntPtr inst)
		{
			try {
				IHypertextImplementor __obj = GLib.Object.GetObject (inst, false) as IHypertextImplementor;
				int __result;
				__result = __obj.NLinks;
				return __result;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate int GetLinkIndexNativeDelegate (IntPtr inst, int char_index);

		static int GetLinkIndex_cb (IntPtr inst, int char_index)
		{
			try {
				IHypertextImplementor __obj = GLib.Object.GetObject (inst, false) as IHypertextImplementor;
				int __result;
				__result = __obj.GetLinkIndex (char_index);
				return __result;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		static int class_offset = 2 * IntPtr.Size;

		static void Initialize (IntPtr ptr, IntPtr data)
		{
			IntPtr ifaceptr = new IntPtr (ptr.ToInt64 () + class_offset);
			AtkHypertextIface native_iface = (AtkHypertextIface) Marshal.PtrToStructure (ifaceptr, typeof (AtkHypertextIface));
			native_iface.GetLink = iface.GetLink;
			native_iface.GetNLinks = iface.GetNLinks;
			native_iface.GetLinkIndex = iface.GetLinkIndex;
			Marshal.StructureToPtr (native_iface, ifaceptr, false);
		}

		GLib.Object implementor;

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

		public HypertextAdapter (IHypertextImplementor 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 HypertextAdapter (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_atk_hypertext_get_type();
		static d_atk_hypertext_get_type atk_hypertext_get_type = FuncLoader.LoadFunction<d_atk_hypertext_get_type>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Atk), "atk_hypertext_get_type"));

		private static GLib.GType _gtype = new GLib.GType (atk_hypertext_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 IHypertext GetObject (IntPtr handle, bool owned)
		{
			GLib.Object obj = GLib.Object.GetObject (handle, owned);
			return GetObject (obj);
		}

		public static IHypertext GetObject (GLib.Object obj)
		{
			if (obj == null)
				return null;
			else if (obj is IHypertextImplementor)
				return new HypertextAdapter (obj as IHypertextImplementor);
			else if (obj as IHypertext == null)
				return new HypertextAdapter (obj.Handle);
			else
				return obj as IHypertext;
		}

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

		[GLib.Signal("link_selected")]
		public event Atk.LinkSelectedHandler LinkSelected {
			add {
				GLib.Object.GetObject (Handle).AddSignalHandler ("link_selected", value, typeof (Atk.LinkSelectedArgs));
			}
			remove {
				GLib.Object.GetObject (Handle).RemoveSignalHandler ("link_selected", value);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_atk_hypertext_get_link(IntPtr raw, int link_index);
		static d_atk_hypertext_get_link atk_hypertext_get_link = FuncLoader.LoadFunction<d_atk_hypertext_get_link>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Atk), "atk_hypertext_get_link"));

		public Atk.Hyperlink GetLink(int link_index) {
			IntPtr raw_ret = atk_hypertext_get_link(Handle, link_index);
			Atk.Hyperlink ret = GLib.Object.GetObject(raw_ret) as Atk.Hyperlink;
			return ret;
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate int d_atk_hypertext_get_link_index(IntPtr raw, int char_index);
		static d_atk_hypertext_get_link_index atk_hypertext_get_link_index = FuncLoader.LoadFunction<d_atk_hypertext_get_link_index>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Atk), "atk_hypertext_get_link_index"));

		public int GetLinkIndex(int char_index) {
			int raw_ret = atk_hypertext_get_link_index(Handle, char_index);
			int ret = raw_ret;
			return ret;
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate int d_atk_hypertext_get_n_links(IntPtr raw);
		static d_atk_hypertext_get_n_links atk_hypertext_get_n_links = FuncLoader.LoadFunction<d_atk_hypertext_get_n_links>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Atk), "atk_hypertext_get_n_links"));

		public int NLinks { 
			get {
				int raw_ret = atk_hypertext_get_n_links(Handle);
				int ret = raw_ret;
				return ret;
			}
		}

#endregion
	}
}
