summaryrefslogtreecommitdiff
path: root/libs/mTextControl/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-10-29 19:55:01 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-10-29 19:55:01 +0300
commiteb7783cca53e945354b83aa3899ca9cdb0602dbd (patch)
treed900571248d3c761f92fae7509834882fdeeb538 /libs/mTextControl/src
parent54c499be356449adfba900116fb264113cbd6c7f (diff)
further investigation about RTF for ITextServices
Diffstat (limited to 'libs/mTextControl/src')
-rw-r--r--libs/mTextControl/src/FormattedTextDraw.cpp45
-rw-r--r--libs/mTextControl/src/services.cpp17
-rw-r--r--libs/mTextControl/src/stdafx.h1
3 files changed, 29 insertions, 34 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>