45 public class WInputMethod extends InputMethodAdapter
46 {
47 /**
48 * The input method context, which is used to dispatch input method
49 * events to the client component and to request information from
50 * the client component.
51 */
52 private InputMethodContext inputContext;
53
54 private Component awtFocussedComponent;
55 private WComponentPeer awtFocussedComponentPeer = null;
56 private WComponentPeer lastFocussedComponentPeer = null;
57 private boolean isLastFocussedActiveClient = false;
58 private boolean isActive;
59 private int context;
60 private boolean open; //default open status;
61 private int cmode; //default conversion mode;
62 private Locale currentLocale;
63 // indicate whether status window is hidden or not.
64 private boolean statusWindowHidden = false;
65
66 // attribute definition in Win32 (in IMM.H)
67 public final static byte ATTR_INPUT = 0x00;
68 public final static byte ATTR_TARGET_CONVERTED = 0x01;
69 public final static byte ATTR_CONVERTED = 0x02;
70 public final static byte ATTR_TARGET_NOTCONVERTED = 0x03;
71 public final static byte ATTR_INPUT_ERROR = 0x04;
72 // cmode definition in Win32 (in IMM.H)
73 public final static int IME_CMODE_ALPHANUMERIC = 0x0000;
74 public final static int IME_CMODE_NATIVE = 0x0001;
75 public final static int IME_CMODE_KATAKANA = 0x0002;
76 public final static int IME_CMODE_LANGUAGE = 0x0003;
77 public final static int IME_CMODE_FULLSHAPE = 0x0008;
78 public final static int IME_CMODE_HANJACONVERT = 0x0040;
79 public final static int IME_CMODE_ROMAN = 0x0010;
80
81 // flag values for endCompositionNative() behavior
82 private final static boolean COMMIT_INPUT = true;
83 private final static boolean DISCARD_INPUT = false;
84
287 // When the last focussed component peer is different from the
288 // current focussed component or if they are different client
289 // (active or passive), disable native IME for the old focussed
290 // component and enable for the new one.
291 if (lastFocussedComponentPeer != awtFocussedComponentPeer ||
292 isLastFocussedActiveClient != isAc) {
293 if (lastFocussedComponentPeer != null) {
294 disableNativeIME(lastFocussedComponentPeer);
295 }
296 if (awtFocussedComponentPeer != null) {
297 enableNativeIME(awtFocussedComponentPeer, context, !isAc);
298 }
299 lastFocussedComponentPeer = awtFocussedComponentPeer;
300 isLastFocussedActiveClient = isAc;
301 }
302 isActive = true;
303 if (currentLocale != null) {
304 setLocale(currentLocale, true);
305 }
306
307 /* If the status window or Windows language bar is turned off due to
308 native input method was switched to java input method, we
309 have to turn it on otherwise it is gone for good until next time
310 the user turns it on through Windows Control Panel. See details
311 from bug 6252674.
312 */
313 if (statusWindowHidden) {
314 setStatusWindowVisible(awtFocussedComponentPeer, true);
315 statusWindowHidden = false;
316 }
317
318 }
319
320 public void deactivate(boolean isTemporary)
321 {
322 // Sync currentLocale with the Windows keyboard layout which might be changed
323 // by hot key
324 getLocale();
325
326 // Delay calling disableNativeIME until activate is called and the newly
327 // focussed component has a different peer as the last focussed component.
328 if (awtFocussedComponentPeer != null) {
329 lastFocussedComponentPeer = awtFocussedComponentPeer;
330 isLastFocussedActiveClient = haveActiveClient();
331 }
332 isActive = false;
333 }
334
335 /**
336 * Explicitly disable the native IME. Native IME is not disabled when
337 * deactivate is called.
338 */
339 public void disableInputMethod() {
340 if (lastFocussedComponentPeer != null) {
341 disableNativeIME(lastFocussedComponentPeer);
342 lastFocussedComponentPeer = null;
343 isLastFocussedActiveClient = false;
344 }
345 }
346
347 /**
348 * Returns a string with information about the windows input method,
349 * or null.
350 */
351 public String getNativeInputMethodInfo() {
352 return getNativeIMMDescription();
603 else
604 return null;
605
606 }
607
608 private native int createNativeContext();
609 private native void destroyNativeContext(int context);
610 private native void enableNativeIME(WComponentPeer peer, int context, boolean useNativeCompWindow);
611 private native void disableNativeIME(WComponentPeer peer);
612 private native void handleNativeIMEEvent(WComponentPeer peer, AWTEvent e);
613 private native void endCompositionNative(int context, boolean flag);
614 private native void setConversionStatus(int context, int cmode);
615 private native int getConversionStatus(int context);
616 private native void setOpenStatus(int context, boolean flag);
617 private native boolean getOpenStatus(int context);
618 private native void setStatusWindowVisible(WComponentPeer peer, boolean visible);
619 private native String getNativeIMMDescription();
620 static native Locale getNativeLocale();
621 static native boolean setNativeLocale(String localeName, boolean onActivate);
622 private native void openCandidateWindow(WComponentPeer peer, int x, int y);
623 }
|
45 public class WInputMethod extends InputMethodAdapter
46 {
47 /**
48 * The input method context, which is used to dispatch input method
49 * events to the client component and to request information from
50 * the client component.
51 */
52 private InputMethodContext inputContext;
53
54 private Component awtFocussedComponent;
55 private WComponentPeer awtFocussedComponentPeer = null;
56 private WComponentPeer lastFocussedComponentPeer = null;
57 private boolean isLastFocussedActiveClient = false;
58 private boolean isActive;
59 private int context;
60 private boolean open; //default open status;
61 private int cmode; //default conversion mode;
62 private Locale currentLocale;
63 // indicate whether status window is hidden or not.
64 private boolean statusWindowHidden = false;
65 private boolean hasCompositionString = false;
66
67 // attribute definition in Win32 (in IMM.H)
68 public final static byte ATTR_INPUT = 0x00;
69 public final static byte ATTR_TARGET_CONVERTED = 0x01;
70 public final static byte ATTR_CONVERTED = 0x02;
71 public final static byte ATTR_TARGET_NOTCONVERTED = 0x03;
72 public final static byte ATTR_INPUT_ERROR = 0x04;
73 // cmode definition in Win32 (in IMM.H)
74 public final static int IME_CMODE_ALPHANUMERIC = 0x0000;
75 public final static int IME_CMODE_NATIVE = 0x0001;
76 public final static int IME_CMODE_KATAKANA = 0x0002;
77 public final static int IME_CMODE_LANGUAGE = 0x0003;
78 public final static int IME_CMODE_FULLSHAPE = 0x0008;
79 public final static int IME_CMODE_HANJACONVERT = 0x0040;
80 public final static int IME_CMODE_ROMAN = 0x0010;
81
82 // flag values for endCompositionNative() behavior
83 private final static boolean COMMIT_INPUT = true;
84 private final static boolean DISCARD_INPUT = false;
85
288 // When the last focussed component peer is different from the
289 // current focussed component or if they are different client
290 // (active or passive), disable native IME for the old focussed
291 // component and enable for the new one.
292 if (lastFocussedComponentPeer != awtFocussedComponentPeer ||
293 isLastFocussedActiveClient != isAc) {
294 if (lastFocussedComponentPeer != null) {
295 disableNativeIME(lastFocussedComponentPeer);
296 }
297 if (awtFocussedComponentPeer != null) {
298 enableNativeIME(awtFocussedComponentPeer, context, !isAc);
299 }
300 lastFocussedComponentPeer = awtFocussedComponentPeer;
301 isLastFocussedActiveClient = isAc;
302 }
303 isActive = true;
304 if (currentLocale != null) {
305 setLocale(currentLocale, true);
306 }
307
308 // Compare IM's composition string with Java's composition string
309 if (hasCompositionString && !isCompositionStringAvailable(context)) {
310 endCompositionNative(context, DISCARD_INPUT);
311 sendInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
312 EventQueue.getMostRecentEventTime(),
313 null, null, null, null, null, 0, 0, 0);
314 hasCompositionString = false;
315 }
316
317 /* If the status window or Windows language bar is turned off due to
318 native input method was switched to java input method, we
319 have to turn it on otherwise it is gone for good until next time
320 the user turns it on through Windows Control Panel. See details
321 from bug 6252674.
322 */
323 if (statusWindowHidden) {
324 setStatusWindowVisible(awtFocussedComponentPeer, true);
325 statusWindowHidden = false;
326 }
327
328 }
329
330 public void deactivate(boolean isTemporary)
331 {
332 // Sync currentLocale with the Windows keyboard layout which might be changed
333 // by hot key
334 getLocale();
335
336 // Delay calling disableNativeIME until activate is called and the newly
337 // focussed component has a different peer as the last focussed component.
338 if (awtFocussedComponentPeer != null) {
339 lastFocussedComponentPeer = awtFocussedComponentPeer;
340 isLastFocussedActiveClient = haveActiveClient();
341 }
342 isActive = false;
343 hasCompositionString = isCompositionStringAvailable(context);
344 }
345
346 /**
347 * Explicitly disable the native IME. Native IME is not disabled when
348 * deactivate is called.
349 */
350 public void disableInputMethod() {
351 if (lastFocussedComponentPeer != null) {
352 disableNativeIME(lastFocussedComponentPeer);
353 lastFocussedComponentPeer = null;
354 isLastFocussedActiveClient = false;
355 }
356 }
357
358 /**
359 * Returns a string with information about the windows input method,
360 * or null.
361 */
362 public String getNativeInputMethodInfo() {
363 return getNativeIMMDescription();
614 else
615 return null;
616
617 }
618
619 private native int createNativeContext();
620 private native void destroyNativeContext(int context);
621 private native void enableNativeIME(WComponentPeer peer, int context, boolean useNativeCompWindow);
622 private native void disableNativeIME(WComponentPeer peer);
623 private native void handleNativeIMEEvent(WComponentPeer peer, AWTEvent e);
624 private native void endCompositionNative(int context, boolean flag);
625 private native void setConversionStatus(int context, int cmode);
626 private native int getConversionStatus(int context);
627 private native void setOpenStatus(int context, boolean flag);
628 private native boolean getOpenStatus(int context);
629 private native void setStatusWindowVisible(WComponentPeer peer, boolean visible);
630 private native String getNativeIMMDescription();
631 static native Locale getNativeLocale();
632 static native boolean setNativeLocale(String localeName, boolean onActivate);
633 private native void openCandidateWindow(WComponentPeer peer, int x, int y);
634 private native boolean isCompositionStringAvailable(int context);
635 }
|