[Libreoffice-commits] core.git: Branch 'distro/lhm/libreoffice-6-1+backports' - 300 commits - include/o3tl sw/CppunitTest_sw_layoutwriter.mk sw/inc sw/qa sw/source sw/uiconfig sw/UIConfig_swriter.mk xmloff/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Jan 11 16:38:00 UTC 2019


 include/o3tl/strong_int.hxx                               |    9 
 sw/CppunitTest_sw_layoutwriter.mk                         |    5 
 sw/UIConfig_swriter.mk                                    |    1 
 sw/inc/IDocumentContentOperations.hxx                     |    8 
 sw/inc/IDocumentFieldsAccess.hxx                          |   11 
 sw/inc/IDocumentListItems.hxx                             |    8 
 sw/inc/IDocumentOutlineNodes.hxx                          |    5 
 sw/inc/SwNodeNum.hxx                                      |    7 
 sw/inc/ToxTextGenerator.hxx                               |   27 
 sw/inc/authfld.hxx                                        |   19 
 sw/inc/calbck.hxx                                         |    2 
 sw/inc/cellfml.hxx                                        |    4 
 sw/inc/chpfld.hxx                                         |   38 
 sw/inc/crsrsh.hxx                                         |   44 
 sw/inc/dbfld.hxx                                          |   12 
 sw/inc/ddefld.hxx                                         |    2 
 sw/inc/doc.hxx                                            |   53 
 sw/inc/docufld.hxx                                        |   45 
 sw/inc/editsh.hxx                                         |    2 
 sw/inc/expfld.hxx                                         |  137 
 sw/inc/fldbas.hxx                                         |    9 
 sw/inc/flddat.hxx                                         |    2 
 sw/inc/flddropdown.hxx                                    |    2 
 sw/inc/fmtftn.hxx                                         |    9 
 sw/inc/fmtinfmt.hxx                                       |    5 
 sw/inc/ftnidx.hxx                                         |   17 
 sw/inc/hints.hxx                                          |   24 
 sw/inc/list.hxx                                           |    1 
 sw/inc/modeltoviewhelper.hxx                              |    3 
 sw/inc/ndarr.hxx                                          |    3 
 sw/inc/ndgrf.hxx                                          |    3 
 sw/inc/ndole.hxx                                          |    4 
 sw/inc/ndtxt.hxx                                          |   51 
 sw/inc/node.hxx                                           |   31 
 sw/inc/pam.hxx                                            |   31 
 sw/inc/postithelper.hxx                                   |    5 
 sw/inc/redline.hxx                                        |   10 
 sw/inc/reffld.hxx                                         |   39 
 sw/inc/shellio.hxx                                        |    1 
 sw/inc/swcrsr.hxx                                         |   67 
 sw/inc/tox.hxx                                            |    3 
 sw/inc/txtftn.hxx                                         |    8 
 sw/inc/unocrsrhelper.hxx                                  |    3 
 sw/inc/usrfld.hxx                                         |    2 
 sw/qa/core/macros-test.cxx                                |    4 
 sw/qa/core/test_ToxTextGenerator.cxx                      |   30 
 sw/qa/core/uwriter.cxx                                    |   93 
 sw/qa/extras/layout/data/redline_charatr.fodt             |  164 +
 sw/qa/extras/layout/data/redline_footnotes.odt            |binary
 sw/qa/extras/layout/data/redline_sections.fodt            |  110 
 sw/qa/extras/layout/data/redline_table.fodt               |  128 
 sw/qa/extras/layout/layout.cxx                            | 2191 ++++++++++++++
 sw/qa/extras/tiledrendering/tiledrendering.cxx            |   18 
 sw/qa/extras/uiwriter/uiwriter.cxx                        |  136 
 sw/qa/extras/uiwriter/uiwriter2.cxx                       |  101 
 sw/qa/unit/data/sw-dialogs-test.txt                       |    1 
 sw/qa/unit/data/sw-dialogs-test_2.txt                     |    1 
 sw/source/core/SwNumberTree/SwNodeNum.cxx                 |   23 
 sw/source/core/access/accdoc.cxx                          |   56 
 sw/source/core/access/accfootnote.cxx                     |    4 
 sw/source/core/access/acchyperlink.cxx                    |   92 
 sw/source/core/access/acchyperlink.hxx                    |   19 
 sw/source/core/access/accmap.cxx                          |   53 
 sw/source/core/access/accpara.cxx                         |  653 +---
 sw/source/core/access/accpara.hxx                         |   14 
 sw/source/core/access/accportions.cxx                     |  180 -
 sw/source/core/access/accportions.hxx                     |   62 
 sw/source/core/access/textmarkuphelper.cxx                |  117 
 sw/source/core/access/textmarkuphelper.hxx                |    8 
 sw/source/core/attr/calbck.cxx                            |    2 
 sw/source/core/attr/hints.cxx                             |   10 
 sw/source/core/crsr/callnk.cxx                            |    7 
 sw/source/core/crsr/crbm.cxx                              |   59 
 sw/source/core/crsr/crsrsh.cxx                            |  245 +
 sw/source/core/crsr/crstrvl.cxx                           |  187 -
 sw/source/core/crsr/crstrvl1.cxx                          |   64 
 sw/source/core/crsr/findattr.cxx                          |  303 +
 sw/source/core/crsr/findcoll.cxx                          |   27 
 sw/source/core/crsr/findfmt.cxx                           |   45 
 sw/source/core/crsr/findtxt.cxx                           |  743 +++-
 sw/source/core/crsr/pam.cxx                               |   60 
 sw/source/core/crsr/swcrsr.cxx                            |  467 +-
 sw/source/core/crsr/trvlfnfl.cxx                          |   15 
 sw/source/core/crsr/trvltbl.cxx                           |    5 
 sw/source/core/crsr/viscrs.cxx                            |   16 
 sw/source/core/doc/CntntIdxStore.cxx                      |   36 
 sw/source/core/doc/DocumentContentOperationsManager.cxx   |  453 ++
 sw/source/core/doc/DocumentFieldsManager.cxx              |  237 +
 sw/source/core/doc/DocumentLinksAdministrationManager.cxx |    2 
 sw/source/core/doc/DocumentListItemsManager.cxx           |   19 
 sw/source/core/doc/DocumentOutlineNodesManager.cxx        |   62 
 sw/source/core/doc/DocumentRedlineManager.cxx             |  255 +
 sw/source/core/doc/doc.cxx                                |   11 
 sw/source/core/doc/doccomp.cxx                            |    6 
 sw/source/core/doc/docdesc.cxx                            |    2 
 sw/source/core/doc/docedt.cxx                             |   14 
 sw/source/core/doc/docfld.cxx                             |   66 
 sw/source/core/doc/docfly.cxx                             |    8 
 sw/source/core/doc/docfmt.cxx                             |   46 
 sw/source/core/doc/docftn.cxx                             |   14 
 sw/source/core/doc/docglbl.cxx                            |    2 
 sw/source/core/doc/docnum.cxx                             |  486 ++-
 sw/source/core/doc/docredln.cxx                           |   81 
 sw/source/core/doc/docsort.cxx                            |    2 
 sw/source/core/doc/doctxm.cxx                             |  231 -
 sw/source/core/doc/ftnidx.cxx                             |  250 +
 sw/source/core/doc/list.cxx                               |   56 
 sw/source/core/doc/tblrwcl.cxx                            |    2 
 sw/source/core/docnode/ndcopy.cxx                         |    4 
 sw/source/core/docnode/ndsect.cxx                         |   23 
 sw/source/core/docnode/ndtbl.cxx                          |   56 
 sw/source/core/docnode/ndtbl1.cxx                         |    6 
 sw/source/core/docnode/node.cxx                           |  120 
 sw/source/core/docnode/node2lay.cxx                       |   33 
 sw/source/core/docnode/nodes.cxx                          |   42 
 sw/source/core/docnode/section.cxx                        |    2 
 sw/source/core/draw/dcontact.cxx                          |    8 
 sw/source/core/edit/acorrect.cxx                          |  175 -
 sw/source/core/edit/autofmt.cxx                           | 1043 +++---
 sw/source/core/edit/edatmisc.cxx                          |   10 
 sw/source/core/edit/edattr.cxx                            |   92 
 sw/source/core/edit/eddel.cxx                             |    6 
 sw/source/core/edit/edfcol.cxx                            |    9 
 sw/source/core/edit/edfld.cxx                             |   11 
 sw/source/core/edit/edfmt.cxx                             |    2 
 sw/source/core/edit/edglss.cxx                            |    2 
 sw/source/core/edit/editsh.cxx                            |   73 
 sw/source/core/edit/edlingu.cxx                           |   20 
 sw/source/core/edit/ednumber.cxx                          |  159 -
 sw/source/core/edit/edsect.cxx                            |    3 
 sw/source/core/edit/edtox.cxx                             |    8 
 sw/source/core/edit/edws.cxx                              |   14 
 sw/source/core/fields/authfld.cxx                         |  100 
 sw/source/core/fields/cellfml.cxx                         |   20 
 sw/source/core/fields/chpfld.cxx                          |  108 
 sw/source/core/fields/dbfld.cxx                           |   10 
 sw/source/core/fields/ddefld.cxx                          |    2 
 sw/source/core/fields/docufld.cxx                         |  133 
 sw/source/core/fields/expfld.cxx                          |  325 +-
 sw/source/core/fields/fldbas.cxx                          |    9 
 sw/source/core/fields/flddat.cxx                          |    2 
 sw/source/core/fields/flddropdown.cxx                     |    2 
 sw/source/core/fields/fldlst.cxx                          |   40 
 sw/source/core/fields/macrofld.cxx                        |    2 
 sw/source/core/fields/postithelper.cxx                    |    8 
 sw/source/core/fields/reffld.cxx                          |  391 +-
 sw/source/core/fields/scrptfld.cxx                        |    2 
 sw/source/core/fields/tblcalc.cxx                         |    4 
 sw/source/core/fields/usrfld.cxx                          |    2 
 sw/source/core/frmedt/fecopy.cxx                          |    6 
 sw/source/core/frmedt/fedesc.cxx                          |    8 
 sw/source/core/frmedt/fefly1.cxx                          |   17 
 sw/source/core/frmedt/feshview.cxx                        |    6 
 sw/source/core/frmedt/fetab.cxx                           |    3 
 sw/source/core/frmedt/fews.cxx                            |    9 
 sw/source/core/frmedt/tblsel.cxx                          |   59 
 sw/source/core/graphic/ndgrf.cxx                          |    9 
 sw/source/core/inc/DocumentContentOperationsManager.hxx   |   12 
 sw/source/core/inc/DocumentFieldsManager.hxx              |    6 
 sw/source/core/inc/DocumentListItemsManager.hxx           |    6 
 sw/source/core/inc/DocumentOutlineNodesManager.hxx        |    3 
 sw/source/core/inc/DocumentRedlineManager.hxx             |   13 
 sw/source/core/inc/SwPortionHandler.hxx                   |    2 
 sw/source/core/inc/TextFrameIndex.hxx                     |   10 
 sw/source/core/inc/UndoAttribute.hxx                      |    3 
 sw/source/core/inc/acorrect.hxx                           |    3 
 sw/source/core/inc/docfld.hxx                             |   30 
 sw/source/core/inc/doctxm.hxx                             |   30 
 sw/source/core/inc/fieldhint.hxx                          |   14 
 sw/source/core/inc/frminf.hxx                             |    6 
 sw/source/core/inc/frmtool.hxx                            |   31 
 sw/source/core/inc/ftnboss.hxx                            |    2 
 sw/source/core/inc/ftnfrm.hxx                             |   10 
 sw/source/core/inc/mvsave.hxx                             |   12 
 sw/source/core/inc/node2lay.hxx                           |   21 
 sw/source/core/inc/pamtyp.hxx                             |   39 
 sw/source/core/inc/rootfrm.hxx                            |    8 
 sw/source/core/inc/txmsrt.hxx                             |   54 
 sw/source/core/inc/txtfrm.hxx                             |   87 
 sw/source/core/inc/wrong.hxx                              |   29 
 sw/source/core/layout/atrfrm.cxx                          |   41 
 sw/source/core/layout/flycnt.cxx                          |    3 
 sw/source/core/layout/flylay.cxx                          |    2 
 sw/source/core/layout/frmtool.cxx                         |  238 +
 sw/source/core/layout/ftnfrm.cxx                          |   48 
 sw/source/core/layout/laycache.cxx                        |   13 
 sw/source/core/layout/layhelp.hxx                         |    1 
 sw/source/core/layout/newfrm.cxx                          |    3 
 sw/source/core/layout/pagedesc.cxx                        |    9 
 sw/source/core/layout/ssfrm.cxx                           |   24 
 sw/source/core/layout/trvlfrm.cxx                         |   17 
 sw/source/core/layout/wsfrm.cxx                           |  428 ++
 sw/source/core/ole/ndole.cxx                              |    9 
 sw/source/core/text/EnhancedPDFExportHelper.cxx           |   42 
 sw/source/core/text/atrstck.cxx                           |   13 
 sw/source/core/text/frminf.cxx                            |   39 
 sw/source/core/text/frmpaint.cxx                          |    9 
 sw/source/core/text/guess.cxx                             |    7 
 sw/source/core/text/itratr.cxx                            |  237 -
 sw/source/core/text/itratr.hxx                            |    5 
 sw/source/core/text/itrcrsr.cxx                           |   12 
 sw/source/core/text/itrform2.cxx                          |    4 
 sw/source/core/text/itrform2.hxx                          |    4 
 sw/source/core/text/porfld.cxx                            |    4 
 sw/source/core/text/porlay.cxx                            |    2 
 sw/source/core/text/pormulti.cxx                          |   12 
 sw/source/core/text/pormulti.hxx                          |    1 
 sw/source/core/text/porrst.cxx                            |    3 
 sw/source/core/text/redlnitr.cxx                          |  227 +
 sw/source/core/text/txtdrop.cxx                           |    3 
 sw/source/core/text/txtfld.cxx                            |   87 
 sw/source/core/text/txtfrm.cxx                            |  618 +++
 sw/source/core/text/txtftn.cxx                            |    9 
 sw/source/core/text/wrong.cxx                             |  127 
 sw/source/core/text/xmldump.cxx                           |   25 
 sw/source/core/tox/ToxTextGenerator.cxx                   |  153 
 sw/source/core/tox/tox.cxx                                |    4 
 sw/source/core/tox/txmsrt.cxx                             |  153 
 sw/source/core/txtnode/atrfld.cxx                         |   15 
 sw/source/core/txtnode/atrftn.cxx                         |   47 
 sw/source/core/txtnode/fmtatr2.cxx                        |    1 
 sw/source/core/txtnode/modeltoviewhelper.cxx              |    7 
 sw/source/core/txtnode/ndtxt.cxx                          |  596 +++
 sw/source/core/txtnode/thints.cxx                         |   59 
 sw/source/core/txtnode/txtedt.cxx                         |   44 
 sw/source/core/undo/rolbck.cxx                            |    2 
 sw/source/core/undo/unattr.cxx                            |    7 
 sw/source/core/undo/undel.cxx                             |  191 +
 sw/source/core/undo/undobj.cxx                            |    4 
 sw/source/core/undo/unovwr.cxx                            |   23 
 sw/source/core/undo/unredln.cxx                           |   24 
 sw/source/core/undo/unsort.cxx                            |    4 
 sw/source/core/undo/untbl.cxx                             |   21 
 sw/source/core/unocore/unofield.cxx                       |    8 
 sw/source/core/unocore/unoflatpara.cxx                    |    6 
 sw/source/core/unocore/unoftn.cxx                         |    2 
 sw/source/core/unocore/unoidx.cxx                         |    5 
 sw/source/core/unocore/unoobj.cxx                         |   11 
 sw/source/core/unocore/unoobj2.cxx                        |    2 
 sw/source/core/unocore/unoport.cxx                        |    2 
 sw/source/core/unocore/unoportenum.cxx                    |    2 
 sw/source/core/unocore/unotbl.cxx                         |    7 
 sw/source/core/view/printdata.cxx                         |    5 
 sw/source/core/view/vprint.cxx                            |    5 
 sw/source/filter/ascii/ascatr.cxx                         |  119 
 sw/source/filter/basflt/fltshell.cxx                      |    2 
 sw/source/filter/html/htmlfldw.cxx                        |    4 
 sw/source/filter/html/htmlftn.cxx                         |    4 
 sw/source/filter/html/htmltab.cxx                         |    2 
 sw/source/filter/writer/writer.cxx                        |    1 
 sw/source/filter/ww8/docxattributeoutput.cxx              |    4 
 sw/source/filter/ww8/rtfattributeoutput.cxx               |    2 
 sw/source/filter/ww8/rtfexport.cxx                        |    2 
 sw/source/filter/ww8/writerhelper.cxx                     |    2 
 sw/source/filter/ww8/wrtw8esh.cxx                         |    2 
 sw/source/filter/ww8/wrtw8nds.cxx                         |    2 
 sw/source/filter/ww8/wrtww8.cxx                           |    7 
 sw/source/filter/ww8/ww8atr.cxx                           |   18 
 sw/source/filter/ww8/ww8par.cxx                           |   13 
 sw/source/filter/ww8/ww8par2.cxx                          |    2 
 sw/source/filter/ww8/ww8par5.cxx                          |    2 
 sw/source/filter/xml/XMLRedlineImportHelper.cxx           |   27 
 sw/source/filter/xml/XMLRedlineImportHelper.hxx           |    4 
 sw/source/filter/xml/swxml.cxx                            |    9 
 sw/source/filter/xml/wrtxml.cxx                           |   22 
 sw/source/filter/xml/xmlexp.cxx                           |    5 
 sw/source/filter/xml/xmltbli.cxx                          |    2 
 sw/source/filter/xml/xmltexti.cxx                         |    2 
 sw/source/ui/dbui/mmlayoutpage.cxx                        |    2 
 sw/source/ui/fldui/DropDownFieldDialog.cxx                |    2 
 sw/source/ui/fldui/flddok.cxx                             |    2 
 sw/source/ui/fldui/fldedt.cxx                             |    2 
 sw/source/ui/fldui/fldref.cxx                             |   21 
 sw/source/ui/fldui/inpdlg.cxx                             |    6 
 sw/source/ui/index/multmrk.cxx                            |    3 
 sw/source/ui/index/swuiidxmrk.cxx                         |   11 
 sw/source/ui/misc/titlepage.cxx                           |    2 
 sw/source/uibase/app/applab.cxx                           |    8 
 sw/source/uibase/docvw/PageBreakWin.cxx                   |    3 
 sw/source/uibase/docvw/PostItMgr.cxx                      |   52 
 sw/source/uibase/docvw/edtwin2.cxx                        |   10 
 sw/source/uibase/fldui/fldmgr.cxx                         |    4 
 sw/source/uibase/inc/content.hxx                          |    2 
 sw/source/uibase/inc/swcont.hxx                           |    9 
 sw/source/uibase/inc/toxmgr.hxx                           |    1 
 sw/source/uibase/inc/wrtsh.hxx                            |    6 
 sw/source/uibase/index/toxmgr.cxx                         |    2 
 sw/source/uibase/shells/listsh.cxx                        |   18 
 sw/source/uibase/shells/txtcrsr.cxx                       |    8 
 sw/source/uibase/uiview/view2.cxx                         |   22 
 sw/source/uibase/uiview/viewling.cxx                      |    5 
 sw/source/uibase/uiview/viewsrch.cxx                      |   15 
 sw/source/uibase/uiview/viewstat.cxx                      |    6 
 sw/source/uibase/uno/unotxdoc.cxx                         |   14 
 sw/source/uibase/uno/unotxvw.cxx                          |    7 
 sw/source/uibase/utlui/content.cxx                        |   93 
 sw/source/uibase/wrtsh/move.cxx                           |    7 
 sw/source/uibase/wrtsh/select.cxx                         |    6 
 sw/source/uibase/wrtsh/wrtsh1.cxx                         |   17 
 sw/uiconfig/swriter/ui/queryshowchangesdialog.ui          |   35 
 xmloff/source/core/xmlimp.cxx                             |    1 
 301 files changed, 13096 insertions(+), 4556 deletions(-)

