summaryrefslogtreecommitdiff
path: root/libs/mTextControl
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-10-30 14:26:08 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-10-30 14:26:08 +0300
commit16143e784b1697c4b5349bc888c97f7160cf4534 (patch)
tree4c0fe1126581e3a3a3d0768634125622467aca4a /libs/mTextControl
parent029872c0b8993f84ac2cad5ac701d6056aad2d7d (diff)
mTextControl: code cleaning + stronger types
Diffstat (limited to 'libs/mTextControl')
-rw-r--r--libs/mTextControl/src/FormattedTextDraw.cpp38
-rw-r--r--libs/mTextControl/src/FormattedTextDraw.h2
-rw-r--r--libs/mTextControl/src/services.cpp4
3 files changed, 9 insertions, 35 deletions
diff --git a/libs/mTextControl/src/FormattedTextDraw.cpp b/libs/mTextControl/src/FormattedTextDraw.cpp
index fc1e84c0ea..e89ab6ad1d 100644
--- a/libs/mTextControl/src/FormattedTextDraw.cpp
+++ b/libs/mTextControl/src/FormattedTextDraw.cpp
@@ -151,46 +151,20 @@ HRESULT CFormattedTextDraw::putTextW(wchar_t *newVal)
return S_OK;
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-#define STREAMSTAGE_HEADER 0
-#define STREAMSTAGE_EVENTS 1
-#define STREAMSTAGE_TAIL 2
-#define STREAMSTAGE_STOP 3
-
-struct STREAMDATA
-{
- 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->lSize - dat->lCount < cb)
- *pcb = dat->lSize - dat->lCount;
- else
- *pcb = cb;
-
- memcpy(pbBuff, dat->str + dat->lCount, *pcb);
- dat->lCount += *pcb;
- return 0; // callback succeeded - no errors
-}
-
-HRESULT CFormattedTextDraw::putRTFText(MRtfProvider *pProv)
+HRESULT CFormattedTextDraw::putRTFText(char *newVal)
{
if (!m_spTextServices)
return S_FALSE;
- CMStringA buf = pProv->CreateRtfHeader() + pProv->CreateRtfBody() + pProv->CreateRtfFooter();
-
- STREAMDATA streamData = { buf.c_str(), buf.GetLength(), 0 };
+ STREAMDATATEXT streamData = {};
+ streamData.isUnicode = false;
+ streamData.ansi = newVal;
+ streamData.cbSize = mir_strlen(newVal);
EDITSTREAM editStream;
editStream.dwCookie = (DWORD_PTR)&streamData;
editStream.dwError = 0;
- editStream.pfnCallback = EditStreamInCallback;
+ editStream.pfnCallback = EditStreamTextInCallback;
LRESULT lResult = 0;
m_spTextServices->TxSendMessage(EM_STREAMIN, SF_RTF, (LPARAM)&editStream, &lResult);
diff --git a/libs/mTextControl/src/FormattedTextDraw.h b/libs/mTextControl/src/FormattedTextDraw.h
index 3ec7a7412e..f9ff25f2b6 100644
--- a/libs/mTextControl/src/FormattedTextDraw.h
+++ b/libs/mTextControl/src/FormattedTextDraw.h
@@ -38,7 +38,7 @@ public:
HRESULT get_NaturalSize(HDC hdcDraw, long *Width, long *pVal);
HRESULT Draw(HDC hdcDraw, RECT *prc);
- HRESULT putRTFText(MRtfProvider *pProv);
+ HRESULT putRTFText(char *newVal);
HRESULT putTextA(char *newVal);
HRESULT putTextW(wchar_t *newVal);
diff --git a/libs/mTextControl/src/services.cpp b/libs/mTextControl/src/services.cpp
index bd7eee6a50..1575b716dd 100644
--- a/libs/mTextControl/src/services.cpp
+++ b/libs/mTextControl/src/services.cpp
@@ -101,7 +101,7 @@ MTEXTCONTROL_DLL(TextObject *) MTextCreateW(HANDLE userHandle, const char *szPro
/////////////////////////////////////////////////////////////////////////////////////////
// allocate text object (advanced)
-MTEXTCONTROL_DLL(TextObject *) MTextCreateEx(HANDLE userHandle, void *text, uint32_t flags)
+MTEXTCONTROL_DLL(TextObject *) MTextCreateEx(HANDLE userHandle, const void *text, uint32_t flags)
{
TextObject *result = new TextObject;
result->options = TextUserGetOptions(userHandle);
@@ -110,7 +110,7 @@ MTEXTCONTROL_DLL(TextObject *) MTextCreateEx(HANDLE userHandle, void *text, uint
MText_InitFormatting0(result->ftd, result->options);
if (flags & MTEXT_FLG_RTF) {
- result->ftd->putRTFText((MRtfProvider *)text);
+ result->ftd->putRTFText((char *)text);
}
else {
if (flags & MTEXT_FLG_WCHAR)