Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/riched20/para.c | 11 +++++++++- dlls/riched20/tests/txtsrv.c | 41 +++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c index f2a70e5746..27234b061a 100644 --- a/dlls/riched20/para.c +++ b/dlls/riched20/para.c @@ -35,7 +35,7 @@ static ME_DisplayItem *make_para(ME_TextEditor *editor) void ME_MakeFirstParagraph(ME_TextEditor *editor) { ME_Context c; - CHARFORMAT2W cf; + CHARFORMAT2W cf, cf_tmp; LOGFONTW lf; HFONT hf; ME_TextBuffer *text = editor->pBuffer; @@ -44,6 +44,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) ME_Style *style; int eol_len; WCHAR cr_lf[] = {'\r','\n',0}; + CHARFORMATW *host_cf;
ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
@@ -76,6 +77,14 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) style = ME_MakeStyle(&cf); text->pDefaultStyle = style;
+ if (ITextHost_TxGetCharFormat(editor->texthost, (const CHARFORMATW **)&host_cf) == S_OK) + { + ZeroMemory(&cf_tmp, sizeof(cf_tmp)); + cf_tmp.cbSize = sizeof(cf_tmp); + cfany_to_cf2w(&cf_tmp, (CHARFORMAT2W *)host_cf); + ME_SetDefaultCharFormat(editor, &cf_tmp); + } + eol_len = editor->bEmulateVersion10 ? 2 : 1; para->member.para.text = ME_MakeStringN( cr_lf, eol_len );
diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c index 5d312ca2cd..9d3fc361d6 100644 --- a/dlls/riched20/tests/txtsrv.c +++ b/dlls/riched20/tests/txtsrv.c @@ -85,6 +85,7 @@ typedef struct ITextHostTestImpl { ITextHost ITextHost_iface; LONG refCount; + CHARFORMAT2W char_format; } ITextHostTestImpl;
static inline ITextHostTestImpl *impl_from_ITextHost(ITextHost *iface) @@ -330,7 +331,8 @@ static HRESULT WINAPI ITextHostImpl_TxGetCharFormat(ITextHost *iface, { ITextHostTestImpl *This = impl_from_ITextHost(iface); TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This, ppCF); - return E_NOTIMPL; + *ppCF = (CHARFORMATW *)&This->char_format; + return S_OK; }
static HRESULT WINAPI ITextHostImpl_TxGetParaFormat(ITextHost *iface, @@ -624,6 +626,7 @@ static BOOL init_texthost(ITextServices **txtserv, ITextHost **ret) ITextHostTestImpl *dummyTextHost; IUnknown *init; HRESULT result; + HFONT hf;
dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost)); if (dummyTextHost == NULL) { @@ -632,6 +635,11 @@ static BOOL init_texthost(ITextServices **txtserv, ITextHost **ret) } dummyTextHost->ITextHost_iface.lpVtbl = &itextHostVtbl; dummyTextHost->refCount = 1; + memset(&dummyTextHost->char_format, 0, sizeof(dummyTextHost->char_format)); + dummyTextHost->char_format.cbSize = sizeof(dummyTextHost->char_format); + dummyTextHost->char_format.dwMask = CFM_ALL2; + hf = GetStockObject(DEFAULT_GUI_FONT); + hf_to_cf(hf, &dummyTextHost->char_format);
/* MSDN states that an IUnknown object is returned by CreateTextServices which is then queried to obtain a @@ -952,6 +960,36 @@ static void test_QueryInterface(void) ITextHost_Release(host); }
+static void test_default_format(void) +{ + ITextServices *txtserv; + ITextHost *host; + HRESULT result; + LRESULT lresult; + CHARFORMAT2W cf2; + CHARFORMATW *host_cf; + DWORD expected_effects; + + if (!init_texthost(&txtserv, &host)) + return; + + cf2.cbSize = sizeof(CHARFORMAT2W); + result = ITextServices_TxSendMessage(txtserv, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf2, &lresult); + ok(result == S_OK, "ITextServices_TxSendMessage failed: 0x%08x.\n", result); + + ITextHostImpl_TxGetCharFormat(host, (const CHARFORMATW **)&host_cf); + ok(!lstrcmpW(host_cf->szFaceName, cf2.szFaceName), "got wrong font name: %s.\n", wine_dbgstr_w(cf2.szFaceName)); + ok(cf2.yHeight == host_cf->yHeight, "got wrong yHeight: %d, expetced %d.\n", cf2.yHeight, host_cf->yHeight); + expected_effects = (cf2.dwEffects & ~(CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR)); + ok(host_cf->dwEffects == expected_effects , "got wrong dwEffects: %x, expetced %x.\n", cf2.dwEffects, expected_effects); + ok(cf2.bPitchAndFamily == host_cf->bPitchAndFamily, "got wrong bPitchAndFamily: %x, expected %x.\n", + cf2.bPitchAndFamily, host_cf->bPitchAndFamily); + ok(cf2.bCharSet == host_cf->bCharSet, "got wrong bCharSet: %x, expected %x.\n", cf2.bCharSet, host_cf->bCharSet); + + ITextServices_Release(txtserv); + ITextHost_Release(host); +} + START_TEST( txtsrv ) { ITextServices *txtserv; @@ -982,6 +1020,7 @@ START_TEST( txtsrv ) test_TxGetNaturalSize(); test_TxDraw(); test_QueryInterface(); + test_default_format(); } if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE); }
On Mon, Aug 06, 2018 at 04:52:05PM +0800, Jactry Zeng wrote:
Signed-off-by: Jactry Zeng jzeng@codeweavers.com
dlls/riched20/para.c | 11 +++++++++- dlls/riched20/tests/txtsrv.c | 41 +++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c index f2a70e5746..27234b061a 100644 --- a/dlls/riched20/para.c +++ b/dlls/riched20/para.c @@ -35,7 +35,7 @@ static ME_DisplayItem *make_para(ME_TextEditor *editor) void ME_MakeFirstParagraph(ME_TextEditor *editor) { ME_Context c;
- CHARFORMAT2W cf;
- CHARFORMAT2W cf, cf_tmp;
Just reuse cf, there's no need for a separate cf_tmp.
LOGFONTW lf; HFONT hf; ME_TextBuffer *text = editor->pBuffer; @@ -44,6 +44,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) ME_Style *style; int eol_len; WCHAR cr_lf[] = {'\r','\n',0};
- CHARFORMATW *host_cf;
const CHARFORMATW *host_cf, then you don't need the cast when calling TxGetCharFormat. Also, can you move this to below the CHARFORMAT2W declarations?
ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
@@ -76,6 +77,14 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) style = ME_MakeStyle(&cf); text->pDefaultStyle = style;
- if (ITextHost_TxGetCharFormat(editor->texthost, (const CHARFORMATW **)&host_cf) == S_OK)
- {
- ZeroMemory(&cf_tmp, sizeof(cf_tmp));
- cf_tmp.cbSize = sizeof(cf_tmp);
- cfany_to_cf2w(&cf_tmp, (CHARFORMAT2W *)host_cf);
- ME_SetDefaultCharFormat(editor, &cf_tmp);
- }
- eol_len = editor->bEmulateVersion10 ? 2 : 1; para->member.para.text = ME_MakeStringN( cr_lf, eol_len );
diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c index 5d312ca2cd..9d3fc361d6 100644 --- a/dlls/riched20/tests/txtsrv.c +++ b/dlls/riched20/tests/txtsrv.c @@ -85,6 +85,7 @@ typedef struct ITextHostTestImpl { ITextHost ITextHost_iface; LONG refCount;
- CHARFORMAT2W char_format;
} ITextHostTestImpl;
static inline ITextHostTestImpl *impl_from_ITextHost(ITextHost *iface) @@ -330,7 +331,8 @@ static HRESULT WINAPI ITextHostImpl_TxGetCharFormat(ITextHost *iface, { ITextHostTestImpl *This = impl_from_ITextHost(iface); TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This, ppCF);
- return E_NOTIMPL;
- *ppCF = (CHARFORMATW *)&This->char_format;
- return S_OK;
}
static HRESULT WINAPI ITextHostImpl_TxGetParaFormat(ITextHost *iface, @@ -624,6 +626,7 @@ static BOOL init_texthost(ITextServices **txtserv, ITextHost **ret) ITextHostTestImpl *dummyTextHost; IUnknown *init; HRESULT result;
HFONT hf;
dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost)); if (dummyTextHost == NULL) {
@@ -632,6 +635,11 @@ static BOOL init_texthost(ITextServices **txtserv, ITextHost **ret) } dummyTextHost->ITextHost_iface.lpVtbl = &itextHostVtbl; dummyTextHost->refCount = 1;
memset(&dummyTextHost->char_format, 0, sizeof(dummyTextHost->char_format));
dummyTextHost->char_format.cbSize = sizeof(dummyTextHost->char_format);
dummyTextHost->char_format.dwMask = CFM_ALL2;
hf = GetStockObject(DEFAULT_GUI_FONT);
hf_to_cf(hf, &dummyTextHost->char_format);
/* MSDN states that an IUnknown object is returned by CreateTextServices which is then queried to obtain a
@@ -952,6 +960,36 @@ static void test_QueryInterface(void) ITextHost_Release(host); }
+static void test_default_format(void) +{
- ITextServices *txtserv;
- ITextHost *host;
- HRESULT result;
- LRESULT lresult;
- CHARFORMAT2W cf2;
- CHARFORMATW *host_cf;
- DWORD expected_effects;
- if (!init_texthost(&txtserv, &host))
return;
- cf2.cbSize = sizeof(CHARFORMAT2W);
- result = ITextServices_TxSendMessage(txtserv, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf2, &lresult);
- ok(result == S_OK, "ITextServices_TxSendMessage failed: 0x%08x.\n", result);
- ITextHostImpl_TxGetCharFormat(host, (const CHARFORMATW **)&host_cf);
- ok(!lstrcmpW(host_cf->szFaceName, cf2.szFaceName), "got wrong font name: %s.\n", wine_dbgstr_w(cf2.szFaceName));
- ok(cf2.yHeight == host_cf->yHeight, "got wrong yHeight: %d, expetced %d.\n", cf2.yHeight, host_cf->yHeight);
- expected_effects = (cf2.dwEffects & ~(CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR));
- ok(host_cf->dwEffects == expected_effects , "got wrong dwEffects: %x, expetced %x.\n", cf2.dwEffects, expected_effects);
- ok(cf2.bPitchAndFamily == host_cf->bPitchAndFamily, "got wrong bPitchAndFamily: %x, expected %x.\n",
cf2.bPitchAndFamily, host_cf->bPitchAndFamily);
- ok(cf2.bCharSet == host_cf->bCharSet, "got wrong bCharSet: %x, expected %x.\n", cf2.bCharSet, host_cf->bCharSet);
- ITextServices_Release(txtserv);
- ITextHost_Release(host);
+}
START_TEST( txtsrv ) { ITextServices *txtserv; @@ -982,6 +1020,7 @@ START_TEST( txtsrv ) test_TxGetNaturalSize(); test_TxDraw(); test_QueryInterface();
} if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE);test_default_format();
}
2.18.0