diff --git a/ChangeLog b/ChangeLog index 67bd9ce79..025f3d788 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-08-31 Fred Kiefer + + * Source/NSWindow.m (-makeFirstResponder:): When parameter is nil, + set self as first responder and return YES. + * Source/NSCell.m (-isEntryAcceptable:): Accept empty strings. + * Source/NSTableView.m (-validateEditing): Check if delegate + supports method, before calling it. + * Source/NSTextField.m (-validateEditing): Accept empty strings. + Patches partly by Andreas Höschler . + 2007-08-29 Fred Kiefer * Headers/AppKit/NSCell.h: Export more private drawing methods. diff --git a/Source/NSCell.m b/Source/NSCell.m index fb5e725dd..b9ce0e626 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -1238,13 +1238,13 @@ static NSColor *shadowCol; - (BOOL) isEntryAcceptable: (NSString*)aString { - if (_formatter != nil) + if ((_formatter != nil) && ![aString isEqualToString: @""]) { id newObjectValue; return [_formatter getObjectValue: &newObjectValue - forString: aString - errorDescription: NULL]; + forString: aString + errorDescription: NULL]; } else { diff --git a/Source/NSTableView.m b/Source/NSTableView.m index 7683dec8c..bcbd34030 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -3158,50 +3158,64 @@ byExtendingSelection: (BOOL)flag BOOL validatedOK = YES; formatter = [_editedCell formatter]; - string = AUTORELEASE ([[_textObject text] copy]); + string = AUTORELEASE([[_textObject text] copy]); if (formatter == nil) - { - newObjectValue = string; - } + { + newObjectValue = string; + } else - { - NSString *error; + { + NSString *error; - if ([formatter getObjectValue: &newObjectValue - forString: string - errorDescription: &error] == NO) - { - if ([_delegate control: self - didFailToFormatString: string - errorDescription: error] == NO) - { - validatedOK = NO; - } - else - { - newObjectValue = string; - } - } - } - if (validatedOK == YES) - { - [_editedCell setObjectValue: newObjectValue]; - - if (_dataSource_editable) - { - NSTableColumn *tb; - - tb = [_tableColumns objectAtIndex: _editedColumn]; - - [self _setObjectValue: newObjectValue - forTableColumn: tb - row: _editedRow]; + if ([formatter getObjectValue: &newObjectValue + forString: string + errorDescription: &error] == NO) + { + if ([_delegate respondsToSelector: + @selector(control:didFailToFormatString:errorDescription:)]) + { + if ([_delegate control: self + didFailToFormatString: string + errorDescription: error] == NO) - //[_dataSource tableView: self setObjectValue: newObjectValue - // forTableColumn: tb row: _editedRow]; - } - } + { + validatedOK = NO; + } + else + { + newObjectValue = string; + } + } + // Allow an empty string to fall through + else if ([string isEqualToString: @""]) + { + newObjectValue = string; + } + else + { + validatedOK = NO; + } + } + } + if (validatedOK == YES) + { + [_editedCell setObjectValue: newObjectValue]; + + if (_dataSource_editable) + { + NSTableColumn *tb; + + tb = [_tableColumns objectAtIndex: _editedColumn]; + + [self _setObjectValue: newObjectValue + forTableColumn: tb + row: _editedRow]; + + //[_dataSource tableView: self setObjectValue: newObjectValue + // forTableColumn: tb row: _editedRow]; + } + } } } diff --git a/Source/NSTextField.m b/Source/NSTextField.m index 6cb036119..3cb723acb 100644 --- a/Source/NSTextField.m +++ b/Source/NSTextField.m @@ -376,22 +376,22 @@ static Class textFieldCellClass; * was in use by another control. */ if ([_window makeFirstResponder: self]) - { - NSText *t = [_window fieldEditor: YES forObject: self]; + { + NSText *t = [_window fieldEditor: YES forObject: self]; - if ([t superview] != nil) - { - /* Can't take the field editor ... give up. */ - return; - } - - _text_object = [_cell setUpFieldEditorAttributes: t]; - [_cell editWithFrame: _bounds - inView: self - editor: _text_object - delegate: self - event: theEvent]; - } + if ([t superview] != nil) + { + /* Can't take the field editor ... give up. */ + return; + } + + _text_object = [_cell setUpFieldEditorAttributes: t]; + [_cell editWithFrame: _bounds + inView: self + editor: _text_object + delegate: self + event: theEvent]; + } } } @@ -457,39 +457,44 @@ static Class textFieldCellClass; { NSFormatter *formatter; NSString *string; + BOOL validatedOK = YES; formatter = [_cell formatter]; string = AUTORELEASE ([[_text_object text] copy]); - if (formatter == nil) - { - [_cell setStringValue: string]; - } - else - { - id newObjectValue; - NSString *error; - - if ([formatter getObjectValue: &newObjectValue - forString: string - errorDescription: &error] == YES) - { - [_cell setObjectValue: newObjectValue]; - } - else - { - SEL sel = @selector(control:didFailToFormatString:errorDescription:); + if (formatter != nil) + { + id newObjectValue; + NSString *error; + + if ([formatter getObjectValue: &newObjectValue + forString: string + errorDescription: &error] == YES) + { + [_cell setObjectValue: newObjectValue]; + return; + } + else + { + SEL sel = @selector(control:didFailToFormatString:errorDescription:); + + if ([_delegate respondsToSelector: sel]) + { + validatedOK = [_delegate control: self + didFailToFormatString: string + errorDescription: error]; + } + else if (![string isEqualToString: @""]) + { + validatedOK = NO; + } + } + } - if ([_delegate respondsToSelector: sel] && - [_delegate control: self - didFailToFormatString: string - errorDescription: error] == YES) - { - [_cell setStringValue: string]; - } - - } - } + if (validatedOK) + { + [_cell setStringValue: string]; + } } } diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 049e0ba8f..f347d6aed 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -1363,19 +1363,19 @@ many times. _f.is_key = YES; if ((!_firstResponder) || (_firstResponder == self)) - { - if (_initialFirstResponder) - { - [self makeFirstResponder: _initialFirstResponder]; - } - } + { + if (_initialFirstResponder) + { + [self makeFirstResponder: _initialFirstResponder]; + } + } [_firstResponder becomeFirstResponder]; if ((_firstResponder != self) - && [_firstResponder respondsToSelector: @selector(becomeKeyWindow)]) - { - [_firstResponder becomeKeyWindow]; - } + && [_firstResponder respondsToSelector: @selector(becomeKeyWindow)]) + { + [_firstResponder becomeKeyWindow]; + } [_wv setInputState: GSTitleBarKey]; [GSServerForWindow(self) setinputfocus: _windowNum]; @@ -2819,11 +2819,11 @@ resetCursorRectsForView(NSView *theView) return NO; _firstResponder = aResponder; - if (![_firstResponder becomeFirstResponder]) + if ((aResponder == nil) || ![_firstResponder becomeFirstResponder]) { _firstResponder = self; [_firstResponder becomeFirstResponder]; - return NO; + return (aResponder == nil); } return YES; @@ -3893,20 +3893,20 @@ resetCursorRectsForView(NSView *theView) if ((theView == nil) && (_initialFirstResponder)) { if ([_initialFirstResponder acceptsFirstResponder]) - theView = _initialFirstResponder; + theView = _initialFirstResponder; else - theView = [_initialFirstResponder nextValidKeyView]; + theView = [_initialFirstResponder nextValidKeyView]; } if (theView) { [self makeFirstResponder: theView]; if ([theView respondsToSelector:@selector(selectText:)]) - { - _selectionDirection = NSSelectingNext; - [(id)theView selectText: self]; - _selectionDirection = NSDirectSelection; - } + { + _selectionDirection = NSSelectingNext; + [(id)theView selectText: self]; + _selectionDirection = NSDirectSelection; + } } } @@ -3929,20 +3929,20 @@ resetCursorRectsForView(NSView *theView) if ((theView == nil) && (_initialFirstResponder)) { if ([_initialFirstResponder acceptsFirstResponder]) - theView = _initialFirstResponder; + theView = _initialFirstResponder; else - theView = [_initialFirstResponder previousValidKeyView]; + theView = [_initialFirstResponder previousValidKeyView]; } if (theView) { [self makeFirstResponder: theView]; if ([theView respondsToSelector:@selector(selectText:)]) - { - _selectionDirection = NSSelectingPrevious; - [(id)theView selectText: self]; - _selectionDirection = NSDirectSelection; - } + { + _selectionDirection = NSSelectingPrevious; + [(id)theView selectText: self]; + _selectionDirection = NSDirectSelection; + } } }