context: // This file was generated by the Gtk# code generator.
  // Any changes made will be lost if regenerated.
  
  namespace Gtk {
  
  	using System;
  	using System.Collections;
  	using System.Collections.Generic;
  	using System.Runtime.InteropServices;
  
  #region Autogenerated code
  	public partial class IMContext : GLib.Object {
  
  		public IMContext (IntPtr raw) : base(raw) {}
  
  		protected IMContext() : base(IntPtr.Zero)
  		{
  			CreateNativeObject (new string [0], new GLib.Value [0]);
  		}
  
  		[GLib.Signal("preedit-end")]
  		public event System.EventHandler PreeditEnd {
  			add {
  				this.AddSignalHandler ("preedit-end", value);
  			}
  			remove {
  				this.RemoveSignalHandler ("preedit-end", value);
  			}
  		}
  
  		[GLib.Signal("retrieve-surrounding")]
  		public event Gtk.RetrieveSurroundingHandler RetrieveSurrounding {
  			add {
  				this.AddSignalHandler ("retrieve-surrounding", value, typeof (Gtk.RetrieveSurroundingArgs));
  			}
  			remove {
  				this.RemoveSignalHandler ("retrieve-surrounding", value);
  			}
  		}
  
  		[GLib.Signal("commit")]
  		public event Gtk.CommitHandler Commit {
  			add {
  				this.AddSignalHandler ("commit", value, typeof (Gtk.CommitArgs));
  			}
  			remove {
  				this.RemoveSignalHandler ("commit", value);
  			}
  		}
  
  		[GLib.Signal("delete-surrounding")]
  		public event Gtk.SurroundingDeletedHandler SurroundingDeleted {
  			add {
  				this.AddSignalHandler ("delete-surrounding", value, typeof (Gtk.SurroundingDeletedArgs));
  			}
  			remove {
  				this.RemoveSignalHandler ("delete-surrounding", value);
  			}
  		}
  
  		[GLib.Signal("preedit-start")]
  		public event System.EventHandler PreeditStart {
  			add {
  				this.AddSignalHandler ("preedit-start", value);
  			}
  			remove {
  				this.RemoveSignalHandler ("preedit-start", value);
  			}
  		}
  
  		[GLib.Signal("preedit-changed")]
  		public event System.EventHandler PreeditChanged {
  			add {
  				this.AddSignalHandler ("preedit-changed", value);
  			}
  			remove {
  				this.RemoveSignalHandler ("preedit-changed", value);
  			}
  		}
  
  		static PreeditStartNativeDelegate PreeditStart_cb_delegate;
  		static PreeditStartNativeDelegate PreeditStartVMCallback {
  			get {
  				if (PreeditStart_cb_delegate == null)
  					PreeditStart_cb_delegate = new PreeditStartNativeDelegate (PreeditStart_cb);
  				return PreeditStart_cb_delegate;
  			}
  		}
  
  		static void OverridePreeditStart (GLib.GType gtype)
  		{
  			OverridePreeditStart (gtype, PreeditStartVMCallback);
  		}
  
  		static void OverridePreeditStart (GLib.GType gtype, PreeditStartNativeDelegate callback)
  		{
  			GtkIMContextClass class_iface = GetClassStruct (gtype, false);
  			class_iface.PreeditStart = callback;
  			OverrideClassStruct (gtype, class_iface);
  		}
  
  		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
  		delegate void PreeditStartNativeDelegate (IntPtr inst);
  
  		static void PreeditStart_cb (IntPtr inst)
  		{
  			try {
  				IMContext __obj = GLib.Object.GetObject (inst, false) as IMContext;
  				__obj.OnPreeditStart ();
  			} catch (Exception e) {
  				GLib.ExceptionManager.RaiseUnhandledException (e, false);
  			}
  		}
  
  		[GLib.DefaultSignalHandler(Type=typeof(Gtk.IMContext), ConnectionMethod="OverridePreeditStart")]
  		protected virtual void OnPreeditStart ()
  		{
  			InternalPreeditStart ();
  		}
  
  		private void InternalPreeditStart ()
  		{
  			PreeditStartNativeDelegate unmanaged = GetClassStruct (this.LookupGType ().GetThresholdType (), true).PreeditStart;
  			if (unmanaged == null) return;
  
  			unmanaged (this.Handle);
  		}
  
  		static PreeditEndNativeDelegate PreeditEnd_cb_delegate;
  		static PreeditEndNativeDelegate PreeditEndVMCallback {
  			get {
  				if (PreeditEnd_cb_delegate == null)
  					PreeditEnd_cb_delegate = new PreeditEndNativeDelegate (PreeditEnd_cb);
  				return PreeditEnd_cb_delegate;
  			}
  		}
  
  		static void OverridePreeditEnd (GLib.GType gtype)
  		{
  			OverridePreeditEnd (gtype, PreeditEndVMCallback);
  		}
  
  		static void OverridePreeditEnd (GLib.GType gtype, PreeditEndNativeDelegate callback)
  		{
  			GtkIMContextClass class_iface = GetClassStruct (gtype, false);
  			class_iface.PreeditEnd = callback;
  			OverrideClassStruct (gtype, class_iface);
  		}
  
  		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
  		delegate void PreeditEndNativeDelegate (IntPtr inst);
  
  		static void PreeditEnd_cb (IntPtr inst)
  		{
  			try {
  				IMContext __obj = GLib.Object.GetObject (inst, false) as IMContext;
  				__obj.OnPreeditEnd ();
  			} catch (Exception e) {
  				GLib.ExceptionManager.RaiseUnhandledException (e, false);
  			}
  		}
  
  		[GLib.DefaultSignalHandler(Type=typeof(Gtk.IMContext), ConnectionMethod="OverridePreeditEnd")]
  		protected virtual void OnPreeditEnd ()
  		{
  			InternalPreeditEnd ();
  		}
  
  		private void InternalPreeditEnd ()
  		{
  			PreeditEndNativeDelegate unmanaged = GetClassStruct (this.LookupGType ().GetThresholdType (), true).PreeditEnd;
  			if (unmanaged == null) return;
  
  			unmanaged (this.Handle);
  		}
  
  		static PreeditChangedNativeDelegate PreeditChanged_cb_delegate;
  		static PreeditChangedNativeDelegate PreeditChangedVMCallback {
  			get {
  				if (PreeditChanged_cb_delegate == null)
  					PreeditChanged_cb_delegate = new PreeditChangedNativeDelegate (PreeditChanged_cb);
  				return PreeditChanged_cb_delegate;
  			}
  		}
  
  		static void OverridePreeditChanged (GLib.GType gtype)
  		{
  			OverridePreeditChanged (gtype, PreeditChangedVMCallback);
  		}
  
  		static void OverridePreeditChanged (GLib.GType gtype, PreeditChangedNativeDelegate callback)
  		{
  			GtkIMContextClass class_iface = GetClassStruct (gtype, false);
  			class_iface.PreeditChanged = callback;
  			OverrideClassStruct (gtype, class_iface);
  		}
  
  		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
  		delegate void PreeditChangedNativeDelegate (IntPtr inst);
  
  		static void PreeditChanged_cb (IntPtr inst)
  		{
  			try {
  				IMContext __obj = GLib.Object.GetObject (inst, false) as IMContext;
  				__obj.OnPreeditChanged ();
  			} catch (Exception e) {
  				GLib.ExceptionManager.RaiseUnhandledException (e, false);
  			}
  		}
  
  		[GLib.DefaultSignalHandler(Type=typeof(Gtk.IMContext), ConnectionMethod="OverridePreeditChanged")]
  		protected virtual void OnPreeditChanged ()
  		{
  			InternalPreeditChanged ();
  		}
  
  		private void InternalPreeditChanged ()
  		{
  			PreeditChangedNativeDelegate unmanaged = GetClassStruct (this.LookupGType ().GetThresholdType (), true).PreeditChanged;
  			if (unmanaged == null) return;
  
  			unmanaged (this.Handle);
  		}
  
  		static CommitNativeDelegate Commit_cb_delegate;
  		static CommitNativeDelegate CommitVMCallback {
  			get {
  				if (Commit_cb_delegate == null)
  					Commit_cb_delegate = new CommitNativeDelegate (Commit_cb);
  				return Commit_cb_delegate;
  			}
  		}
  
  		static void OverrideCommit (GLib.GType gtype)
  		{
  			OverrideCommit (gtype, CommitVMCallback);
  		}
  
  		static void OverrideCommit (GLib.GType gtype, CommitNativeDelegate callback)
  		{
  			GtkIMContextClass class_iface = GetClassStruct (gtype, false);
  			class_iface.Commit = callback;
  			OverrideClassStruct (gtype, class_iface);
  		}
  
  		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
  		delegate void CommitNativeDelegate (IntPtr inst, IntPtr str);
  
  		static void Commit_cb (IntPtr inst, IntPtr str)
  		{
  			try {
  				IMContext __obj = GLib.Object.GetObject (inst, false) as IMContext;
  				__obj.OnCommit (GLib.Marshaller.Utf8PtrToString (str));
  			} catch (Exception e) {
  				GLib.ExceptionManager.RaiseUnhandledException (e, false);
  			}
  		}
  
  		[GLib.DefaultSignalHandler(Type=typeof(Gtk.IMContext), ConnectionMethod="OverrideCommit")]
  		protected virtual void OnCommit (string str)
  		{
  			InternalCommit (str);
  		}
  
  		private void InternalCommit (string str)
  		{
  			CommitNativeDelegate unmanaged = GetClassStruct (this.LookupGType ().GetThresholdType (), true).Commit;
  			if (unmanaged == null) return;
  
  			IntPtr native_str = GLib.Marshaller.StringToPtrGStrdup (str);
  			unmanaged (this.Handle, native_str);
  			GLib.Marshaller.Free (native_str);
  		}
  
  		static RetrieveSurroundingNativeDelegate RetrieveSurrounding_cb_delegate;
  		static RetrieveSurroundingNativeDelegate RetrieveSurroundingVMCallback {
  			get {
  				if (RetrieveSurrounding_cb_delegate == null)
  					RetrieveSurrounding_cb_delegate = new RetrieveSurroundingNativeDelegate (RetrieveSurrounding_cb);
  				return RetrieveSurrounding_cb_delegate;
  			}
  		}
  
  		static void OverrideRetrieveSurrounding (GLib.GType gtype)
  		{
  			OverrideRetrieveSurrounding (gtype, RetrieveSurroundingVMCallback);
  		}
  
  		static void OverrideRetrieveSurrounding (GLib.GType gtype, RetrieveSurroundingNativeDelegate callback)
  		{
  			GtkIMContextClass class_iface = GetClassStruct (gtype, false);
  			class_iface.RetrieveSurrounding = callback;
  			OverrideClassStruct (gtype, class_iface);
  		}
  
  		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
  		delegate bool RetrieveSurroundingNativeDelegate (IntPtr inst);
  
  		static bool RetrieveSurrounding_cb (IntPtr inst)
  		{
  			try {
  				IMContext __obj = GLib.Object.GetObject (inst, false) as IMContext;
  				bool __result;
  				__result = __obj.OnRetrieveSurrounding ();
  				return __result;
  			} catch (Exception e) {
  				GLib.ExceptionManager.RaiseUnhandledException (e, true);
  				// NOTREACHED: above call does not return.
  				throw e;
  			}
  		}
  
  		[GLib.DefaultSignalHandler(Type=typeof(Gtk.IMContext), ConnectionMethod="OverrideRetrieveSurrounding")]
  		protected virtual bool OnRetrieveSurrounding ()
  		{
  			return InternalRetrieveSurrounding ();
  		}
  
  		private bool InternalRetrieveSurrounding ()
  		{
  			RetrieveSurroundingNativeDelegate unmanaged = GetClassStruct (this.LookupGType ().GetThresholdType (), true).RetrieveSurrounding;
  			if (unmanaged == null) return false;
  
  			bool __result = unmanaged (this.Handle);
  			return __result;
  		}
  
  		static SurroundingDeletedNativeDelegate SurroundingDeleted_cb_delegate;
  		static SurroundingDeletedNativeDelegate SurroundingDeletedVMCallback {
  			get {
  				if (SurroundingDeleted_cb_delegate == null)
  					SurroundingDeleted_cb_delegate = new SurroundingDeletedNativeDelegate (SurroundingDeleted_cb);
  				return SurroundingDeleted_cb_delegate;
  			}
  		}
  
  		static void OverrideSurroundingDeleted (GLib.GType gtype)
  		{
  			OverrideSurroundingDeleted (gtype, SurroundingDeletedVMCallback);
  		}
  
  		static void OverrideSurroundingDeleted (GLib.GType gtype, SurroundingDeletedNativeDelegate callback)
  		{
  			GtkIMContextClass class_iface = GetClassStruct (gtype, false);
  			class_iface.SurroundingDeleted = callback;
  			OverrideClassStruct (gtype, class_iface);
  		}
  
  		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
  		delegate bool SurroundingDeletedNativeDelegate (IntPtr inst, int offset, int n_chars);
  
  		static bool SurroundingDeleted_cb (IntPtr inst, int offset, int n_chars)
  		{
  			try {
  				IMContext __obj = GLib.Object.GetObject (inst, false) as IMContext;
  				bool __result;
  				__result = __obj.OnSurroundingDeleted (offset, n_chars);
  				return __result;
  			} catch (Exception e) {
  				GLib.ExceptionManager.RaiseUnhandledException (e, true);
  				// NOTREACHED: above call does not return.
  				throw e;
  			}
  		}
  
  		[GLib.DefaultSignalHandler(Type=typeof(Gtk.IMContext), ConnectionMethod="OverrideSurroundingDeleted")]
  		protected virtual bool OnSurroundingDeleted (int offset, int n_chars)
  		{
  			return InternalSurroundingDeleted (offset, n_chars);
  		}
  
  		private bool InternalSurroundingDeleted (int offset, int n_chars)
  		{
  			SurroundingDeletedNativeDelegate unmanaged = GetClassStruct (this.LookupGType ().GetThresholdType (), true).SurroundingDeleted;
  			if (unmanaged == null) return false;
  
  			bool __result = unmanaged (this.Handle, offset, n_chars);
  			return __result;
  		}
  
  		static SetClientWindowNativeDelegate SetClientWindow_cb_delegate;
  		static SetClientWindowNativeDelegate SetClientWindowVMCallback {
  			get {
  				if (SetClientWindow_cb_delegate == null)
  					SetClientWindow_cb_delegate = new SetClientWindowNativeDelegate (SetClientWindow_cb);
  				return SetClientWindow_cb_delegate;
  			}
  		}
  
  		static void OverrideSetClientWindow (GLib.GType gtype)
  		{
  			OverrideSetClientWindow (gtype, SetClientWindowVMCallback);
  		}
  
  		static void OverrideSetClientWindow (GLib.GType gtype, SetClientWindowNativeDelegate callback)
  		{
  			GtkIMContextClass class_iface = GetClassStruct (gtype, false);
  			class_iface.SetClientWindow = callback;
  			OverrideClassStruct (gtype, class_iface);
  		}
  
  		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
  		delegate void SetClientWindowNativeDelegate (IntPtr inst, IntPtr window);
  
  		static void SetClientWindow_cb (IntPtr inst, IntPtr window)
  		{
  			try {
  				IMContext __obj = GLib.Object.GetObject (inst, false) as IMContext;
  				__obj.OnSetClientWindow (GLib.Object.GetObject(window) as Gdk.Window);
  			} catch (Exception e) {
  				GLib.ExceptionManager.RaiseUnhandledException (e, false);
  			}
  		}
  
  		[GLib.DefaultSignalHandler(Type=typeof(Gtk.IMContext), ConnectionMethod="OverrideSetClientWindow")]
  		protected virtual void OnSetClientWindow (Gdk.Window window)
  		{
  			InternalSetClientWindow (window);
  		}
  
  		private void InternalSetClientWindow (Gdk.Window window)
  		{
  			SetClientWindowNativeDelegate unmanaged = GetClassStruct (this.LookupGType ().GetThresholdType (), true).SetClientWindow;
  			if (unmanaged == null) return;
  
  			unmanaged (this.Handle, window == null ? IntPtr.Zero : window.Handle);
  		}
  
  		static GetPreeditStringNativeDelegate GetPreeditString_cb_delegate;
  		static GetPreeditStringNativeDelegate GetPreeditStringVMCallback {
  			get {
  				if (GetPreeditString_cb_delegate == null)
  					GetPreeditString_cb_delegate = new GetPreeditStringNativeDelegate (GetPreeditString_cb);
  				return GetPreeditString_cb_delegate;
  			}
  		}
  
  		static void OverrideGetPreeditString (GLib.GType gtype)
  		{
  			OverrideGetPreeditString (gtype, GetPreeditStringVMCallback);
  		}
  
  		static void OverrideGetPreeditString (GLib.GType gtype, GetPreeditStringNativeDelegate callback)
  		{
  			GtkIMContextClass class_iface = GetClassStruct (gtype, false);
  			class_iface.GetPreeditString = callback;
  			OverrideClassStruct (gtype, class_iface);
  		}
  
  		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
  		delegate void GetPreeditStringNativeDelegate (IntPtr inst, IntPtr str, IntPtr attrs, out int cursor_pos);
  
  		static void GetPreeditString_cb (IntPtr inst, IntPtr str, IntPtr attrs, out int cursor_pos)
  		{
  			try {
  				IMContext __obj = GLib.Object.GetObject (inst, false) as IMContext;
  				__obj.OnGetPreeditString (GLib.Marshaller.PtrToStringGFree(str), attrs == IntPtr.Zero ? null : (Pango.AttrList) GLib.Opaque.GetOpaque (attrs, typeof (Pango.AttrList), false), out cursor_pos);
  			} catch (Exception e) {
  				GLib.ExceptionManager.RaiseUnhandledException (e, true);
  				// NOTREACHED: above call does not return.
  				throw e;
  			}
  		}
  
  		[GLib.DefaultSignalHandler(Type=typeof(Gtk.IMContext), ConnectionMethod="OverrideGetPreeditString")]
  		protected virtual void OnGetPreeditString (string str, Pango.AttrList attrs, out int cursor_pos)
  		{
  			InternalGetPreeditString (str, attrs, out cursor_pos);
  		}
  
  		private void InternalGetPreeditString (string str, Pango.AttrList attrs, out int cursor_pos)
  		{
  			GetPreeditStringNativeDelegate unmanaged = GetClassStruct (this.LookupGType ().GetThresholdType (), true).GetPreeditString;
  			if (unmanaged == null) throw new InvalidOperationException ("No base method to invoke");
  
  			unmanaged (this.Handle, GLib.Marshaller.StringToPtrGStrdup(str), attrs == null ? IntPtr.Zero : attrs.Handle, out cursor_pos);
  		}
  
  		static FilterKeypressNativeDelegate FilterKeypress_cb_delegate;
  		static FilterKeypressNativeDelegate FilterKeypressVMCallback {
  			get {
  				if (FilterKeypress_cb_delegate == null)
  					FilterKeypress_cb_delegate = new FilterKeypressNativeDelegate (FilterKeypress_cb);
  				return FilterKeypress_cb_delegate;
  			}
  		}
  
  		static void OverrideFilterKeypress (GLib.GType gtype)
  		{
  			OverrideFilterKeypress (gtype, FilterKeypressVMCallback);
  		}
  
  		static void OverrideFilterKeypress (GLib.GType gtype, FilterKeypressNativeDelegate callback)
  		{
  			GtkIMContextClass class_iface = GetClassStruct (gtype, false);
  			class_iface.FilterKeypress = callback;
  			OverrideClassStruct (gtype, class_iface);
  		}
  
  		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
  		delegate bool FilterKeypressNativeDelegate (IntPtr inst, IntPtr evnt);
  
  		static bool FilterKeypress_cb (IntPtr inst, IntPtr evnt)
  		{
  			try {
  				IMContext __obj = GLib.Object.GetObject (inst, false) as IMContext;
  				bool __result;
  				__result = __obj.OnFilterKeypress (new Gdk.EventKey(evnt));
  				return __result;
  			} catch (Exception e) {
  				GLib.ExceptionManager.RaiseUnhandledException (e, true);
  				// NOTREACHED: above call does not return.
  				throw e;
  			}
  		}
  
  		[GLib.DefaultSignalHandler(Type=typeof(Gtk.IMContext), ConnectionMethod="OverrideFilterKeypress")]
  		protected virtual bool OnFilterKeypress (Gdk.EventKey evnt)
  		{
  			return InternalFilterKeypress (evnt);
  		}
  
  		private bool InternalFilterKeypress (Gdk.EventKey evnt)
  		{
  			FilterKeypressNativeDelegate unmanaged = GetClassStruct (this.LookupGType ().GetThresholdType (), true).FilterKeypress;
  
gt: 			if (unmanaged == null) return false;