summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-08-17 21:06:32 +0200
committerMiklos Vajna <vmiklos@collabora.com>2020-08-18 09:03:45 +0200
commitb784ee4feb554987eff1c7fdaff640abb340504d (patch)
treebf6cd0a4958bf1dbe3bed72a839cb4720d3dc1f1
parentb7b4565473b09c771d5a949c394013956f1c4db7 (diff)
tdf#135016 DOCX export: fix unexpected error on save with undo/redo
Regression from commit d379d18666aa42031359ca8eb34b0021960347ae (oox: import WPS shape with text as shape with textbox, 2014-06-18), then problem was that when undo restored text deleted by cut, we ended up with an SwXShape that had no frame format. Fix the problem by deleting the cached old UNO wrapper after changing the association between a textbox's shape and text frame. An alternative would be to handle errors better when the TextBox UNO property is not of type bool, but that would still lead to silent data loss, so don't fix the problem that way. Change-Id: Id45ad292befc746e7c49a3b827c91efd069d29df Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100876 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/CppunitTest_sw_core_undo.mk74
-rw-r--r--sw/Module_sw.mk1
-rw-r--r--sw/qa/core/undo/data/textbox-cut-save.docxbin0 -> 7272 bytes
-rw-r--r--sw/qa/core/undo/undo.cxx55
-rw-r--r--sw/source/core/undo/undobj1.cxx13
5 files changed, 143 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_core_undo.mk b/sw/CppunitTest_sw_core_undo.mk
new file mode 100644
index 000000000000..11593cd9e604
--- /dev/null
+++ b/sw/CppunitTest_sw_core_undo.mk
@@ -0,0 +1,74 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_core_undo))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_undo))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_undo, \
+ sw/qa/core/undo/undo \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_undo, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ sfx \
+ svxcore \
+ sw \
+ swqahelper \
+ test \
+ unotest \
+ utl \
+ vcl \
+ svt \
+ tl \
+ svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_undo,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_undo,\
+ -I$(SRCDIR)/sw/inc \
+ -I$(SRCDIR)/sw/source/core/inc \
+ -I$(SRCDIR)/sw/source/uibase/inc \
+ -I$(SRCDIR)/sw/qa/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_core_undo,\
+ udkapi \
+ offapi \
+ oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_undo))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_undo))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_undo,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_undo,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_undo))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_undo, \
+ modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_undo))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 66d27573ec98..0df68e21a6f7 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -119,6 +119,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_core_objectpositioning \
CppunitTest_sw_core_unocore \
CppunitTest_sw_core_crsr \
+ CppunitTest_sw_core_undo \
))
ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/undo/data/textbox-cut-save.docx b/sw/qa/core/undo/data/textbox-cut-save.docx
new file mode 100644
index 000000000000..a1a350d08aac
--- /dev/null
+++ b/sw/qa/core/undo/data/textbox-cut-save.docx
Binary files differ
diff --git a/sw/qa/core/undo/undo.cxx b/sw/qa/core/undo/undo.cxx
new file mode 100644
index 000000000000..aeacffc78e9b
--- /dev/null
+++ b/sw/qa/core/undo/undo.cxx
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <unotools/mediadescriptor.hxx>
+
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+#include <wrtsh.hxx>
+#include <swdtflvr.hxx>
+
+char const DATA_DIRECTORY[] = "/sw/qa/core/undo/data/";
+
+/// Covers sw/source/core/undo/ fixes.
+class SwCoreUndoTest : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(SwCoreUndoTest, testTextboxCutSave)
+{
+ // Load the document and select all.
+ load(DATA_DIRECTORY, "textbox-cut-save.docx");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ SwDocShell* pDocShell = pTextDoc->GetDocShell();
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+ pWrtShell->SelAll();
+
+ // Cut.
+ rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
+ pTransfer->Cut();
+
+ // Undo.
+ pWrtShell->Undo();
+
+ // Save.
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OUString("Office Open XML Text");
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // void sax_fastparser::FastSaxSerializer::endDocument(): Assertion `mbMarkStackEmpty && maMarkStack.empty()' failed.
+ // i.e. failed to save because we tried to write not-well-formed XML.
+ xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/undo/undobj1.cxx b/sw/source/core/undo/undobj1.cxx
index ea0f0f850d39..039180145d86 100644
--- a/sw/source/core/undo/undobj1.cxx
+++ b/sw/source/core/undo/undobj1.cxx
@@ -39,6 +39,7 @@
#include <ndtxt.hxx>
#include <ndole.hxx>
#include <frameformats.hxx>
+#include <svx/svdobj.hxx>
SwUndoFlyBase::SwUndoFlyBase( SwFrameFormat* pFormat, SwUndoId nUndoId )
: SwUndo(nUndoId, pFormat->GetDoc())
@@ -141,6 +142,18 @@ void SwUndoFlyBase::InsFly(::sw::UndoRedoContext & rContext, bool bShowSelFrame)
// recklessly assume that this thing will live longer than the
// SwUndoFlyBase - not sure what could be done if that isn't the case...
m_pFrameFormat->GetOtherTextBoxFormat()->SetOtherTextBoxFormat(m_pFrameFormat);
+
+ if (m_pFrameFormat->GetOtherTextBoxFormat()->Which() == RES_DRAWFRMFMT)
+ {
+ SdrObject* pSdrObject = m_pFrameFormat->GetOtherTextBoxFormat()->FindSdrObject();
+ if (pSdrObject)
+ {
+ // Make sure the old UNO wrapper is no longer cached after changing the shape +
+ // textframe pair. Otherwise we would have a wrapper which doesn't know about its
+ // textframe, even if it's there.
+ pSdrObject->setUnoShape(nullptr);
+ }
+ }
}
m_pFrameFormat->MakeFrames();