include/vbahelper/vbahelper.hxx | 4 ++++ oovbaapi/ooo/vba/word/XWordBasic.idl | 1 + sw/qa/core/data/docm/testVBA.docm |binary sw/source/ui/vba/vbawordbasic.cxx | 13 +++++++++++++ sw/source/ui/vba/vbawordbasic.hxx | 1 + vbahelper/source/vbahelper/vbahelper.cxx | 21 +++++++++++++++++++++ 6 files changed, 40 insertions(+)
New commits: commit 4f355ba5dee253c5ffc12fa8cc20f2ddf96e8b52 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Thu Oct 13 17:22:52 2022 -0400 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Oct 24 15:05:47 2022 +0200 sw vba: add WordBasic.MsgBox The unit test just consists of adding a "WordBasic.MsgBox()" to the vba code in testVBA.docm. make CppunitTest_sw_macros_test or just open the file manually for an easy-to-run experience. Cherry-pick of 55628d6b258f77eac8a34a1a8f6bbcbf09fd97cc Change-Id: I38edfee42649fcc85f0f535a2c9861c45038fa0e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141347 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141595 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/include/vbahelper/vbahelper.hxx b/include/vbahelper/vbahelper.hxx index fd4549cf99a8..bf8998755baa 100644 --- a/include/vbahelper/vbahelper.hxx +++ b/include/vbahelper/vbahelper.hxx @@ -26,6 +26,7 @@ #include <com/sun/star/uno/Any.hxx> #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Sequence.hxx> +#include <basic/sbxmeth.hxx> #include <rtl/ustring.hxx> #include <sal/types.h> #include <tools/color.hxx> @@ -134,6 +135,9 @@ namespace ooo::vba VBAHELPER_DLLPUBLIC bool setPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue ); VBAHELPER_DLLPUBLIC void setOrAppendPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue ); + VBAHELPER_DLLPUBLIC bool executeRunTimeLibrary(const std::u16string_view& rSbRtl_command, + SbxArray* pParameters); + class VBAHELPER_DLLPUBLIC Millimeter { //Factor to translate between points and hundredths of millimeters: diff --git a/oovbaapi/ooo/vba/word/XWordBasic.idl b/oovbaapi/ooo/vba/word/XWordBasic.idl index 124b0809234d..7a4d8881049d 100644 --- a/oovbaapi/ooo/vba/word/XWordBasic.idl +++ b/oovbaapi/ooo/vba/word/XWordBasic.idl @@ -44,6 +44,7 @@ interface XWordBasic any DocMaximize( [in] any State ); void AppShow( [in] any WindowName ); any AppCount(); + void MsgBox( [in] string Prompt ); void ScreenUpdating( [in] /*optional*/ any On ); }; diff --git a/sw/qa/core/data/docm/testVBA.docm b/sw/qa/core/data/docm/testVBA.docm index c02e353c3c3e..a2609feb6cd0 100644 Binary files a/sw/qa/core/data/docm/testVBA.docm and b/sw/qa/core/data/docm/testVBA.docm differ diff --git a/sw/source/ui/vba/vbawordbasic.cxx b/sw/source/ui/vba/vbawordbasic.cxx index ae59cf245f55..f08ed4e0daa8 100644 --- a/sw/source/ui/vba/vbawordbasic.cxx +++ b/sw/source/ui/vba/vbawordbasic.cxx @@ -22,6 +22,8 @@ #include "vbamailmerge.hxx" #include "vbawordbasic.hxx" +#include <basic/sbx.hxx> +#include <basic/sbxvar.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> #include <osl/file.hxx> @@ -242,6 +244,17 @@ css::uno::Any SAL_CALL SwWordBasic::AppCount() return css::uno::Any(sal_Int32(2)); } +void SAL_CALL SwWordBasic::MsgBox(const OUString& sPrompt) +{ + SbxArrayRef pArgs = new SbxArray; + SbxVariable* pVar = new SbxVariable(); + pVar->PutString(sPrompt); + pArgs->Put(pVar, 1); + + if (!executeRunTimeLibrary(u"MsgBox", pArgs.get())) + SAL_WARN("sw.vba", "failed to execute runtime library function MsgBox (" << sPrompt << ")"); +} + void SAL_CALL SwWordBasic::ScreenUpdating(const uno::Any& On) { sal_Int32 nOn; diff --git a/sw/source/ui/vba/vbawordbasic.hxx b/sw/source/ui/vba/vbawordbasic.hxx index 57b3c735f1df..8c63bee3619b 100644 --- a/sw/source/ui/vba/vbawordbasic.hxx +++ b/sw/source/ui/vba/vbawordbasic.hxx @@ -74,6 +74,7 @@ public: virtual css::uno::Any SAL_CALL DocMaximize(const css::uno::Any& State) override; virtual void SAL_CALL AppShow(const css::uno::Any& WindowName) override; virtual css::uno::Any SAL_CALL AppCount() override; + virtual void SAL_CALL MsgBox(const OUString& sPrompt) override; virtual void SAL_CALL ScreenUpdating(const css::uno::Any& On) override; }; diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx index 25da3beca4d4..195bbcca7d53 100644 --- a/vbahelper/source/vbahelper/vbahelper.cxx +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -757,6 +757,27 @@ void setOrAppendPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, con pProp[ nLength ].Value = aValue; } +bool executeRunTimeLibrary(const std::u16string_view& rSbRtl_command, SbxArray* pParameters) +{ + StarBASIC* pBasic = dynamic_cast< StarBASIC* >(StarBASIC::GetActiveModule()->GetParent()); + if (!pBasic) + return false; + + SbxObject* pRunTimeLibrary = pBasic->GetRtl(); + if (!pRunTimeLibrary) + return false; + + SbxVariable* pFound = pRunTimeLibrary->Find(OUString(rSbRtl_command), SbxClassType::Method); + SbxMethod* pMethod = dynamic_cast<SbxMethod*>(pFound); + if (!pMethod) + return false; + + pMethod->SetParameters(pParameters); + // Believe it or not, this actually runs the command + pMethod->Broadcast(SfxHintId::BasicDataWanted); + return true; +} + // ====UserFormGeomentryHelper==== UserFormGeometryHelper::UserFormGeometryHelper(