2006-09-02 16:09:20 +00:00
|
|
|
#import "ImageTextCell.h"
|
|
|
|
|
|
|
|
@implementation ImageTextCell
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
image = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- copyWithZone:(NSZone *)zone {
|
|
|
|
ImageTextCell *cell = (ImageTextCell *)[super copyWithZone:zone];
|
2016-05-05 20:05:39 +00:00
|
|
|
cell->image = image;
|
2006-09-02 16:09:20 +00:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setImage:(NSImage *)anImage {
|
2016-05-05 20:05:39 +00:00
|
|
|
image = anImage;
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImage *)image {
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)imageFrameForCellFrame:(NSRect)cellFrame {
|
|
|
|
if (image != nil) {
|
|
|
|
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)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent {
|
|
|
|
NSRect textFrame, imageFrame;
|
|
|
|
NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
|
|
|
|
[super editWithFrame: textFrame inView: controlView editor:textObj delegate:anObject event: theEvent];
|
|
|
|
}
|
|
|
|
|
2013-10-03 08:00:58 +00:00
|
|
|
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength {
|
2006-09-02 16:09:20 +00:00
|
|
|
NSRect textFrame, imageFrame;
|
|
|
|
NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
|
|
|
|
[super selectWithFrame: textFrame inView: controlView editor:textObj delegate:anObject start:selStart length:selLength];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
|
|
|
|
if (image != nil) {
|
|
|
|
NSSize imageSize;
|
|
|
|
NSRect imageFrame;
|
|
|
|
|
|
|
|
imageSize = [image size];
|
|
|
|
NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge);
|
|
|
|
if ([self drawsBackground]) {
|
|
|
|
[[self backgroundColor] set];
|
|
|
|
NSRectFill(imageFrame);
|
|
|
|
}
|
|
|
|
imageFrame.origin.x += 3;
|
|
|
|
imageFrame.size = imageSize;
|
|
|
|
|
2013-10-09 17:33:22 +00:00
|
|
|
imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
|
2006-09-02 16:09:20 +00:00
|
|
|
|
2013-10-09 17:33:22 +00:00
|
|
|
[image drawInRect:imageFrame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
[super drawWithFrame:cellFrame inView:controlView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize)cellSize {
|
|
|
|
NSSize cellSize = [super cellSize];
|
|
|
|
cellSize.width += (image ? [image size].width : 0) + 3;
|
|
|
|
return cellSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|