40 @
typedef CPTitlePosition
58 CPBorderType _borderType;
66 + (Class)_binderClassForBinding:(
CPString)aBinding
68 if ([aBinding hasPrefix:CPDisplayPatternTitleBinding])
71 return [
super _binderClassForBinding:aBinding];
85 @"corner-radius": 3.0,
86 @"inner-shadow-offset": CGSizeMakeZero(),
87 @"inner-shadow-size": 6.0,
89 @"content-margin": CGSizeMakeZero(),
95 var box = [[
self alloc] initWithFrame:CGRectMakeZero()],
99 [box setFrameFromContentFrame:[aView
frame]];
101 [enclosingView replaceSubview:aView with:box];
103 [box setContentView:aView];
108 - (id)initWithFrame:(CGRect)frameRect
119 _contentView = [[
CPView alloc] initWithFrame:[
self bounds]];
120 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
153 - (CPBorderType)borderType
171 - (void)setBorderType:(CPBorderType)aBorderType
173 if (_borderType === aBorderType)
176 _borderType = aBorderType;
215 - (void)setBoxType:(CPBoxType)aBoxType
217 if (_boxType === aBoxType)
226 return [
self valueForThemeAttribute:@"border-color"];
231 if ([color
isEqual:[
self borderColor]])
239 return [
self valueForThemeAttribute:@"border-width"];
242 - (void)setBorderWidth:(
float)width
244 if (
width === [
self borderWidth])
250 - (float)cornerRadius
252 return [
self valueForThemeAttribute:@"corner-radius"];
255 - (void)setCornerRadius:(
float)radius
257 if (radius === [
self cornerRadius])
265 return [
self valueForThemeAttribute:@"background-color"];
270 if ([color
isEqual:[
self fillColor]])
283 if (aView === _contentView)
287 contentMargin = [
self valueForThemeAttribute:@"content-margin"];
289 [aView
setFrame:CGRectInset([
self bounds], contentMargin.width + borderWidth, contentMargin.height + borderWidth)];
294 [_contentView removeFromSuperview];
295 else if (_contentView)
300 _contentView = aView;
303 - (CGSize)contentViewMargins
305 return [
self valueForThemeAttribute:@"content-margin"];
308 - (void)setContentViewMargins:(CGSize)size
310 if (size.width < 0 || size.height < 0)
316 - (void)setFrameFromContentFrame:(CGRect)aRect
318 var offset = [
self _titleHeightOffset],
320 contentMargin = [
self valueForThemeAttribute:@"content-margin"];
322 [
self setFrame:CGRectInset(aRect, -(contentMargin.width + borderWidth), -(contentMargin.height + offset[0] + borderWidth))];
327 if (aTitle == _title)
332 [
self _manageTitlePositioning];
335 - (void)setTitlePosition:(
int)aTitlePotisition
337 if (aTitlePotisition == _titlePosition)
340 _titlePosition = aTitlePotisition;
342 [
self _manageTitlePositioning];
347 return [_titleView font];
352 [_titleView setFont:aFont];
365 - (void)_manageTitlePositioning
369 [_titleView removeFromSuperview];
370 [
self setNeedsDisplay:YES];
374 [_titleView setStringValue:_title];
375 [_titleView sizeToFit];
376 [
self addSubview:_titleView];
378 switch (_titlePosition)
383 [_titleView setFrameOrigin:CGPointMake(5.0, 0.0)];
384 [_titleView setAutoresizingMask:CPViewNotSizable];
390 var h = [_titleView frameSize].height;
391 [_titleView setFrameOrigin:CGPointMake(5.0, [
self frameSize].height - h)];
392 [_titleView setAutoresizingMask:CPViewMinYMargin];
397 [
self setNeedsDisplay:YES];
402 var contentFrame = [_contentView frame],
403 offset = [
self _titleHeightOffset],
404 contentMargin = [
self valueForThemeAttribute:@"content-margin"];
409 [_contentView setFrameOrigin:CGPointMake(contentMargin.width, contentMargin.height + offset[1])];
412 - (float)_titleHeightOffset
417 switch (_titlePosition)
420 return [[_titleView frameSize].height, [_titleView frameSize].height];
423 return [[_titleView frameSize].height, 0.0];
432 if (aKey === CPDisplayPatternTitleBinding)
435 [
super setValue:aValue forKey:aKey];
438 - (void)drawRect:(CGRect)rect
447 if (CGRectGetWidth(
bounds) === 5.0)
448 return [
self _drawVerticalSeparatorInRect:bounds];
449 else if (CGRectGetHeight(
bounds) === 5.0)
450 return [
self _drawHorizontalSeparatorInRect:bounds];
457 bounds.origin.y += [_titleView frameSize].height;
458 bounds.size.height -= [_titleView frameSize].height;
462 bounds.size.height -= [_titleView frameSize].height;
468 [
self _drawPrimaryBorderInRect:bounds];
475 [
self _drawBezelBorderInRect:bounds];
480 [
self _drawLineBorderInRect:bounds];
484 [
self _drawNoBorderInRect:bounds];
489 - (void)_drawHorizontalSeparatorInRect:(CGRect)aRect
501 - (void)_drawVerticalSeparatorInRect:(CGRect)aRect
513 - (void)_drawLineBorderInRect:(CGRect)aRect
516 cornerRadius = [
self cornerRadius],
517 borderWidth = [
self borderWidth];
519 aRect = CGRectInset(aRect, borderWidth / 2.0, borderWidth / 2.0);
529 - (void)_drawBezelBorderInRect:(CGRect)aRect
532 cornerRadius = [
self cornerRadius],
533 borderWidth = [
self borderWidth],
534 shadowOffset = [
self valueForThemeAttribute:@"inner-shadow-offset"],
535 shadowSize = [
self valueForThemeAttribute:@"inner-shadow-size"],
536 shadowColor = [
self valueForThemeAttribute:@"inner-shadow-color"];
538 var baseRect = aRect;
539 aRect = CGRectInset(aRect, borderWidth / 2.0, borderWidth / 2.0);
552 - (void)_drawPrimaryBorderInRect:(CGRect)aRect
557 cornerRadius = [
self cornerRadius],
558 borderWidth = [
self borderWidth],
559 shadowOffset = [
self valueForThemeAttribute:@"inner-shadow-offset"],
560 shadowSize = [
self valueForThemeAttribute:@"inner-shadow-size"],
561 shadowColor = [
self valueForThemeAttribute:@"inner-shadow-color"],
564 aRect = CGRectInset(aRect, borderWidth / 2.0, borderWidth / 2.0);
577 CGContextClip(context);
584 - (void)_drawNoBorderInRect:(CGRect)aRect
609 _boxType = [aCoder decodeIntForKey:CPBoxTypeKey];
610 _borderType = [aCoder decodeIntForKey:CPBoxBorderTypeKey];
612 _title = [aCoder decodeObjectForKey:CPBoxTitle];
613 _titlePosition = [aCoder decodeIntForKey:CPBoxTitlePosition];
625 _contentView = [aCoder decodeObjectForKey:CPBoxContentView] || [[
CPView alloc] initWithFrame:[
self bounds]];
626 var malformedContentView = [
self subviews][0];
627 [_contentView setSubviews:[malformedContentView subviews]];
636 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
638 [
self _manageTitlePositioning];
648 [aCoder encodeInt:_boxType forKey:CPBoxTypeKey];
649 [aCoder encodeInt:_borderType forKey:CPBoxBorderTypeKey];
650 [aCoder encodeObject:_title forKey:CPBoxTitle];
651 [aCoder encodeInt:_titlePosition forKey:CPBoxTitlePosition];
652 [aCoder encodeObject:_titleView forKey:CPBoxTitleView];
653 [aCoder encodeObject:_contentView forKey:CPBoxContentView];
673 return _titlePosition;
id initWithFrame:(CGRect aFrame)
Used to implement exception handling (creating & raising).
function CGContextSetShadowWithColor(aContext, aSize, aBlur, aColor)
void addSubview:(CPView aSubview)
function CGPathWithRoundedRectangleInRect(aRect, xRadius, yRadius, ne, se, sw, nw)
CPGraphicsContext currentContext()
An object representation of nil.
id initWithCoder:(CPCoder aCoder)
function CGContextSetStrokeColor(aContext, aColor)
void setFrame:(CGRect aFrame)
function CGContextRestoreGState(aContext)
void raise:reason:(CPString aName, [reason] CPString aReason)
void replaceSubview:with:(CPView aSubview, [with] CPView aView)
function CGContextAddLineToPoint(aContext, x, y)
void setValue:forThemeAttribute:(id aValue, [forThemeAttribute] CPString aName)
function CGContextStrokePath(aContext)
A mutable key-value pair collection.
function CGContextSetLineWidth(aContext, aLineWidth)
An immutable string (collection of characters).
function CGContextAddPath(aContext, aPath)
function CGContextSetFillColor(aContext, aColor)
void setAutoresizingMask:(unsigned aMask)
void setNeedsDisplay:(BOOL aFlag)
void encodeWithCoder:(CPCoder aCoder)
function CGContextStrokeRoundedRectangleInRect(aContext, aRect, aRadius, ne, se, sw, nw)
function CGContextBeginPath(aContext)
void setAutoresizesSubviews:(BOOL aFlag)
CPTitlePosition CPNoTitle
Defines methods for use when archiving & restoring (enc/decoding).
CPTextField labelWithTitle:(CPString aTitle)
function CGContextSaveGState(aContext)
void setTitle:(CPString aTitle)
function CGContextFillRoundedRectangleInRect(aContext, aRect, aRadius, ne, se, sw, nw)
function CGContextFillRect(aContext, aRect)
unsigned autoresizingMask()
function CGContextMoveToPoint(aContext, x, y)