Re: UTF8 guarantees for GdkEntryKey



On Sun, 2003-04-06 at 11:10, Dave Malcolm wrote:
> Is the "string" field of a GdkEventKey guaranteed to be valid UTF-8?  Am I 
> correct in thinking that I ought to be able to write (regardless of 
> language/input method):
> 	g_return_if_fail(g_utf8_validate(event->string, -1, NULL));
> 
> I'm having problems with Cyrillic key entry in a custom XML editor widget I'm 
> writing (www.conglomerate.org, a free-as-in-GPL user-friendly XML editor).
> 
> Thanks in advance

The value of event->string is guaranteed to be completely useless;
you need to use GtkIMContext.

Quoting:

http://developer.gnome.org/doc/API/2.2/gdk/gdk-Event-Structures.html#GdkEventKey

gchar *string
 
 a string containing the an approximation of the text that would result  
 from this keypress. The only correct way to handle text input of text is
 using input methods (see GtkIMContext), so this field is deprecated and
 should never be used. (gdk_unicode_to_keyval() provides a
 non-deprecated way of getting an approximate translation for a key.) The
 string is encoded in the encoding of the current locale (Note: this for
 backwards compatibility: strings in GTK+ and GDK are typically in
 UTF-8.) and NUL-terminated. In some cases, the translation of the key
 code will be a single NUL byte, in which case looking at length is
 necessary to distinguish it from the an empty translation.

Regards,
                                              Owen





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