New commits:
commit 9f4ee6552150d32daabbde8d436327f322ef5f8a
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Jan 11 15:22:59 2019 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Fri Jan 11 15:36:15 2019 +0100

    sw_redlinehide: fix infinite loop when deleting comments
    
    The problem is that sw::UpdateFramesForAddDeleteRedline() sends a
    SwFormatFieldHintWhich::REMOVED event in order to remove any comments
    that may have been deleted from the document view.
    
    Unfortunately there's another listener in class FieldDocWatchingStack
    that is used during various SwPostItMgr::Delete* functions, which will
    effectively start over from scratch if it receives this event, so it
    is an infinite loop.
    
    Avoid this by simply ignoring any redline-deleted fields; deleting them
    again won't provide any benefit anyway.
    
    This can be seen with UITest
    deleteAllComments.DeleteAllComments.test_comment_trackchanges.
    
    (regression from 9b67b6a6d4b912f1e515d3884fa02c1be8aa6921)
    
    Change-Id: Ie1d5676d1d79a51e2e4a01a3e282f8739ff08899

diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index 6abeb9866de9..00826636595c 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -1390,6 +1390,28 @@ public:
     }
 };
 
+class IsFieldNotDeleted : public FilterFunctor
+{
+private:
+    IDocumentRedlineAccess const& m_rIDRA;
+    FilterFunctor const& m_rNext;
+
+public:
+    IsFieldNotDeleted(IDocumentRedlineAccess const& rIDRA,
+            FilterFunctor & rNext)
+        : m_rIDRA(rIDRA)
+        , m_rNext(rNext)
+    {
+    }
+    bool operator()(const SwFormatField* pField) const override
+    {
+        if (!m_rNext(pField))
+            return false;
+        if (!pField->GetTextField())
+            return false;
+        return !sw::IsFieldDeletedInModel(m_rIDRA, *pField->GetTextField());
+    }
+};
 
 //Manages the passed in vector by automatically removing entries if they are deleted
 //and automatically adding entries if they appear in the document and match the
@@ -1500,7 +1522,9 @@ void SwPostItMgr::Delete(const OUString& rAuthor)
     mpWrtShell->StartUndo( SwUndoId::DELETE, &aRewriter );
 
     IsPostitFieldWithAuthorOf aFilter(rAuthor);
-    FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter);
+    IDocumentRedlineAccess const& rIDRA(mpWrtShell->getIDocumentRedlineAccess());
+    IsFieldNotDeleted aFilter2(rIDRA, aFilter);
+    FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter2);
     while (const SwFormatField* pField = aStack.pop())
     {
         if (mpWrtShell->GotoField(*pField))
@@ -1527,7 +1551,9 @@ void SwPostItMgr::Delete(sal_uInt32 nPostItId)
     mpWrtShell->StartUndo( SwUndoId::DELETE, &aRewriter );
 
     IsPostitFieldWithPostitId aFilter(nPostItId);
-    FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter);
+    IDocumentRedlineAccess const& rIDRA(mpWrtShell->getIDocumentRedlineAccess());
+    IsFieldNotDeleted aFilter2(rIDRA, aFilter);
+    FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(), aFilter2);
     const SwFormatField* pField = aStack.pop();
     if (pField && mpWrtShell->GotoField(*pField))
         mpWrtShell->DelRight();
@@ -1548,8 +1574,10 @@ void SwPostItMgr::Delete()
     mpWrtShell->StartUndo( SwUndoId::DELETE, &aRewriter );
 
     IsPostitField aFilter;
+    IDocumentRedlineAccess const& rIDRA(mpWrtShell->getIDocumentRedlineAccess());
+    IsFieldNotDeleted aFilter2(rIDRA, aFilter);
     FieldDocWatchingStack aStack(mvPostItFields, *mpView->GetDocShell(),
-        aFilter);
+        aFilter2);
     while (const SwFormatField* pField = aStack.pop())
     {
         if (mpWrtShell->GotoField(*pField))
commit 0774453331c47dfdb3d3c9397854b337f35acee4
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Jan 8 13:32:05 2019 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Jan 10 18:52:15 2019 +0100

    tdf#122452 sw_redlinehide: WW8 import/export sets layout show/hide mode
    
    ... and not SetRedlineFlags(), similar to the way the ODF filter does it.
    
    The RTF/DOCX filters don't appear to be able to export the show/hide
    flag currently, they can only handle the enabled flag.
    
    Change-Id: I76bc19292882d7de5c28ea6afe0f81eadbd4a04f
    Reviewed-on: https://gerrit.libreoffice.org/65966
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
    (cherry picked from commit 2dda396f4de051cccf3442f17c84bf2ff5d1db1d)
    Reviewed-on: https://gerrit.libreoffice.org/65973
    Tested-by: Xisco Faulí <xiscofauli at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit b4d942fce7e6764cd354517140e0249cb7382dd3)

diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 1791c4747ff3..29e24e96a871 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -57,6 +57,7 @@
 #include <fmtpdsc.hxx>
 #include <fmtrowsplt.hxx>
 #include <frmatr.hxx>
+#include <../../core/inc/rootfrm.hxx>
 #include <doc.hxx>
 #include <IDocumentSettingAccess.hxx>
 #include <IDocumentDrawModelAccess.hxx>
@@ -3356,7 +3357,8 @@ ErrCode WW8Export::ExportDocument_Impl()
     pDop = new WW8Dop;
 
     pDop->fRevMarking = bool( RedlineFlags::On & m_nOrigRedlineFlags );
-    pDop->fRMView = bool( RedlineFlags::ShowDelete & m_nOrigRedlineFlags );
+    SwRootFrame const*const pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
+    pDop->fRMView = pLayout == nullptr || !pLayout->IsHideRedlines();
     pDop->fRMPrint = pDop->fRMView;
 
     // set AutoHyphenation flag if found in default para style
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 4561f1f90c80..f03b8eff30f3 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -82,6 +82,7 @@
 #include <IDocumentMarkAccess.hxx>
 #include <IDocumentStylePoolAccess.hxx>
 #include <IDocumentExternalData.hxx>
+#include <../../core/inc/DocumentRedlineManager.hxx>
 #include <docufld.hxx>
 #include <swfltopt.hxx>
 #include <viewsh.hxx>
@@ -4987,7 +4988,7 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const *pGloss)
     SwNodeIndex aSttNdIdx( m_rDoc.GetNodes() );
     SwRelNumRuleSpaces aRelNumRule(m_rDoc, m_bNewDoc);
 
-    RedlineFlags eMode = RedlineFlags::ShowInsert;
+    RedlineFlags eMode = RedlineFlags::ShowInsert | RedlineFlags::ShowDelete;
 
     m_xSprmParser.reset(new wwSprmParser(*m_xWwFib));
 
@@ -5287,12 +5288,13 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const *pGloss)
         }
     }
 
+    bool isHideRedlines(false);
+
     if (m_bNewDoc)
     {
         if( m_xWDop->fRevMarking )
             eMode |= RedlineFlags::On;
-        if( m_xWDop->fRMView )
-            eMode |= RedlineFlags::ShowDelete;
+        isHideRedlines = !m_xWDop->fRMView;
     }
 
     m_aInsertedTables.DelAndMakeTableFrames();
@@ -5426,6 +5428,9 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const *pGloss)
 
     UpdatePageDescs(m_rDoc, nPageDescOffset);
 
+    // can't set it on the layout or view shell because it doesn't exist yet
+    m_rDoc.GetDocumentRedlineManager().SetHideRedlines(isHideRedlines);
+
     return ERRCODE_NONE;
 }
 
commit 82679a8d45b91f7e1cd7feee175257856c74c366
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Jan 8 13:22:31 2019 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Jan 10 18:51:05 2019 +0100

    sw_redlinehide: try harder to prevent SetRedlineFlags from messing things up
    
    Rearrange the code added in 15f1555da8adfa81ea1d4b0d8b694164fddbb2ae
    to set all layouts to non-hidden before moving redlines in the model.
    
    tdf52550-1.doc contains lots of consecutive delete redlines that
    when exported to ODF trigger asserts about wrong start nodes in
    CheckParaRedlineMerge().
    
    Reviewed-on: https://gerrit.libreoffice.org/65965
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
    (cherry picked from commit b15f1ed2a1df45a57b587ac90efa90c1c18866fc)
    Reviewed-on: https://gerrit.libreoffice.org/65972
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 307a6b4287c0096e1a10d2fdb73b073e9eef7a11)
    
    Change-Id: I89c3d4fefd26691a9632807b9899138eee895fff

diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx
index 1075a8e7673e..ec8f19f291a4 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -824,6 +824,25 @@ void DocumentRedlineManager::SetRedlineFlags( RedlineFlags eMode )
             CheckAnchoredFlyConsistency(m_rDoc);
             CHECK_REDLINE( *this )
 
+            std::set<SwRootFrame *> hiddenLayouts;
+            if (eShowMode == (RedlineFlags::ShowInsert | RedlineFlags::ShowDelete))
+            {
+                // sw_redlinehide: the problem here is that MoveFromSection
+                // creates the frames wrongly (non-merged), because its own
+                // SwRangeRedline has wrong positions until after the nodes
+                // are all moved, so fix things up by force by re-creating
+                // all merged frames from scratch.
+                std::set<SwRootFrame *> const layouts(m_rDoc.GetAllLayouts());
+                for (SwRootFrame *const pLayout : layouts)
+                {
+                    if (pLayout->IsHideRedlines())
+                    {
+                        pLayout->SetHideRedlines(false);
+                        hiddenLayouts.insert(pLayout);
+                    }
+                }
+            }
+
             if (pFnc)
             {
                 for (sal_uInt16 nLoop = 1; nLoop <= 2; ++nLoop)
@@ -845,24 +864,13 @@ void DocumentRedlineManager::SetRedlineFlags( RedlineFlags eMode )
 
             CheckAnchoredFlyConsistency(m_rDoc);
             CHECK_REDLINE( *this )
-            m_rDoc.SetInXMLImport( bSaveInXMLImportFlag );
-            if (eShowMode == (RedlineFlags::ShowInsert | RedlineFlags::ShowDelete))
+
+            for (SwRootFrame *const pLayout : hiddenLayouts)
             {
-                // sw_redlinehide: the problem here is that MoveFromSection
-                // creates the frames wrongly (non-merged), because its own
-                // SwRangeRedline has wrong positions until after the nodes
-                // are all moved, so fix things up by force by re-creating
-                // all merged frames from scratch.
-                std::set<SwRootFrame *> const layouts(m_rDoc.GetAllLayouts());
-                for (SwRootFrame *const pLayout : layouts)
-                {
-                    if (pLayout->IsHideRedlines())
-                    {
-                        pLayout->SetHideRedlines(false);
-                        pLayout->SetHideRedlines(true);
-                    }
-                }
+                pLayout->SetHideRedlines(true);
             }
+
+            m_rDoc.SetInXMLImport( bSaveInXMLImportFlag );
         }
         meRedlineFlags = eMode;
         m_rDoc.getIDocumentState().SetModified();
