desktop/source/lib/init.cxx                                         |    1 
 officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu |    5 
 sfx2/source/control/unoctitm.cxx                                    |    1 
 sw/Library_swui.mk                                                  |    1 
 sw/UIConfig_swriter.mk                                              |    1 
 sw/inc/cmdid.h                                                      |    1 
 sw/inc/strings.hrc                                                  |    1 
 sw/inc/swabstdlg.hxx                                                |   11 
 sw/inc/swundo.hxx                                                   |    1 
 sw/sdi/_textsh.sdi                                                  |    7 
 sw/sdi/swriter.sdi                                                  |   18 
 sw/source/core/undo/undobj.cxx                                      |    3 
 sw/source/ui/dialog/swdlgfact.cxx                                   |   26 +
 sw/source/ui/dialog/swdlgfact.hxx                                   |   16 
 sw/source/ui/misc/pagenumberdlg.cxx                                 |   92 ++++
 sw/source/uibase/inc/pagenumberdlg.hxx                              |   51 ++
 sw/source/uibase/shells/textfld.cxx                                 |   81 +++
 sw/uiconfig/swriter/menubar/menubar.xml                             |    2 
 sw/uiconfig/swriter/ui/pagenumberdlg.ui                             |  222 
++++++++++
 vcl/inc/jsdialog/jsdialogbuilder.hxx                                |    2 
 vcl/jsdialog/enabled.cxx                                            |    1 
 vcl/jsdialog/jsdialogbuilder.cxx                                    |   12 
 22 files changed, 555 insertions(+), 1 deletion(-)

New commits:
commit 19820c3db7a704e22f5db72b91bf10d85cc48897
Author:     offtkp <parisop...@gmail.com>
AuthorDate: Wed Dec 21 14:29:59 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Jan 9 08:59:01 2023 +0000

    tdf#86630 sw: Add one-step page number insertion wizard
    
    Add a one-step wizard for easy insertion of the page number to the
    header/footer.
    
    Change-Id: Idb33c92d594e04d9256460fe414e4b10e5166af5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144998
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 0c3be4b25743..edaf0ad75477 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -3337,6 +3337,7 @@ static void doc_iniUnoCommands ()
         OUString(".uno:InsertAuthoritiesEntry"),
         OUString(".uno:InsertMultiIndex"),
         OUString(".uno:InsertField"),
+        OUString(".uno:PageNumberWizard"),
         OUString(".uno:InsertPageNumberField"),
         OUString(".uno:InsertPageCountField"),
         OUString(".uno:InsertDateField"),
