diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 057ddc8deb..73b93b4c86 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -505,6 +505,18 @@ extern NSLayoutManager* gNSLayoutManager; wxString wxStringWithNSString(NSString *nsstring); NSString* wxNSStringWithWxString(const wxString &wxstring); +// helper class for setting the current appearance to the +// effective appearance and restore when exiting scope + +class WXDLLIMPEXP_CORE wxOSXEffectiveAppearanceSetter +{ +public: + wxOSXEffectiveAppearanceSetter(); + ~wxOSXEffectiveAppearanceSetter(); +private: + void * formerAppearance; +}; + #endif // wxUSE_GUI #endif diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 4bb4f8fc17..22305a4c91 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -584,5 +584,29 @@ NSString* wxNSStringWithWxString(const wxString &wxstring) #endif // wxUSE_UNICODE } +// ---------------------------------------------------------------------------- +// helper class for getting the correct system colors according to the +// appearance in effect +// ---------------------------------------------------------------------------- + +wxOSXEffectiveAppearanceSetter::wxOSXEffectiveAppearanceSetter() +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 + if ( wxPlatformInfo::Get().CheckOSVersion(10, 14 ) ) + { + formerAppearance = NSAppearance.currentAppearance; + NSAppearance.currentAppearance = NSApp.effectiveAppearance; + } +#endif +} + +wxOSXEffectiveAppearanceSetter::~wxOSXEffectiveAppearanceSetter() +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 + if ( wxPlatformInfo::Get().CheckOSVersion(10, 14 ) ) + NSAppearance.currentAppearance = (NSAppearance*) formerAppearance; +#endif +} + #endif diff --git a/src/osx/cocoa/settings.mm b/src/osx/cocoa/settings.mm index 060f24037f..f6270bbb90 100644 --- a/src/osx/cocoa/settings.mm +++ b/src/osx/cocoa/settings.mm @@ -52,6 +52,8 @@ static int wxOSXGetUserDefault(NSString* key, int defaultValue) wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) { + wxOSXEffectiveAppearanceSetter helper; + NSColor* sysColor = nil; switch( index ) {