From 44548eed4c7e103ced2c9e87bd056fe59fedf617 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 14 Aug 2009 22:57:11 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20SPTooltips=20for=20cell=20content?= =?UTF-8?q?=20in=20Content=20Table=20-=20text=20strings=20are=20display=20?= =?UTF-8?q?with=20line=20breaks=20and=20tabs=20-=20if=20cell=20content=20r?= =?UTF-8?q?epresents=20image=20data=20display=20that=20image=20as=20transp?= =?UTF-8?q?arent=20thumbnail=20(by=20using=20base64=20encoded=20HTML=20img?= =?UTF-8?q?=20tag)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notes: - SPTooltip implementation to show an image via a NSImageView will be implemented soon (the HTML way needs too much memory due to base64 encoded string) - to discuss: Should we add a preference setting to display these tooltips? --- Source/SPTextAndLinkCell.m | 8 ++++++++ Source/SPTooltip.m | 2 +- Source/TableContent.m | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/SPTextAndLinkCell.m b/Source/SPTextAndLinkCell.m index eee3f517..90012fa9 100644 --- a/Source/SPTextAndLinkCell.m +++ b/Source/SPTextAndLinkCell.m @@ -264,4 +264,12 @@ static inline NSRect SPTextLinkRectFromCellRect(NSRect inRect) { return lastLinkRow; } +/** + * Suppress the built-in expansion tooltip + */ +- (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView *)view +{ + return NSZeroRect; +} + @end diff --git a/Source/SPTooltip.m b/Source/SPTooltip.m index 94017795..793deb54 100644 --- a/Source/SPTooltip.m +++ b/Source/SPTooltip.m @@ -325,7 +325,7 @@ static float slow_in_out (float t) float deltaY = p.y - aPoint.y; float dist = sqrtf(deltaX * deltaX + deltaY * deltaY); - float moveThreshold = 20; + float moveThreshold = 10; return dist > moveThreshold; } diff --git a/Source/TableContent.m b/Source/TableContent.m index 5ebb15f9..3f8c9596 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -43,6 +43,7 @@ #import "SPTextAndLinkCell.h" #import "QLPreviewPanel.h" #import "SPFieldEditorController.h" +#import "SPTooltip.h" @implementation TableContent @@ -1789,6 +1790,46 @@ #pragma mark - #pragma mark TableView delegate methods +/** + * Show the table cell content as tooltip + * - for text displays line breaks and tabs as well + * - if blob data can be interpret as image data display the image as transparent thumbnail + * (up to now using base64 encoded HTML data) + */ +- (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(SPTextAndLinkCell *)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)row mouseLocation:(NSPoint)mouseLocation +{ + + if([[aCell stringValue] length] < 1) return nil; + + NSPoint pos = [NSEvent mouseLocation]; + pos.y -= 20; + + // Get the original data for trying to display the blob data as an image + id theValue = NSArrayObjectAtIndex(NSArrayObjectAtIndex(tableValues, row), [[aTableColumn identifier] intValue]); + if ([theValue isKindOfClass:[NSData class]]) { + NSImage *image = [[NSImage alloc] initWithData:theValue]; + if(image) { + int imageWidth = [image size].width; + if (imageWidth > 100) imageWidth = 100; + [SPTooltip showWithObject:[NSString stringWithFormat: + @"", + imageWidth, + [[image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0]] + atLocation:pos + ofType:@"html" + displayOptions:[NSDictionary dictionaryWithObjectsAndKeys:@"transparent", @"transparent", nil]]; + } + [image release]; + return nil; + } + + // Show the cell string value as tooltip (including line breaks and tabs) + if([[aCell stringValue] length] > 1) + [SPTooltip showWithObject:[aCell stringValue] atLocation:pos]; + + return nil; +} + - (int)numberOfRowsInTableView:(NSTableView *)aTableView { return [tableValues count]; -- cgit v1.2.3