Corrected delegate setup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3731 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-02-17 09:13:43 +00:00
parent 9fd1de051c
commit 663c70afac
5 changed files with 92 additions and 33 deletions

View file

@ -1,3 +1,13 @@
Wed Feb 17 8:38:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* 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 <richard@brainstorm.co.uk>
* Source/NSApplication.m: ([-setDelegate:]) remove old delegate as

View file

@ -33,7 +33,6 @@
#include <math.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSRunLoop.h>
#import <AppKit/AppKit.h>
@ -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

View file

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

View file

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

View file

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