Here's my custom cell code. Where am I going wrong?
Thanks for any help
@interface PMXDocumentCell : NSCell
{
NSButtonCell *addButton;
NSImage *backImage,
*backSelectedImage,
*addButtonImage,
*addButtonSelectedImage,
*currentBackImage;
NSString *documentName;
NSDictionary *textAttributes;
}
+ (id) documentCell;
- (void) initImages;
- (void) initSubCells;
- (NSString *) documentName;
- (void) setDocumentName:(NSString *) inName;
- (id) objectValue;
- (void) setObjectValue:(id) inObject;
@end
#define ADD_BUTTON_SIZE 17
@implementation PMXDocumentCell
+ (id) documentCell
{
return [[[PMXDocumentCell alloc]
init]
autorelease];
}
- (id) init
{
self = [super init];
if (self)
{
[self initImages];
[self initSubCells];
currentBackImage = backImage;
textAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSColor blackColor], NSForegroundColorAttributeName,
[NSFont systemFontOfSize:13], NSFontAttributeName,
nil];
}
return self;
}
- (void) initImages
{
NSBundle *bundle = [NSBundle bundleForClass: [self class]];
NSString *path;
path = [bundle pathForResource: @"add_button" ofType: @"png"];
addButtonImage = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForResource: @"add_button_white" ofType:
@"png"];
addButtonSelectedImage = [[NSImage alloc] initWithContentsOfFile:
path];
path = [bundle pathForResource: @"toolbar_25" ofType: @"png"];
backImage = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForResource: @"toolbar_25_focus" ofType:
@"png"];
backSelectedImage = [[NSImage alloc] initWithContentsOfFile: path];
// set resizing
[addButtonImage setScalesWhenResized: YES];
[addButtonSelectedImage setScalesWhenResized: YES];
[backImage setScalesWhenResized: YES];
[backSelectedImage setScalesWhenResized: YES];
// size button images
[addButtonImage setSize: NSMakeSize(ADD_BUTTON_SIZE,
ADD_BUTTON_SIZE)];
[addButtonSelectedImage setSize: NSMakeSize(ADD_BUTTON_SIZE,
ADD_BUTTON_SIZE)];
}
- (void) initSubCells
{
addButton = [[NSButtonCell alloc] init];
[addButton setBordered: NO];
[addButton setButtonType: NSMomentaryChangeButton];
[addButton setImage: addButtonImage];
[addButton setAlternateImage: addButtonSelectedImage];
}
- (void) drawWithFrame:(NSRect) inCellFrame
inView:(NSView *) inControlView
{
NSRect buttonFrame = NSMakeRect(inCellFrame.size.width -
ADD_BUTTON_SIZE - 6, inCellFrame.origin.y, ADD_BUTTON_SIZE,
ADD_BUTTON_SIZE),
nameFrame = NSMakeRect(6, inCellFrame.origin.y,
inCellFrame.size.width - ADD_BUTTON_SIZE - 12 , ADD_BUTTON_SIZE);
NSPoint textPoint = NSMakePoint(inCellFrame.origin.x + 1,
inCellFrame.origin.y);
currentBackImage = [self isHighlighted] ? backSelectedImage :
backImage ;
[currentBackImage drawAtPoint: inCellFrame.origin
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0];
[addButton drawWithFrame: buttonFrame
inView: inControlView];
[documentName drawInRect: nameFrame
withAttributes: textAttributes];
}
- (NSString *) objectValue
{
return documentName;
}
- (void) setObjectValue:(id) inObject
{
if (inObject == nil)
inObject = @"document name";
if ([inObject isKindOfClass: [NSString class]])
[self setStringValue: inObject];
else
[NSException raise: NSInvalidArgumentException format: @"%@
Invalid object %@", NSStringFromSelector(_cmd), inObject];
}
- (NSString *) documentName
{
return documentName;
}
- (void) setDocumentName:(NSString *) inName
{
[inName retain];
[documentName release];
documentName = inName;
// Tell control view to redisplay us.
[(NSControl *)[self controlView] updateCell: self];
}
@end