From ccb20c8f04dc24924a18ac63b64afa69a988d4b3 Mon Sep 17 00:00:00 2001 From: KIRIYAMA Takuya Date: Tue, 21 Oct 2025 17:54:45 +0900 Subject: [PATCH] 8212678: Windows IME related patch --- .../classes/sun/awt/windows/WInputMethod.java | 20 +++++++++++++++++-- .../native/sun/windows/awt_Component.cpp | 5 +++++ .../native/sun/windows/awt_InputMethod.cpp | 17 ++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/jdk/src/windows/classes/sun/awt/windows/WInputMethod.java b/jdk/src/windows/classes/sun/awt/windows/WInputMethod.java index 3e2fbfa71ce..b54bf97d15a 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WInputMethod.java +++ b/jdk/src/windows/classes/sun/awt/windows/WInputMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -62,6 +62,7 @@ final class WInputMethod extends InputMethodAdapter 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; @@ -241,6 +242,7 @@ else if (subset1 == InputSubset.FULLWIDTH_LATIN) } else if (locale.getLanguage().equals(Locale.KOREAN.getLanguage())) { if (subset1 == UnicodeBlock.BASIC_LATIN || subset1 == InputSubset.LATIN_DIGITS) { setOpenStatus(context, false); + setConversionStatus(context, IME_CMODE_ALPHANUMERIC); } else { if (subset1 == UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || subset1 == InputSubset.HANJA @@ -258,11 +260,14 @@ else if (subset1 == InputSubset.FULLWIDTH_LATIN) } else if (locale.getLanguage().equals(Locale.CHINESE.getLanguage())) { if (subset1 == UnicodeBlock.BASIC_LATIN || subset1 == InputSubset.LATIN_DIGITS) { setOpenStatus(context, false); + newmode = getConversionStatus(context); + newmode &= ~IME_CMODE_FULLSHAPE; + setConversionStatus(context, newmode); } else { if (subset1 == UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || subset1 == InputSubset.TRADITIONAL_HANZI || subset1 == InputSubset.SIMPLIFIED_HANZI) - newmode = IME_CMODE_NATIVE; + newmode = IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE; else if (subset1 == InputSubset.FULLWIDTH_LATIN) newmode = IME_CMODE_FULLSHAPE; else @@ -313,6 +318,15 @@ public void activate() { 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 @@ -340,6 +354,7 @@ public void deactivate(boolean isTemporary) isLastFocussedActiveClient = haveActiveClient(); } isActive = false; + hasCompositionString = isCompositionStringAvailable(context); } /** @@ -644,4 +659,5 @@ private WComponentPeer getNearestNativePeer(Component comp) 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); } diff --git a/jdk/src/windows/native/sun/windows/awt_Component.cpp b/jdk/src/windows/native/sun/windows/awt_Component.cpp index c4dc99cf209..ca9a6a09b75 100644 --- a/jdk/src/windows/native/sun/windows/awt_Component.cpp +++ b/jdk/src/windows/native/sun/windows/awt_Component.cpp @@ -3832,6 +3832,11 @@ void AwtComponent::SetCompositionWindow(RECT& r) return; } COMPOSITIONFORM cf = {CFS_DEFAULT, {0, 0}, {0, 0, 0, 0}}; + LOGFONT lf; + HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT); + if (GetObject(hFont, sizeof(lf), (LPVOID)&lf) == sizeof(lf)) { + ImmSetCompositionFont(hIMC, &lf); + } ImmSetCompositionWindow(hIMC, &cf); ImmReleaseContext(hwnd, hIMC); } diff --git a/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp b/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp index d70ab901151..fcc6e4c2cb8 100644 --- a/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp +++ b/jdk/src/windows/native/sun/windows/awt_InputMethod.cpp @@ -528,6 +528,23 @@ JNIEXPORT jobjectArray JNICALL Java_sun_awt_windows_WInputMethodDescriptor_getNa 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