Index: gtkimcontextxim.c
===================================================================
--- gtkimcontextxim.c	(revision 18886)
+++ gtkimcontextxim.c	(working copy)
@@ -1241,8 +1241,8 @@
   if (gtk_im_context_get_surrounding ((GtkIMContext *)context_xim,
                                       &surrounding, &cursor_index))
     {
-      gchar *text = NULL;
-      gsize text_len = 0;
+      gunichar *text = NULL;
+      glong text_len = 0;
       gint  subst_offset = 0, subst_nchars = 0;
       gint  i;
       gchar *p = surrounding + cursor_index, *q;
@@ -1279,7 +1279,7 @@
             q = g_utf8_next_char (q);
           if (i > 0)
             break;
-          text = g_locale_from_utf8 (p, q - p, NULL, &text_len, NULL);
+          text = g_utf8_to_ucs4 (p, q - p, NULL, &text_len, NULL);
           subst_offset = position;
           subst_nchars = conv_data->factor;
           break;
@@ -1289,7 +1289,7 @@
             q = g_utf8_prev_char (q);
           if (i > 0)
             break;
-          text = g_locale_from_utf8 (q, p - q, NULL, &text_len, NULL);
+          text = g_utf8_to_ucs4 (q, p - q, NULL, &text_len, NULL);
           subst_offset = position - conv_data->factor;
           subst_nchars = conv_data->factor;
           break;
@@ -1316,10 +1316,13 @@
             {
               conv_data->text->length = text_len;
               conv_data->text->feedback = NULL;
-              conv_data->text->encoding_is_wchar = False;
-              conv_data->text->string.mbs = (char *)malloc (text_len);
-              if (conv_data->text->string.mbs)
-                memcpy (conv_data->text->string.mbs, text, text_len);
+              conv_data->text->encoding_is_wchar = True;
+              conv_data->text->string.wcs = (wchar_t *)malloc (text_len * sizeof (wchar_t));
+              if (conv_data->text->string.wcs)
+                {
+                  for (i = 0; i < text_len; i++)
+                    conv_data->text->string.wcs[i] = text[i];
+                }
               else
                 {
                   free (conv_data->text);
