Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 339116 - SWT.Hide not sent properly for menus
Summary: SWT.Hide not sent properly for menus
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-07 11:22 EST by Silenio Quarti CLA
Modified: 2011-05-23 04:31 EDT (History)
2 users (show)

See Also:


Attachments
fix (3.75 KB, patch)
2011-03-07 11:23 EST, Silenio Quarti CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Silenio Quarti CLA 2011-03-07 11:22:13 EST
There are cases where SWT.Hide is not sent and other causes where the event is sent but the menu is not hidden.

1) Run the snippet, show the File menu and press ESC. Note that the event is not sent

2a) Run the snippet, show "File" menu, show "Sub" menu, make sure the mouse is over "Sub Item0" and the item is highlighted. 
2b) Quickly move the mouse over "Sub", "Other", "Sub Item1" and back to "Sub Item0" using a circular motion. Note that the event is sent to the "Sub" menu, but it did not really got hidden. 

The problem is happening because Control.WM_MENUSELECT detects that "Other" is highlighted and usually this means that the "Sub" menu would be hidden. This was probably true on older versions of Windows (Win98?), but in WinXp there is delay to hide the menu and if the mouse goes back over the sub menu before the timeout expires it is not hidden.

This problem causes bug#244316.

I am not sure why WM_MENUSELECT is used to send SWT.Hide to menus given that WM_UNINITMENUPOPUP is exactly what we need. Maybe WM_UNINITMENUPOPUP was not availble in Win98. I will attach a patch.
Comment 1 Silenio Quarti CLA 2011-03-07 11:23:01 EST
Created attachment 190564 [details]
fix
Comment 2 Silenio Quarti CLA 2011-03-07 11:25:08 EST
Snippet:

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;


public class PR111 {
public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display);

	Menu bar = new Menu(shell, SWT.BAR);
	MenuItem file = new MenuItem(bar, SWT.CASCADE);
	file.setText("File");
	Menu m = new Menu(shell, SWT.DROP_DOWN);
	file.setMenu(m);
	MenuItem i1 = new MenuItem(m, SWT.PUSH);
	i1.setText("New");
	MenuItem i2 = new MenuItem(m, SWT.CASCADE);
	i2.setText("Sub");
	MenuItem i3 = new MenuItem(m, SWT.PUSH);
	i3.setText("Other");
	Menu m1 = new Menu(shell, SWT.DROP_DOWN);
	i2.setMenu(m1);
	MenuItem i4 = new MenuItem(m1, SWT.PUSH);
	i4.setText("Sub Item0");
	MenuItem i5 = new MenuItem(m1, SWT.PUSH);
	i5.setText("Sub Item1");
	shell.setMenuBar(bar);
	
	Listener hide = new Listener() {
		public void handleEvent(Event event) {
			System.out.println("hide=" + event.widget);
		}
	};
	Listener show = new Listener() {
		public void handleEvent(Event event) {
			System.out.println("show=" + event.widget);
		}
	};
	display.addFilter(SWT.Show, show);
	display.addFilter(SWT.Hide, hide);
	
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
}
Comment 3 Silenio Quarti CLA 2011-03-07 11:37:51 EST
Fixed > 20110307
Comment 4 Markus Keller CLA 2011-05-23 04:31:50 EDT
*** Bug 244316 has been marked as a duplicate of this bug. ***