diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-06-07 12:27:23 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-06-08 08:03:53 +0200 |
commit | 9af01c56237b716c7f3bfe4664fd1ca1cd87edde (patch) | |
tree | 8f9444907bde4d00a0c08650a6363af8ffaf67b6 | |
parent | d51becdd4f469922581924e0ae4c91df2b06beda (diff) |
Related: tdf#108269 DOCM filter: reuse oox code for VBA preservation
With this, the project stream import is shared between DOCM and XLSM.
Change-Id: I8fbffefc5acf28adea4875fa6bc4148a99b5ebef
Reviewed-on: https://gerrit.libreoffice.org/38495
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
(cherry picked from commit e4adb8d9e77bab353dda26375e11a6b7a456368f)
Reviewed-on: https://gerrit.libreoffice.org/38544
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 55 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 1 |
2 files changed, 32 insertions, 24 deletions
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 25d30ef02d1e..ae4c27a9aa84 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -24,6 +24,7 @@ #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> #include <com/sun/star/document/XDocumentProperties.hpp> +#include <com/sun/star/document/XStorageBasedDocument.hpp> #include <com/sun/star/drawing/XShape.hpp> #include <com/sun/star/i18n/ScriptType.hpp> #include <com/sun/star/frame/XModel.hpp> @@ -1256,6 +1257,36 @@ void DocxExport::WriteActiveX() void DocxExport::WriteVBA() { + uno::Reference<document::XStorageBasedDocument> xStorageBasedDocument(m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY); + if (!xStorageBasedDocument.is()) + return; + + uno::Reference<embed::XStorage> xDocumentStorage(xStorageBasedDocument->getDocumentStorage(), uno::UNO_QUERY); + OUString aMacrosName("_MS_VBA_Macros"); + if (!xDocumentStorage.is() || !xDocumentStorage->hasByName(aMacrosName)) + return; + + const sal_Int32 nOpenMode = embed::ElementModes::READ; + uno::Reference<io::XStream> xMacrosStream(xDocumentStorage->openStreamElement(aMacrosName, nOpenMode), uno::UNO_QUERY); + uno::Reference<io::XOutputStream> xProjectStream; + if (xMacrosStream.is()) + { + // First handle the the project stream, this sets xProjectStream. + std::unique_ptr<SvStream> pIn(utl::UcbStreamHelper::CreateStream(xMacrosStream)); + + xProjectStream = GetFilter().openFragmentStream("word/vbaProject.bin", "application/vnd.ms-office.vbaProject"); + uno::Reference<io::XStream> xOutputStream(xProjectStream, uno::UNO_QUERY); + if (!xOutputStream.is()) + return; + std::unique_ptr<SvStream> pOut(utl::UcbStreamHelper::CreateStream(xOutputStream)); + + // Write the stream. + pOut->WriteStream(*pIn); + + // Write the relationship. + m_pFilter->addRelation(m_pDocumentFS->getOutputStream(), "http://schemas.microsoft.com/office/2006/relationships/vbaProject", "vbaProject.bin"); + } + uno::Reference<beans::XPropertySet> xPropertySet(m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY); if (!xPropertySet.is()) return; @@ -1275,31 +1306,9 @@ void DocxExport::WriteVBA() if (!aVBA.hasElements()) return; - uno::Reference<io::XOutputStream> xProjectStream; for (const auto& rProperty : aVBA) { - if (rProperty.Name == "ProjectStream") - { - // First check for the project stream, this sets xProjectStream. - uno::Reference<io::XStream> xInputStream; - rProperty.Value >>= xInputStream; - if (!xInputStream.is()) - return; - std::unique_ptr<SvStream> pIn(utl::UcbStreamHelper::CreateStream(xInputStream)); - - xProjectStream = GetFilter().openFragmentStream("word/vbaProject.bin", "application/vnd.ms-office.vbaProject"); - uno::Reference<io::XStream> xOutputStream(xProjectStream, uno::UNO_QUERY); - if (!xOutputStream.is()) - return; - std::unique_ptr<SvStream> pOut(utl::UcbStreamHelper::CreateStream(xOutputStream)); - - // Write the stream. - pOut->WriteStream(*pIn); - - // Write the relationship. - m_pFilter->addRelation(m_pDocumentFS->getOutputStream(), "http://schemas.microsoft.com/office/2006/relationships/vbaProject", "vbaProject.bin"); - } - else if (rProperty.Name == "DataStream") + if (rProperty.Name == "DataStream") { // Then the data stream, which wants to work with an already set // xProjectStream. diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx index 550820be018e..3c3aa8822bec 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -873,7 +873,6 @@ void OOXMLDocumentImpl::preserveVBA() maVBA = comphelper::InitPropertySequence( { - {"ProjectStream", uno::makeAny(xStream)}, {"DataStream", uno::makeAny(xDataStream)} }); } |