Bug 4606 - Text.computeTrim doesn't work (1G8W5RN)
Summary: Text.computeTrim doesn't work (1G8W5RN)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P4 normal (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-11 14:19 EDT by Carolyn MacLeod CLA
Modified: 2004-09-16 15:47 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carolyn MacLeod CLA 2001-10-11 14:19:48 EDT
computeTrim does not work for Text on Windows.
	Test case pasted below.
	When the shell comes up, you should see 345 in the Text,
	but you only see 34. (the 5 is scrolled to the right).

	If you uncomment these 2 lines:
		//Point pt2 = text.computeSize (pt.x, pt.y);
		//text.setSize (pt2.x, pt2.y);

	and comment these 2 lines:
		Rectangle rect = text.computeTrim (0, 0, pt.x, pt.y);
		text.setSize (rect.width, rect.height);

	then you will see that computeSize works fine - it's just the computeTrim that is bogus.

[
import com.ibm.swt.*;
import com.ibm.swt.graphics.*;
import com.ibm.swt.widgets.*;

public class PR1G8W5RN {

public static void main (String[] args) {
	String string = "345";
	Display display =  new Display();
	Shell shell = new Shell(display);
	shell.setSize(300, 150);
	Text text = new Text (shell, SWT.SINGLE | SWT.BORDER);
	text.setText (string);
	GC gc = new GC (text);
	Point pt = gc.textExtent (string);
	gc.dispose ();
	Rectangle rect = text.computeTrim (0, 0, pt.x, pt.y);
	text.setSize (rect.width, rect.height);
	//Point pt2 = text.computeSize (pt.x, pt.y);
	//text.setSize (pt2.x, pt2.y);
	shell.open();		
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
}

}
]

NOTES:
	CM (3/10/01 6:06:25 PM)
		It's even worse on Motif - you can barely see the top half of the 3.
		Changing PR title to ALL instead of just WINNT.
		We should fix this.

	McQ (26/06/2001 11:09:50 AM) -
		CM to look at all of these.
Comment 1 DJ Houghton CLA 2001-10-29 16:25:08 EST
PRODUCT VERSION:
	SWT 0.059 on Windows

Comment 2 Christophe Cornu CLA 2003-02-14 13:58:45 EST
On Windows, the problem is that the default computeTrim does not take into 
account the edit rectangle, which is usually a subset of the text client area 
in OS terms. 
A workaround is probably to use EM_GETMARGINS in a way similar to 
Text.computeSize. EM_GETRECT is good on the paper but returns undesired values 
when the width is < than a char, on W2K.
Comment 3 Steve Northover CLA 2003-02-17 19:36:55 EST
Chrix, do you have a fix for this?
Comment 4 Steve Northover CLA 2004-07-26 16:30:59 EDT
Fixed > 20040726