[PATCH] show preedit string



I made a patch for showing preedit string when using input
method.


Index: disp_callbacks.c
===================================================================
RCS file: /cvs/gnome/dia/app/disp_callbacks.c,v
retrieving revision 1.73
diff -u -r1.73 disp_callbacks.c
--- disp_callbacks.c    2 Nov 2003 10:58:30 -0000       1.73
+++ disp_callbacks.c    16 Jan 2004 13:57:29 -0000
@@ -364,11 +364,24 @@
          (the default IM on X should perform the local->UTF8 conversion)
       */
       
+  ddisplay_im_context_preedit_reset(ddisp, active_focus());
+
   handle_key_event(ddisp, active_focus(), 0, str, g_utf8_strlen(str,-1));
 }
 
 void ddisplay_im_context_preedit_changed(GtkIMContext *context,
                                          DDisplay *ddisp) {
+  gint cursor_pos;
+  Focus *focus = active_focus();
+
+  ddisplay_im_context_preedit_reset(ddisp, focus);
+  
+  gtk_im_context_get_preedit_string(context, &ddisp->preedit_string,
+                                    NULL, &cursor_pos);
+  if (ddisp->preedit_string != NULL) {
+    handle_key_event(ddisp, active_focus(), 0, ddisp->preedit_string,
+                     g_utf8_strlen(ddisp->preedit_string,-1));
+  }
 /*  char *str;
   PangoAttrList *attrs;
   gint cursor_pos;
Index: display.c
===================================================================
RCS file: /cvs/gnome/dia/app/display.c,v
retrieving revision 1.81
diff -u -r1.81 display.c
--- display.c   31 Dec 2003 11:44:37 -0000      1.81
+++ display.c   16 Jan 2004 13:57:30 -0000
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <math.h>
+#include <gdk/gdkkeysyms.h>
 
 #ifdef GNOME
 #include <gnome.h>
@@ -33,6 +34,7 @@
 #include "display.h"
 #include "group.h"
 #include "interface.h"
+#include "focus.h"
 #include "color.h"
 #include "handle_ops.h"
 #include "connectionpoint_ops.h"
@@ -173,6 +175,7 @@
   ddisp->im_context = gtk_im_multicontext_new();
   g_signal_connect (G_OBJECT (ddisp->im_context), "commit",
                     G_CALLBACK (ddisplay_im_context_commit), ddisp);
+  ddisp->preedit_string = NULL;
   g_signal_connect (G_OBJECT (ddisp->im_context), "preedit_changed",
                     G_CALLBACK (ddisplay_im_context_preedit_changed),
                     ddisp);
@@ -938,6 +941,8 @@
   g_object_unref (G_OBJECT (ddisp->im_context));
   ddisp->im_context = NULL;
 
+  ddisplay_im_context_preedit_reset(ddisp, active_focus());
+
   gtk_widget_destroy (ddisp->shell);
 }
 
@@ -1189,5 +1194,20 @@
                                      GTK_WINDOW(ddisp->shell));
       }
     }
+  }
+}
+
+void
+ddisplay_im_context_preedit_reset(DDisplay *ddisp, Focus *focus)
+{
+  if (ddisp->preedit_string != NULL) {
+    int i;
+    ObjectChange *change;
+    
+    for (i = 0; i < g_utf8_strlen(ddisp->preedit_string, -1); i++) {
+      (focus->key_event)(focus, GDK_BackSpace, NULL, 0, &change);
+    }
+               g_free(ddisp->preedit_string);
+    ddisp->preedit_string = NULL;
   }
 }
Index: display.h
===================================================================
RCS file: /cvs/gnome/dia/app/display.h,v
retrieving revision 1.29
diff -u -r1.29 display.h
--- display.h   10 Sep 2003 21:05:56 -0000      1.29
+++ display.h   16 Jan 2004 13:57:30 -0000
@@ -92,6 +92,9 @@
   guint update_id;                /* idle handler ID for redraws       */
 
   GtkIMContext *im_context;
+
+       /* Preedit String */
+       gchar* preedit_string;
 };
 
 extern GdkCursor *default_cursor;
@@ -154,5 +157,7 @@
 void ddisplay_do_update_menu_sensitivity (DDisplay *ddisp);
 
 void display_set_active(DDisplay *ddisp);
+
+void ddisplay_im_context_preedit_reset(DDisplay *ddisp, Focus *focus);
 
 #endif /* DDISPLAY_H */

--
kou



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]