Kaydet (Commit) 2a6450cb authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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/70980
Tested-by: Jenkins
Reviewed-by: 's avatarTor Lillqvist <tml@collabora.com>
üst d20af20e
...@@ -18,6 +18,7 @@ interface XWordBasic ...@@ -18,6 +18,7 @@ interface XWordBasic
void FileOpen( [in] string Name, [in] any ConfirmConversions, [in] any ReadOnly, [in] any AddToMru, [in] any PasswordDoc, [in] any PasswordDot, [in] any Revert, [in] any WritePasswordDoc, [in] any WritePasswordDot ); void FileOpen( [in] string Name, [in] any ConfirmConversions, [in] any ReadOnly, [in] any AddToMru, [in] any PasswordDoc, [in] any PasswordDot, [in] any Revert, [in] any WritePasswordDoc, [in] any WritePasswordDot );
void FileSave(); void FileSave();
void FileSaveAs( [in] any Name, [in] any Format, [in] any LockAnnot, [in] any Password, [in] any AddToMru, [in] any WritePassword, [in] any RecommendReadOnly, [in] any EmbedFonts, [in] any NativePictureFormat, [in] any FormsData, [in] any SaveAsAOCELetter );
void FileClose( [in] any Save ); void FileClose( [in] any Save );
void ToolsOptionsView( [in] any DraftFont, [in] any WrapToWindow, [in] any PicturePlaceHolders, [in] any FieldCodes, [in] any BookMarks, [in] any FieldShading, [in] any StatusBar, [in] any HScroll, [in] any VScroll, [in] any StyleAreaWidth, [in] any Tabs, [in] any Spaces, [in] any Paras, [in] any Hyphens, [in] any Hidden, [in] any ShowAll, [in] any Drawings, [in] any Anchors, [in] any TextBoundaries, [in] any VRuler, [in] any Highlight ); void ToolsOptionsView( [in] any DraftFont, [in] any WrapToWindow, [in] any PicturePlaceHolders, [in] any FieldCodes, [in] any BookMarks, [in] any FieldShading, [in] any StatusBar, [in] any HScroll, [in] any VScroll, [in] any StyleAreaWidth, [in] any Tabs, [in] any Spaces, [in] any Paras, [in] any Hyphens, [in] any Hidden, [in] any ShowAll, [in] any Drawings, [in] any Anchors, [in] any TextBoundaries, [in] any VRuler, [in] any Highlight );
any WindowName( [in] any Number ); any WindowName( [in] any Number );
......
...@@ -19,9 +19,11 @@ ...@@ -19,9 +19,11 @@
#include <com/sun/star/task/XStatusIndicatorSupplier.hpp> #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp> #include <com/sun/star/task/XStatusIndicator.hpp>
#include <com/sun/star/util/thePathSettings.hpp>
#include "vbaapplication.hxx" #include "vbaapplication.hxx"
#include "vbadocument.hxx" #include "vbadocument.hxx"
#include "vbafilterpropsfromformat.hxx"
#include <sal/log.hxx> #include <sal/log.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
...@@ -39,6 +41,7 @@ ...@@ -39,6 +41,7 @@
#include <ooo/vba/word/WdWindowState.hpp> #include <ooo/vba/word/WdWindowState.hpp>
#include <ooo/vba/word/XApplicationOutgoing.hpp> #include <ooo/vba/word/XApplicationOutgoing.hpp>
#include <ooo/vba/word/XBookmarks.hpp> #include <ooo/vba/word/XBookmarks.hpp>
#include <comphelper/processfactory.hxx>
#include <basic/sbuno.hxx> #include <basic/sbuno.hxx>
#include <editeng/acorrcfg.hxx> #include <editeng/acorrcfg.hxx>
#include "wordvbahelper.hxx" #include "wordvbahelper.hxx"
...@@ -46,6 +49,7 @@ ...@@ -46,6 +49,7 @@
#include <swdll.hxx> #include <swdll.hxx>
#include <swmodule.hxx> #include <swmodule.hxx>
#include "vbalistgalleries.hxx" #include "vbalistgalleries.hxx"
#include <tools/urlobj.hxx>
using namespace ::ooo; using namespace ::ooo;
using namespace ::ooo::vba; using namespace ::ooo::vba;
...@@ -78,6 +82,17 @@ public: ...@@ -78,6 +82,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 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 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 FileClose( const css::uno::Any& Save ) override;
virtual void SAL_CALL ToolsOptionsView( const css::uno::Any& DraftFont, virtual void SAL_CALL ToolsOptionsView( const css::uno::Any& DraftFont,
const css::uno::Any& WrapToWindow, const css::uno::Any& WrapToWindow,
...@@ -550,6 +565,79 @@ SwWordBasic::FileSave() ...@@ -550,6 +565,79 @@ SwWordBasic::FileSave()
dispatchRequests(xModel,".uno:Save"); dispatchRequests(xModel,".uno:Save");
} }
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*/ )
{
SAL_INFO("sw.vba", "WordBasic.FileSaveAs(Name:=" << Name << ",Format:=" << Format << ")");
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 void SAL_CALL
SwWordBasic::FileClose( const css::uno::Any& Save ) SwWordBasic::FileClose( const css::uno::Any& Save )
{ {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <sal/log.hxx> #include <sal/log.hxx>
#include "service.hxx" #include "service.hxx"
#include "vbafilterpropsfromformat.hxx"
#include "vbadocument.hxx" #include "vbadocument.hxx"
#include "vbarange.hxx" #include "vbarange.hxx"
#include "vbarangehelper.hxx" #include "vbarangehelper.hxx"
...@@ -456,53 +457,6 @@ SwVbaDocument::Frames( const uno::Any& index ) ...@@ -456,53 +457,6 @@ SwVbaDocument::Frames( const uno::Any& index )
return uno::makeAny( xCol ); 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 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*/ ) 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*/ )
{ {
......
/* -*- 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment