Keyboard Events(Chapter 19 of Cocoa Programming for Mac OS X)
1 #import "BigLetterView.h"2
3
4 @implementation BigLetterView
5
6 - (id)initWithFrame:(NSRect)frameRect
7 {
8 if(!)
9 {
10 return nil;
11 }
12
13 NSLog(@"initializing view");
14 bgColor = [ retain];
15 string = @" ";
16 return self;
17 }
18
19 - (void)dealloc
20 {
21 ;
22 ;
23 ;
24 }
25
26 - (void)drawRect:(NSRect)dirtyRect
27 {
28 NSRect bounds = ;
29 ;
30 ;
31
32 if([ firstResponder] == self)
33 {
34 [ set];
35 ;
36 ;
37 }
38 }
39
40 - (BOOL)isOpaque
41 {
42 return YES;
43 }
44
45 - (BOOL)acceptsFirstResponder
46 {
47 NSLog(@"Accepting");
48 return YES;
49 }
50
51 - (BOOL)resignFirstResponder
52 {
53 NSLog(@"Resigning");
54 ;
55 return YES;
56 }
57
58 - (BOOL)becomeFirstResponder
59 {
60 NSLog(@"Becoming");
61 ;
62 return YES;
63 }
64
65 - (void)keyDown:(NSEvent *)theEvent
66 {
67 ];
68 }
69
70 - (void)insertText:(NSString *)input
71 {
72 ;
73 }
74
75 - (void)insertTab:(id)sender
76 {
77 [ selectKeyViewPrecedingView:self];
78 }
79
80 - (void)deleteBackward:(id)sender
81 {
82 ;
83 }
84
85 #pragma mark Accessors
86
87 - (void)setBgColor:(NSColor *)c
88 {
89 ;
90 ;
91 bgColor = c;
92 ;
93 }
94
95 - (NSColor *)bgColor
96 {
97 return bgColor;
98 }
99
100 - (void)setString:(NSString *)c
101 {
102 c = ;
103 ;
104 string = c;
105 NSLog(@"The string is now %@", string);
106 }
107
108 - (NSString *)string
109 {
110 return string;
111 }
112
113 @end
页:
[1]