#import "BBObjectCell.h" @implementation BBObjectCell - (NSCellImagePosition)preferredImagePosition { return NSImageAbove; } - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { BOOL isFirstResponder = [[controlView window] firstResponder] == controlView && ![controlView isKindOfClass:[NSTableView class]]; BOOL dropTarget = ([self isHighlighted] && ([self highlightsBy] & NSChangeBackgroundCellMask) && ![self isBezeled]); NSColor *fillColor; NSColor *strokeColor = [NSColor clearColor]; if (isFirstResponder) { fillColor = [NSColor selectedTextBackgroundColor]; } else { fillColor = [NSColor clearColor]; } if (dropTarget) { fillColor = [NSColor controlAccentColor]; } [fillColor setFill]; [strokeColor setStroke]; NSBezierPath *roundRect = [NSBezierPath bezierPath]; [roundRect appendBezierPathWithRoundedRectangle:cellFrame withRadius:NSHeight(cellFrame)/cellRadiusFactor]; [roundRect fill]; [self drawInteriorWithFrame:[self drawingRectForBounds:cellFrame] inView:controlView]; } - (NSRect)titleRectForBounds:(NSRect)theRect { NSRect rect = theRect; rect = NSOffsetRect(rect, 0, -4); return [super titleRectForBounds: rect]; } - (void)drawTextForObject:(QSObject *)drawObject withFrame:(NSRect)cellFrame inView:(NSView *)controlView { if ([self imagePosition] == NSImageOnly) return; NSString *abbrString = nil; if ([controlView respondsToSelector:@selector(matchedString)]) abbrString = [(QSSearchObjectView *)controlView matchedString]; NSString *nameString = nil; NSIndexSet *hitMask = nil; id ranker = [drawObject ranker]; if (ranker && abbrString) nameString = [ranker matchedStringForAbbreviation:abbrString hitmask:&hitMask inContext:nil]; if (!nameString) nameString = [drawObject displayName]; BOOL rankedStringIsName = [nameString isEqualToString:[drawObject displayName]] || nameString == nil; if (!nameString) { // fall back to the identifier if no reasonable name can be found nameString = [drawObject identifier]; } if (!nameString) { // Couldn't find anything sensible to use for the name, fallback to avoid a crash nameString = @"Unknown"; } BOOL useAlternateColor = [controlView isKindOfClass:[NSTableView class]] && [(NSTableView *)controlView isRowSelected:[(NSTableView *)controlView rowAtPoint:cellFrame.origin]]; NSColor *mainColor = (textColor ? textColor : (useAlternateColor ? [NSColor alternateSelectedControlTextColor] : [NSColor controlTextColor])); NSColor *fadedColor = [mainColor colorWithAlphaComponent:0.50]; NSRect textDrawRect = [self titleRectForBounds:cellFrame]; NSMutableAttributedString *titleString = [[[NSMutableAttributedString alloc] initWithString:nameString] autorelease]; [titleString setAttributes:rankedStringIsName ? nameAttributes : detailsAttributes range:NSMakeRange(0, [titleString length])]; // Bring out the matched letters if (abbrString && ![abbrString hasPrefix:@"QSActionMnemonic"]) { [titleString addAttribute:NSForegroundColorAttributeName value:rankedStringIsName ? fadedColor : [fadedColor colorWithAlphaComponent:0.8] range:NSMakeRange(0, [titleString length])]; NSUInteger i = 0; NSUInteger j = 0; NSUInteger hits[[titleString length]]; NSUInteger count = [hitMask getIndexes:(NSUInteger *)&hits maxCount:[titleString length] inIndexRange:nil]; NSDictionary *attributes = @{ NSForegroundColorAttributeName: rankedStringIsName ? mainColor : fadedColor }; for(i = 0; i