[Libreoffice-commits] core.git: oox/source sd/source

Jan Holesovsky kendy at collabora.com
Fri Jul 21 17:49:21 UTC 2017


 oox/source/ppt/presentationfragmenthandler.cxx |   37 +++++++++++++++++--------
 sd/source/filter/eppt/epptooxml.hxx            |    3 ++
 sd/source/filter/eppt/pptx-epptooxml.cxx       |   35 ++++++++++++++++++++++-
 3 files changed, 63 insertions(+), 12 deletions(-)

New commits:
commit ee6f8f1982d666f8fcda96d2141a9332a10b8273
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Jul 19 16:35:10 2017 +0200

    sd pptm: Preserve the VBA stream on export.
    
    This actually implements the reading of the VBA stream in Impress too, so the
    user will get a warning when opening such a file (that the it contains
    macros).
    
    Change-Id: I1638199529196ed217cbd9ebef88eb7c88f2179a
    Reviewed-on: https://gerrit.libreoffice.org/40197
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Reviewed-on: https://gerrit.libreoffice.org/40267
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx
index a41284c3177f..4ef9ea282dea 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -27,6 +27,7 @@
 #include <com/sun/star/drawing/XDrawPages.hpp>
 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
 #include <com/sun/star/xml/dom/XDocument.hpp>
 #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
@@ -34,16 +35,18 @@
 #include <com/sun/star/presentation/XPresentationPage.hpp>
 #include <com/sun/star/task/XStatusIndicator.hpp>
 
-#include "oox/drawingml/theme.hxx"
-#include "oox/drawingml/drawingmltypes.hxx"
-#include "oox/drawingml/themefragmenthandler.hxx"
-#include "drawingml/textliststylecontext.hxx"
+#include <oox/drawingml/theme.hxx>
+#include <oox/drawingml/drawingmltypes.hxx>
+#include <oox/drawingml/themefragmenthandler.hxx>
+#include <drawingml/textliststylecontext.hxx>
 #include <oox/helper/attributelist.hxx>
-#include "oox/ppt/pptshape.hxx"
-#include "oox/ppt/presentationfragmenthandler.hxx"
-#include "oox/ppt/slidefragmenthandler.hxx"
-#include "oox/ppt/layoutfragmenthandler.hxx"
-#include "oox/ppt/pptimport.hxx"
+#include <oox/ole/olestorage.hxx>
+#include <oox/ole/vbaproject.hxx>
+#include <oox/ppt/pptshape.hxx>
+#include <oox/ppt/presentationfragmenthandler.hxx>
+#include <oox/ppt/slidefragmenthandler.hxx>
+#include <oox/ppt/layoutfragmenthandler.hxx>
+#include <oox/ppt/pptimport.hxx>
 #include <oox/token/namespaces.hxx>
 #include <oox/token/tokens.hxx>
 
@@ -394,8 +397,8 @@ void PresentationFragmentHandler::finalizeImport()
     StringRangeEnumerator aRangeEnumerator( aPageRange, 0, nPageCount - 1 );
     StringRangeEnumerator::Iterator aIter = aRangeEnumerator.begin();
     StringRangeEnumerator::Iterator aEnd  = aRangeEnumerator.end();
-    if(aIter!=aEnd) {
-
+    if (aIter!=aEnd)
+    {
         // todo: localized progress bar text
         const Reference< task::XStatusIndicator >& rxStatusIndicator( getFilter().getStatusIndicator() );
         if ( rxStatusIndicator.is() )
@@ -424,6 +427,18 @@ void PresentationFragmentHandler::finalizeImport()
         if ( rxStatusIndicator.is() )
             rxStatusIndicator->end();
     }
+
+    // open the VBA project storage
+    OUString aVbaFragmentPath = getFragmentPathFromFirstType(CREATE_MSOFFICE_RELATION_TYPE("vbaProject"));
+    if (!aVbaFragmentPath.isEmpty())
+    {
+        uno::Reference<io::XInputStream> xInStrm = getFilter().openInputStream(aVbaFragmentPath);
+        if (xInStrm.is())
+        {
+            StorageRef xPrjStrg(new oox::ole::OleStorage(getFilter().getComponentContext(), xInStrm, false));
+            getFilter().getVbaProject().importVbaProject(*xPrjStrg);
+        }
+    }
 }
 
 // CT_Presentation
