[Libreoffice-commits] core.git: Branch 'private/mst/sw_redlinehide_3' - 18 commits - sw/inc sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Nov 14 17:46:36 UTC 2018


Rebased ref, commits from common ancestor:
commit 04ff698720c692e974a239e97decc145432492e9
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 14 15:45:51 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw: GSE_INP is dead since CVS import, remove it
    
    Change-Id: Ib0713df614e63c20965979e7e34f7481fe8ed838

diff --git a/sw/inc/fldbas.hxx b/sw/inc/fldbas.hxx
index 65f06bac106a..52ca812c1c0b 100644
--- a/sw/inc/fldbas.hxx
+++ b/sw/inc/fldbas.hxx
@@ -131,7 +131,7 @@ enum SwFieldTypesEnum {
     TYP_PARAGRAPHSIGFLD,
     TYP_END
 };
-enum SwAttrFieldTYpe {
+enum SwAttrFieldType {
     ATTR_NONE,
     ATTR_DATEFLD,
     ATTR_TIMEFLD,
@@ -192,7 +192,6 @@ namespace nsSwGetSetExpType
 {
 const SwGetSetExpType GSE_STRING  = 0x0001; ///< String
 const SwGetSetExpType GSE_EXPR    = 0x0002; ///< Expression
-const SwGetSetExpType GSE_INP     = 0x0004; ///< InputField
 const SwGetSetExpType GSE_SEQ     = 0x0008; ///< Sequence
 const SwGetSetExpType GSE_FORMULA = 0x0010; ///< Formula
 }
commit d7d6cac0b18f39786aec61b935d077622590e3d2
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 14 14:27:33 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw: fix a search-and-replace gone bad in DocumentFieldsManager.cxx
    
    Change-Id: I6b2df2aee96ab32123d3fa23fd9a2480b3ed3c72

diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx
index efe6c60357ff..65d70390df0c 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -214,7 +214,7 @@ SwFieldType* DocumentFieldsManager::InsertFieldType(const SwFieldType &rFieldTyp
     case SwFieldIds::SetExp:
             //JP 29.01.96: SequenceFields start at INIT_FLDTYPES - 3!!
             //             Or we get doubble number circles!!
-            //MIB 14.03.95: From now on also the SW3-Reader relies on &m_rDoc, when
+            //MIB 14.03.95: From now on also the SW3-Reader relies on this, when
             //constructing string pools and when reading SetExp fields
             if( nsSwGetSetExpType::GSE_SEQ & static_cast<const SwSetExpFieldType&>(rFieldTyp).GetType() )
                 i -= INIT_SEQ_FLDTYPES;
@@ -301,7 +301,7 @@ SwFieldType* DocumentFieldsManager::GetFieldType(
     case SwFieldIds::SetExp:
             //JP 29.01.96: SequenceFields start at INIT_FLDTYPES - 3!!
             //             Or we get doubble number circles!!
-            //MIB 14.03.95: From now on also the SW3-Reader relies on &m_rDoc, when
+            //MIB 14.03.95: From now on also the SW3-Reader relies on this, when
             //constructing string pools and when reading SetExp fields
         i = INIT_FLDTYPES - INIT_SEQ_FLDTYPES;
         break;
@@ -438,7 +438,7 @@ void DocumentFieldsManager::UpdateFields( bool bCloseDB )
 void DocumentFieldsManager::InsDeletedFieldType( SwFieldType& rFieldTyp )
 {
     // The FieldType was marked as deleted and removed from the array.
-    // One has to look &m_rDoc up again, now.
+    // One has to look this up again, now.
     // - If it's not present, it can be re-inserted.
     // - If the same type is found, the deleted one has to be renamed.
 
@@ -621,7 +621,7 @@ void DocumentFieldsManager::UpdateRefFields()
 void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
 {
     OSL_ENSURE( !pHt || RES_TABLEFML_UPDATE  == pHt->Which(),
-            "What MessageItem is &m_rDoc?" );
+            "What MessageItem is this?" );
 
     SwFieldType* pFieldType(nullptr);
 
@@ -642,7 +642,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
 
                     if( pUpdateField )
                     {
-                        // table where &m_rDoc field is located
+                        // table where this field is located
                         const SwTableNode* pTableNd;
                         const SwTextNode& rTextNd = pFormatField->GetTextField()->GetTextNode();
                         if(!rTextNd.GetNodes().IsDocNodes())
@@ -663,7 +663,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
                                 pField->ChgValid( false );
                             break;
                         case TBL_BOXNAME:
-                            // is &m_rDoc the wanted table?
+                            // is this the wanted table?
                             if( &pTableNd->GetTable() == pUpdateField->m_pTable )
                                 // to the external representation
                                 pField->PtrToBoxNm( pUpdateField->m_pTable );
@@ -675,7 +675,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
                             pField->BoxNmToPtr( pUpdateField->m_pTable );
                             break;
                         case TBL_RELBOXNAME:
-                            // is &m_rDoc the wanted table?
+                            // is this the wanted table?
                             if( &pTableNd->GetTable() == pUpdateField->m_pTable )
                                 // to the relative representation
                                 pField->ToRelBoxNm( pUpdateField->m_pTable );
@@ -728,7 +728,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
                 // start calculation at the end
                 // new fields are inserted at the beginning of the modify chain
                 // that gives faster calculation on import
-                // mba: do we really need &m_rDoc "optimization"? Is it still valid?
+                // mba: do we really need this "optimization"? Is it still valid?
                 if (!pFormatField->GetTextField())
                     continue;
                 SwTableField *const pField(static_cast<SwTableField*>(pFormatField->GetField()));
@@ -738,7 +738,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
                 // needs to be recalculated
                 if( !pField->IsValid() )
                 {
-                    // table where &m_rDoc field is located
+                    // table where this field is located
                     const SwTextNode& rTextNd = pFormatField->GetTextField()->GetTextNode();
                     if( !rTextNd.GetNodes().IsDocNodes() )
                         continue;
@@ -746,7 +746,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
                     if( !pTableNd )
                         continue;
 
-                    // if &m_rDoc field is not in the to-be-updated table, skip it
+                    // if this field is not in the to-be-updated table, skip it
                     if( pHt && &pTableNd->GetTable() !=
                                             static_cast<SwTableFormulaUpdate*>(pHt)->m_pTable )
                         continue;
@@ -1248,7 +1248,7 @@ void DocumentFieldsManager::UpdateExpFieldsImpl(
 
         pFormatField->ModifyNotification( nullptr, nullptr );        // trigger formatting
 
-        if( pUpdateField == pTextField )       // if only &m_rDoc one is updated
+        if (pUpdateField == pTextField) // if only this one is updated
         {
             if( SwFieldIds::GetExp == nWhich ||      // only GetField or
                 SwFieldIds::HiddenText == nWhich ||   // HiddenText?
@@ -1763,7 +1763,7 @@ void DocumentFieldsManager::InitFieldTypes()       // is being called by the CTO
     mpFieldTypes->push_back( new SwDropDownFieldType );
 
     // Types have to be at the end!
-    // We expect &m_rDoc in the InsertFieldType!
+    // We expect this in the InsertFieldType!
     // MIB 14.04.95: In Sw3StringPool::Setup (sw3imp.cxx) and
     //               lcl_sw3io_InSetExpField (sw3field.cxx) now also
     mpFieldTypes->push_back( new SwSetExpFieldType(&m_rDoc,
commit 2fb5eb5b83220ba28b965ae699a376138442fc33
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Nov 9 16:04:17 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw_redlinehide_3: update fields on redline ops
    
    Can't tell which chapter/reference fields will be affected by a redline,
    so we have to either update all of them, or rely on the
    IDocumentSettingAccess::getFieldUpdateFlags() which lets the SwIdle
    update the fields, at some later time...
    
    Change-Id: I3b9cfd17bd227a18f64dac193f0cc912768810c1

diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx
index 0d4448a79079..a5b60561abdf 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -22,6 +22,7 @@
 #include <txtfrm.hxx>
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
+#include <IDocumentFieldsAccess.hxx>
 #include <IDocumentState.hxx>
 #include <redline.hxx>
 #include <UndoRedline.hxx>
@@ -29,6 +30,7 @@
 #include <ndtxt.hxx>
 #include <unocrsr.hxx>
 #include <ftnidx.hxx>
+#include <authfld.hxx>
 #include <strings.hrc>
 #include <swmodule.hxx>
 #include <editsh.hxx>
@@ -119,6 +121,20 @@ using namespace com::sun::star;
 
 namespace sw {
 
+static void UpdateFieldsForRedline(IDocumentFieldsAccess & rIDFA)
+{
+    auto const pAuthType(static_cast<SwAuthorityFieldType*>(rIDFA.GetFieldType(
+        SwFieldIds::TableOfAuthorities, OUString(), false)));
+    if (pAuthType) // created on demand...
+    {
+        pAuthType->DelSequenceArray();
+    }
+    rIDFA.GetFieldType(SwFieldIds::RefPageGet, OUString(), false)->UpdateFields();
+    rIDFA.GetSysFieldType(SwFieldIds::Chapter)->UpdateFields();
+    rIDFA.UpdateExpFields(nullptr, false);
+    rIDFA.UpdateRefFields();
+}
+
 void UpdateFramesForAddDeleteRedline(SwDoc & rDoc, SwPaM const& rPam)
 {
     // no need to call UpdateFootnoteNums for FTNNUM_PAGE:
@@ -148,6 +164,8 @@ void UpdateFramesForAddDeleteRedline(SwDoc & rDoc, SwPaM const& rPam)
         // node of the merged frame, there could be another redline nearby
         sw::AddRemoveFlysAnchoredToFrameStartingAtNode(*pFrame, *pStartNode, nullptr);
     }
+    // fields last - SwGetRefField::UpdateField requires up-to-date frames
+    UpdateFieldsForRedline(rDoc.getIDocumentFieldsAccess()); // after footnotes
 }
 
 void UpdateFramesForRemoveDeleteRedline(SwDoc & rDoc, SwPaM const& rPam)
@@ -205,6 +223,8 @@ void UpdateFramesForRemoveDeleteRedline(SwDoc & rDoc, SwPaM const& rPam)
             AppendAllObjs(rDoc.GetSpzFrameFormats(), pLayout);
         }
     }
+    // fields last - SwGetRefField::UpdateField requires up-to-date frames
+    UpdateFieldsForRedline(rDoc.getIDocumentFieldsAccess()); // after footnotes
 }
 
 } // namespace sw
commit 978d10d28e12748e4328ada16ee6f563dd659cec
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Nov 9 12:50:04 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw_redlinehide_3: update fields in UnHideRedlines
    
    Repainting is not enough, values require up-to-date outline visibility
    etc.
    
    Change-Id: I85d99fc65a071279c2d4656a52ff82ed3b2db7d8

diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index eb8a0fa12368..914df003d2b1 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -4504,6 +4504,19 @@ void SwRootFrame::SetHideRedlines(bool const bHideRedlines)
             pFootnote->InvalidateNumberInLayout();
         }
     }
+    // update various fields to re-expand them with the new layout
+    IDocumentFieldsAccess & rIDFA(rDoc.getIDocumentFieldsAccess());
+    auto const pAuthType(rIDFA.GetFieldType(
+        SwFieldIds::TableOfAuthorities, OUString(), false));
+    if (pAuthType) // created on demand...
+    {   // calling DelSequenceArray() should be unnecessary here since the
+        // sequence doesn't depend on frames
+        pAuthType->UpdateFields();
+    }
+    rIDFA.GetFieldType(SwFieldIds::RefPageGet, OUString(), false)->UpdateFields();
+    rIDFA.GetSysFieldType(SwFieldIds::Chapter)->UpdateFields();
+    rIDFA.UpdateExpFields(nullptr, false);
+    rIDFA.UpdateRefFields();
 
 //    InvalidateAllContent(SwInvalidateFlags::Size); // ??? TODO what to invalidate?  this is the big hammer
 }
commit 510829c5493df129604df5d8fe43078cb1a0800d
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 14 17:32:26 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw_redlinehide_3: filter deleted footnotes in Field Reference dialog
    
    Change-Id: I386bce6b929e38077c01595de618b89fccdaf5fe

diff --git a/sw/inc/ftnidx.hxx b/sw/inc/ftnidx.hxx
index 3dfb118a1f6b..245d9176dc16 100644
--- a/sw/inc/ftnidx.hxx
+++ b/sw/inc/ftnidx.hxx
@@ -67,6 +67,13 @@ public:
             IDocumentRedlineAccess const&, const SwTextFootnote& rTextFootnote);
 };
 
+namespace sw {
+
+bool IsFootnoteDeleted(IDocumentRedlineAccess const& rIDRA,
+        SwTextFootnote const& rTextFootnote);
+
+}
+
 #endif // INCLUDED_SW_INC_FTNIDX_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/ftnidx.cxx b/sw/source/core/doc/ftnidx.cxx
index 85c35ecc51e7..41831272a534 100644
--- a/sw/source/core/doc/ftnidx.cxx
+++ b/sw/source/core/doc/ftnidx.cxx
@@ -32,7 +32,9 @@
 #include <rootfrm.hxx>
 #include <txtfrm.hxx>
 
-static bool IsFootnoteDeleted(IDocumentRedlineAccess const& rIDRA,
+namespace sw {
+
+bool IsFootnoteDeleted(IDocumentRedlineAccess const& rIDRA,
         SwTextFootnote const& rTextFootnote)
 {
     SwRedlineTable::size_type tmp;
@@ -44,6 +46,10 @@ static bool IsFootnoteDeleted(IDocumentRedlineAccess const& rIDRA,
         && *pRedline->GetPoint() != *pRedline->GetMark());
 }
 
+}
+
+using sw::IsFootnoteDeleted;
+
 bool CompareSwFootnoteIdxs::operator()(SwTextFootnote* const& lhs, SwTextFootnote* const& rhs) const
 {
     sal_uLong nIdxLHS = SwTextFootnote_GetIndex( lhs );
diff --git a/sw/source/core/edit/edattr.cxx b/sw/source/core/edit/edattr.cxx
index 34610c2b57e1..e80ef6f109e1 100644
--- a/sw/source/core/edit/edattr.cxx
+++ b/sw/source/core/edit/edattr.cxx
@@ -446,6 +446,8 @@ size_t SwEditShell::GetSeqFootnoteList( SwSeqFieldList& rList, bool bEndNotes )
 {
     rList.Clear();
 
+    IDocumentRedlineAccess & rIDRA(mxDoc->getIDocumentRedlineAccess());
+
     const size_t nFootnoteCnt = mxDoc->GetFootnoteIdxs().size();
     SwTextFootnote* pTextFootnote;
     for( size_t n = 0; n < nFootnoteCnt; ++n )
@@ -465,6 +467,12 @@ size_t SwEditShell::GetSeqFootnoteList( SwSeqFieldList& rList, bool bEndNotes )
 
             if( pTextNd )
             {
+                if (GetLayout()->IsHideRedlines()
+                    && sw::IsFootnoteDeleted(rIDRA, *pTextFootnote))
+                {
+                    continue;
+                }
+
                 OUString sText(rFootnote.GetViewNumStr(*mxDoc, GetLayout()));
                 if( !sText.isEmpty() )
                     sText += " ";
commit 76ea34e606b358f14f104e496f316fc616abd3f6
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Thu Nov 8 14:59:17 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw_redlinehide_3: adapt SwSetExpFieldType::GetSeqFieldList()
    
    Change-Id: Iea24b3823b648066e331dc5e9789c79662727a12

diff --git a/sw/inc/expfld.hxx b/sw/inc/expfld.hxx
index 6acf1a02c987..c82d1e0edab8 100644
--- a/sw/inc/expfld.hxx
+++ b/sw/inc/expfld.hxx
@@ -29,6 +29,7 @@
 class SfxPoolItem;
 class SwTextNode;
 class SwFrame;
+class SwRootFrame;
 struct SwPosition;
 class SwTextField;
 class SwDoc;
@@ -170,7 +171,7 @@ public:
 
     void   SetSeqRefNo( SwSetExpField& rField );
 
-    size_t GetSeqFieldList( SwSeqFieldList& rList );
+    size_t GetSeqFieldList(SwSeqFieldList& rList, SwRootFrame const* pLayout);
 
     /// Number sequence fields chapterwise if required.
     const OUString& GetDelimiter() const      { return m_sDelim; }
diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx
index e7b9aebfdeb0..964d9d5d150f 100644
--- a/sw/source/core/fields/expfld.cxx
+++ b/sw/source/core/fields/expfld.cxx
@@ -617,20 +617,25 @@ void SwSetExpFieldType::SetSeqRefNo( SwSetExpField& rField )
     rField.SetSeqNumber( n );
 }
 
-size_t SwSetExpFieldType::GetSeqFieldList( SwSeqFieldList& rList )
+size_t SwSetExpFieldType::GetSeqFieldList(SwSeqFieldList& rList,
+        SwRootFrame const*const pLayout)
 {
     rList.Clear();
 
+    IDocumentRedlineAccess const& rIDRA(GetDoc()->getIDocumentRedlineAccess());
+
     SwIterator<SwFormatField,SwFieldType> aIter( *this );
     for( SwFormatField* pF = aIter.First(); pF; pF = aIter.Next() )
     {
         const SwTextNode* pNd;
         if( pF->GetTextField() &&
             nullptr != ( pNd = pF->GetTextField()->GetpTextNode() ) &&
-            pNd->GetNodes().IsDocNodes() )
+            pNd->GetNodes().IsDocNodes()
+            && (!pLayout || !pLayout->IsHideRedlines()
+                || !sw::IsFieldDeletedInModel(rIDRA, *pF->GetTextField())))
         {
             SeqFieldLstElem aNew(
-                    pNd->GetExpandText(nullptr/*TODO*/),
+                    pNd->GetExpandText(pLayout),
                     static_cast<SwSetExpField*>(pF->GetField())->GetSeqNumber() );
             rList.InsertSort( aNew );
         }
diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx
index ba94bc890781..47f5cc9b1692 100644
--- a/sw/source/ui/fldui/fldref.cxx
+++ b/sw/source/ui/fldui/fldref.cxx
@@ -667,7 +667,7 @@ void SwFieldRefPage::UpdateSubType(const OUString& filterString)
                 if(IsFieldEdit())
                     sOldSel.clear();
 
-                const size_t nCnt = pType->GetSeqFieldList( aArr );
+                const size_t nCnt = pType->GetSeqFieldList(aArr, pSh->GetLayout());
                 for( size_t n = 0; n < nCnt; ++n )
                 {
                     bool isSubstring = MatchSubstring(aArr[ n ].sDlgEntry, filterString);
@@ -1085,7 +1085,8 @@ bool SwFieldRefPage::FillItemSet(SfxItemSet* )
                 nSubType = REF_SEQUENCEFLD;
                 aName = pType->GetName();
 
-                if (pType->GetSeqFieldList(aArr) && aArr.SeekEntry(aElem, &nPos))
+                if (pType->GetSeqFieldList(aArr, pSh->GetLayout())
+                    && aArr.SeekEntry(aElem, &nPos))
                 {
                     aVal = OUString::number( aArr[nPos].nSeqNo );
 
commit 11ab5aaeb9e50386b3cace4471fc2cd747420cce
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 14 12:41:23 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw_redlinehide_3: add second result to SwRefPageGetField
    
    With the old Hide implementation this actually would take the last
    set-field in the redline nodes array section to set the value at the
    start of the document, because there was no check for that; surely that
    was wrong...
    
    Change-Id: I63fb89ccf0067f1fe375226d6d04cafb6485c5d6

diff --git a/sw/inc/docufld.hxx b/sw/inc/docufld.hxx
index 03f2a1deebb9..f9ba0d6344b0 100644
--- a/sw/inc/docufld.hxx
+++ b/sw/inc/docufld.hxx
@@ -600,14 +600,16 @@ class SwRefPageGetFieldType : public SwFieldType
     SwDoc*          m_pDoc;
     sal_Int16       m_nNumberingType;
 
-    void UpdateField( SwTextField const * pTextField, SetGetExpFields const & rSetList );
+    void UpdateField(SwTextField const * pTextField,
+            SetGetExpFields const & rSetList, SwRootFrame const* pLayout);
+
 protected:
     /// overwritten to update all RefPageGet fields
     virtual void Modify( const SfxPoolItem*, const SfxPoolItem * ) override;
 public:
     SwRefPageGetFieldType( SwDoc* pDoc );
     virtual SwFieldType*    Copy() const override;
-    bool MakeSetList( SetGetExpFields& rTmpLst );
+    bool MakeSetList(SetGetExpFields& rTmpLst, SwRootFrame const* pLayout);
     SwDoc*  GetDoc() const                  { return m_pDoc; }
 };
 
@@ -615,15 +617,17 @@ public:
 class SwRefPageGetField : public SwField
 {
     OUString m_sText;
+    OUString m_sTextRLHidden; ///< hidden redlines
+
 public:
     SwRefPageGetField( SwRefPageGetFieldType*, sal_uInt32 nFormat );
 
     virtual OUString    ExpandImpl(SwRootFrame const* pLayout) const override;
     virtual std::unique_ptr<SwField> Copy() const override;
 
-    void SetText( const OUString& rText )      { m_sText = rText; }
+    void SetText(const OUString& rText, SwRootFrame const* pLayout);
 
-    void ChangeExpansion( const SwFrame* pFrame, const SwTextField* pField );
+    void ChangeExpansion(const SwFrame& rFrame, const SwTextField* pField);
     virtual bool        QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
     virtual bool        PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
 };
diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx
index 2f997bed40fe..859c5d4ddc02 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -2157,18 +2157,42 @@ SwFieldType* SwRefPageGetFieldType::Copy() const
 
 void SwRefPageGetFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
 {
-    // update all GetReference fields
-    if( !pNew && !pOld && HasWriterListeners() )
+    auto const ModifyImpl = [this](SwRootFrame const*const pLayout)
     {
         // first collect all SetPageRefFields
         SetGetExpFields aTmpLst;
-        if( MakeSetList( aTmpLst ) )
+        if (MakeSetList(aTmpLst, pLayout))
         {
             SwIterator<SwFormatField,SwFieldType> aIter( *this );
             for ( SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next() )
+            {
                     // update only the GetRef fields
                     if( pFormatField->GetTextField() )
-                        UpdateField( pFormatField->GetTextField(), aTmpLst );
+                        UpdateField(pFormatField->GetTextField(), aTmpLst, pLayout);
+            }
+        }
+    };
+
+    // update all GetReference fields
+    if( !pNew && !pOld && HasWriterListeners() )
+    {
+        SwRootFrame const* pLayout(nullptr);
+        SwRootFrame const* pLayoutRLHidden(nullptr);
+        for (SwRootFrame const*const pLay : m_pDoc->GetAllLayouts())
+        {
+            if (pLay->IsHideRedlines())
+            {
+                pLayoutRLHidden = pLay;
+            }
+            else
+            {
+                pLayout = pLay;
+            }
+        }
+        ModifyImpl(pLayout);
+        if (pLayoutRLHidden)
+        {
+            ModifyImpl(pLayoutRLHidden);
         }
     }
 
@@ -2176,14 +2200,19 @@ void SwRefPageGetFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem*
     NotifyClients( pOld, pNew );
 }
 
-bool SwRefPageGetFieldType::MakeSetList( SetGetExpFields& rTmpLst )
+bool SwRefPageGetFieldType::MakeSetList(SetGetExpFields& rTmpLst,
+        SwRootFrame const*const pLayout)
 {
+    IDocumentRedlineAccess const& rIDRA(m_pDoc->getIDocumentRedlineAccess());
     SwIterator<SwFormatField,SwFieldType> aIter(*m_pDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::RefPageSet));
     for ( SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next() )
     {
-            // update only the GetRef fields
-            const SwTextField* pTField = pFormatField->GetTextField();
-            if( pTField )
+        // update only the GetRef fields
+        const SwTextField* pTField = pFormatField->GetTextField();
+        if( pTField )
+        {
+            if (!pLayout || !pLayout->IsHideRedlines()
+                || !sw::IsFieldDeletedInModel(rIDRA, *pTField))
             {
                 const SwTextNode& rTextNd = pTField->GetTextNode();
 
@@ -2191,8 +2220,7 @@ bool SwRefPageGetFieldType::MakeSetList( SetGetExpFields& rTmpLst )
                 Point aPt;
                 std::pair<Point, bool> const tmp(aPt, false);
                 const SwContentFrame *const pFrame = rTextNd.getLayoutFrame(
-                    rTextNd.GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
-                    nullptr, &tmp);
+                    pLayout, nullptr, &tmp);
 
                 std::unique_ptr<SetGetExpField> pNew;
 
@@ -2218,16 +2246,18 @@ bool SwRefPageGetFieldType::MakeSetList( SetGetExpFields& rTmpLst )
 
                 rTmpLst.insert( std::move(pNew) );
             }
+        }
     }
 
     return !rTmpLst.empty();
 }
 
 void SwRefPageGetFieldType::UpdateField( SwTextField const * pTextField,
-                                        SetGetExpFields const & rSetList )
+                                        SetGetExpFields const & rSetList,
+                                        SwRootFrame const*const pLayout)
 {
     SwRefPageGetField* pGetField = const_cast<SwRefPageGetField*>(static_cast<const SwRefPageGetField*>(pTextField->GetFormatField().GetField()));
-    pGetField->SetText( OUString() );
+    pGetField->SetText( OUString(), pLayout );
 
     // then search the correct RefPageSet field
     SwTextNode* pTextNode = &pTextField->GetTextNode();
@@ -2251,10 +2281,9 @@ void SwRefPageGetFieldType::UpdateField( SwTextField const * pTextField,
                 Point aPt;
                 std::pair<Point, bool> const tmp(aPt, false);
                 const SwContentFrame *const pFrame = pTextNode->getLayoutFrame(
-                    pTextNode->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, &tmp);
+                    pLayout, nullptr, &tmp);
                 const SwContentFrame *const pRefFrame = pRefTextField->GetTextNode().getLayoutFrame(
-                    pRefTextField->GetTextNode().GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
-                    nullptr, &tmp);
+                    pLayout, nullptr, &tmp);
                 const SwPageFrame* pPgFrame = nullptr;
                 const short nDiff = ( pFrame && pRefFrame )
                         ?   (pPgFrame = pFrame->FindPageFrame())->GetPhyPageNum() -
@@ -2267,7 +2296,7 @@ void SwRefPageGetFieldType::UpdateField( SwTextField const * pTextField,
                                 : pPgFrame->GetPageDesc()->GetNumType().GetNumberingType() )
                         : static_cast<SvxNumType>(pGetField->GetFormat());
                 const short nPageNum = std::max<short>(0, pSetField->GetOffset() + nDiff);
-                pGetField->SetText( FormatNumber( nPageNum, nTmpFormat ) );
+                pGetField->SetText(FormatNumber(nPageNum, nTmpFormat), pLayout);
             }
         }
     }
@@ -2283,20 +2312,34 @@ SwRefPageGetField::SwRefPageGetField( SwRefPageGetFieldType* pTyp,
 {
 }
 
-OUString SwRefPageGetField::ExpandImpl(SwRootFrame const*const) const
+void SwRefPageGetField::SetText(const OUString& rText,
+        SwRootFrame const*const pLayout)
 {
-    return m_sText;
+    if (!pLayout || !pLayout->IsHideRedlines())
+    {
+        m_sText = rText;
+    }
+    if (!pLayout || pLayout->IsHideRedlines())
+    {
+        m_sTextRLHidden = rText;
+    }
+}
+
+OUString SwRefPageGetField::ExpandImpl(SwRootFrame const*const pLayout) const
+{
+    return pLayout && pLayout->IsHideRedlines() ? m_sTextRLHidden : m_sText;
 }
 
 std::unique_ptr<SwField> SwRefPageGetField::Copy() const
 {
     std::unique_ptr<SwRefPageGetField> pCpy(new SwRefPageGetField(
                         static_cast<SwRefPageGetFieldType*>(GetTyp()), GetFormat() ));
-    pCpy->SetText( m_sText );
+    pCpy->m_sText = m_sText;
+    pCpy->m_sTextRLHidden = m_sTextRLHidden;
     return std::unique_ptr<SwField>(pCpy.release());
 }
 
-void SwRefPageGetField::ChangeExpansion( const SwFrame* pFrame,
+void SwRefPageGetField::ChangeExpansion(const SwFrame& rFrame,
                                         const SwTextField* pField )
 {
     // only fields in Footer, Header, FootNote, Flys
@@ -2306,18 +2349,20 @@ void SwRefPageGetField::ChangeExpansion( const SwFrame* pFrame,
         pDoc->GetNodes().GetEndOfExtras().GetIndex() )
         return;
 
-    m_sText.clear();
+    SwRootFrame const& rLayout(*rFrame.getRootFrame());
+    OUString & rText(rLayout.IsHideRedlines() ? m_sTextRLHidden : m_sText);
+    rText.clear();
 
-    OSL_ENSURE( !pFrame->IsInDocBody(), "Flag incorrect, frame is in DocBody" );
+    OSL_ENSURE(!rFrame.IsInDocBody(), "Flag incorrect, frame is in DocBody");
 
     // collect all SetPageRefFields
     SetGetExpFields aTmpLst;
-    if( !pGetType->MakeSetList( aTmpLst ) )
+    if (!pGetType->MakeSetList(aTmpLst, &rLayout))
         return ;
 
     //  create index for determination of the TextNode
     SwPosition aPos( SwNodeIndex( pDoc->GetNodes() ) );
-    SwTextNode* pTextNode = const_cast<SwTextNode*>(GetBodyTextNode( *pDoc, aPos, *pFrame ));
+    SwTextNode* pTextNode = const_cast<SwTextNode*>(GetBodyTextNode(*pDoc, aPos, rFrame));
 
     // If no layout exists, ChangeExpansion is called for header and
     // footer lines via layout formatting without existing TextNode.
@@ -2338,11 +2383,11 @@ void SwRefPageGetField::ChangeExpansion( const SwFrame* pFrame,
     Point aPt;
     std::pair<Point, bool> const tmp(aPt, false);
     const SwContentFrame *const pRefFrame = pRefTextField->GetTextNode().getLayoutFrame(
-            pFrame->getRootFrame(), nullptr, &tmp);
+            &rLayout, nullptr, &tmp);
     if( pSetField->IsOn() && pRefFrame )
     {
         // determine the correct offset
-        const SwPageFrame* pPgFrame = pFrame->FindPageFrame();
+        const SwPageFrame* pPgFrame = rFrame.FindPageFrame();
         const short nDiff = pPgFrame->GetPhyPageNum() -
                             pRefFrame->FindPageFrame()->GetPhyPageNum() + 1;
 
@@ -2351,7 +2396,7 @@ void SwRefPageGetField::ChangeExpansion( const SwFrame* pFrame,
                             ? pPgFrame->GetPageDesc()->GetNumType().GetNumberingType()
                             : static_cast<SvxNumType>(pGetField->GetFormat());
         const short nPageNum = std::max<short>(0, pSetField->GetOffset() + nDiff);
-        pGetField->SetText( FormatNumber( nPageNum, nTmpFormat ) );
+        pGetField->SetText(FormatNumber(nPageNum, nTmpFormat), &rLayout);
     }
 }
 
@@ -2385,6 +2430,7 @@ bool SwRefPageGetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
         break;
         case FIELD_PROP_PAR1:
             rAny >>= m_sText;
+            m_sTextRLHidden = m_sText;
         break;
     default:
         assert(false);
diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index c4db3035c775..d0cad7b2569c 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -221,7 +221,7 @@ SwExpandPortion *SwTextFormatter::NewFieldPortion( SwTextFormatInfo &rInf,
         case SwFieldIds::RefPageGet:
             if( !bName && pSh && !pSh->Imp()->IsUpdateExpFields() )
             {
-                static_cast<SwRefPageGetField*>(pField)->ChangeExpansion(pFrame,
+                static_cast<SwRefPageGetField*>(pField)->ChangeExpansion(*pFrame,
                         static_txtattr_cast<SwTextField const*>(pHint));
             }
             {
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index 4fe387ba3b59..57a101b9f3eb 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -1594,7 +1594,7 @@ void SAL_CALL SwXTextField::attach(
                     static_cast<SwRefPageGetFieldType*>(pFieldType),
                     m_pImpl->m_pProps->nUSHORT1 );
             xField.reset(pRGField);
-            pRGField->SetText(m_pImpl->m_pProps->sPar1);
+            pRGField->SetText(m_pImpl->m_pProps->sPar1, nullptr);
         }
         break;
         case SwServiceType::FieldTypePageNum:
commit e83fe075468915aaa481bcf73a06ccec485517db
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Nov 13 18:53:50 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw_redlinehide_3: add second result to SwAuthorityField
    
    ... and SwAuthorityFieldType, which needs 2 lists of the fields because
    each citation may occur multiple times, so their order might change on
    deletions.
    
    This is for when there is a bibliography in the document, and it is set
    to IsSequence(), i.e.,
    insert Bibliography -> Number entries -> Sort by document position...
    
    Change-Id: Iba2c31267aeebacb779713567eeb0aa6659afefb

diff --git a/sw/inc/IDocumentFieldsAccess.hxx b/sw/inc/IDocumentFieldsAccess.hxx
index 617ea990614c..00ceff6fcc2a 100644
--- a/sw/inc/IDocumentFieldsAccess.hxx
+++ b/sw/inc/IDocumentFieldsAccess.hxx
@@ -39,6 +39,7 @@ enum class SwFieldIds : sal_uInt16;
 template <class T> class SwHashTable;
 struct HashStr;
 class SwRootFrame;
+class IDocumentRedlineAccess;
 
 namespace rtl { class OUString; }
 using rtl::OUString;
@@ -139,6 +140,11 @@ protected:
     virtual ~IDocumentFieldsAccess() {};
  };
 
+namespace sw {
+bool IsFieldDeletedInModel(IDocumentRedlineAccess const& rIDRA,
+        SwTextField const& rTextField);
+}
+
 #endif // INCLUDED_SW_INC_IDOCUMENTFIELDSACCESS_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/authfld.hxx b/sw/inc/authfld.hxx
index c6bab5ccf91c..72837f765c65 100644
--- a/sw/inc/authfld.hxx
+++ b/sw/inc/authfld.hxx
@@ -62,6 +62,7 @@ class SW_DLLPUBLIC SwAuthorityFieldType : public SwFieldType
     SwDoc*                  m_pDoc;
     SwAuthDataArr           m_DataArr;
     std::vector<sal_IntPtr> m_SequArr;
+    std::vector<sal_IntPtr> m_SequArrRLHidden; ///< hidden redlines
     SortKeyArr              m_SortKeyArr;
     sal_Unicode             m_cPrefix;
     sal_Unicode             m_cSuffix;
@@ -90,6 +91,7 @@ public:
     void                DelSequenceArray()
                         {
                             m_SequArr.clear();
+                            m_SequArrRLHidden.clear();
                         }
 
     const SwAuthEntry*  GetEntryByHandle(sal_IntPtr nHandle) const;
@@ -102,7 +104,7 @@ public:
     sal_uInt16          AppendField(const SwAuthEntry& rInsert);
     sal_IntPtr          GetHandle(sal_uInt16 nPos);
 
-    sal_uInt16          GetSequencePos(sal_IntPtr nHandle);
+    sal_uInt16          GetSequencePos(sal_IntPtr nHandle, SwRootFrame const* pLayout);
 
     bool            IsSequence() const      {return m_bIsSequence;}
     void                SetSequence(bool bSet)
@@ -142,20 +144,29 @@ public:
 
 };
 
+/** invariant for SwAuthorityField is that it is always registered at its
+    SwAuthorityFieldType via AddField()/RemoveField() & therefore has m_nHandle
+    set - but it's possible that multiple SwAuthorityField have the same
+    m_nHandle & so the number of instances is an upper bound on
+    SwAuthorityField::m_DataArr.size() - it's not clear to me if more than one
+    one of the instances with the same m_nHandle is actually in the document,
+    they're all cloned via CopyField()...
+ */
 class SwAuthorityField : public SwField
 {
     sal_IntPtr          m_nHandle;
     mutable sal_IntPtr  m_nTempSequencePos;
+    mutable sal_IntPtr  m_nTempSequencePosRLHidden; ///< hidden redlines
 
     virtual OUString    ExpandImpl(SwRootFrame const* pLayout) const override;
     virtual std::unique_ptr<SwField> Copy() const override;
 
 public:
     /// For internal use only, in general continue using ExpandField() instead.
-    OUString ConditionalExpandAuthIdentifier() const;
+    OUString ConditionalExpandAuthIdentifier(SwRootFrame const* pLayout) const;
 
     //To handle Citation
-    SW_DLLPUBLIC OUString ExpandCitation(ToxAuthorityField eField) const;
+    SW_DLLPUBLIC OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const* pLayout) const;
 
     SwAuthorityField(SwAuthorityFieldType* pType, const OUString& rFieldContents);
     SwAuthorityField(SwAuthorityFieldType* pType, sal_IntPtr nHandle);
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx
index e089f88ec7fb..efe6c60357ff 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -59,6 +59,21 @@
 
 using namespace ::com::sun::star::uno;
 
+namespace sw
+{
+    bool IsFieldDeletedInModel(IDocumentRedlineAccess const& rIDRA,
+            SwTextField const& rTextField)
+    {
+        SwRedlineTable::size_type tmp;
+        SwPosition const pos(rTextField.GetTextNode(),
+                rTextField.GetStart());
+        SwRangeRedline const*const pRedline(rIDRA.GetRedline(pos, &tmp));
+        return (pRedline
+            && pRedline->GetType() == nsRedlineType_t::REDLINE_DELETE
+            && *pRedline->GetPoint() != *pRedline->GetMark());
+    }
+}
+
 namespace
 {
     #if HAVE_FEATURE_DBCONNECTIVITY
@@ -94,13 +109,7 @@ namespace
             // for *any* layout...
             return true;
         }
-        SwRedlineTable::size_type tmp;
-        SwPosition const pos(const_cast<SwTextNode&>(rTextField.GetTextNode()),
-                rTextField.GetStart());
-        SwRangeRedline const*const pRedline(rIDRA.GetRedline(pos, &tmp));
-        return (pRedline
-            && pRedline->GetType() == nsRedlineType_t::REDLINE_DELETE
-            && *pRedline->GetPoint() != *pRedline->GetMark());
+        return sw::IsFieldDeletedInModel(rIDRA, rTextField);
     }
 
     void lcl_CalcField( SwDoc& rDoc, SwCalc& rCalc, const SetGetExpField& rSGEField,
diff --git a/sw/source/core/fields/authfld.cxx b/sw/source/core/fields/authfld.cxx
index 034a221e72e5..1e9c1ab6ed74 100644
--- a/sw/source/core/fields/authfld.cxx
+++ b/sw/source/core/fields/authfld.cxx
@@ -30,6 +30,7 @@
 #include <expfld.hxx>
 #include <pam.hxx>
 #include <cntfrm.hxx>
+#include <rootfrm.hxx>
 #include <tox.hxx>
 #include <txmsrt.hxx>
 #include <doctxm.hxx>
@@ -231,7 +232,8 @@ sal_IntPtr SwAuthorityFieldType::GetHandle(sal_uInt16 nPos)
     return 0;
 }
 
-sal_uInt16  SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle)
+sal_uInt16 SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle,
+        SwRootFrame const*const pLayout)
 {
     //find the field in a sorted array of handles,
 #if OSL_DEBUG_LEVEL > 0
@@ -241,7 +243,11 @@ sal_uInt16  SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle)
         DelSequenceArray();
     if(m_SequArr.empty())
     {
+        IDocumentRedlineAccess const& rIDRA(m_pDoc->getIDocumentRedlineAccess());
+        // sw_redlinehide: need 2 arrays because the sorting may be different,
+        // if multiple fields refer to the same entry and first one is deleted
         std::vector<std::unique_ptr<SwTOXSortTabBase>> aSortArr;
+        std::vector<std::unique_ptr<SwTOXSortTabBase>> aSortArrRLHidden;
         SwIterator<SwFormatField,SwFieldType> aIter( *this );
 
         SwTOXInternational aIntl(m_eLanguage, SwTOIOptions::NONE, m_sSortAlgorithm);
@@ -268,16 +274,21 @@ sal_uInt16  SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle)
             //body the directly available text node will be used
             if(!pTextNode)
                 pTextNode = &rFieldTextNode;
-            if (!pTextNode->GetText().isEmpty() &&
-                pTextNode->getLayoutFrame( rDoc.getIDocumentLayoutAccess().GetCurrentLayout() ) &&
-                pTextNode->GetNodes().IsDocNodes() )
+            if (pTextNode->GetText().isEmpty()
+                || !pTextNode->getLayoutFrame(rDoc.getIDocumentLayoutAccess().GetCurrentLayout())
+                || !pTextNode->GetNodes().IsDocNodes())
+            {
+                continue;
+            }
+            auto const InsertImpl = [&aIntl, pTextNode, pFormatField]
+                (std::vector<std::unique_ptr<SwTOXSortTabBase>> & rSortArr)
             {
                 std::unique_ptr<SwTOXAuthority> pNew(
                     new SwTOXAuthority(*pTextNode, *pFormatField, aIntl));
 
-                for(size_t i = 0; i < aSortArr.size(); ++i)
+                for (size_t i = 0; i < rSortArr.size(); ++i)
                 {
-                    SwTOXSortTabBase* pOld = aSortArr[i].get();
+                    SwTOXSortTabBase* pOld = rSortArr[i].get();
                     if(*pOld == *pNew)
                     {
                         //only the first occurrence in the document
@@ -285,7 +296,7 @@ sal_uInt16  SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle)
                         if(*pOld < *pNew)
                             pNew.reset();
                         else // remove the old content
-                            aSortArr.erase(aSortArr.begin() + i);
+                            rSortArr.erase(rSortArr.begin() + i);
                         break;
                     }
                 }
@@ -294,31 +305,41 @@ sal_uInt16  SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle)
                 {
                     size_t j {0};
 
-                    while(j < aSortArr.size())
+                    while (j < rSortArr.size())
                     {
-                        SwTOXSortTabBase* pOld = aSortArr[j].get();
+                        SwTOXSortTabBase* pOld = rSortArr[j].get();
                         if(*pNew < *pOld)
                             break;
                         ++j;
                     }
-                    aSortArr.insert(aSortArr.begin() + j, std::move(pNew));
+                    rSortArr.insert(rSortArr.begin() + j, std::move(pNew));
                 }
+            };
+            InsertImpl(aSortArr);
+            if (!sw::IsFieldDeletedInModel(rIDRA, *pTextField))
+            {
+                InsertImpl(aSortArrRLHidden);
             }
         }
 
         for(auto & pBase : aSortArr)
         {
-            SwTOXSortTabBase& rBase = *pBase;
-            SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(rBase).GetFieldFormat();
+            SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
             SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
             m_SequArr.push_back(pAField->GetHandle());
         }
