56 CPBorderType _borderType;
64 CPSize _contentMargin;
74 var box = [[
self alloc] initWithFrame:CGRectMakeZero()],
78 [box setFrameFromContentFrame:[aView
frame]];
80 [enclosingView replaceSubview:aView with:box];
82 [box setContentView:aView];
87 - (id)initWithFrame:(CPRect)frameRect
98 _contentMargin = CGSizeMake(0.0, 0.0);
104 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
137 - (CPBorderType)borderType
155 - (void)setBorderType:(CPBorderType)aBorderType
157 if (_borderType === aBorderType)
160 _borderType = aBorderType;
199 - (void)setBoxType:(CPBoxType)aBoxType
201 if (_boxType === aBoxType)
215 if ([color
isEqual:_borderColor])
218 _borderColor = color;
227 - (void)setBorderWidth:(
float)width
229 if (
width === _borderWidth)
232 _borderWidth =
width;
236 - (float)cornerRadius
238 return _cornerRadius;
241 - (void)setCornerRadius:(
float)radius
243 if (radius === _cornerRadius)
246 _cornerRadius = radius;
257 if ([color
isEqual:_fillColor])
271 if (aView === _contentView)
274 [aView
setFrame:CGRectInset([
self bounds], _contentMargin.width + _borderWidth, _contentMargin.height + _borderWidth)];
278 _contentView = aView;
281 - (CPSize)contentViewMargins
283 return _contentMargin;
286 - (void)setContentViewMargins:(CPSize)size
288 if (size.width < 0 || size.height < 0)
291 _contentMargin = CGSizeMakeCopy(size);
295 - (void)setFrameFromContentFrame:(CPRect)aRect
297 var offset = [
self _titleHeightOffset];
299 [
self setFrame:CGRectInset(aRect, -(_contentMargin.width + _borderWidth), -(_contentMargin.height + offset[0] + _borderWidth))];
306 if (aTitle == _title)
311 [
self _manageTitlePositioning];
314 - (void)setTitlePosition:(
int)aTitlePotisition
316 if (aTitlePotisition == _titlePosition)
319 _titlePosition = aTitlePotisition;
321 [
self _manageTitlePositioning];
326 return [_titleView font];
331 [_titleView setFont:aFont];
344 - (void)_manageTitlePositioning
348 [_titleView removeFromSuperview];
349 [
self setNeedsDisplay:YES];
353 [_titleView setStringValue:_title];
354 [_titleView sizeToFit];
355 [
self addSubview:_titleView];
357 switch (_titlePosition)
362 [_titleView setFrameOrigin:CPPointMake(5.0, 0.0)];
363 [_titleView setAutoresizingMask:CPViewNotSizable];
369 var h = [_titleView frameSize].height;
370 [_titleView setFrameOrigin:CPPointMake(5.0, [
self frameSize].height - h)];
371 [_titleView setAutoresizingMask:CPViewMinYMargin];
376 [
self setNeedsDisplay:YES];
381 var contentFrame = [_contentView frame],
382 offset = [
self _titleHeightOffset];
387 [_contentView setAutoresizingMask:CPViewNotSizable];
388 [
self setFrameSize:CGSizeMake(contentFrame.size.width + _contentMargin.width * 2,
389 contentFrame.size.height + _contentMargin.height * 2 + offset[0])];
390 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
392 [_contentView setFrameOrigin:CGPointMake(_contentMargin.width, _contentMargin.height + offset[1])];
395 - (float)_titleHeightOffset
400 switch (_titlePosition)
403 return [[_titleView frameSize].height, [_titleView frameSize].height];
406 return [[_titleView frameSize].height, 0.0];
413 - (void)drawRect:(CPRect)rect
418 var bounds = CGRectMakeCopy([
self bounds]);
425 if (CGRectGetWidth(bounds) === 5.0)
426 return [
self _drawVerticalSeperatorInRect:bounds];
427 else if (CGRectGetHeight(bounds) === 5.0)
428 return [
self _drawHorizontalSeperatorInRect:bounds];
435 bounds.origin.y += [_titleView frameSize].height;
436 bounds.size.height -= [_titleView frameSize].height;
440 bounds.size.height -= [_titleView frameSize].height;
446 [
self _drawBezelBorderInRect:bounds];
451 [
self _drawLineBorderInRect:bounds];
456 - (void)_drawHorizontalSeperatorInRect:(CGRect)aRect
468 - (void)_drawVerticalSeperatorInRect:(CGRect)aRect
480 - (void)_drawBezelBorderInRect:(CGRect)aRect
483 sides = [CPMinYEdge, CPMaxXEdge, CPMaxYEdge, CPMinXEdge],
484 sideGray = 190.0 / 255.0,
485 grays = [142.0 / 255.0, sideGray, sideGray, sideGray],
486 borderWidth = _borderWidth;
488 while (borderWidth--)
495 - (void)_drawLineBorderInRect:(CGRect)aRect
499 aRect = CGRectInset(aRect, _borderWidth / 2.0, _borderWidth / 2.0);
530 _boxType = [aCoder decodeIntForKey:CPBoxTypeKey];
531 _borderType = [aCoder decodeIntForKey:CPBoxBorderTypeKey];
533 _borderColor = [aCoder decodeObjectForKey:CPBoxBorderColorKey];
534 _fillColor = [aCoder decodeObjectForKey:CPBoxFillColorKey];
536 _cornerRadius = [aCoder decodeFloatForKey:CPBoxCornerRadiusKey];
537 _borderWidth = [aCoder decodeFloatForKey:CPBoxBorderWidthKey];
539 _contentMargin = [aCoder decodeSizeForKey:CPBoxContentMarginKey];
541 _title = [aCoder decodeObjectForKey:CPBoxTitle];
542 _titlePosition = [aCoder decodeIntForKey:CPBoxTitlePosition];
548 [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
550 [
self _manageTitlePositioning];
560 [aCoder encodeInt:_boxType forKey:CPBoxTypeKey];
561 [aCoder encodeInt:_borderType forKey:CPBoxBorderTypeKey];
563 [aCoder encodeObject:_borderColor forKey:CPBoxBorderColorKey];
564 [aCoder encodeObject:_fillColor forKey:CPBoxFillColorKey];
566 [aCoder encodeFloat:_cornerRadius forKey:CPBoxCornerRadiusKey];
567 [aCoder encodeFloat:_borderWidth forKey:CPBoxBorderWidthKey];
569 [aCoder encodeObject:_title forKey:CPBoxTitle];
570 [aCoder encodeInt:_titlePosition forKey:CPBoxTitlePosition];
571 [aCoder encodeObject:_titleView forKey:CPBoxTitleView];
573 [aCoder encodeSize:_contentMargin forKey:CPBoxContentMarginKey];
593 return _titlePosition;