Bug 48914 - Make drop-down ToolItems behave more like real menus
Summary: Make drop-down ToolItems behave more like real menus
Status: RESOLVED DUPLICATE of bug 193318
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Grant Gayed CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-12-16 16:10 EST by Stefan Zeiger CLA
Modified: 2007-06-20 09:10 EDT (History)
1 user (show)

See Also:


Attachments
Screenshot of toolbar besides menu in IE 6 (21.31 KB, image/jpeg)
2004-03-25 14:28 EST, Markus Keller CLA
no flags Details
Toolbars in Word which contain tool items and menus (16.20 KB, image/jpeg)
2004-03-27 11:33 EST, Stefan Zeiger CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Zeiger CLA 2003-12-16 16:10:28 EST
It would be nice if SWT allowed real dropdown menus (not ToolItems with style =
SWT.DROPDOWN; see below) to be used on ToolBars. Modern applications for Windows
 (e.g. Internet Explorer, Microsoft Word, DirectoryOpus) often allow menu and
tool bars to be customized to the extent that they behave almost identically.
Menu and tool bars can be arranged together in a single row and they can both
contain a mix of menus and tool items.

With SWT, I can put a push buttton on a tool bar and open a popup menu when the
button is pressed, but there are differences to a real menu (at least on Win32),
most importantly the menu is opened when the button is released and not when it
is pressed down.

ToolItems with style = SWT.DROPDOWN suffer from a similar problem. I can only
attach a menu to the arrow part if I want it to open when the button is pressed
down. The event for the non-arrow part is not fired until the button is released.
Comment 1 Grant Gayed CLA 2004-01-07 11:34:56 EST
I don't think that real menus can be put into ToolBars; what you're probably 
seeing in other apps are similar drop-down mechanisms that are more tuned to 
behave like menus.

I see two main differences (on win32) between Menus and drop-down ToolItems:

1. After a mouseDown on a ToolItem's arrow, a mouseUp must occur before an item 
from the subsequent popup can be invoked.  This is annoying.
2. As you say, the only way to show a ToolItem's popup on mouseDown is if the 
user clicks on the arrow, not the item itself.  This is correct native ToolItem 
behaviour, but can be worked around by listening for mouseDown on the ToolBar, 
as shown below.  This will have the same issue as #1 though.

public static void main(String[] args) {
	final Display display = new Display();
	Shell shell = new Shell(display);
	shell.setBounds(10, 10, 400, 200);
	final Menu menu = new Menu(shell, SWT.POP_UP);
	for (int i = 0; i < 8; i++) {
		MenuItem item = new MenuItem(menu, SWT.PUSH);
		item.setText("menu item " + i);
	}
	final ToolBar bar = new ToolBar(shell, SWT.FLAT | SWT.BORDER);
	bar.setBounds(10, 10, 380, 30);
	final ToolItem[] items = new ToolItem[6];
	for (int i = 0; i < 6; i++) {
		items[i] = new ToolItem(bar, SWT.PUSH);
		items[i].setText("tool item " + i);
	}
	bar.addListener(SWT.MouseDown, new Listener() {
		public void handleEvent(Event event) {
			ToolItem item = bar.getItem(new Point(event.x, 
event.y));
			Rectangle rect = item.getBounds();
			Point pt = new Point(rect.x, rect.y + rect.height);
			pt = bar.toDisplay(pt);
			menu.setLocation(pt.x, pt.y);
			menu.setVisible(true);
		}
	});
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}

Changing the report's title to better reflect the issue.  Perhaps #1 can be 
addressed by releasing the grab (?).  Will investigate.
Comment 2 Markus Keller CLA 2004-03-25 14:28:56 EST
Created attachment 8887 [details]
Screenshot of toolbar besides menu in IE 6

I think the OP wanted to be able to crate a setup like in the attached
screenshot. In some Windows applications, the menu bar is just one toolbar,
which can be arranged with other toolbars at the user's will.
(And of course, the menus in the menu-toolbar drop down on mousedown and
menuitems are executed on the mouseup after dragging.)
Comment 3 Stefan Zeiger CLA 2004-03-27 11:33:13 EST
Created attachment 8955 [details]
Toolbars in Word which contain tool items and menus

I remember seeing another feature request asking for a way to put MenuBars on
CoolBars. That's what MSIE is doing and what you can see on Markus' screenshot.
My original idea was to go even further and allow Menus to be put on ToolBars,
so that you can mix Menus with other ToolItems on a single ToolBar, thus
allowing even greater flexibility (especially if an application allows the user
to change the menu/tool bars). The Microsoft Office applications are using this
kind of tool bars. I've attached a screenshot of (badly) reconfigured tool bars
in Word where you can see this.
Comment 4 Steve Northover CLA 2007-06-20 09:10:05 EDT

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