sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 18 +- sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 2 sw/qa/extras/ooxmlexport/ooxmlexport6.cxx | 10 - sw/qa/extras/uiwriter/uiwriter3.cxx | 10 - sw/source/core/frmedt/fecopy.cxx | 254 ++++++++++++++--------------- sw/source/core/layout/flycnt.cxx | 3 6 files changed, 150 insertions(+), 147 deletions(-)
New commits: commit 84c8adb703906b0fe2c7f9a5e7174e00139a08f3 Author: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> AuthorDate: Mon Oct 25 20:50:26 2021 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Nov 3 11:55:30 2021 +0100 tdf#140798, tdf#143815, tdf#141659: fix fly content hint handling Also revert most of the test changes in 188ec34cf157ffee8c63f03f420ca9daafb5ff29, except in mailmerge, where 3bc8f90e9693f710f12632f69b9348c1c833c906 seems to have done some research and the old state wasnt particulary well-justified. In testSmartArtAnchoredInline the order of elements has changed. This exposes a bug in SwFEShell::Paste, which stops copying SpzFrameFormats (aka FlyFrameFormats and DrawFrameFormats) after having copied the first FlyFrameFormat, claiming other Flys will have been copied via FlyInFly. If there are DrawFrameFormats behind the FlyFrameFormats, they will be forgotten. So instead: - first copy the DrawFrameFormats - then copy the first FlyFrameFormat to not forget any Draw Formats. Also, give the format copying its own function, at 100 lines its annoying enough all by itself. Change-Id: I301e27ff94fb82cf0502457630acdcbfa342a566 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124162 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124438 diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index a9e21389009f..81629a8b03c4 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -464,31 +464,31 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testMsoPosition, "bnc884615-mso-position.doc // We write the frames out in different order than they were read, so check it's the correct // textbox first by checking width. These tests may need reordering if that gets fixed. OUString style1 = getXPath(doc, "/w:ftr/w:p/w:r[3]/mc:AlternateContent/mc:Fallback/w:pict/v:rect", "style"); - CPPUNIT_ASSERT( style1.indexOf( ";width:36pt;" ) >= 0 ); - CPPUNIT_ASSERT( style1.indexOf( ";mso-position-horizontal-relative:text" ) >= 0 ); - CPPUNIT_ASSERT( style1.indexOf( ";mso-position-vertical-relative:text" ) >= 0 ); + CPPUNIT_ASSERT( style1.indexOf( ";width:531pt;" ) >= 0 ); + CPPUNIT_ASSERT( style1.indexOf( ";mso-position-vertical-relative:page" ) >= 0 ); + CPPUNIT_ASSERT( style1.indexOf( ";mso-position-horizontal-relative:page" ) >= 0 ); OUString style2 = getXPath(doc, "/w:ftr/w:p/w:r[4]/mc:AlternateContent/mc:Fallback/w:pict/v:rect", "style"); CPPUNIT_ASSERT( style2.indexOf( ";width:549pt;" ) >= 0 ); CPPUNIT_ASSERT( style2.indexOf( ";mso-position-vertical-relative:text" ) >= 0 ); CPPUNIT_ASSERT( style2.indexOf( ";mso-position-horizontal:center" ) >= 0 ); CPPUNIT_ASSERT( style2.indexOf( ";mso-position-horizontal-relative:text" ) >= 0 ); OUString style3 = getXPath(doc, "/w:ftr/w:p/w:r[5]/mc:AlternateContent/mc:Fallback/w:pict/v:rect", "style"); - CPPUNIT_ASSERT( style3.indexOf( ";width:531pt;" ) >= 0 ); - CPPUNIT_ASSERT( style3.indexOf( ";mso-position-vertical-relative:page" ) >= 0 ); - CPPUNIT_ASSERT( style3.indexOf( ";mso-position-horizontal-relative:page" ) >= 0 ); + CPPUNIT_ASSERT( style3.indexOf( ";width:36pt;" ) >= 0 ); + CPPUNIT_ASSERT( style3.indexOf( ";mso-position-horizontal-relative:text" ) >= 0 ); + CPPUNIT_ASSERT( style3.indexOf( ";mso-position-vertical-relative:text" ) >= 0 ); } xmlDocUniquePtr doc = parseExport("word/header1.xml"); OUString style1 = getXPath(doc, "/w:hdr/w:p/w:r[2]/mc:AlternateContent/mc:Fallback/w:pict/v:rect", "style"); - CPPUNIT_ASSERT( style1.indexOf( ";width:138.15pt;" ) >= 0 ); + CPPUNIT_ASSERT( style1.indexOf( ";width:335.75pt;" ) >= 0 ); CPPUNIT_ASSERT( style1.indexOf( ";mso-position-horizontal-relative:page" ) >= 0 ); CPPUNIT_ASSERT( style1.indexOf( ";mso-position-vertical-relative:page" ) >= 0 ); OUString style2 = getXPath(doc, "/w:hdr/w:p/w:r[3]/mc:AlternateContent/mc:Fallback/w:pict/v:rect", "style"); - CPPUNIT_ASSERT( style2.indexOf( ";width:163.8pt;" ) >= 0 ); + CPPUNIT_ASSERT( style2.indexOf( ";width:138.15pt;" ) >= 0 ); CPPUNIT_ASSERT( style2.indexOf( ";mso-position-horizontal-relative:page" ) >= 0 ); CPPUNIT_ASSERT( style2.indexOf( ";mso-position-vertical-relative:page" ) >= 0 ); OUString style3 = getXPath(doc, "/w:hdr/w:p/w:r[4]/mc:AlternateContent/mc:Fallback/w:pict/v:rect", "style"); - CPPUNIT_ASSERT( style3.indexOf( ";width:335.75pt;" ) >= 0 ); + CPPUNIT_ASSERT( style3.indexOf( ";width:163.8pt;" ) >= 0 ); CPPUNIT_ASSERT( style3.indexOf( ";mso-position-horizontal-relative:page" ) >= 0 ); CPPUNIT_ASSERT( style3.indexOf( ";mso-position-vertical-relative:page" ) >= 0 ); diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index aefa24911b43..bb2ab0a3a2b4 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -171,7 +171,7 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf128207, "tdf128207.docx") //There was the charts on each other, because their horizontal and vertical position was 0! xmlDocUniquePtr p_XmlDoc = parseExport("word/document.xml"); CPPUNIT_ASSERT(p_XmlDoc); - assertXPathContent(p_XmlDoc, "/w:document/w:body/w:p[1]/w:r[1]/w:drawing/wp:anchor/wp:positionH/wp:posOffset", "4445"); + assertXPathContent(p_XmlDoc, "/w:document/w:body/w:p[1]/w:r[1]/w:drawing[4]/wp:anchor/wp:positionH/wp:posOffset", "4445"); } DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf123873, "tdf123873.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx index 4cf43b15a052..6cd7110359c2 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx @@ -694,14 +694,14 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testSmartArtAnchoredInline, "fdo73227.docx") */ xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); - assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing[1]/wp:anchor/wp:docPr","id","1"); - assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing[1]/wp:anchor/wp:docPr","name","Diagram1"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing[2]/wp:anchor/wp:docPr","id","2"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing[2]/wp:anchor/wp:docPr","name","Diagram2"); - assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:docPr","id","2"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:docPr","id","3"); assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:docPr","name","10-Point Star 3"); - assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing[2]/wp:anchor/wp:docPr","id","3"); - assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing[2]/wp:anchor/wp:docPr","name","Picture 1"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing[1]/wp:anchor/wp:docPr","id","1"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing[1]/wp:anchor/wp:docPr","name","Picture 1"); } DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFdo65833, "fdo65833.docx") diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index 127268737d71..514a13e88ff1 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -251,11 +251,11 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132911) CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(0, getShapes()); - //FIXME: tdf#135247 - //dispatchCommand(mxComponent, ".uno:Undo", {}); - //Scheduler::ProcessEventsToIdle(); - //CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); - //CPPUNIT_ASSERT_EQUAL(4, getShapes()); + //tdf#135247: Without the fix in place, this would have crashed + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); + CPPUNIT_ASSERT_EQUAL(4, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf61154) diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx index bb6aa4a12654..0f9e3fc063a2 100644 --- a/sw/source/core/frmedt/fecopy.cxx +++ b/sw/source/core/frmedt/fecopy.cxx @@ -70,6 +70,7 @@ #include <frameformats.hxx> #include <vcl/virdev.hxx> #include <svx/svdundo.hxx> +#include <viewimp.hxx> using namespace ::com::sun::star; @@ -708,6 +709,123 @@ namespace { } } +namespace { + bool lcl_PasteFlyOrDrawFormat(SwPaM& rPaM, SwFrameFormat* pCpyFormat, SwFEShell& rSh) + { + auto& rImp = *rSh.Imp(); + auto& rDoc = *rSh.GetDoc(); + auto& rDrawView = *rImp.GetDrawView(); + if(rDrawView.IsGroupEntered() && + RES_DRAWFRMFMT == pCpyFormat->Which() && + (RndStdIds::FLY_AS_CHAR != pCpyFormat->GetAnchor().GetAnchorId())) + { + const SdrObject* pSdrObj = pCpyFormat->FindSdrObject(); + if(pSdrObj) + { + SdrObject* pNew = rDoc.CloneSdrObj(*pSdrObj, false, false); + // Insert object sets any anchor position to 0. + // Therefore we calculate the absolute position here + // and after the insert the anchor of the object + // is set to the anchor of the group object. + tools::Rectangle aSnapRect = pNew->GetSnapRect(); + if(pNew->GetAnchorPos().X() || pNew->GetAnchorPos().Y()) + { + const Point aPoint(0, 0); + // OD 2004-04-05 #i26791# - direct drawing object + // positioning for group members + pNew->NbcSetAnchorPos(aPoint); + pNew->NbcSetSnapRect(aSnapRect); + } + + rDrawView.InsertObjectAtView(pNew, *rImp.GetPageView()); + + Point aGrpAnchor(0, 0); + SdrObjList* pList = pNew->getParentSdrObjListFromSdrObject(); + if(pList) + { + SdrObjGroup* pOwner(dynamic_cast<SdrObjGroup*>(pList->getSdrObjectFromSdrObjList())); + + if(nullptr != pOwner) + aGrpAnchor = pOwner->GetAnchorPos(); + } + + // OD 2004-04-05 #i26791# - direct drawing object + // positioning for group members + pNew->NbcSetAnchorPos(aGrpAnchor); + pNew->SetSnapRect(aSnapRect); + return true; + } + } + SwFormatAnchor aAnchor(pCpyFormat->GetAnchor()); + if ((RndStdIds::FLY_AT_PARA == aAnchor.GetAnchorId()) || + (RndStdIds::FLY_AT_CHAR == aAnchor.GetAnchorId()) || + (RndStdIds::FLY_AS_CHAR == aAnchor.GetAnchorId())) + { + SwPosition* pPos = rPaM.GetPoint(); + // allow shapes (no controls) in header/footer + if(RES_DRAWFRMFMT == pCpyFormat->Which() && rDoc.IsInHeaderFooter(pPos->nNode)) + { + const SdrObject *pCpyObj = pCpyFormat->FindSdrObject(); + if(pCpyObj && CheckControlLayer(pCpyObj)) + return true; + } + else if(pCpyFormat->Which() == RES_FLYFRMFMT && IsInTextBox(pCpyFormat)) + { + // This is a fly frame which is anchored in a TextBox, ignore it as + // it's already copied as part of copying the content of the + // TextBox. + return true; + } + // Ignore TextBoxes, they are already handled in sw::DocumentLayoutManager::CopyLayoutFormat(). + if(SwTextBoxHelper::isTextBox(pCpyFormat, RES_FLYFRMFMT)) + return true; + aAnchor.SetAnchor(pPos); + } + else if(RndStdIds::FLY_AT_PAGE == aAnchor.GetAnchorId()) + { + aAnchor.SetPageNum(rSh.GetPhyPageNum()); + } + else if(RndStdIds::FLY_AT_FLY == aAnchor.GetAnchorId()) + { + Point aPt; + (void)lcl_SetAnchor(*rPaM.GetPoint(), rPaM.GetNode(), nullptr, aPt, rSh, aAnchor, aPt, false); + } + + SwFrameFormat* pNew = rDoc.getIDocumentLayoutAccess().CopyLayoutFormat(*pCpyFormat, aAnchor, true, true); + + if(!pNew) + return true; + switch(pNew->Which()) + { + case RES_FLYFRMFMT: + { + assert(dynamic_cast<SwFlyFrameFormat*>(pNew)); + const Point aPt(rSh.GetCursorDocPos()); + SwFlyFrame* pFlyFrame = static_cast<SwFlyFrameFormat*>(pNew)->GetFrame(&aPt); + if(pFlyFrame) + rSh.SelectFlyFrame(*pFlyFrame); + return false; + } + case RES_DRAWFRMFMT: + { + assert(dynamic_cast<SwDrawFrameFormat*>(pNew)); + SwDrawFrameFormat* pDrawFormat = static_cast<SwDrawFrameFormat*>(pNew); + // #i52780# - drawing object has to be made visible on paste. + pDrawFormat->CallSwClientNotify(sw::DrawFrameFormatHint(sw::DrawFrameFormatHintId::PREPPASTING)); + SdrObject* pObj = pDrawFormat->FindSdrObject(); + rDrawView.MarkObj(pObj, rDrawView.GetSdrPageView()); + // #i47455# - notify draw frame format + // that position attributes are already set. + pDrawFormat->PosAttrSet(); + break; + } + default: + SAL_WARN("sw.core", "unknown fly type"); + } + return true; + } +} + bool SwFEShell::Paste(SwDoc& rClpDoc, bool bNestedTable) { CurrShell aCurr( this ); @@ -912,136 +1030,18 @@ bool SwFEShell::Paste(SwDoc& rClpDoc, bool bNestedTable) break; // exit the "while-loop" } - else if( *aCpyPam.GetPoint() == *aCpyPam.GetMark() && - !rClpDoc.GetSpzFrameFormats()->empty() ) + else if(*aCpyPam.GetPoint() == *aCpyPam.GetMark() && !rClpDoc.GetSpzFrameFormats()->empty()) { // we need a DrawView - if( !Imp()->GetDrawView() ) + if(!Imp()->GetDrawView()) MakeDrawView(); - - for ( auto pCpyFormat : *rClpDoc.GetSpzFrameFormats() ) - { - bool bInsWithFormat = true; - - if( Imp()->GetDrawView()->IsGroupEntered() && - RES_DRAWFRMFMT == pCpyFormat->Which() && - (RndStdIds::FLY_AS_CHAR != pCpyFormat->GetAnchor().GetAnchorId()) ) - { - const SdrObject* pSdrObj = pCpyFormat->FindSdrObject(); - if( pSdrObj ) - { - SdrObject* pNew = GetDoc()->CloneSdrObj( *pSdrObj, - false, false ); - - // Insert object sets any anchor position to 0. - // Therefore we calculate the absolute position here - // and after the insert the anchor of the object - // is set to the anchor of the group object. - tools::Rectangle aSnapRect = pNew->GetSnapRect(); - if( pNew->GetAnchorPos().X() || pNew->GetAnchorPos().Y() ) - { - const Point aPoint( 0, 0 ); - // OD 2004-04-05 #i26791# - direct drawing object - // positioning for group members - pNew->NbcSetAnchorPos( aPoint ); - pNew->NbcSetSnapRect( aSnapRect ); - } - - Imp()->GetDrawView()->InsertObjectAtView( pNew, *Imp()->GetPageView() ); - - Point aGrpAnchor( 0, 0 ); - SdrObjList* pList = pNew->getParentSdrObjListFromSdrObject(); - if ( pList ) - { - SdrObjGroup* pOwner(dynamic_cast< SdrObjGroup* >(pList->getSdrObjectFromSdrObjList())); - - if(nullptr != pOwner) - { - aGrpAnchor = pOwner->GetAnchorPos(); - } - } - - // OD 2004-04-05 #i26791# - direct drawing object - // positioning for group members - pNew->NbcSetAnchorPos( aGrpAnchor ); - pNew->SetSnapRect( aSnapRect ); - - bInsWithFormat = false; - } - } - - if( bInsWithFormat ) - { - SwFormatAnchor aAnchor( pCpyFormat->GetAnchor() ); - if ((RndStdIds::FLY_AT_PARA == aAnchor.GetAnchorId()) || - (RndStdIds::FLY_AT_CHAR == aAnchor.GetAnchorId()) || - (RndStdIds::FLY_AS_CHAR == aAnchor.GetAnchorId())) - { - SwPosition* pPos = rPaM.GetPoint(); - // allow shapes (no controls) in header/footer - if( RES_DRAWFRMFMT == pCpyFormat->Which() && - GetDoc()->IsInHeaderFooter( pPos->nNode ) ) - { - const SdrObject *pCpyObj = pCpyFormat->FindSdrObject(); - if (pCpyObj && CheckControlLayer(pCpyObj)) - continue; - } - else if (pCpyFormat->Which() == RES_FLYFRMFMT && IsInTextBox(pCpyFormat)) - { - // This is a fly frame which is anchored in a TextBox, ignore it as - // it's already copied as part of copying the content of the - // TextBox. - continue; - } - - // Ignore TextBoxes, they are already handled in sw::DocumentLayoutManager::CopyLayoutFormat(). - if (SwTextBoxHelper::isTextBox(pCpyFormat, RES_FLYFRMFMT)) - continue; - - aAnchor.SetAnchor( pPos ); - } - else if ( RndStdIds::FLY_AT_PAGE == aAnchor.GetAnchorId() ) - { - aAnchor.SetPageNum( GetPhyPageNum() ); - } - else if( RndStdIds::FLY_AT_FLY == aAnchor.GetAnchorId() ) - { - Point aPt; - (void)lcl_SetAnchor( *rPaM.GetPoint(), rPaM.GetNode(), - nullptr, aPt, *this, aAnchor, aPt, false ); - } - - SwFrameFormat * pNew = GetDoc()->getIDocumentLayoutAccess().CopyLayoutFormat( *pCpyFormat, aAnchor, true, true ); - - if( pNew ) - { - if( RES_FLYFRMFMT == pNew->Which() ) - { - const Point aPt( GetCursorDocPos() ); - SwFlyFrame* pFlyFrame = static_cast<SwFlyFrameFormat*>(pNew)-> - GetFrame( &aPt ); - if( pFlyFrame ) - SelectFlyFrame( *pFlyFrame ); - // always pick the first FlyFrame only; the others - // were copied to the clipboard via Fly in Fly - break; - } - else - { - OSL_ENSURE( RES_DRAWFRMFMT == pNew->Which(), "New format."); - // #i52780# - drawing object has to be made visible on paste. - pNew->CallSwClientNotify(sw::DrawFrameFormatHint(sw::DrawFrameFormatHintId::PREPPASTING)); - SdrObject *pObj = pNew->FindSdrObject(); - SwDrawView *pDV = Imp()->GetDrawView(); - pDV->MarkObj( pObj, pDV->GetSdrPageView() ); - // #i47455# - notify draw frame format - // that position attributes are already set. - if (SwDrawFrameFormat *pDrawFormat = dynamic_cast<SwDrawFrameFormat*>(pNew)) - pDrawFormat->PosAttrSet(); - } - } - } - } + for(auto pCpyFormat: *rClpDoc.GetSpzFrameFormats()) + if(pCpyFormat->Which() != RES_FLYFRMFMT) + lcl_PasteFlyOrDrawFormat(rPaM, pCpyFormat, *this); + for(auto pCpyFormat: *rClpDoc.GetSpzFrameFormats()) + if(pCpyFormat->Which() == RES_FLYFRMFMT) + if(!lcl_PasteFlyOrDrawFormat(rPaM, pCpyFormat, *this)) + break; } else { diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx index 8cfb9524365c..214df4da1b27 100644 --- a/sw/source/core/layout/flycnt.cxx +++ b/sw/source/core/layout/flycnt.cxx @@ -86,7 +86,10 @@ SwFlyAtContentFrame::SwFlyAtContentFrame( SwFlyFrameFormat *pFormat, SwFrame* pS void SwFlyAtContentFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint) { if (rHint.GetId() != SfxHintId::SwLegacyModify) + { + SwFlyFrame::SwClientNotify(rMod, rHint); return; + } auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); const SwFormatAnchor* pAnch = pLegacy->m_pNew ? GetAnchorFromPoolItem(*pLegacy->m_pNew) : nullptr; if(!pAnch)