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 <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit 9188d7389c06496905c351a936b85974c1ae516f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136982
Tested-by: Jenkins
Signed-off-by: Xisco Fauli <xiscofauli@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 0000000..70682a5
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf142715.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index 068a141..d4175cc 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 418c699..413424c 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());