tdf#107893 sw: fix broken "Add Text Box" after Undo
Adding text frame to a shape by "Add Text Box"
menu item of its local menu and undoing the text
frame by Undo resulted inoperative "Add Text Box",
i.e. it was not possible to readd the text frame.
Change-Id: Id871cecf9682cec040e9db7a0a3a68262c505833
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103541
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/qa/extras/uiwriter/data3/tdf107893.odt b/sw/qa/extras/uiwriter/data3/tdf107893.odt
new file mode 100755
index 0000000..9c24ecc
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data3/tdf107893.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index 315a6f9..dc98dff 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -1301,7 +1301,39 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130805)
CPPUNIT_ASSERT(pShpAnch);
CPPUNIT_ASSERT_EQUAL_MESSAGE("The textbox got apart!", pTxAnch->nNode, pShpAnch->nNode);
//CPPUNIT_ASSERT_EQUAL_MESSAGE("", xShp->getPosition().Y, xShp2->getPosition().Y);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf107893)
{
//Open the sample doc
load(DATA_DIRECTORY, "tdf107893.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
//Get the Writer shell
SwWrtShell* pWrtSh = pTextDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtSh);
//Get the format of the shape
const SwFrameFormats& rFrmFormats = *pWrtSh->GetDoc()->GetSpzFrameFormats();
CPPUNIT_ASSERT(rFrmFormats.size() >= size_t(o3tl::make_unsigned(1)));
SwFrameFormat* pShape = rFrmFormats.front();
CPPUNIT_ASSERT(pShape);
//Add a textbox
SwTextBoxHelper::create(pShape);
SwFrameFormat* pTxBxFrm = SwTextBoxHelper::getOtherTextBoxFormat(getShape(1));
CPPUNIT_ASSERT(pTxBxFrm);
//Remove the textbox using Undo
dispatchCommand(mxComponent, ".uno:Undo", {});
//Add again
SwTextBoxHelper::create(pShape);
pTxBxFrm = SwTextBoxHelper::getOtherTextBoxFormat(getShape(1));
//This was nullptr because of unsuccessful re-adding
CPPUNIT_ASSERT_MESSAGE("Textbox cannot be readd after Undo!", pTxBxFrm);
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf121031)
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 0f095c7..15d80ea 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -52,7 +52,7 @@ using namespace com::sun::star;
void SwTextBoxHelper::create(SwFrameFormat* pShape)
{
// If TextBox wasn't enabled previously
if (pShape->GetAttrSet().HasItem(RES_CNTNT))
if (pShape->GetAttrSet().HasItem(RES_CNTNT) && pShape->GetOtherTextBoxFormat())
return;
// Create the associated TextFrame and insert it into the document.