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
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/uiwriter6.cxx b/sw/qa/extras/uiwriter/uiwriter6.cxx
index e52e16a..6a341088 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -31,6 +31,7 @@

#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <o3tl/cppunittraitshelper.hxx>
#include <swdtflvr.hxx>
#include <comphelper/propertysequence.hxx>
@@ -2055,6 +2056,47 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testNestedGroupTextBoxCopyCrash)
    assertXPath(pLayout, "/root/page/body/txt/anchored/fly[2]");
}

CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 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(SwUiWriterTest6, testCaptionShape)
{
    createSwDoc();
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index dffe2d8..131bbaa 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());