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

Bug 335354

Summary: Site selection combo has strange default selection in increased font size
Product: [Eclipse Project] Platform Reporter: Remy Suen <remy.suen>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: minor    
Priority: P3 CC: carolynmacleod4, dean.t.roberts, dj.houghton, eclipse.felipe
Version: 3.7   
Target Milestone: 3.7   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Screenshot depicting the behaviour in question. none

Description Remy Suen CLA 2011-01-25 12:46:29 EST
Created attachment 187548 [details]
Screenshot depicting the behaviour in question.

I20110124-1800

1. Window > Preferences > General > Appearance > Colors and Fonts
2. Basic > Dialog Font
3. Increase the font size.
4. Click 'OK'.
5. Help > Install New Software...
6. The text I see selected is 'elect a site'. If I alt+tab to another window and then back it is okay.
Comment 1 DJ Houghton CLA 2011-01-26 15:39:15 EST
Dean, please investigate and see if there is something simple we are doing wrong here.
Comment 2 Dean Roberts CLA 2011-01-31 11:35:00 EST
This appears to be a problem in org.eclipse.swt.widgets.Combo.

Specifically I believe the problem may be in (or around) Combo.setScrollWidth().  The for loop in this method seems to be iterating over the entire string CB_GETLBTEXTLEN, Although I'm not entierly sure what the various OS calls are here ... it seems suspicious to me that the entire string is being used each time.  The imperical result of CB_GETLBTEXTLEN is also very close to the number of characters being cut off to the left.

Additionally, the defect as described above will still be present if you set the point size of the font back to the original number.  The problem will go away if you use the "Use System Font" or "Restore Defaults" to put the dialog font back to the original number.  The difference between these two scenerios is that setting things back to system font or default results in Combo.setFont(Font) not being called when the dialog is opened.  Setting the actual font size NUMBER back to its original of 9 still causes Combo.setFont(Font) to be called ... which ends up calling Combo.setScrollWidth()

Similarly you don't actually have to change the font size to make the problem happen.  On my system the default dialog font is Segoe UI 9.  If you edit the font and pick the same size, 9, the problem will occur since Combo.setFont(Font) will be called.
Comment 3 Dean Roberts CLA 2011-01-31 11:40:17 EST
Addtionally here is a Snippet that shows similar behaviour.

If you comment out the setFont call the bug "goes away"

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

public class Snippet269 {

public static void main(String[] args) {
	final Display display = new Display ();
	Font font = new Font(display, "Tahoma", 14, SWT.NORMAL);
	Shell shell = new Shell (display);
	shell.setLayout (new GridLayout ());
	Combo combo = new Combo (shell, SWT.NONE);
	combo.add ("type or select a site");
	combo.select (0);
	combo.setFont(font);
	shell.pack ();
	shell.open ();
	int stringLength = combo.getText ().length (); 
	combo.setSelection (new Point (0, stringLength));
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	font.dispose();
	display.dispose ();
}
}
Comment 4 Felipe Heidrich CLA 2011-01-31 12:03:52 EST
I think this is the same as bug 277618.
When the combo is made bigger it does not scroll the text to the right. 
This should be done by the Combo itself, we tried to force it once by there was no API to do it correctly. We tried different hacks but they all had problems.

In your snippet, calling combo.select(0) (instead of setSelection()) would make the problem "go away".
Comment 5 Dean Roberts CLA 2011-01-31 14:40:03 EST
I do believe this defect is, in fact, a duplicate of bug 277618, but, I don't believe your description of what is going on in comment #4 of this bug is accurate.

I will annotate bug 277618 since there is an issue with that defect and reproducibility that I can solve for them.  IE the defect is only reproducible if you change the dialog font to a non default system font.

Note that the issue is not a combo box size issue.  There can be plenty of space available in the combo box text field for the text in question and I can still make the text appear scrolled to the left.  This is why I believe there is a problem in the text sizing calculation in Combo.setScrollWidth()
Comment 6 Felipe Heidrich CLA 2011-01-31 15:49:34 EST

*** This bug has been marked as a duplicate of bug 277618 ***