Index: libzvt.h
===================================================================
RCS file: /cvs/gnome/libzvt/libzvt/libzvt.h,v
retrieving revision 1.13
diff -u -r1.13 libzvt.h
--- libzvt.h	2002/05/14 04:04:07	1.13
+++ libzvt.h	2002/05/21 00:29:00
@@ -37,6 +37,7 @@
 #include <gtk/gtkadjustment.h>
 #include <gtk/gtkwidget.h>
 #include <gtk/gtksignal.h>
+#include <gtk/gtkimcontext.h>
 #include <libzvt/vtx.h>
 #include <libzvt/background.h>
 
@@ -119,8 +120,12 @@
   /*GdkColorContext *color_ctx;*/	/* Color context in use, where we allocate our colors */
   /* gulong colors [18];*/	/* Our colors, pixel values. */
   GdkColor colors [18];		/* GdkColor for colormap support */
-  /* GdkIC depecated, needto be substituted with GtkIMContext, not yet done */
-  /* GdkIC *ic;*/		/* input context */
+
+  /* input context */
+  GtkIMContext *ic;
+  guint16 preedit_length;	/* length of preedit string, in bytes */
+  guint16 preedit_cursor;	/* offset of cursor within preedit string, in chars */
+  gboolean      need_im_reset;
 
  /* file name of a pixmap, if NULL, none is loaded
   * and normal mode is used
Index: zvtterm.c
===================================================================
RCS file: /cvs/gnome/libzvt/libzvt/zvtterm.c,v
retrieving revision 1.186
diff -u -r1.186 zvtterm.c
--- zvtterm.c	2002/05/14 16:55:21	1.186
+++ zvtterm.c	2002/05/21 00:29:05
@@ -388,8 +388,10 @@
   /* Deprecated */
   /*
   term->color_ctx = 0;
-  term->ic = NULL;
   */
+  term->ic = NULL;
+  term->preedit_length = 0;
+  term->preedit_cursor = 0;
 
   /* grid sizing */
   term->grid_width = term->vx->vt.width;
@@ -407,10 +409,6 @@
   term->scroll_on_keystroke = 0;
   term->scroll_on_output = 0;
   term->blink_enabled = 1;
-  /* Deprecated */
-  /*
-  term->ic = NULL;
-  */
   term->in_expose = 0;
   term->transparent = 0;
   term->shaded = 0;
@@ -759,14 +757,12 @@
     term->adjustment = NULL;
   }
 
-  /* Deprecated */
-  /*
+  /* destroy input context */
   if (term->ic) {
-    gdk_ic_destroy(term->ic);
+    g_object_unref (term->ic);
     term->ic = NULL;
   }
-  */
-
+    
   /* release private data */
   if (zp) {
     if (zp->text_expand)
@@ -964,6 +960,47 @@
 }
 
 static void
+zvt_term_commit_handler (GtkIMContext  *context,
+			 const gchar   *str,
+			 ZvtTerm       *term)
+{
+  gint   length = 0;
+  gchar *locstr = g_locale_from_utf8 (str, -1, NULL, &length, NULL);
+
+  if (length > 0) {
+    vt_writechild (&term->vx->vt, locstr, length);
+    if (term->scroll_on_keystroke) zvt_term_scroll (term, 0);
+  }
+  g_free (locstr);
+}
+
+static void
+zvt_term_preedit_changed_handler (GtkIMContext *context,
+				  ZvtTerm *term)
+{
+  gchar *preedit_string;
+  gint cursor_pos;
+
+  gtk_im_context_get_preedit_string (context,
+				     &preedit_string, NULL,
+				     &cursor_pos);
+  term->preedit_length = strlen (preedit_string);
+  cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
+  term->preedit_cursor = cursor_pos;
+  g_free (preedit_string);
+
+}
+
+static void
+zvt_term_im_reset (ZvtTerm *term)
+{
+  if (term->ic && term->need_im_reset) {
+    term->need_im_reset = FALSE;
+    gtk_im_context_reset (term->ic);
+  }
+}
+
+static void
 zvt_term_realize (GtkWidget *widget)
 {
   ZvtTerm *term;
@@ -1066,20 +1103,18 @@
   term_force_size(term);
 
   /* input context */
-#ifdef UNDEF
-  if (gdk_im_ready () && !term->ic) {
-    GdkICAttr attr;
-    
-    /* FIXME: do we have any window yet? */
-    attr.style = GDK_IM_PREEDIT_NOTHING | GDK_IM_STATUS_NOTHING;
-    attr.client_window = attr.focus_window = widget->window;
-    term->ic = gdk_ic_new(&attr, GDK_IC_ALL_REQ);
-    
-    if (!term->ic) {
-      g_warning("Can't create input context.");
-    }
+  if (!term->ic) {
+    term->ic = gtk_im_multicontext_new ();
+    g_signal_connect (term->ic, "commit",
+		      G_CALLBACK (zvt_term_commit_handler), term);
+
+    gtk_im_context_set_client_window (term->ic, widget->window);
+    g_signal_connect (G_OBJECT(term->ic), "preedit-changed",
+		      GTK_SIGNAL_FUNC(zvt_term_preedit_changed_handler), term);
   }
-#endif /* UNDEF */
+  
+  if (term->ic)
+  
   /* if we have a delayed background set, set it here? */
   if (zp->background_queue) {
     zvt_term_background_load(term, zp->background_queue);
@@ -1129,6 +1164,9 @@
   g_object_unref (term->fore_gc);
   term->fore_gc = NULL;
 
+  if (term->ic)
+    gtk_im_context_set_client_window (term->ic, NULL);
+  
   if (GTK_WIDGET_CLASS (parent_class)->unrealize)
     (*GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
 }
@@ -1189,13 +1227,12 @@
   /* setup blinking cursor */
   if (term->blink_enabled && term->timeout_id == -1)
     term->timeout_id = gtk_timeout_add (500, zvt_term_cursor_blink, term);
-
-  /* Deprecated */
-  /*
-  if (term->ic)
-    gdk_im_begin (term->ic, widget->window);
-  */
 
+  if (term->ic) {
+    term->need_im_reset = TRUE;
+    gtk_im_context_focus_in (term->ic);
+  }
+  
   return FALSE;
 }
 
@@ -1222,12 +1259,11 @@
     term->timeout_id = -1;
   }
   
-  /* Deprecated */
-  /*
-  if (term->ic)
-    gdk_im_end ();
-  */
-
+  if (term->ic) {
+    term->need_im_reset = TRUE;
+    gtk_im_context_focus_out (term->ic);
+  }
+  
   return FALSE;
 }
 