diff --git 
a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
index 9247374da3f6..59a66a8382a8 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
@@ -1003,6 +1003,11 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:PageNumberWizard" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">~Page Number...</value>
+        </prop>
+      </node>
       <node oor:name=".uno:InsertPageNumberField" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">~Page Number</value>
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 868d7749f32b..30538c614772 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -1091,6 +1091,7 @@ static void InterceptLOKStateChangeEvent(sal_uInt16 nSID, 
SfxViewFrame* pViewFra
              aEvent.FeatureURL.Path == "InsertAuthoritiesEntry" ||
              aEvent.FeatureURL.Path == "InsertMultiIndex" ||
              aEvent.FeatureURL.Path == "InsertField" ||
+             aEvent.FeatureURL.Path == "PageNumberWizard" ||
              aEvent.FeatureURL.Path == "InsertPageNumberField" ||
              aEvent.FeatureURL.Path == "InsertPageCountField" ||
              aEvent.FeatureURL.Path == "InsertDateField" ||
diff --git a/sw/Library_swui.mk b/sw/Library_swui.mk
index 532617295808..c34451317dd7 100644
--- a/sw/Library_swui.mk
+++ b/sw/Library_swui.mk
@@ -141,6 +141,7 @@ $(eval $(call gb_Library_add_exception_objects,swui,\
     sw/source/ui/misc/bookmark \
     sw/source/ui/misc/contentcontroldlg \
     sw/source/ui/misc/contentcontrollistitemdlg \
+    sw/source/ui/misc/pagenumberdlg \
     sw/source/ui/misc/docfnote \
     sw/source/ui/misc/glosbib \
     sw/source/ui/misc/glossary \
diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk
index 22b91c7f57c9..b5fab9613f66 100644
--- a/sw/UIConfig_swriter.mk
+++ b/sw/UIConfig_swriter.mk
@@ -243,6 +243,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
        sw/uiconfig/swriter/ui/notebookbar_online \
        sw/uiconfig/swriter/ui/pagecolumncontrol \
        sw/uiconfig/swriter/ui/pagemargincontrol \
+       sw/uiconfig/swriter/ui/pagenumberdlg \
        sw/uiconfig/swriter/ui/pageorientationcontrol \
        sw/uiconfig/swriter/ui/pagesizecontrol \
        sw/uiconfig/swriter/ui/pagestylemenu \
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index 43f4b12f55e3..dfd22f400459 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -233,6 +233,7 @@
 #define FN_TOOL_ANCHOR_PAGE     (FN_INSERT + 50)    /* anchor Draw object to 
page */
 #define FN_TOOL_ANCHOR_PARAGRAPH (FN_INSERT + 51)   /* anchor Draw object to 
paragraph */
 #define FN_TOOL_HIERARCHIE      (FN_INSERT + 52)    /* change hierarchy */
+#define FN_PGNUMBER_WIZARD      (FN_INSERT + 53)    /* page number wizard */
 
 #define FN_MAILMERGE_WIZARD     (FN_INSERT + 64)    /* mail merge wizard */
 #define FN_TOOL_ANCHOR_FRAME    (FN_INSERT + 66)    /* anchor Draw-Object to 
frame*/
diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index 59fe112fecba..8ec74176c6a8 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -583,6 +583,7 @@
 #define STR_UNDO_TBLSTYLE_UPDATE                
NC_("STR_UNDO_TBLSTYLE_UPDATE", "Update table style: $1")
 #define STR_UNDO_TABLE_DELETE                   NC_("STR_UNDO_TABLE_DELETE", 
"Delete table")
 #define STR_UNDO_INSERT_FORM_FIELD              
NC_("STR_UNDO_INSERT_FORM_FIELD", "Insert form field")
+#define STR_UNDO_INSERT_PAGE_NUMBER             
NC_("STR_UNDO_INSERT_PAGE_NUMBER", "Insert page number")
 #define STR_DROP_DOWN_FIELD_ITEM_LIMIT          
NC_("STR_DROP_DOWN_FIELD_ITEM_LIMIT", "You can specify maximum of 25 items for 
a drop-down form field.")
 
 #define STR_ACCESS_DOC_NAME                     NC_("STR_ACCESS_DOC_NAME", 
"Document view")
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index a841ce5d0ffd..adcc12012654 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -229,6 +229,16 @@ public:
 
 };
 
+/// Interface for the insert -> fields -> page number wizard dialog
+class AbstractSwPageNumberDlg : public VclAbstractDialog
+{
+protected:
+    virtual ~AbstractSwPageNumberDlg() override = default;
+public:
+    virtual int GetPageNumberPosition() const = 0;
+    virtual int GetPageNumberAlignment() const = 0;
+};
+
 class AbstractSwBreakDlg
 {
 protected:
@@ -467,6 +477,7 @@ public:
         css::uno::Reference< css::container::XNamed > & xNamed,
         css::uno::Reference< css::container::XNameAccess > & xNameAccess) = 0;
     virtual VclPtr<AbstractSwModalRedlineAcceptDlg> 
CreateSwModalRedlineAcceptDlg(weld::Window *pParent) = 0;
+    virtual VclPtr<AbstractSwPageNumberDlg> 
CreateSwPageNumberDlg(weld::Window* pParent) = 0;
 
     virtual VclPtr<VclAbstractDialog>          
CreateTableMergeDialog(weld::Window* pParent, bool& rWithPrev) = 0;
     virtual VclPtr<SfxAbstractTabDialog>       CreateFrameTabDialog(const 
OUString &rDialogType,
diff --git a/sw/inc/swundo.hxx b/sw/inc/swundo.hxx
index cda4ec02c49f..7e9e0108b71f 100644
--- a/sw/inc/swundo.hxx
+++ b/sw/inc/swundo.hxx
@@ -166,6 +166,7 @@ enum class SwUndoId
 
     INSERT_FORM_FIELD,                 // 135
     OUTLINE_EDIT,                      // 136
+    INSERT_PAGE_NUMBER,                // 137
 };
 
 OUString GetUndoComment(SwUndoId eId);
diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index b03f90903868..fb7100fde476 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -924,6 +924,13 @@ interface BaseText
         DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
     ]
 
