Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 110005

Summary: Shift F10 - using context menu key makes menu pop up in wrong place
Product: [Eclipse Project] Platform Reporter: Mike Wilson <mikewse>
Component: SWTAssignee: Silenio Quarti <Silenio_Quarti>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: carolynmacleod4, cocoakevin, markus.kell.r, michael.glass+eclipse, Mike_Wilson, nevicosi, pombredanne, Silenio_Quarti, sjanuary
Version: 3.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard: stalebug
Bug Depends on:    
Bug Blocks: 357532    

Description Mike Wilson CLA 2005-09-20 08:55:42 EDT
There is a behavioral quirk in the handling of the context menu "right mouse 
button" keyboard key located to the right of the space bar. In Eclipse, when 
pressing this key, the corresponding menu pops up under the mouse pointer 
instead of below the focused element which is the standard behaviour.
Compare f ex with Outlook:
1) Select an element in the treeview on the left 
   (Outlook's folder tree, Eclipse's navigator)
2) Position the mouse pointer out in the view to the right 
   (Outlook's mail header list, Eclipse's editor pane)
3) Press the context menu key on the keyboard.
   Outlook: popup menu displays below the selected folder
   Eclipse: popup menu displays below the mouse pointer in the editor pane

Showing the popup menu belonging to the navigator pane inside the editor pane 
may be confusing and is also non-standard comparing with major Windows 
applications.

This quirk is related, but not equivalent to, 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=75766 as there may need to be a 
discussion on whether SWT should mimic the exact API behaviour of win32 (and 
the fixes should go into Eclipse code) or whether it should do what 
applications normally want to do.
Comment 1 Florian Priester CLA 2005-09-20 15:55:06 EDT
See bug 5892, bug 100557.
Comment 2 Steve Northover CLA 2005-10-04 19:39:05 EDT
*** Bug 100557 has been marked as a duplicate of this bug. ***
Comment 3 Steve Northover CLA 2006-04-17 11:36:56 EDT
*** Bug 71883 has been marked as a duplicate of this bug. ***
Comment 4 Steve Northover CLA 2007-03-30 17:21:21 EDT
*** Bug 180092 has been marked as a duplicate of this bug. ***
Comment 5 Mike Wilson CLA 2008-04-22 10:15:51 EDT
How hard is it to fix this? Isn't it just a matter of recognizing that the menu request came from the keyboard rather than the mouse and using the view bounds rather than the mouse position when popping it up?

