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

riched20: Use the point from char helpers to calculate the selection rectangle.

parent 2a6f99ef
...@@ -295,6 +295,15 @@ static void draw_space( ME_Context *c, ME_Run *run, int x, int y, ...@@ -295,6 +295,15 @@ static void draw_space( ME_Context *c, ME_Run *run, int x, int y,
PatBlt( hdc, x, ymin, run->nWidth, cy, DSTINVERT ); PatBlt( hdc, x, ymin, run->nWidth, cy, DSTINVERT );
} }
static void get_selection_rect( ME_Context *c, ME_Run *run, int from, int to, int cy, RECT *r )
{
r->left = ME_PointFromCharContext( c, run, from );
r->top = 0;
r->right = ME_PointFromCharContext( c, run, to );
r->bottom = cy;
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)
...@@ -307,37 +316,22 @@ static void ME_DrawTextWithStyle(ME_Context *c, ME_Run *run, int x, int y, LPCWS ...@@ -307,37 +316,22 @@ static void ME_DrawTextWithStyle(ME_Context *c, ME_Run *run, int x, int y, LPCWS
HPEN hPen = NULL, hOldPen = NULL; HPEN hPen = NULL, hOldPen = NULL;
BOOL bHighlightedText = (nSelFrom < run->len && nSelTo >= 0 BOOL bHighlightedText = (nSelFrom < run->len && nSelTo >= 0
&& nSelFrom < nSelTo && !c->editor->bHideSelection); && nSelFrom < nSelTo && !c->editor->bHideSelection);
int xSelStart = x, xSelEnd = x; RECT sel_rect;
hOldFont = ME_SelectStyleFont(c, run->style);
yOffset = calc_y_offset( c, run->style ); yOffset = calc_y_offset( c, run->style );
rgb = get_text_color( c, run->style, FALSE ); rgb = get_text_color( c, run->style, FALSE );
if (bHighlightedText) if (bHighlightedText)
{ {
SIZE sz; nSelFrom = max( 0, nSelFrom );
if (nSelFrom <= 0) nSelTo = min( run->len, nSelTo );
{ get_selection_rect( c, run, nSelFrom, nSelTo, cy, &sel_rect );
nSelFrom = 0; OffsetRect( &sel_rect, x, ymin );
}
else
{
GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
xSelStart = x + sz.cx;
}
if (nSelTo >= run->len)
{
nSelTo = run->len;
xSelEnd = x + run->nWidth;
}
else
{
GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
xSelEnd = xSelStart + sz.cx;
}
} }
hOldFont = ME_SelectStyleFont(c, run->style);
get_underline_pen( run->style, rgb, &hPen ); get_underline_pen( run->style, rgb, &hPen );
if (hPen) hOldPen = SelectObject( hDC, hPen ); if (hPen) hOldPen = SelectObject( hDC, hPen );
...@@ -345,32 +339,27 @@ static void ME_DrawTextWithStyle(ME_Context *c, ME_Run *run, int x, int y, LPCWS ...@@ -345,32 +339,27 @@ static void ME_DrawTextWithStyle(ME_Context *c, ME_Run *run, int x, int y, LPCWS
if (bHighlightedText && !c->editor->bEmulateVersion10) if (bHighlightedText && !c->editor->bEmulateVersion10)
{ {
COLORREF rgbBackOld; COLORREF rgbBackOld;
RECT dim;
/* FIXME: should use textmetrics info for Descent info */ /* FIXME: should use textmetrics info for Descent info */
if (hPen) if (hPen)
MoveToEx(hDC, x, y - yOffset + 1, NULL); MoveToEx(hDC, x, y - yOffset + 1, NULL);
if (xSelStart > x) if (sel_rect.left > x)
{ {
ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nSelFrom, NULL); ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nSelFrom, NULL);
if (hPen) if (hPen)
LineTo(hDC, xSelStart, y - yOffset + 1); LineTo(hDC, sel_rect.left, y - yOffset + 1);
} }
dim.top = ymin;
dim.bottom = ymin + cy;
dim.left = xSelStart;
dim.right = xSelEnd;
SetTextColor( hDC, get_text_color( c, run->style, TRUE ) ); SetTextColor( hDC, get_text_color( c, run->style, TRUE ) );
rgbBackOld = SetBkColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost, rgbBackOld = SetBkColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
COLOR_HIGHLIGHT)); COLOR_HIGHLIGHT));
ExtTextOutW(hDC, xSelStart, y-yOffset, ETO_OPAQUE, &dim, ExtTextOutW(hDC, sel_rect.left, y-yOffset, ETO_OPAQUE, &sel_rect,
szText+nSelFrom, nSelTo-nSelFrom, NULL); szText+nSelFrom, nSelTo-nSelFrom, NULL);
if (hPen) if (hPen)
LineTo(hDC, xSelEnd, y - yOffset + 1); LineTo(hDC, sel_rect.right, y - yOffset + 1);
SetBkColor(hDC, rgbBackOld); SetBkColor(hDC, rgbBackOld);
if (xSelEnd < x + run->nWidth) if (sel_rect.right < x + run->nWidth)
{ {
SetTextColor(hDC, rgb); SetTextColor(hDC, rgb);
ExtTextOutW(hDC, xSelEnd, y-yOffset, 0, NULL, szText+nSelTo, ExtTextOutW(hDC, sel_rect.right, y-yOffset, 0, NULL, szText+nSelTo,
run->len - nSelTo, NULL); run->len - nSelTo, NULL);
if (hPen) if (hPen)
LineTo(hDC, x + run->nWidth, y - yOffset + 1); LineTo(hDC, x + run->nWidth, y - yOffset + 1);
...@@ -389,7 +378,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, ME_Run *run, int x, int y, LPCWS ...@@ -389,7 +378,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, ME_Run *run, int x, int y, LPCWS
if (bHighlightedText) /* v1.0 inverts the selection */ if (bHighlightedText) /* v1.0 inverts the selection */
{ {
PatBlt(hDC, xSelStart, ymin, xSelEnd-xSelStart, cy, DSTINVERT); PatBlt(hDC, sel_rect.left, ymin, sel_rect.right - sel_rect.left, cy, DSTINVERT);
} }
} }
......
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