summaryrefslogtreecommitdiff
path: root/sw/source/ui/misc/titlepage.cxx
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2020-12-28 17:15:06 +0300
committerMiklos Vajna <vmiklos@collabora.com>2021-01-21 09:20:16 +0100
commit22ee887346ef870fbf9b758fe2bcaa9aeae04a82 (patch)
treedbba96e2f8d9f150f3524652fc6a6afb4aee34a3 /sw/source/ui/misc/titlepage.cxx
parent47fbbdaf091ea0ec0fb692340ad11f0d4c0f2d5c (diff)
tdf#138907 sw TitlePageDlg: Goto correct (existing) page
If the starting page for the new Title pages is beyond the end of the document, then insert the new pages after the last page. Also, handle the "physical" blank pages which threw off calculations for Index pages. 1.) It was wrongly inserting before the last page. 2.) Cap InsertPosition() to document-end. 3.) An odd/even blank filler page would cause missing or mis-applied styles. NOTE: The wizard is still completely useless when adding pages, because GotoPage does not recognize that the document has inserted pages, and so it goes by pre-wizard page coordinates. This is just the first step in correcting the overall problem (which I don't know how to do). make UITest_writer_tests5 UITEST_TEST_NAME=\ titlePageWizard.tdf138907.test_tdf138907 Change-Id: Ie138c4ab3126bc6d3fae16028b41a80bda329f1c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108332 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source/ui/misc/titlepage.cxx')
-rw-r--r--sw/source/ui/misc/titlepage.cxx47
1 files changed, 35 insertions, 12 deletions
diff --git a/sw/source/ui/misc/titlepage.cxx b/sw/source/ui/misc/titlepage.cxx
index a05165fe063a..eb431a35d757 100644
--- a/sw/source/ui/misc/titlepage.cxx
+++ b/sw/source/ui/misc/titlepage.cxx
@@ -91,7 +91,33 @@ namespace
rSh.GetPageNumber(0, true, nPhyNum, nVirtNum, sDummy);
return nPhyNum;
}
+
+bool lcl_GotoPage(SwWrtShell& rSh, const sal_uInt16 nStartingPage, sal_uInt16 nOffset = 0)
+{
+ rSh.GotoPage(nStartingPage, /*bRecord=*/false);
+
+ sal_uInt16 nCurrentPage = lcl_GetCurrentPage(rSh);
+ // return false if at document end (unless that was the requested destination)
+ if (nCurrentPage == rSh.GetPageCnt())
+ return nCurrentPage == nStartingPage + nOffset;
+
+ if (nCurrentPage != nStartingPage)
+ {
+ assert(nStartingPage != 1 && "Physical page 1 couldn't be found/moved to?");
+ // Probably there is an auto-inserted blank page to handle odd/even, which Goto doesn't understand.
+ rSh.GotoPage(nStartingPage + 1, /*bRecord=*/false);
+
+ nCurrentPage = lcl_GetCurrentPage(rSh);
+ assert(nCurrentPage == nStartingPage + 1 && "Impossible, since unknown goes to last page");
+ if (nCurrentPage != nStartingPage + 1)
+ return false;
+ }
+ // Now that we have the correct starting point, move to the correct offset.
+ while (nOffset--)
+ rSh.SttNxtPg();
+ return true;
}
+} // namespace
/*
* Only include the Index page in the list if the page count implies one
@@ -113,8 +139,6 @@ void SwTitlePageDlg::FillList()
sal_uInt16 SwTitlePageDlg::GetInsertPosition() const
{
sal_uInt16 nPage = 1;
- // FIXME: If GetInsertPosition is greater than the current number of pages,
- // it needs to be reduced to page-count + 1.
if (m_xPageStartNF->get_sensitive())
nPage = m_xPageStartNF->get_value();
return nPage;
@@ -139,6 +163,7 @@ SwTitlePageDlg::SwTitlePageDlg(weld::Window *pParent)
m_xOkPB->connect_clicked(LINK(this, SwTitlePageDlg, OKHdl));
m_xRestartNumberingCB->connect_toggled(LINK(this, SwTitlePageDlg, RestartNumberingHdl));
m_xSetPageNumberCB->connect_toggled(LINK(this, SwTitlePageDlg, SetPageNumberHdl));
+ m_xPageStartNF->set_max(mrSh.GetPageCnt() + 1);
sal_uInt16 nSetPage = 1;
sal_uInt16 nResetPage = 1;
@@ -237,8 +262,6 @@ IMPL_LINK_NOARG(SwTitlePageDlg, EditHdl, weld::Button&, void)
IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
{
- // FIXME: This wizard is almost completely non-functional for inserting new pages.
-
lcl_PushCursor(mrSh);
mrSh.StartUndo();
@@ -253,17 +276,17 @@ IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
sal_uInt16 nNumTitlePages = m_xPageCountNF->get_value();
if (!m_xUseExistingPagesRB->get_active())
{
- // FIXME: If the starting page number is larger than the last page,
- // probably should add pages AFTER the last page, not before it.
- mrSh.GotoPage(GetInsertPosition(), false);
+ // Assuming that a failure to GotoPage means the end of the document,
+ // insert new pages after the last page.
+ if (!lcl_GotoPage(mrSh, GetInsertPosition()))
+ mrSh.EndPg();
// FIXME: These new pages cannot be accessed currently with GotoPage. It doesn't know they exist.
for (sal_uInt16 nI = 0; nI < nNumTitlePages; ++nI)
mrSh.InsertPageBreak();
}
- mrSh.GotoPage(GetInsertPosition(), false);
- mrSh.SetAttrItem(aTitleDesc);
- // FIXME: GotoPage is pointing to a page after the newly created index pages, so the wrong pages are getting Index style.
+ if (lcl_GotoPage(mrSh, GetInsertPosition()))
+ mrSh.SetAttrItem(aTitleDesc);
for (sal_uInt16 nI = 1; nI < nNumTitlePages; ++nI)
{
if (mrSh.SttNxtPg())
@@ -281,14 +304,14 @@ IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
{
sal_uInt16 nPgNo = m_xRestartNumberingCB->get_active() ? m_xRestartNumberingNF->get_value() : 0;
const SwPageDesc* pNewDesc = nNumTitlePages > 1 ? mpNormalDesc : nullptr;
- mrSh.GotoPage(GetInsertPosition() + nNumTitlePages, false);
+ lcl_GotoPage(mrSh, GetInsertPosition(), nNumTitlePages);
lcl_ChangePage(mrSh, nPgNo, pNewDesc);
}
mrSh.EndUndo();
lcl_PopCursor(mrSh);
if (!m_xUseExistingPagesRB->get_active())
- mrSh.GotoPage(GetInsertPosition(), false);
+ lcl_GotoPage(mrSh, GetInsertPosition());
m_xDialog->response(RET_OK);
}