Re: Unicode and input method

Robert Roebling t-online de (Robert Roebling) writes:

> I have written some sort of text editor
> with GTK 1.2 and I have converted it
> to GTK 2.0 now. Most things behave
> nicely, but I am still unable to enter
> any non-ascii characters, because I am
> unable to decode the key event. I read
> that the "string" part contains the
> actual character in "multi-byte" format.
> I am surprised to read that this is not
> done in utf8, but there is certainly some
> reason for it.

The string part of the event should be ignored; in fact,
I'm thinking of just making it always "". 
To do text input in GTK+-2.0, you need to use an input
method object. (You create a GtkIMMulticontext and
that will chain to the correct input method for the user.)

> Now the question, how do I correctly
> decode the string into utf8 or wchar_t
> and what is the official way to make
> input via (e.g. Japanese) input methods
> possible?
> I have read the code in GtkEntry.c but
> it doesn't seem to handle key press 
> events at all, it just forwards them
> to an input method filter. I was unable
> to see how the char finally arrives in
> the GtkEntry widget.

When the input context decides it has characters ready,
it sends a "commit" signal.

The only hard part about input methods is displaying the
preedit string ... what you need to do there is connect
to preedit_changed, and when you recieve that, use:

void     gtk_im_context_get_preedit_string  (GtkIMContext   *context,
					     gchar         **str,
					     PangoAttrList **attrs,
					     gint           *cursor_pos);

to get a string and list of attributes that you should
virtually insert into your text at the cursor position.

Since this can sometimes be a little tricky, you can call:

void     gtk_im_context_set_use_preedit     (GtkIMContext   *context,
					     gboolean        use_preedit);

To say "I can't do preedit preedit strings, fall back as best as
you can".


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