diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 80d356d..7a2bd19 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -1285,6 +1285,28 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   g_type_class_add_private (gobject_class, sizeof (GtkTextViewPrivate));
 }
 
+static GtkIMContext*
+gtk_text_view_create_im_context (GtkTextView *text_view)
+{
+  GtkTextViewPrivate *priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
+  GtkIMContext* im_context = gtk_im_multicontext_new ();
+
+  gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (im_context),
+                                      priv->im_module);
+  if (text_view->text_window->bin_window)
+    gtk_im_context_set_client_window (im_context, text_view->text_window->bin_window);
+
+  g_signal_connect (im_context, "commit",
+                    G_CALLBACK (gtk_text_view_commit_handler), text_view);
+  g_signal_connect (im_context, "preedit-changed",
+                    G_CALLBACK (gtk_text_view_preedit_changed_handler), text_view);
+  g_signal_connect (im_context, "retrieve-surrounding",
+                    G_CALLBACK (gtk_text_view_retrieve_surrounding_handler), text_view);
+  g_signal_connect (im_context, "delete-surrounding",
+                    G_CALLBACK (gtk_text_view_delete_surrounding_handler), text_view);
+  return im_context;
+}
+
 static void
 gtk_text_view_init (GtkTextView *text_view)
 {
@@ -1315,19 +1337,7 @@ gtk_text_view_init (GtkTextView *text_view)
   text_view->virtual_cursor_x = -1;
   text_view->virtual_cursor_y = -1;
 
-  /* This object is completely private. No external entity can gain a reference
-   * to it; so we create it here and destroy it in finalize ().
-   */
-  text_view->im_context = gtk_im_multicontext_new ();
-
-  g_signal_connect (text_view->im_context, "commit",
-                    G_CALLBACK (gtk_text_view_commit_handler), text_view);
-  g_signal_connect (text_view->im_context, "preedit-changed",
- 		    G_CALLBACK (gtk_text_view_preedit_changed_handler), text_view);
-  g_signal_connect (text_view->im_context, "retrieve-surrounding",
- 		    G_CALLBACK (gtk_text_view_retrieve_surrounding_handler), text_view);
-  g_signal_connect (text_view->im_context, "delete-surrounding",
- 		    G_CALLBACK (gtk_text_view_delete_surrounding_handler), text_view);
+  text_view->im_context = NULL;
 
   text_view->cursor_visible = TRUE;
 
@@ -2099,7 +2109,7 @@ gtk_text_view_update_im_spot_location (GtkTextView *text_view)
 {
   GdkRectangle area;
 
-  if (text_view->layout == NULL)
+  if (text_view->layout == NULL || text_view->im_context == NULL)
     return;
   
   gtk_text_view_get_cursor_location (text_view, &area);
@@ -2371,13 +2381,13 @@ gtk_text_view_set_editable (GtkTextView *text_view,
       if (!setting)
 	{
 	  gtk_text_view_reset_im_context(text_view);
-	  if (GTK_WIDGET_HAS_FOCUS (text_view))
+	  if (GTK_WIDGET_HAS_FOCUS (text_view) && text_view->im_context != NULL)
 	    gtk_im_context_focus_out (text_view->im_context);
 	}
 
       text_view->editable = setting;
 
-      if (setting && GTK_WIDGET_HAS_FOCUS (text_view))
+      if (setting && GTK_WIDGET_HAS_FOCUS (text_view) && text_view->im_context != NULL)
 	gtk_im_context_focus_in (text_view->im_context);
 
       if (text_view->layout)
@@ -2947,7 +2957,8 @@ gtk_text_view_finalize (GObject *object)
   if (text_view->bottom_window)
     text_window_free (text_view->bottom_window);
 
-  g_object_unref (text_view->im_context);
+  if (text_view->im_context != NULL)
+    g_object_unref (text_view->im_context);
 
   g_free (priv->im_module);
 
@@ -3027,8 +3038,9 @@ gtk_text_view_set_property (GObject         *object,
     case PROP_IM_MODULE:
       g_free (priv->im_module);
       priv->im_module = g_value_dup_string (value);
-      if (GTK_IS_IM_MULTICONTEXT (text_view->im_context))
-        gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (text_view->im_context), priv->im_module);
+      if (g_strcmp0 (priv->im_module, "none"))
+        if (text_view->im_context != NULL)
+          gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (text_view->im_context), priv->im_module);
       break;
 
     default:
@@ -4225,6 +4237,16 @@ gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
       get_buffer (text_view) == NULL)
     return FALSE;
 
+  if (text_view->im_context == NULL)
+    {
+      GtkTextViewPrivate *priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
+      if (!g_strcmp0 (priv->im_module, "none"))
+        return FALSE;
+      text_view->im_context = gtk_text_view_create_im_context (text_view);
+      if (GTK_WIDGET_HAS_FOCUS (text_view))
+        gtk_im_context_focus_in (text_view->im_context);
+    }
+
   /* Make sure input method knows where it is */
   flush_update_im_spot_location (text_view);
 
@@ -4302,7 +4324,17 @@ gtk_text_view_key_release_event (GtkWidget *widget, GdkEventKey *event)
 
   if (text_view->layout == NULL || get_buffer (text_view) == NULL)
     return FALSE;
-      
+
+  if (text_view->im_context == NULL)
+    {
+      GtkTextViewPrivate *priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
+      if (!g_strcmp0 (priv->im_module, "none"))
+        return FALSE;
+      text_view->im_context = gtk_text_view_create_im_context (text_view);
+      if (GTK_WIDGET_HAS_FOCUS (text_view))
+        gtk_im_context_focus_in (text_view->im_context);
+    }
+
   insert = gtk_text_buffer_get_insert (get_buffer (text_view));
   gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
   if (gtk_text_iter_can_insert (&iter, text_view->editable) &&
@@ -4491,6 +4523,13 @@ gtk_text_view_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
 
   if (text_view->editable)
     {
+      if (text_view->im_context == NULL)
+        {
+          GtkTextViewPrivate *priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
+          if (!g_strcmp0 (priv->im_module, "none"))
+            return FALSE;
+          text_view->im_context = gtk_text_view_create_im_context (text_view);
+        }
       text_view->need_im_reset = TRUE;
       gtk_im_context_focus_in (GTK_TEXT_VIEW (widget)->im_context);
     }
@@ -4519,7 +4558,7 @@ gtk_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
 					keymap_direction_changed,
 					text_view);
 
-  if (text_view->editable)
+  if (text_view->editable && text_view->im_context != NULL)
     {
       text_view->need_im_reset = TRUE;
       gtk_im_context_focus_out (GTK_TEXT_VIEW (widget)->im_context);
@@ -7471,7 +7510,7 @@ gtk_text_view_mark_set_handler (GtkTextBuffer     *buffer,
       text_view->virtual_cursor_x = -1;
       text_view->virtual_cursor_y = -1;
       gtk_text_view_update_im_spot_location (text_view);
-      need_reset = TRUE;
+      need_reset = text_view->im_context != NULL;
     }
   else if (mark == gtk_text_buffer_get_selection_bound (buffer))
     {
@@ -7854,7 +7893,7 @@ popup_targets_received (GtkClipboard     *clipboard,
 	  gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
 	}
 
-      if (show_input_method_menu)
+      if (show_input_method_menu && text_view->im_context != NULL)
         {
 	  menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
 	  gtk_widget_show (menuitem);
@@ -8039,8 +8078,9 @@ text_window_realize (GtkTextWindow *win,
           gdk_cursor_unref (cursor);
         } 
 
-      gtk_im_context_set_client_window (GTK_TEXT_VIEW (widget)->im_context,
-                                        win->window);
+      if (GTK_TEXT_VIEW (widget)->im_context != NULL)
+        gtk_im_context_set_client_window (GTK_TEXT_VIEW (widget)->im_context,
+                                          win->window);
 
 
       gdk_window_set_background (win->bin_window,
@@ -8064,7 +8104,7 @@ text_window_realize (GtkTextWindow *win,
 static void
 text_window_unrealize (GtkTextWindow *win)
 {
-  if (win->type == GTK_TEXT_WINDOW_TEXT)
+  if (win->type == GTK_TEXT_WINDOW_TEXT && GTK_TEXT_VIEW (win->widget)->im_context != NULL)
     {
       gtk_im_context_set_client_window (GTK_TEXT_VIEW (win->widget)->im_context,
                                         NULL);
