Community
Participate
Working Groups
public class DropDownTest { public static void main(String[] argv) { Display display = new Display(); Shell shell = new Shell(display); ToolBar toolBar = new ToolBar(shell, SWT.FLAT); ToolItem toolItem = new ToolItem(toolBar, SWT.DROP_DOWN); toolItem.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { System.out.println("event occurred"); } }); toolBar.setBounds(0, 0, 100, 50); Combo combo = new Combo(shell, SWT.DROP_DOWN); combo.add("foo"); combo.setBounds(100, 0, 100, 25); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } } -- When this code is run on Windows, the following will happen: 1. If the mouse is pressed over the main part of the button (ie. not the arrow) the event is not sent until the button is released, just like a normal button. 2. If the mouse is pressed over the arrow, the event is sent as soon as the button is pressed, and before it is released. This behaviour is consistent with the way combo boxes work on both Windows and Motif. ie., items can be selected from the dropdown as [button down] -> [move over desired item] -> [release button]. When the same code is run on Motif, the selection is only sent after the button is released no matter where the click occurred, on the arrow or on the main part of the button. This behaviour is inconsistent with Windows but especially with the way drop-down menus work in Motif. -- Also the combo box displays slightly weird behaviour on Motif: if you click and release very quickly, the menu stays up but if you click, hold, and release, the menu disappears quickly. This could be a Motif feature though.
Clarification: the two paragraphs above refer to the ToolItem, not the Combo. Only the two sentences after refer to the Combo.
I tried sending the event on MouseDown, but we can get into trouble if this results in opening a popup menu (which it usually does). The problem becomes visible when some non-trivial amount of time is spent in the selection handler. If the quickly clicks on the drop-down button without moving the mouse (ie., does not interact with the menu), the ToolItem will receive MouseDown, but never seems to get MouseUp. Thus whenever it receives MouseEnter it thinks it should be drawn depressed. It seems that the Motif menu widget grabs the pointer which is why the ToolItem never sees it. Not sure what the "correct" behaviour is, however.
*** This bug has been marked as a duplicate of bug 139318 ***
Oops, wrong duplicate.
*** This bug has been marked as a duplicate of bug 193318 ***