sw/inc/swabstdlg.hxx                    |    1 +
 sw/source/ui/dialog/swdlgfact.cxx       |    5 +++++
 sw/source/ui/dialog/swdlgfact.hxx       |    1 +
 sw/source/ui/misc/pagenumberdlg.cxx     |    7 +++++++
 sw/source/uibase/inc/pagenumberdlg.hxx  |    2 ++
 sw/source/uibase/shells/textfld.cxx     |   29 +++++++++++++++++++++++++----
 sw/uiconfig/swriter/ui/pagenumberdlg.ui |   26 ++++++++++++++++++++++++--
 7 files changed, 65 insertions(+), 6 deletions(-)

New commits:
commit 751cb2cf874a2d017cae699a7983e4419dcbe6f6
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Apr 28 13:38:13 2023 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue May 2 15:36:07 2023 +0200

    tdf#86630 sw page number wizard: add page total
    
    1 - 3 is the format of the output.
    Not totally clear, but it is at least not in English,
    and I'm fairly certain I've seen this format used numerous times.
    
    At least everything is there, and all the user needs to do is
    modify the - to be whatever they want.
    
    I checked to see if by some miracle localedata had a specification
    for "X of Y" but it doesn't.
    
    Change-Id: Iae1e74e612ec449f72086b3f5a5e32713fee4d27
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151173
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index 49eefef5e4a3..fe6bab309ef9 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -239,6 +239,7 @@ public:
     virtual int GetPageNumberPosition() const = 0;
     virtual int GetPageNumberAlignment() const = 0;
     virtual bool GetMirrorOnEvenPages() const = 0;
+    virtual bool GetIncludePageTotal() const = 0;
     virtual SvxNumType GetPageNumberType() const = 0;
     virtual void SetPageNumberType(SvxNumType nSet) = 0;
 };
diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index 6ec8e23a6304..90f7c6e34d84 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -647,6 +647,11 @@ bool AbstractSwPageNumberDlg_Impl::GetMirrorOnEvenPages() 
const
     return m_xDlg->GetMirrorOnEvenPages();
 }
 
+bool AbstractSwPageNumberDlg_Impl::GetIncludePageTotal() const
+{
+    return m_xDlg->GetIncludePageTotal();
+}
+
 SvxNumType AbstractSwPageNumberDlg_Impl::GetPageNumberType() const
 {
     return m_xDlg->GetPageNumberType();
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index 6d3f37aa6a47..0b6f67b1da23 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -167,6 +167,7 @@ public:
     virtual int GetPageNumberPosition() const override;
     virtual int GetPageNumberAlignment() const override;
     bool GetMirrorOnEvenPages() const override;
+    bool GetIncludePageTotal() const override;
     SvxNumType GetPageNumberType() const override;
     void SetPageNumberType(SvxNumType nSet) override;
 };
diff --git a/sw/source/ui/misc/pagenumberdlg.cxx 
b/sw/source/ui/misc/pagenumberdlg.cxx
index 06facf1bff22..1b5084c5e94b 100644
--- a/sw/source/ui/misc/pagenumberdlg.cxx
+++ b/sw/source/ui/misc/pagenumberdlg.cxx
@@ -31,6 +31,7 @@ SwPageNumberDlg::SwPageNumberDlg(weld::Window* pParent)
     , m_xPageNumberPosition(m_xBuilder->weld_combo_box("positionCombo"))
     , m_xPageNumberAlignment(m_xBuilder->weld_combo_box("alignmentCombo"))
     , m_xMirrorOnEvenPages(m_xBuilder->weld_check_button("mirrorCheckbox"))
+    , m_xIncludePageTotal(m_xBuilder->weld_check_button("pagetotalCheckbox"))
     , m_xPageNumberTypeLB(new 
SvxPageNumberListBox(m_xBuilder->weld_combo_box("numfmtlb")))
     , m_xPreviewImage(m_xBuilder->weld_image("previewImage"))
     , m_aPageNumberPosition(1) // bottom
