richedit: Return correct values when EM_SETTEXTMODE fails.
The checks for the text length and invalid parameters needed to be swapped, and the code could be easily simplified.
This commit is contained in:
parent
428e8a5a01
commit
75eef41881
|
@ -4316,35 +4316,25 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
|
||||||
return editor->mode;
|
return editor->mode;
|
||||||
case EM_SETTEXTMODE:
|
case EM_SETTEXTMODE:
|
||||||
{
|
{
|
||||||
LRESULT ret;
|
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
int changes = 0;
|
int changes = 0;
|
||||||
GETTEXTLENGTHEX how;
|
|
||||||
|
|
||||||
/* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
|
if (ME_GetTextLength(editor))
|
||||||
how.flags = GTL_CLOSE | (editor->bEmulateVersion10 ? 0 : GTL_USECRLF) | GTL_NUMCHARS;
|
return E_UNEXPECTED;
|
||||||
how.codepage = unicode ? 1200 : CP_ACP;
|
|
||||||
ret = ME_GetTextLengthEx(editor, &how);
|
/* Check for mutually exclusive flags in adjacent bits of wParam */
|
||||||
if (!ret)
|
if ((wParam & (TM_RICHTEXT | TM_MULTILEVELUNDO | TM_MULTICODEPAGE)) &
|
||||||
|
(wParam & (TM_PLAINTEXT | TM_SINGLELEVELUNDO | TM_SINGLECODEPAGE)) << 1)
|
||||||
|
return E_INVALIDARG;
|
||||||
|
|
||||||
|
if (wParam & (TM_RICHTEXT | TM_PLAINTEXT))
|
||||||
{
|
{
|
||||||
/*Check for valid wParam*/
|
mask |= TM_RICHTEXT | TM_PLAINTEXT;
|
||||||
if ((((wParam & TM_RICHTEXT) && ((wParam & TM_PLAINTEXT) << 1))) ||
|
changes |= wParam & (TM_RICHTEXT | TM_PLAINTEXT);
|
||||||
(((wParam & TM_MULTILEVELUNDO) && ((wParam & TM_SINGLELEVELUNDO) << 1))) ||
|
|
||||||
(((wParam & TM_MULTICODEPAGE) && ((wParam & TM_SINGLECODEPAGE) << 1))))
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (wParam & (TM_RICHTEXT | TM_PLAINTEXT))
|
|
||||||
{
|
|
||||||
mask |= (TM_RICHTEXT | TM_PLAINTEXT);
|
|
||||||
changes |= (wParam & (TM_RICHTEXT | TM_PLAINTEXT));
|
|
||||||
}
|
|
||||||
/*FIXME: Currently no support for undo level and code page options*/
|
|
||||||
editor->mode = (editor->mode & (~mask)) | changes;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
/* FIXME: Currently no support for undo level and code page options */
|
||||||
|
editor->mode = (editor->mode & ~mask) | changes;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
case EM_SETPASSWORDCHAR:
|
case EM_SETPASSWORDCHAR:
|
||||||
{
|
{
|
||||||
|
|
|
@ -1053,6 +1053,11 @@ static void test_EM_SETTEXTMODE(void)
|
||||||
CHARRANGE cr;
|
CHARRANGE cr;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
|
/*Attempt to use mutually exclusive modes*/
|
||||||
|
rc = SendMessage(hwndRichEdit, EM_SETTEXTMODE, (WPARAM) TM_PLAINTEXT|TM_RICHTEXT, 0);
|
||||||
|
ok(rc == E_INVALIDARG,
|
||||||
|
"EM_SETTEXTMODE: using mutually exclusive mode flags - returned: %x\n", rc);
|
||||||
|
|
||||||
/*Test that EM_SETTEXTMODE fails if text exists within the control*/
|
/*Test that EM_SETTEXTMODE fails if text exists within the control*/
|
||||||
/*Insert text into the control*/
|
/*Insert text into the control*/
|
||||||
|
|
||||||
|
@ -1060,7 +1065,8 @@ static void test_EM_SETTEXTMODE(void)
|
||||||
|
|
||||||
/*Attempt to change the control to plain text mode*/
|
/*Attempt to change the control to plain text mode*/
|
||||||
rc = SendMessage(hwndRichEdit, EM_SETTEXTMODE, (WPARAM) TM_PLAINTEXT, 0);
|
rc = SendMessage(hwndRichEdit, EM_SETTEXTMODE, (WPARAM) TM_PLAINTEXT, 0);
|
||||||
ok(rc != 0, "EM_SETTEXTMODE: changed text mode in control containing text - returned: %d\n", rc);
|
ok(rc == E_UNEXPECTED,
|
||||||
|
"EM_SETTEXTMODE: changed text mode in control containing text - returned: %x\n", rc);
|
||||||
|
|
||||||
/*Test that EM_SETTEXTMODE does not allow rich edit text to be pasted.
|
/*Test that EM_SETTEXTMODE does not allow rich edit text to be pasted.
|
||||||
If rich text is pasted, it should have the same formatting as the rest
|
If rich text is pasted, it should have the same formatting as the rest
|
||||||
|
|
Loading…
Reference in New Issue