diff options
-rw-r--r-- | libs/mTextControl/src/FormattedTextDraw.cpp | 45 | ||||
-rw-r--r-- | libs/mTextControl/src/services.cpp | 17 | ||||
-rw-r--r-- | libs/mTextControl/src/stdafx.h | 1 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.cpp | 9 |
4 files changed, 32 insertions, 40 deletions
diff --git a/libs/mTextControl/src/FormattedTextDraw.cpp b/libs/mTextControl/src/FormattedTextDraw.cpp index 8a074430fc..fc1e84c0ea 100644 --- a/libs/mTextControl/src/FormattedTextDraw.cpp +++ b/libs/mTextControl/src/FormattedTextDraw.cpp @@ -44,7 +44,7 @@ CFormattedTextDraw::CFormattedTextDraw() m_dwPropertyBits = TXTBIT_RICHTEXT | TXTBIT_MULTILINE | TXTBIT_WORDWRAP | TXTBIT_USECURRENTBKG; IUnknown *spUnk; - HRESULT hr = MyCreateTextServices(nullptr, static_cast<ITextHost *>(this), &spUnk); + HRESULT hr = MyCreateTextServices(nullptr, this, &spUnk); if (hr == S_OK) { hr = spUnk->QueryInterface(IID_ITextServices, (void **)&m_spTextServices); hr = spUnk->QueryInterface(IID_ITextDocument, (void **)&m_spTextDocument); @@ -160,45 +160,21 @@ HRESULT CFormattedTextDraw::putTextW(wchar_t *newVal) struct STREAMDATA { - CMStringA buf; - int iStage = STREAMSTAGE_HEADER; - MRtfProvider *pProv; + const char *str; + int lSize, lCount; }; static DWORD CALLBACK EditStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { auto *dat = (STREAMDATA *)dwCookie; - if (dat->buf.IsEmpty()) { - switch (dat->iStage) { - case STREAMSTAGE_HEADER: - dat->buf = dat->pProv->CreateRtfHeader(); - dat->iStage = STREAMSTAGE_EVENTS; - break; - - case STREAMSTAGE_EVENTS: - dat->buf = dat->pProv->CreateRtfBody(); - dat->iStage = STREAMSTAGE_TAIL; - break; - - case STREAMSTAGE_TAIL: - dat->buf = dat->pProv->CreateRtfFooter(); - dat->iStage = STREAMSTAGE_STOP; - break; - - case STREAMSTAGE_STOP: - *pcb = 0; - return 0; - } - } - - *pcb = min(cb, dat->buf.GetLength()); - memcpy(pbBuff, dat->buf.GetBuffer(), *pcb); - if (dat->buf.GetLength() == *pcb) - dat->buf.Empty(); + if (dat->lSize - dat->lCount < cb) + *pcb = dat->lSize - dat->lCount; else - dat->buf.Delete(0, *pcb); + *pcb = cb; + memcpy(pbBuff, dat->str + dat->lCount, *pcb); + dat->lCount += *pcb; return 0; // callback succeeded - no errors } @@ -207,8 +183,9 @@ HRESULT CFormattedTextDraw::putRTFText(MRtfProvider *pProv) if (!m_spTextServices) return S_FALSE; - STREAMDATA streamData = {}; - streamData.pProv = pProv; + CMStringA buf = pProv->CreateRtfHeader() + pProv->CreateRtfBody() + pProv->CreateRtfFooter(); + + STREAMDATA streamData = { buf.c_str(), buf.GetLength(), 0 }; EDITSTREAM editStream; editStream.dwCookie = (DWORD_PTR)&streamData; diff --git a/libs/mTextControl/src/services.cpp b/libs/mTextControl/src/services.cpp index 2716bce13b..c3d568e56c 100644 --- a/libs/mTextControl/src/services.cpp +++ b/libs/mTextControl/src/services.cpp @@ -66,6 +66,14 @@ void MText_InitFormatting1(TextObject *text) ///////////////////////////////////////////////////////////////////////////////////////// // allocate text object (unicode) +DWORD CALLBACK EditStreamOutCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) +{ + CMStringA *rtf = (CMStringA *)dwCookie; + rtf->Append((char *)pbBuff, cb); + *pcb = cb; + return 0; +} + MTEXTCONTROL_DLL(TextObject *) MTextCreateW(HANDLE userHandle, const char *szProto, const wchar_t *text) { TextObject *result = new TextObject; @@ -78,6 +86,15 @@ MTEXTCONTROL_DLL(TextObject *) MTextCreateW(HANDLE userHandle, const char *szPro result->ftd->putTextW((wchar_t *)text); MText_InitFormatting1(result); + /* + LRESULT res; + CMStringA buf; + EDITSTREAM es = { 0 }; + es.dwCookie = (DWORD_PTR)&buf; + es.pfnCallback = &EditStreamOutCallback; + result->ftd->getTextService()->TxSendMessage(EM_STREAMOUT, SF_RTF, (LPARAM)&es, &res); + + Netlib_Logf(0, "Rtf created: %s", buf.c_str());*/ return result; } diff --git a/libs/mTextControl/src/stdafx.h b/libs/mTextControl/src/stdafx.h index 302d594b39..3866c8849d 100644 --- a/libs/mTextControl/src/stdafx.h +++ b/libs/mTextControl/src/stdafx.h @@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include <m_database.h> #include <m_langpack.h> +#include <m_netlib.h> #include <m_utils.h> #include <m_text.h> diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index 7010ff1e85..7e6f82a0a7 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -60,8 +60,6 @@ CMStringW TplFormatStringEx(int tpl, wchar_t *sztpl, ItemData *item) static void AppendUnicodeToBuffer(CMStringA &buf, const wchar_t *p) { - buf.Append("{\\uc1 "); - for (; *p; p++) { if (*p == '\r' && p[1] == '\n') { buf.Append("\\p "); @@ -118,7 +116,6 @@ static void AppendUnicodeToBuffer(CMStringA &buf, const wchar_t *p) buf.AppendFormat("\\u%d ?", *p); } } - buf.AppendChar('}'); } CMStringA NSRtfProvider::CreateRtfHeader() @@ -127,7 +124,7 @@ CMStringA NSRtfProvider::CreateRtfHeader() buf.Append("{\\rtf1\\ansi\\deff0"); auto &F = g_fontTable[(m_pItem->dbe.flags & DBEF_SENT) ? FONT_OUTMSG : FONT_INMSG]; - buf.AppendFormat("{\\fonttbl{\\f0\\fnil\\fcharset1 %s;}}", F.lf.lfFaceName); + buf.AppendFormat("{\\fonttbl{\\f0\\fnil\\fcharset0 %s;}}", F.lf.lfFaceName); COLORREF cr = GetSysColor(COLOR_WINDOWTEXT); buf.AppendFormat("{\\colortbl \\red%u\\green%u\\blue%u;", GetRValue(cr), GetGValue(cr), GetBValue(cr)); @@ -142,14 +139,14 @@ CMStringA NSRtfProvider::CreateRtfBody() CMStringW wszText = TplFormatString(m_pItem->getTemplate(), m_pItem->hContact, m_pItem); CMStringA buf; - // buf.AppendFormat("\\f0\\cf0\\b0\\i0\\fs%d ", -F.lf.lfHeight); + buf.AppendFormat("\\viewkind4\\uc1\\pard \\f0\\b0\\i0\\fs%d ", F.lf.lfHeight); AppendUnicodeToBuffer(buf, wszText); return buf; } CMStringA NSRtfProvider::CreateRtfFooter() { - return "}"; + return " \\par }"; } /////////////////////////////////////////////////////////////////////////////// |