56 CPBorderType _borderType;
64 + (Class)_binderClassForBinding:(
CPString)aBinding
66 if ([aBinding hasPrefix:CPDisplayPatternTitleBinding])
69 return [
super _binderClassForBinding:aBinding];
83 @"corner-radius": 3.0,
84 @"inner-shadow-offset": CGSizeMakeZero(),
85 @"inner-shadow-size": 6.0,
87 @"content-margin": CGSizeMakeZero(),
93 var box = [[
self alloc] initWithFrame:CGRectMakeZero()],
94 enclosingView = [aView superview];
96 [box setAutoresizingMask:[aView autoresizingMask]];
97 [box setFrameFromContentFrame:[aView frame]];
99 [enclosingView replaceSubview:aView with:box];
101 [box setContentView:aView];
106 - (id)initWithFrame:(CGRect)frameRect
108 self = [
super initWithFrame:frameRect];
117 _contentView = [[
CPView alloc] initWithFrame:[
self bounds]];
118 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
120 [
self setAutoresizesSubviews:YES];
121 [
self addSubview:_contentView];
136 return [
self bounds];
151 - (CPBorderType)borderType
169 - (void)setBorderType:(CPBorderType)aBorderType
171 if (_borderType === aBorderType)
174 _borderType = aBorderType;
175 [
self setNeedsDisplay:YES];
213 - (void)setBoxType:(CPBoxType)aBoxType
215 if (_boxType === aBoxType)
219 [
self setNeedsDisplay:YES];
224 return [
self valueForThemeAttribute:@"border-color"];
229 if ([color
isEqual:[
self borderColor]])
232 [
self setValue:color forThemeAttribute:@"border-color"];
237 return [
self valueForThemeAttribute:@"border-width"];
240 - (void)setBorderWidth:(
float)width
242 if (
width === [
self borderWidth])
245 [
self setValue:width forThemeAttribute:@"border-width"];
248 - (float)cornerRadius
250 return [
self valueForThemeAttribute:@"corner-radius"];
253 - (void)setCornerRadius:(
float)radius
255 if (radius === [
self cornerRadius])
258 [
self setValue:radius forThemeAttribute:@"corner-radius"];
263 return [
self valueForThemeAttribute:@"background-color"];
268 if ([color
isEqual:[
self fillColor]])
271 [
self setValue:color forThemeAttribute:@"background-color"];
281 if (aView === _contentView)
285 contentMargin = [
self valueForThemeAttribute:@"content-margin"];
287 [aView setFrame:CGRectInset([
self bounds], contentMargin.width + borderWidth, contentMargin.height + borderWidth)];
288 [aView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
292 [_contentView removeFromSuperview];
293 else if (_contentView)
294 [
self replaceSubview:_contentView with:aView];
296 [
self addSubview:aView];
298 _contentView = aView;
301 - (CGSize)contentViewMargins
303 return [
self valueForThemeAttribute:@"content-margin"];
306 - (void)setContentViewMargins:(CGSize)size
308 if (size.width < 0 || size.height < 0)
311 [
self setValue:CGSizeMakeCopy(size) forThemeAttribute:@"content-margin"];
314 - (void)setFrameFromContentFrame:(CGRect)aRect
316 var offset = [
self _titleHeightOffset],
318 contentMargin = [
self valueForThemeAttribute:@"content-margin"];
320 [
self setFrame:CGRectInset(aRect, -(contentMargin.width + borderWidth), -(contentMargin.height + offset[0] + borderWidth))];
325 if (aTitle == _title)
330 [
self _manageTitlePositioning];
333 - (void)setTitlePosition:(
int)aTitlePotisition
335 if (aTitlePotisition == _titlePosition)
338 _titlePosition = aTitlePotisition;
340 [
self _manageTitlePositioning];
345 return [_titleView font];
350 [_titleView setFont:aFont];
363 - (void)_manageTitlePositioning
367 [_titleView removeFromSuperview];
368 [
self setNeedsDisplay:YES];
372 [_titleView setStringValue:_title];
373 [_titleView sizeToFit];
374 [
self addSubview:_titleView];
376 switch (_titlePosition)
381 [_titleView setFrameOrigin:CGPointMake(5.0, 0.0)];
382 [_titleView setAutoresizingMask:CPViewNotSizable];
388 var h = [_titleView frameSize].height;
389 [_titleView setFrameOrigin:CGPointMake(5.0, [
self frameSize].height - h)];
390 [_titleView setAutoresizingMask:CPViewMinYMargin];
395 [
self setNeedsDisplay:YES];
400 var contentFrame = [_contentView frame],
401 offset = [
self _titleHeightOffset],
402 contentMargin = [
self valueForThemeAttribute:@"content-margin"];
407 [_contentView setFrameOrigin:CGPointMake(contentMargin.width, contentMargin.height + offset[1])];
410 - (float)_titleHeightOffset
415 switch (_titlePosition)
418 return [[_titleView frameSize].height, [_titleView frameSize].height];
421 return [[_titleView frameSize].height, 0.0];
430 if (aKey === CPDisplayPatternTitleBinding)
433 [
super setValue:aValue forKey:aKey];
436 - (void)drawRect:(CGRect)rect
438 var bounds = [
self bounds];
445 if (CGRectGetWidth(bounds) === 5.0)
446 return [
self _drawVerticalSeparatorInRect:bounds];
447 else if (CGRectGetHeight(bounds) === 5.0)
448 return [
self _drawHorizontalSeparatorInRect:bounds];
455 bounds.origin.y += [_titleView frameSize].height;
456 bounds.size.height -= [_titleView frameSize].height;
460 bounds.size.height -= [_titleView frameSize].height;
466 [
self _drawPrimaryBorderInRect:bounds];
473 [
self _drawBezelBorderInRect:bounds];
478 [
self _drawLineBorderInRect:bounds];
482 [
self _drawNoBorderInRect:bounds];
487 - (void)_drawHorizontalSeparatorInRect:(CGRect)aRect
499 - (void)_drawVerticalSeparatorInRect:(CGRect)aRect
511 - (void)_drawLineBorderInRect:(CGRect)aRect
514 cornerRadius = [
self cornerRadius],
515 borderWidth = [
self borderWidth];
517 aRect = CGRectInset(aRect, borderWidth / 2.0, borderWidth / 2.0);
527 - (void)_drawBezelBorderInRect:(CGRect)aRect
530 cornerRadius = [
self cornerRadius],
531 borderWidth = [
self borderWidth],
532 shadowOffset = [
self valueForThemeAttribute:@"inner-shadow-offset"],
533 shadowSize = [
self valueForThemeAttribute:@"inner-shadow-size"],
534 shadowColor = [
self valueForThemeAttribute:@"inner-shadow-color"];
536 var baseRect = aRect;
537 aRect = CGRectInset(aRect, borderWidth / 2.0, borderWidth / 2.0);
550 - (void)_drawPrimaryBorderInRect:(CGRect)aRect
555 cornerRadius = [
self cornerRadius],
556 borderWidth = [
self borderWidth],
557 shadowOffset = [
self valueForThemeAttribute:@"inner-shadow-offset"],
558 shadowSize = [
self valueForThemeAttribute:@"inner-shadow-size"],
559 shadowColor = [
self valueForThemeAttribute:@"inner-shadow-color"],
562 aRect = CGRectInset(aRect, borderWidth / 2.0, borderWidth / 2.0);
575 CGContextClip(context);
582 - (void)_drawNoBorderInRect:(CGRect)aRect
602 self = [
super initWithCoder:aCoder];
606 _boxType = [aCoder decodeIntForKey:CPBoxTypeKey];
607 _borderType = [aCoder decodeIntForKey:CPBoxBorderTypeKey];
609 _title = [aCoder decodeObjectForKey:CPBoxTitle];
610 _titlePosition = [aCoder decodeIntForKey:CPBoxTitlePosition];
611 _titleView = [aCoder decodeObjectForKey:CPBoxTitleView] || [
CPTextField labelWithTitle:_title];
613 _contentView = [
self subviews][0];
615 [
self setAutoresizesSubviews:YES];
616 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
618 [
self _manageTitlePositioning];
626 [
super encodeWithCoder:aCoder];
628 [aCoder encodeInt:_boxType forKey:CPBoxTypeKey];
629 [aCoder encodeInt:_borderType forKey:CPBoxBorderTypeKey];
630 [aCoder encodeObject:_title forKey:CPBoxTitle];
631 [aCoder encodeInt:_titlePosition forKey:CPBoxTitlePosition];
632 [aCoder encodeObject:_titleView forKey:CPBoxTitleView];
652 return _titlePosition;