diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-01-10 13:20:40 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@cib.de> | 2020-01-21 12:09:01 +0100 |
commit | 8f84922be15d37cb54fa592e1445fa5ab2c37f15 (patch) | |
tree | b2b176aa29fdb6673735396b6dfd51a199dbd4db | |
parent | 97928a862bd7e74955dbc59732be9e43f1a2d42a (diff) |
DOCX import: fix lost objects anchored to the single para of a linked header
Regression from commit 08f13ab85b5c65b5dc8adfa15918fb3e426fcc3c
(tdf#112202 writerfilter,sw: fix loss of headers, 2019-12-16), the
problem is that on one hand, copyText() is meant to copy a complete
XText (header, table cell, footnote, etc), OTOH the internal API use
used only copies at-para anchored objects for complete text nodes, so a
one-paragraph header will loose its anchored objects when a linked
header is copied.
Introduce a new "CopyText" flag that provides the expected copyText()
behavior and use that when the copyText() UNO API is invoked, but leave
the selection behavior unchanged.
Perform the inclusive check in IsSelectFrameAnchoredAtPara(), opt in for
that from SwXText::copyText(), the rest is just passing the flag around.
Change-Id: Id727f7ca4f6121a7050340359716a52ecb4886f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86529
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
(cherry picked from commit 04b2310aaa094794ceedaa1bb6ff1823a2d29d3e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87122
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
25 files changed, 97 insertions, 46 deletions
diff --git a/sw/inc/IDocumentContentOperations.hxx b/sw/inc/IDocumentContentOperations.hxx index f59b1f0eef89..6ba51df9f740 100644 --- a/sw/inc/IDocumentContentOperations.hxx +++ b/sw/inc/IDocumentContentOperations.hxx @@ -109,7 +109,7 @@ public: rPam. If false, then no such check will be performed, and it is assumed that the caller took care of verifying this constraint already. */ - virtual bool CopyRange(SwPaM& rPam, SwPosition& rPos, const bool bCopyAll, bool bCheckPos ) const = 0; + virtual bool CopyRange(SwPaM& rPam, SwPosition& rPos, const bool bCopyAll, bool bCheckPos, bool bCopyText ) const = 0; /** Delete section containing the node. */ diff --git a/sw/inc/undobj.hxx b/sw/inc/undobj.hxx index 7f3fb1ff93ec..ea6ca925dadd 100644 --- a/sw/inc/undobj.hxx +++ b/sw/inc/undobj.hxx @@ -137,9 +137,10 @@ enum class DelContentType : sal_uInt16 AllMask = 0x0b, ExcludeFlyAtStartEnd = 0x40, CheckNoCntnt = 0x80, + CopyText = 0x100, }; namespace o3tl { - template<> struct typed_flags<DelContentType> : is_typed_flags<DelContentType, 0xcb> {}; + template<> struct typed_flags<DelContentType> : is_typed_flags<DelContentType, 0x1cb> {}; } /// will DelContentIndex destroy a frame anchored at character at rAnchorPos? diff --git a/sw/qa/extras/ooxmlimport/data/text-copy.docx b/sw/qa/extras/ooxmlimport/data/text-copy.docx Binary files differnew file mode 100644 index 000000000000..9c871e633517 --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/text-copy.docx diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx index f5ff5b3b53e8..11243d14e33d 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -283,6 +283,34 @@ DECLARE_OOXMLIMPORT_TEST(testTdf124754, "tdf124754.docx") getProperty<sal_Int32>(xText, "CharColor")); } +DECLARE_OOXMLIMPORT_TEST(testTextCopy, "text-copy.docx") +{ + // The document has a header on the second page that is copied as part of the import process. + // The header has a single paragraph: make sure shapes anchored to it are not lost. + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference<beans::XPropertySet> xPara; + while (xParaEnum->hasMoreElements()) + { + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + } + auto aPageStyleName = getProperty<OUString>(xPara, "PageStyleName"); + uno::Reference<beans::XPropertySet> xPageStyle( + getStyles("PageStyles")->getByName(aPageStyleName), uno::UNO_QUERY); + auto xHeaderText = getProperty<uno::Reference<text::XText>>(xPageStyle, "HeaderText"); + uno::Reference<container::XContentEnumerationAccess> xHeaderPara( + getParagraphOfText(1, xHeaderText), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xHeaderShapes + = xHeaderPara->createContentEnumeration("com.sun.star.text.TextContent"); + // Without the accompanying fix in place, this test would have failed with: + // assertion failed + // - Expression: xHeaderShapes->hasMoreElements() + // i.e. the second page's header had no anchored shapes. + CPPUNIT_ASSERT(xHeaderShapes->hasMoreElements()); +} + DECLARE_OOXMLIMPORT_TEST(testTdf112443, "tdf112443.docx") { // the position of the flying text frame should be off page diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 52003fe601f8..c26b3b6f19dc 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -747,7 +747,7 @@ void SwUiWriterTest::testBookmarkCopy() aPaM.SttEndDoc(true/*start*/); aPaM.Move(fnMoveForward, GoInContent); // partially select 1st para - rIDCO.CopyRange(aPaM, target, /*bCopyAll=*/false, /*bCheckPos=*/true); + rIDCO.CopyRange(aPaM, target, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false); // check bookmark was copied to correct position CPPUNIT_ASSERT_EQUAL(sal_Int32(2), rIDMA.getBookmarksCount()); @@ -763,7 +763,7 @@ void SwUiWriterTest::testBookmarkCopy() rIDCO.SplitNode(*aPaM.GetPoint(), false); aPaM.SttEndDoc(true/*start*/); - rIDCO.CopyRange(aCopyPaM, *aPaM.GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true); + rIDCO.CopyRange(aCopyPaM, *aPaM.GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false); // check bookmark was copied to correct position CPPUNIT_ASSERT_EQUAL(sal_Int32(3), rIDMA.getBookmarksCount()); diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 6ead169ec498..aacb19945791 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -1830,7 +1830,7 @@ DocumentContentOperationsManager::DocumentContentOperationsManager( SwDoc& i_rSw // Copy an area into this document or into another document bool -DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, const bool bCopyAll, bool bCheckPos ) const +DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, const bool bCopyAll, bool bCheckPos, bool bCopyText ) const { const SwPosition *pStt = rPam.Start(), *pEnd = rPam.End(); @@ -1878,7 +1878,7 @@ DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, cons if( pDoc != &m_rDoc ) { // ordinary copy - bRet = CopyImpl( rPam, rPos, bCopyAll, pRedlineRange ); + bRet = CopyImpl( rPam, rPos, bCopyAll, pRedlineRange, bCopyText ); } else if( ! ( *pStt <= rPos && rPos < *pEnd && ( pStt->nNode != pEnd->nNode || @@ -1886,7 +1886,7 @@ DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, cons { // Copy to a position outside of the area, or copy a single TextNode // Do an ordinary copy - bRet = CopyImpl( rPam, rPos, bCopyAll, pRedlineRange ); + bRet = CopyImpl( rPam, rPos, bCopyAll, pRedlineRange, bCopyText ); } else { @@ -3361,7 +3361,8 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( const std::pair<const SwPaM&, const SwPosition&>* pCopiedPaM /*and real insert pos*/, const bool bMakeNewFrames, const bool bDelRedlines, - const bool bCopyFlyAtFly ) const + const bool bCopyFlyAtFly, + bool bCopyText ) const { assert(!pCopiedPaM || pCopiedPaM->first.End()->nNode == rRg.aEnd); assert(!pCopiedPaM || pCopiedPaM->second.nNode <= rInsPos); @@ -3411,7 +3412,8 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( (pCopiedPaM && rRg.aStart != pCopiedPaM->first.Start()->nNode) ? pCopiedPaM->second.nNode : aSavePos, - bCopyFlyAtFly); + bCopyFlyAtFly, + bCopyText); } SwNodeRange aCpyRange( aSavePos, rInsPos ); @@ -3449,7 +3451,8 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl( const SwNodeRange& rRg, SwPaM const*const pCopiedPaM, const SwNodeIndex& rStartIdx, - const bool bCopyFlyAtFly ) const + const bool bCopyFlyAtFly, + bool bCopyText ) const { assert(!pCopiedPaM || pCopiedPaM->End()->nNode == rRg.aEnd); @@ -3484,9 +3487,17 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl( break; case RndStdIds::FLY_AT_PARA: { + DelContentType eDelContentType = DelContentType::AllMask; + if (bCopyText) + { + // Called from SwXText::copyText(), select the frame if rAnchorPos is inside + // the range, inclusive. + eDelContentType = DelContentType::CopyText; + } bAdd = IsSelectFrameAnchoredAtPara(*pAPos, pCopiedPaM ? *pCopiedPaM->Start() : SwPosition(rRg.aStart), - pCopiedPaM ? *pCopiedPaM->End() : SwPosition(rRg.aEnd)); + pCopiedPaM ? *pCopiedPaM->End() : SwPosition(rRg.aEnd), + eDelContentType); } break; case RndStdIds::FLY_AT_CHAR: @@ -4438,7 +4449,8 @@ static void lcl_PopNumruleState( bool DocumentContentOperationsManager::CopyImpl(SwPaM& rPam, SwPosition& rPos, const bool bCopyAll, - SwPaM *const pCopyRange) const + SwPaM *const pCopyRange, + bool bCopyText) const { std::vector<std::pair<sal_uLong, sal_Int32>> Breaks; @@ -4446,7 +4458,7 @@ bool DocumentContentOperationsManager::CopyImpl(SwPaM& rPam, SwPosition& rPos, if (Breaks.empty()) { - return CopyImplImpl(rPam, rPos, bCopyAll, pCopyRange); + return CopyImplImpl(rPam, rPos, bCopyAll, pCopyRange, bCopyText); } SwPosition const & rSelectionEnd( *rPam.End() ); @@ -4468,7 +4480,7 @@ bool DocumentContentOperationsManager::CopyImpl(SwPaM& rPam, SwPosition& rPos, if (rStart < rEnd) // check if part is empty { // pass in copyRange member as rPos; should work ... - bRet &= CopyImplImpl(aPam, *copyRange.Start(), bCopyAll, ©Range); + bRet &= CopyImplImpl(aPam, *copyRange.Start(), bCopyAll, ©Range, /*bCopyText=*/false); nOffset = iter->first - rStart.nNode.GetIndex(); // fly nodes... if (pCopyRange) { @@ -4488,7 +4500,7 @@ bool DocumentContentOperationsManager::CopyImpl(SwPaM& rPam, SwPosition& rPos, rStart = *rPam.Start(); // set to original start if (rStart < rEnd) // check if part is empty { - bRet &= CopyImplImpl(aPam, *copyRange.Start(), bCopyAll, ©Range); + bRet &= CopyImplImpl(aPam, *copyRange.Start(), bCopyAll, ©Range, /*bCopyText=*/false); if (pCopyRange) { if (bFirst) @@ -4505,7 +4517,7 @@ bool DocumentContentOperationsManager::CopyImpl(SwPaM& rPam, SwPosition& rPos, bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPos, const bool bCopyAll, - SwPaM *const pCpyRange ) const + SwPaM *const pCpyRange, bool bCopyText ) const { SwDoc* pDoc = rPos.nNode.GetNode().GetDoc(); const bool bColumnSel = pDoc->IsClipBoard() && pDoc->IsColumnSelection(); @@ -4838,13 +4850,13 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo SwNodeIndex aSaveIdx( aInsPos, -1 ); assert(pStt->nNode != pEnd->nNode); pEnd->nContent = 0; // TODO why this? - CopyWithFlyInFly( aRg, aInsPos, &tmp, /*bMakeNewFrames*/true, false ); + CopyWithFlyInFly( aRg, aInsPos, &tmp, /*bMakeNewFrames*/true, false, /*bCopyFlyAtFly=*/false, bCopyText ); ++aSaveIdx; pEnd->nNode = aSaveIdx; pEnd->nContent.Assign( aSaveIdx.GetNode().GetTextNode(), 0 ); } else - CopyWithFlyInFly( aRg, aInsPos, &tmp, /*bMakeNewFrames*/true, false ); + CopyWithFlyInFly( aRg, aInsPos, &tmp, /*bMakeNewFrames*/true, false, /*bCopyFlyAtFly=*/false, bCopyText ); bCopyBookmarks = false; } diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx index 534f471e9310..c2e67e8d8f1c 100644 --- a/sw/source/core/doc/doccomp.cxx +++ b/sw/source/core/doc/doccomp.cxx @@ -1367,7 +1367,7 @@ bool SwCompareLine::ChangesInLine( const SwCompareLine& rLine, aCpyPam.SetMark(); aCpyPam.GetPoint()->nContent = nSrcTo; aCpyPam.GetDoc()->getIDocumentContentOperations().CopyRange( aCpyPam, *aPam.GetPoint(), - /*bCopyAll=*/false, /*bCheckPos=*/true ); + /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); pDstDoc->GetIDocumentUndoRedo().DoUndo( bUndo ); SwPaM* pTmp = new SwPaM( *aPam.GetPoint(), rpDelRing.get() ); @@ -1934,7 +1934,7 @@ sal_uInt16 SaveMergeRedline::InsertRedline(SwPaM* pLastDestRedline) pSrcRedl->GetDoc()->getIDocumentContentOperations().CopyRange( *const_cast<SwPaM*>(static_cast<const SwPaM*>(pSrcRedl)), - *pDestRedl->GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true ); + *pDestRedl->GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); diff --git a/sw/source/core/doc/docglos.cxx b/sw/source/core/doc/docglos.cxx index 56e8533f24f2..f034d289a5ed 100644 --- a/sw/source/core/doc/docglos.cxx +++ b/sw/source/core/doc/docglos.cxx @@ -189,7 +189,7 @@ bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const OUString& rEntry, SwDontExpandItem aACD; aACD.SaveDontExpandItems( rInsPos ); - pGDoc->getIDocumentContentOperations().CopyRange( aCpyPam, rInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + pGDoc->getIDocumentContentOperations().CopyRange( aCpyPam, rInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); aACD.RestoreDontExpandItems( rInsPos ); if( pShell ) diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index de177655f7dd..8feb5986d509 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -428,7 +428,7 @@ SwFlyFrameFormat* SwDoc::MakeFlyAndMove( const SwPaM& rPam, const SfxItemSet& rS *rTmp.GetPoint() != *rTmp.GetMark() ) { // aPos is the newly created fly section, so definitely outside rPam, it's pointless to check that again. - getIDocumentContentOperations().CopyRange( *const_cast<SwPaM*>(&rTmp), aPos, /*bCopyAll=*/false, /*bCheckPos=*/false ); + getIDocumentContentOperations().CopyRange( *const_cast<SwPaM*>(&rTmp), aPos, /*bCopyAll=*/false, /*bCheckPos=*/false, /*bCopyText=*/false ); } } getIDocumentRedlineAccess().SetRedlineMove(bOldRedlineMove); diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index 73a39fd9f1f9..21d250ce59c3 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -1142,7 +1142,7 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu #ifdef DBG_UTIL SAL_INFO( "sw.docappend", "CopyRange In: " << CNTNT_DOC( this ) ); #endif - rSource.getIDocumentContentOperations().CopyRange( aCpyPam, rInsPos, /*bCopyAll=*/true, /*bCheckPos=*/true ); + rSource.getIDocumentContentOperations().CopyRange( aCpyPam, rInsPos, /*bCopyAll=*/true, /*bCheckPos=*/true, /*bCopyText=*/false ); // Note: aCpyPam is invalid now #ifdef DBG_UTIL SAL_INFO( "sw.docappend", "CopyRange Out: " << CNTNT_DOC( this ) ); diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index a27d0a87122e..d0efa05bb990 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -2170,7 +2170,7 @@ bool SwDoc::MoveParagraphImpl(SwPaM& rPam, long const nOffset, --aIdx; // move before insertion - getIDocumentContentOperations().CopyRange( aPam, aInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + getIDocumentContentOperations().CopyRange( aPam, aInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); // now delete all the delete redlines that were copied #ifndef NDEBUG diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index e101bdc65b9e..ee8e8b23d8c0 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -1404,7 +1404,7 @@ void SwRangeRedline::CopyToSection() SwNodeIndex aNdIdx( *pSttNd, 1 ); SwTextNode* pTextNd = aNdIdx.GetNode().GetTextNode(); SwPosition aPos( aNdIdx, SwIndex( pTextNd )); - pDoc->getIDocumentContentOperations().CopyRange( *this, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + pDoc->getIDocumentContentOperations().CopyRange( *this, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); // Take over the style from the EndNode if needed // We don't want this in Doc::Copy @@ -1427,7 +1427,7 @@ void SwRangeRedline::CopyToSection() if( pCEndNd ) { SwPosition aPos( *pSttNd->EndOfSectionNode() ); - pDoc->getIDocumentContentOperations().CopyRange( *this, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + pDoc->getIDocumentContentOperations().CopyRange( *this, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); } else { diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx index 21e4247cfc62..c974d37bb72d 100644 --- a/sw/source/core/docnode/section.cxx +++ b/sw/source/core/docnode/section.cxx @@ -1318,7 +1318,7 @@ static void lcl_UpdateLinksInSect( SwBaseLink& rUpdLnk, SwSectionNode& rSectNd ) pCpyPam->Start()->nNode > rInsPos || rInsPos >= pCpyPam->End()->nNode ) { - pSrcDoc->getIDocumentContentOperations().CopyRange( *pCpyPam, *pPam->GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true ); + pSrcDoc->getIDocumentContentOperations().CopyRange( *pCpyPam, *pPam->GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); } delete pCpyPam; } diff --git a/sw/source/core/edit/acorrect.cxx b/sw/source/core/edit/acorrect.cxx index 45af22ab2176..431b8c1552f3 100644 --- a/sw/source/core/edit/acorrect.cxx +++ b/sw/source/core/edit/acorrect.cxx @@ -466,7 +466,7 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, SwDontExpandItem aExpItem; aExpItem.SaveDontExpandItems( *aPam.GetPoint() ); - pAutoDoc->getIDocumentContentOperations().CopyRange( aCpyPam, *aPam.GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true ); + pAutoDoc->getIDocumentContentOperations().CopyRange( aCpyPam, *aPam.GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); aExpItem.RestoreDontExpandItems( *aPam.GetPoint() ); diff --git a/sw/source/core/edit/eddel.cxx b/sw/source/core/edit/eddel.cxx index 6d2d83902c85..162be4b48fff 100644 --- a/sw/source/core/edit/eddel.cxx +++ b/sw/source/core/edit/eddel.cxx @@ -252,7 +252,7 @@ bool SwEditShell::Copy( SwEditShell* pDestShell ) bFirstMove = false; } - const bool bSuccess( GetDoc()->getIDocumentContentOperations().CopyRange( rPaM, *pPos, /*bCopyAll=*/false, /*bCheckPos=*/true ) ); + const bool bSuccess( GetDoc()->getIDocumentContentOperations().CopyRange( rPaM, *pPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ) ); if (!bSuccess) continue; diff --git a/sw/source/core/edit/edglss.cxx b/sw/source/core/edit/edglss.cxx index 807eaa3e19cb..99e242ba61de 100644 --- a/sw/source/core/edit/edglss.cxx +++ b/sw/source/core/edit/edglss.cxx @@ -142,7 +142,7 @@ sal_uInt16 SwEditShell::SaveGlossaryDoc( SwTextBlocks& rBlock, aStt = pGDoc->GetNodes().GetEndOfExtras(); pContentNd = pGDoc->GetNodes().GoNext( &aStt ); SwPosition aInsPos( aStt, SwIndex( pContentNd )); - pMyDoc->getIDocumentContentOperations().CopyRange( aCpyPam, aInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + pMyDoc->getIDocumentContentOperations().CopyRange( aCpyPam, aInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); nRet = rBlock.PutDoc(); } @@ -215,7 +215,7 @@ bool SwEditShell::CopySelToDoc( SwDoc* pInsDoc ) { rPaM.SetMark(); rPaM.Move( fnMoveForward, GoInContent ); - bRet = GetDoc()->getIDocumentContentOperations().CopyRange( rPaM, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true ) + bRet = GetDoc()->getIDocumentContentOperations().CopyRange( rPaM, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ) || bRet; rPaM.Exchange(); rPaM.DeleteMark(); @@ -235,7 +235,7 @@ bool SwEditShell::CopySelToDoc( SwDoc* pInsDoc ) aPaM.Start()->nNode = aPaM.Start()->nNode.GetNode().FindTableNode()->GetIndex(); aPaM.Start()->nContent.Assign(nullptr, 0); } - bRet = GetDoc()->getIDocumentContentOperations().CopyRange( aPaM, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true ) || bRet; + bRet = GetDoc()->getIDocumentContentOperations().CopyRange( aPaM, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ) || bRet; } } } diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx index b3fffee8b22f..c2470b997a93 100644 --- a/sw/source/core/frmedt/fecopy.cxx +++ b/sw/source/core/frmedt/fecopy.cxx @@ -806,7 +806,7 @@ bool SwFEShell::Paste( SwDoc* pClpDoc, bool bNestedTable ) { SwNodeIndex aIndexBefore(rInsPos.nNode); --aIndexBefore; - pClpDoc->getIDocumentContentOperations().CopyRange( rCopy, rInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + pClpDoc->getIDocumentContentOperations().CopyRange( rCopy, rInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); { ++aIndexBefore; SwPaM aPaM(SwPosition(aIndexBefore), @@ -1045,7 +1045,7 @@ bool SwFEShell::Paste( SwDoc* pClpDoc, bool bNestedTable ) --aIndexBefore; - pClpDoc->getIDocumentContentOperations().CopyRange( aCpyPam, rInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + pClpDoc->getIDocumentContentOperations().CopyRange( aCpyPam, rInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); // Note: aCpyPam is invalid now ++aIndexBefore; diff --git a/sw/source/core/inc/DocumentContentOperationsManager.hxx b/sw/source/core/inc/DocumentContentOperationsManager.hxx index 21829eaf22a5..4f523bec9f3d 100644 --- a/sw/source/core/inc/DocumentContentOperationsManager.hxx +++ b/sw/source/core/inc/DocumentContentOperationsManager.hxx @@ -37,7 +37,7 @@ public: DocumentContentOperationsManager( SwDoc& i_rSwdoc ); //Interface methods: - bool CopyRange(SwPaM&, SwPosition&, const bool bCopyAll, bool bCheckPos ) const override; + bool CopyRange(SwPaM&, SwPosition&, const bool bCopyAll, bool bCheckPos, bool bCopyText ) const override; void DeleteSection(SwNode* pNode) override; @@ -108,11 +108,13 @@ public: const std::pair<const SwPaM&, const SwPosition&> * pCopiedPaM = nullptr, bool bMakeNewFrames = true, bool bDelRedlines = true, - bool bCopyFlyAtFly = false ) const; + bool bCopyFlyAtFly = false, + bool bCopyText = false ) const; void CopyFlyInFlyImpl( const SwNodeRange& rRg, SwPaM const*const pCopiedPaM, const SwNodeIndex& rStartIdx, - const bool bCopyFlyAtFly = false ) const; + const bool bCopyFlyAtFly = false, + bool bCopyText = false ) const; /// Parameters for _Rst and lcl_SetTextFormatColl //originallyfrom docfmt.cxx @@ -169,9 +171,9 @@ private: /* Copy a range within the same or to another document. Position may not lie within range! */ bool CopyImpl( SwPaM&, SwPosition&, - const bool bCopyAll, SwPaM *const pCpyRng /*= 0*/ ) const; + const bool bCopyAll, SwPaM *const pCpyRng /*= 0*/, bool bCopyText ) const; bool CopyImplImpl(SwPaM&, SwPosition&, - const bool bCopyAll, SwPaM *const pCpyRng /*= 0*/) const; + const bool bCopyAll, SwPaM *const pCpyRng /*= 0*/, bool bCopyText ) const; DocumentContentOperationsManager(DocumentContentOperationsManager const&) = delete; DocumentContentOperationsManager& operator=(DocumentContentOperationsManager const&) = delete; diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx index b3f08f29022a..08f6f466f318 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -1590,6 +1590,11 @@ bool IsSelectFrameAnchoredAtPara(SwPosition const & rAnchorPos, && (rStart.nNode <= rAnchorPos.nNode); } + if (nDelContentType == DelContentType::CopyText) + { + return (rStart.nNode <= rAnchorPos.nNode) && (rAnchorPos.nNode <= rEnd.nNode); + } + if (rAnchorPos.GetDoc()->IsInReading()) { // FIXME hack for writerfilter RemoveLastParagraph(); can't test file format more specific? // but it MUST NOT be done during the SetRedlineFlags at the end of ODF diff --git a/sw/source/core/undo/untblk.cxx b/sw/source/core/undo/untblk.cxx index 9597aca435b3..db586c615e4b 100644 --- a/sw/source/core/undo/untblk.cxx +++ b/sw/source/core/undo/untblk.cxx @@ -423,7 +423,7 @@ void SwUndoInserts::RepeatImpl(::sw::RepeatContext & rContext) SwPaM aPam( rContext.GetDoc().GetNodes().GetEndOfContent() ); SetPaM( aPam ); SwPaM & rRepeatPaM( rContext.GetRepeatPaM() ); - aPam.GetDoc()->getIDocumentContentOperations().CopyRange( aPam, *rRepeatPaM.GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true ); + aPam.GetDoc()->getIDocumentContentOperations().CopyRange( aPam, *rRepeatPaM.GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); } SwUndoInsDoc::SwUndoInsDoc( const SwPaM& rPam ) diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx index 316bafa63c6b..71894e2d1908 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -2251,7 +2251,10 @@ SwXText::copyText( { pNode->MakeEndIndex(&temp.GetPoint()->nContent); } - m_pImpl->m_pDoc->getIDocumentContentOperations().CopyRange(temp, rPos, /*bCopyAll=*/false, /*bCheckPos=*/true); + // Explicitly request copy text mode, so + // sw::DocumentContentOperationsManager::CopyFlyInFlyImpl() will copy shapes anchored to + // us, even if we have only a single paragraph. + m_pImpl->m_pDoc->getIDocumentContentOperations().CopyRange(temp, rPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/true); } if (!pFirstNode) { // the node at rPos was split; get rid of the first empty one so @@ -2262,7 +2265,7 @@ SwXText::copyText( } else { - m_pImpl->m_pDoc->getIDocumentContentOperations().CopyRange(*pCursor->GetPaM(), rPos, /*bCopyAll=*/false, /*bCheckPos=*/true); + m_pImpl->m_pDoc->getIDocumentContentOperations().CopyRange(*pCursor->GetPaM(), rPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/true); } } diff --git a/sw/source/filter/docx/swdocxreader.cxx b/sw/source/filter/docx/swdocxreader.cxx index b2122a2f6c4d..114fb84514ca 100644 --- a/sw/source/filter/docx/swdocxreader.cxx +++ b/sw/source/filter/docx/swdocxreader.cxx @@ -240,7 +240,7 @@ bool SwDOCXReader::MakeEntries( SwDoc *pD, SwTextBlocks &rBlocks ) SwNodeIndex aIdx( pGlDoc->GetNodes().GetEndOfContent(), -1 ); pCNd = aIdx.GetNode().GetContentNode(); SwPosition aPos( aIdx, SwIndex( pCNd, pCNd ? pCNd->Len() : 0 ) ); - pD->getIDocumentContentOperations().CopyRange( aPam, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + pD->getIDocumentContentOperations().CopyRange( aPam, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); rBlocks.PutDoc(); } else diff --git a/sw/source/filter/ww8/ww8glsy.cxx b/sw/source/filter/ww8/ww8glsy.cxx index 15e6955edd25..60fdcf4cf4a1 100644 --- a/sw/source/filter/ww8/ww8glsy.cxx +++ b/sw/source/filter/ww8/ww8glsy.cxx @@ -170,7 +170,7 @@ bool WW8Glossary::MakeEntries(SwDoc *pD, SwTextBlocks &rBlocks, -1 ); pCNd = aIdx.GetNode().GetContentNode(); SwPosition aPos(aIdx, SwIndex(pCNd, pCNd ? pCNd->Len() : 0)); - pD->getIDocumentContentOperations().CopyRange( aPam, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + pD->getIDocumentContentOperations().CopyRange( aPam, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); rBlocks.PutDoc(); } } diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx index b7807e0e87d6..0fde4d3c509d 100644 --- a/sw/source/filter/xml/xmltbli.cxx +++ b/sw/source/filter/xml/xmltbli.cxx @@ -682,7 +682,7 @@ void SwXMLTableCellContext_Impl::EndElement() assert(pDstTextCursor && "SwXTextCursor missing"); SwPaM aSrcPaM(*pSrcPaM->GetMark(), *pSrcPaM->GetPoint()); SwPosition aDstPos( *pDstTextCursor->GetPaM()->GetPoint() ); - pDoc->getIDocumentContentOperations().CopyRange( aSrcPaM, aDstPos, /*bCopyAll=*/false, /*bCheckPos=*/true ); + pDoc->getIDocumentContentOperations().CopyRange( aSrcPaM, aDstPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ); m_nColRepeat--; } diff --git a/sw/source/uibase/uno/unoatxt.cxx b/sw/source/uibase/uno/unoatxt.cxx index d226b52ae31d..fccaef19acba 100644 --- a/sw/source/uibase/uno/unoatxt.cxx +++ b/sw/source/uibase/uno/unoatxt.cxx @@ -317,7 +317,7 @@ static bool lcl_CopySelToDoc( SwDoc* pInsDoc, OTextCursorHelper* pxCursor, SwXTe } } if (!pPam) { return false; } - bRet = pDoc->getIDocumentContentOperations().CopyRange( *pPam, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true ) || bRet; + bRet = pDoc->getIDocumentContentOperations().CopyRange( *pPam, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true, /*bCopyText=*/false ) || bRet; } pInsDoc->getIDocumentFieldsAccess().UnlockExpFields(); |