Skip to content

Commit 8304a76

Browse files
Takuya Kiriyamajerboaa
authored andcommitted
8212678: Windows IME related patch
Reviewed-by: andrew Backport-of: 60613c5fbc2554cbbf09d79804de276b9c2d786c
1 parent f67be21 commit 8304a76

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

jdk/src/windows/classes/sun/awt/windows/WInputMethod.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,7 @@ final class WInputMethod extends InputMethodAdapter
6262
private Locale currentLocale;
6363
// indicate whether status window is hidden or not.
6464
private boolean statusWindowHidden = false;
65+
private boolean hasCompositionString = false;
6566

6667
// attribute definition in Win32 (in IMM.H)
6768
public final static byte ATTR_INPUT = 0x00;
@@ -241,6 +242,7 @@ else if (subset1 == InputSubset.FULLWIDTH_LATIN)
241242
} else if (locale.getLanguage().equals(Locale.KOREAN.getLanguage())) {
242243
if (subset1 == UnicodeBlock.BASIC_LATIN || subset1 == InputSubset.LATIN_DIGITS) {
243244
setOpenStatus(context, false);
245+
setConversionStatus(context, IME_CMODE_ALPHANUMERIC);
244246
} else {
245247
if (subset1 == UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
246248
|| subset1 == InputSubset.HANJA
@@ -258,11 +260,14 @@ else if (subset1 == InputSubset.FULLWIDTH_LATIN)
258260
} else if (locale.getLanguage().equals(Locale.CHINESE.getLanguage())) {
259261
if (subset1 == UnicodeBlock.BASIC_LATIN || subset1 == InputSubset.LATIN_DIGITS) {
260262
setOpenStatus(context, false);
263+
newmode = getConversionStatus(context);
264+
newmode &= ~IME_CMODE_FULLSHAPE;
265+
setConversionStatus(context, newmode);
261266
} else {
262267
if (subset1 == UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
263268
|| subset1 == InputSubset.TRADITIONAL_HANZI
264269
|| subset1 == InputSubset.SIMPLIFIED_HANZI)
265-
newmode = IME_CMODE_NATIVE;
270+
newmode = IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE;
266271
else if (subset1 == InputSubset.FULLWIDTH_LATIN)
267272
newmode = IME_CMODE_FULLSHAPE;
268273
else
@@ -313,6 +318,15 @@ public void activate() {
313318
setLocale(currentLocale, true);
314319
}
315320

321+
// Compare IM's composition string with Java's composition string
322+
if (hasCompositionString && !isCompositionStringAvailable(context)) {
323+
endCompositionNative(context, DISCARD_INPUT);
324+
sendInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
325+
EventQueue.getMostRecentEventTime(),
326+
null, null, null, null, null, 0, 0, 0);
327+
hasCompositionString = false;
328+
}
329+
316330
/* If the status window or Windows language bar is turned off due to
317331
native input method was switched to java input method, we
318332
have to turn it on otherwise it is gone for good until next time
@@ -340,6 +354,7 @@ public void deactivate(boolean isTemporary)
340354
isLastFocussedActiveClient = haveActiveClient();
341355
}
342356
isActive = false;
357+
hasCompositionString = isCompositionStringAvailable(context);
343358
}
344359

345360
/**
@@ -644,4 +659,5 @@ private WComponentPeer getNearestNativePeer(Component comp)
644659
static native Locale getNativeLocale();
645660
static native boolean setNativeLocale(String localeName, boolean onActivate);
646661
private native void openCandidateWindow(WComponentPeer peer, int x, int y);
662+
private native boolean isCompositionStringAvailable(int context);
647663
}

jdk/src/windows/native/sun/windows/awt_Component.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,6 +3832,11 @@ void AwtComponent::SetCompositionWindow(RECT& r)
38323832
return;
38333833
}
38343834
COMPOSITIONFORM cf = {CFS_DEFAULT, {0, 0}, {0, 0, 0, 0}};
3835+
LOGFONT lf;
3836+
HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
3837+
if (GetObject(hFont, sizeof(lf), (LPVOID)&lf) == sizeof(lf)) {
3838+
ImmSetCompositionFont(hIMC, &lf);
3839+
}
38353840
ImmSetCompositionWindow(hIMC, &cf);
38363841
ImmReleaseContext(hwnd, hIMC);
38373842
}

jdk/src/windows/native/sun/windows/awt_InputMethod.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,23 @@ JNIEXPORT jobjectArray JNICALL Java_sun_awt_windows_WInputMethodDescriptor_getNa
528528
CATCH_BAD_ALLOC_RET(NULL);
529529
}
530530

531+
/*
532+
* Class: sun_awt_windows_WInputMethod
533+
* Method: isCompositionStringAvailable
534+
* Signature: (I)Z
535+
*/
536+
JNIEXPORT jboolean JNICALL Java_sun_awt_windows_WInputMethod_isCompositionStringAvailable
537+
(JNIEnv *env, jobject self, jint context)
538+
{
539+
LONG length;
540+
length = ImmGetCompositionString((HIMC)IntToPtr(context), GCS_COMPSTR, NULL, 0);
541+
if (length > 0) {
542+
return JNI_TRUE;
543+
} else {
544+
return JNI_FALSE;
545+
}
546+
}
547+
531548
/**
532549
* Class: sun_awt_windows_WInputMethod
533550
* Method: getNativeIMMDescription

0 commit comments

Comments
 (0)