Set the isFunctionKey boolean correctly.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25401 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2007-08-20 13:19:28 +00:00
parent 7baadf2e7c
commit 6e69654253
2 changed files with 232 additions and 225 deletions

View file

@ -1,3 +1,9 @@
2007-08-20 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSInputManager.m (-handleKeyboardEvents:client:): Set the
isFunctionKey boolean correctly. This was needed as the
NSFunctionKeyMask value doesn't fit in the first byte.
2007-08-19 21:18-EDT Gregory John Casamento <greg_casamento@yahoo.com> 2007-08-19 21:18-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* Source/NSController.m * Source/NSController.m

View file

@ -164,39 +164,39 @@ static NSInputManager *currentInputManager = nil;
NSString *modifier = [components objectAtIndex: i]; NSString *modifier = [components objectAtIndex: i];
if ([modifier isEqualToString: @"Control"] if ([modifier isEqualToString: @"Control"]
|| [modifier isEqualToString: @"Ctrl"] || [modifier isEqualToString: @"Ctrl"]
|| [modifier isEqualToString: @"C"]) || [modifier isEqualToString: @"C"])
{ {
flags |= NSControlKeyMask; flags |= NSControlKeyMask;
} }
else if ([modifier isEqualToString: @"Alternate"] else if ([modifier isEqualToString: @"Alternate"]
|| [modifier isEqualToString: @"Alt"] || [modifier isEqualToString: @"Alt"]
|| [modifier isEqualToString: @"A"] || [modifier isEqualToString: @"A"]
|| [modifier isEqualToString: @"Meta"] || [modifier isEqualToString: @"Meta"]
|| [modifier isEqualToString: @"M"]) || [modifier isEqualToString: @"M"])
{ {
flags |= NSAlternateKeyMask; flags |= NSAlternateKeyMask;
} }
/* The Shift modifier is only meaningful when used in /* The Shift modifier is only meaningful when used in
* conjunction with function keys. 'Shift-LeftArrow' is * conjunction with function keys. 'Shift-LeftArrow' is
* meaningful; 'Control-Shift-g' is not - you should use * meaningful; 'Control-Shift-g' is not - you should use
* 'Control-G' instead. */ * 'Control-G' instead. */
else if ([modifier isEqualToString: @"Shift"] else if ([modifier isEqualToString: @"Shift"]
|| [modifier isEqualToString: @"S"]) || [modifier isEqualToString: @"S"])
{ {
flags |= NSShiftKeyMask; flags |= NSShiftKeyMask;
} }
else if ([modifier isEqualToString: @"NumericPad"] else if ([modifier isEqualToString: @"NumericPad"]
|| [modifier isEqualToString: @"Numeric"] || [modifier isEqualToString: @"Numeric"]
|| [modifier isEqualToString: @"N"]) || [modifier isEqualToString: @"N"])
{ {
flags |= NSNumericPadKeyMask; flags |= NSNumericPadKeyMask;
} }
else else
{ {
NSLog (@"NSInputManager - unknown modifier '%@' ignored", modifier); NSLog (@"NSInputManager - unknown modifier '%@' ignored", modifier);
return NO; return NO;
} }
} }
/* Now, parse the actual key. */ /* Now, parse the actual key. */
@ -216,19 +216,19 @@ static NSInputManager *currentInputManager = nil;
{ {
/* A descriptive string, such as Tab or Home. */ /* A descriptive string, such as Tab or Home. */
for (i = 0; i < CHARACTER_TABLE_SIZE; i++) for (i = 0; i < CHARACTER_TABLE_SIZE; i++)
{ {
if ([name isEqualToString: (character_table[i]).name]) if ([name isEqualToString: (character_table[i]).name])
{ {
c = (character_table[i]).character; c = (character_table[i]).character;
flags |= NSFunctionKeyMask; flags |= NSFunctionKeyMask;
break; break;
} }
} }
if (i == CHARACTER_TABLE_SIZE) if (i == CHARACTER_TABLE_SIZE)
{ {
NSLog (@"NSInputManager - unknown character '%@' ignored", name); NSLog (@"NSInputManager - unknown character '%@' ignored", name);
return NO; return NO;
} }
} }
if (character != NULL) if (character != NULL)
{ {
@ -244,7 +244,7 @@ static NSInputManager *currentInputManager = nil;
} }
+ (NSString *) describeKeyStroke: (unichar)character + (NSString *) describeKeyStroke: (unichar)character
withModifiers: (unsigned int)modifiers withModifiers: (unsigned int)modifiers
{ {
NSMutableString *description = [NSMutableString new]; NSMutableString *description = [NSMutableString new];
int i; int i;
@ -277,10 +277,10 @@ static NSInputManager *currentInputManager = nil;
for (i = 0; i < CHARACTER_TABLE_SIZE; i++) for (i = 0; i < CHARACTER_TABLE_SIZE; i++)
{ {
if (character == ((character_table[i]).character)) if (character == ((character_table[i]).character))
{ {
[description appendString: character_table[i].name]; [description appendString: character_table[i].name];
break; break;
} }
} }
if (i == CHARACTER_TABLE_SIZE) if (i == CHARACTER_TABLE_SIZE)
@ -314,7 +314,7 @@ static NSInputManager *currentInputManager = nil;
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
paths = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, paths = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory,
NSAllDomainsMask, YES); NSAllDomainsMask, YES);
/* paths are in the order - user, network, local, root. Instead we /* paths are in the order - user, network, local, root. Instead we
want to load keybindings in the order root, local, network, user want to load keybindings in the order root, local, network, user
- so that user can override root - for this reason we use a - so that user can override root - for this reason we use a
@ -324,18 +324,18 @@ static NSInputManager *currentInputManager = nil;
{ {
NSString *fullPath; NSString *fullPath;
fullPath = fullPath =
[[[libraryPath stringByAppendingPathComponent: @"KeyBindings"] [[[libraryPath stringByAppendingPathComponent: @"KeyBindings"]
stringByAppendingPathComponent: fileName] stringByAppendingPathComponent: fileName]
stringByAppendingPathExtension: @"dict"]; stringByAppendingPathExtension: @"dict"];
if ([fileManager fileExistsAtPath: fullPath]) if ([fileManager fileExistsAtPath: fullPath])
{ {
[self loadBindingsFromFile: fullPath]; [self loadBindingsFromFile: fullPath];
} }
} }
} }
- (NSInputManager *) initWithName: (NSString *)inputServerName - (NSInputManager *) initWithName: (NSString *)inputServerName
host: (NSString *)hostName host: (NSString *)hostName
{ {
NSUserDefaults *defaults; NSUserDefaults *defaults;
CREATE_AUTORELEASE_POOL (pool); CREATE_AUTORELEASE_POOL (pool);
@ -352,23 +352,23 @@ static NSInputManager *currentInputManager = nil;
if (abortKey == nil) if (abortKey == nil)
{ {
_abortCharacter = 'g'; _abortCharacter = 'g';
_abortFlags = NSControlKeyMask; _abortFlags = NSControlKeyMask;
} }
else if (![NSInputManager parseKey: abortKey else if (![NSInputManager parseKey: abortKey
intoCharacter: &_abortCharacter intoCharacter: &_abortCharacter
andModifiers: &_abortFlags]) andModifiers: &_abortFlags])
{ {
NSLog (@"Could not parse GSAbortKey - using Control-g"); NSLog (@"Could not parse GSAbortKey - using Control-g");
_abortCharacter = 'g'; _abortCharacter = 'g';
_abortFlags = NSControlKeyMask; _abortFlags = NSControlKeyMask;
} }
} }
/* Read if we should insert Control- keystrokes into the text. /* Read if we should insert Control- keystrokes into the text.
This defaults to NO. */ This defaults to NO. */
_insertControlKeystrokes = [defaults boolForKey: _insertControlKeystrokes = [defaults boolForKey:
@"GSInsertControlKeystrokes"]; @"GSInsertControlKeystrokes"];
/* Read the quote key from the user defaults. */ /* Read the quote key from the user defaults. */
{ {
@ -379,7 +379,7 @@ static NSInputManager *currentInputManager = nil;
if (quoteKey == nil) if (quoteKey == nil)
{ {
quoteKey = @"Control-q"; quoteKey = @"Control-q";
} }
[_rootBindingTable bindKey: quoteKey toAction: quoteAction]; [_rootBindingTable bindKey: quoteKey toAction: quoteAction];
@ -433,7 +433,7 @@ static NSInputManager *currentInputManager = nil;
if (keyBindingsFiles == nil) if (keyBindingsFiles == nil)
{ {
keyBindingsFiles = [NSArray arrayWithObject: @"DefaultKeyBindings"]; keyBindingsFiles = [NSArray arrayWithObject: @"DefaultKeyBindings"];
} }
{ {
@ -441,14 +441,14 @@ static NSInputManager *currentInputManager = nil;
unsigned int i; unsigned int i;
for (i = 0; i < [keyBindingsFiles count]; i++) for (i = 0; i < [keyBindingsFiles count]; i++)
{ {
NSString *filename = [keyBindingsFiles objectAtIndex: i]; NSString *filename = [keyBindingsFiles objectAtIndex: i];
if ([filename isKindOfClass: string]) if ([filename isKindOfClass: string])
{ {
[self loadBindingsWithName: filename]; [self loadBindingsWithName: filename];
} }
} }
} }
} }
@ -458,7 +458,7 @@ static NSInputManager *currentInputManager = nil;
if ([keyBindings isKindOfClass: [NSDictionary class]]) if ([keyBindings isKindOfClass: [NSDictionary class]])
{ {
[_rootBindingTable loadBindingsFromDictionary: keyBindings]; [_rootBindingTable loadBindingsFromDictionary: keyBindings];
} }
} }
@ -475,7 +475,7 @@ static NSInputManager *currentInputManager = nil;
} }
- (void) handleKeyboardEvents: (NSArray *)eventArray - (void) handleKeyboardEvents: (NSArray *)eventArray
client: (id)client client: (id)client
{ {
NSEvent *theEvent; NSEvent *theEvent;
NSEnumerator *eventEnum = [eventArray objectEnumerator]; NSEnumerator *eventEnum = [eventArray objectEnumerator];
@ -495,184 +495,185 @@ static NSInputManager *currentInputManager = nil;
NSString *unmodifiedCharacters = [theEvent charactersIgnoringModifiers]; NSString *unmodifiedCharacters = [theEvent charactersIgnoringModifiers];
unichar character = 0; unichar character = 0;
unsigned flags = [theEvent modifierFlags] & (NSShiftKeyMask unsigned flags = [theEvent modifierFlags] & (NSShiftKeyMask
| NSAlternateKeyMask | NSAlternateKeyMask
| NSControlKeyMask | NSControlKeyMask
| NSNumericPadKeyMask); | NSNumericPadKeyMask);
BOOL isFunctionKey = [theEvent modifierFlags] & NSFunctionKeyMask; BOOL isFunctionKey = ([theEvent modifierFlags] & NSFunctionKeyMask)
== NSFunctionKeyMask;
if ([unmodifiedCharacters length] > 0) if ([unmodifiedCharacters length] > 0)
{ {
character = [unmodifiedCharacters characterAtIndex: 0]; character = [unmodifiedCharacters characterAtIndex: 0];
} }
if (!_interpretNextKeyStrokeLiterally) if (!_interpretNextKeyStrokeLiterally)
{ {
GSKeyBindingAction *action; GSKeyBindingAction *action;
GSKeyBindingTable *table; GSKeyBindingTable *table;
BOOL found; BOOL found;
unsigned adaptedFlags; unsigned adaptedFlags;
/* If the keystroke is a function key, then we need to use /* If the keystroke is a function key, then we need to use
* the full modifier flags to compare it against stored * the full modifier flags to compare it against stored
* keybindings, so that we can make a difference for example * keybindings, so that we can make a difference for example
* between Shift-LeftArrow and LeftArrow. But if it's not a * between Shift-LeftArrow and LeftArrow. But if it's not a
* function key, then we should ignore the shift modifier - * function key, then we should ignore the shift modifier -
* for example Control-g is a keystroke, and Control-G is * for example Control-g is a keystroke, and Control-G is
* another one. The shift modifier flag is not used to * another one. The shift modifier flag is not used to
* match these keystrokes - the fact that it's 'G' rather * match these keystrokes - the fact that it's 'G' rather
* than 'g' already contains the fact that it's typed in * than 'g' already contains the fact that it's typed in
* with Shift. */ * with Shift. */
if (!isFunctionKey) if (!isFunctionKey)
{ {
adaptedFlags = flags & (~NSShiftKeyMask); adaptedFlags = flags & (~NSShiftKeyMask);
} }
else else
{ {
adaptedFlags = flags; adaptedFlags = flags;
} }
/* Special keybinding recognized in all contexts - abort - /* Special keybinding recognized in all contexts - abort -
normally bound to Control-g. The user is confused and normally bound to Control-g. The user is confused and
wants to go home. Abort whatever train of thoughts we wants to go home. Abort whatever train of thoughts we
were following, discarding whatever pending keystrokes we were following, discarding whatever pending keystrokes we
have, and return into default state. */ have, and return into default state. */
if (character == _abortCharacter && adaptedFlags == _abortFlags) if (character == _abortCharacter && adaptedFlags == _abortFlags)
{ {
[self resetInternalState]; [self resetInternalState];
break; break;
} }
/* Look up the character in the current keybindings table. */ /* Look up the character in the current keybindings table. */
found = [_currentBindingTable lookupKeyStroke: character found = [_currentBindingTable lookupKeyStroke: character
modifiers: adaptedFlags modifiers: adaptedFlags
returningActionIn: &action returningActionIn: &action
tableIn: &table]; tableIn: &table];
if (found) if (found)
{ {
if (action != nil) if (action != nil)
{ {
/* First reset our internal state - we are done /* First reset our internal state - we are done
interpreting this keystroke sequence. */ interpreting this keystroke sequence. */
[self resetInternalState]; [self resetInternalState];
/* Then perform the action. The action might actually /* Then perform the action. The action might actually
modify our internal state, which is why we reset it modify our internal state, which is why we reset it
before calling the action! (for example, performing before calling the action! (for example, performing
the action might cause us to interpret the next the action might cause us to interpret the next
keystroke literally). */ keystroke literally). */
[action performActionWithInputManager: self]; [action performActionWithInputManager: self];
break; break;
} }
else if (table != nil) else if (table != nil)
{ {
/* It's part of a composite multi-stroke /* It's part of a composite multi-stroke
keybinding. */ keybinding. */
_currentBindingTable = table; _currentBindingTable = table;
[_pendingKeyEvents addObject: theEvent]; [_pendingKeyEvents addObject: theEvent];
break; break;
} }
/* Else it is as if we didn't find it! */ /* Else it is as if we didn't find it! */
} }
/* Ok - the keybinding wasn't found. If we were tracking a /* Ok - the keybinding wasn't found. If we were tracking a
multi-stroke keybinding, it means we were on a false multi-stroke keybinding, it means we were on a false
track. */ track. */
if ([_pendingKeyEvents count] > 0) if ([_pendingKeyEvents count] > 0)
{ {
NSEvent *e; NSEvent *e;
/* Save the pending events locally in this stack /* Save the pending events locally in this stack
frame. */ frame. */
NSMutableArray *a = _pendingKeyEvents; NSMutableArray *a = _pendingKeyEvents;
RETAIN (a); RETAIN (a);
/* Reset our internal state. */ /* Reset our internal state. */
[self resetInternalState]; [self resetInternalState];
/* Take the very first event we received and which we /* Take the very first event we received and which we
tried to interpret as a key binding, which now we tried to interpret as a key binding, which now we
know was the wrong thing to do. */ know was the wrong thing to do. */
e = [a objectAtIndex: 0]; e = [a objectAtIndex: 0];
/* Interpret it literally, since interpreting it as a /* Interpret it literally, since interpreting it as a
keybinding failed. */ keybinding failed. */
_interpretNextKeyStrokeLiterally = YES; _interpretNextKeyStrokeLiterally = YES;
[self handleKeyboardEvents: [NSArray arrayWithObject: e] [self handleKeyboardEvents: [NSArray arrayWithObject: e]
client: client]; client: client];
/* Now feed the remaining pending key events to /* Now feed the remaining pending key events to
ourselves for interpretation - again from ourselves for interpretation - again from
scratch. */ scratch. */
[a removeObjectAtIndex: 0]; [a removeObjectAtIndex: 0];
[a addObject: theEvent]; [a addObject: theEvent];
[self handleKeyboardEvents: a [self handleKeyboardEvents: a
client: client]; client: client];
RELEASE (a); RELEASE (a);
break; break;
} }
} }
/* We couldn't (or shouldn't) find the keybinding ... perform /* We couldn't (or shouldn't) find the keybinding ... perform
the default action - literally interpreting the the default action - literally interpreting the
keystroke. */ keystroke. */
/* If this was a forced literal interpretation, make sure the /* If this was a forced literal interpretation, make sure the
next one is interpreted normally. */ next one is interpreted normally. */
_interpretNextKeyStrokeLiterally = NO; _interpretNextKeyStrokeLiterally = NO;
/* During literal interpretation, function keys are ignored. /* During literal interpretation, function keys are ignored.
Trying to insert 'PageUp' literally makes simply no sense. */ Trying to insert 'PageUp' literally makes simply no sense. */
if (isFunctionKey) if (isFunctionKey)
{ {
NSBeep (); NSBeep ();
break; break;
} }
/* During literal interpretation, control characters are ignored /* During literal interpretation, control characters are ignored
if GSInsertControlKeystrokes was NO. */ if GSInsertControlKeystrokes was NO. */
if (_insertControlKeystrokes == NO) if (_insertControlKeystrokes == NO)
{ {
if (flags & NSControlKeyMask) if (flags & NSControlKeyMask)
{ {
NSBeep (); NSBeep ();
break; break;
} }
} }
switch (character) switch (character)
{ {
case NSBackspaceCharacter: case NSBackspaceCharacter:
[self doCommandBySelector: @selector (deleteBackward:)]; [self doCommandBySelector: @selector (deleteBackward:)];
break; break;
case NSTabCharacter: case NSTabCharacter:
if (flags & NSShiftKeyMask) if (flags & NSShiftKeyMask)
{ {
[self doCommandBySelector: @selector (insertBacktab:)]; [self doCommandBySelector: @selector (insertBacktab:)];
} }
else else
{ {
[self doCommandBySelector: @selector (insertTab:)]; [self doCommandBySelector: @selector (insertTab:)];
} }
break; break;
case NSEnterCharacter: case NSEnterCharacter:
case NSFormFeedCharacter: case NSFormFeedCharacter:
case NSCarriageReturnCharacter: case NSCarriageReturnCharacter:
[self doCommandBySelector: @selector (insertNewline:)]; [self doCommandBySelector: @selector (insertNewline:)];
break; break;
case NSHelpFunctionKey: case NSHelpFunctionKey:
[NSHelpManager setContextHelpModeActive: YES]; [NSHelpManager setContextHelpModeActive: YES];
break; break;
default: default:
[self insertText: characters]; [self insertText: characters];
break; break;
} }
} }
} }
@ -708,7 +709,7 @@ static NSInputManager *currentInputManager = nil;
{} {}
- (void) markedTextSelectionChanged: (NSRange)newSel - (void) markedTextSelectionChanged: (NSRange)newSel
client: (id)client client: (id)client
{} {}
- (BOOL) wantsToDelayTextChangeNotifications - (BOOL) wantsToDelayTextChangeNotifications
@ -727,7 +728,7 @@ static NSInputManager *currentInputManager = nil;
} }
- (void) setMarkedText: (id)aString - (void) setMarkedText: (id)aString
selectedRange: (NSRange)selRange selectedRange: (NSRange)selRange
{} {}
- (BOOL) hasMarkedText - (BOOL) hasMarkedText