+ // 2005.01.26 modified by Hong Jen Yee (hzysoft@sina.com.tw):
+ // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
+ // docs, if IM filter returns true, no further processing should be done.
+ // wWe should send the key_down event anyway.
+ if (useIM)
+ {
+ // it may be useful for the input method, though:
+ IM_ret = gtk_im_context_filter_keypress(win->m_imData->context, gdk_event);
+ win->m_imData->lastKeyEvent = NULL;
+ if (IM_ret)
+ wxLogTrace(TRACE_KEYS, _T("Key event intercepted by IM"));
+ }
+#endif
+
+ wxKeyEvent event( wxEVT_KEY_DOWN );
+ bool ret = FALSE;
+
+ // 2005.02.02 modified by Hong Jen Yee (hzysoft@sina.com.tw).
+ // In GTK+ 1.2, strings sent by IMs are also regarded as key_press events whose
+ // keyCodes cannot be recognized by wxWidgets. These MBCS strings, however, are
+ // composed of more than one character, which means gdk_event->length will always
+ // greater than one. When gtk_event->length == 1, this may be an ASCII character
+ // and can be translated by wx. However, when MBCS characters are sent by IM,
+ // gdk_event->length will >= 2. So neither should we pass it to accelerator table,
+ // nor should we pass it to controls. The following explanation was excerpted
+ // from GDK documentation.
+ // gint length : the length of string.
+ // gchar *string : a null-terminated multi-byte string containing the composed
+ // characters resulting from the key press. When text is being input, in a GtkEntry
+ // for example, it is these characters which should be added to the input buffer.
+ // When using Input Methods to support internationalized text input, the composed
+ // characters appear here after the pre-editing has been completed.
+
+#ifndef __WXGTK20__
+ // This is for GTK+ 1.2 only. The char event generatation for
+ // GTK+ 2.0 is done in the emit handler.
+
+ if ( (!ret) && (gdk_event->length > 1) ) // If this event contains a pre-edited string from IM.
+ {
+ // We should translate this key event into wxEVT_CHAR not wxEVT_KEY_DOWN.
+ #if wxUSE_UNICODE // GTK+ 1.2 is not UTF-8 based.
+ const wxWCharBuffer string = wxConvLocal.cMB2WC( gdk_event->string );
+ if( !string )
+ return false;
+ #else
+ const char* string = gdk_event->string;
+ #endif
+
+ // Implement OnCharHook by checking ancesteror top level windows
+ wxWindow *parent = window;
+ while (parent && !parent->IsTopLevel())
+ parent = parent->GetParent();
+
+ for( wxChar* pstr = string; *pstr; pstr++ )