diff --git a/src/gui/inputmethod/qwininputcontext_win.cpp b/src/gui/inputmethod/qwininputcontext_win.cpp
index 4005b72..9023dec 100644
--- a/src/gui/inputmethod/qwininputcontext_win.cpp
+++ b/src/gui/inputmethod/qwininputcontext_win.cpp
@@ -50,7 +50,7 @@
 #include "qtextformat.h"
 #include "qtextboundaryfinder.h"
 
-//#define Q_IME_DEBUG
+#define Q_IME_DEBUG
 
 #ifdef Q_IME_DEBUG
 #include "qdebug.h"
@@ -453,6 +453,7 @@ bool QWinInputContext::endComposition()
     if (fw) {
         Q_ASSERT(fw->testAttribute(Qt::WA_WState_Created));
         HIMC imc = getContext(fw->effectiveWinId());
+        qDebug() << __FUNCTION__ << "cancel";
         notifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
         releaseContext(fw->effectiveWinId(), imc);
         if(haveCaret) {
@@ -500,6 +501,7 @@ void QWinInputContext::reset()
 
     if (fw) {
         Q_ASSERT(fw->testAttribute(Qt::WA_WState_Created));
+        qDebug() << __FUNCTION__ << "cancel";
         HIMC imc = getContext(fw->effectiveWinId());
         notifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
         releaseContext(fw->effectiveWinId(), imc);
@@ -657,29 +659,37 @@ inline QWidget *findParentforPopup(QWidget *w)
 // enables or disables the ime 
 inline void enableIme(QWidget *w,  bool value) 
 {
+    qDebug() << __FUNCTION__ << '>' <<w << "winId" << w->internalWinId() << value;
     if (value) {
         // enable ime
-        if (defaultContext)
+        if (defaultContext) {
+            qDebug() << __FUNCTION__ << "ImmAssociateContext(w->effectiveWinId(), defaultContext=" << defaultContext;
             ImmAssociateContext(w->effectiveWinId(), defaultContext);
+        }
 #ifdef Q_WS_WINCE
         if (qApp->autoSipEnabled())
             qt_wince_show_SIP(true);
 #endif
     } else {
         // disable ime
+        qDebug() << __FUNCTION__ << "ImmAssociateContext(w->effectiveWinId(), 0";
         HIMC oldimc = ImmAssociateContext(w->effectiveWinId(), 0);
-        if (!defaultContext)
+        if (!defaultContext) {
+            qDebug() << __FUNCTION__ << "assigning defaultContext=oldimc" << oldimc;
             defaultContext = oldimc;
+        }
 #ifdef Q_WS_WINCE
         if (qApp->autoSipEnabled())
             qt_wince_show_SIP(false);
 #endif
     }
+    qDebug() << __FUNCTION__ << '<';
 }
 
 
 void QWinInputContext::updateImeStatus(QWidget *w, bool hasFocus)
 {
+    qDebug() << __FUNCTION__ << '>' <<  w << hasFocus;
     if (!w)
         return;
     // It's always the proxy that carries the hints.
@@ -698,10 +708,12 @@ void QWinInputContext::updateImeStatus(QWidget *w, bool hasFocus)
         else
             QWinInputContext::enable(w, hasIme);
     }
+    qDebug() << __FUNCTION__ << '<' << w;
 }
 
 void QWinInputContext::enablePopupChild(QWidget *w, bool e)
 {
+    qDebug() << __FUNCTION__  << w << e;
     if (aimm) {
         enable(w, e);
         return;
@@ -725,7 +737,7 @@ void QWinInputContext::enablePopupChild(QWidget *w, bool e)
 }
 
 void QWinInputContext::enable(QWidget *w, bool e)
-{
+{    
     if(w) {
 #ifdef Q_IME_DEBUG
         qDebug() <<"enable: w=" << w << "enable=" << e;
@@ -735,13 +747,16 @@ void QWinInputContext::enable(QWidget *w, bool e)
         if(aimm) {
             HIMC oldimc;
             if (!e) {
+                qDebug() << __FUNCTION__  << "disable IActiveIMMApp";
                 aimm->AssociateContext(w->effectiveWinId(), 0, &oldimc);
                 if (!defaultContext)
                     defaultContext = oldimc;
             } else if (defaultContext) {
+                qDebug() << __FUNCTION__  << "enabled IActiveIMMApp";
                 aimm->AssociateContext(w->effectiveWinId(), defaultContext, &oldimc);
             }
         } else {
+            qDebug() << __FUNCTION__  << "IActiveIMMApp==0";
             // update ime status on the widget
             QWidget *p = QWidget::find(w->effectiveWinId());
             if (p)
@@ -753,6 +768,7 @@ void QWinInputContext::enable(QWidget *w, bool e)
 void QWinInputContext::setFocusWidget(QWidget *w)
 {
     QWidget *oldFocus = focusWidget();
+    qDebug() << __FUNCTION__  << "old=" << oldFocus << "new" << w;
     if (oldFocus == w)
         return;
     if (w) {
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index 428588d..98a4c48 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -2225,6 +2225,7 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
             || !focus_widget->testAttribute(Qt::WA_WState_Created))))) {
              QInputContext *qic = prev->inputContext();
             if(qic) {
+                qDebug() << __FUNCTION__ << "clearing IM focus (for" << focus_widget << ')';
                 qic->reset();
                 qic->setFocusWidget(0);
             }
@@ -2269,8 +2270,10 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
                 if (focus->testAttribute(Qt::WA_InputMethodEnabled)) {
                     QInputContext *qic = focus->inputContext();
                     if (qic && focus->testAttribute(Qt::WA_WState_Created)
-                        && focus->isEnabled())
+                        && focus->isEnabled()) {
+                        qDebug() << __FUNCTION__ << "setting IM focus" << focus;
                         qic->setFocusWidget(focus);
+                    }
                 }
 #endif //QT_NO_IM
                 QFocusEvent in(QEvent::FocusIn, reason);
