>From da43fe92d633dade59e978e516b43ec409117a2a Mon Sep 17 00:00:00 2001 From: James McKenzie Date: Sun, 16 Jan 2011 08:27:03 -0700 Subject: Adds tests for EM_SETMARGINS for ANSI and UNICODE --- dlls/riched20/tests/editor.c | 523 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 521 insertions(+), 2 deletions(-) diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 63b23e9..2bc684c 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -50,9 +50,13 @@ static int is_win9x = 0; static HWND new_window(LPCTSTR lpClassName, DWORD dwStyle, HWND parent) { HWND hwnd; - hwnd = CreateWindow(lpClassName, NULL, dwStyle|WS_POPUP|WS_HSCROLL|WS_VSCROLL +/* hwnd = CreateWindow(lpClassName, NULL, dwStyle|WS_POPUP|WS_HSCROLL|WS_VSCROLL |WS_VISIBLE, 0, 0, 200, 60, parent, NULL, - hmoduleRichEdit, NULL); + hmoduleRichEdit, NULL); */ + /* Set screen to VGA proportions for testing purposes, will be removed from final patch release */ + hwnd = CreateWindow(lpClassName, NULL, dwStyle|WS_POPUP|WS_HSCROLL|WS_VSCROLL + |WS_VISIBLE, 0, 0, 640, 480, parent, NULL, + hmoduleRichEdit, NULL); ok(hwnd != NULL, "class: %s, error: %d\n", lpClassName, (int) GetLastError()); return hwnd; } @@ -7068,6 +7072,518 @@ static void test_dialogmode(void) DestroyWindow(hwParent); } +static INT CALLBACK find_font_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam) +{ + return 0; +} + +static inline int is_win9xA() +{ + static WCHAR arialW[]={'A','r','i','a','l',0}; + SetLastError(0xdeadbeef); + lstrcmpW(arialW, arialW); + return (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED); +} + +static void test_em_setmargins(void) +{ + HWND hwndRichEdit; + RECT old_rect, new_rect; + + HDC hDC; + LOGFONT lf; + LOGFONTW sentLogFont, lfW; + LOGFONTA sentLogFontA, lfA; + CHARFORMAT2A CharFont1ANSI; + CHARFORMAT2W CharFont1Unicode; + + TEXTMETRICA tma; + TEXTMETRICW tmw; + + UINT ret; + int ry; + + HFONT testFont1W, testFont2W, testFont3W, testFont4W, testFont1A, testFont2A, hDC_font; + + hwndRichEdit = new_richedit(NULL); + + hDC = GetDC(hwndRichEdit); + ok (hDC, "Creation of hdc failed \n"); + if (!hDC) + { + DeleteObject(testFont1A); + DeleteObject(testFont2A); + DeleteObject(testFont1W); + DeleteObject(testFont2W); + DeleteObject(testFont3W); + DeleteObject(testFont4W); + DeleteDC(hDC); + DestroyWindow(hwndRichEdit); + return; + } + + /* Calculate the twips per pixel */ + ry = GetDeviceCaps(hDC, LOGPIXELSY); + + static const WCHAR arialW[] = {'A','r','i','a','l',0}; + static const WCHAR courier[] = {'C','o','u','r','i','e','r',0}; + static const WCHAR msSansSerif [] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0}; + + memset(&CharFont1ANSI, 0, sizeof(CHARFORMAT2A)); + CharFont1ANSI.cbSize = sizeof(CharFont1ANSI); + memset(&CharFont1Unicode, 0, sizeof(CHARFORMAT2W)); + CharFont1Unicode.cbSize = sizeof(CharFont1Unicode); + memset(&sentLogFont, 0, sizeof(LOGFONTW)); + + memset(&lfA, 0, sizeof(lfA)); + strcpy(lfA.lfFaceName, "Arial"); + lfA.lfHeight = 16; + lfA.lfCharSet = ANSI_CHARSET; + lfA.lfWeight = FW_NORMAL; + testFont1A = CreateFontIndirectA(&lfA); + lfA.lfHeight = 30; + testFont2A = CreateFontIndirectA(&lfA); + + /*Initialize old_rect variable to be the size of the entire richedit window */ + SendMessageA(hwndRichEdit, EM_SETRECT, 0, (LPARAM)&old_rect); + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&old_rect); + + /*Set Left Margin to five pixels in size */ + todo_wine { + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN, MAKELONG (5,0)); + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left + 5, "The left border of the rectangle is wrong. The value of it is %d.\n", \ + new_rect.left); + } + ok(new_rect.right == old_rect.right, "The right border was changed in Left Margin Change test by %d\n", \ + new_rect.right - old_rect.right); + ok(new_rect.top == old_rect.top, "The top border was changed\n"); + ok(new_rect.bottom == old_rect.bottom, "The bottom border was changed\n"); + + /*Set Right Margin to five pixels in size. The left margin should remain at 5 pixels*/ + todo_wine { + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_RIGHTMARGIN, MAKELONG (0,5)); + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.right == (old_rect.right - 5), "The right border of the rectangle is wrong. The value of it is %d. " \ + "The value of the prior margin was %d.\n", new_rect.right, old_rect.right); + ok(new_rect.left == old_rect.left + 5, "The left border was changed in Right Margin Change test." \ + " It changed to %d from %d\n", new_rect.left, old_rect.left); + } + ok(new_rect.top == old_rect.top, "The top border was changed\n"); + ok(new_rect.bottom == old_rect.bottom, "The bottom border was changed\n"); + + /* Test changing of Margins to a larger margin size */ + todo_wine { + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5, 5)); + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&old_rect); + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(15, 20)); + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left + 10, "The left border of the rectangle is wrong\n"); + ok(new_rect.right == old_rect.right - 15, "The right border of the rectangle is wrong\n"); + } + ok(new_rect.top == old_rect.top, "The top border of the rectangle must not change\n"); + ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle must not change\n"); + + /* Verify if we use the same margins, the size of the rectangle does not change */ + todo_wine { + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10)); + } + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&old_rect); + todo_wine { + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(10, 10)); + } + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left, "The left border of the rectangle has changed to %d\n", new_rect.left); + ok(new_rect.right == old_rect.right, "The right border of the rectangle has changed to %d\n", new_rect.right); + ok(new_rect.top == old_rect.top, "The top border of the rectangle has changed\n"); + ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle has changed\n"); + + /* Test case of EC_USEFONTINFO */ + /* First with no font information set */ + SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "x"); + SendMessageA(hwndRichEdit, WM_SETFONT, 0, 0); + /* Check Font Metrics after setting Font */ + ret = GetTextMetricsA (hDC, &tma); + ok (ret, "GetTextMetricsA failed\n"); + SendMessageA(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &CharFont1ANSI); + GetObjectA(testFont1A, sizeof(LOGFONTA), &sentLogFontA); + ok (!lstrcmpA("System",CharFont1ANSI.szFaceName), "Font not set to System (0), it is %s\n", CharFont1ANSI.szFaceName); + ok (16 == sentLogFontA.lfHeight, "Height not set to 12 for System Font. Height is %d\n", sentLogFontA.lfHeight); + ok (96 == ry, "DPI for screen does not equal 96 it is %d\n", ry); + ok (-240 == CharFont1ANSI.yHeight /* Wine */|| 195 == CharFont1ANSI.yHeight /* Windows */, "y Height of System Character is " + "not -240 or 195 but is %d\n", CharFont1ANSI.yHeight); + ok (16 == abs(CharFont1ANSI.yHeight) * ry / 1440 /*Wine*/|| 13 == abs(CharFont1ANSI.yHeight) * ry / 1440 /*Windows*/, \ + "Character Height of System character set is not 16 but %d\n", abs(CharFont1ANSI.yHeight) * ry / 1440); + ok (0 == CharFont1ANSI.yOffset, "Character Offset for System character set is not zero but %x\n", CharFont1ANSI.yOffset); + ok (7 == tma.tmAveCharWidth, "Average Character Width for System character set is %d\n", tma.tmAveCharWidth); + ok (15 == tma.tmMaxCharWidth /*Wine*/ || 14 == tma.tmMaxCharWidth /*Windows*/, "Maximum Character Width for System character set " \ + "is %d\n", tma.tmMaxCharWidth); + + todo_wine { + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, 0); + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&old_rect); + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_USEFONTINFO, 0); + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + } + ok(new_rect.left == old_rect.left, "USEFONTINFO with no font set did not return zero\n"); + ok(new_rect.right == old_rect.right, "USEFONTINFO with no font set did not return zero\n"); + ok(new_rect.top == old_rect.top, "USEFONTINFO with no font set moved the top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "USEFONTINFO with no font set moved the bottom margin\n"); + + /* Clear CharFont1ANSI variable for next test */ + memset(&CharFont1ANSI, 0, sizeof(CHARFORMAT2A)); + CharFont1ANSI.cbSize = sizeof(CharFont1ANSI); + + if(EnumFontFamiliesA(hDC, "Arial", find_font_proc, 0)) + { + trace("Arial not found - skipping font change margin tests\n"); + DeleteObject(testFont1A); + DeleteObject(testFont2A); + DeleteObject(testFont1W); + DeleteObject(testFont2W); + DeleteObject(testFont3W); + DeleteObject(testFont4W); + ReleaseDC(hwndRichEdit, hDC); + DestroyWindow(hwndRichEdit); + return; + } + + /* Test Font changes for ANSI processes with Arial 16*/ + SendMessageA(hwndRichEdit, WM_SETFONT, (WPARAM)testFont1A, 1); + hDC_font = SelectObject(hDC, &testFont1A); + ret = GetTextMetricsA (hDC, &tma); + ok (ret, "GetTextMetricsA failed. Error is %d\n", GetLastError()); + GetObjectA(testFont1A, sizeof(LOGFONTA), &sentLogFontA); + SendMessageA(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &CharFont1ANSI); + ok (!lstrcmpA(CharFont1ANSI.szFaceName,sentLogFontA.lfFaceName), "Font not set to Arial, but set to %s\n", \ + CharFont1ANSI.szFaceName); + ok (7 == tma.tmAveCharWidth, "Average Character Width for Arial 16 ANSI is %d\n", tma.tmAveCharWidth); + ok (14 == tma.tmMaxCharWidth /*Windows*/ || 15 == tma.tmMaxCharWidth /*Wine*/, "Maximum Character Width for Arial 16 ANSI "\ + "is not 14 or 15 but is %d\n", tma.tmMaxCharWidth); + ok (0 == sentLogFontA.lfWidth, "Maximum Character Font Width for Arial 16 ANSI is %d\n", sentLogFont.lfWidth); + ok (195 == CharFont1ANSI.yHeight /*Windows*/ || -240 == CharFont1ANSI.yHeight /*Wine*/, "Character Height for Arial "\ + "16 ANSI is not -240 or 195 but %d\n", abs(CharFont1ANSI.yHeight)); + ok (13 == (abs(CharFont1ANSI.yHeight) * ry) / 1440 /*Windows*/ || 16 == (abs(CharFont1ANSI.yHeight) * ry) / 1440 /*Wine*/,\ + "Character Height of Arial 16 ANSI character set is not 16 but %d\n", abs(CharFont1ANSI.yHeight) * ry / 1440); + ok (0 == CharFont1ANSI.yOffset, "Character Offset for Arial 16 ANSI is not zero but %x\n", CharFont1ANSI.yOffset); + + todo_wine { + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_USEFONTINFO, MAKELONG(10, 10)); + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + } + ok(new_rect.left == old_rect.left, "wParam Arial 16 ANSI USEFONTINFO Left returned incorrect value. It is %d, " \ + "should be zero\n", new_rect.left); + ok(new_rect.right == old_rect.right, "wParam Arial 16 ANSI USEFONTINFO Right margin moved. It moved by %d\n", \ + new_rect.right - old_rect.right); + ok(new_rect.top == old_rect.top, "wParam Arial 16 ANSI USEFONTINFO 10 moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "wParam Arial 16 ANSI USEFONTINFO 10 moved bottom margin\n"); + + /* Clear CharFont1ANSI variable for next test and reset cbSize structure variable*/ + memset(&CharFont1ANSI, 0, sizeof(CHARFORMAT2A)); + CharFont1ANSI.cbSize = sizeof(CharFont1ANSI); + + /* Test Font changes for ANSI processes with Arial 30*/ + SendMessageA(hwndRichEdit, WM_SETFONT, (WPARAM)testFont2A, MAKELPARAM(0,1)); + ZeroMemory(&tma, sizeof(TEXTMETRICA)); + ZeroMemory(&sentLogFontA, sizeof(sentLogFontA)); + hDC_font = SelectObject(hDC, &testFont2A); + ret = GetTextMetricsA (hDC, &tma); + ok (ret, "GetTextMetricsA failed. Error is %d\n", GetLastError()); + GetObjectA(testFont2A, sizeof(LOGFONTA), &sentLogFontA); + SendMessageA(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &CharFont1ANSI); + ok (!lstrcmpA(CharFont1ANSI.szFaceName,sentLogFontA.lfFaceName), "Font not set to Arial, but set to %s\n", \ + CharFont1ANSI.szFaceName); + ok (30 == sentLogFontA.lfHeight, "Height not set to 30. Height is %d\n", sentLogFontA.lfHeight); + ok (7 == tma.tmAveCharWidth, "Average Character Width for Arial 30 ANSI is %d\n", tma.tmAveCharWidth); + ok (14 == tma.tmMaxCharWidth /*Windows*/ || 15 == tma.tmMaxCharWidth /*Wine*/, "Maximum Character Width for Arial 30 ANSI "\ + "is not 14 or 15 but is %d\n", tma.tmMaxCharWidth); + ok (0 == sentLogFontA.lfWidth, "Maximum Character Font Width for Arial 30 ANSI is %d\n", sentLogFont.lfWidth); + ok (405 == CharFont1ANSI.yHeight /*Windows*/ || -450 == CharFont1ANSI.yHeight, "Character Height for Arial 30 ANSI is not "\ + "-450 or 405 but %d\n", abs(CharFont1ANSI.yHeight)); + ok (27 == (abs(CharFont1ANSI.yHeight) * ry) / 1440 /*Windows*/ || 30 == (abs(CharFont1ANSI.yHeight) * ry) / 1440 /*Wine*/,\ + "Character Height for Aril 30 ANSI not set to 30 but %d\n", abs(CharFont1ANSI.yHeight) * ry / 1440); + ok (0 == CharFont1ANSI.yOffset, "Character Offset is not zero but %x\n", CharFont1ANSI.yOffset); + + todo_wine { + SendMessageA(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_USEFONTINFO, MAKELONG(10, 10)); + SendMessageA(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + } + ok(new_rect.left == old_rect.left, "wParam Courier USEFONTINFO Left returned incorrect value. It is %d, " \ + "should be zero\n", new_rect.left); + ok(new_rect.right == old_rect.right, "wParam Courier USEFONTINFO Right margin moved. It moved by %d\n", \ + new_rect.right - old_rect.right); + ok(new_rect.top == old_rect.top, "wParam USEFONTINFO 10 moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "wParam USEFONTINFO 10 moved bottom margin\n"); + + if (is_win9xA()) + { + win_skip ("Cannot perform EC_USEFONTINFO tests on Windows 95/98/ME (Richedit 1.0 and 2.0) as lparam\n"); + DeleteObject(testFont1A); + DeleteObject(testFont2A); + DeleteObject(testFont1W); + DeleteObject(testFont2W); + DeleteObject(testFont3W); + DeleteObject(testFont4W); + ReleaseDC(hwndRichEdit, hDC); + DestroyWindow(hwndRichEdit); + return; + } + + memset(&lfW, 0, sizeof(lfW)); + lstrcmpW(lfW.lfFaceName, courier); + lfW.lfHeight = 13; + lfW.lfWeight = FW_NORMAL; + lfW.lfCharSet = DEFAULT_CHARSET; + testFont1W = CreateFontIndirectW(&lfW); + lstrcmpW(lfW.lfFaceName, msSansSerif); + lfW.lfHeight = 13; + lfW.lfWeight = FW_NORMAL; + testFont2W = CreateFontIndirectW(&lfW); + lstrcmpW(lfW.lfFaceName, arialW); + lfW.lfHeight = 16; + lfW.lfCharSet = DEFAULT_CHARSET; + testFont3W = CreateFontIndirectW(&lfW); + lfW.lfHeight = 30; + testFont4W = CreateFontIndirectW(&lfW); + + /*Set test font to be Courier font */ + SendMessageW(hwndRichEdit, WM_SETFONT, (WPARAM)testFont1W, MAKELPARAM(TRUE, 0)); + /*Verify font is set */ + SendMessageW(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &CharFont1Unicode); + GetObjectW(testFont1W, sizeof(LOGFONTW), &sentLogFont); + ok (!lstrcmpW(sentLogFont.lfFaceName, CharFont1Unicode.szFaceName), "WM_SETFONT set wrong font. " \ + "Font was set to %s or %s, was supposed to be \"Courier\".\n", wine_dbgstr_w(CharFont1Unicode.szFaceName), \ + wine_dbgstr_w(sentLogFont.lfFaceName)); + hDC_font = SelectObject(hDC, &testFont1W); + ret = GetTextMetricsW (hDC, &tmw); + ok (ret, "GetTextMetricsW failed. Error is %d\n", GetLastError()); + ok (13 == sentLogFont.lfHeight, "Height for Courier not set to 13. Height is %d\n", tmw.tmHeight); + ok (0== CharFont1Unicode.wWeight /*Windoows*/ || FW_NORMAL == CharFont1Unicode.wWeight /*Wine*/, "Average Character Weight for "\ + "Courier 12 is %d\n", CharFont1Unicode.wWeight); + ok (0 == sentLogFont.lfWidth, "Maximum Character Width for Courier 12 is %d\n", sentLogFont.lfWidth); + ok (150 == CharFont1Unicode.yHeight /*Windows*/ || -180 == CharFont1Unicode.yHeight, "Character height for Courier 12 is not 180 "\ + "but is %d\n", abs(CharFont1Unicode.yHeight)); + ok (10 == (abs(CharFont1Unicode.yHeight) * ry) / 1440 /*Windows*/ || 13 == (abs(CharFont1Unicode.yHeight) * ry) / 1440 /*Wine*/,\ + "Character Height of Courier 12 character set is not 12 but %d\n", abs(CharFont1Unicode.yHeight) * ry / 1440); + + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, 0); + } + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&old_rect); + /* This seems to do nothing with Windows 7 + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN | EC_USEFONTINFO, MAKELONG(0, 0)); */ + ok(new_rect.left == old_rect.left, "wParam Courier EC_LEFT/RIGHT/USEFONTINFO Zero Left returned non-zero, value is " \ + "%d\n", new_rect.left); + ok(new_rect.right == old_rect.right, "wParam Courier EC_LEFT/RIGHT/USEFONTINFO Zero Right returned non-zero, value "\ + "is %d\n", new_rect.right); + ok(new_rect.top == old_rect.top, "wParam EC_LEFT/RIGHT/USEFONTINFO wparam Courier moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "wParam EC_LEFT/RIGHT/USEFONTINFO wparam Courier moved bottom margin\n"); + + todo_wine { + /* Per http://www.piclist.com/techref/os/win/api/win32/mess/src/msg06_7.htm the Left Margin + should be set to the 'C' value, that is the value used to set white space after a character + and the Right Margin should be set to the 'A' value, that is the value use to set white space to the + current position before drawing the next character. The margin value passed in the lParam variable + is ignored */ + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_USEFONTINFO, MAKELONG(10, 10)); + } + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left, "wParam Courier USEFONTINFO Left returned incorrect value. It is %d, should be " + "zero\n", new_rect.left); + ok(new_rect.right == old_rect.right, "wParam Courier USEFONTINFO Right margin moved. It moved by %d\n", new_rect.right -\ + old_rect.right); + ok(new_rect.top == old_rect.top, "wParam USEFONTINFO 10 moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "wParam USEFONTINFO 10 moved bottom margin\n"); + + /* Per http://msdn.microsoft.com/en-us/library/bb761649%(VS.85).asp if the lparam is + EC_USEFONTINFO the Left and Right Margins should be set to a narrow width if the + font has been set */ + + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN, MAKELONG(EC_USEFONTINFO, 0)); + } + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + todo_wine { + ok(new_rect.left == old_rect.left + 65535, "lParam Courier USEFONTINFO Left returned incorrect value. It is %d\n", \ + new_rect.left - old_rect.left); + } + ok(new_rect.right == old_rect.right, "lParam Courier USEFONTINFO Right returned non-zero, value is %d\n", new_rect.right); + ok(new_rect.top == old_rect.top, "lParam Courier USEFONTINFO moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "lParam USEFONTINFO moved bottom margin\n"); + + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_USEFONTINFO, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO)); + } + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left, "wParam Courier USEFONTINFO Triple returned non-zero, value is %d\n", new_rect.left); + ok(new_rect.right == old_rect.right, "wParam Courier USEFONTINFO Triple returned non-zero, value is %d\n", new_rect.right); + ok(new_rect.top == old_rect.top, "wParam Courier USEFONTINFO moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "wParam Courier USEFONTINFO moved bottom margin\n"); + + /*Set test font to be MS San Serif font (for reliable tests) */ + SendMessage(hwndRichEdit, WM_SETFONT, (WPARAM)testFont2W, MAKELPARAM(TRUE, 0)); + /*Verify font is set */ + SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &CharFont1Unicode); + GetObjectW(testFont2W, sizeof(LOGFONTW), &sentLogFont); + ok (!lstrcmpW(sentLogFont.lfFaceName, CharFont1Unicode.szFaceName), "WM_SETFONT set wrong font." \ + " Font was set to %s, was supposed to be \"MS Sans Serif\".\n", wine_dbgstr_w(CharFont1Unicode.szFaceName)); + + ret = GetTextMetricsW (hDC, &tmw); + ok (ret, "GetTextMetricsW failed\n"); + ok (7 == tmw.tmAveCharWidth, "Average Character Width for MS Sans Serif is %d\n", tmw.tmAveCharWidth); + ok (14 == tmw.tmMaxCharWidth, "Maximum Character Width for MS Sans Serif is %d\n", tmw.tmMaxCharWidth); + ok (150== CharFont1Unicode.yHeight /*Windows*/ || -195 == CharFont1Unicode.yHeight /*Wine*/, \ + "Character height for MS Sans Serif is not 195 but is %d\n", abs(CharFont1Unicode.yHeight)); + ok (10 == (abs(CharFont1Unicode.yHeight) * ry) / 1440 /*Windows*/ || 13 == (abs(CharFont1Unicode.yHeight) * ry) / 1440 /*Wine*/, \ + "Character Height of MS San Serif character set is not 12 but %d\n", abs(CharFont1Unicode.yHeight) * ry / 1440); + ok (0 == CharFont1Unicode.wWeight /*Windows*/ || FW_NORMAL == CharFont1Unicode.wWeight /*Wine*/, "Average Character Weight for MS"\ + " Sans Serif is %d\n", CharFont1Unicode.wWeight); + + todo_wine { + SendMessage(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN, MAKELONG(EC_USEFONTINFO, 0)); + } + SendMessage(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + todo_wine { + ok(new_rect.left == old_rect.left + 65535, "lParam MS Sans Serif USEFONTINFO Left returned incorrect value. It is %d\n", \ + new_rect.left - old_rect.left ); + } + ok(new_rect.right == old_rect.right, "lParam MS Sans Serif USEFONTINFO Right did not return zero, value is %d\n", new_rect.right); + ok(new_rect.top == old_rect.top, "USEFONTINFO moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "USEFONTINFO moved bottom margin\n"); + + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_USEFONTINFO, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO)); + } + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left, "wParam MS Sans Serif USEFONTINFO Triple returned non-zero, value is %d\n", new_rect.left); + ok(new_rect.right == old_rect.right, "wParam MS Sans Serif USEFONTINFO Triple returned non-zero, value is %d\n", new_rect.right); + ok(new_rect.top == old_rect.top, "wParam MS Sans Serif USEFONTINFO moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "wParam Ms Sans Serif USEFONTINFO moved bottom margin\n"); + + /* reset rect to original settings */ + SendMessage(hwndRichEdit, EM_SETRECT, 0, (LPARAM)&old_rect); + SendMessage(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&old_rect); + + /*Set test font to be Arial font at a height of 16 */ + SendMessage(hwndRichEdit, WM_SETFONT, (WPARAM)testFont3W, MAKELPARAM(TRUE, 0)); + /*Verify font is set to Arial */ + SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &CharFont1Unicode); + GetObjectW(testFont3W, sizeof(LOGFONTW), &sentLogFont); + ok (!lstrcmpW(sentLogFont.lfFaceName, CharFont1Unicode.szFaceName), "WM_SETFONT set wrong font. Font was set to %s, was "\ + "supposed to be \"Arial\".\n", wine_dbgstr_w(CharFont1Unicode.szFaceName)); + + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0,0)); + } + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left, "Arial16 Left Zero did not return zero, old value is %d, new value is %d\n", \ + old_rect.left, new_rect.left); + ok(new_rect.right == old_rect.right, "Arial16 Right Zero did not return zero, old value is %d, new value is %d\n", \ + old_rect.right, new_rect.right); + ok(new_rect.top == old_rect.top, "Arial16 moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "Arial16 moved bottom margin\n"); + + /* Set Left Margin to 1 */ + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0)); + } + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + todo_wine { + ok(new_rect.left == old_rect.left + 1, "Set Left Margin for Arial16 to one, got %d\n", new_rect.left - old_rect.left); + } + ok(new_rect.right == old_rect.right, "Set Left Margin to one for Arial16. Right margin moved, got %d\n", new_rect.right); + + todo_wine { + /* Set Left and Right margins to 1 */ + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1)); + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left + 1, "Set Left Margin for Arial16, should be 1, got %d\n", new_rect.left - old_rect.left); + ok(new_rect.right == old_rect.right - 1, "Set Right Margin (1) for Arial16, should be %d, got %d\n", old_rect.right, \ + new_rect.right); + } + + /* Set margins using EC_USEFONTINFO */ + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO,EC_USEFONTINFO)); + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left + 65535, "Set Left Margin (USEFONTINFO) for Arial 16 pt, should be 65535, got %d\n", \ + new_rect.left - old_rect.left); + ok(new_rect.right == old_rect.right - 65535, "Set Right Margin (USEFONTINFO) for Arial 16 pt, should be %d, got %d\n", \ + old_rect.right - 65535, new_rect.right); + } + + /* Set margins using EC_USEFONTINFO wParam */ + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_USEFONTINFO, MAKELONG(0,0)); + } + SendMessage(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left, "Set Left Margin (USEFONTINFO wParam) for Arial16, should be 0, got %d\n", new_rect.left); + ok(new_rect.right == old_rect.right, "Set Right Margin (USEFONTINFO wParam) for Arial16, should be %d, got %d\n",old_rect.right, \ + new_rect.right); + + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_USEFONTINFO, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO)); + } + SendMessageW(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left, "wParam Arial 16 USEFONTINFO Triple returned non-zero, value is %d\n", new_rect.left); + ok(new_rect.right == old_rect.right, "wParam Arial 16 USEFONTINFO Triple returned non-zero, value is %d\n", new_rect.right); + ok(new_rect.top == old_rect.top, "wParam Arial 16 USEFONTINFO Triple moved top margin\n"); + ok(new_rect.bottom == old_rect.bottom, "wParam Arial 16 USEFONTINFO Triple moved bottom margin\n"); + + /* Set Arial font to larger font size, margins should NOT move */ + todo_wine { + SendMessageW(hwndRichEdit, WM_SETFONT, (WPARAM)testFont4W, MAKELPARAM(TRUE, 0)); + } + SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &CharFont1Unicode); + GetObjectW(testFont4W, sizeof(LOGFONTW), &sentLogFont); + ok (!lstrcmpW(sentLogFont.lfFaceName, CharFont1Unicode.szFaceName), "WM_SETFONT set wrong font. Font was set to %s, was supposed "\ + "to be \"Arial\".\n", wine_dbgstr_w(CharFont1Unicode.szFaceName)); + + SendMessage(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left, "Set Left Margin for Arial 30 pt, should be 0, got %d\n", new_rect.left); + ok(new_rect.right == old_rect.right, "Set Right Margin for Arial 30 pt, should be %d, got %d\n",old_rect.right -1, new_rect.right); + + /* Above a certain size threshold then the margin is updated */ + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,0)); + } + SendMessage(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + todo_wine { + ok(new_rect.left == old_rect.left + 1, "Set Left Margin Arial 30pt did not return one, value is %d\n", \ + new_rect.left - old_rect.left); + } + ok(new_rect.right == old_rect.right, "Set Right Margin to zero for Arial 30pt Right did not return zero, value is %d\n", \ + new_rect.right - old_rect.right); + + todo_wine{ + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(1,1)); + } + SendMessage(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + todo_wine { + ok(new_rect.left == old_rect.left +1 , "Set Left Margin Arial 30 pt to one did not return one, value is %d\n", new_rect.left); + ok(new_rect.right == old_rect.right -1, "Set Right Margin Arial 30 to one did not return %d, value is %d\n", old_rect.left -1, \ + new_rect.right); + } + + todo_wine { + SendMessageW(hwndRichEdit, EM_SETMARGINS, EC_USEFONTINFO, MAKELONG(10,10)); + } + SendMessage(hwndRichEdit, EM_GETRECT, 0, (LPARAM)&new_rect); + ok(new_rect.left == old_rect.left, "Set Left Margin Arial 30pt variation to USEFONTINFO (wParam) did not return zero, value is "\ + "%d\n", new_rect.left - old_rect.left); + ok(new_rect.right == old_rect.right, "Set Right Margin Arial 30pt variation to USEFONTINFO (wParam) did not return zero, value is "\ + "%d\n", new_rect.right - old_rect.right); + + ReleaseDC (hwndRichEdit, hDC); + DeleteObject(testFont1A); + DeleteObject(testFont2A); + DeleteObject(testFont1W); + DeleteObject(testFont2W); + DeleteObject(testFont4W); + DeleteObject(testFont3W); + DestroyWindow (hwndRichEdit); +} + START_TEST( editor ) { BOOL ret; @@ -7078,6 +7594,7 @@ START_TEST( editor ) is_win9x = GetVersion() & 0x80000000; + if (winetest_debug > 1) { test_WM_CHAR(); test_EM_FINDTEXT(); test_EM_GETLINE(); @@ -7126,6 +7643,8 @@ START_TEST( editor ) test_WM_GETDLGCODE(); test_zoom(); test_dialogmode(); + } + test_em_setmargins(); /* Set the environment variable WINETEST_RICHED20 to keep windows * responsive and open for 30 seconds. This is useful for debugging. -- 1.7.3.4