sw/qa/extras/uiwriter/data/tdf142715.odt |binary sw/qa/extras/uiwriter/uiwriter3.cxx | 34 +++++++++++++++++++++++++++++++ sw/source/core/doc/textboxhelper.cxx | 13 +---------- 3 files changed, 36 insertions(+), 11 deletions(-)
New commits: commit 8e75da583db160b15ca55d74b3a2c64b1d034e33 Author: Attila Bakos (NISZ) <bakos.attilakar...@nisz.hu> AuthorDate: Thu Jun 30 15:48:07 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Jul 19 09:45:44 2022 +0200 tdf#142715 sw: fix crash on exit when textbox inserted to table This reverts commit 06e2cbb31d0ea703df872b91eb8eacdcaced7653 "tdf#130805 SwTextBoxHelper::create: fix frame position in shape" which caused this regression. That fix is not necessary any more: synchronization does the same without crashing. Note: according to this, unit test of commit 06e2cbb31d0ea703df872b91eb8eacdcaced7653 wasn't removed. Change-Id: I45bc15d3cf6a5d93b8c54cb4e68018702e58efff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136674 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit 9188d7389c06496905c351a936b85974c1ae516f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136982 Tested-by: Jenkins Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137047 diff --git a/sw/qa/extras/uiwriter/data/tdf142715.odt b/sw/qa/extras/uiwriter/data/tdf142715.odt new file mode 100644 index 000000000000..70682a54056c Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf142715.odt differ diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index 068a14113a0b..d4175ccc93a5 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -22,6 +22,7 @@ #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> #include <com/sun/star/text/XPageCursor.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> #include <comphelper/propertysequence.hxx> #include <boost/property_tree/json_parser.hpp> #include <fmtanchr.hxx> @@ -3920,6 +3921,39 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf103612) "Text after section"); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testCrashOnExit) +{ + // Load the bugdoc with a table and a textbox shape inside. + CPPUNIT_ASSERT(createSwDoc(DATA_DIRECTORY, "tdf142715.odt")); + // Get the textbox selected + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + auto xShape = getShape(1); + CPPUNIT_ASSERT(xShape); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xModel); + uno::Reference<frame::XController> xController = xModel->getCurrentController(); + CPPUNIT_ASSERT(xController); + uno::Reference<view::XSelectionSupplier> xSelection(xController, uno::UNO_QUERY); + CPPUNIT_ASSERT(xSelection); + CPPUNIT_ASSERT(xSelection->select(uno::Any(xShape))); + CPPUNIT_ASSERT(xSelection->getSelection().hasValue()); + uno::Reference<beans::XPropertySet> xProperties(xShape, uno::UNO_QUERY); + // Check if the textbox is selected + CPPUNIT_ASSERT_EQUAL(true, xProperties->getPropertyValue("TextBox").get<bool>()); + // Remove the textbox + dispatchCommand(mxComponent, ".uno:RemoveTextBox", {}); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(false, xProperties->getPropertyValue("TextBox").get<bool>()); + // Readd the textbox (to run the textboxhelper::create() method) + dispatchCommand(mxComponent, ".uno:AddTextBox", {}); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(true, xProperties->getPropertyValue("TextBox").get<bool>()); + // save and reload + reload("writer8", "tdf142715_.odt"); + // Before the fix this crashed here and could not reopen. + CPPUNIT_ASSERT_MESSAGE("Crash on exit, isn't it?", mxComponent); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf97899) { SwDoc* pDoc = createSwDoc(); diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 418c69927228..413424cb93b0 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -93,17 +93,8 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape, SdrObject* pObject, bool bCo pShape->GetDoc()->GetDocShell()->GetBaseModel(), uno::UNO_QUERY); uno::Reference<text::XTextContentAppend> xTextContentAppend(xTextDocument->getText(), uno::UNO_QUERY); - try - { - uno::Reference<text::XTextContent> XSourceShape(pObject->getUnoShape(), - uno::UNO_QUERY_THROW); - xTextContentAppend->insertTextContentWithProperties( - xTextFrame, uno::Sequence<beans::PropertyValue>(), XSourceShape->getAnchor()); - } - catch (uno::Exception&) - { - xTextContentAppend->appendTextContent(xTextFrame, uno::Sequence<beans::PropertyValue>()); - } + xTextContentAppend->appendTextContent(xTextFrame, uno::Sequence<beans::PropertyValue>()); + // Link FLY and DRAW formats, so it becomes a text box (needed for syncProperty calls). uno::Reference<text::XTextFrame> xRealTextFrame(xTextFrame, uno::UNO_QUERY); auto pTextFrame = dynamic_cast<SwXTextFrame*>(xRealTextFrame.get());