Commit ab6bb569 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Simplify selection painting by drawing a selected run twice with appropriate clipping.

parent d528e760
...@@ -305,89 +305,91 @@ static void get_selection_rect( ME_Context *c, ME_Run *run, int from, int to, in ...@@ -305,89 +305,91 @@ static void get_selection_rect( ME_Context *c, ME_Run *run, int from, int to, in
return; return;
} }
static void draw_text( ME_Context *c, ME_Run *run, int x, int y, const WCHAR *text, BOOL selected, RECT *sel_rect )
{
COLORREF text_color = get_text_color( c, run->style, selected );
COLORREF back_color = selected ? ITextHost_TxGetSysColor( c->editor->texthost, COLOR_HIGHLIGHT ) : 0;
COLORREF old_text, old_back;
HPEN pen;
old_text = SetTextColor( c->hDC, text_color );
if (selected) old_back = SetBkColor( c->hDC, back_color );
ExtTextOutW( c->hDC, x, y, selected ? ETO_OPAQUE : 0, sel_rect, text, run->len, NULL );
if (selected) SetBkColor( c->hDC, old_back );
SetTextColor( c->hDC, old_text );
get_underline_pen( run->style, text_color, &pen );
if (pen)
{
HPEN old_pen = SelectObject( c->hDC, pen );
MoveToEx( c->hDC, x, y + 1, NULL );
LineTo( c->hDC, x + run->nWidth, y + 1 );
SelectObject( c->hDC, old_pen );
DeleteObject( pen );
}
return;
}
static void ME_DrawTextWithStyle(ME_Context *c, ME_Run *run, int x, int y, LPCWSTR szText, static void ME_DrawTextWithStyle(ME_Context *c, ME_Run *run, int x, int y, LPCWSTR szText,
int nSelFrom, int nSelTo, int ymin, int cy) int nSelFrom, int nSelTo, int ymin, int cy)
{ {
HDC hDC = c->hDC; HDC hDC = c->hDC;
HGDIOBJ hOldFont; HGDIOBJ hOldFont;
COLORREF rgbOld;
int yOffset = 0; int yOffset = 0;
COLORREF rgb; BOOL selected = (nSelFrom < run->len && nSelTo >= 0
HPEN hPen = NULL, hOldPen = NULL; && nSelFrom < nSelTo && !c->editor->bHideSelection);
BOOL bHighlightedText = (nSelFrom < run->len && nSelTo >= 0 BOOL old_style_selected = FALSE;
&& nSelFrom < nSelTo && !c->editor->bHideSelection);
RECT sel_rect; RECT sel_rect;
HRGN clip = NULL, sel_rgn = NULL;
yOffset = calc_y_offset( c, run->style ); yOffset = calc_y_offset( c, run->style );
rgb = get_text_color( c, run->style, FALSE ); if (selected)
if (bHighlightedText)
{ {
nSelFrom = max( 0, nSelFrom ); nSelFrom = max( 0, nSelFrom );
nSelTo = min( run->len, nSelTo ); nSelTo = min( run->len, nSelTo );
get_selection_rect( c, run, nSelFrom, nSelTo, cy, &sel_rect ); get_selection_rect( c, run, nSelFrom, nSelTo, cy, &sel_rect );
OffsetRect( &sel_rect, x, ymin ); OffsetRect( &sel_rect, x, ymin );
}
hOldFont = ME_SelectStyleFont(c, run->style);
get_underline_pen( run->style, rgb, &hPen ); if (c->editor->bEmulateVersion10)
if (hPen) hOldPen = SelectObject( hDC, hPen );
rgbOld = SetTextColor(hDC, rgb);
if (bHighlightedText && !c->editor->bEmulateVersion10)
{
COLORREF rgbBackOld;
/* FIXME: should use textmetrics info for Descent info */
if (hPen)
MoveToEx(hDC, x, y - yOffset + 1, NULL);
if (sel_rect.left > x)
{ {
ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nSelFrom, NULL); old_style_selected = TRUE;
if (hPen) selected = FALSE;
LineTo(hDC, sel_rect.left, y - yOffset + 1);
} }
SetTextColor( hDC, get_text_color( c, run->style, TRUE ) ); else
rgbBackOld = SetBkColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
COLOR_HIGHLIGHT));
ExtTextOutW(hDC, sel_rect.left, y-yOffset, ETO_OPAQUE, &sel_rect,
szText+nSelFrom, nSelTo-nSelFrom, NULL);
if (hPen)
LineTo(hDC, sel_rect.right, y - yOffset + 1);
SetBkColor(hDC, rgbBackOld);
if (sel_rect.right < x + run->nWidth)
{ {
SetTextColor(hDC, rgb); sel_rgn = CreateRectRgnIndirect( &sel_rect );
ExtTextOutW(hDC, sel_rect.right, y-yOffset, 0, NULL, szText+nSelTo, clip = CreateRectRgn( 0, 0, 0, 0 );
run->len - nSelTo, NULL); if (GetClipRgn( hDC, clip ) != 1)
if (hPen) {
LineTo(hDC, x + run->nWidth, y - yOffset + 1); DeleteObject( clip );
clip = NULL;
}
} }
} }
else
{
ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, run->len, NULL);
/* FIXME: should use textmetrics info for Descent info */ hOldFont = ME_SelectStyleFont( c, run->style );
if (hPen)
{
MoveToEx(hDC, x, y - yOffset + 1, NULL);
LineTo(hDC, x + run->nWidth, y - yOffset + 1);
}
if (bHighlightedText) /* v1.0 inverts the selection */
{
PatBlt(hDC, sel_rect.left, ymin, sel_rect.right - sel_rect.left, cy, DSTINVERT);
}
}
if (hPen) if (sel_rgn) ExtSelectClipRgn( hDC, sel_rgn, RGN_DIFF );
draw_text( c, run, x, y - yOffset, szText, FALSE, NULL );
if (sel_rgn)
{ {
SelectObject(hDC, hOldPen); ExtSelectClipRgn( hDC, clip, RGN_COPY );
DeleteObject(hPen); ExtSelectClipRgn( hDC, sel_rgn, RGN_AND );
draw_text( c, run, x, y - yOffset, szText, TRUE, &sel_rect );
ExtSelectClipRgn( hDC, clip, RGN_COPY );
if (clip) DeleteObject( clip );
DeleteObject( sel_rgn );
} }
SetTextColor(hDC, rgbOld);
if (old_style_selected)
PatBlt( hDC, sel_rect.left, ymin, sel_rect.right - sel_rect.left, cy, DSTINVERT );
ME_UnselectStyleFont(c, run->style, hOldFont); ME_UnselectStyleFont(c, run->style, hOldFont);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment