sd/qa/unit/misc-tests.cxx | 42 +++++++++++++++++++++++++++++++++++++++++ sd/source/ui/view/drviews1.cxx | 3 ++ 2 files changed, 45 insertions(+)
New commits: commit 6b6849107562b258aa8858e94ff3c07160f07062 Author: Jim Raykowski <rayk...@gmail.com> AuthorDate: Sat Nov 25 15:14:04 2023 -0900 Commit: Jim Raykowski <rayk...@gmail.com> CommitDate: Mon Feb 5 20:38:18 2024 +0100 tdf#157117 sd: fix page switched to after last page is deleted Makes the new last page in the document be the page switched to after a page delete of the last page in the document. Before the patch, when the draw view has focus (not the slide sorter), deleting the last page in the document results in a switch to the first page. Change-Id: I8d3904e85254228e01d423f15312981d11fc9755 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159963 Tested-by: Jenkins Reviewed-by: Jim Raykowski <rayk...@gmail.com> diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx index 1bbf8364fd3e..342f720a6e6e 100644 --- a/sd/qa/unit/misc-tests.cxx +++ b/sd/qa/unit/misc-tests.cxx @@ -84,6 +84,7 @@ public: void testTdf136956(); void testTdf39519(); void testEncodedTableStyles(); + void testTdf157117(); CPPUNIT_TEST_SUITE(SdMiscTest); CPPUNIT_TEST(testTdf99396); @@ -107,6 +108,7 @@ public: CPPUNIT_TEST(testTdf136956); CPPUNIT_TEST(testTdf39519); CPPUNIT_TEST(testEncodedTableStyles); + CPPUNIT_TEST(testTdf157117); CPPUNIT_TEST_SUITE_END(); }; @@ -955,6 +957,46 @@ void SdMiscTest::testEncodedTableStyles() } } +void SdMiscTest::testTdf157117() +{ + createSdImpressDoc(); + SdXImpressDocument* pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pXImpressDocument); + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + + // insert two pages to make a total of 3 pages + dispatchCommand(mxComponent, ".uno:InsertPage", {}); + dispatchCommand(mxComponent, ".uno:InsertPage", {}); + + // assert the document has 3 standard pages + SdDrawDocument* pDocument = pXImpressDocument->GetDoc(); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pDocument->GetSdPageCount(PageKind::Standard)); + + // alternate page insert method + // uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); + // uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages(); + // xDrawPages->insertNewByIndex(0); + // xDrawPages->insertNewByIndex(0); + // CPPUNIT_ASSERT_EQUAL(xDrawPages->getCount(), 3); + + // move to the last page + dispatchCommand(mxComponent, ".uno:LastPage", {}); + + SdPage* pPage = pViewShell->GetActualPage(); + auto nPageNum = pPage->GetPageNum(); + // assert move to last page + CPPUNIT_ASSERT_EQUAL(2, (nPageNum - 1) / 2); + + // delete the last page + dispatchCommand(mxComponent, ".uno:DeletePage", {}); + pPage = pViewShell->GetActualPage(); + nPageNum = pPage->GetPageNum(); + + // Check that the new last page is moved to. Before, the first page was always moved to when + // the last page was deleted. + CPPUNIT_ASSERT_EQUAL(1, (nPageNum - 1) / 2); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/source/ui/view/drviews1.cxx b/sd/source/ui/view/drviews1.cxx index a48ab7a11546..a481e944e7c6 100644 --- a/sd/source/ui/view/drviews1.cxx +++ b/sd/source/ui/view/drviews1.cxx @@ -689,6 +689,9 @@ void DrawViewShell::ResetActualPage() sal_uInt16 nCurrentPageNum = maTabControl->GetPagePos(nCurrentPageId); sal_uInt16 nPageCount = (meEditMode == EditMode::Page)?GetDoc()->GetSdPageCount(mePageKind):GetDoc()->GetMasterSdPageCount(mePageKind); + if (nCurrentPageNum >= nPageCount) + nCurrentPageNum = nPageCount - 1; + if (meEditMode == EditMode::Page) {