-
Notifications
You must be signed in to change notification settings - Fork 1
/
PDButtonColorWell.m
84 lines (65 loc) · 1.8 KB
/
PDButtonColorWell.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// PDButtonColorWell.m
// SproutedInterface
//
// Created by Philip Dow on 1/7/06.
// Copyright Sprouted. All rights reserved.
// Inquiries should be directed to [email protected]
//
#import <SproutedInterface/PDButtonColorWell.h>
#import <SproutedInterface/PDButtonColorWellCell.h>
@implementation PDButtonColorWell
- (id)initWithCoder:(NSCoder *)decoder {
if ( self = [super initWithCoder:decoder] ) {
NSArchiver * anArchiver = [[[NSArchiver alloc] initForWritingWithMutableData:[NSMutableData dataWithCapacity: 256]] autorelease];
[anArchiver encodeClassName:@"NSButtonCell" intoClassName:@"PDButtonColorWellCell"];
[anArchiver encodeRootObject:[self cell]];
[self setCell:[NSUnarchiver unarchiveObjectWithData:[anArchiver archiverData]]];
}
return self;
}
- (void) dealloc
{
[defaultsKey release];
[super dealloc];
}
+ (Class) cellClass
{
return [PDButtonColorWellCell class];
}
- (BOOL) isFlipped
{
return YES;
}
- (NSColor*) color
{
return [[self cell] color];
}
- (void) setColor:(NSColor*)color
{
[self willChangeValueForKey:@"color"];
[[self cell] setColor:color];
[self didChangeValueForKey:@"color"];
[self setNeedsDisplay:YES];
}
- (NSString*) defaultsKey
{
return defaultsKey;
}
- (void) setDefaultsKey:(NSString*)aKey
{
if ( defaultsKey != aKey )
{
[self willChangeValueForKey:@"defaultsKey"];
[defaultsKey release];
defaultsKey = [aKey copyWithZone:[self zone]];
[self didChangeValueForKey:@"defaultsKey"];
[self unbind:@"color"];
[self bind:@"color"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:[NSString stringWithFormat:@"values.%@",defaultsKey]
options:[NSDictionary dictionaryWithObjectsAndKeys:
NSUnarchiveFromDataTransformerName, NSValueTransformerNameBindingOption, nil]];
}
}
@end