// 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 TreeSortableAdapter : GLib.GInterfaceAdapter, Gtk.ITreeSortable {

		[StructLayout (LayoutKind.Sequential)]
		struct GtkTreeSortableIface {
			IntPtr SortColumnChanged;
			public GetSortColumnIdNativeDelegate GetSortColumnId;
			public SetSortColumnIdNativeDelegate SetSortColumnId;
			public SetSortFuncNativeDelegate SetSortFunc;
			public SetDefaultSortFuncNativeDelegate SetDefaultSortFunc;
			public HasDefaultSortFuncNativeDelegate HasDefaultSortFunc;
		}

		static GtkTreeSortableIface iface;

		static TreeSortableAdapter ()
		{
			GLib.GType.Register (_gtype, typeof (TreeSortableAdapter));
			iface.GetSortColumnId = new GetSortColumnIdNativeDelegate (GetSortColumnId_cb);
			iface.SetSortColumnId = new SetSortColumnIdNativeDelegate (SetSortColumnId_cb);
			iface.SetSortFunc = new SetSortFuncNativeDelegate (SetSortFunc_cb);
			iface.SetDefaultSortFunc = new SetDefaultSortFuncNativeDelegate (SetDefaultSortFunc_cb);
			iface.HasDefaultSortFunc = new HasDefaultSortFuncNativeDelegate (HasDefaultSortFunc_cb);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate bool GetSortColumnIdNativeDelegate (IntPtr inst, out int sort_column_id, out int order);

		static bool GetSortColumnId_cb (IntPtr inst, out int sort_column_id, out int order)
		{
			try {
				ITreeSortableImplementor __obj = GLib.Object.GetObject (inst, false) as ITreeSortableImplementor;
				bool __result;
				Gtk.SortType myorder;
				__result = __obj.GetSortColumnId (out sort_column_id, out myorder);
				order = (int) myorder;
				return __result;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, true);
				// NOTREACHED: above call does not return.
				throw;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void SetSortColumnIdNativeDelegate (IntPtr inst, int sort_column_id, int order);

		static void SetSortColumnId_cb (IntPtr inst, int sort_column_id, int order)
		{
			try {
				ITreeSortableImplementor __obj = GLib.Object.GetObject (inst, false) as ITreeSortableImplementor;
				__obj.SetSortColumnId (sort_column_id, (Gtk.SortType) order);
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void SetSortFuncNativeDelegate (IntPtr inst, int sort_column_id, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, GLib.DestroyNotify destroy);

		static void SetSortFunc_cb (IntPtr inst, int sort_column_id, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, GLib.DestroyNotify destroy)
		{
			try {
				ITreeSortableImplementor __obj = GLib.Object.GetObject (inst, false) as ITreeSortableImplementor;
				GtkSharp.TreeIterCompareFuncInvoker sort_func_invoker = new GtkSharp.TreeIterCompareFuncInvoker (sort_func, user_data, destroy);
				__obj.SetSortFunc (sort_column_id, sort_func_invoker.Handler);
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void SetDefaultSortFuncNativeDelegate (IntPtr inst, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, GLib.DestroyNotify destroy);

		static void SetDefaultSortFunc_cb (IntPtr inst, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, GLib.DestroyNotify destroy)
		{
			try {
				ITreeSortableImplementor __obj = GLib.Object.GetObject (inst, false) as ITreeSortableImplementor;
				GtkSharp.TreeIterCompareFuncInvoker sort_func_invoker = new GtkSharp.TreeIterCompareFuncInvoker (sort_func, user_data, destroy);
				__obj.DefaultSortFunc = sort_func_invoker.Handler;
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate bool HasDefaultSortFuncNativeDelegate (IntPtr inst);

		static bool HasDefaultSortFunc_cb (IntPtr inst)
		{
			try {
				ITreeSortableImplementor __obj = GLib.Object.GetObject (inst, false) as ITreeSortableImplementor;
				bool __result;
				__result = __obj.HasDefaultSortFunc;
				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);
			GtkTreeSortableIface native_iface = (GtkTreeSortableIface) Marshal.PtrToStructure (ifaceptr, typeof (GtkTreeSortableIface));
			native_iface.GetSortColumnId = iface.GetSortColumnId;
			native_iface.SetSortColumnId = iface.SetSortColumnId;
			native_iface.SetSortFunc = iface.SetSortFunc;
			native_iface.SetDefaultSortFunc = iface.SetDefaultSortFunc;
			native_iface.HasDefaultSortFunc = iface.HasDefaultSortFunc;
			Marshal.StructureToPtr (native_iface, ifaceptr, false);
		}

		GLib.Object implementor;

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

		public TreeSortableAdapter (ITreeSortableImplementor 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 TreeSortableAdapter (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_tree_sortable_get_type();
		static d_gtk_tree_sortable_get_type gtk_tree_sortable_get_type = FuncLoader.LoadFunction<d_gtk_tree_sortable_get_type>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_tree_sortable_get_type"));

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

		public static ITreeSortable GetObject (GLib.Object obj)
		{
			if (obj == null)
				return null;
			else if (obj is ITreeSortableImplementor)
				return new TreeSortableAdapter (obj as ITreeSortableImplementor);
			else if (obj as ITreeSortable == null)
				return new TreeSortableAdapter (obj.Handle);
			else
				return obj as ITreeSortable;
		}

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

		[GLib.Signal("sort-column-changed")]
		public event System.EventHandler SortColumnChanged {
			add {
				GLib.Object.GetObject (Handle).AddSignalHandler ("sort-column-changed", value);
			}
			remove {
				GLib.Object.GetObject (Handle).RemoveSignalHandler ("sort-column-changed", value);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate bool d_gtk_tree_sortable_get_sort_column_id(IntPtr raw, out int sort_column_id, out int order);
		static d_gtk_tree_sortable_get_sort_column_id gtk_tree_sortable_get_sort_column_id = FuncLoader.LoadFunction<d_gtk_tree_sortable_get_sort_column_id>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_tree_sortable_get_sort_column_id"));

		public bool GetSortColumnId(out int sort_column_id, out Gtk.SortType order) {
			int native_order;
			bool raw_ret = gtk_tree_sortable_get_sort_column_id(Handle, out sort_column_id, out native_order);
			bool ret = raw_ret;
			order = (Gtk.SortType) native_order;
			return ret;
		}

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

		public bool HasDefaultSortFunc { 
			get {
				bool raw_ret = gtk_tree_sortable_has_default_sort_func(Handle);
				bool ret = raw_ret;
				return ret;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_gtk_tree_sortable_set_default_sort_func(IntPtr raw, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, GLib.DestroyNotify destroy);
		static d_gtk_tree_sortable_set_default_sort_func gtk_tree_sortable_set_default_sort_func = FuncLoader.LoadFunction<d_gtk_tree_sortable_set_default_sort_func>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_tree_sortable_set_default_sort_func"));

		public Gtk.TreeIterCompareFunc DefaultSortFunc { 
			set {
				GtkSharp.TreeIterCompareFuncWrapper value_wrapper = new GtkSharp.TreeIterCompareFuncWrapper (value);
				IntPtr user_data;
				GLib.DestroyNotify destroy;
				if (value == null) {
					user_data = IntPtr.Zero;
					destroy = null;
				} else {
					user_data = (IntPtr) GCHandle.Alloc (value_wrapper);
					destroy = GLib.DestroyHelper.NotifyHandler;
				}
				gtk_tree_sortable_set_default_sort_func(Handle, value_wrapper.NativeDelegate, user_data, destroy);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_gtk_tree_sortable_set_sort_column_id(IntPtr raw, int sort_column_id, int order);
		static d_gtk_tree_sortable_set_sort_column_id gtk_tree_sortable_set_sort_column_id = FuncLoader.LoadFunction<d_gtk_tree_sortable_set_sort_column_id>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_tree_sortable_set_sort_column_id"));

		public void SetSortColumnId(int sort_column_id, Gtk.SortType order) {
			gtk_tree_sortable_set_sort_column_id(Handle, sort_column_id, (int) order);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_gtk_tree_sortable_set_sort_func(IntPtr raw, int sort_column_id, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, GLib.DestroyNotify destroy);
		static d_gtk_tree_sortable_set_sort_func gtk_tree_sortable_set_sort_func = FuncLoader.LoadFunction<d_gtk_tree_sortable_set_sort_func>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_tree_sortable_set_sort_func"));

		public void SetSortFunc(int sort_column_id, Gtk.TreeIterCompareFunc sort_func) {
			GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = new GtkSharp.TreeIterCompareFuncWrapper (sort_func);
			IntPtr user_data;
			GLib.DestroyNotify destroy;
			if (sort_func == null) {
				user_data = IntPtr.Zero;
				destroy = null;
			} else {
				user_data = (IntPtr) GCHandle.Alloc (sort_func_wrapper);
				destroy = GLib.DestroyHelper.NotifyHandler;
			}
			gtk_tree_sortable_set_sort_func(Handle, sort_column_id, sort_func_wrapper.NativeDelegate, user_data, destroy);
		}

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

		public void ChangeSortColumn() {
			gtk_tree_sortable_sort_column_changed(Handle);
		}

#endregion
	}
}
