summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2023-05-01 10:57:25 -0400
committerJustin Luth <jluth@mail.com>2023-05-18 18:06:15 +0200
commit800cccaeb191a900de8c96dfb0d56a9089b016d8 (patch)
treed2707a806bae4aaa72a4b20039f4bbf1d19eac26 /sw
parentd466b9603b4917f1d4a8fdc702a8ed69f0ced8ae (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> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151905 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/uibase/shells/textfld.cxx71
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx1
2 files changed, 49 insertions, 23 deletions
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index 30d346b5b31a..2a68219774ba 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>
@@ -1030,10 +1033,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 )
@@ -1066,23 +1067,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();
@@ -1091,17 +1116,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;
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index b4e8b882da4e..4b9e12fa561b 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -2193,6 +2193,7 @@ void SwWrtShell::ChangeHeaderOrFooter(
rMaster.SetFormatAttr( SwFormatFooter( bOn ));
if( bOn )
{
+ // keep in sync with FN_PGNUMBER_WIZARD
constexpr tools::Long constTwips_5mm = o3tl::toTwips(5, o3tl::Length::mm);
SvxULSpaceItem aUL(bHeader ? 0 : constTwips_5mm, bHeader ? constTwips_5mm : 0, RES_UL_SPACE );
SwFrameFormat* pFormat = bHeader ?