fdo#82191 sw::DocumentLayoutManager: copy textbox content of draw formats
The SwFmtCntnt, i.e. the content of the draw format was already copied,
but that's only a pointer to the real content: instead duplicate the
real contents on copy&paste, that's how we copy fly frames as well.
Change-Id: I42475e356aaa1c54c08fb23a6a395d1726e5f33e
diff --git a/sw/qa/extras/uiwriter/data/fdo82191.odt b/sw/qa/extras/uiwriter/data/fdo82191.odt
new file mode 100644
index 0000000..d0759c0
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/fdo82191.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 10cb454..e12af85 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -18,6 +18,7 @@
#include <section.hxx>
#include <fmtclds.hxx>
#include <dcontact.hxx>
#include <textboxhelper.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdview.hxx>
@@ -46,6 +47,7 @@
void testCp1000071();
void testShapeTextboxVertadjust();
void testShapeTextboxAutosize();
void testFdo82191();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -62,6 +64,7 @@
CPPUNIT_TEST(testCp1000071);
CPPUNIT_TEST(testShapeTextboxVertadjust);
CPPUNIT_TEST(testShapeTextboxAutosize);
CPPUNIT_TEST(testFdo82191);
CPPUNIT_TEST_SUITE_END();
private:
@@ -390,6 +393,27 @@
CPPUNIT_ASSERT(pFirst->GetSnapRect().getHeight() < pSecond->GetSnapRect().getHeight());
}
void SwUiWriterTest::testFdo82191()
{
SwDoc* pDoc = createDoc("fdo82191.odt");
SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
std::set<const SwFrmFmt*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pDoc);
// Make sure we have a single draw shape.
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), SwTextBoxHelper::getCount(pPage, aTextBoxes));
SwDoc aClipboard;
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
SdrObject* pObject = pPage->GetObj(0);
// Select it, then copy and paste.
pWrtShell->SelectObj(Point(), 0, pObject);
pWrtShell->Copy(&aClipboard);
pWrtShell->Paste(&aClipboard);
aTextBoxes = SwTextBoxHelper::findTextBoxes(pDoc);
// This was one: the textbox of the shape wasn't copied.
CPPUNIT_ASSERT_EQUAL(size_t(2), aTextBoxes.size());
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/DocumentLayoutManager.cxx b/sw/source/core/doc/DocumentLayoutManager.cxx
index 1772723..19b07cb 100644
--- a/sw/source/core/doc/DocumentLayoutManager.cxx
+++ b/sw/source/core/doc/DocumentLayoutManager.cxx
@@ -39,6 +39,7 @@
#include <unoframe.hxx>
#include <docary.hxx>
#include <dcontact.hxx>
#include <textboxhelper.hxx>
using namespace ::com::sun::star;
@@ -493,6 +494,16 @@
if( bMakeFrms )
pDest->MakeFrms();
// If the draw format has a TextBox, then copy its fly format as well.
if (SwFrmFmt* pSourceTextBox = SwTextBoxHelper::findTextBox(&rSource))
{
SwFrmFmt* pDestTextBox = CopyLayoutFmt(*pSourceTextBox, rNewAnchor, bSetTxtFlyAtt, bMakeFrms);
SwAttrSet aSet(pDest->GetAttrSet());
SwFmtCntnt aCntnt(pDestTextBox->GetCntnt().GetCntntIdx()->GetNode().GetStartNode());
aSet.Put(aCntnt);
pDest->SetFmtAttr(aSet);
}
return pDest;
}
diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx
index 261f492..6bdf41f 100644
--- a/sw/source/core/frmedt/fecopy.cxx
+++ b/sw/source/core/frmedt/fecopy.cxx
@@ -75,6 +75,7 @@
#include <docsh.hxx>
#include <pagedesc.hxx>
#include <mvsave.hxx>
#include <textboxhelper.hxx>
#include <vcl/virdev.hxx>
#include <svx/svdundo.hxx>
@@ -884,6 +885,7 @@
if( !Imp()->GetDrawView() )
MakeDrawView();
std::set<const SwFrmFmt*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pClpDoc);
for ( sal_uInt16 i = 0; i < pClpDoc->GetSpzFrmFmts()->size(); ++i )
{
bool bInsWithFmt = true;
@@ -953,6 +955,10 @@
continue;
}
// Ignore TextBoxes, they are already handled in sw::DocumentLayoutManager::CopyLayoutFmt().
if (aTextBoxes.find(&rCpyFmt) != aTextBoxes.end())
continue;
aAnchor.SetAnchor( pPos );
}
else if ( FLY_AT_PAGE == aAnchor.GetAnchorId() )