X-Git-Url: http://git.ithinksw.org/ITKit.git/blobdiff_plain/d9649564199a7220e70716aa0999c6fddb0efadc..f43112aa0d5738cf9f2f8b8fa0fc63627871a69c:/ITKeyBroadcaster.m?ds=inline diff --git a/ITKeyBroadcaster.m b/ITKeyBroadcaster.m old mode 100755 new mode 100644 index b09ea9a..4411022 --- a/ITKeyBroadcaster.m +++ b/ITKeyBroadcaster.m @@ -1,73 +1,58 @@ -// -// ITKeyBroadcaster.m -// -// Created by Quentin Carnicelli on Sun Aug 03 2003. -// Copyright (c) 2003 iThink Software. All rights reserved. -// - #import "ITKeyBroadcaster.h" #import "ITKeyCombo.h" #import -NSString* ITKeyBroadcasterKeyEvent = @"ITKeyBroadcasterKeyEvent"; +NSString *ITKeyBroadcasterKeyEvent = @"ITKeyBroadcasterKeyEvent"; @implementation ITKeyBroadcaster -- (void)_bcastKeyCode: (short)keyCode modifiers: (long)modifiers -{ - ITKeyCombo* keyCombo = [ITKeyCombo keyComboWithKeyCode: keyCode modifiers: modifiers]; - NSDictionary* userInfo = [NSDictionary dictionaryWithObject: keyCombo forKey:@"keyCombo"]; - - [[NSNotificationCenter defaultCenter] - postNotificationName: ITKeyBroadcasterKeyEvent - object: self - userInfo: userInfo]; +- (void)_bcastKeyCode:(short)keyCode modifiers:(long)modifiers { + ITKeyCombo *keyCombo = [ITKeyCombo keyComboWithKeyCode:keyCode modifiers:modifiers]; + NSDictionary *userInfo = [NSDictionary dictionaryWithObject:keyCombo forKey:@"keyCombo"]; + + [[NSNotificationCenter defaultCenter] postNotificationName:ITKeyBroadcasterKeyEvent object:self userInfo:userInfo]; } -- (void)_bcastEvent: (NSEvent*)event -{ +- (void)_bcastEvent:(NSEvent *)event { short keyCode; long modifiers; keyCode = [event keyCode]; modifiers = [event modifierFlags]; - modifiers = [[self class] cocoaModifiersAsCarbonModifiers: modifiers]; - - [self _bcastKeyCode: keyCode modifiers: modifiers]; + modifiers = [[self class] cocoaModifiersAsCarbonModifiers:modifiers]; + + [self _bcastKeyCode:keyCode modifiers:modifiers]; } -- (void)keyDown: (NSEvent*)event -{ - [self _bcastEvent: event]; +- (void)keyDown:(NSEvent *)event { + [self _bcastEvent:event]; } -- (BOOL)performKeyEquivalent: (NSEvent*)event -{ - [self _bcastEvent: event]; +- (BOOL)performKeyEquivalent:(NSEvent *)event { + [self _bcastEvent:event]; return YES; } -+ (long)cocoaModifiersAsCarbonModifiers: (long)cocoaModifiers -{ - static long cocoaToCarbon[6][2] = - { - { NSCommandKeyMask, cmdKey}, - { NSAlternateKeyMask, optionKey}, - { NSControlKeyMask, controlKey}, - { NSShiftKeyMask, shiftKey}, - { NSFunctionKeyMask, rightControlKey}, ++ (long)cocoaModifiersAsCarbonModifiers:(long)cocoaModifiers { + static long cocoaToCarbon[6][2] = { + { NSCommandKeyMask, cmdKey }, + { NSAlternateKeyMask, optionKey }, + { NSControlKeyMask, controlKey }, + { NSShiftKeyMask, shiftKey }, + { NSFunctionKeyMask, rightControlKey }, //{ NSAlphaShiftKeyMask, alphaLock }, //Ignore this? }; - + long carbonModifiers = 0; int i; - for( i = 0 ; i < 6; i++ ) - if( cocoaModifiers & cocoaToCarbon[i][0] ) + for (i = 0;i < 6;i++) { + if (cocoaModifiers & cocoaToCarbon[i][0]) { carbonModifiers += cocoaToCarbon[i][1]; + } + } return carbonModifiers; } - -@end +@end \ No newline at end of file