@@ -44,6 +45,7 @@ SwPageNumberDlg::SwPageNumberDlg(weld::Window* pParent)
     m_xPageNumberAlignment->set_active(m_aPageNumberAlignment);
     m_xMirrorOnEvenPages->set_sensitive(false);
     m_xMirrorOnEvenPages->set_state(TRISTATE_TRUE);
+    m_xIncludePageTotal->set_state(TRISTATE_FALSE);
     
SvxNumOptionsTabPageHelper::GetI18nNumbering(m_xPageNumberTypeLB->get_widget(),
                                                  
::std::numeric_limits<sal_uInt16>::max());
     m_xPageNumberTypeLB->connect_changed(LINK(this, SwPageNumberDlg, 
NumberTypeSelectHdl));
@@ -80,6 +82,11 @@ bool SwPageNumberDlg::GetMirrorOnEvenPages()
            && m_xMirrorOnEvenPages->get_state() == TRISTATE_TRUE;
 }
 
+bool SwPageNumberDlg::GetIncludePageTotal()
+{
+    return m_xIncludePageTotal->get_state() == TRISTATE_TRUE;
+}
+
 void SwPageNumberDlg::SetPageNumberType(SvxNumType nSet)
 {
     m_nPageNumberType = nSet;
diff --git a/sw/source/uibase/inc/pagenumberdlg.hxx 
b/sw/source/uibase/inc/pagenumberdlg.hxx
index b5dccd93127a..cf719b492a33 100644
--- a/sw/source/uibase/inc/pagenumberdlg.hxx
+++ b/sw/source/uibase/inc/pagenumberdlg.hxx
@@ -32,6 +32,7 @@ class SwPageNumberDlg final : public SfxDialogController
     std::unique_ptr<weld::ComboBox> m_xPageNumberPosition;
     std::unique_ptr<weld::ComboBox> m_xPageNumberAlignment;
     std::unique_ptr<weld::CheckButton> m_xMirrorOnEvenPages;
+    std::unique_ptr<weld::CheckButton> m_xIncludePageTotal;
     std::unique_ptr<SvxPageNumberListBox> m_xPageNumberTypeLB;
 
     std::unique_ptr<weld::Image> m_xPreviewImage;
@@ -52,6 +53,7 @@ public:
     int GetPageNumberPosition() const { return m_aPageNumberPosition; }
     int GetPageNumberAlignment() const { return m_aPageNumberAlignment; }
     bool GetMirrorOnEvenPages();
+    bool GetIncludePageTotal();
     SvxNumType GetPageNumberType() const { return m_nPageNumberType; }
     void SetPageNumberType(SvxNumType nSet);
 };
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index 64694b0ab07b..35fd1b50b90f 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -1204,16 +1204,27 @@ FIELD_INSERT:
                     }
                 }
 
