26 var _CPColorWellDidBecomeExclusiveNotification =
@"_CPColorWellDidBecomeExclusiveNotification";
44 + (Class)_binderClassForBinding:(
CPString)aBinding
46 if (aBinding == CPValueBinding)
49 return [
super _binderClassForBinding:aBinding];
60 @"bezel-inset": CGInsetMakeZero(),
62 @"content-inset": CGInsetMake(3.0, 3.0, 3.0, 3.0),
63 @"content-border-inset": CGInsetMakeZero(),
68 - (void)_reverseSetBinding
70 var binderClass = [[
self class] _binderClassForBinding:CPValueBinding],
71 theBinding = [binderClass getBinding:CPValueBinding forObject:self];
73 [theBinding reverseSetValueFor:@"color"];
76 - (id)initWithFrame:(CGRect)aFrame
86 [
self _registerForNotifications];
92 - (void)_registerForNotifications
98 selector:@selector(colorWellDidBecomeExclusive:)
99 name:_CPColorWellDidBecomeExclusiveNotification
104 selector:@selector(colorPanelWillClose:)
105 name:CPWindowWillCloseNotification
112 - (void)setBordered:(BOOL)shouldBeBordered
114 if (shouldBeBordered)
115 [
self setThemeState:CPThemeStateBordered];
117 [
self unsetThemeState:CPThemeStateBordered];
125 return [
self hasThemeState:CPThemeStateBordered];
143 if (_color == aColor)
148 [
self setNeedsLayout];
155 - (void)takeColorFrom:(
id)aSender
166 - (void)activate:(BOOL)shouldBeExclusive
168 if (shouldBeExclusive)
183 name:CPColorPanelColorDidChangeNotification
192 if (![
self isActive])
199 name:CPColorPanelColorDidChangeNotification
220 if (
self != [aNotification
object])
229 - (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
233 if (!mouseIsUp || !CGRectContainsPoint([
self bounds], aPoint) || ![
self isEnabled])
240 [colorPanel setColor:_color];
241 [colorPanel orderFront:self];
244 - (CGRect)contentRectForBounds:(CGRect)bounds
246 var contentInset = [
self currentValueForThemeAttribute:@"content-inset"];
248 return CGRectInsetByInset(bounds, contentInset);
251 - (CGRect)bezelRectForBounds:(CGRect)bounds
253 var bezelInset = [
self currentValueForThemeAttribute:@"bezel-inset"];
255 return CGRectInsetByInset(bounds, bezelInset);
258 - (CGRect)contentBorderRectForBounds:(CGRect)bounds
260 var contentBorderInset = [
self currentValueForThemeAttribute:@"content-border-inset"];
262 return CGRectInsetByInset(bounds, contentBorderInset);
265 - (CGRect)rectForEphemeralSubviewNamed:(
CPString)aName
273 case "content-border-view":
277 return [
super rectForEphemeralSubviewNamed:aName];
282 var view = [[
CPView alloc] initWithFrame:CGRectMakeZero()];
284 [view setHitTests:NO];
289 - (void)layoutSubviews
291 var bezelView = [
self layoutEphemeralSubviewNamed:@"bezel-view"
292 positioned:CPWindowBelow
293 relativeToEphemeralSubviewNamed:@"content-view"];
295 [bezelView setBackgroundColor:[
self currentValueForThemeAttribute:@"bezel-color"]];
297 var contentView = [
self layoutEphemeralSubviewNamed:@"content-view"
298 positioned:CPWindowAbove
299 relativeToEphemeralSubviewNamed:@"bezel-view"];
302 [contentView setBackgroundColor:_color];
304 var contentBorderView = [
self layoutEphemeralSubviewNamed:@"content-border-view"
305 positioned:CPWindowAbove
306 relativeToEphemeralSubviewNamed:@"content-view"];
308 [contentBorderView setBackgroundColor:[
self currentValueForThemeAttribute:@"content-border-color"]];
317 - (void)_updatePlaceholdersWithOptions:(
CPDictionary)options
321 [
self _setPlaceholder:placeholderColor forMarker:CPMultipleValuesMarker isDefault:YES];
322 [
self _setPlaceholder:placeholderColor forMarker:CPNoSelectionMarker isDefault:YES];
323 [
self _setPlaceholder:placeholderColor forMarker:CPNotApplicableMarker isDefault:YES];
324 [
self _setPlaceholder:placeholderColor forMarker:CPNullMarker isDefault:YES];
329 return [_source color];
332 - (void)setValue:(
id)aValue forBinding:(
CPString)theBinding
334 [_source setColor:aValue];
337 - (void)setPlaceholderValue:(
id)aValue withMarker:(
CPString)aMarker forBinding:(
CPString)aBinding
339 [_source setColor:aValue];
360 _color = [aCoder decodeObjectForKey:CPColorWellColorKey];
361 [
self setBordered:[aCoder decodeBoolForKey:CPColorWellBorderedKey]];
363 [
self _registerForNotifications];
377 [aCoder encodeObject:_color forKey:CPColorWellColorKey];
378 [aCoder encodeObject:[
self isBordered] forKey:CPColorWellBorderedKey];