summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-07-18 18:03:54 +0200
committerMiklos Vajna <vmiklos@collabora.com>2019-07-19 12:10:51 +0200
commitdb175f7b0114fce67b2ae403b572e53fd8aa9f25 (patch)
treed673e13b1fb2638d01fae44f9c1686cc33d8ec93
parentb202fabd2123555fad0ca251ab3e8b7ab7c8d36a (diff)
sw: fix missing OLE preview for actively edited OLE object on save
Regression from commit 74844277cc2194c9e43f5bd7a6f78a9603da32f3 (disable generation of ole previews in ODF format until after load, 2016-09-13), if the user started an OLE edit in a Writer document, and saved without ending the OLE edit, then svt::EmbeddedObjectRef::UpdateReplacementOnDemand() removed the old replacement image, but no new one was created. Given that save is always an explicit user action (auto-save does not kick in for unmodified documents), restore the permission to update OLE replacement images during save. Do this check in SwDocShell::CalcLayoutForOLEObjects(), as that's OLE-related and is called from all the relevant save code paths (save, save-as, convert to alien formats). Reviewed-on: https://gerrit.libreoffice.org/75867 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins (cherry picked from commit d33cc4f7edc2ce21a9c5a01a7f5e85cfd324c6d9) Conflicts: sw/qa/extras/uiwriter/uiwriter2.cxx sw/source/uibase/app/docsh.cxx Change-Id: Idaad43909cd744a379e713efd70ffd000e2692bc
-rw-r--r--sw/qa/extras/uiwriter/data/ole-save-while-edit.odtbin0 -> 14547 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx38
-rw-r--r--sw/source/uibase/app/docsh.cxx8
3 files changed, 46 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/data/ole-save-while-edit.odt b/sw/qa/extras/uiwriter/data/ole-save-while-edit.odt
new file mode 100644
index 000000000000..33a2284dd314
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/ole-save-while-edit.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 66886a70fa05..735ab11d4518 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -108,6 +108,7 @@
#include <sfx2/watermarkitem.hxx>
#include <svtools/htmlout.hxx>
#include <test/htmltesttools.hxx>
+#include <comphelper/lok.hxx>
#include <wrthtml.hxx>
namespace
@@ -279,6 +280,7 @@ public:
void testHtmlCopyImages();
void testTdf116789();
void testTdf117225();
+ void testOleSaveWhileEdit();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -420,6 +422,7 @@ public:
CPPUNIT_TEST(testHtmlCopyImages);
CPPUNIT_TEST(testTdf116789);
CPPUNIT_TEST(testTdf117225);
+ CPPUNIT_TEST(testOleSaveWhileEdit);
CPPUNIT_TEST_SUITE_END();
private:
@@ -5083,6 +5086,41 @@ void SwUiWriterTest::testTdf117225()
CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
}
+void SwUiWriterTest::testOleSaveWhileEdit()
+{
+ // Enable LOK mode, otherwise OCommonEmbeddedObject::SwitchStateTo_Impl() will throw when it
+ // finds out that the test runs headless.
+ comphelper::LibreOfficeKit::setActive();
+
+ // Load a document with a Draw doc in it.
+ SwDoc* pDoc = createDoc("ole-save-while-edit.odt");
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->GotoObj(/*bNext=*/true, GotoObjFlags::Any);
+
+ // Select the frame and switch to the frame shell.
+ SwView* pView = pDoc->GetDocShell()->GetView();
+ pView->StopShellTimer();
+
+ // Start editing the OLE object.
+ pWrtShell->LaunchOLEObj();
+
+ // Save the document without existing the OLE edit.
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ xStorable->storeToURL(maTempFile.GetURL(), {});
+
+ uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
+ = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory),
+ maTempFile.GetURL());
+ // Without the accompanying fix in place, this test would have failed: the OLE object lost its
+ // replacement on save if the edit was active while saving.
+ CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 1"));
+
+ // Dispose the document while LOK is still active to avoid leaks.
+ mxComponent->dispose();
+ mxComponent.clear();
+ comphelper::LibreOfficeKit::setActive(false);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx
index 2f1815ab6598..18a079835957 100644
--- a/sw/source/uibase/app/docsh.cxx
+++ b/sw/source/uibase/app/docsh.cxx
@@ -1211,6 +1211,14 @@ void SwDocShell::CalcLayoutForOLEObjects()
if (!m_pWrtShell)
return;
+ if (m_pView && m_pView->GetIPClient())
+ {
+ // We have an active OLE edit: allow link updates, so an up to date replacement graphic can
+ // be created.
+ comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
+ rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
+ }
+
SwIterator<SwContentNode,SwFormatColl> aIter( *m_pDoc->GetDfltGrfFormatColl() );
for( SwContentNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
{