+    FN_PGNUMBER_WIZARD
+    [
+        ExecMethod = ExecField ;
+        StateMethod = StateField ;
+        DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
+        ReadOnlyDoc = FALSE ;
+    ]
     FN_INSERT_FLD_PGNUMBER
     [
         ExecMethod = ExecField ;
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 2c644638443e..6deae2abb2c8 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -3359,6 +3359,24 @@ SfxVoidItem InsertPageNumberField FN_INSERT_FLD_PGNUMBER
     GroupId = SfxGroupId::Insert;
 ]
 
+SfxVoidItem PageNumberWizard FN_PGNUMBER_WIZARD
+()
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = FALSE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Asynchron;
+
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::Insert;
+]
+
 SfxVoidItem InsertPara FN_INSERT_BREAK
 ()
 [
diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx
index c23aeba3ba51..b2248ee3bcf9 100644
--- a/sw/source/core/undo/undobj.cxx
+++ b/sw/source/core/undo/undobj.cxx
@@ -653,6 +653,9 @@ OUString GetUndoComment(SwUndoId eId)
         case SwUndoId::INSERT_FORM_FIELD:
             pId = STR_UNDO_INSERT_FORM_FIELD;
             break;
+        case SwUndoId::INSERT_PAGE_NUMBER:
+            pId = STR_UNDO_INSERT_PAGE_NUMBER;
+            break;
     }
 
     assert(pId);
diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index 7578266db372..eda2be389ae8 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -35,6 +35,7 @@
 #include <colwd.hxx>
 #include <contentcontroldlg.hxx>
 #include <contentcontrollistitemdlg.hxx>
+#include <pagenumberdlg.hxx>
 #include <convert.hxx>
 #include <cption.hxx>
 #include <dbinsdlg.hxx>
@@ -151,6 +152,16 @@ short AbstractSwMergeTableDlg_Impl::Execute()
     return m_xDlg->run();
 }
 
+short AbstractSwPageNumberDlg_Impl::Execute()
+{
+    return m_xDlg->run();
+}
+
+bool AbstractSwPageNumberDlg_Impl::StartExecuteAsync(AsyncContext &rCtx)
+{
+    return weld::GenericDialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
+}
+
 short AbstractGenericDialog_Impl::Execute()
 {
     return m_xDlg->run();
@@ -626,6 +637,16 @@ OUString AbstractInsFootNoteDlg_Impl::GetFontName()
     return m_xDlg->GetFontName();
 }
 
+int AbstractSwPageNumberDlg_Impl::GetPageNumberPosition() const
+{
+    return m_xDlg->GetPageNumberPosition();
+}
+
+int AbstractSwPageNumberDlg_Impl::GetPageNumberAlignment() const
+{
+    return m_xDlg->GetPageNumberAlignment();
+}
+
 bool AbstractInsFootNoteDlg_Impl::IsEndNote()
 {
     return m_xDlg->IsEndNote();
@@ -1073,6 +1094,11 @@ VclPtr<AbstractSwModalRedlineAcceptDlg> 
SwAbstractDialogFactory_Impl::CreateSwMo
     return 
VclPtr<AbstractSwModalRedlineAcceptDlg_Impl>::Create(std::make_unique<SwModalRedlineAcceptDlg>(pParent));
 }
 
+VclPtr<AbstractSwPageNumberDlg> 
SwAbstractDialogFactory_Impl::CreateSwPageNumberDlg(weld::Window *pParent)
+{
+    return 
VclPtr<AbstractSwPageNumberDlg_Impl>::Create(std::make_shared<SwPageNumberDlg>(pParent));
+}
+
 VclPtr<VclAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateTableMergeDialog(weld::Window* pParent, 
bool& rWithPrev)
 {
     return 
VclPtr<AbstractSwMergeTableDlg_Impl>::Create(std::make_unique<SwMergeTableDlg>(pParent,
 rWithPrev));
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index ccaa286828f9..a08a8af26318 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -55,6 +55,7 @@
 #include <itabenum.hxx>
 #include <optional>
 #include <o3tl/deleter.hxx>
+#include <pagenumberdlg.hxx>
 
 
 class SwInsertAbstractDlg;
@@ -151,6 +152,20 @@ public:
     virtual void FillOptions( SwAsciiOptions& rOptions ) override;
 };
 
