From e93e9558f46f424a9c81dc0868c981b500d55716 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 21 Jul 2020 08:54:28 +0200 Subject: [PATCH] Fix change the shaped of a shaped window under Mac MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The shape path was not reset when another region shape was set, so add a workaround to trigger a recalculation of the TLW’s outer shape. Closes #18775. --- src/osx/cocoa/nonownedwnd.mm | 7 +++++++ src/osx/nonownedwnd_osx.cpp | 15 +++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index c118d47b08..f38eeddde4 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -997,6 +997,13 @@ void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region)) { + // macOS caches the contour of the drawn area, so when the region is changed and the content view redrawn + // the shape of the tlw does not change, this is a workaround I found that leads to a contour-refresh ... + NSRect formerFrame = [m_macWindow frame]; + NSSize formerSize = [NSWindow contentRectForFrameRect:formerFrame styleMask:[m_macWindow styleMask]].size; + [m_macWindow setContentSize:NSMakeSize(10,10)]; + [m_macWindow setContentSize:formerSize]; + [m_macWindow setOpaque:NO]; [m_macWindow setBackgroundColor:[NSColor clearColor]]; diff --git a/src/osx/nonownedwnd_osx.cpp b/src/osx/nonownedwnd_osx.cpp index d17624f029..d5118be241 100644 --- a/src/osx/nonownedwnd_osx.cpp +++ b/src/osx/nonownedwnd_osx.cpp @@ -510,6 +510,7 @@ void *wxNonOwnedWindow::OSXGetViewOrWindow() const bool wxNonOwnedWindow::DoClearShape() { m_shape.Clear(); + m_shapePath = wxGraphicsPath(); wxSize sz = GetClientSize(); wxRegion region(0, 0, sz.x, sz.y); @@ -519,11 +520,13 @@ bool wxNonOwnedWindow::DoClearShape() bool wxNonOwnedWindow::DoSetRegionShape(const wxRegion& region) { + m_shapePath = wxGraphicsPath(); m_shape = region; // set the native content view to transparency, this is an implementation detail // no reflected in the wx BackgroundStyle GetPeer()->SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); + GetPeer()->SetNeedsDisplay(); return m_nowpeer->SetShape(region); } @@ -534,8 +537,6 @@ bool wxNonOwnedWindow::DoSetRegionShape(const wxRegion& region) bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path) { - m_shapePath = path; - // Convert the path to wxRegion by rendering the path on a window-sized // bitmap, creating a mask from it and finally creating the region from // this mask. @@ -548,12 +549,18 @@ bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path) wxScopedPtr context(wxGraphicsContext::Create(dc)); context->SetBrush(*wxWHITE); - context->FillPath(m_shapePath); + context->FillPath(path); } bmp.SetMask(new wxMask(bmp, *wxBLACK)); - return DoSetRegionShape(wxRegion(bmp)); + // the shape path has to be set AFTER the region is set, because that method + // clears any former path + bool success = DoSetRegionShape(wxRegion(bmp)); + if ( success ) + m_shapePath = path; + + return success; } void