summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-08-10 17:08:54 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-08-10 17:08:54 +0300
commitc6cfee9f2c096278dae31d241cc814d10fee806e (patch)
treeab1e3a996418d1c99e6b86bf1cbf41524645b02a
parent3187428bb2f7b929e31ebf64b1e21d9c0fbc4f2b (diff)
code cleaning
-rw-r--r--libs/mTextControl/src/FormattedTextDraw.cpp66
-rw-r--r--libs/mTextControl/src/FormattedTextDraw.h12
2 files changed, 38 insertions, 40 deletions
diff --git a/libs/mTextControl/src/FormattedTextDraw.cpp b/libs/mTextControl/src/FormattedTextDraw.cpp
index 2d15b6d02f..f18833bd25 100644
--- a/libs/mTextControl/src/FormattedTextDraw.cpp
+++ b/libs/mTextControl/src/FormattedTextDraw.cpp
@@ -24,9 +24,20 @@ const IID IID_ITextDocument = {
/////////////////////////////////////////////////////////////////////////////
// CallBack functions
+struct STREAMDATA
+{
+ bool isUnicode;
+ union
+ {
+ char *ansi;
+ wchar_t *unicode;
+ };
+ size_t cbSize, cbCount;
+};
+
static DWORD CALLBACK EditStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
- COOKIE *pCookie = (COOKIE *)dwCookie;
+ STREAMDATA *pCookie = (STREAMDATA *)dwCookie;
if (pCookie->isUnicode) {
if ((pCookie->cbSize - pCookie->cbCount) * sizeof(wchar_t) < (size_t)cb)
*pcb = LONG(pCookie->cbSize - pCookie->cbCount) * sizeof(wchar_t);
@@ -96,18 +107,18 @@ HRESULT CFormattedTextDraw::putRTFTextA(char *newVal)
if (!m_spTextServices)
return S_FALSE;
- m_editCookie.isUnicode = false;
- m_editCookie.ansi = newVal;
- m_editCookie.cbSize = mir_strlen(m_editCookie.ansi);
- m_editCookie.cbCount = 0;
+ STREAMDATA streamData = {};
+ streamData.isUnicode = false;
+ streamData.ansi = newVal;
+ streamData.cbSize = mir_strlen(newVal);
EDITSTREAM editStream;
- editStream.dwCookie = (DWORD_PTR)&m_editCookie;
+ editStream.dwCookie = (DWORD_PTR)&streamData;
editStream.dwError = 0;
editStream.pfnCallback = (EDITSTREAMCALLBACK)EditStreamInCallback;
LRESULT lResult = 0;
- m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_RTF), (LPARAM)&editStream, &lResult);
+ m_spTextServices->TxSendMessage(EM_STREAMIN, SF_RTF, (LPARAM)&editStream, &lResult);
return S_OK;
}
@@ -116,20 +127,19 @@ HRESULT CFormattedTextDraw::putRTFTextW(wchar_t *newVal)
if (!m_spTextServices)
return S_FALSE;
- m_editCookie.isUnicode = true;
- m_editCookie.unicode = newVal;
- m_editCookie.cbSize = mir_wstrlen(m_editCookie.unicode);
- m_editCookie.cbCount = 0;
+ STREAMDATA streamData = {};
+ streamData.isUnicode = true;
+ streamData.unicode = newVal;
+ streamData.cbSize = mir_wstrlen(newVal);
EDITSTREAM editStream;
- editStream.dwCookie = (DWORD_PTR)&m_editCookie;
+ editStream.dwCookie = (DWORD_PTR)&streamData;
editStream.dwError = 0;
editStream.pfnCallback = (EDITSTREAMCALLBACK)EditStreamInCallback;
LRESULT lResult = 0;
- m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_RTF | SF_UNICODE), (LPARAM)&editStream, &lResult);
+ m_spTextServices->TxSendMessage(EM_STREAMIN, SF_RTF | SF_UNICODE, (LPARAM)&editStream, &lResult);
return S_OK;
-
}
HRESULT CFormattedTextDraw::putTextA(char *newVal)
@@ -137,25 +147,25 @@ HRESULT CFormattedTextDraw::putTextA(char *newVal)
if (!m_spTextServices)
return S_FALSE;
- m_editCookie.isUnicode = false;
- m_editCookie.ansi = newVal;
- m_editCookie.cbSize = mir_strlen(m_editCookie.ansi);
- m_editCookie.cbCount = 0;
+ STREAMDATA streamData = {};
+ streamData.isUnicode = false;
+ streamData.ansi = newVal;
+ streamData.cbSize = mir_strlen(newVal);
EDITSTREAM editStream;
- editStream.dwCookie = (DWORD_PTR)&m_editCookie;
+ editStream.dwCookie = (DWORD_PTR)&streamData;
editStream.dwError = 0;
editStream.pfnCallback = (EDITSTREAMCALLBACK)EditStreamInCallback;
LRESULT lResult = 0;
- m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_TEXT), (LPARAM)&editStream, &lResult);
+ m_spTextServices->TxSendMessage(EM_STREAMIN, SF_TEXT, (LPARAM)&editStream, &lResult);
CHARFORMAT cf;
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_FACE | CFM_BOLD;
cf.dwEffects = 0;
wcsncpy_s(cf.szFaceName, L"MS Shell Dlg", _TRUNCATE);
- m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
+ m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult);
return S_OK;
}
@@ -165,25 +175,25 @@ HRESULT CFormattedTextDraw::putTextW(wchar_t *newVal)
if (!m_spTextServices)
return S_FALSE;
- m_editCookie.isUnicode = true;
- m_editCookie.unicode = newVal;
- m_editCookie.cbSize = mir_wstrlen(m_editCookie.unicode);
- m_editCookie.cbCount = 0;
+ STREAMDATA streamData = {};
+ streamData.isUnicode = true;
+ streamData.unicode = newVal;
+ streamData.cbSize = mir_wstrlen(newVal);
EDITSTREAM editStream;
- editStream.dwCookie = (DWORD_PTR)&m_editCookie;
+ editStream.dwCookie = (DWORD_PTR)&streamData;
editStream.dwError = 0;
editStream.pfnCallback = (EDITSTREAMCALLBACK)EditStreamInCallback;
LRESULT lResult = 0;
- m_spTextServices->TxSendMessage(EM_STREAMIN, (WPARAM)(SF_TEXT | SF_UNICODE), (LPARAM)&editStream, &lResult);
+ m_spTextServices->TxSendMessage(EM_STREAMIN, SF_TEXT | SF_UNICODE, (LPARAM)&editStream, &lResult);
CHARFORMAT cf;
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_FACE | CFM_BOLD;
cf.dwEffects = 0;
wcsncpy_s(cf.szFaceName, L"MS Shell Dlg", _TRUNCATE);
- m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult);
+ m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult);
return S_OK;
}
diff --git a/libs/mTextControl/src/FormattedTextDraw.h b/libs/mTextControl/src/FormattedTextDraw.h
index 3e09d49113..cd902e2cae 100644
--- a/libs/mTextControl/src/FormattedTextDraw.h
+++ b/libs/mTextControl/src/FormattedTextDraw.h
@@ -11,17 +11,6 @@
#define HOST_BORDER 0
#endif
-struct COOKIE
-{
- bool isUnicode;
- union
- {
- char *ansi;
- wchar_t *unicode;
- };
- size_t cbSize, cbCount;
-};
-
/////////////////////////////////////////////////////////////////////////////
// CFormattedTextDraw
@@ -40,7 +29,6 @@ class CFormattedTextDraw : public ITextHost, public MZeroedObject
uint32_t m_dwScrollbar; // Scroll bar style
uint32_t m_dwPropertyBits; // Property bits
uint32_t m_dwMaxLength;
- COOKIE m_editCookie;
ITextServices *m_spTextServices;
ITextDocument *m_spTextDocument;