riched20: Implement alignment styles support.

Signed-off-by: Jactry Zeng <jzeng@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jactry Zeng 2015-11-06 17:35:35 +08:00 committed by Alexandre Julliard
parent f8e73e370d
commit 6401ab45c0
8 changed files with 91 additions and 14 deletions

View File

@ -446,7 +446,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
continue; continue;
} }
} }
if (delete_all) ME_SetDefaultParaFormat( start_para->member.para.pFmt ); if (delete_all) ME_SetDefaultParaFormat( editor, start_para->member.para.pFmt );
return TRUE; return TRUE;
} }

View File

@ -172,14 +172,14 @@
- ES_AUTOHSCROLL - ES_AUTOHSCROLL
- ES_AUTOVSCROLL - ES_AUTOVSCROLL
- ES_CENTER + ES_CENTER
+ ES_DISABLENOSCROLL (scrollbar is always visible) + ES_DISABLENOSCROLL (scrollbar is always visible)
- ES_EX_NOCALLOLEINIT - ES_EX_NOCALLOLEINIT
- ES_LEFT + ES_LEFT
- ES_MULTILINE (currently single line controls aren't supported) - ES_MULTILINE (currently single line controls aren't supported)
- ES_NOIME - ES_NOIME
- ES_READONLY (I'm not sure if beeping is the proper behaviour) - ES_READONLY (I'm not sure if beeping is the proper behaviour)
- ES_RIGHT + ES_RIGHT
- ES_SAVESEL - ES_SAVESEL
- ES_SELFIME - ES_SELFIME
- ES_SUNKEN - ES_SUNKEN
@ -1563,7 +1563,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
ME_GetTextLength(editor), FALSE); ME_GetTextLength(editor), FALSE);
from = to = 0; from = to = 0;
ME_ClearTempStyle(editor); 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, ME_InsertTextFromCursor(editor, 0, &endl, 1,
editor->pCursors[0].pRun->member.run.style); editor->pCursors[0].pRun->member.run.style);
para = editor->pBuffer->pFirst->member.para.next_para; 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; para->member.para.nFlags = MEPF_REWRAP;
editor->pCursors[0].pPara = para; editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); 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; 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); ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
int i; int i;
@ -2804,6 +2804,11 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
ed->reOle = NULL; ed->reOle = NULL;
ed->bEmulateVersion10 = bEmulateVersion10; ed->bEmulateVersion10 = bEmulateVersion10;
ed->styleFlags = 0; 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, ITextHost_TxGetPropertyBits(texthost,
(TXTBIT_RICHTEXT|TXTBIT_MULTILINE| (TXTBIT_RICHTEXT|TXTBIT_MULTILINE|
TXTBIT_READONLY|TXTBIT_USEPASSWORD| TXTBIT_READONLY|TXTBIT_USEPASSWORD|

View File

@ -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; BOOL ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN; void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
void ME_MarkAllForWrapping(ME_TextEditor *editor) 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 */ /* paint.c */
void ME_PaintContent(ME_TextEditor *editor, HDC hDC, const RECT *rcUpdate) DECLSPEC_HIDDEN; 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; void ME_GetITextDocumentInterface(IRichEditOle *iface, LPVOID *ppvObj) DECLSPEC_HIDDEN;
/* editor.c */ /* 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; void ME_DestroyEditor(ME_TextEditor *editor) DECLSPEC_HIDDEN;
LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
LPARAM lParam, BOOL unicode, HRESULT* phresult) DECLSPEC_HIDDEN; LPARAM lParam, BOOL unicode, HRESULT* phresult) DECLSPEC_HIDDEN;

View File

@ -391,6 +391,7 @@ typedef struct tagME_TextEditor
ME_TextBuffer *pBuffer; ME_TextBuffer *pBuffer;
ME_Cursor *pCursors; ME_Cursor *pCursors;
DWORD styleFlags; DWORD styleFlags;
DWORD alignStyle;
DWORD exStyleFlags; DWORD exStyleFlags;
int nCursors; int nCursors;
SIZE sizeWindow; SIZE sizeWindow;

View File

@ -28,7 +28,7 @@ static ME_DisplayItem *make_para(ME_TextEditor *editor)
ME_DisplayItem *item = ME_MakeDI(diParagraph); ME_DisplayItem *item = ME_MakeDI(diParagraph);
item->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2); 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; item->member.para.nFlags = MEPF_REWRAP;
return item; 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)); ZeroMemory(pFmt, sizeof(PARAFORMAT2));
pFmt->cbSize = sizeof(PARAFORMAT2); pFmt->cbSize = sizeof(PARAFORMAT2);
pFmt->dwMask = PFM_ALL2; pFmt->dwMask = PFM_ALL2;
pFmt->wAlignment = PFA_LEFT; pFmt->wAlignment = editor->alignStyle;
pFmt->sStyle = -1; pFmt->sStyle = -1;
pFmt->bOutlineLevel = TRUE; pFmt->bOutlineLevel = TRUE;
} }

View File

@ -7965,6 +7965,76 @@ static void test_EM_SETFONTSIZE(void)
DestroyWindow(richedit); 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 ) START_TEST( editor )
{ {
BOOL ret; BOOL ret;
@ -8031,6 +8101,7 @@ START_TEST( editor )
test_reset_default_para_fmt(); test_reset_default_para_fmt();
test_EM_SETREADONLY(); test_EM_SETREADONLY();
test_EM_SETFONTSIZE(); test_EM_SETFONTSIZE();
test_alignment_style();
/* Set the environment variable WINETEST_RICHED20 to keep windows /* Set the environment variable WINETEST_RICHED20 to keep windows
* responsive and open for 30 seconds. This is useful for debugging. * responsive and open for 30 seconds. This is useful for debugging.

View File

@ -55,7 +55,7 @@ ITextHost *ME_CreateTextHost(HWND hwnd, CREATESTRUCTW *cs, BOOL bEmulateVersion1
texthost->hWnd = hwnd; texthost->hWnd = hwnd;
texthost->bEmulateVersion10 = bEmulateVersion10; 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->exStyleFlags = GetWindowLongW(hwnd, GWL_EXSTYLE);
editor->styleFlags |= GetWindowLongW(hwnd, GWL_STYLE) & ES_WANTRETURN; editor->styleFlags |= GetWindowLongW(hwnd, GWL_STYLE) & ES_WANTRETURN;
editor->hWnd = hwnd; /* FIXME: Remove editor's dependence on hWnd */ editor->hWnd = hwnd; /* FIXME: Remove editor's dependence on hWnd */

View File

@ -414,7 +414,7 @@ HRESULT WINAPI CreateTextServices(IUnknown *pUnkOuter, ITextHost *pITextHost, I
ITextImpl->pMyHost = pITextHost; ITextImpl->pMyHost = pITextHost;
ITextImpl->IUnknown_inner.lpVtbl = &textservices_inner_vtbl; ITextImpl->IUnknown_inner.lpVtbl = &textservices_inner_vtbl;
ITextImpl->ITextServices_iface.lpVtbl = &textservices_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->exStyleFlags = 0;
ITextImpl->editor->rcFormat.left = 0; ITextImpl->editor->rcFormat.left = 0;
ITextImpl->editor->rcFormat.top = 0; ITextImpl->editor->rcFormat.top = 0;