oovbaapi/ooo/vba/excel/XApplication.idl | 1 sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm |binary sc/qa/extras/testdocuments/VariousTestMacros.xlsm |binary sc/qa/extras/vba-macro-test.cxx | 101 ++++++++++++ sc/source/ui/vba/vbaapplication.cxx | 10 + sc/source/ui/vba/vbaapplication.hxx | 2 6 files changed, 114 insertions(+)
New commits: commit 93806a2831c93154981e3a6ef933270d0d5a6021 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Jan 26 16:50:41 2022 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Jan 27 07:38:09 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> 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 89639ceb1863..51d8c36cbded 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -48,6 +48,8 @@ public: void testSimpleCopyAndPaste(); void testMultiDocumentCopyAndPaste(); void testSheetAndColumnSelectAndHide(); + void testWindowState(); + void testVba(); void testTdf107885(); void testTdf131562(); @@ -58,6 +60,7 @@ public: CPPUNIT_TEST(testSimpleCopyAndPaste); CPPUNIT_TEST(testMultiDocumentCopyAndPaste); CPPUNIT_TEST(testSheetAndColumnSelectAndHide); + CPPUNIT_TEST(testWindowState); CPPUNIT_TEST(testVba); CPPUNIT_TEST(testTdf107885); @@ -230,6 +233,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); +} + void VBAMacroTest::testVba() { TestMacroInfo testInfo[] = { diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index f518f4a82293..f11ee6f21bbe 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -488,6 +488,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 09d2b02d3b59..db9c91cdd677 100644 --- a/sc/source/ui/vba/vbaapplication.hxx +++ b/sc/source/ui/vba/vbaapplication.hxx @@ -109,6 +109,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; commit cfa4867b0b66b0d4fb3aee52ca40d380e50de9ef Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Jan 25 16:14:32 2022 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Jan 27 07:37:55 2022 +0100 vba: test for selcting and hiding columns from a VBA Macro Change-Id: Ib954a98e3cf91253c416f358a114bf6b6eb549b3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129012 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm new file mode 100644 index 000000000000..684480c3ff04 Binary files /dev/null and b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm differ diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index b4736fc689cc..89639ceb1863 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -12,6 +12,8 @@ #include <osl/file.hxx> #include <sal/log.hxx> #include <vcl/svapp.hxx> +#include <viewdata.hxx> +#include <tabvwsh.hxx> #include <docsh.hxx> #include <document.hxx> @@ -45,6 +47,7 @@ public: void testSimpleCopyAndPaste(); void testMultiDocumentCopyAndPaste(); + void testSheetAndColumnSelectAndHide(); void testVba(); void testTdf107885(); void testTdf131562(); @@ -54,6 +57,8 @@ public: CPPUNIT_TEST_SUITE(VBAMacroTest); CPPUNIT_TEST(testSimpleCopyAndPaste); CPPUNIT_TEST(testMultiDocumentCopyAndPaste); + CPPUNIT_TEST(testSheetAndColumnSelectAndHide); + CPPUNIT_TEST(testVba); CPPUNIT_TEST(testTdf107885); CPPUNIT_TEST(testTdf131562); @@ -153,6 +158,78 @@ void VBAMacroTest::testMultiDocumentCopyAndPaste() CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 3, 0))); } +void VBAMacroTest::testSheetAndColumnSelectAndHide() +{ + OUString aFileName; + createFileURL(u"SheetAndColumnSelectAndHide.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); + ScDocument& rDoc = pDocSh->GetDocument(); + + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& rViewData = pView->GetViewData(); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 1)); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 2)); + + 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.testHide?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 1)); + CPPUNIT_ASSERT(rDoc.ColHidden(1, 1)); + CPPUNIT_ASSERT(rDoc.ColHidden(2, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 1)); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 2)); + CPPUNIT_ASSERT(rDoc.ColHidden(2, 2)); + CPPUNIT_ASSERT(rDoc.ColHidden(3, 2)); + CPPUNIT_ASSERT(rDoc.ColHidden(4, 2)); + + CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testUnhide?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 1)); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 2)); + + CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); +} + void VBAMacroTest::testVba() { TestMacroInfo testInfo[] = {