diff --git a/AppKit/CPColorWell.j b/AppKit/CPColorWell.j index e1cdd1dbc6..d2a16d1d99 100644 --- a/AppKit/CPColorWell.j +++ b/AppKit/CPColorWell.j @@ -38,6 +38,7 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv @implementation CPColorWell : CPControl { BOOL _active; + BOOL _bordered; CPColor _color; CPView _wellView; @@ -50,30 +51,56 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv if (self) { _active = NO; - + _bordered = YES; _color = [CPColor whiteColor]; [self drawBezelWithHighlight:NO]; [self drawWellInside:CGRectInset([self bounds], 3.0, 3.0)]; - var defaultCenter = [CPNotificationCenter defaultCenter]; - - [defaultCenter - addObserver:self - selector:@selector(colorWellDidBecomeExclusive:) - name:_CPColorWellDidBecomeExclusiveNotification - object:nil]; - - [defaultCenter - addObserver:self - selector:@selector(colorPanelWillClose:) - name:CPWindowWillCloseNotification - object:[CPColorPanel sharedColorPanel]]; + [self _registerForNotifications]; } return self; } +- (void)_registerForNotifications +{ + var defaultCenter = [CPNotificationCenter defaultCenter]; + + [defaultCenter + addObserver:self + selector:@selector(colorWellDidBecomeExclusive:) + name:_CPColorWellDidBecomeExclusiveNotification + object:nil]; + + [defaultCenter + addObserver:self + selector:@selector(colorPanelWillClose:) + name:CPWindowWillCloseNotification + object:[CPColorPanel sharedColorPanel]]; +} + +/*! + Returns whether the color well is bordered +*/ +- (BOOL)isBordered +{ + return _bordered; +} + +/*! + Sets the color well's current color. +*/ +- (void)setBordered:(BOOL)bordered +{ + if (_bordered == bordered) + return; + + _bordered = bordered; + + [self drawWellInside:CGRectInset([self bounds], 3.0, 3.0)]; +} + // Managing Color From Color Wells /*! @@ -226,3 +253,51 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv } @end + +var CPColorWellColorKey = "CPColorWellColorKey", + CPColorWellBorderedKey = "CPColorWellBorderedKey"; + +@implementation CPColorWell (CPCoding) + +/*! + Initializes the color well by unarchiving data from aCoder. + @param aCoder the coder containing the archived CPColorWell. +*/ +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super initWithCoder:aCoder]; + + if (self) + { + _active = NO; + _bordered = [aCoder decodeObjectForKey:CPColorWellBorderedKey]; + _color = [aCoder decodeObjectForKey:CPColorWellColorKey]; + + [self _registerForNotifications]; + } + + return self; +} + +/*! + Archives this button into the provided coder. + @param aCoder the coder to which the color well's instance data will be written. +*/ +- (void)encodeWithCoder:(CPCoder)aCoder +{ + // We do this in order to avoid encoding the _wellView, which + // should just automatically be created programmatically as needed. + var actualSubviews = _subviews; + + _subviews = [_subviews copy]; + [_subviews removeObjectIdenticalTo:_wellView]; + + [super encodeWithCoder:aCoder]; + + _subviews = actualSubviews; + + [aCoder encodeObject:_color forKey:CPColorWellColorKey]; + [aCoder encodeObject:_bordered forKey:CPColorWellBorderedKey]; +} + +@end diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j index 21117449c6..1a7c357b9f 100644 --- a/Tools/nib2cib/NSAppKit.j +++ b/Tools/nib2cib/NSAppKit.j @@ -23,6 +23,7 @@ @import "NSButton.j" @import "NSCell.j" @import "NSColor.j" +@import "NSColorWell.j" @import "NSControl.j" @import "NSCustomObject.j" @import "NSCustomView.j" diff --git a/Tools/nib2cib/NSColorWell.j b/Tools/nib2cib/NSColorWell.j new file mode 100644 index 0000000000..d427f04f7d --- /dev/null +++ b/Tools/nib2cib/NSColorWell.j @@ -0,0 +1,60 @@ +/* + * NSColorWell.j + * nib2cib + * + * Created by Thomas Robinson. + * Copyright 2008, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import + +@import "NSCell.j" +@import "NSControl.j" + + +@implementation CPColorWell (NSCoding) + +- (id)NS_initWithCoder:(CPCoder)aCoder +{ + self = [super NS_initWithCoder:aCoder]; + + if (self) + { + [self setBordered:[aCoder decodeBoolForKey:"NSIsBordered"]]; + [self setColor:[aCoder decodeBoolForKey:"NSColor"]]; + } + + return self; +} + +@end + +@implementation NSColorWell : CPColorWell +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self NS_initWithCoder:aCoder]; +} + +- (Class)classForKeyedArchiver +{ + return [CPColorWell class]; +} + +@end