@@ -1690,6 +1726,7 @@
 
   zvt_term_show_pointer (term);
 
+  zvt_term_im_reset (term);
 
   gdk_window_get_pointer(widget->window, &x, &y, &mask);
   x /= term->charwidth;
@@ -2511,6 +2548,13 @@
                             event->keyval,
                             event->state)){
   
+    if (term->ic) {
+      if (gtk_im_context_filter_keypress (term->ic, event)) {
+	term->need_im_reset = TRUE;
+	return TRUE;
+      }
+    }
+    
   switch (event->keyval) {
   case GDK_BackSpace:
     if (term->backspace_binding == ZVT_ERASE_CONTROL_H ||
@@ -2711,6 +2755,7 @@
   if (handled && p>buffer) {
     vt_writechild(&vx->vt, buffer, (p-buffer));
     if (term->scroll_on_keystroke) zvt_term_scroll (term, 0);
+    zvt_term_im_reset (term);
   }
   }
 
@@ -3413,26 +3458,32 @@
   }
   break;
   /* this is limited to 65535 characters! */
-  case ZVT_FONT_FONTSET: {
-    wchar_t *expandwc = zp->text_expand;
-    XFontSet fontset = (XFontSet) GDK_FONT_XFONT(f);
+  case ZVT_FONT_FONTSET:
+    {
+      char *expandmb = zp->text_expand;
+      XFontSet fontset = (XFontSet) GDK_FONT_XFONT(f);
 
-    for (i=0;i<len;i++) {
-      expandwc[i] = VT_ASCII(line->data[i+col]);
-    }
+      for (i = 0; i < len;i++)
+	expandmb[i] = VT_ASCII(line->data[i+col]);
 
-    /* render wide characters, with fill if we can */
-    if (dofill) {
-      XwcDrawImageString(GDK_WINDOW_XDISPLAY(widget->window), GDK_WINDOW_XWINDOW(real_drawable),
-			 fontset, GDK_GC_XGC(fgc), offx + x, offy + y, expandwc, len);
-    } else {
-      XwcDrawString(GDK_WINDOW_XDISPLAY(widget->window), GDK_WINDOW_XWINDOW(real_drawable),
-		    fontset, GDK_GC_XGC(fgc), offx + x, offy + y, expandwc, len);
+      /* render wide characters, with fill if we can */
+      if (dofill)
+	XmbDrawImageString (GDK_WINDOW_XDISPLAY(widget->window),
+			    GDK_WINDOW_XWINDOW(real_drawable),
+			    fontset, GDK_GC_XGC(fgc), offx + x, offy + y,
+			    expandmb, len);
+      else
+	XmbDrawString (GDK_WINDOW_XDISPLAY(widget->window),
+		       GDK_WINDOW_XWINDOW(real_drawable),
+		       fontset, GDK_GC_XGC(fgc), offx + x, offy + y,
+		       expandmb, len);
+      if (overstrike)
+	XmbDrawString (GDK_WINDOW_XDISPLAY(widget->window),
+		       GDK_WINDOW_XWINDOW(real_drawable),
+		       fontset, GDK_GC_XGC(fgc), offx + x + 1, offy + y,
+		       expandmb, len);
     }
-    if (overstrike)
-      XwcDrawString(GDK_WINDOW_XDISPLAY(widget->window), GDK_WINDOW_XWINDOW(real_drawable),
-		    fontset, GDK_GC_XGC(fgc), offx + x + 1, offy + y, expandwc, len);
-  }
+    break;
   }
   offx+=real_offx;
   offy+=real_offy;