+class AbstractSwPageNumberDlg_Impl : public AbstractSwPageNumberDlg
+{
+    std::shared_ptr<SwPageNumberDlg> m_xDlg;
+public:
+    explicit AbstractSwPageNumberDlg_Impl(std::shared_ptr<SwPageNumberDlg> p)
+        : m_xDlg(std::move(p))
+    {
+    }
+    virtual short Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext &rCtx) override;
+    virtual int GetPageNumberPosition() const override;
+    virtual int GetPageNumberAlignment() const override;
+};
+
 class AbstractGenericDialog_Impl : public VclAbstractDialog
 {
     std::shared_ptr<weld::GenericDialogController> m_xDlg;
@@ -707,6 +722,7 @@ public:
                                                                 SvStream* 
pStream) override;
     virtual VclPtr<VclAbstractDialog> CreateSwInsertBookmarkDlg(weld::Window 
*pParent, SwWrtShell &rSh) override;
     virtual VclPtr<VclAbstractDialog> CreateSwContentControlDlg(weld::Window 
*pParent, SwWrtShell &rSh) override;
+    virtual VclPtr<AbstractSwPageNumberDlg> CreateSwPageNumberDlg(weld::Window 
*pParent) override;
 
     VclPtr<AbstractSwContentControlListItemDlg>
     CreateSwContentControlListItemDlg(weld::Window* pParent,
diff --git a/sw/source/ui/misc/pagenumberdlg.cxx 
b/sw/source/ui/misc/pagenumberdlg.cxx
new file mode 100644
index 000000000000..47e532e18ae6
--- /dev/null
+++ b/sw/source/ui/misc/pagenumberdlg.cxx
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <pagenumberdlg.hxx>
+#include <vcl/bitmap.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/BitmapTools.hxx>
+#include <vcl/virdev.hxx>
+
+SwPageNumberDlg::SwPageNumberDlg(weld::Window* pParent)
+    : SfxDialogController(pParent, "modules/swriter/ui/pagenumberdlg.ui", 
"PageNumberDialog")
+    , m_xOk(m_xBuilder->weld_button("ok"))
+    , m_xCancel(m_xBuilder->weld_button("cancel"))
+    , m_xPageNumberPosition(m_xBuilder->weld_combo_box("positionCombo"))
+    , m_xPageNumberAlignment(m_xBuilder->weld_combo_box("alignmentCombo"))
+    , m_xPreviewImage(m_xBuilder->weld_image("previewImage"))
+    , m_aPageNumberPosition(1)
+    , m_aPageNumberAlignment(0)
+{
+    m_xOk->connect_clicked(LINK(this, SwPageNumberDlg, OkHdl));
+    m_xPageNumberPosition->connect_changed(LINK(this, SwPageNumberDlg, 
PositionSelectHdl));
+    m_xPageNumberAlignment->connect_changed(LINK(this, SwPageNumberDlg, 
AlignmentSelectHdl));
+    m_xPageNumberPosition->set_active(m_aPageNumberPosition);
+    m_xPageNumberAlignment->set_active(m_aPageNumberAlignment);
+    updateImage();
+}
+
+IMPL_LINK_NOARG(SwPageNumberDlg, OkHdl, weld::Button&, void) { 
m_xDialog->response(RET_OK); }
+
+IMPL_LINK_NOARG(SwPageNumberDlg, CancelHdl, weld::Button&, void)
+{
+    m_xDialog->response(RET_CANCEL);
+}
+
+IMPL_LINK_NOARG(SwPageNumberDlg, PositionSelectHdl, weld::ComboBox&, void)
+{
+    m_aPageNumberPosition = m_xPageNumberPosition->get_active();
+    updateImage();
+}
+
+IMPL_LINK_NOARG(SwPageNumberDlg, AlignmentSelectHdl, weld::ComboBox&, void)
+{
+    m_aPageNumberAlignment = m_xPageNumberAlignment->get_active();
+    updateImage();
+}
+
+void SwPageNumberDlg::updateImage()
+{
+    int nBackgroundWidth = 75;
+    int nBackgroundHeight = 105;
+
+    int nSpriteWidth = 10;
+    int nSpriteHeight = 14;
+
+    ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
+    Size aVDSize(nBackgroundWidth, nBackgroundHeight);
+    pVirtualDev->SetOutputSizePixel(aVDSize);
+    pVirtualDev->SetBackground(Color(0xF0, 0xF0, 0xF0));
+    pVirtualDev->Erase();
+
+    int y = m_aPageNumberPosition ? (nBackgroundHeight - nSpriteHeight - 5) : 
5;
+    int x = 5;
+    if (m_aPageNumberAlignment == 1)
+    {
+        x = (nBackgroundWidth - nSpriteWidth) / 2;
+    }
+    else if (m_aPageNumberAlignment == 2)
+    {
+        x = nBackgroundWidth - nSpriteWidth - 5;
+    }
+    pVirtualDev->DrawText(Point(x, y), "#");
+
+    m_xPreviewImage->set_image(pVirtualDev);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/pagenumberdlg.hxx 
b/sw/source/uibase/inc/pagenumberdlg.hxx
new file mode 100644
index 000000000000..23a3c1423462
--- /dev/null
+++ b/sw/source/uibase/inc/pagenumberdlg.hxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sfx2/basedlgs.hxx>
+
+class SwWrtShell;
+
+/// Page number wizard for easy header/footer page number insertion
+class SwPageNumberDlg : public SfxDialogController
+{
+    std::unique_ptr<weld::Button> m_xOk;
+    std::unique_ptr<weld::Button> m_xCancel;
+    std::unique_ptr<weld::ComboBox> m_xPageNumberPosition;
+    std::unique_ptr<weld::ComboBox> m_xPageNumberAlignment;
+    std::unique_ptr<weld::Image> m_xPreviewImage;
+
+    int m_aPageNumberPosition;
+    int m_aPageNumberAlignment;
+
+    DECL_LINK(OkHdl, weld::Button&, void);
+    DECL_LINK(CancelHdl, weld::Button&, void);
+    DECL_LINK(PositionSelectHdl, weld::ComboBox&, void);
+    DECL_LINK(AlignmentSelectHdl, weld::ComboBox&, void);
+
+    void updateImage();
+
+public:
+    SwPageNumberDlg(weld::Window* pParent);
+    int GetPageNumberPosition() const { return m_aPageNumberPosition; }
+    int GetPageNumberAlignment() const { return m_aPageNumberAlignment; }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index 7db07202b1b2..3d97a9fbcf28 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -66,6 +66,7 @@
 #include <officecfg/Office/Compatibility.hxx>
 #include <ndtxt.hxx>
 #include <translatehelper.hxx>
+#include <sfx2/dispatch.hxx>
 
 
 using namespace nsSwDocInfoSubType;
@@ -920,6 +921,86 @@ FIELD_INSERT:
         rSh.EndAction();
         
rSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT_FORM_FIELD, 
nullptr);
     }
+    break;
+    case FN_PGNUMBER_WIZARD:
+    {
+        SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
+        VclPtr<AbstractSwPageNumberDlg> pDlg(
+                pFact->CreateSwPageNumberDlg(GetView().GetFrameWeld()));
+        auto pShell = GetShellPtr();
+        pDlg->StartExecuteAsync([pShell, &rSh, pDlg](int nResult) {
+            if ( nResult == RET_OK )
+            {
+                auto rDoc = rSh.GetDoc();
+
+                rSh.LockView(true);
+                rSh.StartAllAction();
+                rSh.SwCursorShell::Push();
+                
rDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT_PAGE_NUMBER, nullptr);
+
+                // Insert header/footer
+                bool bFooter = (pDlg->GetPageNumberPosition() == 1);
+                sal_uInt16 nPageNumberPosition = bFooter ?
+                    FN_INSERT_PAGEFOOTER : FN_INSERT_PAGEHEADER;
+                SfxBoolItem aItem(FN_PARAM_1, true);
+                rSh.GetView().GetDispatcher().ExecuteList(
+                    nPageNumberPosition,
+                    SfxCallMode::API | SfxCallMode::SYNCHRON,
+                    {&aItem}
+                );
+
+                SwTextNode* pTextNode = 
rSh.GetCursor()->GetPoint()->GetNode().GetTextNode();
+
+                // Insert new line if there is already text in header/footer
+                if (pTextNode && !pTextNode->GetText().isEmpty())
+                {
+                    
rDoc->getIDocumentContentOperations().SplitNode(*rSh.GetCursor()->GetPoint(), 
false);
+                }
+
+                // Go back to start of header/footer
+                if (bFooter)
+                    rSh.GotoFooterText();
+                else
+                    rSh.GotoHeaderText();
+
+                // Set alignment for the new line
+                switch (pDlg->GetPageNumberAlignment())
+                {
+                    case 0:
+                    {
+                        SvxAdjustItem aAdjustItem(SvxAdjust::Left, 
RES_PARATR_ADJUST);
+                        rSh.SetAttrItem(aAdjustItem);
+                        break;
+                    }
+                    case 1:
+                    {
+                        SvxAdjustItem aAdjustItem(SvxAdjust::Center, 
RES_PARATR_ADJUST);
+                        rSh.SetAttrItem(aAdjustItem);
+                        break;
+                    }
+                    case 2:
+                    {
+                        SvxAdjustItem aAdjustItem(SvxAdjust::Right, 
RES_PARATR_ADJUST);
+                        rSh.SetAttrItem(aAdjustItem);
+                        break;
+                    }
+                }
+
+                // Insert page number
+                SwFieldMgr aMgr(pShell);
+                SwInsertField_Data aData(SwFieldTypesEnum::PageNumber, 0,
+                            OUString(), OUString(), SVX_NUM_PAGEDESC);
+                aMgr.InsertField(aData);
+
+                rSh.SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent);
+                rSh.EndAllAction();
+                rSh.LockView(false);
+                
rDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT_PAGE_NUMBER, nullptr);
+            }
+            pDlg->disposeOnce();
+        });
+        rReq.Done();
+    }
     break;
         default:
             OSL_FAIL("wrong dispatcher");
