--- old/src/windows/classes/sun/awt/windows/WInputMethod.java 2013-05-07 15:05:31.834779625 +0800 +++ new/src/windows/classes/sun/awt/windows/WInputMethod.java 2013-05-07 15:05:31.626779621 +0800 @@ -62,6 +62,7 @@ private Locale currentLocale; // indicate whether status window is hidden or not. private boolean statusWindowHidden = false; + private boolean hasCompositionString = false; // attribute definition in Win32 (in IMM.H) public final static byte ATTR_INPUT = 0x00; @@ -304,6 +305,15 @@ setLocale(currentLocale, true); } + // Compare IM's composition string with Java's composition string + if (hasCompositionString && !isCompositionStringAvailable(context)) { + endCompositionNative(context, DISCARD_INPUT); + sendInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, + EventQueue.getMostRecentEventTime(), + null, null, null, null, null, 0, 0, 0); + hasCompositionString = false; + } + /* If the status window or Windows language bar is turned off due to native input method was switched to java input method, we have to turn it on otherwise it is gone for good until next time @@ -330,6 +340,7 @@ isLastFocussedActiveClient = haveActiveClient(); } isActive = false; + hasCompositionString = isCompositionStringAvailable(context); } /** @@ -620,4 +631,5 @@ static native Locale getNativeLocale(); static native boolean setNativeLocale(String localeName, boolean onActivate); private native void openCandidateWindow(WComponentPeer peer, int x, int y); + private native boolean isCompositionStringAvailable(int context); } --- old/src/windows/native/sun/windows/awt_InputMethod.cpp 2013-05-07 15:05:32.578779644 +0800 +++ new/src/windows/native/sun/windows/awt_InputMethod.cpp 2013-05-07 15:05:32.370779639 +0800 @@ -496,6 +496,23 @@ CATCH_BAD_ALLOC_RET(NULL); } +/* + * Class: sun_awt_windows_WInputMethod + * Method: isCompositionStringAvailable + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_sun_awt_windows_WInputMethod_isCompositionStringAvailable + (JNIEnv *env, jobject self, jint context) +{ + LONG length; + length = ImmGetCompositionString((HIMC)IntToPtr(context), GCS_COMPSTR, NULL, 0); + if (length > 0) { + return JNI_TRUE; + } else { + return JNI_FALSE; + } +} + /** * Class: sun_awt_windows_WInputMethod * Method: getNativeIMMDescription