Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 86529

Summary: [Widgets] Text.computeSize wrong for new line with no text
Product: [Eclipse Project] Platform Reporter: Veronika Irvine <veronika_irvine>
Component: SWTAssignee: 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.1Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Veronika Irvine CLA 2005-02-24 14:20:06 EST
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 ();
}
Comment 1 Steve Northover CLA 2006-10-25 04:04:36 EDT
*** Bug 155052 has been marked as a duplicate of this bug. ***
Comment 2 Steve Northover CLA 2006-10-25 04:06:46 EDT
Only happens when SWT.WRAP is set.
Comment 3 Carles Galdó CLA 2008-12-09 05:46:44 EST
Is there some progress with this bug?
Comment 4 Roy Paterson CLA 2010-07-13 10:54:06 EDT
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?
Comment 5 Felipe Heidrich CLA 2010-07-14 12:39:01 EDT
(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).
Comment 6 Roy Paterson CLA 2010-08-17 10:26:07 EDT
//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));
    }

}
Comment 7 Roy Paterson CLA 2010-08-17 10:32:35 EDT
Amend that:

if (!"win32".equals(SWT.getPlatform()))

...should more properly be...

if (!"win32".equals(SWT.getPlatform()) || (getStyle() & SWT.WRAP) == 0)
Comment 8 Roy Paterson CLA 2010-08-26 16:19:48 EDT
Can't believe I just thought of this now, but another workaround is simply to use StyledText instead - it doesn't have this problem.
Comment 9 Leo Ufimtsev CLA 2017-08-03 12:33:17 EDT
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
Comment 10 Eclipse Genie CLA 2019-08-04 16:24:01 EDT
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.