[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - oovbaapi/ooo sw/source

Tor Lillqvist (via logerrit) logerrit at kemper.freedesktop.org
Fri Sep 20 10:56:23 UTC 2019


 oovbaapi/ooo/vba/word/XDocument.idl |    3 
 sw/source/ui/vba/vbadocument.cxx    |  112 ++++++++++++++++++++++++++++++++++++
 sw/source/ui/vba/vbadocument.hxx    |    2 
 3 files changed, 117 insertions(+)

New commits:
commit cd71c8f1d3eea5a17a209d98a568f8592a4e480b
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Tue Mar 26 15:05:02 2019 +0200
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Fri Sep 20 12:55:29 2019 +0200

    Add SaveAs2000() and SaveAs() to ooo.vba.word.XDocument and implement
    
    Change-Id: If7e45e2f791a7806e6cf8e7fc9693e19e87d2dbb
    (cherry picked from commit 0de4f894cf23635db639a64fcac2e77b8560c122)
    Reviewed-on: https://gerrit.libreoffice.org/79189
    Reviewed-by: Tor Lillqvist <tml at collabora.com>
    Tested-by: Tor Lillqvist <tml at collabora.com>

diff --git a/oovbaapi/ooo/vba/word/XDocument.idl b/oovbaapi/ooo/vba/word/XDocument.idl
index 9259fc9fa4a9..888287b34e1b 100644
--- a/oovbaapi/ooo/vba/word/XDocument.idl
+++ b/oovbaapi/ooo/vba/word/XDocument.idl
@@ -61,6 +61,9 @@ interface XDocument
     void ClosePrintPreview();
     any Revisions( [in] any index );
     any Frames( [in] any index );
+    void SaveAs2000( [in] any FileName, [in] any FileFormat, [in] any LockComments, [in] any Password, [in] any AddToRecentFiles, [in] any WritePassword, [in] any ReadOnlyRecommended, [in] any EmbedTrueTypeFonts, [in] any SaveNativePictureFormat, [in] any SaveFormsData, [in] any SaveAsAOCELetter );
+    void SaveAs( [in] any FileName, [in] any FileFormat, [in] any LockComments, [in] any Password, [in] any AddToRecentFiles, [in] any WritePassword, [in] any ReadOnlyRecommended, [in] any EmbedTrueTypeFonts, [in] any SaveNativePictureFormat, [in] any SaveFormsData, [in] any SaveAsAOCELetter, [in] any Encoding, [in] any InsertLineBreaks, [in] any AllowSubstitutions, [in] any LineEnding, [in] any AddBiDiMarks );
+
 };
 
 }; }; };
diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx
index df94a8585fd9..4fcd09f693a0 100644
--- a/sw/source/ui/vba/vbadocument.cxx
+++ b/sw/source/ui/vba/vbadocument.cxx
@@ -34,9 +34,13 @@
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/drawing/XControlShape.hpp>
 #include <com/sun/star/form/XFormsSupplier.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/document/XRedlinesSupplier.hpp>
+#include <com/sun/star/util/thePathSettings.hpp>
 #include <ooo/vba/XControlProvider.hpp>
 #include <ooo/vba/word/WdProtectionType.hpp>
+#include <ooo/vba/word/WdSaveFormat.hpp>
+#include <ooo/vba/word/XApplication.hpp>
 #include <ooo/vba/word/XDocumentOutgoing.hpp>
 
 #include <vbahelper/helperdecl.hxx>
@@ -451,6 +455,114 @@ SwVbaDocument::Frames( const uno::Any& index )
     return uno::makeAny( xCol );
 }
 
