| Summary: | [Widgets] Text.computeSize wrong for new line with no text | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Veronika Irvine <veronika_irvine> |
| Component: | SWT | Assignee: | Platform-SWT-Inbox <platform-swt-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | Felipe Heidrich <eclipse.felipe> |
| Severity: | normal | ||
| Priority: | P3 | CC: | carles.galdo, rgrzywinski, roy.paterson, Silenio_Quarti |
| Version: | 3.1 | Keywords: | triaged |
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | stalebug | ||
*** Bug 155052 has been marked as a duplicate of this bug. *** Only happens when SWT.WRAP is set. Is there some progress with this bug? Just ran in to this with 3.6 - I'm amazed that this is still a problem 5 years after being reported. It seems simple - what's going on? (In reply to comment #4) > Just ran in to this with 3.6 - I'm amazed that this is still a problem 5 years > after being reported. It seems simple - what's going on? Sorry Roy, this is not simple. The bug is in the Windows function DrawText(), we don't know all the cases when the problem occurs in the OS. It is possible Windows will fix the problem in future releases (causing our fix to become the problem). //here's my workaround for this bug
package com.smartbear.swt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
final public class RightSizeText extends Text {
public RightSizeText(Composite parent, int style) {
super(parent, style);
}
@Override
protected void checkSubclass() {
// allow subclass
}
private Point getFixedSize(Point size) {
if (!"win32".equals(SWT.getPlatform()))
return size;
// workaround bug 86529
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=86529
int y = size.y;
if (getText().endsWith(getLineDelimiter()))
y += getLineHeight();
return new Point(size.x, y);
}
@Override
public Point computeSize(int wHint, int hHint) {
return getFixedSize(super.computeSize(wHint, hHint));
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return getFixedSize(super.computeSize(wHint, hHint, changed));
}
}
Amend that: if (!"win32".equals(SWT.getPlatform())) ...should more properly be... if (!"win32".equals(SWT.getPlatform()) || (getStyle() & SWT.WRAP) == 0) Can't believe I just thought of this now, but another workaround is simply to use StyledText instead - it doesn't have this problem. This is a one-off bulk update. (The last one in the triage migration). Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process: https://wiki.eclipse.org/SWT/Devel/Triage See Bug 518478 for details. Tag for notification/mail filters: @TriageBulkUpdate This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
Eclipse 3.1 M5 Run the following example. The result from computeSize should be the same but the height in the first case is incorrect. public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell (display); Text text = new Text(shell, SWT.WRAP | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); text.setText("abd\n"); System.out.println(text.getText() + "\n"+text.computeSize(SWT.DEFAULT, SWT.DEFAULT)); text.setText("abd\na"); System.out.println(text.getText() + "\n"+text.computeSize(SWT.DEFAULT, SWT.DEFAULT)); display.dispose (); }