(-glyphIndexForPoint:inTextContainer:fractionOfDistanceThroughGlyph:): Try harder to always return a valid glyph index.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15727 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-01-26 20:10:21 +00:00
parent 7e4d879270
commit 8a98cb98a8
2 changed files with 36 additions and 4 deletions

View file

@ -1,3 +1,9 @@
2003-01-26 21:08 Alexander Malmberg <alexander@malmberg.org>
* Source/NSLayoutManager.m
(-glyphIndexForPoint:inTextContainer:fractionOfDistanceThroughGlyph:):
Try harder to always return a valid glyph index.
2003-01-26 20:41 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/NSTextView.h: Don't use protocol forward

View file

@ -414,6 +414,10 @@ line frag rect. */
fractionOfDistanceThroughGlyph: NULL];
}
/*
TODO: decide on behavior wrt. invisible glyphs and pointer far away from
anything visible
*/
- (unsigned int) glyphIndexForPoint: (NSPoint)point
inTextContainer: (NSTextContainer *)container
fractionOfDistanceThroughGlyph: (float *)partialFraction
@ -439,10 +443,32 @@ line frag rect. */
[self _doLayoutToContainer: i point: point];
for (i = 0, lf = tc->linefrags; i < tc->num_linefrags; i++, lf++)
if (NSPointInRect(point, lf->rect))
break;
{
if (NSPointInRect(point, lf->rect))
break;
/* Point is between two lines. */
if (NSMinY(lf->rect) > point.y)
{
if (lf->pos > 0)
{
*partialFraction = 1.0;
return lf->pos - 1;
}
else
{
*partialFraction = 0.0;
return lf->pos;
}
}
}
/* Point is below all line frags. */
if (i == tc->num_linefrags)
return -1;
{
*partialFraction = 1.0;
return tc->pos + tc->length - 1; /* TODO: this should return the correct thing even if the container is empty */
}
/* only interested in x from here on */
point.x -= lf->rect.origin.x;
@ -475,7 +501,7 @@ line frag rect. */
prev = lp->p.x;
last_visible = (unsigned int)-1;
last_visible = lf->pos;
for (i = lp->pos - glyph_pos; i + glyph_pos < lp->pos + lp->length; )
{
if (r->glyphs[i].isNotShown || r->glyphs[i].g == NSControlGlyph ||