From 57f358f1ac4f3e05fcdf54326388ba8a19f0f2b3 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 13 Nov 2018 11:00:33 +0100 Subject: sw_redlinehide_3: add second result to SwGetExpField, SwSetExpField This is quite tricky & somewhat ugly due to the SwValueField base class & we need to duplicate its member too :( It would be possible to filter the deleted fields in SwDocUpdateField::MakeFieldList(), but the problem with that is that the instance is long-lived & might be used with different layout settings, so it's probably better to filter in the 5 or so client functions that iterate over the GetSortList(). Note that this will also filter other fields including database fields, hopefully that shouldn't cause problems. Change-Id: I0cdbc7757fa529598b5dbceec0bd2c4a619be05a --- sw/inc/IDocumentFieldsAccess.hxx | 5 +- sw/inc/cellfml.hxx | 4 +- sw/inc/expfld.hxx | 32 ++--- sw/source/core/doc/DocumentFieldsManager.cxx | 174 +++++++++++++++++++++------ sw/source/core/fields/cellfml.cxx | 15 ++- sw/source/core/fields/expfld.cxx | 133 ++++++++++++++++---- sw/source/core/inc/DocumentFieldsManager.hxx | 6 +- sw/source/core/unocore/unofield.cxx | 4 +- sw/source/filter/ww8/ww8par5.cxx | 2 +- 9 files changed, 287 insertions(+), 88 deletions(-) diff --git a/sw/inc/IDocumentFieldsAccess.hxx b/sw/inc/IDocumentFieldsAccess.hxx index 5b8299ac14db..617ea990614c 100644 --- a/sw/inc/IDocumentFieldsAccess.hxx +++ b/sw/inc/IDocumentFieldsAccess.hxx @@ -38,6 +38,7 @@ class SwNode; enum class SwFieldIds : sal_uInt16; template class SwHashTable; struct HashStr; +class SwRootFrame; namespace rtl { class OUString; } using rtl::OUString; @@ -122,9 +123,9 @@ namespace com { namespace sun { namespace star { namespace uno { class Any; } } // (if the address != 0 and the pointer == 0 a new list will be returned). virtual void FieldsToCalc(SwCalc& rCalc, sal_uLong nLastNd, sal_uInt16 nLastCnt) = 0; - virtual void FieldsToCalc(SwCalc& rCalc, const SetGetExpField& rToThisField) = 0; + virtual void FieldsToCalc(SwCalc& rCalc, const SetGetExpField& rToThisField, SwRootFrame const* pLayout) = 0; - virtual void FieldsToExpand(SwHashTable & rTable, const SetGetExpField& rToThisField) = 0; + virtual void FieldsToExpand(SwHashTable & rTable, const SetGetExpField& rToThisField, SwRootFrame const& rLayout) = 0; virtual bool IsNewFieldLst() const = 0; diff --git a/sw/inc/cellfml.hxx b/sw/inc/cellfml.hxx index 96b52b576743..f9fd74c09c57 100644 --- a/sw/inc/cellfml.hxx +++ b/sw/inc/cellfml.hxx @@ -31,6 +31,7 @@ class SwCalc; class SwTableBox; class SwTableFormulaUpdate; class SwDoc; +class SwRootFrame; class SwTableCalcPara { @@ -38,11 +39,12 @@ class SwTableCalcPara sal_uInt16 m_nStackCount, m_nMaxSize; public: + SwRootFrame const*const m_pLayout; ///< layout to access text field results std::unique_ptr m_pBoxStack; ///< stack for recognizing recursion SwCalc& m_rCalc; ///< current Calculator const SwTable* m_pTable; ///< current table - SwTableCalcPara( SwCalc& rCalculator, const SwTable& rTable ); + SwTableCalcPara(SwCalc& rCalculator, const SwTable& rTable, SwRootFrame const* pLayout); ~SwTableCalcPara(); bool CalcWithStackOverflow(); diff --git a/sw/inc/expfld.hxx b/sw/inc/expfld.hxx index 94240200e998..6acf1a02c987 100644 --- a/sw/inc/expfld.hxx +++ b/sw/inc/expfld.hxx @@ -79,7 +79,9 @@ protected: class SW_DLLPUBLIC SwGetExpField : public SwFormulaField { + double m_fValueRLHidden; ///< SwValueField; hidden redlines OUString m_sExpand; + OUString m_sExpandRLHidden; ///< hidden redlines bool m_bIsInBodyText; sal_uInt16 m_nSubType; @@ -87,15 +89,19 @@ class SW_DLLPUBLIC SwGetExpField : public SwFormulaField virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override; virtual std::unique_ptr Copy() const override; + using SwFormulaField::GetValue; // hide it, don't use + virtual void SetValue(const double& rVal) override; // hide it public: SwGetExpField( SwGetExpFieldType*, const OUString& rFormel, sal_uInt16 nSubType, sal_uLong nFormat); - virtual void SetValue( const double& rVal ) override; + double GetValue(SwRootFrame const* pLayout) const; + void SetValue(const double& rVal, SwRootFrame const* pLayout); + virtual void SetLanguage(LanguageType nLng) override; - inline void ChgExpStr(const OUString& rExpand); + void ChgExpStr(const OUString& rExpand, SwRootFrame const* pLayout); /// Called by formatting. inline bool IsInBodyText() const; @@ -123,9 +129,6 @@ public: void SetLateInitialization() { m_bLateInitialization = true;} }; -inline void SwGetExpField::ChgExpStr(const OUString& rExpand) - { m_sExpand = rExpand;} - /// Called by formatting. inline bool SwGetExpField::IsInBodyText() const { return m_bIsInBodyText; } @@ -174,7 +177,7 @@ public: void SetDelimiter( const OUString& s ) { m_sDelim = s; } sal_uInt8 GetOutlineLvl() const { return m_nLevel; } void SetOutlineLvl( sal_uInt8 n ) { m_nLevel = n; } - void SetChapter( SwSetExpField& rField, const SwNode& rNd ); + void SetChapter(SwSetExpField& rField, const SwNode& rNd, SwRootFrame const* pLayout); virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override; virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override; @@ -194,7 +197,9 @@ inline const OUString& SwSetExpFieldType::GetSetRefName() const class SW_DLLPUBLIC SwSetExpField : public SwFormulaField { + double m_fValueRLHidden; ///< SwValueField; hidden redlines OUString msExpand; + OUString msExpandRLHidden; ///< hidden redlines OUString maPText; bool mbInput; sal_uInt16 mnSeqNo; @@ -203,6 +208,8 @@ class SW_DLLPUBLIC SwSetExpField : public SwFormulaField virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override; virtual std::unique_ptr Copy() const override; + using SwFormulaField::GetValue; // hide it, don't use + virtual void SetValue(const double& rVal) override; // hide it public: SwSetExpField(SwSetExpFieldType*, const OUString& rFormel, sal_uLong nFormat = 0); @@ -210,11 +217,12 @@ public: void SetFormatField(SwFormatField & rFormatField); SwFormatField* GetFormatField() { return mpFormatField;} - virtual void SetValue( const double& rVal ) override; + double GetValue(SwRootFrame const* pLayout) const; + void SetValue(const double& rVal, SwRootFrame const* pLayout); - inline const OUString& GetExpStr() const; + const OUString& GetExpStr(SwRootFrame const* pLayout) const; - inline void ChgExpStr( const OUString& rExpand ); + void ChgExpStr(const OUString& rExpand, SwRootFrame const* pLayout); inline void SetPromptText(const OUString& rStr); inline const OUString& GetPromptText() const; @@ -243,12 +251,6 @@ public: virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override; }; -inline const OUString& SwSetExpField::GetExpStr() const - { return msExpand; } - -inline void SwSetExpField::ChgExpStr( const OUString& rExpand ) - { msExpand = rExpand; } - inline void SwSetExpField::SetPromptText(const OUString& rStr) { maPText = rStr; } diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index f24fd9688238..e089f88ec7fb 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -22,6 +22,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -78,13 +81,41 @@ namespace #endif + bool IsFieldDeleted(IDocumentRedlineAccess const& rIDRA, + SwRootFrame const& rLayout, SwTextField const& rTextField) + { + SwTextNode const& rNode(rTextField.GetTextNode()); + bool const isInBody( + rNode.GetNodes().GetEndOfExtras().GetIndex() < rNode.GetIndex()); + if (!isInBody && nullptr == rNode.getLayoutFrame(&rLayout)) + { // see SwDocUpdateField::GetBodyNode() - fields in hidden sections + // don't have layout frames but must be updated, so use the same + // check as there, but do it again because GetBodyNode() checks + // for *any* layout... + return true; + } + SwRedlineTable::size_type tmp; + SwPosition const pos(const_cast(rTextField.GetTextNode()), + rTextField.GetStart()); + SwRangeRedline const*const pRedline(rIDRA.GetRedline(pos, &tmp)); + return (pRedline + && pRedline->GetType() == nsRedlineType_t::REDLINE_DELETE + && *pRedline->GetPoint() != *pRedline->GetMark()); + } + void lcl_CalcField( SwDoc& rDoc, SwCalc& rCalc, const SetGetExpField& rSGEField, - SwDBManager* pMgr ) + SwDBManager* pMgr, SwRootFrame const*const pLayout) { const SwTextField* pTextField = rSGEField.GetTextField(); if( !pTextField ) return ; + if (pLayout && pLayout->IsHideRedlines() + && IsFieldDeleted(rDoc.getIDocumentRedlineAccess(), *pLayout, *pTextField)) + { + return; + } + const SwField* pField = pTextField->GetFormatField().GetField(); const SwFieldIds nFieldWhich = pField->GetTyp()->Which(); @@ -92,10 +123,10 @@ namespace { SwSbxValue aValue; if( nsSwGetSetExpType::GSE_EXPR & pField->GetSubType() ) - aValue.PutDouble( static_cast(pField)->GetValue() ); + aValue.PutDouble( static_cast(pField)->GetValue(pLayout) ); else // Extension to calculate with Strings - aValue.PutString( static_cast(pField)->GetExpStr() ); + aValue.PutString( static_cast(pField)->GetExpStr(pLayout) ); // set the new value in Calculator rCalc.VarChange( pField->GetTyp()->GetName(), aValue ); @@ -666,6 +697,13 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt ) } } + SwRootFrame const* pLayout(nullptr); + for (SwRootFrame const*const pLay : m_rDoc.GetAllLayouts()) + { + assert(!pLayout || pLay->IsHideRedlines() == pLayout->IsHideRedlines()); // TODO + pLayout = pLay; + } + // all fields/boxes are now invalid, so we can start to calculate if( pHt && ( RES_TABLEFML_UPDATE != pHt->Which() || TBL_CALC != static_cast(pHt)->m_eFlags )) @@ -715,16 +753,14 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt ) // is in the special section, that's expensive! Point aPt; // return the first frame of the layout - Tab.Headline!! std::pair const tmp(aPt, true); - pFrame = rTextNd.getLayoutFrame( - m_rDoc.getIDocumentLayoutAccess().GetCurrentLayout(), - nullptr, &tmp); + pFrame = rTextNd.getLayoutFrame(pLayout, nullptr, &tmp); if( pFrame ) { SwPosition aPos( *pTableNd ); if( GetBodyTextNode( m_rDoc, aPos, *pFrame ) ) FieldsToCalc( *pCalc, SetGetExpField( aPos.nNode, pFormatField->GetTextField(), - &aPos.nContent )); + &aPos.nContent), pLayout); else pFrame = nullptr; } @@ -734,10 +770,11 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt ) // create index to determine the TextNode SwNodeIndex aIdx( rTextNd ); FieldsToCalc( *pCalc, - SetGetExpField( aIdx, pFormatField->GetTextField() )); + SetGetExpField(aIdx, pFormatField->GetTextField()), + pLayout); } - SwTableCalcPara aPara( *pCalc, pTableNd->GetTable() ); + SwTableCalcPara aPara(*pCalc, pTableNd->GetTable(), pLayout); pField->CalcField( aPara ); if( aPara.IsStackOverflow() ) { @@ -789,12 +826,12 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt ) std::pair const tmp(aPt, true); if (pCNd && nullptr != (pFrame = pCNd->getLayoutFrame( - m_rDoc.getIDocumentLayoutAccess().GetCurrentLayout(), - nullptr, &tmp))) + pLayout, nullptr, &tmp))) { SwPosition aPos( *pCNd ); if( GetBodyTextNode( m_rDoc, aPos, *pFrame ) ) - FieldsToCalc( *pCalc, SetGetExpField( aPos.nNode )); + FieldsToCalc(*pCalc, SetGetExpField(aPos.nNode), + pLayout); else pFrame = nullptr; } @@ -803,10 +840,10 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt ) { // create index to determine the TextNode SwNodeIndex aIdx( *pTableNd ); - FieldsToCalc( *pCalc, SetGetExpField( aIdx )); + FieldsToCalc(*pCalc, SetGetExpField(aIdx), pLayout); } - SwTableCalcPara aPara( *pCalc, pTableNd->GetTable() ); + SwTableCalcPara aPara(*pCalc, pTableNd->GetTable(), pLayout); pFormula->Calc( aPara, nValue ); if( aPara.IsStackOverflow() ) @@ -859,6 +896,39 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp return ; } + SwRootFrame const* pLayout(nullptr); + SwRootFrame const* pLayoutRLHidden(nullptr); + for (SwRootFrame const*const pLay : m_rDoc.GetAllLayouts()) + { + if (pLay->IsHideRedlines()) + { + pLayoutRLHidden = pLay; + } + else + { + pLayout = pLay; + } + } + if (pLayout || !pLayoutRLHidden) // always calc *something*... + { + UpdateExpFieldsImpl(pUpdateField, pLayout); + } + if (pLayoutRLHidden) + { + UpdateExpFieldsImpl(pUpdateField, pLayoutRLHidden); + } + + // update reference fields + if( bUpdRefFields ) + UpdateRefFields(); + + mpUpdateFields->SetInUpdateFields( bOldInUpdateFields ); + mpUpdateFields->SetFieldsDirty( false ); +} + +void DocumentFieldsManager::UpdateExpFieldsImpl( + SwTextField * pUpdateField, SwRootFrame const*const pLayout) +{ SwFieldIds nWhich; // Hash table for all string replacements is filled on-the-fly. @@ -925,6 +995,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp } } + IDocumentRedlineAccess const& rIDRA(m_rDoc.getIDocumentRedlineAccess()); std::unordered_map SetExpOutlineNodeMap; for (std::unique_ptr const& it : *mpUpdateFields->GetSortList()) @@ -967,6 +1038,12 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp continue; } + if (pLayout && pLayout->IsHideRedlines() + && IsFieldDeleted(rIDRA, *pLayout, *pTextField)) + { + continue; + } + SwFormatField* pFormatField = const_cast(&pTextField->GetFormatField()); const SwField* pField = pFormatField->GetField(); @@ -1058,7 +1135,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp && pGField->IsInBodyText() ) { OUString aNew = LookString( aHashStrTable, pGField->GetFormula() ); - pGField->ChgExpStr( aNew ); + pGField->ChgExpStr( aNew, pLayout ); } } else @@ -1072,7 +1149,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp // only update one field if( !pUpdateField || pUpdateField == pTextField ) - pSField->ChgExpStr( aNew ); + pSField->ChgExpStr( aNew, pLayout ); // lookup the field's name aNew = static_cast(pSField->GetTyp())->GetSetRefName(); @@ -1081,12 +1158,12 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp HashStr* pFnd = aHashStrTable.Find( aNew, &nPos ); if( pFnd ) // Modify entry in the hash table - pFnd->aSetStr = pSField->GetExpStr(); + pFnd->aSetStr = pSField->GetExpStr(pLayout); else { // insert new entry aHashStrTable[nPos].reset( new HashStr( aNew, - pSField->GetExpStr(), + pSField->GetExpStr(pLayout), aHashStrTable[nPos].release() ) ); pFnd = aHashStrTable[nPos].get(); } @@ -1109,7 +1186,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp SwSbxValue aValue = aCalc.Calculate( pGField->GetFormula()); if(!aValue.IsVoidValue()) - pGField->SetValue(aValue.GetDouble() ); + pGField->SetValue(aValue.GetDouble(), pLayout); } } else @@ -1129,7 +1206,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp pSeqNd = m_rDoc.GetNodes()[ it->GetNode() ]; const SwTextNode* pOutlNd = pSeqNd-> - FindOutlineNodeOfLevel( nLvl ); + FindOutlineNodeOfLevel(nLvl, pLayout); auto const iter(SetExpOutlineNodeMap.find(pSFieldTyp)); if (iter == SetExpOutlineNodeMap.end() || iter->second != pOutlNd) @@ -1148,10 +1225,10 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp // only update one field if( !aValue.IsVoidValue() && (!pUpdateField || pUpdateField == pTextField) ) { - pSField->SetValue( nErg ); + pSField->SetValue(nErg, pLayout); if( pSeqNd ) - pSFieldTyp->SetChapter( *pSField, *pSeqNd ); + pSFieldTyp->SetChapter(*pSField, *pSeqNd, pLayout); } } } @@ -1175,13 +1252,6 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp #if HAVE_FEATURE_DBCONNECTIVITY pMgr->CloseAll(false); #endif - - // update reference fields - if( bUpdRefFields ) - UpdateRefFields(); - - mpUpdateFields->SetInUpdateFields( bOldInUpdateFields ); - mpUpdateFields->SetFieldsDirty( false ); } /// Insert field type that was marked as deleted @@ -1429,7 +1499,8 @@ void DocumentFieldsManager::SetFixFields( const DateTime* pNewDateTime ) m_rDoc.getIDocumentState().ResetModified(); } -void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, const SetGetExpField& rToThisField ) +void DocumentFieldsManager::FieldsToCalc(SwCalc& rCalc, + const SetGetExpField& rToThisField, SwRootFrame const*const pLayout) { // create the sorted list of all SetFields mpUpdateFields->MakeFieldList( m_rDoc, mbNewFieldLst, GETFLD_CALC ); @@ -1449,7 +1520,7 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, const SetGetExpField& r &rToThisField); for (auto it = mpUpdateFields->GetSortList()->begin(); it != itLast; ++it) { - lcl_CalcField( m_rDoc, rCalc, **it, pMgr ); + lcl_CalcField(m_rDoc, rCalc, **it, pMgr, pLayout); } } #if HAVE_FEATURE_DBCONNECTIVITY @@ -1470,6 +1541,22 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_ pMgr->CloseAll(false); #endif + SwRootFrame const* pLayout(nullptr); + SwRootFrame const* pLayoutRLHidden(nullptr); + for (SwRootFrame const*const pLay : m_rDoc.GetAllLayouts()) + { + if (pLay->IsHideRedlines()) + { + pLayoutRLHidden = pLay; + } + else + { + pLayout = pLay; + } + } + + // note this is not duplicate of the other FieldsToCalc because there is + // (currently) no SetGetExpField that compares only a position for(auto it = mpUpdateFields->GetSortList()->begin(); it != mpUpdateFields->GetSortList()->end() && ( (*it)->GetNode() < nLastNd || @@ -1477,7 +1564,14 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_ ); ++it ) { - lcl_CalcField( m_rDoc, rCalc, **it, pMgr ); + if (pLayout || !pLayoutRLHidden) // always calc *something*... + { + lcl_CalcField( m_rDoc, rCalc, **it, pMgr, pLayout ); + } + if (pLayoutRLHidden) + { + lcl_CalcField( m_rDoc, rCalc, **it, pMgr, pLayoutRLHidden ); + } } #if HAVE_FEATURE_DBCONNECTIVITY @@ -1486,12 +1580,14 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_ } void DocumentFieldsManager::FieldsToExpand( SwHashTable & rHashTable, - const SetGetExpField& rToThisField ) + const SetGetExpField& rToThisField, SwRootFrame const& rLayout) { // create the sorted list of all SetFields mpUpdateFields->MakeFieldList( m_rDoc, mbNewFieldLst, GETFLD_EXPAND ); mbNewFieldLst = false; + IDocumentRedlineAccess const& rIDRA(m_rDoc.getIDocumentRedlineAccess()); + // Hash table for all string replacements is filled on-the-fly. // Try to fabricate an uneven number. sal_uInt16 nTableSize = ((mpUpdateFields->GetSortList()->size() / 7) + 1) * 7; @@ -1506,6 +1602,12 @@ void DocumentFieldsManager::FieldsToExpand( SwHashTable & rHashTable, if( !pTextField ) continue; + if (rLayout.IsHideRedlines() + && IsFieldDeleted(rIDRA, rLayout, *pTextField)) + { + continue; + } + const SwField* pField = pTextField->GetFormatField().GetField(); switch( pField->GetTyp()->Which() ) { @@ -1522,7 +1624,7 @@ void DocumentFieldsManager::FieldsToExpand( SwHashTable & rHashTable, // #i3141# - update expression of field as in method // for string/text fields - pSField->ChgExpStr( aNew ); + pSField->ChgExpStr(aNew, &rLayout); // look up the field's name aNew = static_cast(pSField->GetTyp())->GetSetRefName(); @@ -1531,11 +1633,11 @@ void DocumentFieldsManager::FieldsToExpand( SwHashTable & rHashTable, SwHash* pFnd = rHashTable.Find( aNew, &nPos ); if( pFnd ) // modify entry in the hash table - static_cast(pFnd)->aSetStr = pSField->GetExpStr(); + static_cast(pFnd)->aSetStr = pSField->GetExpStr(&rLayout); else // insert the new entry rHashTable[nPos].reset( new HashStr( aNew, - pSField->GetExpStr(), rHashTable[nPos].release() ) ); + pSField->GetExpStr(&rLayout), rHashTable[nPos].release())); } break; case SwFieldIds::Database: diff --git a/sw/source/core/fields/cellfml.cxx b/sw/source/core/fields/cellfml.cxx index 836ae5c24ef6..2edf4762c3e4 100644 --- a/sw/source/core/fields/cellfml.cxx +++ b/sw/source/core/fields/cellfml.cxx @@ -163,7 +163,7 @@ double SwTableBox::GetValue( SwTableCalcPara& rCalcPara ) const switch ( pField->GetTyp()->Which() ) { case SwFieldIds::SetExp: - nRet = static_cast(pField)->GetValue(); + nRet = static_cast(pField)->GetValue(rCalcPara.m_pLayout); break; case SwFieldIds::User: nRet = static_cast(pField)->GetValue(); @@ -251,10 +251,15 @@ double SwTableBox::GetValue( SwTableCalcPara& rCalcPara ) const // structure needed for calculation of tables -SwTableCalcPara::SwTableCalcPara( SwCalc& rCalculator, const SwTable& rTable ) - : m_pLastTableBox( nullptr ), m_nStackCount( 0 ), m_nMaxSize( cMAXSTACKSIZE ), - m_pBoxStack( new SwTableSortBoxes ), - m_rCalc( rCalculator ), m_pTable( &rTable ) +SwTableCalcPara::SwTableCalcPara(SwCalc& rCalculator, const SwTable& rTable, + SwRootFrame const*const pLayout) + : m_pLastTableBox(nullptr) + , m_nStackCount( 0 ) + , m_nMaxSize( cMAXSTACKSIZE ) + , m_pLayout(pLayout) + , m_pBoxStack( new SwTableSortBoxes ) + , m_rCalc( rCalculator ) + , m_pTable( &rTable ) { } diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx index bb461c1bd49e..e7b9aebfdeb0 100644 --- a/sw/source/core/fields/expfld.cxx +++ b/sw/source/core/fields/expfld.cxx @@ -283,7 +283,9 @@ void SwGetExpFieldType::Modify( const SfxPoolItem*, const SfxPoolItem* pNew ) SwGetExpField::SwGetExpField(SwGetExpFieldType* pTyp, const OUString& rFormel, sal_uInt16 nSub, sal_uLong nFormat) - : SwFormulaField( pTyp, nFormat, 0.0 ), + : SwFormulaField( pTyp, nFormat, 0.0 ) + , m_fValueRLHidden(0.0) + , m_bIsInBodyText( true ), m_nSubType(nSub), m_bLateInitialization( false ) @@ -291,12 +293,24 @@ SwGetExpField::SwGetExpField(SwGetExpFieldType* pTyp, const OUString& rFormel, SetFormula( rFormel ); } -OUString SwGetExpField::ExpandImpl(SwRootFrame const*const) const +void SwGetExpField::ChgExpStr(const OUString& rExpand, SwRootFrame const*const pLayout) +{ + if (!pLayout || pLayout->IsHideRedlines()) + { + m_sExpandRLHidden = rExpand; + } + if (!pLayout || !pLayout->IsHideRedlines()) + { + m_sExpand = rExpand; + } +} + +OUString SwGetExpField::ExpandImpl(SwRootFrame const*const pLayout) const { if(m_nSubType & nsSwExtendedSubType::SUB_CMD) return GetFormula(); - return m_sExpand; + return (pLayout && pLayout->IsHideRedlines()) ? m_sExpandRLHidden : m_sExpand; } OUString SwGetExpField::GetFieldName() const @@ -314,6 +328,7 @@ std::unique_ptr SwGetExpField::Copy() const std::unique_ptr pTmp(new SwGetExpField(static_cast(GetTyp()), GetFormula(), m_nSubType, GetFormat())); pTmp->SetLanguage(GetLanguage()); + pTmp->m_fValueRLHidden = m_fValueRLHidden; pTmp->SwValueField::SetValue(GetValue()); pTmp->m_sExpand = m_sExpand; pTmp->m_bIsInBodyText = m_bIsInBodyText; @@ -356,25 +371,27 @@ void SwGetExpField::ChangeExpansion( const SwFrame& rFrame, const SwTextField& r } } + SwRootFrame const& rLayout(*rFrame.getRootFrame()); + OUString & rExpand(rLayout.IsHideRedlines() ? m_sExpandRLHidden : m_sExpand); SetGetExpField aEndField( aPos.nNode, &rField, &aPos.nContent ); if(GetSubType() & nsSwGetSetExpType::GSE_STRING) { SwHashTable aHashTable(0); - rDoc.getIDocumentFieldsAccess().FieldsToExpand( aHashTable, aEndField ); - m_sExpand = LookString( aHashTable, GetFormula() ); + rDoc.getIDocumentFieldsAccess().FieldsToExpand(aHashTable, aEndField, rLayout); + rExpand = LookString( aHashTable, GetFormula() ); } else { // fill calculator with values SwCalc aCalc( rDoc ); - rDoc.getIDocumentFieldsAccess().FieldsToCalc(aCalc, aEndField); + rDoc.getIDocumentFieldsAccess().FieldsToCalc(aCalc, aEndField, &rLayout); // calculate value - SetValue(aCalc.Calculate(GetFormula()).GetDouble()); + SetValue(aCalc.Calculate(GetFormula()).GetDouble(), &rLayout); // analyse based on format - m_sExpand = static_cast(GetTyp())->ExpandValue( - GetValue(), GetFormat(), GetLanguage()); + rExpand = static_cast(GetTyp())->ExpandValue( + GetValue(&rLayout), GetFormat(), GetLanguage()); } } @@ -447,6 +464,7 @@ bool SwGetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) { case FIELD_PROP_DOUBLE: SwValueField::SetValue(*o3tl::doAccess(rAny)); + m_fValueRLHidden = *o3tl::doAccess(rAny); break; case FIELD_PROP_FORMAT: rAny >>= nTmp; @@ -478,7 +496,7 @@ bool SwGetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) { OUString sTmp; rAny >>= sTmp; - ChgExpStr(sTmp); + ChgExpStr(sTmp, nullptr); break; } default: @@ -513,6 +531,23 @@ OUString SwSetExpFieldType::GetName() const return m_sName; } +const OUString& SwSetExpField::GetExpStr(SwRootFrame const*const pLayout) const +{ + return (pLayout && pLayout->IsHideRedlines()) ? msExpandRLHidden : msExpand; +} + +void SwSetExpField::ChgExpStr(const OUString& rExpand, SwRootFrame const*const pLayout) +{ + if (!pLayout || pLayout->IsHideRedlines()) + { + msExpandRLHidden = rExpand; + } + if (!pLayout || !pLayout->IsHideRedlines()) + { + msExpand = rExpand; + } +} + void SwSetExpFieldType::Modify( const SfxPoolItem*, const SfxPoolItem* ) { // do not expand further @@ -604,9 +639,10 @@ size_t SwSetExpFieldType::GetSeqFieldList( SwSeqFieldList& rList ) return rList.Count(); } -void SwSetExpFieldType::SetChapter( SwSetExpField& rField, const SwNode& rNd ) +void SwSetExpFieldType::SetChapter(SwSetExpField& rField, const SwNode& rNd, + SwRootFrame const*const pLayout) { - const SwTextNode* pTextNd = rNd.FindOutlineNodeOfLevel( m_nLevel ); + const SwTextNode* pTextNd = rNd.FindOutlineNodeOfLevel(m_nLevel, pLayout); if( pTextNd ) { SwNumRule * pRule = pTextNd->GetNumRule(); @@ -614,19 +650,17 @@ void SwSetExpFieldType::SetChapter( SwSetExpField& rField, const SwNode& rNd ) if (pRule) { // --> OD 2005-11-02 #i51089 - TUNING# - if ( pTextNd->GetNum() ) + if (SwNodeNum const*const pNum = pTextNd->GetNum(pLayout)) { - const SwNodeNum & aNum = *(pTextNd->GetNum()); - // only get the number, without pre-/post-fixstrings - OUString sNumber( pRule->MakeNumString(aNum, false )); + OUString const sNumber(pRule->MakeNumString(*pNum, false)); if( !sNumber.isEmpty() ) - rField.ChgExpStr( sNumber + m_sDelim + rField.GetExpStr() ); + rField.ChgExpStr(sNumber + m_sDelim + rField.GetExpStr(pLayout), pLayout); } else { - OSL_FAIL( " - text node with numbering rule, but without number. This is a serious defect" ); + OSL_ENSURE(pTextNd->GetNum(nullptr), " - text node with numbering rule, but without number. This is a serious defect"); } } } @@ -773,8 +807,10 @@ bool SwSeqFieldList::SeekEntry( const SeqFieldLstElem& rNew, size_t* pP ) const SwSetExpField::SwSetExpField(SwSetExpFieldType* pTyp, const OUString& rFormel, sal_uLong nFormat) - : SwFormulaField( pTyp, nFormat, 0.0 ), mnSeqNo( USHRT_MAX ), - mnSubType(0) + : SwFormulaField( pTyp, nFormat, 0.0 ) + , m_fValueRLHidden(0.0) + , mnSeqNo( USHRT_MAX ) + , mnSubType(0) , mpFormatField(nullptr) { SetFormula(rFormel); @@ -783,6 +819,7 @@ SwSetExpField::SwSetExpField(SwSetExpFieldType* pTyp, const OUString& rFormel, if( IsSequenceField() ) { SwValueField::SetValue(1.0); + m_fValueRLHidden = 1.0; if( rFormel.isEmpty() ) { SetFormula(pTyp->GetName() + "+1"); @@ -795,7 +832,7 @@ void SwSetExpField::SetFormatField(SwFormatField & rFormatField) mpFormatField = &rFormatField; } -OUString SwSetExpField::ExpandImpl(SwRootFrame const*const) const +OUString SwSetExpField::ExpandImpl(SwRootFrame const*const pLayout) const { if (mnSubType & nsSwExtendedSubType::SUB_CMD) { // we need the CommandString @@ -803,7 +840,7 @@ OUString SwSetExpField::ExpandImpl(SwRootFrame const*const) const } if(!(mnSubType & nsSwExtendedSubType::SUB_INVISIBLE)) { // value is visible - return msExpand; + return (pLayout && pLayout->IsHideRedlines()) ? msExpandRLHidden : msExpand; } return OUString(); } @@ -835,7 +872,9 @@ std::unique_ptr SwSetExpField::Copy() const std::unique_ptr pTmp(new SwSetExpField(static_cast(GetTyp()), GetFormula(), GetFormat())); pTmp->SwValueField::SetValue(GetValue()); + pTmp->m_fValueRLHidden = m_fValueRLHidden; pTmp->msExpand = msExpand; + pTmp->msExpandRLHidden = msExpandRLHidden; pTmp->SetAutomaticLanguage(IsAutomaticLanguage()); pTmp->SetLanguage(GetLanguage()); pTmp->maPText = maPText; @@ -870,6 +909,32 @@ void SwSetExpField::SetValue( const double& rAny ) GetFormat(), GetLanguage()); } +void SwSetExpField::SetValue(const double& rValue, SwRootFrame const*const pLayout) +{ + if (!pLayout || !pLayout->IsHideRedlines()) + { + SetValue(rValue); + } + if (!pLayout || pLayout->IsHideRedlines()) + { + m_fValueRLHidden = rValue; + if (IsSequenceField()) + { + msExpandRLHidden = FormatNumber(rValue, static_cast(GetFormat()), GetLanguage()); + } + else + { + msExpandRLHidden = static_cast(GetTyp())->ExpandValue( + rValue, GetFormat(), GetLanguage()); + } + } +} + +double SwSetExpField::GetValue(SwRootFrame const* pLayout) const +{ + return (pLayout && pLayout->IsHideRedlines()) ? m_fValueRLHidden : GetValue(); +} + void SwGetExpField::SetValue( const double& rAny ) { SwValueField::SetValue(rAny); @@ -877,6 +942,25 @@ void SwGetExpField::SetValue( const double& rAny ) GetLanguage()); } +void SwGetExpField::SetValue(const double& rValue, SwRootFrame const*const pLayout) +{ + if (!pLayout || !pLayout->IsHideRedlines()) + { + SetValue(rValue); + } + if (!pLayout || pLayout->IsHideRedlines()) + { + m_fValueRLHidden = rValue; + m_sExpandRLHidden = static_cast(GetTyp())->ExpandValue( + rValue, GetFormat(), GetLanguage()); + } +} + +double SwGetExpField::GetValue(SwRootFrame const* pLayout) const +{ + return (pLayout && pLayout->IsHideRedlines()) ? m_fValueRLHidden : GetValue(); +} + /** Find the index of the reference text following the current field * * @param rFormat @@ -1020,6 +1104,7 @@ bool SwSetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) double fVal = 0.0; rAny >>= fVal; SetValue(fVal); + m_fValueRLHidden = fVal; } break; case FIELD_PROP_SUBTYPE: @@ -1043,7 +1128,7 @@ bool SwSetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) { OUString sTmp; rAny >>= sTmp; - ChgExpStr( sTmp ); + ChgExpStr(sTmp, nullptr); } break; default: @@ -1100,7 +1185,7 @@ bool SwSetExpField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const rAny <<= GetInputFlag(); break; case FIELD_PROP_PAR4: - rAny <<= GetExpStr(); + rAny <<= GetExpStr(nullptr); break; default: return SwField::QueryValue(rAny, nWhichId); diff --git a/sw/source/core/inc/DocumentFieldsManager.hxx b/sw/source/core/inc/DocumentFieldsManager.hxx index 0475eb345492..c73345f669c5 100644 --- a/sw/source/core/inc/DocumentFieldsManager.hxx +++ b/sw/source/core/inc/DocumentFieldsManager.hxx @@ -56,8 +56,8 @@ public: virtual bool SetFieldsDirty(bool b, const SwNode* pChk, sal_uLong nLen) override; virtual void SetFixFields(const DateTime* pNewDateTime) override; virtual void FieldsToCalc(SwCalc& rCalc, sal_uLong nLastNd, sal_uInt16 nLastCnt) override; - virtual void FieldsToCalc(SwCalc& rCalc, const SetGetExpField& rToThisField) override; - virtual void FieldsToExpand(SwHashTable& rTable, const SetGetExpField& rToThisField) override; + virtual void FieldsToCalc(SwCalc& rCalc, const SetGetExpField& rToThisField, SwRootFrame const* pLayout) override; + virtual void FieldsToExpand(SwHashTable& rTable, const SetGetExpField& rToThisField, SwRootFrame const& rLayout) override; virtual bool IsNewFieldLst() const override; virtual void SetNewFieldLst( bool bFlag) override; virtual void InsDelFieldInFieldLst(bool bIns, const SwTextField& rField) override; @@ -95,6 +95,8 @@ private: DocumentFieldsManager(DocumentFieldsManager const&) = delete; DocumentFieldsManager& operator=(DocumentFieldsManager const&) = delete; + void UpdateExpFieldsImpl(SwTextField* pField, SwRootFrame const* pLayout); + SwDoc& m_rDoc; bool mbNewFieldLst; //< TRUE: Rebuild field-list. diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index b8ada47916cd..4fe387ba3b59 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -1730,7 +1730,7 @@ void SAL_CALL SwXTextField::attach( pSEField->SetInputFlag(m_pImpl->m_pProps->bBool1); pSEField->SetPromptText(m_pImpl->m_pProps->sPar3); if (!m_pImpl->m_pProps->sPar4.isEmpty()) - pSEField->ChgExpStr(m_pImpl->m_pProps->sPar4); + pSEField->ChgExpStr(m_pImpl->m_pProps->sPar4, nullptr); } break; @@ -1772,7 +1772,7 @@ void SAL_CALL SwXTextField::attach( xField.reset(pGEField); //TODO: evaluate SubType! if (!m_pImpl->m_pProps->sPar4.isEmpty()) - pGEField->ChgExpStr(m_pImpl->m_pProps->sPar4); + pGEField->ChgExpStr(m_pImpl->m_pProps->sPar4, nullptr); // #i82544# if (bSetGetExpFieldUninitialized) pGEField->SetLateInitialization(); diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index 51f6ca542053..49c506b3d5d6 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -1393,7 +1393,7 @@ eF_ResT SwWW8ImplReader::Read_F_ANumber( WW8FieldDesc*, OUString& rStr ) } SwSetExpField aField( static_cast(m_pNumFieldType), OUString(), GetNumberPara( rStr ) ); - aField.SetValue( ++m_nFieldNum ); + aField.SetValue( ++m_nFieldNum, nullptr ); m_rDoc.getIDocumentContentOperations().InsertPoolItem( *m_pPaM, SwFormatField( aField ) ); return eF_ResT::OK; } -- cgit v1.2.3