-        aSortArr.clear();
+        for (auto & pBase : aSortArrRLHidden)
+        {
+            SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
+            SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
+            m_SequArrRLHidden.push_back(pAField->GetHandle());
+        }
     }
     //find nHandle
-    for(std::vector<sal_IntPtr>::size_type i = 0; i < m_SequArr.size(); ++i)
+    auto const& rSequArr(pLayout && pLayout->IsHideRedlines() ? m_SequArrRLHidden : m_SequArr);
+    for (std::vector<sal_IntPtr>::size_type i = 0; i < rSequArr.size(); ++i)
     {
-        if(m_SequArr[i] == nHandle)
+        if (rSequArr[i] == nHandle)
         {
             return i + 1;
         }
@@ -491,17 +512,19 @@ void SwAuthorityFieldType::SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey  const
 
 SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
                                     const OUString& rFieldContents )
-    : SwField(pInitType),
-    m_nTempSequencePos( -1 )
+    : SwField(pInitType)
+    , m_nTempSequencePos( -1 )
+    , m_nTempSequencePosRLHidden( -1 )
 {
     m_nHandle = pInitType->AddField( rFieldContents );
 }
 
 SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
                                                 sal_IntPtr nSetHandle )
-    : SwField( pInitType ),
-    m_nHandle( nSetHandle ),
-    m_nTempSequencePos( -1 )
+    : SwField( pInitType )
+    , m_nHandle( nSetHandle )
+    , m_nTempSequencePos( -1 )
+    , m_nTempSequencePosRLHidden( -1 )
 {
     pInitType->AddField( m_nHandle );
 }
