From 9fc4f973499e8d3bf327f699cd0e18d7e640a54d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 12 Oct 2009 15:59:07 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0first=20steps=20to=20improve=20the=20gen?= =?UTF-8?q?eral=20tooltip=20behaviour=20of=20'ImageAndTextCell'=20class=20?= =?UTF-8?q?=E2=80=A2=20simplified=20the=20tooltip=20of=20Preference's=20Fa?= =?UTF-8?q?vorite=20List?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/ImageAndTextCell.m | 46 +++++++++++++++++++++++++++++++++++++++- Source/SPFavoriteTextFieldCell.m | 20 ++++++++++++----- Source/SPPreferenceController.m | 13 ------------ 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/Source/ImageAndTextCell.m b/Source/ImageAndTextCell.m index 345d4aeb..ad6ec247 100644 --- a/Source/ImageAndTextCell.m +++ b/Source/ImageAndTextCell.m @@ -81,6 +81,44 @@ [super selectWithFrame:aRect inView: controlView editor:textObj delegate:anObject start:selStart length:selLength]; } +- (void)drawWithExpansionFrame:(NSRect)cellFrame inView:(NSView *)view +{ + 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 ([view 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]; + } else + if (_indentationLevel == 0) + cellFrame.size.height = [view frame].size.height+2; + + [super drawWithExpansionFrame:cellFrame inView:view]; + +} + - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { if (_indentationLevel != 0) @@ -111,13 +149,19 @@ [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); + cellSize.width += (image ? [image size].width : 0) + ((1 - MIN(1,INDENT_AMOUNT)) * 3) + (INDENT_AMOUNT * _indentationLevel) + 2; + // TODO : this has to be generalized yet + if (image != nil) + cellSize.height += 2; + else + cellSize.height += 8; return cellSize; } diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m index af65d28e..1c1c6f86 100644 --- a/Source/SPFavoriteTextFieldCell.m +++ b/Source/SPFavoriteTextFieldCell.m @@ -129,14 +129,14 @@ // Total height of both strings with a 2 pixel separation space float totalHeight = [mainString size].height + [subString size].height + 1.0; - cellFrame.origin.y += (cellFrame.size.height - totalHeight) / 2.0; + cellFrame.origin.y += (cellFrame.size.height - totalHeight) / 2.0; cellFrame.origin.x += 10.0; // Indent main string from image // Position the sub text's frame rect subFrame.origin.y = [mainString size].height + cellFrame.origin.y + 1.0; subFrame.origin.x = cellFrame.origin.x; - cellFrame.size.height = totalHeight; + cellFrame.size.height = totalHeight; int i; float maxWidth = cellFrame.size.width; @@ -166,10 +166,20 @@ [subString drawInRect:subFrame]; } -// Suppress built-in tooltips -- (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView *)view +- (NSSize)cellSize { - return NSMakeRect(0,0,0,0); + NSSize cellSize = [super cellSize]; + NSAttributedString *mainString = [[self attributedStringForFavoriteName] autorelease]; + NSAttributedString *subString = [[self constructSubStringAttributedString] autorelease]; + + // 15 := indention 10 from image to string plus 5 px padding + float theWidth = MAX([mainString size].width, [subString size].width) + (([self image] != nil) ? [[self image] size].width : 0) + 15; + + float totalHeight = [mainString size].height + [subString size].height + 1.0; + + cellSize.width = theWidth; + cellSize.height = totalHeight + 13.0; + return cellSize; } // ------------------------------------------------------------------------------- diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index aed79610..36834616 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -29,7 +29,6 @@ #import "SPKeychain.h" #import "TableDocument.h" #import "SPConnectionController.h" -#import "SPTooltip.h" #define FAVORITES_PB_DRAG_TYPE @"SequelProPreferencesPasteboard" @@ -669,18 +668,6 @@ favoriteNameFieldWasTouched = YES; } -- (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(SPFavoriteTextFieldCell *)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)row mouseLocation:(NSPoint)mouseLocation -{ - NSRect r = *rect; - // No tooltip if cellSize < controlSize - if([aCell cellSize].width < r.size.width-20) return nil; - - NSPoint pos = [NSEvent mouseLocation]; - pos.y -= 20; - [SPTooltip showWithObject:[NSString stringWithFormat:@"%@
%@", [aCell favoriteName], [aCell favoriteHost]] atLocation:pos ofType:@"html"]; - return nil; -} - #pragma mark - #pragma mark Toolbar delegate methods -- cgit v1.2.3