riched20: Some cleanup for CHARFORMAT convertor functions.

Signed-off-by: Jactry Zeng <jzeng@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jactry Zeng 2018-07-13 17:11:35 +08:00 committed by Alexandre Julliard
parent 6e264bbd1d
commit 8d506cb216
3 changed files with 31 additions and 28 deletions

View File

@ -3901,17 +3901,17 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
return editor->nEventMask;
case EM_SETCHARFORMAT:
{
CHARFORMAT2W buf, *p;
CHARFORMAT2W p;
BOOL bRepaint = TRUE;
p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
if (p == NULL) return 0;
if (!cfany_to_cf2w(&p, (CHARFORMAT2W *)lParam))
return 0;
if (wParam & SCF_ALL) {
if (editor->mode & TM_PLAINTEXT) {
ME_SetDefaultCharFormat(editor, p);
ME_SetDefaultCharFormat(editor, &p);
} else {
ME_Cursor start;
ME_SetCursorToStart(editor, &start);
ME_SetCharFormat(editor, &start, NULL, p);
ME_SetCharFormat(editor, &start, NULL, &p);
editor->nModifyStep = 1;
}
} else if (wParam & SCF_SELECTION) {
@ -3923,13 +3923,13 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
ME_MoveCursorWords(editor, &end, +1);
start = end;
ME_MoveCursorWords(editor, &start, -1);
ME_SetCharFormat(editor, &start, &end, p);
ME_SetCharFormat(editor, &start, &end, &p);
}
bRepaint = ME_IsSelection(editor);
ME_SetSelectionCharFormat(editor, p);
ME_SetSelectionCharFormat(editor, &p);
if (bRepaint) editor->nModifyStep = 1;
} else { /* SCF_DEFAULT */
ME_SetDefaultCharFormat(editor, p);
ME_SetDefaultCharFormat(editor, &p);
}
ME_CommitUndo(editor);
if (bRepaint)
@ -3953,7 +3953,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
ME_GetDefaultCharFormat(editor, &tmp);
else
ME_GetSelectionCharFormat(editor, &tmp);
ME_CopyToCFAny(dst, &tmp);
cf2w_to_cfany(dst, &tmp);
return tmp.dwMask;
}
case EM_SETPARAFORMAT:

View File

@ -61,8 +61,8 @@ void ME_SaveTempStyle(ME_TextEditor *editor, ME_Style *style) DECLSPEC_HIDDEN;
void ME_ClearTempStyle(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048]) DECLSPEC_HIDDEN;
void ME_DumpStyle(ME_Style *s) DECLSPEC_HIDDEN;
CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from) DECLSPEC_HIDDEN;
void ME_CopyToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from) DECLSPEC_HIDDEN;
BOOL cfany_to_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from) DECLSPEC_HIDDEN;
BOOL cf2w_to_cfany(CHARFORMAT2W *to, const CHARFORMAT2W *from) DECLSPEC_HIDDEN;
void ME_CopyCharFormat(CHARFORMAT2W *pDest, const CHARFORMAT2W *pSrc) DECLSPEC_HIDDEN; /* only works with 2W structs */
void ME_CharFormatFromLogFont(HDC hDC, const LOGFONTW *lf, CHARFORMAT2W *fmt) DECLSPEC_HIDDEN; /* ditto */

View File

@ -33,7 +33,7 @@ static int all_refs = 0;
* sizeof(char[AW])
*/
CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
BOOL cfany_to_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from)
{
if (from->cbSize == sizeof(CHARFORMATA))
{
@ -43,7 +43,7 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
if (f->dwMask & CFM_FACE) {
MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
}
return to;
return TRUE;
}
if (from->cbSize == sizeof(CHARFORMATW))
{
@ -52,7 +52,7 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
/* theoretically, we don't need to zero the remaining memory */
ZeroMemory(&to->wWeight, sizeof(CHARFORMAT2W)-FIELD_OFFSET(CHARFORMAT2W, wWeight));
to->cbSize = sizeof(CHARFORMAT2W);
return to;
return TRUE;
}
if (from->cbSize == sizeof(CHARFORMAT2A))
{
@ -65,13 +65,18 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
/* copy the rest of the 2A structure to 2W */
CopyMemory(&to->wWeight, &f->wWeight, sizeof(CHARFORMAT2A)-FIELD_OFFSET(CHARFORMAT2A, wWeight));
to->cbSize = sizeof(CHARFORMAT2W);
return to;
return TRUE;
}
if (from->cbSize == sizeof(CHARFORMAT2W))
{
CopyMemory(to, from, sizeof(CHARFORMAT2W));
return TRUE;
}
return (from->cbSize >= sizeof(CHARFORMAT2W)) ? from : NULL;
return FALSE;
}
static CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
BOOL cf2w_to_cfany(CHARFORMAT2W *to, const CHARFORMAT2W *from)
{
assert(from->cbSize == sizeof(CHARFORMAT2W));
if (to->cbSize == sizeof(CHARFORMATA))
@ -80,14 +85,14 @@ static CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
CopyMemory(t, from, FIELD_OFFSET(CHARFORMATA, szFaceName));
WideCharToMultiByte(CP_ACP, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), NULL, NULL);
t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
return to;
return TRUE;
}
if (to->cbSize == sizeof(CHARFORMATW))
{
CHARFORMATW *t = (CHARFORMATW *)to;
CopyMemory(t, from, sizeof(*t));
t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
return to;
return TRUE;
}
if (to->cbSize == sizeof(CHARFORMAT2A))
{
@ -99,16 +104,14 @@ static CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
/* copy the rest of the 2A structure to 2W */
CopyMemory(&t->wWeight, &from->wWeight, sizeof(CHARFORMAT2W)-FIELD_OFFSET(CHARFORMAT2W,wWeight));
t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
return to;
return TRUE;
}
assert(to->cbSize >= sizeof(CHARFORMAT2W));
return from;
}
void ME_CopyToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
if (to->cbSize == sizeof(CHARFORMAT2W))
{
if (ME_ToCFAny(to, from) == from)
CopyMemory(to, from, to->cbSize);
CopyMemory(to, from, sizeof(CHARFORMAT2W));
return TRUE;
}
return FALSE;
}
ME_Style *ME_MakeStyle(CHARFORMAT2W *style)