commit 349fb6124ea017a6767a6b62948117fdf910341b
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Dec 21 11:56:30 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Jan 10 18:49:16 2019 +0100

    sw_redlinehide: adapt ToX Update
    
    The ToX exists only once in the model, so it either has to have the
    content corresponding to redlines being shown, or hidden.
    
    Adapt Update based on current layout setting.
    
    Reviewed-on: https://gerrit.libreoffice.org/65527
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
    (cherry picked from commit 80cedb5dcb6a7dd6c01349b93fab49ecee5f6594)
    
    Reviewed-on: https://gerrit.libreoffice.org/65562
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 6c5094a4995238c19f022ee5e4c6439a52691f84)
    
    Change-Id: Ibf5ec092632cf3a5f513965afdb840fd8239a7fd

diff --git a/sw/inc/ToxTextGenerator.hxx b/sw/inc/ToxTextGenerator.hxx
index 79f4d30b13d1..96a573581d01 100644
--- a/sw/inc/ToxTextGenerator.hxx
+++ b/sw/inc/ToxTextGenerator.hxx
@@ -32,6 +32,7 @@ class SwFormatAutoFormat;
 class SwChapterField;
 class SwChapterFieldType;
 class SwContentFrame;
+class SwRootFrame;
 class SwContentNode;
 class SwDoc;
 class SwForm;
@@ -45,6 +46,7 @@ namespace sw {
 
 class ToxLinkProcessor;
 class ToxTabStopTokenHandler;
+class ToxWhitespaceStripper;
 
 /** This class generates text for the entries of a table of x.
  *
@@ -64,7 +66,8 @@ public:
      */
     void
     GenerateText(SwDoc *doc, const std::vector<std::unique_ptr<SwTOXSortTabBase>>& entries,
-                      sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess);
+        sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess,
+        SwRootFrame const* pLayout);
 
 private:
     const SwForm& mToxForm;
@@ -80,13 +83,23 @@ private:
         std::vector<sal_Int32> startPositions;
         std::vector<sal_Int32> endPositions;
     };
+
+    static void GetAttributesForNode(
+        HandledTextToken & rResult,
+        sal_Int32 & rOffset,
+        SwTextNode const& rNode,
+        ToxWhitespaceStripper const& rStripper,
+        SwAttrPool & rPool,
+        SwRootFrame const*const pLayout);
+
     /** Append text (and selected attributes) to a target node.
      *
      * Will take the text of @p source, and return the text and the attributes which should be added to the
      * target text node. @see CollectAttributesForTox() for the criteria of the attributes which are taken.
      */
     static HandledTextToken
-    HandleTextToken(const SwTOXSortTabBase& source, SwAttrPool& attrPool);
+    HandleTextToken(const SwTOXSortTabBase& source, SwAttrPool& attrPool,
+            SwRootFrame const*const pLayout);
 
     /** Applies the result of a handled text token to a target node. */
     static void
@@ -124,18 +137,20 @@ private:
      * for details.
      */
     static OUString
-    GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase, bool bUsePrefix, sal_uInt8 nLevel);
+    GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase, bool bUsePrefix,
+            sal_uInt8 nLevel, SwRootFrame const* pLayout);
 
     /** Handle a chapter token.
      */
     OUString
