From cf7a747a7d5fcaf543f0e2a7457fca1d18004705 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 17 Feb 1999 09:13:43 +0000 Subject: [PATCH] Corrected delegate setup git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3731 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 10 +++++++++ Source/NSSplitView.m | 40 +++++++++++++++++++++------------- Source/NSText.m | 52 +++++++++++++++++++++++++++++--------------- Source/NSTextView.m | 17 +++++++++++++++ Source/externs.m | 6 +++++ 5 files changed, 92 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31b750405..a0f2d4b15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Wed Feb 17 8:38:00 1999 Richard Frith-Macdonald + + * Source/NSSplitView.m: ([-setDelegate:]) corrected to register + delegate to recieve notifications. + * Source/NSText.m: ([-setDelegate:]) corrected to register + delegate to recieve notifications. + * Source/NSTextView.m: ([-setDelegate:]) implemented to register + delegate to recieve notifications. + * Source/externs.m: Added missing TextView notifications. + Wed Feb 17 4:06:00 1999 Richard Frith-Macdonald * Source/NSApplication.m: ([-setDelegate:]) remove old delegate as diff --git a/Source/NSSplitView.m b/Source/NSSplitView.m index 7e0382e01..ae4703961 100644 --- a/Source/NSSplitView.m +++ b/Source/NSSplitView.m @@ -33,7 +33,6 @@ #include #import -#import #import @@ -265,11 +264,14 @@ RETURN_LABEL: [self display]; } -- (void)adjustSubviews +- (void) adjustSubviews { - NSRect fr = [self frame]; + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + NSRect fr = [self frame]; + + [nc postNotificationName: NSSplitViewWillResizeSubviewsNotification + object: self]; -NSLog (@"XRSplitView adjustSubviews"); if(delegate && [delegate respondsToSelector:@selector(splitView:resizeSubviewsWithOldSize:)]) { [delegate splitView:self resizeSubviewsWithOldSize:fr.size]; @@ -348,8 +350,8 @@ NSLog (@"XRSplitView adjustSubviews"); } } } - [[NSNotificationCenter defaultCenter] - postNotificationName:NSSplitViewDidResizeSubviewsNotification object:self]; + [nc postNotificationName: NSSplitViewDidResizeSubviewsNotification + object: self]; } - (void)addSubview:(NSView *)aView @@ -358,10 +360,6 @@ NSLog (@"XRSplitView adjustSubviews"); { [super addSubview:aView positioned:place relativeTo:otherView]; - /* register the subviews up for notification */ - //[[NSNotificationCenter defaultCenter] addObserver:aView - // selector:@selector(splitViewDidResizeSubviews:) - // name:NSSplitViewDidResizeSubviewsNotification object:self]; [self adjustSubviews]; } @@ -522,16 +520,28 @@ NSPoint centerRectInRect(NSRect innerRect, NSRect outerRect) [[self window] invalidateCursorRectsForView:self]; } -- delegate +- (id) delegate { return delegate; } -- (void)setDelegate:anObject +- (void) setDelegate: (id)anObject { - if(delegate==anObject) return; - [delegate release]; - delegate=[anObject retain]; + 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(splitView##notif_name:)]) \ + [nc addObserver: delegate \ + selector: @selector(splitView##notif_name:) \ + name: NSSplitView##notif_name##Notification \ + object: self] + + SET_DELEGATE_NOTIFICATION(DidResizeSubviews); + SET_DELEGATE_NOTIFICATION(WillResizeSubviews); } - (NSColor *)dividerColor diff --git a/Source/NSText.m b/Source/NSText.m index 030433d1f..92f2079c9 100644 --- a/Source/NSText.m +++ b/Source/NSText.m @@ -1585,35 +1585,51 @@ NSLog(@"keycode:%x",keyCode); // // Managing the Delegate // -- delegate { return delegate; } +- (id) delegate +{ + return delegate; +} --(void) setDelegate:anObject -{ delegate = anObject; +-(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(text##notif_name:)]) \ + [nc addObserver: delegate \ + selector: @selector(text##notif_name:) \ + name: NSText##notif_name##Notification \ + object: self] + + SET_DELEGATE_NOTIFICATION(DidBeginEditing); + SET_DELEGATE_NOTIFICATION(DidChange); + SET_DELEGATE_NOTIFICATION(DidEndEditing); } // // Implemented by the Delegate // --(void) textDidBeginEditing:(NSNotification *)aNotification -{ if ([delegate respondsToSelector:@selector(textDidBeginEditing:)]) - [delegate textDidBeginEditing:aNotification? aNotification:[NSNotification notificationWithName:NSTextDidBeginEditingNotification object:self]]; - - [[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidBeginEditingNotification object:self]; +-(void) textDidBeginEditing: (NSNotification*)aNotification +{ + [[NSNotificationCenter defaultCenter] + postNotificationName: NSTextDidBeginEditingNotification object: self]; } -- (void)textDidChange:(NSNotification *)aNotification -{ if ([delegate respondsToSelector:@selector(textDidChange:)]) - [delegate textDidChange:aNotification? aNotification:[NSNotification notificationWithName:NSTextDidChangeNotification object:self]]; - - [[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidChangeNotification object:self]; +- (void) textDidChange: (NSNotification*)aNotification +{ + [[NSNotificationCenter defaultCenter] + postNotificationName: NSTextDidChangeNotification object: self]; } --(void)textDidEndEditing:(NSNotification *)aNotification -{ if ([delegate respondsToSelector:@selector(textDidEndEditing:)]) - [delegate textDidEndEditing:aNotification? aNotification:[NSNotification notificationWithName:NSTextDidEndEditingNotification object:self]]; - - [[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidEndEditingNotification object:self]; +-(void) textDidEndEditing: (NSNotification*)aNotification +{ + [[NSNotificationCenter defaultCenter] + postNotificationName: NSTextDidEndEditingNotification object: self]; } -(BOOL) textShouldBeginEditing:(NSText *)textObject diff --git a/Source/NSTextView.m b/Source/NSTextView.m index 68fbaca20..d25862f4b 100644 --- a/Source/NSTextView.m +++ b/Source/NSTextView.m @@ -354,4 +354,21 @@ if(container) [self setTextContainer: container]; { } +- (void) setDelegate: (id) anObject +{ + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + + [super setDelegate: anObject]; + +#define SET_DELEGATE_NOTIFICATION(notif_name) \ + if ([delegate respondsToSelector: @selector(textView##notif_name:)]) \ + [nc addObserver: delegate \ + selector: @selector(textView##notif_name:) \ + name: NSTextView##notif_name##Notification \ + object: self] + + SET_DELEGATE_NOTIFICATION(DidChangeSelection); + SET_DELEGATE_NOTIFICATION(WillChangeNotifyingTextView); +} + @end diff --git a/Source/externs.m b/Source/externs.m index e7bd6ff29..964f64c9c 100644 --- a/Source/externs.m +++ b/Source/externs.m @@ -246,6 +246,12 @@ NSString *NSTextDidBeginEditingNotification = NSString *NSTextDidEndEditingNotification = @"NSTextDidEndEditingNotification"; NSString *NSTextDidChangeNotification = @"NSTextDidChangeNotification"; +// NSTextView notifications +NSString *NSTextDidChangeSelectionNotification = +@"NSTextDidChangeSelectionNotification"; +NSString *NSTextWillChangeNotifyingTextViewNotification = +@"NSTextWillChangeNotifyingTextViewNotification"; + // NSView notifications NSString *NSViewFocusDidChangeNotification = @"NSViewFocusDidChangeNotification";