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

Bug 287650

Summary: ToolItems get resized by the first ToolItem in the Toolbar
Product: [Eclipse Project] Platform Reporter: Flavio Donze <flavio.donze>
Component: SWTAssignee: Project Inbox <swt-triaged>
Status: RESOLVED WONTFIX QA Contact: Felipe Heidrich <eclipse.felipe>
Severity: normal    
Priority: P3 CC: cgold, cocoakevin, markus.kell.r, pwebster, remy.suen, Silenio_Quarti
Version: 3.5   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
SWT Toolbar Test none

Description Flavio Donze CLA 2009-08-26 03:21:09 EDT
Build id: I20090611-1540

Having the following code construct, Logo.png has a width of 125px and the refresh icon 16px. When adding the logoAction first to the toolbar the refresh icon is resized to 125px and when adding the refreshAction first the logoAction is resized to 16px.

FormToolkit toolkit = new FormToolkit(Display.getCurrent());
ScrolledForm form = toolkit.createScrolledForm(parent);
toolkit.decorateFormHeading(form.getForm());

IToolBarManager toolBarManager = form.getToolBarManager();
toolBarManager.removeAll();
toolBarManager.update(true);

Action refreshAction = new Action("Refresh", UIPlugin.getImageDescriptor(IconConstants.REFRESH)) {
	@Override
	public void run() {
	}
};
Action logoAction = new Action("Logo", UIPlugin.getImageDescriptor("Logo.png")) {
	@Override
	public void run() {

	}
};
toolBarManager.add(logoAction);
toolBarManager.add(new Separator());
toolBarManager.add(refreshAction);
form.updateToolBar();
Comment 1 Remy Suen CLA 2009-08-26 07:43:14 EDT
Do you have this problem with general uses of IToolBarManagers such as standalone JFace applications or ones that uses a workbench view's toolbar? This could be a Forms bug.
Comment 2 Flavio Donze CLA 2009-08-26 11:00:18 EDT
Just did a test and added the actions to the workbechwindow toolbar, same result the images get resized.
Don't know about standalone applications.
Should I do a test?
Comment 3 Flavio Donze CLA 2010-01-08 10:06:10 EST
Created attachment 155605 [details]
SWT Toolbar Test
Comment 4 Flavio Donze CLA 2010-01-08 10:09:54 EST
I just attached a SWT Toolbar test project.
There you can see the effect, the second (Refresh.gif 16x16) is resized to size of the first image (LogoLong16.png 124x16).

So this is not a Forms but SWT bug.
Comment 5 Flavio Donze CLA 2010-02-17 04:55:50 EST
Did some further investigations.

The problem seems to be in Toolbar.computeSize() which is called during pack().

if (count != 0) {
	RECT rect = new RECT ();
	OS.SendMessage (handle, OS.TB_GETITEMRECT, count - 1, rect);
	width = Math.max (width, rect.right);
	height = Math.max (height, rect.bottom);
}

'width' is double the size of the first icon + 14.

46 when the 16x16 icon is added first and 262 if the 124x16 icon is added first.

I guess the icons are then stretched out equally to fit this size.
Comment 6 Felipe Heidrich CLA 2010-02-17 09:23:22 EST
In win32, all images in the toolbar are added to the same image list, for that reason they are have to have the same size:
http://msdn.microsoft.com/en-us/library/bb761389(VS.85).aspx

In another words, in win32 all images in the toolbar control must have the same size. Closing as wont fix (platform limitation).