mirror of
https://github.com/nickshanks/ResKnife.git
synced 2024-08-31 04:29:17 +00:00
101 lines
2.8 KiB
Objective-C
101 lines
2.8 KiB
Objective-C
#import "ResourceNameCell.h"
|
|
|
|
@implementation ResourceNameCell
|
|
|
|
- (void)dealloc
|
|
{
|
|
[image release];
|
|
[super dealloc];
|
|
}
|
|
|
|
- copyWithZone:(NSZone *)zone
|
|
{
|
|
ResourceNameCell *cell = (ResourceNameCell *)[super copyWithZone:zone];
|
|
(* cell).image = [image retain];
|
|
return cell;
|
|
}
|
|
|
|
- (void)setImage:(NSImage *)newImage
|
|
{
|
|
// save image and set to 16x16 pixels
|
|
[image release]; // would this be better autoreleased instead?
|
|
image = [newImage retain];
|
|
[image setScalesWhenResized:YES];
|
|
[image setSize:NSMakeSize(16,16)];
|
|
}
|
|
|
|
- (NSImage *)image
|
|
{
|
|
return image;
|
|
}
|
|
|
|
- (NSRect)imageFrameForCellFrame:(NSRect)cellFrame
|
|
{
|
|
if( image != nil )
|
|
{
|
|
// center image vertically in frame, offset right by three
|
|
NSRect imageFrame;
|
|
imageFrame.size = [image size];
|
|
imageFrame.origin = cellFrame.origin;
|
|
imageFrame.origin.x += 3;
|
|
imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
|
|
return imageFrame;
|
|
}
|
|
else return NSZeroRect;
|
|
}
|
|
|
|
- (void)editWithFrame:(NSRect)cellFrame inView:(NSView *)controlView editor:(NSText *)textObject delegate:(id)delegateObject event:(NSEvent *)theEvent
|
|
{
|
|
// split cell frame into two, pass the text part to the superclass
|
|
NSRect textFrame, imageFrame;
|
|
NSDivideRect( cellFrame, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge );
|
|
[super editWithFrame:textFrame inView:controlView editor:textObject delegate:delegateObject event:theEvent];
|
|
}
|
|
|
|
- (void)selectWithFrame:(NSRect)cellFrame inView:(NSView *)controlView editor:(NSText *)textObject delegate:(id)delegateObject start:(int)selStart length:(int)selLength
|
|
{
|
|
// split cell frame into two, pass the text part to the superclass
|
|
NSRect textFrame, imageFrame;
|
|
NSDivideRect( cellFrame, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
|
|
[super selectWithFrame:textFrame inView:controlView editor:textObject delegate:delegateObject start:selStart length:selLength];
|
|
}
|
|
|
|
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
|
{
|
|
if( image != nil )
|
|
{
|
|
NSRect imageFrame;
|
|
NSSize imageSize = [image size];
|
|
|
|
// get image frame
|
|
NSDivideRect( cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge );
|
|
if( [self drawsBackground] )
|
|
{
|
|
[[self backgroundColor] set];
|
|
NSRectFill(imageFrame);
|
|
}
|
|
imageFrame.origin.x += 3;
|
|
imageFrame.size = imageSize;
|
|
|
|
// center vertically
|
|
if( [controlView isFlipped] )
|
|
imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2);
|
|
else imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
|
|
|
|
// draw image
|
|
[image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];
|
|
}
|
|
|
|
// get the superclass to draw the text stuff
|
|
[super drawWithFrame:cellFrame inView:controlView];
|
|
}
|
|
|
|
- (NSSize)cellSize
|
|
{
|
|
NSSize cellSize = [super cellSize];
|
|
cellSize.width += (image? [image size].width:0) + 3;
|
|
return cellSize;
|
|
}
|
|
|
|
@end
|