summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/CppunitTest_sw_uibase_shells.mk1
-rw-r--r--sw/inc/viewsh.hxx4
-rw-r--r--sw/qa/uibase/shells/data/ole-preview-update.odtbin0 -> 20265 bytes
-rw-r--r--sw/qa/uibase/shells/shells.cxx23
-rw-r--r--sw/source/core/view/viewsh.cxx41
-rw-r--r--sw/source/uibase/shells/basesh.cxx1
-rw-r--r--sw/source/uibase/uiview/view.cxx3
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx10
8 files changed, 82 insertions, 1 deletions
diff --git a/sw/CppunitTest_sw_uibase_shells.mk b/sw/CppunitTest_sw_uibase_shells.mk
index 9734b395bca6..a3b913ab572c 100644
--- a/sw/CppunitTest_sw_uibase_shells.mk
+++ b/sw/CppunitTest_sw_uibase_shells.mk
@@ -32,6 +32,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uibase_shells, \
unotest \
utl \
vcl \
+ tl \
))
$(eval $(call gb_CppunitTest_use_externals,sw_uibase_shells,\
diff --git a/sw/inc/viewsh.hxx b/sw/inc/viewsh.hxx
index fe3fee74bcea..72b361203824 100644
--- a/sw/inc/viewsh.hxx
+++ b/sw/inc/viewsh.hxx
@@ -370,6 +370,10 @@ public:
// All about fields.
void UpdateFields(bool bCloseDB = false);
bool IsAnyFieldInDoc() const;
+
+ /// Update the previews of all OLE objects.
+ void UpdateOleObjectPreviews();
+
// Update all charts, for that exists any table.
void UpdateAllCharts();
bool HasCharts() const;
diff --git a/sw/qa/uibase/shells/data/ole-preview-update.odt b/sw/qa/uibase/shells/data/ole-preview-update.odt
new file mode 100644
index 000000000000..3fd4d264628e
--- /dev/null
+++ b/sw/qa/uibase/shells/data/ole-preview-update.odt
Binary files differ
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index fbdf35758156..75f975fabaaa 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -17,6 +17,7 @@
#include <editeng/adjustitem.hxx>
#include <editeng/outlobj.hxx>
#include <editeng/editobj.hxx>
+#include <unotools/ucbstreamhelper.hxx>
#include <IDocumentContentOperations.hxx>
#include <cmdid.h>
@@ -139,6 +140,28 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testOleSavePreviewUpdate)
CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 2"));
}
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testOlePreviewUpdate)
+{
+ // Given a document with an embedded Writer object:
+ load(DATA_DIRECTORY, "ole-preview-update.odt");
+
+ // When updating "all" (including OLE previews):
+ dispatchCommand(mxComponent, ".uno:UpdateAll", {});
+
+ // Then make sure the preview is no longer a 0-sized stream:
+ 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());
+ uno::Reference<io::XInputStream> xInputStream(
+ xNameAccess->getByName("ObjectReplacements/Object 1"), uno::UNO_QUERY);
+ std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
+ // Without the accompanying fix in place, this test would have failed, the stream was still
+ // empty.
+ CPPUNIT_ASSERT_GREATER(static_cast<sal_uInt64>(0), pStream->remainingSize());
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index c5d20fe38d88..e30fc909eaad 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -81,6 +81,9 @@
#include <vcl/sysdata.hxx>
#endif
+#include <frameformats.hxx>
+#include <fmtcntnt.hxx>
+
bool SwViewShell::mbLstAct = false;
ShellResource *SwViewShell::mpShellRes = nullptr;
vcl::DeleteOnDeinit<std::shared_ptr<weld::Window>> SwViewShell::mpCareDialog(new std::shared_ptr<weld::Window>);
@@ -655,6 +658,44 @@ void SwViewShell::UpdateFields(bool bCloseDB)
EndAction();
}
+void SwViewShell::UpdateOleObjectPreviews()
+{
+ SwDoc* pDoc = GetDoc();
+ const SwFrameFormats* const pFormats = pDoc->GetSpzFrameFormats();
+ if (pFormats->empty())
+ {
+ return;
+ }
+
+ for (size_t i = 0; i < pFormats->size(); ++i)
+ {
+ SwFrameFormat* pFormat = (*pFormats)[i];
+ if (pFormat->Which() != RES_FLYFRMFMT)
+ {
+ continue;
+ }
+
+ const SwNodeIndex* pNodeIndex = pFormat->GetContent().GetContentIdx();
+ if (!pNodeIndex || !pNodeIndex->GetNodes().IsDocNodes())
+ {
+ continue;
+ }
+
+ SwNode* pNode = pDoc->GetNodes()[pNodeIndex->GetIndex() + 1];
+ SwOLENode* pOleNode = pNode->GetOLENode();
+ if (!pOleNode)
+ {
+ continue;
+ }
+
+ SwOLEObj& rOleObj = pOleNode->GetOLEObj();
+ svt::EmbeddedObjectRef& rObject = rOleObj.GetObject();
+ rObject.UpdateReplacement();
+ // Trigger the repaint.
+ pOleNode->SetChanged();
+ }
+}
+
/** update all charts for which any table exists */
void SwViewShell::UpdateAllCharts()
{
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx
index 44d78d6e5821..892f4c8fdfbe 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -734,6 +734,7 @@ void SwBaseShell::Execute(SfxRequest &rReq)
rDis.Execute( FN_UPDATE_TOX );
rDis.Execute( FN_UPDATE_CHARTS );
rSh.CalcLayout();
+ rSh.UpdateOleObjectPreviews();
}
break;
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index d7837c800bfb..c21190fecb85 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -131,7 +131,8 @@ void SwView::ImpSetVerb( SelectionType nSelType )
if ( !GetViewFrame()->GetFrame().IsInPlace() &&
(SelectionType::Ole|SelectionType::Graphic) & nSelType )
{
- if ( m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content) == FlyProtectFlags::NONE )
+ FlyProtectFlags eProtectFlags = m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content);
+ if (eProtectFlags == FlyProtectFlags::NONE || nSelType & SelectionType::Ole)
{
if ( nSelType & SelectionType::Ole )
{
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 0dbb7aaf0796..8d369fa50e40 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -25,6 +25,7 @@
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
#include <hintids.hxx>
#include <sot/exchange.hxx>
@@ -98,6 +99,7 @@
#include <svtools/embedhlp.hxx>
#include <svx/postattr.hxx>
#include <comphelper/lok.hxx>
+#include <comphelper/propertyvalue.hxx>
#include <memory>
using namespace sw::mark;
@@ -622,6 +624,14 @@ void SwWrtShell::LaunchOLEObj( long nVerb )
if ( !pCli )
pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xRef );
+ uno::Reference<lang::XInitialization> xOLEInit(xRef.GetObject(), uno::UNO_QUERY);
+ if (xOLEInit.is())
+ {
+ uno::Sequence<beans::PropertyValue> aArguments
+ = { comphelper::makePropertyValue("ReadOnly", pCli->IsProtected()) };
+ xOLEInit->initialize({ uno::makeAny(aArguments) });
+ }
+
static_cast<SwOleClient*>(pCli)->SetInDoVerb( true );
CalcAndSetScale( xRef );