diff --git a/src/osx/cocoa/menu.mm b/src/osx/cocoa/menu.mm index 4a74f33e3d..31707ef802 100644 --- a/src/osx/cocoa/menu.mm +++ b/src/osx/cocoa/menu.mm @@ -237,12 +237,40 @@ public : virtual void PopUp( wxWindow *win, int x, int y ) wxOVERRIDE { - win->ScreenToClient( &x , &y ) ; NSView *view = win->GetPeer()->GetWXWidget(); - // Turn off auto-enable; it caused popup menus inside of dialogs - // to be entirely disabled. - DisableAutoEnable(); - [m_osxMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(x, y) inView:view]; + + wxPoint screenPoint(x,y); + NSPoint pointInView = wxToNSPoint(view, win->ScreenToClient( screenPoint )); + + // action and validation methods are not called from macos for modal dialogs + // when using popUpMenuPositioningItem therefore we fall back to the older method + if ( wxDialog::OSXHasModalDialogsOpen() ) + { + // we don't want plug-ins interfering + m_osxMenu.allowsContextMenuPlugIns = NO; + + wxTopLevelWindow* tlw = static_cast(wxGetTopLevelParent(win)); + NSWindow* nsWindow = tlw->GetWXWindow(); + NSRect nsrect = NSZeroRect; + nsrect.origin = wxToNSPoint( NULL, screenPoint ); + nsrect = [nsWindow convertRectFromScreen:nsrect]; + + NSEvent* rightClick = [NSEvent mouseEventWithType:NSRightMouseDown + location:nsrect.origin + modifierFlags:0 + timestamp:0 + windowNumber:[nsWindow windowNumber] + context:nil + eventNumber:0 + clickCount:1 + pressure:0]; + + [NSMenu popUpContextMenu:m_osxMenu withEvent:rightClick forView:view]; + } + else + { + [m_osxMenu popUpMenuPositioningItem:nil atLocation:pointInView inView:view]; + } } virtual void GetMenuBarDimensions(int &x, int &y, int &width, int &height) const wxOVERRIDE