#import "CellSource.h"


@implementation CellSource

/*"	Override basic data source to handle icon, checked values
"*/
- (id)tableView:(NSTableView *)inTableView
objectValueForTableColumn:(NSTableColumn *)inTableColumn
			   row:(int)inRowIndex
{
	id result = nil;
	// Start out with the string that the SimpleSource returns from the dictionary
	id stringValue = [super tableView:inTableView objectValueForTableColumn:inTableColumn row:inRowIndex];

	// Now, handle special cases depending on the table column identifier.
	NSString *identifier = [inTableColumn identifier];
	if ([identifier isEqualToString:@"icon"])
	{
		if (nil != stringValue)
		{
			result = [NSImage imageNamed:stringValue];
		}
	}
	else if ([identifier isEqualToString:@"checked"])
	{
		// Return NSNumber of 1 or 0.  The line below builds the NSNumber
		// from from the string or NSNumber currently in the dictionary.
		result = [NSNumber numberWithInt:[stringValue intValue]];
	}
	else if ([identifier isEqualToString:@"rank"])
	{
		// Return NSNumber of a float between 0 and 1
		result = [NSNumber numberWithFloat:[stringValue floatValue]];
	}
	else if ([identifier isEqualToString:@"name"])
	{
		// Really, these dictionaries should be created once and cached....
		NSDictionary *plainAttr = [NSDictionary dictionaryWithObject:
			   [NSFont systemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];
		NSDictionary *boldAttr = [NSDictionary dictionaryWithObject:
		  [NSFont boldSystemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];

		// Return an attributed string, with the first character boldface.
		result = [[[NSMutableAttributedString alloc] init] autorelease];

		[result appendAttributedString: [[[NSAttributedString alloc]
				initWithString:[stringValue substringToIndex:1]
					   attributes:boldAttr] autorelease]];
		[result appendAttributedString: [[[NSAttributedString alloc]
				initWithString:[stringValue substringFromIndex:1]
					   attributes:plainAttr] autorelease]];
	}
	else
	{
		// If not the special cases, we've gotten the string result from the superclass.
		result = stringValue;
	}
	return result;
}



@end
