aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/CustomQuery.m22
-rw-r--r--Source/SPTooltip.m66
-rw-r--r--Source/TableContent.m21
3 files changed, 76 insertions, 33 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 6bdfe191..891cb38e 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -1695,6 +1695,9 @@
- (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(SPTextAndLinkCell *)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)row mouseLocation:(NSPoint)mouseLocation
{
+
+ NSImage *image;
+
if([[aCell stringValue] length] < 1) return nil;
NSPoint pos = [NSEvent mouseLocation];
@@ -1703,22 +1706,17 @@
// Get the original data for trying to display the blob data as an image
id theValue = NSArrayObjectAtIndex(NSArrayObjectAtIndex(fullResult, row), [[aTableColumn identifier] intValue]);
if ([theValue isKindOfClass:[NSData class]]) {
- NSImage *image = [[NSImage alloc] initWithData:theValue];
+ image = [[NSImage alloc] initWithData:theValue];
if(image) {
- int imageWidth = [image size].width;
- if (imageWidth > 100) imageWidth = 100;
- [SPTooltip showWithObject:[NSString stringWithFormat:
- @"<IMG WIDTH='%d' SRC=\"data:image/auto;base64,%@\">",
- imageWidth,
- [[image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0]]
- atLocation:pos
- ofType:@"html"
- displayOptions:[NSDictionary dictionaryWithObjectsAndKeys:@"transparent", @"transparent", nil]];
+ [SPTooltip showWithObject:image atLocation:pos ofType:@"image"];
+ [image release];
+ theValue = nil;
+ return nil;
}
- [image release];
- return nil;
}
+ if(image) [image release];
+
// Show the cell string value as tooltip (including line breaks and tabs)
if([[aCell stringValue] length] > 1)
[SPTooltip showWithObject:[aCell stringValue] atLocation:pos];
diff --git a/Source/SPTooltip.m b/Source/SPTooltip.m
index 793deb54..64842427 100644
--- a/Source/SPTooltip.m
+++ b/Source/SPTooltip.m
@@ -42,11 +42,11 @@
// ofType:(NSString *)type
// displayOptions:(NSDictionary *)displayOptions]
//
-// content: a NSString with the actual content
+// content: a NSString with the actual content; a NSImage object AND type:"image"
// point: n NSPoint where the tooltip should be shown
// if not given it will be shown under the current caret position or
// if no caret could be found in the upper left corner of the current window
-// type: a NSString of: "text", or "html"; no type - 'text' is default
+// type: a NSString of: "text", "html", or "image"; no type - 'text' is default
// displayOptions: a NSDictionary with the following keys (all values must be of type NSString):
// fontname, fontsize, backgroundcolor (as #RRGGBB), transparent (any value)
// if no displayOptions are passed or if a key doesn't exist the following default
@@ -73,6 +73,7 @@ static float slow_in_out (float t)
- (void)setContent:(NSString *)content withOptions:(NSDictionary *)displayOptions;
- (void)runUntilUserActivity;
- (void)stopAnimation:(id)sender;
+- (void)sizeToContent;
+ (NSPoint)caretPosition;
+ (void)setDisplayOptions:(NSDictionary *)aDict;
- (void)initMeWithOptions:(NSDictionary *)displayOptions;
@@ -143,6 +144,42 @@ static float slow_in_out (float t)
else if([type isEqualToString:@"html"]) {
[tip setContent:(NSString*)content withOptions:displayOptions];
}
+ else if([type isEqualToString:@"image"]) {
+ [tip setBackgroundColor:[NSColor clearColor]];
+ [tip setOpaque:NO];
+ [tip setLevel:NSNormalWindowLevel];
+ [tip setExcludedFromWindowsMenu:YES];
+ [tip setAlphaValue:1];
+
+ NSSize s = [(NSImage *)content size];
+
+ // Downsize a large image
+ int w = s.width;
+ int h = s.height;
+ if(w>h) {
+ if(s.width > 200) {
+ w = 200;
+ h = 200/s.width*s.height;
+ }
+ } else {
+ if(s.height > 200) {
+ h = 200;
+ w = 200/s.height*s.width;
+ }
+ }
+
+ // Show image in a NSImageView
+ NSImageView *backgroundImageView = [[NSImageView alloc] initWithFrame:NSMakeRect(0,0,w, h)];
+ [backgroundImageView setImage:(NSImage *)content];
+ [backgroundImageView setFrameSize:NSMakeSize(w, h)];
+ [tip setContentView:backgroundImageView];
+ [tip setContentSize:NSMakeSize(w,h)];
+ [tip setFrameTopLeftPoint:point];
+ [tip sizeToContent];
+ [tip orderFront:self];
+ [tip performSelector:@selector(runUntilUserActivity) withObject:nil afterDelay:0];
+ [backgroundImageView release];
+ }
else {
[tip setContent:(NSString*)content withOptions:displayOptions];
NSBeep();
@@ -265,6 +302,9 @@ static float slow_in_out (float t)
- (void)sizeToContent
{
+
+ NSRect frame;
+
// Current tooltip position
NSPoint pos = NSMakePoint([self frame].origin.x, [self frame].origin.y + [self frame].size.height);
@@ -277,25 +317,33 @@ static float slow_in_out (float t)
screenFrame = [candidate frame];
}
- // The webview is set to a large initial size and then sized down to fit the content
- [self setContentSize:NSMakeSize(screenFrame.size.width - screenFrame.size.width / 3.0f , screenFrame.size.height)];
+ // is contentView a webView calculate actual rendered size via JavaScript
+ if([[[[self contentView] class] description] isEqualToString:@"WebView"]) {
+ // The webview is set to a large initial size and then sized down to fit the content
+ [self setContentSize:NSMakeSize(screenFrame.size.width - screenFrame.size.width / 3.0f , screenFrame.size.height)];
- int height = [[[webView windowScriptObject] evaluateWebScript:@"document.body.offsetHeight + document.body.offsetTop;"] intValue];
- int width = [[[webView windowScriptObject] evaluateWebScript:@"document.body.offsetWidth + document.body.offsetLeft;"] intValue];
+ int height = [[[webView windowScriptObject] evaluateWebScript:@"document.body.offsetHeight + document.body.offsetTop;"] intValue];
+ int width = [[[webView windowScriptObject] evaluateWebScript:@"document.body.offsetWidth + document.body.offsetLeft;"] intValue];
- [webView setFrameSize:NSMakeSize(width, height)];
+ [webView setFrameSize:NSMakeSize(width, height)];
- NSRect frame = [self frameRectForContentRect:[webView frame]];
+ frame = [self frameRectForContentRect:[webView frame]];
+ } else {
+ frame = [self frame];
+ }
+
+ //Adjust frame to fit into the screenFrame
frame.size.width = MIN(NSWidth(frame), NSWidth(screenFrame));
frame.size.height = MIN(NSHeight(frame), NSHeight(screenFrame));
-
[self setFrame:frame display:NO];
+ //Adjust tooltip origin to fit into the screenFrame
pos.x = MAX(NSMinX(screenFrame), MIN(pos.x, NSMaxX(screenFrame)-NSWidth(frame)));
pos.y = MIN(MAX(NSMinY(screenFrame)+NSHeight(frame), pos.y), NSMaxY(screenFrame));
[self setFrameTopLeftPoint:pos];
+
}
- (void)webView:(WebView*)sender didFinishLoadForFrame:(WebFrame*)frame;
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 3f8c9596..3ac60e29 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -1799,6 +1799,8 @@
- (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(SPTextAndLinkCell *)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)row mouseLocation:(NSPoint)mouseLocation
{
+ NSImage *image;
+
if([[aCell stringValue] length] < 1) return nil;
NSPoint pos = [NSEvent mouseLocation];
@@ -1807,22 +1809,17 @@
// 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];
+ image = [[NSImage alloc] initWithData:theValue];
if(image) {
- int imageWidth = [image size].width;
- if (imageWidth > 100) imageWidth = 100;
- [SPTooltip showWithObject:[NSString stringWithFormat:
- @"<IMG WIDTH='%d' SRC=\"data:image/auto;base64,%@\">",
- imageWidth,
- [[image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0]]
- atLocation:pos
- ofType:@"html"
- displayOptions:[NSDictionary dictionaryWithObjectsAndKeys:@"transparent", @"transparent", nil]];
+ [SPTooltip showWithObject:image atLocation:pos ofType:@"image"];
+ [image release];
+ theValue = nil;
+ return nil;
}
- [image release];
- return nil;
}
+ if(image) [image release];
+
// Show the cell string value as tooltip (including line breaks and tabs)
if([[aCell stringValue] length] > 1)
[SPTooltip showWithObject:[aCell stringValue] atLocation:pos];