sw/inc/tox.hxx | 4 +++- sw/source/core/doc/docnew.cxx | 16 ++++++++-------- sw/source/core/doc/doctxm.cxx | 2 +- sw/source/core/inc/rolbck.hxx | 1 + sw/source/core/tox/tox.cxx | 8 +++++--- sw/source/core/txtnode/atrtox.cxx | 2 +- sw/source/core/txtnode/thints.cxx | 17 ++++++++++++++++- sw/source/core/undo/rolbck.cxx | 27 +++++++++++++++++---------- sw/source/core/unocore/unoidx.cxx | 4 ++-- sw/source/uibase/index/toxmgr.cxx | 2 +- 10 files changed, 55 insertions(+), 28 deletions(-)
New commits: commit 3faa7a5efad3c0532446c2e576464570d7110179 Author: Caolán McNamara <[email protected]> AuthorDate: Wed Oct 28 10:22:58 2020 +0000 Commit: Michael Stahl <[email protected]> CommitDate: Mon Nov 2 10:16:49 2020 +0100 tdf#98868 re-register cloned TOXMark if the dest doc is different if the SwTOXType is from a different document that the target, re-register the TOXMark against a matching SwTOXType from the target document instead includes #1 Related: tdf#98868 split out reusable hunk as function Change-Id: I7e410ba55f94e87c007acbe1887a022948ef354f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104925 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> (cherry picked from commit 496771a6466d6a48f0bcbd8976df24308e052f38) includes #1 Related: tdf#98868 add SwDoc& member to SwTOXType Change-Id: Ic1dc600e75cb4f6a7a0aa86714a87e3ec5658cb0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104926 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> (cherry picked from commit 60b1f8f6ef715ee4cb282215375188c1511ad6d6) Change-Id: Ib9e5a2c437a7510712a10f41c551f0813a8323db Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104910 Tested-by: Jenkins Reviewed-by: Michael Stahl <[email protected]> (cherry picked from commit fd9c47eda58dda5e61850e9b9f6de0f38d221b4a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105072 diff --git a/sw/inc/tox.hxx b/sw/inc/tox.hxx index 7787d432d01b..24bee485f4b0 100644 --- a/sw/inc/tox.hxx +++ b/sw/inc/tox.hxx @@ -148,15 +148,17 @@ public: class SwTOXType final: public sw::BroadcastingModify { public: - SwTOXType(TOXTypes eTyp, const OUString& aName); + SwTOXType(SwDoc& rDoc, TOXTypes eTyp, const OUString& rName); // @@@ public copy ctor, but no copy assignment? SwTOXType(const SwTOXType& rCopy); inline const OUString& GetTypeName() const; inline TOXTypes GetType() const; + SwDoc& GetDoc() const { return m_rDoc; } private: + SwDoc& m_rDoc; OUString m_aName; TOXTypes m_eType; diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index e4f38b44bbb0..358887b21585 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -797,21 +797,21 @@ SwDoc::GetXmlIdRegistry() void SwDoc::InitTOXTypes() { ShellResource* pShellRes = SwViewShell::GetShellRes(); - SwTOXType * pNew = new SwTOXType(TOX_CONTENT, pShellRes->aTOXContentName ); + SwTOXType* pNew = new SwTOXType(*this, TOX_CONTENT, pShellRes->aTOXContentName); mpTOXTypes->emplace_back( pNew ); - pNew = new SwTOXType(TOX_INDEX, pShellRes->aTOXIndexName ); + pNew = new SwTOXType(*this, TOX_INDEX, pShellRes->aTOXIndexName); mpTOXTypes->emplace_back( pNew ); - pNew = new SwTOXType(TOX_USER, pShellRes->aTOXUserName ); + pNew = new SwTOXType(*this, TOX_USER, pShellRes->aTOXUserName); mpTOXTypes->emplace_back( pNew ); - pNew = new SwTOXType(TOX_ILLUSTRATIONS, pShellRes->aTOXIllustrationsName ); + pNew = new SwTOXType(*this, TOX_ILLUSTRATIONS, pShellRes->aTOXIllustrationsName); mpTOXTypes->emplace_back( pNew ); - pNew = new SwTOXType(TOX_OBJECTS, pShellRes->aTOXObjectsName ); + pNew = new SwTOXType(*this, TOX_OBJECTS, pShellRes->aTOXObjectsName); mpTOXTypes->emplace_back( pNew ); - pNew = new SwTOXType(TOX_TABLES, pShellRes->aTOXTablesName ); + pNew = new SwTOXType(*this, TOX_TABLES, pShellRes->aTOXTablesName); mpTOXTypes->emplace_back( pNew ); - pNew = new SwTOXType(TOX_AUTHORITIES, pShellRes->aTOXAuthoritiesName ); + pNew = new SwTOXType(*this, TOX_AUTHORITIES, pShellRes->aTOXAuthoritiesName); mpTOXTypes->emplace_back( pNew ); - pNew = new SwTOXType(TOX_CITATION, pShellRes->aTOXCitationName ); + pNew = new SwTOXType(*this, TOX_CITATION, pShellRes->aTOXCitationName); mpTOXTypes->emplace_back( pNew ); } diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx index 83a38236c04d..7ca7103ffbf9 100644 --- a/sw/source/core/doc/doctxm.cxx +++ b/sw/source/core/doc/doctxm.cxx @@ -628,7 +628,7 @@ const SwTOXType* SwDoc::GetTOXType( TOXTypes eTyp, sal_uInt16 nId ) const const SwTOXType* SwDoc::InsertTOXType( const SwTOXType& rTyp ) { - SwTOXType * pNew = new SwTOXType( rTyp ); + SwTOXType * pNew = new SwTOXType(rTyp); mpTOXTypes->emplace_back( pNew ); return pNew; } diff --git a/sw/source/core/inc/rolbck.hxx b/sw/source/core/inc/rolbck.hxx index f473ad63b753..d6cec5075284 100644 --- a/sw/source/core/inc/rolbck.hxx +++ b/sw/source/core/inc/rolbck.hxx @@ -174,6 +174,7 @@ public: virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override; bool IsEqual( const SwTOXMark& rCmp ) const; + static SwTOXType* GetSwTOXType(SwDoc& rDoc, TOXTypes eTOXTypes, const OUString& rTOXName); }; class SwHistoryResetText : public SwHistoryHint diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx index 10d42cc89a60..92b3bddccd32 100644 --- a/sw/source/core/tox/tox.cxx +++ b/sw/source/core/tox/tox.cxx @@ -194,13 +194,15 @@ void SwTOXMark::InsertTOXMarks( SwTOXMarks& aMarks, const SwTOXType& rType ) } // Manage types of TOX -SwTOXType::SwTOXType(TOXTypes eTyp, const OUString& rName) - : m_aName(rName) +SwTOXType::SwTOXType(SwDoc& rDoc, TOXTypes eTyp, const OUString& rName) + : m_rDoc(rDoc) + , m_aName(rName) , m_eType(eTyp) { } SwTOXType::SwTOXType(const SwTOXType& rCopy) - : m_aName(rCopy.m_aName) + : m_rDoc(rCopy.m_rDoc) + , m_aName(rCopy.m_aName) , m_eType(rCopy.m_eType) { if (auto pRegister = const_cast<SwTOXType&>(rCopy).GetRegisteredIn()) diff --git a/sw/source/core/txtnode/atrtox.cxx b/sw/source/core/txtnode/atrtox.cxx index 613956be9979..de3a782d2cf9 100644 --- a/sw/source/core/txtnode/atrtox.cxx +++ b/sw/source/core/txtnode/atrtox.cxx @@ -79,7 +79,7 @@ void SwTextTOXMark::CopyTOXMark( SwDoc* pDoc ) // if the requested tox type does not exist, create it if(!pType) { - pDoc->InsertTOXType( SwTOXType( eType, rNm ) ); + pDoc->InsertTOXType( SwTOXType( *pDoc, eType, rNm ) ); pType = pDoc->GetTOXType(eType, 0); } diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index 711e29dda0d9..f31e39713ece 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -1113,8 +1113,23 @@ SwTextAttr* MakeTextAttr( : new SwTextRefMark( static_cast<SwFormatRefMark&>(rNew), nStt, &nEnd ); break; case RES_TXTATR_TOXMARK: - pNew = new SwTextTOXMark( static_cast<SwTOXMark&>(rNew), nStt, &nEnd ); + { + SwTOXMark& rMark = static_cast<SwTOXMark&>(rNew); + + // tdf#98868 if the SwTOXType is from a different document that the + // target, re-register the TOXMark against a matching SwTOXType from + // the target document instead + const SwTOXType* pTOXType = rMark.GetTOXType(); + if (pTOXType && &pTOXType->GetDoc() != &rDoc) + { + SwTOXType* pToxType = SwHistorySetTOXMark::GetSwTOXType(rDoc, pTOXType->GetType(), + pTOXType->GetTypeName()); + rMark.RegisterToTOXType(*pToxType); + } + + pNew = new SwTextTOXMark(rMark, nStt, &nEnd); break; + } case RES_TXTATR_CJK_RUBY: pNew = new SwTextRuby( static_cast<SwFormatRuby&>(rNew), nStt, nEnd ); break; diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx index ceac742f9bbc..206ad93434a2 100644 --- a/sw/source/core/undo/rolbck.cxx +++ b/sw/source/core/undo/rolbck.cxx @@ -348,20 +348,15 @@ SwHistorySetTOXMark::SwHistorySetTOXMark( const SwTextTOXMark* pTextHt, sal_uLon m_TOXMark.EndListeningAll(); } -void SwHistorySetTOXMark::SetInDoc( SwDoc* pDoc, bool ) +SwTOXType* SwHistorySetTOXMark::GetSwTOXType(SwDoc& rDoc, TOXTypes eTOXTypes, const OUString& rTOXName) { - SwTextNode * pTextNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetTextNode(); - OSL_ENSURE( pTextNd, "SwHistorySetTOXMark: no TextNode" ); - if ( !pTextNd ) - return; - // search for respective TOX type - const sal_uInt16 nCnt = pDoc->GetTOXTypeCount( m_eTOXTypes ); + const sal_uInt16 nCnt = rDoc.GetTOXTypeCount(eTOXTypes); SwTOXType* pToxType = nullptr; for ( sal_uInt16 n = 0; n < nCnt; ++n ) { - pToxType = const_cast<SwTOXType*>(pDoc->GetTOXType( m_eTOXTypes, n )); - if ( pToxType->GetTypeName() == m_TOXName ) + pToxType = const_cast<SwTOXType*>(rDoc.GetTOXType(eTOXTypes, n)); + if (pToxType->GetTypeName() == rTOXName) break; pToxType = nullptr; } @@ -369,9 +364,21 @@ void SwHistorySetTOXMark::SetInDoc( SwDoc* pDoc, bool ) if ( !pToxType ) // TOX type not found, create new { pToxType = const_cast<SwTOXType*>( - pDoc->InsertTOXType( SwTOXType( m_eTOXTypes, m_TOXName ))); + rDoc.InsertTOXType(SwTOXType(rDoc, eTOXTypes, rTOXName))); } + return pToxType; +} + +void SwHistorySetTOXMark::SetInDoc( SwDoc* pDoc, bool ) +{ + SwTextNode * pTextNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetTextNode(); + OSL_ENSURE( pTextNd, "SwHistorySetTOXMark: no TextNode" ); + if ( !pTextNd ) + return; + + SwTOXType* pToxType = GetSwTOXType(*pDoc, m_eTOXTypes, m_TOXName); + SwTOXMark aNew( m_TOXMark ); aNew.RegisterToTOXType( *pToxType ); diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx index 82e42e167ce9..873058e98af7 100644 --- a/sw/source/core/unocore/unoidx.cxx +++ b/sw/source/core/unocore/unoidx.cxx @@ -112,7 +112,7 @@ lcl_ReAssignTOXType(SwDoc* pDoc, SwTOXBase& rTOXBase, const OUString& rNewName) } if(!pNewType) { - SwTOXType aNewType(TOX_USER, rNewName); + SwTOXType aNewType(*pDoc, TOX_USER, rNewName); pNewType = pDoc->InsertTOXType( aNewType ); } @@ -1813,7 +1813,7 @@ SwXDocumentIndexMark::attach( } if (!pTOXType) { - SwTOXType aUserType(TOX_USER, m_pImpl->m_sUserIndexName); + SwTOXType aUserType(*pDoc, TOX_USER, m_pImpl->m_sUserIndexName); pTOXType = pDoc->InsertTOXType(aUserType); } } diff --git a/sw/source/uibase/index/toxmgr.cxx b/sw/source/uibase/index/toxmgr.cxx index 53223fc91ff1..4e7e65f9c4d0 100644 --- a/sw/source/uibase/index/toxmgr.cxx +++ b/sw/source/uibase/index/toxmgr.cxx @@ -227,7 +227,7 @@ sal_uInt16 SwTOXMgr::GetUserTypeID(const OUString& rStr) if(pTmp && pTmp->GetTypeName() == rStr) return i; } - SwTOXType aUserType(TOX_USER, rStr); + SwTOXType aUserType(*pSh->GetDoc(), TOX_USER, rStr); pSh->InsertTOXType(aUserType); return nSize; } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
