0
-// Created by Martin Kahr on 10.10.06.
0
-// Copyright 2006 CASE Apps. All rights reserved.
0
-#import "ImageTextCell.h"
0
-@implementation ImageTextCell
0
- [self setDataDelegate: nil];
0
- [self setIconKeyPath: nil];
0
- [self setPrimaryTextKeyPath: nil];
0
- [self setSecondaryTextKeyPath: nil];
0
-- copyWithZone:(NSZone *)zone {
0
- ImageTextCell *cell = (ImageTextCell *)[super copyWithZone:zone];
0
- [cell setDataDelegate: delegate];
0
-- (void) setIconKeyPath: (NSString*) path {
0
- [iconKeyPath autorelease];
0
- iconKeyPath = [path retain];
0
-- (void) setPrimaryTextKeyPath: (NSString*) path {
0
- [primaryTextKeyPath autorelease];
0
- primaryTextKeyPath = [path retain];
0
-- (void) setSecondaryTextKeyPath: (NSString*) path {
0
- [secondaryTextKeyPath autorelease];
0
- secondaryTextKeyPath = [path retain];
0
-- (void) setDataDelegate: (NSObject*) aDelegate {
0
- [delegate autorelease];
0
- if (delegate) return delegate;
0
- return self; // in case there is no delegate we try to resolve values by using key paths
0
-- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
0
- [self setTextColor:[NSColor blackColor]];
0
- NSObject* data = [self objectValue];
0
- // give the delegate a chance to set a different data object
0
- if ([[self dataDelegate] respondsToSelector: @selector(dataElementForCell:)]) {
0
- data = [[self dataDelegate] dataElementForCell:self];
0
- //TODO: Selection with gradient and selection color in white with shadow
0
- // check out http://www.cocoadev.com/index.pl?NSTableView
0
- BOOL elementDisabled = NO;
0
- if ([[self dataDelegate] respondsToSelector: @selector(disabledForCell:data:)]) {
0
- elementDisabled = [[self dataDelegate] disabledForCell: self data: data];
0
- NSColor* primaryColor = [self isHighlighted] ? [NSColor alternateSelectedControlTextColor] : (elementDisabled? [NSColor disabledControlTextColor] : [NSColor textColor]);
0
- NSString* primaryText = [[self dataDelegate] primaryTextForCell:self data: data];
0
- NSMutableParagraphStyle* style = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
0
- [style setLineBreakMode:NSLineBreakByTruncatingTail];
0
- NSDictionary* primaryTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
0
- primaryColor, NSForegroundColorAttributeName,
0
- [NSFont systemFontOfSize:12], NSFontAttributeName,
0
- style, NSParagraphStyleAttributeName,
0
- [primaryText drawAtPoint:NSMakePoint(cellFrame.origin.x+cellFrame.size.height+9, cellFrame.origin.y) withAttributes:primaryTextAttributes];
0
- NSColor* secondaryColor = [self isHighlighted] ? [NSColor alternateSelectedControlTextColor] : [NSColor disabledControlTextColor];
0
- NSString* secondaryText = [[self dataDelegate] secondaryTextForCell:self data: data];
0
- NSDictionary* secondaryTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: secondaryColor, NSForegroundColorAttributeName,
0
- [NSFont systemFontOfSize:10], NSFontAttributeName, nil];
0
- [secondaryText drawAtPoint:NSMakePoint(cellFrame.origin.x+cellFrame.size.height+9, cellFrame.origin.y+cellFrame.size.height/2.2)
0
- withAttributes:secondaryTextAttributes];
0
- [[NSGraphicsContext currentContext] saveGraphicsState];
0
- float yOffset = cellFrame.origin.y;
0
- if ([controlView isFlipped]) {
0
- NSAffineTransform* xform = [NSAffineTransform transform];
0
- [xform translateXBy:0.0 yBy: cellFrame.size.height];
0
- [xform scaleXBy:1.0 yBy:-1.0];
0
- yOffset = 0-cellFrame.origin.y;
0
- NSImage* icon = [[self dataDelegate] iconForCell:self data: data];
0
- NSImageInterpolation interpolation = [[NSGraphicsContext currentContext] imageInterpolation];
0
- [[NSGraphicsContext currentContext] setImageInterpolation: NSImageInterpolationHigh];
0
- [icon drawInRect:NSMakeRect(cellFrame.origin.x+3,yOffset+3,cellFrame.size.height-6, cellFrame.size.height-6)
0
- fromRect:NSMakeRect(0,0,[icon size].width, [icon size].height)
0
- operation:NSCompositeSourceOver
0
- [[NSGraphicsContext currentContext] setImageInterpolation: interpolation];
0
- [[NSGraphicsContext currentContext] restoreGraphicsState];
0
-#pragma mark Delegate methods
0
-- (NSImage*) iconForCell: (ImageTextCell*) cell data: (NSObject*) data {
0
- return [data valueForKeyPath: iconKeyPath];
0
-- (NSString*) primaryTextForCell: (ImageTextCell*) cell data: (NSObject*) data {
0
- if (primaryTextKeyPath) {
0
- return [data valueForKeyPath: primaryTextKeyPath];
0
-- (NSString*) secondaryTextForCell: (ImageTextCell*) cell data: (NSObject*) data {
0
- if (primaryTextKeyPath) {
0
- return [data valueForKeyPath: secondaryTextKeyPath];
Comments
No one has commented yet.