Bug 78888 - [consistency] ToolBar events
Summary: [consistency] ToolBar events
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Grant Gayed CLA
QA Contact:
URL:
Whiteboard:
Keywords: consistency
Depends on:
Blocks:
 
Reported: 2004-11-17 15:51 EST by Grant Gayed CLA
Modified: 2016-08-28 05:17 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Grant Gayed CLA 2004-11-17 15:51:39 EST
- 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();
}
}
Comment 1 Steve Northover CLA 2004-11-22 18:28:11 EST
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).
Comment 2 Grant Gayed CLA 2004-11-23 14:49:26 EST
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.
Comment 3 Felipe Heidrich CLA 2004-11-24 15:24:05 EST
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).

Comment 4 Fai Sigalov CLA 2004-12-16 09:38:49 EST
on win32, if a dragdetect listener is added the events are:
  mouse down
  mouse up
  selection
  mouse up
  traverse
  key down
  key up
Comment 5 Steve Northover CLA 2005-01-19 19:44:52 EST
GG to prioritize.
Comment 6 Eric Williams CLA 2016-08-05 08:46:00 EDT
Using the snippet attached, this isn't reproducible. Please re-open if the issue persists.