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).
Change-Id: Idaad43909cd744a379e713efd70ffd000e2692bc
Reviewed-on: https://gerrit.libreoffice.org/75867
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sw/qa/extras/uiwriter/data2/ole-save-while-edit.odt b/sw/qa/extras/uiwriter/data2/ole-save-while-edit.odt
new file mode 100644
index 0000000..33a2284
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data2/ole-save-while-edit.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 2c9e4e9..b48dfdf 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -37,6 +37,7 @@
#include <sfx2/dispatch.hxx>
#include <svl/stritem.hxx>
#include <svx/svxids.hrc>
#include <comphelper/lok.hxx>
#include <txtfrm.hxx>
#include <redline.hxx>
#include <view.hxx>
@@ -2004,4 +2005,39 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDateFormFieldCurrentDateInvalidation)
}
#endif
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, 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);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx
index 229deca..b6c0df3 100644
--- a/sw/source/uibase/app/docsh.cxx
+++ b/sw/source/uibase/app/docsh.cxx
@@ -1276,6 +1276,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_xDoc->GetDfltGrfFormatColl() );
for( SwContentNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
{