IM Context Filter for Chinese Input


I'm trying to write an application, in which there is
a GtkEntry, in which the user will type chinese
characters using the IME available on Red Hat (xcin). 
Refer on
how i'm trying to type the characters.

Now I have a GtkEntry, in which I connect a
"key-press-event" signal, so that I can process the
characters that are typed.

But before I process the characters, I must let the
IME process the characters typed by calling
gtk_im_context_filter_keypress() function.  If this
function returns TRUE, I return TRUE from the
key-press-callback.  Otherwise I do something with the
character, and then return FALSE from the function.

The problem is that when I type somethign in chinese,
and confirm the input, and then if I press a function
key such as HOME, then the program goes into an
infinite loop, calling my key-press-callback

Please help me understand if there is something wrong
with my code, or is this a bug with GTK IME?


See code of my small sample program below.

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>

gboolean keypresscallback(GtkWidget *widget, GdkEvent
*event, gpointer data)
                return TRUE;

        return FALSE;

int main( int   argc,
          char *argv[] )

    GtkWidget *window;
    GtkWidget *vbox, *hbox;
    GtkWidget *entry1;
    GtkWidget *entry2;
    GtkWidget *entry3;
    GtkWidget *entry4;

    gtk_init (&argc, &argv);

    /* create a new window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request (GTK_WIDGET (window),
200, 100);
    gtk_window_set_title (GTK_WINDOW (window), "GTK
    g_signal_connect (G_OBJECT (window), "destroy",
                      G_CALLBACK (gtk_main_quit),
    g_signal_connect_swapped (G_OBJECT (window),
                              G_OBJECT (window));

    vbox = gtk_vbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), vbox);
    gtk_widget_show (vbox);

    entry1 = gtk_entry_new();
    g_signal_connect (G_OBJECT (entry1),
                      G_CALLBACK (keypresscallback),

    gtk_box_pack_start (GTK_BOX (vbox), entry1, TRUE,
TRUE, 0);
    gtk_widget_show (entry1);

    hbox = gtk_hbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (vbox), hbox);
    gtk_widget_show (hbox);

    gtk_widget_show (window);


    return 0;

Yahoo! Mail - PC Magazine Editors' Choice 2005

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