//// BWTransparentCheckboxCell.m// BWToolkit//// Created by Brandon Walkin (www.brandonwalkin.com)// All code is provided under the New BSD license.//#import "BWTransparentCheckboxCell.h"#import "BWTransparentTableView.h"#import "NSApplication+BWAdditions.h"staticNSImage*checkboxOffN,*checkboxOffP,*checkboxOnN,*checkboxOnP;staticNSColor*enabledColor,*disabledColor;staticNSShadow*contentShadow;@interfaceNSCell(BWTCCPrivate)-(NSDictionary*)_textAttributes;@end@interfaceBWTransparentCheckboxCell(BWTCCPrivate)-(NSColor*)interiorColor;-(BOOL)isInTableView;@end@implementationBWTransparentCheckboxCell+(void)initialize;{NSBundle*bundle=[NSBundlebundleForClass:[BWTransparentCheckboxCellclass]];checkboxOffN=[[NSImagealloc]initWithContentsOfFile:[bundlepathForImageResource:@"TransparentCheckboxOffN.tiff"]];checkboxOffP=[[NSImagealloc]initWithContentsOfFile:[bundlepathForImageResource:@"TransparentCheckboxOffP.tiff"]];checkboxOnN=[[NSImagealloc]initWithContentsOfFile:[bundlepathForImageResource:@"TransparentCheckboxOnN.tiff"]];checkboxOnP=[[NSImagealloc]initWithContentsOfFile:[bundlepathForImageResource:@"TransparentCheckboxOnP.tiff"]];[checkboxOffNsetFlipped:YES];[checkboxOffPsetFlipped:YES];[checkboxOnNsetFlipped:YES];[checkboxOnPsetFlipped:YES];enabledColor=[[NSColorwhiteColor]retain];disabledColor=[[NSColorcolorWithCalibratedWhite:0.6alpha:1]retain];contentShadow=[[NSShadowalloc]init];[contentShadowsetShadowOffset:NSMakeSize(0,-1)];}-(NSDictionary*)_textAttributes{NSMutableDictionary*attributes=[[[NSMutableDictionaryalloc]init]autorelease];[attributesaddEntriesFromDictionary:[super_textAttributes]];[attributessetObject:[selfinteriorColor]forKey:NSForegroundColorAttributeName];if([selfisInTableView]){[attributessetObject:[NSFontsystemFontOfSize:11]forKey:NSFontAttributeName];}else{[attributessetObject:[NSFontboldSystemFontOfSize:11]forKey:NSFontAttributeName];[attributessetObject:contentShadowforKey:NSShadowAttributeName];}returnattributes;}-(BOOL)isInTableView{return[[selfcontrolView]isMemberOfClass:[BWTransparentTableViewclass]];}-(NSRect)drawTitle:(NSAttributedString*)titlewithFrame:(NSRect)frameinView:(NSView*)controlView{if([selfisInTableView])return[superdrawTitle:titlewithFrame:frameinView:controlView];CGContextRefcontext=[[NSGraphicsContextcurrentContext]graphicsPort];CGContextSaveGState(context);CGContextSetShouldSmoothFonts(context,NO);NSRectrect=[superdrawTitle:titlewithFrame:frameinView:controlView];CGContextRestoreGState(context);returnrect;}-(NSColor*)interiorColor{NSColor*interiorColor;if([[selfcontrolView]isMemberOfClass:[BWTransparentTableViewclass]]){// Make the text white if the row is selectedif([selfbackgroundStyle]!=1)interiorColor=[NSColorcolorWithCalibratedWhite:(198.0f/255.0f)alpha:1];elseinteriorColor=[NSColorwhiteColor];}else{interiorColor=[selfisEnabled]?enabledColor:disabledColor;}returninteriorColor;}-(void)drawInteriorWithFrame:(NSRect)cellFrameinView:(NSView*)controlView{if([selfisInTableView])cellFrame.origin.x+=4;[superdrawInteriorWithFrame:cellFrameinView:controlView];}-(void)drawImage:(NSImage*)imagewithFrame:(NSRect)frameinView:(NSView*)controlView{CGFloaty=NSMaxY(frame)-(frame.size.height-checkboxOffN.size.height)/2.0-15;CGFloatx=frame.origin.x+1;NSPointpoint=NSMakePoint(x,roundf(y));CGFloatalpha=[selfisEnabled]?1.0:0.6;if([selfisHighlighted]&&[selfintValue])[checkboxOnPdrawAtPoint:pointfromRect:NSZeroRectoperation:NSCompositeSourceOverfraction:alpha];elseif(![selfisHighlighted]&&[selfintValue])[checkboxOnNdrawAtPoint:pointfromRect:NSZeroRectoperation:NSCompositeSourceOverfraction:alpha];elseif(![selfisHighlighted]&&![selfintValue])[checkboxOffNdrawAtPoint:pointfromRect:NSZeroRectoperation:NSCompositeSourceOverfraction:alpha];elseif([selfisHighlighted]&&![selfintValue])[checkboxOffPdrawAtPoint:pointfromRect:NSZeroRectoperation:NSCompositeSourceOverfraction:alpha];}-(NSControlSize)controlSize{returnNSSmallControlSize;}-(void)setControlSize:(NSControlSize)size{}@end