-    HandleChapterToken(const SwTOXSortTabBase& rBase, const SwFormToken& aToken, SwDoc* pDoc) const;
+    HandleChapterToken(const SwTOXSortTabBase& rBase, const SwFormToken& aToken,
+            SwRootFrame const* pLayout) const;
 
     /** Generate the text for a chapter token.
      */
     OUString
     GenerateTextForChapterToken(const SwFormToken& chapterToken, const SwContentFrame* contentFrame,
-            const SwContentNode *contentNode) const;
+            const SwContentNode *contentNode, SwRootFrame const* pLayout) const;
 
     /** Obtain a ChapterField to use for the text generation.
      * @internal
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index b570476d2b53..42621658f569 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -914,7 +914,8 @@ public:
     SwTOXBaseSection* InsertTableOf( const SwPosition& rPos,
                                             const SwTOXBase& rTOX,
                                             const SfxItemSet* pSet = nullptr,
-                                            bool bExpand = false );
+                                            bool bExpand = false,
+                                    SwRootFrame const* pLayout = nullptr);
     void              InsertTableOf( sal_uLong nSttNd, sal_uLong nEndNd,
                                             const SwTOXBase& rTOX,
                                             const SfxItemSet* pSet );
@@ -960,7 +961,8 @@ public:
     void                SetDefaultTOXBase(const SwTOXBase& rBase);
 
     // Key for management of index.
-    void GetTOIKeys( SwTOIKeyType eTyp, std::vector<OUString>& rArr ) const;
+    void GetTOIKeys(SwTOIKeyType eTyp, std::vector<OUString>& rArr,
+            SwRootFrame const& rLayout) const;
 
     // Sort table text.
     bool SortTable(const SwSelBoxes& rBoxes, const SwSortOptions&);
@@ -1528,7 +1530,7 @@ public:
                    bool bBroadcast = false);
 
     // Change a TOX undoable.
-    void ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew);
+    void ChangeTOX(SwTOXBase & rTOX, const SwTOXBase & rNew, SwRootFrame const& rLayout);
 
     /**
        Returns a textual description of a PaM.
diff --git a/sw/inc/tox.hxx b/sw/inc/tox.hxx
index 2ca0604d3926..20b6c8df8e5c 100644
--- a/sw/inc/tox.hxx
+++ b/sw/inc/tox.hxx
@@ -41,6 +41,7 @@ class SwTOXType;
 class SwTOXMark;
 class SwTextTOXMark;
 class SwDoc;
+class SwRootFrame;
 
 typedef std::vector<SwTOXMark*> SwTOXMarks;
 
@@ -98,7 +99,7 @@ public:
 
     void InvalidateTOXMark();
 
-    OUString                GetText() const;
+    OUString                GetText(SwRootFrame const* pLayout) const;
 
     inline bool             IsAlternativeText() const;
     inline const OUString&  GetAlternativeText() const;
diff --git a/sw/qa/core/test_ToxTextGenerator.cxx b/sw/qa/core/test_ToxTextGenerator.cxx
index 3ddc9fef6f80..25304a382ed3 100644
--- a/sw/qa/core/test_ToxTextGenerator.cxx
+++ b/sw/qa/core/test_ToxTextGenerator.cxx
@@ -50,7 +50,7 @@ struct MockedSortTab : public SwTOXSortTabBase {
     MockedSortTab()
     : SwTOXSortTabBase(TOX_SORT_INDEX,nullptr,nullptr,nullptr) {}
 
-    virtual TextAndReading GetText_Impl() const override {
+    virtual TextAndReading GetText_Impl(SwRootFrame const*) const override {
         return TextAndReading();
     }
     virtual sal_uInt16  GetLevel() const override {
@@ -89,7 +89,7 @@ ToxTextGeneratorTest::EmptyStringIsReturnedAsNumStringIfNoTextMarkIsSet()
     sortTab.pTextMark = nullptr;
 
     OUString const expected("");
-    OUString actual = ToxTextGenerator::GetNumStringOfFirstNode(sortTab, false, 0);
+    OUString actual = ToxTextGenerator::GetNumStringOfFirstNode(sortTab, false, 0, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 }
 
@@ -100,7 +100,7 @@ ToxTextGeneratorTest::EmptyStringIsReturnedAsNumStringIfToxSourcesIsEmpty()
     sortTab.pTextMark = reinterpret_cast<SwTextTOXMark*>(1);
 
     OUString const expected("");
-    OUString actual = ToxTextGenerator::GetNumStringOfFirstNode(sortTab, false, 0);
+    OUString actual = ToxTextGenerator::GetNumStringOfFirstNode(sortTab, false, 0, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 }
 
@@ -150,13 +150,13 @@ ToxTextGeneratorTest::ChapterNumberWithoutTextIsGeneratedForNoprepstTitle()
     token.nChapterFormat = CF_NUM_NOPREPST_TITLE;
 
     OUString expected("1");
-    OUString actual = ttg.GenerateTextForChapterToken(token, nullptr, nullptr);
+    OUString actual = ttg.GenerateTextForChapterToken(token, nullptr, nullptr, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 
     // we cannot mock the pre- and suffix generation in the chapterfield. We just test that sNumber and
     // sTitle are used and hope that the pre- and suffix addition works.
     token.nChapterFormat = CF_NUMBER;
-    expected = ttg.GenerateTextForChapterToken(token, nullptr, nullptr);
+    expected = ttg.GenerateTextForChapterToken(token, nullptr, nullptr, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 }
 
@@ -176,13 +176,13 @@ ToxTextGeneratorTest::ChapterNumberWithTitleIsGeneratedForNumberNoPrepst()
     token.nChapterFormat = CF_NUMBER_NOPREPST;
 
     OUString expected("5 myTitle");
-    OUString actual = ttg.GenerateTextForChapterToken(token, nullptr, nullptr);
+    OUString actual = ttg.GenerateTextForChapterToken(token, nullptr, nullptr, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 
     // we cannot mock the pre- and suffix generation in the chapterfield. We just test that sNumber and
     // sTitle are used and hope that the pre- and suffix addition works.
     token.nChapterFormat = CF_NUM_TITLE;
-    expected = ttg.GenerateTextForChapterToken(token, nullptr, nullptr);
+    expected = ttg.GenerateTextForChapterToken(token, nullptr, nullptr, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 }
 
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 903e1195b3e3..e51b73577a4d 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1727,7 +1727,8 @@ void SwDoc::AppendUndoForInsertFromDB( const SwPaM& rPam, bool bIsTable )
     }
 }
 
-void SwDoc::ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew)
+void SwDoc::ChangeTOX(SwTOXBase & rTOX, const SwTOXBase & rNew,
+        SwRootFrame const& rLayout)
 {
     if (GetIDocumentUndoRedo().DoesUndo())
     {
@@ -1742,7 +1743,7 @@ void SwDoc::ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew)
 
     if (dynamic_cast<const SwTOXBaseSection*>( &rTOX) !=  nullptr)
     {
-        static_cast<SwTOXBaseSection &>(rTOX).Update();
+        static_cast<SwTOXBaseSection &>(rTOX).Update(nullptr, &rLayout);
         static_cast<SwTOXBaseSection &>(rTOX).UpdatePageNum();
     }
 }
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index d508f3015607..fb4e7b55ea6d 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -79,8 +79,17 @@
 
 using namespace ::com::sun::star;
 
+template<typename T, typename... Args> static
+typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
+MakeSwTOXSortTabBase(SwRootFrame const*const pLayout, Args&& ... args)
+{
+    std::unique_ptr<T> pRet(new T(std::forward<Args>(args)...));
+    pRet->InitText(pLayout); // ensure it's expanded with the layout
+    return pRet;
+}
 
-void SwDoc::GetTOIKeys( SwTOIKeyType eTyp, std::vector<OUString>& rArr ) const
+void SwDoc::GetTOIKeys(SwTOIKeyType eTyp, std::vector<OUString>& rArr,
+        SwRootFrame const& rLayout) const
 {
     rArr.clear();
 
@@ -96,7 +105,9 @@ void SwDoc::GetTOIKeys( SwTOIKeyType eTyp, std::vector<OUString>& rArr ) const
             continue;
         const SwTextTOXMark* pMark = pItem->GetTextTOXMark();
         if ( pMark && pMark->GetpTextNd() &&
-             pMark->GetpTextNd()->GetNodes().IsDocNodes() )
+             pMark->GetpTextNd()->GetNodes().IsDocNodes() &&
+             (!rLayout.IsHideRedlines()
+                || !sw::IsMarkHintHidden(rLayout, *pMark->GetpTextNd(), *pMark)))
         {
             const OUString sStr = TOI_PRIMARY == eTyp
                 ? pItem->GetPrimaryKey()
@@ -268,7 +279,7 @@ const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark,
             // possible to also travel across Entries on the same (!)
             // position. If someone has time, please feel free to optimize.
             case TOX_SAME_PRV:
-                if( pTOXMark->GetText() != rCurTOXMark.GetText() )
+                if (pTOXMark->GetText(nullptr) != rCurTOXMark.GetText(nullptr))
                     break;
                 SAL_FALLTHROUGH;
             case TOX_PRV:
@@ -290,7 +301,7 @@ const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark,
                 break;
 
             case TOX_SAME_NXT:
-                if( pTOXMark->GetText() != rCurTOXMark.GetText() )
+                if (pTOXMark->GetText(nullptr) != rCurTOXMark.GetText(nullptr))
                     break;
                 SAL_FALLTHROUGH;
             case TOX_NXT:
@@ -338,7 +349,8 @@ const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark,
 SwTOXBaseSection* SwDoc::InsertTableOf( const SwPosition& rPos,
                                                 const SwTOXBase& rTOX,
                                                 const SfxItemSet* pSet,
-                                                bool bExpand )
+                                                bool bExpand,
+                                        SwRootFrame const*const pLayout)
 {
     GetIDocumentUndoRedo().StartUndo( SwUndoId::INSTOX, nullptr );
 
@@ -357,7 +369,7 @@ SwTOXBaseSection* SwDoc::InsertTableOf( const SwPosition& rPos,
             // add value for 2nd parameter = true to
             // indicate, that a creation of a new table of content has to be performed.
             // Value of 1st parameter = default value.
-            pNewSection->Update( nullptr, true );
+            pNewSection->Update( nullptr, pLayout, true );
         }
         else if( rTOX.GetTitle().getLength()==1 && IsInReading() )
         // insert title of TOX
@@ -695,7 +707,8 @@ bool SwDoc::SetTOXBaseName(const SwTOXBase& rTOXBase, const OUString& rName)
     return false;
 }
 
-static const SwTextNode* lcl_FindChapterNode( const SwNode& rNd, sal_uInt8 nLvl = 0 )
+static const SwTextNode* lcl_FindChapterNode( const SwNode& rNd,
+        SwRootFrame const*const pLayout, sal_uInt8 const nLvl = 0 )
 {
     const SwNode* pNd = &rNd;
     if( pNd->GetNodes().GetEndOfExtras().GetIndex() > pNd->GetIndex() )
@@ -712,7 +725,7 @@ static const SwTextNode* lcl_FindChapterNode( const SwNode& rNd, sal_uInt8 nLvl
             OSL_ENSURE( pNd, "Where's the paragraph?" );
         }
     }
-    return pNd ? pNd->FindOutlineNodeOfLevel( nLvl ) : nullptr;
+    return pNd ? pNd->FindOutlineNodeOfLevel(nLvl, pLayout) : nullptr;
 }
 
 // Table of contents class
@@ -744,7 +757,8 @@ bool SwTOXBaseSection::SetPosAtStartEnd( SwPosition& rPos ) const
 
 /// Collect table of contents content
 void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
-                              const bool        _bNewTOX )
+                              SwRootFrame const*const pLayout,
+                              const bool        _bNewTOX)
 {
     if (!SwTOXBase::GetRegisteredIn()->HasWriterListeners() ||
         !GetFormat())
@@ -754,7 +768,8 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     SwSectionNode const*const pSectNd(GetFormat()->GetSectionNode());
     if (nullptr == pSectNd ||
         !pSectNd->GetNodes().IsDocNodes() ||
-        IsHiddenFlag() )
+        IsHiddenFlag() ||
+        (pLayout->IsHideRedlines() && pSectNd->GetRedlineMergeFlag() == SwNode::Merge::Hidden))
     {
         return;
     }
@@ -838,7 +853,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     // find the first layout node for this TOX, if it only find the content
     // in his own chapter
     const SwTextNode* pOwnChapterNode = IsFromChapter()
-            ? ::lcl_FindChapterNode( *pSectNd )
+            ? ::lcl_FindChapterNode( *pSectNd, pLayout )
             : nullptr;
 
     SwNode2LayoutSaveUpperFrames aN2L(*pSectNd);
@@ -902,36 +917,36 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     pDoc->UpdateNumRule();
 
     if( GetCreateType() & SwTOXElement::Mark )
-        UpdateMarks( aIntl, pOwnChapterNode );
+        UpdateMarks( aIntl, pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::OutlineLevel )
-        UpdateOutline( pOwnChapterNode );
+        UpdateOutline( pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Template )
-        UpdateTemplate( pOwnChapterNode );
+        UpdateTemplate( pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Ole ||
             TOX_OBJECTS == SwTOXBase::GetType())
-        UpdateContent( SwTOXElement::Ole, pOwnChapterNode );
+        UpdateContent( SwTOXElement::Ole, pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Table ||
             (TOX_TABLES == SwTOXBase::GetType() && IsFromObjectNames()) )
-        UpdateTable( pOwnChapterNode );
+        UpdateTable( pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Graphic ||
         (TOX_ILLUSTRATIONS == SwTOXBase::GetType() && IsFromObjectNames()))
-        UpdateContent( SwTOXElement::Graphic, pOwnChapterNode );
+        UpdateContent( SwTOXElement::Graphic, pOwnChapterNode, pLayout );
 
     if( !GetSequenceName().isEmpty() && !IsFromObjectNames() &&
         (TOX_TABLES == SwTOXBase::GetType() ||
          TOX_ILLUSTRATIONS == SwTOXBase::GetType() ) )
-        UpdateSequence( pOwnChapterNode );
+        UpdateSequence( pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Frame )
-        UpdateContent( SwTOXElement::Frame, pOwnChapterNode );
+        UpdateContent( SwTOXElement::Frame, pOwnChapterNode, pLayout );
 
     if(TOX_AUTHORITIES == SwTOXBase::GetType())
-        UpdateAuthorities( aIntl );
+        UpdateAuthorities( aIntl, pLayout );
 
     // Insert AlphaDelimitters if needed (just for keywords)
     if( TOX_INDEX == SwTOXBase::GetType() &&
@@ -988,7 +1003,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
                                 sw::DefaultToxTabStopTokenHandler::TABSTOPS_RELATIVE_TO_INDENT :
                                 sw::DefaultToxTabStopTokenHandler::TABSTOPS_RELATIVE_TO_PAGE);
         sw::ToxTextGenerator ttgn(GetTOXForm(), tabStopTokenHandler);
-        ttgn.GenerateText(GetFormat()->GetDoc(), aSortArr, nCnt, nRange);
+        ttgn.GenerateText(GetFormat()->GetDoc(), aSortArr, nCnt, nRange, pLayout);
         nCnt += nRange - 1;
     }
 
@@ -1055,7 +1070,9 @@ void SwTOXBaseSection::InsertAlphaDelimitter( const SwTOXInternational& rIntl )
             // We skip all that are less than a small Blank (these are special characters)
             if( ' ' <= sDeli[0] )
             {
-                std::unique_ptr<SwTOXCustom> pCst(new SwTOXCustom( TextAndReading(sDeli, OUString()),
+                std::unique_ptr<SwTOXCustom> pCst(
+                        MakeSwTOXSortTabBase<SwTOXCustom>(nullptr,
+                                TextAndReading(sDeli, OUString()),
                                                      FORM_ALPHA_DELIMITTER,
                                                      rIntl, aSortArr[i]->GetLocale() ));
                 aSortArr.insert( aSortArr.begin() + i, std::move(pCst));
@@ -1123,7 +1140,8 @@ SwTextFormatColl* SwTOXBaseSection::GetTextFormatColl( sal_uInt16 nLevel )
 
 /// Create from Marks
 void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
-                                    const SwTextNode* pOwnChapterNode )
+                                    const SwTextNode* pOwnChapterNode,
+                                    SwRootFrame const*const pLayout)
 {
     const SwTOXType* pType = static_cast<SwTOXType*>( SwTOXBase::GetRegisteredIn() );
     if( !pType->HasWriterListeners() )
@@ -1150,9 +1168,11 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
             if( pTOXSrc->GetNodes().IsDocNodes() &&
                 pTOXSrc->GetText().getLength() && pTOXSrc->HasWriterListeners() &&
                 pTOXSrc->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) &&
-               (!IsFromChapter() || ::lcl_FindChapterNode( *pTOXSrc ) == pOwnChapterNode ) &&
+               (!IsFromChapter() || ::lcl_FindChapterNode(*pTOXSrc, pLayout) == pOwnChapterNode) &&
                !pTOXSrc->IsHiddenByParaField() &&
-               !SwScriptInfo::IsInHiddenRange( *pTOXSrc, pTextMark->GetStart() ) )
+               !SwScriptInfo::IsInHiddenRange(*pTOXSrc, pTextMark->GetStart()) &&
+               (!pLayout || !pLayout->IsHideRedlines()
+                    || !sw::IsMarkHintHidden(*pLayout, *pTOXSrc, *pTextMark)))
             {
                 if(TOX_INDEX == eTOXTyp)
                 {
@@ -1160,16 +1180,16 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
                     assert(g_pBreakIt);
                     lang::Locale aLocale = g_pBreakIt->GetLocale(pTOXSrc->GetLang(pTextMark->GetStart()));
 
-                    InsertSorted(o3tl::make_unique<SwTOXIndex>( *pTOXSrc, pTextMark,
+                    InsertSorted(MakeSwTOXSortTabBase<SwTOXIndex>(pLayout, *pTOXSrc, pTextMark,
                                             GetOptions(), FORM_ENTRY, rIntl, aLocale ));
                     if(GetOptions() & SwTOIOptions::KeyAsEntry &&
                         !pTextMark->GetTOXMark().GetPrimaryKey().isEmpty())
                     {
-                        InsertSorted(o3tl::make_unique<SwTOXIndex>( *pTOXSrc, pTextMark,
+                        InsertSorted(MakeSwTOXSortTabBase<SwTOXIndex>(pLayout, *pTOXSrc, pTextMark,
                                                 GetOptions(), FORM_PRIMARY_KEY, rIntl, aLocale ));
                         if (!pTextMark->GetTOXMark().GetSecondaryKey().isEmpty())
                         {
-                            InsertSorted(o3tl::make_unique<SwTOXIndex>( *pTOXSrc, pTextMark,
+                            InsertSorted(MakeSwTOXSortTabBase<SwTOXIndex>(pLayout, *pTOXSrc, pTextMark,
                                                     GetOptions(), FORM_SECONDARY_KEY, rIntl, aLocale ));
                         }
                     }
@@ -1178,7 +1198,7 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
                     pMark->GetLevel() <= GetLevel())
                 {   // table of content mark
                     // also used for user marks
-                    InsertSorted(o3tl::make_unique<SwTOXContent>( *pTOXSrc, pTextMark, rIntl ));
+                    InsertSorted(MakeSwTOXSortTabBase<SwTOXContent>(pLayout, *pTOXSrc, pTextMark, rIntl));
                 }
             }
         }
@@ -1186,7 +1206,8 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
 }
 
 /// Generate table of contents from outline
-void SwTOXBaseSection::UpdateOutline( const SwTextNode* pOwnChapterNode )
+void SwTOXBaseSection::UpdateOutline( const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwNodes& rNds = pDoc->GetNodes();
@@ -1198,19 +1219,22 @@ void SwTOXBaseSection::UpdateOutline( const SwTextNode* pOwnChapterNode )
         SwTextNode* pTextNd = pOutlineNode->GetTextNode();
         if( pTextNd && pTextNd->Len() && pTextNd->HasWriterListeners() &&
             sal_uInt16( pTextNd->GetAttrOutlineLevel()) <= GetLevel() &&
-            pTextNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) &&
+            pTextNd->getLayoutFrame(pLayout) &&
            !pTextNd->IsHiddenByParaField() &&
            !pTextNd->HasHiddenCharAttribute( true ) &&
+           (!pLayout || !pLayout->IsHideRedlines()
+                || static_cast<SwTextFrame*>(pTextNd->getLayoutFrame(pLayout))->GetTextNodeForParaProps() == pTextNd) &&
             ( !IsFromChapter() ||
-               ::lcl_FindChapterNode( *pTextNd ) == pOwnChapterNode ))
+               ::lcl_FindChapterNode(*pTextNd, pLayout) == pOwnChapterNode ))
         {
-            InsertSorted( o3tl::make_unique<SwTOXPara>( *pTextNd, SwTOXElement::OutlineLevel ) );
+            InsertSorted(MakeSwTOXSortTabBase<SwTOXPara>(pLayout, *pTextNd, SwTOXElement::OutlineLevel));
         }
     }
 }
 
 /// Generate table of contents from template areas
-void SwTOXBaseSection::UpdateTemplate( const SwTextNode* pOwnChapterNode )
+void SwTOXBaseSection::UpdateTemplate(const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
@@ -1237,12 +1261,14 @@ void SwTOXBaseSection::UpdateTemplate( const SwTextNode* pOwnChapterNode )
                 ::SetProgressState( 0, pDoc->GetDocShell() );
 
                 if (pTextNd->GetText().getLength() &&
-                    pTextNd->getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout()) &&
+                    pTextNd->getLayoutFrame(pLayout) &&
                     pTextNd->GetNodes().IsDocNodes() &&
-                    ( !IsFromChapter() || pOwnChapterNode ==
-                        ::lcl_FindChapterNode( *pTextNd ) ) )
+                    (!pLayout || !pLayout->IsHideRedlines()
+                        || static_cast<SwTextFrame*>(pTextNd->getLayoutFrame(pLayout))->GetTextNodeForParaProps() == pTextNd) &&
+                    (!IsFromChapter() || pOwnChapterNode ==
+                        ::lcl_FindChapterNode(*pTextNd, pLayout)))
                 {
-                    InsertSorted( o3tl::make_unique<SwTOXPara>( *pTextNd, SwTOXElement::Template, i + 1 ) );
+                    InsertSorted(MakeSwTOXSortTabBase<SwTOXPara>(pLayout, *pTextNd, SwTOXElement::Template, i + 1));
                 }
             }
         }
@@ -1250,7 +1276,8 @@ void SwTOXBaseSection::UpdateTemplate( const SwTextNode* pOwnChapterNode )
 }
 
 /// Generate content from sequence fields
-void SwTOXBaseSection::UpdateSequence( const SwTextNode* pOwnChapterNode )
+void SwTOXBaseSection::UpdateSequence(const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwFieldType* pSeqField = pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::SetExp, GetSequenceName(), false);
@@ -1267,10 +1294,12 @@ void SwTOXBaseSection::UpdateSequence( const SwTextNode* pOwnChapterNode )
         ::SetProgressState( 0, pDoc->GetDocShell() );
 
         if (rTextNode.GetText().getLength() &&
-            rTextNode.getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout()) &&
+            rTextNode.getLayoutFrame(pLayout) &&
             rTextNode.GetNodes().IsDocNodes() &&
             ( !IsFromChapter() ||
-                ::lcl_FindChapterNode( rTextNode ) == pOwnChapterNode ) )
+                ::lcl_FindChapterNode(rTextNode, pLayout) == pOwnChapterNode)
+            && (!pLayout || !pLayout->IsHideRedlines()
+                || !sw::IsFieldDeletedInModel(pDoc->getIDocumentRedlineAccess(), *pTextField)))
         {
             const SwSetExpField& rSeqField = dynamic_cast<const SwSetExpField&>(*(pFormatField->GetField()));
             const OUString sName = GetSequenceName()
@@ -1287,12 +1316,14 @@ void SwTOXBaseSection::UpdateSequence( const SwTextNode* pOwnChapterNode )
             {
                 pNew->SetEndIndex(pTextField->GetStart() + 1);
             }
+            pNew->InitText(pLayout);
             InsertSorted(std::move(pNew));
         }
     }
 }
 
-void SwTOXBaseSection::UpdateAuthorities( const SwTOXInternational& rIntl )
+void SwTOXBaseSection::UpdateAuthorities(const SwTOXInternational& rIntl,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwFieldType* pAuthField = pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::TableOfAuthorities, OUString(), false);
@@ -1310,11 +1341,13 @@ void SwTOXBaseSection::UpdateAuthorities( const SwTOXInternational& rIntl )
         ::SetProgressState( 0, pDoc->GetDocShell() );
 
         if (rTextNode.GetText().getLength() &&
-            rTextNode.getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout()) &&
-            rTextNode.GetNodes().IsDocNodes() )
+            rTextNode.getLayoutFrame(pLayout) &&
+            rTextNode.GetNodes().IsDocNodes()
+            && (!pLayout || !pLayout->IsHideRedlines()
+                || !sw::IsFieldDeletedInModel(pDoc->getIDocumentRedlineAccess(), *pTextField)))
         {
             //#106485# the body node has to be used!
-            SwContentFrame *pFrame = rTextNode.getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() );
+            SwContentFrame *const pFrame = rTextNode.getLayoutFrame(pLayout);
             SwPosition aFieldPos(rTextNode);
             const SwTextNode* pTextNode = nullptr;
             if(pFrame && !pFrame->IsInDocBody())
@@ -1322,7 +1355,7 @@ void SwTOXBaseSection::UpdateAuthorities( const SwTOXInternational& rIntl )
             if(!pTextNode)
                 pTextNode = &rTextNode;
 
-            InsertSorted(o3tl::make_unique<SwTOXAuthority>( *pTextNode, *pFormatField, rIntl ));
+            InsertSorted(MakeSwTOXSortTabBase<SwTOXAuthority>(pLayout, *pTextNode, *pFormatField, rIntl));
         }
     }
 }
@@ -1372,7 +1405,8 @@ static SwTOOElements lcl_IsSOObject( const SvGlobalName& rFactoryNm )
 }
 
 void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType,
-                                    const SwTextNode* pOwnChapterNode )
+        const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwNodes& rNds = pDoc->GetNodes();
@@ -1446,7 +1480,7 @@ void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType,
                     TOX_OBJECTS != SwTOXBase::GetType() )
             {
                 const SwTextNode* pOutlNd = ::lcl_FindChapterNode( *pCNd,
-                                                        MAXLEVEL - 1 );
+                                                pLayout, MAXLEVEL - 1);
                 if( pOutlNd )
                 {
                     if( pOutlNd->GetTextColl()->IsAssignedToListLevelOfOutlineStyle())
@@ -1456,10 +1490,14 @@ void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType,
                 }
             }
 
-            if( pCNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) && ( !IsFromChapter() ||
-                    ::lcl_FindChapterNode( *pCNd ) == pOwnChapterNode ))
+            if (pCNd->getLayoutFrame(pLayout)
+                && (!pLayout || !pLayout->IsHideRedlines()
+                    || pCNd->GetRedlineMergeFlag() != SwNode::Merge::Hidden)
+                && ( !IsFromChapter() ||
+                    ::lcl_FindChapterNode(*pCNd, pLayout) == pOwnChapterNode ))
             {
-                std::unique_ptr<SwTOXPara> pNew( new SwTOXPara( *pCNd, eMyType,
+                std::unique_ptr<SwTOXPara> pNew( MakeSwTOXSortTabBase<SwTOXPara>(
+                        pLayout, *pCNd, eMyType,
                             ( USHRT_MAX != nSetLevel )
                             ? static_cast<sal_uInt16>(nSetLevel)
                             : FORM_ALPHA_DELIMITTER ) );
@@ -1472,7 +1510,8 @@ void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType,
 }
 
 /// Collect table entries
-void SwTOXBaseSection::UpdateTable( const SwTextNode* pOwnChapterNode )
+void SwTOXBaseSection::UpdateTable(const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwNodes& rNds = pDoc->GetNodes();
@@ -1494,14 +1533,17 @@ void SwTOXBaseSection::UpdateTable( const SwTextNode* pOwnChapterNode )
             while( nullptr != ( pCNd = rNds.GoNext( &aContentIdx ) ) &&
                 aContentIdx.GetIndex() < pTableNd->EndOfSectionIndex() )
             {
-                if( pCNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) && (!IsFromChapter() ||
-                    ::lcl_FindChapterNode( *pCNd ) == pOwnChapterNode ))
+                if (pCNd->getLayoutFrame(pLayout)
+                    && (!pLayout || !pLayout->IsHideRedlines()
+                        || pCNd->GetRedlineMergeFlag() != SwNode::Merge::Hidden)
+                    && (!IsFromChapter()
+                        || ::lcl_FindChapterNode(*pCNd, pLayout) == pOwnChapterNode))
                 {
                     std::unique_ptr<SwTOXTable> pNew(new SwTOXTable( *pCNd ));
                     if( IsLevelFromChapter() && TOX_TABLES != SwTOXBase::GetType())
                     {
                         const SwTextNode* pOutlNd =
-                            ::lcl_FindChapterNode( *pCNd, MAXLEVEL - 1 );
+                            ::lcl_FindChapterNode(*pCNd, pLayout, MAXLEVEL - 1);
                         if( pOutlNd )
                         {
                             if( pOutlNd->GetTextColl()->IsAssignedToListLevelOfOutlineStyle())
@@ -1511,6 +1553,7 @@ void SwTOXBaseSection::UpdateTable( const SwTextNode* pOwnChapterNode )
                             }
                         }
                     }
+                    pNew->InitText(pLayout);
                     InsertSorted(std::move(pNew));
                     break;
                 }
@@ -1919,8 +1962,8 @@ Range SwTOXBaseSection::GetKeyRange(const OUString& rStr, const OUString& rStrRe
     }
     if(i == nMax)
     {   // If not already present, create and insert
-        std::unique_ptr<SwTOXCustom> pKey(new SwTOXCustom( aToCompare, nLevel, rIntl,
-                                             rNew.GetLocale() ));
+        std::unique_ptr<SwTOXCustom> pKey(MakeSwTOXSortTabBase<SwTOXCustom>(
+                    nullptr, aToCompare, nLevel, rIntl, rNew.GetLocale() ));
         for(i = nMin; i < nMax; ++i)
         {
             if(nLevel == aSortArr[i]->GetLevel() &&  *pKey < *(aSortArr[i]))
diff --git a/sw/source/core/edit/edtox.cxx b/sw/source/core/edit/edtox.cxx
index 54ff2b286a8c..b6c1c5df59fb 100644
--- a/sw/source/core/edit/edtox.cxx
+++ b/sw/source/core/edit/edtox.cxx
@@ -137,7 +137,7 @@ void SwEditShell::InsertTableOf( const SwTOXBase& rTOX, const SfxItemSet* pSet )
 
     // Insert listing
     const SwTOXBaseSection* pTOX = mxDoc->InsertTableOf(
-                                        *GetCursor()->GetPoint(), rTOX, pSet, true );
+                *GetCursor()->GetPoint(), rTOX, pSet, true, GetLayout() );
     OSL_ENSURE(pTOX, "No current TOx");
 
     // start formatting
@@ -175,7 +175,7 @@ bool SwEditShell::UpdateTableOf( const SwTOXBase& rTOX, const SfxItemSet* pSet )
         pMyDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::TOXCHANGE, nullptr);
 
         // create listing stub
-        pTOX->Update(pSet);
+        pTOX->Update(pSet, GetLayout());
 
         // correct Cursor
         if( bInIndex )
@@ -217,7 +217,7 @@ const SwTOXType* SwEditShell::GetTOXType(TOXTypes eTyp, sal_uInt16 nId) const
 
 void SwEditShell::GetTOIKeys( SwTOIKeyType eTyp, std::vector<OUString>& rArr ) const
 {
-    GetDoc()->GetTOIKeys( eTyp, rArr );
+    GetDoc()->GetTOIKeys( eTyp, rArr, *GetLayout() );
 }
 
 sal_uInt16 SwEditShell::GetTOXCount() const
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index 049e57ffd19e..cb80f96854c9 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -1101,33 +1101,37 @@ void SwGetRefFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew
     NotifyClients( pOld, pNew );
 }
 
-static bool
-IsRefMarkHidden(SwRootFrame const& rLayout, SwTextRefMark const& rRefMark)
+namespace sw {
+
+bool IsMarkHintHidden(SwRootFrame const& rLayout,
+        SwTextNode const& rNode, SwTextAttrEnd const& rHint)
 {
     if (!rLayout.IsHideRedlines())
     {
         return false;
     }
-    SwTextNode const& rNode(rRefMark.GetTextNode());
     SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
         rNode.getLayoutFrame(&rLayout)));
     if (!pFrame)
     {
         return true;
     }
-    sal_Int32 const*const pEnd(const_cast<SwTextRefMark&>(rRefMark).GetEnd());
+    sal_Int32 const*const pEnd(const_cast<SwTextAttrEnd &>(rHint).GetEnd());
     if (pEnd)
     {
-        return pFrame->MapModelToView(&rNode, rRefMark.GetStart())
+        return pFrame->MapModelToView(&rNode, rHint.GetStart())
             == pFrame->MapModelToView(&rNode, *pEnd);
     }
     else
     {
-        return pFrame->MapModelToView(&rNode, rRefMark.GetStart())
-            == pFrame->MapModelToView(&rNode, rRefMark.GetStart() + 1);
+        assert(rHint.HasDummyChar());
+        return pFrame->MapModelToView(&rNode, rHint.GetStart())
+            == pFrame->MapModelToView(&rNode, rHint.GetStart() + 1);
     }
 }
 
+} // namespace sw
+
 SwTextNode* SwGetRefFieldType::FindAnchor( SwDoc* pDoc, const OUString& rRefMark,
                                         sal_uInt16 nSubType, sal_uInt16 nSeqNo,
                                         sal_Int32* pStt, sal_Int32* pEnd,
@@ -1143,7 +1147,8 @@ SwTextNode* SwGetRefFieldType::FindAnchor( SwDoc* pDoc, const OUString& rRefMark
         {
             const SwFormatRefMark *pRef = pDoc->GetRefMark( rRefMark );
             SwTextRefMark const*const pRefMark(pRef ? pRef->GetTextRefMark() : nullptr);
-            if (pRefMark && (!pLayout || !IsRefMarkHidden(*pLayout, *pRefMark)))
+            if (pRefMark && (!pLayout || !sw::IsMarkHintHidden(*pLayout,
+                                           pRefMark->GetTextNode(), *pRefMark)))
             {
                 pTextNd = const_cast<SwTextNode*>(&pRef->GetTextRefMark()->GetTextNode());
                 *pStt = pRef->GetTextRefMark()->GetStart();
diff --git a/sw/source/core/inc/doctxm.hxx b/sw/source/core/inc/doctxm.hxx
index 9eba84b25630..629d5f2b4589 100644
--- a/sw/source/core/inc/doctxm.hxx
+++ b/sw/source/core/inc/doctxm.hxx
@@ -36,14 +36,21 @@ class SwTOXBaseSection : public SwTOXBase, public SwSection
     std::vector<std::unique_ptr<SwTOXSortTabBase>> aSortArr;
 
     void UpdateMarks( const SwTOXInternational& rIntl,
-                      const SwTextNode* pOwnChapterNode );
-    void UpdateOutline( const SwTextNode* pOwnChapterNode );
-    void UpdateTemplate( const SwTextNode* pOwnChapterNode );
+             const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateOutline( const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateTemplate( const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
     void UpdateContent( SwTOXElement eType,
-                      const SwTextNode* pOwnChapterNode );
-    void UpdateTable( const SwTextNode* pOwnChapterNode );
-    void UpdateSequence( const SwTextNode* pOwnChapterNode );
-    void UpdateAuthorities( const SwTOXInternational& rIntl );
+             const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateTable( const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateSequence( const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateAuthorities( const SwTOXInternational& rIntl,
+             SwRootFrame const* pLayout );
 
     // insert sorted into array for creation
     void InsertSorted(std::unique_ptr<SwTOXSortTabBase> pBase);
@@ -73,6 +80,7 @@ public:
     // <_bNewTOX> : distinguish between the creation of a new table-of-content
     //              (true) or an update of a table-of-content (false)
     void Update( const SfxItemSet* pAttr = nullptr,
+                 SwRootFrame const* pLayout = nullptr,
                  const bool        _bNewTOX = false );
     void UpdatePageNum();               // insert page numbering
 
diff --git a/sw/source/core/inc/txmsrt.hxx b/sw/source/core/inc/txmsrt.hxx
index 2bb74d78d725..dcc91e673d93 100644
--- a/sw/source/core/inc/txmsrt.hxx
+++ b/sw/source/core/inc/txmsrt.hxx
@@ -30,6 +30,7 @@ class SwTextNode;
 class SwTextTOXMark;
 class SwIndex;
 class SwFormatField;
+class SwRootFrame;
 class IndexEntrySupplierWrapper;
 
 enum TOXSortType
@@ -138,32 +139,40 @@ struct SwTOXSortTabBase
     sal_uInt16  GetType() const         { return nType; }
     static SwTOIOptions  GetOptions()   { return nOpt; }
 
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const;
     virtual sal_uInt16  GetLevel()  const = 0;
     virtual bool    operator==( const SwTOXSortTabBase& );
     virtual bool    operator<( const SwTOXSortTabBase& );
 
     virtual OUString  GetURL() const;
 
+    virtual bool IsFullPara() const;
+
+    // must be called
+    inline void InitText(SwRootFrame const*const pLayout);
     inline TextAndReading const & GetText() const;
     inline const css::lang::Locale& GetLocale() const;
 
 private:
-    mutable bool bValidText;
-    mutable TextAndReading m_aSort;
+    bool m_bValidText;
+    TextAndReading m_aSort;
 
-    virtual TextAndReading GetText_Impl() const = 0;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const = 0;
 };
 
-inline TextAndReading const & SwTOXSortTabBase::GetText() const
+inline void SwTOXSortTabBase::InitText(SwRootFrame const*const pLayout)
 {
-    if( !bValidText )
-    {
         // 'this' is 'SwTOXSortTabBase const*', so the virtual
         // mechanism will call the derived class' GetText_Impl
-        m_aSort = GetText_Impl();
-        bValidText = true;
-    }
+    assert(!m_bValidText);
+    m_aSort = GetText_Impl(pLayout);
+    m_bValidText = true;
+}
+
+inline TextAndReading const & SwTOXSortTabBase::GetText() const
+{
+    assert(m_bValidText);
     return m_aSort;
 }
 
@@ -181,13 +190,14 @@ struct SwTOXIndex : public SwTOXSortTabBase
                 const SwTOXInternational& rIntl,
                 const css::lang::Locale& rLocale );
 
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const override;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
     virtual sal_uInt16  GetLevel() const override;
     virtual bool    operator==( const SwTOXSortTabBase& ) override;
     virtual bool    operator<( const SwTOXSortTabBase& ) override;
 
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
     sal_uInt8   nKeyLevel;
 };
@@ -203,7 +213,7 @@ struct SwTOXCustom : public SwTOXSortTabBase
     virtual bool   operator<( const SwTOXSortTabBase& ) override;
 
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
     TextAndReading m_aKey;
     sal_uInt16  nLev;
@@ -217,10 +227,11 @@ struct SwTOXContent : public SwTOXSortTabBase
     SwTOXContent( const SwTextNode&, const SwTextTOXMark*,
                 const SwTOXInternational& rIntl );
 
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const override;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
     virtual sal_uInt16  GetLevel() const override;
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
 };
 
@@ -231,12 +242,14 @@ struct SwTOXPara : public SwTOXSortTabBase
     void    SetStartIndex(sal_Int32 nSet)    { nStartIndex = nSet; }
     void    SetEndIndex(sal_Int32 nSet)      { nEndIndex = nSet; }
 
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const override;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
     virtual sal_uInt16  GetLevel() const override;
 
     virtual OUString  GetURL() const override;
+    virtual bool IsFullPara() const override;
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
     SwTOXElement eType;
     sal_uInt16 m_nLevel;
@@ -255,7 +268,7 @@ struct SwTOXTable : public SwTOXSortTabBase
 
     virtual OUString  GetURL() const override;
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
     sal_uInt16 nLevel;
 };
@@ -264,8 +277,9 @@ struct SwTOXAuthority : public SwTOXSortTabBase
 {
 private:
     SwFormatField& m_rField;
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const override;
-    virtual TextAndReading GetText_Impl() const override;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
 public:
     SwTOXAuthority( const SwContentNode& rNd, SwFormatField& rField, const SwTOXInternational& rIntl );
diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx
index 0a5aab44a349..436e89330c16 100644
--- a/sw/source/core/inc/txtfrm.hxx
+++ b/sw/source/core/inc/txtfrm.hxx
@@ -30,6 +30,7 @@ namespace com { namespace sun { namespace star { namespace linguistic2 { class X
 namespace sw { namespace mark { class IMark; } }
 class SwCharRange;
 class SwTextNode;
+class SwTextAttrEnd;
 class SwTextFormatter;
 class SwTextFormatInfo;
 class SwParaPortion;
@@ -138,6 +139,8 @@ OUString GetExpandTextMerged(SwRootFrame const* pLayout,
         bool bWithSpacesForLevel, ExpandMode i_mode);
 
 bool IsMarkHidden(SwRootFrame const& rLayout, ::sw::mark::IMark const& rMark);
+bool IsMarkHintHidden(SwRootFrame const& rLayout,
+        SwTextNode const& rNode, SwTextAttrEnd const& rHint);
 
 } // namespace sw
 
diff --git a/sw/source/core/tox/ToxTextGenerator.cxx b/sw/source/core/tox/ToxTextGenerator.cxx
index 11b2ac3a4558..04e6bd63bb0d 100644
--- a/sw/source/core/tox/ToxTextGenerator.cxx
+++ b/sw/source/core/tox/ToxTextGenerator.cxx
@@ -21,6 +21,9 @@
 
 #include <chpfld.hxx>
 #include <cntfrm.hxx>
+#include <txtfrm.hxx>
+#include <rootfrm.hxx>
+#include <ndindex.hxx>
 #include <fchrfmt.hxx>
 #include <doc.hxx>
 #include <IDocumentLayoutAccess.hxx>
@@ -63,7 +66,9 @@ bool sortTabHasNoToxSourcesOrFirstToxSourceHasNoNode(const SwTOXSortTabBase& sor
 namespace sw {
 
 OUString
-ToxTextGenerator::GetNumStringOfFirstNode( const SwTOXSortTabBase& rBase, bool bUsePrefix, sal_uInt8 nLevel )
+ToxTextGenerator::GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase,
+        bool bUsePrefix, sal_uInt8 nLevel,
+        SwRootFrame const*const pLayout)
 {
     if (sortTabHasNoToxSourcesOrFirstToxSourceHasNoNode(rBase)) {
         return OUString();
@@ -78,6 +83,10 @@ ToxTextGenerator::GetNumStringOfFirstNode( const SwTOXSortTabBase& rBase, bool b
     if (!pNd) {
         return sRet;
     }
+    if (pLayout && pLayout->IsHideRedlines())
+    {   // note: pNd could be any node, since it could be Sequence etc.
+        pNd = sw::GetParaPropsNode(*pLayout, SwNodeIndex(*pNd));
+    }
 
     const SwNumRule* pRule = pNd->GetNumRule();
     if (!pRule) {
@@ -85,7 +94,7 @@ ToxTextGenerator::GetNumStringOfFirstNode( const SwTOXSortTabBase& rBase, bool b
     }
 
     if (pNd->GetActualListLevel() < MAXLEVEL) {
-        sRet = pNd->GetNumString(bUsePrefix, nLevel);
+        sRet = pNd->GetNumString(bUsePrefix, nLevel, pLayout);
     }
 
     if (!sRet.isEmpty()) {
@@ -107,8 +116,8 @@ ToxTextGenerator::~ToxTextGenerator()
 {}
 
 OUString
-ToxTextGenerator::HandleChapterToken(const SwTOXSortTabBase& rBase, const SwFormToken& aToken,
-        SwDoc* pDoc) const
+ToxTextGenerator::HandleChapterToken(const SwTOXSortTabBase& rBase,
+        const SwFormToken& aToken, SwRootFrame const*const pLayout) const
 {
     if (sortTabHasNoToxSourcesOrFirstToxSourceHasNoNode(rBase)) {
         return OUString();
@@ -121,17 +130,18 @@ ToxTextGenerator::HandleChapterToken(const SwTOXSortTabBase& rBase, const SwForm
     }
 
     // #i53420#
-    const SwContentFrame* contentFrame = contentNode->getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
+    const SwContentFrame* contentFrame = contentNode->getLayoutFrame(pLayout);
     if (!contentFrame) {
         return OUString();
     }
 
-    return GenerateTextForChapterToken(aToken, contentFrame, contentNode);
+    return GenerateTextForChapterToken(aToken, contentFrame, contentNode, pLayout);
 }
 
 OUString
 ToxTextGenerator::GenerateTextForChapterToken(const SwFormToken& chapterToken, const SwContentFrame* contentFrame,
-        const SwContentNode *contentNode) const
+        const SwContentNode *contentNode,
+        SwRootFrame const*const pLayout) const
 {
     OUString retval;
 
@@ -142,14 +152,14 @@ ToxTextGenerator::GenerateTextForChapterToken(const SwFormToken& chapterToken, c
     // continue to support CF_NUMBER and CF_NUM_TITLE in order to handle ODF 1.0/1.1 written by OOo 3.x
     // in the same way as OOo 2.x would handle them.
     if (CF_NUM_NOPREPST_TITLE == chapterToken.nChapterFormat || CF_NUMBER == chapterToken.nChapterFormat) {
-        retval += aField.GetNumber(); // get the string number without pre/postfix
+        retval += aField.GetNumber(pLayout); // get the string number without pre/postfix
     }
     else if (CF_NUMBER_NOPREPST == chapterToken.nChapterFormat || CF_NUM_TITLE == chapterToken.nChapterFormat) {
-        retval += aField.GetNumber();
+        retval += aField.GetNumber(pLayout);
         retval += " ";
-        retval += aField.GetTitle();
+        retval += aField.GetTitle(pLayout);
     } else if (CF_TITLE == chapterToken.nChapterFormat) {
-        retval += aField.GetTitle();
+        retval += aField.GetTitle(pLayout);
     }
     return retval;
 }
@@ -158,7 +168,8 @@ ToxTextGenerator::GenerateTextForChapterToken(const SwFormToken& chapterToken, c
 // which page description is used, no appropriate one is found.
 void
 ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<SwTOXSortTabBase>> &entries,
-        sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess)
+        sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess,
+        SwRootFrame const*const pLayout)
 {
     // pTOXNd is only set at the first mark
     SwTextNode* pTOXNd = const_cast<SwTextNode*>(entries.at(indexOfEntryToProcess)->pTOXNd);
@@ -188,11 +199,13 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<Sw
             {
             case TOKEN_ENTRY_NO:
                 // for TOC numbering
-                rText += GetNumStringOfFirstNode( rBase, aToken.nChapterFormat == CF_NUMBER, static_cast<sal_uInt8>(aToken.nOutlineLevel - 1) ) ;
+                rText += GetNumStringOfFirstNode(rBase,
+                    aToken.nChapterFormat == CF_NUMBER,
+                    static_cast<sal_uInt8>(aToken.nOutlineLevel - 1), pLayout);
                 break;
 
             case TOKEN_ENTRY_TEXT: {
-                HandledTextToken htt = HandleTextToken(rBase, pDoc->GetAttrPool());
+                HandledTextToken htt = HandleTextToken(rBase, pDoc->GetAttrPool(), pLayout);
                 ApplyHandledTextToken(htt, *pTOXNd);
             }
                 break;
@@ -200,8 +213,8 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<Sw
             case TOKEN_ENTRY:
                 {
                     // for TOC numbering
-                    rText += GetNumStringOfFirstNode( rBase, true, MAXLEVEL );
-                    HandledTextToken htt = HandleTextToken(rBase, pDoc->GetAttrPool() );
+                    rText += GetNumStringOfFirstNode(rBase, true, MAXLEVEL, pLayout);
+                    HandledTextToken htt = HandleTextToken(rBase, pDoc->GetAttrPool(), pLayout);
                     ApplyHandledTextToken(htt, *pTOXNd);
                 }
                 break;
@@ -223,7 +236,7 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<Sw
                 break;
 
             case TOKEN_CHAPTER_INFO:
-                rText += HandleChapterToken(rBase, aToken, pDoc);
+                rText += HandleChapterToken(rBase, aToken, pLayout);
                 break;
 
             case TOKEN_LINK_START:
@@ -238,7 +251,7 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<Sw
                 {
                     ToxAuthorityField eField = static_cast<ToxAuthorityField>(aToken.nAuthorityField);
                     SwIndex aIdx( pTOXNd, rText.getLength() );
-                    rBase.FillText( *pTOXNd, aIdx, static_cast<sal_uInt16>(eField) );
+                    rBase.FillText( *pTOXNd, aIdx, static_cast<sal_uInt16>(eField), pLayout );
                 }
                 break;
             case TOKEN_END: break;
@@ -294,40 +307,98 @@ ToxTextGenerator::CollectAttributesForTox(const SwTextAttr& hint, SwAttrPool& po
     return retval;
 }
 
+void ToxTextGenerator::GetAttributesForNode(
+    ToxTextGenerator::HandledTextToken & rResult,
+    sal_Int32 & rOffset,
+    SwTextNode const& rNode,
+    ToxWhitespaceStripper const& rStripper,
+    SwAttrPool & rPool,
+    SwRootFrame const*const pLayout)
+{
+    // note: this *must* use the same flags as SwTextNode::GetExpandText()
+    // or indexes will be off!
+    ExpandMode eMode = ExpandMode::ExpandFields;
+    if (pLayout && pLayout->IsHideRedlines())
+    {
+        eMode |= ExpandMode::HideDeletions;
+    }
+    ModelToViewHelper aConversionMap(rNode, pLayout, eMode);
+    if (SwpHints const*const pHints = rNode.GetpSwpHints())
+    {
+        for (size_t i = 0; i < pHints->Count(); ++i)
+        {
+            const SwTextAttr* pHint = pHints->Get(i);
+            std::shared_ptr<SfxItemSet> attributesToClone =
+                CollectAttributesForTox(*pHint, rPool);
+            if (attributesToClone->Count() <= 0) {
+                continue;
+            }
+
+            // sw_redlinehide: due to the ... interesting ... multi-level index
+            // mapping going on here, can't use the usual merged attr iterators :(
+
+            sal_Int32 const nStart(aConversionMap.ConvertToViewPosition(pHint->GetStart()));
+            sal_Int32 const nEnd(aConversionMap.ConvertToViewPosition(*pHint->GetAnyEnd()));
+            if (nStart != nEnd) // might be in delete redline, and useless anyway
+            {
+                SwFormatAutoFormat *const pClone(
+                    static_cast<SwFormatAutoFormat*>(pHint->GetAutoFormat().Clone()));
+                pClone->SetStyleHandle(attributesToClone);
+                rResult.autoFormats.push_back(pClone);
+                // note the rStripper is on the whole merged text, so need rOffset
+                rResult.startPositions.push_back(
+                    rStripper.GetPositionInStrippedString(rOffset + nStart));
+                rResult.endPositions.push_back(
+                    rStripper.GetPositionInStrippedString(rOffset + nEnd));
+            }
+        }
+    }
+    rOffset += aConversionMap.getViewText().getLength();
+}
+
 ToxTextGenerator::HandledTextToken
-ToxTextGenerator::HandleTextToken(const SwTOXSortTabBase& source, SwAttrPool& pool)
+ToxTextGenerator::HandleTextToken(const SwTOXSortTabBase& source,
+        SwAttrPool& pool, SwRootFrame const*const pLayout)
 {
     HandledTextToken result;
     ToxWhitespaceStripper stripper(source.GetText().sText);
     result.text = stripper.GetStrippedString();
 
-    if( source.aTOXSources.empty() )
+    // FIXME: there is a pre-existing problem that the index mapping of the
+    // attributes only works if the paragraph is fully selected
+    if (!source.IsFullPara() || source.aTOXSources.empty())
         return result;
 
     const SwTextNode* pSrc = source.aTOXSources.front().pNd->GetTextNode();
-    if (!pSrc || !pSrc->HasHints()) {
+    if (!pSrc)
+    {
         return result;
     }
-    const SwpHints& hints = pSrc->GetSwpHints();
-    for (size_t i = 0; i < hints.Count(); ++i) {
-        const SwTextAttr* hint = hints.Get(i);
-        std::shared_ptr<SfxItemSet> attributesToClone = CollectAttributesForTox(*hint, pool);
-        if (attributesToClone->Count() <= 0) {
-            continue;
+
+    sal_Int32 nOffset(0);
+    GetAttributesForNode(result, nOffset, *pSrc, stripper, pool, pLayout);
+    if (pLayout && pLayout->IsHideRedlines())
+    {
+        if (SwTextFrame const*const pFrame = static_cast<SwTextFrame*>(pSrc->getLayoutFrame(pLayout)))
+        {
+            if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara())
+            {
+                // pSrc already copied above
+                assert(pSrc == pMerged->pParaPropsNode);
+                for (sal_uLong i = pSrc->GetIndex() + 1;
+                     i <= pMerged->pLastNode->GetIndex(); ++i)
+                {
+                    SwNode *const pTmp(pSrc->GetNodes()[i]);
+                    if (pTmp->GetRedlineMergeFlag() == SwNode::Merge::NonFirst)
+                    {
+                        GetAttributesForNode(result, nOffset,
+                                *pTmp->GetTextNode(), stripper, pool, pLayout);
+                    }
+                }
+            }
         }
-        SwFormatAutoFormat* clone = static_cast<SwFormatAutoFormat*>(hint->GetAutoFormat().Clone());
-        clone->SetStyleHandle(attributesToClone);
-
-        result.autoFormats.push_back(clone);
-
-        ModelToViewHelper aConversionMap(*pSrc, nullptr, ExpandMode::ExpandFields);
-        result.startPositions.push_back(
-                stripper.GetPositionInStrippedString(aConversionMap.ConvertToViewPosition(
-                        hint->GetStart() )));
-        result.endPositions.push_back(
-                stripper.GetPositionInStrippedString(aConversionMap.ConvertToViewPosition(
-                        *hint->GetAnyEnd() )));
     }
+
     return result;
 }
 
diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx
index d284a693e55b..3b3e61e5481e 100644
--- a/sw/source/core/tox/tox.cxx
+++ b/sw/source/core/tox/tox.cxx
@@ -164,7 +164,7 @@ void SwTOXMark::InvalidateTOXMark()
     NotifyClients(&aMsgHint, &aMsgHint);
 }
 
-OUString SwTOXMark::GetText() const
+OUString SwTOXMark::GetText(SwRootFrame const*const pLayout) const
 {
     if( !m_aAltText.isEmpty() )
         return m_aAltText;
@@ -176,7 +176,7 @@ OUString SwTOXMark::GetText() const
         if( pEndIdx )
         {
             const sal_Int32 nStt = m_pTextAttr->GetStart();
-            return m_pTextAttr->GetpTextNd()->GetExpandText(nullptr, nStt, *pEndIdx-nStt);
+            return m_pTextAttr->GetpTextNd()->GetExpandText(pLayout, nStt, *pEndIdx-nStt);
         }
     }
 
diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx
index 2a649cf4e2fd..3e814c72c15b 100644
--- a/sw/source/core/tox/txmsrt.cxx
+++ b/sw/source/core/tox/txmsrt.cxx
@@ -26,6 +26,9 @@
 #include <IDocumentMarkAccess.hxx>
 #include <docary.hxx>
 #include <cntfrm.hxx>
+#include <txtfrm.hxx>
+#include <rootfrm.hxx>
+#include <modeltoviewhelper.hxx>
 #include <node.hxx>
 #include <frmatr.hxx>
 #include <pam.hxx>
@@ -132,7 +135,8 @@ SwTOXSortTabBase::SwTOXSortTabBase( TOXSortType nTyp, const SwContentNode* pNd,
                                     const SwTOXInternational* pInter,
                                     const lang::Locale* pLocale )
     : pTOXNd( nullptr ), pTextMark( pMark ), pTOXIntl( pInter ),
-    nPos( 0 ), nCntPos( 0 ), nType( static_cast<sal_uInt16>(nTyp) ), bValidText( false )
+    nPos( 0 ), nCntPos( 0 ), nType( static_cast<sal_uInt16>(nTyp) )
+    , m_bValidText( false )
 {
     if ( pLocale )
         aLocale = *pLocale;
@@ -185,8 +189,13 @@ OUString SwTOXSortTabBase::GetURL() const
     return OUString();
 }
 
+bool SwTOXSortTabBase::IsFullPara() const
+{
+    return false;
+}
+
 void SwTOXSortTabBase::FillText( SwTextNode& rNd, const SwIndex& rInsPos,
-                                    sal_uInt16 ) const
+                                    sal_uInt16, SwRootFrame const*const) const
 {
     rNd.InsertText( GetText().sText, rInsPos );
 }
@@ -328,7 +337,7 @@ bool SwTOXIndex::operator<( const SwTOXSortTabBase& rCmpBase )
 
 // The keyword itself
 
-TextAndReading SwTOXIndex::GetText_Impl() const
+TextAndReading SwTOXIndex::GetText_Impl(SwRootFrame const*const pLayout) const
 {
     OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
     const SwTOXMark& rTOXMark = pTextMark->GetTOXMark();
@@ -350,7 +359,7 @@ TextAndReading SwTOXIndex::GetText_Impl() const
         break;
         case FORM_ENTRY          :
         {
-            aRet.sText = rTOXMark.GetText();
+            aRet.sText = rTOXMark.GetText(pLayout);
             aRet.sReading = rTOXMark.GetTextReading();
         }
         break;
@@ -364,8 +373,10 @@ TextAndReading SwTOXIndex::GetText_Impl() const
     return aRet;
 }
 
-void SwTOXIndex::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
+void SwTOXIndex::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
+        SwRootFrame const*const pLayout) const
 {
+    assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
     const sal_Int32* pEnd = pTextMark->End();
 
     TextAndReading aRet;
@@ -373,9 +384,13 @@ void SwTOXIndex::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 )
             !(GetOptions() & SwTOIOptions::KeyAsEntry))
     {
         aRet.sText = static_cast<const SwTextNode*>(aTOXSources[0].pNd)->GetExpandText(
-                            nullptr,
+                            pLayout,
                             pTextMark->GetStart(),
-                            *pEnd - pTextMark->GetStart());
+                            *pEnd - pTextMark->GetStart(),
+                            false, false, false,
+                            pLayout && pLayout->IsHideRedlines()
+                                ? ExpandMode::HideDeletions
+                                : ExpandMode(0));
         if(SwTOIOptions::InitialCaps & nOpt && pTOXIntl && !aRet.sText.isEmpty())
         {
             aRet.sText = pTOXIntl->ToUpper( aRet.sText, 0 ) + aRet.sText.copy(1);
@@ -432,7 +447,7 @@ sal_uInt16 SwTOXCustom::GetLevel() const
     return nLev;
 }
 
-TextAndReading SwTOXCustom::GetText_Impl() const
+TextAndReading SwTOXCustom::GetText_Impl(SwRootFrame const*const) const
 {
     return m_aKey;
 }
@@ -446,29 +461,36 @@ SwTOXContent::SwTOXContent( const SwTextNode& rNd, const SwTextTOXMark* pMark,
 
 // The content's text
 
-TextAndReading SwTOXContent::GetText_Impl() const
+TextAndReading SwTOXContent::GetText_Impl(SwRootFrame const*const pLayout) const
 {
     const sal_Int32* pEnd = pTextMark->End();
     if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() )
     {
         return TextAndReading(
             static_cast<const SwTextNode*>(aTOXSources[0].pNd)->GetExpandText(
-                                     nullptr,
+                                     pLayout,
                                      pTextMark->GetStart(),
-                                     *pEnd - pTextMark->GetStart() ),
+                                     *pEnd - pTextMark->GetStart(),
+                            false, false, false,
+                            pLayout && pLayout->IsHideRedlines()
+                                ? ExpandMode::HideDeletions
+                                : ExpandMode(0)),
             pTextMark->GetTOXMark().GetTextReading());
     }
 
     return TextAndReading(pTextMark->GetTOXMark().GetAlternativeText(), OUString());
 }
 
-void SwTOXContent::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
+void SwTOXContent::FillText(SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
+        SwRootFrame const*const pLayout) const
 {
+    assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
     const sal_Int32* pEnd = pTextMark->End();
     if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() )
+        // sw_redlinehide: this probably won't HideDeletions
         static_cast<const SwTextNode*>(aTOXSources[0].pNd)->CopyExpandText(
                 rNd, &rInsPos, pTextMark->GetStart(),
-                *pEnd - pTextMark->GetStart(), nullptr );
+                *pEnd - pTextMark->GetStart(), pLayout);
     else
     {
         rNd.InsertText( GetText().sText, rInsPos );
@@ -495,20 +517,34 @@ SwTOXPara::SwTOXPara( const SwContentNode& rNd, SwTOXElement eT, sal_uInt16 nLev
 {
 }
 
-TextAndReading SwTOXPara::GetText_Impl() const
+TextAndReading SwTOXPara::GetText_Impl(SwRootFrame const*const pLayout) const
 {
     const SwContentNode* pNd = aTOXSources[0].pNd;
     switch( eType )
     {
     case SwTOXElement::Sequence:
+        if (nStartIndex != 0 || nEndIndex != -1)
+        {
+            // sw_redlinehide: "captions" are a rather fuzzily defined concept anyway
+            return TextAndReading(static_cast<const SwTextNode*>(pNd)->GetExpandText(
+                        pLayout,
+                        nStartIndex,
+                        nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
+                        false, false, false,
+                        pLayout && pLayout->IsHideRedlines()
+                            ? ExpandMode::HideDeletions
+                            : ExpandMode(0)),
+                    OUString());
+        }
+        BOOST_FALLTHROUGH;
     case SwTOXElement::Template:
     case SwTOXElement::OutlineLevel:
         {
-            return TextAndReading(static_cast<const SwTextNode*>(pNd)->GetExpandText(
-                    nullptr,
-                    nStartIndex,
-                    nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
-                    false, false, false),
+            assert(nStartIndex == 0);
+            assert(nEndIndex == -1);
+            return TextAndReading(sw::GetExpandTextMerged(
+                        pLayout, *static_cast<const SwTextNode*>(pNd),
+                        false, false, ExpandMode(0)),
                     OUString());
         }
         break;
@@ -536,14 +572,51 @@ TextAndReading SwTOXPara::GetText_Impl() const
     return TextAndReading();
 }
 
-void SwTOXPara::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
+void SwTOXPara::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
+        SwRootFrame const*const pLayout) const
 {
+    assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
     if( SwTOXElement::Template == eType || SwTOXElement::Sequence == eType  || SwTOXElement::OutlineLevel == eType)
     {
         const SwTextNode* pSrc = static_cast<const SwTextNode*>(aTOXSources[0].pNd);
-        pSrc->CopyExpandText( rNd, &rInsPos, nStartIndex,
-                nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
-                nullptr, false, false, true );
+        if (SwTOXElement::Sequence == eType
+            && (nStartIndex != 0 || nEndIndex != -1))
+        {
+            pSrc->CopyExpandText( rNd, &rInsPos, nStartIndex,
+                    nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
+                    pLayout, false, false, true );
+        }
+        else
+        {
+            assert(nStartIndex == 0);
+            assert(nEndIndex == -1);
+            // sw_redlinehide: this probably won't HideDeletions
+            pSrc->CopyExpandText( rNd, &rInsPos, 0, -1,
+                    pLayout, false, false, true );
+            if (pLayout && pLayout->IsHideRedlines())
+            {
+                if (SwTextFrame const*const pFrame = static_cast<SwTextFrame*>(pSrc->getLayoutFrame(pLayout)))
+                {
+                    if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara())
+                    {
+                        // pSrc already copied above
+                        assert(pSrc == pMerged->pParaPropsNode);
+                        for (sal_uLong i = pSrc->GetIndex() + 1;
+                             i <= pMerged->pLastNode->GetIndex(); ++i)
+                        {
+                            SwNode *const pTmp(pSrc->GetNodes()[i]);
+                            if (pTmp->GetRedlineMergeFlag() == SwNode::Merge::NonFirst)
+                            {
+
+                                pTmp->GetTextNode()->CopyExpandText(
+                                        rNd, &rInsPos, 0, -1,
+                                        pLayout, false, false, false );
+                            }
+                        }
+                    }
+                }
+            }
+        }
     }
     else
     {
@@ -617,6 +690,19 @@ OUString SwTOXPara::GetURL() const
     return aText;
 }
 
+bool SwTOXPara::IsFullPara() const
+{
+    switch (eType)
+    {
+        case SwTOXElement::Sequence:
+        case SwTOXElement::Template:
+        case SwTOXElement::OutlineLevel:
+            return nStartIndex == 0 && nEndIndex == -1;
+        default:
+            return false;
+    }
+}
+
 // Table
 SwTOXTable::SwTOXTable( const SwContentNode& rNd )
     : SwTOXSortTabBase( TOX_SORT_TABLE, &rNd, nullptr, nullptr ),
@@ -624,7 +710,7 @@ SwTOXTable::SwTOXTable( const SwContentNode& rNd )
 {
 }
 
-TextAndReading SwTOXTable::GetText_Impl() const
+TextAndReading SwTOXTable::GetText_Impl(SwRootFrame const*const) const
 {
     const SwNode* pNd = aTOXSources[0].pNd;
     if( pNd )
@@ -688,24 +774,25 @@ sal_uInt16 SwTOXAuthority::GetLevel() const
     return nRet;
 }
 
-static OUString lcl_GetText(SwFormatField const& rField)
+static OUString lcl_GetText(SwFormatField const& rField, SwRootFrame const*const pLayout)
 {
-    return rField.GetField()->ExpandField(true, nullptr);
+    return rField.GetField()->ExpandField(true, pLayout);
 }
 
-TextAndReading SwTOXAuthority::GetText_Impl() const
+TextAndReading SwTOXAuthority::GetText_Impl(SwRootFrame const*const pLayout) const
 {
-    return TextAndReading(lcl_GetText(m_rField), OUString());
+    return TextAndReading(lcl_GetText(m_rField, pLayout), OUString());
 }
 
 void    SwTOXAuthority::FillText( SwTextNode& rNd,
-                        const SwIndex& rInsPos, sal_uInt16 nAuthField ) const
+                        const SwIndex& rInsPos, sal_uInt16 nAuthField,
+        SwRootFrame const*const pLayout) const
 {
     SwAuthorityField* pField = static_cast<SwAuthorityField*>(m_rField.GetField());
     OUString sText;
     if(AUTH_FIELD_IDENTIFIER == nAuthField)
     {
-        sText = lcl_GetText(m_rField);
+        sText = lcl_GetText(m_rField, pLayout);
         const SwAuthorityFieldType* pType = static_cast<const SwAuthorityFieldType*>(pField->GetTyp());
         sal_Unicode cChar = pType->GetPrefix();
         if(cChar && cChar != ' ')
diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx
index 76f4faf3e09b..076cd53afb84 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -1271,7 +1271,7 @@ void SAL_CALL SwXDocumentIndex::refresh()
                     "SwXDocumentIndex::refresh: must be in attached state",
                      static_cast< ::cppu::OWeakObject*>(this));
         }
-        pTOXBase->Update();
+        pTOXBase->Update(nullptr, m_pImpl->m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
 
         // the insertion of TOC will affect the document layout
         lcl_CalcLayout(m_pImpl->m_pDoc);
@@ -1353,7 +1353,8 @@ SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange)
     }
     //TODO: apply Section attributes (columns and background)
     SwTOXBaseSection *const pTOX =
-        pDoc->InsertTableOf( *aPam.GetPoint(), rTOXBase );
+        pDoc->InsertTableOf( *aPam.GetPoint(), rTOXBase, nullptr, false,
+                m_pImpl->m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
 
     pDoc->SetTOXBaseName(*pTOX, m_pImpl->m_pProps->GetTOXBase().GetTOXName());
 
diff --git a/sw/source/ui/index/multmrk.cxx b/sw/source/ui/index/multmrk.cxx
index 735927a58ff5..7cc876e1f004 100644
--- a/sw/source/ui/index/multmrk.cxx
+++ b/sw/source/ui/index/multmrk.cxx
@@ -20,6 +20,7 @@
 #include <swtypes.hxx>
 #include <multmrk.hxx>
 #include <toxmgr.hxx>
+#include <wrtsh.hxx>
 
 SwMultiTOXMarkDlg::SwMultiTOXMarkDlg(weld::Window* pParent, SwTOXMgr& rTOXMgr)
     : GenericDialogController(pParent, "modules/swriter/ui/selectindexdialog.ui", "SelectIndexDialog")
@@ -35,7 +36,7 @@ SwMultiTOXMarkDlg::SwMultiTOXMarkDlg(weld::Window* pParent, SwTOXMgr& rTOXMgr)
 
     sal_uInt16 nSize = m_rMgr.GetTOXMarkCount();
     for(sal_uInt16 i=0; i < nSize; ++i)
-        m_xTOXLB->append_text(m_rMgr.GetTOXMark(i)->GetText());
+        m_xTOXLB->append_text(m_rMgr.GetTOXMark(i)->GetText(m_rMgr.GetShell()->GetLayout()));
 
     m_xTOXLB->select(0);
     m_xTextFT->set_label(m_rMgr.GetTOXMark(0)->GetTOXType()->GetTypeName());
diff --git a/sw/source/ui/index/swuiidxmrk.cxx b/sw/source/ui/index/swuiidxmrk.cxx
index 3938320fedc0..6fd42bc867e5 100644
--- a/sw/source/ui/index/swuiidxmrk.cxx
+++ b/sw/source/ui/index/swuiidxmrk.cxx
@@ -406,13 +406,14 @@ void SwIndexMarkPane::InsertUpdate()
         InsertMark();
 
         if ( pTOXMgr->GetCurTOXMark())
-            aRewriter.AddRule(UndoArg1, pTOXMgr->GetCurTOXMark()->GetText());
+            aRewriter.AddRule(UndoArg1,
+                    pTOXMgr->GetCurTOXMark()->GetText(pSh->GetLayout()));
     }
     else if( !pSh->HasReadonlySel() )
     {
         if ( pTOXMgr->GetCurTOXMark())
             aRewriter.AddRule(UndoArg1,
-                              pTOXMgr->GetCurTOXMark()->GetText());
+                    pTOXMgr->GetCurTOXMark()->GetText(pSh->GetLayout()));
 
         if( bDel )
             pTOXMgr->DeleteTOXMark();
@@ -770,7 +771,7 @@ void SwIndexMarkPane::UpdateDialog()
 
     SwViewShell::SetCareWin(&m_rDialog);
 
-    aOrgStr = pMark->GetText();
+    aOrgStr = pMark->GetText(pSh->GetLayout());
     m_pEntryED->SetText(aOrgStr);
 
     // set index type
@@ -788,7 +789,7 @@ void SwIndexMarkPane::UpdateDialog()
         bKeyEnable = true;
         bKey1HasText = bKey2Enable = !pMark->GetPrimaryKey().isEmpty();
         bKey2HasText = !pMark->GetSecondaryKey().isEmpty();
-        bEntryHasText = !pMark->GetText().isEmpty();
+        bEntryHasText = !pMark->GetText(pSh->GetLayout()).isEmpty();
         m_pKey1DCB->SetText( pMark->GetPrimaryKey() );
         m_pKey2DCB->SetText( pMark->GetSecondaryKey() );
         m_pPhoneticED0->SetText( pMark->GetTextReading() );
diff --git a/sw/source/uibase/inc/toxmgr.hxx b/sw/source/uibase/inc/toxmgr.hxx
index 0cf6a5f22745..ae15fc6e3504 100644
--- a/sw/source/uibase/inc/toxmgr.hxx
+++ b/sw/source/uibase/inc/toxmgr.hxx
@@ -257,6 +257,7 @@ public:
     bool    UpdateOrInsertTOX(const SwTOXDescription& rDesc, SwTOXBase** ppBase, const SfxItemSet* pSet);
 
     const SwTOXType*    GetTOXType(TOXTypes eTyp) const;
+    SwWrtShell * GetShell() { return pSh; }
 };
 
 // inlines
diff --git a/sw/source/uibase/index/toxmgr.cxx b/sw/source/uibase/index/toxmgr.cxx
index b5b8b31e9198..8e06d73f667c 100644
--- a/sw/source/uibase/index/toxmgr.cxx
+++ b/sw/source/uibase/index/toxmgr.cxx
@@ -440,7 +440,7 @@ bool SwTOXMgr::UpdateOrInsertTOX(const SwTOXDescription& rDesc,
             pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::TOXCHANGE, nullptr);
         }
 
-        pDoc->ChgTOX(*pTOX, *pNewTOX);
+        pDoc->ChangeTOX(*pTOX, *pNewTOX, *pSh->GetLayout());
 
         pTOX->DisableKeepExpression();
         bRet = pSh->UpdateTableOf(*pTOX, pSet);
commit d55721cf64a84f7cd6e8c6f5a09462ed0e0701b2
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Aug 14 14:03:58 2018 +0200
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Jan 10 18:16:18 2019 +0100

    loplugin:useuniqueptr in SwTOXBaseSection
    
    Reviewed-on: https://gerrit.libreoffice.org/59030
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    (cherry picked from commit 5a6d2392e02294721ef26e38d7c174d9b7faf93e)
    
    Change-Id: I1c4d9cb4189073d83ea2872b87475b8bf79e43db

diff --git a/sw/inc/ToxTextGenerator.hxx b/sw/inc/ToxTextGenerator.hxx
index f93db784ce58..79f4d30b13d1 100644
--- a/sw/inc/ToxTextGenerator.hxx
+++ b/sw/inc/ToxTextGenerator.hxx
@@ -63,7 +63,7 @@ public:
      * process @p numberOfEntriesToProcess entries.
      */
     void