+namespace {
+
+bool setFilterPropsFromFormat( sal_Int32 nFormat, uno::Sequence< beans::PropertyValue >& rProps )
+{
+    bool bRes = false;
+    for ( sal_Int32 index = 0; index < rProps.getLength(); ++index )
+    {
+        if ( rProps[ index ].Name == "FilterName" )
+        {
+            switch( nFormat )
+            {
+                case word::WdSaveFormat::wdFormatDocument:
+                    rProps[ index ].Value <<= OUString("MS Word 97");
+                    break;
+                // Just save all the text formats as "Text"
+                case word::WdSaveFormat::wdFormatDOSText:
+                case word::WdSaveFormat::wdFormatDOSTextLineBreaks:
+                case word::WdSaveFormat::wdFormatEncodedText:
+                case word::WdSaveFormat::wdFormatText:
+                case word::WdSaveFormat::wdFormatTextLineBreaks:
+                    rProps[ index ].Value <<= OUString("Text");
+                    break;
+                case word::WdSaveFormat::wdFormatFilteredHTML:
+                case word::WdSaveFormat::wdFormatHTML:
+                    rProps[ index ].Value <<= OUString("HTML");
+                    break;
+                case word::WdSaveFormat::wdFormatRTF:
+                    rProps[ index ].Value <<= OUString("Rich Text Format");
+                    break;
+                case word::WdSaveFormat::wdFormatTemplate:
+                    rProps[ index ].Value <<= OUString("MS Word 97 Vorlage");
+                    break;
+
+                // Default to "MS Word 97"
+                default:
+                    rProps[ index ].Value <<= OUString("MS Word 97");
+                    break;
+            }
+            bRes = true;
+            break;
+        }
+    }
+    return bRes;
+}
+
+}
+
+void SAL_CALL
+SwVbaDocument::SaveAs2000( const uno::Any& FileName, const uno::Any& FileFormat, const uno::Any& /*LockComments*/, const uno::Any& /*Password*/, const uno::Any& /*AddToRecentFiles*/, const uno::Any& /*WritePassword*/, const uno::Any& /*ReadOnlyRecommended*/, const uno::Any& /*EmbedTrueTypeFonts*/, const uno::Any& /*SaveNativePictureFormat*/, const uno::Any& /*SaveFormsData*/, const uno::Any& /*SaveAsAOCELetter*/ )
+{
+    // Based on ScVbaWorkbook::SaveAs.
+    OUString sFileName;
+    FileName >>= sFileName;
+    OUString sURL;
+    osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
+
+    // Detect if there is no path then we need to use the current folder.
+    INetURLObject aURL( sURL );
+    sURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
+    if( sURL.isEmpty() )
+    {
+        // Need to add cur dir ( of this document ) or else the 'Work' dir
+        sURL = getModel()->getURL();
+
+        if ( sURL.isEmpty() )
+        {
+            // Not path available from 'this' document. Need to add the 'document'/work directory then.
+            // Based on SwVbaOptions::getValueEvent()
+            uno::Reference< util::XPathSettings > xPathSettings = util::thePathSettings::get( comphelper::getProcessComponentContext() );
+            OUString sPathUrl;
+            xPathSettings->getPropertyValue( "Work" ) >>= sPathUrl;
+            // Path could be a multipath, Microsoft doesn't support this feature in Word currently.
+            // Only the last path is from interest.
+            sal_Int32 nIndex = sPathUrl.lastIndexOf( ';' );
+            if( nIndex != -1 )
+            {
+                sPathUrl = sPathUrl.copy( nIndex + 1 );
+            }
+
+            aURL.SetURL( sPathUrl );
+        }
+        else
+        {
+            aURL.SetURL( sURL );
+            aURL.Append( sFileName );
+        }
+        sURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
+
+    }
+
+    sal_Int32 nFileFormat = word::WdSaveFormat::wdFormatDocument;
+    FileFormat >>= nFileFormat;
+
+    uno::Sequence<  beans::PropertyValue > storeProps(1);
+    storeProps[0].Name = "FilterName" ;
+
+    setFilterPropsFromFormat( nFileFormat, storeProps );
+
+    uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
+    xStor->storeAsURL( sURL, storeProps );
+}
+
+void SAL_CALL
+SwVbaDocument::SaveAs( const uno::Any& FileName, const uno::Any& FileFormat, const uno::Any& LockComments, const uno::Any& Password, const uno::Any& AddToRecentFiles, const uno::Any& WritePassword, const uno::Any& ReadOnlyRecommended, const uno::Any& EmbedTrueTypeFonts, const uno::Any& SaveNativePictureFormat, const uno::Any& SaveFormsData, const uno::Any& SaveAsAOCELetter, const uno::Any& /*Encoding*/, const uno::Any& /*InsertLineBreaks*/, const uno::Any& /*AllowSubstitutions*/, const uno::Any& /*LineEnding*/, const uno::Any& /*AddBiDiMarks*/ )
+{
+    return SaveAs2000( FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter );
+}
+
 uno::Any
 SwVbaDocument::getControlShape( const OUString& sName )
 {
diff --git a/sw/source/ui/vba/vbadocument.hxx b/sw/source/ui/vba/vbadocument.hxx
index 5dca8ae709b7..1acb42e9232f 100644
--- a/sw/source/ui/vba/vbadocument.hxx
+++ b/sw/source/ui/vba/vbadocument.hxx
@@ -88,6 +88,8 @@ public:
     virtual void SAL_CALL ClosePrintPreview(  ) override;
     virtual css::uno::Any SAL_CALL Revisions( const css::uno::Any& aIndex ) override;
     virtual css::uno::Any SAL_CALL Frames( const css::uno::Any& aIndex ) override;
+    virtual void SAL_CALL SaveAs2000( const css::uno::Any& FileName, const css::uno::Any& FileFormat, const css::uno::Any& LockComments, const css::uno::Any& Password, const css::uno::Any& AddToRecentFiles, const css::uno::Any& WritePassword, const css::uno::Any& ReadOnlyRecommended, const css::uno::Any& EmbedTrueTypeFonts, const css::uno::Any& SaveNativePictureFormat, const css::uno::Any& SaveFormsData, const css::uno::Any& SaveAsAOCELetter ) override;
+    virtual void SAL_CALL SaveAs( const css::uno::Any& FileName, const css::uno::Any& FileFormat, const css::uno::Any& LockComments, const css::uno::Any& Password, const css::uno::Any& AddToRecentFiles, const css::uno::Any& WritePassword, const css::uno::Any& ReadOnlyRecommended, const css::uno::Any& EmbedTrueTypeFonts, const css::uno::Any& SaveNativePictureFormat, const css::uno::Any& SaveFormsData, const css::uno::Any& SaveAsAOCELetter, const css::uno::Any& Encoding, const css::uno::Any& InsertLineBreaks, const css::uno::Any& AllowSubstitutions, const css::uno::Any& LineEnding, const css::uno::Any& AddBiDiMarks ) override;
 
     // XInvocation
     virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection(  ) override;


More information about the Libreoffice-commits mailing list