riched20: Move the white space painting operations to a common function.
This commit is contained in:
parent
4178de89ef
commit
4cbe94f42a
|
@ -228,55 +228,74 @@ static void get_underline_pen( ME_Style *style, COLORREF color, HPEN *pen )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ME_HighlightSpace(ME_Context *c, int x, int y, LPCWSTR szText,
|
/*********************************************************************
|
||||||
int nChars, ME_Style *s, int width,
|
* draw_space
|
||||||
int nSelFrom, int nSelTo, int ymin, int cy)
|
*
|
||||||
|
* Draw the end-of-paragraph or tab space.
|
||||||
|
*
|
||||||
|
* If actually_draw is TRUE then ensure any underline is drawn.
|
||||||
|
*/
|
||||||
|
static void draw_space( ME_Context *c, ME_Run *run, int x, int y,
|
||||||
|
BOOL selected, BOOL actually_draw, int ymin, int cy )
|
||||||
{
|
{
|
||||||
HDC hDC = c->hDC;
|
HDC hdc = c->hDC;
|
||||||
HGDIOBJ hOldFont = NULL;
|
BOOL old_style_selected = FALSE;
|
||||||
SIZE sz;
|
|
||||||
int selWidth;
|
|
||||||
/* Only highlight if there is a selection in the run and when
|
|
||||||
* EM_HIDESELECTION is not being used to hide the selection. */
|
|
||||||
if (nSelFrom >= nChars || nSelTo < 0 || nSelFrom >= nSelTo
|
|
||||||
|| c->editor->bHideSelection)
|
|
||||||
return;
|
|
||||||
hOldFont = ME_SelectStyleFont(c, s);
|
|
||||||
if (width <= 0)
|
|
||||||
{
|
|
||||||
GetTextExtentPoint32W(hDC, szText, nChars, &sz);
|
|
||||||
width = sz.cx;
|
|
||||||
}
|
|
||||||
if (nSelFrom < 0) nSelFrom = 0;
|
|
||||||
if (nSelTo > nChars) nSelTo = nChars;
|
|
||||||
GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
|
|
||||||
x += sz.cx;
|
|
||||||
if (nSelTo != nChars)
|
|
||||||
{
|
|
||||||
GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
|
|
||||||
selWidth = sz.cx;
|
|
||||||
} else {
|
|
||||||
selWidth = width - sz.cx;
|
|
||||||
}
|
|
||||||
ME_UnselectStyleFont(c, s, hOldFont);
|
|
||||||
|
|
||||||
if (c->editor->bEmulateVersion10)
|
|
||||||
PatBlt(hDC, x, ymin, selWidth, cy, DSTINVERT);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RECT rect;
|
RECT rect;
|
||||||
HBRUSH hBrush;
|
COLORREF back_color = 0;
|
||||||
rect.left = x;
|
|
||||||
rect.top = ymin;
|
SetRect( &rect, x, ymin, x + run->nWidth, ymin + cy );
|
||||||
rect.right = x + selWidth;
|
|
||||||
rect.bottom = ymin + cy;
|
if (c->editor->bHideSelection) selected = FALSE;
|
||||||
hBrush = CreateSolidBrush(ITextHost_TxGetSysColor(c->editor->texthost,
|
if (c->editor->bEmulateVersion10)
|
||||||
COLOR_HIGHLIGHT));
|
{
|
||||||
FillRect(hDC, &rect, hBrush);
|
old_style_selected = selected;
|
||||||
DeleteObject(hBrush);
|
selected = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selected)
|
||||||
|
back_color = ITextHost_TxGetSysColor( c->editor->texthost, COLOR_HIGHLIGHT );
|
||||||
|
|
||||||
|
if (actually_draw)
|
||||||
|
{
|
||||||
|
COLORREF text_color = get_text_color( c, run->style, selected );
|
||||||
|
COLORREF old_text, old_back;
|
||||||
|
HFONT old_font = NULL;
|
||||||
|
HPEN pen = NULL;
|
||||||
|
int y_offset = calc_y_offset( c, run->style );
|
||||||
|
static const WCHAR space[1] = {' '};
|
||||||
|
|
||||||
|
old_font = ME_SelectStyleFont( c, run->style );
|
||||||
|
old_text = SetTextColor( hdc, text_color );
|
||||||
|
if (selected) old_back = SetBkColor( hdc, back_color );
|
||||||
|
|
||||||
|
ExtTextOutW( hdc, x, y - y_offset, selected ? ETO_OPAQUE : 0, &rect, space, 1, &run->nWidth );
|
||||||
|
|
||||||
|
if (selected) SetBkColor( hdc, old_back );
|
||||||
|
SetTextColor( hdc, old_text );
|
||||||
|
ME_UnselectStyleFont( c, run->style, old_font );
|
||||||
|
|
||||||
|
get_underline_pen( run->style, text_color, &pen );
|
||||||
|
if (pen)
|
||||||
|
{
|
||||||
|
HPEN old_pen = SelectObject( hdc, pen );
|
||||||
|
MoveToEx( hdc, x, y - y_offset + 1, NULL );
|
||||||
|
LineTo( hdc, x + run->nWidth, y - y_offset + 1 );
|
||||||
|
SelectObject( hdc, old_pen );
|
||||||
|
DeleteObject( pen );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (selected)
|
||||||
|
{
|
||||||
|
HBRUSH brush = CreateSolidBrush( back_color );
|
||||||
|
FillRect( hdc, &rect, brush );
|
||||||
|
DeleteObject( brush );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (old_style_selected)
|
||||||
|
PatBlt( hdc, x, ymin, run->nWidth, cy, DSTINVERT );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 nChars, int nSelFrom, int nSelTo, int ymin, int cy)
|
int nChars, int nSelFrom, int nSelTo, int ymin, int cy)
|
||||||
{
|
{
|
||||||
|
@ -406,7 +425,6 @@ static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Pa
|
||||||
ME_DisplayItem *start;
|
ME_DisplayItem *start;
|
||||||
int runofs = run->nCharOfs+para->nCharOfs;
|
int runofs = run->nCharOfs+para->nCharOfs;
|
||||||
int nSelFrom, nSelTo;
|
int nSelFrom, nSelTo;
|
||||||
const WCHAR wszSpace[] = {' ', 0};
|
|
||||||
|
|
||||||
if (run->nFlags & MERF_HIDDEN)
|
if (run->nFlags & MERF_HIDDEN)
|
||||||
return;
|
return;
|
||||||
|
@ -419,21 +437,20 @@ static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Pa
|
||||||
{
|
{
|
||||||
if (runofs >= nSelFrom && runofs < nSelTo)
|
if (runofs >= nSelFrom && runofs < nSelTo)
|
||||||
{
|
{
|
||||||
ME_HighlightSpace(c, x, y, wszSpace, 1, run->style, 0, 0, 1,
|
draw_space( c, run, x, y, TRUE, FALSE,
|
||||||
c->pt.y + para->pt.y + start->member.row.pt.y,
|
c->pt.y + para->pt.y + start->member.row.pt.y,
|
||||||
start->member.row.nHeight);
|
start->member.row.nHeight );
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (run->nFlags & (MERF_TAB | MERF_ENDCELL))
|
if (run->nFlags & (MERF_TAB | MERF_ENDCELL))
|
||||||
{
|
{
|
||||||
/* wszSpace is used instead of the tab character because otherwise
|
BOOL selected = runofs >= nSelFrom && runofs < nSelTo;
|
||||||
* an unwanted symbol can be inserted instead. */
|
|
||||||
ME_DrawTextWithStyle(c, run, x, y, wszSpace, 1,
|
draw_space( c, run, x, y, selected, TRUE,
|
||||||
nSelFrom-runofs, nSelTo-runofs,
|
c->pt.y + para->pt.y + start->member.row.pt.y,
|
||||||
c->pt.y + para->pt.y + start->member.row.pt.y,
|
start->member.row.nHeight );
|
||||||
start->member.row.nHeight);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue