Change KeyInputTextView from a TextView to a TextField. Simplifies the nib contents...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 27 Feb 2013 01:20:33 +0000 (02:20 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 27 Feb 2013 01:20:33 +0000 (02:20 +0100)
English.lproj/MainMenu.xib
KeyInputTextView.h
KeyInputTextView.m
TargetController.m

index a4efa46d010c02ec57b5357910c9531fb03fab9c..7ba11779b37fe5fe45a3f427cf541301cb36c18f 100644 (file)
@@ -32,7 +32,6 @@
                        <string>NSTableView</string>
                        <string>NSTextField</string>
                        <string>NSTextFieldCell</string>
-                       <string>NSTextView</string>
                        <string>NSToolbar</string>
                        <string>NSToolbarFlexibleSpaceItem</string>
                        <string>NSToolbarItem</string>
                                                                                        <string key="NSFrame">{{20, 16}, {201, 236}}</string>
                                                                                        <reference key="NSSuperview" ref="606740242"/>
                                                                                        <reference key="NSWindow"/>
-                                                                                       <reference key="NSNextKeyView" ref="719496628"/>
+                                                                                       <reference key="NSNextKeyView"/>
                                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                        <int key="NSNumRows">7</int>
                                                                                        <int key="NSNumCols">1</int>
@@ -1077,126 +1076,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                                                                        <reference key="NSCellBackgroundColor" ref="214000480"/>
                                                                                        <reference key="NSFont" ref="45863614"/>
                                                                                </object>
-                                                                               <object class="NSScrollView" id="719496628">
-                                                                                       <reference key="NSNextResponder" ref="606740242"/>
-                                                                                       <int key="NSvFlags">8460</int>
-                                                                                       <array class="NSMutableArray" key="NSSubviews">
-                                                                                               <object class="NSClipView" id="912477807">
-                                                                                                       <reference key="NSNextResponder" ref="719496628"/>
-                                                                                                       <int key="NSvFlags">2304</int>
-                                                                                                       <array class="NSMutableArray" key="NSSubviews">
-                                                                                                               <object class="NSTextView" id="945527731">
-                                                                                                                       <reference key="NSNextResponder" ref="912477807"/>
-                                                                                                                       <int key="NSvFlags">2322</int>
-                                                                                                                       <string key="NSFrameSize">{172, 20}</string>
-                                                                                                                       <reference key="NSSuperview" ref="912477807"/>
-                                                                                                                       <reference key="NSWindow"/>
-                                                                                                                       <reference key="NSNextKeyView" ref="194275224"/>
-                                                                                                                       <object class="NSTextContainer" key="NSTextContainer" id="964782117">
-                                                                                                                               <object class="NSLayoutManager" key="NSLayoutManager">
-                                                                                                                                       <object class="NSTextStorage" key="NSTextStorage">
-                                                                                                                                               <object class="NSMutableString" key="NSString">
-                                                                                                                                                       <characters key="NS.bytes"/>
-                                                                                                                                               </object>
-                                                                                                                                               <nil key="NSDelegate"/>
-                                                                                                                                       </object>
-                                                                                                                                       <array class="NSMutableArray" key="NSTextContainers">
-                                                                                                                                               <reference ref="964782117"/>
-                                                                                                                                       </array>
-                                                                                                                                       <int key="NSLMFlags">38</int>
-                                                                                                                                       <nil key="NSDelegate"/>
-                                                                                                                               </object>
-                                                                                                                               <reference key="NSTextView" ref="945527731"/>
-                                                                                                                               <double key="NSWidth">172</double>
-                                                                                                                               <int key="NSTCFlags">1</int>
-                                                                                                                       </object>
-                                                                                                                       <object class="NSTextViewSharedData" key="NSSharedData">
-                                                                                                                               <int key="NSFlags">2320</int>
-                                                                                                                               <int key="NSTextCheckingTypes">0</int>
-                                                                                                                               <nil key="NSMarkedAttributes"/>
-                                                                                                                               <reference key="NSBackgroundColor" ref="214000480"/>
-                                                                                                                               <dictionary key="NSSelectedAttributes">
-                                                                                                                                       <object class="NSColor" key="NSBackgroundColor">
-                                                                                                                                               <int key="NSColorSpace">6</int>
-                                                                                                                                               <string key="NSCatalogName">System</string>
-                                                                                                                                               <string key="NSColorName">selectedTextBackgroundColor</string>
-                                                                                                                                               <reference key="NSColor" ref="783809746"/>
-                                                                                                                                       </object>
-                                                                                                                                       <object class="NSColor" key="NSColor">
-                                                                                                                                               <int key="NSColorSpace">6</int>
-                                                                                                                                               <string key="NSCatalogName">System</string>
-                                                                                                                                               <string key="NSColorName">selectedTextColor</string>
-                                                                                                                                               <reference key="NSColor" ref="838935852"/>
-                                                                                                                                       </object>
-                                                                                                                               </dictionary>
-                                                                                                                               <reference key="NSInsertionColor" ref="838935852"/>
-                                                                                                                               <dictionary key="NSLinkAttributes">
-                                                                                                                                       <object class="NSColor" key="NSColor">
-                                                                                                                                               <int key="NSColorSpace">1</int>
-                                                                                                                                               <bytes key="NSRGB">MCAwIDEAA</bytes>
-                                                                                                                                       </object>
-                                                                                                                                       <integer value="1" key="NSUnderline"/>
-                                                                                                                               </dictionary>
-                                                                                                                               <nil key="NSDefaultParagraphStyle"/>
-                                                                                                                               <nil key="NSTextFinder"/>
-                                                                                                                               <int key="NSPreferredTextFinderStyle">0</int>
-                                                                                                                       </object>
-                                                                                                                       <int key="NSTVFlags">6</int>
-                                                                                                                       <string key="NSMaxSize">{463, 10000000}</string>
-                                                                                                                       <nil key="NSDelegate"/>
-                                                                                                               </object>
-                                                                                                       </array>
-                                                                                                       <string key="NSFrame">{{2, 2}, {172, 20}}</string>
-                                                                                                       <reference key="NSSuperview" ref="719496628"/>
-                                                                                                       <reference key="NSWindow"/>
-                                                                                                       <reference key="NSNextKeyView" ref="945527731"/>
-                                                                                                       <reference key="NSDocView" ref="945527731"/>
-                                                                                                       <reference key="NSBGColor" ref="214000480"/>
-                                                                                                       <object class="NSCursor" key="NSCursor">
-                                                                                                               <string key="NSHotSpot">{1, -1}</string>
-                                                                                                               <int key="NSCursorType">0</int>
-                                                                                                       </object>
-                                                                                                       <int key="NScvFlags">4</int>
-                                                                                               </object>
-                                                                                               <object class="NSScroller" id="605541128">
-                                                                                                       <reference key="NSNextResponder" ref="719496628"/>
-                                                                                                       <int key="NSvFlags">-2147483392</int>
-                                                                                                       <string key="NSFrame">{{-100, -100}, {15, 133}}</string>
-                                                                                                       <reference key="NSSuperview" ref="719496628"/>
-                                                                                                       <reference key="NSWindow"/>
-                                                                                                       <reference key="NSNextKeyView" ref="725849905"/>
-                                                                                                       <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
-                                                                                                       <reference key="NSTarget" ref="719496628"/>
-                                                                                                       <string key="NSAction">_doScroller:</string>
-                                                                                                       <double key="NSPercent">0.73888889999999996</double>
-                                                                                               </object>
-                                                                                               <object class="NSScroller" id="725849905">
-                                                                                                       <reference key="NSNextResponder" ref="719496628"/>
-                                                                                                       <int key="NSvFlags">-2147483392</int>
-                                                                                                       <string key="NSFrame">{{-100, -100}, {87, 18}}</string>
-                                                                                                       <reference key="NSSuperview" ref="719496628"/>
-                                                                                                       <reference key="NSWindow"/>
-                                                                                                       <reference key="NSNextKeyView" ref="912477807"/>
-                                                                                                       <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
-                                                                                                       <int key="NSsFlags">1</int>
-                                                                                                       <reference key="NSTarget" ref="719496628"/>
-                                                                                                       <string key="NSAction">_doScroller:</string>
-                                                                                                       <double key="NSCurValue">1</double>
-                                                                                                       <double key="NSPercent">0.94565220000000005</double>
-                                                                                               </object>
-                                                                                       </array>
-                                                                                       <string key="NSFrame">{{229, 191}, {176, 24}}</string>
-                                                                                       <reference key="NSSuperview" ref="606740242"/>
-                                                                                       <reference key="NSWindow"/>
-                                                                                       <reference key="NSNextKeyView" ref="605541128"/>
-                                                                                       <int key="NSsFlags">133123</int>
-                                                                                       <reference key="NSVScroller" ref="605541128"/>
-                                                                                       <reference key="NSHScroller" ref="725849905"/>
-                                                                                       <reference key="NSContentView" ref="912477807"/>
-                                                                                       <double key="NSMinMagnification">0.25</double>
-                                                                                       <double key="NSMaxMagnification">4</double>
-                                                                                       <double key="NSMagnification">1</double>
-                                                                               </object>
                                                                                <object class="NSPopUpButton" id="194275224">
                                                                                        <reference key="NSNextResponder" ref="606740242"/>
                                                                                        <int key="NSvFlags">268</int>
@@ -1283,6 +1162,15 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                                                                        <int key="NSTitlePosition">0</int>
                                                                                        <bool key="NSTransparent">NO</bool>
                                                                                </object>
+                                                                               <object class="NSCustomView" id="57697638">
+                                                                                       <reference key="NSNextResponder" ref="606740242"/>
+                                                                                       <int key="NSvFlags">265</int>
+                                                                                       <string key="NSFrame">{{229, 190}, {176, 24}}</string>
+                                                                                       <reference key="NSSuperview" ref="606740242"/>
+                                                                                       <reference key="NSWindow"/>
+                                                                                       <string key="NSReuseIdentifierKey">_NS:9</string>
+                                                                                       <string key="NSClassName">KeyInputTextView</string>
+                                                                               </object>
                                                                        </array>
                                                                        <string key="NSFrame">{{211, 0}, {429, 300}}</string>
                                                                        <reference key="NSSuperview" ref="206489479"/>
@@ -1503,6 +1391,29 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                        <object class="NSCustomObject" id="801536542">
                                <string key="NSClassName">TargetController</string>
                        </object>
+                       <object class="NSButton" id="735675040">
+                               <reference key="NSNextResponder"/>
+                               <int key="NSvFlags">268</int>
+                               <string key="NSFrameSize">{82, 32}</string>
+                               <reference key="NSSuperview"/>
+                               <string key="NSReuseIdentifierKey">_NS:9</string>
+                               <bool key="NSEnabled">YES</bool>
+                               <object class="NSButtonCell" key="NSCell" id="835359972">
+                                       <int key="NSCellFlags">67108864</int>
+                                       <int key="NSCellFlags2">134217728</int>
+                                       <string key="NSContents">Button</string>
+                                       <reference key="NSSupport" ref="45863614"/>
+                                       <string key="NSCellIdentifier">_NS:9</string>
+                                       <reference key="NSControlView" ref="735675040"/>
+                                       <int key="NSButtonFlags">-2038284288</int>
+                                       <int key="NSButtonFlags2">129</int>
+                                       <string key="NSAlternateContents"/>
+                                       <string key="NSKeyEquivalent"/>
+                                       <int key="NSPeriodicDelay">200</int>
+                                       <int key="NSPeriodicInterval">25</int>
+                               </object>
+                               <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+                       </object>
                </array>
                <object class="IBObjectContainer" key="IBDocument.Objects">
                        <array class="NSMutableArray" key="connectionRecords">
@@ -1786,30 +1697,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                        </object>
                                        <int key="connectionID">696</int>
                                </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" key="connection">
-                                               <string key="label">window</string>
-                                               <reference key="source" ref="945527731"/>
-                                               <reference key="destination" ref="808667431"/>
-                                       </object>
-                                       <int key="connectionID">684</int>
-                               </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" key="connection">
-                                               <string key="label">targetController</string>
-                                               <reference key="source" ref="945527731"/>
-                                               <reference key="destination" ref="801536542"/>
-                                       </object>
-                                       <int key="connectionID">688</int>
-                               </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" key="connection">
-                                               <string key="label">keyInput</string>
-                                               <reference key="source" ref="801536542"/>
-                                               <reference key="destination" ref="945527731"/>
-                                       </object>
-                                       <int key="connectionID">689</int>
-                               </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
                                                <string key="label">radioKey</string>
@@ -1938,6 +1825,30 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                        </object>
                                        <int key="connectionID">757</int>
                                </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBOutletConnection" key="connection">
+                                               <string key="label">keyInput</string>
+                                               <reference key="source" ref="801536542"/>
+                                               <reference key="destination" ref="57697638"/>
+                                       </object>
+                                       <int key="connectionID">781</int>
+                               </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBOutletConnection" key="connection">
+                                               <string key="label">targetController</string>
+                                               <reference key="source" ref="57697638"/>
+                                               <reference key="destination" ref="801536542"/>
+                                       </object>
+                                       <int key="connectionID">779</int>
+                               </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBOutletConnection" key="connection">
+                                               <string key="label">window</string>
+                                               <reference key="source" ref="57697638"/>
+                                               <reference key="destination" ref="808667431"/>
+                                       </object>
+                                       <int key="connectionID">780</int>
+                               </object>
                        </array>
                        <object class="IBMutableOrderedSet" key="objectRecords">
                                <array key="orderedObjects">
@@ -2343,8 +2254,8 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                                        <reference ref="125828224"/>
                                                        <reference ref="875916470"/>
                                                        <reference ref="194275224"/>
-                                                       <reference ref="719496628"/>
                                                        <reference ref="1016088174"/>
+                                                       <reference ref="57697638"/>
                                                </array>
                                                <reference key="parent" ref="206489479"/>
                                        </object>
@@ -2353,31 +2264,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                                <reference key="object" ref="801536542"/>
                                                <reference key="parent" ref="0"/>
                                        </object>
-                                       <object class="IBObjectRecord">
-                                               <int key="objectID">680</int>
-                                               <reference key="object" ref="719496628"/>
-                                               <array class="NSMutableArray" key="children">
-                                                       <reference ref="605541128"/>
-                                                       <reference ref="725849905"/>
-                                                       <reference ref="945527731"/>
-                                               </array>
-                                               <reference key="parent" ref="606740242"/>
-                                       </object>
-                                       <object class="IBObjectRecord">
-                                               <int key="objectID">681</int>
-                                               <reference key="object" ref="605541128"/>
-                                               <reference key="parent" ref="719496628"/>
-                                       </object>
-                                       <object class="IBObjectRecord">
-                                               <int key="objectID">682</int>
-                                               <reference key="object" ref="725849905"/>
-                                               <reference key="parent" ref="719496628"/>
-                                       </object>
-                                       <object class="IBObjectRecord">
-                                               <int key="objectID">683</int>
-                                               <reference key="object" ref="945527731"/>
-                                               <reference key="parent" ref="719496628"/>
-                                       </object>
                                        <object class="IBObjectRecord">
                                                <int key="objectID">656</int>
                                                <reference key="object" ref="120408205"/>
@@ -2517,6 +2403,24 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                                <reference key="object" ref="241270212"/>
                                                <reference key="parent" ref="875916470"/>
                                        </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">765</int>
+                                               <reference key="object" ref="735675040"/>
+                                               <array class="NSMutableArray" key="children">
+                                                       <reference ref="835359972"/>
+                                               </array>
+                                               <reference key="parent" ref="0"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">766</int>
+                                               <reference key="object" ref="835359972"/>
+                                               <reference key="parent" ref="735675040"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">778</int>
+                                               <reference key="object" ref="57697638"/>
+                                               <reference key="parent" ref="606740242"/>
+                                       </object>
                                </array>
                        </object>
                        <dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -2583,11 +2487,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                <string key="657.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="658.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="659.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <string key="680.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <string key="681.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <string key="682.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <string key="683.CustomClassName">KeyInputTextView</string>
-                               <string key="683.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="686.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="699.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="700.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2610,6 +2509,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                                <string key="754.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <integer value="1" key="755.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                <string key="755.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+                               <string key="765.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+                               <string key="766.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+                               <string key="778.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="81.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="83.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="92.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2618,7 +2520,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
                        <nil key="activeLocalization"/>
                        <dictionary class="NSMutableDictionary" key="localizations"/>
                        <nil key="sourceID"/>
-                       <int key="maxID">764</int>
+                       <int key="maxID">781</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <array class="NSMutableArray" key="referencedPartialClassDescriptions">
index e327c7851ba19602595f21af851932bcbd7627e3..9927385ed13c90542598fc6708ab2c0193f77627 100644 (file)
@@ -1,5 +1,5 @@
 //
-//  KeyInputTextField.h
+//  KeyInputTextView.h
 //  Enjoy
 //
 //  Created by Sam McCall on 5/05/09.
@@ -7,22 +7,17 @@
 //
 
 #import <Cocoa/Cocoa.h>
-@class TargetController;
 
-@interface KeyInputTextView: NSTextView {
-       IBOutlet NSWindow* window;
-       IBOutlet TargetController* targetController;
-       BOOL hasKey;
-       int vk;
-       NSString* descr;
-       BOOL enabled;
+@interface KeyInputTextView : NSTextField {
+       IBOutlet NSWindow *window;
+       IBOutlet TargetController *targetController;
 }
 
-@property(readonly) BOOL hasKey;
-@property(readwrite) int vk;
-@property(copy) NSString* descr;
-@property(readwrite) BOOL enabled;
+@property (copy) NSString* descr;
+@property (assign) int vk;
+@property (readonly) BOOL hasKey;
+@property (assign) BOOL enabled;
 
--(void) clear;
+- (void)clear;
 
 @end
index 9b6bc37c4d56f252cd117841371f6535e2e212f0..288d903fa156bde99ff12c9c1f1c830e4c746cee 100644 (file)
 //
-//  KeyInputTextField.m
+//  KeyInputTextView.m
 //  Enjoy
 //
 //  Created by Sam McCall on 5/05/09.
 //
 
-@implementation KeyInputTextView
+#import "KeyInputTextView.h"
 
-@synthesize descr, hasKey;
+@implementation KeyInputTextView {
+    int vk;
+    BOOL enabled;
+}
+
+@synthesize descr;
 
--(id) init {
-       if(self = [super init]) {
-               setEnabled: NO;
-       }
-       return self;
+- (id)initWithFrame:(NSRect)frameRect {
+    if ((self = [super initWithFrame:frameRect])) {
+        self.alignment = NSCenterTextAlignment;
+        [self setEditable:NO];
+        [self setSelectable:NO];
+    }
+    return self;
 }
 
--(void) clear {
-       [self setString: [NSString string]];
-       vk = -1;
-       hasKey = NO;
-       descr = NULL;
+- (void)clear {
+    self.vk = -1;
 }
 
--(NSString*) stringForKeyCode: (int) keycode {
-       switch(keycode) {
-               case 0x7a :     return @"F1";
-               case 0x78 :     return @"F2";
-               case 0x63 :     return @"F3";
-               case 0x76 :     return @"F4";
-               case 0x60 :     return @"F5";
-               case 0x61 :     return @"F6";
-               case 0x62 :     return @"F7";
-               case 0x64 :     return @"F8";
-               case 0x65 :     return @"F9";
-               case 0x6d :     return @"F10";
-               case 0x67 :     return @"F11";
-               case 0x6f :     return @"F12";
-               case 0x69 :     return @"F13";
-               case 0x6b :     return @"F14";
-               case 0x71 :     return @"F15";
-               case 0x6a :     return @"F16";
-               case 0x40 :     return @"F17";
-               case 0x4f :     return @"F18";
-               case 0x50 :     return @"F19";
-
-               case 0x35 :     return @"Esc";
-               case 0x32 : return @"`";
-                       
-               case 0x12 : return @"1";
-               case 0x13 : return @"2";
-               case 0x14 : return @"3";
-               case 0x15 : return @"4";
-               case 0x17 : return @"5";
-               case 0x16 : return @"6";
-               case 0x1a : return @"7";
-               case 0x1c : return @"8";
-               case 0x19 : return @"9";
-               case 0x1d : return @"0";
-               case 0x1b : return @"-";
-               case 0x18 : return @"=";
-                       
-               case 0x3f : return @"Fn";
-               case 0x39 : return @"Caps Lock";
-               case 0x38 : return @"Left Shift";
-               case 0x3b : return @"Left Control";
-               case 0x3a : return @"Left Option";
-               case 0x37 : return @"Left Command";
-               case 0x36 : return @"Right Command";
-               case 0x3d : return @"Right Option";
-               case 0x3e : return @"Right Control";
-               case 0x3c : return @"Right Shift";
-                       
-               case 0x73 : return @"Home";
-               case 0x74 : return @"Page Up";
-               case 0x75 : return @"Delete";
-               case 0x77 : return @"End";
-               case 0x79 : return @"Page Down";
-                       
-               case 0x30 : return @"Tab";
-               case 0x33 : return @"Backspace";
-               case 0x24 : return @"Return";
-               case 0x31 : return @"Space";
-                       
-               case 0x0c : return @"Q";
-               case 0x0d : return @"W";
-               case 0x0e : return @"E";
-               case 0x0f : return @"R";
-               case 0x11 : return @"T";
-               case 0x10 : return @"Y";
-               case 0x20 : return @"U";
-               case 0x22 : return @"I";
-               case 0x1f : return @"O";
-               case 0x23 : return @"P";
-               case 0x21 : return @"[";
-               case 0x1e : return @"]";
-               case 0x2a : return @"\\";
-               case 0x00 : return @"A";
-               case 0x01 : return @"S";
-               case 0x02 : return @"D";
-               case 0x03 : return @"F";
-               case 0x05 : return @"G";
-               case 0x04 : return @"H";
-               case 0x26 : return @"J";
-               case 0x28 : return @"K";
-               case 0x25 : return @"L";
-               case 0x29 : return @";";
-               case 0x27 : return @"'";
-               case 0x06 : return @"Z";
-               case 0x07 : return @"X";
-               case 0x08 : return @"C";
-               case 0x09 : return @"V";
-               case 0x0b : return @"B";
-               case 0x2d : return @"N";
-               case 0x2e : return @"M";
-               case 0x2b : return @",";
-               case 0x2f : return @".";
-               case 0x2c : return @"/";
-                       
-               case 0x47 : return @"Clear";
-               case 0x51 : return @"Keypad =";
-               case 0x4b : return @"Keypad /";
-               case 0x43 : return @"Keypad *";
-               case 0x59 : return @"Keypad 7";
-               case 0x5b : return @"Keypad 8";
-               case 0x5c : return @"Keypad 9";
-               case 0x4e : return @"Keypad -";
-               case 0x56 : return @"Keypad 4";
-               case 0x57 : return @"Keypad 5";
-               case 0x58 : return @"Keypad 6";
-               case 0x45 : return @"Keypad +";
-               case 0x53 : return @"Keypad 1";
-               case 0x54 : return @"Keypad 2";
-               case 0x55 : return @"Keypad 3";
-               case 0x52 : return @"Keypad 0";
-               case 0x41 : return @"Keypad .";
-               case 0x4c : return @"Enter";
-                       
-               case 0x7e : return @"Up";
-               case 0x7d : return @"Down";
-               case 0x7b : return @"Left";
-               case 0x7c : return @"Right";
-       }
-       return [[NSString alloc] initWithFormat: @"Key 0x%x",keycode];
+- (BOOL)hasKey {
+    return self.vk >= 0;
 }
 
--(BOOL) acceptsFirstResponder {
-       return enabled;
+- (NSString *)stringForKeyCode:(int)keycode {
+    switch(keycode) {
+        case   -1: return @"";
+        case 0x7a: return @"F1";
+        case 0x78: return @"F2";
+        case 0x63: return @"F3";
+        case 0x76: return @"F4";
+        case 0x60: return @"F5";
+        case 0x61: return @"F6";
+        case 0x62: return @"F7";
+        case 0x64: return @"F8";
+        case 0x65: return @"F9";
+        case 0x6d: return @"F10";
+        case 0x67: return @"F11";
+        case 0x6f: return @"F12";
+        case 0x69: return @"F13";
+        case 0x6b: return @"F14";
+        case 0x71: return @"F15";
+        case 0x6a: return @"F16";
+        case 0x40: return @"F17";
+        case 0x4f: return @"F18";
+        case 0x50: return @"F19";
+            
+        case 0x35: return @"Esc";
+        case 0x32: return @"`";
+            
+        case 0x12: return @"1";
+        case 0x13: return @"2";
+        case 0x14: return @"3";
+        case 0x15: return @"4";
+        case 0x17: return @"5";
+        case 0x16: return @"6";
+        case 0x1a: return @"7";
+        case 0x1c: return @"8";
+        case 0x19: return @"9";
+        case 0x1d: return @"0";
+        case 0x1b: return @"-";
+        case 0x18: return @"=";
+            
+        case 0x3f: return @"Fn";
+        case 0x39: return @"Caps Lock";
+        case 0x38: return @"Left Shift";
+        case 0x3b: return @"Left Control";
+        case 0x3a: return @"Left Option";
+        case 0x37: return @"Left Command";
+        case 0x36: return @"Right Command";
+        case 0x3d: return @"Right Option";
+        case 0x3e: return @"Right Control";
+        case 0x3c: return @"Right Shift";
+            
+        case 0x73: return @"Home";
+        case 0x74: return @"Page Up";
+        case 0x75: return @"Delete";
+        case 0x77: return @"End";
+        case 0x79: return @"Page Down";
+            
+        case 0x30: return @"Tab";
+        case 0x33: return @"Backspace";
+        case 0x24: return @"Return";
+        case 0x31: return @"Space";
+            
+        case 0x0c: return @"Q";
+        case 0x0d: return @"W";
+        case 0x0e: return @"E";
+        case 0x0f: return @"R";
+        case 0x11: return @"T";
+        case 0x10: return @"Y";
+        case 0x20: return @"U";
+        case 0x22: return @"I";
+        case 0x1f: return @"O";
+        case 0x23: return @"P";
+        case 0x21: return @"[";
+        case 0x1e: return @"]";
+        case 0x2a: return @"\\";
+        case 0x00: return @"A";
+        case 0x01: return @"S";
+        case 0x02: return @"D";
+        case 0x03: return @"F";
+        case 0x05: return @"G";
+        case 0x04: return @"H";
+        case 0x26: return @"J";
+        case 0x28: return @"K";
+        case 0x25: return @"L";
+        case 0x29: return @";";
+        case 0x27: return @"'";
+        case 0x06: return @"Z";
+        case 0x07: return @"X";
+        case 0x08: return @"C";
+        case 0x09: return @"V";
+        case 0x0b: return @"B";
+        case 0x2d: return @"N";
+        case 0x2e: return @"M";
+        case 0x2b: return @",";
+        case 0x2f: return @".";
+        case 0x2c: return @"/";
+            
+        case 0x47: return @"Clear";
+        case 0x51: return @"Keypad =";
+        case 0x4b: return @"Keypad /";
+        case 0x43: return @"Keypad *";
+        case 0x59: return @"Keypad 7";
+        case 0x5b: return @"Keypad 8";
+        case 0x5c: return @"Keypad 9";
+        case 0x4e: return @"Keypad -";
+        case 0x56: return @"Keypad 4";
+        case 0x57: return @"Keypad 5";
+        case 0x58: return @"Keypad 6";
+        case 0x45: return @"Keypad +";
+        case 0x53: return @"Keypad 1";
+        case 0x54: return @"Keypad 2";
+        case 0x55: return @"Keypad 3";
+        case 0x52: return @"Keypad 0";
+        case 0x41: return @"Keypad .";
+        case 0x4c: return @"Enter";
+            
+        case 0x7e: return @"Up";
+        case 0x7d: return @"Down";
+        case 0x7b: return @"Left";
+        case 0x7c: return @"Right";
+    }
+    return [[NSString alloc] initWithFormat: @"Key 0x%x",keycode];
 }
 
--(BOOL) becomeFirstResponder {
-       [self setBackgroundColor: [NSColor selectedTextBackgroundColor]];
-       return YES;
+- (BOOL)acceptsFirstResponder {
+    return enabled;
 }
 
--(BOOL) resignFirstResponder {
-       [self setBackgroundColor: [NSColor textBackgroundColor]];
-       return YES;
+- (BOOL)becomeFirstResponder {
+    [self setBackgroundColor:[NSColor selectedTextBackgroundColor]];
+    return [super becomeFirstResponder];
 }
 
--(void) pressed:(int) keycode {
-       [self setVk: keycode];
-       [[self window] makeFirstResponder: nil];
-       [targetController keyChanged];
+- (BOOL)resignFirstResponder {
+    [self setBackgroundColor:[NSColor textBackgroundColor]];
+    return [super resignFirstResponder];
 }
 
--(void) setVk: (int) key {
-       vk=key;
-       hasKey = YES;
-       descr = [self stringForKeyCode: key];
-       [self setString: descr];
+- (void)setBackgroundColor:(NSColor *)color {
+    [super setBackgroundColor:color];
 }
--(int) vk {
-       return vk;
+
+- (void)setVk:(int)key {
+    vk = key;
+    descr = [self stringForKeyCode:key];
+    [self setStringValue:descr];
+    if (self.hasKey)
+        [targetController keyChanged];
+}
+
+- (int)vk {
+    return vk;
 }
 
 - (void)keyDown:(NSEvent *)evt {
-       if([evt isARepeat])
-               return;
-       [self pressed: [evt keyCode]];
+    if (!evt.isARepeat) {
+        self.vk = evt.keyCode;
+        [[self window] makeFirstResponder:nil];
+    }
 }
 
--(void) flagsChanged:(NSEvent*)evt {
-       // XXX sometimes it's key up
-       [self pressed: [evt keyCode]];
+- (void)flagsChanged:(NSEvent *)evt {
+    self.vk = evt.keyCode;
+    [[self window] makeFirstResponder:nil];
 }
 
--(void) setEnabled: (BOOL) newEnabled {
-       enabled = newEnabled;
-       if(!newEnabled && [window firstResponder] == self)
-               [window makeFirstResponder: NULL];
-       
-       
-       if(enabled) {
-               if([window firstResponder] == self)
-                       [self setBackgroundColor: [NSColor selectedTextBackgroundColor]];
-               else
-                       [self setBackgroundColor: [NSColor textBackgroundColor]];
-       } else {
-               [self setBackgroundColor: [NSColor textBackgroundColor]];
-       }       
+- (void)setEnabled:(BOOL)newEnabled {
+    enabled = newEnabled;
+
+    if (!enabled && window.firstResponder == self)
+        [window makeFirstResponder:nil];
 }
--(BOOL) enabled {
-       return enabled;
+
+- (BOOL)enabled {
+    return enabled;
 }
 
 
index 9f85fd989913d0ec25db1974fdbf8d4854eb5352..82eec039b08b9ad1a4715a60266e8bb1ec98e4d3 100644 (file)
@@ -37,7 +37,7 @@
                case 0: // none
                        return NULL;
                case 1: // key
-                       if([keyInput hasKey]) {
+                       if(keyInput.hasKey) {
                                TargetKeyboard* k = [[TargetKeyboard alloc] init];
                                [k setVk: [keyInput vk]];
                                [k setDescr: [keyInput descr]];