diff --git a/AppKit/CPBox.j b/AppKit/CPBox.j index 05500b550..bdbad5212 100644 --- a/AppKit/CPBox.j +++ b/AppKit/CPBox.j @@ -19,7 +19,8 @@ * 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 "CPGraphics.j" @import "CPView.j" // CPBorderType @@ -71,6 +72,9 @@ CPGrooveBorder = 3; _contentView = [[CPView alloc] initWithFrame:[self bounds]]; [self addSubview:_contentView]; + + [_contentView setAutoresizesSubviews:YES]; + [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; } return self; @@ -164,6 +168,9 @@ CPGrooveBorder = 3; [self replaceSubview:_contentView with:aView]; _contentView = aView; + + [_contentView setAutoresizesSubviews:YES]; + [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; } - (CPSize)contentViewMargins @@ -199,7 +206,7 @@ CPGrooveBorder = 3; - (void)drawRect:(CPRect)rect { var bounds = [self bounds], - aContext = [[CPGraphicsContext currentContext] graphicsPort], + context = [[CPGraphicsContext currentContext] graphicsPort], border2 = _borderWidth/2, strokeRect = CGRectMake(bounds.origin.x + border2, @@ -212,33 +219,80 @@ CPGrooveBorder = 3; bounds.size.width - _borderWidth, bounds.size.height - _borderWidth); - CGContextSetFillColor(aContext, [self fillColor]); - CGContextSetStrokeColor(aContext, [self borderColor]); - CGContextSetLineWidth(aContext, _borderWidth); + CGContextSetFillColor(context, [self fillColor]); + CGContextSetStrokeColor(context, [self borderColor]); + CGContextSetLineWidth(context, _borderWidth); switch(_borderType) { - case CPLineBorder: CGContextFillRoundedRectangleInRect(aContext, fillRect, _cornerRadius, YES, YES, YES, YES); - CGContextStrokeRoundedRectangleInRect(aContext, strokeRect, _cornerRadius, YES, YES, YES, YES); - break; + case CPNoBorder: + case CPLineBorder: + CGContextFillRoundedRectangleInRect(context, fillRect, _cornerRadius, YES, YES, YES, YES); + + if (_borderType === CPLineBorder) + CGContextStrokeRoundedRectangleInRect(context, strokeRect, _cornerRadius, YES, YES, YES, YES); + break; - case CPBezelBorder: CGContextFillRoundedRectangleInRect(aContext, fillRect, _cornerRadius, YES, YES, YES, YES); - CGContextSetStrokeColor(aContext, [CPColor colorWithWhite:190.0/255.0 alpha:1.0]); - CGContextBeginPath(aContext); - CGContextMoveToPoint(aContext, strokeRect.origin.x, strokeRect.origin.y); - CGContextAddLineToPoint(aContext, CGRectGetMinX(strokeRect), CGRectGetMaxY(strokeRect)), - CGContextAddLineToPoint(aContext, CGRectGetMaxX(strokeRect), CGRectGetMaxY(strokeRect)), - CGContextAddLineToPoint(aContext, CGRectGetMaxX(strokeRect), CGRectGetMinY(strokeRect)), - CGContextStrokePath(aContext); - CGContextSetStrokeColor(aContext, [CPColor colorWithWhite:142.0/255.0 alpha:1.0]); - CGContextBeginPath(aContext); - CGContextMoveToPoint(aContext, bounds.origin.x, strokeRect.origin.y); - CGContextAddLineToPoint(aContext, CGRectGetMaxX(bounds), CGRectGetMinY(strokeRect)); - CGContextStrokePath(aContext); - break; + case CPBezelBorder: + CGContextFillRoundedRectangleInRect(context, fillRect, _cornerRadius, YES, YES, YES, YES); + CPDrawGrayBezel(fillRect); + break; - default: break; + default: + break; } } @end + +var CPBoxBorderTypeKey = @"CPBoxBorderTypeKey", + CPBoxBorderColorKey = @"CPBoxBorderColorKey", + CPBoxFillColorKey = @"CPBoxFillColorKey", + CPBoxCornerRadiusKey = @"CPBoxCornerRadiusKey", + CPBoxBorderWidthKey = @"CPBoxBorderWidthKey", + CPBoxContentMarginKey = @"CPBoxContentMarginKey"; + +@implementation CPBox (CPCoding) + +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super initWithCoder:aCoder]; + + if (self) + { + _borderType = [aCoder decodeIntForKey:CPBoxBorderTypeKey]; + + _borderColor = [aCoder decodeObjectForKey:CPBoxBorderColorKey]; + _fillColor = [aCoder decodeObjectForKey:CPBoxFillColorKey]; + + _cornerRadius = [aCoder decodeFloatForKey:CPBoxCornerRadiusKey]; + _borderWidth = [aCoder decodeFloatForKey:CPBoxBorderWidthKey]; + + _contentMargin = [aCoder decodeSizeForKey:CPBoxContentMarginKey]; + + _contentView = [self subviews][0]; + + [self setAutoresizesSubviews:YES]; + [_contentView setAutoresizesSubviews:YES]; + [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; + } + + return self; +} + +- (void)encodeWithCoder:(CPCoder)aCoder +{ + [super encodeWithCoder:aCoder]; + + [aCoder encodeInt:_borderType forKey:CPBoxBorderTypeKey]; + + [aCoder encodeObject:_borderColor forKey:CPBoxBorderColorKey]; + [aCoder encodeObject:_fillColor forKey:CPBoxFillColorKey]; + + [aCoder encodeFloat:_cornerRadius forKey:CPBoxCornerRadiusKey]; + [aCoder encodeFloat:_borderWidth forKey:CPBoxBorderWidthKey]; + + [aCoder encodeSize:_contentMargin forKey:CPBoxContentMarginKey]; +} + +@end diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j index 96a3a52b8..4673e3439 100644 --- a/Tools/nib2cib/NSAppKit.j +++ b/Tools/nib2cib/NSAppKit.j @@ -21,6 +21,7 @@ */ @import "_NSCornerView.j" +@import "NSBox.j" @import "NSButton.j" @import "NSCell.j" @import "NSClassSwapper.j" diff --git a/Tools/nib2cib/NSBox.j b/Tools/nib2cib/NSBox.j new file mode 100644 index 000000000..62a97ea42 --- /dev/null +++ b/Tools/nib2cib/NSBox.j @@ -0,0 +1,63 @@ +/* + * NSBox.j + * nib2cib + * + * Created by Aparajita Fishman. + * + * 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 + + +@implementation CPBox (CPCoding) + +- (id)NS_initWithCoder:(CPCoder)aCoder +{ + self = [super NS_initWithCoder:aCoder]; + + if (self) + { + _borderType = [aCoder decodeIntForKey:@"NSBorderType"]; + + _borderColor = [aCoder decodeObjectForKey:@"NSBorderColor2"] || [CPColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.42]; + _fillColor = [aCoder decodeObjectForKey:@"NSFillColor2"] || [CPColor clearColor]; + + _cornerRadius = [aCoder decodeFloatForKey:@"NSCornerRadius2"] || 0.0; + _borderWidth = [aCoder decodeFloatForKey:@"NSBorderWidth2"] || 1.0; + + _contentMargin = [aCoder decodeSizeForKey:@"NSOffsets"]; + } + + return self; +} + +@end + +@implementation NSBox : CPBox +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self NS_initWithCoder:aCoder]; +} + +- (Class)classForKeyedArchiver +{ + return [CPBox class]; +} + +@end