My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /AppKit/NSMatrix.m
e5277a40a7e8 vs. 2470bd80abf4 Compare: vs.  Format:
Revision 2470bd80abf4
Go to: 
Project members, sign in to write a code review
/AppKit/NSMatrix.m   e5277a40a7e8 /AppKit/NSMatrix.m   2470bd80abf4
1 /* Copyright (c) 2006 Christopher J. W. Lloyd 1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
2 2
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 4
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 6
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8 8
9 // Keyboard movement - David Young <daver@geeks.org> 9 // Keyboard movement - David Young <daver@geeks.org>
10 // Original - Christopher Lloyd <cjwl@objc.net> 10 // Original - Christopher Lloyd <cjwl@objc.net>
11 #import <AppKit/NSMatrix.h> 11 #import <AppKit/NSMatrix.h>
12 #import <AppKit/NSCell.h> 12 #import <AppKit/NSCell.h>
13 #import <AppKit/NSFont.h> 13 #import <AppKit/NSFont.h>
14 #import <AppKit/NSApplication.h> 14 #import <AppKit/NSApplication.h>
15 #import <AppKit/NSEvent.h> 15 #import <AppKit/NSEvent.h>
16 #import <AppKit/NSColor.h> 16 #import <AppKit/NSColor.h>
17 #import <AppKit/NSGraphics.h> 17 #import <AppKit/NSGraphics.h>
18 #import <AppKit/NSWindow.h> 18 #import <AppKit/NSWindow.h>
19 #import <AppKit/NSNibKeyedUnarchiver.h> 19 #import <AppKit/NSNibKeyedUnarchiver.h>
20 20
21 @implementation NSMatrix 21 @implementation NSMatrix
22 22
23 -(void)encodeWithCoder:(NSCoder *)coder { 23 -(void)encodeWithCoder:(NSCoder *)coder {
24 NSUnimplementedMethod(); 24 NSUnimplementedMethod();
25 } 25 }
26 26
27 -initWithCoder:(NSCoder *)coder { 27 -initWithCoder:(NSCoder *)coder {
28 [super initWithCoder:coder]; 28 [super initWithCoder:coder];
29 29
30 if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){ 30 if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){
31 NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder; 31 NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
32 int flags=[keyed decodeIntForKey:@"NSMatrixFlags"]; 32 int flags=[keyed decodeIntForKey:@"NSMatrixFlags"];
33 NSString *name; 33 NSString *name;
34 34
35 _numberOfRows=[keyed decodeIntForKey:@"NSNumRows"]; 35 _numberOfRows=[keyed decodeIntForKey:@"NSNumRows"];
36 _numberOfColumns=[keyed decodeIntForKey:@"NSNumCols"]; 36 _numberOfColumns=[keyed decodeIntForKey:@"NSNumCols"];
37 _cellSize=[keyed decodeSizeForKey:@"NSCellSize"]; 37 _cellSize=[keyed decodeSizeForKey:@"NSCellSize"];
38 _intercellSpacing=[keyed decodeSizeForKey:@"NSIntercellSpacing"]; 38 _intercellSpacing=[keyed decodeSizeForKey:@"NSIntercellSpacing"];
39 _autosizesCells=(flags&0x00800000)?YES:NO; 39 _autosizesCells=(flags&0x00800000)?YES:NO;
40 _mode=NSTrackModeMatrix; 40 _mode=NSTrackModeMatrix;
41 if(flags&0x20000000) 41 if(flags&0x20000000)
42 _mode=NSListModeMatrix; 42 _mode=NSListModeMatrix;
43 if(flags&0x40000000) 43 if(flags&0x40000000)
44 _mode=NSRadioModeMatrix; 44 _mode=NSRadioModeMatrix;
45 if(flags&0x80000000) 45 if(flags&0x80000000)
46 _mode=NSHighlightModeMatrix; 46 _mode=NSHighlightModeMatrix;
47 _drawsBackground=(flags&0x01000000)?YES:NO; 47 _drawsBackground=(flags&0x01000000)?YES:NO;
48 _backgroundColor=[[keyed decodeObjectForKey:@"NSBackgroundColor"] retain]; 48 _backgroundColor=[[keyed decodeObjectForKey:@"NSBackgroundColor"] retain];
49 name=[keyed decodeObjectForKey:@"NSCellClass"]; 49 name=[keyed decodeObjectForKey:@"NSCellClass"];
50 if((_cellClass=NSClassFromString(name))==Nil){ 50 if((_cellClass=NSClassFromString(name))==Nil){
51 NSLog(@"Unknown cell class %@, using NSCell",name); 51 NSLog(@"Unknown cell class %@, using NSCell",name);
52 _cellClass=[NSCell class]; 52 _cellClass=[NSCell class];
53 _tabKeyTraversesCells=YES; 53 _tabKeyTraversesCells=YES;
54 } 54 }
55 _prototype=[[keyed decodeObjectForKey:@"NSProtoCell"] retain]; 55 _prototype=[[keyed decodeObjectForKey:@"NSProtoCell"] retain];
56 _cells=[[NSMutableArray new] initWithArray:[keyed decodeObjectForKey:@"NSCells"]]; 56 _cells=[[NSMutableArray new] initWithArray:[keyed decodeObjectForKey:@"NSCells"]];
57 _tabKeyTraversesCells=YES; 57 _tabKeyTraversesCells=YES;
58 } 58 }
59 else { 59 else {
60 [NSException raise:NSInvalidArgumentException format:@"-[%@ %s] is not implemented for coder %@",isa,SELNAME(_cmd),coder]; 60 [NSException raise:NSInvalidArgumentException format:@"-[%@ %s] is not implemented for coder %@",isa,SELNAME(_cmd),coder];
61 } 61 }
62 return self; 62 return self;
63 } 63 }
64 64
65 -initWithFrame:(NSRect)frame { 65 -initWithFrame:(NSRect)frame {
66 [super initWithFrame:frame]; 66 [super initWithFrame:frame];
67 _target=nil; 67 _target=nil;
68 _action=NULL; 68 _action=NULL;
69 _doubleAction=NULL; 69 _doubleAction=NULL;
70 _font=[[NSFont userFontOfSize:0] retain]; 70 _font=[[NSFont userFontOfSize:0] retain];
71 _cells=[NSMutableArray new]; 71 _cells=[NSMutableArray new];
72 _numberOfRows=0; 72 _numberOfRows=0;
73 _numberOfColumns=1; 73 _numberOfColumns=1;
74 _selectedIndex=-1; 74 _selectedIndex=-1;
75 _keyCellIndex=-1; 75 _keyCellIndex=-1;
76 _cellSize=NSMakeSize(frame.size.width,20); 76 _cellSize=NSMakeSize(frame.size.width,20);
77 _intercellSpacing=NSMakeSize(0,0); 77 _intercellSpacing=NSMakeSize(0,0);
78 _prototype=nil; 78 _prototype=nil;
79 _cellClass=[NSCell class]; 79 _cellClass=[NSCell class];
80 _mode=NSListModeMatrix; 80 _mode=NSListModeMatrix;
81 _tabKeyTraversesCells=YES; 81 _tabKeyTraversesCells=YES;
82 82
83 return self; 83 return self;
84 } 84 }
85 85
86 -(void)dealloc { 86 -(void)dealloc {
87 [_font release]; 87 [_font release];
88 [_backgroundColor release]; 88 [_backgroundColor release];
89 [_cellBackgroundColor release]; 89 [_cellBackgroundColor release];
90 [_cells release]; 90 [_cells release];
91 [_prototype release]; 91 [_prototype release];
92 [super dealloc]; 92 [super dealloc];
93 } 93 }
94 94
95 -(BOOL)resignFirstResponder { 95 -(BOOL)resignFirstResponder {
96 [self setNeedsDisplay:YES]; 96 [self setNeedsDisplay:YES];
97 return [super resignFirstResponder]; 97 return [super resignFirstResponder];
98 } 98 }
99 99
100 -(void)setRefusesFirstResponder:(BOOL)flag { 100 -(void)setRefusesFirstResponder:(BOOL)flag {
101 _refusesFirstResponder=flag; 101 _refusesFirstResponder=flag;
102 } 102 }
103 103
104 -(BOOL)refusesFirstResponder { 104 -(BOOL)refusesFirstResponder {
105 return _refusesFirstResponder; 105 return _refusesFirstResponder;
106 } 106 }
107 107
108 -(void)resizeWithOldSuperviewSize:(NSSize)oldSize { 108 -(void)resizeWithOldSuperviewSize:(NSSize)oldSize {
109 [super resizeWithOldSuperviewSize:oldSize]; 109 [super resizeWithOldSuperviewSize:oldSize];
110 110
111 if(_autosizesCells){ 111 if(_autosizesCells){
112 NSRect frame=[self frame]; 112 NSRect frame=[self frame];
113 113
114 if(_autoresizingMask&NSViewWidthSizable){ 114 if(_autoresizingMask&NSViewWidthSizable){
115 if(_numberOfColumns==0) 115 if(_numberOfColumns==0)
116 _cellSize.width=frame.size.width; 116 _cellSize.width=frame.size.width;
117 else 117 else
118 _cellSize.width=(frame.size.width- 118 _cellSize.width=(frame.size.width-
119 (_numberOfColumns-1)*_intercellSpacing.width)/_numberOfColumns; 119 (_numberOfColumns-1)*_intercellSpacing.width)/_numberOfColumns;
120 } 120 }
121 121
122 if(_autoresizingMask& NSViewHeightSizable){ 122 if(_autoresizingMask& NSViewHeightSizable){
123 if(_numberOfRows==0) 123 if(_numberOfRows==0)
124 _cellSize.height= frame.size.height; 124 _cellSize.height= frame.size.height;
125 else 125 else
126 _cellSize.height=(frame.size.height- 126 _cellSize.height=(frame.size.height-
127 (_numberOfRows-1)*_intercellSpacing.height)/_numberOfRows; 127 (_numberOfRows-1)*_intercellSpacing.height)/_numberOfRows;
128 } 128 }
129 } 129 }
130 } 130 }
131 131
132 -(void)sizeToFit { 132 -(void)sizeToFit {
133 NSSize size; 133 NSSize size;
134 134
135 size.width=_cellSize.width*_numberOfColumns+ 135 size.width=_cellSize.width*_numberOfColumns+
136 _intercellSpacing.width*(_numberOfColumns-1); 136 _intercellSpacing.width*(_numberOfColumns-1);
137 size.height=_cellSize.height*_numberOfRows+ 137 size.height=_cellSize.height*_numberOfRows+
138 _intercellSpacing.height*(_numberOfRows-1); 138 _intercellSpacing.height*(_numberOfRows-1);
139 139
140 [self setFrameSize:size]; 140 [self setFrameSize:size];
141 } 141 }
142 142
143 -(BOOL)isFlipped { 143 -(BOOL)isFlipped {
144 return YES; 144 return YES;
145 } 145 }
146 146
147 -(void)resetCursorRects { 147 -(void)resetCursorRects {
148 NSRect visibleRect=[self visibleRect]; 148 NSRect visibleRect=[self visibleRect];
149 int row,col; 149 int row,col;
150 150
151 for(row=0;row<_numberOfRows;row++) 151 for(row=0;row<_numberOfRows;row++)
152 for(col=0;col<_numberOfColumns;col++){ 152 for(col=0;col<_numberOfColumns;col++){
153 NSRect frame=[self cellFrameAtRow:row column:col]; 153 NSRect frame=[self cellFrameAtRow:row column:col];
154 154
155 if(NSIntersectsRect(frame,visibleRect)){ 155 if(NSIntersectsRect(frame,visibleRect)){
156 NSCell *cell=[self cellAtRow:row column:col]; 156 NSCell *cell=[self cellAtRow:row column:col];
157 157
158 [cell resetCursorRect:frame inView:self]; 158 [cell resetCursorRect:frame inView:self];
159 } 159 }
160 } 160 }
161 } 161 }
162 162
163 -(NSFont *)font { 163 -(NSFont *)font {
164 return _font; 164 return _font;
165 } 165 }
166 166
167 -(void)setFont:(NSFont *)font { 167 -(void)setFont:(NSFont *)font {
168 font=[font retain]; 168 font=[font retain];
169 [_font release]; 169 [_font release];
170 _font=font; 170 _font=font;
171 } 171 }
172 172
173 -target { 173 -target {
174 return _target; 174 return _target;
175 } 175 }
176 176
177 -(SEL)action { 177 -(SEL)action {
178 return _action; 178 return _action;
179 } 179 }
180 180
181 -delegate { 181 -delegate {
182 return _delegate; 182 return _delegate;
183 } 183 }
184 184
185 -(SEL)doubleAction { 185 -(SEL)doubleAction {
186 return _doubleAction; 186 return _doubleAction;
187 } 187 }
188 188
189 -(Class)cellClass { 189 -(Class)cellClass {
190 return _cellClass; 190 return _cellClass;
191 } 191 }
192 192
193 -prototype { 193 -prototype {
194 return _prototype; 194 return _prototype;
195 } 195 }
196 196
197 -(NSArray *)cells { 197 -(NSArray *)cells {
198 return _cells; 198 return _cells;
199 } 199 }
200 200
201 -cellWithTag:(int)tag { 201 -cellWithTag:(int)tag {
202 int i,count=[_cells count]; 202 int i,count=[_cells count];
203 203
204 for(i=0;i<count;i++){ 204 for(i=0;i<count;i++){
205 NSCell *cell=[_cells objectAtIndex:i]; 205 NSCell *cell=[_cells objectAtIndex:i];
206 if([cell tag]==tag) 206 if([cell tag]==tag)
207 return cell; 207 return cell;
208 } 208 }
209 209
210 return nil; 210 return nil;
211 } 211 }
212 212
213 -cellAtRow:(int)row column:(int)column { 213 -cellAtRow:(int)row column:(int)column {
214 unsigned index=row*_numberOfColumns+column; 214 unsigned index=row*_numberOfColumns+column;
215 215
216 if(index>=[_cells count]) 216 if(index>=[_cells count])
217 return nil; 217 return nil;
218 218
219 // bounds checking added for keyboard spatial movement, hopefully doesn't blow up anything 219 // bounds checking added for keyboard spatial movement, hopefully doesn't blow up anything
220 // which relies on broken behavior 220 // which relies on broken behavior
221 if (row < 0 || row >= _numberOfRows) 221 if (row < 0 || row >= _numberOfRows)
222 return nil; 222 return nil;
223 if (column < 0 || column >= _numberOfColumns) 223 if (column < 0 || column >= _numberOfColumns)
224 return nil; 224 return nil;
225 225
226 return [_cells objectAtIndex:index]; 226 return [_cells objectAtIndex:index];
227 } 227 }
228 228
229 -(NSRect)cellFrameAtRow:(int)row column:(int)column { 229 -(NSRect)cellFrameAtRow:(int)row column:(int)column {
230 NSRect result; 230 NSRect result;
231 231
232 result.origin.x=column*_cellSize.width+column*_intercellSpacing.width; 232 result.origin.x=column*_cellSize.width+column*_intercellSpacing.width;
233 result.origin.y=row*_cellSize.height+row*_intercellSpacing.height; 233 result.origin.y=row*_cellSize.height+row*_intercellSpacing.height;
234 result.size=_cellSize; 234 result.size=_cellSize;
235 235
236 return result; 236 return result;
237 } 237 }
238 238
239 -(BOOL)getRow:(int *)row column:(int *)column ofCell:(NSCell *)cell { 239 -(BOOL)getRow:(int *)row column:(int *)column ofCell:(NSCell *)cell {
240 int index=[_cells indexOfObjectIdenticalTo:cell]; 240 int index=[_cells indexOfObjectIdenticalTo:cell];
241 241
242 if(index!=NSNotFound){ 242 if(index!=NSNotFound){
243 *row=index/_numberOfColumns; 243 *row=index/_numberOfColumns;
244 *column=index%_numberOfColumns; 244 *column=index%_numberOfColumns;
245 return YES; 245 return YES;
246 } 246 }
247 247
248 return NO; 248 return NO;
249 } 249 }
250 250
251 -(BOOL)getRow:(int *)row column:(int *)column forPoint:(NSPoint)point { 251 -(BOOL)getRow:(int *)row column:(int *)column forPoint:(NSPoint)point {
252 NSRect cellFrame; 252 NSRect cellFrame;
253 253
254 *row=point.y/(_cellSize.height+_intercellSpacing.height); 254 *row=point.y/(_cellSize.height+_intercellSpacing.height);
255 *column=point.x/(_cellSize.width+_intercellSpacing.width); 255 *column=point.x/(_cellSize.width+_intercellSpacing.width);
256 256
257 cellFrame=[self cellFrameAtRow:*row column:*column]; 257 cellFrame=[self cellFrameAtRow:*row column:*column];
258 258
259 return NSMouseInRect(point,cellFrame,[self isFlipped]); 259 return NSMouseInRect(point,cellFrame,[self isFlipped]);
260 } 260 }
261 261
262 -(int)numberOfRows { 262 -(int)numberOfRows {
263 return _numberOfRows; 263 return _numberOfRows;
264 } 264 }
265 265
266 -(int)numberOfColumns { 266 -(int)numberOfColumns {
267 return _numberOfColumns; 267 return _numberOfColumns;
268 } 268 }
269 269
270 -(void)getNumberOfRows:(int *)rows columns:(int *)columns { 270 -(void)getNumberOfRows:(int *)rows columns:(int *)columns {
271 *rows=_numberOfRows; 271 *rows=_numberOfRows;
272 *columns=_numberOfColumns; 272 *columns=_numberOfColumns;
273 } 273 }
274 274
275 -(NSString *)toolTipForCell:(NSCell *)cell { 275 -(NSString *)toolTipForCell:(NSCell *)cell {
276 } 276 }
277 277
278 -keyCell { 278 -keyCell {
279 if(_keyCellIndex==-1) 279 if(_keyCellIndex==-1)
280 return nil; 280 return nil;
281 281
282 return [_cells objectAtIndex:_keyCellIndex]; 282 return [_cells objectAtIndex:_keyCellIndex];
283 } 283 }
284 284
285 -(NSMatrixMode)mode { 285 -(NSMatrixMode)mode {
286 return _mode; 286 return _mode;
287 } 287 }
288 288
289 -(BOOL)allowsEmptySelection { 289 -(BOOL)allowsEmptySelection {
290 return _allowsEmptySelection; 290 return _allowsEmptySelection;
291 } 291 }
292 292
293 -(BOOL)tabKeyTraversesCells { 293 -(BOOL)tabKeyTraversesCells {
294 return _tabKeyTraversesCells; 294 return _tabKeyTraversesCells;
295 } 295 }
296 296
297 -(BOOL)autosizesCells { 297 -(BOOL)autosizesCells {
298 return _autosizesCells; 298 return _autosizesCells;
299 } 299 }
300 300
301 -(NSSize)cellSize { 301 -(NSSize)cellSize {
302 return _cellSize; 302 return _cellSize;
303 } 303 }
304 304
305 -(NSSize)intercellSpacing { 305 -(NSSize)intercellSpacing {
306 return _intercellSpacing; 306 return _intercellSpacing;
307 } 307 }
308 308
309 -(BOOL)drawsBackground { 309 -(BOOL)drawsBackground {
310 return _drawsBackground; 310 return _drawsBackground;
311 } 311 }
312 312
313 -(NSColor *)backgroundColor { 313 -(NSColor *)backgroundColor {
314 return _backgroundColor; 314 return _backgroundColor;
315 } 315 }
316 316
317 -(BOOL)drawsCellBackground { 317 -(BOOL)drawsCellBackground {
318 return _drawsCellBackground; 318 return _drawsCellBackground;
319 } 319 }
320 320
321 -(NSColor *)cellBackgroundColor { 321 -(NSColor *)cellBackgroundColor {
322 return _cellBackgroundColor; 322 return _cellBackgroundColor;
323 } 323 }
324 324
325 -(BOOL)isAutoscroll { 325 -(BOOL)isAutoscroll {
326 return _isAutoscroll; 326 return _isAutoscroll;
327 } 327 }
328 328
329 -(int)selectedRow { 329 -(int)selectedRow {
330 if(_selectedIndex<0 || _numberOfRows==0 || _numberOfColumns==0) 330 if(_selectedIndex<0 || _numberOfRows==0 || _numberOfColumns==0)
331 return -1; 331 return -1;
332 332
333 return _selectedIndex/_numberOfColumns; 333 return _selectedIndex/_numberOfColumns;
334 } 334 }
335 335
336 -(int)selectedColumn { 336 -(int)selectedColumn {
337 if(_selectedIndex<0 || _numberOfRows==0 || _numberOfColumns==0) 337 if(_selectedIndex<0 || _numberOfRows==0 || _numberOfColumns==0)
338 return -1; 338 return -1;
339 339
340 return _selectedIndex%_numberOfColumns; 340 return _selectedIndex%_numberOfColumns;
341 } 341 }
342 342
343 -selectedCell { 343 -selectedCell {
344 if(_selectedIndex<0) 344 if(_selectedIndex<0)
345 return nil; 345 return nil;
346 346
347 // FIX shouldn't need this check if _selectedIndex is kept in sync 347 // FIX shouldn't need this check if _selectedIndex is kept in sync
348 if(_selectedIndex>=[_cells count]) 348 if(_selectedIndex>=[_cells count])
349 return nil; 349 return nil;
350 350
351 return [_cells objectAtIndex:_selectedIndex]; 351 return [_cells objectAtIndex:_selectedIndex];
352 } 352 }
353 353
354 -(NSArray *)selectedCells { 354 -(NSArray *)selectedCells {
355 NSMutableArray *result=[NSMutableArray array]; 355 NSMutableArray *result=[NSMutableArray array];
356 int i,count=[_cells count]; 356 int i,count=[_cells count];
357 357
358 for(i=0;i<count;i++){ 358 for(i=0;i<count;i++){
359 NSCell *cell=[_cells objectAtIndex:i]; 359 NSCell *cell=[_cells objectAtIndex:i];
360 360
361 if([cell isHighlighted]) 361 if([cell isHighlighted])
362 [result addObject:cell]; 362 [result addObject:cell];
363 } 363 }
364 364
365 return result; 365 return result;
366 } 366 }
367 367
368 -(void)setDelegate:delegate { 368 -(void)setDelegate:delegate {
369 NSNotificationCenter *center=[NSNotificationCenter defaultCenter]; 369 NSNotificationCenter *center=[NSNotificationCenter defaultCenter];
370 struct { 370 struct {
371 SEL selector; 371 SEL selector;
372 NSString *name; 372 NSString *name;
373 } notes[]={ 373 } notes[]={
374 { @selector(controlTextDidBeginEditing:), NSControlTextDidBeginEditingNotification }, 374 { @selector(controlTextDidBeginEditing:), NSControlTextDidBeginEditingNotification },
375 { @selector(controlTextDidChange:), NSControlTextDidChangeNotification }, 375 { @selector(controlTextDidChange:), NSControlTextDidChangeNotification },
376 { @selector(controlTextDidEndEditing:), NSControlTextDidEndEditingNotification }, 376 { @selector(controlTextDidEndEditing:), NSControlTextDidEndEditingNotification },
377 { NULL, nil } 377 { NULL, nil }
378 }; 378 };
379 int i; 379 int i;
380 380
381 if(_delegate!=nil) 381 if(_delegate!=nil)
382 for(i=0;notes[i].selector!=NULL;i++) 382 for(i=0;notes[i].selector!=NULL;i++)
383 [center removeObserver:_delegate name:notes[i].name object:self]; 383 [center removeObserver:_delegate name:notes[i].name object:self];
384 384
385 _delegate=delegate; 385 _delegate=delegate;
386 386
387 for(i=0;notes[i].selector!=NULL;i++) 387 for(i=0;notes[i].selector!=NULL;i++)
388 if([_delegate respondsToSelector:notes[i].selector]) 388 if([_delegate respondsToSelector:notes[i].selector])
389 [center addObserver:_delegate selector:notes[i].selector name:notes[i].name object:self]; 389 [center addObserver:_delegate selector:notes[i].selector name:notes[i].name object:self];
390 } 390 }
391 391
392 -(void)setTarget:target { 392 -(void)setTarget:target {
393 _target=target; 393 _target=target;
394 } 394 }
395 395
396 -(void)setAction:(SEL)action { 396 -(void)setAction:(SEL)action {
397 _action=action; 397 _action=action;
398 } 398 }
399 399
400 -(void)setDoubleAction:(SEL)action { 400 -(void)setDoubleAction:(SEL)action {
401 _doubleAction=action; 401 _doubleAction=action;
402 } 402 }
403 403
404 -(void)setCellClass:(Class)class { 404 -(void)setCellClass:(Class)class {
405 _cellClass=class; 405 _cellClass=class;
406 } 406 }
407 407
408 -(void)setPrototype:(NSCell *)cell { 408 -(void)setPrototype:(NSCell *)cell {
409 cell=[cell retain]; 409 cell=[cell retain];
410 [_prototype release]; 410 [_prototype release];
411 _prototype=cell; 411 _prototype=cell;
412 } 412 }
413 413
414 -(void)_deselectAllCells { 414 -(void)_deselectAllCells {
415 int i,count=[_cells count]; 415 int i,count=[_cells count];
416 416
417 _selectedIndex=-1; 417 _selectedIndex=-1;
418 _keyCellIndex=-1; 418 _keyCellIndex=-1;
419 419
420 for(i=0;i<count;i++) 420 for(i=0;i<count;i++)
421 [[_cells objectAtIndex:i] setState:NSOffState]; 421 [[_cells objectAtIndex:i] setState:NSOffState];
422 } 422 }
423 423
424 -(void)renewRows:(int)rows columns:(int)columns { 424 -(void)renewRows:(int)rows columns:(int)columns {
425 while(_numberOfRows<rows) 425 while(_numberOfRows<rows)
426 [self addRow]; 426 [self addRow];
427 while(_numberOfRows>rows) 427 while(_numberOfRows>rows)
428 [self removeRow:_numberOfRows-1]; 428 [self removeRow:_numberOfRows-1];
429 while(_numberOfColumns<columns) 429 while(_numberOfColumns<columns)
430 [self addColumn]; 430 [self addColumn];
431 while(_numberOfColumns>columns) 431 while(_numberOfColumns>columns)
432 [self removeColumn:_numberOfColumns-1]; 432 [self removeColumn:_numberOfColumns-1];
433 433
434 [self _deselectAllCells]; 434 [self _deselectAllCells];
435 } 435 }
436 436
437 -(NSCell *)makeCellAtRow:(int)row column:(int)column { 437 -(NSCell *)makeCellAtRow:(int)row column:(int)column {
438 NSCell *result=[[_prototype copy] autorelease]; 438 NSCell *result=[[_prototype copy] autorelease];
439 439
440 if(result==nil) 440 if(result==nil)
441 result=[[[_cellClass alloc] init] autorelease]; 441 result=[[[_cellClass alloc] init] autorelease];
442 442
443 return result; 443 return result;
444 } 444 }
445 445
446 -(void)putCell:(NSCell *)cell atRow:(int)row column:(int)column { 446 -(void)putCell:(NSCell *)cell atRow:(int)row column:(int)column {
447 unsigned index=row*_numberOfColumns+column; 447 unsigned index=row*_numberOfColumns+column;
448 448
449 [_cells replaceObjectAtIndex:index withObject:cell]; 449 [_cells replaceObjectAtIndex:index withObject:cell];
450 [self setNeedsDisplayInRect:[self cellFrameAtRow:row column:column]]; 450 [self setNeedsDisplayInRect:[self cellFrameAtRow:row column:column]];
451 } 451 }
452 452
453 -(void)addRow { 453 -(void)addRow {
454 int i; 454 int i;
455 455
456 for(i=0;i<_numberOfColumns;i++) 456 for(i=0;i<_numberOfColumns;i++)
457 [_cells addObject:[self makeCellAtRow:_numberOfRows column:i]]; 457 [_cells addObject:[self makeCellAtRow:_numberOfRows column:i]];
458 458
459 _numberOfRows++; 459 _numberOfRows++;
460 } 460 }
461 461
462 -(void)insertRow:(int)row { 462 -(void)insertRow:(int)row {
463 int i; 463 int i;
464 464
465 for(i=0;i<_numberOfColumns;i++){ 465 for(i=0;i<_numberOfColumns;i++){
466 [_cells insertObject:[self makeCellAtRow:row column:i] 466 [_cells insertObject:[self makeCellAtRow:row column:i]
467 atIndex:row*_numberOfColumns]; 467 atIndex:row*_numberOfColumns];
468 } 468 }
469 _numberOfRows++; 469 _numberOfRows++;
470 } 470 }
471 471
472 -(void)removeRow:(int)row { 472 -(void)removeRow:(int)row {
473 int i; 473 int i;
474 474
475 for(i=0;i<_numberOfColumns;i++){ 475 for(i=0;i<_numberOfColumns;i++){
476 [_cells removeObjectAtIndex:row*_numberOfColumns]; 476 [_cells removeObjectAtIndex:row*_numberOfColumns];
477 } 477 }
478 478
479 _numberOfRows--; 479 _numberOfRows--;
480 } 480 }
481 481
482 -(void)addColumn { 482 -(void)addColumn {
483 int i=_numberOfRows*_numberOfColumns; 483 int i=_numberOfRows*_numberOfColumns;
484 484
485 for(;i>0;i-=_numberOfRows){ 485 for(;i>0;i-=_numberOfRows){
486 int row= i/_numberOfColumns; 486 int row= i/_numberOfColumns;
487 NSCell *cell=[self makeCellAtRow:row column:_numberOfColumns]; 487 NSCell *cell=[self makeCellAtRow:row column:_numberOfColumns];
488 488
489 [_cells insertObject:cell atIndex:i]; 489 [_cells insertObject:cell atIndex:i];
490 } 490 }
491 491
492 _numberOfColumns++; 492 _numberOfColumns++;
493 } 493 }
494 494
495 -(void)removeColumn:(int)col { 495 -(void)removeColumn:(int)col {
496 int i; 496 int i;
497 497
498 for(i=_numberOfRows;i>=1;i--) 498 for(i=_numberOfRows;i>=1;i--)
499 [_cells removeObjectAtIndex:(i*col)]; 499 [_cells removeObjectAtIndex:(i*col)];
500 500
501 _numberOfColumns--; 501 _numberOfColumns--;
502 } 502 }
503 503
504 -(void)setToolTip:(NSString *)tip forCell:(NSCell *)cell { 504 -(void)setToolTip:(NSString *)tip forCell:(NSCell *)cell {
505 } 505 }
506 506
507 -(void)setKeyCell:cell { 507 -(void)setKeyCell:cell {
508 _keyCellIndex=[_cells indexOfObjectIdenticalTo:cell]; 508 _keyCellIndex=[_cells indexOfObjectIdenticalTo:cell];
509 } 509 }
510 510
511 -(void)setMode:(NSMatrixMode)mode { 511 -(void)setMode:(NSMatrixMode)mode {
512 _mode=mode; 512 _mode=mode;
513 } 513 }
514 514
515 -(void)setAllowsEmptySelection:(BOOL)flag { 515 -(void)setAllowsEmptySelection:(BOOL)flag {
516 _allowsEmptySelection=flag; 516 _allowsEmptySelection=flag;
517 } 517 }
518 518
519 -(void)setTabKeyTraversesCells:(BOOL)flag { 519 -(void)setTabKeyTraversesCells:(BOOL)flag {
520 _tabKeyTraversesCells=flag; 520 _tabKeyTraversesCells=flag;
521 } 521 }
522 522
523 -(void)setAutosizesCells:(BOOL)flag { 523 -(void)setAutosizesCells:(BOOL)flag {
524 _autosizesCells=flag; 524 _autosizesCells=flag;
525 } 525 }
526 526
527 -(void)setCellSize:(NSSize)size { 527 -(void)setCellSize:(NSSize)size {
528 _cellSize=size; 528 _cellSize=size;
529 } 529 }
530 530
531 -(void)setIntercellSpacing:(NSSize)size { 531 -(void)setIntercellSpacing:(NSSize)size {
532 _intercellSpacing=size; 532 _intercellSpacing=size;
533 } 533 }
534 534
535 -(void)setDrawsBackground:(BOOL)flag { 535 -(void)setDrawsBackground:(BOOL)flag {
536 _drawsBackground=flag; 536 _drawsBackground=flag;
537 } 537 }
538 538
539 -(void)setBackgroundColor:(NSColor *)color { 539 -(void)setBackgroundColor:(NSColor *)color {
540 color=[color retain]; 540 color=[color retain];
541 [_backgroundColor release]; 541 [_backgroundColor release];
542 _backgroundColor=color; 542 _backgroundColor=color;
543 [self setNeedsDisplay:YES]; 543 [self setNeedsDisplay:YES];
544 } 544 }
545 545
546 -(void)setDrawsCellBackground:(BOOL)flag { 546 -(void)setDrawsCellBackground:(BOOL)flag {
547 _drawsCellBackground=flag; 547 _drawsCellBackground=flag;
548 } 548 }
549 549
550 -(void)setCellBackgroundColor:(NSColor *)color { 550 -(void)setCellBackgroundColor:(NSColor *)color {
551 color=[color retain]; 551 color=[color retain];
552 [_cellBackgroundColor release]; 552 [_cellBackgroundColor release];
553 _cellBackgroundColor=color; 553 _cellBackgroundColor=color;
554 [self setNeedsDisplay:YES]; 554 [self setNeedsDisplay:YES];
555 } 555 }
556 556
557 -(void)setAutoscroll:(BOOL)flag { 557 -(void)setAutoscroll:(BOOL)flag {
558 _isAutoscroll=flag; 558 _isAutoscroll=flag;
559 } 559 }
560 560
561 -(void)selectCellAtRow:(int)row column:(int)column { 561 -(void)selectCellAtRow:(int)row column:(int)column {
562 NSCell *cell; 562 NSCell *cell;
563 563
564 if(row<0 || row>=_numberOfRows) 564 if(row<0 || row>=_numberOfRows)
565 cell=nil; 565 cell=nil;
566 else if(column<0 || column>=_numberOfColumns) 566 else if(column<0 || column>=_numberOfColumns)
567 cell=nil; 567 cell=nil;
568 else 568 else
569 cell=[_cells objectAtIndex:row*_numberOfColumns+column]; 569 cell=[_cells objectAtIndex:row*_numberOfColumns+column];
570 570
571 [self selectCell:cell]; 571 [self selectCell:cell];
572 } 572 }
573 573
574 -(void)_setSelectedIndexFromCell:(NSCell *)select { 574 -(void)_setSelectedIndexFromCell:(NSCell *)select {
575 if(select==nil) 575 if(select==nil)
576 _selectedIndex=-1; 576 _selectedIndex=-1;
577 else 577 else
578 _selectedIndex=[_cells indexOfObjectIdenticalTo:select]; 578 _selectedIndex=[_cells indexOfObjectIdenticalTo:select];
579 579
580 _keyCellIndex=_selectedIndex; 580 _keyCellIndex=_selectedIndex;
581 } 581 }
582 582
583 -(void)_selectCell:(NSCell *)select deselectOthers:(BOOL)deselectOthers { 583 -(void)_selectCell:(NSCell *)select deselectOthers:(BOOL)deselectOthers {
584 if([self mode]==NSRadioModeMatrix){ 584 if([self mode]==NSRadioModeMatrix){
585 if(![self allowsEmptySelection] && select==nil) 585 if(![self allowsEmptySelection] && select==nil)
586 return; 586 return;
587 } 587 }
588 588
589 if(deselectOthers) 589 if(deselectOthers)
590 [self _deselectAllCells]; 590 [self _deselectAllCells];
591 591
592 [self _setSelectedIndexFromCell:select]; 592 [self _setSelectedIndexFromCell:select];
593 [select setState:NSOnState]; 593 [select setState:NSOnState];
594 if([self mode]==NSListModeMatrix) 594 if([self mode]==NSListModeMatrix)
595 [select setHighlighted:YES]; 595 [select setHighlighted:YES];
596 596
597 [self setNeedsDisplay:YES]; 597 [self setNeedsDisplay:YES];
598 } 598 }
599 599
600 -(void)selectCell:(NSCell *)select { 600 -(void)selectCell:(NSCell *)select {
601 [self _selectCell:select deselectOthers:YES]; 601 [self _selectCell:select deselectOthers:YES];
602 } 602 }
603 603
604 -(BOOL)selectCellWithTag:(int)tag { 604 -(BOOL)selectCellWithTag:(int)tag {
605 NSCell *cell=[self cellWithTag:tag]; 605 NSCell *cell=[self cellWithTag:tag];
606 606
607 [self selectCell:cell]; 607 [self selectCell:cell];
608 608
609 return (cell!=nil)?YES:NO; 609 return (cell!=nil)?YES:NO;
610 } 610 }
611 611
612 -(void)selectAll:sender { 612 -(void)selectAll:sender {
613 int i, count = [_cells count]; 613 int i, count = [_cells count];
614 614
615 for (i=0; i < count; ++i) 615 for (i=0; i < count; ++i)
616 [self _selectCell:[_cells objectAtIndex:i] deselectOthers:NO]; 616 [self _selectCell:[_cells objectAtIndex:i] deselectOthers:NO];
617 } 617 }
618 618
619 -(void)setSelectionFrom:(int)from to:(int)to anchor:(int)anchor highlight:(BOOL)highlight { 619 -(void)setSelectionFrom:(int)from to:(int)to anchor:(int)anchor highlight:(BOOL)highlight {
620 if (anchor != -1) { // no anchor, i.e., no selected cell 620 if (anchor != -1) { // no anchor, i.e., no selected cell
621 if (anchor < from) 621 if (anchor < from)
622 from = anchor; 622 from = anchor;
623 if (anchor > to) 623 if (anchor > to)
624 to = anchor; 624 to = anchor;
625 } 625 }
626 626
627 [self _deselectAllCells]; 627 [self _deselectAllCells];
628 while (from < to) { 628 while (from < to) {
629 NSCell *cell = [_cells objectAtIndex:from]; 629 NSCell *cell = [_cells objectAtIndex:from];
630 630
631 [self _selectCell:cell deselectOthers:NO]; 631 [self _selectCell:cell deselectOthers:NO];
632 if (highlight) 632 if (highlight)
633 [cell setHighlighted:YES]; 633 [cell setHighlighted:YES];
634 from++; 634 from++;
635 } 635 }
636 } 636 }
637 637
638 -(void)_deselectAllCellsInLockFocus { 638 -(void)_deselectAllCellsInLockFocus {
639 int row,column; 639 int row,column;
640 640
641 for(row=0;row<_numberOfRows;row++) 641 for(row=0;row<_numberOfRows;row++)
642 for(column=0;column<_numberOfColumns;column++){ 642 for(column=0;column<_numberOfColumns;column++){
643 NSCell *cell=[self cellAtRow:row column:column]; 643 NSCell *cell=[self cellAtRow:row column:column];
644 NSRect cellFrame=[self cellFrameAtRow:row column:column]; 644 NSRect cellFrame=[self cellFrameAtRow:row column:column];
645 645
646 [cell setState:NSOffState]; 646 [cell setState:NSOffState];
647 [cell setHighlighted:NO]; 647 [cell setHighlighted:NO];
648 [cell drawWithFrame:cellFrame inView:self]; 648 [cell drawWithFrame:cellFrame inView:self];
649 } 649 }
650 } 650 }
651 651
652 -(void)deselectAllCells { 652 -(void)deselectAllCells {
653 if([self mode]==NSRadioModeMatrix && [self allowsEmptySelection]==NO) 653 if([self mode]==NSRadioModeMatrix && [self allowsEmptySelection]==NO)
654 return; 654 return;
655 655
656 [self lockFocus]; 656 [self lockFocus];
657 [self _deselectAllCellsInLockFocus]; 657 [self _deselectAllCellsInLockFocus];
658 [self unlockFocus]; 658 [self unlockFocus];
659 [[self window] flushWindow]; 659 [[self window] flushWindow];
660 660
661 _selectedIndex=-1; 661 _selectedIndex=-1;
662 _keyCellIndex=-1; 662 _keyCellIndex=-1;
663 } 663 }
664 664
665 -(void)deselectSelectedCell { 665 -(void)deselectSelectedCell {
666 int row,column; 666 int row,column;
667 667
668 if ([self mode] == NSRadioModeMatrix && [self allowsEmptySelection] == NO) 668 if ([self mode] == NSRadioModeMatrix && [self allowsEmptySelection] == NO)
669 return; 669 return;
670 670
671 for(row=0;row<_numberOfRows;row++) 671 for(row=0;row<_numberOfRows;row++)
672 for(column=0;column<_numberOfColumns;column++){ 672 for(column=0;column<_numberOfColumns;column++){
673 NSCell *cell=[self cellAtRow:row column:column]; 673 NSCell *cell=[self cellAtRow:row column:column];
674 674
675 [cell setState:NSOffState]; 675 [cell setState:NSOffState];
676 [self drawCellAtRow:row column:column]; 676 [self drawCellAtRow:row column:column];
677 } 677 }
678 _selectedIndex=-1; 678 _selectedIndex=-1;
679 _keyCellIndex=-1; 679 _keyCellIndex=-1;
680 } 680 }
681 681
682 -(void)sizeToCells { 682 -(void)sizeToCells {
683 [self sizeToFit]; 683 [self sizeToFit];
684 } 684 }
685 685
686 -(void)highlightCell:(BOOL)highlight atRow:(int)row column:(int)column { 686 -(void)highlightCell:(BOOL)highlight atRow:(int)row column:(int)column {
687 NSCell *cell=[self cellAtRow:row column:column]; 687 NSCell *cell=[self cellAtRow:row column:column];
688 688
689 if(cell!=nil){ 689 if(cell!=nil){
690 NSRect frame=[self cellFrameAtRow:row column:column]; 690 NSRect frame=[self cellFrameAtRow:row column:column];
691 691
692 [self lockFocus]; 692 [self lockFocus];
693 [cell highlight:highlight withFrame:frame inView:self]; 693 [cell highlight:highlight withFrame:frame inView:self];
694 [self unlockFocus]; 694 [self unlockFocus];
695 [[self window] flushWindow]; 695 [[self window] flushWindow];
696 } 696 }
697 } 697 }
698 698
699 -(void)drawCellAtRow:(int)row column:(int)column { 699 -(void)drawCellAtRow:(int)row column:(int)column {
700 NSCell *cell=[self cellAtRow:row column:column]; 700 NSCell *cell=[self cellAtRow:row column:column];
701 701
702 [self drawCell:cell]; 702 [self drawCell:cell];
703 } 703 }
704 704
705 -(void)scrollCellToVisibleAtRow:(int)row column:(int)column { 705 -(void)scrollCellToVisibleAtRow:(int)row column:(int)column {
706 NSRect frame=[self cellFrameAtRow:row column:column]; 706 NSRect frame=[self cellFrameAtRow:row column:column];
707 [self scrollRectToVisible:frame]; 707 [self scrollRectToVisible:frame];
708 } 708 }
709 709
710 -(BOOL)sendAction { 710 -(BOOL)sendAction {
711 NSCell *cell=[self selectedCell]; 711 NSCell *cell=[self selectedCell];
712 SEL action=[cell action]; 712 SEL action=[cell action];
713 id target=[cell target]; 713 id target=[cell target];
714 714
715 if(action==NULL){ 715 if(action==NULL){
716 action=[self action]; 716 action=[self action];
717 target=[self target]; 717 target=[self target];
718 } 718 }
719 else if(target==nil){ 719 else if(target==nil){
720 target=[self target]; 720 target=[self target];
721 } 721 }
722 722
723 return [NSApp sendAction:action to:target from:self]; 723 return [NSApp sendAction:action to:target from:self];
724 } 724 }
725 725
726 -(void)sendDoubleAction { 726 -(void)sendDoubleAction {
727 SEL action=[self doubleAction]; 727 SEL action=[self doubleAction];
728 id target=[self target]; 728 id target=[self target];
729 729
730 if(action==NULL){ 730 if(action==NULL){
731 action=[[self selectedCell] action]; 731 action=[[self selectedCell] action];
732 target=nil; 732 target=nil;
733 } 733 }
734 734
735 if(action==NULL){ 735 if(action==NULL){
736 action=[self action]; 736 action=[self action];
737 target=[self target]; 737 target=[self target];
738 } 738 }
739 739
740 [NSApp sendAction:action to:target from:self]; 740 [NSApp sendAction:action to:target from:self];
741 } 741 }
742 742
743 743
744 -(void)setEnabled:(BOOL)enabled { 744 -(void)setEnabled:(BOOL)enabled {
745 int count=[_cells count]; 745 int count=[_cells count];
746 746
747 while(--count>=0){ 747 while(--count>=0){
748 [[_cells objectAtIndex:count] setEnabled:enabled]; 748 [[_cells objectAtIndex:count] setEnabled:enabled];
749 } 749 }
750 [self setNeedsDisplay:YES]; 750 [self setNeedsDisplay:YES];
751 } 751 }
752 752
753 753
754 -(BOOL)isOpaque { 754 -(BOOL)isOpaque {
755 return [self drawsBackground]; 755 return [self drawsBackground];
756 } 756 }
757 757
758 -(void)updateCell:(NSCell *)cell { 758 -(void)updateCell:(NSCell *)cell {
759 int row,column; 759 int row,column;
760 760
761 if([self getRow:&row column:&column ofCell:cell]){ 761 if([self getRow:&row column:&column ofCell:cell]){
762 NSRect frame=[self cellFrameAtRow:row column:column]; 762 NSRect frame=[self cellFrameAtRow:row column:column];
763 763
764 [self setNeedsDisplayInRect:frame]; 764 [self setNeedsDisplayInRect:frame];
765 } 765 }
766 } 766 }
767 767
768 -(void)updateCellInside:(NSCell *)cell { 768 -(void)updateCellInside:(NSCell *)cell {
769 int row,column; 769 int row,column;
770 770
771 if([self getRow:&row column:&column ofCell:cell]){ 771 if([self getRow:&row column:&column ofCell:cell]){
772 NSRect frame=[self cellFrameAtRow:row column:column]; 772 NSRect frame=[self cellFrameAtRow:row column:column];
773 773
774 [self setNeedsDisplayInRect:frame]; 774 [self setNeedsDisplayInRect:frame];
775 } 775 }
776 } 776 }
777 777
778 778
779 779
780 780
781 -(void)drawCell:(NSCell *)cell { 781 -(void)drawCell:(NSCell *)cell {
782 int row,column; 782 int row,column;
783 783
784 if([self getRow:&row column:&column ofCell:cell]){ 784 if([self getRow:&row column:&column ofCell:cell]){
785 NSRect frame=[self cellFrameAtRow:row column:column]; 785 NSRect frame=[self cellFrameAtRow:row column:column];
786 [self lockFocus]; 786 [self lockFocus];
787 [cell drawWithFrame:frame inView:self]; 787 [cell drawWithFrame:frame inView:self];
788 [self unlockFocus]; 788 [self unlockFocus];
789 [[self window] flushWindow]; 789 [[self window] flushWindow];
790 } 790 }
791 } 791 }
792 792
793 793
794 794
795 -(void)drawRect:(NSRect)rect { 795 -(void)drawRect:(NSRect)rect {
796 int row,col; 796 int row,col;
797 797
798 if([self drawsBackground]){ 798 if([self drawsBackground]){
799 [[self backgroundColor] set]; 799 [[self backgroundColor] set];
800 NSRectFill(rect); 800 NSRectFill(rect);
801 } 801 }
802 802
803 for(row=0;row<_numberOfRows;row++) 803 for(row=0;row<_numberOfRows;row++)
804 for(col=0;col<_numberOfColumns;col++){ 804 for(col=0;col<_numberOfColumns;col++){
805 NSRect frame=[self cellFrameAtRow:row column:col]; 805 NSRect frame=[self cellFrameAtRow:row column:col];
806 806
807 if(NSIntersectsRect(frame,rect)){ 807 if(NSIntersectsRect(frame,rect)){
808 NSCell *cell=[self cellAtRow:row column:col]; 808 NSCell *cell=[self cellAtRow:row column:col];
809 [cell drawWithFrame:frame inView:self]; 809 [cell drawWithFrame:frame inView:self];
810 } 810 }
811 } 811 }
812 } 812 }
813 813
814 -(void)_fieldEditCell:(NSCell *)cell row:(int)row column:(int)column { 814 -(void)_fieldEditCell:(NSCell *)cell row:(int)row column:(int)column {
815 [self selectCell:cell]; 815 [self selectCell:cell];
816 816
817 _currentEditor=[[self window] fieldEditor:YES forObject:self]; 817 _currentEditor=[[self window] fieldEditor:YES forObject:self];
818 _currentEditor=[cell setUpFieldEditorAttributes:_currentEditor]; 818 _currentEditor=[cell setUpFieldEditorAttributes:_currentEditor];
819 [_currentEditor retain]; 819 [_currentEditor retain];
820 } 820 }
821 821
822 -(void)_selectTextCell:(NSCell *)cell { 822 -(void)_selectTextCell:(NSCell *)cell {
823 int row,column; 823 int row,column;
824 NSRect cellFrame; 824 NSRect cellFrame;
825 825
826 if(![cell isEditable]) 826 if(![cell isEditable])
827 return; 827 return;
828 828
829 [self getRow:&row column:&column ofCell:cell]; 829 [self getRow:&row column:&column ofCell:cell];
830 cellFrame=[self cellFrameAtRow:row column:column]; 830 cellFrame=[self cellFrameAtRow:row column:column];
831 831
832 [self _fieldEditCell:cell row:row column:column]; 832 [self _fieldEditCell:cell row:row column:column];
833 [cell selectWithFrame:cellFrame inView:self editor:_currentEditor delegate:self start:0 length:[[cell stringValue] length]]; 833 [cell selectWithFrame:cellFrame inView:self editor:_currentEditor delegate:self start:0 length:[[cell stringValue] length]];
834 } 834 }
835 835
836 -(void)_editTextCell:(NSCell *)cell row:(int)row column:(int)column event:(NSEvent *)event { 836 -(void)_editTextCell:(NSCell *)cell row:(int)row column:(int)column event:(NSEvent *)event {
837 NSRect cellFrame=[self cellFrameAtRow:row column:column]; 837 NSRect cellFrame=[self cellFrameAtRow:row column:column];
838 838
839 [self _fieldEditCell:cell row:row column:column]; 839 [self _fieldEditCell:cell row:row column:column];
840 [cell editWithFrame:cellFrame inView:self editor:_currentEditor delegate:self event:event]; 840 [cell editWithFrame:cellFrame inView:self editor:_currentEditor delegate:self event:event];
841 } 841 }
842 842
843 -(NSCell *)_enabledCellAtPoint:(NSPoint)point row:(int *)row column:(int *)column { 843 -(NSCell *)_enabledCellAtPoint:(NSPoint)point row:(int *)row column:(int *)column {
844 if([self getRow:row column:column forPoint:point]){ 844 if([self getRow:row column:column forPoint:point]){
845 NSCell *cell=[self cellAtRow:*row column:*column]; 845 NSCell *cell=[self cellAtRow:*row column:*column];
846 846
847 if([cell isEnabled]) 847 if([cell isEnabled])
848 return cell; 848 return cell;
849 } 849 }
850 850
851 return nil; 851 return nil;
852 } 852 }
853 853
854 -(BOOL)_mouseDownRadio:(NSEvent *)event { 854 -(BOOL)_mouseDownRadio:(NSEvent *)event {
855 BOOL result=NO; 855 BOOL result=NO;
856 NSEvent *lastMouse=event; 856 NSEvent *lastMouse=event;
857 857
858 do { 858 do {
859 NSPoint point=[self convertPoint:[lastMouse locationInWindow] fromView:nil]; 859 NSPoint point=[self convertPoint:[lastMouse locationInWindow] fromView:nil];
860 int row,column; 860 int row,column;
861 NSCell *cell; 861 NSCell *cell;
862 862
863 [[self superview] autoscroll:lastMouse]; 863 [[self superview] autoscroll:lastMouse];
864 [self lockFocus]; 864 [self lockFocus];
865 if((cell=[self _enabledCellAtPoint:point row:&row column:&column])!=nil){ 865 if((cell=[self _enabledCellAtPoint:point row:&row column:&column])!=nil){
866 result=YES; 866 result=YES;
867 867
868 if([self selectedCell]!=cell) 868 if([self selectedCell]!=cell)
869 [self highlightCell:NO atRow:[self selectedRow] column:[self selectedColumn]]; 869 [self highlightCell:NO atRow:[self selectedRow] column:[self selectedColumn]];
870 870
871 [self highlightCell:YES atRow:row column:column]; 871 [self highlightCell:YES atRow:row column:column];
872 [self selectCell:cell]; 872 [self selectCell:cell];
873 } 873 }
874 [self unlockFocus]; 874 [self unlockFocus];
875 [[self window] flushWindow]; 875 [[self window] flushWindow];
876 event=[[self window] nextEventMatchingMask:NSLeftMouseUpMask| 876 event=[[self window] nextEventMatchingMask:NSLeftMouseUpMask|
877 NSLeftMouseDraggedMask|NSPeriodicMask]; 877 NSLeftMouseDraggedMask|NSPeriodicMask];
878 if([event type]!=NSPeriodic) 878 if([event type]!=NSPeriodic)
879 lastMouse=event; 879 lastMouse=event;
880 880
881 }while([event type]!=NSLeftMouseUp); 881 }while([event type]!=NSLeftMouseUp);
882 882
883 [self highlightCell:NO atRow:[self selectedRow] column:[self selectedColumn]]; 883 [self highlightCell:NO atRow:[self selectedRow] column:[self selectedColumn]];
884 884
885 return result; 885 return result;
886 } 886 }
887 887
888 -(BOOL)_mouseDownHighlight:(NSEvent *)event { 888 -(BOOL)_mouseDownHighlight:(NSEvent *)event {
889 BOOL result=NO; 889 BOOL result=NO;
890 NSEvent *lastMouse=event; 890 NSEvent *lastMouse=event;
891 do { 891 do {
892 NSPoint point=[self convertPoint:[lastMouse locationInWindow] fromView:nil]; 892 NSPoint point=[self convertPoint:[lastMouse locationInWindow] fromView:nil];
893 int row,column; 893 int row,column;
894 NSCell *cell; 894 NSCell *cell;
895 895
896 [[self superview] autoscroll:lastMouse]; 896 [[self superview] autoscroll:lastMouse];
897 [self lockFocus]; 897 [self lockFocus];
898 if((cell=[self _enabledCellAtPoint:point row:&row column:&column])!=nil){ 898 if((cell=[self _enabledCellAtPoint:point row:&row column:&column])!=nil){
899 NSRect cellFrame=[self cellFrameAtRow:row column:column]; 899 NSRect cellFrame=[self cellFrameAtRow:row column:column];
900 int currentState=[cell state]; 900 int currentState=[cell state];
901 int nextState=[cell nextState]; 901 int nextState=[cell nextState];
902 902
903 result=YES; 903 result=YES;
904 [cell highlight:YES withFrame:cellFrame inView:self]; 904 [cell highlight:YES withFrame:cellFrame inView:self];
905 905
906 [cell setState:nextState]; 906 [cell setState:nextState];
907 907
908 if([cell trackMouse:lastMouse inRect:cellFrame ofView:self untilMouseUp:NO]){ 908 if([cell trackMouse:lastMouse inRect:cellFrame ofView:self untilMouseUp:NO]){
909 _selectedIndex=[_cells indexOfObjectIdenticalTo:cell]; 909 _selectedIndex=[_cells indexOfObjectIdenticalTo:cell];
910 _keyCellIndex=_selectedIndex; 910 _keyCellIndex=_selectedIndex;
911 [cell highlight:NO withFrame:cellFrame inView:self]; 911 [cell highlight:NO withFrame:cellFrame inView:self];
912 break; 912 break;
913 } 913 }
914 else { 914 else {
915 [cell setState:currentState]; 915 [cell setState:currentState];
916 [cell highlight:NO withFrame:cellFrame inView:self]; 916 [cell highlight:NO withFrame:cellFrame inView:self];
917 } 917 }
918 } 918 }
919 [self unlockFocus]; 919 [self unlockFocus];
920 [[self window] flushWindow]; 920 [[self window] flushWindow];
921 event=[[self window] nextEventMatchingMask:NSLeftMouseUpMask| 921 event=[[self window] nextEventMatchingMask:NSLeftMouseUpMask|
922 NSLeftMouseDraggedMask|NSPeriodicMask]; 922 NSLeftMouseDraggedMask|NSPeriodicMask];
923 if([event type]!=NSPeriodic) 923 if([event type]!=NSPeriodic)
924 lastMouse=event; 924 lastMouse=event;
925 }while([event type]!=NSLeftMouseUp); 925 }while([event type]!=NSLeftMouseUp);
926 926
927 return result; 927 return result;
928 } 928 }
929 929
930 -(BOOL)_mouseDownList:(NSEvent *)event { 930 -(BOOL)_mouseDownList:(NSEvent *)event {
931 BOOL result=YES; 931 BOOL result=YES;
932 NSEvent *lastMouse=event; 932 NSEvent *lastMouse=event;
933 int firstRow=-1,firstColumn=-1; 933 int firstRow=-1,firstColumn=-1;
934 int previousRow=-1,previousColumn=-1; 934 int previousRow=-1,previousColumn=-1;
935 BOOL firstHighlight=YES; 935 BOOL firstHighlight=YES;
936 936
937 if([event modifierFlags]&NSShiftKeyMask){ 937 if([event modifierFlags]&NSShiftKeyMask){
938 firstRow=previousRow=[self selectedRow]; 938 firstRow=previousRow=[self selectedRow];
939 firstColumn=previousColumn=[self selectedColumn]; 939 firstColumn=previousColumn=[self selectedColumn];
940 [self lockFocus]; 940 [self lockFocus];
941 [self _deselectAllCellsInLockFocus]; 941 [self _deselectAllCellsInLockFocus];
942 [self unlockFocus]; 942 [self unlockFocus];
943 } 943 }
944 else if(!([event modifierFlags]&NSControlKeyMask)) 944 else if(!([event modifierFlags]&NSControlKeyMask))
945 [self deselectAllCells]; 945 [self deselectAllCells];
946 946
947 do { 947 do {
948 NSPoint point=[self convertPoint:[lastMouse locationInWindow] fromView:nil]; 948 NSPoint point=[self convertPoint:[lastMouse locationInWindow] fromView:nil];
949 int row,column,minSelRow,maxSelRow,minSelColumn,maxSelColumn,r,c; 949 int row,column,minSelRow,maxSelRow,minSelColumn,maxSelColumn,r,c;
950 950
951 [[self superview] autoscroll:lastMouse]; 951 [[self superview] autoscroll:lastMouse];
952 952
953 if([self getRow:&row column:&column forPoint:point]){ 953 if([self getRow:&row column:&column forPoint:point]){
954 NSCell *cell=[self cellAtRow:row column:column]; 954 NSCell *cell=[self cellAtRow:row column:column];
955 955
956 if(firstRow==-1){ 956 if(firstRow==-1){
957 previousRow=firstRow=row; 957 previousRow=firstRow=row;
958 previousColumn=firstColumn=column; 958 previousColumn=firstColumn=column;
959 if([lastMouse modifierFlags]&NSControlKeyMask) 959 if([lastMouse modifierFlags]&NSControlKeyMask)
960 firstHighlight=![cell isHighlighted]; 960 firstHighlight=![cell isHighlighted];
961 // [self _selectCell:cell]; 961 // [self _selectCell:cell];
962 } 962 }
963 963
964 964
965 [self lockFocus]; 965 [self lockFocus];
966 966
967 minSelRow=MIN(firstRow,row); 967 minSelRow=MIN(firstRow,row);
968 maxSelRow=MAX(firstRow,row); 968 maxSelRow=MAX(firstRow,row);
969 minSelColumn=MIN(firstColumn,column); 969 minSelColumn=MIN(firstColumn,column);
970 maxSelColumn=MAX(firstColumn,column); 970 maxSelColumn=MAX(firstColumn,column);
971 for(r=MIN(minSelRow,previousRow);r<=MAX(maxSelRow,previousRow);r++){ 971 for(r=MIN(minSelRow,previousRow);r<=MAX(maxSelRow,previousRow);r++){
972 for(c=MIN(minSelColumn,previousColumn);c<=MAX(maxSelColumn,previousColumn);c++){ 972 for(c=MIN(minSelColumn,previousColumn);c<=MAX(maxSelColumn,previousColumn);c++){
973 cell=[self cellAtRow:r column:c]; 973 cell=[self cellAtRow:r column:c];
974 974
975 if([cell isEnabled]){ 975 if([cell isEnabled]){
976 NSRect cellFrame=[self cellFrameAtRow:r column:c]; 976 NSRect cellFrame=[self cellFrameAtRow:r column:c];
977 BOOL inSelection=(r>=minSelRow && r<=maxSelRow && c>=minSelColumn && c<=maxSelColumn); 977 BOOL inSelection=(r>=minSelRow && r<=maxSelRow && c>=minSelColumn && c<=maxSelColumn);
978 BOOL highlight=inSelection?firstHighlight:!firstHighlight; 978 BOOL highlight=inSelection?firstHighlight:!firstHighlight;
979 979
980 [cell setState:highlight?NSOnState:NSOffState]; 980 [cell setState:highlight?NSOnState:NSOffState];
981 [cell setHighlighted:highlight]; 981 [cell setHighlighted:highlight];
982 [self _setSelectedIndexFromCell:cell]; 982 [self _setSelectedIndexFromCell:cell];
983 983
984 //[self setNeedsDisplay:YES]; 984 //[self setNeedsDisplay:YES];
985 [cell drawWithFrame:cellFrame inView:self]; 985 [cell drawWithFrame:cellFrame inView:self];
986 } 986 }
987 } 987 }
988 } 988 }
989 [self unlockFocus]; 989 [self unlockFocus];
990 [[self window] flushWindow]; 990 [[self window] flushWindow];
991 991
992 previousRow=row; 992 previousRow=row;
993 previousColumn=column; 993 previousColumn=column;
994 } 994 }
995 995
996 event=[[self window] nextEventMatchingMask:NSLeftMouseUpMask|NSLeftMouseDraggedMask|NSPeriodicMask]; 996 event=[[self window] nextEventMatchingMask:NSLeftMouseUpMask|NSLeftMouseDraggedMask|NSPeriodicMask];
997 if([event type]!=NSPeriodic) 997 if([event type]!=NSPeriodic)
998 lastMouse=event; 998 lastMouse=event;
999 }while([event type]!=NSLeftMouseUp); 999 }while([event type]!=NSLeftMouseUp);
1000 1000
1001 return result; 1001 return result;
1002 } 1002 }
1003 1003
1004 -(BOOL)_mouseDownTrack:(NSEvent *)event { 1004 -(BOOL)_mouseDownTrack:(NSEvent *)event {
1005 BOOL result=NO; 1005 BOOL result=NO;
1006 NSPoint point=[self convertPoint:[event locationInWindow] fromView:nil]; 1006 NSPoint point=[self convertPoint:[event locationInWindow] fromView:nil];
1007 int row,column; 1007 int row,column;
1008 NSCell *cell; 1008 NSCell *cell;
1009 1009
1010 [self lockFocus]; 1010 [self lockFocus];
1011 if((cell=[self _enabledCellAtPoint:point row:&row column:&column])!=nil){ 1011 if((cell=[self _enabledCellAtPoint:point row:&row column:&column])!=nil){
1012 NSRect cellFrame=[self cellFrameAtRow:row column:column]; 1012 NSRect cellFrame=[self cellFrameAtRow:row column:column];
1013 1013
1014 if([cell trackMouse:event inRect:cellFrame ofView:self untilMouseUp:YES]){ 1014 if([cell trackMouse:event inRect:cellFrame ofView:self untilMouseUp:YES]){
1015 [cell setState:[cell nextState]]; 1015 [cell setState:[cell nextState]];
1016 [self selectCell:cell]; 1016 [self selectCell:cell];
1017 } 1017 }
1018 result=YES; 1018 result=YES;
1019 } 1019 }
1020 [self unlockFocus]; 1020 [self unlockFocus];
1021 1021
1022 return result; 1022 return result;
1023 } 1023 }
1024 1024
1025 -(void)mouseDown:(NSEvent *)event { 1025 -(void)mouseDown:(NSEvent *)event {
1026 NSPoint point=[self convertPoint:[event locationInWindow] fromView:nil]; 1026 NSPoint point=[self convertPoint:[event locationInWindow] fromView:nil];
1027 int row,column; 1027 int row,column;
1028 BOOL sendAction=NO; 1028 BOOL sendAction=NO;
1029 1029
1030 if([self getRow:&row column:&column forPoint:point]){ 1030 if([self getRow:&row column:&column forPoint:point]){
1031 NSCell *cell=[self cellAtRow:row column:column]; 1031 NSCell *cell=[self cellAtRow:row column:column];
1032 1032
1033 if([cell isEditable]){ 1033 if([cell isEditable]){
1034 if([cell isEnabled]) 1034 if([cell isEnabled])
1035 [self _editTextCell:cell row:row column:column event:event]; 1035 [self _editTextCell:cell row:row column:column event:event];
1036 return; 1036 return;
1037 } 1037 }
1038 } 1038 }
1039 1039
1040 [NSEvent startPeriodicEventsAfterDelay:0.1 withPeriod:0.2]; 1040 [NSEvent startPeriodicEventsAfterDelay:0.1 withPeriod:0.2];
1041 1041
1042 switch([self mode]){ 1042 switch([self mode]){
1043 case NSRadioModeMatrix: sendAction=[self _mouseDownRadio:event]; break; 1043 case NSRadioModeMatrix: sendAction=[self _mouseDownRadio:event]; break;
1044 case NSHighlightModeMatrix: sendAction=[self _mouseDownHighlight:event]; break; 1044 case NSHighlightModeMatrix: sendAction=[self _mouseDownHighlight:event]; break;
1045 case NSListModeMatrix: sendAction=[self _mouseDownList:event]; break; 1045 case NSListModeMatrix: sendAction=[self _mouseDownList:event]; break;
1046 case NSTrackModeMatrix: sendAction=[self _mouseDownTrack:event]; break; 1046 case NSTrackModeMatrix: sendAction=[self _mouseDownTrack:event]; break;
1047 } 1047 }
1048 1048
1049 [NSEvent stopPeriodicEvents]; 1049 [NSEvent stopPeriodicEvents];
1050 1050
1051 if(sendAction){ 1051 if(sendAction){
1052 if([event clickCount]==2) 1052 if([event clickCount]==2)
1053 [self sendDoubleAction]; 1053 [self sendDoubleAction];
1054 else 1054 else
1055 [self sendAction]; 1055 [self sendAction];
1056 } 1056 }
1057 1057
1058 [[self window] flushWindow]; 1058 [[self window] flushWindow];
1059 } 1059 }
1060 1060
1061 // n.b. now moves to next/previous view on last/first cell, should not wrap (according to spec) 1061 // n.b. now moves to next/previous view on last/first cell, should not wrap (according to spec)
1062 - (void)insertTab:sender { 1062 - (void)insertTab:sender {
1063 BOOL selectNextKeyView = YES; 1063 BOOL selectNextKeyView = YES;
1064 1064
1065 if ([self tabKeyTraversesCells] && [self mode] != NSRadioModeMatrix){ 1065 if ([self tabKeyTraversesCells] && [self mode] != NSRadioModeMatrix){
1066 _keyCellIndex++; 1066 _keyCellIndex++;
1067 if(_keyCellIndex >= [_cells count]) 1067 if(_keyCellIndex >= [_cells count])
1068 _keyCellIndex = [_cells count]-1; 1068 _keyCellIndex = [_cells count]-1;
1069 else 1069 else
1070 selectNextKeyView = NO; 1070 selectNextKeyView = NO;
1071 1071
1072 [self setNeedsDisplay:YES]; 1072 [self setNeedsDisplay:YES];
1073 } 1073 }
1074 1074
1075 if (selectNextKeyView) 1075 if (selectNextKeyView)
1076 [[self window] selectNextKeyView:sender]; 1076 [[self window] selectNextKeyView:sender];
1077 } 1077 }
1078 1078
1079 - (void)insertBacktab:sender { 1079 - (void)insertBacktab:sender {
1080 BOOL selectPreviousKeyView = YES; 1080 BOOL selectPreviousKeyView = YES;
1081 1081
1082 if ([self tabKeyTraversesCells] && [self mode] != NSRadioModeMatrix){ 1082 if ([self tabKeyTraversesCells] && [self mode] != NSRadioModeMatrix){
1083 _keyCellIndex--; 1083 _keyCellIndex--;
1084 if(_keyCellIndex < 0) 1084 if(_keyCellIndex < 0)
1085 _keyCellIndex = 0; 1085 _keyCellIndex = 0;
1086 else 1086 else
1087 selectPreviousKeyView = NO; 1087 selectPreviousKeyView = NO;
1088 1088
1089 [self setNeedsDisplay:YES]; 1089 [self setNeedsDisplay:YES];
1090 } 1090 }
1091 1091
1092 if (selectPreviousKeyView) 1092 if (selectPreviousKeyView)
1093 [[self window] selectPreviousKeyView:sender]; 1093 [[self window] selectPreviousKeyView:sender];
1094 } 1094 }
1095 1095
1096 - (void)performClick:sender { 1096 - (void)performClick:sender {
1097 if([self mode]==NSHighlightModeMatrix){ 1097 if([self mode]==NSHighlightModeMatrix){
1098 NSCell *cell=[self keyCell]; 1098 NSCell *cell=[self keyCell];
1099 int nextState=[cell nextState]; 1099 int nextState=[cell nextState];
1100 1100
1101 [self selectCell:cell]; 1101 [self selectCell:cell];
1102 [cell setState:nextState]; 1102 [cell setState:nextState];
1103 [self drawCell:cell]; 1103 [self drawCell:cell];
1104 [self sendAction]; 1104 [self sendAction];
1105 return; 1105 return;
1106 } 1106 }
1107 } 1107 }
1108 1108
1109 - (void)keyDown:(NSEvent *)event { 1109 - (void)keyDown:(NSEvent *)event {
1110 [self interpretKeyEvents:[NSArray arrayWithObject:event]]; 1110 [self interpretKeyEvents:[NSArray arrayWithObject:event]];
1111 } 1111 }
1112 1112
1113 // bounds checking is done at selectCellAtRow:column: 1113 // bounds checking is done at selectCellAtRow:column:
1114 // revised to pass keyboard events down to cells if possible 1114 // revised to pass keyboard events down to cells if possible
1115 // hmm. if we're in radio mode, movement == selection 1115 // hmm. if we're in radio mode, movement == selection
1116 // otherwise, movement = keyboard focus 1116 // otherwise, movement = keyboard focus
1117 -(void)moveUp:sender { 1117 -(void)moveUp:sender {
1118 NSCell *nextCell = nil; 1118 NSCell *nextCell = nil;
1119 int row = -1, column = -1; 1119 int row = -1, column = -1;
1120 1120
1121 if ([self mode] == NSRadioModeMatrix) { 1121 if ([self mode] == NSRadioModeMatrix) {
1122 row = [self selectedRow]; 1122 row = [self selectedRow];
1123 column = [self selectedColumn]; 1123 column = [self selectedColumn];
1124 } 1124 }
1125 else 1125 else
1126 [self getRow:&row column:&column ofCell:[self keyCell]]; 1126 [self getRow:&row column:&column ofCell:[self keyCell]];
1127 1127
1128 nextCell = [self cellAtRow:row-1 column:column]; 1128 nextCell = [self cellAtRow:row-1 column:column];
1129 1129
1130 if (nextCell) { 1130 if (nextCell) {
1131 if ([self mode] == NSRadioModeMatrix) 1131 if ([self mode] == NSRadioModeMatrix)
1132 [self selectCell:nextCell]; 1132 [self selectCell:nextCell];
1133 1133
1134 [self setKeyCell:nextCell]; 1134 [self setKeyCell:nextCell];
1135 } 1135 }
1136 else if ([[self keyCell] respondsToSelector:@selector(moveUp:)]) 1136 else if ([[self keyCell] respondsToSelector:@selector(moveUp:)])
1137 [[self keyCell] moveUp:sender]; 1137 [[self keyCell] moveUp:sender];
1138 1138
1139 [self setNeedsDisplay:YES]; 1139 [self setNeedsDisplay:YES];
1140 } 1140 }
1141 1141
1142 -(void)moveDown:sender { 1142 -(void)moveDown:sender {
1143 NSCell *nextCell = nil; 1143 NSCell *nextCell = nil;
1144 int row = -1, column = -1; 1144 int row = -1, column = -1;
1145 1145
1146 if ([self mode] == NSRadioModeMatrix) { 1146 if ([self mode] == NSRadioModeMatrix) {
1147 row = [self selectedRow]; 1147 row = [self selectedRow];
1148 column = [self selectedColumn]; 1148 column = [self selectedColumn];
1149 } 1149 }
1150 else 1150 else
1151 [self getRow:&row column:&column ofCell:[self keyCell]]; 1151 [self getRow:&row column:&column ofCell:[self keyCell]];
1152 1152
1153 nextCell = [self cellAtRow:row+1 column:column]; 1153 nextCell = [self cellAtRow:row+1 column:column];
1154 1154
1155 if (nextCell) { 1155 if (nextCell) {
1156 if ([self mode] == NSRadioModeMatrix) 1156 if ([self mode] == NSRadioModeMatrix)
1157 [self selectCell:nextCell]; 1157 [self selectCell:nextCell];
1158 1158
1159 [self setKeyCell:nextCell]; 1159 [self setKeyCell:nextCell];
1160 } 1160 }
1161 else if ([[self keyCell] respondsToSelector:@selector(moveDown:)]) 1161 else if ([[self keyCell] respondsToSelector:@selector(moveDown:)])
1162 [[self keyCell] moveDown:sender]; 1162 [[self keyCell] moveDown:sender];
1163 1163
1164 [self setNeedsDisplay:YES]; 1164 [self setNeedsDisplay:YES];
1165 } 1165 }
1166 1166
1167 -(void)moveLeft:sender { 1167 -(void)moveLeft:sender {
1168 NSCell *nextCell = nil; 1168 NSCell *nextCell = nil;
1169 int row = -1, column = -1; 1169 int row = -1, column = -1;
1170 1170
1171 if ([self mode] == NSRadioModeMatrix) { 1171 if ([self mode] == NSRadioModeMatrix) {
1172 row = [self selectedRow]; 1172 row = [self selectedRow];
1173 column = [self selectedColumn]; 1173 column = [self selectedColumn];
1174 } 1174 }
1175 else 1175 else
1176 [self getRow:&row column:&column ofCell:[self keyCell]]; 1176 [self getRow:&row column:&column ofCell:[self keyCell]];
1177 1177
1178 nextCell = [self cellAtRow:row column:column-1]; 1178 nextCell = [self cellAtRow:row column:column-1];
1179 1179
1180 if (nextCell) { 1180 if (nextCell) {
1181 if ([self mode] == NSRadioModeMatrix) 1181 if ([self mode] == NSRadioModeMatrix)
1182 [self selectCell:nextCell]; 1182 [self selectCell:nextCell];
1183 1183
1184 [self setKeyCell:nextCell]; 1184 [self setKeyCell:nextCell];
1185 } 1185 }
1186 else if ([[self keyCell] respondsToSelector:@selector(moveLeft:)]) 1186 else if ([[self keyCell] respondsToSelector:@selector(moveLeft:)])
1187 [[self keyCell] moveLeft:sender]; 1187 [[self keyCell] moveLeft:sender];
1188 1188
1189 [self setNeedsDisplay:YES]; 1189 [self setNeedsDisplay:YES];
1190 } 1190 }
1191 1191
1192 -(void)moveRight:sender { 1192 -(void)moveRight:sender {
1193 NSCell *nextCell = nil; 1193 NSCell *nextCell = nil;
1194 int row = -1, column = -1; 1194 int row = -1, column = -1;
1195 1195
1196 if ([self mode] == NSRadioModeMatrix) { 1196 if ([self mode] == NSRadioModeMatrix) {
1197 row = [self selectedRow]; 1197 row = [self selectedRow];
1198 column = [self selectedColumn]; 1198 column = [self selectedColumn];
1199 } 1199 }
1200 else 1200 else
1201 [self getRow:&row column:&column ofCell:[self keyCell]]; 1201 [self getRow:&row column:&column ofCell:[self keyCell]];
1202 1202
1203 nextCell = [self cellAtRow:row column:column+1]; 1203 nextCell = [self cellAtRow:row column:column+1];
1204 1204
1205 if (nextCell) { 1205 if (nextCell) {
1206 if ([self mode] == NSRadioModeMatrix) 1206 if ([self mode] == NSRadioModeMatrix)
1207 [self selectCell:nextCell]; 1207 [self selectCell:nextCell];
1208 1208
1209 [self setKeyCell:nextCell]; 1209 [self setKeyCell:nextCell];
1210 } 1210 }
1211 else if ([[self keyCell] respondsToSelector:@selector(moveRight:)]) 1211 else if ([[self keyCell] respondsToSelector:@selector(moveRight:)])
1212 [[self keyCell] moveRight:sender]; 1212 [[self keyCell] moveRight:sender];
1213 1213
1214 [self setNeedsDisplay:YES]; 1214 [self setNeedsDisplay:YES];
1215 } 1215 }
1216 1216
1217 -(BOOL)becomeFirstResponder { 1217 -(BOOL)becomeFirstResponder {
1218 [self _selectTextCell:[self keyCell]]; 1218 [self _selectTextCell:[self keyCell]];
1219 1219
1220 return YES; 1220 return YES;
1221 } 1221 }
1222 1222
1223 -(void)textDidEndEditing:(NSNotification *)note { 1223 -(void)textDidEndEditing:(NSNotification *)note {
1224 int movement=[[[note userInfo] objectForKey:@"NSTextMovement"] intValue]; 1224 int movement=[[[note userInfo] objectForKey:@"NSTextMovement"] intValue];
1225 1225
1226 [super textDidEndEditing:note]; 1226 [super textDidEndEditing:note];
1227 1227
1228 if(movement==NSReturnTextMovement) 1228 if(movement==NSReturnTextMovement)
1229 [self sendAction]; 1229 [self sendAction];
1230 1230
1231 if(movement==NSTabTextMovement){ 1231 if(movement==NSTabTextMovement){
1232 1232
1233 _keyCellIndex++; 1233 _keyCellIndex++;
1234 if(_keyCellIndex>=[_cells count]){ 1234 if(_keyCellIndex>=[_cells count]){
1235 NSView *next=[self nextValidKeyView]; 1235 NSView *next=[self nextValidKeyView];
1236 1236
1237 _keyCellIndex=0; 1237 _keyCellIndex=0;
1238 1238
1239 if(next!=nil){ 1239 if(next!=nil){
1240 [[self window] makeFirstResponder:next]; 1240 [[self window] makeFirstResponder:next];
1241 return; 1241 return;
1242 } 1242 }
1243 } 1243 }
1244 if(_keyCellIndex>=[_cells count]) 1244 if(_keyCellIndex>=[_cells count])
1245 _keyCellIndex=-1; 1245 _keyCellIndex=-1;
1246 1246
1247 [self _selectTextCell:[self keyCell]]; 1247 [self _selectTextCell:[self keyCell]];
1248 } 1248 }
1249 } 1249 }
1250 1250
1251 @end 1251 @end
Powered by Google Project Hosting