From 4d8c1fc89035b86300ccd4973e3c987e6a8af24c Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 8 Sep 2017 14:35:49 +0200 Subject: [PATCH] Using another API for popup menus on modal dialogs Using popupMenuPositioningItem leads to several problems on modal dialogs - the validation and action callbacks are not used, thefore we revert in this situation to using the older API, see #549 and https://trac.wxwidgets.org/ticket/17459 --- src/osx/cocoa/menu.mm | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) 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