Re: Problems in Typing Vietnamese in Gtk application



Hey Arvind,

Thanks for the response.  I was away from town last week, so couldn't
respond earlier.

Are you talking about the gtk_im_context_get_preedit_string() API?  If
so, that won't work for me, because in my case this is not returning
the complete string, but is always empty.  Note that the
"preedit_changed_cb" is never being called in case of Vietnamese -
what's happening is that the "commit_cb" is getting called at each
key-press.  And a call to gtk_im_context_get_preedit_string() from the
commit_cb() returns empty string.

I looked around on the GtkIMContext page at
http://developer.gnome.org/doc/API/2.0/gtk/GtkIMContext.html, but
couldn't find any such API (that you referred to).

Please do let me know if you can recall the API that you were talking
about.  Also adding the Gtk list to CC, so if this strikes anybody
else, they may help me out.

Thanks,
Gaurav

On 9/29/05, Arvind Sachdeva <asachdeva gmail com> wrote:
> There is definetly a way to do get the current contents of the IMContext as utf8 string ( with all conversions done). You can retrieve the contents from IMContext and use that to display the whole string in the label/form widget instead of doing character by character translation.
>  I have done it in the past but don't remember the exact api.
>
>   -Arvind Sachdeva.
>
>
>
>
> On 9/29/05, Gaurav Jain <gaurav anywhere gmail com> wrote:
> >
> >  Hello!
> >
> > I have a small program (code at the end of this mail), in which I'm trying
> > to achieve the following:
> > - Type Vietnamese characters, such that the key-presses are processed by a
> > GtkLayout, and the actual text is shown on a GtkLabel. I cannot directly use
> > a GtkEntry or a GtkTextView, (which both work fine, if I were allowed to use
> > them)
> >
> > Now whenever a vowel's accent is typed subsequent to the vowel (e.g., if I
> > type 'ee', this should become 'ê'), the key-press-callback returns 'e' both
> > times. The GtkIMContext's commit-callback returns "e" first time, and "ê" on
> > the second time. The problem is that I'm unable to find out a way to realize
> > that the second "ê" corresponds to the first "e", and I'm supposed to erase
> > the "e" from the GtkLabel, and replace it with a "ê". There are callbacks
> > called "retrieve_surrounding" and "delete_surrounding" in the GtkIMContext
> > which sound like they may help me out (if I get the opportunity to provide
> > the context to the IME), but they are actually NEVER called!
> >
> > Could somebody help me understand if any of the following are possible, and
> > how:
> > 1) Somehow get the IME to invoke the "retrieve_surrounding" and
> > "delete_surrounding" callbacks, so that I can provide the context to the
> > IME, and delete the already entered characters if I'm typing a new accented
> > version of a character (like the "ê").
> >  2) Somehow be able to calculate that the character 'ê' is an accented
> > version of the character 'e' (in general for any accented character in
> > vietnamese).
> >
> > If any of the above is possible, I would be able to resolve my problem.
> > Maybe there's a third way to do it too. I'm using Red Hat EL Workstation 4.0,
> > and the IME is called X-Unikey (http://unikey.sourceforge.net/linux.php)
> >
> > Sorry about the long mail, but since the problem is a bit deep, I needed to
> > give some explanation. Any help in this regard would be highly
> > appreciated!!!
> >
> > Thanks in advance,
> > Gaurav
> >
> > ----- code follows -----
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <gtk/gtk.h>
> > #include <gdk/gdk.h>
> >
> > GtkWidget *layout;
> > GtkIMContext *imContext = NULL;
> > GtkWidget *label;
> > gboolean keypresscallback(GtkWidget *widget, GdkEvent *event, gpointer data)
> > {
> > //printf("keypresscallback, event->key = %d\n", event->key);
> > //const char *full_text = gtk_label_get_label(GTK_LABEL(label));
> > //int length = g_utf8_strlen(full_text, -1);
> > //gtk_im_context_set_surrounding(imContext, full_text, length, length);
> > if (gtk_im_context_filter_keypress(imContext, &(event->key)))
> > {
> > return TRUE;
> > }
> >
> > return FALSE;
> > }
> >
> > void commit_cb(GtkIMContext *context, const gchar *str, gpointer data)
> > {
> > GtkWidget *entry = (GtkWidget *)data;
> > printf("commit_cb [%s], %d\n", str, str[0]);
> > //gtk_im_context_set_surrounding(context, full_text, length, length);
> > const char *old_text = gtk_label_get_label(GTK_LABEL(label));
> > int length = g_utf8_strlen(old_text, -1);
> > char *full_text = (char *)malloc(length + 1 + g_utf8_strlen(str, -1));
> > strcpy(full_text, old_text);
> > strcat(full_text, str);
> > gtk_label_set_text(GTK_LABEL(label), full_text);
> > free(full_text);
> > }
> >
> > void preedit_start_cb(GtkIMContext *imContext, gpointer clientData)
> > {
> > printf("preedit_start_cb\n");
> > }
> >
> > void preedit_changed_cb(GtkIMContext *imContext, gpointer clientData)
> > {
> > printf("preedit_changed_cb\n");
> > }
> >
> > void preedit_end_cb(GtkIMContext *imContext, gpointer clientData)
> > {
> > printf("preedit_end_cb\n");
> > }
> >
> > gboolean retrieve_surrounding_cb(GtkIMContext *context, gpointer data)
> > {
> > printf("retrieve_surrounding_cb\n");
> > return FALSE;
> > }
> >
> > gboolean delete_surrounding_cb(GtkIMContext *context, gint offset, gint
> > n_chars, gpointer data)
> > {
> > printf("delete_surrounding_cb\n");
> > return FALSE;
> > }
> >
> > int main( int argc, char *argv[] )
> > {
> > GtkWidget *window;
> > GtkWidget *vbox, *hbox;
> >
> > 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), "Typing Vietnamese");
> > g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit),
> > NULL);
> > g_signal_connect_swapped (G_OBJECT (window), "delete_event", G_CALLBACK
> > (gtk_widget_destroy), G_OBJECT (window));
> >
> > vbox = gtk_vbox_new (FALSE, 0);
> > gtk_container_add (GTK_CONTAINER (window), vbox);
> > gtk_widget_show (vbox);
> >
> > /* add layout */
> > GdkColor layout_color = {0, 0xFFFF, 0x0000, 0x0000};
> > layout = gtk_layout_new(NULL, NULL);
> > GTK_WIDGET_SET_FLAGS(layout, GTK_CAN_FOCUS);
> > gtk_widget_modify_bg(layout, GTK_STATE_NORMAL, &layout_color);
> > gtk_box_pack_start (GTK_BOX (vbox), layout, TRUE, TRUE, 0);
> > gtk_widget_show (layout);
> >
> > /* add label */
> > label = gtk_label_new("");
> > gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
> > gtk_widget_show (label);
> >
> > hbox = gtk_hbox_new (FALSE, 0);
> > gtk_container_add (GTK_CONTAINER (vbox), hbox);
> >  gtk_widget_show (hbox);
> >
> > gtk_widget_show (window);
> >
> > /* add events to the layout */
> > GdkWindow *gdkWin = GTK_LAYOUT(layout)->bin_window;
> > gint eveMask = gdk_window_get_events(gdkWin);
> > eveMask |= GDK_ALL_EVENTS_MASK;
> > gdk_window_set_events(gdkWin, (GdkEventMask)eveMask);
> > gtk_widget_add_events(layout, GDK_ALL_EVENTS_MASK);
> > g_signal_connect (G_OBJECT (layout), "key-press-event", G_CALLBACK
> > (keypresscallback), NULL);
> >
> > /* create the IM context */
> > imContext = gtk_im_multicontext_new();
> > g_signal_connect(G_OBJECT(imContext), "commit", G_CALLBACK(commit_cb),
> > (gpointer)label);
> > g_signal_connect(G_OBJECT(imContext), "preedit_changed",
> > G_CALLBACK(preedit_changed_cb), (gpointer)label);
> > g_signal_connect(G_OBJECT(imContext), "preedit_start",
> > G_CALLBACK(preedit_start_cb), (gpointer)label);
> > g_signal_connect(G_OBJECT(imContext), "preedit_end",
> > G_CALLBACK(preedit_end_cb), (gpointer)label);
> > g_signal_connect (G_OBJECT (imContext), "retrieve_surrounding", G_CALLBACK
> > (retrieve_surrounding_cb), label);
> > g_signal_connect (G_OBJECT (imContext), "delete_surrounding", G_CALLBACK
> > (delete_surrounding_cb), label);
> > GdkWindow *im_context_window = (GTK_IS_LAYOUT(layout) ?
> > (GTK_LAYOUT(layout))->bin_window: layout->window);
> > gtk_im_context_set_client_window (imContext, im_context_window);
> >
> > gtk_main();
> >
> > return 0;
> > }
> > _______________________________________________
> > gtk-app-devel-list mailing list
> > gtk-app-devel-list gnome org
> >  http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> >
>
>



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