Implement wxEVT_SYS_COLOUR_CHANGED in wxOSX (#832)
Starting with macOS 10.14 Mojave, system colors can change dynamically when the user switches between light and dark modes. Detect this by observing the effectiveAppearance property and emit wxSysColourChangedEvent accordingly. See #18146.
This commit is contained in:
committed by
Stefan Csomor
parent
f4d4545873
commit
cd02c548f4
@@ -305,6 +305,8 @@ static NSResponder* s_formerFirstResponder = NULL;
|
||||
// controller
|
||||
//
|
||||
|
||||
static void *EffectiveAppearanceContext = &EffectiveAppearanceContext;
|
||||
|
||||
@interface wxNonOwnedWindowController : NSObject <NSWindowDelegate>
|
||||
{
|
||||
}
|
||||
@@ -610,6 +612,32 @@ extern int wxOSXGetIdFromSelector(SEL action );
|
||||
[view setFrameSize: expectedframerect.size];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)addObservers:(NSWindow*)win
|
||||
{
|
||||
[win addObserver:self forKeyPath:@"effectiveAppearance"
|
||||
options:0 context:EffectiveAppearanceContext];
|
||||
}
|
||||
|
||||
- (void)removeObservers:(NSWindow*)win
|
||||
{
|
||||
[win removeObserver:self forKeyPath:@"effectiveAppearance" context:EffectiveAppearanceContext];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
if (context == EffectiveAppearanceContext)
|
||||
{
|
||||
wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*)object WX_implementation];
|
||||
wxNonOwnedWindow* wxpeer = windowimpl ? windowimpl->GetWXPeer() : NULL;
|
||||
if (wxpeer)
|
||||
{
|
||||
wxSysColourChangedEvent event;
|
||||
event.SetEventObject(wxpeer);
|
||||
wxpeer->HandleWindowEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -632,6 +660,7 @@ wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
|
||||
{
|
||||
if ( !m_wxPeer->IsNativeWindowWrapper() )
|
||||
{
|
||||
[(wxNonOwnedWindowController*)[m_macWindow delegate] removeObservers:m_macWindow];
|
||||
[m_macWindow setDelegate:nil];
|
||||
|
||||
// make sure we remove this first, otherwise the ref count will not lead to the
|
||||
@@ -648,6 +677,7 @@ void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
|
||||
{
|
||||
if ( !m_wxPeer->IsNativeWindowWrapper() )
|
||||
{
|
||||
[(wxNonOwnedWindowController*)[m_macWindow delegate] removeObservers:m_macWindow];
|
||||
[m_macWindow setDelegate:nil];
|
||||
}
|
||||
}
|
||||
@@ -738,6 +768,7 @@ long style, long extraStyle, const wxString& WXUNUSED(name) )
|
||||
[m_macWindow setLevel:m_macWindowLevel];
|
||||
|
||||
[m_macWindow setDelegate:controller];
|
||||
[controller addObservers:m_macWindow];
|
||||
|
||||
if ( ( style & wxFRAME_SHAPED) )
|
||||
{
|
||||
|
Reference in New Issue
Block a user