diff --git a/ChangeLog b/ChangeLog index 705f848da..31b750405 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Feb 17 4:06:00 1999 Richard Frith-Macdonald + + * Source/NSApplication.m: ([-setDelegate:]) remove old delegate as + observer of application notifications. + * Source/NSWindow.m: ([-setDelegate:]) add delegate as observer for + window notifications. + Tue Feb 16 17:06:00 1999 Richard Frith-Macdonald Additions provided by mgiddings@ypc.net - diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 1204a02e5..c30543019 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -1649,6 +1649,8 @@ BOOL done = NO; { NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; + if (delegate) + [nc removeObserver: delegate name: nil object: self]; delegate = anObject; #define SET_DELEGATE_NOTIFICATION(notif_name) \ diff --git a/Source/NSWindow.m b/Source/NSWindow.m index bf3562b8c..a849aab30 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -1180,8 +1180,40 @@ id result = nil; // // Assigning a delegate // -- delegate { return delegate; } -- (void)setDelegate:anObject { delegate = anObject; } +- (id) delegate +{ + return delegate; +} + +- (void) setDelegate: (id)anObject +{ + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + + if (delegate) + [nc removeObserver: delegate name: nil object: self]; + delegate = anObject; + +#define SET_DELEGATE_NOTIFICATION(notif_name) \ + if ([delegate respondsToSelector:@selector(window##notif_name:)]) \ + [nc addObserver:delegate \ + selector:@selector(window##notif_name:) \ + name:NSWindow##notif_name##Notification object:self] + + SET_DELEGATE_NOTIFICATION(DidBecomeKey); + SET_DELEGATE_NOTIFICATION(DidBecomeMain); + SET_DELEGATE_NOTIFICATION(DidChangeScreen); + SET_DELEGATE_NOTIFICATION(DidDeminiaturize); + SET_DELEGATE_NOTIFICATION(DidExpose); + SET_DELEGATE_NOTIFICATION(DidMiniaturize); + SET_DELEGATE_NOTIFICATION(DidMove); + SET_DELEGATE_NOTIFICATION(DidResignKey); + SET_DELEGATE_NOTIFICATION(DidResignMain); + SET_DELEGATE_NOTIFICATION(DidResize); + SET_DELEGATE_NOTIFICATION(DidUpdate); + SET_DELEGATE_NOTIFICATION(WillClose); + SET_DELEGATE_NOTIFICATION(WillMiniaturize); + SET_DELEGATE_NOTIFICATION(WillMove); +} // // Implemented by the delegate