@@ -511,12 +534,13 @@ SwAuthorityField::~SwAuthorityField()
     static_cast<SwAuthorityFieldType* >(GetTyp())->RemoveField(m_nHandle);
 }
 
-OUString SwAuthorityField::ExpandImpl(SwRootFrame const*const) const
+OUString SwAuthorityField::ExpandImpl(SwRootFrame const*const pLayout) const
 {
-    return ConditionalExpandAuthIdentifier();
+    return ConditionalExpandAuthIdentifier(pLayout);
 }
 
-OUString SwAuthorityField::ConditionalExpandAuthIdentifier() const
+OUString SwAuthorityField::ConditionalExpandAuthIdentifier(
+        SwRootFrame const*const pLayout) const
 {
     SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
     OUString sRet;
@@ -525,10 +549,12 @@ OUString SwAuthorityField::ConditionalExpandAuthIdentifier() const
 
     if( pAuthType->IsSequence() )
     {
+        sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
+                ? m_nTempSequencePosRLHidden : m_nTempSequencePos);
        if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked())
-           m_nTempSequencePos = pAuthType->GetSequencePos( m_nHandle );
-       if( m_nTempSequencePos >= 0 )
-           sRet += OUString::number( m_nTempSequencePos );
+            rnTempSequencePos = pAuthType->GetSequencePos(m_nHandle, pLayout);
+        if (0 <= rnTempSequencePos)
+            sRet += OUString::number(rnTempSequencePos);
     }
     else
     {
@@ -542,17 +568,20 @@ OUString SwAuthorityField::ConditionalExpandAuthIdentifier() const
     return sRet;
 }
 
