From f725afdcbd4168fce3d1e8f952fe55b03cdf8a7e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 9 Jan 2018 12:04:20 +0000 Subject: [PATCH 1/2] Backport OSX disabled-window fixes from master. Also adds ReparentQuasiModal() which is required for Kicad quasi-modal dialogs. --- include/wx/osx/dialog.h | 3 +++ src/osx/cocoa/dialog.mm | 12 ++++++++++++ src/osx/cocoa/window.mm | 13 ++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/wx/osx/dialog.h b/include/wx/osx/dialog.h index 3b0b724fb8..5beda35130 100644 --- a/include/wx/osx/dialog.h +++ b/include/wx/osx/dialog.h @@ -59,6 +59,9 @@ public: // may be called to terminate the dialog with the given return code virtual void EndModal(int retCode); + // hack to keep window behind quasi-modal dialog from being fronted + void ReparentQuasiModal(); + static bool OSXHasModalDialogsOpen(); static void OSXBeginModalDialog(); static void OSXEndModalDialog(); diff --git a/src/osx/cocoa/dialog.mm b/src/osx/cocoa/dialog.mm index 8b1e48f1b4..c6b508013e 100644 --- a/src/osx/cocoa/dialog.mm +++ b/src/osx/cocoa/dialog.mm @@ -44,3 +44,15 @@ [NSApp endSheet: GetWXWindow()]; [GetWXWindow() orderOut:GetWXWindow()]; } + +void wxDialog::ReparentQuasiModal() +{ + wxTopLevelWindow* parent = static_cast(wxGetTopLevelParent(GetParent())); + + wxASSERT_MSG(parent, "QuasiModal dialogs require a parent."); + + NSWindow* parentWindow = parent->GetWXWindow(); + NSWindow* theWindow = GetWXWindow(); + + [parentWindow addChildWindow:theWindow ordered:NSWindowAbove]; +} diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index ede8ebf778..2366d65d6b 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -863,6 +863,15 @@ - (BOOL) canBecomeKeyView return NO; } +- (NSView *)hitTest:(NSPoint)aPoint; +{ + wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + if ( viewimpl && viewimpl->GetWXPeer() && !viewimpl->GetWXPeer()->IsEnabled() ) + return nil; + + return [super hitTest:aPoint]; +} + @end // wxNSView // We need to adopt NSTextInputClient protocol in order to interpretKeyEvents: to work. @@ -985,7 +994,9 @@ void wxOSX_mouseEvent(NSView* self, SEL _cmd, NSEvent *event) if (impl == NULL) return; - impl->mouseEvent(event, self, _cmd); + // We shouldn't let disabled windows get mouse events. + if (impl->GetWXPeer()->IsEnabled()) + impl->mouseEvent(event, self, _cmd); } void wxOSX_cursorUpdate(NSView* self, SEL _cmd, NSEvent *event) -- 2.14.3 (Apple Git-98)