Revision: 7215
http://skim-app.svn.sourceforge.net/skim-app/?rev=7215&view=rev
Author: hofman
Date: 2011-04-22 10:17:58 +0000 (Fri, 22 Apr 2011)
Log Message:
-----------
replace function by method
Modified Paths:
--------------
trunk/SKImageToolTipContext.h
trunk/SKImageToolTipContext.m
Modified: trunk/SKImageToolTipContext.h
===================================================================
--- trunk/SKImageToolTipContext.h 2011-04-21 10:17:28 UTC (rev 7214)
+++ trunk/SKImageToolTipContext.h 2011-04-22 10:17:58 UTC (rev 7215)
@@ -45,6 +45,9 @@
@end
+@interface NSAttributedString (SKImageToolTipContext) <SKImageToolTipContext>
+@end
+
@interface PDFDestination (SKImageToolTipContext) <SKImageToolTipContext>
@end
Modified: trunk/SKImageToolTipContext.m
===================================================================
--- trunk/SKImageToolTipContext.m 2011-04-21 10:17:28 UTC (rev 7214)
+++ trunk/SKImageToolTipContext.m 2011-04-22 10:17:58 UTC (rev 7215)
@@ -60,14 +60,17 @@
return [[[NSAttributedString alloc] initWithString:string
attributes:attributes] autorelease];
}
-static NSImage *toolTipImageForAttributedString(NSAttributedString
*attrString) {
+
+@implementation NSAttributedString (SKImageToolTipContext)
+
+- (NSImage *)toolTipImage {
static NSColor *backgroundColor = nil;
if (backgroundColor == nil)
backgroundColor = [[NSColor colorWithCalibratedRed:1.0 green:1.0
blue:0.75 alpha:1.0] retain];
CGFloat width = [[NSUserDefaults standardUserDefaults]
doubleForKey:SKToolTipWidthKey];
CGFloat height = [[NSUserDefaults standardUserDefaults]
doubleForKey:SKToolTipHeightKey];
- NSRect textRect = [attrString boundingRectWithSize:NSMakeSize(width + 2 *
TEXT_MARGIN_X, height + 2 * TEXT_MARGIN_Y)
options:NSStringDrawingUsesLineFragmentOrigin];
+ NSRect textRect = [self boundingRectWithSize:NSMakeSize(width + 2 *
TEXT_MARGIN_X, height + 2 * TEXT_MARGIN_Y)
options:NSStringDrawingUsesLineFragmentOrigin];
textRect.size.height = fmin(NSHeight(textRect), height);
textRect.origin = NSMakePoint(TEXT_MARGIN_X, TEXT_MARGIN_Y);
@@ -78,13 +81,15 @@
[image lockFocus];
[backgroundColor setFill];
NSRectFill(imageRect);
- [attrString drawWithRect:textRect
options:NSStringDrawingUsesLineFragmentOrigin];
+ [self drawWithRect:textRect options:NSStringDrawingUsesLineFragmentOrigin];
[image unlockFocus];
return image;
}
+@end
+
@interface PDFDestination (SKImageToolTipContextExtension)
- (NSImage *)toolTipImageWithOffset:(NSPoint)offset;
@end
@@ -194,23 +199,26 @@
NSAttributedString *attrString = [self text];
NSString *string = [attrString string];
NSUInteger i, l = [string length];
- NSRange r = NSMakeRange(0, l);
if (l == 0 || [string rangeOfCharacterFromSet:[NSCharacterSet
nonWhitespaceAndNewlineCharacterSet]].location == NSNotFound) {
string = [self string];
- attrString = [string length] ? toolTipAttributedString(string) : nil;
+ l = [string length];
+ attrString = l > 0 ? toolTipAttributedString(string) : nil;
}
- if ([string length]) {
+ if (l > 0) {
+ NSRange r = NSMakeRange(0, l);
while (NSNotFound != (i = NSMaxRange([string
rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]
options:NSAnchoredSearch range:r])))
r = NSMakeRange(i, l - i);
while (NSNotFound != (i = [string
rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]
options:NSBackwardsSearch | NSAnchoredSearch range:r].location))
r.length = i - r.location;
- if (r.length < l)
+ if (r.length == 0)
+ attrString == nil;
+ else if (NSMaxRange(r) < l)
attrString = [attrString attributedSubstringFromRange:r];
}
- return [attrString length] ? toolTipImageForAttributedString(attrString) :
nil;
+ return [attrString length] ? [attrString toolTipImage] : nil;
}
@end
@@ -223,7 +231,7 @@
if (image == nil && [self URL]) {
NSAttributedString *attrString = toolTipAttributedString([[self URL]
absoluteString]);
if ([attrString length])
- image = toolTipImageForAttributedString(attrString);
+ image = [attrString toolTipImage];
}
return image;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit