Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#15385 closed enhancement (fixed)

Popup menu default position is wrong in osx-cocoa

Reported by: joecarl Owned by: Vadim Zeitlin <vadim@…>
Priority: normal Milestone: 3.1.0
Component: wxOSX Version: 2.9.5
Keywords: Cc:
Blocked By: Blocking:
Patch: yes

Description

when you create a wxMenu; and make it appear by calling wxWindow::PopupMenu(...); without specifying coordinates it doesn't appear in the correct position under osx.

Since screen captures don't catch the mouse pointer I took some pictures with my camera:

Windows wxWidgets App:
http://img844.imageshack.us/img844/1691/lhsc.jpg

OSX wxWidgets App:
http://imageshack.us/a/img19/772/urpg.jpg

OSX Finder:
http://imageshack.us/a/img593/8060/m0h3.jpg

As you can see the position of the cursor's active point is outside the menu in wxMSW and in OSX Finder but in wxOSX the active point is inside the menu making the first item to highlight. This is not good since you can make a non-desired double right click and select the first item when you really don't want that.

If you specify coordinates mouse coordinates you get a weird behaviour when the mouse pointer is close to the bottom of the screen: for example if you right click on the botom the context menu appears at the top part of the screen...

Attachments (1)

osx_popup_position_fix.patch download (1.2 KB) - added by david.vanderson 3 years ago.
fix position of popup when mouse pointer is close to bottom of screen

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by vadz

  • Milestone 3.0 deleted

I don't think this is 3.0-critical, even if I agree that it should be fixed. It looks like we need to adjust the frame used in wxMenuCocoaImpl::PopUp() in source:wxWidgets/trunk/src/osx/cocoa/menu.mm but I don't see anything obviously wrong there...

comment:2 Changed 5 years ago by joecarl

I thought this would be a simple bug easily fixable. Maybe it's not critical but it's quite annoying. Leave it for the future... never mind.

comment:3 Changed 5 years ago by joecarl

  • Milestone set to 3.0.1

comment:4 Changed 5 years ago by vadz

  • Milestone 3.0.1 deleted

Changed 3 years ago by david.vanderson

fix position of popup when mouse pointer is close to bottom of screen

comment:5 Changed 3 years ago by vadz

  • Milestone set to 3.1.0
  • Patch set

comment:6 Changed 3 years ago by johnr

The following approach is available from 10.6 and is simpler than creating a NSPopUpButtonCell. It also positions the cursor arrow appropriately. I haven't yet found any problems.

diff --git a/src/osx/cocoa/menu.mm b/src/osx/cocoa/menu.mm
index eb52113..b76e211 100644
--- a/src/osx/cocoa/menu.mm
+++ b/src/osx/cocoa/menu.mm
@@ -237,20 +237,12 @@ public :
     {
         win->ScreenToClient( &x , &y ) ;
         NSView *view = win->GetPeer()->GetWXWidget();
-        NSRect frame = [view frame];
-        frame.origin.x = x;
-        frame.origin.y = y;
-        frame.size.width = 1;
-        frame.size.height = 1;
-        NSPopUpButtonCell *popUpButtonCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
-        [popUpButtonCell setAutoenablesItems:NO];
-        [popUpButtonCell setAltersStateOfSelectedItem:NO];
-        [popUpButtonCell setMenu:m_osxMenu];
-        [popUpButtonCell selectItem:nil];
-        [popUpButtonCell performClickWithFrame:frame inView:view];
-        [popUpButtonCell release];
+        NSPoint point = {x,y};
+        [m_osxMenu popUpMenuPositioningItem:nil
+                                  atLocation: point
+                                      inView:view];
     }
-    
+
     virtual void GetMenuBarDimensions(int &x, int &y, int &width, int &height) const wxOVERRIDE
     {
         NSRect r = [(NSScreen*)[[NSScreen screens] objectAtIndex:0] frame];

comment:7 Changed 3 years ago by Vadim Zeitlin <vadim@…>

  • Owner set to Vadim Zeitlin <vadim@…>
  • Resolution set to fixed
  • Status changed from new to closed

In 33d8d4e57c14483f201da588129bfea9616da8d8/git-wxWidgets:

Correct positioning of popup menus relative to mouse pointer

Also simplify the code by using the native method available since OS X 10.6
instead of emulating it.

Closes #15385.

comment:8 Changed 3 years ago by Vadim Zeitlin <vadim@…>

In 01e09e534ff82019274383046db602c22e78b209/git-wxWidgets:

Compilation fix for wxOSX: don't use CGPointMake()

Use NSMakePoint() to, well, make the point.

This should have been in 33d8d4e57c14483f201da588129bfea9616da8d8 but the
wrong function was inadvertently used (and still compiled somehow...).

See #15385.

Note: See TracTickets for help on using tickets.