diff --git a/sw/uiconfig/swriter/menubar/menubar.xml 
b/sw/uiconfig/swriter/menubar/menubar.xml
index 09df7a12dc56..9b5129e8890d 100644
--- a/sw/uiconfig/swriter/menubar/menubar.xml
+++ b/sw/uiconfig/swriter/menubar/menubar.xml
@@ -347,7 +347,7 @@
         </menu:menupopup>
       </menu:menu>
       <menu:menuseparator/>
-      <menu:menuitem menu:id=".uno:InsertPageNumberField"/>
+      <menu:menuitem menu:id=".uno:PageNumberWizard"/>
       <menu:menuitem menu:id=".uno:InsertFieldCtrl" menu:style="text"/>
       <menu:menu menu:id=".uno:InsertHeaderFooterMenu">
         <menu:menupopup>
diff --git a/sw/uiconfig/swriter/ui/pagenumberdlg.ui 
b/sw/uiconfig/swriter/ui/pagenumberdlg.ui
new file mode 100644
index 000000000000..4f46767d9491
--- /dev/null
+++ b/sw/uiconfig/swriter/ui/pagenumberdlg.ui
@@ -0,0 +1,222 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.40.0 -->
+<interface domain="sw">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkDialog" id="PageNumberDialog">
+    <property name="can-focus">False</property>
+    <property name="title" translatable="yes" 
context="pagenumberdlg|PageNumberDialog">Page Number Wizard</property>
+    <property name="resizable">False</property>
+    <property name="default-width">0</property>
+    <property name="default-height">0</property>
+    <property name="type-hint">dialog</property>
+    <property name="gravity">north-east</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="mainVBox">
+        <property name="can-focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="buttonBox">
+            <property name="can-focus">False</property>
+            <property name="layout-style">end</property>
+            <child>
+              <object class="GtkButton" id="ok">
+                <property name="label" translatable="yes" 
context="stock">_OK</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">True</property>
+                <property name="use-underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="cancel">
+                <property name="label" translatable="yes" 
context="stock">_Cancel</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">True</property>
+                <property name="use-underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="HBox">
+            <property name="visible">True</property>
+            <property name="can-focus">False</property>
+            <property name="spacing">29</property>
+            <child>
+              <object class="GtkBox" id="leftVBox">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="margin-end">10</property>
+                <property name="margin-bottom">10</property>
+                <property name="hexpand">True</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkLabel" id="positionLabel">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="halign">start</property>
+                    <property name="xpad">7</property>
+                    <property name="ypad">7</property>
+                    <property name="label" translatable="yes" 
context="pagenumberdlg|positionLabel">Position:</property>
+                    <accessibility>
+                      <relation type="label-for" target="positionCombo"/>
+                    </accessibility>
+                    <child internal-child="accessible">
+                      <object class="AtkObject" id="positionLabel-atkobject">
+                        <property name="AtkObject::accessible-name" 
translatable="yes" 
context="pagenumberdlg|positionLabel-atkobject">Position</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkComboBoxText" id="positionCombo">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="active">1</property>
+                    <items>
+                      <item translatable="yes" 
context="pagenumberdlg|liststore2">Top of page (Header)</item>
+                      <item translatable="yes" 
context="pagenumberdlg|liststore2">Bottom of page (Footer)</item>
+                    </items>
+                    <accessibility>
+                      <relation type="labelled-by" target="positionLabel"/>
+                    </accessibility>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="alignmentLabel">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="halign">start</property>
+                    <property name="xpad">7</property>
+                    <property name="ypad">7</property>
+                    <property name="label" translatable="yes" 
context="pagenumberdlg|alignmentLabel">Alignment:</property>
+                    <accessibility>
+                      <relation type="label-for" target="alignmentCombo"/>
+                    </accessibility>
+                    <child internal-child="accessible">
+                      <object class="AtkObject" id="alignmentLabel-atkobject">
+                        <property name="AtkObject::accessible-name" 
translatable="yes" 
context="pagenumberdlg|alignmentLabel-atkobject">Alignment</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkComboBoxText" id="alignmentCombo">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="active">0</property>
+                    <items>
+                      <item translatable="yes" 
context="pagenumberdlg|liststore1">Left</item>
+                      <item translatable="yes" 
context="pagenumberdlg|liststore1">Center</item>
+                      <item translatable="yes" 
context="pagenumberdlg|liststore1">Right</item>
+                    </items>
+                    <accessibility>
+                      <relation type="labelled-by" target="alignmentLabel"/>
+                    </accessibility>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="rightVBox">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="margin-end">10</property>
+                <property name="margin-bottom">10</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkLabel" id="previewLabel">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="xpad">7</property>
+                    <property name="ypad">7</property>
+                    <property name="label" translatable="yes" 
context="pagenumberdlg|previewLabel">Preview</property>
+                    <property name="justify">center</property>
+                    <accessibility>
+                      <relation type="label-for" target="previewImage"/>
+                    </accessibility>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkImage" id="previewImage">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <accessibility>
+                      <relation type="labelled-by" target="previewLabel"/>
+                    </accessibility>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-5">ok</action-widget>
+      <action-widget response="-6">cancel</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx 
b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index 35c954dc9b8a..e57f22b8e212 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -781,6 +781,8 @@ class JSImage : public JSWidget<SalInstanceImage, 
FixedImage>
 public:
     JSImage(JSDialogSender* pSender, FixedImage* pImage, SalInstanceBuilder* 
pBuilder,
             bool bTakeOwnership);