-OUString SwAuthorityField::ExpandCitation(ToxAuthorityField eField) const
+OUString SwAuthorityField::ExpandCitation(ToxAuthorityField eField,
+        SwRootFrame const*const pLayout) const
 {
     SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
     OUString sRet;
 
     if( pAuthType->IsSequence() )
     {
+        sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
+                ? m_nTempSequencePosRLHidden : m_nTempSequencePos);
        if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked())
-           m_nTempSequencePos = pAuthType->GetSequencePos( m_nHandle );
-       if( m_nTempSequencePos >= 0 )
-           sRet += OUString::number( m_nTempSequencePos );
+            rnTempSequencePos = pAuthType->GetSequencePos(m_nHandle, pLayout);
+        if (0 <= rnTempSequencePos)
+            sRet += OUString::number(rnTempSequencePos);
     }
     else
     {
diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx
index 7be1be2d0f11..a5008b4c4e3a 100644
--- a/sw/source/core/fields/fldbas.cxx
+++ b/sw/source/core/fields/fldbas.cxx
@@ -418,7 +418,7 @@ SwField::ExpandField(bool const bCached, SwRootFrame const*const pLayout) const
             if (GetTypeId() == TYP_AUTHORITY)
             {
                 const SwAuthorityField* pAuthorityField = static_cast<const SwAuthorityField*>(this);
-                m_Cache = pAuthorityField->ConditionalExpandAuthIdentifier();
+                m_Cache = pAuthorityField->ConditionalExpandAuthIdentifier(pLayout);
             }
             else
                 m_Cache = ExpandImpl(pLayout);
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 796c6e621f8e..756cf145443a 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1940,7 +1940,7 @@ void DocxAttributeOutput::EndField_Impl( const SwTextNode* pNode, sal_Int32 nPos
         if(rInfos.eType == ww::eCITATION)
         {
             sExpand = static_cast<SwAuthorityField const*>(rInfos.pField.get())
-                        ->ExpandCitation(AUTH_FIELD_TITLE);
+                        ->ExpandCitation(AUTH_FIELD_TITLE, nullptr);
         }
         else
         {
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index cbe0fa6ac810..3deb8c137891 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -2993,7 +2993,7 @@ void AttributeOutputBase::TextField( const SwFormatField& rField )
     case SwFieldIds::TableOfAuthorities:
     {
         OUString sRet(static_cast<SwAuthorityField const*>(pField)
-                        ->ExpandCitation(AUTH_FIELD_IDENTIFIER));
+                        ->ExpandCitation(AUTH_FIELD_IDENTIFIER, nullptr));
         // FIXME: DomainMapper_Impl::CloseFieldCommand() stuffs fully formed
         // field instructions in here, but if the field doesn't originate
         // from those filters it won't have that
commit 57f358f1ac4f3e05fcdf54326388ba8a19f0f2b3
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Nov 13 11:00:33 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    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

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 T> 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<HashStr> & rTable, const SetGetExpField& rToThisField) = 0;
+    virtual void FieldsToExpand(SwHashTable<HashStr> & 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<SwTableSortBoxes> 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<SwField> 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<SwField> 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 <IDocumentUndoRedo.hxx>
 #include <IDocumentState.hxx>
 #include <IDocumentLayoutAccess.hxx>
+#include <IDocumentRedlineAccess.hxx>
+#include <redline.hxx>
+#include <rootfrm.hxx>
 #include <dbmgr.hxx>
 #include <chpfld.hxx>
 #include <dbfld.hxx>
@@ -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<SwTextNode&>(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<const SwSetExpField*>(pField)->GetValue() );
+                aValue.PutDouble( static_cast<const SwSetExpField*>(pField)->GetValue(pLayout) );
             else
                 // Extension to calculate with Strings
-                aValue.PutString( static_cast<const SwSetExpField*>(pField)->GetExpStr() );
+                aValue.PutString( static_cast<const SwSetExpField*>(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<SwTableFormulaUpdate*>(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<Point, bool> 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<Point, bool> 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<SwSetExpFieldType const*, SwTextNode const*> SetExpOutlineNodeMap;
 
     for (std::unique_ptr<SetGetExpField> 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<SwFormatField*>(&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<SwSetExpFieldType*>(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<HashStr> & 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<HashStr> & 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<HashStr> & rHashTable,
 
                 // #i3141# - update expression of field as in method
                 // <SwDoc::UpdateExpFields(..)> for string/text fields
-                pSField->ChgExpStr( aNew );
+                pSField->ChgExpStr(aNew, &rLayout);
 
                 // look up the field's name
                 aNew = static_cast<SwSetExpFieldType*>(pSField->GetTyp())->GetSetRefName();
@@ -1531,11 +1633,11 @@ void DocumentFieldsManager::FieldsToExpand( SwHashTable<HashStr> & rHashTable,
                 SwHash* pFnd = rHashTable.Find( aNew, &nPos );
                 if( pFnd )
                     // modify entry in the hash table
-                    static_cast<HashStr*>(pFnd)->aSetStr = pSField->GetExpStr();
+                    static_cast<HashStr*>(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<const SwSetExpField*>(pField)->GetValue();
+                nRet = static_cast<const SwSetExpField*>(pField)->GetValue(rCalcPara.m_pLayout);
                 break;
             case SwFieldIds::User:
                 nRet = static_cast<const SwUserField*>(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<SwField> SwGetExpField::Copy() const
     std::unique_ptr<SwGetExpField> pTmp(new SwGetExpField(static_cast<SwGetExpFieldType*>(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<HashStr> 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<SwValueFieldType*>(GetTyp())->ExpandValue(
-                                GetValue(), GetFormat(), GetLanguage());
+        rExpand = static_cast<SwValueFieldType*>(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<double>(rAny));
+        m_fValueRLHidden = *o3tl::doAccess<double>(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( "<SwSetExpFieldType::SetChapter(..)> - text node with numbering rule, but without number. This is a serious defect" );
+                OSL_ENSURE(pTextNd->GetNum(nullptr), "<SwSetExpFieldType::SetChapter(..)> - 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<SwField> SwSetExpField::Copy() const
     std::unique_ptr<SwSetExpField> pTmp(new SwSetExpField(static_cast<SwSetExpFieldType*>(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<SvxNumType>(GetFormat()), GetLanguage());
+        }
+        else
+        {
+            msExpandRLHidden = static_cast<SwValueFieldType*>(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<SwValueFieldType*>(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<HashStr>& rTable, const SetGetExpField& rToThisField) override;
+    virtual void FieldsToCalc(SwCalc& rCalc, const SetGetExpField& rToThisField, SwRootFrame const* pLayout) override;
+    virtual void FieldsToExpand(SwHashTable<HashStr>& 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<SwSetExpFieldType*>(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;
 }
commit 5e622d1bf3491bce79e2e1831b30716abb924750
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Nov 12 14:39:08 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw: booleans are hard, let's go shopping
    
    Has been like that since CVS import...
    
    Change-Id: Iefa49407de90bace5eea2f86170ba8cd29b1cfe7

diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx
index 0a3a8a47a8c3..f24fd9688238 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -1578,7 +1578,7 @@ void DocumentFieldsManager::SetNewFieldLst(bool bFlag)
 
 void DocumentFieldsManager::InsDelFieldInFieldLst( bool bIns, const SwTextField& rField )
 {
-    if( !mbNewFieldLst || !m_rDoc.IsInDtor() )
+    if (!mbNewFieldLst && !m_rDoc.IsInDtor())
         mpUpdateFields->InsDelFieldInFieldLst( bIns, rField );
 }
 
commit 8e1e61c49e28fa3d0a76ebf02a6cb61d6bd3479b
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Nov 12 13:36:49 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw: flag check looks incorrect in SwDocUpdateField::MakeFieldList()
    
    Change-Id: Ifebbaa6ef21ac518f62a726dadaceb97fd5e446b

diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 4a7a80d23129..42d47a4cc0e6 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -801,7 +801,8 @@ void SwDocUpdateField::InsDelFieldInFieldLst( bool bIns, const SwTextField& rFie
 
 void SwDocUpdateField::MakeFieldList( SwDoc& rDoc, bool bAll, int eGetMode )
 {
-    if (!m_pFieldSortList || bAll || !(eGetMode & m_nFieldListGetMode)
+    if (!m_pFieldSortList || bAll
+        || ((eGetMode & m_nFieldListGetMode) != eGetMode)
         || rDoc.GetNodes().Count() != m_nNodes)
     {
         MakeFieldList_( rDoc, eGetMode );
commit bcddccbfe0d864c6276d70a71ecd72a9bc32c032
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Nov 12 13:23:20 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Nov 14 18:42:15 2018 +0100

    sw: prefix members of SwDocUpdateField & trivial cleanups
    
    Change-Id: Ied1e89279e3071e0c6c1b414bb23044e6439258c

diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx
index efb42e357632..0a3a8a47a8c3 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -146,7 +146,7 @@ namespace sw
 
 DocumentFieldsManager::DocumentFieldsManager( SwDoc& i_rSwdoc ) : m_rDoc( i_rSwdoc ),
                                                                   mbNewFieldLst(true),
-                                                                  mpUpdateFields( new SwDocUpdateField( &m_rDoc ) ),
+                                                                  mpUpdateFields(new SwDocUpdateField(m_rDoc)),
                                                                   mpFieldTypes( new SwFieldTypes ),
                                                                   mnLockExpField( 0 )
 {
@@ -849,7 +849,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp
     mpUpdateFields->MakeFieldList( m_rDoc, true, GETFLD_ALL );
     mbNewFieldLst = false;
 
-    if( mpUpdateFields->GetSortLst()->empty() )
+    if (mpUpdateFields->GetSortList()->empty())
     {
         if( bUpdRefFields )
             UpdateRefFields();
@@ -927,9 +927,9 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp
 
     std::unordered_map<SwSetExpFieldType const*, SwTextNode const*> SetExpOutlineNodeMap;
 
-    for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin(); it != mpUpdateFields->GetSortLst()->end(); ++it )
+    for (std::unique_ptr<SetGetExpField> const& it : *mpUpdateFields->GetSortList())
     {
-        SwSection* pSect = const_cast<SwSection*>((*it)->GetSection());
+        SwSection* pSect = const_cast<SwSection*>(it->GetSection());
         if( pSect )
         {
             SwSbxValue aValue = aCalc.Calculate(
@@ -960,7 +960,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp
             continue;
         }
 
-        SwTextField* pTextField = const_cast<SwTextField*>((*it)->GetTextField());
+        SwTextField* pTextField = const_cast<SwTextField*>(it->GetTextField());
         if( !pTextField )
         {
             OSL_ENSURE( false, "what's wrong now'" );
@@ -1126,7 +1126,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp
                         if( MAXLEVEL > nLvl )
                         {
                             // test if the Number needs to be updated
-                            pSeqNd = m_rDoc.GetNodes()[ (*it)->GetNode() ];
+                            pSeqNd = m_rDoc.GetNodes()[ it->GetNode() ];
 
                             const SwTextNode* pOutlNd = pSeqNd->
                                     FindOutlineNodeOfLevel( nLvl );
@@ -1211,13 +1211,12 @@ sal_Int32 DocumentFieldsManager::GetRecordsPerDocument() const
     sal_Int32 nRecords = 1;
 
     mpUpdateFields->MakeFieldList( m_rDoc, true, GETFLD_ALL );
-    if( mpUpdateFields->GetSortLst()->empty() )
+    if (mpUpdateFields->GetSortList()->empty())
         return nRecords;
 
-    for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin();
-        it != mpUpdateFields->GetSortLst()->end(); ++it )
+    for (std::unique_ptr<SetGetExpField> const& it : *mpUpdateFields->GetSortList())
     {
-        const SwTextField *pTextField = (*it)->GetTextField();
+        const SwTextField *pTextField = it->GetTextField();
         if( !pTextField )
             continue;
 
@@ -1443,13 +1442,15 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, const SetGetExpField& r
     pMgr->CloseAll(false);
 #endif
 
-    if( !mpUpdateFields->GetSortLst()->empty() )
+    if (!mpUpdateFields->GetSortList()->empty())
     {
         SetGetExpFields::const_iterator const itLast =
-            mpUpdateFields->GetSortLst()->upper_bound(
+            mpUpdateFields->GetSortList()->upper_bound(
                 &rToThisField);
-        for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin(); it != itLast; ++it )
+        for (auto it = mpUpdateFields->GetSortList()->begin(); it != itLast; ++it)
+        {
             lcl_CalcField( m_rDoc, rCalc, **it, pMgr );
+        }
     }
 #if HAVE_FEATURE_DBCONNECTIVITY
     pMgr->CloseAll(false);
@@ -1469,8 +1470,8 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_
     pMgr->CloseAll(false);
 #endif
 
-    for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin();
-        it != mpUpdateFields->GetSortLst()->end() &&
+    for(auto it = mpUpdateFields->GetSortList()->begin();
+        it != mpUpdateFields->GetSortList()->end() &&
         ( (*it)->GetNode() < nLastNd ||
           ( (*it)->GetNode() == nLastNd && (*it)->GetContent() <= nLastCnt )
         );
@@ -1493,13 +1494,13 @@ void DocumentFieldsManager::FieldsToExpand( SwHashTable<HashStr> & rHashTable,
 
     // Hash table for all string replacements is filled on-the-fly.
     // Try to fabricate an uneven number.
-    sal_uInt16 nTableSize = (( mpUpdateFields->GetSortLst()->size() / 7 ) + 1 ) * 7;
+    sal_uInt16 nTableSize = ((mpUpdateFields->GetSortList()->size() / 7) + 1) * 7;
     rHashTable.resize(nTableSize);
 
     SetGetExpFields::const_iterator const itLast =
-        mpUpdateFields->GetSortLst()->upper_bound(&rToThisField);
+        mpUpdateFields->GetSortList()->upper_bound(&rToThisField);
 
-    for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin(); it != itLast; ++it )
+    for (auto it = mpUpdateFields->GetSortList()->begin(); it != itLast; ++it)
     {
         const SwTextField* pTextField = (*it)->GetTextField();
         if( !pTextField )
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 3affc7cdd901..4a7a80d23129 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -775,11 +775,11 @@ void SwDocUpdateField::InsDelFieldInFieldLst( bool bIns, const SwTextField& rFie
     }
 
     SetFieldsDirty( true );
-    if( !pFieldSortLst )
+    if (!m_pFieldSortList)
     {
         if( !bIns )             // if list is present and deleted
             return;             // don't do a thing
-        pFieldSortLst.reset(new SetGetExpFields);
+        m_pFieldSortList.reset(new SetGetExpFields);
     }
 
     if( bIns )      // insert anew:
@@ -788,26 +788,30 @@ void SwDocUpdateField::InsDelFieldInFieldLst( bool bIns, const SwTextField& rFie
     {
         // look up via the pTextField pointer. It is a sorted list, but it's sorted by node
         // position. Until this is found, the search for the pointer is already done.
-        for( SetGetExpFields::size_type n = 0; n < pFieldSortLst->size(); ++n )
-            if( &rField == (*pFieldSortLst)[ n ]->GetPointer() )
+        for (SetGetExpFields::size_type n = 0; n < m_pFieldSortList->size(); ++n)
+        {
+            if (&rField == (*m_pFieldSortList)[n]->GetPointer())
             {
-                pFieldSortLst->erase(n);
+                m_pFieldSortList->erase(n);
                 n--; // one field can occur multiple times
             }
+        }
     }
 }
 
 void SwDocUpdateField::MakeFieldList( SwDoc& rDoc, bool bAll, int eGetMode )
 {
-    if( !pFieldSortLst || bAll || !( eGetMode & nFieldLstGetMode ) ||
-        rDoc.GetNodes().Count() != nNodes )
+    if (!m_pFieldSortList || bAll || !(eGetMode & m_nFieldListGetMode)
+        || rDoc.GetNodes().Count() != m_nNodes)
+    {
         MakeFieldList_( rDoc, eGetMode );
+    }
 }
 
 void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int eGetMode )
 {
     // new version: walk all fields of the attribute pool
-    pFieldSortLst.reset(new SetGetExpFields);
+    m_pFieldSortList.reset(new SetGetExpFields);
 
     // consider and unhide sections
     //     with hide condition, only in mode GETFLD_ALL (<eGetMode == GETFLD_ALL>)
@@ -820,7 +824,7 @@ void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int eGetMode )
     //         the hide conditions of section have to be updated.

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list