//// BWAnchoredButtonCell.m// BWToolkit//// Created by Brandon Walkin (www.brandonwalkin.com)// All code is provided under the New BSD license.//#import "BWAnchoredButtonCell.h"#import "BWAnchoredButtonBar.h"#import "BWAnchoredButton.h"#import "NSColor+BWAdditions.h"#import "NSImage+BWAdditions.h"staticNSColor*fillStop1,*fillStop2,*fillStop3,*fillStop4;staticNSColor*topBorderColor,*bottomBorderColor,*sideBorderColor,*sideInsetColor,*pressedColor;staticNSColor*enabledTextColor,*disabledTextColor,*enabledImageColor,*disabledImageColor;staticNSColor*borderedSideBorderColor,*borderedTopBorderColor;staticNSGradient*fillGradient;staticNSShadow*contentShadow;@interfaceNSCell(BWABCPrivate)-(NSDictionary*)_textAttributes;@end@interfaceBWAnchoredButtonCell(BWABCPrivate)-(NSColor*)textColor;-(NSColor*)imageColor;-(NSRect)highlightRectForBounds:(NSRect)cellFrame;@end@implementationBWAnchoredButtonCell+(void)initialize;{fillStop1=[[NSColorcolorWithCalibratedWhite:(253.0f/255.0f)alpha:1]retain];fillStop2=[[NSColorcolorWithCalibratedWhite:(242.0f/255.0f)alpha:1]retain];fillStop3=[[NSColorcolorWithCalibratedWhite:(230.0f/255.0f)alpha:1]retain];fillStop4=[[NSColorcolorWithCalibratedWhite:(230.0f/255.0f)alpha:1]retain];fillGradient=[[NSGradientalloc]initWithColorsAndLocations:fillStop1,(CGFloat)0.0,fillStop2,(CGFloat)0.45454,fillStop3,(CGFloat)0.45454,fillStop4,(CGFloat)1.0,nil];topBorderColor=[[NSColorcolorWithCalibratedWhite:(202.0f/255.0f)alpha:1]retain];bottomBorderColor=[[NSColorcolorWithCalibratedWhite:(170.0f/255.0f)alpha:1]retain];sideBorderColor=[[NSColorcolorWithCalibratedWhite:(0.0f/255.0f)alpha:0.2]retain];sideInsetColor=[[NSColorcolorWithCalibratedWhite:(255.0f/255.0f)alpha:0.5]retain];pressedColor=[[NSColorcolorWithCalibratedWhite:(0.0f/255.0f)alpha:0.35]retain];enabledTextColor=[[NSColorcolorWithCalibratedWhite:(10.0f/255.0f)alpha:1]retain];disabledTextColor=[[enabledTextColorcolorWithAlphaComponent:0.6]retain];enabledImageColor=[[NSColorcolorWithCalibratedWhite:(72.0f/255.0f)alpha:1]retain];disabledImageColor=[[enabledImageColorcolorWithAlphaComponent:0.6]retain];borderedSideBorderColor=[[NSColorcolorWithCalibratedWhite:(0.0f/255.0f)alpha:0.25]retain];borderedTopBorderColor=[[NSColorcolorWithCalibratedWhite:(190.0f/255.0f)alpha:1]retain];contentShadow=[[NSShadowalloc]init];[contentShadowsetShadowOffset:NSMakeSize(0,-1)];[contentShadowsetShadowColor:[NSColorcolorWithCalibratedWhite:(255.0f/255.0f)alpha:0.75]];}-(NSControlSize)controlSize{returnNSSmallControlSize;}-(void)setControlSize:(NSControlSize)size{}#pragma mark Draw Bezel-(void)drawWithFrame:(NSRect)cellFrameinView:(NSView*)controlView{[superdrawWithFrame:cellFrameinView:controlView];if([selfisHighlighted]){[pressedColorset];NSRectFillUsingOperation([selfhighlightRectForBounds:cellFrame],NSCompositeSourceOver);}}-(NSRect)highlightRectForBounds:(NSRect)bounds{returnbounds;}-(void)drawBezelWithFrame:(NSRect)cellFrameinView:(NSView*)controlView{BOOLinBorderedBar=YES;if([[[selfcontrolView]superview]respondsToSelector:@selector(isAtBottom)]){if([(BWAnchoredButtonBar*)[[selfcontrolView]superview]isAtBottom])inBorderedBar=NO;}[fillGradientdrawInRect:cellFrameangle:90];[bottomBorderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:cellFrameinView:[selfcontrolView]horizontal:YESflip:YES];[sideInsetColorbwDrawPixelThickLineAtPosition:1withInset:1inRect:cellFrameinView:[selfcontrolView]horizontal:NOflip:NO];[sideInsetColorbwDrawPixelThickLineAtPosition:1withInset:1inRect:cellFrameinView:[selfcontrolView]horizontal:NOflip:YES];if(inBorderedBar){[borderedTopBorderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:cellFrameinView:[selfcontrolView]horizontal:YESflip:NO];[borderedSideBorderColorbwDrawPixelThickLineAtPosition:0withInset:1inRect:cellFrameinView:[selfcontrolView]horizontal:NOflip:NO];[borderedSideBorderColorbwDrawPixelThickLineAtPosition:0withInset:1inRect:cellFrameinView:[selfcontrolView]horizontal:NOflip:YES];}else{[topBorderColorbwDrawPixelThickLineAtPosition:0withInset:0inRect:cellFrameinView:[selfcontrolView]horizontal:YESflip:NO];[sideBorderColorbwDrawPixelThickLineAtPosition:0withInset:1inRect:cellFrameinView:[selfcontrolView]horizontal:NOflip:NO];[sideBorderColorbwDrawPixelThickLineAtPosition:0withInset:1inRect:cellFrameinView:[selfcontrolView]horizontal:NOflip:YES];}if(inBorderedBar&&[[selfcontrolView]respondsToSelector:@selector(isAtLeftEdgeOfBar)]){if([(BWAnchoredButton*)[selfcontrolView]isAtLeftEdgeOfBar])[bottomBorderColorbwDrawPixelThickLineAtPosition:0withInset:1inRect:cellFrameinView:[selfcontrolView]horizontal:NOflip:NO];if([(BWAnchoredButton*)[selfcontrolView]isAtRightEdgeOfBar])[bottomBorderColorbwDrawPixelThickLineAtPosition:0withInset:1inRect:cellFrameinView:[selfcontrolView]horizontal:NOflip:YES];}}#pragma mark Draw Title-(NSColor*)textColor{return[selfisEnabled]?enabledTextColor:disabledTextColor;}-(NSDictionary*)_textAttributes{NSMutableDictionary*attributes=[[[NSMutableDictionaryalloc]init]autorelease];[attributesaddEntriesFromDictionary:[super_textAttributes]];[attributessetObject:[selftextColor]forKey:NSForegroundColorAttributeName];[attributessetObject:[NSFontsystemFontOfSize:11]forKey:NSFontAttributeName];[attributessetObject:contentShadowforKey:NSShadowAttributeName];returnattributes;}-(NSRect)titleRectForBounds:(NSRect)bounds{returnNSOffsetRect([supertitleRectForBounds:bounds],0,1);}#pragma mark Draw Image-(NSColor*)imageColor{return[selfisEnabled]?enabledImageColor:disabledImageColor;}-(void)drawImage:(NSImage*)imagewithFrame:(NSRect)frameinView:(NSView*)controlView{if([[imagename]isEqualToString:@"NSActionTemplate"])[imagesetSize:NSMakeSize(10,10)];NSImage*newImage=image;// Only tint if the image is a template and shouldn't be rendered as a blue active stateif([imageisTemplate]&&!([selfshowsStateBy]==NSContentsCellMask&&[selfintValue]==1)){newImage=[imagebwTintedImageWithColor:[selfimageColor]];[newImagesetTemplate:NO];[contentShadowset];}[superdrawImage:newImagewithFrame:NSOffsetRect(frame,0,1)inView:controlView];}@end