From 81ef669c6d040b3ddbbfdae64affad1b08e4454a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Sun, 16 Sep 2018 14:16:26 +0200 Subject: [PATCH] Fix wxPreferencesPage rendering in macOS dark mode In 10.14's dark mode, all views are layer-backed and the assumption that child windows are redrawn with their parent may not be correct. Change Refresh() to explicitly refresh child windows too. Also explicitly refresh the page before showing it in wxPreferences, because otherwise generic windows wouldn't be drawn correctly. --- src/osx/cocoa/preferences.mm | 4 ++++ src/osx/cocoa/window.mm | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/osx/cocoa/preferences.mm b/src/osx/cocoa/preferences.mm index 2590bd24df..bbc13a1ff9 100644 --- a/src/osx/cocoa/preferences.mm +++ b/src/osx/cocoa/preferences.mm @@ -151,6 +151,10 @@ private: info->win->Show(); SetTitle(info->page->GetName()); + // Refresh the page to ensure everything is drawn in 10.14's dark mode; + // without it, generic controls aren't shown at all + info->win->Refresh(); + // TODO: Preferences window may have some pages resizeable and some // non-resizable on OS X; the whole window is or is not resizable // depending on which page is selected. diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index c33cd56dba..eaddbc7cad 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -3024,12 +3024,30 @@ void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &hei } } +static void SetSubviewsNeedDisplay( NSView *view ) +{ + for ( NSView *sub in view.subviews ) + { + if ( !sub.layer ) + continue; + + [sub setNeedsDisplay:YES]; + SetSubviewsNeedDisplay(sub); + } +} + void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where ) { if ( where ) [m_osxView setNeedsDisplayInRect:wxToNSRect(m_osxView, *where )]; else [m_osxView setNeedsDisplay:YES]; + + // Layer-backed views (which are all in Mojave's Dark Mode) may not have + // their children implicitly redrawn with the parent. For compatibility, + // do it manually here: + if ( m_osxView.layer ) + SetSubviewsNeedDisplay(m_osxView); } bool wxWidgetCocoaImpl::GetNeedsDisplay() const