+    virtual void set_image(VirtualDevice* pDevice) override;
+    virtual void set_image(const css::uno::Reference<css::graphic::XGraphic>& 
rImage) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx
index 3b3f1e045ed3..81a1a6f4603b 100644
--- a/vcl/jsdialog/enabled.cxx
+++ b/vcl/jsdialog/enabled.cxx
@@ -77,6 +77,7 @@ bool isBuilderEnabled(std::u16string_view rUIFile, bool 
bMobile)
         || rUIFile == u"modules/swriter/ui/insertcaption.ui"
         || rUIFile == u"modules/swriter/ui/splittable.ui"
         || rUIFile == u"modules/swriter/ui/translationdialog.ui"
+        || rUIFile == u"modules/swriter/ui/pagenumberdlg.ui"
         // sfx
         || rUIFile == u"sfx/ui/cmisinfopage.ui"
         || rUIFile == u"sfx/ui/custominfopage.ui"
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 9db13c08fe9f..7d8579ba7483 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -1895,4 +1895,16 @@ JSImage::JSImage(JSDialogSender* pSender, FixedImage* 
pImage, SalInstanceBuilder
 {
 }
 
+void JSImage::set_image(VirtualDevice* pDevice)
+{
+    SalInstanceImage::set_image(pDevice);
+    sendUpdate();
+}
+
+void JSImage::set_image(const css::uno::Reference<css::graphic::XGraphic>& 
rImage)
+{
+    SalInstanceImage::set_image(rImage);
+    sendUpdate();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to