riched20: Use run ptrs in GetCharFormat().

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2020-10-15 10:39:37 +01:00 committed by Alexandre Julliard
parent 54c31d5332
commit 1994d21ddb
1 changed files with 28 additions and 39 deletions

View File

@ -816,9 +816,9 @@ void ME_SetCharFormat( ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end,
} }
} }
static void ME_GetRunCharFormat(ME_TextEditor *editor, ME_DisplayItem *run, CHARFORMAT2W *pFmt) static void run_copy_char_fmt( ME_Run *run, CHARFORMAT2W *fmt )
{ {
ME_CopyCharFormat(pFmt, &run->member.run.style->fmt); ME_CopyCharFormat( fmt, &run->style->fmt );
} }
/****************************************************************************** /******************************************************************************
@ -856,33 +856,25 @@ void ME_GetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
* Returns the style consisting of those attributes which are consistently set * Returns the style consisting of those attributes which are consistently set
* in the whole character range. * in the whole character range.
*/ */
void ME_GetCharFormat(ME_TextEditor *editor, const ME_Cursor *from, void ME_GetCharFormat( ME_TextEditor *editor, const ME_Cursor *from,
const ME_Cursor *to, CHARFORMAT2W *pFmt) const ME_Cursor *to, CHARFORMAT2W *fmt )
{ {
ME_DisplayItem *run, *run_end; ME_Run *run, *run_end, *prev_run;
CHARFORMAT2W tmp; CHARFORMAT2W tmp;
run = from->pRun; run = &from->pRun->member.run;
/* special case - if selection is empty, take previous char's formatting */ /* special case - if selection is empty, take previous char's formatting */
if (from->pRun == to->pRun && from->nOffset == to->nOffset) if (from->pRun == to->pRun && from->nOffset == to->nOffset)
{ {
if (!from->nOffset) if (!from->nOffset && (prev_run = run_prev( run ))) run = prev_run;
{ run_copy_char_fmt( run, fmt );
ME_DisplayItem *tmp_run = ME_FindItemBack(run, diRunOrParagraph);
if (tmp_run->type == diRun) {
ME_GetRunCharFormat(editor, tmp_run, pFmt);
return;
}
}
ME_GetRunCharFormat(editor, run, pFmt);
return; return;
} }
run_end = to->pRun; run_end = &to->pRun->member.run;
if (!to->nOffset) if (!to->nOffset) run_end = run_prev_all_paras( run_end );
run_end = ME_FindItemBack(run_end, diRun);
ME_GetRunCharFormat(editor, run, pFmt); run_copy_char_fmt( run, fmt );
if (run == run_end) return; if (run == run_end) return;
@ -891,40 +883,37 @@ void ME_GetCharFormat(ME_TextEditor *editor, const ME_Cursor *from,
DWORD dwAttribs = CFM_SIZE | CFM_FACE | CFM_COLOR | CFM_UNDERLINETYPE; DWORD dwAttribs = CFM_SIZE | CFM_FACE | CFM_COLOR | CFM_UNDERLINETYPE;
DWORD dwEffects = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED | CFM_LINK | CFM_SUPERSCRIPT; DWORD dwEffects = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED | CFM_LINK | CFM_SUPERSCRIPT;
run = ME_FindItemFwd(run, diRun); run = run_next_all_paras( run );
ZeroMemory(&tmp, sizeof(tmp)); memset( &tmp, 0, sizeof(tmp) );
tmp.cbSize = sizeof(tmp); tmp.cbSize = sizeof(tmp);
ME_GetRunCharFormat(editor, run, &tmp); run_copy_char_fmt( run, &tmp );
assert((tmp.dwMask & dwAttribs) == dwAttribs); assert((tmp.dwMask & dwAttribs) == dwAttribs);
/* reset flags that differ */ /* reset flags that differ */
if (pFmt->yHeight != tmp.yHeight) if (fmt->yHeight != tmp.yHeight) fmt->dwMask &= ~CFM_SIZE;
pFmt->dwMask &= ~CFM_SIZE; if (fmt->dwMask & CFM_FACE)
if (pFmt->dwMask & CFM_FACE)
{ {
if (!(tmp.dwMask & CFM_FACE)) if (!(tmp.dwMask & CFM_FACE))
pFmt->dwMask &= ~CFM_FACE; fmt->dwMask &= ~CFM_FACE;
else if (wcscmp(pFmt->szFaceName, tmp.szFaceName) || else if (wcscmp( fmt->szFaceName, tmp.szFaceName ) ||
pFmt->bPitchAndFamily != tmp.bPitchAndFamily) fmt->bPitchAndFamily != tmp.bPitchAndFamily)
pFmt->dwMask &= ~CFM_FACE; fmt->dwMask &= ~CFM_FACE;
} }
if (pFmt->yHeight != tmp.yHeight) if (fmt->yHeight != tmp.yHeight) fmt->dwMask &= ~CFM_SIZE;
pFmt->dwMask &= ~CFM_SIZE; if (fmt->bUnderlineType != tmp.bUnderlineType) fmt->dwMask &= ~CFM_UNDERLINETYPE;
if (pFmt->bUnderlineType != tmp.bUnderlineType) if (fmt->dwMask & CFM_COLOR)
pFmt->dwMask &= ~CFM_UNDERLINETYPE;
if (pFmt->dwMask & CFM_COLOR)
{ {
if (!((pFmt->dwEffects&CFE_AUTOCOLOR) & (tmp.dwEffects&CFE_AUTOCOLOR))) if (!((fmt->dwEffects&CFE_AUTOCOLOR) & (tmp.dwEffects&CFE_AUTOCOLOR)))
{ {
if (pFmt->crTextColor != tmp.crTextColor) if (fmt->crTextColor != tmp.crTextColor)
pFmt->dwMask &= ~CFM_COLOR; fmt->dwMask &= ~CFM_COLOR;
} }
} }
pFmt->dwMask &= ~((pFmt->dwEffects ^ tmp.dwEffects) & dwEffects); fmt->dwMask &= ~((fmt->dwEffects ^ tmp.dwEffects) & dwEffects);
pFmt->dwEffects = tmp.dwEffects; fmt->dwEffects = tmp.dwEffects;
} while(run != run_end); } while(run != run_end);
} }