-    GenerateText(SwDoc *doc, const std::vector<SwTOXSortTabBase*>& entries,
+    GenerateText(SwDoc *doc, const std::vector<std::unique_ptr<SwTOXSortTabBase>>& entries,
                       sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess);
 
 private:
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 4fd966377350..ae827aebe4ef 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -552,7 +552,7 @@ SwTOXSortTabBase* SwAccessibleParagraph::GetTOXSortTabBase()
 
                 for(size_t nIndex = 0; nIndex<nSize; nIndex++ )
                 {
-                    pSortBase = pTOXBaseSect->GetTOXSortTabBases()[nIndex];
+                    pSortBase = pTOXBaseSect->GetTOXSortTabBases()[nIndex].get();
                     if( pSortBase->pTOXNd == pTextNd )
                         break;
                 }
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index b641395d6c70..d508f3015607 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -71,6 +71,7 @@
 #include <calbck.hxx>
 #include <ToxTextGenerator.hxx>
 #include <ToxTabStopTokenHandler.hxx>
+#include <o3tl/make_unique.hxx>
 #include <tools/datetimeutils.hxx>
 #include <tools/globname.hxx>
 
@@ -725,8 +726,6 @@ SwTOXBaseSection::SwTOXBaseSection(SwTOXBase const& rBase, SwSectionFormat & rFo
 
 SwTOXBaseSection::~SwTOXBaseSection()
 {
-    for (SwTOXSortTabBases::const_iterator it = aSortArr.begin(); it != aSortArr.end(); ++it)
-        delete *it;
 }
 
 bool SwTOXBaseSection::SetPosAtStartEnd( SwPosition& rPos ) const
@@ -834,8 +833,6 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
                                GetOptions() : SwTOIOptions::NONE,
                                GetSortAlgorithm() );
 
-    for (SwTOXSortTabBases::const_iterator it = aSortArr.begin(); it != aSortArr.end(); ++it)
-        delete *it;
     aSortArr.clear();
 
     // find the first layout node for this TOX, if it only find the content
@@ -944,7 +941,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     // Sort the List of all TOC Marks and TOC Sections
     std::vector<SwTextFormatColl*> aCollArr( GetTOXForm().GetFormMax(), nullptr );
     SwNodeIndex aInsPos( *pFirstEmptyNd, 1 );
-    for( SwTOXSortTabBases::size_type nCnt = 0; nCnt < aSortArr.size(); ++nCnt )
+    for( size_t nCnt = 0; nCnt < aSortArr.size(); ++nCnt )
     {
         ::SetProgressState( 0, pDoc->GetDocShell() );
 
@@ -1038,7 +1035,7 @@ void SwTOXBaseSection::InsertAlphaDelimitter( const SwTOXInternational& rIntl )
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     OUString sLastDeli;
-    SwTOXSortTabBases::size_type i = 0;
+    size_t i = 0;
     while( i < aSortArr.size() )
     {
         ::SetProgressState( 0, pDoc->GetDocShell() );
@@ -1058,10 +1055,10 @@ void SwTOXBaseSection::InsertAlphaDelimitter( const SwTOXInternational& rIntl )
             // We skip all that are less than a small Blank (these are special characters)
             if( ' ' <= sDeli[0] )
             {
-                SwTOXCustom* pCst = new SwTOXCustom( TextAndReading(sDeli, OUString()),
+                std::unique_ptr<SwTOXCustom> pCst(new SwTOXCustom( TextAndReading(sDeli, OUString()),
                                                      FORM_ALPHA_DELIMITTER,
-                                                     rIntl, aSortArr[i]->GetLocale() );
-                aSortArr.insert( aSortArr.begin() + i, pCst);
+                                                     rIntl, aSortArr[i]->GetLocale() ));
+                aSortArr.insert( aSortArr.begin() + i, std::move(pCst));
                 i++;
             }
             sLastDeli = sDeli;
@@ -1157,27 +1154,23 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
                !pTOXSrc->IsHiddenByParaField() &&
                !SwScriptInfo::IsInHiddenRange( *pTOXSrc, pTextMark->GetStart() ) )
             {
-                SwTOXSortTabBase* pBase = nullptr;
                 if(TOX_INDEX == eTOXTyp)
                 {
                     // index entry mark
                     assert(g_pBreakIt);
                     lang::Locale aLocale = g_pBreakIt->GetLocale(pTOXSrc->GetLang(pTextMark->GetStart()));
 
-                    pBase = new SwTOXIndex( *pTOXSrc, pTextMark,
-                                            GetOptions(), FORM_ENTRY, rIntl, aLocale );
-                    InsertSorted(pBase);
+                    InsertSorted(o3tl::make_unique<SwTOXIndex>( *pTOXSrc, pTextMark,
+                                            GetOptions(), FORM_ENTRY, rIntl, aLocale ));
                     if(GetOptions() & SwTOIOptions::KeyAsEntry &&
                         !pTextMark->GetTOXMark().GetPrimaryKey().isEmpty())
                     {
-                        pBase = new SwTOXIndex( *pTOXSrc, pTextMark,
-                                                GetOptions(), FORM_PRIMARY_KEY, rIntl, aLocale );
-                        InsertSorted(pBase);
+                        InsertSorted(o3tl::make_unique<SwTOXIndex>( *pTOXSrc, pTextMark,
+                                                GetOptions(), FORM_PRIMARY_KEY, rIntl, aLocale ));
                         if (!pTextMark->GetTOXMark().GetSecondaryKey().isEmpty())
                         {
-                            pBase = new SwTOXIndex( *pTOXSrc, pTextMark,
-                                                    GetOptions(), FORM_SECONDARY_KEY, rIntl, aLocale );
-                            InsertSorted(pBase);
+                            InsertSorted(o3tl::make_unique<SwTOXIndex>( *pTOXSrc, pTextMark,
+                                                    GetOptions(), FORM_SECONDARY_KEY, rIntl, aLocale ));
                         }
                     }
                 }
@@ -1185,8 +1178,7 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
                     pMark->GetLevel() <= GetLevel())
                 {   // table of content mark
                     // also used for user marks
-                    pBase = new SwTOXContent( *pTOXSrc, pTextMark, rIntl );
-                    InsertSorted(pBase);
+                    InsertSorted(o3tl::make_unique<SwTOXContent>( *pTOXSrc, pTextMark, rIntl ));
                 }
             }
         }
