diff options
author | Caolán McNamara <caolanm@redhat.com> | 2014-03-27 10:54:53 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-03-28 08:57:47 +0000 |
commit | d0c545bede035f3a4757ac433d919f65d1d06cf0 (patch) | |
tree | 38ec9037b33471f2939459cecb4d6dc6dfa4f5c9 /sw | |
parent | c76b8783e2ada67449fd88390c30943ca7f5a55e (diff) |
Related: fdo#73936 expand FormFieldDropDowns in ModelToViewHelper
when EXPANDFIELDS is set. i.e. for spell and grammar checking
Change-Id: I8c524f0cd584c9d6043dece5c1b736afb254b7c0
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/IDocumentMarkAccess.hxx | 2 | ||||
-rw-r--r-- | sw/inc/IMark.hxx | 2 | ||||
-rw-r--r-- | sw/inc/pam.hxx | 2 | ||||
-rw-r--r-- | sw/qa/core/uwriter.cxx | 23 | ||||
-rw-r--r-- | sw/source/core/doc/docbm.cxx | 22 | ||||
-rw-r--r-- | sw/source/core/inc/MarkManager.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/text/itrform2.cxx | 9 | ||||
-rw-r--r-- | sw/source/core/txtnode/modeltoviewhelper.cxx | 110 |
8 files changed, 135 insertions, 37 deletions
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index 8d59cbf24b8b..3fd37b890129 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -249,6 +249,8 @@ class IDocumentMarkAccess virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& pos) const =0; virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& pos) const =0; + virtual std::vector< ::sw::mark::IFieldmark* > getDropDownsFor(const SwPaM &rPaM) const=0; + // Marks exclusive annotation marks virtual const_iterator_t getCommonMarksBegin() const = 0; virtual const_iterator_t getCommonMarksEnd() const = 0; diff --git a/sw/inc/IMark.hxx b/sw/inc/IMark.hxx index d073085420a1..ba2b0f4fb78f 100644 --- a/sw/inc/IMark.hxx +++ b/sw/inc/IMark.hxx @@ -156,6 +156,8 @@ namespace sw { namespace mark #endif }; + OUString ExpandFieldmark(IFieldmark* pBM); + }} #endif diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx index c2a7f34e8391..957f9673b18f 100644 --- a/sw/inc/pam.hxx +++ b/sw/inc/pam.hxx @@ -290,7 +290,7 @@ public: something protected. */ bool HasReadonlySel( bool bFormView, bool bAnnotationMode = false ) const; - bool ContainsPosition(const SwPosition & rPos) + bool ContainsPosition(const SwPosition & rPos) const { return *Start() <= rPos && rPos <= *End(); } diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index 046158cdca2a..bdbeda3199b3 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -242,6 +242,7 @@ void SwDocTest::testModelToViewHelper() //set character attribute hidden on range SvxCharHiddenItem aHidden(true, RES_CHRATR_HIDDEN); m_pDoc->InsertPoolItem(aPaM, aHidden, 0 ); + aPaM.DeleteMark(); //turn on red-lining and show changes m_pDoc->SetRedlineMode(nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_SHOW_DELETE|nsRedlineMode_t::REDLINE_SHOW_INSERT); @@ -254,6 +255,7 @@ void SwDocTest::testModelToViewHelper() //set end of selection to second last B aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), 9); m_pDoc->DeleteAndJoin(aPaM); //redline-aware deletion api + aPaM.DeleteMark(); { ModelToViewHelper aModelToViewHelper(*pTxtNode, PASSTHROUGH); @@ -307,6 +309,27 @@ void SwDocTest::testModelToViewHelper() OUString sViewText = aModelToViewHelper.getViewText(); CPPUNIT_ASSERT(sViewText == "AAAACCCCC foo DDDDD"); } + + m_pDoc->AppendTxtNode(*aPaM.GetPoint()); + m_pDoc->InsertString(aPaM, OUString("AAAAA")); + IDocumentMarkAccess* pMarksAccess = m_pDoc->getIDocumentMarkAccess(); + sw::mark::IFieldmark *pFieldmark = dynamic_cast<sw::mark::IFieldmark*>( + pMarksAccess->makeNoTextFieldBookmark(aPaM, "test", ODF_FORMDROPDOWN)); + CPPUNIT_ASSERT(pFieldmark); + uno::Sequence< OUString > vListEntries(1); + vListEntries[0] = "BBBBB"; + (*pFieldmark->GetParameters())[ODF_FORMDROPDOWN_LISTENTRY] = uno::makeAny(vListEntries); + (*pFieldmark->GetParameters())[ODF_FORMDROPDOWN_RESULT] = uno::makeAny(sal_Int32(0)); + m_pDoc->InsertString(aPaM, OUString("CCCCC")); + pTxtNode = aPaM.GetNode()->GetTxtNode(); + CPPUNIT_ASSERT(pTxtNode->GetTxt().getLength() == 11); + + { + ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS); + OUString sViewText = aModelToViewHelper.getViewText(); + fprintf(stderr, "string is %s\n", OUStringToOString(sViewText, RTL_TEXTENCODING_UTF8).getStr()); + CPPUNIT_ASSERT(sViewText == "AAAAABBBBBCCCCC"); + } } } diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index d9722362278b..e3f3583002e8 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1013,6 +1013,28 @@ namespace sw { namespace mark return dynamic_cast<IFieldmark*>(pFieldmark->get()); } + std::vector<IFieldmark*> MarkManager::getDropDownsFor(const SwPaM &rPaM) const + { + std::vector<IFieldmark*> aRet; + + for (IDocumentMarkAccess::const_iterator_t aI = m_vFieldmarks.begin(), + aEnd = m_vFieldmarks.end(); aI != aEnd; ++aI) + { + boost::shared_ptr<IMark> xI = *aI; + const SwPosition &rStart = xI->GetMarkPos(); + if (!rPaM.ContainsPosition(rStart)) + continue; + + IFieldmark *pMark = dynamic_cast<IFieldmark*>(xI.get()); + if (!pMark || pMark->GetFieldname() != ODF_FORMDROPDOWN) + continue; + + aRet.push_back(pMark); + } + + return aRet; + } + IFieldmark* MarkManager::getFieldmarkAfter(const SwPosition& rPos) const { return dynamic_cast<IFieldmark*>(lcl_getMarkAfter(m_vFieldmarks, rPos)); } diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index 0d9dc6f0e1cd..890fe7d591fc 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -82,6 +82,8 @@ namespace sw { virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& rPos) const SAL_OVERRIDE; virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& rPos) const SAL_OVERRIDE; + virtual std::vector< ::sw::mark::IFieldmark* > getDropDownsFor(const SwPaM &rPaM) const; + void dumpAsXml(xmlTextWriterPtr w); // Marks exclusive annotation marks diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 5edca1df961f..7926e6d332a5 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -873,9 +873,8 @@ void SwMetaPortion::Paint( const SwTxtPaintInfo &rInf ) const } } -namespace { - using namespace sw::mark; - static OUString getCurrentListIndex(IFieldmark* pBM) +namespace sw { namespace mark { + OUString ExpandFieldmark(IFieldmark* pBM) { const IFieldmark::parameter_map_t* const pParameters = pBM->GetParameters(); sal_Int32 nCurrentIdx = 0; @@ -893,7 +892,7 @@ namespace { } return OUString(); } -} +} } /************************************************************************* * SwTxtFormatter::WhichTxtPor() @@ -944,7 +943,7 @@ SwTxtPortion *SwTxtFormatter::WhichTxtPor( SwTxtFormatInfo &rInf ) const } else if (pBM->GetFieldname( ) == ODF_FORMDROPDOWN) { - pPor = new SwFieldFormDropDownPortion(getCurrentListIndex(pBM)); + pPor = new SwFieldFormDropDownPortion(sw::mark::ExpandFieldmark(pBM)); } else { diff --git a/sw/source/core/txtnode/modeltoviewhelper.cxx b/sw/source/core/txtnode/modeltoviewhelper.cxx index 85390d0e1654..0d77cb1c75bc 100644 --- a/sw/source/core/txtnode/modeltoviewhelper.cxx +++ b/sw/source/core/txtnode/modeltoviewhelper.cxx @@ -17,25 +17,46 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <modeltoviewhelper.hxx> +#include <tools/multisel.hxx> +#include <doc.hxx> +#include <IMark.hxx> #include <fldbas.hxx> #include <fmtfld.hxx> #include <fmtftn.hxx> +#include <modeltoviewhelper.hxx> #include <ndtxt.hxx> +#include <pam.hxx> #include <txatbase.hxx> #include <txtfld.hxx> #include <txtftn.hxx> +#include <scriptinfo.hxx> +#include <set> +#include <vector> -#include <tools/multisel.hxx> +struct FieldResult +{ + sal_Int32 m_nFieldPos; + OUString m_sExpand; +}; -#include <scriptinfo.hxx> +class sortfieldresults : + public std::binary_function<const FieldResult&, const FieldResult&, bool> +{ +public: + bool operator()(const FieldResult &rOne, const FieldResult &rTwo) const + { + return rOne.m_nFieldPos < rTwo.m_nFieldPos; + } +}; + +typedef std::set<FieldResult, sortfieldresults> FieldResultSet; struct block { sal_Int32 m_nStart; sal_Int32 m_nLen; bool m_bVisible; - std::vector<const SwTxtAttr*> m_aAttrs; + FieldResultSet m_aAttrs; block(sal_Int32 nStart, sal_Int32 nLen, bool bVisible) : m_nStart(nStart), m_nLen(nLen), m_bVisible(bVisible) { @@ -100,6 +121,8 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode) if (eMode & EXPANDFIELDS) { + //first the normal fields, get their position in the node and what the text they expand + //to is const SwpHints* pSwpHints2 = rNode.GetpSwpHints(); for ( sal_uInt16 i = 0; pSwpHints2 && i < pSwpHints2->Count(); ++i ) { @@ -109,13 +132,59 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode) const sal_Int32 nDummyCharPos = *pAttr->GetStart(); if (aHiddenMulti.IsSelected(nDummyCharPos)) continue; - std::vector<block>::iterator aFind = std::find_if(aBlocks.begin(), aBlocks.end(), containsPos(nDummyCharPos)); + std::vector<block>::iterator aFind = std::find_if(aBlocks.begin(), + aBlocks.end(), containsPos(nDummyCharPos)); if (aFind != aBlocks.end()) { - aFind->m_aAttrs.push_back(pAttr); + FieldResult aFieldResult; + aFieldResult.m_nFieldPos = nDummyCharPos; + switch (pAttr->Which()) + { + case RES_TXTATR_FIELD: + case RES_TXTATR_ANNOTATION: + aFieldResult.m_sExpand = + static_cast<SwTxtFld const*>(pAttr)->GetFmtFld().GetField() + ->ExpandField(true); + break; + case RES_TXTATR_FTN: + { + const SwFmtFtn& rFtn = static_cast<SwTxtFtn const*>(pAttr)->GetFtn(); + const SwDoc *pDoc = rNode.GetDoc(); + aFieldResult.m_sExpand = rFtn.GetViewNumStr(*pDoc); + } + break; + default: + break; + } + + aFind->m_aAttrs.insert(aFieldResult); } } } + + //now get the dropdown formfields, get their position in the node and what the text they expand + //to is + SwPaM aPaM(rNode, 0, rNode, rNode.Len()); + std::vector<sw::mark::IFieldmark*> aDropDowns = + rNode.GetDoc()->getIDocumentMarkAccess()->getDropDownsFor(aPaM); + + for (std::vector<sw::mark::IFieldmark*>::iterator aI = aDropDowns.begin(), aEnd = aDropDowns.end(); + aI != aEnd; ++aI) + { + sw::mark::IFieldmark *pMark = *aI; + const sal_Int32 nDummyCharPos = pMark->GetMarkPos().nContent.GetIndex()-1; + if (aHiddenMulti.IsSelected(nDummyCharPos)) + continue; + std::vector<block>::iterator aFind = std::find_if(aBlocks.begin(), aBlocks.end(), + containsPos(nDummyCharPos)); + if (aFind != aBlocks.end()) + { + FieldResult aFieldResult; + aFieldResult.m_nFieldPos = nDummyCharPos; + aFieldResult.m_sExpand = sw::mark::ExpandFieldmark(pMark); + aFind->m_aAttrs.insert(aFieldResult); + } + } } sal_Int32 nOffset = 0; @@ -132,32 +201,11 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode) } else { - for (std::vector<const SwTxtAttr*>::iterator j = i->m_aAttrs.begin(); j != i->m_aAttrs.end(); ++j) + for (FieldResultSet::iterator j = i->m_aAttrs.begin(); j != i->m_aAttrs.end(); ++j) { - const SwTxtAttr* pAttr = *j; - const sal_Int32 nFieldPos = *pAttr->GetStart(); - OUString aExpand; - switch (pAttr->Which()) - { - case RES_TXTATR_FIELD: - case RES_TXTATR_ANNOTATION: - aExpand = - static_cast<SwTxtFld const*>(pAttr)->GetFmtFld().GetField() - ->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; + m_aRetText = m_aRetText.replaceAt( nOffset + j->m_nFieldPos, 1, j->m_sExpand ); + m_aMap.push_back( ConversionMapEntry( j->m_nFieldPos, nOffset + j->m_nFieldPos ) ); + nOffset += j->m_sExpand.getLength() - 1; } } } |