[Libreoffice-commits] core.git: sw/source writerfilter/source
Miklos Vajna
vmiklos at collabora.co.uk
Wed Jun 7 12:49:23 UTC 2017
sw/source/filter/ww8/docxexport.cxx | 55 +++++++++++++-----------
writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 1
2 files changed, 32 insertions(+), 24 deletions(-)
New commits:
commit e4adb8d9e77bab353dda26375e11a6b7a456368f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Jun 7 12:27:23 2017 +0200
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 at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index a57eb02915c8..f95aa0cb3a82 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 5eb517810957..c6095737d6ba 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -872,7 +872,6 @@ void OOXMLDocumentImpl::preserveVBA()
maVBA = comphelper::InitPropertySequence(
{
- {"ProjectStream", uno::makeAny(xStream)},
{"DataStream", uno::makeAny(xDataStream)}
});
}
More information about the Libreoffice-commits
mailing list