summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-11-26 08:45:24 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-11-26 13:41:15 +0100
commit6f85752705c5e5bdb4eef539f669bc0961f14356 (patch)
tree17dec25fb9cc193309e19ac97f68f05991ef4480
parent18a2d02f7969878fa90e0dcffd15ea5261b2369f (diff)
sw, viewing OLE objects: also protect "common" embeded objects
Commit 4f9f1ac33366817df61c488a9f36b09c592ee939 (sw: allow viewing OLE objects in protected sections, 2021-11-25) allowed launching OLE objects in protected sections, and then made sure that changes done in "real" OLE editors (on Windows) are discarded: both the native data and preview. Extend this mechanism to also handle common embedded objects (i.e. when we load the data into an own document model, like Calc-in-Writer on Linux): there we can simply load the data read-only, so there will be no need to discard anything. This requires some way to pass down the read-only flag from sw/ to embeddedobj, implement XInitialization on OCommonEmbeddedObject to do that. (cherry picked from commit 32842d4bf250bcab281eb71a218d618485c60290) Conflicts: sw/source/uibase/wrtsh/wrtsh1.cxx Change-Id: I7b32d7514a6b0a40b4f58bed57879d292daa4ed7
-rw-r--r--embeddedobj/source/commonembedding/miscobj.cxx22
-rw-r--r--embeddedobj/source/commonembedding/persistence.cxx5
-rw-r--r--embeddedobj/source/inc/commonembobj.hxx5
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx10
4 files changed, 42 insertions, 0 deletions
diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx
index 8a1dd801f6ea..3f4414b8118a 100644
--- a/embeddedobj/source/commonembedding/miscobj.cxx
+++ b/embeddedobj/source/commonembedding/miscobj.cxx
@@ -33,6 +33,7 @@
#include <vcl/svapp.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <comphelper/sequenceashashmap.hxx>
#include "persistence.hxx"
@@ -347,6 +348,11 @@ uno::Any SAL_CALL OCommonEmbeddedObject::queryInterface( const uno::Type& rType
void* p = static_cast<lang::XServiceInfo*>(this);
return uno::Any(&p, rType);
}
+ else if (rType == cppu::UnoType<lang::XInitialization>::get())
+ {
+ void* p = static_cast<lang::XInitialization*>(this);
+ return uno::Any(&p, rType);
+ }
else if (rType == cppu::UnoType<lang::XTypeProvider>::get())
{
void* p = static_cast<lang::XTypeProvider*>(this);
@@ -619,6 +625,7 @@ uno::Sequence<uno::Type> SAL_CALL OCommonEmbeddedObject::getTypes()
cppu::UnoType<container::XChild>::get(),
cppu::UnoType<chart2::XDefaultSizeTransmitter>::get(),
cppu::UnoType<lang::XServiceInfo>::get(),
+ cppu::UnoType<lang::XInitialization>::get(),
cppu::UnoType<lang::XTypeProvider>::get(),
};
return aTypes;
@@ -629,4 +636,19 @@ uno::Sequence<sal_Int8> SAL_CALL OCommonEmbeddedObject::getImplementationId()
return uno::Sequence<sal_Int8>();
}
+void SAL_CALL OCommonEmbeddedObject::initialize(const uno::Sequence<uno::Any>& rArguments)
+{
+ if (!rArguments.hasElements())
+ {
+ return;
+ }
+
+ comphelper::SequenceAsHashMap aMap(rArguments[0]);
+ auto it = aMap.find("ReadOnly");
+ if (it != aMap.end())
+ {
+ it->second >>= m_bReadOnly;
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embeddedobj/source/commonembedding/persistence.cxx b/embeddedobj/source/commonembedding/persistence.cxx
index 3e4ab0dd989f..9618c2776de6 100644
--- a/embeddedobj/source/commonembedding/persistence.cxx
+++ b/embeddedobj/source/commonembedding/persistence.cxx
@@ -530,6 +530,11 @@ uno::Reference< util::XCloseable > OCommonEmbeddedObject::LoadDocumentFromStorag
// set the document mode to embedded as the first step!!!
EmbedAndReparentDoc_Impl( xDocument );
+ if (m_bReadOnly)
+ {
+ aLoadArgs.put("ReadOnly", true);
+ }
+
if ( xDoc.is() )
{
xDoc->loadFromStorage( xSourceStorage, aLoadArgs.getPropertyValues() );
diff --git a/embeddedobj/source/inc/commonembobj.hxx b/embeddedobj/source/inc/commonembobj.hxx
index 922ecf50d59f..88fccb37bc40 100644
--- a/embeddedobj/source/inc/commonembobj.hxx
+++ b/embeddedobj/source/inc/commonembobj.hxx
@@ -34,6 +34,7 @@
#include <com/sun/star/util/XCloseable.hpp>
#include <com/sun/star/chart2/XDefaultSizeTransmitter.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
#include <cppuhelper/weak.hxx>
#include <rtl/ref.hxx>
#include <map>
@@ -80,6 +81,7 @@ class OCommonEmbeddedObject : public css::embed::XEmbeddedObject
, public css::container::XChild
, public css::chart2::XDefaultSizeTransmitter
, public css::lang::XServiceInfo
+ , public css::lang::XInitialization
, public css::lang::XTypeProvider
, public ::cppu::OWeakObject
{
@@ -403,6 +405,9 @@ public:
sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
+ // XInitialization
+ void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;
+
// XTypeProvider
css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
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 );