1/* 2 Project: LaternaMagica 3 LMFlipView.m 4 5 Copyright (C) 2006-2013 Riccardo Mottola 6 7 Author: Riccardo Mottola 8 9 Created: 2006-06-11 10 11 This application is free software; you can redistribute it and/or 12 modify it under the terms of the GNU General Public 13 License as published by the Free Software Foundation; either 14 version 2 of the License, or (at your option) any later version. 15 16 This application is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 Library General Public License for more details. 20 21 You should have received a copy of the GNU General Public 22 License along with this library; if not, write to the Free 23 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24*/ 25 26#import "LMFlipView.h" 27#import "AppController.h" 28 29/* we define our own constants */ 30enum 31{ 32 NSEscapeCharacter = 0x001b, 33 NSSpaceCharacter = 0x0020 34}; 35 36@implementation LMFlipView 37 38- (BOOL)isFlipped 39{ 40 return YES; 41} 42 43- (void)setController:(AppController *)aController 44{ 45 controller = aController; 46} 47 48/* ---- Key event methods ---- */ 49 50/** respond to key equivalents which are not bound to menu items */ 51-(BOOL)performKeyEquivalent: (NSEvent*)theEvent 52{ 53 NSString *keyStr; 54 unichar keyCh; 55 unsigned int modifierFlags; 56 57#ifdef __APPLE__ 58/* Apple is definitively broken here and on all versions tested it returns for the arrow key 59 also a KeyUp event, which it should not, as the Event is specified to be keyDown */ 60 if ([theEvent type] == NSKeyUp) 61 return [super performKeyEquivalent:theEvent]; 62#endif 63 64 keyCh = 0x0; 65 keyStr = [theEvent characters]; 66 if ([keyStr length] > 0) 67 keyCh = [keyStr characterAtIndex:0]; 68 modifierFlags = [theEvent modifierFlags]; 69 70 if (keyCh == NSEscapeCharacter) 71 { 72 [controller setFullScreen:theEvent]; 73 return YES; 74 } 75 else if (keyCh == NSLeftArrowFunctionKey || keyCh == NSUpArrowFunctionKey) 76 { 77 [controller prevImage:theEvent]; 78 return YES; 79 } 80 else if (keyCh == NSRightArrowFunctionKey || keyCh == NSDownArrowFunctionKey || keyCh == NSSpaceCharacter) 81 { 82 [controller nextImage:theEvent]; 83 return YES; 84 } 85 else if (keyCh == NSDeleteFunctionKey || keyCh == NSDeleteCharacter) 86 { 87 if (modifierFlags & NSShiftKeyMask) 88 [controller removeImage:theEvent]; 89 else 90 [controller eraseImage:theEvent]; 91 return YES; 92 } 93 else if (keyCh == 0x72) 94 { 95 // "r" to rotate clockwise 96 [controller rotateImage270:nil]; 97 return YES; 98 } 99 else if (keyCh == 0x6c) 100 { 101 // "l" to rotate counterclockwise 102 [controller rotateImage90:nil]; 103 return YES; 104 } 105 else 106 NSLog(@"keyCh %x", keyCh); 107 return [super performKeyEquivalent:theEvent]; 108} 109 110@end 111