+#ifdef __WXGTK20__
+static void gtk_wxwindow_commit_cb (GtkIMContext *context,
+ const gchar *str,
+ wxWindow *window)
+{
+ wxKeyEvent event( wxEVT_KEY_DOWN );
+
+ // take modifiers, cursor position, timestamp etc. from the last
+ // key_press_event that was fed into Input Method:
+ if (window->m_imData->lastKeyEvent)
+ {
+ wxFillOtherKeyEventFields(event,
+ window, window->m_imData->lastKeyEvent);
+ }
+
+#if wxUSE_UNICODE
+ event.m_uniChar = g_utf8_get_char( str );
+
+ // Backward compatible for ISO-8859
+ if (event.m_uniChar < 256)
+ event.m_keyCode = event.m_uniChar;
+ wxLogTrace(TRACE_KEYS, _T("IM sent character '%c'"), event.m_uniChar);
+#else
+ wchar_t unistr[2];
+ unistr[0] = g_utf8_get_char(str);
+ unistr[1] = 0;
+ wxCharBuffer ansistr(wxConvLocal.cWC2MB(unistr));
+ // We cannot handle characters that cannot be represented in
+ // current locale's charset in non-Unicode mode:
+ if (ansistr.data() == NULL)
+ return;
+ event.m_keyCode = ansistr[0u];
+ wxLogTrace(TRACE_KEYS, _T("IM sent character '%c'"), (wxChar)event.m_keyCode);
+#endif // wxUSE_UNICODE
+
+ bool ret = false;
+
+ // Implement OnCharHook by checking ancestor top level windows
+ wxWindow *parent = window;
+ while (parent && !parent->IsTopLevel())
+ parent = parent->GetParent();
+ if (parent)
+ {
+ event.SetEventType( wxEVT_CHAR_HOOK );
+ ret = parent->GetEventHandler()->ProcessEvent( event );
+ }
+
+ if (!ret)
+ {
+ event.SetEventType(wxEVT_CHAR);
+ ret = window->GetEventHandler()->ProcessEvent( event );
+ }
+}
+#endif
+
+