diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java index 64d8a101d69f..305a58f35b00 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java @@ -292,6 +292,18 @@ public class CInputMethod extends InputMethodAdapter { if (component.getInputMethodRequests() == null) { imInstance = null; } + + LWWindowPeer windowPeer = peer.getPlatformWindow().getPeer(); + if (windowPeer.isSimpleWindow()) { + // A simple window gains focus. Cocoa won't dispatch IME events into the simple window, but into its owner. + // This IM represents the focused component in the simple window. We will use the owner as IME proxy. + // For that, this IM is set for the owner and is dropped for the simple window. + Window owner = windowPeer.getTarget().getOwner(); + assert owner != null && owner.isActive(); + long ownerPtr = getNativeViewPtr((LWComponentPeer)AWTAccessor.getComponentAccessor().getPeer(owner)); + nativeNotifyPeer(ownerPtr, this); + imInstance = null; + } } if (peer != null) { @@ -368,6 +380,14 @@ public class CInputMethod extends InputMethodAdapter { fAwtFocussedComponentPeer = null; } + private boolean isValid() { + return fIMContext != null && + fAwtFocussedComponent != null && + fAwtFocussedComponentPeer != null && + fCurrentText != null && + fCurrentTextAsString != null; + } + /** * Returns a control object from this input method, or null. A * control object provides methods that control the behavior of the @@ -587,6 +607,7 @@ public class CInputMethod extends InputMethodAdapter { final String[] retString = new String[1]; try { + if (isValid()) LWCToolkit.invokeAndWait(new Runnable() { public void run() { synchronized(retString) { int location = locationIn; @@ -639,6 +660,7 @@ public class CInputMethod extends InputMethodAdapter { final int[] returnValue = new int[2]; try { + if (isValid()) LWCToolkit.invokeAndWait(new Runnable() { public void run() { synchronized(returnValue) { AttributedCharacterIterator theIterator = fIMContext.getSelectedText(null); @@ -714,6 +736,7 @@ public class CInputMethod extends InputMethodAdapter { final int[] rect = new int[4]; try { + if (isValid()) LWCToolkit.invokeAndWait(new Runnable() { public void run() { synchronized(rect) { int insertOffset = fIMContext.getInsertPositionOffset(); @@ -758,6 +781,7 @@ public class CInputMethod extends InputMethodAdapter { final int[] insertPositionOffset = new int[1]; try { + if (isValid()) LWCToolkit.invokeAndWait(new Runnable() { public void run() { synchronized(offsetInfo) { offsetInfo[0] = fIMContext.getLocationOffset(screenX, screenY);