richedit: Insertion style must NOT be cleared unless selection actually changed.

This commit is contained in:
Alex Villacís Lasso 2008-05-04 22:51:52 -05:00 committed by Alexandre Julliard
parent d2900a53e1
commit c7873afbb2
2 changed files with 113 additions and 2 deletions

View File

@ -1316,8 +1316,6 @@ void ME_SendSelChange(ME_TextEditor *editor)
{
SELCHANGE sc;
ME_ClearTempStyle(editor);
if (!(editor->nEventMask & ENM_SELCHANGE))
return;
@ -1336,6 +1334,8 @@ void ME_SendSelChange(ME_TextEditor *editor)
(sc.seltyp & SEL_MULTICHAR) ? "SEL_MULTICHAR" : "");
if (sc.chrg.cpMin != editor->notified_cr.cpMin || sc.chrg.cpMax != editor->notified_cr.cpMax)
{
ME_ClearTempStyle(editor);
editor->notified_cr = sc.chrg;
SendMessageW(GetParent(editor->hWnd), WM_NOTIFY, sc.nmhdr.idFrom, (LPARAM)&sc);
}

View File

@ -414,6 +414,7 @@ static void test_EM_SETCHARFORMAT(void)
0
};
int i;
CHARRANGE cr;
/* Invalid flags, CHARFORMAT2 structure blanked out */
memset(&cf2, 0, sizeof(cf2));
@ -639,6 +640,116 @@ static void test_EM_SETCHARFORMAT(void)
DestroyWindow(hwndRichEdit);
}
/* Effects applied on an empty selection should take effect when selection is
replaced with text */
hwndRichEdit = new_richedit(NULL);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
SendMessage(hwndRichEdit, EM_SETSEL, 2, 2); /* Empty selection */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_BOLD;
cf2.dwEffects = CFE_BOLD;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Selection is now nonempty */
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"newi");
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 2, 6);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok (((cf2.dwMask & CFM_BOLD) == CFM_BOLD),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, CFM_BOLD);
ok((cf2.dwEffects & CFE_BOLD) == CFE_BOLD,
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, CFE_BOLD);
/* Set two effects on an empty selection */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
SendMessage(hwndRichEdit, EM_SETSEL, 2, 2); /* Empty selection */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_BOLD;
cf2.dwEffects = CFE_BOLD;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
cf2.dwMask = CFM_ITALIC;
cf2.dwEffects = CFE_ITALIC;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Selection is now nonempty */
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"newi");
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 2, 6);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok (((cf2.dwMask & (CFM_BOLD|CFM_ITALIC)) == (CFM_BOLD|CFM_ITALIC)),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, (CFM_BOLD|CFM_ITALIC));
ok((cf2.dwEffects & (CFE_BOLD|CFE_ITALIC)) == (CFE_BOLD|CFE_ITALIC),
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, (CFE_BOLD|CFE_ITALIC));
/* Setting the (empty) selection to exactly the same place as before should
NOT clear the insertion style! */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
SendMessage(hwndRichEdit, EM_SETSEL, 2, 2); /* Empty selection */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_BOLD;
cf2.dwEffects = CFE_BOLD;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Empty selection in same place, insert style should NOT be forgotten here. */
SendMessage(hwndRichEdit, EM_SETSEL, 2, 2);
/* Selection is now nonempty */
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"newi");
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 2, 6);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok (((cf2.dwMask & CFM_BOLD) == CFM_BOLD),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, CFM_BOLD);
ok((cf2.dwEffects & CFE_BOLD) == CFE_BOLD,
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, CFE_BOLD);
/* Ditto with EM_EXSETSEL */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
cr.cpMin = 2; cr.cpMax = 2;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM)&cr); /* Empty selection */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_BOLD;
cf2.dwEffects = CFE_BOLD;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Empty selection in same place, insert style should NOT be forgotten here. */
cr.cpMin = 2; cr.cpMax = 2;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM)&cr); /* Empty selection */
/* Selection is now nonempty */
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"newi");
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cr.cpMin = 2; cr.cpMax = 6;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM)&cr); /* Empty selection */
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok (((cf2.dwMask & CFM_BOLD) == CFM_BOLD),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, CFM_BOLD);
ok((cf2.dwEffects & CFE_BOLD) == CFE_BOLD,
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, CFE_BOLD);
DestroyWindow(hwndRichEdit);
}
static void test_EM_SETTEXTMODE(void)