Community
Participate
Working Groups
- run the snippet at the bottom and press Space on the selected ToolItem. You'll get the following events printed: win32: mouse down mouse up selection traverse key down key up linux-gtk: key down selection linux-motif: key down selection key up So gtk should have a key up, and both motif and gtk should have traversal events assuming that pressing Space on a ToolItem should be similar to pressing Space on a Button. I'm not sure about the MouseDown/Up on win32. public class Main { public static void main(String[] args) { Display display = new Display (); final Shell shell = new Shell(display); shell.setBounds(10,10,200,200); ToolBar bar = new ToolBar(shell, SWT.FLAT); bar.setBounds(10,10,150,30); ToolItem item = new ToolItem(bar, SWT.PUSH); item.setText("&item 1"); bar.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { System.out.println("traverse"); } }); bar.addMouseListener(new MouseAdapter() { public void mouseDown(MouseEvent e) { System.out.println("mouse down"); } public void mouseUp(MouseEvent e) { System.out.println("mouse up"); } }); item.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { System.out.println("selection"); } }); bar.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { System.out.println("key down"); } public void keyReleased(KeyEvent e) { System.out.println("key up"); } }); shell.open(); bar.setFocus(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
The mouse down and up on Windows happen because we fake the button getting pressed and the only way to do this is to send it mouse events. The native Windows push button does this as well. The key down, key up, selection issue needs to be resolved. NOTE: It is platform dependent whether selection is issued on key down or key up so we may not need to change any code (other than fix the missing key up on GTK).
Changing OS to gtk since there's definitely a KeyUp fix needed here. Beyond this, check with SN to resolve KeyDown-KeyUp-Selection across the platforms.
It was hard to understand the difference behaviour between GtkButon in our Button and the GtkButton in our ToolItem. I tested pressing Enter and Space in both and I tested the differences. Button - Return - gtk_key_press in Button, during the traverse code (Shell#traverseReturn) SWT calls gtk_window_activate_default and returns 1, stopping the event. SWT.KeyDown not fired (BUG). - SWT.Selection is generate by gtk_window_activate_default. - gtk_key_release happens normally (generating SWT.KeyUp). Button - Space - gtk_key_press in Button, SWT.KeyDown is generated and the event is propagate to Gtk. - In GTK, when the event reach the window it activate the focus widget (queued) - gtk_key_release is first received by SWT, SWT.KeyUp is generated. - gtk_key_release is passed to GTK, GtkButton receives the event, activates the focus widget and stop the event. ToolBar - Return - gtk_key_press in GtkButton, foward by GTK to the parent (ToolBar), SWT sends SWT.KeyDown is give the event to GTK. GTK keep sending the event up in the hierarchy. - When gtk_key_press reach Shell, in Composite#gtk_key_press_event(), the event is stopped. - The window never receives the event, consequently the default widget (or the focus widget) are never activated (I consider this a BUG). - gtk_key_release happens normally (generating SWT.KeyUp) ToolBar - Space - gtk_key_press in GtkButton, since SWT doesn't hook key_press in ToolItem it (the event) will only be seen by SWT when GTK propagates the event up the hierarchy to the ToolBar. - When the event reaches the ToolBar SWT sends SWT.KeyDown and give the event back to GTK. - GTK sends the event up in the hierarchy. This time SWT doesn't stop the event from reaching the window. - When the event reach the window it activate the focus widget (queued). - gtk_key_release in GtkButton, the button uses the key_release to activate itself and stop the event, consequently it is not send to its parent (ToolBar) and never seen by SWT (so the SWT.KeyUp is never fired).
on win32, if a dragdetect listener is added the events are: mouse down mouse up selection mouse up traverse key down key up
GG to prioritize.
Using the snippet attached, this isn't reproducible. Please re-open if the issue persists.