+                sal_Int32 nStartContentIndex = 
rSh.GetCursor()->Start()->GetContentIndex();
+                assert(!nStartContentIndex && "earlier split node if not 
empty, but not zero?");
+
                 // Insert page number
                 SwFieldMgr aMgr(pShell);
                 SwInsertField_Data aData(SwFieldTypesEnum::PageNumber, 0,
                             OUString(), OUString(), SVX_NUM_PAGEDESC);
                 aMgr.InsertField(aData);
+                if (pDlg->GetIncludePageTotal())
+                {
+                    
rDoc->getIDocumentContentOperations().InsertString(*rSh.GetCursor(), " - ");
+                    SwInsertField_Data 
aPageTotalData(SwFieldTypesEnum::DocumentStatistics, DS_PAGE,
+                                                      OUString(), OUString(), 
SVX_NUM_PAGEDESC);
+                    aMgr.InsertField(aPageTotalData);
+                }
 
+                // Mark inserted fields with a bookmark - so it can be 
found/removed if re-run
                 SwPaM aNewBookmarkPaM(*rSh.GetCursor()->Start());
                 aNewBookmarkPaM.SetMark();
-                rSh.GetCursor()->Left(1);
-                *aNewBookmarkPaM.Start() = *rSh.GetCursor()->Start();
+                assert(aNewBookmarkPaM.GetPointContentNode() && "only 
SetContent on content node");
+                aNewBookmarkPaM.Start()->SetContent(nStartContentIndex);
                 rIDMA.makeMark(aNewBookmarkPaM,
                                sBookmarkName + 
OUString::number(rSh.GetVirtPageNum()),
                                IDocumentMarkAccess::MarkType::BOOKMARK,
@@ -1250,14 +1261,24 @@ FIELD_INSERT:
                     SvxAdjustItem aMirrorAdjustItem(eAdjust, 
RES_PARATR_ADJUST);
                     rSh.SetAttrItem(aMirrorAdjustItem);
 
+                    nStartContentIndex = 
rSh.GetCursor()->Start()->GetContentIndex();
+
                     // Insert page number
                     SwFieldMgr aEvenMgr(pShell);
                     aEvenMgr.InsertField(aData);
+                    if (pDlg->GetIncludePageTotal())
+                    {
+                        
rDoc->getIDocumentContentOperations().InsertString(*rSh.GetCursor(), " - ");
+                        SwInsertField_Data 
aPageTotalData(SwFieldTypesEnum::DocumentStatistics,
+                                                          DS_PAGE, OUString(), 
OUString(),
+                                                          SVX_NUM_PAGEDESC);
+                        aMgr.InsertField(aPageTotalData);
+                    }
 
+                    // Mark inserted fields with a bookmark - so it can be 
found/removed if re-run
                     SwPaM aNewEvenBookmarkPaM(*rSh.GetCursor()->Start());
                     aNewEvenBookmarkPaM.SetMark();
-                    rSh.GetCursor()->Left(1);
-                    *aNewEvenBookmarkPaM.Start() = *rSh.GetCursor()->Start();
+                    
aNewEvenBookmarkPaM.Start()->SetContent(nStartContentIndex);
                     rIDMA.makeMark(aNewEvenBookmarkPaM,
                                    sBookmarkName + 
OUString::number(rSh.GetVirtPageNum()),
                                    IDocumentMarkAccess::MarkType::BOOKMARK,
diff --git a/sw/uiconfig/swriter/ui/pagenumberdlg.ui 
b/sw/uiconfig/swriter/ui/pagenumberdlg.ui
index 5ed72d4fad3f..5fff5178898a 100644
--- a/sw/uiconfig/swriter/ui/pagenumberdlg.ui
+++ b/sw/uiconfig/swriter/ui/pagenumberdlg.ui
@@ -186,6 +186,28 @@
                     <property name="position">4</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkCheckButton" id="pagetotalCheckbox">
+                    <property name="label" translatable="yes" 
context="pagenumberdlg|pagetotalCheckbox">Include page total</property>
+                    <property name="visible">True</property>
+                    <property name="can-focus">True</property>
+                    <property name="receives-default">False</property>
+                    <property name="margin-start">18</property>
+                    <property name="margin-top">3</property>
+                    <property name="use-underline">True</property>
+                    <property name="draw-indicator">True</property>
+                    <child internal-child="accessible">
+                      <object class="AtkObject" 
id="pagetotalCheckbox-atkobject">
+                        <property name="AtkObject::accessible-description" 
translatable="yes" context="pagenumberdlg|extended_tip|pagetotalCheckbox">Also 
insert the total number of pages</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">5</property>
+                  </packing>
+                </child>
                 <child>
                   <object class="GtkLabel" id="numfmtLabel">
                     <property name="visible">True</property>
@@ -207,7 +229,7 @@
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
-                    <property name="position">5</property>
+                    <property name="position">6</property>
                   </packing>
                 </child>
                 <child>
@@ -226,7 +248,7 @@
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
-                    <property name="position">6</property>
+                    <property name="position">7</property>
                   </packing>
                 </child>
               </object>

Reply via email to