Supporting Appearance Mode change under macOS 10.14

The system color functions depend on the current appearance, this is not automatically set to the effective appearance (that can be changed during runtime via the system preferences), added a helper class to make sure the correct version is used for retrieval.
This commit is contained in:
Stefan Csomor
2018-06-13 23:02:50 +02:00
parent ebe70d2af0
commit 9cef8282ab
3 changed files with 38 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -52,6 +52,8 @@ static int wxOSXGetUserDefault(NSString* key, int defaultValue)
wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
{
wxOSXEffectiveAppearanceSetter helper;
NSColor* sysColor = nil;
switch( index )
{