diff options
author | George Hazan <ghazan@miranda.im> | 2023-02-19 18:20:00 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-02-19 18:20:00 +0300 |
commit | e2d329c3c48ea1bd398a946276ebab61678b3727 (patch) | |
tree | a6f13e8bc6235d34dcc787a6807a1dc213b0865a | |
parent | 5a754e4a418e767ea3355521fd04878197cfe7aa (diff) |
massive code cleaning
-rw-r--r-- | libs/mTextControl/src/FormattedTextDraw.cpp | 133 | ||||
-rw-r--r-- | libs/mTextControl/src/FormattedTextDraw.h | 221 | ||||
-rw-r--r-- | libs/mTextControl/src/ImageDataObjectHlp.cpp | 32 | ||||
-rw-r--r-- | libs/mTextControl/src/fancy_rtf.cpp | 55 | ||||
-rw-r--r-- | libs/mTextControl/src/main.cpp | 2 | ||||
-rw-r--r-- | libs/mTextControl/src/richeditutils.cpp | 44 | ||||
-rw-r--r-- | libs/mTextControl/src/services.cpp | 33 | ||||
-rw-r--r-- | libs/mTextControl/src/textusers.cpp | 2 |
8 files changed, 237 insertions, 285 deletions
diff --git a/libs/mTextControl/src/FormattedTextDraw.cpp b/libs/mTextControl/src/FormattedTextDraw.cpp index c5ca3d4ecc..a789d44cd1 100644 --- a/libs/mTextControl/src/FormattedTextDraw.cpp +++ b/libs/mTextControl/src/FormattedTextDraw.cpp @@ -33,10 +33,10 @@ const IID IID_ITextDocument = { uint32_t CALLBACK EditStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { - COOKIE *pCookie = (COOKIE*)dwCookie; + COOKIE *pCookie = (COOKIE *)dwCookie; if (pCookie->isUnicode) { - if ((pCookie->cbSize - pCookie->cbCount)*sizeof(wchar_t) < (size_t)cb) - *pcb = LONG(pCookie->cbSize - pCookie->cbCount)*sizeof(wchar_t); + if ((pCookie->cbSize - pCookie->cbCount) * sizeof(wchar_t) < (size_t)cb) + *pcb = LONG(pCookie->cbSize - pCookie->cbCount) * sizeof(wchar_t); else *pcb = cb & ~1UL; memcpy(pbBuff, pCookie->unicode + pCookie->cbCount, *pcb); @@ -57,6 +57,47 @@ uint32_t CALLBACK EditStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG c ///////////////////////////////////////////////////////////////////////////// // CFormattedTextDraw +CFormattedTextDraw::CFormattedTextDraw() +{ + HDC hdcScreen; + + hdcScreen = GetDC(nullptr); + nPixelsPerInchX = GetDeviceCaps(hdcScreen, LOGPIXELSX); + nPixelsPerInchY = GetDeviceCaps(hdcScreen, LOGPIXELSY); + ReleaseDC(nullptr, hdcScreen); + + SetRectEmpty(&m_rcClient); + SetRectEmpty(&m_rcViewInset); + + m_pCF = (CHARFORMAT2W *)malloc(sizeof(CHARFORMAT2W)); + + InitDefaultCharFormat(); + InitDefaultParaFormat(); + m_spTextServices = nullptr; + m_spTextDocument = nullptr; + + m_dwPropertyBits = TXTBIT_RICHTEXT | TXTBIT_MULTILINE | TXTBIT_WORDWRAP | TXTBIT_USECURRENTBKG; + m_dwScrollbar = 0; + m_dwMaxLength = INFINITE; + + IUnknown *spUnk; + HRESULT hr = MyCreateTextServices(nullptr, static_cast<ITextHost *>(this), &spUnk); + if (hr == S_OK) { + hr = spUnk->QueryInterface(IID_ITextServices, (void **)&m_spTextServices); + hr = spUnk->QueryInterface(IID_ITextDocument, (void **)&m_spTextDocument); + spUnk->Release(); + } +} + +CFormattedTextDraw::~CFormattedTextDraw() +{ + free(m_pCF); + if (m_spTextServices != nullptr) + m_spTextServices->Release(); + if (m_spTextDocument != nullptr) + m_spTextDocument->Release(); +} + HRESULT CFormattedTextDraw::putRTFTextA(char *newVal) { if (!m_spTextServices) @@ -153,10 +194,10 @@ HRESULT CFormattedTextDraw::putTextW(wchar_t *newVal) return S_OK; } -HRESULT CFormattedTextDraw::Draw(void *hdcDraw, RECT *prc) +HRESULT CFormattedTextDraw::Draw(HDC hdcDraw, RECT *prc) { LOGFONT lf; - GetObject(GetCurrentObject((HDC)hdcDraw, OBJ_FONT), sizeof(lf), &lf); + GetObject(GetCurrentObject(hdcDraw, OBJ_FONT), sizeof(lf), &lf); LRESULT lResult; CHARFORMAT cf; @@ -167,44 +208,40 @@ HRESULT CFormattedTextDraw::Draw(void *hdcDraw, RECT *prc) (lf.lfUnderline ? CFM_UNDERLINE : 0) | (lf.lfStrikeOut ? CFM_STRIKEOUT : 0); cf.dwEffects = CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE; - cf.crTextColor = GetTextColor((HDC)hdcDraw); + cf.crTextColor = GetTextColor(hdcDraw); cf.bCharSet = lf.lfCharSet; - cf.yHeight = 1440 * abs(lf.lfHeight) / GetDeviceCaps((HDC)hdcDraw, LOGPIXELSY); + cf.yHeight = 1440 * abs(lf.lfHeight) / GetDeviceCaps(hdcDraw, LOGPIXELSY); wcsncpy_s(cf.szFaceName, lf.lfFaceName, _TRUNCATE); - m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult); + m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); m_spTextServices->TxDraw( - DVASPECT_CONTENT, // Draw Aspect - 0, // Lindex - nullptr, // Info for drawing optimization - nullptr, // target device information - (HDC)hdcDraw, // Draw device HDC - nullptr, // Target device HDC - (RECTL *)prc, // Bounding client rectangle - nullptr, // Clipping rectangle for metafiles - (RECT *)nullptr, // Update rectangle - nullptr, // Call back function - NULL, // Call back parameter - TXTVIEW_INACTIVE); // What view of the object could be TXTVIEW_ACTIVE - return S_OK; -} + DVASPECT_CONTENT, // Draw Aspect + 0, // Lindex + nullptr, // Info for drawing optimization + nullptr, // target device information + hdcDraw, // Draw device HDC + nullptr, // Target device HDC + (RECTL *)prc, // Bounding client rectangle + nullptr, // Clipping rectangle for metafiles + (RECT *)nullptr, // Update rectangle + nullptr, // Call back function + NULL, // Call back parameter + TXTVIEW_INACTIVE); // What view of the object could be TXTVIEW_ACTIVE -HRESULT CFormattedTextDraw::Create() -{ - return CreateTextServicesObject(); + return S_OK; } -HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *Height) +HRESULT CFormattedTextDraw::get_NaturalSize(HDC hdcDraw, long *Width, long *Height) { if (hdcDraw == 0) return S_FALSE; - int iCaps = GetDeviceCaps((HDC)hdcDraw, LOGPIXELSY); + int iCaps = GetDeviceCaps(hdcDraw, LOGPIXELSY); if (iCaps == 0) return S_FALSE; LOGFONT lf; - GetObject(GetCurrentObject((HDC)hdcDraw, OBJ_FONT), sizeof(lf), &lf); + GetObject(GetCurrentObject(hdcDraw, OBJ_FONT), sizeof(lf), &lf); LRESULT lResult; CHARFORMAT cf; @@ -215,7 +252,7 @@ HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *He (lf.lfUnderline ? CFM_UNDERLINE : 0) | (lf.lfStrikeOut ? CFM_STRIKEOUT : 0); cf.dwEffects = CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE; - cf.crTextColor = GetTextColor((HDC)hdcDraw); + cf.crTextColor = GetTextColor(hdcDraw); cf.bCharSet = lf.lfCharSet; cf.yHeight = 1440 * abs(lf.lfHeight) / iCaps; wcsncpy_s(cf.szFaceName, lf.lfFaceName, _TRUNCATE); @@ -223,14 +260,14 @@ HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *He if (!m_spTextServices) return S_FALSE; - m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, (WPARAM)(SCF_ALL), (LPARAM)&cf, &lResult); + m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); *Height = 1; SIZEL szExtent; szExtent.cx = *Width; szExtent.cy = *Height; - if (m_spTextServices->TxGetNaturalSize(DVASPECT_CONTENT, (HDC)hdcDraw, nullptr, nullptr, TXTNS_FITTOCONTENT, &szExtent, Width, Height) != S_OK) + if (m_spTextServices->TxGetNaturalSize(DVASPECT_CONTENT, hdcDraw, nullptr, nullptr, TXTNS_FITTOCONTENT, &szExtent, Width, Height) != S_OK) return S_FALSE; return S_OK; @@ -241,12 +278,12 @@ HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *He HDC CFormattedTextDraw::TxGetDC() { - return GetDC(nullptr); + return GetDC(m_hwndParent); } INT CFormattedTextDraw::TxReleaseDC(HDC hdc) { - ReleaseDC(nullptr, hdc); + ReleaseDC(m_hwndParent, hdc); return FALSE; } @@ -297,20 +334,16 @@ BOOL CFormattedTextDraw::TxSetTimer(UINT, UINT) } void CFormattedTextDraw::TxKillTimer(UINT) -{ -} +{} void CFormattedTextDraw::TxScrollWindowEx(INT, INT, LPCRECT, LPCRECT, HRGN, LPRECT, UINT) -{ -} +{} void CFormattedTextDraw::TxSetCapture(BOOL) -{ -} +{} void CFormattedTextDraw::TxSetFocus() -{ -} +{} void CFormattedTextDraw::TxSetCursor(HCURSOR hcur, BOOL fText) { @@ -408,13 +441,13 @@ HRESULT CFormattedTextDraw::TxGetExtent(LPSIZEL) return E_NOTIMPL; } -HRESULT CFormattedTextDraw::OnTxCharFormatChange(const CHARFORMATW * pcf) +HRESULT CFormattedTextDraw::OnTxCharFormatChange(const CHARFORMATW *pcf) { memcpy(m_pCF, pcf, pcf->cbSize); return S_OK; } -HRESULT CFormattedTextDraw::OnTxParaFormatChange(const PARAFORMAT * ppf) +HRESULT CFormattedTextDraw::OnTxParaFormatChange(const PARAFORMAT *ppf) { memcpy(&m_PF, ppf, ppf->cbSize); return S_OK; @@ -448,7 +481,7 @@ HRESULT CFormattedTextDraw::TxGetSelectionBarWidth(LONG *lSelBarWidth) ///////////////////////////////////////////////////////////////////////////// // custom functions -HRESULT CFormattedTextDraw::CharFormatFromHFONT(CHARFORMAT2W* pCF, HFONT hFont) +HRESULT CFormattedTextDraw::CharFormatFromHFONT(CHARFORMAT2W *pCF, HFONT hFont) // Takes an HFONT and fills in a CHARFORMAT2W structure with the corresponding info { // Get LOGFONT for default font @@ -511,15 +544,3 @@ HRESULT CFormattedTextDraw::InitDefaultParaFormat() m_PF.rgxTabs[0] = lDefaultTab; return S_OK; } - -HRESULT CFormattedTextDraw::CreateTextServicesObject() -{ - IUnknown *spUnk; - HRESULT hr = MyCreateTextServices(nullptr, static_cast<ITextHost*>(this), &spUnk); - if (hr == S_OK) { - hr = spUnk->QueryInterface(IID_ITextServices, (void**)&m_spTextServices); - hr = spUnk->QueryInterface(IID_ITextDocument, (void**)&m_spTextDocument); - spUnk->Release(); - } - return hr; -} diff --git a/libs/mTextControl/src/FormattedTextDraw.h b/libs/mTextControl/src/FormattedTextDraw.h index 58f22a667b..3e09d49113 100644 --- a/libs/mTextControl/src/FormattedTextDraw.h +++ b/libs/mTextControl/src/FormattedTextDraw.h @@ -23,168 +23,105 @@ struct COOKIE }; ///////////////////////////////////////////////////////////////////////////// -// IFormatttedTextDraw -interface IFormattedTextDraw -{ -public: - virtual ~IFormattedTextDraw() {}; - virtual HRESULT get_NaturalSize(void *hdcDraw, long *Width, long *pVal) PURE; - virtual HRESULT Create() PURE; - virtual HRESULT Draw(void *hdcDraw, RECT *prc) PURE; - virtual HRESULT putRTFTextA(char *newVal) PURE; - virtual HRESULT putRTFTextW(wchar_t *newVal) PURE; - virtual HRESULT putTextA(char *newVal) PURE; - virtual HRESULT putTextW(wchar_t *newVal) PURE; - - virtual ITextServices *getTextService() PURE; - virtual ITextDocument *getTextDocument() PURE; - virtual void setParentWnd(HWND hwnd, RECT rect) PURE; - - // COM-like functions - virtual ULONG STDMETHODCALLTYPE AddRef(void) PURE; - virtual ULONG STDMETHODCALLTYPE Release(void) PURE; -}; - -///////////////////////////////////////////////////////////////////////////// // CFormattedTextDraw -class CFormattedTextDraw : - public ITextHost, - public IFormattedTextDraw + +class CFormattedTextDraw : public ITextHost, public MZeroedObject { -public: - CFormattedTextDraw() - { - HDC hdcScreen; + HWND m_hwndParent; + RECT m_rcClient; // Client Rect + RECT m_rcViewInset; // view rect inset + SIZEL m_sizelExtent; // Extent array - hdcScreen = GetDC(nullptr); - nPixelsPerInchX = GetDeviceCaps(hdcScreen, LOGPIXELSX); - nPixelsPerInchY = GetDeviceCaps(hdcScreen, LOGPIXELSY); - ReleaseDC(nullptr, hdcScreen); + int nPixelsPerInchX; // Pixels per logical inch along width + int nPixelsPerInchY; // Pixels per logical inch along height - SetRectEmpty(&m_rcClient); - SetRectEmpty(&m_rcViewInset); + CHARFORMAT2W *m_pCF; + PARAFORMAT2 m_PF; + uint32_t m_dwScrollbar; // Scroll bar style + uint32_t m_dwPropertyBits; // Property bits + uint32_t m_dwMaxLength; + COOKIE m_editCookie; - m_pCF = (CHARFORMAT2W*)malloc(sizeof(CHARFORMAT2W)); + ITextServices *m_spTextServices; + ITextDocument *m_spTextDocument; - InitDefaultCharFormat(); - InitDefaultParaFormat(); - m_spTextServices = nullptr; - m_spTextDocument = nullptr; +public: + CFormattedTextDraw(); + ~CFormattedTextDraw(); - m_dwPropertyBits = TXTBIT_RICHTEXT | TXTBIT_MULTILINE | TXTBIT_WORDWRAP | TXTBIT_USECURRENTBKG; - m_dwScrollbar = 0; - m_dwMaxLength = INFINITE; - } + HRESULT get_NaturalSize(HDC hdcDraw, long *Width, long *pVal); + HRESULT Draw(HDC hdcDraw, RECT *prc); + HRESULT putRTFTextA(char *newVal); + HRESULT putRTFTextW(wchar_t *newVal); + HRESULT putTextA(char *newVal); + HRESULT putTextW(wchar_t *newVal); - ~CFormattedTextDraw() - { - free(m_pCF); - if (m_spTextServices != nullptr) - m_spTextServices->Release(); - if (m_spTextDocument != nullptr) - m_spTextDocument->Release(); - } + __forceinline ITextServices *getTextService() { return m_spTextServices; }; + __forceinline ITextDocument *getTextDocument() { return m_spTextDocument; }; - // Minimal COM functionality - HRESULT STDMETHODCALLTYPE QueryInterface( - /* [in] */ REFIID, - /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject) - { - *ppvObject = nullptr; + __forceinline void setParentWnd(HWND hwnd, RECT rect) { m_hwndParent = hwnd; m_rcClient = rect; } + + // IUnknown + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void __RPC_FAR *__RPC_FAR *ppvObject) override + { *ppvObject = nullptr; return S_FALSE; } - ULONG STDMETHODCALLTYPE AddRef(void) - { - return 0; + ULONG STDMETHODCALLTYPE AddRef(void) override + { return 0; } - ULONG STDMETHODCALLTYPE Release(void) - { - return 0; + ULONG STDMETHODCALLTYPE Release(void) override + { return 0; } - // IFormattedTextDraw -public: - HRESULT get_NaturalSize(void *hdcDraw, long *Width, long *pVal); - HRESULT Create(); - HRESULT Draw(void *hdcDraw, RECT *prc); - HRESULT putRTFTextA(char *newVal); - HRESULT putRTFTextW(wchar_t *newVal); - HRESULT putTextA(char *newVal); - HRESULT putTextW(wchar_t *newVal); - - ITextServices *getTextService() { return m_spTextServices; }; - ITextDocument *getTextDocument() { return m_spTextDocument; }; - virtual void setParentWnd(HWND hwnd, RECT rect) { m_hwndParent = hwnd; m_rcClient = rect; } - // ITextHost - HDC TxGetDC(); - INT TxReleaseDC(HDC hdc); - BOOL TxShowScrollBar(INT fnBar, BOOL fShow); - BOOL TxEnableScrollBar(INT fuSBFlags, INT fuArrowflags); - BOOL TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw); - BOOL TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw); - void TxInvalidateRect(LPCRECT prc, BOOL fMode); - void TxViewChange(BOOL fUpdate); - BOOL TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight); - BOOL TxShowCaret(BOOL fShow); - BOOL TxSetCaretPos(INT x, INT y); - BOOL TxSetTimer(UINT idTimer, UINT uTimeout); - void TxKillTimer(UINT idTimer); - void TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll); - void TxSetCapture(BOOL fCapture); - void TxSetFocus(); - void TxSetCursor(HCURSOR hcur, BOOL fText); - BOOL TxScreenToClient(LPPOINT lppt); - BOOL TxClientToScreen(LPPOINT lppt); - HRESULT TxActivate(LONG * plOldState); - HRESULT TxDeactivate(LONG lNewState); - HRESULT TxGetClientRect(LPRECT prc); - HRESULT TxGetViewInset(LPRECT prc); - HRESULT TxGetCharFormat(const CHARFORMATW **ppCF); - HRESULT TxGetParaFormat(const PARAFORMAT **ppPF); - COLORREF TxGetSysColor(int nIndex); - HRESULT TxGetBackStyle(TXTBACKSTYLE *pstyle); - HRESULT TxGetMaxLength(DWORD *plength); - HRESULT TxGetScrollBars(DWORD *pdwScrollBar); - HRESULT TxGetPasswordChar(wchar_t *pch); - HRESULT TxGetAcceleratorPos(LONG *pcp); - HRESULT TxGetExtent(LPSIZEL lpExtent); - HRESULT OnTxCharFormatChange(const CHARFORMATW * pcf); - HRESULT OnTxParaFormatChange(const PARAFORMAT * ppf); - HRESULT TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits); - HRESULT TxNotify(DWORD iNotify, void *pv); - HIMC TxImmGetContext(); - void TxImmReleaseContext(HIMC himc); - HRESULT TxGetSelectionBarWidth(LONG *lSelBarWidth); + HDC TxGetDC() override; + INT TxReleaseDC(HDC hdc) override; + BOOL TxShowScrollBar(INT fnBar, BOOL fShow) override; + BOOL TxEnableScrollBar(INT fuSBFlags, INT fuArrowflags) override; + BOOL TxSetScrollRange(INT fnBar, LONG nMinPos, INT nMaxPos, BOOL fRedraw) override; + BOOL TxSetScrollPos(INT fnBar, INT nPos, BOOL fRedraw) override; + void TxInvalidateRect(LPCRECT prc, BOOL fMode) override; + void TxViewChange(BOOL fUpdate) override; + BOOL TxCreateCaret(HBITMAP hbmp, INT xWidth, INT yHeight) override; + BOOL TxShowCaret(BOOL fShow) override; + BOOL TxSetCaretPos(INT x, INT y) override; + BOOL TxSetTimer(UINT idTimer, UINT uTimeout) override; + void TxKillTimer(UINT idTimer) override; + void TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll) override; + void TxSetCapture(BOOL fCapture) override; + void TxSetFocus() override; + void TxSetCursor(HCURSOR hcur, BOOL fText) override; + BOOL TxScreenToClient(LPPOINT lppt) override; + BOOL TxClientToScreen(LPPOINT lppt) override; + HRESULT TxActivate(LONG * plOldState) override; + HRESULT TxDeactivate(LONG lNewState) override; + HRESULT TxGetClientRect(LPRECT prc) override; + HRESULT TxGetViewInset(LPRECT prc) override; + HRESULT TxGetCharFormat(const CHARFORMATW **ppCF) override; + HRESULT TxGetParaFormat(const PARAFORMAT **ppPF) override; + COLORREF TxGetSysColor(int nIndex) override; + HRESULT TxGetBackStyle(TXTBACKSTYLE *pstyle) override; + HRESULT TxGetMaxLength(DWORD *plength) override; + HRESULT TxGetScrollBars(DWORD *pdwScrollBar) override; + HRESULT TxGetPasswordChar(wchar_t *pch) override; + HRESULT TxGetAcceleratorPos(LONG *pcp) override; + HRESULT TxGetExtent(LPSIZEL lpExtent) override; + HRESULT OnTxCharFormatChange(const CHARFORMATW * pcf) override; + HRESULT OnTxParaFormatChange(const PARAFORMAT * ppf) override; + HRESULT TxGetPropertyBits(DWORD dwMask, DWORD *pdwBits) override; + HRESULT TxNotify(DWORD iNotify, void *pv) override; + HIMC TxImmGetContext() override; + void TxImmReleaseContext(HIMC himc) override; + HRESULT TxGetSelectionBarWidth(LONG *lSelBarWidth) override; // Custom functions - HRESULT CharFormatFromHFONT(CHARFORMAT2W* pCF, HFONT hFont); - HRESULT InitDefaultCharFormat(); - HRESULT InitDefaultParaFormat(); - HRESULT CreateTextServicesObject(); - - // Variables - HWND m_hwndParent; - RECT m_rcClient; // Client Rect - RECT m_rcViewInset; // view rect inset - SIZEL m_sizelExtent; // Extent array - - int nPixelsPerInchX; // Pixels per logical inch along width - int nPixelsPerInchY; // Pixels per logical inch along height - - CHARFORMAT2W *m_pCF; - PARAFORMAT2 m_PF; - 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; + HRESULT CharFormatFromHFONT(CHARFORMAT2W* pCF, HFONT hFont); + HRESULT InitDefaultCharFormat(); + HRESULT InitDefaultParaFormat(); }; -void bbCodeParse(IFormattedTextDraw *ts); +void bbCodeParse(CFormattedTextDraw *ts); #endif //__FORMATTEDTEXTDRAW_H_ diff --git a/libs/mTextControl/src/ImageDataObjectHlp.cpp b/libs/mTextControl/src/ImageDataObjectHlp.cpp index 358ce0b1ef..71f5824d82 100644 --- a/libs/mTextControl/src/ImageDataObjectHlp.cpp +++ b/libs/mTextControl/src/ImageDataObjectHlp.cpp @@ -35,8 +35,7 @@ mir_cs csEmfCache; void UnloadEmfCache() { - while (emfCache) - { + while (emfCache) { EMFCACHE *tmp = emfCache->next; delete emfCache; emfCache = tmp; @@ -48,10 +47,8 @@ HENHMETAFILE CacheIconToEmf(HICON hIcon) HENHMETAFILE result = nullptr; mir_cslock lck(csEmfCache); for (EMFCACHE *p = emfCache; p; p = p->next) - if (p->hIcon == hIcon) - { - if (p->prev) - { + if (p->hIcon == hIcon) { + if (p->prev) { p->prev->next = p->next; if (p->next) p->next->prev = p->prev; p->prev = nullptr; @@ -64,8 +61,7 @@ HENHMETAFILE CacheIconToEmf(HICON hIcon) } // cache new item - if (!result) - { + if (!result) { EMFCACHE *newItem = new EMFCACHE; newItem->prev = nullptr; newItem->next = emfCache; @@ -81,15 +77,13 @@ HENHMETAFILE CacheIconToEmf(HICON hIcon) } // tail cutoff - if (emfCacheSize > 20) - { + if (emfCacheSize > 20) { int n = 0; EMFCACHE *p; for (p = emfCache; p; p = p->next) if (++n > 20) break; - while (p->next) - { + while (p->next) { EMFCACHE *tmp = p->next; p->next = p->next->next; delete tmp; @@ -105,7 +99,7 @@ HRESULT CreateDataObject(const FORMATETC *fmtetc, const STGMEDIUM *stgmed, UINT // returns true on success, false on failure //bool InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap, HGLOBAL hGlobal) -bool InsertBitmap(IRichEditOle* pRichEditOle, HENHMETAFILE hEmf) +bool InsertBitmap(IRichEditOle *pRichEditOle, HENHMETAFILE hEmf) { SCODE sc; @@ -137,8 +131,7 @@ bool InsertBitmap(IRichEditOle* pRichEditOle, HENHMETAFILE hEmf) // LPLOCKBYTES lpLockBytes = nullptr; sc = CreateILockBytesOnHGlobal(nullptr, TRUE, &lpLockBytes); - if (sc != S_OK) - { + if (sc != S_OK) { pOleClientSite->Release(); return false; } @@ -146,8 +139,7 @@ bool InsertBitmap(IRichEditOle* pRichEditOle, HENHMETAFILE hEmf) IStorage *pStorage; sc = StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage); - if (sc != S_OK) - { + if (sc != S_OK) { lpLockBytes->Release(); pOleClientSite->Release(); pods->Release(); @@ -159,8 +151,7 @@ bool InsertBitmap(IRichEditOle* pRichEditOle, HENHMETAFILE hEmf) IOleObject *pOleObject; sc = OleCreateStaticFromData(pods, IID_IOleObject, OLERENDER_FORMAT, (LPFORMATETC)lc_format, pOleClientSite, pStorage, (void **)&pOleObject); - if (sc != S_OK) - { + if (sc != S_OK) { pStorage->Release(); lpLockBytes->Release(); pOleClientSite->Release(); @@ -184,8 +175,7 @@ bool InsertBitmap(IRichEditOle* pRichEditOle, HENHMETAFILE hEmf) reobject.dwFlags = REO_BELOWBASELINE; sc = pOleObject->GetUserClassID(&reobject.clsid); - if (sc != S_OK) - { + if (sc != S_OK) { pOleObject->Release(); pStorage->Release(); lpLockBytes->Release(); diff --git a/libs/mTextControl/src/fancy_rtf.cpp b/libs/mTextControl/src/fancy_rtf.cpp index 29c62c0ba5..18e1232120 100644 --- a/libs/mTextControl/src/fancy_rtf.cpp +++ b/libs/mTextControl/src/fancy_rtf.cpp @@ -6,17 +6,18 @@ struct BBCodeInfo { wchar_t *start; wchar_t *end; - bool(*func)(IFormattedTextDraw *ftd, CHARRANGE range, wchar_t *txt, uint32_t cookie); + bool (*func)(CFormattedTextDraw *ftd, CHARRANGE range, wchar_t *txt, uint32_t cookie); uint32_t cookie; }; -enum { +enum +{ BBS_BOLD_S, BBS_BOLD_E, BBS_ITALIC_S, BBS_ITALIC_E, BBS_UNDERLINE_S, BBS_UNDERLINE_E, BBS_STRIKEOUT_S, BBS_STRIKEOUT_E, BBS_COLOR_S, BBS_COLOR_E, BBS_URL1, BBS_URL2, BBS_IMG1, BBS_IMG2 }; -static bool bbCodeSimpleFunc(IFormattedTextDraw *ftd, CHARRANGE range, wchar_t *pwszText, uint32_t cookie) +static bool bbCodeSimpleFunc(CFormattedTextDraw *ftd, CHARRANGE range, wchar_t *pwszText, uint32_t cookie) { wchar_t *pwszStr = L""; CHARFORMAT cf = { 0 }; @@ -75,7 +76,7 @@ static bool bbCodeSimpleFunc(IFormattedTextDraw *ftd, CHARRANGE range, wchar_t * return true; } -static bool bbCodeImageFunc(IFormattedTextDraw *ftd, CHARRANGE range, wchar_t *txt, uint32_t) +static bool bbCodeImageFunc(CFormattedTextDraw *ftd, CHARRANGE range, wchar_t *txt, uint32_t) { ITextServices *ts = ftd->getTextService(); ITextDocument *td = ftd->getTextDocument(); @@ -83,15 +84,15 @@ static bool bbCodeImageFunc(IFormattedTextDraw *ftd, CHARRANGE range, wchar_t *t long cnt; LRESULT lResult; ts->TxSendMessage(EM_SETSEL, range.cpMin, range.cpMax, &lResult); - IRichEditOle* RichEditOle; + IRichEditOle *RichEditOle; ts->TxSendMessage(EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle, &lResult); td->Freeze(&cnt); -#ifdef _WIN64 + #ifdef _WIN64 bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_wtoi64(txt))); -#else + #else bool res = InsertBitmap(RichEditOle, CacheIconToEmf((HICON)_wtoi(txt))); -#endif + #endif td->Unfreeze(&cnt); RichEditOle->Release(); @@ -100,27 +101,27 @@ static bool bbCodeImageFunc(IFormattedTextDraw *ftd, CHARRANGE range, wchar_t *t static BBCodeInfo bbCodes[] = { - { L"[b]", nullptr, bbCodeSimpleFunc, BBS_BOLD_S }, - { L"[/b]", nullptr, bbCodeSimpleFunc, BBS_BOLD_E }, - { L"[i]", nullptr, bbCodeSimpleFunc, BBS_ITALIC_S }, - { L"[/i]", nullptr, bbCodeSimpleFunc, BBS_ITALIC_E }, - { L"[u]", nullptr, bbCodeSimpleFunc, BBS_UNDERLINE_S }, - { L"[/u]", nullptr, bbCodeSimpleFunc, BBS_UNDERLINE_E }, - { L"[s]", nullptr, bbCodeSimpleFunc, BBS_STRIKEOUT_S }, - { L"[/s]", nullptr, bbCodeSimpleFunc, BBS_STRIKEOUT_E }, - - { L"[color=", L"]", bbCodeSimpleFunc, BBS_COLOR_S }, - { L"[/color]", 0, bbCodeSimpleFunc, BBS_COLOR_E }, - - { L"[$hicon=", L"$]", bbCodeImageFunc, 0 }, - - { L"[url]", L"[/url]", bbCodeSimpleFunc, BBS_URL1 }, - { L"[url=", L"]", bbCodeSimpleFunc, BBS_URL2 }, - { L"[url]", L"[/url]", bbCodeSimpleFunc, BBS_IMG1 }, - { L"[url=", L"]", bbCodeSimpleFunc, BBS_IMG2 }, + { L"[b]", nullptr, bbCodeSimpleFunc, BBS_BOLD_S }, + { L"[/b]", nullptr, bbCodeSimpleFunc, BBS_BOLD_E }, + { L"[i]", nullptr, bbCodeSimpleFunc, BBS_ITALIC_S }, + { L"[/i]", nullptr, bbCodeSimpleFunc, BBS_ITALIC_E }, + { L"[u]", nullptr, bbCodeSimpleFunc, BBS_UNDERLINE_S }, + { L"[/u]", nullptr, bbCodeSimpleFunc, BBS_UNDERLINE_E }, + { L"[s]", nullptr, bbCodeSimpleFunc, BBS_STRIKEOUT_S }, + { L"[/s]", nullptr, bbCodeSimpleFunc, BBS_STRIKEOUT_E }, + + { L"[color=", L"]", bbCodeSimpleFunc, BBS_COLOR_S }, + { L"[/color]", 0, bbCodeSimpleFunc, BBS_COLOR_E }, + + { L"[$hicon=", L"$]", bbCodeImageFunc, 0 }, + + { L"[url]", L"[/url]", bbCodeSimpleFunc, BBS_URL1 }, + { L"[url=", L"]", bbCodeSimpleFunc, BBS_URL2 }, + { L"[url]", L"[/url]", bbCodeSimpleFunc, BBS_IMG1 }, + { L"[url=", L"]", bbCodeSimpleFunc, BBS_IMG2 }, }; -void bbCodeParse(IFormattedTextDraw *ftd) +void bbCodeParse(CFormattedTextDraw *ftd) { ITextServices *ts = ftd->getTextService(); LRESULT lResult; diff --git a/libs/mTextControl/src/main.cpp b/libs/mTextControl/src/main.cpp index 64438a39b1..795ab424a8 100644 --- a/libs/mTextControl/src/main.cpp +++ b/libs/mTextControl/src/main.cpp @@ -59,6 +59,6 @@ BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD ul_reason_for_call, LPVOID) FreeLibrary(hMsfteditDll); break; } - + return TRUE; } diff --git a/libs/mTextControl/src/richeditutils.cpp b/libs/mTextControl/src/richeditutils.cpp index 310b19c67f..31ac38a35b 100644 --- a/libs/mTextControl/src/richeditutils.cpp +++ b/libs/mTextControl/src/richeditutils.cpp @@ -10,67 +10,67 @@ private: public: CREOleCallback() {} - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID * ppvObj) + STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj) override { if (IsEqualIID(riid, IID_IRichEditOleCallback)) { *ppvObj = this; - this->AddRef(); + AddRef(); return S_OK; } *ppvObj = nullptr; return E_NOINTERFACE; } - ULONG STDMETHODCALLTYPE AddRef() + ULONG STDMETHODCALLTYPE AddRef() override { - if (this->refCount == 0) { + if (refCount == 0) { if (S_OK != StgCreateDocfile(nullptr, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_DELETEONRELEASE, 0, &this->pictStg)) - this->pictStg = nullptr; - this->nextStgId = 0; + pictStg = nullptr; + nextStgId = 0; } - return ++this->refCount; + return ++refCount; } - ULONG STDMETHODCALLTYPE Release() + ULONG STDMETHODCALLTYPE Release() override { - if (--this->refCount == 0) { - if (this->pictStg) - this->pictStg->Release(); + if (--refCount == 0) { + if (pictStg) + pictStg->Release(); } - return this->refCount; + return refCount; } - HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL) + STDMETHODIMP ContextSensitiveHelp(BOOL) override { return S_OK; } - HRESULT STDMETHODCALLTYPE DeleteObject(LPOLEOBJECT) + STDMETHODIMP DeleteObject(LPOLEOBJECT) override { return S_OK; } - HRESULT STDMETHODCALLTYPE GetClipboardData(CHARRANGE *, DWORD, LPDATAOBJECT *) + STDMETHODIMP GetClipboardData(CHARRANGE *, DWORD, LPDATAOBJECT *) override { return E_NOTIMPL; } - HRESULT STDMETHODCALLTYPE GetContextMenu(uint16_t, LPOLEOBJECT, CHARRANGE *, HMENU *) + STDMETHODIMP GetContextMenu(uint16_t, LPOLEOBJECT, CHARRANGE *, HMENU *) override { return E_INVALIDARG; } - HRESULT STDMETHODCALLTYPE GetDragDropEffect(BOOL, DWORD, LPDWORD) + STDMETHODIMP GetDragDropEffect(BOOL, DWORD, LPDWORD) override { return S_OK; } - HRESULT STDMETHODCALLTYPE GetInPlaceContext(LPOLEINPLACEFRAME *, LPOLEINPLACEUIWINDOW *, LPOLEINPLACEFRAMEINFO) + STDMETHODIMP GetInPlaceContext(LPOLEINPLACEFRAME *, LPOLEINPLACEUIWINDOW *, LPOLEINPLACEFRAMEINFO) override { return E_INVALIDARG; } - HRESULT STDMETHODCALLTYPE GetNewStorage(LPSTORAGE * lplpstg) + STDMETHODIMP GetNewStorage(LPSTORAGE *lplpstg) override { wchar_t sztName[64]; mir_snwprintf(sztName, L"s%u", this->nextStgId); @@ -81,17 +81,17 @@ public: } - HRESULT STDMETHODCALLTYPE QueryAcceptData(LPDATAOBJECT, CLIPFORMAT *, DWORD, BOOL, HGLOBAL) + STDMETHODIMP QueryAcceptData(LPDATAOBJECT, CLIPFORMAT *, DWORD, BOOL, HGLOBAL) override { return S_OK; } - HRESULT STDMETHODCALLTYPE QueryInsertObject(LPCLSID, LPSTORAGE, LONG) + STDMETHODIMP QueryInsertObject(LPCLSID, LPSTORAGE, LONG) override { return S_OK; } - HRESULT STDMETHODCALLTYPE ShowContainerUI(BOOL) + STDMETHODIMP ShowContainerUI(BOOL) override { return S_OK; } diff --git a/libs/mTextControl/src/services.cpp b/libs/mTextControl/src/services.cpp index b5529797c2..397c6b37e5 100644 --- a/libs/mTextControl/src/services.cpp +++ b/libs/mTextControl/src/services.cpp @@ -22,17 +22,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA struct TextObject { - uint32_t options; - const char *szProto; - IFormattedTextDraw *ftd; - TextObject() : options(0), ftd(nullptr) {} - ~TextObject() { if (ftd) delete ftd; } + uint32_t options = 0; + const char *szProto = nullptr; + CFormattedTextDraw *ftd = nullptr; + + TextObject() {} + + ~TextObject() + { + delete ftd; + } }; ///////////////////////////////////////////////////////////////////////////////////////// -// elper functions +// Helper functions -void MText_InitFormatting0(IFormattedTextDraw *ftd, uint32_t) +void MText_InitFormatting0(CFormattedTextDraw *ftd, uint32_t) { // urls LRESULT lResult; @@ -61,17 +66,16 @@ void MText_InitFormatting1(TextObject *text) ///////////////////////////////////////////////////////////////////////////////////////// // allocate text object (unicode) -MTEXTCONTROL_DLL(TextObject*) MTextCreateW(HANDLE userHandle, const char *szProto, const wchar_t *text) +MTEXTCONTROL_DLL(TextObject *) MTextCreateW(HANDLE userHandle, const char *szProto, const wchar_t *text) { TextObject *result = new TextObject; result->szProto = szProto; result->options = TextUserGetOptions(userHandle); - result->ftd = new CFormattedTextDraw; - result->ftd->Create(); + result->ftd = new CFormattedTextDraw(); InitRichEdit(result->ftd->getTextService()); MText_InitFormatting0(result->ftd, result->options); - result->ftd->putTextW((wchar_t*)text); + result->ftd->putTextW((wchar_t *)text); MText_InitFormatting1(result); return result; @@ -80,12 +84,11 @@ MTEXTCONTROL_DLL(TextObject*) MTextCreateW(HANDLE userHandle, const char *szProt ///////////////////////////////////////////////////////////////////////////////////////// // allocate text object (advanced) -MTEXTCONTROL_DLL(TextObject*) MTextCreateEx(HANDLE userHandle, void *text, uint32_t flags) +MTEXTCONTROL_DLL(TextObject *) MTextCreateEx(HANDLE userHandle, void *text, uint32_t flags) { TextObject *result = new TextObject; result->options = TextUserGetOptions(userHandle); - result->ftd = new CFormattedTextDraw; - result->ftd->Create(); + result->ftd = new CFormattedTextDraw(); InitRichEdit(result->ftd->getTextService()); MText_InitFormatting0(result->ftd, result->options); @@ -105,7 +108,7 @@ MTEXTCONTROL_DLL(TextObject*) MTextCreateEx(HANDLE userHandle, void *text, uint3 MTEXTCONTROL_DLL(int) MTextMeasure(HDC dc, SIZE *sz, TextObject *text) { if (!text) return 0; - + long lWidth = sz->cx, lHeight = sz->cy; text->ftd->get_NaturalSize(dc, &lWidth, &lHeight); sz->cx = lWidth; diff --git a/libs/mTextControl/src/textusers.cpp b/libs/mTextControl/src/textusers.cpp index 2ea5569b8a..aa276183ac 100644 --- a/libs/mTextControl/src/textusers.cpp +++ b/libs/mTextControl/src/textusers.cpp @@ -64,7 +64,7 @@ void TextUsersSave() void TextUsersReset() { for (TextUser *textUser = textUserFirst; textUser; textUser = textUser->next) - textUser->options = (db_get_dw(0, MODULENAME, textUser->name, 0) & MTEXT_FANCY_MASK) | (textUser->options&MTEXT_SYSTEM_MASK); + textUser->options = (db_get_dw(0, MODULENAME, textUser->name, 0) & MTEXT_FANCY_MASK) | (textUser->options & MTEXT_SYSTEM_MASK); } ///////////////////////////////////////////////////////////////////////////////////////// |