Drawing Text With Attributes(Chapter 20 of Cocoa Programming for Mac OS X)
1 #import "BigLetterView.h"2
3
4 @implementation BigLetterView
5
6 - (IBAction)savePDF:(id)sender
7 {
8 NSSavePanel *panel = ;
9 ;
10 modalDelegate:self didEndSelector:@selector(didEnd:returnCode:contextInfo:) contextInfo:NULL];
11 }
12
13 - (void)prepareAttributes
14 {
15 attributes = [ init];
16 forKey:NSFontAttributeName];
17 forKey:NSForegroundColorAttributeName];
18 }
19
20 - (void)didEnd:(NSSavePanel *)sheet returnCode:(int)code contextInfo:(void *)contextInfo
21 {
22 if(code != NSOKButton)
23 {
24 return;
25 }
26
27 NSRect r = ;
28 NSData *data = ;
29 NSString *path = ;
30 NSError *error;
31 BOOL successful = ;
32 if (!successful)
33 {
34 NSAlert *a = ;
35 ;
36 }
37 }
38
39 - (id)initWithFrame:(NSRect)frameRect
40 {
41 if(!)
42 {
43 return nil;
44 }
45
46 NSLog(@"initializing view");
47 ;
48 bgColor = [ retain];
49 string = @" ";
50 return self;
51 }
52
53 - (void)dealloc
54 {
55 ;
56 ;
57 ;
58 ;
59 }
60
61 - (void)drawRect:(NSRect)dirtyRect
62 {
63 NSRect bounds = ;
64 ;
65 ;
66 ;
67
68 if([ firstResponder] == self)
69 {
70 [ set];
71 ;
72 ;
73 }
74 }
75
76 - (BOOL)isOpaque
77 {
78 return YES;
79 }
80
81 - (BOOL)acceptsFirstResponder
82 {
83 NSLog(@"Accepting");
84 return YES;
85 }
86
87 - (BOOL)resignFirstResponder
88 {
89 NSLog(@"Resigning");
90 ;
91 return YES;
92 }
93
94 - (BOOL)becomeFirstResponder
95 {
96 NSLog(@"Becoming");
97 ;
98 return YES;
99 }
100
101 - (void)keyDown:(NSEvent *)theEvent
102 {
103 ];
104 }
105
106 - (void)insertText:(NSString *)input
107 {
108 ;
109 }
110
111 - (void)insertTab:(id)sender
112 {
113 [ selectKeyViewPrecedingView:self];
114 }
115
116 - (void)deleteBackward:(id)sender
117 {
118 ;
119 }
120
121 #pragma mark Accessors
122
123 - (void)setBgColor:(NSColor *)c
124 {
125 ;
126 ;
127 bgColor = c;
128 ;
129 }
130
131 - (NSColor *)bgColor
132 {
133 return bgColor;
134 }
135
136 - (void)drawStringCenteredIn:(NSRect)r
137 {
138 NSSize strSize = ;
139 NSPoint strOrigin;
140 strOrigin.x = r.origin.x + (r.size.width - strSize.width)/2;
141 strOrigin.y = r.origin.y + (r.size.height - strSize.height)/2;
142 ;
143 }
144
145 - (void)setString:(NSString *)c
146 {
147 c = ;
148 ;
149 string = c;
150 NSLog(@"The string is now %@", string);
151 ;
152 }
153
154 - (NSString *)string
155 {
156 return string;
157 }
158
159 @end
页:
[1]