diff options
author | abhibeckert <abhi@abhibeckert.com> | 2008-09-29 09:49:36 +0000 |
---|---|---|
committer | abhibeckert <abhi@abhibeckert.com> | 2008-09-29 09:49:36 +0000 |
commit | 8b39f25ee75d7db1eff68aaa71b92d3282e4c054 (patch) | |
tree | 75e5fd2f66210a5d7170f92c40903fe9fe1c5b57 /trunk/ImageAndTextCell.m | |
parent | c0e7a42a5deba6b1529db959411a416ab114edba (diff) | |
download | sequelpro-8b39f25ee75d7db1eff68aaa71b92d3282e4c054.tar.gz sequelpro-8b39f25ee75d7db1eff68aaa71b92d3282e4c054.tar.bz2 sequelpro-8b39f25ee75d7db1eff68aaa71b92d3282e4c054.zip |
tag release candidate 2 of 0.9.2 releaserelease-0.9.2
Diffstat (limited to 'trunk/ImageAndTextCell.m')
-rwxr-xr-x | trunk/ImageAndTextCell.m | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/trunk/ImageAndTextCell.m b/trunk/ImageAndTextCell.m new file mode 100755 index 00000000..96c0ff9d --- /dev/null +++ b/trunk/ImageAndTextCell.m @@ -0,0 +1,135 @@ +/* + ImageAndTextCell.m + Copyright © 2006, Apple Computer, Inc., all rights reserved. + + Subclass of NSTextFieldCell which can display text and an image simultaneously. +*/ + +#import "ImageAndTextCell.h" + +@implementation ImageAndTextCell + +- (void)dealloc { + [image release]; + image = nil; + [super dealloc]; +} + +- copyWithZone:(NSZone *)zone +{ + ImageAndTextCell *cell = (ImageAndTextCell *)[super copyWithZone:zone]; + cell->image = [image retain]; + return cell; +} + +- (void)setImage:(NSImage *)anImage +{ + if (anImage != image) + { + [image release]; + image = [anImage retain]; + } +} + +- (NSImage *)image +{ + return image; +} + +- (NSRect)imageFrameForCellFrame:(NSRect)cellFrame +{ + if (image != nil) + { + NSRect imageFrame; + imageFrame.size = [image size]; + imageFrame.origin = cellFrame.origin; + imageFrame.origin.x += ((1 - MIN(1,INDENT_AMOUNT)) * 3) + (INDENT_AMOUNT * _indentationLevel); + 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 +{ + if (_indentationLevel != 0) { + NSRect indentationFrame; + NSDivideRect(aRect, &indentationFrame, &aRect, (INDENT_AMOUNT * _indentationLevel), NSMinXEdge); + } + + if (image != nil) { + NSRect imageFrame; + NSDivideRect (aRect, &imageFrame, &aRect, 3 + [image size].width, NSMinXEdge); + } + + [super editWithFrame:aRect inView: controlView editor:textObj delegate:anObject event:theEvent]; +} + +- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(int)selStart length:(int)selLength +{ + if (_indentationLevel != 0) { + NSRect indentationFrame; + NSDivideRect(aRect, &indentationFrame, &aRect, (INDENT_AMOUNT * _indentationLevel), NSMinXEdge); + } + + if (image != nil) { + NSRect imageFrame; + NSDivideRect (aRect, &imageFrame, &aRect, 3 + [image size].width, NSMinXEdge); + } + + [super selectWithFrame:aRect inView: controlView editor:textObj delegate:anObject start:selStart length:selLength]; +} + +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView +{ + if (_indentationLevel != 0) + { + NSRect indentationFrame; + NSDivideRect(cellFrame, &indentationFrame, &cellFrame, (INDENT_AMOUNT * _indentationLevel), NSMinXEdge); + } + + 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; + + 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); + + [image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver]; + } + [super drawWithFrame:cellFrame inView:controlView]; +} + +- (NSSize)cellSize +{ + NSSize cellSize = [super cellSize]; + cellSize.width += (image ? [image size].width : 0) + ((1 - MIN(1,INDENT_AMOUNT)) * 3) + (INDENT_AMOUNT * _indentationLevel); + return cellSize; +} + +- (void)setIndentationLevel:(int)level +{ + _indentationLevel = MAX(0,level); +} + +- (int)IndentationLevel +{ + return _indentationLevel; +} + +@end + |