Critical fixes in keyboard processing when the text is edited in cells

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5146 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 1999-11-09 23:07:31 +00:00
parent 489fcc3745
commit f05e6a54fd

View file

@ -1209,10 +1209,14 @@ rectForCharacterIndex: [self selectedRange].location],
// //
// Managing the Field Editor // Managing the Field Editor
// //
- (BOOL) isFieldEditor { return is_field_editor; } - (BOOL) isFieldEditor
{
return is_field_editor;
}
- (void) setFieldEditor: (BOOL)flag - (void) setFieldEditor: (BOOL)flag
{ is_field_editor = flag; {
is_field_editor = flag;
} }
- (int) lineLayoutIndexForCharacterIndex: (unsigned) anIndex - (int) lineLayoutIndexForCharacterIndex: (unsigned) anIndex
@ -1499,117 +1503,159 @@ NSLog(NSStringFromRange(redrawLineRange));
} }
- (void) keyDown: (NSEvent *)theEvent - (void) keyDown: (NSEvent *)theEvent
{ unsigned short keyCode; {
unsigned short keyCode;
// If not editable then don't recognize the key down
if (!is_editable)
{
[super keyDown: theEvent];
return;
}
keyCode = [theEvent keyCode];
if (!is_editable) return; // If not editable then don't recognize the key down // Some keys are extremely special if we are field editor
if ([self isFieldEditor])
if ((keyCode = [theEvent keyCode])) {
switch(keyCode) int notNumber = NSIllegalTextMovement;
{ case NSUpArrowFunctionKey: //NSUpArrowFunctionKey:
[self moveCursorUp: self]; switch (keyCode)
return; {
case NSDownArrowFunctionKey: //NSDownArrowFunctionKey: case NSUpArrowFunctionKey:
[self moveCursorDown: self]; notNumber = NSUpTextMovement;
return; break;
case NSLeftArrowFunctionKey: //NSLeftArrowFunctionKey: case NSDownArrowFunctionKey:
[self moveCursorLeft: self]; notNumber = NSDownTextMovement;
return; break;
case NSRightArrowFunctionKey: //NSRightArrowFunctionKey: case NSLeftArrowFunctionKey:
[self moveCursorRight: self]; //notNumber = NSLeftTextMovement;
return; break;
case NSBackspaceKey: // backspace case NSRightArrowFunctionKey:
[self deleteRange: [self selectedRange] backspace: YES]; //notNumber = NSRightTextMovement;
return; break;
#if 1 case NSCarriageReturnKey:
case 0x6d: // end - key: debugging: enforce complete re - layout notNumber = NSReturnTextMovement;
break;
[lineLayoutInformation autorelease]; lineLayoutInformation = nil; case 0x09:
[self rebuildLineLayoutInformationStartingAtLine: 0]; if ([theEvent modifierFlags] & NSShiftKeyMask)
[self setNeedsDisplay: YES]; notNumber = NSBacktabTextMovement;
return; else
#endif notNumber = NSTabTextMovement;
#if 1 break;
case 0x45: // num - lock: debugging
NSLog([lineLayoutInformation description]);
return;
#endif
case NSCarriageReturnKey: // return
if ([self isFieldEditor]) //textShouldEndEditing delegation is handled in resignFirstResponder
{
#if 0
// Movement codes for movement between fields; these codes are the intValue of the NSTextMovement key in NSTextDidEndEditing notifications
[NSNumber numberWithInt: NSIllegalTextMovement]
[NSNumber numberWithInt: NSReturnTextMovement]
[NSNumber numberWithInt: NSTabTextMovement]
[NSNumber numberWithInt: NSBacktabTextMovement]
[NSNumber numberWithInt: NSLeftTextMovement]
[NSNumber numberWithInt: NSRightTextMovement]
[NSNumber numberWithInt: NSUpTextMovement]
[NSNumber numberWithInt: NSDownTextMovement]
#endif
[[self window] makeFirstResponder: [self nextResponder]];
[self textDidEndEditing: [NSNotification notificationWithName: NSTextDidEndEditingNotification object: self
userInfo: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: NSReturnTextMovement],@"NSTextMovement",nil]]];
} else
{
NSLog(@"\bCarriage return.\b\n");
[self insertText: [[self class] newlineString]];
return;
}
break;
/* fixme */
case 0x09:
if ([self isFieldEditor])
{
[[self window] makeFirstResponder: [self nextResponder]];
[self textDidEndEditing: [NSNotification
notificationWithName: NSTextDidEndEditingNotification object: self
userInfo: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: NSTabTextMovement],@"NSTextMovement",nil]]];
break;
}
/* fixme */
} }
#if 0 if (notNumber != NSIllegalTextMovement)
NSLog(@"keycode: %x",keyCode);
#endif
{ {
// else if ([self resignFirstResponder])
[self insertText: [theEvent characters]]; {
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];
}
return;
} }
}
// Special Characters for generic NSText
switch(keyCode)
{
case NSUpArrowFunctionKey:
[self moveCursorUp: self];
return;
case NSDownArrowFunctionKey:
[self moveCursorDown: self];
return;
case NSLeftArrowFunctionKey:
[self moveCursorLeft: self];
return;
case NSRightArrowFunctionKey:
[self moveCursorRight: self];
return;
case NSBackspaceKey:
[self deleteRange: [self selectedRange] backspace: YES];
return;
#if 1
case 0x6d: // end - key: debugging: enforce complete re - layout
[lineLayoutInformation autorelease];
lineLayoutInformation = nil;
[self rebuildLineLayoutInformationStartingAtLine: 0];
[self setNeedsDisplay: YES];
return;
#endif
#if 1
// TODO: Choose another key
case 0x45: // num - lock: debugging
NSLog ([lineLayoutInformation description]);
return;
#endif
case NSCarriageReturnKey:
NSLog (@"\bCarriage return.\b\n");
[self insertText: [[self class] newlineString]];
return;
}
// If the character(s) was not a special one, simply insert it.
[self insertText: [theEvent characters]];
} }
- (BOOL) acceptsFirstResponder - (BOOL) acceptsFirstResponder
{ if ([self isSelectable]) return YES; {
else return NO; if ([self isSelectable])
return YES;
else
return NO;
} }
- (BOOL) resignFirstResponder - (BOOL) resignFirstResponder
{ if ([self shouldDrawInsertionPoint]) {
{ if ([self isEditable])
// [self lockFocus]; if ([self textShouldEndEditing: self] == NO)
[self drawInsertionPointAtIndex: [self selectedRange].location color: nil turnedOn: NO]; return NO;
// [self unlockFocus];
//<!> stop timed entry // Add any clean-up stuff here
}
if ([self isEditable]) return [self textShouldEndEditing: (NSText*)self]; if ([self shouldDrawInsertionPoint])
return YES; {
[self drawInsertionPointAtIndex: [self selectedRange].location
color: nil turnedOn: NO];
//<!> stop timed entry
}
[self textDidEndEditing: nil];
return YES;
} }
- (BOOL) becomeFirstResponder - (BOOL) becomeFirstResponder
{ {
// if ([self shouldDrawInsertionPoint]) if ([self isSelectable])
// { if ([self textShouldBeginEditing: self])
// [self lockFocus]; {
// [self drawInsertionPointAtIndex: [self selectedRange].location color: [NSColor blackColor] turnedOn: YES]; // Add any initialization stuff here.
// [self unlockFocus];
// //<!> restart timed entry //if ([self shouldDrawInsertionPoint])
// } // {
if ([self isEditable] && [self textShouldBeginEditing: (NSText*)self]) return YES; // [self lockFocus];
else return NO; // [self drawInsertionPointAtIndex: [self selectedRange].location
// color: [NSColor blackColor] turnedOn: YES];
// [self unlockFocus];
// //<!> restart timed entry
// }
[self textDidBeginEditing: nil];
return YES;
}
return NO;
} }
/* /*
@ -1643,38 +1689,77 @@ NSLog(@"keycode: %x",keyCode);
/* /*
* 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]]; if ([delegate respondsToSelector: @selector(textDidBeginEditing: )])
{
if (!aNotification)
aNotification = [NSNotification notificationWithName:
NSTextDidBeginEditingNotification
object: self];
[delegate textDidBeginEditing: aNotification];
}
[[NSNotificationCenter defaultCenter] postNotificationName: NSTextDidBeginEditingNotification object: self]; [[NSNotificationCenter defaultCenter]
postNotificationName: NSTextDidBeginEditingNotification
object: (id)self];
} }
- (void)textDidChange: (NSNotification *)aNotification - (void)textDidChange: (NSNotification *)aNotification
{ if ([delegate respondsToSelector: @selector(textDidChange: )]) {
[delegate textDidChange: aNotification? aNotification: [NSNotification notificationWithName: NSTextDidChangeNotification object: self]]; if ([delegate respondsToSelector: @selector(textDidChange: )])
{
if (!aNotification)
aNotification = [NSNotification notificationWithName:
NSTextDidChangeNotification
object: (id)self];
[[NSNotificationCenter defaultCenter] postNotificationName: NSTextDidChangeNotification object: self]; [delegate textDidChange: aNotification];
}
[[NSNotificationCenter defaultCenter]
postNotificationName: NSTextDidChangeNotification
object: (id)self];
} }
- (void)textDidEndEditing: (NSNotification *)aNotification - (void)textDidEndEditing: (NSNotification *)aNotification
{ if ([delegate respondsToSelector: @selector(textDidEndEditing: )]) {
[delegate textDidEndEditing: aNotification? aNotification: [NSNotification notificationWithName: NSTextDidEndEditingNotification object: self]]; if ([delegate respondsToSelector: @selector(textDidEndEditing: )])
{
[[NSNotificationCenter defaultCenter] postNotificationName: NSTextDidEndEditingNotification object: self]; if (!aNotification)
aNotification = [NSNotification notificationWithName:
NSTextDidEndEditingNotification
object: (id)self];
[delegate textDidEndEditing: aNotification];
}
[[NSNotificationCenter defaultCenter]
postNotificationName: NSTextDidEndEditingNotification
object: (id)self];
} }
- (BOOL) textShouldBeginEditing: (NSText *)textObject - (BOOL) textShouldBeginEditing: (NSText *)textObject
{ if ([delegate respondsToSelector: @selector(textShouldBeginEditing: )]) {
return [delegate textShouldBeginEditing: (NSText*)self]; if ([delegate respondsToSelector: @selector(textShouldBeginEditing: )])
else return YES; return [delegate textShouldBeginEditing: self];
else
return YES;
} }
- (BOOL) textShouldEndEditing: (NSText *)textObject - (BOOL) textShouldEndEditing: (NSText *)textObject
{ if ([delegate respondsToSelector: @selector(textShouldEndEditing: )]) {
return [delegate textShouldEndEditing: (NSText*)self]; if ([delegate respondsToSelector: @selector(textShouldEndEditing: )])
else return YES; return [delegate textShouldEndEditing: 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) characterRangeForBoundingRect: (NSRect)boundsRect