oovbaapi/ooo/vba/excel/XApplication.idl | 1 sc/qa/extras/testdocuments/VariousTestMacros.xlsm |binary sc/qa/extras/vba-macro-test.cxx | 189 ++++++++++++++++++++++ sc/source/ui/vba/vbaapplication.cxx | 10 + sc/source/ui/vba/vbaapplication.hxx | 2 5 files changed, 202 insertions(+)
New commits: commit 58d74724631425b083c4bd3d316a0a4bc1af4eb3 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Jan 26 16:54:12 2022 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Jan 31 03:45:43 2022 +0100 vba: add tests for scrolling, range selecting, print area This adds various tests involving scrolling to a particular cell in the document, selecting whole ranges or ranges o filled cells and setting the print area. VBA functions: ActiveWindow.ScrollColumn ActiveWindow.ScrollRow Selection Selection.End(xlToRight) ActiveSheet.PageSetup.PrintArea Change-Id: Iacde9c513b41571e98234c12cc3b42a16de4b833 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129014 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 9a46a203515779ae40b7cfac36dbc22990e23290) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129020 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index 174e2e7229b6..b256eb373036 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -21,6 +21,8 @@ #include <scitems.hxx> #include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XPrintAreas.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> using namespace css; @@ -48,13 +50,21 @@ public: void testSimpleCopyAndPaste(); void testMultiDocumentCopyAndPaste(); void testSheetAndColumnSelectAndHide(); + void testPrintArea(); + void testSelectAllChaged(); + void testRangeSelect(); void testWindowState(); + void testScroll(); CPPUNIT_TEST_SUITE(VBAMacroTest); CPPUNIT_TEST(testSimpleCopyAndPaste); CPPUNIT_TEST(testMultiDocumentCopyAndPaste); CPPUNIT_TEST(testSheetAndColumnSelectAndHide); + CPPUNIT_TEST(testPrintArea); + CPPUNIT_TEST(testSelectAllChaged); + CPPUNIT_TEST(testRangeSelect); CPPUNIT_TEST(testWindowState); + CPPUNIT_TEST(testScroll); CPPUNIT_TEST_SUITE_END(); }; @@ -221,6 +231,126 @@ void VBAMacroTest::testSheetAndColumnSelectAndHide() CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); } +void VBAMacroTest::testPrintArea() +{ + // Sets the print area to A1:B5 + // ActiveSheet.PageSetup.PrintArea = "$A$1:$B$5" + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XPrintAreas> xPrintAreas(xSheet, uno::UNO_QUERY_THROW); + + { + const uno::Sequence<table::CellRangeAddress> aSequence = xPrintAreas->getPrintAreas(); + CPPUNIT_ASSERT_EQUAL(false, aSequence.hasElements()); + } + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testPrintArea?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + { + const uno::Sequence<table::CellRangeAddress> aSequence = xPrintAreas->getPrintAreas(); + CPPUNIT_ASSERT_EQUAL(true, aSequence.hasElements()); + } +} + +void VBAMacroTest::testSelectAllChaged() +{ + // Columns("A:A").Select + // Range(Selection, Selection.End(xlToRight)).Select + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& pViewData = pView->GetViewData(); + + { + ScRange aRange; + pViewData.GetMarkData().GetMarkArea(aRange); + CPPUNIT_ASSERT_EQUAL(ScRange(), aRange); + } + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testSelectAll?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + { + ScRange aRange; + pViewData.GetMarkData().GetMarkArea(aRange); + // A1:E1048576 + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 4, MAXROW, 0), aRange); + } +} + +void VBAMacroTest::testRangeSelect() +{ + // Range("B2").Select + // Range(Selection, Selection.End(xlToRight)).Select + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& pViewData = pView->GetViewData(); + + { + ScRange aRange; + pViewData.GetMarkData().GetMarkArea(aRange); + CPPUNIT_ASSERT_EQUAL(ScRange(), aRange); + } + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testRangeSelect?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + { + ScRange aRange; + pViewData.GetMarkData().GetMarkArea(aRange); + // B2:E5 + CPPUNIT_ASSERT_EQUAL(ScRange(1, 1, 0, 4, 1, 0), aRange); + } +} + void VBAMacroTest::testWindowState() { // Application.WindowState = xlMinimized @@ -242,6 +372,42 @@ void VBAMacroTest::testWindowState() aParams, aRet, aOutParamIndex, aOutParam); } +void VBAMacroTest::testScroll() +{ + // ActiveWindow.ScrollColumn = 30 + // ActiveWindow.ScrollRow = 100 + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& rViewData = pView->GetViewData(); + + CPPUNIT_ASSERT_EQUAL(ScSplitPos::SC_SPLIT_BOTTOMLEFT, rViewData.GetActivePart()); + CPPUNIT_ASSERT_EQUAL(SCCOL(0), rViewData.GetPosX(ScHSplitPos::SC_SPLIT_LEFT)); + CPPUNIT_ASSERT_EQUAL(SCROW(0), rViewData.GetPosY(ScVSplitPos::SC_SPLIT_BOTTOM)); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testScroll?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT_EQUAL(ScSplitPos::SC_SPLIT_BOTTOMLEFT, rViewData.GetActivePart()); + CPPUNIT_ASSERT_EQUAL(SCCOL(29), rViewData.GetPosX(ScHSplitPos::SC_SPLIT_LEFT)); + CPPUNIT_ASSERT_EQUAL(SCROW(99), rViewData.GetPosY(ScVSplitPos::SC_SPLIT_BOTTOM)); +} + CPPUNIT_TEST_SUITE_REGISTRATION(VBAMacroTest); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit b0999355c9314125a233ef386f590faf025dc97e Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Jan 26 16:50:41 2022 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Jan 31 03:45:32 2022 +0100 vba: add support for Application.WindowState + test This just delegates the get/set calls to ActiveWindow.WindowState which is already supported, but calling it directly on Application is also possible. Change-Id: Ibf6f55581a5c66a47ec4dd21cc8d0fe3558330ac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129013 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 93806a2831c93154981e3a6ef933270d0d5a6021) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129019 Reviewed-by: Luboš Luňák <l.lu...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/oovbaapi/ooo/vba/excel/XApplication.idl b/oovbaapi/ooo/vba/excel/XApplication.idl index b1bcf46336be..ab6f79655696 100644 --- a/oovbaapi/ooo/vba/excel/XApplication.idl +++ b/oovbaapi/ooo/vba/excel/XApplication.idl @@ -47,6 +47,7 @@ interface XApplication [attribute] boolean DisplayFormulaBar; [attribute] any CutCopyMode; [attribute] any StatusBar; + [attribute] any WindowState; [attribute] long Cursor; [attribute] boolean EnableEvents; [attribute] boolean EnableCancelKey; diff --git a/sc/qa/extras/testdocuments/VariousTestMacros.xlsm b/sc/qa/extras/testdocuments/VariousTestMacros.xlsm new file mode 100644 index 000000000000..455dad654eea Binary files /dev/null and b/sc/qa/extras/testdocuments/VariousTestMacros.xlsm differ diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index 532e47d14ad5..174e2e7229b6 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -48,11 +48,13 @@ public: void testSimpleCopyAndPaste(); void testMultiDocumentCopyAndPaste(); void testSheetAndColumnSelectAndHide(); + void testWindowState(); CPPUNIT_TEST_SUITE(VBAMacroTest); CPPUNIT_TEST(testSimpleCopyAndPaste); CPPUNIT_TEST(testMultiDocumentCopyAndPaste); CPPUNIT_TEST(testSheetAndColumnSelectAndHide); + CPPUNIT_TEST(testWindowState); CPPUNIT_TEST_SUITE_END(); }; @@ -219,6 +221,27 @@ void VBAMacroTest::testSheetAndColumnSelectAndHide() CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); } +void VBAMacroTest::testWindowState() +{ + // Application.WindowState = xlMinimized + // Application.WindowState = xlMaximized + // Application.WindowState = xlNormal + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testWindowState?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); +} + CPPUNIT_TEST_SUITE_REGISTRATION(VBAMacroTest); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index 0fd425c15cf6..0ec78418bb31 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -483,6 +483,16 @@ ScVbaApplication::getStatusBar() return uno::makeAny( !getDisplayStatusBar() ); } +css::uno::Any SAL_CALL ScVbaApplication::getWindowState() +{ + return getActiveWindow()->getWindowState(); +} + +void SAL_CALL ScVbaApplication::setWindowState(const css::uno::Any& rWindowState) +{ + getActiveWindow()->setWindowState(rWindowState); +} + void SAL_CALL ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) { diff --git a/sc/source/ui/vba/vbaapplication.hxx b/sc/source/ui/vba/vbaapplication.hxx index 9a7eb8328363..d5edff95a849 100644 --- a/sc/source/ui/vba/vbaapplication.hxx +++ b/sc/source/ui/vba/vbaapplication.hxx @@ -110,6 +110,8 @@ public: virtual void SAL_CALL setCutCopyMode( const css::uno::Any& _cutcopymode ) override; virtual css::uno::Any SAL_CALL getStatusBar() override; virtual void SAL_CALL setStatusBar( const css::uno::Any& _statusbar ) override; + virtual css::uno::Any SAL_CALL getWindowState() override; + virtual void SAL_CALL setWindowState(const css::uno::Any& rWindowState) override; virtual ::sal_Int32 SAL_CALL getCursor() override; virtual void SAL_CALL setCursor( ::sal_Int32 _cursor ) override; virtual void SAL_CALL OnKey( const OUString& Key, const css::uno::Any& Procedure ) override;