diff options
author | Justin Luth <justin.luth@collabora.com> | 2023-05-01 10:57:25 -0400 |
---|---|---|
committer | Justin Luth <jluth@mail.com> | 2023-05-03 03:09:34 +0200 |
commit | 98f766004e29ea35eef6fcf3a4c28696b95f6c90 (patch) | |
tree | f107fce893b9dc2095da9a7322249fd6b7c8d583 /sw/source/uibase/shells/textfld.cxx | |
parent | 98726695af0e3a673618d16b981818155d43bc0c (diff) |
tdf#86630 sw page number wizard: try avoid copying bookmarks
Each time the pagedesc is changed, it makes extra copies
for undo purposes. That really messes up unique bookmark names.
So, consolidate all the page description changes,
and make the change in one big batch.
I like this better anyway, because now it doesn't
look like all kinds of magic incantations.
This is now straight forward programming,
and consolidates three separate calls to adjust the page style.
Change-Id: Ib200a1f6ba810fdf0111c9909679e3f80d573230
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151243
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
Diffstat (limited to 'sw/source/uibase/shells/textfld.cxx')
-rw-r--r-- | sw/source/uibase/shells/textfld.cxx | 71 |
1 files changed, 48 insertions, 23 deletions
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 35fd1b50b90f..8257038cb1e5 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -56,12 +56,15 @@ #include <doc.hxx> #include <PostItMgr.hxx> #include <swmodule.hxx> + +#include <editeng/ulspitem.hxx> #include <xmloff/odffields.hxx> #include <IDocumentContentOperations.hxx> #include <IDocumentRedlineAccess.hxx> #include <IDocumentUndoRedo.hxx> #include <svl/zforlist.hxx> #include <svl/zformat.hxx> +#include <svx/xfillit0.hxx> #include <svx/pageitem.hxx> #include <comphelper/sequenceashashmap.hxx> #include <IMark.hxx> @@ -1033,10 +1036,8 @@ FIELD_INSERT: pFact->CreateSwPageNumberDlg(GetView().GetFrameWeld())); auto pShell = GetShellPtr(); - const SvxPageItem* pPageItem; - rSh.GetView().GetDispatcher().QueryState(SID_ATTR_PAGE, pPageItem); - if (pPageItem) - pDlg->SetPageNumberType(pPageItem->GetNumType()); + const SwPageDesc& rCurrDesc = rSh.GetPageDesc(rSh.GetCurPageDesc()); + pDlg->SetPageNumberType(rCurrDesc.GetNumType().GetNumberingType()); pDlg->StartExecuteAsync([pShell, &rSh, pDlg](int nResult) { if ( nResult == RET_OK ) @@ -1069,23 +1070,47 @@ FIELD_INSERT: rDoc->getIDocumentContentOperations().DeleteAndJoin(aDeleteOldPageNum); } - 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)) + SwPageDesc aNewDesc(rDesc); + bool bChangePageDesc = false; + if (pDlg->GetPageNumberType() != aNewDesc.GetNumType().GetNumberingType()) { - aPageItem.SetPageUsage(SvxPageUsage::Mirror); + bChangePageDesc = true; + SvxNumberType aNewType(rDesc.GetNumType()); + aNewType.SetNumberingType(pDlg->GetPageNumberType()); + aNewDesc.SetNumType(aNewType); } - rSh.GetView().GetDispatcher().ExecuteList(SID_ATTR_PAGE, - SfxCallMode::API | SfxCallMode::SYNCHRON, - { &aPageItem }); // Insert header/footer - if (bHeader && !bHeaderAlreadyOn) - rSh.ChangeHeaderOrFooter(rDesc.GetName(), bHeader, /*On=*/true, /*Warn=*/false); - else if (!bHeader && !bFooterAlreadyOn) - rSh.ChangeHeaderOrFooter(rDesc.GetName(), false, /*On=*/true, /*Warn=*/false); + if ((bHeader && !bHeaderAlreadyOn) || (!bHeader && !bFooterAlreadyOn)) + { + bChangePageDesc = true; + SwFrameFormat &rMaster = aNewDesc.GetMaster(); + if (bHeader) + rMaster.SetFormatAttr(SwFormatHeader(/*On=*/true)); + else + rMaster.SetFormatAttr(SwFormatFooter(/*On=*/true)); + + // Init copied from ChangeHeaderOrFooter: keep in sync + constexpr tools::Long constTwips_5mm = o3tl::toTwips(5, o3tl::Length::mm); + const SvxULSpaceItem aUL(bHeader ? 0 : constTwips_5mm, + bHeader ? constTwips_5mm : 0, + RES_UL_SPACE); + const XFillStyleItem aFill(drawing::FillStyle_NONE); + SwFrameFormat& rFormat + = bHeader + ? const_cast<SwFrameFormat&>(*rMaster.GetHeader().GetHeaderFormat()) + : const_cast<SwFrameFormat&>(*rMaster.GetFooter().GetFooterFormat()); + rFormat.SetFormatAttr(aUL); + rFormat.SetFormatAttr(aFill); + + // Might as well turn on margin mirroring too - if appropriate + if (pDlg->GetMirrorOnEvenPages() && !bHeaderAlreadyOn && !bFooterAlreadyOn + && !bIsSinglePage + && (aNewDesc.ReadUseOn() & UseOnPage::Mirror) == UseOnPage::All) + { + aNewDesc.WriteUseOn(rDesc.ReadUseOn() | UseOnPage::Mirror); + } + } const bool bCreateMirror = !bIsSinglePage && pDlg->GetMirrorOnEvenPages() && nMirrorPagesNeeded <= rSh.GetPageCnt(); @@ -1094,17 +1119,17 @@ FIELD_INSERT: // Use different left/right header/footer if ((bHeader && rDesc.IsHeaderShared()) || (!bHeader && rDesc.IsFooterShared())) { - SwPageDesc rNewDesc(rSh.GetPageDesc(nPageDescIndex)); - + bChangePageDesc = true; if (bHeader) - rNewDesc.ChgHeaderShare(false); + aNewDesc.ChgHeaderShare(/*Share=*/false); else - rNewDesc.ChgFooterShare(false); - - rSh.ChgPageDesc(nPageDescIndex, rNewDesc); + aNewDesc.ChgFooterShare(/*Share=*/false); } } + if (bChangePageDesc) + rSh.ChgPageDesc(nPageDescIndex, aNewDesc); + // Go to the header or footer insert position bool bInHF = false; bool bSkipMirror = true; |