From 79d7b69076feddaafdcde34fc747d83371464239 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Tue, 12 Jun 2018 20:01:41 +0300 Subject: Add a MailMerge class and object to the Writer VBA API Just a dummy implementation so far. Needed because customer Automation client software seems to access it (through the very obsolete WordBasic API, even). It remains to be seen whether any actual mail merge functionality is needed. Change-Id: I40419da544f61173e4bcf759b887997c7f233b02 Reviewed-on: https://gerrit.libreoffice.org/55731 Reviewed-by: Andras Timar Tested-by: Andras Timar --- sw/source/ui/vba/vbaapplication.cxx | 50 ++++++++++++++++++++++++++++++ sw/source/ui/vba/vbaapplication.hxx | 3 +- sw/source/ui/vba/vbadocument.cxx | 6 ++++ sw/source/ui/vba/vbadocument.hxx | 2 ++ sw/source/ui/vba/vbamailmerge.cxx | 61 +++++++++++++++++++++++++++++++++++++ sw/source/ui/vba/vbamailmerge.hxx | 55 +++++++++++++++++++++++++++++++++ 6 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 sw/source/ui/vba/vbamailmerge.cxx create mode 100644 sw/source/ui/vba/vbamailmerge.hxx (limited to 'sw/source/ui') diff --git a/sw/source/ui/vba/vbaapplication.cxx b/sw/source/ui/vba/vbaapplication.cxx index 441f1b6841af..e4f0363ede4b 100644 --- a/sw/source/ui/vba/vbaapplication.cxx +++ b/sw/source/ui/vba/vbaapplication.cxx @@ -30,6 +30,7 @@ #include "vbaselection.hxx" #include "vbadocuments.hxx" #include "vbaaddins.hxx" +#include "vbamailmerge.hxx" #include "vbadialogs.hxx" #include #include @@ -70,9 +71,20 @@ public: SwWordBasic( SwVbaApplication* pApp ); // XWordBasic + virtual sal_Int32 SAL_CALL getMailMergeMainDocumentType() override; + virtual void SAL_CALL setMailMergeMainDocumentType( sal_Int32 _mailmergemaindocumenttype ) 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 OUString SAL_CALL WindowName() override; virtual sal_Bool SAL_CALL ExistingBookmark( const OUString& Name ) override; + virtual void SAL_CALL MailMergeOpenDataSource(const OUString& Name, const css::uno::Any& Format, + const css::uno::Any& ConfirmConversions, const css::uno::Any& ReadOnly, + const css::uno::Any& LinkToSource, const css::uno::Any& AddToRecentFiles, + const css::uno::Any& PasswordDocument, const css::uno::Any& PasswordTemplate, + const css::uno::Any& Revert, const css::uno::Any& WritePasswordDocument, + const css::uno::Any& WritePasswordTemplate, const css::uno::Any& Connection, + const css::uno::Any& SQLStatement, const css::uno::Any& SQLStatement1, + const css::uno::Any& OpenExclusive, const css::uno::Any& SubType) override; }; SwVbaApplication::SwVbaApplication( uno::Reference& xContext ): @@ -127,6 +139,12 @@ SwVbaApplication::getActiveSwVbaWindow() return new SwVbaWindow( uno::Reference< XHelperInterface >(), mxContext, xModel, xController ); } +uno::Reference< css::uno::XComponentContext > +SwVbaApplication::getContext() +{ + return mxContext; +} + uno::Reference< word::XWindow > SAL_CALL SwVbaApplication::getActiveWindow() { @@ -450,7 +468,20 @@ SwWordBasic::SwWordBasic( SwVbaApplication* pApp ) : { } +// XWordBasic +sal_Int32 SAL_CALL +SwWordBasic::getMailMergeMainDocumentType() +{ + return SwVbaMailMerge::get( mpApp->getParent(), mpApp->getContext() )->getMainDocumentType(); +} + // XWordBasic +void SAL_CALL +SwWordBasic::setMailMergeMainDocumentType( sal_Int32 _mailmergemaindocumenttype ) +{ + SwVbaMailMerge::get( mpApp->getParent(), mpApp->getContext() )->setMainDocumentType( _mailmergemaindocumenttype ); +} + void SAL_CALL SwWordBasic::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 ) { @@ -475,4 +506,23 @@ SwWordBasic::ExistingBookmark( const OUString& Name ) return xBookmarks.is() && xBookmarks->Exists( Name ); } +void SAL_CALL +SwWordBasic::MailMergeOpenDataSource( const OUString& Name, const css::uno::Any& Format, + const css::uno::Any& ConfirmConversions, const css::uno::Any& ReadOnly, + const css::uno::Any& LinkToSource, const css::uno::Any& AddToRecentFiles, + const css::uno::Any& PasswordDocument, const css::uno::Any& PasswordTemplate, + const css::uno::Any& Revert, const css::uno::Any& WritePasswordDocument, + const css::uno::Any& WritePasswordTemplate, const css::uno::Any& Connection, + const css::uno::Any& SQLStatement, const css::uno::Any& SQLStatement1, + const css::uno::Any& OpenExclusive, const css::uno::Any& SubType ) +{ + mpApp->getActiveDocument()->getMailMerge()->OpenDataSource( Name, Format, ConfirmConversions, ReadOnly, + LinkToSource, AddToRecentFiles, + PasswordDocument, PasswordTemplate, + Revert, WritePasswordDocument, + WritePasswordTemplate, Connection, + SQLStatement, SQLStatement1, + OpenExclusive, SubType ); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/vba/vbaapplication.hxx b/sw/source/ui/vba/vbaapplication.hxx index 13d18423143e..d1a19abb2e28 100644 --- a/sw/source/ui/vba/vbaapplication.hxx +++ b/sw/source/ui/vba/vbaapplication.hxx @@ -52,13 +52,14 @@ class SwVbaApplication : public SwVbaApplication_BASE std::vector> mvSinks; public: - explicit SwVbaApplication( css::uno::Reference< css::uno::XComponentContext >& m_xContext ); + explicit SwVbaApplication( css::uno::Reference< css::uno::XComponentContext >& xContext ); virtual ~SwVbaApplication() override; sal_uInt32 AddSink( const css::uno::Reference< ooo::vba::XSink >& xSink ); void RemoveSink( sal_uInt32 nNumber ); SwVbaWindow* getActiveSwVbaWindow(); + css::uno::Reference< css::uno::XComponentContext > getContext(); // XApplication virtual OUString SAL_CALL getName() override; diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index aa4849a6ab8e..d35d32c21718 100644 --- a/sw/source/ui/vba/vbadocument.cxx +++ b/sw/source/ui/vba/vbadocument.cxx @@ -25,6 +25,7 @@ #include "vbarangehelper.hxx" #include "vbadocumentproperties.hxx" #include "vbabookmarks.hxx" +#include "vbamailmerge.hxx" #include "vbavariables.hxx" #include #include @@ -399,6 +400,11 @@ void SAL_CALL SwVbaDocument::setConsecutiveHyphensLimit( ::sal_Int32 _consecutiv xParaProps->setPropertyValue("ParaHyphenationMaxHyphens", uno::makeAny( nHyphensLimit ) ); } +uno::Reference< ooo::vba::word::XMailMerge > SAL_CALL SwVbaDocument::getMailMerge() +{ + return uno::Reference< ooo::vba::word::XMailMerge >(SwVbaMailMerge::get(mxParent, mxContext).get()); +} + void SAL_CALL SwVbaDocument::Protect( ::sal_Int32 /*Type*/, const uno::Any& /*NOReset*/, const uno::Any& /*Password*/, const uno::Any& /*UseIRM*/, const uno::Any& /*EnforceStyleLock*/ ) { // Seems not support in Writer diff --git a/sw/source/ui/vba/vbadocument.hxx b/sw/source/ui/vba/vbadocument.hxx index 19ca2eed8caa..dee256ef63d4 100644 --- a/sw/source/ui/vba/vbadocument.hxx +++ b/sw/source/ui/vba/vbadocument.hxx @@ -79,6 +79,8 @@ public: virtual void SAL_CALL setHyphenationZone( ::sal_Int32 _hyphenationzone ) override; virtual ::sal_Int32 SAL_CALL getConsecutiveHyphensLimit() override; virtual void SAL_CALL setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit ) override; + virtual css::uno::Reference< ooo::vba::word::XMailMerge > SAL_CALL getMailMerge() override; + using VbaDocumentBase::Protect; virtual void SAL_CALL Protect( ::sal_Int32 Type, const css::uno::Any& NOReset, const css::uno::Any& Password, const css::uno::Any& UseIRM, const css::uno::Any& EnforceStyleLock ) override; virtual void SAL_CALL PrintOut( const css::uno::Any& Background, const css::uno::Any& Append, const css::uno::Any& Range, const css::uno::Any& OutputFileName, const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Item, const css::uno::Any& Copies, const css::uno::Any& Pages, const css::uno::Any& PageType, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& FileName, const css::uno::Any& ActivePrinterMacGX, const css::uno::Any& ManualDuplexPrint, const css::uno::Any& PrintZoomColumn, const css::uno::Any& PrintZoomRow, const css::uno::Any& PrintZoomPaperWidth, const css::uno::Any& PrintZoomPaperHeight ) override; diff --git a/sw/source/ui/vba/vbamailmerge.cxx b/sw/source/ui/vba/vbamailmerge.cxx new file mode 100644 index 000000000000..59711d7de8a8 --- /dev/null +++ b/sw/source/ui/vba/vbamailmerge.cxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column:100 -*- */ +/* + * 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/. + */ + +#include "vbamailmerge.hxx" + +#include + +SwVbaMailMerge::SwVbaMailMerge(const css::uno::Reference& xParent, + const css::uno::Reference& xContext) + : SwVbaMailMerge_BASE(xParent, xContext) + , m_nMainDocType(ooo::vba::word::WdMailMergeMainDocType::wdNotAMergeDocument) +{ +} + +SwVbaMailMerge::~SwVbaMailMerge() {} + +rtl::Reference +SwVbaMailMerge::get(const css::uno::Reference& xParent, + const css::uno::Reference& xContext) +{ + static rtl::Reference xInstance(new SwVbaMailMerge(xParent, xContext)); + + return xInstance; +} + +sal_Int32 SAL_CALL SwVbaMailMerge::getMainDocumentType() { return m_nMainDocType; } + +void SAL_CALL SwVbaMailMerge::setMainDocumentType(sal_Int32 _maindocumenttype) +{ + m_nMainDocType = _maindocumenttype; +} + +// Completely dummy, no-op. +void SAL_CALL SwVbaMailMerge::OpenDataSource( + const OUString&, const css::uno::Any&, const css::uno::Any&, const css::uno::Any&, + const css::uno::Any&, const css::uno::Any&, const css::uno::Any&, const css::uno::Any&, + const css::uno::Any&, const css::uno::Any&, const css::uno::Any&, const css::uno::Any&, + const css::uno::Any&, const css::uno::Any&, const css::uno::Any&, const css::uno::Any&) +{ +} + +OUString SwVbaMailMerge::getServiceImplName() { return OUString("SwVbaMailMerge"); } + +css::uno::Sequence SwVbaMailMerge::getServiceNames() +{ + static css::uno::Sequence aServiceNames; + if (aServiceNames.getLength() == 0) + { + aServiceNames.realloc(1); + aServiceNames[0] = "ooo.vba.word.MailMerge"; + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/vba/vbamailmerge.hxx b/sw/source/ui/vba/vbamailmerge.hxx new file mode 100644 index 000000000000..7718815da344 --- /dev/null +++ b/sw/source/ui/vba/vbamailmerge.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ +#ifndef INCLUDED_SW_SOURCE_UI_VBA_VBAMAILMERGE_HXX +#define INCLUDED_SW_SOURCE_UI_VBA_VBAMAILMERGE_HXX + +#include +#include +#include + +typedef InheritedHelperInterfaceWeakImpl SwVbaMailMerge_BASE; + +// Singleton class. Get the single instance using the get() method. + +class SwVbaMailMerge : public SwVbaMailMerge_BASE +{ + sal_Int32 m_nMainDocType; + + SwVbaMailMerge(const css::uno::Reference& xParent, + const css::uno::Reference& xContext); + +public: + virtual ~SwVbaMailMerge() override; + + static rtl::Reference + get(const css::uno::Reference& xParent, + const css::uno::Reference& xContext); + + // XMailMerge + virtual sal_Int32 SAL_CALL getMainDocumentType() override; + virtual void SAL_CALL setMainDocumentType(sal_Int32 _maindocumenttype) override; + + virtual void SAL_CALL + OpenDataSource(const OUString& Name, const css::uno::Any& Format, + const css::uno::Any& ConfirmConversions, const css::uno::Any& ReadOnly, + const css::uno::Any& LinkToSource, const css::uno::Any& AddToRecentFiles, + const css::uno::Any& PasswordDocument, const css::uno::Any& PasswordTemplate, + const css::uno::Any& Revert, const css::uno::Any& WritePasswordDocument, + const css::uno::Any& WritePasswordTemplate, const css::uno::Any& Connection, + const css::uno::Any& SQLStatement, const css::uno::Any& SQLStatement1, + const css::uno::Any& OpenExclusive, const css::uno::Any& SubType) override; + + // XHelperInterface + virtual OUString getServiceImplName() override; + virtual css::uno::Sequence getServiceNames() override; +}; + +#endif // INCLUDED_SW_SOURCE_UI_VBA_VBAMAILMERGE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3