Draw background for the selected range.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15730 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-01-26 23:02:55 +00:00
parent ecfebfecfc
commit b3782e2403
2 changed files with 58 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2003-01-27 00:01 Alexander Malmberg <alexander@malmberg.org>
* Source/NSLayoutManager.m (-drawBackgroundForGlyphRange:atPoint:):
Draw background for the selected range.
2003-01-26 21:16 Alexander Malmberg <alexander@malmberg.org>
* Source/NSLayoutManager.m

View file

@ -558,7 +558,7 @@ container */
{
NSTextContainer *textContainer;
glyph_run_t *glyph_run;
unsigned int glyph_pos, char_pos;
unsigned int glyph_pos, char_pos, first_char_pos;
int i, j;
NSRect *rects;
int count;
@ -593,6 +593,7 @@ container */
glyph_run = run_for_glyph_index(range.location, glyphs, &glyph_pos, &char_pos);
i = range.location - glyph_pos;
last_color = nil;
first_char_pos = char_pos;
while (1)
{
rects = [self rectArrayForGlyphRange:
@ -622,6 +623,7 @@ container */
}
}
}
glyph_pos += glyph_run->head.glyph_length;
char_pos += glyph_run->head.char_length;
i = 0;
@ -629,6 +631,56 @@ container */
if (i + glyph_pos >= range.location + range.length)
break;
}
if (!_selected_range.length || _selected_range.location == NSNotFound)
return;
if (_selected_range.location >= char_pos ||
_selected_range.location + _selected_range.length <= first_char_pos)
{
return;
}
/* The selection (might) intersect our glyph range. */
{
NSRange r = [self glyphRangeForCharacterRange: _selected_range
actualCharacterRange: NULL];
NSRange sel = r;
if (r.location < range.location)
{
r.length -= range.location - r.location;
r.location = range.location;
}
if (r.location + r.length > range.location + range.length)
{
r.length = range.location + range.length - r.location;
}
if (r.length <= 0)
return;
/* TODO: use the text view's selected text attributes */
color = [NSColor selectedTextBackgroundColor];
if (!color)
return;
rects = [self rectArrayForGlyphRange: r
withinSelectedGlyphRange: sel
inTextContainer: textContainer
rectCount: &count];
if (count)
{
[color set];
for (j = 0; j < count; j++, rects++)
{
DPSrectfill(ctxt,
rects->origin.x + containerOrigin.x,
rects->origin.y + containerOrigin.y,
rects->size.width, rects->size.height);
}
}
}
}