* Source/NSTextView.m: Use pointing hand cursor for links

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33043 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Eric Wasylishen 2011-05-15 06:55:33 +00:00
parent 360c974c4e
commit d199cb565e
2 changed files with 51 additions and 0 deletions

View file

@ -1,3 +1,7 @@
2011-05-15 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSTextView.m: Use pointing hand cursor for links
2011-05-14 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSTableHeaderView.m: Use resize cursors

View file

@ -3901,6 +3901,53 @@ Figure out how the additional layout stuff is supposed to work.
{
[self addCursorRect: visibleRect cursor: [NSCursor IBeamCursor]];
}
/**
* Add pointing hand cursor to any visible links
* FIXME: Also look for NSCursorAttributeName
* FIXME: Too complex, factor out common patterns into private methods
*/
if (_layoutManager != nil && _textContainer != nil)
{
NSInteger i;
NSRange visibleGlyphs, visibleCharacters;
const NSPoint containerOrigin = [self textContainerOrigin];
NSRect visibleRectInContainerCoordinates = visibleRect;
visibleRectInContainerCoordinates.origin.x -= containerOrigin.x;
visibleRectInContainerCoordinates.origin.y -= containerOrigin.y;
visibleGlyphs = [_layoutManager glyphRangeForBoundingRectWithoutAdditionalLayout: visibleRectInContainerCoordinates
inTextContainer: _textContainer];
visibleCharacters = [_layoutManager characterRangeForGlyphRange: visibleGlyphs
actualGlyphRange: NULL];
for (i = visibleCharacters.location; i < NSMaxRange(visibleCharacters); )
{
NSRange linkCharacterRange;
id linkValue = [[self textStorage] attribute: NSLinkAttributeName
atIndex: i
longestEffectiveRange: &linkCharacterRange
inRange: visibleCharacters];
if (linkValue != nil)
{
NSUInteger count, j;
NSRectArray rects = [_layoutManager rectArrayForCharacterRange: linkCharacterRange
withinSelectedCharacterRange: linkCharacterRange
inTextContainer: _textContainer
rectCount: &count];
for (j = 0; j < count; j++)
{
NSRect rectInViewCoordinates = rects[j];
rectInViewCoordinates.origin.x += containerOrigin.x;
rectInViewCoordinates.origin.y += containerOrigin.y;
[self addCursorRect: rectInViewCoordinates
cursor: [NSCursor pointingHandCursor]];
}
}
i += linkCharacterRange.length;
}
}
}
}