From fc1b2e0473d26ecb37575edae139e3a684e3d1c8 Mon Sep 17 00:00:00 2001 From: Kenneth Haley Date: Mon, 15 Aug 2016 13:03:07 -0600 Subject: [PATCH] v4 resend: Riched20: allow setting background text color. Signed-off-by: Kenneth Haley Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/riched20/editor.c | 2 +- dlls/riched20/paint.c | 43 +++++++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index fb77a671be6..9c54623c526 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -489,7 +489,7 @@ void ME_RTFCharAttrHook(RTF_Info *info) { RTFColor *c = RTFGetColor(info, info->rtfParam); if (c && c->rtfCBlue >= 0) - fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed); + fmt.crBackColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed); else fmt.dwEffects = CFE_AUTOBACKCOLOR; } diff --git a/dlls/riched20/paint.c b/dlls/riched20/paint.c index 42434b9b470..736080aa692 100644 --- a/dlls/riched20/paint.c +++ b/dlls/riched20/paint.c @@ -201,6 +201,21 @@ static COLORREF get_text_color( ME_Context *c, ME_Style *style, BOOL highlight ) return color; } +static COLORREF get_back_color( ME_Context *c, ME_Style *style, BOOL highlight ) +{ + COLORREF color; + + if (highlight) + color = ITextHost_TxGetSysColor( c->editor->texthost, COLOR_HIGHLIGHT ); + else if ( (style->fmt.dwMask & CFM_BACKCOLOR) + && !(style->fmt.dwEffects & CFE_AUTOBACKCOLOR) ) + color = style->fmt.crBackColor; + else + color = ITextHost_TxGetSysColor( c->editor->texthost, COLOR_WINDOW ); + + return color; +} + static void get_underline_pen( ME_Style *style, COLORREF color, HPEN *pen ) { *pen = NULL; @@ -314,14 +329,17 @@ static void get_selection_rect( ME_Context *c, ME_Run *run, int from, int to, in return; } - static void draw_text( ME_Context *c, ME_Run *run, int x, int y, 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 back_color = get_back_color( c, run->style, selected ); COLORREF old_text, old_back = 0; const WCHAR *text = get_text( run, 0 ); ME_String *masked = NULL; + const BOOL paint_bg = ( selected + || ( ( run->style->fmt.dwMask & CFM_BACKCOLOR ) + && !(CFE_AUTOBACKCOLOR & run->style->fmt.dwEffects) ) + ); if (c->editor->cPasswordMask) { @@ -330,16 +348,16 @@ static void draw_text( ME_Context *c, ME_Run *run, int x, int y, BOOL selected, } old_text = SetTextColor( c->hDC, text_color ); - if (selected) old_back = SetBkColor( c->hDC, back_color ); + if (paint_bg) old_back = SetBkColor( c->hDC, back_color ); if (run->para->nFlags & MEPF_COMPLEX) - ScriptTextOut( c->hDC, &run->style->script_cache, x, y, selected ? ETO_OPAQUE : 0, sel_rect, + ScriptTextOut( c->hDC, &run->style->script_cache, x, y, paint_bg ? ETO_OPAQUE : 0, sel_rect, &run->script_analysis, NULL, 0, run->glyphs, run->num_glyphs, run->advances, NULL, run->offsets ); else - ExtTextOutW( c->hDC, x, y, selected ? ETO_OPAQUE : 0, sel_rect, text, run->len, NULL ); + ExtTextOutW( c->hDC, x, y, paint_bg ? ETO_OPAQUE : 0, sel_rect, text, run->len, NULL ); - if (selected) SetBkColor( c->hDC, old_back ); + if (paint_bg) SetBkColor( c->hDC, old_back ); SetTextColor( c->hDC, old_text ); draw_underline( c, run, x, y, text_color ); @@ -389,7 +407,18 @@ static void ME_DrawTextWithStyle(ME_Context *c, ME_Run *run, int x, int y, hOldFont = ME_SelectStyleFont( c, run->style ); if (sel_rgn) ExtSelectClipRgn( hDC, sel_rgn, RGN_DIFF ); - draw_text( c, run, x, y - yOffset, FALSE, NULL ); + + if (!(run->style->fmt.dwEffects & CFE_AUTOBACKCOLOR) + && (run->style->fmt.dwMask & CFM_BACKCOLOR) ) + { + RECT tmp_rect; + get_selection_rect( c, run, 0, run->len, cy, &tmp_rect ); + OffsetRect( &tmp_rect, x, ymin ); + draw_text( c, run, x, y - yOffset, FALSE, &tmp_rect ); + } + else + draw_text( c, run, x, y - yOffset, FALSE, NULL ); + if (sel_rgn) { ExtSelectClipRgn( hDC, clip, RGN_COPY );