summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2019-04-19 11:47:51 +0300
committerTor Lillqvist <tml@collabora.com>2019-09-20 13:56:09 +0200
commit302d67f01f795b88fd2bee09326ec0d895a02177 (patch)
tree6d48aa810eb789ddff97e4a471c6a8b159fc98cc /sw/source
parent13dbbd5f46f2c52426decb019783a3b627bc478d (diff)
Add XWordBasic.FileSaveAs() and implement
Factor out the setFilterPropsFromFormat() also used by SwVbaDocument::SaveAs2000() to a header file of its own. Change-Id: I4bc9e1e420719a115036beb7e82a4ac3feac05f0 Reviewed-on: https://gerrit.libreoffice.org/79208 Reviewed-by: Tor Lillqvist <tml@collabora.com> Tested-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/ui/vba/vbaapplication.cxx85
-rw-r--r--sw/source/ui/vba/vbadocument.cxx48
-rw-r--r--sw/source/ui/vba/vbafilterpropsfromformat.hxx76
3 files changed, 162 insertions, 47 deletions
diff --git a/sw/source/ui/vba/vbaapplication.cxx b/sw/source/ui/vba/vbaapplication.cxx
index b63bc413aff2..e448f871db79 100644
--- a/sw/source/ui/vba/vbaapplication.cxx
+++ b/sw/source/ui/vba/vbaapplication.cxx
@@ -19,9 +19,11 @@
#include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <com/sun/star/util/thePathSettings.hpp>
#include "vbaapplication.hxx"
#include "vbadocument.hxx"
+#include "vbafilterpropsfromformat.hxx"
#include <sal/log.hxx>
#include <osl/file.hxx>
#include <vbahelper/vbahelper.hxx>
@@ -45,6 +47,7 @@
#include <swdll.hxx>
#include <swmodule.hxx>
#include "vbalistgalleries.hxx"
+#include <tools/urlobj.hxx>
using namespace ::ooo;
using namespace ::ooo::vba;
@@ -77,6 +80,17 @@ public:
virtual void SAL_CALL FileOpen( const OUString& Name, const uno::Any& ConfirmConversions, const uno::Any& ReadOnly, const uno::Any& AddToMru, const uno::Any& PasswordDoc, const uno::Any& PasswordDot, const uno::Any& Revert, const uno::Any& WritePasswordDoc, const uno::Any& WritePasswordDot ) override;
virtual void SAL_CALL FileSave() override;
+ virtual void SAL_CALL FileSaveAs( const css::uno::Any& Name,
+ const css::uno::Any& Format,
+ const css::uno::Any& LockAnnot,
+ const css::uno::Any& Password,
+ const css::uno::Any& AddToMru,
+ const css::uno::Any& WritePassword,
+ const css::uno::Any& RecommendReadOnly,
+ const css::uno::Any& EmbedFonts,
+ const css::uno::Any& NativePictureFormat,
+ const css::uno::Any& FormsData,
+ const css::uno::Any& SaveAsAOCELetter ) override;
virtual void SAL_CALL FileClose( const css::uno::Any& Save ) override;
virtual void SAL_CALL ToolsOptionsView( const css::uno::Any& DraftFont,
const css::uno::Any& WrapToWindow,
@@ -553,6 +567,77 @@ SwWordBasic::FileSave()
}
void SAL_CALL
+SwWordBasic::FileSaveAs( const css::uno::Any& Name,
+ const css::uno::Any& Format,
+ const css::uno::Any& /*LockAnnot*/,
+ const css::uno::Any& /*Password*/,
+ const css::uno::Any& /*AddToMru*/,
+ const css::uno::Any& /*WritePassword*/,
+ const css::uno::Any& /*RecommendReadOnly*/,
+ const css::uno::Any& /*EmbedFonts*/,
+ const css::uno::Any& /*NativePictureFormat*/,
+ const css::uno::Any& /*FormsData*/,
+ const css::uno::Any& /*SaveAsAOCELetter*/ )
+{
+ uno::Reference< frame::XModel > xModel( mpApp->getCurrentDocument(), uno::UNO_SET_THROW );
+
+ // Based on SwVbaDocument::SaveAs2000.
+
+ OUString sFileName;
+ Name >>= 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 = xModel->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.
+ // No idea if this crack is relevant for WordBasic or not.
+ 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;
+ Format >>= nFileFormat;
+
+ uno::Sequence< beans::PropertyValue > aProps(2);
+ aProps[0].Name = "FilterName";
+
+ setFilterPropsFromFormat( nFileFormat, aProps );
+
+ aProps[1].Name = "FileName";
+ aProps[1].Value <<= sURL;
+
+ dispatchRequests(xModel,".uno:SaveAs",aProps);
+}
+
+void SAL_CALL
SwWordBasic::FileClose( const css::uno::Any& Save )
{
uno::Reference< frame::XModel > xModel( mpApp->getCurrentDocument(), uno::UNO_SET_THROW );
diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx
index 728107daddda..ba0bfc27189b 100644
--- a/sw/source/ui/vba/vbadocument.cxx
+++ b/sw/source/ui/vba/vbadocument.cxx
@@ -21,6 +21,7 @@
#include <sal/log.hxx>
#include "service.hxx"
+#include "vbafilterpropsfromformat.hxx"
#include "vbadocument.hxx"
#include "vbarange.hxx"
#include "vbarangehelper.hxx"
@@ -456,53 +457,6 @@ 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*/ )
{
diff --git a/sw/source/ui/vba/vbafilterpropsfromformat.hxx b/sw/source/ui/vba/vbafilterpropsfromformat.hxx
new file mode 100644
index 000000000000..e51cdc3cc30e
--- /dev/null
+++ b/sw/source/ui/vba/vbafilterpropsfromformat.hxx
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef INCLUDED_SW_SOURCE_UI_VBA_VBAFILTERPROPSFROMFORMAT_HXX
+#define INCLUDED_SW_SOURCE_UI_VBA_VBAFILTERPROPSFROMFORMAT_HXX
+
+#include <sal/config.h>
+
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <rtl/ustring.hxx>
+#include <ooo/vba/word/WdSaveFormat.hpp>
+
+namespace
+{
+inline bool setFilterPropsFromFormat(sal_Int32 nFormat,
+ css::uno::Sequence<css::beans::PropertyValue>& rProps)
+{
+ bool bRes = false;
+ for (sal_Int32 index = 0; index < rProps.getLength(); ++index)
+ {
+ if (rProps[index].Name == "FilterName")
+ {
+ switch (nFormat)
+ {
+ case ooo::vba::word::WdSaveFormat::wdFormatDocument:
+ rProps[index].Value <<= OUString("MS Word 97");
+ break;
+ // Just save all the text formats as "Text"
+ case ooo::vba::word::WdSaveFormat::wdFormatDOSText:
+ case ooo::vba::word::WdSaveFormat::wdFormatDOSTextLineBreaks:
+ case ooo::vba::word::WdSaveFormat::wdFormatEncodedText:
+ case ooo::vba::word::WdSaveFormat::wdFormatText:
+ case ooo::vba::word::WdSaveFormat::wdFormatTextLineBreaks:
+ rProps[index].Value <<= OUString("Text");
+ break;
+ case ooo::vba::word::WdSaveFormat::wdFormatFilteredHTML:
+ case ooo::vba::word::WdSaveFormat::wdFormatHTML:
+ rProps[index].Value <<= OUString("HTML");
+ break;
+ case ooo::vba::word::WdSaveFormat::wdFormatRTF:
+ rProps[index].Value <<= OUString("Rich Text Format");
+ break;
+ case ooo::vba::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;
+}
+}
+
+#endif