diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c index e3e42cc85f7..ca50f189e94 100644 --- a/dlls/riched20/caret.c +++ b/dlls/riched20/caret.c @@ -446,7 +446,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start, continue; } } - if (delete_all) ME_SetDefaultParaFormat( start_para->member.para.pFmt ); + if (delete_all) ME_SetDefaultParaFormat( editor, start_para->member.para.pFmt ); return TRUE; } diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 98c7414a5b3..ec584eb2820 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -172,14 +172,14 @@ - ES_AUTOHSCROLL - ES_AUTOVSCROLL - - ES_CENTER + + ES_CENTER + ES_DISABLENOSCROLL (scrollbar is always visible) - ES_EX_NOCALLOLEINIT - - ES_LEFT + + ES_LEFT - ES_MULTILINE (currently single line controls aren't supported) - ES_NOIME - ES_READONLY (I'm not sure if beeping is the proper behaviour) - - ES_RIGHT + + ES_RIGHT - ES_SAVESEL - ES_SELFIME - ES_SUNKEN @@ -1563,7 +1563,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre ME_GetTextLength(editor), FALSE); from = to = 0; ME_ClearTempStyle(editor); - ME_SetDefaultParaFormat(editor->pCursors[0].pPara->member.para.pFmt); + ME_SetDefaultParaFormat(editor, editor->pCursors[0].pPara->member.para.pFmt); } @@ -2364,7 +2364,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) ME_InsertTextFromCursor(editor, 0, &endl, 1, editor->pCursors[0].pRun->member.run.style); para = editor->pBuffer->pFirst->member.para.next_para; - ME_SetDefaultParaFormat(para->member.para.pFmt); + ME_SetDefaultParaFormat(editor, para->member.para.pFmt); para->member.para.nFlags = MEPF_REWRAP; editor->pCursors[0].pPara = para; editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); @@ -2790,7 +2790,7 @@ static BOOL ME_ShowContextMenu(ME_TextEditor *editor, int x, int y) return TRUE; } -ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10) +ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10, DWORD csStyle) { ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor); int i; @@ -2804,6 +2804,11 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10) ed->reOle = NULL; ed->bEmulateVersion10 = bEmulateVersion10; ed->styleFlags = 0; + ed->alignStyle = PFA_LEFT; + if (csStyle & ES_RIGHT) + ed->alignStyle = PFA_RIGHT; + if (csStyle & ES_CENTER) + ed->alignStyle = PFA_CENTER; ITextHost_TxGetPropertyBits(texthost, (TXTBIT_RICHTEXT|TXTBIT_MULTILINE| TXTBIT_READONLY|TXTBIT_USEPASSWORD| diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h index 3e42ed8e929..f22f0e651b8 100644 --- a/dlls/riched20/editor.h +++ b/dlls/riched20/editor.h @@ -213,7 +213,7 @@ void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]) DECLSPEC_HID BOOL ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN; void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN; void ME_MarkAllForWrapping(ME_TextEditor *editor) DECLSPEC_HIDDEN; -void ME_SetDefaultParaFormat(PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN; +void ME_SetDefaultParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN; /* paint.c */ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, const RECT *rcUpdate) DECLSPEC_HIDDEN; @@ -249,7 +249,7 @@ void ME_DeleteReObject(REOBJECT* reo) DECLSPEC_HIDDEN; void ME_GetITextDocumentInterface(IRichEditOle *iface, LPVOID *ppvObj) DECLSPEC_HIDDEN; /* editor.c */ -ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10) DECLSPEC_HIDDEN; +ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10, DWORD csStyle) DECLSPEC_HIDDEN; void ME_DestroyEditor(ME_TextEditor *editor) DECLSPEC_HIDDEN; LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode, HRESULT* phresult) DECLSPEC_HIDDEN; diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h index 57d7fef44fe..90f7fa0ee20 100644 --- a/dlls/riched20/editstr.h +++ b/dlls/riched20/editstr.h @@ -391,6 +391,7 @@ typedef struct tagME_TextEditor ME_TextBuffer *pBuffer; ME_Cursor *pCursors; DWORD styleFlags; + DWORD alignStyle; DWORD exStyleFlags; int nCursors; SIZE sizeWindow; diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c index c068d845687..3ea98c5976a 100644 --- a/dlls/riched20/para.c +++ b/dlls/riched20/para.c @@ -28,7 +28,7 @@ static ME_DisplayItem *make_para(ME_TextEditor *editor) ME_DisplayItem *item = ME_MakeDI(diParagraph); item->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2); - ME_SetDefaultParaFormat(item->member.para.pFmt); + ME_SetDefaultParaFormat(editor, item->member.para.pFmt); item->member.para.nFlags = MEPF_REWRAP; return item; } @@ -629,12 +629,12 @@ void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) } } -void ME_SetDefaultParaFormat(PARAFORMAT2 *pFmt) +void ME_SetDefaultParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) { ZeroMemory(pFmt, sizeof(PARAFORMAT2)); pFmt->cbSize = sizeof(PARAFORMAT2); pFmt->dwMask = PFM_ALL2; - pFmt->wAlignment = PFA_LEFT; + pFmt->wAlignment = editor->alignStyle; pFmt->sStyle = -1; pFmt->bOutlineLevel = TRUE; } diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index da9671ba85e..31af4b200af 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -7965,6 +7965,76 @@ static void test_EM_SETFONTSIZE(void) DestroyWindow(richedit); } +static void test_alignment_style(void) +{ + HWND richedit = NULL; + PARAFORMAT2 pf; + DWORD align_style[] = {ES_LEFT, ES_CENTER, ES_RIGHT, ES_RIGHT | ES_CENTER, + ES_LEFT | ES_CENTER, ES_LEFT | ES_RIGHT, + ES_LEFT | ES_RIGHT | ES_CENTER}; + DWORD align_mask[] = {PFA_LEFT, PFA_CENTER, PFA_RIGHT, PFA_CENTER, PFA_CENTER, + PFA_RIGHT, PFA_CENTER}; + const char * streamtext = + "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang12298{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 System;}}\r\n" + "\\viewkind4\\uc1\\pard\\f0\\fs17 TestSomeText\\par\r\n" + "}\r\n"; + EDITSTREAM es; + int i; + + for (i = 0; i < sizeof(align_style) / sizeof(align_style[0]); i++) + { + DWORD dwStyle, new_align; + + richedit = new_windowW(RICHEDIT_CLASS20W, align_style[i], NULL); + memset(&pf, 0, sizeof(pf)); + pf.cbSize = sizeof(PARAFORMAT2); + pf.dwMask = -1; + + SendMessageW(richedit, EM_GETPARAFORMAT, 0, (LPARAM)&pf); + ok(pf.wAlignment == align_mask[i], "(i = %d) got %d expected %d\n", + i, pf.wAlignment, align_mask[i]); + dwStyle = GetWindowLongW(richedit, GWL_STYLE); + ok((i ? (dwStyle & align_style[i]) : (!(dwStyle & 0x0000000f))) , + "(i = %d) didn't set right align style: 0x%x\n", i, dwStyle); + + + /* Based on test_reset_default_para_fmt() */ + new_align = (align_mask[i] == PFA_LEFT) ? PFA_RIGHT : PFA_LEFT; + simulate_typing_characters(richedit, "123"); + + SendMessageW(richedit, EM_SETSEL, 0, -1); + pf.dwMask = PFM_ALIGNMENT; + pf.wAlignment = new_align; + SendMessageW(richedit, EM_SETPARAFORMAT, 0, (LPARAM)&pf); + + SendMessageW(richedit, EM_GETPARAFORMAT, 0, (LPARAM)&pf); + ok(pf.wAlignment == new_align, "got %d expect %d\n", pf.wAlignment, new_align); + + SendMessageW(richedit, EM_SETSEL, 0, -1); + SendMessageW(richedit, WM_CUT, 0, 0); + + SendMessageW(richedit, EM_GETPARAFORMAT, 0, (LPARAM)&pf); + ok(pf.wAlignment == align_mask[i], "got %d exppect %d\n", pf.wAlignment, align_mask[i]); + + DestroyWindow(richedit); + } + + /* test with EM_STREAMIN */ + richedit = new_windowW(RICHEDIT_CLASS20W, ES_CENTER, NULL); + simulate_typing_characters(richedit, "abc"); + es.dwCookie = (DWORD_PTR)&streamtext; + es.dwError = 0; + es.pfnCallback = test_EM_STREAMIN_esCallback; + SendMessageW(richedit, EM_STREAMIN, SF_RTF, (LPARAM)&es); + SendMessageW(richedit, EM_SETSEL, 0, -1); + memset(&pf, 0, sizeof(pf)); + pf.cbSize = sizeof(PARAFORMAT2); + pf.dwMask = -1; + SendMessageW(richedit, EM_GETPARAFORMAT, SCF_SELECTION, (LPARAM)&pf); + ok(pf.wAlignment == ES_CENTER, "got %d expected ES_CENTER\n", pf.wAlignment); + DestroyWindow(richedit); +} + START_TEST( editor ) { BOOL ret; @@ -8031,6 +8101,7 @@ START_TEST( editor ) test_reset_default_para_fmt(); test_EM_SETREADONLY(); test_EM_SETFONTSIZE(); + test_alignment_style(); /* Set the environment variable WINETEST_RICHED20 to keep windows * responsive and open for 30 seconds. This is useful for debugging. diff --git a/dlls/riched20/txthost.c b/dlls/riched20/txthost.c index af32c1af413..b99c9334d05 100644 --- a/dlls/riched20/txthost.c +++ b/dlls/riched20/txthost.c @@ -55,7 +55,7 @@ ITextHost *ME_CreateTextHost(HWND hwnd, CREATESTRUCTW *cs, BOOL bEmulateVersion1 texthost->hWnd = hwnd; texthost->bEmulateVersion10 = bEmulateVersion10; - editor = ME_MakeEditor(&texthost->ITextHost_iface, bEmulateVersion10); + editor = ME_MakeEditor(&texthost->ITextHost_iface, bEmulateVersion10, cs->style); editor->exStyleFlags = GetWindowLongW(hwnd, GWL_EXSTYLE); editor->styleFlags |= GetWindowLongW(hwnd, GWL_STYLE) & ES_WANTRETURN; editor->hWnd = hwnd; /* FIXME: Remove editor's dependence on hWnd */ diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c index 1bf9cf29bfa..18b26ac0da1 100644 --- a/dlls/riched20/txtsrv.c +++ b/dlls/riched20/txtsrv.c @@ -414,7 +414,7 @@ HRESULT WINAPI CreateTextServices(IUnknown *pUnkOuter, ITextHost *pITextHost, I ITextImpl->pMyHost = pITextHost; ITextImpl->IUnknown_inner.lpVtbl = &textservices_inner_vtbl; ITextImpl->ITextServices_iface.lpVtbl = &textservices_vtbl; - ITextImpl->editor = ME_MakeEditor(pITextHost, FALSE); + ITextImpl->editor = ME_MakeEditor(pITextHost, FALSE, ES_LEFT); ITextImpl->editor->exStyleFlags = 0; ITextImpl->editor->rcFormat.left = 0; ITextImpl->editor->rcFormat.top = 0;