Community
Participate
Working Groups
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.
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.
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.)
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.
*** This bug has been marked as a duplicate of bug 193318 ***