The current behavior is actually irritating if you are driving Eclipse entirely via the keyboard.
Comment 6 Kevin Barnes CLA 2008-05-06 17:11:40 EDT
We don't know the bounds of the selection so it's difficult for us to place the menu in the correct location. In the future we could add API to let MenuDetect listeners know that the event is coming from the keyboard so that the location of the menu could be set at the application level. Not for 3.4 though.
Comment 7 Mike Wilson CLA 2008-05-07 09:41:27 EDT
(In reply to comment #6)
> We don't know the bounds of the selection...
>
I'm not sure I understand this. All I was asking for was to get the menu to pop up centered over the *control* that it is associated with. 
Comment 8 Markus Keller CLA 2008-05-07 10:04:55 EDT
> All I was asking for was to get the menu to pop
> up centered over the *control* that it is associated with. 

-1 for centering over the control. This would often make the menu overlap the selected item. I wouldn't start playing with this so late in the game...

Note that e.g. the Refactoring and Show In quick menus (Alt+Shift+R/W) already implement this request (Plat/UI API request is bug 151711), but only for a limited set of controls (StyledText, Tree, Table).
Comment 9 Mike Wilson CLA 2008-05-07 10:11:59 EDT
(In reply to comment #7)
> (In reply to comment #6)
> > We don't know the bounds of the selection...
> >
> I'm not sure I understand this. All I was asking for was to get 
> the menu to pop up centered over the *control* that it is 
> associated with. 

[Nice name, Mike :-)]
I think what Kevin refers to is the functionality you can see in f ex Outlook, that when pressing the context meny key the menu will pop up just below the selected item in the focused control.
Your suggestion is certainly an ok compromise on the way to that goal.

(In reply to comment #6)
> We don't know the bounds of the selection so it's difficult for 
> us to place the menu in the correct location. In the future we 
> could add API to let MenuDetect listeners know that the event is 
> coming from the keyboard so that the location of the menu could 
> be set at the application level. Not for 3.4 though.

IMO this API should involve the application as little as possible
and the SWT widget as much as possible, as the respective widget
(f ex List, Tree or DateTime) has the best chance of saying where
the menu should be placed depending on selection.
Without being an SWT expert, I am thinking about something like
having the widget fill these coordinates into the MenuDetectEvent, 
either in the existing x/y members or in new ones.
Comment 10 Kevin Barnes CLA 2008-05-07 10:39:53 EDT
The doc for WM_CONTEXTMENU Notification states that the menu should be placed at the location of the current selection when the context menu is opened from the keyboard. In my previous comment I was essentially saying that we don't always know where the selection is so we can't always locate the menu in the correct place. API would be needed in this case to tell users in the Show event that the menu was opened from the keyboard.

Centering the menu over the control is a potential workaround, but as Markus stated, this could obscure the current selection. I don't know if that would be more or less disruptive to users than our current situation. To be honest, I just don't open context menus from the keyboard enough to have an opinion either way.

I'll try making a patch that centers the menu over the control.
Comment 11 Mike Wilson CLA 2008-05-07 12:31:02 EDT
(In reply to comment #9)
> [Nice name, Mike :-)]
>
Indeed! That's one of the reasons why I ended up being called "McQ" -- there seem to be lots of those in the world too, but many fewer than the number of Mike Wilsons.


Comment 12 Kevin Barnes CLA 2008-05-08 10:05:22 EDT
Because a menu can be opened in a number of different ways, this is more complicated than just detecting a key press and using a different location. We tried to find a solution, but feel it's too late to make this change for 3.4.
Comment 13 Mike Wilson CLA 2008-05-12 16:33:08 EDT
Ok, bad luck, but I'm still very happy that you have started working on it. 
(hey, getting it fixed in 3.5 will just be an 0.4 increment since I reported it ;-)

When you do plan your design changes I would you suggest you look at
https://bugs.eclipse.org/bugs/show_bug.cgi?id=75766
at the same time, as there may be some overlapping concerns on how to distribute widget vs framework responsibilities.

Best regards
Mike
Comment 14 Mike Wilson CLA 2008-05-13 13:17:42 EDT
So can we put the 3.5 target on this?

Comment 15 Kevin Barnes CLA 2008-05-13 13:19:04 EDT
Sure.
Comment 16 Steve Northover CLA 2008-05-16 14:33:12 EDT
> I am thinking about something like
> having the widget fill these coordinates into the MenuDetectEvent, 
> either in the existing x/y members or in new ones.

My thoughts as well.  We'll need to implement something for each native control.  To implement this for custom controls, they can listen for MenuDetect and set the x and y fields in the event for subsequent listeners in the chain.
Comment 17 Kathy Chan CLA 2009-04-28 09:35:43 EDT
Hi Steve,

Is there an outlook for this defect?  Is it going to be fixed in Eclipse 3.5 (as it's currently targeted at)?  This is currently affecting our accessibility test.

Thanks,
Kathy
Comment 18 Kathy Chan CLA 2009-04-28 10:32:51 EDT
Actually, this problem was found during our accessibility test but does not really affect accessibility.  So you could ignore comment #17.
Comment 19 Carolyn MacLeod CLA 2012-03-13 17:21:01 EDT
As a first step in fixing this bug, new API was added so that custom controls can tell if the menu detect is from the mouse or keyboard. This lets them set the x, y location of the context menu based on control-specific selection or focus.
This will be in 3.8/4.2 M6 (API freeze milestone).
See bug 374147 for details.
Comment 20 Markus Keller CLA 2012-04-13 11:45:50 EDT
(In reply to comment #19)
I've released bug 374320, so that the new API will be used in the Open Context Menu command. Filed bug 375723 and bug 375721 for follow-up problems.
Comment 21 Carolyn MacLeod CLA 2012-04-16 12:23:04 EDT
(In reply to comment #20)
Thanks, Markus. I am just getting to these today. I really appreciate that you have given inspirational sample code in those 2 bugs.  :)  I'll be in touch.
Comment 22 Markus Keller CLA 2012-05-07 13:26:13 EDT
In 3.8/4.2 M7, Windows 7, custom context menus are now placed at the control's desired location when I press the menu key or Shift+F10.

The native Text menu always opens centered on the Text control and doesn't use the same location as a custom menu (which opens below the caret). This may just be OS behavior.


But non-native menus are not all handled the same:

- On Table, Tree and Text, Shift+F10 uses SWT's location, but the ContextMenuHandler doesn't get SWT's location when it sends the SWT.MenuDetect event as suggested in bug 374320.

- In contrast, StyledText handles the SWT.MenuDetect event and thus places both the Shift+F10 menu as well as the ContextMenuHandler's menu at SWT's location.

The behavior of native control and custom controls should be the same, preferably that both us SWT's location all the time.
Comment 23 Lars Vogel CLA 2019-11-27 07:05:02 EST
This bug hasn't had any activity in quite some time. Maybe the problem got
resolved, was a duplicate of something else, or became less pressing for some
reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it.
The information can be, for example, that the problem still occurs, that you
still want the feature, that more information is needed, or that the bug is
(for whatever reason) no longer relevant.

If the bug is still relevant, please remove the stalebug whiteboard tag.
Comment 24 Mike Wilson CLA 2020-03-11 16:20:04 EDT
Hi folks, thanks for keeping this work going! Not long after I reported this bug in 2005 :-) I switched to Linux and haven't had a daily Windows dose since. 

Anyway, I dug up some old (and installed some new) Eclipse versions on my Windows box and tested the scenario I reported in the original bug text.
This is the result:

Eclipse 2019-12/Win10/64-bit: fixed
Eclipse 4.6.3/Win10/64-bit: fixed
Eclipse 4.6.3/Win7/32-bit: fixed
Eclipse 4.2M3/Win7/32-bit: not fixed
Eclipse 3.7/Win7/32-bit: not fixed

So seems all good from what I came across in 2005. I haven't checked if there are other special cases that would fail according to Markus's comment from 2012.
Thanks all!