diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-08-02 17:01:19 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-08-03 10:55:43 +0100 |
commit | 27c2fe405ca55a2630176a657fb4895c5e31fcea (patch) | |
tree | ac4b00a96e7882647b5cc21c0c133b2ece54d538 /sw/source | |
parent | ab852cc0b6fe6e3a8b398b7fa0313a1425adf31b (diff) |
Related: fdo#46757 extend ModelToViewHelper for more cases
beef up ModelToViewHelper to be able to optionally expand fields, collapse
hidden text and collapse/expand redline deleted text
Change-Id: I6d4d0969102ad9699f7fafe091b2eff6a5707bc4
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/txtnode/ndtxt.cxx | 152 |
1 files changed, 116 insertions, 36 deletions
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 90e9a2b6f26c..22ddb66b2934 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -37,6 +37,7 @@ #include <editeng/tstpitem.hxx> #include <svl/urihelper.hxx> #include <svl/ctloptions.hxx> +#include <tools/multisel.hxx> #include <swmodule.hxx> #include <txtfld.hxx> #include <txtinet.hxx> @@ -3092,52 +3093,131 @@ sal_Bool SwTxtNode::GetExpandTxt( SwTxtNode& rDestNd, const SwIndex* pDestIdx, return sal_True; } -ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode) +struct block +{ + sal_Int32 m_nStart; + sal_Int32 m_nLen; + bool m_bVisible; + std::vector<const SwTxtAttr*> m_aAttrs; + block(sal_Int32 nStart, sal_Int32 nLen, bool bVisible) + : m_nStart(nStart), m_nLen(nLen), m_bVisible(bVisible) + { + } +}; + +struct containsPos +{ + const sal_Int32 m_nPos; + containsPos(const sal_Int32 nPos) + : m_nPos(nPos) + { + } + bool operator() (const block& rIn) const + { + return m_nPos >= rIn.m_nStart && m_nPos < rIn.m_nStart + rIn.m_nLen; + } +}; + +ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, int eMode) { const rtl::OUString& rNodeText = rNode.GetTxt(); m_aRetText = rNodeText; - const SwpHints* pSwpHints2 = rNode.GetpSwpHints(); - xub_StrLen nPos = 0; + if (eMode == PASSTHROUGH) + return; + + Range aRange( 0, rNodeText.isEmpty() ? 0 : rNodeText.getLength() - 1); + MultiSelection aHiddenMulti(aRange); + + if (eMode & HIDEINVISIBLE) + SwScriptInfo::selectHiddenTextProperty(rNode, aHiddenMulti); - for ( sal_uInt16 i = 0; pSwpHints2 && i < pSwpHints2->Count(); ++i ) + if (eMode & HIDEREDLINED) + SwScriptInfo::selectRedLineDeleted(rNode, aHiddenMulti); + + std::vector<block> aBlocks; + + sal_Int32 nShownStart = 0; + for (size_t i = 0; i < aHiddenMulti.GetRangeCount(); ++i) { - const SwTxtAttr* pAttr = (*pSwpHints2)[i]; - bool bReplace = false; - xub_StrLen nFieldPos(STRING_NOTFOUND); - rtl::OUString aExpand; - switch (pAttr->Which()) + const Range& rRange = aHiddenMulti.GetRange(i); + sal_Int32 nHiddenStart = rRange.Min(); + sal_Int32 nHiddenEnd = rRange.Max() + 1; + sal_Int32 nHiddenLen = nHiddenEnd - nHiddenStart; + + sal_Int32 nShownEnd = nHiddenStart; + sal_Int32 nShownLen = nShownEnd - nShownStart; + + if (nShownLen) + aBlocks.push_back(block(nShownStart, nShownLen, true)); + + if (nHiddenLen) + aBlocks.push_back(block(nHiddenStart, nHiddenLen, false)); + + nShownStart = nHiddenEnd; + } + + sal_Int32 nTrailingShownLen = rNodeText.getLength() - nShownStart; + if (nTrailingShownLen) + aBlocks.push_back(block(nShownStart, nTrailingShownLen, true)); + + if (eMode & EXPANDFIELDS) + { + const SwpHints* pSwpHints2 = rNode.GetpSwpHints(); + for ( sal_uInt16 i = 0; pSwpHints2 && i < pSwpHints2->Count(); ++i ) { - case RES_TXTATR_FIELD: - bReplace = true; - aExpand = - static_cast<SwTxtFld const*>(pAttr)->GetFld().GetFld() - ->ExpandField(true); - nFieldPos = *pAttr->GetStart(); - break; - case RES_TXTATR_FTN: - { - bReplace = true; - const SwFmtFtn& rFtn = static_cast<SwTxtFtn const*>(pAttr)->GetFtn(); - const SwDoc *pDoc = rNode.GetDoc(); - aExpand = rFtn.GetViewNumStr(*pDoc); - nFieldPos = *pAttr->GetStart(); - } - break; - default: - if (pAttr->HasDummyChar()) - { - bReplace = true; - nFieldPos = *pAttr->GetStart(); - } - break; + const SwTxtAttr* pAttr = (*pSwpHints2)[i]; + if (pAttr->HasDummyChar()) + { + xub_StrLen nDummyCharPos = *pAttr->GetStart(); + if (aHiddenMulti.IsSelected(nDummyCharPos)) + continue; + std::vector<block>::iterator aFind = std::find_if(aBlocks.begin(), aBlocks.end(), containsPos(nDummyCharPos)); + aFind->m_aAttrs.push_back(pAttr); + } } + } + + sal_Int32 nOffset = 0; + for (std::vector<block>::iterator i = aBlocks.begin(); i != aBlocks.end(); ++i) + { + if (!i->m_bVisible) + { + const sal_Int32 nHiddenStart = i->m_nStart; + const sal_Int32 nHiddenLen = i->m_nLen; - if (bReplace) + m_aRetText = m_aRetText.replaceAt( nOffset + nHiddenStart, nHiddenLen, rtl::OUString() ); + m_aMap.push_back( ConversionMapEntry( nHiddenStart, nOffset + nHiddenStart ) ); + nOffset -= nHiddenLen; + } + else { - m_aRetText = m_aRetText.replaceAt( nPos + nFieldPos, 1, aExpand ); - m_aMap.push_back( ConversionMapEntry( nFieldPos, nPos + nFieldPos ) ); - nPos += ( aExpand.getLength() - 1 ); + for (std::vector<const SwTxtAttr*>::iterator j = i->m_aAttrs.begin(); j != i->m_aAttrs.end(); ++j) + { + const SwTxtAttr* pAttr = *j; + xub_StrLen nFieldPos = *pAttr->GetStart(); + rtl::OUString aExpand; + switch (pAttr->Which()) + { + case RES_TXTATR_FIELD: + aExpand = + static_cast<SwTxtFld const*>(pAttr)->GetFld().GetFld() + ->ExpandField(true); + break; + case RES_TXTATR_FTN: + { + const SwFmtFtn& rFtn = static_cast<SwTxtFtn const*>(pAttr)->GetFtn(); + const SwDoc *pDoc = rNode.GetDoc(); + aExpand = rFtn.GetViewNumStr(*pDoc); + } + break; + default: + break; + } + m_aRetText = m_aRetText.replaceAt( nOffset + nFieldPos, 1, aExpand ); + m_aMap.push_back( ConversionMapEntry( nFieldPos, nOffset + nFieldPos ) ); + nOffset += ( aExpand.getLength() - 1 ); + } } } |