-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSSMatrixButtons.m
45 lines (36 loc) · 1.21 KB
/
SSMatrixButtons.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#import "SSMatrixButtons.h"
@implementation SSMatrixButtons
SSANm(NSInteger, tagOffset, setTagOffset)
// Over-rides of NSMatrix methods
// The objectValue is an NSArray of NSNumbers of buttons which are pushed
- (NSArray*)objectValue {
NSMutableArray* pushedButtonIndexes = [[NSMutableArray alloc] init] ;
NSEnumerator* e = [[self cells] objectEnumerator] ;
NSCell* cell ;
while ((cell = [e nextObject])) {
if ([[cell objectValue] boolValue]) {
NSNumber* value = [NSNumber numberWithInteger:([cell tag] + _tagOffset)] ;
[pushedButtonIndexes addObject:value] ;
}
}
NSArray* output = [pushedButtonIndexes copy] ;
[pushedButtonIndexes release] ;
return [output autorelease] ;
}
- (void)setObjectValue:(NSArray*)pushedButtonIndexes {
NSEnumerator* e = [[self cells] objectEnumerator] ;
NSCell* cell ;
while ((cell = [e nextObject])) {
NSNumber* cellKey = [NSNumber numberWithInteger:([cell tag] + _tagOffset)] ;
BOOL active = ([pushedButtonIndexes indexOfObject:cellKey] != NSNotFound) ;
NSNumber* value = [NSNumber numberWithBool:active] ;
[cell setObjectValue:value] ;
}
}
- (id)initWithCoder:(NSCoder*)coder {
if ((self = [super initWithCoder:coder])) {
_tagOffset = 0 ;
}
return self ;
}
@end