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 1999-02-17 09:13:43 +00:00
parent a2f42a39e9
commit cf7a747a7d
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> Wed Feb 17 4:06:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSApplication.m: ([-setDelegate:]) remove old delegate as * Source/NSApplication.m: ([-setDelegate:]) remove old delegate as

View file

@ -33,7 +33,6 @@
#include <math.h> #include <math.h>
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <Foundation/NSRunLoop.h>
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
@ -265,11 +264,14 @@ RETURN_LABEL:
[self display]; [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:)]) if(delegate && [delegate respondsToSelector:@selector(splitView:resizeSubviewsWithOldSize:)])
{ {
[delegate splitView:self resizeSubviewsWithOldSize:fr.size]; [delegate splitView:self resizeSubviewsWithOldSize:fr.size];
@ -348,8 +350,8 @@ NSLog (@"XRSplitView adjustSubviews");
} }
} }
} }
[[NSNotificationCenter defaultCenter] [nc postNotificationName: NSSplitViewDidResizeSubviewsNotification
postNotificationName:NSSplitViewDidResizeSubviewsNotification object:self]; object: self];
} }
- (void)addSubview:(NSView *)aView - (void)addSubview:(NSView *)aView
@ -358,10 +360,6 @@ NSLog (@"XRSplitView adjustSubviews");
{ {
[super addSubview:aView positioned:place relativeTo:otherView]; [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]; [self adjustSubviews];
} }
@ -522,16 +520,28 @@ NSPoint centerRectInRect(NSRect innerRect, NSRect outerRect)
[[self window] invalidateCursorRectsForView:self]; [[self window] invalidateCursorRectsForView:self];
} }
- delegate - (id) delegate
{ {
return delegate; return delegate;
} }
- (void)setDelegate:anObject - (void) setDelegate: (id)anObject
{ {
if(delegate==anObject) return; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[delegate release];
delegate=[anObject retain]; 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 - (NSColor *)dividerColor

View file

@ -1585,35 +1585,51 @@ NSLog(@"keycode:%x",keyCode);
// //
// Managing the Delegate // Managing the Delegate
// //
- delegate { return delegate; } - (id) delegate
{
return delegate;
}
-(void) setDelegate:anObject -(void) setDelegate: (id)anObject
{ delegate = 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 // Implemented by the Delegate
// //
-(void) textDidBeginEditing:(NSNotification *)aNotification -(void) textDidBeginEditing: (NSNotification*)aNotification
{ if ([delegate respondsToSelector:@selector(textDidBeginEditing:)]) {
[delegate textDidBeginEditing:aNotification? aNotification:[NSNotification notificationWithName:NSTextDidBeginEditingNotification object:self]]; [[NSNotificationCenter defaultCenter]
postNotificationName: NSTextDidBeginEditingNotification object: self];
[[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidBeginEditingNotification object:self];
} }
- (void)textDidChange:(NSNotification *)aNotification - (void) textDidChange: (NSNotification*)aNotification
{ if ([delegate respondsToSelector:@selector(textDidChange:)]) {
[delegate textDidChange:aNotification? aNotification:[NSNotification notificationWithName:NSTextDidChangeNotification object:self]]; [[NSNotificationCenter defaultCenter]
postNotificationName: NSTextDidChangeNotification object: self];
[[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidChangeNotification object:self];
} }
-(void)textDidEndEditing:(NSNotification *)aNotification -(void) textDidEndEditing: (NSNotification*)aNotification
{ if ([delegate respondsToSelector:@selector(textDidEndEditing:)]) {
[delegate textDidEndEditing:aNotification? aNotification:[NSNotification notificationWithName:NSTextDidEndEditingNotification object:self]]; [[NSNotificationCenter defaultCenter]
postNotificationName: NSTextDidEndEditingNotification object: self];
[[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidEndEditingNotification object:self];
} }
-(BOOL) textShouldBeginEditing:(NSText *)textObject -(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 @end

View file

@ -246,6 +246,12 @@ NSString *NSTextDidBeginEditingNotification =
NSString *NSTextDidEndEditingNotification = @"NSTextDidEndEditingNotification"; NSString *NSTextDidEndEditingNotification = @"NSTextDidEndEditingNotification";
NSString *NSTextDidChangeNotification = @"NSTextDidChangeNotification"; NSString *NSTextDidChangeNotification = @"NSTextDidChangeNotification";
// NSTextView notifications
NSString *NSTextDidChangeSelectionNotification =
@"NSTextDidChangeSelectionNotification";
NSString *NSTextWillChangeNotifyingTextViewNotification =
@"NSTextWillChangeNotifyingTextViewNotification";
// NSView notifications // NSView notifications
NSString *NSViewFocusDidChangeNotification NSString *NSViewFocusDidChangeNotification
= @"NSViewFocusDidChangeNotification"; = @"NSViewFocusDidChangeNotification";