@@ -1212,8 +1204,7 @@ void SwTOXBaseSection::UpdateOutline( const SwTextNode* pOwnChapterNode )
             ( !IsFromChapter() ||
                ::lcl_FindChapterNode( *pTextNd ) == pOwnChapterNode ))
         {
-            SwTOXPara * pNew = new SwTOXPara( *pTextNd, SwTOXElement::OutlineLevel );
-            InsertSorted( pNew );
+            InsertSorted( o3tl::make_unique<SwTOXPara>( *pTextNd, SwTOXElement::OutlineLevel ) );
         }
     }
 }
@@ -1251,8 +1242,7 @@ void SwTOXBaseSection::UpdateTemplate( const SwTextNode* pOwnChapterNode )
                     ( !IsFromChapter() || pOwnChapterNode ==
                         ::lcl_FindChapterNode( *pTextNd ) ) )
                 {
-                    SwTOXPara * pNew = new SwTOXPara( *pTextNd, SwTOXElement::Template, i + 1 );
-                    InsertSorted(pNew);
+                    InsertSorted( o3tl::make_unique<SwTOXPara>( *pTextNd, SwTOXElement::Template, i + 1 ) );
                 }
             }
         }
@@ -1286,7 +1276,7 @@ void SwTOXBaseSection::UpdateSequence( const SwTextNode* pOwnChapterNode )
             const OUString sName = GetSequenceName()
                 + OUStringLiteral1(cSequenceMarkSeparator)
                 + OUString::number( rSeqField.GetSeqNumber() );
