Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354020 - Text extent for wrapped Label widgets computed incorrectly if text contains tabs
Summary: Text extent for wrapped Label widgets computed incorrectly if text contains tabs
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-05 11:30 EDT by Mike Parker CLA
Modified: 2019-11-14 03:37 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Parker CLA 2011-08-05 11:30:12 EDT
Message dialogs use labels with the SWT.WRAP style to display the message, which causes the label to be created with the SS_EDITCONTROL style flag:

Label.java (#widgetStyle()):

	if (OS.WIN32_VERSION >= OS.VERSION (5, 0)) {
		if ((style & SWT.WRAP) != 0) bits |= OS.SS_EDITCONTROL;
	} 

I wanted to format Message dialog text into columns using tab characters (\t), using GC#textExtent() to figure out how many tab characters to insert to reach a particular column.

This approach failed, however, because it proved to be impossible to correctly work out the extent of a string containing one or more tab characters.

Reason: The SS_EDITCONTROL style flag alters the tab spacings! For example, for 8pt Tahoma (the default), the tab spacing within a label widget was 48 with SS_EDITCONTROL set, but only 40 without. To obtain the correct text extents in the former case, it would be necessary for GC#textExtent() to call DrawText() with the DT_EDITCONTROL flag set, which is unfortunately not one of the supported DT_* flags (see snippet below):

GC.java (#textExtent(String, int)):

	int uFormat = OS.DT_LEFT | OS.DT_CALCRECT;
	if ((flags & SWT.DRAW_DELIMITER) == 0) uFormat |= OS.DT_SINGLELINE;
	if ((flags & SWT.DRAW_TAB) != 0) uFormat |= OS.DT_EXPANDTABS;
	if ((flags & SWT.DRAW_MNEMONIC) == 0) uFormat |= OS.DT_NOPREFIX;
	OS.DrawText(handle, buffer, buffer.length(), rect, uFormat);

Analogously to the code in Label.java (see above), I was expecting to be able to indirectly set the DT_EDITCONTROL flag by calling #textExtent() with the SWT.WRAP flag:

	if ((flags & SWT.WRAP) != 0) uFormat |= OS.DT_EDITCONTROL;

Could this line be added in to the source code base?
Comment 1 Lars Vogel CLA 2019-11-14 03:37:54 EST
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.

If the bug is still relevant, please remove the "stalebug" whiteboard tag.