sw/source/uibase/shells/textfld.cxx | 55 +++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)
New commits: commit 4dfe107409f977b545f2ff5cda615ec12be2bf95 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Thu Apr 27 17:03:48 2023 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Thu May 18 17:56:39 2023 +0200 tdf#86630 sw page number wizard: allow wizard to be re-run This is a squashed commit including 47016a3374af6effb795ada4efa9fb682b566e25 Fix typo First delete what a previous run of the wizard inserted, then re-insert the page number. Change-Id: I1cbf1a7a40e71a13a06a174fd662eccfe8298e28 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151148 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151903 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 5f1f1e821573..f50918838c33 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -1047,10 +1047,24 @@ FIELD_INSERT: const size_t nPageDescIndex = rSh.GetCurPageDesc(); const SwPageDesc& rDesc = rSh.GetPageDesc(nPageDescIndex); + const bool bHeader = !pDlg->GetPageNumberPosition(); const bool bHeaderAlreadyOn = rDesc.GetMaster().GetHeader().IsActive(); const bool bFooterAlreadyOn = rDesc.GetMaster().GetFooter().IsActive(); const bool bIsSinglePage = rDesc.GetFollow() != &rDesc; const size_t nMirrorPagesNeeded = rDesc.IsFirstShared() ? 2 : 3; + const OUString sBookmarkName = OUString::Concat("PageNumWizard_") + + (bHeader ? "HEADER" : "FOOTER") + "_" + rDesc.GetName(); + IDocumentMarkAccess& rIDMA = *rSh.getIDocumentMarkAccess(); + + // Allow wizard to be re-run: delete previously wizard-inserted page number. + // Try before creating non-shared header: avoid copying ODD bookmark onto EVEN page. + IDocumentMarkAccess::const_iterator_t ppMark = rIDMA.findMark( + sBookmarkName + OUString::number(rSh.GetVirtPageNum())); + if (ppMark != rIDMA.getAllMarksEnd() && *ppMark) + { + SwPaM aDeleteOldPageNum((*ppMark)->GetMarkStart(), (*ppMark)->GetMarkEnd()); + rDoc->getIDocumentContentOperations().DeleteAndJoin(aDeleteOldPageNum); + } SvxPageItem aPageItem(SID_ATTR_PAGE); aPageItem.SetNumType(pDlg->GetPageNumberType()); @@ -1065,7 +1079,6 @@ FIELD_INSERT: { &aPageItem }); // Insert header/footer - const bool bHeader = !pDlg->GetPageNumberPosition(); if (bHeader && !bHeaderAlreadyOn) rSh.ChangeHeaderOrFooter(rDesc.GetName(), bHeader, /*On=*/true, /*Warn=*/false); else if (!bHeader && !bFooterAlreadyOn) @@ -1142,6 +1155,15 @@ FIELD_INSERT: assert(bInHF && "shouldn't have a problem going to text when no mirroring"); } + // Allow wizard to be re-run: delete previously wizard-inserted page number. + // Now that the cursor may have moved to a different page, try delete again. + ppMark = rIDMA.findMark(sBookmarkName + OUString::number(rSh.GetVirtPageNum())); + if (ppMark != rIDMA.getAllMarksEnd() && *ppMark) + { + SwPaM aDeleteOldPageNum((*ppMark)->GetMarkStart(), (*ppMark)->GetMarkEnd()); + rDoc->getIDocumentContentOperations().DeleteAndJoin(aDeleteOldPageNum); + } + SwTextNode* pTextNode = rSh.GetCursor()->GetPoint()->GetNode().GetTextNode(); // Insert new line if there is already text in header/footer @@ -1185,11 +1207,27 @@ FIELD_INSERT: OUString(), OUString(), SVX_NUM_PAGEDESC); aMgr.InsertField(aData); + SwPaM aNewBookmarkPaM(*rSh.GetCursor()->Start()); + aNewBookmarkPaM.SetMark(); + rSh.GetCursor()->Left(1); + *aNewBookmarkPaM.Start() = *rSh.GetCursor()->Start(); + rIDMA.makeMark(aNewBookmarkPaM, + sBookmarkName + OUString::number(rSh.GetVirtPageNum()), + IDocumentMarkAccess::MarkType::BOOKMARK, + sw::mark::InsertMode::New); + // Mirror on the even pages if (!bSkipMirror && bCreateMirror && rSh.SetCursorInHdFt(nPageDescIndex, bHeader, /*Even=*/true)) { assert(nEvenPage && "what? no even page and yet we got here?"); + ppMark = rIDMA.findMark(sBookmarkName + OUString::number(rSh.GetVirtPageNum())); + if (ppMark != rIDMA.getAllMarksEnd() && *ppMark) + { + SwPaM aDeleteOldPageNum((*ppMark)->GetMarkStart(), (*ppMark)->GetMarkEnd()); + rDoc->getIDocumentContentOperations().DeleteAndJoin(aDeleteOldPageNum); + } + pTextNode = rSh.GetCursor()->GetPoint()->GetNode().GetTextNode(); // Insert new line if there is already text in header/footer @@ -1212,6 +1250,15 @@ FIELD_INSERT: // Insert page number SwFieldMgr aEvenMgr(pShell); aEvenMgr.InsertField(aData); + + SwPaM aNewEvenBookmarkPaM(*rSh.GetCursor()->Start()); + aNewEvenBookmarkPaM.SetMark(); + rSh.GetCursor()->Left(1); + *aNewEvenBookmarkPaM.Start() = *rSh.GetCursor()->Start(); + rIDMA.makeMark(aNewEvenBookmarkPaM, + sBookmarkName + OUString::number(rSh.GetVirtPageNum()), + IDocumentMarkAccess::MarkType::BOOKMARK, + sw::mark::InsertMode::New); } rSh.SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent); commit 33d984bb205d710a33303502884cda6d105a0d14 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Thu Apr 27 09:32:41 2023 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Thu May 18 17:56:27 2023 +0200 tdf#86630 sw page number wizard: mirror margins as well This is only done in a very specific situation, when no heading/footer is defined at all. If we turn on mirroring at this point, then be helpful and mirror the margins as well. By default, this is irrelevant because the margins are identical. It isn't necessary for page numbering, but I think it is a nice touch to add something that most people wouldn't find otherwise. If they really want mirrorred page numbers, then it is highly likely they also want mirrored margins. Helping out people is the whole point of wizards after all. Change-Id: I20cde65dc95ea3115951a4ea3a01534399f19f3d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151153 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151902 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 66f016df7c65..5f1f1e821573 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -1054,6 +1054,12 @@ FIELD_INSERT: SvxPageItem aPageItem(SID_ATTR_PAGE); aPageItem.SetNumType(pDlg->GetPageNumberType()); + // Might as well turn on margin mirroring too - if appropriate + if (!bHeaderAlreadyOn && !bFooterAlreadyOn && !bIsSinglePage + && pDlg->GetMirrorOnEvenPages() && (rDesc.GetUseOn() & UseOnPage::All)) + { + aPageItem.SetPageUsage(SvxPageUsage::Mirror); + } rSh.GetView().GetDispatcher().ExecuteList(SID_ATTR_PAGE, SfxCallMode::API | SfxCallMode::SYNCHRON, { &aPageItem });