-            SwTOXPara * pNew = new SwTOXPara( rTextNode, SwTOXElement::Sequence, 1, sName );
+            std::unique_ptr<SwTOXPara> pNew(new SwTOXPara( rTextNode, SwTOXElement::Sequence, 1, sName ));
             // set indexes if the number or the reference text are to be displayed
             if( GetCaptionDisplay() == CAPTION_TEXT )
             {
@@ -1297,7 +1287,7 @@ void SwTOXBaseSection::UpdateSequence( const SwTextNode* pOwnChapterNode )
             {
                 pNew->SetEndIndex(pTextField->GetStart() + 1);
             }
-            InsertSorted(pNew);
+            InsertSorted(std::move(pNew));
         }
     }
 }
@@ -1331,9 +1321,8 @@ void SwTOXBaseSection::UpdateAuthorities( const SwTOXInternational& rIntl )
                 pTextNode = GetBodyTextNode( *pDoc, aFieldPos, *pFrame );
             if(!pTextNode)
                 pTextNode = &rTextNode;
-            SwTOXAuthority* pNew = new SwTOXAuthority( *pTextNode, *pFormatField, rIntl );
 
-            InsertSorted(pNew);
+            InsertSorted(o3tl::make_unique<SwTOXAuthority>( *pTextNode, *pFormatField, rIntl ));
         }
     }
 }
