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 <jluth@mail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
This commit is contained in:
Justin Luth
2022-10-13 17:22:52 -04:00
committed by Miklos Vajna
parent daa85533cf
commit 55628d6b25
6 changed files with 40 additions and 0 deletions

View File

@@ -26,6 +26,7 @@
#include <com/sun/star/uno/Any.hxx> #include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/Sequence.hxx>
#include <basic/sbxmeth.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <sal/types.h> #include <sal/types.h>
#include <tools/color.hxx> #include <tools/color.hxx>
@@ -131,6 +132,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 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 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 class VBAHELPER_DLLPUBLIC Millimeter
{ {
//Factor to translate between points and hundredths of millimeters: //Factor to translate between points and hundredths of millimeters:

View File

@@ -42,6 +42,7 @@ interface XWordBasic
any DocMaximize( [in] any State ); any DocMaximize( [in] any State );
void AppShow( [in] any WindowName ); void AppShow( [in] any WindowName );
any AppCount(); any AppCount();
void MsgBox( [in] string Prompt );
void ScreenUpdating( [in] /*optional*/ any On ); void ScreenUpdating( [in] /*optional*/ any On );
}; };

Binary file not shown.

View File

@@ -22,6 +22,8 @@
#include "vbamailmerge.hxx" #include "vbamailmerge.hxx"
#include "vbawordbasic.hxx" #include "vbawordbasic.hxx"
#include <basic/sbx.hxx>
#include <basic/sbxvar.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <comphelper/propertyvalue.hxx> #include <comphelper/propertyvalue.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
@@ -242,6 +244,17 @@ css::uno::Any SAL_CALL SwWordBasic::AppCount()
return css::uno::Any(sal_Int32(2)); 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) void SAL_CALL SwWordBasic::ScreenUpdating(const uno::Any& On)
{ {
sal_Int32 nOn; sal_Int32 nOn;

View File

@@ -86,6 +86,7 @@ public:
virtual css::uno::Any SAL_CALL DocMaximize(const css::uno::Any& State) override; 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 void SAL_CALL AppShow(const css::uno::Any& WindowName) override;
virtual css::uno::Any SAL_CALL AppCount() 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; virtual void SAL_CALL ScreenUpdating(const css::uno::Any& On) override;
}; };

View File

@@ -746,6 +746,27 @@ void setOrAppendPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, con
pProp[ nLength ].Value = aValue; 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==== // ====UserFormGeomentryHelper====
UserFormGeometryHelper::UserFormGeometryHelper( UserFormGeometryHelper::UserFormGeometryHelper(