From 86a0571c9eb1c4cfa4136329b9c768704366c7b4 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sun, 25 Jun 2017 22:06:01 +0900 Subject: [PATCH] CCrystalTextView.*: Add CCrystalTextView::GetTextBocks() function. --- Externals/crystaledit/editlib/ccrystaltextview.cpp | 32 ++++++++++++++++++++++ Externals/crystaledit/editlib/ccrystaltextview.h | 18 ++++++------ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Externals/crystaledit/editlib/ccrystaltextview.cpp b/Externals/crystaledit/editlib/ccrystaltextview.cpp index bd6c90e5e..af30cabf5 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview.cpp @@ -1661,6 +1661,38 @@ MergeTextBlocks (TEXTBLOCK *pBuf1, int nBlocks1, TEXTBLOCK *pBuf2, return j; } +std::vector +CCrystalTextView::GetTextBlocks(int nLineIndex) +{ + int nLength = GetViewableLineLength (nLineIndex); + + // Parse the line + DWORD dwCookie = GetParseCookie(nLineIndex - 1); + TEXTBLOCK *pBuf = new TEXTBLOCK[(nLength + 1) * 3]; // be aware of nLength == 0 + int nBlocks = 0; + // insert at least one textblock of normal color at the beginning + pBuf[0].m_nCharPos = 0; + pBuf[0].m_nColorIndex = COLORINDEX_NORMALTEXT; + pBuf[0].m_nBgColorIndex = COLORINDEX_BKGND; + nBlocks++; + (*m_ParseCookies)[nLineIndex] = ParseLine(dwCookie, nLineIndex, pBuf, nBlocks); + ASSERT((*m_ParseCookies)[nLineIndex] != -1); + + TEXTBLOCK *pAddedBuf; + int nAddedBlocks = GetAdditionalTextBlocks(nLineIndex, pAddedBuf); + + TEXTBLOCK *pMergedBuf; + int nMergedBlocks = MergeTextBlocks(pBuf, nBlocks, pAddedBuf, nAddedBlocks, pMergedBuf); + + std::vector blocks(pMergedBuf, pMergedBuf + nMergedBlocks); + + delete[] pMergedBuf; + delete[] pAddedBuf; + delete[] pBuf; + + return blocks; +} + void CCrystalTextView:: DrawSingleLine (CDC * pdc, const CRect & rc, int nLineIndex) { diff --git a/Externals/crystaledit/editlib/ccrystaltextview.h b/Externals/crystaledit/editlib/ccrystaltextview.h index df3cef9a8..cac3236b3 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.h +++ b/Externals/crystaledit/editlib/ccrystaltextview.h @@ -92,6 +92,15 @@ class EDITPADC_CLASS CCrystalTextView : public CView friend CCrystalParser; +public: + // Syntax coloring overrides + struct TEXTBLOCK + { + int m_nCharPos; + int m_nColorIndex; + int m_nBgColorIndex; + }; + protected: // Search parameters bool m_bLastSearch; @@ -558,14 +567,6 @@ protected: void InvalidateScreenRect(bool bInvalidateView = true); //END SW - // Syntax coloring overrides - struct TEXTBLOCK - { - int m_nCharPos; - int m_nColorIndex; - int m_nBgColorIndex; - }; - virtual HINSTANCE GetResourceHandle (); //BEGIN SW @@ -584,6 +585,7 @@ protected: public: virtual CString GetHTMLLine (int nLineIndex, LPCTSTR pszTag); virtual CString GetHTMLStyles (); + std::vector GetTextBlocks(int nLineIndex); protected: virtual CString GetHTMLAttribute (int nColorIndex, int nBgColorIndex, COLORREF crText, COLORREF crBkgnd); -- 2.11.0