diff --git a/sd/source/filter/eppt/epptooxml.hxx b/sd/source/filter/eppt/epptooxml.hxx
index cc60f76d8089..aa27ad8adf19 100644
--- a/sd/source/filter/eppt/epptooxml.hxx
+++ b/sd/source/filter/eppt/epptooxml.hxx
@@ -157,6 +157,9 @@ private:
     AuthorsMap maAuthors;
 
     void WriteAuthors();
+
+    /// If this is PPTM, output the VBA stream.
+    void WriteVBA();
 };
 
 }
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx
index c359859358a6..ebf122d8a34c 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -28,12 +28,14 @@
 #include <oox/export/shapes.hxx>
 
 #include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/storagehelper.hxx>
 #include <cppuhelper/implementationentry.hxx>
 #include <cppuhelper/factory.hxx>
 #include <sax/fshelper.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <filter/msfilter/escherex.hxx>
 #include <tools/poly.hxx>
+#include <unotools/ucbstreamhelper.hxx>
 
 #include <com/sun/star/animations/AnimationAdditiveMode.hpp>
 #include <com/sun/star/animations/AnimationCalcMode.hpp>
@@ -55,6 +57,7 @@
 #include <com/sun/star/container/XEnumerationAccess.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
 #include <com/sun/star/drawing/RectanglePoint.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
 #include <com/sun/star/geometry/RealPoint2D.hpp>
 #include <com/sun/star/office/XAnnotationEnumeration.hpp>
 #include <com/sun/star/office/XAnnotationAccess.hpp>
@@ -69,6 +72,7 @@
 
 #include <com/sun/star/document/XDocumentProperties.hpp>
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
+#include <com/sun/star/document/XStorageBasedDocument.hpp>
 #include <utility>
 
 // presentation namespaces
@@ -399,6 +403,8 @@ bool PowerPointExport::exportDocument()
 
     WriteAuthors();
 
+    WriteVBA();
+
     mPresentationFS->endElementNS( XML_p, XML_presentation );
     mPresentationFS.reset();
     // Free all FSHelperPtr, to flush data before committing storage
@@ -1439,7 +1445,8 @@ void PowerPointExport::WriteAuthors()
 
 sal_Int32 PowerPointExport::GetAuthorIdAndLastIndex( const OUString& sAuthor, sal_Int32& nLastIndex )
 {
-    if ( maAuthors.count( sAuthor ) <= 0 ) {
+    if (maAuthors.count(sAuthor) <= 0)
+    {
         struct AuthorComments aAuthorComments;
 
         aAuthorComments.nId = maAuthors.size();
@@ -1513,6 +1520,32 @@ bool PowerPointExport::WriteComments( sal_uInt32 nPageNum )
     return false;
 }
 
+void PowerPointExport::WriteVBA()
+{
+    if (!mbPptm)
+        return;
+
+    uno::Reference<document::XStorageBasedDocument> xStorageBasedDocument(getModel(), 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::XInputStream> xMacrosStream(xDocumentStorage->openStreamElement(aMacrosName, nOpenMode), uno::UNO_QUERY);
+    if (!xMacrosStream.is())
+        return;
+
+    uno::Reference<io::XOutputStream> xOutputStream = openFragmentStream("ppt/vbaProject.bin", "application/vnd.ms-office.vbaProject");
+    comphelper::OStorageHelper::CopyInputToOutput(xMacrosStream, xOutputStream);
+
+    // Write the relationship.
+    addRelation(mPresentationFS->getOutputStream(), "http://schemas.microsoft.com/office/2006/relationships/vbaProject", "vbaProject.bin");
+}
+
 void PowerPointExport::ImplWriteSlide( sal_uInt32 nPageNum, sal_uInt32 nMasterNum, sal_uInt16 /* nMode */,
                                        bool bHasBackground, Reference< XPropertySet > const & aXBackgroundPropSet )
 {


More information about the Libreoffice-commits mailing list