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.
Change-Id: I38edfee42649fcc85f0f535a2c9861c45038fa0e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141347
Tested-by: Jenkins
Reviewed-by: Justin Luth <[email protected]>
Reviewed-by: Miklos Vajna <[email protected]>
diff --git a/include/vbahelper/vbahelper.hxx b/include/vbahelper/vbahelper.hxx
index 533d5e3..9be2b90 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>
@@ -131,6 +132,9 @@
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 66c867f..7cc1efe 100644
--- a/oovbaapi/ooo/vba/word/XWordBasic.idl
+++ b/oovbaapi/ooo/vba/word/XWordBasic.idl
@@ -42,6 +42,7 @@
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 c02e353..a2609fe 100644
--- a/sw/qa/core/data/docm/testVBA.docm
+++ b/sw/qa/core/data/docm/testVBA.docm
Binary files differ
diff --git a/sw/source/ui/vba/vbawordbasic.cxx b/sw/source/ui/vba/vbawordbasic.cxx
index ae59cf24..f08ed4e 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 @@
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 75f8a05..05589f0 100644
--- a/sw/source/ui/vba/vbawordbasic.hxx
+++ b/sw/source/ui/vba/vbawordbasic.hxx
@@ -86,6 +86,7 @@
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 4e71cb58..2722f62 100644
--- a/vbahelper/source/vbahelper/vbahelper.cxx
+++ b/vbahelper/source/vbahelper/vbahelper.cxx
@@ -746,6 +746,27 @@
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(