From a4cdbd775f46023ec875b0e5c1aeb6cea3835b79 Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Sun, 14 Nov 1999 03:23:54 +0000 Subject: [PATCH] Simplified, by removing 'methods implemented by the delegate'; the code was moved elsewhere. Also, some fixes. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5176 72102866-910b-0410-8b05-ffd578937521 --- Source/NSText.m | 168 +++++++++++++++++------------------------------- 1 file changed, 59 insertions(+), 109 deletions(-) diff --git a/Source/NSText.m b/Source/NSText.m index 2814a4d37..96146e166 100644 --- a/Source/NSText.m +++ b/Source/NSText.m @@ -42,6 +42,7 @@ #endif // the definition in gstep-base produces warnings FIX ME FAR #include +#include #include #include @@ -2024,7 +2025,9 @@ static NSRange MakeRangeFromAbs(int a1,int a2) [self visibleRect]]); [self redisplayForLineRange: redrawLineRange]; // broadcast notification - [self textDidChange: nil]; + [[NSNotificationCenter defaultCenter] + postNotificationName: NSTextDidChangeNotification + object: self]; } // central text deletion/backspace method @@ -2111,7 +2114,9 @@ static NSRange MakeRangeFromAbs(int a1,int a2) [self redisplayForLineRange: redrawLineRange]; // broadcast notification - [self textDidChange: nil]; + [[NSNotificationCenter defaultCenter] + postNotificationName: NSTextDidChangeNotification + object: self]; } @@ -2159,21 +2164,29 @@ static NSRange MakeRangeFromAbs(int a1,int a2) } if (notNumber != NSIllegalTextMovement) { - if ([self resignFirstResponder]) - { - NSNumber *number; - NSDictionary *uiDictionary; - NSNotification *notification; - - number = [NSNumber numberWithInt: notNumber]; - uiDictionary = [NSDictionary dictionaryWithObjectsAndKeys: number, - @"NSTextMovement", NULL]; - notification = [NSNotification notificationWithName: - NSTextDidEndEditingNotification - object: self - userInfo: uiDictionary]; - [self textDidEndEditing: notification]; - } + // This is similar to [self resignFirstResponder], + // with the difference that in the notification we need + // to put the NSTextMovement, which resignFirstResponder + // does not. Also, if we are ending editing, we are going + // to be removed, so it's useless to update any drawing. + NSNumber *number; + NSDictionary *uiDictionary; + + if (([self isEditable]) + && ([delegate respondsToSelector: + @selector(textShouldEndEditing:)]) + && ([delegate textShouldEndEditing: self] == NO)) + return; + + // Add any clean-up stuff here + + number = [NSNumber numberWithInt: notNumber]; + uiDictionary = [NSDictionary dictionaryWithObject: number + forKey: @"NSTextMovement"]; + [[NSNotificationCenter defaultCenter] + postNotificationName: NSTextDidEndEditingNotification + object: self + userInfo: uiDictionary]; return; } } @@ -2230,10 +2243,11 @@ static NSRange MakeRangeFromAbs(int a1,int a2) - (BOOL) resignFirstResponder { - if ([self isEditable]) - if ([self textShouldEndEditing: self] == NO) - return NO; - + if (([self isEditable]) + && ([delegate respondsToSelector: @selector(textShouldEndEditing:)]) + && ([delegate textShouldEndEditing: self] == NO)) + return NO; + // Add any clean-up stuff here if ([self shouldDrawInsertionPoint]) @@ -2244,30 +2258,35 @@ static NSRange MakeRangeFromAbs(int a1,int a2) // stop timed entry } - [self textDidEndEditing: nil]; + [[NSNotificationCenter defaultCenter] + postNotificationName: NSTextDidEndEditingNotification + object: self]; return YES; } - (BOOL) becomeFirstResponder { - if ([self isSelectable]) - if ([self textShouldBeginEditing: self]) - { - // Add any initialization stuff here. - - //if ([self shouldDrawInsertionPoint]) - // { - // [self lockFocus]; - // [self drawInsertionPointAtIndex: [self selectedRange].location - // color: [NSColor blackColor] turnedOn: YES]; - // [self unlockFocus]; - // // restart timed entry - // } - [self textDidBeginEditing: nil]; - return YES; - } - - return NO; + if ([self isSelectable] == NO) + return NO; + + if (([delegate respondsToSelector: @selector(textShouldBeginEditing:)]) + && ([delegate textShouldBeginEditing: self] == NO)) + return NO; + + // Add any initialization stuff here. + + //if ([self shouldDrawInsertionPoint]) + // { + // [self lockFocus]; + // [self drawInsertionPointAtIndex: [self selectedRange].location + // color: [NSColor blackColor] turnedOn: YES]; + // [self unlockFocus]; + // // restart timed entry + // } + [[NSNotificationCenter defaultCenter] + postNotificationName: NSTextDidBeginEditingNotification + object: self]; + return YES; } /* @@ -2298,75 +2317,6 @@ static NSRange MakeRangeFromAbs(int a1,int a2) SET_DELEGATE_NOTIFICATION(DidEndEditing); } -/* - * Implemented by the Delegate - */ - -- (void) textDidBeginEditing: (NSNotification *)aNotification -{ - if ([delegate respondsToSelector: @selector(textDidBeginEditing: )]) - { - if (!aNotification) - aNotification = [NSNotification notificationWithName: - NSTextDidBeginEditingNotification - object: self]; - [delegate textDidBeginEditing: aNotification]; - } - - [[NSNotificationCenter defaultCenter] - postNotificationName: NSTextDidBeginEditingNotification - object: (id)self]; -} - -- (void)textDidChange: (NSNotification *)aNotification -{ - if ([delegate respondsToSelector: @selector(textDidChange: )]) - { - if (!aNotification) - aNotification = [NSNotification notificationWithName: - NSTextDidChangeNotification - object: (id)self]; - - [delegate textDidChange: aNotification]; - } - - [[NSNotificationCenter defaultCenter] - postNotificationName: NSTextDidChangeNotification - object: (id)self]; -} - -- (void)textDidEndEditing: (NSNotification *)aNotification -{ - if ([delegate respondsToSelector: @selector(textDidEndEditing: )]) - { - if (!aNotification) - aNotification = [NSNotification notificationWithName: - NSTextDidEndEditingNotification - object: (id)self]; - [delegate textDidEndEditing: aNotification]; - } - - [[NSNotificationCenter defaultCenter] - postNotificationName: NSTextDidEndEditingNotification - object: (id)self]; -} - -- (BOOL) textShouldBeginEditing: (NSText *)textObject -{ - if ([delegate respondsToSelector: @selector(textShouldBeginEditing: )]) - return [delegate textShouldBeginEditing: self]; - else - return YES; -} - -- (BOOL) textShouldEndEditing: (NSText *)textObject -{ - if ([delegate respondsToSelector: @selector(textShouldEndEditing: )]) - return [delegate textShouldEndEditing: self]; - else - return YES; -} - - (NSRange) characterRangeForBoundingRect: (NSRect)boundsRect { NSRange lineRange = [self lineRangeForRect: boundsRect];