diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2018-06-07 17:37:00 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-06-14 16:19:08 +0200 |
commit | fb93a9da22dc9052e8ab8d057283e0cfffb659c4 (patch) | |
tree | 445031af42c1409cabb1e60398188024b99013ab | |
parent | 543fc57787ebccb30a05f795abe6e74c4288e704 (diff) |
sw_redlinehide: use WrongListIterator in text formatting code
Change-Id: Ie13119d456fa6fe3919871cc541a9ad927b5982e
-rw-r--r-- | sw/source/core/inc/drawfont.hxx | 20 | ||||
-rw-r--r-- | sw/source/core/text/frmpaint.cxx | 19 | ||||
-rw-r--r-- | sw/source/core/text/inftxt.cxx | 122 | ||||
-rw-r--r-- | sw/source/core/text/inftxt.hxx | 33 | ||||
-rw-r--r-- | sw/source/core/text/portxt.cxx | 6 | ||||
-rw-r--r-- | sw/source/core/txtnode/fntcache.cxx | 7 |
6 files changed, 121 insertions, 86 deletions
diff --git a/sw/source/core/inc/drawfont.hxx b/sw/source/core/inc/drawfont.hxx index f484e56546c9..8cfa4b720082 100644 --- a/sw/source/core/inc/drawfont.hxx +++ b/sw/source/core/inc/drawfont.hxx @@ -30,7 +30,7 @@ class SwTextFrame; class SwViewShell; class SwScriptInfo; class Point; -class SwWrongList; +namespace sw { class WrongListIterator; } class Size; class SwFont; namespace vcl { @@ -50,9 +50,9 @@ class SW_DLLPUBLIC SwDrawTextInfo Point m_aPos; vcl::TextLayoutCache const* m_pCachedVclData; OUString m_aText; - const SwWrongList* m_pWrong; - const SwWrongList* m_pGrammarCheck; - const SwWrongList* m_pSmartTags; + sw::WrongListIterator* m_pWrong; + sw::WrongListIterator* m_pGrammarCheck; + sw::WrongListIterator* m_pSmartTags; Size m_aSize; SwFont *m_pFnt; SwUnderlineFont* m_pUnderFnt; @@ -220,7 +220,7 @@ public: return m_aText; } - const SwWrongList* GetWrong() const + sw::WrongListIterator* GetWrong() const { #ifdef DBG_UTIL OSL_ENSURE( m_bWrong, "DrawTextInfo: Undefined WrongList" ); @@ -228,7 +228,7 @@ public: return m_pWrong; } - const SwWrongList* GetGrammarCheck() const + sw::WrongListIterator* GetGrammarCheck() const { #ifdef DBG_UTIL OSL_ENSURE( m_bGrammarCheck, "DrawTextInfo: Undefined GrammarCheck List" ); @@ -236,7 +236,7 @@ public: return m_pGrammarCheck; } - const SwWrongList* GetSmartTags() const + sw::WrongListIterator* GetSmartTags() const { return m_pSmartTags; } @@ -418,7 +418,7 @@ public: m_pCachedVclData = nullptr; // would any case benefit from save/restore? } - void SetWrong( const SwWrongList* pNew ) + void SetWrong(sw::WrongListIterator *const pNew) { m_pWrong = pNew; #ifdef DBG_UTIL @@ -426,7 +426,7 @@ public: #endif } - void SetGrammarCheck( const SwWrongList* pNew ) + void SetGrammarCheck(sw::WrongListIterator *const pNew) { m_pGrammarCheck = pNew; #ifdef DBG_UTIL @@ -434,7 +434,7 @@ public: #endif } - void SetSmartTags( const SwWrongList* pNew ) + void SetSmartTags(sw::WrongListIterator *const pNew) { m_pSmartTags = pNew; } diff --git a/sw/source/core/text/frmpaint.cxx b/sw/source/core/text/frmpaint.cxx index 217615337e37..5cbc6dbd38c5 100644 --- a/sw/source/core/text/frmpaint.cxx +++ b/sw/source/core/text/frmpaint.cxx @@ -45,6 +45,7 @@ #include <tabfrm.hxx> #include <numrule.hxx> #include <SwGrammarMarkUp.hxx> +#include <wrong.hxx> #include <EnhancedPDFExportHelper.hxx> @@ -651,9 +652,21 @@ void SwTextFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& SwitchRTLtoLTR( const_cast<SwRect&>(rRect) ); SwTextPaintInfo aInf( const_cast<SwTextFrame*>(this), rRect ); - aInf.SetWrongList( const_cast<SwTextNode*>(GetTextNode())->GetWrong() ); - aInf.SetGrammarCheckList( const_cast<SwTextNode*>(GetTextNode())->GetGrammarCheck() ); - aInf.SetSmartTags( const_cast<SwTextNode*>(GetTextNode())->GetSmartTags() ); + sw::WrongListIterator iterWrong(*this, &SwTextNode::GetWrong); + sw::WrongListIterator iterGrammar(*this, &SwTextNode::GetGrammarCheck); + sw::WrongListIterator iterSmartTags(*this, &SwTextNode::GetSmartTags); + if (iterWrong.LooksUseful()) + { + aInf.SetWrongList( &iterWrong ); + } + if (iterGrammar.LooksUseful()) + { + aInf.SetGrammarCheckList( &iterGrammar ); + } + if (iterSmartTags.LooksUseful()) + { + aInf.SetSmartTags( &iterSmartTags ); + } aInf.GetTextFly().SetTopRule(); SwTextPainter aLine( const_cast<SwTextFrame*>(this), &aInf ); diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx index a0e7c1c06131..9a29d58d0b19 100644 --- a/sw/source/core/text/inftxt.cxx +++ b/sw/source/core/text/inftxt.cxx @@ -487,18 +487,18 @@ void SwTextPaintInfo::CtorInitTextPaintInfo( OutputDevice* pRenderContext, SwTex aPaintRect = rPaint; nSpaceIdx = 0; pSpaceAdd = nullptr; - pWrongList = nullptr; - pGrammarCheckList = nullptr; - pSmartTags = nullptr; + m_pWrongList = nullptr; + m_pGrammarCheckList = nullptr; + m_pSmartTags = nullptr; pBrushItem = nullptr; } SwTextPaintInfo::SwTextPaintInfo( const SwTextPaintInfo &rInf, const OUString* pText ) - : SwTextSizeInfo( rInf, pText ), - pWrongList( rInf.GetpWrongList() ), - pGrammarCheckList( rInf.GetGrammarCheckList() ), - pSmartTags( rInf.GetSmartTags() ), - pSpaceAdd( rInf.GetpSpaceAdd() ), + : SwTextSizeInfo( rInf, pText ) + , m_pWrongList( rInf.GetpWrongList() ) + , m_pGrammarCheckList( rInf.GetGrammarCheckList() ) + , m_pSmartTags( rInf.GetSmartTags() ) + , pSpaceAdd( rInf.GetpSpaceAdd() ), pBrushItem( rInf.GetBrushItem() ), aTextFly( rInf.GetTextFly() ), aPos( rInf.GetPos() ), @@ -507,11 +507,11 @@ SwTextPaintInfo::SwTextPaintInfo( const SwTextPaintInfo &rInf, const OUString* p { } SwTextPaintInfo::SwTextPaintInfo( const SwTextPaintInfo &rInf ) - : SwTextSizeInfo( rInf ), - pWrongList( rInf.GetpWrongList() ), - pGrammarCheckList( rInf.GetGrammarCheckList() ), - pSmartTags( rInf.GetSmartTags() ), - pSpaceAdd( rInf.GetpSpaceAdd() ), + : SwTextSizeInfo( rInf ) + , m_pWrongList( rInf.GetpWrongList() ) + , m_pGrammarCheckList( rInf.GetGrammarCheckList() ) + , m_pSmartTags( rInf.GetSmartTags() ) + , pSpaceAdd( rInf.GetpSpaceAdd() ), pBrushItem( rInf.GetBrushItem() ), aTextFly( rInf.GetTextFly() ), aPos( rInf.GetPos() ), @@ -693,9 +693,9 @@ void SwTextPaintInfo::DrawText_( const OUString &rText, const SwLinePortion &rPo aDrawInf.SetSize( aSize ); aDrawInf.SetAscent( rPor.GetAscent() ); aDrawInf.SetKern( bKern ? rPor.Width() : 0 ); - aDrawInf.SetWrong( bTmpWrong ? pWrongList : nullptr ); - aDrawInf.SetGrammarCheck( bTmpGrammarCheck ? pGrammarCheckList : nullptr ); - aDrawInf.SetSmartTags( bTmpSmart ? pSmartTags : nullptr ); + aDrawInf.SetWrong( bTmpWrong ? m_pWrongList : nullptr ); + aDrawInf.SetGrammarCheck( bTmpGrammarCheck ? m_pGrammarCheckList : nullptr ); + aDrawInf.SetSmartTags( bTmpSmart ? m_pSmartTags : nullptr ); GetTextFly().DrawTextOpaque( aDrawInf ); } else @@ -705,9 +705,9 @@ void SwTextPaintInfo::DrawText_( const OUString &rText, const SwLinePortion &rPo m_pFnt->DrawStretchText_( aDrawInf ); else { - aDrawInf.SetWrong( bTmpWrong ? pWrongList : nullptr ); - aDrawInf.SetGrammarCheck( bTmpGrammarCheck ? pGrammarCheckList : nullptr ); - aDrawInf.SetSmartTags( bTmpSmart ? pSmartTags : nullptr ); + aDrawInf.SetWrong( bTmpWrong ? m_pWrongList : nullptr ); + aDrawInf.SetGrammarCheck( bTmpGrammarCheck ? m_pGrammarCheckList : nullptr ); + aDrawInf.SetSmartTags( bTmpSmart ? m_pSmartTags : nullptr ); m_pFnt->DrawText_( aDrawInf ); } } @@ -1718,9 +1718,8 @@ SwTextSlot::SwTextSlot( bool bExgLists, OUString const & rCh ) : pOldText(nullptr) - , pOldSmartTagList(nullptr) - , pOldGrammarCheckList(nullptr) - , pTempList(nullptr) + , m_pOldSmartTagList(nullptr) + , m_pOldGrammarCheckList(nullptr) , nIdx(0) , nLen(0) , pInf(nullptr) @@ -1751,37 +1750,63 @@ SwTextSlot::SwTextSlot( // ST2 if ( bExgLists ) { - pOldSmartTagList = static_cast<SwTextPaintInfo*>(pInf)->GetSmartTags(); - if ( pOldSmartTagList ) + m_pOldSmartTagList = static_cast<SwTextPaintInfo*>(pInf)->GetSmartTags(); + if (m_pOldSmartTagList) { - const sal_uInt16 nPos = pOldSmartTagList->GetWrongPos(nIdx); - const sal_Int32 nListPos = pOldSmartTagList->Pos(nPos); - if( nListPos == nIdx ) - static_cast<SwTextPaintInfo*>(pInf)->SetSmartTags( pOldSmartTagList->SubList( nPos ) ); - else if( !pTempList && nPos < pOldSmartTagList->Count() && nListPos < nIdx && !aText.isEmpty() ) + std::pair<SwTextNode const*, sal_Int32> pos(pNew->GetTextFrame()->MapViewToModel(nIdx)); + SwWrongList const*const pSmartTags(pos.first->GetSmartTags()); + assert(m_pOldSmartTagList->MergedOrSame(pSmartTags)); + if (pSmartTags) { - pTempList = new SwWrongList( WRONGLIST_SMARTTAG ); - pTempList->Insert( OUString(), nullptr, 0, aText.getLength(), 0 ); - static_cast<SwTextPaintInfo*>(pInf)->SetSmartTags( pTempList ); + const sal_uInt16 nPos = pSmartTags->GetWrongPos(pos.second); + const sal_Int32 nListPos = pSmartTags->Pos(nPos); + if (nListPos == pos.second) + { + m_pTempIter.reset(new sw::WrongListIterator(*pSmartTags->SubList(nPos))); + static_cast<SwTextPaintInfo*>(pInf)->SetSmartTags(m_pTempIter.get()); + } + else if (!m_pTempList && nPos < pSmartTags->Count() + && nListPos < pos.second && !aText.isEmpty()) + { + m_pTempList.reset(new SwWrongList( WRONGLIST_SMARTTAG )); + m_pTempList->Insert( OUString(), nullptr, 0, aText.getLength(), 0 ); + m_pTempIter.reset(new sw::WrongListIterator(*m_pTempList)); + static_cast<SwTextPaintInfo*>(pInf)->SetSmartTags(m_pTempIter.get()); + } + else + static_cast<SwTextPaintInfo*>(pInf)->SetSmartTags(nullptr); } else - static_cast<SwTextPaintInfo*>(pInf)->SetSmartTags( nullptr); + static_cast<SwTextPaintInfo*>(pInf)->SetSmartTags(nullptr); } - pOldGrammarCheckList = static_cast<SwTextPaintInfo*>(pInf)->GetGrammarCheckList(); - if ( pOldGrammarCheckList ) + m_pOldGrammarCheckList = static_cast<SwTextPaintInfo*>(pInf)->GetGrammarCheckList(); + if (m_pOldGrammarCheckList) { - const sal_uInt16 nPos = pOldGrammarCheckList->GetWrongPos(nIdx); - const sal_Int32 nListPos = pOldGrammarCheckList->Pos(nPos); - if( nListPos == nIdx ) - static_cast<SwTextPaintInfo*>(pInf)->SetGrammarCheckList( pOldGrammarCheckList->SubList( nPos ) ); - else if( !pTempList && nPos < pOldGrammarCheckList->Count() && nListPos < nIdx && !aText.isEmpty() ) + std::pair<SwTextNode const*, sal_Int32> pos(pNew->GetTextFrame()->MapViewToModel(nIdx)); + SwWrongList const*const pGrammar(pos.first->GetGrammarCheck()); + assert(m_pOldGrammarCheckList->MergedOrSame(pGrammar)); + if (pGrammar) { - pTempList = new SwWrongList( WRONGLIST_GRAMMAR ); - pTempList->Insert( OUString(), nullptr, 0, aText.getLength(), 0 ); - static_cast<SwTextPaintInfo*>(pInf)->SetGrammarCheckList( pTempList ); + const sal_uInt16 nPos = pGrammar->GetWrongPos(pos.second); + const sal_Int32 nListPos = pGrammar->Pos(nPos); + if (nListPos == pos.second) + { + m_pTempIter.reset(new sw::WrongListIterator(*pGrammar->SubList(nPos))); + static_cast<SwTextPaintInfo*>(pInf)->SetGrammarCheckList(m_pTempIter.get()); + } + else if (!m_pTempList && nPos < pGrammar->Count() + && nListPos < pos.second && !aText.isEmpty()) + { + m_pTempList.reset(new SwWrongList( WRONGLIST_GRAMMAR )); + m_pTempList->Insert( OUString(), nullptr, 0, aText.getLength(), 0 ); + m_pTempIter.reset(new sw::WrongListIterator(*m_pTempList)); + static_cast<SwTextPaintInfo*>(pInf)->SetGrammarCheckList(m_pTempIter.get()); + } + else + static_cast<SwTextPaintInfo*>(pInf)->SetGrammarCheckList(nullptr); } else - static_cast<SwTextPaintInfo*>(pInf)->SetGrammarCheckList( nullptr); + static_cast<SwTextPaintInfo*>(pInf)->SetGrammarCheckList(nullptr); } } } @@ -1798,11 +1823,10 @@ SwTextSlot::~SwTextSlot() // ST2 // Restore old smart tag list - if ( pOldSmartTagList ) - static_cast<SwTextPaintInfo*>(pInf)->SetSmartTags( pOldSmartTagList ); - if ( pOldGrammarCheckList ) - static_cast<SwTextPaintInfo*>(pInf)->SetGrammarCheckList( pOldGrammarCheckList ); - delete pTempList; + if (m_pOldSmartTagList) + static_cast<SwTextPaintInfo*>(pInf)->SetSmartTags(m_pOldSmartTagList); + if (m_pOldGrammarCheckList) + static_cast<SwTextPaintInfo*>(pInf)->SetGrammarCheckList(m_pOldGrammarCheckList); } } diff --git a/sw/source/core/text/inftxt.hxx b/sw/source/core/text/inftxt.hxx index 40bf57ebcebb..1156e1197c14 100644 --- a/sw/source/core/text/inftxt.hxx +++ b/sw/source/core/text/inftxt.hxx @@ -55,7 +55,7 @@ class SwViewShell; class SwAttrIter; struct SwMultiCreator; class SwMultiPortion; -class SwWrongList; +namespace sw { class WrongListIterator; } #define ARROW_WIDTH 200 #define DIR_LEFT2RIGHT 0 @@ -351,9 +351,9 @@ public: class SwTextPaintInfo : public SwTextSizeInfo { - const SwWrongList *pWrongList; - const SwWrongList *pGrammarCheckList; - const SwWrongList *pSmartTags; + sw::WrongListIterator *m_pWrongList; + sw::WrongListIterator *m_pGrammarCheckList; + sw::WrongListIterator *m_pSmartTags; std::vector<long>* pSpaceAdd; const SvxBrushItem *pBrushItem; // For the background SwTextFly aTextFly; // Calculate the FlyFrame @@ -371,9 +371,9 @@ class SwTextPaintInfo : public SwTextSizeInfo protected: SwTextPaintInfo() - : pWrongList(nullptr) - , pGrammarCheckList(nullptr) - , pSmartTags(nullptr) + : m_pWrongList(nullptr) + , m_pGrammarCheckList(nullptr) + , m_pSmartTags(nullptr) , pSpaceAdd(nullptr) , pBrushItem(nullptr) , nSpaceIdx(0) @@ -458,14 +458,14 @@ public: void SetpSpaceAdd( std::vector<long>* pNew ){ pSpaceAdd = pNew; } std::vector<long>* GetpSpaceAdd() const { return pSpaceAdd; } - void SetWrongList( const SwWrongList *pNew ){ pWrongList = pNew; } - const SwWrongList* GetpWrongList() const { return pWrongList; } + void SetWrongList(sw::WrongListIterator *const pNew) { m_pWrongList = pNew; } + sw::WrongListIterator* GetpWrongList() const { return m_pWrongList; } - void SetGrammarCheckList( const SwWrongList *pNew ){ pGrammarCheckList = pNew; } - const SwWrongList* GetGrammarCheckList() const { return pGrammarCheckList; } + void SetGrammarCheckList(sw::WrongListIterator *const pNew) { m_pGrammarCheckList = pNew; } + sw::WrongListIterator* GetGrammarCheckList() const { return m_pGrammarCheckList; } - void SetSmartTags( const SwWrongList *pNew ){ pSmartTags = pNew; } - const SwWrongList* GetSmartTags() const { return pSmartTags; } + void SetSmartTags(sw::WrongListIterator *const pNew) { m_pSmartTags = pNew; } + sw::WrongListIterator* GetSmartTags() const { return m_pSmartTags; } }; class SwTextFormatInfo : public SwTextPaintInfo @@ -683,9 +683,10 @@ class SwTextSlot final OUString aText; std::shared_ptr<vcl::TextLayoutCache> m_pOldCachedVclData; const OUString *pOldText; - const SwWrongList* pOldSmartTagList; - const SwWrongList* pOldGrammarCheckList; - SwWrongList* pTempList; + sw::WrongListIterator * m_pOldSmartTagList; + sw::WrongListIterator * m_pOldGrammarCheckList; + std::unique_ptr<SwWrongList> m_pTempList; + std::unique_ptr<sw::WrongListIterator> m_pTempIter; TextFrameIndex nIdx; TextFrameIndex nLen; bool bOn; diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx index 8256d458357e..69593f8d157c 100644 --- a/sw/source/core/text/portxt.cxx +++ b/sw/source/core/text/portxt.cxx @@ -550,9 +550,9 @@ void SwTextPortion::Paint( const SwTextPaintInfo &rInf ) const if( rInf.OnWin() && pPortion && !pPortion->Width() ) pPortion->PrePaint( rInf, this ); - const SwWrongList *pWrongList = rInf.GetpWrongList(); - const SwWrongList *pGrammarCheckList = rInf.GetGrammarCheckList(); - const SwWrongList *pSmarttags = rInf.GetSmartTags(); + auto const* pWrongList = rInf.GetpWrongList(); + auto const* pGrammarCheckList = rInf.GetGrammarCheckList(); + auto const* pSmarttags = rInf.GetSmartTags(); const bool bWrong = nullptr != pWrongList; const bool bGrammarCheck = nullptr != pGrammarCheckList; diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx index c45b14086a2a..ed1b86f36218 100644 --- a/sw/source/core/txtnode/fntcache.cxx +++ b/sw/source/core/txtnode/fntcache.cxx @@ -644,7 +644,7 @@ typedef std::vector< std::pair< sal_Int32, sal_Int32 > > SwForbidden; static void lcl_DrawLineForWrongListData( SwForbidden &rForbidden, const SwDrawTextInfo &rInf, - const SwWrongList *pWList, + sw::WrongListIterator *pWList, const CalcLinePosData &rCalcLinePosData, const Size &rPrtFontSize ) { @@ -715,10 +715,7 @@ static void lcl_DrawLineForWrongListData( Point aEnd; lcl_calcLinePos( rCalcLinePosData, aStart, aEnd, nNextStart, nNextEnd - nNextStart ); - const sal_uInt16 wrongPos = pWList->GetWrongPos(nNextStart + rInf.GetIdx()); - - const SwWrongArea* wrongArea = pWList->GetElement(wrongPos); - + SwWrongArea const*const wrongArea = pWList->GetWrongElement(nNextStart + rInf.GetIdx()); if (wrongArea != nullptr) { if (WRONGAREA_DASHED == wrongArea->mLineType) |