Bug 99984 - Sync view toolbar buttons are bigger with SWT manifest
Summary: Sync view toolbar buttons are bigger with SWT manifest
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.2 RC2   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 52871 111155 134530 135542 137875 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-14 11:37 EDT by Michael Valenta CLA
Modified: 2006-08-26 11:57 EDT (History)
16 users (show)

See Also:


Attachments
Screenshot that shows big toolbar buttons for sync view (50.91 KB, image/x-png)
2005-06-14 11:38 EDT, Michael Valenta CLA
no flags Details
modified snippet (3.15 KB, text/plain)
2006-04-11 12:12 EDT, Randy Hudson CLA
no flags Details
Screenshot (7.75 KB, image/png)
2006-04-21 13:28 EDT, Genady Beryozkin CLA
no flags Details
Screenshot (20.17 KB, image/png)
2006-04-22 08:10 EDT, Genady Beryozkin CLA
no flags Details
Views screenshot (25.01 KB, image/png)
2006-04-22 08:18 EDT, Genady Beryozkin CLA
no flags Details
Toolbar buttons Eclipse, Windows and "Fixed" (23.50 KB, image/png)
2006-04-22 08:41 EDT, Gunnar Wagenknecht CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Valenta CLA 2005-06-14 11:37:24 EDT
I started using the SWT manifest so I could take screenshots. The toolbar 
buttons in the sync view are quite a bit bigger than they were (and other 
view's button's are not). It could be related to the use of a view subtitle. 
Is this the intented behavior?
Comment 1 Michael Valenta CLA 2005-06-14 11:38:10 EDT
Created attachment 23065 [details]
Screenshot that shows big toolbar buttons for sync view
Comment 2 Michael Valenta CLA 2005-06-14 12:40:03 EDT
This is because we have a drop down button as the first button in the toolbar. 
Unfortunately, havinbg the sync dropdown first makes the most sense. Now that 
I know the cause, I seem to recall that this was a known issue.
Comment 3 Michael Valenta CLA 2005-06-14 13:06:04 EDT
I've been told this is a bug (or Platform behavior depending on how you look 
at it) on Windows so I'm moving it to SWT. Unfortunately, this really makes 
the sync view stick out like a sore thumb. It also causes the toolbar docking 
behavior of the workbench to act differently (i.e. the toolbar can never be in 
the tab line). To me, this seems like a serious impediment to using the SWT XP 
manifests.
Comment 4 Steve Northover CLA 2005-06-15 14:24:07 EDT
This is a dup of a WONTFIX Windows bug that I can't find right now.  When we 
first got XP, I spent a while trying to make it stop doing this and had to 
give up.
Comment 5 Carolyn MacLeod CLA 2005-08-25 16:26:27 EDT
FYI, bug 52871, bug 86194, bug 86286, bug 90767, and bug 91766 all describe 
this problem.
Comment 6 Nick Edgar CLA 2005-08-26 15:27:37 EDT
*** Bug 52871 has been marked as a duplicate of this bug. ***
Comment 7 Randy Hudson CLA 2005-08-26 15:37:51 EDT
Couldn't someone create a bogus toolitem to workaround the limitation?
Comment 8 Douglas Pollock CLA 2005-09-30 09:43:44 EDT
*** Bug 111155 has been marked as a duplicate of this bug. ***
Comment 9 Steve Northover CLA 2006-04-04 11:50:52 EDT
*** Bug 134530 has been marked as a duplicate of this bug. ***
Comment 10 Mik Kersten CLA 2006-04-04 12:31:06 EDT
Until I found a non drop-down button to use as the first button I used to use a blank button to avoid this issue (comment#7), which was an annoying hack.  It made me wonder if it would be possible to have a 0 or 1px wide dummy 'separator' button that could be added (or would automatically be added) if the first button was a pull-down.  Which seems like an annoying hack for Platform/SWT to do.  But I think that the current inconsistency between views ends up looking like a hack to users.  Personally, the way the toolbar and synch view toolbar blow up has kept me from using the XP manifest.  I imagine that when Vista rolls out this will be even more of an issue since not using the XP manifest will make Eclipse look dated.
Comment 11 Randy Hudson CLA 2006-04-04 13:12:19 EDT
I think you can create the bogus toolitem and then dispose it shortly thereafter. So the size of it doesn't matter.
Comment 12 Steve Northover CLA 2006-04-04 15:07:15 EDT
Randy, does this actually work?
Comment 13 Randy Hudson CLA 2006-04-05 11:09:09 EDT
It's a hunch. I can't imagine that by disposing a toolitem, the others would change their widths. I don't have your snippets loaded in my workspace, but you could probably find out the answer in less time than it takes me to type this comment :-)
Comment 14 Eric Moffatt CLA 2006-04-11 09:37:08 EDT
*** Bug 135542 has been marked as a duplicate of this bug. ***
Comment 15 Randy Hudson CLA 2006-04-11 12:12:04 EDT
Created attachment 38297 [details]
modified snippet

Here is a modified snippet 150. Clicking on the non-dropdown toolitem disposes them, and appends more items with dropdown style. There is no height increase.

But, I had to change the snippet to only display images. If you have text, the original height requirement calculation is different. In that case it doesn't matter if first item is dropdown or not. So the workaround works, except in the following scenario:

Finally, if you dynamically add a toolitem containing dropdown style and text (instead of image), the toolbar must be resized taller, or else it will be blank. Try commenting out line 34 and uncommenting 35.
Comment 16 Steve Northover CLA 2006-04-13 14:53:12 EDT
Your snippet seems to do it but I can't seem to create some code that does this without the interactive part.  Here is an attempt that fails:

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

public class PR_99984 {
	public static void main(String[] args) {
		Display display = new Display();
		Image icon = new Image(display, 16, 16);
		GC gc = new GC (icon);
		gc.setBackground (display.getSystemColor (SWT.COLOR_RED));
		gc.fillRectangle (icon.getBounds ());
		gc.dispose ();
		Shell shell = new Shell(display);
		RowLayout layout = new RowLayout(SWT.VERTICAL);
		shell.setLayout(layout);
		ToolBar toolBar0 = new ToolBar(shell, SWT.FLAT | SWT.BORDER);
		for (int i = 0; i < 8; i++) {
			ToolItem bogus = i == 0 ? new ToolItem (toolBar0, SWT.NONE) : null;
			ToolItem item = new ToolItem(toolBar0, false && i != 0 ? SWT.PUSH : SWT.DROP_DOWN);
			if (bogus != null) bogus.dispose ();
			item.setImage(icon);
			//item.setText("Item" + i);
		}
		toolBar0.pack();
		ToolBar toolBar1 = new ToolBar(shell, SWT.FLAT | SWT.BORDER);
		for (int i = 0; i < 8; i++) {
			ToolItem item = new ToolItem(toolBar1, i != 7 ? SWT.PUSH : SWT.DROP_DOWN);
			item.setImage(icon);
			//item.setText("Item" + i);
		}
		toolBar1.pack();
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}
Comment 17 Steve Northover CLA 2006-04-13 14:54:07 EDT
BTW, get rid of the "false & i != 0" part.
Comment 18 Eric Moffatt CLA 2006-04-21 09:29:26 EDT
*** Bug 137875 has been marked as a duplicate of this bug. ***
Comment 19 Jeff McAffer CLA 2006-04-21 10:19:03 EDT
Can we reopen this one (if indeed it is the cause of bug 137875.  Not quite sure this is a complete dup as the basic problem is that the buttons used to be on the line beside the tabs.  HOwever, the buttons certainly are bigger.  Makes the UI look like somewhat goofy and very gray.
Comment 20 Steve Northover CLA 2006-04-21 10:51:22 EDT
I seems like there should be some path to convince XP to make the buttons smaller, given Randy's hack.  Go ahead and reopen it and add it to the polish list.  Those of us that have been running with the manifest file have seen this for ages and got use to it though.

I have had a go at whacking XP when this problem first happened in the early XP day and failed but it seems like it's time to try again.  One thing though, the "too big" look is really XP look and feel so in the end, even if it can be whacked, there is an argument that says we shouldn't do it.  Let's get to the point where we can make that decision before having the argument.
Comment 21 Randy Hudson CLA 2006-04-21 10:55:39 EDT
The following workaround works. The "catch": wait until another toolitem gets created before disposing the bogus one. From a JFace point of view, just before asking the first contribution to fill the toolbar, create a bogus toolitem, then dispose it after.

public class PR_99984 {
public static void main(String[] args) {
	Display display = new Display();
	Image icon = new Image(display, 16, 16);
	GC gc = new GC(icon);
	gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_BLUE));
	gc.fillRectangle(icon.getBounds());
	gc.dispose();
	Shell shell = new Shell(display);
	RowLayout layout = new RowLayout(SWT.VERTICAL);
	shell.setLayout(layout);
	ToolBar toolBar0 = new ToolBar(shell, SWT.FLAT | SWT.BORDER);
	for (int i = 0; i < 8; i++) {
		ToolItem item = new ToolItem(toolBar0, i == 0 ? SWT.PUSH : SWT.DROP_DOWN);
		item.setImage(icon);
		if (i == 1)
			toolBar0.getItem(0).dispose();
	}
	toolBar0.pack();
	ToolBar toolBar1 = new ToolBar(shell, SWT.FLAT | SWT.BORDER);
	for (int i = 0; i < 8; i++) {
		ToolItem item = new ToolItem(toolBar1, i != 7 ? SWT.PUSH : SWT.DROP_DOWN);
		item.setImage(icon);
	}
	toolBar1.pack();
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
}
Comment 22 Mik Kersten CLA 2006-04-21 11:51:49 EDT
Steve, regarding comment#20 note that even though explorer uses the tall toolbars I'm not sure many consider it the 'XP look' because all office apps use the short ones, and do make use of drop-downs.

Side note regarding the future of toolbars on Windows: Ribbons are coming (http://blogs.msdn.com/jensenh/archive/2006/04/17/577485.aspx), and seem to have imitated plugin.xml style extensibility, called RibbonX (google).  But since we have very nice view toolbars and menus, the Ribbon thing seems less compelling for Eclipse...
Comment 23 Genady Beryozkin CLA 2006-04-21 13:28:07 EDT
Created attachment 39191 [details]
Screenshot

I think I have another workaround. The idea is to delay setting the drop down style until after the toolbar has been created. 

I've added the following method to the Toolbar class:

public void fixDropDown() {
	
	for (int i = 0; i < items.length; i++) {
		if ((items[i].getStyle() & SWT.DROP_DOWN) == 0) {
			continue;
		}
		TBBUTTONINFO buttonInfo = new TBBUTTONINFO ();
		buttonInfo.cbSize = TBBUTTONINFO.sizeof;
		buttonInfo.dwMask = OS.TBIF_STYLE;
		OS.SendMessage(handle, OS.TB_GETBUTTONINFO, i, buttonInfo);
		buttonInfo.fsStyle |= OS.TBSTYLE_DROPDOWN;
		OS.SendMessage(handle, OS.TB_SETBUTTONINFO, i, buttonInfo);		
	}
}

and changed the line in createItem (ToolItem item, int index):
    int bits = item.widgetStyle ();
to
    int bits = item.widgetStyle () & ~OS.BTNS_DROPDOWN;

Then I removed the "bogus" button in PR_99984 and "toolBar0.fixDropDown()" after "pack()".

The result is attached.
Comment 24 Steve Northover CLA 2006-04-21 14:22:46 EDT
Ok, I'm on it.  The question is when is it safe to hammer in the drop down style?  I tried doing it directly after the tool item was created and this did not work.

Stand by ...
Comment 25 Genady Beryozkin CLA 2006-04-21 14:34:57 EDT
(that was my first attempt too)
I think it is safe, since this is how it's done in most MFC applications.
In MFC when the toolbar is loaded from a resource file, you can't specify the drop down style in the resource file, so it is done after the toolbar has been loaded.

See http://msdn2.microsoft.com/en-us/library/1ke6s1fc.aspx
and http://www.codeproject.com/docking/toolbar_droparrow.asp
Comment 26 Steve Northover CLA 2006-04-21 15:24:54 EDT
Specifically, hammering the style back in ToolBar.createItem() after the item has been created in the operating system DOES NOT work.  It seems that the tool bar must have been layed out at the smaller size before the style is hammered.
Comment 27 Steve Northover CLA 2006-04-21 19:12:02 EDT
Determining when XP hammers the size is turning out to be quite difficult.  I have code that works for simple examples but fails in Eclipse.  Still working on it ...
Comment 28 Genady Beryozkin CLA 2006-04-22 08:08:20 EDT
I think I found an even better way.
When XP Styles are enabled there is a TB_SETMETRICS message that can be used to specify various padding and spacing sizes. The default Y padding is 7 pixels.
If this padding is set to -2, the toolbar height is the same as if there were no drop down buttons. The nasty thing is that it must be set only for toolbars that are oversized (the first button rule seems to work here).

I wrote a new native method for Toolbar:

public native int fixTB(int handle);

implemented as (the -2 constant makes it look exactly the same size if there are no toolbar, but maybe it depends on some other UI constants):

JNIEXPORT jint JNICALL Java_org_eclipse_swt_widgets_ToolBar_fixTB
(JNIEnv *, jobject self, jint handle) 
{
	int hwnd = handle;

	LRESULT res;

	TBMETRICS metrics;
	memset(&metrics, 0, sizeof(metrics));
	metrics.cbSize = sizeof(metrics);
	metrics.dwMask = TBMF_BARPAD | TBMF_PAD;
	metrics.cxPad = 0;
	metrics.cxBarPad = 0;
	metrics.cyPad = -2;
	res = SendMessage((HWND)hwnd, TB_SETMETRICS, 0, (LPARAM)&metrics);

	return res;
}

then in createItem I have added the following code, just before it returns:

	boolean hasDD = false;
	for (int i = 0; i < items.length; i++) {
		if (items[i] != null && (items[i].getStyle() & SWT.DROP_DOWN) != 0) {
			hasDD = true;
		}
	}
	if (hasDD) {
		fixTB(handle);
	}

The result will be attached in the screenshot.
Comment 29 Genady Beryozkin CLA 2006-04-22 08:10:52 EDT
Created attachment 39236 [details]
Screenshot

PS. The first button rule seems to not work after all. The code I attached checks all the buttons.

(I should also add that if the perspective bar is placed on the top right, the toolbar is oversized again.)
Comment 30 Genady Beryozkin CLA 2006-04-22 08:18:00 EDT
Created attachment 39237 [details]
Views screenshot

Console view - "before" and "after"
Comment 31 Gunnar Wagenknecht CLA 2006-04-22 08:41:29 EDT
Created attachment 39239 [details]
Toolbar buttons Eclipse, Windows and "Fixed"

I have a problem with the last modification. See the attached screenshot. The proposed modification renders the button height incorrectly. Actually, if you compare the buttons with other toolbar buttons the button height is absolutely correct in Eclipse 3.1 RC1a.
Comment 32 Randy Hudson CLA 2006-04-24 09:59:33 EDT
Gunnar, the problem is that the toolbar height varries. Your screenshots just show that IE has not worked around the issue, probably because the size of their toolbar is limited and they have plenty of space.

If you customize the IE toolbar such that it doesn't have dropdown items, its height will shrink.
Comment 33 Steve Northover CLA 2006-04-24 11:01:46 EDT
You fix seems really dangerous and subject to future badness (font changes, theme changes, Vista changes etc.).  I think it's a possibility, but we'd need to be extremely carful.  Changes like this, where we have decided what is best for the operating system, have burned us in the past.  Particularly scaring is the use of "-2".

I'm going to keep investigating this and keep your fix in mind.
Comment 34 Darin Wright CLA 2006-04-24 12:15:58 EDT
*** Bug 135542 has been marked as a duplicate of this bug. ***
Comment 35 Michael Van Meekeren CLA 2006-04-24 16:42:25 EDT
This appears to have been introduced AFTER M4 and was evident in M5.
Comment 36 Steve Northover CLA 2006-04-24 19:10:07 EDT
SSQ and I checked the changes to ToolBar and ToolItem and none seemed suspicious.  Could someone check the JFace changes?
Comment 37 Randy Hudson CLA 2006-04-25 09:44:23 EDT
MVM, Eclipse started shipping with the manifest so that it gets the XP look and feel out of the box. Is this what you were referring to? That may have started aoound M5.
Comment 38 Michael Van Meekeren CLA 2006-04-25 09:54:41 EDT
wrt comment #37 , actually no, I mean running M4 and M5 both with the manifest shows M5 with taller toolbars when there is a dropdown present.
Comment 39 Steve Northover CLA 2006-04-25 14:52:56 EDT
I have hacked a path through this that works in both the simple case and in Eclipse.  I am refining the code and will be releasing it shortly.  Stand by ...
Comment 40 Randy Hudson CLA 2006-04-25 15:16:35 EDT
Can I get a "woo-woo!"? Nice hacking, Steve!

now if we could just get back those etched separators between the coolitems...
Comment 41 Steve Northover CLA 2006-04-25 15:28:59 EDT
It ain't over quite yet but it's looking good ... 
Comment 42 Steve Northover CLA 2006-04-25 18:56:39 EDT
Fixed > 20060425

I had to back away from the fix that would make tool bars with drop down items that had only text or mixed text and images smaller because this caused drawing problems.  I was close but just ran out of time.  The changes, although awful, are somewhat safer than "-2" (which we still have up our sleaves in case this fails).
Comment 43 Mik Kersten CLA 2006-04-25 20:31:35 EDT
To follow up on comment#40... whoohoooo!  greatbugfix
Comment 44 Jeff McAffer CLA 2006-04-25 21:23:36 EDT
eeeeexcellent! 
Comment 45 Markus Keller CLA 2006-04-26 05:31:31 EDT
Awesome. Thanks Steve for this great "new look" :-).

Verified that N20060426-0010 makes the toolbar height stay small no matter what type the first button is, so it also fixes the 3.1 problems.
Comment 46 Vishwas CLA 2006-04-27 05:59:07 EDT
Cute :-) 
Comment 47 Michael Van Meekeren CLA 2006-04-27 10:42:49 EDT
ccing eric
Comment 48 Gunnar Wagenknecht CLA 2006-05-12 13:35:34 EDT
see bug 78839 comment 26 for a side effect of this fix on Vista
Comment 49 Steve Northover CLA 2006-05-12 14:18:15 EDT
Nope.  The first thing I tried was removing the work around.  It seems Micrsoft had the same "too big" problem that we did and did something to fix it, breaking something else on Vista.
Comment 50 Vasil Svetoslavov CLA 2006-07-07 05:30:44 EDT
Hello

Sorry for asking these questions but I have no more than 6-7 months of experience with Eclipse.

I have Eclipse 3.1.2 WTP with the 20060428 updates installed. I don't know whether toolbar buttons should be displayed correctly but they aren't. I failed to download the bugfix mentionned and even if I manage to download it I'm not sure I'd have the knowledge how to install it.

Can someone please provide me some help on where can the bugfix be downloaded and how is it installed.

Please accept my appologies for bothering the community with silly questions and thanks in advance.

Regards,
V. Svetoslavov
Comment 51 Steve Northover CLA 2006-07-07 10:51:14 EDT
You'll need 3.2 to get the fix.  There's no plan to backport it to 3.1.x because of the complexity of the changes.
Comment 52 Mark McLaren CLA 2006-08-25 17:51:41 EDT
When I modify SWT Snippet150 to use the DROP_DOWN style (using either 3.2 or 3.3 M1), the toolbar is still big! Am I doing something wrong?

Thanks
Comment 53 Steve Northover CLA 2006-08-26 09:47:12 EDT
Nope.  We were only able to (safely) fix button that had only images.  The work around we went with caused sizing problems for text and mixed text and images.
Comment 54 Mark McLaren CLA 2006-08-26 11:57:26 EDT
Thanks for the quick response.  I suspect it's lower priority now, but I have raised bug 155311 to note that drop-down items with text are still broken.