Skip to content

Commit 60613c5

Browse files
author
Ichiroh Takiguchi
committed
8212678: Windows IME related patch
Reviewed-by: serb, naoto
1 parent 5aca7ef commit 60613c5

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

src/java.desktop/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, 2018, 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
@@ -65,6 +65,7 @@ final class WInputMethod extends InputMethodAdapter
6565
private Locale currentLocale;
6666
// indicate whether status window is hidden or not.
6767
private boolean statusWindowHidden = false;
68+
private boolean hasCompositionString = false;
6869

6970
// attribute definition in Win32 (in IMM.H)
7071
public static final byte ATTR_INPUT = 0x00;
@@ -246,6 +247,7 @@ else if (subset1 == InputSubset.FULLWIDTH_LATIN)
246247
} else if (locale.getLanguage().equals(Locale.KOREAN.getLanguage())) {
247248
if (subset1 == UnicodeBlock.BASIC_LATIN || subset1 == InputSubset.LATIN_DIGITS) {
248249
setOpenStatus(context, false);
250+
setConversionStatus(context, IME_CMODE_ALPHANUMERIC);
249251
} else {
250252
if (subset1 == UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
251253
|| subset1 == InputSubset.HANJA
@@ -263,11 +265,14 @@ else if (subset1 == InputSubset.FULLWIDTH_LATIN)
263265
} else if (locale.getLanguage().equals(Locale.CHINESE.getLanguage())) {
264266
if (subset1 == UnicodeBlock.BASIC_LATIN || subset1 == InputSubset.LATIN_DIGITS) {
265267
setOpenStatus(context, false);
268+
newmode = getConversionStatus(context);
269+
newmode &= ~IME_CMODE_FULLSHAPE;
270+
setConversionStatus(context, newmode);
266271
} else {
267272
if (subset1 == UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
268273
|| subset1 == InputSubset.TRADITIONAL_HANZI
269274
|| subset1 == InputSubset.SIMPLIFIED_HANZI)
270-
newmode = IME_CMODE_NATIVE;
275+
newmode = IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE;
271276
else if (subset1 == InputSubset.FULLWIDTH_LATIN)
272277
newmode = IME_CMODE_FULLSHAPE;
273278
else
@@ -318,6 +323,15 @@ public void activate() {
318323
setLocale(currentLocale, true);
319324
}
320325

326+
// Compare IM's composition string with Java's composition string
327+
if (hasCompositionString && !isCompositionStringAvailable(context)) {
328+
endCompositionNative(context, DISCARD_INPUT);
329+
sendInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
330+
EventQueue.getMostRecentEventTime(),
331+
null, null, null, null, null, 0, 0, 0);
332+
hasCompositionString = false;
333+
}
334+
321335
/* If the status window or Windows language bar is turned off due to
322336
native input method was switched to java input method, we
323337
have to turn it on otherwise it is gone for good until next time
@@ -345,6 +359,7 @@ public void deactivate(boolean isTemporary)
345359
isLastFocussedActiveClient = haveActiveClient();
346360
}
347361
isActive = false;
362+
hasCompositionString = isCompositionStringAvailable(context);
348363
}
349364

350365
/**
@@ -649,4 +664,5 @@ private WComponentPeer getNearestNativePeer(Component comp)
649664
static native Locale getNativeLocale();
650665
static native boolean setNativeLocale(String localeName, boolean onActivate);
651666
private native void openCandidateWindow(WComponentPeer peer, int x, int y);
667+
private native boolean isCompositionStringAvailable(int context);
652668
}

src/java.desktop/windows/native/libawt/windows/awt_Component.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 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
@@ -3869,6 +3869,11 @@ void AwtComponent::SetCompositionWindow(RECT& r)
38693869
return;
38703870
}
38713871
COMPOSITIONFORM cf = {CFS_DEFAULT, {0, 0}, {0, 0, 0, 0}};
3872+
LOGFONT lf;
3873+
HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
3874+
if (GetObject(hFont, sizeof(lf), (LPVOID)&lf) == sizeof(lf)) {
3875+
ImmSetCompositionFont(hIMC, &lf);
3876+
}
38723877
ImmSetCompositionWindow(hIMC, &cf);
38733878
ImmReleaseContext(hwnd, hIMC);
38743879
}

src/java.desktop/windows/native/libawt/windows/awt_InputMethod.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2014, 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
@@ -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)