diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index fc6e4eac579..28609522de9 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -3929,13 +3929,8 @@ BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_max) /* CFE_LINK effect should be consistently unset */ link.cbSize = sizeof(link); ME_GetCharFormat(editor, beforeURL[0], beforeURL[1], &link); - /* FIXME: Workaround for what looks like a bug - ME_GetCharFormat does not - clear the CFM_LINK flag when selection spans text without CFE_LINK, - followed by CFE_LINK set. This needs a test for EM_GETCHARFORMAT */ -#if 0 if (!(link.dwMask & CFM_LINK) || (link.dwEffects & CFE_LINK)) { -#endif /* CFE_LINK must be unset from this range */ memset(&link, 0, sizeof(CHARFORMAT2W)); link.cbSize = sizeof(link); @@ -3943,9 +3938,7 @@ BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_max) link.dwEffects = 0; ME_SetCharFormat(editor, beforeURL[0], beforeURL[1] - beforeURL[0], &link); modified = TRUE; -#if 0 } -#endif } if (inURL[0] < inURL[1]) { diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c index c49eb16e670..0af3ba08012 100644 --- a/dlls/riched20/run.c +++ b/dlls/riched20/run.c @@ -857,6 +857,16 @@ void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod) static void ME_GetRunCharFormat(ME_TextEditor *editor, ME_DisplayItem *run, CHARFORMAT2W *pFmt) { ME_CopyCharFormat(pFmt, &run->member.run.style->fmt); + if ((pFmt->dwMask & CFM_UNDERLINETYPE) && (pFmt->bUnderlineType == CFU_CF1UNDERLINE)) + { + pFmt->dwMask |= CFM_UNDERLINE; + pFmt->dwEffects |= CFE_UNDERLINE; + } + if ((pFmt->dwMask & CFM_UNDERLINETYPE) && (pFmt->bUnderlineType == CFU_UNDERLINENONE)) + { + pFmt->dwMask |= CFM_UNDERLINE; + pFmt->dwEffects &= ~CFE_UNDERLINE; + } } /****************************************************************************** @@ -928,7 +938,7 @@ void ME_GetCharFormat(ME_TextEditor *editor, int nFrom, int nTo, CHARFORMAT2W *p do { /* FIXME add more style feature comparisons */ int nAttribs = CFM_SIZE | CFM_FACE | CFM_COLOR | CFM_UNDERLINETYPE; - int nEffects = CFM_BOLD | CFM_ITALIC; + int nEffects = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED | CFM_LINK | CFM_SUPERSCRIPT; run = ME_FindItemFwd(run, diRun); @@ -937,7 +947,6 @@ void ME_GetCharFormat(ME_TextEditor *editor, int nFrom, int nTo, CHARFORMAT2W *p ME_GetRunCharFormat(editor, run, &tmp); assert((tmp.dwMask & nAttribs) == nAttribs); - assert((tmp.dwMask & nEffects) == nEffects); /* reset flags that differ */ if (pFmt->yHeight != tmp.yHeight) @@ -964,6 +973,7 @@ void ME_GetCharFormat(ME_TextEditor *editor, int nFrom, int nTo, CHARFORMAT2W *p } pFmt->dwMask &= ~((pFmt->dwEffects ^ tmp.dwEffects) & nEffects); + pFmt->dwEffects = tmp.dwEffects; } while(run != run_end); } diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 05824bb5b3c..e57b5a9f59a 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -402,6 +402,18 @@ static void test_EM_SETCHARFORMAT(void) HWND hwndRichEdit = new_richedit(NULL); CHARFORMAT2 cf2; int rc = 0; + int tested_effects[] = { + CFE_BOLD, + CFE_ITALIC, + CFE_UNDERLINE, + CFE_STRIKEOUT, + CFE_PROTECTED, + CFE_LINK, + CFE_SUBSCRIPT, + CFE_SUPERSCRIPT, + 0 + }; + int i; /* Invalid flags, CHARFORMAT2 structure blanked out */ memset(&cf2, 0, sizeof(cf2)); @@ -520,6 +532,113 @@ static void test_EM_SETCHARFORMAT(void) ok(rc == -1, "Text not marked as modified, expected modified! (%d)\n", rc); DestroyWindow(hwndRichEdit); + + /* EM_GETCHARFORMAT tests */ + for (i = 0; tested_effects[i]; i++) + { + hwndRichEdit = new_richedit(NULL); + SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine"); + + memset(&cf2, 0, sizeof(CHARFORMAT2)); + cf2.cbSize = sizeof(CHARFORMAT2); + cf2.dwMask = tested_effects[i]; + if (cf2.dwMask == CFE_SUBSCRIPT || cf2.dwMask == CFE_SUPERSCRIPT) + cf2.dwMask = CFM_SUPERSCRIPT; + cf2.dwEffects = tested_effects[i]; + SendMessage(hwndRichEdit, EM_SETSEL, 0, 2); + SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2); + + memset(&cf2, 0, sizeof(CHARFORMAT2)); + cf2.cbSize = sizeof(CHARFORMAT2); + SendMessage(hwndRichEdit, EM_SETSEL, 0, 2); + SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2); + ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) && + (cf2.dwMask & CFM_SUPERSCRIPT) == CFM_SUPERSCRIPT) + || + (cf2.dwMask & tested_effects[i]) == tested_effects[i]), + "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, tested_effects[i]); + ok((cf2.dwEffects & tested_effects[i]) == tested_effects[i], + "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, tested_effects[i]); + + memset(&cf2, 0, sizeof(CHARFORMAT2)); + cf2.cbSize = sizeof(CHARFORMAT2); + SendMessage(hwndRichEdit, EM_SETSEL, 2, 4); + SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2); + ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) && + (cf2.dwMask & CFM_SUPERSCRIPT) == CFM_SUPERSCRIPT) + || + (cf2.dwMask & tested_effects[i]) == tested_effects[i]), + "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, tested_effects[i]); + ok((cf2.dwEffects & tested_effects[i]) == 0, + "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x clear\n", i, cf2.dwEffects, tested_effects[i]); + + memset(&cf2, 0, sizeof(CHARFORMAT2)); + cf2.cbSize = sizeof(CHARFORMAT2); + SendMessage(hwndRichEdit, EM_SETSEL, 1, 3); + SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2); + ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) && + (cf2.dwMask & CFM_SUPERSCRIPT) == 0) + || + (cf2.dwMask & tested_effects[i]) == 0), + "%d, cf2.dwMask == 0x%08x expected mask 0x%08x clear\n", i, cf2.dwMask, tested_effects[i]); + ok((cf2.dwEffects & tested_effects[i]) == 0, + "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x clear\n", i, cf2.dwEffects, tested_effects[i]); + + DestroyWindow(hwndRichEdit); + } + + for (i = 0; tested_effects[i]; i++) + { + hwndRichEdit = new_richedit(NULL); + SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine"); + + memset(&cf2, 0, sizeof(CHARFORMAT2)); + cf2.cbSize = sizeof(CHARFORMAT2); + cf2.dwMask = tested_effects[i]; + if (cf2.dwMask == CFE_SUBSCRIPT || cf2.dwMask == CFE_SUPERSCRIPT) + cf2.dwMask = CFM_SUPERSCRIPT; + cf2.dwEffects = tested_effects[i]; + SendMessage(hwndRichEdit, EM_SETSEL, 2, 4); + SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2); + + memset(&cf2, 0, sizeof(CHARFORMAT2)); + cf2.cbSize = sizeof(CHARFORMAT2); + SendMessage(hwndRichEdit, EM_SETSEL, 0, 2); + SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2); + ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) && + (cf2.dwMask & CFM_SUPERSCRIPT) == CFM_SUPERSCRIPT) + || + (cf2.dwMask & tested_effects[i]) == tested_effects[i]), + "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, tested_effects[i]); + ok((cf2.dwEffects & tested_effects[i]) == 0, + "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x clear\n", i, cf2.dwEffects, tested_effects[i]); + + memset(&cf2, 0, sizeof(CHARFORMAT2)); + cf2.cbSize = sizeof(CHARFORMAT2); + SendMessage(hwndRichEdit, EM_SETSEL, 2, 4); + SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2); + ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) && + (cf2.dwMask & CFM_SUPERSCRIPT) == CFM_SUPERSCRIPT) + || + (cf2.dwMask & tested_effects[i]) == tested_effects[i]), + "%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, tested_effects[i]); + ok((cf2.dwEffects & tested_effects[i]) == tested_effects[i], + "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, tested_effects[i]); + + memset(&cf2, 0, sizeof(CHARFORMAT2)); + cf2.cbSize = sizeof(CHARFORMAT2); + SendMessage(hwndRichEdit, EM_SETSEL, 1, 3); + SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2); + ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) && + (cf2.dwMask & CFM_SUPERSCRIPT) == 0) + || + (cf2.dwMask & tested_effects[i]) == 0), + "%d, cf2.dwMask == 0x%08x expected mask 0x%08x clear\n", i, cf2.dwMask, tested_effects[i]); + ok((cf2.dwEffects & tested_effects[i]) == tested_effects[i], + "%d, cf2.dwEffects == 0x%08x expected effect 0x%08x set\n", i, cf2.dwEffects, tested_effects[i]); + + DestroyWindow(hwndRichEdit); + } } static void test_EM_SETTEXTMODE(void)