diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index a5eed3e9bb..9a7bb661e6 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -305,6 +305,8 @@ static NSResponder* s_formerFirstResponder = NULL; // controller // +static void *EffectiveAppearanceContext = &EffectiveAppearanceContext; + @interface wxNonOwnedWindowController : NSObject { } @@ -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) ) {