Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 347490 - Shell.setImeInputMode(int mode) does not always set IME flags as expected, and causes Chinese IME single space mode changes to double space.
Summary: Shell.setImeInputMode(int mode) does not always set IME flags as expected, an...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.8 M1   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-27 13:43 EDT by angelr CLA
Modified: 2014-02-10 01:53 EST (History)
6 users (show)

See Also:


Attachments
patch (1017 bytes, patch)
2011-07-13 15:20 EDT, Felipe Heidrich CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description angelr CLA 2011-05-27 13:43:42 EDT
Build Identifier: Eclipse 3.6.0 I20100608-0911

Shell.setImeInputMode(int mode) does not always set IME flags as expected, and causes Chinese IME single space mode changes to double space.

The SWT constant for IME input mode are:
SWT.DBCS (int value 2), if set, full shape
SWT.ALPHA (int value 4),
SWT.NATIVE (int value 8), if set, IME is on
SWT.PHONETIC (int value 16),
SWT.ROMAN (int value 32),
When chinese IME is on and half shape, Shell.getImeInputMode() returns "8". Calling setImeInputMode(8) then calling Shell.getImeInputMode() on the same Shell, it will return "10" instead of expected value "8". 10 means IME is on and FullShape is set.

This problem reproduces in Eclipse 3.4.0 through Eclipse 3.6.0.

Code snippet to reproduce it:
-----------------------

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;

public class Snippet1 {

	public static void main(String[] args) {
		Display display = new Display();
		final Shell shell = new Shell(display);		
		shell.setLayout(new GridLayout());
		
		Text text1 = new Text(shell, SWT.BORDER);
		text1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		text1.setFocus();
		text1.addKeyListener(new KeyListener() {
			@Override
			public void keyPressed(KeyEvent e) {
				// TODO Auto-generated method stub
				System.out.println("- Watch the character width (double or single space). Current imeInputMode is: " + shell.getImeInputMode());
			}

			@Override
			public void keyReleased(KeyEvent e) {
				// TODO Auto-generated method stub

			}

		});

		Button button1 = new Button(shell, SWT.PUSH);
		button1.setText("Change IME");
		button1.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
				shell.setImeInputMode(8);
				System.out.println("(3) After calling setImeInputMode(8), shell.getImeInputMode()=" + shell.getImeInputMode());
				System.out.println("    Notice how the language bar changes to double space characters.");
				System.out.println("    Enter a digit in text input to compare with the previous one (single space digit now changes to double space digit).");
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
				
			}
			
		});

		shell.setSize(200, 200);
		shell.open();
		
		System.out.println("(1) Initially shell imeInputMode is: " + shell.getImeInputMode());
		System.out.println("(2) With foucs set in the text input area, manually change IME to Chinese IME and half space."); 
		System.out.println("    Enter a digit in text input, verify imeInputMode is 8, and verify language bar showing half space character.");
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}


Reproducible: Always

Steps to Reproduce:
1. With IME off a shell's getImeInputMode() returns 0.
2. Manually change IME to Chinese IME (such as Windows 7 Simplified Chinese QuanPin 6.0) and half space. shell.getImeInputMode() returns 8.
3. After calling shell.setImeInputMode(8), shell.getImeInputMode() now returns "10" instead of expected "8". Also, the language bar changes from single space mode to double space mode.
Comment 1 Felipe Heidrich CLA 2011-06-07 12:53:35 EDT
The behavior is right.
SWT.NATIVE - gives full-width native input
(we also need to set SWT.DBCS internally for MS-IME2000 to work, see bug 150365)

If you want half-width native input use SWT.PHONETIC
Comment 2 Felipe Heidrich CLA 2011-06-21 16:35:40 EDT
If you want to open a new shell2 that has the same input mode as shell you can use:
int mode = shell.getImeInputMode();
int newMode = 0;
if ((mode & (SWT.NATIVE | SWT.PHONETIC)) != 0) newMode = SWT.PHONETIC;
if ((mode & (SWT.DBCS)) != 0) newMode |= SWT.DBCS;
if ((mode & (SWT.ROMAN)) != 0) newMode |= SWT.ROMAN;
shell2.setImeInputMode(newMode);

-Notes-
It works for:
CH full-width
CH half-width
EN half-width
fails for EN full-width (this mode will never work cause shell.getImeInputMode() returns zero, this is a win32 limitation).

