sw/source/uibase/shells/textfld.cxx |   71 ++++++++++++++++++++++++------------
 sw/source/uibase/wrtsh/wrtsh1.cxx   |    1 
 2 files changed, 49 insertions(+), 23 deletions(-)

New commits:
commit 98f766004e29ea35eef6fcf3a4c28696b95f6c90
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Mon May 1 10:57:25 2023 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Wed May 3 03:09:34 2023 +0200

    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 <jl...@mail.com>

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;
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx 
b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 0cdd279df379..d12ad1c68f14 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -2188,6 +2188,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 ?

Reply via email to