//// BWGradientSplitViewSubview.m// BWToolkit//// Created by Brandon Walkin (www.brandonwalkin.com)// All code is provided under the New BSD license.//#import "BWCustomView.h"#import "NSColor+BWAdditions.h"#import "NSWindow+BWAdditions.h"#import "NSApplication+BWAdditions.h"#import "IBColor.h"@interfaceBWCustomView(BWCVPrivate)-(void)drawTextInRect:(NSRect)rect;-(NSColor*)containerCustomViewBackgroundColor;-(NSColor*)childlessCustomViewBackgroundColor;-(NSColor*)customViewDarkTexturedBorderColor;-(NSColor*)customViewDarkBorderColor;-(NSColor*)customViewLightBorderColor;@end@implementationBWCustomView-(void)drawRect:(NSRect)rect{rect=self.bounds;NSColor*insetColor=[selfcustomViewLightBorderColor];NSColor*borderColor;if([[selfwindow]bwIsTextured])borderColor=[selfcustomViewDarkTexturedBorderColor];elseborderColor=[selfcustomViewDarkBorderColor];// Note: These two colors are reversed in IBColor in 10.5if(self.subviews.count==0){if([NSApplicationbwIsOnLeopard])[[selfcontainerCustomViewBackgroundColor]set];else[[selfchildlessCustomViewBackgroundColor]set];NSRectFillUsingOperation(rect,NSCompositeSourceOver);}else{if([NSApplicationbwIsOnLeopard])[[selfchildlessCustomViewBackgroundColor]set];else[[selfcontainerCustomViewBackgroundColor]set];NSRectFillUsingOperation(rect,NSCompositeSourceOver);}if([[selfsuperview]isKindOfClass:NSClassFromString(@"BWSplitView")]&&[[selfsuperview]subviews].count>1){isOnItsOwn=NO;NSArray*subviews=[[selfsuperview]subviews];if([subviewsobjectAtIndex:0]==self){[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];if([(NSSplitView*)[selfsuperview]isVertical]){[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];[insetColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];}else{[insetColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];}[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];}elseif([subviewslastObject]==self){[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];if([(NSSplitView*)[selfsuperview]isVertical]){[insetColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];}else{[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];[insetColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];}[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];}else{if([(NSSplitView*)[selfsuperview]isVertical]){[insetColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];[insetColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];}else{[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];[insetColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];[insetColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];}}}else{isOnItsOwn=YES;[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];[insetColorbwDrawPixelThickLineAtPosition:1withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:NO];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:NOflip:YES];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:YES];[borderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:rectinView:selfhorizontal:YESflip:NO];}if(rect.size.height>16)[selfdrawTextInRect:rect];}-(void)drawTextInRect:(NSRect)rect{NSString*text;if(isOnItsOwn)text=[NSStringstringWithFormat:@"%d x %d pt",(int)rect.size.width,(int)rect.size.height];elseif([(NSSplitView*)[selfsuperview]isVertical])text=[NSStringstringWithFormat:@"%d pt",(int)rect.size.width];elsetext=[NSStringstringWithFormat:@"%d pt",(int)rect.size.height];if(![self.classNameisEqualToString:@"NSView"])text=self.className;NSMutableDictionary*attributes=[[[NSMutableDictionaryalloc]init]autorelease];[attributessetObject:[NSColorwhiteColor]forKey:NSForegroundColorAttributeName];[attributessetObject:[NSFontboldSystemFontOfSize:12]forKey:NSFontAttributeName];NSShadow*shadow=[[[NSShadowalloc]init]autorelease];[shadowsetShadowOffset:NSMakeSize(0,-1)];[shadowsetShadowColor:[[NSColorblackColor]colorWithAlphaComponent:0.4]];[attributessetObject:shadowforKey:NSShadowAttributeName];NSMutableAttributedString*string=[[[NSMutableAttributedStringalloc]initWithString:textattributes:attributes]autorelease];NSRectboundingRect=[stringboundingRectWithSize:rect.sizeoptions:0];NSPointrectCenter;rectCenter.x=rect.size.width/2;rectCenter.y=rect.size.height/2;NSPointdrawPoint=rectCenter;drawPoint.x-=boundingRect.size.width/2;drawPoint.y-=boundingRect.size.height/2;drawPoint.x=roundf(drawPoint.x);drawPoint.y=roundf(drawPoint.y);[stringdrawAtPoint:drawPoint];}@end