I only tested for Windows 7 Simplified Chinese QuanPin 6.0
I know that this code would not work for Japanese Input Method (it would convert hiragana to katagana).
Comment 3 Nina CLA 2011-06-22 01:46:55 EDT
(In reply to comment #1)
> The behavior is right.
> SWT.NATIVE - gives full-width native input
> (we also need to set SWT.DBCS internally for MS-IME2000 to work, see bug
> 150365)
> 
> If you want half-width native input use SWT.PHONETIC

Reply to comment 1:
I don't think using SWT.PHONETIC will solve the problem.                     
                                                                             
When Chinese IME is on and is in half shape, shell.getImeInputMode()         
will return int 8 or SWT.NATIVE, it does not return int 16 or                
SWT.PHONETIC. With Chinese IME on and half shape, if we call                 
shell.setImeInputMode(shell.getImeInputMode()), then the shell will          
change the Chinese IME to full shape, and calling                            
shell.getImeInputMode() AGAIN will return 10 (SWT.NATIVE | SWT.DBCS)         
instead of 8. This is incorrect behavior. The correct behavior should        
return 8, because calling shell.setImeInputMode(shell.getImeInputMode())     
should NOT change the shell's IME input mode.                                
                                                                             
Another issue is that if the shell already has Chinese IME turned on,        
calling shell.setImeInputMode(SWT.PHONETIC) can keep the Chinese IME and     
half shape. But if Chinese input is OFF and shell.getImeInputMode()==0,      
calling shell.setImeInputMode(SWT.PHONETIC) will NOT turn on Chinese         
IME, it will still be English input with half space. So we cannot call       
shell.setImeInputMode(SWT.PHONETIC) to turn on a shell's Chinese input       
and keep it in half shape.                                                   
                                                                             
In our use case, we are setting shell2's IME mode based on the shell1's      
IME mode, ie, we are calling                                                 
shell2.setImeInputMode(shell1.getImeInputMode()). We need:                   
(1) shell.getImeInputMode() to return the expected int value when            
Chinese IME is on and half shape. Please clarify if it should be             
SWT.NATIVE(int 8), or SWT.PHONETIC(int 16) as you suggested.                 
(2) shell.setImeInputMode(int mode) to actually set the value correct,       
so that calling getImeInputMode() again on this same shell will return       
the exact same int "mode".
Comment 4 Felipe Heidrich CLA 2011-06-22 14:10:11 EDT
Please let me know if you can use the workaround in comment 2 ?
Comment 5 Nina CLA 2011-06-30 02:07:41 EDT
(In reply to comment #4)
> Please let me know if you can use the workaround in comment 2 ?

The suggested fix has 2 issues:                                            
(1) With Chinese IME on, the fix will keep the half width for letters      
and digits. However, it will not keep width for punctuation marks such     
as comma, period. If puncation width was full width, after calling this    
code, punction width will become half width.                               
Also, this fix will change a shell's imeInputMode to a different value     
when user didn't actually change anything in IME option. (normally with    
Chinese IME on, the value is 8, but calling this code will change it to    
16.)                                                                       
(2) If this fix does not work with Japanese, we cannot include it as a     
Sametime hotfix, because Japanese input user will find it problematic.     
Still, I would like to get a SWT fix, so that calling                      
shell.setImeInputMode(shell.getImeInputMode()) will not alter the          
shell's imeInputMode unexpectedly.
Comment 6 Nina CLA 2011-07-04 10:35:49 EDT
(In reply to comment #4)
> Please let me know if you can use the workaround in comment 2 ?

Please can you provide an update on this response.?
Comment 7 Felipe Heidrich CLA 2011-07-13 15:20:51 EDT
Created attachment 199615 [details]
patch
Comment 8 Felipe Heidrich CLA 2011-07-13 15:23:28 EDT
I changed the code in our end so that the fix for  bug 150365 only runs on japanese.

with that the 'shell2.setImeInputMode(shell.getImeInputMode());' works for:
CH full-width
CH half-width
EN half-width
fails for EN full-width (this mode will never work cause
shell.getImeInputMode() returns zero, this is a win32 limitation).
Comment 10 Hafiz CLA 2014-02-06 09:02:36 EST
This bug is regressed in recent version of SWT like 3.7.2.v3740f and beyond. 

The same code snippet fails on 3.7.2.v3740f. 

This issue is reported by our customer and we need to get fix as soon as possible.

Appreciate your help.
Comment 11 Arun Thondapu CLA 2014-02-07 14:03:23 EST
(In reply to Hafiz from comment #10)
> This bug is regressed in recent version of SWT like 3.7.2.v3740f and beyond. 
> 
> The same code snippet fails on 3.7.2.v3740f. 
> 
> This issue is reported by our customer and we need to get fix as soon as
> possible.
> 
> Appreciate your help.

I don't think there is any regression here. This bug was fixed only in 3.8 and later versions. Please use SWT later than 3.8 if you need this fix in your product.
Comment 12 Hafiz CLA 2014-02-10 01:53:48 EST
Apologies for the confusion. I assumed the patch given on 3.6 was available in 3.7.x. 

Thanks for your confirmation. I confirmed, the issue does not reproduce on SWT 3.8.x