+ if (return_after_IM)
+ return false;
+
+#ifndef __WXGTK20__
+ // This is for GTK+ 1.2 only. The char event generatation for GTK+ 2.0 is done
+ // in the "commit" handler.
+
+ // 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.
+
+ 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 = win;
+ while (parent && !parent->IsTopLevel())
+ parent = parent->GetParent();
+
+ for( const wxChar* pstr = string; *pstr; pstr++ )
+ {
+ #if wxUSE_UNICODE
+ event.m_uniChar = *pstr;
+ // Backward compatible for ISO-8859-1
+ event.m_keyCode = *pstr < 256 ? event.m_uniChar : 0;
+ #else
+ event.m_keyCode = *pstr;
+ #endif
+ if (parent)
+ {
+ event.SetEventType( wxEVT_CHAR_HOOK );
+ ret = parent->GetEventHandler()->ProcessEvent( event );
+ }
+ if (!ret)
+ {
+ event.SetEventType(wxEVT_CHAR);
+ win->GetEventHandler()->ProcessEvent( event );
+ }
+ }
+ return true;