@@ -1470,11 +1459,11 @@ void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType,
             if( pCNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) && ( !IsFromChapter() ||
                     ::lcl_FindChapterNode( *pCNd ) == pOwnChapterNode ))
             {
-                SwTOXPara * pNew = new SwTOXPara( *pCNd, eMyType,
+                std::unique_ptr<SwTOXPara> pNew( new SwTOXPara( *pCNd, eMyType,
                             ( USHRT_MAX != nSetLevel )
                             ? static_cast<sal_uInt16>(nSetLevel)
-                            : FORM_ALPHA_DELIMITTER );
-                InsertSorted( pNew );
+                            : FORM_ALPHA_DELIMITTER ) );
+                InsertSorted( std::move(pNew) );
             }
         }
 
@@ -1508,7 +1497,7 @@ void SwTOXBaseSection::UpdateTable( const SwTextNode* pOwnChapterNode )
                 if( pCNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) && (!IsFromChapter() ||
                     ::lcl_FindChapterNode( *pCNd ) == pOwnChapterNode ))
                 {
-                    SwTOXTable * pNew = new SwTOXTable( *pCNd );
+                    std::unique_ptr<SwTOXTable> pNew(new SwTOXTable( *pCNd ));
                     if( IsLevelFromChapter() && TOX_TABLES != SwTOXBase::GetType())
                     {
                         const SwTextNode* pOutlNd =
@@ -1522,7 +1511,7 @@ void SwTOXBaseSection::UpdateTable( const SwTextNode* pOwnChapterNode )
                             }
                         }
                     }
-                    InsertSorted(pNew);
+                    InsertSorted(std::move(pNew));
                     break;
                 }
             }
@@ -1546,12 +1535,12 @@ void SwTOXBaseSection::UpdatePageNum()
                               GetOptions() : SwTOIOptions::NONE,
                               GetSortAlgorithm() );
 
-    for( SwTOXSortTabBases::size_type nCnt = 0; nCnt < aSortArr.size(); ++nCnt )
+    for( size_t nCnt = 0; nCnt < aSortArr.size(); ++nCnt )
     {
         // Loop over all SourceNodes
 
         // process run in lines
-        SwTOXSortTabBases::size_type nRange = 0;
+        size_t nRange = 0;
         if(GetTOXForm().IsCommaSeparated() &&
                 aSortArr[nCnt]->GetType() == TOX_SORT_INDEX)
         {
@@ -1569,12 +1558,12 @@ void SwTOXBaseSection::UpdatePageNum()
         else
             nRange = 1;
 
-        for(SwTOXSortTabBases::size_type nRunInEntry = nCnt; nRunInEntry < nCnt + nRange; ++nRunInEntry)
+        for(size_t nRunInEntry = nCnt; nRunInEntry < nCnt + nRange; ++nRunInEntry)
         {
             std::vector<sal_uInt16> aNums; // the PageNumber
             std::vector<SwPageDesc*> aDescs; // The PageDescriptors matching the PageNumbers
             std::vector<sal_uInt16> aMainNums; // contains page numbers of main entries
-            SwTOXSortTabBase* pSortBase = aSortArr[nRunInEntry];
+            SwTOXSortTabBase* pSortBase = aSortArr[nRunInEntry].get();
             size_t nSize = pSortBase->aTOXSources.size();
             for (size_t j = 0; j < nSize; ++j)
             {
@@ -1625,7 +1614,7 @@ void SwTOXBaseSection::UpdatePageNum()
                 }
             }
             // Insert the PageNumber into the TOC TextNode
-            const SwTOXSortTabBase* pBase = aSortArr[ nCnt ];
+            const SwTOXSortTabBase* pBase = aSortArr[ nCnt ].get();
             if(pBase->pTOXNd)
             {
                 const SwTextNode* pTextNd = pBase->pTOXNd->GetTextNode();

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list