weld writer navigator

GtkToggleToolButton are much wider than vcl equivalents.  Split the bottom
toolbar into two toolbars. Rearrange their contents so the layout of each level
visually match.

Notes:

Master documents have two modes, master content tree and the normal content
tree.

You can drag entries from the content tree into the document, drag mode drop
down controls whether its a link or a copy etc that's dropped in.

Documents can be dropped into the content and global trees.

If outline tracking isn't active, then when content changes the tree is cleared
and refilled, typically an effort is made to reselect the same entry that was
previously selected. Additionally, if the amount of content didn't change an
effort is made to scroll back to the location the scrollbar was at before the
clear.

Change-Id: I00c015145eac5b1acc3398d3c40861d830e4264a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89725
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/sfx2/weldutils.hxx b/include/sfx2/weldutils.hxx
index 8c577f9..c2e05d5 100644
--- a/include/sfx2/weldutils.hxx
+++ b/include/sfx2/weldutils.hxx
@@ -24,6 +24,7 @@

namespace weld
{
class Builder;
class Toolbar;
}

@@ -33,6 +34,7 @@ private:
    css::uno::Reference<css::frame::XFrame> m_xFrame;
    SvtMiscOptions m_aToolbarOptions;
    weld::Toolbar* m_pToolbar;
    weld::Builder* m_pBuilder;

    DECL_LINK(SelectHdl, const OString&, void);
    DECL_LINK(ToggleMenuHdl, const OString&, void);
@@ -47,7 +49,7 @@ private:

public:
    // fill in the label and icons for actions and dispatch the action on item click
    ToolbarUnoDispatcher(weld::Toolbar& rToolbar,
    ToolbarUnoDispatcher(weld::Toolbar& rToolbar, weld::Builder& rBuilder,
                         const css::uno::Reference<css::frame::XFrame>& rFrame);

    css::uno::Reference<css::frame::XToolbarController>
diff --git a/include/svtools/toolboxcontroller.hxx b/include/svtools/toolboxcontroller.hxx
index b97c0e1..bcf688d 100644
--- a/include/svtools/toolboxcontroller.hxx
+++ b/include/svtools/toolboxcontroller.hxx
@@ -47,6 +47,7 @@ class ToolBox;

namespace weld
{
    class Builder;
    class Toolbar;
}

@@ -184,6 +185,7 @@ class SVT_DLLPUBLIC ToolboxController :
        css::uno::Reference< css::util::XURLTransformer >         m_xUrlTransformer;
        OUString                                                  m_sModuleName;
        weld::Toolbar*                                            m_pToolbar;
        weld::Builder*                                            m_pBuilder;
};

}
diff --git a/include/vcl/weldutils.hxx b/include/vcl/weldutils.hxx
index dc2ca29..fdc9e8c 100644
--- a/include/vcl/weldutils.hxx
+++ b/include/vcl/weldutils.hxx
@@ -27,6 +27,7 @@ class VCL_DLLPUBLIC TransportAsXWindow : public TransportAsXWindow_Base
private:
    osl::Mutex m_aHelperMtx;
    weld::Widget* m_pWeldWidget;
    weld::Builder* m_pWeldWidgetBuilder;

    comphelper::OInterfaceContainerHelper2 m_aWindowListeners;
    comphelper::OInterfaceContainerHelper2 m_aKeyListeners;
@@ -36,9 +37,10 @@ private:
    comphelper::OInterfaceContainerHelper2 m_aPaintListeners;

public:
    TransportAsXWindow(weld::Widget* pWeldWidget)
    TransportAsXWindow(weld::Widget* pWeldWidget, weld::Builder* pWeldWidgetBuilder = nullptr)
        : TransportAsXWindow_Base(m_aHelperMtx)
        , m_pWeldWidget(pWeldWidget)
        , m_pWeldWidgetBuilder(pWeldWidgetBuilder)
        , m_aWindowListeners(m_aHelperMtx)
        , m_aKeyListeners(m_aHelperMtx)
        , m_aFocusListeners(m_aHelperMtx)
@@ -50,7 +52,13 @@ public:

    weld::Widget* getWidget() const { return m_pWeldWidget; }

    virtual void clear() { m_pWeldWidget = nullptr; }
    weld::Builder* getBuilder() const { return m_pWeldWidgetBuilder; }

    virtual void clear()
    {
        m_pWeldWidget = nullptr;
        m_pWeldWidgetBuilder = nullptr;
    }

    // css::awt::XWindow
    void SAL_CALL setPosSize(sal_Int32, sal_Int32, sal_Int32, sal_Int32, sal_Int16) override
diff --git a/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx b/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx
index f5c8f7e..25ad4f1 100644
--- a/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx
+++ b/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx
@@ -58,13 +58,13 @@ AlignmentPropertyPanel::AlignmentPropertyPanel(
    , mxCBStacked(m_xBuilder->weld_check_button("stacked"))
    , mxTextOrientBox(m_xBuilder->weld_widget("textorientbox"))
    , mxHorizontalAlign(m_xBuilder->weld_toolbar("horizontalalignment"))
    , mxHorizontalAlignDispatch(new ToolbarUnoDispatcher(*mxHorizontalAlign, rxFrame))
    , mxHorizontalAlignDispatch(new ToolbarUnoDispatcher(*mxHorizontalAlign, *m_xBuilder, rxFrame))
    , mxVertAlign(m_xBuilder->weld_toolbar("verticalalignment"))
    , mxVertAlignDispatch(new ToolbarUnoDispatcher(*mxVertAlign, rxFrame))
    , mxVertAlignDispatch(new ToolbarUnoDispatcher(*mxVertAlign, *m_xBuilder, rxFrame))
    , mxWriteDirection(m_xBuilder->weld_toolbar("writedirection"))
    , mxWriteDirectionDispatch(new ToolbarUnoDispatcher(*mxWriteDirection, rxFrame))
    , mxWriteDirectionDispatch(new ToolbarUnoDispatcher(*mxWriteDirection, *m_xBuilder, rxFrame))
    , mxIndentButtons(m_xBuilder->weld_toolbar("indentbuttons"))
    , mxIndentButtonsDispatch(new ToolbarUnoDispatcher(*mxIndentButtons, rxFrame))
    , mxIndentButtonsDispatch(new ToolbarUnoDispatcher(*mxIndentButtons, *m_xBuilder, rxFrame))
    , maAlignHorControl(SID_H_ALIGNCELL, *pBindings, *this)
    , maLeftIndentControl(SID_ATTR_ALIGN_INDENT, *pBindings, *this)
    , maMergeCellControl(FID_MERGE_TOGGLE, *pBindings, *this)
diff --git a/sc/source/ui/sidebar/CellAppearancePropertyPanel.cxx b/sc/source/ui/sidebar/CellAppearancePropertyPanel.cxx
index b7e0417..b3669f5 100644
--- a/sc/source/ui/sidebar/CellAppearancePropertyPanel.cxx
+++ b/sc/source/ui/sidebar/CellAppearancePropertyPanel.cxx
@@ -51,10 +51,10 @@ CellAppearancePropertyPanel::CellAppearancePropertyPanel(

    mxTBCellBorder(m_xBuilder->weld_toolbar("cellbordertype")),
    mxTBCellBackground(m_xBuilder->weld_toolbar("cellbackgroundcolor")),
    mxBackColorDispatch(new ToolbarUnoDispatcher(*mxTBCellBackground, rxFrame)),
    mxBackColorDispatch(new ToolbarUnoDispatcher(*mxTBCellBackground, *m_xBuilder, rxFrame)),
    mxTBLineStyle(m_xBuilder->weld_toolbar("borderlinestyle")),
    mxTBLineColor(m_xBuilder->weld_toolbar("borderlinecolor")),
    mxLineColorDispatch(new ToolbarUnoDispatcher(*mxTBLineColor, rxFrame)),
    mxLineColorDispatch(new ToolbarUnoDispatcher(*mxTBLineColor, *m_xBuilder, rxFrame)),

    mbCellBorderPopoverCreated(false),
    mbLinePopoverCreated(false),
diff --git a/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx b/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx
index 653a649..ec9e665 100644
--- a/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx
+++ b/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx
@@ -37,7 +37,7 @@ NumberFormatPropertyPanel::NumberFormatPropertyPanel(
    : PanelLayout(pParent,"NumberFormatPropertyPanel", "modules/scalc/ui/sidebarnumberformat.ui", rxFrame, true)
    , mxLbCategory(m_xBuilder->weld_combo_box("category"))
    , mxTBCategory(m_xBuilder->weld_toolbar("numberformat"))
    , mxCatagoryDispatch(new ToolbarUnoDispatcher(*mxTBCategory, rxFrame))
    , mxCatagoryDispatch(new ToolbarUnoDispatcher(*mxTBCategory, *m_xBuilder, rxFrame))
    , mxFtDecimals(m_xBuilder->weld_label("decimalplaceslabel"))
    , mxEdDecimals(m_xBuilder->weld_spin_button("decimalplaces"))
    , mxFtDenominator(m_xBuilder->weld_label("denominatorplaceslabel"))
diff --git a/sfx2/inc/sidebar/ControllerFactory.hxx b/sfx2/inc/sidebar/ControllerFactory.hxx
index 66c3e43..5bfc138 100644
--- a/sfx2/inc/sidebar/ControllerFactory.hxx
+++ b/sfx2/inc/sidebar/ControllerFactory.hxx
@@ -28,7 +28,10 @@ namespace com::sun::star::frame { class XToolbarController; }

class ToolBox;

namespace weld { class Toolbar; }
namespace weld {
    class Builder;
    class Toolbar;
}

namespace sfx2 { namespace sidebar {

@@ -48,6 +51,7 @@ public:

    static css::uno::Reference<css::frame::XToolbarController> CreateToolBoxController(
        weld::Toolbar& rToolbar,
        weld::Builder& rBuilder,
        const OUString& rsCommandName,
        const css::uno::Reference<css::frame::XFrame>& rxFrame);

diff --git a/sfx2/source/dialog/recfloat.cxx b/sfx2/source/dialog/recfloat.cxx
index 28073a3..18833ea5 100644
--- a/sfx2/source/dialog/recfloat.cxx
+++ b/sfx2/source/dialog/recfloat.cxx
@@ -100,7 +100,7 @@ SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(SfxBindings* pBind, SfxChildWindo
    : SfxModelessDialogController(pBind, pChildWin, pParent, "sfx/ui/floatingrecord.ui",
                                  "FloatingRecord")
    , m_xToolbar(m_xBuilder->weld_toolbar("toolbar"))
    , m_xDispatcher(new ToolbarUnoDispatcher(*m_xToolbar, pBind->GetActiveFrame()))
    , m_xDispatcher(new ToolbarUnoDispatcher(*m_xToolbar, *m_xBuilder, pBind->GetActiveFrame()))
{
    // start recording
    SfxBoolItem aItem( SID_RECORDMACRO, true );
diff --git a/sfx2/source/sidebar/ControllerFactory.cxx b/sfx2/source/sidebar/ControllerFactory.cxx
index ef07c08..71d5a36 100644
--- a/sfx2/source/sidebar/ControllerFactory.cxx
+++ b/sfx2/source/sidebar/ControllerFactory.cxx
@@ -139,11 +139,11 @@ Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController(
}

Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController(
    weld::Toolbar& rToolbar,
    weld::Toolbar& rToolbar, weld::Builder& rBuilder,
    const OUString& rsCommandName,
    const Reference<frame::XFrame>& rxFrame)
{
    css::uno::Reference<css::awt::XWindow> xWidget(new weld::TransportAsXWindow(&rToolbar));
    css::uno::Reference<css::awt::XWindow> xWidget(new weld::TransportAsXWindow(&rToolbar, &rBuilder));

    Reference<frame::XToolbarController> xController(
        CreateToolBarController(
@@ -188,6 +188,8 @@ Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController(

    if (xController.is())
    {
        xController->createItemWindow(xWidget);

        Reference<util::XUpdatable> xUpdatable(xController, UNO_QUERY);
        if (xUpdatable.is())
            xUpdatable->update();
diff --git a/sfx2/source/toolbox/weldutils.cxx b/sfx2/source/toolbox/weldutils.cxx
index 1be8559..c35f904 100644
--- a/sfx2/source/toolbox/weldutils.cxx
+++ b/sfx2/source/toolbox/weldutils.cxx
@@ -71,10 +71,11 @@ vcl::ImageType ToolbarUnoDispatcher::GetIconSize() const
    return eType;
}

ToolbarUnoDispatcher::ToolbarUnoDispatcher(weld::Toolbar& rToolbar,
ToolbarUnoDispatcher::ToolbarUnoDispatcher(weld::Toolbar& rToolbar, weld::Builder& rBuilder,
                                           const css::uno::Reference<css::frame::XFrame>& rFrame)
    : m_xFrame(rFrame)
    , m_pToolbar(&rToolbar)
    , m_pBuilder(&rBuilder)
{
    rToolbar.connect_clicked(LINK(this, ToolbarUnoDispatcher, SelectHdl));
    rToolbar.connect_menu_toggled(LINK(this, ToolbarUnoDispatcher, ToggleMenuHdl));
@@ -112,7 +113,8 @@ ToolbarUnoDispatcher::ToolbarUnoDispatcher(weld::Toolbar& rToolbar,
void ToolbarUnoDispatcher::CreateController(const OUString& rCommand)
{
    css::uno::Reference<css::frame::XToolbarController> xController(
        sfx2::sidebar::ControllerFactory::CreateToolBoxController(*m_pToolbar, rCommand, m_xFrame));
        sfx2::sidebar::ControllerFactory::CreateToolBoxController(*m_pToolbar, *m_pBuilder,
                                                                  rCommand, m_xFrame));

    if (xController.is())
        maControllers.insert(std::make_pair(rCommand, xController));
@@ -190,6 +192,7 @@ void ToolbarUnoDispatcher::dispose()

    m_pToolbar->connect_clicked(Link<const OString&, void>());
    m_pToolbar = nullptr;
    m_pBuilder = nullptr;
}

ToolbarUnoDispatcher::~ToolbarUnoDispatcher() { dispose(); }
diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist
index 3de9010..1d5f591 100644
--- a/solenv/clang-format/blacklist
+++ b/solenv/clang-format/blacklist
@@ -15343,7 +15343,6 @@ sw/source/uibase/app/swdllimpl.hxx
sw/source/uibase/app/swmodul1.cxx
sw/source/uibase/app/swmodule.cxx
sw/source/uibase/app/swwait.cxx
sw/source/uibase/cctrl/actctrl.cxx
sw/source/uibase/chrdlg/ccoll.cxx
sw/source/uibase/config/StoredChapterNumbering.cxx
sw/source/uibase/config/barcfg.cxx
@@ -15424,7 +15423,6 @@ sw/source/uibase/inc/SidebarWindowsConsts.hxx
sw/source/uibase/inc/SwSpellDialogChildWindow.hxx
sw/source/uibase/inc/SwXFilterOptions.hxx
sw/source/uibase/inc/abstract.hxx
sw/source/uibase/inc/actctrl.hxx
sw/source/uibase/inc/annotsh.hxx
sw/source/uibase/inc/ascfldlg.hxx
sw/source/uibase/inc/barcfg.hxx
diff --git a/solenv/sanitizers/ui/modules/swriter.suppr b/solenv/sanitizers/ui/modules/swriter.suppr
index b9ebbda..004fce1 100644
--- a/solenv/sanitizers/ui/modules/swriter.suppr
+++ b/solenv/sanitizers/ui/modules/swriter.suppr
@@ -161,6 +161,8 @@ sw/uiconfig/swriter/ui/mmsendmails.ui://GtkProgressBar[@id='progress'] no-labell
sw/uiconfig/swriter/ui/mmsendmails.ui://GtkLabel[@id='errorstatus'] orphan-label
sw/uiconfig/swriter/ui/mmsalutationpage.ui://GtkLabel[@id='documentindex'] orphan-label
sw/uiconfig/swriter/ui/mmsalutationpage.ui://GtkLabel[@id='femalefi'] orphan-label
sw/uiconfig/swriter/ui/navigatorcontextmenu.ui://GtkMenuItem[@id='800'] button-no-label
sw/uiconfig/swriter/ui/navigatorpanel.ui://GtkSpinButton[@id='spinbutton'] no-labelled-by
sw/uiconfig/swriter/ui/notebookbar_groups.ui://GtkLabel[@id='filegrouplabel'] orphan-label
sw/uiconfig/swriter/ui/notebookbar_groups.ui://GtkLabel[@id='clipboardgrouplabel'] orphan-label
sw/uiconfig/swriter/ui/notebookbar_groups.ui://GtkLabel[@id='formatgrouplabel'] orphan-label
@@ -195,7 +197,6 @@ sw/uiconfig/swriter/ui/selectaddressdialog.ui://GtkLabel[@id='connecting'] orpha
sw/uiconfig/swriter/ui/selecttabledialog.ui://GtkLabel[@id='select'] orphan-label
sw/uiconfig/swriter/ui/spellmenu.ui://GtkMenuItem[@id='spelldialog'] button-no-label
sw/uiconfig/swriter/ui/spellmenu.ui://GtkMenuItem[@id='correctdialog'] button-no-label
sw/uiconfig/swriter/ui/spinbox.ui://GtkSpinButton[@id='spin'] no-labelled-by
sw/uiconfig/swriter/ui/statisticsinfopage.ui://GtkLabel[@id='nopages'] orphan-label
sw/uiconfig/swriter/ui/statisticsinfopage.ui://GtkLabel[@id='notables'] orphan-label
sw/uiconfig/swriter/ui/statisticsinfopage.ui://GtkLabel[@id='nogrfs'] orphan-label
diff --git a/svtools/source/uno/toolboxcontroller.cxx b/svtools/source/uno/toolboxcontroller.cxx
index 3ff118f..2c0292b 100644
--- a/svtools/source/uno/toolboxcontroller.cxx
+++ b/svtools/source/uno/toolboxcontroller.cxx
@@ -62,6 +62,7 @@ ToolboxController::ToolboxController(
    ,   m_aCommandURL( aCommandURL )
    ,   m_aListenerContainer( m_aMutex )
    ,   m_pToolbar(nullptr)
    ,   m_pBuilder(nullptr)
{
    OSL_ASSERT( m_xContext.is() );
    registerProperty( TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE,
@@ -87,6 +88,7 @@ ToolboxController::ToolboxController() :
    ,   m_nToolBoxId( SAL_MAX_UINT16 )
    ,   m_aListenerContainer( m_aMutex )
    ,   m_pToolbar(nullptr)
    ,   m_pBuilder(nullptr)
{
    registerProperty( TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE,
        TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE,
@@ -217,6 +219,7 @@ void SAL_CALL ToolboxController::initialize( const Sequence< Any >& aArguments )
    {
        m_pToolbar = dynamic_cast<weld::Toolbar*>(pTunnel->getWidget());
        assert(m_pToolbar && "must be a toolbar");
        m_pBuilder = pTunnel->getBuilder();
    }
}

diff --git a/svx/source/dialog/dlgctrl.cxx b/svx/source/dialog/dlgctrl.cxx
index c061aa7..f63196c 100644
--- a/svx/source/dialog/dlgctrl.cxx
+++ b/svx/source/dialog/dlgctrl.cxx
@@ -1447,7 +1447,7 @@ void padWidthForSidebar(weld::Toolbar& rToolbar, const css::uno::Reference<css::
        // of a "standard" column in a two column panel
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(&rToolbar, "svx/ui/measurewidthbar.ui"));
        std::unique_ptr<weld::Toolbar> xToolbar(xBuilder->weld_toolbar("measurewidth"));
        std::unique_ptr<ToolbarUnoDispatcher> xDispatcher(new ToolbarUnoDispatcher(*xToolbar, rFrame));
        std::unique_ptr<ToolbarUnoDispatcher> xDispatcher(new ToolbarUnoDispatcher(*xToolbar, *xBuilder, rFrame));
        nColumnWidth = xToolbar->get_preferred_size().Width();
        eSize = rToolbar.get_icon_size();
    }
diff --git a/svx/source/sidebar/area/AreaPropertyPanelBase.cxx b/svx/source/sidebar/area/AreaPropertyPanelBase.cxx
index a08ea54..270b29b 100644
--- a/svx/source/sidebar/area/AreaPropertyPanelBase.cxx
+++ b/svx/source/sidebar/area/AreaPropertyPanelBase.cxx
@@ -79,7 +79,7 @@ AreaPropertyPanelBase::AreaPropertyPanelBase(
      mxLbFillGradFrom(new ColorListBox(m_xBuilder->weld_menu_button("fillgrad1"), GetFrameWeld())),
      mxLbFillGradTo(new ColorListBox(m_xBuilder->weld_menu_button("fillgrad2"), GetFrameWeld())),
      mxToolBoxColor(m_xBuilder->weld_toolbar("selectcolor")),
      mxColorDispatch(new ToolbarUnoDispatcher(*mxToolBoxColor, rxFrame)),
      mxColorDispatch(new ToolbarUnoDispatcher(*mxToolBoxColor, *m_xBuilder, rxFrame)),
      mxTrspTextFT(m_xBuilder->weld_label("transparencylabel")),
      mxLBTransType(m_xBuilder->weld_combo_box("transtype")),
      mxMTRTransparent(m_xBuilder->weld_metric_spin_button("settransparency", FieldUnit::PERCENT)),
diff --git a/svx/source/sidebar/line/LinePropertyPanelBase.cxx b/svx/source/sidebar/line/LinePropertyPanelBase.cxx
index fe7ff32..bdb776d 100644
--- a/svx/source/sidebar/line/LinePropertyPanelBase.cxx
+++ b/svx/source/sidebar/line/LinePropertyPanelBase.cxx
@@ -75,9 +75,9 @@ LinePropertyPanelBase::LinePropertyPanelBase(
    const uno::Reference<css::frame::XFrame>& rxFrame)
:   PanelLayout(pParent, "LinePropertyPanel", "svx/ui/sidebarline.ui", rxFrame, true),
    mxTBColor(m_xBuilder->weld_toolbar("color")),
    mxColorDispatch(new ToolbarUnoDispatcher(*mxTBColor, rxFrame)),
    mxColorDispatch(new ToolbarUnoDispatcher(*mxTBColor, *m_xBuilder, rxFrame)),
    mxLineStyleTB(m_xBuilder->weld_toolbar("linestyle")),
    mxLineStyleDispatch(new ToolbarUnoDispatcher(*mxLineStyleTB, rxFrame)),
    mxLineStyleDispatch(new ToolbarUnoDispatcher(*mxLineStyleTB, *m_xBuilder, rxFrame)),
    mxFTWidth(m_xBuilder->weld_label("widthlabel")),
    mxTBWidth(m_xBuilder->weld_toolbar("width")),
    mxFTTransparency(m_xBuilder->weld_label("translabel")),
diff --git a/svx/source/sidebar/lists/ListsPropertyPanel.cxx b/svx/source/sidebar/lists/ListsPropertyPanel.cxx
index e82c3ad..cf9d94c 100644
--- a/svx/source/sidebar/lists/ListsPropertyPanel.cxx
+++ b/svx/source/sidebar/lists/ListsPropertyPanel.cxx
@@ -42,9 +42,9 @@ ListsPropertyPanel::ListsPropertyPanel(vcl::Window* pParent,
                                       const css::uno::Reference<css::frame::XFrame>& rxFrame)
    : PanelLayout(pParent, "ListsPropertyPanel", "svx/ui/sidebarlists.ui", rxFrame, true)
    , mxTBxNumBullet(m_xBuilder->weld_toolbar("numberbullet"))
    , mxNumBulletDispatcher(new ToolbarUnoDispatcher(*mxTBxNumBullet, rxFrame))
    , mxNumBulletDispatcher(new ToolbarUnoDispatcher(*mxTBxNumBullet, *m_xBuilder, rxFrame))
    , mxTBxOutline(m_xBuilder->weld_toolbar("outline"))
    , mxOutlineDispatcher(new ToolbarUnoDispatcher(*mxTBxOutline, rxFrame))
    , mxOutlineDispatcher(new ToolbarUnoDispatcher(*mxTBxOutline, *m_xBuilder, rxFrame))
{
}

diff --git a/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx b/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx
index 75d376e..dd39f05 100644
--- a/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx
+++ b/svx/source/sidebar/paragraph/ParaPropertyPanel.cxx
@@ -406,22 +406,22 @@ ParaPropertyPanel::ParaPropertyPanel(vcl::Window* pParent,
    : PanelLayout(pParent, "ParaPropertyPanel", "svx/ui/sidebarparagraph.ui", rxFrame, true),
      //Alignment
      mxTBxHorzAlign(m_xBuilder->weld_toolbar("horizontalalignment")),
      mxHorzAlignDispatch(new ToolbarUnoDispatcher(*mxTBxHorzAlign, rxFrame)),
      mxHorzAlignDispatch(new ToolbarUnoDispatcher(*mxTBxHorzAlign, *m_xBuilder, rxFrame)),
      mxTBxVertAlign(m_xBuilder->weld_toolbar("verticalalignment")),
      mxVertAlignDispatch(new ToolbarUnoDispatcher(*mxTBxVertAlign, rxFrame)),
      mxVertAlignDispatch(new ToolbarUnoDispatcher(*mxTBxVertAlign, *m_xBuilder, rxFrame)),
      //NumBullet&Backcolor
      mxTBxNumBullet(m_xBuilder->weld_toolbar("numberbullet")),
      mxNumBulletDispatch(new ToolbarUnoDispatcher(*mxTBxNumBullet, rxFrame)),
      mxNumBulletDispatch(new ToolbarUnoDispatcher(*mxTBxNumBullet, *m_xBuilder, rxFrame)),
      mxTBxBackColor(m_xBuilder->weld_toolbar("backgroundcolor")),
      mxBackColorDispatch(new ToolbarUnoDispatcher(*mxTBxBackColor, rxFrame)),
      mxBackColorDispatch(new ToolbarUnoDispatcher(*mxTBxBackColor, *m_xBuilder, rxFrame)),
      mxTBxWriteDirection(m_xBuilder->weld_toolbar("writedirection")),
      mxWriteDirectionDispatch(new ToolbarUnoDispatcher(*mxTBxWriteDirection, rxFrame)),
      mxWriteDirectionDispatch(new ToolbarUnoDispatcher(*mxTBxWriteDirection, *m_xBuilder, rxFrame)),
      mxTBxParaSpacing(m_xBuilder->weld_toolbar("paraspacing")),
      mxParaSpacingDispatch(new ToolbarUnoDispatcher(*mxTBxParaSpacing, rxFrame)),
      mxParaSpacingDispatch(new ToolbarUnoDispatcher(*mxTBxParaSpacing, *m_xBuilder, rxFrame)),
      mxTBxLineSpacing(m_xBuilder->weld_toolbar("linespacing")),
      mxLineSpacingDispatch(new ToolbarUnoDispatcher(*mxTBxLineSpacing, rxFrame)),
      mxLineSpacingDispatch(new ToolbarUnoDispatcher(*mxTBxLineSpacing, *m_xBuilder, rxFrame)),
      mxTBxIndent(m_xBuilder->weld_toolbar("indent")),
      mxIndentDispatch(new ToolbarUnoDispatcher(*mxTBxIndent, rxFrame)),
      mxIndentDispatch(new ToolbarUnoDispatcher(*mxTBxIndent, *m_xBuilder, rxFrame)),
      //Paragraph spacing
      mxTopDist(new SvxRelativeField(m_xBuilder->weld_metric_spin_button("aboveparaspacing", FieldUnit::CM))),
      mxBottomDist(new SvxRelativeField(m_xBuilder->weld_metric_spin_button("belowparaspacing", FieldUnit::CM))),
diff --git a/svx/source/sidebar/possize/PosSizePropertyPanel.cxx b/svx/source/sidebar/possize/PosSizePropertyPanel.cxx
index 18be1aa..0f0697a4 100644
--- a/svx/source/sidebar/possize/PosSizePropertyPanel.cxx
+++ b/svx/source/sidebar/possize/PosSizePropertyPanel.cxx
@@ -70,9 +70,9 @@ PosSizePropertyPanel::PosSizePropertyPanel(
    mxDial(new weld::CustomWeld(*m_xBuilder, "orientationcontrol", *mxCtrlDial)),
    mxFtFlip(m_xBuilder->weld_label("fliplabel")),
    mxFlipTbx(m_xBuilder->weld_toolbar("selectrotationtype")),
    mxFlipDispatch(new ToolbarUnoDispatcher(*mxFlipTbx, rxFrame)),
    mxFlipDispatch(new ToolbarUnoDispatcher(*mxFlipTbx, *m_xBuilder, rxFrame)),
    mxArrangeTbx(m_xBuilder->weld_toolbar("arrangetoolbar")),
    mxArrangeDispatch(new ToolbarUnoDispatcher(*mxArrangeTbx, rxFrame)),
    mxArrangeDispatch(new ToolbarUnoDispatcher(*mxArrangeTbx, *m_xBuilder, rxFrame)),
    mxBtnEditChart(m_xBuilder->weld_button("btnEditChart")),
    maRect(),
    mpView(nullptr),
diff --git a/svx/source/tbxctrls/fillctrl.cxx b/svx/source/tbxctrls/fillctrl.cxx
index 8ae4bf5..8b1339a 100644
--- a/svx/source/tbxctrls/fillctrl.cxx
+++ b/svx/source/tbxctrls/fillctrl.cxx
@@ -560,7 +560,7 @@ FillControl::FillControl(vcl::Window* pParent, const css::uno::Reference<css::fr
    : InterimItemWindow(pParent, "svx/ui/fillctrlbox.ui", "FillCtrlBox")
    , mxLbFillType(m_xBuilder->weld_combo_box("type"))
    , mxToolBoxColor(m_xBuilder->weld_toolbar("color"))
    , mxColorDispatch(new ToolbarUnoDispatcher(*mxToolBoxColor, rFrame))
    , mxColorDispatch(new ToolbarUnoDispatcher(*mxToolBoxColor, *m_xBuilder, rFrame))
    , mxLbFillAttr(m_xBuilder->weld_combo_box("attr"))
    , mnTypeCurPos(0)
    , mnAttrCurPos(0)
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index ec4c3eb..b6d75fd 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -588,7 +588,6 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
    sw/source/uibase/dbui/maildispatcher \
    sw/source/uibase/dbui/mailmergehelper \
    sw/source/uibase/dbui/mmconfigitem \
    sw/source/uibase/cctrl/actctrl \
    sw/source/uibase/chrdlg/ccoll \
    sw/source/uibase/config/StoredChapterNumbering \
    sw/source/uibase/config/barcfg \
diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk
index 872de3c9..ea417c9 100644
--- a/sw/UIConfig_swriter.mk
+++ b/sw/UIConfig_swriter.mk
@@ -209,6 +209,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
	sw/uiconfig/swriter/ui/querysavelabeldialog \
	sw/uiconfig/swriter/ui/mailmerge \
	sw/uiconfig/swriter/ui/managechangessidebar \
	sw/uiconfig/swriter/ui/mastercontextmenu \
	sw/uiconfig/swriter/ui/mmaddressblockpage \
	sw/uiconfig/swriter/ui/mmcreatingdialog \
	sw/uiconfig/swriter/ui/mmlayoutpage \
@@ -220,6 +221,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
	sw/uiconfig/swriter/ui/mmselectpage \
	sw/uiconfig/swriter/ui/mmsendmails \
	sw/uiconfig/swriter/ui/mmsalutationpage \
	sw/uiconfig/swriter/ui/navigatorcontextmenu \
	sw/uiconfig/swriter/ui/navigatorpanel \
	sw/uiconfig/swriter/ui/notebookbar \
	sw/uiconfig/swriter/ui/notebookbar_compact \
@@ -266,7 +268,6 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
	sw/uiconfig/swriter/ui/sidebartableedit \
	sw/uiconfig/swriter/ui/sidebartheme \
	sw/uiconfig/swriter/ui/sortdialog \
	sw/uiconfig/swriter/ui/spinbox \
	sw/uiconfig/swriter/ui/spellmenu \
	sw/uiconfig/swriter/ui/splittable \
	sw/uiconfig/swriter/ui/statisticsinfopage \
diff --git a/sw/inc/pch/precompiled_msword.hxx b/sw/inc/pch/precompiled_msword.hxx
index 3e8c55b..7271e76 100644
--- a/sw/inc/pch/precompiled_msword.hxx
+++ b/sw/inc/pch/precompiled_msword.hxx
@@ -13,7 +13,7 @@
 manual changes will be rewritten by the next run of update_pch.sh (which presumably
 also fixes all possible problems, so it's usually better to use it).

 Generated on 2020-02-17 14:43:22 using:
 Generated on 2020-03-04 21:21:56 using:
 ./bin/update_pch sw msword --cutoff=4 --exclude:system --include:module --include:local

 If after updating build fails, use the following command to locate conflicting headers:
@@ -43,6 +43,7 @@
#include <math.h>
#include <memory>
#include <new>
#include <optional>
#include <ostream>
#include <set>
#include <stddef.h>
@@ -55,6 +56,12 @@
#include <unordered_set>
#include <utility>
#include <vector>
#include <boost/multi_index/composite_key.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#endif // PCH_LEVEL >= 1
#if PCH_LEVEL >= 2
@@ -340,7 +347,6 @@
#include <i18nutil/transliteration.hxx>
#include <o3tl/cow_wrapper.hxx>
#include <o3tl/enumarray.hxx>
#include <optional>
#include <o3tl/safeint.hxx>
#include <o3tl/sorted_vector.hxx>
#include <o3tl/strong_int.hxx>
diff --git a/sw/inc/pch/precompiled_sw.hxx b/sw/inc/pch/precompiled_sw.hxx
index bfd07f2..90cb78e 100644
--- a/sw/inc/pch/precompiled_sw.hxx
+++ b/sw/inc/pch/precompiled_sw.hxx
@@ -13,7 +13,7 @@
 manual changes will be rewritten by the next run of update_pch.sh (which presumably
 also fixes all possible problems, so it's usually better to use it).

 Generated on 2020-02-17 14:43:31 using:
 Generated on 2020-03-04 21:22:05 using:
 ./bin/update_pch sw sw --cutoff=7 --exclude:system --exclude:module --include:local

 If after updating build fails, use the following command to locate conflicting headers:
@@ -35,6 +35,7 @@
#include <map>
#include <memory>
#include <new>
#include <optional>
#include <ostream>
#include <set>
#include <stddef.h>
@@ -68,6 +69,9 @@
#include <rtl/math.hxx>
#include <rtl/ref.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/string.h>
#include <rtl/stringconcat.hxx>
#include <rtl/stringutils.hxx>
#include <rtl/tencinfo.h>
#include <rtl/textenc.h>
#include <rtl/unload.h>
@@ -103,7 +107,6 @@
#include <vcl/imap.hxx>
#include <vcl/imapobj.hxx>
#include <vcl/keycod.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/metric.hxx>
#include <vcl/outdev.hxx>
#include <vcl/settings.hxx>
@@ -274,7 +277,6 @@
#include <o3tl/any.hxx>
#include <o3tl/cow_wrapper.hxx>
#include <o3tl/deleter.hxx>
#include <optional>
#include <o3tl/safeint.hxx>
#include <o3tl/sorted_vector.hxx>
#include <o3tl/strong_int.hxx>
@@ -365,6 +367,7 @@
#include <svx/svdoutl.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdtypes.hxx>
#include <svx/svdview.hxx>
#include <svx/svxdlg.hxx>
#include <svx/svxdllapi.h>
@@ -532,6 +535,7 @@
#include <fmtwrapinfluenceonobjpos.hxx>
#include <fntcache.hxx>
#include <frame.hxx>
#include <frameformats.hxx>
#include <frmatr.hxx>
#include <frmfmt.hxx>
#include <frmmgr.hxx>
diff --git a/sw/inc/pch/precompiled_swui.hxx b/sw/inc/pch/precompiled_swui.hxx
index 39909eb..cc71c3c 100644
--- a/sw/inc/pch/precompiled_swui.hxx
+++ b/sw/inc/pch/precompiled_swui.hxx
@@ -13,7 +13,7 @@
 manual changes will be rewritten by the next run of update_pch.sh (which presumably
 also fixes all possible problems, so it's usually better to use it).

 Generated on 2020-02-19 12:45:34 using:
 Generated on 2020-03-04 21:22:13 using:
 ./bin/update_pch sw swui --cutoff=3 --exclude:system --include:module --include:local

 If after updating build fails, use the following command to locate conflicting headers:
@@ -40,6 +40,7 @@
#include <math.h>
#include <memory>
#include <new>
#include <optional>
#include <ostream>
#include <set>
#include <stack>
@@ -52,12 +53,6 @@
#include <unordered_map>
#include <utility>
#include <vector>
#include <boost/multi_index/composite_key.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#endif // PCH_LEVEL >= 1
#if PCH_LEVEL >= 2
@@ -100,6 +95,7 @@
#include <vcl/GraphicExternalLink.hxx>
#include <vcl/GraphicObject.hxx>
#include <vcl/IDialogRenderable.hxx>
#include <vcl/ITiledRenderable.hxx>
#include <vcl/NotebookBarAddonsMerger.hxx>
#include <vcl/Scanline.hxx>
#include <vcl/accessibletableprovider.hxx>
@@ -312,6 +308,7 @@
#include <com/sun/star/view/XPrintJobBroadcaster.hpp>
#include <com/sun/star/view/XPrintable.hpp>
#include <comphelper/comphelperdllapi.h>
#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/servicehelper.hxx>
#include <comphelper/string.hxx>
@@ -367,7 +364,6 @@
#include <i18nutil/transliteration.hxx>
#include <o3tl/cow_wrapper.hxx>
#include <o3tl/deleter.hxx>
#include <optional>
#include <o3tl/safeint.hxx>
#include <o3tl/sorted_vector.hxx>
#include <o3tl/strong_int.hxx>
@@ -398,6 +394,7 @@
#include <sfx2/shell.hxx>
#include <sfx2/tabdlg.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/viewsh.hxx>
#include <sot/exchange.hxx>
#include <sot/formats.hxx>
#include <sot/sotdllapi.h>
diff --git a/sw/inc/pch/precompiled_vbaswobj.hxx b/sw/inc/pch/precompiled_vbaswobj.hxx
index 26ed24e..c32c83e 100644
--- a/sw/inc/pch/precompiled_vbaswobj.hxx
+++ b/sw/inc/pch/precompiled_vbaswobj.hxx
@@ -13,7 +13,7 @@
 manual changes will be rewritten by the next run of update_pch.sh (which presumably
 also fixes all possible problems, so it's usually better to use it).

 Generated on 2020-02-14 09:24:51 using:
 Generated on 2020-03-04 21:22:17 using:
 ./bin/update_pch sw vbaswobj --cutoff=4 --exclude:system --include:module --include:local

 If after updating build fails, use the following command to locate conflicting headers:
@@ -43,6 +43,7 @@
#include <math.h>
#include <memory>
#include <new>
#include <optional>
#include <ostream>
#include <set>
#include <stack>
@@ -55,12 +56,6 @@
#include <unordered_map>
#include <utility>
#include <vector>
#include <boost/multi_index/composite_key.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#endif // PCH_LEVEL >= 1
#if PCH_LEVEL >= 2
@@ -247,7 +242,6 @@
#include <editeng/svxenum.hxx>
#include <i18nlangtag/lang.h>
#include <o3tl/cow_wrapper.hxx>
#include <optional>
#include <o3tl/sorted_vector.hxx>
#include <o3tl/strong_int.hxx>
#include <o3tl/typed_flags_set.hxx>
diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index 4b5c0d7..dfb17c4 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -647,12 +647,7 @@
#define STR_OUTLINE_TRACKING_DEFAULT            NC_("STR_OUTLINE_TRACKING_DEFAULT", "Default")
#define STR_OUTLINE_TRACKING_FOCUS              NC_("STR_OUTLINE_TRACKING_FOCUS", "Focus")
#define STR_OUTLINE_TRACKING_OFF                NC_("STR_OUTLINE_TRACKING_OFF", "Off")
#define STR_GOTO                                NC_("STR_GOTO", "Go to")
#define STR_SELECT                              NC_("STR_SELECT", "Select")
#define STR_DEMOTE_CHAPTER                      NC_("STR_DEMOTE_CHAPTER", "Demote Chapter")
#define STR_PROMOTE_CHAPTER                     NC_("STR_PROMOTE_CHAPTER", "Promote Chapter")
#define STR_DEMOTE_LEVEL                        NC_("STR_DEMOTE_LEVEL", "Demote Level")
#define STR_PROMOTE_LEVEL                       NC_("STR_PROMOTE_LEVEL", "Promote Level")

#define STR_EXPANDALL                           NC_("STR_EXPANDALL", "Expand All")
#define STR_COLLAPSEALL                         NC_("STR_COLLAPSEALL", "Collapse All")
#define STR_HYPERLINK                           NC_("STR_HYPERLINK", "Insert as Hyperlink")
@@ -678,15 +673,10 @@
#define STR_UPDATE_INDEX                        NC_("STR_UPDATE_INDEX", "Indexes")
#define STR_UPDATE_LINK                         NC_("STR_UPDATE_LINK", "Links")
#define STR_UPDATE_ALL                          NC_("STR_UPDATE_ALL", "All")
#define STR_REMOVE_INDEX                        NC_("STR_REMOVE_INDEX", "~Remove Index")
#define STR_REMOVE_TBL_PROTECTION               NC_("STR_REMOVE_TBL_PROTECTION", "~Unprotect")

#define STR_INVISIBLE                           NC_("STR_INVISIBLE", "hidden")
#define STR_BROKEN_LINK                         NC_("STR_BROKEN_LINK", "File not found: ")
#define STR_RENAME                              NC_("STR_RENAME", "~Rename...")
#define STR_READONLY_IDX                        NC_("STR_READONLY_IDX", "Read-~only")
#define STR_POSTIT_SHOW                         NC_("STR_POSTIT_SHOW", "Show All")
#define STR_POSTIT_HIDE                         NC_("STR_POSTIT_HIDE", "Hide All")
#define STR_POSTIT_DELETE                       NC_("STR_POSTIT_DELETE", "Delete All")

#define STR_RESOLVED                            NC_("STR_RESOLVED", "RESOLVED")
#define STR_PROTECTED                           NC_("STR_PROTECTED", "Protected")

diff --git a/sw/source/uibase/cctrl/actctrl.cxx b/sw/source/uibase/cctrl/actctrl.cxx
deleted file mode 100644
index 62bfe65..0000000
--- a/sw/source/uibase/cctrl/actctrl.cxx
+++ /dev/null
@@ -1,49 +0,0 @@
/* -*- 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 <actctrl.hxx>
#include <vcl/event.hxx>
#include <vcl/toolbox.hxx>

NumEditAction::NumEditAction(vcl::Window* pParent)
    : InterimItemWindow(pParent, "modules/swriter/ui/spinbox.ui", "SpinBox")
    , m_xWidget(m_xBuilder->weld_spin_button("spin"))
{
    m_xWidget->connect_key_press(LINK(this, NumEditAction, KeyInputHdl));
    limitWidth();
    SetSizePixel(m_xContainer->get_preferred_size());
}

void NumEditAction::limitWidth()
{
    m_xWidget->set_width_chars(3);
}

void NumEditAction::set_max(int nMax)
{
    m_xWidget->set_max(nMax);
    limitWidth();
}

IMPL_LINK(NumEditAction, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
    return ChildKeyInput(rKEvt);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/actctrl.hxx b/sw/source/uibase/inc/actctrl.hxx
deleted file mode 100644
index fdb2feb..0000000
--- a/sw/source/uibase/inc/actctrl.hxx
+++ /dev/null
@@ -1,82 +0,0 @@
/* -*- 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 .
 */
#ifndef INCLUDED_SW_SOURCE_UIBASE_INC_ACTCTRL_HXX
#define INCLUDED_SW_SOURCE_UIBASE_INC_ACTCTRL_HXX

#include <sfx2/InterimItemWindow.hxx>
#include <vcl/weld.hxx>
#include <swdllapi.h>

// numerical input
class NumEditAction final : public InterimItemWindow
{
private:
    std::unique_ptr<weld::SpinButton> m_xWidget;

    DECL_LINK(KeyInputHdl, const KeyEvent&, bool);

public:
    NumEditAction(vcl::Window* pParent);

    virtual void dispose() override
    {
        m_xWidget.reset();
        InterimItemWindow::dispose();
    }

    virtual ~NumEditAction() override
    {
        disposeOnce();
    }

    virtual void GetFocus() override
    {
        if (m_xWidget)
            m_xWidget->grab_focus();
        InterimItemWindow::GetFocus();
    }

    void connect_value_changed(const Link<weld::SpinButton&, void>& rLink)
    {
        m_xWidget->connect_value_changed(rLink);
    }

    int get_value() const
    {
        return m_xWidget->get_value();
    }

    void set_value(int nValue)
    {
        m_xWidget->set_value(nValue);
    }

    void set_accessible_name(const OUString& rName)
    {
        m_xWidget->set_accessible_name(rName);
    }

    void set_max(int nMax);

    void limitWidth();
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/conttree.hxx b/sw/source/uibase/inc/conttree.hxx
index 3cb48bc..8df6285 100644
--- a/sw/source/uibase/inc/conttree.hxx
+++ b/sw/source/uibase/inc/conttree.hxx
@@ -20,8 +20,7 @@
#define INCLUDED_SW_SOURCE_UIBASE_INC_CONTTREE_HXX

#include <svl/lstner.hxx>
#include <vcl/treelistbox.hxx>
#include <vcl/svlbitm.hxx>
#include <ndarr.hxx>
#include "swcont.hxx"

#include <map>
@@ -67,11 +66,25 @@ namespace o3tl {
    template<> struct typed_flags<MenuEnableFlags> : is_typed_flags<MenuEnableFlags, 0x00ff> {};
}

/** TreeListBox for content indicator */
class SwContentTree final
    : public SvTreeListBox
    , public SfxListener
class SwContentTree;

class SwContentTreeDropTarget : public DropTargetHelper
{
private:
    SwContentTree& m_rTreeView;

    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;

public:
    SwContentTreeDropTarget(SwContentTree& rTreeView);
};

/** TreeListBox for content indicator */
class SwContentTree final : public SfxListener
{
    std::unique_ptr<weld::TreeView> m_xTreeView;
    SwContentTreeDropTarget m_aDropTargetHelper;
    VclPtr<SwNavigationPI> m_xDialog;
    OUString            m_sSpace;
    AutoTimer           m_aUpdTimer;
@@ -79,16 +92,7 @@ class SwContentTree final
    o3tl::enumarray<ContentTypeId,std::unique_ptr<SwContentType>>  m_aActiveContentArr;
    o3tl::enumarray<ContentTypeId,std::unique_ptr<SwContentType>>  m_aHiddenContentArr;
    OUString            m_aContextStrings[CONTEXT_COUNT + 1];
    OUString            m_sRemoveIdx;
    OUString            m_sUpdateIdx;
    OUString            m_sUnprotTable;
    OUString            m_sRename;
    OUString            m_sReadonlyIdx;
    OUString            m_sInvisible;
    OUString            m_sPostItShow;
    OUString            m_sPostItHide;
    OUString            m_sPostItDelete;
    OUString            m_sProtected;

    SwWrtShell*         m_pHiddenShell;   // dropped Doc
    SwWrtShell*         m_pActiveShell;   // the active or a const. open view
@@ -98,6 +102,7 @@ class SwContentTree final

    sal_Int32           m_nActiveBlock;
    sal_Int32           m_nHiddenBlock;
    size_t              m_nEntryCount;
    ContentTypeId       m_nRootType;
    ContentTypeId       m_nLastSelType;
    sal_uInt8           m_nOutlineLevel;
@@ -107,20 +112,14 @@ class SwContentTree final
    enum class State { ACTIVE, CONSTANT, HIDDEN } m_eState;

    bool                m_bDocChgdInDragging  :1;
    bool                m_bIsInternalDrag     :1;
    bool                m_bIsRoot             :1;
    bool                m_bIsIdleClear        :1;
    bool                m_bIsLastReadOnly     :1;
    bool                m_bIsOutlineMoveable  :1;
    bool                m_bViewHasChanged     :1;

    static bool         bIsInDrag;

    bool                m_bIsKeySpace;
    tools::Rectangle           m_aOldRectangle;

    // outline root mode drag & drop
    std::vector< SvTreeListEntry* > m_aDndOutlinesSelected;
    std::vector<std::unique_ptr<weld::TreeIter>> m_aDndOutlinesSelected;

    bool m_bIsInPromoteDemote = false;

@@ -130,60 +129,57 @@ class SwContentTree final
     */
    void                FindActiveTypeAndRemoveUserData();

    using SvTreeListBox::ExecuteDrop;
    using SvTreeListBox::EditEntry;
    void insert(const weld::TreeIter* pParent, const OUString& rStr, const OUString& rId,
                const OUString* pExpanderName, bool bChildrenOnDemand, weld::TreeIter* pRet);

    virtual void    RequestHelp( const HelpEvent& rHEvt ) override;
    virtual void    InitEntry(SvTreeListEntry*, const OUString&, const Image&, const Image&) override;
    virtual void    DataChanged( const DataChangedEvent& rDCEvt ) override;
    void remove(const weld::TreeIter& rIter);

    SwNavigationPI* GetParentWindow();

    virtual void    StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
    virtual void    DragFinished( sal_Int8 ) override;
    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;

    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;

    bool        FillTransferData( TransferDataContainer& rTransfer,
                                            sal_Int8& rDragMode );

    /** Check if the displayed content is valid. */
    bool            HasContentChanged();

    virtual DragDropMode NotifyStartDrag( TransferDataContainer& rData,
                                        SvTreeListEntry* ) override;
    virtual bool    NotifyAcceptDrop( SvTreeListEntry* ) override;
    size_t          GetAbsPos(const weld::TreeIter& rIter);

    virtual TriState NotifyMoving(   SvTreeListEntry*  pTarget,
                                    SvTreeListEntry*  pEntry,
                                    SvTreeListEntry*& rpNewParent,
                                    sal_uLong&        rNewChildPos
                                ) override;
    virtual TriState NotifyCopying(  SvTreeListEntry*  pTarget,
                                    SvTreeListEntry*  pEntry,
                                    SvTreeListEntry*& rpNewParent,
                                    sal_uLong&        rNewChildPos
                                ) override;
    virtual void    Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
    virtual void    MouseButtonDown( const MouseEvent& rMEvt ) override;

    void            EditEntry( SvTreeListEntry const * pEntry, EditEntryMode nMode );
    void            EditEntry(const weld::TreeIter& rEntry, EditEntryMode nMode);

    void            GotoContent(const SwContent* pCnt);
    static void     SetInDrag(bool bSet) {bIsInDrag = bSet;}

    virtual VclPtr<PopupMenu> CreateContextMenu() override;
    virtual void    ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) override;
    void            ExecuteContextMenuAction(const OString& rSelectedPopupEntry);

    void DeleteOutlineSelections();

    size_t GetEntryCount() const;

    size_t GetChildCount(const weld::TreeIter& rParent) const;

    std::unique_ptr<weld::TreeIter> GetEntryAtAbsPos(size_t nAbsPos) const;

    void Expand(const weld::TreeIter& rParent, std::vector<std::unique_ptr<weld::TreeIter>>* pNodesToExpand);

    void MoveOutline(SwOutlineNodes::size_type nTargetPos);

    void UpdateLastSelType();

    /** Expand - Remember the state for content types */
    DECL_LINK(ExpandHdl, const weld::TreeIter&, bool);
    /** Collapse - Remember the state for content types. */
    DECL_LINK(CollapseHdl, const weld::TreeIter&, bool);
    DECL_LINK(ContentDoubleClickHdl, weld::TreeView&, bool);
    DECL_LINK(SelectHdl, weld::TreeView&, void);
    DECL_LINK(FocusHdl, weld::Widget&, void);
    DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
    DECL_LINK(CommandHdl, const CommandEvent&, bool);
    DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
    DECL_LINK(DragBeginHdl, bool&, bool);
    DECL_LINK(TimerUpdate, Timer *, void);

public:
    SwContentTree(vcl::Window* pParent, SwNavigationPI* pDialog);
    virtual ~SwContentTree() override;
    virtual void dispose() override;
    OUString        GetEntryAltText( SvTreeListEntry* pEntry ) const override;
    OUString        GetEntryLongDescription( SvTreeListEntry* pEntry ) const override;
    SwContentTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog);
    ~SwContentTree();
    SdrObject*      GetDrawingObjectsByContent(const SwContent *pCnt);

    /** Switch the display to Root */
@@ -192,8 +188,8 @@ public:

    /** Show the file */
    void            Display( bool bActiveView );
    /** In the Clear the content types have to be deleted, also. */
    void            Clear();
    /** In the clear the content types have to be deleted, also. */
    void            clear();

    /** After a file is dropped on the Navigator, the new shell will be set */
    void            SetHiddenShell(SwWrtShell* pSh);
@@ -209,18 +205,13 @@ public:
    SwWrtShell*     GetWrtShell()
        { return State::HIDDEN == m_eState ? m_pHiddenShell : m_pActiveShell; }

    static bool     IsInDrag() {return bIsInDrag;}
    bool            IsInDrag() const;

    sal_uInt8       GetOutlineLevel()const {return m_nOutlineLevel;}
    void            SetOutlineLevel(sal_uInt8 nSet);

    /** Expand - Remember the state for content types */
    virtual bool    Expand( SvTreeListEntry* pParent ) override;
    /** Collapse - Remember the state for content types. */
    virtual bool    Collapse( SvTreeListEntry* pParent ) override;

    /** Execute commands of the Navigator */
    void            ExecCommand(const OUString& rCmd, bool bModifier);
    void            ExecCommand(const OString& rCmd, bool bModifier);

    void            ShowTree();
    void            HideTree();
@@ -232,56 +223,79 @@ public:
    const SwWrtShell*   GetActiveWrtShell() const {return m_pActiveShell;}
    SwWrtShell*         GetHiddenWrtShell() {return m_pHiddenShell;}

    DECL_LINK( ContentDoubleClickHdl, SvTreeListBox*, bool );
    DECL_LINK( TimerUpdate, Timer *, void );
    void Select();

    virtual sal_IntPtr GetTabPos( SvTreeListEntry*, SvLBoxTab* ) override;
    virtual void    RequestingChildren( SvTreeListEntry* pParent ) override;
    virtual void    GetFocus() override;
    virtual void    KeyInput(const KeyEvent& rKEvt) override;

    virtual bool    Select( SvTreeListEntry* pEntry, bool bSelect=true ) override;
    virtual Size    GetOptimalSize() const override;
    // return true if it has any children
    bool RequestingChildren(const weld::TreeIter& rParent);

    virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override;

};
    sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt);
    sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt);

// TreeListBox for global documents

class SwLBoxString : public SvLBoxString
{
public:

    SwLBoxString( const OUString& rStr ) : SvLBoxString(rStr)
    bool IsDropFormatSupported(SotClipboardFormatId nFormat)
    {
        return m_aDropTargetHelper.IsDropFormatSupported(nFormat);
    }

    virtual void Paint(const Point& rPos, SvTreeListBox& rDev, vcl::RenderContext& rRenderContext,
                       const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) override;
    void set_accessible_name(const OUString& rName)
    {
        m_xTreeView->set_accessible_name(rName);
    }

    void grab_focus()
    {
        m_xTreeView->grab_focus();
    }

    int count_selected_rows() const
    {
        return m_xTreeView->count_selected_rows();
    }

    void set_selection_mode(SelectionMode eMode)
    {
        m_xTreeView->set_selection_mode(eMode);
    }

    weld::TreeView& get_widget()
    {
        return *m_xTreeView;
    }
};

namespace sfx2 { class DocumentInserter; }
namespace sfx2 { class FileDialogHelper; }

class SwGlobalTree final : public SvTreeListBox
class SwGlobalTree;

class SwGlobalTreeDropTarget : public DropTargetHelper
{
private:
    SwGlobalTree& m_rTreeView;

    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;

public:
    SwGlobalTreeDropTarget(SwGlobalTree& rTreeView);
};

class SwGlobalTree final
{
private:
    std::unique_ptr<weld::TreeView> m_xTreeView;
    SwGlobalTreeDropTarget  m_aDropTargetHelper;
    VclPtr<SwNavigationPI>  m_xDialog;
    AutoTimer               m_aUpdateTimer;
    OUString                m_aContextStrings[GLOBAL_CONTEXT_COUNT];

    SwWrtShell*             m_pActiveShell;
    SvTreeListEntry*        m_pEmphasisEntry; // Drag'n Drop emphasis
    SvTreeListEntry*        m_pDDSource;      // source for Drag'n Drop
    std::unique_ptr<SwGlblDocContents> m_pSwGlblDocContents; // array with sorted content

    std::unique_ptr<SwGlblDocContent>       m_pDocContent;
    std::unique_ptr<sfx2::DocumentInserter> m_pDocInserter;

    bool                m_bIsInternalDrag     :1;
    bool                m_bLastEntryEmphasis  :1; // Drag'n Drop

    static const SfxObjectShell* pShowShell;

    void        InsertRegion( const SwGlblDocContent* _pContent,
@@ -289,48 +303,15 @@ private:

    DECL_LINK(  DialogClosedHdl, sfx2::FileDialogHelper*, void );

    using SvTreeListBox::DoubleClickHdl;
    using SvTreeListBox::ExecuteDrop;
    using Window::Update;
    void Select();

    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;

    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;

    virtual void    DataChanged( const DataChangedEvent& rDCEvt ) override;

    virtual void    RequestHelp( const HelpEvent& rHEvt ) override;

    virtual sal_IntPtr GetTabPos( SvTreeListEntry*, SvLBoxTab* ) override;
    virtual TriState NotifyMoving(   SvTreeListEntry*  pTarget,
                                    SvTreeListEntry*  pEntry,
                                    SvTreeListEntry*& rpNewParent,
                                    sal_uLong&        rNewChildPos
                                ) override;
    virtual TriState NotifyCopying(  SvTreeListEntry*  pTarget,
                                    SvTreeListEntry*  pEntry,
                                    SvTreeListEntry*& rpNewParent,
                                    sal_uLong&        rNewChildPos
                                ) override;

    virtual void    StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override;
    virtual void    DragFinished( sal_Int8 ) override;
    virtual DragDropMode NotifyStartDrag( TransferDataContainer& rData,
                                        SvTreeListEntry* ) override;
    virtual bool    NotifyAcceptDrop( SvTreeListEntry* ) override;

    virtual void    MouseButtonDown( const MouseEvent& rMEvt ) override;
    virtual void    KeyInput(const KeyEvent& rKEvt) override;
    virtual void    GetFocus() override;
    virtual void    SelectHdl() override;
    virtual void    DeselectHdl() override;
    virtual void    InitEntry(SvTreeListEntry*, const OUString&, const Image&, const Image&) override;

    void            Clear();

    DECL_LINK( PopupHdl, Menu*, bool );
    DECL_LINK( Timeout, Timer*, void );
    DECL_LINK( DoubleClickHdl, SvTreeListBox*, bool );
    DECL_LINK(Timeout, Timer*, void);
    DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
    DECL_LINK(SelectHdl, weld::TreeView&, void);
    DECL_LINK(FocusInHdl, weld::Widget&, void);
    DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
    DECL_LINK(CommandHdl, const CommandEvent&, bool);
    DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);

    SwNavigationPI* GetParentWindow();

@@ -341,16 +322,40 @@ private:
    static void     SetShowShell(const SfxObjectShell*pSet) {pShowShell = pSet;}
    DECL_STATIC_LINK(SwGlobalTree, ShowFrameHdl, void*, void);

    virtual VclPtr<PopupMenu> CreateContextMenu() override;
    virtual void    ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) override;

public:
    SwGlobalTree(vcl::Window* pParent, SwNavigationPI* pDialog);
    virtual ~SwGlobalTree() override;
    virtual void        dispose() override;
    virtual Size        GetOptimalSize() const override;
    SwGlobalTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog);
    ~SwGlobalTree();

    void                TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox);
    bool get_visible() const { return m_xTreeView->get_visible(); }

    void set_accessible_name(const OUString& rName)
    {
        m_xTreeView->set_accessible_name(rName);
    }

    void grab_focus()
    {
        m_xTreeView->grab_focus();
    }

    int count_selected_rows() const
    {
        return m_xTreeView->count_selected_rows();
    }

    void set_selection_mode(SelectionMode eMode)
    {
        m_xTreeView->set_selection_mode(eMode);
    }

    weld::TreeView& get_widget()
    {
        return *m_xTreeView;
    }

    void MoveSelectionTo(weld::TreeIter* pDropTarget);

    void                TbxMenuHdl(const OString& rCommand, weld::Menu& rMenu);
    void                InsertRegion( const SwGlblDocContent* pCont,
                                        const OUString* pFileName = nullptr );
    void                EditContent(const SwGlblDocContent* pCont );
@@ -358,11 +363,15 @@ public:
    void                ShowTree();
    void                HideTree();

    void                ExecCommand(const OUString& rCmd);
    void                ExecCommand(const OString& rCmd);

    void                Display(bool bOnlyUpdateUserData = false);

    bool                Update(bool bHard);

    void                ExecuteContextMenuAction(const OString& rSelectedPopupEntry);

    const SwWrtShell*   GetActiveWrtShell() const {return m_pActiveShell;}
};

#endif
diff --git a/sw/source/uibase/inc/navipi.hxx b/sw/source/uibase/inc/navipi.hxx
index 1404d82..1ae6542 100644
--- a/sw/source/uibase/inc/navipi.hxx
+++ b/sw/source/uibase/inc/navipi.hxx
@@ -19,9 +19,6 @@
#ifndef INCLUDED_SW_SOURCE_UIBASE_INC_NAVIPI_HXX
#define INCLUDED_SW_SOURCE_UIBASE_INC_NAVIPI_HXX

#include <vcl/lstbox.hxx>
#include <vcl/layout.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/idle.hxx>
#include <svl/lstner.hxx>
#include <vcl/transfer.hxx>
@@ -30,6 +27,7 @@
#include <sfx2/tbxctrl.hxx>
#include <sfx2/sidebar/ControllerItem.hxx>
#include <sfx2/sidebar/SidebarToolBox.hxx>
#include <sfx2/weldutils.hxx>
#include <svx/sidebar/PanelLayout.hxx>
#include "conttree.hxx"
#include <ndarr.hxx>
@@ -39,7 +37,6 @@ class SwWrtShell;
class SwNavigationPI;
class SwNavigationChild;
class SfxBindings;
class NumEditAction;
class SwNavigationConfig;
class SwView;
class SfxObjectShellLock;
@@ -59,17 +56,23 @@ class SwNavigationPI : public PanelLayout
    ::sfx2::sidebar::ControllerItem m_aDocFullName;
    ::sfx2::sidebar::ControllerItem m_aPageStats;

    VclPtr<sfx2::sidebar::SidebarToolBox> m_aContentToolBox;
    VclPtr<ToolBox>             m_aGlobalToolBox;
    VclPtr<NumEditAction>       m_xEdit;
    VclPtr<VclContainer>        m_aContentBox;
    VclPtr<SwContentTree>       m_aContentTree;
    VclPtr<VclContainer>        m_aGlobalBox;
    VclPtr<SwGlobalTree>        m_aGlobalTree;
    VclPtr<ListBox>             m_aDocListBox;
    std::unique_ptr<weld::Toolbar> m_xContent1ToolBox;
    std::unique_ptr<weld::Toolbar> m_xContent2ToolBox;
    std::unique_ptr<weld::Toolbar> m_xContent3ToolBox;
    std::unique_ptr<ToolbarUnoDispatcher> m_xContent1Dispatch;
    std::unique_ptr<weld::Menu> m_xHeadingsMenu;
    std::unique_ptr<weld::Menu> m_xDragModeMenu;
    std::unique_ptr<weld::Menu> m_xUpdateMenu;
    std::unique_ptr<weld::Menu> m_xInsertMenu;
    std::unique_ptr<weld::Toolbar> m_xGlobalToolBox;
    std::unique_ptr<weld::SpinButton> m_xEdit;
    std::unique_ptr<weld::Widget> m_xContentBox;
    std::unique_ptr<SwContentTree> m_xContentTree;
    std::unique_ptr<weld::Widget> m_xGlobalBox;
    std::unique_ptr<SwGlobalTree> m_xGlobalTree;
    std::unique_ptr<weld::ComboBox> m_xDocListBox;
    Idle                m_aPageChgIdle;
    OUString            m_sContentFileName;
    OUString            m_aContextArr[3];
    OUString            m_aStatusArr[4];

    std::unique_ptr<SfxObjectShellLock>  m_pxObjectShell;
@@ -93,12 +96,15 @@ class SwNavigationPI : public PanelLayout

    void FillBox();

    DECL_LINK( DocListBoxSelectHdl, ListBox&, void );
    DECL_LINK( ToolBoxSelectHdl, ToolBox *, void );
    DECL_LINK( ToolBoxClickHdl, ToolBox *, void );
    DECL_LINK( ToolBoxDropdownClickHdl, ToolBox*, void );
    DECL_LINK( DocListBoxSelectHdl, weld::ComboBox&, void );
    DECL_LINK( ToolBoxSelectHdl, const OString&, void );
    DECL_LINK( ToolBoxClickHdl, const OString&, void );
    DECL_LINK( ToolBox2DropdownClickHdl, const OString&, void );
    DECL_LINK( ToolBox3DropdownClickHdl, const OString&, void );
    DECL_LINK( DoneLink, SfxPoolItem const *, void );
    DECL_LINK( MenuSelectHdl, Menu *, bool );
    DECL_LINK( DropModeMenuSelectHdl, const OString&, void );
    DECL_LINK( HeadingsMenuSelectHdl, const OString&, void );
    DECL_LINK( GlobalMenuSelectHdl, const OString&, void );
    DECL_LINK( ChangePageHdl, Timer*, void );
    DECL_LINK( PageEditModifyHdl, weld::SpinButton&, void );
    bool EditAction();
@@ -109,7 +115,6 @@ protected:
    // release ObjectShellLock early enough for app end
    virtual void    Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;

    NumEditAction&  GetPageEdit();
    void            ToggleTree();
    void            SetGlobalMode(bool bSet) {m_bGlobalMode = bSet;}

diff --git a/sw/source/uibase/ribbar/workctrl.cxx b/sw/source/uibase/ribbar/workctrl.cxx
index 90ed663..feb999d 100644
--- a/sw/source/uibase/ribbar/workctrl.cxx
+++ b/sw/source/uibase/ribbar/workctrl.cxx
@@ -41,6 +41,7 @@
#include <swabstdlg.hxx>
#include <sfx2/zoomitem.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weldutils.hxx>
#include <svx/dialmgr.hxx>
#include <svx/strings.hrc>
#include <bitmaps.hlst>
@@ -566,7 +567,9 @@ VclPtr<vcl::Window> SwJumpToSpecificPageControl::CreateItemWindow( vcl::Window *

namespace {

class NavElementBox_Base;
class NavElementBox_Impl;

class NavElementToolBoxControl : public svt::ToolboxController,
                                 public lang::XServiceInfo
{
@@ -601,10 +604,46 @@ class NavElementToolBoxControl : public svt::ToolboxController,
        using svt::ToolboxController::dispatchCommand;

    private:
        VclPtr<NavElementBox_Impl>           m_pBox;
        VclPtr<NavElementBox_Impl> m_xVclBox;
        std::unique_ptr<NavElementBox_Base> m_xWeldBox;
        NavElementBox_Base* m_pBox;
};

class NavElementBox_Base
{
public:
    NavElementBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
                       const uno::Reference<frame::XFrame>& _xFrame,
                       NavElementToolBoxControl& rCtrl);

    virtual ~NavElementBox_Base()
    {
    }

    void set_sensitive(bool bSensitive)
    {
        m_xWidget->set_sensitive(bSensitive);
    }

    void                UpdateBox();

protected:
    std::unique_ptr<weld::ComboBox>            m_xWidget;
    NavElementToolBoxControl*                  m_pCtrl;
    bool                                       m_bRelease;
    uno::Reference< frame::XFrame >            m_xFrame;

    virtual bool DoKeyInput(const KeyEvent& rKEvt);

    DECL_LINK(SelectHdl, weld::ComboBox&, void);
    DECL_LINK(KeyInputHdl, const KeyEvent&, bool);

    void                ReleaseFocus_Impl();
};


class NavElementBox_Impl final : public InterimItemWindow
                               , public NavElementBox_Base
{
public:
    NavElementBox_Impl(vcl::Window* pParent,
@@ -624,52 +663,48 @@ public:
        InterimItemWindow::GetFocus();
    }

    virtual bool DoKeyInput(const KeyEvent& rKEvt) override;

    virtual ~NavElementBox_Impl() override
    {
        disposeOnce();
    }

    void                Update();

private:
    std::unique_ptr<weld::ComboBox>            m_xWidget;
    NavElementToolBoxControl*                  m_pCtrl;
    bool                                       m_bRelease;
    uno::Reference< frame::XFrame >            m_xFrame;

    DECL_LINK(SelectHdl, weld::ComboBox&, void);
    DECL_LINK(KeyInputHdl, const KeyEvent&, bool);

    void                ReleaseFocus_Impl();
};

}

NavElementBox_Base::NavElementBox_Base(
    std::unique_ptr<weld::ComboBox> xWidget,
    const uno::Reference< frame::XFrame >&            _xFrame,
    NavElementToolBoxControl&                         _rCtrl )
    : m_xWidget(std::move(xWidget))
    , m_pCtrl(&_rCtrl)
    , m_bRelease(true)
    , m_xFrame(_xFrame)
{
    m_xWidget->set_size_request(150, -1);

    std::map<OUString, std::pair<sal_uInt16, rtl::OUString> > aStoreSortedNavigationIds;
    for (sal_uInt16 i = 0; i < NID_COUNT; i++)
        aStoreSortedNavigationIds[SwResId(aNavigationStrIds[i])] = std::make_pair(aNavigationInsertIds[i], aNavigationImgIds[i]);// for ordering of Navigation Pane

    for (auto const &itr : aStoreSortedNavigationIds)
        m_xWidget->append(OUString::number(itr.second.first), itr.first, itr.second.second);
    m_xWidget->connect_changed(LINK(this, NavElementBox_Base, SelectHdl));
    m_xWidget->connect_key_press(LINK(this, NavElementBox_Base, KeyInputHdl));
}

NavElementBox_Impl::NavElementBox_Impl(
    vcl::Window*                                      _pParent,
    const uno::Reference< frame::XFrame >&            _xFrame,
    NavElementToolBoxControl&                         _rCtrl )
    : InterimItemWindow(_pParent, "modules/swriter/ui/combobox.ui", "ComboBox")
    , m_xWidget(m_xBuilder->weld_combo_box("combobox"))
    , m_pCtrl(&_rCtrl)
    , m_bRelease(true)
    , m_xFrame(_xFrame)
    , NavElementBox_Base(m_xBuilder->weld_combo_box("combobox"), _xFrame, _rCtrl)
{
    m_xWidget->set_size_request(42, -1); // set to something small so the size set at the .ui takes precedence

    std::map<OUString, std::pair<sal_uInt16, rtl::OUString> > aStoreSortedNavigationIds;
    for(sal_uInt16 i = 0; i < NID_COUNT; i++)
        aStoreSortedNavigationIds[SwResId(aNavigationStrIds[i])] = std::make_pair(aNavigationInsertIds[i], aNavigationImgIds[i]);// for ordering of Navigation Pane

    for (auto const &itr : aStoreSortedNavigationIds)
        m_xWidget->append(OUString::number(itr.second.first), itr.first, itr.second.second);
    m_xWidget->connect_changed(LINK(this, NavElementBox_Impl, SelectHdl));
    m_xWidget->connect_key_press(LINK(this, NavElementBox_Impl, KeyInputHdl));

    SetSizePixel(m_xContainer->get_preferred_size());
}

void NavElementBox_Impl::ReleaseFocus_Impl()
void NavElementBox_Base::ReleaseFocus_Impl()
{
    if ( !m_bRelease )
    {
@@ -681,7 +716,7 @@ void NavElementBox_Impl::ReleaseFocus_Impl()
        m_xFrame->getContainerWindow()->setFocus();
}

IMPL_LINK(NavElementBox_Impl, SelectHdl, weld::ComboBox&, rComboBox, void)
IMPL_LINK(NavElementBox_Base, SelectHdl, weld::ComboBox&, rComboBox, void)
{
    if (rComboBox.changed_by_direct_pick())  // only when picked from the list
    {
@@ -701,7 +736,7 @@ IMPL_LINK(NavElementBox_Impl, SelectHdl, weld::ComboBox&, rComboBox, void)
    }
}

void NavElementBox_Impl::Update()
void NavElementBox_Base::UpdateBox()
{
    sal_uInt16 nMoveType = SwView::GetMoveType();
    for ( size_t i = 0; i < SAL_N_ELEMENTS( aNavigationInsertIds ); ++i )
@@ -716,7 +751,12 @@ void NavElementBox_Impl::Update()
    }
}

IMPL_LINK(NavElementBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
IMPL_LINK(NavElementBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
    return DoKeyInput(rKEvt);
}

bool NavElementBox_Base::DoKeyInput(const KeyEvent& rKEvt)
{
    bool bHandled = false;

@@ -743,9 +783,15 @@ IMPL_LINK(NavElementBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
            break;
    }

    return bHandled || ChildKeyInput(rKEvt);
    return bHandled;
}

bool NavElementBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
{
    return NavElementBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
}


NavElementToolBoxControl::NavElementToolBoxControl( const uno::Reference< uno::XComponentContext >& rxContext )
 : svt::ToolboxController( rxContext,
                           uno::Reference< frame::XFrame >(),
@@ -796,24 +842,26 @@ void SAL_CALL NavElementToolBoxControl::dispose()
    svt::ToolboxController::dispose();

    SolarMutexGuard aSolarMutexGuard;
    m_pBox.disposeAndClear();
    m_xVclBox.disposeAndClear();
    m_xWeldBox.reset();
    m_pBox = nullptr;
}

// XStatusListener
void SAL_CALL NavElementToolBoxControl::statusChanged( const frame::FeatureStateEvent& rEvent )
{
    if ( m_pBox )
    if (m_pBox)
    {
        SolarMutexGuard aSolarMutexGuard;
        if ( rEvent.FeatureURL.Path == "NavElement" )
        {
            if ( rEvent.IsEnabled )
            {
                m_pBox->Enable();
                m_pBox->Update();
                m_pBox->set_sensitive(true);
                m_pBox->UpdateBox();
            }
            else
                m_pBox->Disable();
                m_pBox->set_sensitive(true);
        }
    }
}
@@ -841,12 +889,27 @@ uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createItemWind
{
    uno::Reference< awt::XWindow > xItemWindow;

    VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
    if ( pParent )
    if (m_pBuilder)
    {
        SolarMutexGuard aSolarMutexGuard;
        m_pBox = VclPtr<NavElementBox_Impl>::Create( pParent, m_xFrame, *this );
        xItemWindow = VCLUnoHelper::GetInterface( m_pBox );

        std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("NavElementWidget"));

        xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));

        m_xWeldBox.reset(new NavElementBox_Base(std::move(xWidget), m_xFrame, *this));
        m_pBox = m_xWeldBox.get();
    }
    else
    {
        VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
        if ( pParent )
        {
            SolarMutexGuard aSolarMutexGuard;
            m_xVclBox = VclPtr<NavElementBox_Impl>::Create( pParent, m_xFrame, *this );
            m_pBox = m_xVclBox.get();
            xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
        }
    }

    uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
@@ -970,13 +1033,17 @@ void SAL_CALL PrevNextScrollToolboxController::dispose()
// XStatusListener
void SAL_CALL PrevNextScrollToolboxController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
    if ( rEvent.FeatureURL.Path == "NavElement" )
    if (rEvent.FeatureURL.Path == "NavElement")
    {
        ToolBox* pToolBox = nullptr;
        sal_uInt16 nId = 0;
        if ( getToolboxId( nId, &pToolBox ) )
            pToolBox->SetQuickHelpText( nId, ( meType == PrevNextScrollToolboxController::PREVIOUS?lcl_GetScrollToolTip( false ):
                                                                                                   lcl_GetScrollToolTip( true ) ) );
        if (m_pToolbar)
            m_pToolbar->set_item_tooltip_text(m_aCommandURL.toUtf8(), lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
        else
        {
            ToolBox* pToolBox = nullptr;
            sal_uInt16 nId = 0;
            if (getToolboxId(nId, &pToolBox))
                pToolBox->SetQuickHelpText(nId, lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
        }
    }
}

diff --git a/sw/source/uibase/sidebar/TableEditPanel.cxx b/sw/source/uibase/sidebar/TableEditPanel.cxx
index 0dec00e..7f4dadb 100644
--- a/sw/source/uibase/sidebar/TableEditPanel.cxx
+++ b/sw/source/uibase/sidebar/TableEditPanel.cxx
@@ -101,19 +101,19 @@ TableEditPanel::TableEditPanel(vcl::Window* pParent,
    , m_xColumnWidthEdit(
          new SvxRelativeField(m_xBuilder->weld_metric_spin_button("columnwidth", FieldUnit::CM)))
    , m_xInsert(m_xBuilder->weld_toolbar("insert"))
    , m_xInsertDispatch(new ToolbarUnoDispatcher(*m_xInsert, rxFrame))
    , m_xInsertDispatch(new ToolbarUnoDispatcher(*m_xInsert, *m_xBuilder, rxFrame))
    , m_xSelect(m_xBuilder->weld_toolbar("select"))
    , m_xSelectDispatch(new ToolbarUnoDispatcher(*m_xSelect, rxFrame))
    , m_xSelectDispatch(new ToolbarUnoDispatcher(*m_xSelect, *m_xBuilder, rxFrame))
    , m_xRowSizing(m_xBuilder->weld_toolbar("rowsizing"))
    , m_xRowSizingDispatch(new ToolbarUnoDispatcher(*m_xRowSizing, rxFrame))
    , m_xRowSizingDispatch(new ToolbarUnoDispatcher(*m_xRowSizing, *m_xBuilder, rxFrame))
    , m_xColumnSizing(m_xBuilder->weld_toolbar("columnsizing"))
    , m_xColumnSizingDispatch(new ToolbarUnoDispatcher(*m_xColumnSizing, rxFrame))
    , m_xColumnSizingDispatch(new ToolbarUnoDispatcher(*m_xColumnSizing, *m_xBuilder, rxFrame))
    , m_xDelete(m_xBuilder->weld_toolbar("delete"))
    , m_xDeleteDispatch(new ToolbarUnoDispatcher(*m_xDelete, rxFrame))
    , m_xDeleteDispatch(new ToolbarUnoDispatcher(*m_xDelete, *m_xBuilder, rxFrame))
    , m_xSplitMerge(m_xBuilder->weld_toolbar("split_merge"))
    , m_xSplitMergeDispatch(new ToolbarUnoDispatcher(*m_xSplitMerge, rxFrame))
    , m_xSplitMergeDispatch(new ToolbarUnoDispatcher(*m_xSplitMerge, *m_xBuilder, rxFrame))
    , m_xMisc(m_xBuilder->weld_toolbar("misc"))
    , m_xMiscDispatch(new ToolbarUnoDispatcher(*m_xMisc, rxFrame))
    , m_xMiscDispatch(new ToolbarUnoDispatcher(*m_xMisc, *m_xBuilder, rxFrame))
    , m_aRowHeightController(SID_ATTR_TABLE_ROW_HEIGHT, *pBindings, *this)
    , m_aColumnWidthController(SID_ATTR_TABLE_COLUMN_WIDTH, *pBindings, *this)
    , m_aInsertRowsBeforeController(FN_TABLE_INSERT_ROW_BEFORE, *pBindings, *this)
diff --git a/sw/source/uibase/sidebar/WrapPropertyPanel.cxx b/sw/source/uibase/sidebar/WrapPropertyPanel.cxx
index e0770cb..feb7abf 100644
--- a/sw/source/uibase/sidebar/WrapPropertyPanel.cxx
+++ b/sw/source/uibase/sidebar/WrapPropertyPanel.cxx
@@ -72,7 +72,7 @@ WrapPropertyPanel::WrapPropertyPanel(
    , maSwLRSpacingControl(SID_ATTR_LRSPACE, *pBindings, *this)
    , maSwULSpacingControl(SID_ATTR_ULSPACE, *pBindings, *this)
    , mxWrapOptions(m_xBuilder->weld_toolbar("wrapoptions"))
    , mxWrapOptionsDispatch(new ToolbarUnoDispatcher(*mxWrapOptions, rxFrame))
    , mxWrapOptionsDispatch(new ToolbarUnoDispatcher(*mxWrapOptions, *m_xBuilder, rxFrame))
    , mxSpacingLB(m_xBuilder->weld_combo_box("spacingLB"))
{
    FieldUnit eMetric = ::GetDfltMetric(false);
diff --git a/sw/source/uibase/uitest/uiobject.cxx b/sw/source/uibase/uitest/uiobject.cxx
index ecdfd68..a0b8da9 100644
--- a/sw/source/uibase/uitest/uiobject.cxx
+++ b/sw/source/uibase/uitest/uiobject.cxx
@@ -138,7 +138,7 @@ StringMap SwNavigationPIUIObject::get_state()
{
    StringMap aMap = WindowUIObject::get_state();

    aMap["selectioncount"] = OUString::number(mxSwNavigationPI->m_aContentTree->GetSelectionCount());
    aMap["selectioncount"] = OUString::number(mxSwNavigationPI->m_xContentTree->count_selected_rows());

    return aMap;
}
@@ -147,9 +147,7 @@ void SwNavigationPIUIObject::execute(const OUString& rAction,
        const StringMap& rParameters)
{
    if (rAction == "ROOT")
    {
        mxSwNavigationPI->m_aContentToolBox->TriggerItem(mxSwNavigationPI->m_aContentToolBox->GetItemId("root"));
    }
        mxSwNavigationPI->ToolBoxSelectHdl("root");
    else
        WindowUIObject::execute(rAction, rParameters);
}
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index b7f8529..51aeea0 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -28,6 +28,7 @@
#include <sfx2/viewfrm.hxx>
#include <o3tl/enumrange.hxx>
#include <o3tl/sorted_vector.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/help.hxx>
#include <vcl/settings.hxx>
#include <sot/formats.hxx>
@@ -69,7 +70,6 @@
#include <dcontact.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdview.hxx>
#include <vcl/scrbar.hxx>
#include <SwRewriter.hxx>
#include <hints.hxx>
#include <numrule.hxx>
@@ -77,7 +77,6 @@
#include <ndtxt.hxx>
#include <PostItMgr.hxx>
#include <postithelper.hxx>
#include <vcl/treelistentry.hxx>

#include <swabstdlg.hxx>
#include <bitmaps.hlst>
@@ -107,18 +106,16 @@ class SwContentArr
{
};

bool SwContentTree::bIsInDrag = false;

namespace
{
    bool lcl_IsContent(const SvTreeListEntry* pEntry)
    bool lcl_IsContent(const weld::TreeIter& rEntry, const weld::TreeView& rTreeView)
    {
        return static_cast<const SwTypeNumber*>(pEntry->GetUserData())->GetTypeId() == CTYPE_CNT;
        return reinterpret_cast<const SwTypeNumber*>(rTreeView.get_id(rEntry).toInt64())->GetTypeId() == CTYPE_CNT;
    }

    bool lcl_IsContentType(const SvTreeListEntry* pEntry)
    bool lcl_IsContentType(const weld::TreeIter& rEntry, const weld::TreeView& rTreeView)
    {
        return static_cast<const SwTypeNumber*>(pEntry->GetUserData())->GetTypeId() == CTYPE_CTT;
        return reinterpret_cast<const SwTypeNumber*>(rTreeView.get_id(rEntry).toInt64())->GetTypeId() == CTYPE_CTT;
    }

    bool lcl_FindShell(SwWrtShell const * pShell)
@@ -860,47 +857,48 @@ static const char* STR_CONTEXT_ARY[] =
    STR_OUTLINE_TRACKING_OFF
};

SwContentTree::SwContentTree(vcl::Window* pParent, SwNavigationPI* pDialog)
    : SvTreeListBox(pParent)
SwContentTree::SwContentTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog)
    : m_xTreeView(std::move(xTreeView))
    , m_aDropTargetHelper(*this)
    , m_xDialog(pDialog)
    , m_sSpace(OUString("                    "))
    , m_sRemoveIdx(SwResId(STR_REMOVE_INDEX))
    , m_sUpdateIdx(SwResId(STR_UPDATE))
    , m_sUnprotTable(SwResId(STR_REMOVE_TBL_PROTECTION))
    , m_sRename(SwResId(STR_RENAME))
    , m_sReadonlyIdx(SwResId(STR_READONLY_IDX))
    , m_sInvisible(SwResId(STR_INVISIBLE))
    , m_sPostItShow(SwResId(STR_POSTIT_SHOW))
    , m_sPostItHide(SwResId(STR_POSTIT_HIDE))
    , m_sPostItDelete(SwResId(STR_POSTIT_DELETE))
    , m_sProtected(SwResId(STR_PROTECTED))
    , m_pHiddenShell(nullptr)
    , m_pActiveShell(nullptr)
    , m_pConfig(SW_MOD()->GetNavigationConfig())
    , m_nActiveBlock(0)
    , m_nHiddenBlock(0)
    , m_nEntryCount(0)
    , m_nRootType(ContentTypeId::UNKNOWN)
    , m_nLastSelType(ContentTypeId::UNKNOWN)
    , m_nOutlineLevel(MAXLEVEL)
    , m_eState(State::ACTIVE)
    , m_bDocChgdInDragging(false)
    , m_bIsInternalDrag(false)
    , m_bIsRoot(false)
    , m_bIsIdleClear(false)
    , m_bIsLastReadOnly(false)
    , m_bIsOutlineMoveable(true)
    , m_bViewHasChanged(false)
    , m_bIsKeySpace(false)
{
    SetHelpId(HID_NAVIGATOR_TREELIST);
    Size aSize(m_xDialog->LogicToPixel(Size(110, 112), MapMode(MapUnit::MapAppFont)));
    m_xTreeView->set_size_request(aSize.Width(), aSize.Height());

    SetNodeDefaultImages();
    SetDoubleClickHdl(LINK(this, SwContentTree, ContentDoubleClickHdl));
    SetDragDropMode(DragDropMode::APP_COPY);
    m_xTreeView->set_help_id(HID_NAVIGATOR_TREELIST);

    m_xTreeView->connect_expanding(LINK(this, SwContentTree, ExpandHdl));
    m_xTreeView->connect_collapsing(LINK(this, SwContentTree, CollapseHdl));
    m_xTreeView->connect_row_activated(LINK(this, SwContentTree, ContentDoubleClickHdl));
    m_xTreeView->connect_changed(LINK(this, SwContentTree, SelectHdl));
    m_xTreeView->connect_focus_in(LINK(this, SwContentTree, FocusHdl));
    m_xTreeView->connect_key_press(LINK(this, SwContentTree, KeyInputHdl));
    m_xTreeView->connect_popup_menu(LINK(this, SwContentTree, CommandHdl));
    m_xTreeView->connect_query_tooltip(LINK(this, SwContentTree, QueryTooltipHdl));
    m_xTreeView->connect_drag_begin(LINK(this, SwContentTree, DragBeginHdl));

    for (ContentTypeId i : o3tl::enumrange<ContentTypeId>())
    {
        m_aActiveContentArr[i]    = nullptr;
        m_aHiddenContentArr[i]    = nullptr;
        m_aActiveContentArr[i] = nullptr;
        m_aHiddenContentArr[i] = nullptr;
    }
    for (int i = 0; i < CONTEXT_COUNT; ++i)
    {
@@ -909,275 +907,110 @@ SwContentTree::SwContentTree(vcl::Window* pParent, SwNavigationPI* pDialog)
    m_nActiveBlock = m_pConfig->GetActiveBlock();
    m_aUpdTimer.SetInvokeHandler(LINK(this, SwContentTree, TimerUpdate));
    m_aUpdTimer.SetTimeout(1000);
    Clear();
    EnableContextMenuHandling();
    SetQuickSearch(true);
}

SwContentTree::~SwContentTree()
{
    disposeOnce();
}

void SwContentTree::dispose()
{
    Clear(); // If applicable erase content types previously.
    bIsInDrag = false;
    clear(); // If applicable erase content types previously.
    m_aUpdTimer.Stop();
    SetActiveShell(nullptr);
    m_xDialog.clear();
    SvTreeListBox::dispose();
}

Size SwContentTree::GetOptimalSize() const
{
    return LogicToPixel(Size(110, 112), MapMode(MapUnit::MapAppFont));
}

OUString SwContentTree::GetEntryAltText( SvTreeListEntry* pEntry ) const
{
    if (pEntry == nullptr || !lcl_IsContent(pEntry))
        return OUString();

    assert(pEntry->GetUserData() == nullptr || dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
    SwContent* pCnt = static_cast<SwContent*>(pEntry->GetUserData());
    if( pCnt == nullptr || pCnt->GetParent() == nullptr)
        return OUString();

    ContentTypeId nJumpType = pCnt->GetParent()->GetType();
    SdrObject* pTemp;

    switch(nJumpType)
    {
        case ContentTypeId::DRAWOBJECT:
            {
                SdrView* pDrawView = m_pActiveShell->GetDrawView();
                if (pDrawView)
                {
                    SwDrawModel* pDrawModel = m_pActiveShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
                    SdrPage* pPage = pDrawModel->GetPage(0);
                    const size_t nCount = pPage->GetObjCount();
                    for( size_t i=0; i<nCount; ++i )
                    {
                        pTemp = pPage->GetObj(i);
                        sal_uInt16 nCmpId;
                        switch( pTemp->GetObjIdentifier() )
                        {
                        case OBJ_GRUP:
                        case OBJ_TEXT:
                        case OBJ_LINE:
                        case OBJ_RECT:
                        case OBJ_CUSTOMSHAPE:
                        case OBJ_CIRC:
                        case OBJ_SECT:
                        case OBJ_CARC:
                        case OBJ_CCUT:
                        case OBJ_POLY:
                        case OBJ_PLIN:
                        case OBJ_PATHLINE:
                        case OBJ_PATHFILL:
                        case OBJ_FREELINE:
                        case OBJ_FREEFILL:
                        case OBJ_PATHPOLY:
                        case OBJ_PATHPLIN:
                        case OBJ_CAPTION:
                            nCmpId = OBJ_GRUP;
                            break;
                        default:
                            nCmpId = pTemp->GetObjIdentifier();
                        }
                        if(nCmpId == OBJ_GRUP && pTemp->GetName() == pCnt->GetName())
                        {
                            return pTemp->GetTitle();
                        }
                    }
                }
            }
            break;
        case ContentTypeId::GRAPHIC   :
            {
                if( m_pActiveShell && m_pActiveShell->GetDoc() )
                {
                    const SwFlyFrameFormat* pFrameFormat = m_pActiveShell->GetDoc()->FindFlyByName( pCnt->GetName());
                    if( pFrameFormat )
                        return pFrameFormat->GetObjTitle();
                }
            }
            break;
        case ContentTypeId::OLE       :
        case ContentTypeId::FRAME     :
            {
                //Can't find the GetAlternateText function. Need to verify again.
                const SwFlyFrameFormat* pFlyFormat = m_pActiveShell->GetDoc()->FindFlyByName( pCnt->GetName());
                if( pFlyFormat )
                    return pFlyFormat->/*GetAlternateText*/GetName();
            }
            break;
        default: break;
    }
    return OUString();
}

OUString SwContentTree::GetEntryLongDescription( SvTreeListEntry* pEntry ) const
{
    if( pEntry == nullptr)
        return OUString();

    assert(pEntry->GetUserData() == nullptr || dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
    SwContent* pCnt = static_cast<SwContent*>(pEntry->GetUserData());
    if( pCnt == nullptr || pCnt->GetParent() == nullptr)
        return OUString();

    SdrObject* pTemp;

    switch(pCnt->GetParent()->GetType())
    {
        case ContentTypeId::DRAWOBJECT:
            {
                SdrView* pDrawView = m_pActiveShell->GetDrawView();
                if (pDrawView)
                {
                    SwDrawModel* pDrawModel = m_pActiveShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
                    SdrPage* pPage = pDrawModel->GetPage(0);
                    const size_t nCount = pPage->GetObjCount();
                    for( size_t i=0; i<nCount; ++i )
                    {
                        pTemp = pPage->GetObj(i);
                        sal_uInt16 nCmpId;
                        switch( pTemp->GetObjIdentifier() )
                        {
                        case OBJ_GRUP:
                        case OBJ_TEXT:
                        case OBJ_LINE:
                        case OBJ_RECT:
                        case OBJ_CUSTOMSHAPE:
                        case OBJ_CIRC:
                        case OBJ_SECT:
                        case OBJ_CARC:
                        case OBJ_CCUT:
                        case OBJ_POLY:
                        case OBJ_PLIN:
                        case OBJ_PATHLINE:
                        case OBJ_PATHFILL:
                        case OBJ_FREELINE:
                        case OBJ_FREEFILL:
                        case OBJ_PATHPOLY:
                        case OBJ_PATHPLIN:
                        case OBJ_CAPTION:
                            nCmpId = OBJ_GRUP;
                            break;
                        default:
                            nCmpId = pTemp->GetObjIdentifier();
                        }
                        if(nCmpId == OBJ_GRUP /*dynamic_cast< const SdrObjGroup *>( pTemp ) !=  nullptr*/ && pTemp->GetName() == pCnt->GetName())
                        {
                            return pTemp->GetDescription();
                        }
                    }
                }
            }
            break;
        case ContentTypeId::GRAPHIC   :
        case ContentTypeId::OLE       :
        case ContentTypeId::FRAME     :
            {
                //Can't find the function "GetLongDescription". Need to verify again.
                const SwFlyFrameFormat* pFlyFormat = m_pActiveShell->GetDoc()->FindFlyByName( pCnt->GetName());
                if( pFlyFormat )
                    return pFlyFormat->GetDescription();
            }
            break;
        default: break;
    }
    return OUString();
}

// Drag&Drop methods

void SwContentTree::StartDrag( sal_Int8 nAction, const Point& rPosPixel )
IMPL_LINK(SwContentTree, DragBeginHdl, bool&, rUnsetDragIcon, bool)
{
    if( !m_bIsRoot || m_nRootType != ContentTypeId::OUTLINE )
    {
        ReleaseMouse();
    rUnsetDragIcon = true;

        rtl::Reference<TransferDataContainer> pContainer = new TransferDataContainer;
    bool bDisallow = true;

        sal_Int8 nDragMode = DND_ACTION_COPYMOVE | DND_ACTION_LINK;
        if( FillTransferData( *pContainer, nDragMode ))
        {
            SwContentTree::SetInDrag(true);
            pContainer->StartDrag( this, nDragMode, GetDragFinishedHdl() );
        }
    }
    else
    {
        SwWrtShell *const pShell = GetWrtShell();
        pShell->StartAllAction();
        pShell->StartUndo(SwUndoId::OUTLINE_UD);
        // Only move drag entry and continuous selected siblings:
        m_aDndOutlinesSelected.clear();
        SvTreeListEntry* pEntry = GetEntry(rPosPixel);
        // Find first selected of continuous siblings
        while (pEntry && IsSelected(pEntry->PrevSibling()))
        {
            pEntry = pEntry->PrevSibling();
        }
        // Record continuous selected siblings
        if (pEntry)
        {
            m_aDndOutlinesSelected.push_back(pEntry);
            while (pEntry && IsSelected(pEntry->NextSibling()))
            {
                pEntry = pEntry->NextSibling();
                m_aDndOutlinesSelected.push_back(pEntry);
            }
        }
        SvTreeListBox::StartDrag( nAction, rPosPixel );
    }
}
    rtl::Reference<TransferDataContainer> xContainer = new TransferDataContainer;
    sal_Int8 nDragMode = DND_ACTION_COPYMOVE | DND_ACTION_LINK;

void SwContentTree::DragFinished( sal_Int8 nAction )
{
    if (FillTransferData(*xContainer, nDragMode))
        bDisallow = false;

    if (m_bIsRoot && m_nRootType == ContentTypeId::OUTLINE)
    {
        SwWrtShell *const pShell = GetWrtShell();
        pShell->EndUndo();
        pShell->EndAllAction();
        m_aActiveContentArr[ContentTypeId::OUTLINE]->Invalidate();
        Display(true);
        // Only move drag entry and continuous selected siblings:
        m_aDndOutlinesSelected.clear();

        std::unique_ptr<weld::TreeIter> xScratch(m_xTreeView->make_iterator());

        std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
        bool bEntry = m_xTreeView->get_selected(xEntry.get());
        if (!bEntry)
            return true; // disallow
        // Find first selected of continuous siblings
        while (true)
        {
            m_xTreeView->copy_iterator(*xEntry, *xScratch);
            if (!m_xTreeView->iter_previous_sibling(*xScratch))
                break;
            if (!m_xTreeView->is_selected(*xScratch))
                break;
            m_xTreeView->copy_iterator(*xScratch, *xEntry);
        }
        // Record continuous selected siblings
        do
        {
            m_aDndOutlinesSelected.push_back(m_xTreeView->make_iterator(xEntry.get()));
        }
        while (m_xTreeView->iter_next_sibling(*xEntry) && m_xTreeView->is_selected(*xEntry));
        bDisallow = false;
    }

    // To prevent the removing of the selected entry in external drag and drop
    // the drag action mustn't be MOVE.
    SvTreeListBox::DragFinished( m_bIsInternalDrag ? nAction : DND_ACTION_COPY );
    SwContentTree::SetInDrag(false);
    m_bIsInternalDrag = false;
    if (!bDisallow)
        m_xTreeView->enable_drag_source(xContainer, nDragMode);
    return bDisallow;
}

SwContentTreeDropTarget::SwContentTreeDropTarget(SwContentTree& rTreeView)
    : DropTargetHelper(rTreeView.get_widget().get_drop_target())
    , m_rTreeView(rTreeView)
{
}

sal_Int8 SwContentTreeDropTarget::AcceptDrop(const AcceptDropEvent& rEvt)
{
    sal_Int8 nAccept = m_rTreeView.AcceptDrop(rEvt);

    if (nAccept != DND_ACTION_NONE)
    {
        // to enable the autoscroll when we're close to the edges
        weld::TreeView& rWidget = m_rTreeView.get_widget();
        rWidget.get_dest_row_at_pos(rEvt.maPosPixel, nullptr);
    }

    return nAccept;
}

bool SwContentTree::IsInDrag() const
{
    return m_xTreeView->get_drag_source() == m_xTreeView.get();
}

// QueryDrop will be executed in the navigator

sal_Int8 SwContentTree::AcceptDrop( const AcceptDropEvent& rEvt )
sal_Int8 SwContentTree::AcceptDrop(const AcceptDropEvent& rEvt)
{
    sal_Int8 nRet = DND_ACTION_NONE;
    if( m_bIsRoot )
    {
        if( m_bIsOutlineMoveable )
            nRet = SvTreeListBox::AcceptDrop( rEvt );
            nRet = rEvt.mnAction;
    }
    else if( !bIsInDrag )
    else if (!IsInDrag())
        nRet = GetParentWindow()->AcceptDrop();
    return nRet;
}

// Drop will be executed in the navigator

static void* lcl_GetOutlineKey( SwContentTree* pTree, SwOutlineContent const * pContent)
static void* lcl_GetOutlineKey(SwContentTree& rTree, SwOutlineContent const * pContent)
{
    void* key = nullptr;
    if( pTree && pContent )
    if (pContent)
    {
        SwWrtShell* pShell = pTree->GetWrtShell();
        SwWrtShell* pShell = rTree.GetWrtShell();
        auto const nPos = pContent->GetOutlinePos();

        key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
@@ -1185,74 +1018,142 @@ static void* lcl_GetOutlineKey( SwContentTree* pTree, SwOutlineContent const * p
    return key;
}

sal_Int8 SwContentTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
sal_Int8 SwContentTreeDropTarget::ExecuteDrop(const ExecuteDropEvent& rEvt)
{
    SvTreeListEntry* pEntry = pTargetEntry;
    if( pEntry && ( m_nRootType == ContentTypeId::OUTLINE ) && lcl_IsContent( pEntry ) )
    return m_rTreeView.ExecuteDrop(rEvt);
}

sal_Int8 SwContentTree::ExecuteDrop(const ExecuteDropEvent& rEvt)
{
    std::unique_ptr<weld::TreeIter> xDropEntry(m_xTreeView->make_iterator());
    if (!m_xTreeView->get_dest_row_at_pos(rEvt.maPosPixel, xDropEntry.get()))
        xDropEntry.reset();

    if (m_nRootType == ContentTypeId::OUTLINE)
    {
        assert(pEntry->GetUserData() == nullptr || dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
        SwOutlineContent* pOutlineContent = static_cast<SwOutlineContent*>(pEntry->GetUserData());
        if( pOutlineContent )
        if (xDropEntry && lcl_IsContent(*xDropEntry, *m_xTreeView))
        {
            void* key = lcl_GetOutlineKey(this, pOutlineContent);
            if( !mOutLineNodeMap[key] )
            assert(dynamic_cast<SwContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xDropEntry).toInt64())));
            SwOutlineContent* pOutlineContent = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xDropEntry).toInt64());
            assert(pOutlineContent);

            void* key = lcl_GetOutlineKey(*this, pOutlineContent);
            assert(key);
            if (!mOutLineNodeMap[key])
            {
                while( pEntry->HasChildren() )
                while (m_xTreeView->iter_has_child(*xDropEntry))
                {
                    SvTreeListEntry* pChildEntry = FirstChild( pEntry );
                    while( pChildEntry )
                    std::unique_ptr<weld::TreeIter> xChildEntry(m_xTreeView->make_iterator(xDropEntry.get()));
                    bool bChildEntry = m_xTreeView->iter_children(*xChildEntry);
                    while (bChildEntry)
                    {
                        pEntry = pChildEntry;
                        pChildEntry = pChildEntry->NextSibling();
                        m_xTreeView->copy_iterator(*xChildEntry, *xDropEntry);
                        bChildEntry = m_xTreeView->iter_next_sibling(*xChildEntry);
                    }
                }
                pTargetEntry = pEntry;
            }
        }

        SwOutlineNodes::size_type nTargetPos = 0;
        if (!xDropEntry)
        {
            // dropped in blank space -> move to bottom
            nTargetPos = GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount() - 1;
        }
        else if (!lcl_IsContent(*xDropEntry, *m_xTreeView))
        {
            // dropped on "heading" parent -> move to start
            nTargetPos = SwOutlineNodes::npos;
        }
        else
        {
            assert(dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xDropEntry).toInt64())));
            nTargetPos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xDropEntry).toInt64())->GetOutlinePos();
        }

        if( MAXLEVEL > m_nOutlineLevel && // Not all layers are displayed.
                        nTargetPos != SwOutlineNodes::npos)
        {
            std::unique_ptr<weld::TreeIter> xNext(m_xTreeView->make_iterator(xDropEntry.get()));
            bool bNext = m_xTreeView->iter_next(*xNext);
            if (bNext)
            {
                assert(dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xNext).toInt64())));
                nTargetPos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xNext).toInt64())->GetOutlinePos() - 1;
            }
            else
                nTargetPos = GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount() - 1;
        }

        MoveOutline(nTargetPos);

    }
    if( m_bIsRoot )
        return SvTreeListBox::ExecuteDrop( rEvt );
    return bIsInDrag ? DND_ACTION_NONE : GetParentWindow()->ExecuteDrop(rEvt);
    return IsInDrag() ? DND_ACTION_NONE : GetParentWindow()->ExecuteDrop(rEvt);
}

namespace
{
    bool IsAllExpanded(const weld::TreeView& rContentTree, const weld::TreeIter& rEntry)
    {
        if (!rContentTree.get_row_expanded(rEntry))
            return false;

        if (!rContentTree.iter_has_child(rEntry))
            return false;

        std::unique_ptr<weld::TreeIter> xChild(rContentTree.make_iterator(&rEntry));
        rContentTree.iter_children(*xChild);

        do
        {
            if (rContentTree.iter_has_child(*xChild) || rContentTree.get_children_on_demand(*xChild))
            {
                if (!IsAllExpanded(rContentTree, *xChild))
                    return false;
            }
        }
        while (rContentTree.iter_next_sibling(*xChild));
        return true;
    }
}

// Handler for Dragging and ContextMenu

static void lcl_InsertExpandCollapseAllItem(SwContentTree* pContentTree, SvTreeListEntry* pEntry, PopupMenu* pPop)
static bool lcl_InsertExpandCollapseAllItem(weld::TreeView& rContentTree, weld::TreeIter& rEntry, weld::Menu& rPop)
{
    if(pEntry->HasChildren() || pEntry->HasChildrenOnDemand())
    if (rContentTree.iter_has_child(rEntry) || rContentTree.get_children_on_demand(rEntry))
    {
        pPop->InsertSeparator();
        pPop->InsertItem(800, pContentTree->IsAllExpanded(pEntry) ? SwResId(STR_COLLAPSEALL) : SwResId(STR_EXPANDALL));
        pPop->SetAccelKey(800, vcl::KeyCode(KEY_MULTIPLY, false, true, false, false));
        rPop.set_label(OString::number(800), IsAllExpanded(rContentTree, rEntry) ? SwResId(STR_COLLAPSEALL) : SwResId(STR_EXPANDALL));
        return false;
    }
    return true;
}

VclPtr<PopupMenu> SwContentTree::CreateContextMenu()
IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool)
{
    bool bOutline(false);
    if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
        return false;

    auto pPop = VclPtr<PopupMenu>::Create();
    VclPtrInstance<PopupMenu> pSubPop1;
    VclPtrInstance<PopupMenu> pSubPop2;
    VclPtrInstance<PopupMenu> pSubPop3;
    VclPtrInstance<PopupMenu> pSubPopOutlineTracking;
    std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xTreeView.get(), "modules/swriter/ui/navigatorcontextmenu.ui"));
    std::unique_ptr<weld::Menu> xPop = xBuilder->weld_menu("navmenu");

    bool bOutline(false);
    std::unique_ptr<weld::Menu> xSubPop1 = xBuilder->weld_menu("outlinelevel");
    std::unique_ptr<weld::Menu> xSubPop2 = xBuilder->weld_menu("dragmodemenu");
    std::unique_ptr<weld::Menu> xSubPop3 = xBuilder->weld_menu("displaymenu");
    std::unique_ptr<weld::Menu> xSubPopOutlineTracking = xBuilder->weld_menu("outlinetracking");

    for(int i = 1; i <= 3; ++i)
    {
        pSubPopOutlineTracking->InsertItem(i + 10, m_aContextStrings[i + IDX_STR_OUTLINE_TRACKING], MenuItemBits::AUTOCHECK | MenuItemBits::RADIOCHECK);
    }
    pSubPopOutlineTracking->CheckItem(10 + m_nOutlineTracking);
    for(int i = 1; i <= MAXLEVEL; ++i)
    {
        pSubPop1->InsertItem(i + 100, OUString::number(i), MenuItemBits::AUTOCHECK | MenuItemBits::RADIOCHECK);
    }
    pSubPop1->CheckItem(100 + m_nOutlineLevel);
    for(int i=0; i < 3; ++i)
    {
        pSubPop2->InsertItem(i + 201, m_aContextStrings[
                IDX_STR_HYPERLINK + i], MenuItemBits::AUTOCHECK | MenuItemBits::RADIOCHECK);
    }
    pSubPop2->CheckItem(201 + static_cast<int>(GetParentWindow()->GetRegionDropMode()));
        xSubPopOutlineTracking->append_radio(OUString::number(i + 10), m_aContextStrings[IDX_STR_OUTLINE_TRACKING + i]);
    xSubPopOutlineTracking->set_active(OString::number(10 + m_nOutlineTracking), true);

    for (int i = 1; i <= MAXLEVEL; ++i)
        xSubPop1->append_radio(OUString::number(i + 100), OUString::number(i));
    xSubPop1->set_active(OString::number(100 + m_nOutlineLevel), true);

    for (int i=0; i < 3; ++i)
        xSubPop2->append_radio(OUString::number(i + 201), m_aContextStrings[IDX_STR_HYPERLINK + i]);
    xSubPop2->set_active(OString::number(201 + static_cast<int>(GetParentWindow()->GetRegionDropMode())), true);

    // Insert the list of the open files
    sal_uInt16 nId = 301;
    const SwView* pActiveView = ::GetActiveView();
@@ -1260,49 +1161,61 @@ VclPtr<PopupMenu> SwContentTree::CreateContextMenu()
    while (pView)
    {
        OUString sInsert = pView->GetDocShell()->GetTitle();
        if(pView == pActiveView)
        if (pView == pActiveView)
        {
            sInsert += "(" +
                m_aContextStrings[IDX_STR_ACTIVE] +
                ")";
        }
        pSubPop3->InsertItem(nId, sInsert, MenuItemBits::AUTOCHECK | MenuItemBits::RADIOCHECK);
        xSubPop3->append_radio(OUString::number(nId), sInsert);
        if (State::CONSTANT == m_eState && m_pActiveShell == &pView->GetWrtShell())
            pSubPop3->CheckItem(nId);
            xSubPop3->set_active(OString::number(nId), true);
        pView = SwModule::GetNextView(pView);
        nId++;
    }
    pSubPop3->InsertItem(nId++, m_aContextStrings[IDX_STR_ACTIVE_VIEW], MenuItemBits::AUTOCHECK | MenuItemBits::RADIOCHECK);
    if(m_pHiddenShell)
    xSubPop3->append_radio(OUString::number(nId++), m_aContextStrings[IDX_STR_ACTIVE_VIEW]);
    if (m_pHiddenShell)
    {
        OUString sHiddenEntry = m_pHiddenShell->GetView().GetDocShell()->GetTitle() +
            " ( " +
            m_aContextStrings[IDX_STR_HIDDEN] +
            " )";
        pSubPop3->InsertItem(nId, sHiddenEntry, MenuItemBits::AUTOCHECK | MenuItemBits::RADIOCHECK);
        xSubPop3->append_radio(OUString::number(nId), sHiddenEntry);
    }

    if (State::ACTIVE == m_eState)
        pSubPop3->CheckItem( --nId );
        xSubPop3->set_active(OString::number(--nId), true);
    else if (State::HIDDEN == m_eState)
        pSubPop3->CheckItem( nId );
        xSubPop3->set_active(OString::number(nId), true);

    SvTreeListEntry* pEntry = FirstSelected();
    if (pEntry && lcl_IsContent(pEntry))
    {
        pPop->InsertItem(900, SwResId(STR_GOTO));
        pPop->SetAccelKey(900, vcl::KeyCode(KEY_RETURN, false, false, false, false));
    }
    std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
    if (!m_xTreeView->get_selected(xEntry.get()))
        xEntry.reset();

    if (!xEntry || !lcl_IsContent(*xEntry, *m_xTreeView))
        xPop->remove(OString::number(900)); // go to

    bool bRemovePostItEntries = true;
    bool bRemoveIndexEntries = true;
    bool bRemoveEditEntry = true;
    bool bRemoveUnprotectEntry = true;
    bool bRemoveDeleteEntry = true;
    bool bRemoveRenameEntry = true;
    bool bRemoveSelectEntry = true;
    bool bRemoveToggleExpandEntry = true;
    bool bRemoveChapterEntries = true;
    bool bRemoveSendOutlineEntry = true;

    // Edit only if the shown content is coming from the current view.
    if ((State::ACTIVE == m_eState || m_pActiveShell == pActiveView->GetWrtShellPtr())
            && pEntry && lcl_IsContent(pEntry))
            && xEntry && lcl_IsContent(*xEntry, *m_xTreeView))
    {
        assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
        const SwContentType* pContType = static_cast<SwContent*>(pEntry->GetUserData())->GetParent();
        assert(dynamic_cast<SwContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
        const SwContentType* pContType = reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetParent();
        const ContentTypeId nContentType = pContType->GetType();
        const bool bReadonly = m_pActiveShell->GetView().GetDocShell()->IsReadOnly();
        const bool bVisible = !static_cast<SwContent*>(pEntry->GetUserData())->IsInvisible();
        const bool bProtected = static_cast<SwContent*>(pEntry->GetUserData())->IsProtect();
        const bool bVisible = !reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xEntry).toInt64())->IsInvisible();
        const bool bProtected = reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xEntry).toInt64())->IsProtect();
        const bool bProtectBM = (ContentTypeId::BOOKMARK == nContentType)
            && m_pActiveShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS);
        const bool bEditable = pContType->IsEditable() &&
@@ -1319,214 +1232,264 @@ VclPtr<PopupMenu> SwContentTree::CreateContextMenu()
                ContentTypeId::INDEX == nContentType ||
                ContentTypeId::DRAWOBJECT == nContentType);

        if(!bReadonly && (bEditable || bDeletable))
        if (!bReadonly && (bEditable || bDeletable))
        {
            if(ContentTypeId::INDEX == nContentType)
            {
                pPop->InsertItem(401, m_sRemoveIdx);
                pPop->InsertItem(402, m_sUpdateIdx);
                bRemoveIndexEntries = false;

                const SwTOXBase* pBase = static_cast<SwTOXBaseContent*>(pEntry->GetUserData())->GetTOXBase();
                if(!pBase->IsTOXBaseInReadonly())
                    pPop->InsertItem(403, m_aContextStrings[IDX_STR_EDIT_ENTRY]);
                pPop->InsertItem(405, m_sReadonlyIdx);
                const SwTOXBase* pBase = reinterpret_cast<SwTOXBaseContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetTOXBase();
                if (!pBase->IsTOXBaseInReadonly())
                    bRemoveEditEntry = false;

                pPop->CheckItem( 405, SwEditShell::IsTOXBaseReadonly(*pBase));
                pPop->InsertItem(501, m_aContextStrings[IDX_STR_DELETE_ENTRY]);
                xPop->set_active(OString::number(405), SwEditShell::IsTOXBaseReadonly(*pBase));
                bRemoveDeleteEntry = false;
            }
            else if(ContentTypeId::TABLE == nContentType)
            {
                pPop->InsertItem(805, SwResId(STR_SELECT));
                pPop->InsertItem(403, m_aContextStrings[IDX_STR_EDIT_ENTRY]);
                pPop->InsertItem(404, m_sUnprotTable);
                bRemoveSelectEntry = false;
                bRemoveEditEntry = false;
                bRemoveUnprotectEntry = false;
                bool bFull = false;
                OUString sTableName = static_cast<SwContent*>(pEntry->GetUserData())->GetName();
                OUString sTableName = reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetName();
                bool bProt = m_pActiveShell->HasTableAnyProtection( &sTableName, &bFull );
                pPop->EnableItem(403, !bFull );
                pPop->EnableItem(404, bProt );
                pPop->InsertItem(501, m_aContextStrings[IDX_STR_DELETE_ENTRY]);
                xPop->set_sensitive(OString::number(403), !bFull);
                xPop->set_sensitive(OString::number(404), bProt);
                bRemoveDeleteEntry = false;
            }
            else if(ContentTypeId::OUTLINE == nContentType)
            {
                bOutline = true;
                lcl_InsertExpandCollapseAllItem(this, pEntry, pPop);
                pPop->InsertSeparator();
                pPop->InsertItem(805, SwResId(STR_SELECT));
                pPop->InsertItem(806, SwResId(STR_DELETE));
                pPop->InsertItem(801, SwResId(STR_PROMOTE_CHAPTER));
                pPop->InsertItem(802, SwResId(STR_DEMOTE_CHAPTER));
                pPop->InsertItem(803, SwResId(STR_PROMOTE_LEVEL));
                pPop->InsertItem(804, SwResId(STR_DEMOTE_LEVEL));
                pPop->SetAccelKey(806, vcl::KeyCode(KEY_DELETE, false, false, false, false));
                pPop->SetAccelKey(801, vcl::KeyCode(KEY_UP, false, true, false, false));
                pPop->SetAccelKey(802, vcl::KeyCode(KEY_DOWN, false, true, false, false));
                pPop->SetAccelKey(803, vcl::KeyCode(KEY_LEFT, false, true, false, false));
                pPop->SetAccelKey(804, vcl::KeyCode(KEY_RIGHT, false, true, false, false));
                bRemoveToggleExpandEntry = lcl_InsertExpandCollapseAllItem(*m_xTreeView, *xEntry, *xPop);
                bRemoveSelectEntry = false;
                bRemoveChapterEntries = false;
            }
            else if(ContentTypeId::DRAWOBJECT == nContentType)
            {
                pPop->InsertItem(501, SwResId(STR_DELETE_ENTRY));
                bRemoveDeleteEntry = false;
            }
            else if(ContentTypeId::REGION == nContentType)
            {
                pPop->InsertItem(805, SwResId(STR_SELECT));
                pPop->InsertItem(403, m_aContextStrings[IDX_STR_EDIT_ENTRY]);
                bRemoveSelectEntry = false;
                bRemoveEditEntry = false;
            }
            else
            {
                if(bEditable && bDeletable)
                if (bEditable && bDeletable)
                {
                    pPop->InsertItem(403, m_aContextStrings[IDX_STR_EDIT_ENTRY]);
                    pPop->InsertItem(501, m_aContextStrings[IDX_STR_DELETE_ENTRY]);
                    bRemoveEditEntry = false;
                    bRemoveDeleteEntry = false;
                }
                else if(bEditable)
                    pPop->InsertItem(403, m_aContextStrings[IDX_STR_EDIT_ENTRY]);
                else if(bDeletable)
                else if (bEditable)
                    bRemoveEditEntry = false;
                else if (bDeletable)
                {
                    pPop->InsertItem(501, m_aContextStrings[IDX_STR_DELETE_ENTRY]);
                    bRemoveDeleteEntry = false;
                }
            }
            //Rename object
            if(bRenamable)
                pPop->InsertItem(502, m_sRename);
            if (bRenamable)
                bRemoveRenameEntry = false;
        }
        else if (bProtectBM)
        {
            pPop->InsertItem(503, m_sProtected);
            pPop->EnableItem(503, false);
        }
        pPop->SetAccelKey(501, vcl::KeyCode(KEY_DELETE, false, false, false, false));
    }
    else if( pEntry )
    else if (xEntry)
    {
        assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
        SwContentType* pType = static_cast<SwContentType*>(pEntry->GetUserData());
        if(ContentTypeId::OUTLINE == pType->GetType())
        assert(dynamic_cast<SwContentType*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
        SwContentType* pType = reinterpret_cast<SwContentType*>(m_xTreeView->get_id(*xEntry).toInt64());
        if (ContentTypeId::OUTLINE == pType->GetType())
        {
            bOutline = true;
            lcl_InsertExpandCollapseAllItem(this, pEntry, pPop);
            pPop->InsertSeparator();
            pPop->InsertItem(700, m_aContextStrings[IDX_STR_SEND_OUTLINE_TO_CLIPBOARD_ENTRY]);
            bRemoveToggleExpandEntry = lcl_InsertExpandCollapseAllItem(*m_xTreeView, *xEntry, *xPop);
            bRemoveSendOutlineEntry = false;
        }
        if ( (pType->GetType() == ContentTypeId::POSTIT) &&  (!m_pActiveShell->GetView().GetDocShell()->IsReadOnly()) && ( pType->GetMemberCount() > 0) )
        {
            pPop->InsertItem(600, m_sPostItShow );
            pPop->InsertItem(601, m_sPostItHide );
            pPop->InsertItem(602, m_sPostItDelete );
        }
            bRemovePostItEntries = false;
    }

    pPop->InsertSeparator();
    if (bOutline)
    if (bRemoveToggleExpandEntry)
    {
        pPop->InsertItem(4, m_aContextStrings[IDX_STR_OUTLINE_TRACKING]);
        pPop->SetPopupMenu(4, pSubPopOutlineTracking);
        pPop->InsertItem(1, m_aContextStrings[IDX_STR_OUTLINE_LEVEL]);
        pPop->SetPopupMenu(1, pSubPop1);
        xPop->remove("separator3");
        xPop->remove(OString::number(800));
    }
    else
    {
        pSubPopOutlineTracking.disposeAndClear();
        pSubPop1.disposeAndClear();
    }
    pPop->InsertItem(2, m_aContextStrings[IDX_STR_DRAGMODE]);
    pPop->SetPopupMenu(2, pSubPop2);
    pPop->InsertItem(3, m_aContextStrings[IDX_STR_DISPLAY]);
    pPop->SetPopupMenu(3, pSubPop3);

    return pPop;
    if (bRemoveSelectEntry)
        xPop->remove(OString::number(805));

    if (bRemoveChapterEntries)
    {
        xPop->remove("separator2");
        xPop->remove(OString::number(806));
        xPop->remove(OString::number(801));
        xPop->remove(OString::number(802));
        xPop->remove(OString::number(803));
        xPop->remove(OString::number(804));
    }

    if (bRemoveSendOutlineEntry)
        xPop->remove(OString::number(700));

    if (bRemovePostItEntries)
    {
        xPop->remove(OString::number(600));
        xPop->remove(OString::number(601));
        xPop->remove(OString::number(602));
    }

    if (bRemoveDeleteEntry)
        xPop->remove(OString::number(501));

    if (bRemoveRenameEntry)
        xPop->remove(OString::number(502));

    if (bRemoveIndexEntries)
    {
        xPop->remove(OString::number(401));
        xPop->remove(OString::number(402));
        xPop->remove(OString::number(405));
    }

    if (bRemoveUnprotectEntry)
        xPop->remove(OString::number(404));

    if (bRemoveEditEntry)
        xPop->remove(OString::number(403));

    if (bRemoveToggleExpandEntry &&
        bRemoveSelectEntry &&
        bRemoveChapterEntries &&
        bRemoveSendOutlineEntry &&
        bRemovePostItEntries &&
        bRemoveDeleteEntry &&
        bRemoveRenameEntry &&
        bRemoveIndexEntries &&
        bRemoveUnprotectEntry &&
        bRemoveEditEntry)
    {
        xPop->remove("separator1");
    }

    if (!bOutline)
    {
        xSubPop1.reset();
        xPop->remove(OString::number(1)); // outline level menu
        xSubPopOutlineTracking.reset();
        xPop->remove(OString::number(4)); // outline tracking menu
    }

    OString sCommand = xPop->popup_at_rect(m_xTreeView.get(), tools::Rectangle(rCEvt.GetMousePosPixel(), Size(1,1)));
    if (!sCommand.isEmpty())
        ExecuteContextMenuAction(sCommand);

    return true;
}

// Indentation for outlines (and sections)

sal_IntPtr SwContentTree::GetTabPos( SvTreeListEntry* pEntry, SvLBoxTab* pTab)
void SwContentTree::insert(const weld::TreeIter* pParent, const OUString& rStr, const OUString& rId,
                           const OUString* pExpanderName, bool bChildrenOnDemand, weld::TreeIter* pRet)
{
    sal_IntPtr nLevel = 0;
    if(lcl_IsContent(pEntry))
    m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, pExpanderName, bChildrenOnDemand, pRet);
    ++m_nEntryCount;
}

void SwContentTree::remove(const weld::TreeIter& rIter)
{
    if (m_xTreeView->iter_has_child(rIter))
    {
        nLevel++;
        assert(pEntry->GetUserData() == nullptr || dynamic_cast<SwContent *>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
        SwContent* pCnt = static_cast<SwContent *>(pEntry->GetUserData());
        const SwContentType*    pParent;
        if(pCnt &&  nullptr != (pParent = pCnt->GetParent()))
        {
            if(pParent->GetType() == ContentTypeId::OUTLINE)
                nLevel = nLevel + static_cast<SwOutlineContent*>(pCnt)->GetOutlineLevel();
            else if(pParent->GetType() == ContentTypeId::REGION)
                nLevel = nLevel + static_cast<SwRegionContent*>(pCnt)->GetRegionLevel();
        }
        std::unique_ptr<weld::TreeIter> xChild = m_xTreeView->make_iterator(&rIter);
        m_xTreeView->iter_children(*xChild);
        remove(*xChild);
    }
    return nLevel * 10 + (m_bIsRoot ? 0 : 5) + pTab->GetPos();  //determined empirically
    m_xTreeView->remove(rIter);
    --m_nEntryCount;
}

// Content will be integrated into the Box only on demand.

void SwContentTree::RequestingChildren( SvTreeListEntry* pParent )
bool SwContentTree::RequestingChildren(const weld::TreeIter& rParent)
{
    // Is this a content type?
    if(lcl_IsContentType(pParent))
    {
        if(!pParent->HasChildren())
        {
            assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pParent->GetUserData())));
            SwContentType* pCntType = static_cast<SwContentType*>(pParent->GetUserData());
    bool bChild = m_xTreeView->iter_has_child(rParent);
    if (bChild || !m_xTreeView->get_children_on_demand(rParent))
        return bChild;

            const size_t nCount = pCntType->GetMemberCount();
            // Add for outline plus/minus
            if(pCntType->GetType() == ContentTypeId::OUTLINE)
    // Is this a content type?
    if (lcl_IsContentType(rParent, *m_xTreeView))
    {
        std::unique_ptr<weld::TreeIter> xChild = m_xTreeView->make_iterator();

        assert(dynamic_cast<SwContentType*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(rParent).toInt64())));
        SwContentType* pCntType = reinterpret_cast<SwContentType*>(m_xTreeView->get_id(rParent).toInt64());

        const size_t nCount = pCntType->GetMemberCount();
        // Add for outline plus/minus
        if (pCntType->GetType() == ContentTypeId::OUTLINE)
        {
            for(size_t i = 0; i < nCount; ++i)
            {
                SvTreeListEntry* pChild = nullptr;
                for(size_t i = 0; i < nCount; ++i)
                const SwContent* pCnt = pCntType->GetMember(i);
                if(pCnt)
                {
                    const SwContent* pCnt = pCntType->GetMember(i);
                    if(pCnt)
                    const auto nLevel = static_cast<const SwOutlineContent*>(pCnt)->GetOutlineLevel();
                    OUString sEntry = pCnt->GetName();
                    if(sEntry.isEmpty())
                        sEntry = m_sSpace;
                    OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pCnt)));
                    if (!bChild || (nLevel == 0))
                    {
                        const auto nLevel = static_cast<const SwOutlineContent*>(pCnt)->GetOutlineLevel();
                        OUString sEntry = pCnt->GetName();
                        if(sEntry.isEmpty())
                            sEntry = m_sSpace;
                        if(!pChild || (nLevel == 0))
                            pChild = InsertEntry(sEntry, pParent, false, TREELIST_APPEND,const_cast<SwContent *>(pCnt));
                        insert(&rParent, sEntry, sId, nullptr, false, xChild.get());
                        m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
                        m_xTreeView->set_extra_row_indent(*xChild, nLevel + 1 - m_xTreeView->get_iter_depth(*xChild));
                        bChild = true;
                    }
                    else
                    {
                        //back search parent.
                        if(static_cast<const SwOutlineContent*>(pCntType->GetMember(i-1))->GetOutlineLevel() < nLevel)
                        {
                            insert(xChild.get(), sEntry, sId, nullptr, false, xChild.get());
                            m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
                            m_xTreeView->set_extra_row_indent(*xChild, nLevel + 1 - m_xTreeView->get_iter_depth(*xChild));
                            bChild = true;
                        }
                        else
                        {
                            //back search parent.
                            if(static_cast<const SwOutlineContent*>(pCntType->GetMember(i-1))->GetOutlineLevel() < nLevel)
                                pChild = InsertEntry(sEntry, pChild, false, TREELIST_APPEND, const_cast<SwContent *>(pCnt));
                            else
                            bChild = m_xTreeView->iter_previous(*xChild);
                            assert(!bChild || lcl_IsContentType(*xChild, *m_xTreeView) || dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xChild).toInt64())));
                            while (bChild &&
                                    lcl_IsContent(*xChild, *m_xTreeView) &&
                                    (reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xChild).toInt64())->GetOutlineLevel() >= nLevel)
                                )
                            {
                                pChild = Prev(pChild);
                                assert(!pChild || lcl_IsContentType(pChild) || dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pChild->GetUserData())));
                                while(pChild &&
                                        lcl_IsContent(pChild) &&
                                        (static_cast<SwOutlineContent*>(pChild->GetUserData())->GetOutlineLevel() >= nLevel)
                                    )
                                {
                                    pChild = Prev(pChild);
                                }
                                if(pChild)
                                    pChild = InsertEntry(sEntry, pChild,
                                                false, TREELIST_APPEND, const_cast<SwContent *>(pCnt));
                                bChild = m_xTreeView->iter_previous(*xChild);
                            }
                            if (bChild)
                            {
                                insert(xChild.get(), sEntry, sId, nullptr, false, xChild.get());
                                m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
                                m_xTreeView->set_extra_row_indent(*xChild, nLevel + 1 - m_xTreeView->get_iter_depth(*xChild));
                            }
                        }
                    }
                }
            }
            else
        }
        else
        {
            for(size_t i = 0; i < nCount; ++i)
            {
                for(size_t i = 0; i < nCount; ++i)
                const SwContent* pCnt = pCntType->GetMember(i);
                if (pCnt)
                {
                    const SwContent* pCnt = pCntType->GetMember(i);
                    if (pCnt)
                    {
                        OUString sEntry = pCnt->GetName();
                        if (sEntry.isEmpty())
                            sEntry = m_sSpace;
                        InsertEntry(sEntry, pParent, false, TREELIST_APPEND, const_cast<SwContent *>(pCnt));
                    }
                    OUString sEntry = pCnt->GetName();
                    if (sEntry.isEmpty())
                        sEntry = m_sSpace;
                    OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pCnt)));
                    insert(&rParent, sEntry, sId, nullptr, false, xChild.get());
                    m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
                    bChild = true;
                }
            }
        }
    }

    return bChild;
}

SdrObject* SwContentTree::GetDrawingObjectsByContent(const SwContent *pCnt)
@@ -1561,18 +1524,19 @@ SdrObject* SwContentTree::GetDrawingObjectsByContent(const SwContent *pCnt)
    return pRetObj;
}

bool  SwContentTree::Expand( SvTreeListEntry* pParent )
void SwContentTree::Expand(const weld::TreeIter& rParent, std::vector<std::unique_ptr<weld::TreeIter>>* pNodesToExpand)
{
    if (!(pParent->HasChildren() || pParent->HasChildrenOnDemand()))
        return SvTreeListBox::Expand(pParent);
    if (!(m_xTreeView->iter_has_child(rParent) || m_xTreeView->get_children_on_demand(rParent)))
        return;

    if (!m_bIsRoot
        || (lcl_IsContentType(pParent) && static_cast<SwContentType*>(pParent->GetUserData())->GetType() == ContentTypeId::OUTLINE)
        || (lcl_IsContentType(rParent, *m_xTreeView) &&
            reinterpret_cast<SwContentType*>(m_xTreeView->get_id(rParent).toInt64())->GetType() == ContentTypeId::OUTLINE)
        || (m_nRootType == ContentTypeId::OUTLINE))
    {
        if(lcl_IsContentType(pParent))
        if (lcl_IsContentType(rParent, *m_xTreeView))
        {
            SwContentType* pCntType = static_cast<SwContentType*>(pParent->GetUserData());
            SwContentType* pCntType = reinterpret_cast<SwContentType*>(m_xTreeView->get_id(rParent).toInt64());
            const sal_Int32 nOr = 1 << static_cast<int>(pCntType->GetType()); //linear -> Bitposition
            if (State::HIDDEN != m_eState)
            {
@@ -1581,65 +1545,90 @@ bool  SwContentTree::Expand( SvTreeListEntry* pParent )
            }
            else
                m_nHiddenBlock |= nOr;
            if(pCntType->GetType() == ContentTypeId::OUTLINE)
            if (pCntType->GetType() == ContentTypeId::OUTLINE)
            {
                std::map< void*, bool > aCurrOutLineNodeMap;

                SwWrtShell* pShell = GetWrtShell();
                bool bBool = SvTreeListBox::Expand(pParent);
                SvTreeListEntry* pChild = Next(pParent);
                while(pChild && lcl_IsContent(pChild) && pParent->HasChildren())
                bool bParentHasChild = RequestingChildren(rParent);
                if (pNodesToExpand)
                    pNodesToExpand->emplace_back(m_xTreeView->make_iterator(&rParent));
                if (bParentHasChild)
                {
                    if(pChild->HasChildren())
                    std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(&rParent));
                    bool bChild = m_xTreeView->iter_next(*xChild);
                    while (bChild && lcl_IsContent(*xChild, *m_xTreeView))
                    {
                        assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pChild->GetUserData())));
                        auto const nPos = static_cast<SwOutlineContent*>(pChild->GetUserData())->GetOutlinePos();
                        void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
                        aCurrOutLineNodeMap.emplace( key, false );
                        std::map<void*, bool>::iterator iter = mOutLineNodeMap.find( key );
                        if( iter != mOutLineNodeMap.end() && mOutLineNodeMap[key])
                        if (m_xTreeView->iter_has_child(*xChild))
                        {
                            aCurrOutLineNodeMap[key] = true;
                            SvTreeListBox::Expand(pChild);
                            assert(dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xChild).toInt64())));
                            auto const nPos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xChild).toInt64())->GetOutlinePos();
                            void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
                            aCurrOutLineNodeMap.emplace( key, false );
                            std::map<void*, bool>::iterator iter = mOutLineNodeMap.find( key );
                            if( iter != mOutLineNodeMap.end() && mOutLineNodeMap[key])
                            {
                                aCurrOutLineNodeMap[key] = true;
                                RequestingChildren(*xChild);
                                if (pNodesToExpand)
                                    pNodesToExpand->emplace_back(m_xTreeView->make_iterator(xChild.get()));
                                m_xTreeView->set_children_on_demand(*xChild, false);
                            }
                        }
                        bChild = m_xTreeView->iter_next(*xChild);
                    }
                    pChild = Next(pChild);
                }
                mOutLineNodeMap = aCurrOutLineNodeMap;
                return bBool;
                return;
            }

        }
        else if( lcl_IsContent(pParent) && static_cast<SwContentType*>(pParent->GetUserData())->GetType() == ContentTypeId::OUTLINE)
        else
        {
            SwWrtShell* pShell = GetWrtShell();
            // paranoid assert now that outline type is checked
            assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pParent->GetUserData())));
            auto const nPos = static_cast<SwOutlineContent*>(pParent->GetUserData())->GetOutlinePos();
            void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
            mOutLineNodeMap[key] = true;
            if (lcl_IsContent(rParent, *m_xTreeView))
            {
                SwWrtShell* pShell = GetWrtShell();
                // paranoid assert now that outline type is checked
                assert(dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(rParent).toInt64())));
                auto const nPos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(rParent).toInt64())->GetOutlinePos();
                void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
                mOutLineNodeMap[key] = true;
            }
        }
    }
    return SvTreeListBox::Expand(pParent);

    RequestingChildren(rParent);
    if (pNodesToExpand)
        pNodesToExpand->emplace_back(m_xTreeView->make_iterator(&rParent));
}

bool  SwContentTree::Collapse( SvTreeListEntry* pParent )
IMPL_LINK(SwContentTree, ExpandHdl, const weld::TreeIter&, rParent, bool)
{
    if (!pParent->HasChildren() || pParent->HasChildrenOnDemand())
        return SvTreeListBox::Collapse(pParent);
    Expand(rParent, nullptr);
    return true;
}

    if(lcl_IsContentType(pParent))
IMPL_LINK(SwContentTree, CollapseHdl, const weld::TreeIter&, rParent, bool)
{
    if (!m_xTreeView->iter_has_child(rParent) || m_xTreeView->get_children_on_demand(rParent))
        return true;

    if (lcl_IsContentType(rParent, *m_xTreeView))
    {
        if(m_bIsRoot)
        if (m_bIsRoot)
        {
            // collapse to children of root node
            for (SvTreeListEntry* pEntry = FirstChild(pParent); pEntry; pEntry = Next(pEntry))
            std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator(&rParent));
            if (m_xTreeView->iter_children(*xEntry))
            {
                Collapse(pEntry);
                do
                {
                    m_xTreeView->collapse_row(*xEntry);
                }
                while (m_xTreeView->iter_next(*xEntry));
            }
            return true;
        }
        SwContentType* pCntType = static_cast<SwContentType*>(pParent->GetUserData());
        SwContentType* pCntType = reinterpret_cast<SwContentType*>(m_xTreeView->get_id(rParent).toInt64());
        const sal_Int32 nAnd = ~(1 << static_cast<int>(pCntType->GetType()));
        if (State::HIDDEN != m_eState)
        {
@@ -1649,54 +1638,59 @@ bool  SwContentTree::Collapse( SvTreeListEntry* pParent )
        else
            m_nHiddenBlock &= nAnd;
    }
    else if( lcl_IsContent(pParent) )
    else if (lcl_IsContent(rParent, *m_xTreeView))
    {
        SwWrtShell* pShell = GetWrtShell();
        assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pParent->GetUserData())));
        auto const nPos = static_cast<SwOutlineContent*>(pParent->GetUserData())->GetOutlinePos();
        assert(dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(rParent).toInt64())));
        auto const nPos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(rParent).toInt64())->GetOutlinePos();
        void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
        mOutLineNodeMap[key] = false;
    }

    return SvTreeListBox::Collapse(pParent);
    return true;
}

// Also on double click will be initially opened only.

IMPL_LINK_NOARG(SwContentTree, ContentDoubleClickHdl, SvTreeListBox*, bool)
IMPL_LINK_NOARG(SwContentTree, ContentDoubleClickHdl, weld::TreeView&, bool)
{
    SvTreeListEntry* pEntry = GetCurEntry();
    bool bConsumed = false;

    std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
    bool bEntry = m_xTreeView->get_cursor(xEntry.get());
    // Is it a content type?
    OSL_ENSURE(pEntry, "no current entry!");
    if(pEntry)
    OSL_ENSURE(bEntry, "no current entry!");
    if (bEntry)
    {
        if(lcl_IsContentType(pEntry) && !pEntry->HasChildren())
        if (lcl_IsContentType(*xEntry, *m_xTreeView) && !m_xTreeView->iter_has_child(*xEntry))
        {
            RequestingChildren(pEntry);
            RequestingChildren(*xEntry);
            m_xTreeView->set_children_on_demand(*xEntry, false);
        }
        else if (!lcl_IsContentType(pEntry) && (State::HIDDEN != m_eState))
        else if (!lcl_IsContentType(*xEntry, *m_xTreeView) && (State::HIDDEN != m_eState))
        {
            if (State::CONSTANT == m_eState)
            {
                m_pActiveShell->GetView().GetViewFrame()->GetWindow().ToTop();
            }
            //Jump to content type:
            assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
            SwContent* pCnt = static_cast<SwContent*>(pEntry->GetUserData());
            OSL_ENSURE( pCnt, "no UserData");
            assert(dynamic_cast<SwContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
            SwContent* pCnt = reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xEntry).toInt64());
            assert(pCnt && "no UserData");
            GotoContent(pCnt);
            if(pCnt->GetParent()->GetType() == ContentTypeId::FRAME)
            const ContentTypeId nActType = pCnt->GetParent()->GetType();
            if (nActType == ContentTypeId::FRAME)
                m_pActiveShell->EnterStdMode();
            return false;   // treelist processing finished
            // fdo#36308 don't expand outlines on double-click
            bConsumed = nActType == ContentTypeId::OUTLINE;
        }
        return true;        // signal more to be done, i.e. expand/collapse children
    }
    return false;

    return bConsumed; // false/true == allow/disallow more to be done, i.e. expand/collapse children
}

namespace
{
    BitmapEx GetBitmapForContentTypeId(ContentTypeId eType)
    OUString GetImageIdForContentTypeId(ContentTypeId eType)
    {
        OUString sResId;

@@ -1743,37 +1737,97 @@ namespace
                break;
        }

        return BitmapEx(sResId);
        return sResId;
    };
}

size_t SwContentTree::GetAbsPos(const weld::TreeIter& rIter)
{
    size_t nAbsPos = 0;

    std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator(&rIter));
    if (!m_xTreeView->get_iter_first(*xEntry))
        xEntry.reset();

    while (xEntry && m_xTreeView->iter_compare(*xEntry, rIter) != 0)
    {
        if (!m_xTreeView->iter_next(*xEntry))
            xEntry.reset();
        nAbsPos++;
    }

    return nAbsPos;
}

size_t SwContentTree::GetEntryCount() const
{
    return m_nEntryCount;
}

size_t SwContentTree::GetChildCount(const weld::TreeIter& rParent) const
{
    if (!m_xTreeView->iter_has_child(rParent))
        return 0;

    std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(&rParent));

    size_t nCount = 0;
    auto nRefDepth = m_xTreeView->get_iter_depth(*xParent);
    auto nActDepth = nRefDepth;
    do
    {
        if (!m_xTreeView->iter_next(*xParent))
            xParent.reset();
        else
            nActDepth = m_xTreeView->get_iter_depth(*xParent);
        nCount++;
    } while(xParent && nRefDepth < nActDepth);

    nCount--;
    return nCount;
}

std::unique_ptr<weld::TreeIter> SwContentTree::GetEntryAtAbsPos(size_t nAbsPos) const
{
    std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
    if (!m_xTreeView->get_iter_first(*xEntry))
        xEntry.reset();

    while (nAbsPos && xEntry)
    {
        if (!m_xTreeView->iter_next(*xEntry))
            xEntry.reset();
        nAbsPos--;
    }
    return xEntry;
}

void SwContentTree::Display( bool bActive )
{
    // First read the selected entry to select it later again if necessary
    // -> the user data here are no longer valid!
    SvTreeListEntry* pOldSelEntry = FirstSelected();
    std::unique_ptr<weld::TreeIter> xOldSelEntry(m_xTreeView->make_iterator());
    if (!m_xTreeView->get_selected(xOldSelEntry.get()))
        xOldSelEntry.reset();
    OUString sEntryName;  // Name of the entry
    sal_uLong nEntryRelPos = 0; // relative position to their parent
    sal_uInt32 nOldEntryCount = GetEntryCount();
    size_t nEntryRelPos = 0; // relative position to their parent
    size_t nOldEntryCount = GetEntryCount();
    sal_Int32 nOldScrollPos = 0;
    if(pOldSelEntry)
    if (xOldSelEntry)
    {
        ScrollBar* pVScroll = GetVScroll();
        if(pVScroll && pVScroll->IsVisible())
            nOldScrollPos = pVScroll->GetThumbPos();
        UpdateLastSelType();

        sEntryName = GetEntryText(pOldSelEntry);
        SvTreeListEntry* pParentEntry = pOldSelEntry;
        while( GetParent(pParentEntry))
        {
            pParentEntry = GetParent(pParentEntry);
        }
        if(GetParent(pOldSelEntry))
        {
            nEntryRelPos = GetModel()->GetAbsPos(pOldSelEntry) - GetModel()->GetAbsPos(pParentEntry);
        }
        nOldScrollPos = m_xTreeView->vadjustment_get_value();
        sEntryName = m_xTreeView->get_text(*xOldSelEntry);
        std::unique_ptr<weld::TreeIter> xParentEntry = m_xTreeView->make_iterator(xOldSelEntry.get());
        while (m_xTreeView->get_iter_depth(*xParentEntry))
            m_xTreeView->iter_parent(*xParentEntry);
        if (m_xTreeView->get_iter_depth(*xOldSelEntry))
            nEntryRelPos = GetAbsPos(*xOldSelEntry) - GetAbsPos(*xParentEntry);
    }
    SvTreeListBox::Clear();

    clear();

    if (!bActive)
        m_eState = State::HIDDEN;
    else if (State::HIDDEN == m_eState)
@@ -1785,18 +1839,24 @@ void SwContentTree::Display( bool bActive )
        m_bIsLastReadOnly = bReadOnly;
        bool bDisable =  pShell == nullptr || bReadOnly;
        SwNavigationPI* pNavi = GetParentWindow();
        pNavi->m_aContentToolBox->EnableItem(pNavi->m_aContentToolBox->GetItemId("up"), !bDisable);
        pNavi->m_aContentToolBox->EnableItem(pNavi->m_aContentToolBox->GetItemId("down"), !bDisable);
        pNavi->m_aContentToolBox->EnableItem(pNavi->m_aContentToolBox->GetItemId("promote"), !bDisable);
        pNavi->m_aContentToolBox->EnableItem(pNavi->m_aContentToolBox->GetItemId("demote"), !bDisable);
        pNavi->m_aContentToolBox->EnableItem(pNavi->m_aContentToolBox->GetItemId("reminder"), !bDisable);
        pNavi->m_xContent3ToolBox->set_item_sensitive("chapterup", !bDisable);
        pNavi->m_xContent3ToolBox->set_item_sensitive("chapterdown", !bDisable);
        pNavi->m_xContent3ToolBox->set_item_sensitive("promote", !bDisable);
        pNavi->m_xContent3ToolBox->set_item_sensitive("demote", !bDisable);
        pNavi->m_xContent2ToolBox->set_item_sensitive("reminder", !bDisable);
    }
    if(pShell)

    if (pShell)
    {
        SvTreeListEntry* pSelEntry = nullptr;
        std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
        std::unique_ptr<weld::TreeIter> xSelEntry;
        // all content navigation view
        if(m_nRootType == ContentTypeId::UNKNOWN)
        {
            m_xTreeView->freeze();

            std::vector<std::unique_ptr<weld::TreeIter>> aNodesToExpand;

            for( ContentTypeId nCntType : o3tl::enumrange<ContentTypeId>() )
            {
                std::unique_ptr<SwContentType>& rpContentT = bActive ?
@@ -1806,141 +1866,181 @@ void SwContentTree::Display( bool bActive )
                    rpContentT.reset(new SwContentType(pShell, nCntType, m_nOutlineLevel ));

                OUString sEntry = rpContentT->GetName();
                Image aImage(GetBitmapForContentTypeId(nCntType));
                OUString aImage(GetImageIdForContentTypeId(nCntType));
                bool bChOnDemand = 0 != rpContentT->GetMemberCount();
                SvTreeListEntry* pEntry = InsertEntry(sEntry, aImage, aImage,
                                nullptr, bChOnDemand, TREELIST_APPEND, rpContentT.get());
                if (!pEntry->HasChildren() && !pEntry->HasChildrenOnDemand())
                {
                    pEntry->SetFlags(pEntry->GetFlags() | SvTLEntryFlags::SEMITRANSPARENT);
                    pEntry->SetTextColor(COL_GRAY);
                }
                if(nCntType == m_nLastSelType)
                    pSelEntry = pEntry;
                OUString sId(OUString::number(reinterpret_cast<sal_Int64>(rpContentT.get())));
                insert(nullptr, sEntry, sId, &aImage, bChOnDemand, xEntry.get());

                m_xTreeView->set_sensitive(*xEntry, bChOnDemand);

                if (nCntType == m_nLastSelType)
                    xSelEntry = m_xTreeView->make_iterator(xEntry.get());
                sal_Int32 nExpandOptions = (State::HIDDEN == m_eState)
                                            ? m_nHiddenBlock
                                            : m_nActiveBlock;
                if(nExpandOptions & (1 << static_cast<int>(nCntType)))
                if (nExpandOptions & (1 << static_cast<int>(nCntType)))
                {
                    Expand(pEntry);
                    if(nEntryRelPos && nCntType == m_nLastSelType)
                    {
                        // reselect the entry
                        SvTreeListEntry* pChild = pEntry;
                        SvTreeListEntry* pTemp = nullptr;
                        sal_uLong nPos = 1;
                        while(nullptr != (pChild = Next(pChild)))
                        {
                            // The old text will be slightly favored
                            if(sEntryName == GetEntryText(pChild) ||
                                nPos == nEntryRelPos )
                            {
                                pSelEntry = pChild;
                                break;
                            }
                            pTemp = pChild;
                            nPos++;
                        }
                        if(!pSelEntry || lcl_IsContentType(pSelEntry))
                            pSelEntry = pTemp;
                    }
                    // fill contents of to-be expanded entries while frozen
                    Expand(*xEntry, &aNodesToExpand);
                    m_xTreeView->set_children_on_demand(*xEntry, false);
                }
            }
            if(pSelEntry)

            m_xTreeView->thaw();

            // restore visual expanded tree state
            for (const auto& rNode : aNodesToExpand)
                m_xTreeView->expand_row(*rNode);

            m_xTreeView->get_iter_first(*xEntry);
            for (ContentTypeId nCntType : o3tl::enumrange<ContentTypeId>())
            {
                Select(pSelEntry);
                sal_Int32 nExpandOptions = (State::HIDDEN == m_eState)
                                            ? m_nHiddenBlock
                                            : m_nActiveBlock;
                if (nExpandOptions & (1 << static_cast<int>(nCntType)))
                {
                    if (nEntryRelPos && nCntType == m_nLastSelType)
                    {
                        // reselect the entry
                        std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(xEntry.get()));
                        std::unique_ptr<weld::TreeIter> xTemp;
                        sal_uLong nPos = 1;
                        while (m_xTreeView->iter_next(*xChild))
                        {
                            // The old text will be slightly favored
                            if (sEntryName == m_xTreeView->get_text(*xChild) ||
                                nPos == nEntryRelPos)
                            {
                                m_xTreeView->copy_iterator(*xChild, *xSelEntry);
                                break;
                            }
                            xTemp = m_xTreeView->make_iterator(xChild.get());
                            nPos++;
                        }
                        if (!xSelEntry || lcl_IsContentType(*xSelEntry, *m_xTreeView))
                            xSelEntry = std::move(xTemp);
                    }
                }

                m_xTreeView->iter_next_sibling(*xEntry);
            }
            else

            if (!xSelEntry)
            {
                nOldScrollPos = 0;
                xSelEntry = m_xTreeView->make_iterator();
                if (!m_xTreeView->get_iter_first(*xSelEntry))
                    xSelEntry.reset();
            }

            if (xSelEntry)
            {
                m_xTreeView->set_cursor(*xSelEntry);
                Select();
            }
        }
        // root content navigation view
        else
        {
            m_xTreeView->freeze();

            std::unique_ptr<SwContentType>& rpRootContentT = bActive ?
                                    m_aActiveContentArr[m_nRootType] :
                                    m_aHiddenContentArr[m_nRootType];
            if(!rpRootContentT)
                rpRootContentT.reset(new SwContentType(pShell, m_nRootType, m_nOutlineLevel ));
            Image aImage(GetBitmapForContentTypeId(m_nRootType));
            SvTreeListEntry* pParent = InsertEntry(
                    rpRootContentT->GetName(), aImage, aImage,
                        nullptr, false, TREELIST_APPEND, rpRootContentT.get());
            OUString aImage(GetImageIdForContentTypeId(m_nRootType));
            bool bChOnDemand = m_nRootType == ContentTypeId::OUTLINE;
            OUString sId(OUString::number(reinterpret_cast<sal_Int64>(rpRootContentT.get())));
            insert(nullptr, rpRootContentT->GetName(), sId, &aImage, bChOnDemand, xEntry.get());

            if(m_nRootType != ContentTypeId::OUTLINE)
            if (!bChOnDemand)
            {
                for(size_t i = 0; i < rpRootContentT->GetMemberCount(); ++i)
                std::unique_ptr<weld::TreeIter> xChild = m_xTreeView->make_iterator();
                for (size_t i = 0; i < rpRootContentT->GetMemberCount(); ++i)
                {
                    const SwContent* pCnt = rpRootContentT->GetMember(i);
                    if(pCnt)
                    if (pCnt)
                    {
                        OUString sEntry = pCnt->GetName();
                        if(sEntry.isEmpty())
                            sEntry = m_sSpace;
                        InsertEntry( sEntry, pParent,
                            false, TREELIST_APPEND, const_cast<SwContent *>(pCnt));
                        OUString sSubId(OUString::number(reinterpret_cast<sal_Int64>(pCnt)));
                        insert(xEntry.get(), sEntry, sSubId, nullptr, false, xChild.get());
                        m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
                    }
                }
            }
            else
                RequestingChildren(pParent);
            Expand(pParent);
            {
                RequestingChildren(*xEntry);
                m_xTreeView->set_children_on_demand(*xEntry, false);
            }

            m_xTreeView->set_sensitive(*xEntry, m_xTreeView->iter_has_child(*xEntry));

            m_xTreeView->thaw();

            m_xTreeView->expand_row(*xEntry);

            // reselect the entry
            if (nEntryRelPos)
            {
                SvTreeListEntry* pChild = pParent;
                std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(xEntry.get()));
                sal_uLong nPos = 1;
                while(nullptr != (pChild = Next(pChild)))
                while (m_xTreeView->iter_next(*xChild))
                {
                    // The old text will be slightly favored
                    if(sEntryName == GetEntryText(pChild) ||
                        nPos == nEntryRelPos)
                    if (sEntryName == m_xTreeView->get_text(*xChild) || nPos == nEntryRelPos)
                    {
                        pSelEntry = pChild;
                        xSelEntry = std::move(xChild);
                        break;
                    }
                    nPos++;
                }
                if(pSelEntry)
                if (xSelEntry)
                {
                    SetCurEntry(pSelEntry); // unselect all entries, make pSelEntry visible, and select
                    m_xTreeView->set_cursor(*xSelEntry); // unselect all entries, make pSelEntry visible, and select
                    Select();
                }
            }
            else
                SetCurEntry(pParent);
            {
                m_xTreeView->set_cursor(*xEntry);
                Select();
            }
        }
    }
    if (!m_bIsInPromoteDemote)

    if (!m_bIsInPromoteDemote && GetEntryCount() == nOldEntryCount)
    {
        ScrollBar* pVScroll = GetVScroll();
        if(GetEntryCount() == nOldEntryCount &&
                nOldScrollPos && pVScroll && pVScroll->IsVisible()
                && pVScroll->GetThumbPos() != nOldScrollPos)
        {
            sal_Int32 nDelta = pVScroll->GetThumbPos() - nOldScrollPos;
            ScrollOutputArea( static_cast<short>(nDelta) );
        }
        m_xTreeView->vadjustment_set_value(nOldScrollPos);
    }
}

void SwContentTree::Clear()
void SwContentTree::clear()
{
    SetUpdateMode(false);
    SvTreeListBox::Clear();
    SetUpdateMode(true);
    m_xTreeView->freeze();
    m_xTreeView->clear();
    m_nEntryCount = 0;
    m_xTreeView->thaw();
}

bool SwContentTree::FillTransferData( TransferDataContainer& rTransfer,
                                            sal_Int8& rDragMode )
{
    bool bRet = false;
    SwWrtShell* pWrtShell = GetWrtShell();
    OSL_ENSURE(pWrtShell, "no Shell!");
    SvTreeListEntry* pEntry = GetCurEntry();
    if(!pEntry || lcl_IsContentType(pEntry) || !pWrtShell)

    std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
    bool bEntry = m_xTreeView->get_cursor(xEntry.get());
    if (!bEntry || lcl_IsContentType(*xEntry, *m_xTreeView) || !pWrtShell)
        return false;
    OUString sEntry;
    assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
    SwContent* pCnt = static_cast<SwContent*>(pEntry->GetUserData());
    assert(dynamic_cast<SwContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
    SwContent* pCnt = reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xEntry).toInt64());

    const ContentTypeId nActType = pCnt->GetParent()->GetType();
    OUString sUrl;
@@ -1995,10 +2095,9 @@ bool SwContentTree::FillTransferData( TransferDataContainer& rTransfer,
                rDragMode &= ~( DND_ACTION_MOVE | DND_ACTION_LINK );
            [[fallthrough]];
        default:
            sEntry = GetEntryText(pEntry);
            sEntry = m_xTreeView->get_text(*xEntry);
    }

    bool bRet = false;
    if(!sEntry.isEmpty())
    {
        const SwDocShell* pDocShell = pWrtShell->GetView().GetDocShell();
@@ -2070,53 +2169,46 @@ void SwContentTree::ToggleToRoot()
{
    if(!m_bIsRoot)
    {
        SvTreeListEntry* pEntry = GetCurEntry();
        std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
        bool bEntry = m_xTreeView->get_cursor(xEntry.get());
        const SwContentType* pCntType;
        if(pEntry)
        if (bEntry)
        {
            if(lcl_IsContentType(pEntry))
            if (lcl_IsContentType(*xEntry, *m_xTreeView))
            {
                assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
                pCntType = static_cast<SwContentType*>(pEntry->GetUserData());
                assert(dynamic_cast<SwContentType*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
                pCntType = reinterpret_cast<SwContentType*>(m_xTreeView->get_id(*xEntry).toInt64());
            }
            else
            {
                assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
                pCntType = static_cast<SwContent*>(pEntry->GetUserData())->GetParent();
                assert(dynamic_cast<SwContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
                pCntType = reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetParent();
            }
            m_nRootType = pCntType->GetType();
            m_bIsRoot = true;
            Display(State::HIDDEN != m_eState);
            if (m_nRootType == ContentTypeId::OUTLINE)
            {
                SetSelectionMode(SelectionMode::Multiple);
                SetDragDropMode(DragDropMode::CTRL_MOVE |
                    DragDropMode::CTRL_COPY |
                    DragDropMode::ENABLE_TOP);
                m_xTreeView->set_selection_mode(SelectionMode::Multiple);
            }
        }
    }
    else
    {
        SetSelectionMode(SelectionMode::Single);
        m_xTreeView->set_selection_mode(SelectionMode::Single);
        m_nRootType = ContentTypeId::UNKNOWN;
        m_bIsRoot = false;
        FindActiveTypeAndRemoveUserData();
        Display(State::HIDDEN != m_eState);
        if( m_bIsKeySpace )
        {
            HideFocus();
            ShowFocus( m_aOldRectangle);
            m_bIsKeySpace = false;
        }
    }
    m_pConfig->SetRootType( m_nRootType );
    VclPtr<ToolBox> xBox = GetParentWindow()->m_aContentToolBox;
    xBox->CheckItem(xBox->GetItemId("root"), m_bIsRoot);
    weld::Toolbar* pBox = GetParentWindow()->m_xContent2ToolBox.get();
    pBox->set_item_active("root", m_bIsRoot);
}

bool SwContentTree::HasContentChanged()
{
    bool bContentChanged = false;

//  - Run through the local array and the Treelistbox in parallel.
//  - Are the records not expanded, they are discarded only in the array
@@ -2129,8 +2221,10 @@ bool SwContentTree::HasContentChanged()
//  at the same time. Once a difference occurs it will be only replenished
//  no longer checked. Finally, the box is filled again.

    bool bRepaint = false;
    bool bInvalidate = false;
    // bVisibilityChanged gets set to true if some element, like a section,
    // changed visibility and should have its name rerendered with a new
    // grayed-out state
    bool bVisibilityChanged = false;

    if (State::HIDDEN == m_eState)
    {
@@ -2143,54 +2237,58 @@ bool SwContentTree::HasContentChanged()
    // root content navigation view
    else if(m_bIsRoot)
    {
        SvTreeListEntry* pRootEntry = First();
        if(!pRootEntry)
            bRepaint = true;
        std::unique_ptr<weld::TreeIter> xRootEntry(m_xTreeView->make_iterator());
        if (!m_xTreeView->get_iter_first(*xRootEntry))
            bContentChanged = true;
        else
        {
            assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pRootEntry->GetUserData())));
            const ContentTypeId nType = static_cast<SwContentType*>(pRootEntry->GetUserData())->GetType();
            assert(dynamic_cast<SwContentType*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xRootEntry).toInt64())));
            const ContentTypeId nType = reinterpret_cast<SwContentType*>(m_xTreeView->get_id(*xRootEntry).toInt64())->GetType();
            SwContentType* pArrType = m_aActiveContentArr[nType].get();
            if(!pArrType)
                bRepaint = true;
            if (!pArrType)
                bContentChanged = true;
            else
            {
                // start check if first selected outline level has changed
                SvTreeListEntry* pFirstSel;
                if(m_nRootType == ContentTypeId::OUTLINE && !HasFocus() &&
                        nullptr != (pFirstSel = FirstSelected()) &&
                            lcl_IsContent(pFirstSel))
                bool bCheckChanged = m_nRootType == ContentTypeId::OUTLINE && !m_xTreeView->has_focus();
                if (bCheckChanged)
                {
                    assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pFirstSel->GetUserData())));
                    const auto nSelLevel = static_cast<SwOutlineContent*>(pFirstSel->GetUserData())->GetOutlineLevel();
                    SwWrtShell* pSh = GetWrtShell();
                    const SwOutlineNodes::size_type nOutlinePos = pSh->GetOutlinePos(MAXLEVEL);
                    if (nOutlinePos != SwOutlineNodes::npos && pSh->getIDocumentOutlineNodesAccess()->getOutlineLevel(nOutlinePos) != nSelLevel)
                        bRepaint = true;
                    std::unique_ptr<weld::TreeIter> xFirstSel(m_xTreeView->make_iterator());
                    bool bFirstSel = m_xTreeView->get_selected(xFirstSel.get());
                    if (bFirstSel && lcl_IsContent(*xFirstSel, *m_xTreeView))
                    {
                        assert(dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xFirstSel).toInt64())));
                        const auto nSelLevel = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xFirstSel).toInt64())->GetOutlineLevel();
                        SwWrtShell* pSh = GetWrtShell();
                        const SwOutlineNodes::size_type nOutlinePos = pSh->GetOutlinePos(MAXLEVEL);
                        if (nOutlinePos != SwOutlineNodes::npos && pSh->getIDocumentOutlineNodesAccess()->getOutlineLevel(nOutlinePos) != nSelLevel)
                            bContentChanged = true;
                    }
                }
                // end check if first selected outline level has changed

                pArrType->Init(&bInvalidate);
                pArrType->Init(&bVisibilityChanged);
                pArrType->FillMemberList();
                pRootEntry->SetUserData(static_cast<void*>(pArrType));
                if(!bRepaint)
                OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pArrType)));
                m_xTreeView->set_id(*xRootEntry, sId);
                if (!bContentChanged)
                {
                    if(GetChildCount(pRootEntry) != pArrType->GetMemberCount())
                        bRepaint = true;
                    const size_t nChildCount = GetChildCount(*xRootEntry);
                    if (nChildCount != pArrType->GetMemberCount())
                        bContentChanged = true;
                    else
                    {
                        const size_t nChildCount = GetChildCount(pRootEntry);
                        SvTreeListEntry* pEntry = pRootEntry;
                        for(size_t j = 0; j < nChildCount; ++j)
                        std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator(xRootEntry.get()));
                        for (size_t j = 0; j < nChildCount; ++j)
                        {
                            pEntry = Next(pEntry);
                            assert(pEntry);
                            m_xTreeView->iter_next(*xEntry);
                            const SwContent* pCnt = pArrType->GetMember(j);
                            pEntry->SetUserData(const_cast<SwContent *>(pCnt));
                            OUString sEntryText = GetEntryText(pEntry);
                            OUString sSubId(OUString::number(reinterpret_cast<sal_Int64>(pCnt)));
                            m_xTreeView->set_id(*xEntry, sSubId);
                            OUString sEntryText = m_xTreeView->get_text(*xEntry);
                            if( sEntryText != pCnt->GetName() &&
                                !(sEntryText == m_sSpace && pCnt->GetName().isEmpty()))
                                bRepaint = true;
                                bContentChanged = true;
                        }
                    }
                }
@@ -2200,54 +2298,59 @@ bool SwContentTree::HasContentChanged()
    // all content navigation view
    else
    {
        SvTreeListEntry* pEntry = First();
        while ( pEntry )
        std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
        bool bEntry = m_xTreeView->get_iter_first(*xEntry);
        while (bEntry)
        {
            bool bNext = true; // at least a next must be
            assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
            SwContentType* pCntType = static_cast<SwContentType*>(pEntry->GetUserData());
            assert(dynamic_cast<SwContentType*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
            SwContentType* pCntType = reinterpret_cast<SwContentType*>(m_xTreeView->get_id(*xEntry).toInt64());
            const size_t nCntCount = pCntType->GetMemberCount();
            const ContentTypeId nType = pCntType->GetType();
            SwContentType* pArrType = m_aActiveContentArr[nType].get();
            if(!pArrType)
                bRepaint = true;
            if (!pArrType)
                bContentChanged = true;
            else
            {
                pArrType->Init(&bInvalidate);
                pEntry->SetUserData(static_cast<void*>(pArrType));
                if(IsExpanded(pEntry))
                pArrType->Init(&bVisibilityChanged);
                OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pArrType)));
                m_xTreeView->set_id(*xEntry, sId);
                if (m_xTreeView->get_row_expanded(*xEntry))
                {
                    bool bLevelOrVisibilityChanged = false;
                    // bLevelOrVisibilityChanged is set if outlines have changed their level
                    // or if the visibility of objects (frames, sections, tables) has changed
                    // i.e. in header/footer
                    pArrType->FillMemberList(&bLevelOrVisibilityChanged);
                    const size_t nChildCount = GetChildCount(pEntry);
                    if((nType == ContentTypeId::OUTLINE) && bLevelOrVisibilityChanged)
                        bRepaint = true;
                    if(bLevelOrVisibilityChanged)
                        bInvalidate = true;
                    const size_t nChildCount = GetChildCount(*xEntry);
                    if (bLevelOrVisibilityChanged)
                    {
                        if (nType == ContentTypeId::OUTLINE)
                            bContentChanged = true;
                        else
                            bVisibilityChanged = true;
                    }

                    if(nChildCount != pArrType->GetMemberCount())
                        bRepaint = true;
                        bContentChanged = true;
                    else
                    {
                        for(size_t j = 0; j < nChildCount; ++j)
                        {
                            pEntry = Next(pEntry);
                            assert(pEntry);
                            bEntry = m_xTreeView->iter_next(*xEntry);
                            bNext = false;
                            const SwContent* pCnt = pArrType->GetMember(j);
                            pEntry->SetUserData(const_cast<SwContent *>(pCnt));
                            OUString sEntryText = GetEntryText(pEntry);
                            OUString sSubId(OUString::number(reinterpret_cast<sal_Int64>(pCnt)));
                            m_xTreeView->set_id(*xEntry, sSubId);
                            OUString sEntryText = m_xTreeView->get_text(*xEntry);
                            if( sEntryText != pCnt->GetName() &&
                                !(sEntryText == m_sSpace && pCnt->GetName().isEmpty()))
                                bRepaint = true;
                                bContentChanged = true;
                        }
                    }
                }
                // not expanded and has children
                else if(pEntry->HasChildren())
                else if (m_xTreeView->iter_has_child(*xEntry))
                {
                    // was the entry once opened, then must also the
                    // invisible records be examined.
@@ -2258,79 +2361,85 @@ bool SwContentTree::HasContentChanged()
                    // i.e. in header/footer
                    pArrType->FillMemberList(&bLevelOrVisibilityChanged);
                    bool bRemoveChildren = false;
                    const size_t nChildCount = GetChildCount(pEntry);
                    if( nChildCount != pArrType->GetMemberCount() )
                    const size_t nChildCount = GetChildCount(*xEntry);
                    if (nChildCount != pArrType->GetMemberCount())
                    {
                        bRemoveChildren = true;
                    }
                    else
                    {
                        SvTreeListEntry* pChild = FirstChild(pEntry);
                        for(size_t j = 0; j < nChildCount; ++j)
                        std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(xEntry.get()));
                        m_xTreeView->iter_children(*xChild);
                        for (size_t j = 0; j < nChildCount; ++j)
                        {
                            const SwContent* pCnt = pArrType->GetMember(j);
                            assert(pChild);
                            pChild->SetUserData(const_cast<SwContent *>(pCnt));
                            OUString sEntryText = GetEntryText(pChild);
                            OUString sSubId(OUString::number(reinterpret_cast<sal_Int64>(pCnt)));
                            m_xTreeView->set_id(*xChild, sSubId);
                            OUString sEntryText = m_xTreeView->get_text(*xChild);
                            if( sEntryText != pCnt->GetName() &&
                                !(sEntryText == m_sSpace && pCnt->GetName().isEmpty()))
                                bRemoveChildren = true;
                            pChild = Next(pChild);
                            m_xTreeView->iter_next(*xChild);
                        }
                    }
                    if(bRemoveChildren)
                    if (bRemoveChildren)
                    {
                        while (SvTreeListEntry *const pRemove = FirstChild(pEntry))
                            RemoveEntry(pRemove);
                        std::unique_ptr<weld::TreeIter> xRemove(m_xTreeView->make_iterator(xEntry.get()));
                        while (m_xTreeView->iter_children(*xRemove))
                        {
                            remove(*xRemove);
                            m_xTreeView->copy_iterator(*xEntry, *xRemove);
                        }
                    }
                    if(!nChildCount)
                    {
                        pEntry->EnableChildrenOnDemand(false);
                        InvalidateEntry(pEntry);
                    }

                    m_xTreeView->set_children_on_demand(*xEntry, !nChildCount);
                }
                else if((nCntCount != 0)
                            != (pArrType->GetMemberCount()!=0))
                {
                    bRepaint = true;
                    bContentChanged = true;
                }
            }
            // The Root-Entry has to be found now
            while( pEntry && (bNext || GetParent(pEntry ) ))
            while (bEntry && (bNext || m_xTreeView->get_iter_depth(*xEntry)))
            {
                pEntry = Next(pEntry);
                bEntry = m_xTreeView->iter_next(*xEntry);
                bNext = false;
            }
        }
    }
    if(!bRepaint && bInvalidate)
        Invalidate();
    return bRepaint;

    if (!bContentChanged && bVisibilityChanged)
        m_aUpdTimer.Start();

    return bContentChanged || bVisibilityChanged;
}

void SwContentTree::UpdateLastSelType()
{
    std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
    if (m_xTreeView->get_selected(xEntry.get()))
    {
        while (m_xTreeView->get_iter_depth(*xEntry))
            m_xTreeView->iter_parent(*xEntry);
        sal_Int64 nId = m_xTreeView->get_id(*xEntry).toInt64();
        if (nId && lcl_IsContentType(*xEntry, *m_xTreeView))
        {
            assert(dynamic_cast<SwContentType*>(reinterpret_cast<SwTypeNumber*>(nId)));
            m_nLastSelType = reinterpret_cast<SwContentType*>(nId)->GetType();
        }
    }
}

void SwContentTree::FindActiveTypeAndRemoveUserData()
{
    SvTreeListEntry* pEntry = FirstSelected();
    if(pEntry)
    {
        // If clear is called by TimerUpdate:
        // Only for root can the validity of the UserData be guaranteed.
        SvTreeListEntry* pParent;
        while(nullptr != (pParent = GetParent(pEntry)))
            pEntry = pParent;
        if(pEntry->GetUserData() && lcl_IsContentType(pEntry))
        {
            assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
            m_nLastSelType = static_cast<SwContentType*>(pEntry->GetUserData())->GetType();
        }
    }
    pEntry = First();
    while(pEntry)
    {
        pEntry->SetUserData(nullptr);
        pEntry = Next(pEntry);
    }
    UpdateLastSelType();

    // If clear is called by TimerUpdate:
    // Only for root can the validity of the UserData be guaranteed.
    m_xTreeView->all_foreach([this](weld::TreeIter& rEntry){
        m_xTreeView->set_id(rEntry, "");
        return false;
    });
}

void SwContentTree::SetHiddenShell(SwWrtShell* pSh)
@@ -2349,7 +2458,7 @@ void SwContentTree::SetHiddenShell(SwWrtShell* pSh)

void SwContentTree::SetActiveShell(SwWrtShell* pSh)
{
    if(m_bIsInternalDrag)
    if (IsInDrag())
        m_bDocChgdInDragging = true;
    bool bClear = m_pActiveShell != pSh;
    if (State::ACTIVE == m_eState && bClear)
@@ -2358,7 +2467,7 @@ void SwContentTree::SetActiveShell(SwWrtShell* pSh)
            EndListening(*m_pActiveShell->GetView().GetDocShell());
        m_pActiveShell = pSh;
        FindActiveTypeAndRemoveUserData();
        Clear();
        clear();
    }
    else if (State::CONSTANT == m_eState)
    {
@@ -2428,7 +2537,15 @@ void SwContentTree::Notify(SfxBroadcaster & rBC, SfxHint const& rHint)
                if (bReadOnly != m_bIsLastReadOnly)
                {
                    m_bIsLastReadOnly = bReadOnly;
                    Select(GetCurEntry());

                    std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
                    if (m_xTreeView->get_cursor(xEntry.get()))
                    {
                        m_xTreeView->select(*xEntry);
                        Select();
                    }
                    else
                        m_xTreeView->unselect_all();
                }
            }
            break;
@@ -2437,10 +2554,10 @@ void SwContentTree::Notify(SfxBroadcaster & rBC, SfxHint const& rHint)
    }
}

void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
void SwContentTree::ExecCommand(const OString& rCmd, bool bOutlineWithChildren)
{
    const bool bUp = rCmd == "up";
    const bool bUpDown = bUp || rCmd == "down";
    const bool bUp = rCmd == "chapterup";
    const bool bUpDown = bUp || rCmd == "chapterdown";
    const bool bLeft = rCmd == "promote";
    const bool bLeftRight = bLeft || rCmd == "demote";
    if (!bUpDown && !bLeftRight)
@@ -2459,19 +2576,20 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
    SwOutlineNodes::size_type nActPos = pShell->GetOutlinePos(nActOutlineLevel);

    std::vector<SwTextNode*> selectedOutlineNodes;
    std::vector<SvTreeListEntry*> selected;
    for (SvTreeListEntry * pEntry = FirstSelected(); pEntry; pEntry = NextSelected(pEntry))
    {
    std::vector<std::unique_ptr<weld::TreeIter>> selected;

    m_xTreeView->selected_foreach([this, pShell, &bLeftRight, &bOutlineWithChildren, &selected, &selectedOutlineNodes](weld::TreeIter& rEntry){
        // it's possible to select the root node too which is a really bad idea
        bool bSkip = lcl_IsContentType(pEntry);
        bool bSkip = lcl_IsContentType(rEntry, *m_xTreeView);
        // filter out children of selected parents so they don't get promoted
        // or moved twice (except if there is Ctrl modifier, since in that
        // case children are re-parented)
        if ((bLeftRight || bOutlineWithChildren) && !selected.empty())
        {
            for (auto pParent = GetParent(pEntry); pParent; pParent = GetParent(pParent))
            std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(&rEntry));
            for (bool bParent = m_xTreeView->iter_parent(*xParent); bParent; bParent = m_xTreeView->iter_parent(*xParent))
            {
                if (selected.back() == pParent)
                if (m_xTreeView->iter_compare(*selected.back(), *xParent) == 0)
                {
                    bSkip = true;
                    break;
@@ -2480,9 +2598,9 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
        }
        if (!bSkip)
        {
            selected.push_back(pEntry);
            selected.emplace_back(m_xTreeView->make_iterator(&rEntry));
            const SwNodes& rNodes = pShell->GetNodes();
            const sal_uLong nPos = GetAbsPos(pEntry) - 1;
            const size_t nPos = GetAbsPos(rEntry) - 1;
            if (nPos < rNodes.GetOutLineNds().size())
            {
                SwNode* pNode = rNodes.GetOutLineNds()[ nPos ];
@@ -2492,7 +2610,9 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                }
            }
        }
    }
        return false;
    });

    if (bUpDown && !bUp)
    {   // to move down, start at the end!
        std::reverse(selected.begin(), selected.end());
@@ -2500,17 +2620,17 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)

    SwOutlineNodes::difference_type nDirLast = bUp ? -1 : 1;
    bool bStartedAction = false;
    for (auto const pCurrentEntry : selected)
    for (auto const& pCurrentEntry : selected)
    {
        assert(pCurrentEntry && lcl_IsContent(pCurrentEntry));
        if (lcl_IsContent(pCurrentEntry))
        assert(pCurrentEntry && lcl_IsContent(*pCurrentEntry, *m_xTreeView));
        if (lcl_IsContent(*pCurrentEntry, *m_xTreeView))
        {
            assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pCurrentEntry->GetUserData())));
            assert(dynamic_cast<SwContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*pCurrentEntry).toInt64())));
            if ((m_bIsRoot && m_nRootType == ContentTypeId::OUTLINE) ||
                static_cast<SwContent*>(pCurrentEntry->GetUserData())->GetParent()->GetType()
                reinterpret_cast<SwContent*>(m_xTreeView->get_id(*pCurrentEntry).toInt64())->GetParent()->GetType()
                                            ==  ContentTypeId::OUTLINE)
            {
                nActPos = static_cast<SwOutlineContent*>(pCurrentEntry->GetUserData())->GetOutlinePos();
                nActPos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*pCurrentEntry).toInt64())->GetOutlinePos();
            }
        }
        if (nActPos == SwOutlineNodes::npos || (bUpDown && !pShell->IsOutlineMovable(nActPos)))
@@ -2529,7 +2649,7 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
        pShell->MakeOutlineSel(nActPos, nActPos, bOutlineWithChildren);
        if (bUpDown)
        {
            sal_uLong const nEntryAbsPos(GetModel()->GetAbsPos(pCurrentEntry));
            const size_t nEntryAbsPos(GetAbsPos(*pCurrentEntry));
            SwOutlineNodes::difference_type nDir = bUp ? -1 : 1;
            if (!bOutlineWithChildren && ((nDir == -1 && nActPos > 0) ||
                       (nDir == 1 && nEntryAbsPos < GetEntryCount() - 2)))
@@ -2541,66 +2661,70 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
            else if (bOutlineWithChildren)
            {
                SwOutlineNodes::size_type nActEndPos = nActPos;
                SvTreeListEntry* pEntry = pCurrentEntry;
                assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pCurrentEntry->GetUserData())));
                const auto nActLevel = static_cast<SwOutlineContent*>(
                        pCurrentEntry->GetUserData())->GetOutlineLevel();
                pEntry = Next(pEntry);
                while (pEntry && lcl_IsContent(pEntry))
                std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator(pCurrentEntry.get()));
                assert(dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*pCurrentEntry).toInt64())));
                const auto nActLevel = reinterpret_cast<SwOutlineContent*>(
                        m_xTreeView->get_id(*pCurrentEntry).toInt64())->GetOutlineLevel();
                bool bEntry = m_xTreeView->iter_next(*xEntry);
                while (bEntry && lcl_IsContent(*xEntry, *m_xTreeView))
                {
                    assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
                    if (nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel())
                    assert(dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
                    if (nActLevel >= reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetOutlineLevel())
                        break;
                    nActEndPos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
                    pEntry = Next(pEntry);
                    nActEndPos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetOutlinePos();
                    bEntry = m_xTreeView->iter_next(*xEntry);
                }
                if (nDir == 1) // move down
                {
                    if (IsSelected(pCurrentEntry->NextSibling()))
                    std::unique_ptr<weld::TreeIter> xNextSibling(m_xTreeView->make_iterator(pCurrentEntry.get()));
                    if (m_xTreeView->iter_next_sibling(*xNextSibling) && m_xTreeView->is_selected(*xNextSibling))
                        nDir = nDirLast;
                    else
                    {
                    // If the last entry is to be moved we're done
                    if (pEntry && lcl_IsContent(pEntry))
                    if (bEntry && lcl_IsContent(*xEntry, *m_xTreeView))
                    {
                        // pEntry now points to the entry following the last
                        // xEntry now points to the entry following the last
                        // selected entry.
                        SwOutlineNodes::size_type nDest = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
                        SwOutlineNodes::size_type nDest = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetOutlinePos();
                        // here needs to found the next entry after next.
                        // The selection must be inserted in front of that.
                        while (pEntry)
                        while (bEntry)
                        {
                            pEntry = Next(pEntry);
                            assert(pEntry == nullptr || !lcl_IsContent(pEntry) || dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
                            // nDest++ may only executed if pEntry != 0
                            if (pEntry)
                            bEntry = m_xTreeView->iter_next(*xEntry);
                            assert(!bEntry || !lcl_IsContent(*xEntry, *m_xTreeView)||
                                   dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
                            // nDest++ may only executed if bEntry
                            if (bEntry)
                            {
                                if (!lcl_IsContent(pEntry))
                                if (!lcl_IsContent(*xEntry, *m_xTreeView))
                                    break;
                                else if (nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel())
                                else if (nActLevel >= reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetOutlineLevel())
                                {
                                    // nDest needs adjusted if there are selected entries (including ancestral lineage)
                                    // immediately before the current moved entry.
                                    SvTreeListEntry* pTmp = Prev(pEntry);
                                    while (pTmp && lcl_IsContent(pTmp) &&
                                           nActLevel < static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel())
                                    std::unique_ptr<weld::TreeIter> xTmp(m_xTreeView->make_iterator(xEntry.get()));
                                    bool bTmp = m_xTreeView->iter_previous(*xTmp);
                                    while (bTmp && lcl_IsContent(*xTmp, *m_xTreeView) &&
                                           nActLevel < reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xTmp).toInt64())->GetOutlineLevel())
                                    {
                                        while (pTmp && lcl_IsContent(pTmp) && !IsSelected(pTmp) &&
                                               nActLevel < static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel())
                                        while (bTmp && lcl_IsContent(*xTmp, *m_xTreeView) && !m_xTreeView->is_selected(*xTmp) &&
                                               nActLevel < reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xTmp).toInt64())->GetOutlineLevel())
                                        {
                                            pTmp = GetParent(pTmp);
                                            bTmp = m_xTreeView->iter_parent(*xTmp);
                                        }
                                        if (!IsSelected(pTmp))
                                        if (!bTmp || !m_xTreeView->is_selected(*xTmp))
                                            break;
                                        pTmp = Prev(pTmp);
                                        nDest = static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlinePos();
                                        bTmp = m_xTreeView->iter_previous(*xTmp);
                                        nDest = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xTmp).toInt64())->GetOutlinePos();
                                    }
                                    if (!IsSelected(pEntry->PrevSibling()))
                                    std::unique_ptr<weld::TreeIter> xPrevSibling(m_xTreeView->make_iterator(xEntry.get()));
                                    if (!m_xTreeView->iter_previous_sibling(*xPrevSibling) || !m_xTreeView->is_selected(*xPrevSibling))
                                        break;
                                }
                                else
                                {
                                    nDest = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
                                    nDest = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetOutlinePos();
                                }
                            }
                        }
@@ -2614,46 +2738,50 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                }
                else // move up
                {
                    if (IsSelected(pCurrentEntry->PrevSibling()))
                    std::unique_ptr<weld::TreeIter> xPrevSibling(m_xTreeView->make_iterator(pCurrentEntry.get()));
                    if (m_xTreeView->iter_previous_sibling(*xPrevSibling) && m_xTreeView->is_selected(*xPrevSibling))
                        nDir = nDirLast;
                    else
                    {
                        SwOutlineNodes::size_type nDest = nActPos;
                        pEntry = pCurrentEntry;
                        while (pEntry && nDest)
                        bEntry = true;
                        m_xTreeView->copy_iterator(*pCurrentEntry, *xEntry);
                        while (bEntry && nDest)
                        {
                            pEntry = Prev(pEntry);
                            assert(pEntry == nullptr || !lcl_IsContent(pEntry) || dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
                            if (pEntry && lcl_IsContent(pEntry))
                            bEntry = m_xTreeView->iter_previous(*xEntry);
                            assert(!bEntry || !lcl_IsContent(*xEntry, *m_xTreeView) ||
                                   dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
                            if (bEntry && lcl_IsContent(*xEntry, *m_xTreeView))
                            {
                                nDest = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
                                nDest = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetOutlinePos();
                            }
                            else
                            {
                                nDest = 0; // presumably?
                            }
                            if (pEntry)
                            if (bEntry)
                            {
                                if (!lcl_IsContent(pEntry))
                                if (!lcl_IsContent(*xEntry, *m_xTreeView))
                                    break;
                                else if (nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel())
                                else if (nActLevel >= reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetOutlineLevel())
                                {
                                    // nDest needs adjusted if there are selected entries immediately
                                    // after the level change.
                                    SvTreeListEntry* pTmp = Next(pEntry);
                                    while (pTmp && lcl_IsContent(pTmp) &&
                                           nActLevel < static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel() &&
                                           IsSelected(pTmp))
                                    std::unique_ptr<weld::TreeIter> xTmp(m_xTreeView->make_iterator(xEntry.get()));
                                    bool bTmp = m_xTreeView->iter_next(*xTmp);
                                    while (bTmp && lcl_IsContent(*xTmp, *m_xTreeView) &&
                                           nActLevel < reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xTmp).toInt64())->GetOutlineLevel() &&
                                           m_xTreeView->is_selected(*xTmp))
                                    {
                                        nDest = static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlinePos();
                                        const auto nLevel = static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel();
                                        nDest = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xTmp).toInt64())->GetOutlinePos();
                                        const auto nLevel = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xTmp).toInt64())->GetOutlineLevel();
                                        // account for selected entries' descendent lineage
                                        pTmp = Next(pTmp);
                                        while (pTmp && lcl_IsContent(pTmp) &&
                                               nLevel < static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel())
                                        bTmp = m_xTreeView->iter_next(*xTmp);
                                        while (bTmp && lcl_IsContent(*xTmp, *m_xTreeView) &&
                                               nLevel < reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xTmp).toInt64())->GetOutlineLevel())
                                        {
                                            nDest = static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlinePos();
                                            pTmp = Next(pTmp);
                                            nDest = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xTmp).toInt64())->GetOutlinePos();
                                            bTmp = m_xTreeView->iter_next(*xTmp);
                                        }
                                    }
                                    break;
@@ -2689,23 +2817,27 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
            m_aActiveContentArr[ContentTypeId::OUTLINE]->Invalidate();

        // clear all selections to prevent the Display function from trying to reselect selected entries
        SelectAll(false);
        m_xTreeView->unselect_all();
        Display(true);

        // reselect entries
        const SwOutlineNodes::size_type nCurrPos = pShell->GetOutlinePos(MAXLEVEL);
        SvTreeListEntry* pListEntry = First();
        while (nullptr != (pListEntry = Next(pListEntry)) && lcl_IsContent(pListEntry))
        std::unique_ptr<weld::TreeIter> xListEntry(m_xTreeView->make_iterator());
        bool bListEntry = m_xTreeView->get_iter_first(*xListEntry);
        while ((bListEntry = m_xTreeView->iter_next(*xListEntry)) && lcl_IsContent(*xListEntry, *m_xTreeView))
        {
            assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pListEntry->GetUserData())));
            if (static_cast<SwOutlineContent*>(pListEntry->GetUserData())->GetOutlinePos() == nCurrPos)
            assert(dynamic_cast<SwOutlineContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xListEntry).toInt64())));
            if (reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xListEntry).toInt64())->GetOutlinePos() == nCurrPos)
            {
                if (!IsExpanded(pListEntry->GetParent()))
                    Expand(pListEntry->GetParent());
                SetCurEntry(pListEntry); // unselect all entries, make entry visible, set focus, and select
                std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(xListEntry.get()));
                if (m_xTreeView->iter_parent(*xParent) && !m_xTreeView->get_row_expanded(*xParent))
                    m_xTreeView->expand_row(*xParent);
                m_xTreeView->set_cursor(*xListEntry); // unselect all entries, make entry visible, set focus, and select
                Select();
                break;
            }
        }

        if (m_bIsRoot)
        {
            const SwOutlineNodes& rOutLineNds = pShell->GetNodes().GetOutLineNds();
@@ -2715,12 +2847,13 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                if(aFndIt == rOutLineNds.end())
                    continue;
                const size_t nFndPos = aFndIt - rOutLineNds.begin();
                SvTreeListEntry* pEntry = GetEntryAtAbsPos(nFndPos + 1);
                if (pEntry)
                std::unique_ptr<weld::TreeIter> xEntry = GetEntryAtAbsPos(nFndPos + 1);
                if (xEntry)
                {
                    SvTreeListBox::SelectListEntry(pEntry, true);
                    if (!IsExpanded(pEntry->GetParent()))
                        Expand(pEntry->GetParent());
                    m_xTreeView->select(*xEntry);
                    std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(xEntry.get()));
                    if (m_xTreeView->iter_parent(*xParent) && !m_xTreeView->get_row_expanded(*xParent))
                        m_xTreeView->expand_row(*xParent);
                }
            }
        }
@@ -2730,42 +2863,27 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)

void SwContentTree::ShowTree()
{
    SvTreeListBox::Show();
}

void SwContentTree::Paint( vcl::RenderContext& rRenderContext,
                           const tools::Rectangle& rRect )
{
    // prevent focus rect from flashing when tree is cleared
    // SvTreeListBox::Paint shows focus rectangle when tree is empty
    if (!GetEntryCount())
        return;
    // Start the update timer on the first paint; avoids
    // flicker on the first reveal.
    m_xTreeView->show();
    m_aUpdTimer.Start();
    SvTreeListBox::Paint( rRenderContext, rRect );
}

void SwContentTree::HideTree()
{
    // folded together will not be idled
    m_aUpdTimer.Stop();
    SvTreeListBox::Hide();
    m_xTreeView->hide();
}

/** No idle with focus or while dragging */
IMPL_LINK_NOARG(SwContentTree, TimerUpdate, Timer *, void)
{
    if (IsDisposed())
        return;

    // No update while focus is not in document.
    // No update while drag and drop.
    // Query view because the Navigator is cleared too late.
    SwView* pView = GetParentWindow()->GetCreateView();
    if(pView && pView->GetWrtShellPtr() && pView->GetWrtShellPtr()->GetWin() &&
        (pView->GetWrtShellPtr()->GetWin()->HasFocus() || m_bViewHasChanged) &&
        !bIsInDrag && !m_bIsInternalDrag && !pView->GetWrtShellPtr()->ActionPend())
        !IsInDrag() && !pView->GetWrtShellPtr()->ActionPend())
    {
        m_bViewHasChanged = false;
        m_bIsIdleClear = false;
@@ -2796,50 +2914,63 @@ IMPL_LINK_NOARG(SwContentTree, TimerUpdate, Timer *, void)
            return;

        // only track if selection is already an outline
        SvTreeListEntry* pFirstSelected = FirstSelected();
        if (pFirstSelected && lcl_IsContent(pFirstSelected) &&
                static_cast<SwContent*>(pFirstSelected->GetUserData())->GetParent()->GetType() != ContentTypeId::OUTLINE)
        std::unique_ptr<weld::TreeIter> xFirstSelected(m_xTreeView->make_iterator());
        if (!m_xTreeView->get_selected(xFirstSelected.get()))
            xFirstSelected.reset();
        if (xFirstSelected && lcl_IsContent(*xFirstSelected, *m_xTreeView) &&
                reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xFirstSelected).toInt64())->GetParent()->GetType() != ContentTypeId::OUTLINE)
            return;
        if (pFirstSelected && lcl_IsContentType(pFirstSelected) &&
                static_cast<SwContentType*>(pFirstSelected->GetUserData())->GetType() != ContentTypeId::OUTLINE)
        if (xFirstSelected && lcl_IsContentType(*xFirstSelected, *m_xTreeView) &&
                reinterpret_cast<SwContentType*>(m_xTreeView->get_id(*xFirstSelected).toInt64())->GetType() != ContentTypeId::OUTLINE)
            return;

        int nSelectedRows = m_xTreeView->count_selected_rows();

        // find the outline in the tree and select it
        for (SvTreeListEntry* pEntry = First(); pEntry; pEntry = Next(pEntry))
        {
            if (lcl_IsContent(pEntry) &&
                    static_cast<SwContent*>(pEntry->GetUserData())->GetParent()->GetType() == ContentTypeId::OUTLINE)
        m_xTreeView->all_foreach([this, nSelectedRows, nActPos, &xFirstSelected](weld::TreeIter& rEntry){
            bool bRet = false;

            if (lcl_IsContent(rEntry, *m_xTreeView) &&
                    reinterpret_cast<SwContent*>(m_xTreeView->get_id(rEntry).toInt64())->GetParent()->GetType() == ContentTypeId::OUTLINE)
            {
                // might have been scrolled out of view by the user so leave it that way
                if (static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos() == nActPos)
                if (reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(rEntry).toInt64())->GetOutlinePos() == nActPos)
                {
                    // only select if not already selected or tree has multiple entries selected
                    if (pEntry != pFirstSelected || GetSelectionCount() > 1)
                    if (nSelectedRows != 1 || m_xTreeView->iter_compare(rEntry, *xFirstSelected) != 0)
                    {
                        if (m_nOutlineTracking == 2) // focused outline tracking
                        {
                            // collapse to children of root node
                            for (SvTreeListEntry* pChildEntry = FirstChild(First()); pChildEntry; pChildEntry = Next(pChildEntry))
                            std::unique_ptr<weld::TreeIter> xChildEntry(m_xTreeView->make_iterator());
                            if (m_xTreeView->get_iter_first(*xChildEntry) && m_xTreeView->iter_children(*xChildEntry))
                            {
                                if (static_cast<SwContent*>(pChildEntry->GetUserData())->GetParent()->GetType() == ContentTypeId::OUTLINE)
                                    Collapse(pChildEntry);
                                else
                                    break;
                                do
                                {
                                    if (reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xChildEntry).toInt64())->GetParent()->GetType() == ContentTypeId::OUTLINE)
                                        m_xTreeView->collapse_row(*xChildEntry);
                                    else
                                        break;
                                }
                                while (m_xTreeView->iter_next(*xChildEntry));
                            }
                        }
                        SetCurEntry(pEntry); // unselect all entries, make pEntry visible, and select
                        m_xTreeView->set_cursor(rEntry); // unselect all entries, make pEntry visible, and select
                        Select();
                    }
                    break;
                    bRet = true;
                }
            }
            else
            {
                // use of this break assumes outline content type is first in tree
                if (lcl_IsContentType(pEntry) &&
                        static_cast<SwContentType*>(pEntry->GetUserData())->GetType() != ContentTypeId::OUTLINE)
                    break;
                if (lcl_IsContentType(rEntry, *m_xTreeView) &&
                        reinterpret_cast<SwContentType*>(m_xTreeView->get_id(rEntry).toInt64())->GetType() != ContentTypeId::OUTLINE)
                    bRet = true;
            }
        }

            return bRet;
        });
    }
    else if (!pView && State::ACTIVE == m_eState && !m_bIsIdleClear)
    {
@@ -2847,188 +2978,73 @@ IMPL_LINK_NOARG(SwContentTree, TimerUpdate, Timer *, void)
        {
            SetActiveShell(nullptr);
        }
        Clear();
        clear();
        m_bIsIdleClear = true;
    }
}

DragDropMode SwContentTree::NotifyStartDrag(
                TransferDataContainer& rContainer,
                SvTreeListEntry* pEntry )
void SwContentTree::MoveOutline(SwOutlineNodes::size_type nTargetPos)
{
    DragDropMode eMode = DragDropMode(0);
    if (State::ACTIVE == m_eState && m_nRootType == ContentTypeId::OUTLINE &&
            GetModel()->GetAbsPos( pEntry ) > 0
            && !GetWrtShell()->GetView().GetDocShell()->IsReadOnly())
    {
        eMode = GetDragDropMode();
        if (m_bIsRoot)
        {
            // Restore selection for multiple selected outlines.
            for (const auto pSelected : m_aDndOutlinesSelected)
                SelectListEntry(pSelected, true);
        }
    }
    else if (State::ACTIVE != m_eState && GetWrtShell()->GetView().GetDocShell()->HasName())
        eMode = DragDropMode::APP_COPY;
    SwWrtShell *const pShell = GetWrtShell();
    pShell->StartAllAction();
    pShell->StartUndo(SwUndoId::OUTLINE_UD);

    sal_Int8 nDragMode;
    FillTransferData( rContainer, nDragMode );
    m_bDocChgdInDragging = false;
    m_bIsInternalDrag = true;
    return eMode;
}
// After the drag the current paragraph will be moved  w i t h  the children.
    SwOutlineNodes::size_type nPrevSourcePos = SwOutlineNodes::npos;
    SwOutlineNodes::size_type nPrevTargetPosOrOffset = SwOutlineNodes::npos;

TriState SwContentTree::NotifyMoving( SvTreeListEntry*  pTarget,
        SvTreeListEntry*  pEntry, SvTreeListEntry*& , sal_uLong& )
{
    static SwOutlineNodes::size_type nStaticSourcePos = SwOutlineNodes::npos;
    static SwOutlineNodes::size_type nStaticTargetPosOrOffset = SwOutlineNodes::npos;
    if(!m_bDocChgdInDragging)
    bool bFirstMove = true;

    for (const auto& source : m_aDndOutlinesSelected)
    {
        SwOutlineNodes::size_type nTargetPos = 0;
        assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
        SwOutlineNodes::size_type nSourcePos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
        if(!lcl_IsContent(pTarget))
            nTargetPos = SwOutlineNodes::npos;
        else
        SwOutlineNodes::size_type nSourcePos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*source).toInt64())->GetOutlinePos();

        // Done on the first selection move
        if (bFirstMove) // only do once
        {
            assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pTarget->GetUserData())));
            nTargetPos = static_cast<SwOutlineContent*>(pTarget->GetUserData())->GetOutlinePos();
        }
        if( MAXLEVEL > m_nOutlineLevel && // Not all layers are displayed.
                        nTargetPos != SwOutlineNodes::npos)
        {
            SvTreeListEntry* pNext = Next(pTarget);
            if(pNext)
            if (nTargetPos == SwOutlineNodes::npos || nSourcePos > nTargetPos)
            {
                assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pNext->GetUserData())));
                nTargetPos = static_cast<SwOutlineContent*>(pNext->GetUserData())->GetOutlinePos() - 1;
                // Up moves
                // The first up move sets the up move amount for the remaining selected outlines to be moved
                if (nTargetPos != SwOutlineNodes::npos)
                    nPrevTargetPosOrOffset = nSourcePos - nTargetPos;
                else
                    nPrevTargetPosOrOffset = nSourcePos + 1;
            }
            else
                nTargetPos = GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount() - 1;
            else if (nSourcePos < nTargetPos)
            {
                // Down moves
                // The first down move sets the source and target positions for the remaining selected outlines to be moved
                nPrevSourcePos = nSourcePos;
                nPrevTargetPosOrOffset = nTargetPos;
            }
            bFirstMove = false;
        }

        OSL_ENSURE( pEntry &&
            lcl_IsContent(pEntry),"Source == 0 or Source has no Content" );

        if (nStaticTargetPosOrOffset != SwOutlineNodes::npos)
        else
        {
            if (nTargetPos == SwOutlineNodes::npos || nSourcePos > nTargetPos)
            {
                // Move up
                nTargetPos = nSourcePos - nStaticTargetPosOrOffset;
                nTargetPos = nSourcePos - nPrevTargetPosOrOffset;
            }
            else if (nSourcePos < nTargetPos)
            {
                // Move down
                nSourcePos = nStaticSourcePos;
                nTargetPos = nStaticTargetPosOrOffset;
                nSourcePos = nPrevSourcePos;
                nTargetPos = nPrevTargetPosOrOffset;
            }
        }
        // Done on the first selection move
        if (nTargetPos == SwOutlineNodes::npos || (nStaticTargetPosOrOffset == SwOutlineNodes::npos && nSourcePos > nTargetPos)) // only do once
        {
            // Up moves
            // The first up move sets the up move amount for the remaining selected outlines to be moved
            if (nTargetPos != SwOutlineNodes::npos)
                nStaticTargetPosOrOffset = nSourcePos - nTargetPos;
            else
                nStaticTargetPosOrOffset = nSourcePos + 1;
        }
        else if (nStaticTargetPosOrOffset == SwOutlineNodes::npos && nSourcePos < nTargetPos)
        {
            // Down moves
            // The first down move sets the source and target positions for the remaining selected outlines to be moved
            nStaticSourcePos = nSourcePos;
            nStaticTargetPosOrOffset = nTargetPos;
        }
        // Done on the last selection move
        if (!IsSelected(pEntry->NextSibling()))
            nStaticTargetPosOrOffset = SwOutlineNodes::npos;

        GetParentWindow()->MoveOutline( nSourcePos,
                                    nTargetPos,
                                    true);
        GetParentWindow()->MoveOutline(nSourcePos, nTargetPos, true);
    }
    //TreeListBox will be reloaded from the document
    return TRISTATE_FALSE;
}

// After the drag the current paragraph will be moved  w i t h o u t  the children.

TriState SwContentTree::NotifyCopying( SvTreeListEntry*  pTarget,
        SvTreeListEntry*  pEntry, SvTreeListEntry*& , sal_uLong& )
{
    if(!m_bDocChgdInDragging)
    {
        SwOutlineNodes::size_type nTargetPos = 0;
        assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
        SwOutlineNodes::size_type nSourcePos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
        if(!lcl_IsContent(pTarget))
            nTargetPos = SwOutlineNodes::npos;
        else
        {
            assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pTarget->GetUserData())));
            nTargetPos = static_cast<SwOutlineContent*>(pTarget->GetUserData())->GetOutlinePos();
        }

        if( MAXLEVEL > m_nOutlineLevel && // Not all layers are displayed.
                        nTargetPos != SwOutlineNodes::npos)
        {
            SvTreeListEntry* pNext = Next(pTarget);
            if(pNext)
            {
                assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pNext->GetUserData())));
                nTargetPos = static_cast<SwOutlineContent*>(pNext->GetUserData())->GetOutlinePos() - 1;
            }
            else
                nTargetPos = GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount() - 1;
        }

        OSL_ENSURE( pEntry &&
            lcl_IsContent(pEntry),"Source == 0 or Source has no Content" );
        GetParentWindow()->MoveOutline( nSourcePos, nTargetPos, false);

        //TreeListBox will be reloaded from the document
        m_aActiveContentArr[ContentTypeId::OUTLINE]->Invalidate();
        Display(true);
    }
    return TRISTATE_FALSE;
}

// No drop before the first entry - it's a SwContentType

bool  SwContentTree::NotifyAcceptDrop( SvTreeListEntry* pEntry)
{
    return pEntry != nullptr;
}

// If a Ctrl + DoubleClick are executed in an open area,
// then the base function of the control is to be called.

void SwContentTree::MouseButtonDown( const MouseEvent& rMEvt )
{
    Point aPos( rMEvt.GetPosPixel());
    SvTreeListEntry* pEntry = GetEntry( aPos, true );
    if( !pEntry && rMEvt.IsLeft() && rMEvt.IsMod1() && (rMEvt.GetClicks() % 2) == 0)
        Control::MouseButtonDown( rMEvt );
    else
    {
        if( pEntry && (rMEvt.GetClicks() % 2) == 0)
        {
            SwContent* pCnt = static_cast<SwContent*>(pEntry->GetUserData());
            const ContentTypeId nActType = pCnt->GetParent()->GetType();
            SetSublistDontOpenWithDoubleClick( nActType == ContentTypeId::OUTLINE );
        }
        SvTreeListBox::MouseButtonDown( rMEvt );
    }
    pShell->EndUndo();
    pShell->EndAllAction();
    m_aActiveContentArr[ContentTypeId::OUTLINE]->Invalidate();
    Display(true);
    m_aDndOutlinesSelected.clear();
}

// Update immediately

void SwContentTree::GetFocus()
IMPL_LINK_NOARG(SwContentTree, FocusHdl, weld::Widget&, void)
{
    SwView* pActView = GetParentWindow()->GetCreateView();
    if(pActView)
@@ -3048,17 +3064,18 @@ void SwContentTree::GetFocus()
        }
    }
    else if (State::ACTIVE == m_eState)
        Clear();
    SvTreeListBox::GetFocus();
        clear();
}

void SwContentTree::KeyInput(const KeyEvent& rEvent)
IMPL_LINK(SwContentTree, KeyInputHdl, const KeyEvent&, rEvent, bool)
{
    bool bConsumed = true;

    const vcl::KeyCode aCode = rEvent.GetKeyCode();
    if(aCode.GetCode() == KEY_RETURN)
    if (aCode.GetCode() == KEY_RETURN)
    {
        SvTreeListEntry* pEntry = FirstSelected();
        if ( pEntry )
        std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
        if (m_xTreeView->get_selected(xEntry.get()))
        {
            switch(aCode.GetModifier())
            {
@@ -3071,41 +3088,37 @@ void SwContentTree::KeyInput(const KeyEvent& rEvent)
                    ToggleToRoot();
                break;
                case 0:
                    if(lcl_IsContentType(pEntry))
                    if (lcl_IsContentType(*xEntry, *m_xTreeView))
                    {
                        IsExpanded(pEntry) ? Collapse(pEntry) : Expand(pEntry);
                        m_xTreeView->get_row_expanded(*xEntry) ? m_xTreeView->collapse_row(*xEntry)
                                                               : m_xTreeView->expand_row(*xEntry);
                    }
                    else
                        ContentDoubleClickHdl(nullptr);
                        ContentDoubleClickHdl(*m_xTreeView);
                break;
            }
        }
    }
    else if(aCode.GetCode() == KEY_DELETE && 0 == aCode.GetModifier())
    {
        SvTreeListEntry* pEntry = FirstSelected();
        if(pEntry && lcl_IsContent(pEntry))
        std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
        if (m_xTreeView->get_selected(xEntry.get()) && lcl_IsContent(*xEntry, *m_xTreeView))
        {
            assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
            if (static_cast<SwContent*>(pEntry->GetUserData())->GetParent()->IsDeletable() &&
            assert(dynamic_cast<SwContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64())));
            if (reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetParent()->IsDeletable() &&
                    !m_pActiveShell->GetView().GetDocShell()->IsReadOnly())
            {
                EditEntry(pEntry, EditEntryMode::DELETE);
                EditEntry(*xEntry, EditEntryMode::DELETE);
            }
        }
    }
    //Make KEY_SPACE has same function as DoubleClick ,
    //and realize multi-selection .
    else if(aCode.GetCode() == KEY_SPACE && 0 == aCode.GetModifier())
    else if (aCode.GetCode() == KEY_SPACE && 0 == aCode.GetModifier())
    {
        SvTreeListEntry* pEntry = GetCurEntry();
        if(pEntry)
        std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
        if (m_xTreeView->get_cursor(xEntry.get()))
        {
            if( GetChildCount( pEntry ) == 0 )
                m_bIsKeySpace = true;
            Point tempPoint = GetEntryPosition( pEntry );//Change from "GetEntryPos" to "GetEntryPosition" for acc migration
            m_aOldRectangle = GetFocusRect(pEntry, tempPoint.Y());

            if (State::HIDDEN != m_eState)
            {
                if (State::CONSTANT == m_eState)
@@ -3113,7 +3126,7 @@ void SwContentTree::KeyInput(const KeyEvent& rEvent)
                    m_pActiveShell->GetView().GetViewFrame()->GetWindow().ToTop();
                }

                SwContent* pCnt = dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData()));
                SwContent* pCnt = dynamic_cast<SwContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64()));

                if (pCnt && pCnt->GetParent()->GetType() == ContentTypeId::DRAWOBJECT)
                {
@@ -3189,20 +3202,19 @@ void SwContentTree::KeyInput(const KeyEvent& rEvent)
                m_bViewHasChanged = true;
            }
        }

    }
    else
    {
        SvTreeListEntry* pEntry = GetCurEntry();
        if (pEntry)
        std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
        if (m_xTreeView->get_cursor(xEntry.get()))
        {
            SwContent* pCnt = dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData()));
            SwContent* pCnt = dynamic_cast<SwContent*>(reinterpret_cast<SwTypeNumber*>(m_xTreeView->get_id(*xEntry).toInt64()));
            if (pCnt && pCnt->GetParent()->GetType() == ContentTypeId::OUTLINE)
            {
                if (m_bIsRoot && aCode.GetCode() == KEY_LEFT && aCode.GetModifier() == 0)
                {
                    SelectAll(false);
                    SvTreeListBox::KeyInput(rEvent);
                    m_xTreeView->unselect_all();
                    bConsumed = false;
                }
                else if (aCode.IsMod1())
                {
@@ -3211,135 +3223,91 @@ void SwContentTree::KeyInput(const KeyEvent& rEvent)
                    else if (aCode.GetCode() == KEY_RIGHT)
                        ExecCommand("demote", !aCode.IsShift());
                    else if (aCode.GetCode() == KEY_UP)
                        ExecCommand("up", !aCode.IsShift());
                        ExecCommand("chapterup", !aCode.IsShift());
                    else if (aCode.GetCode() == KEY_DOWN)
                        ExecCommand("down", !aCode.IsShift());
                        ExecCommand("chapterdown", !aCode.IsShift());
                    else
                        SvTreeListBox::KeyInput(rEvent);
                        bConsumed = false;
                }
                else
                    SvTreeListBox::KeyInput(rEvent);
                    bConsumed = false;
            }
            else
                SvTreeListBox::KeyInput(rEvent);
                bConsumed = false;
        }
        else
            bConsumed = false;
    }
    return bConsumed;
}

void SwContentTree::RequestHelp( const HelpEvent& rHEvt )
IMPL_LINK(SwContentTree, QueryTooltipHdl, const weld::TreeIter&, rEntry, OUString)
{
    bool bCallBase = true;
    if( rHEvt.GetMode() & HelpEventMode::QUICK )
    ContentTypeId nType;
    bool bContent = false;
    void* pUserData = reinterpret_cast<void*>(m_xTreeView->get_id(rEntry).toInt64());
    if (lcl_IsContentType(rEntry, *m_xTreeView))
    {
        Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
        SvTreeListEntry* pEntry = GetEntry( aPos );
        if( pEntry )
        assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pUserData)));
        nType = static_cast<SwContentType*>(pUserData)->GetType();
    }
    else
    {
        assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pUserData)));
        nType = static_cast<SwContent*>(pUserData)->GetParent()->GetType();
        bContent = true;
    }
    OUString sEntry;
    if(bContent)
    {
        switch( nType )
        {
            ContentTypeId nType;
            bool bBalloon = false;
            bool bContent = false;
            void* pUserData = pEntry->GetUserData();
            if(lcl_IsContentType(pEntry))
            {
                assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pUserData)));
                nType = static_cast<SwContentType*>(pUserData)->GetType();
            }
            else
            {
                assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pUserData)));
                nType = static_cast<SwContent*>(pUserData)->GetParent()->GetType();
                bContent = true;
            }
            OUString sEntry;
            bool bRet = false;
            if(bContent)
            {
                switch( nType )
                {
                    case ContentTypeId::URLFIELD:
                        assert(dynamic_cast<SwURLFieldContent*>(static_cast<SwTypeNumber*>(pUserData)));
                        sEntry = static_cast<SwURLFieldContent*>(pUserData)->GetURL();
                        bRet = true;
                    break;
            case ContentTypeId::URLFIELD:
                assert(dynamic_cast<SwURLFieldContent*>(static_cast<SwTypeNumber*>(pUserData)));
                sEntry = static_cast<SwURLFieldContent*>(pUserData)->GetURL();
            break;

                    case ContentTypeId::POSTIT:
                        assert(dynamic_cast<SwPostItContent*>(static_cast<SwTypeNumber*>(pUserData)));
                        sEntry = static_cast<SwPostItContent*>(pUserData)->GetName();
                        bRet = true;
                        if(Help::IsBalloonHelpEnabled())
                            bBalloon = true;
                    break;
                    case ContentTypeId::OUTLINE:
                        assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pUserData)));
                        sEntry = static_cast<SwOutlineContent*>(pUserData)->GetName();
                        bRet = true;
                    break;
                    case ContentTypeId::GRAPHIC:
                        assert(dynamic_cast<SwGraphicContent*>(static_cast<SwTypeNumber*>(pUserData)));
                        sEntry = static_cast<SwGraphicContent*>(pUserData)->GetLink();
                        bRet = true;
                    break;
                    default: break;
                }
                if(static_cast<SwContent*>(pUserData)->IsInvisible())
                {
                    if(!sEntry.isEmpty())
                        sEntry += ", ";
                    sEntry += m_sInvisible;
                    bRet = true;
                }
            }
            else
            {
                const size_t nMemberCount = static_cast<SwContentType*>(pUserData)->GetMemberCount();
                sEntry = OUString::number(nMemberCount) + " " +
                    (nMemberCount == 1
                            ? static_cast<SwContentType*>(pUserData)->GetSingleName()
                            : static_cast<SwContentType*>(pUserData)->GetName());
                bRet = true;
            }
            if(bRet)
            {
                SvLBoxTab* pTab;
                SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
                if (pItem && SvLBoxItemType::String == pItem->GetType())
                {
                    aPos = GetEntryPosition( pEntry );

                    aPos.setX( GetTabPos( pEntry, pTab ) );
                    Size aSize(pItem->GetWidth(this, pEntry), pItem->GetHeight(this, pEntry));

                    if((aPos.X() + aSize.Width()) > GetSizePixel().Width())
                        aSize.setWidth( GetSizePixel().Width() - aPos.X() );

                    aPos = OutputToScreenPixel(aPos);
                    tools::Rectangle aItemRect( aPos, aSize );
                    if(bBalloon)
                    {
                        aPos.AdjustX(aSize.Width() );
                        Help::ShowBalloon( this, aPos, aItemRect, sEntry );
                    }
                    else
                        Help::ShowQuickHelp( this, aItemRect, sEntry,
                            QuickHelpFlags::Left|QuickHelpFlags::VCenter );
                    bCallBase = false;
                }
            }
            else
            {
                Help::ShowQuickHelp( this, tools::Rectangle(), OUString() );
                bCallBase = false;
            }
            case ContentTypeId::POSTIT:
                assert(dynamic_cast<SwPostItContent*>(static_cast<SwTypeNumber*>(pUserData)));
                sEntry = static_cast<SwPostItContent*>(pUserData)->GetName();
            break;
            case ContentTypeId::OUTLINE:
                assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pUserData)));
                sEntry = static_cast<SwOutlineContent*>(pUserData)->GetName();
            break;
            case ContentTypeId::GRAPHIC:
                assert(dynamic_cast<SwGraphicContent*>(static_cast<SwTypeNumber*>(pUserData)));
                sEntry = static_cast<SwGraphicContent*>(pUserData)->GetLink();
            break;
            default: break;
        }
        if(static_cast<SwContent*>(pUserData)->IsInvisible())
        {
            if(!sEntry.isEmpty())
                sEntry += ", ";
            sEntry += m_sInvisible;
        }
    }
    if( bCallBase )
        Window::RequestHelp( rHEvt );
    else
    {
        const size_t nMemberCount = static_cast<SwContentType*>(pUserData)->GetMemberCount();
        sEntry = OUString::number(nMemberCount) + " " +
            (nMemberCount == 1
                    ? static_cast<SwContentType*>(pUserData)->GetSingleName()
                    : static_cast<SwContentType*>(pUserData)->GetName());
    }

    return sEntry;
}

void SwContentTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
void SwContentTree::ExecuteContextMenuAction(const OString& rSelectedPopupEntry)
{
    SvTreeListEntry* pFirst = FirstSelected();
    switch( nSelectedPopupEntry )
    std::unique_ptr<weld::TreeIter> xFirst(m_xTreeView->make_iterator());
    if (!m_xTreeView->get_selected(xFirst.get()))
        xFirst.reset();

    auto nSelectedPopupEntry = rSelectedPopupEntry.toUInt32();
    switch (nSelectedPopupEntry)
    {
        case 11:
        case 12:
@@ -3370,18 +3338,18 @@ void SwContentTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
        break;
        case 401:
        case 402:
            EditEntry(pFirst, nSelectedPopupEntry == 401 ? EditEntryMode::RMV_IDX : EditEntryMode::UPD_IDX);
            EditEntry(*xFirst, nSelectedPopupEntry == 401 ? EditEntryMode::RMV_IDX : EditEntryMode::UPD_IDX);
        break;
        // Edit entry
        case 403:
            EditEntry(pFirst, EditEntryMode::EDIT);
            EditEntry(*xFirst, EditEntryMode::EDIT);
        break;
        case 404:
            EditEntry(pFirst, EditEntryMode::UNPROTECT_TABLE);
            EditEntry(*xFirst, EditEntryMode::UNPROTECT_TABLE);
        break;
        case 405 :
        {
            const SwTOXBase* pBase = static_cast<SwTOXBaseContent*>(pFirst->GetUserData())
            const SwTOXBase* pBase = reinterpret_cast<SwTOXBaseContent*>(m_xTreeView->get_id(*xFirst).toInt64())
                                                                ->GetTOXBase();
            m_pActiveShell->SetTOXBaseReadonly(*pBase, !SwEditShell::IsTOXBaseReadonly(*pBase));
        }
@@ -3389,10 +3357,10 @@ void SwContentTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
        case 4:
        break;
        case 501:
            EditEntry(pFirst, EditEntryMode::DELETE);
            EditEntry(*xFirst, EditEntryMode::DELETE);
        break;
        case 502 :
            EditEntry(pFirst, EditEntryMode::RENAME);
            EditEntry(*xFirst, EditEntryMode::RENAME);
        break;
        case 600:
            m_pActiveShell->GetView().GetPostItMgr()->Show();
@@ -3412,13 +3380,13 @@ void SwContentTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
                break;
            }
        case 800:
            KeyInput(KeyEvent(0, KEY_MOD1|KEY_MULTIPLY));
            KeyInputHdl(KeyEvent(0, KEY_MOD1|KEY_MULTIPLY));
            break;
        case 801:
            ExecCommand("up", true);
            ExecCommand("chapterup", true);
            break;
        case 802:
            ExecCommand("down", true);
            ExecCommand("chapterdown", true);
            break;
        case 803:
            ExecCommand("promote", true);
@@ -3431,17 +3399,17 @@ void SwContentTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
            m_pActiveShell->KillPams();
            m_pActiveShell->ClearMark();
            m_pActiveShell->EnterAddMode();
            SwContent* pCnt = static_cast<SwContent*>(pFirst->GetUserData());
            SwContent* pCnt = reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xFirst).toInt64());
            const ContentTypeId eTypeId = pCnt->GetParent()->GetType();
            if (eTypeId == ContentTypeId::OUTLINE)
            {
                for (SvTreeListEntry* pEntry = FirstSelected(); pEntry; pEntry = NextSelected(pEntry))
                {
                m_xTreeView->selected_foreach([this](weld::TreeIter& rEntry){
                    m_pActiveShell->SttSelect();
                    SwOutlineNodes::size_type nActPos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
                    m_pActiveShell->MakeOutlineSel(nActPos, nActPos, !IsExpanded(pEntry), false); // select children if not expanded
                    SwOutlineNodes::size_type nActPos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(rEntry).toInt64())->GetOutlinePos();
                    m_pActiveShell->MakeOutlineSel(nActPos, nActPos, !m_xTreeView->get_row_expanded(rEntry), false); // select children if not expanded
                    m_pActiveShell->EndSelect();
                }
                    return false;
                });
            }
            else if (eTypeId == ContentTypeId::TABLE)
            {
@@ -3463,11 +3431,11 @@ void SwContentTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
        break;
        case 806:
            // Delete outline selections
            EditEntry(pFirst, EditEntryMode::DELETE);
            EditEntry(*xFirst, EditEntryMode::DELETE);
            break;
        case 900:
        {
            SwContent* pCnt = static_cast<SwContent*>(pFirst->GetUserData());
            SwContent* pCnt = reinterpret_cast<SwContent*>(m_xTreeView->get_id(*xFirst).toInt64());
            GotoContent(pCnt);
        }
        break;
@@ -3503,16 +3471,20 @@ void SwContentTree::DeleteOutlineSelections()
    m_pActiveShell->StartAction();
    m_pActiveShell->EnterAddMode();
    auto nChapters(0);
    for (SvTreeListEntry* pEntry = FirstSelected(); pEntry; pEntry = NextSelected(pEntry))
    {

    m_xTreeView->selected_foreach([this, &nChapters](weld::TreeIter& rEntry){
        ++nChapters;
        if ((pEntry->HasChildren() || pEntry->HasChildrenOnDemand()) && !IsExpanded(pEntry)) // only count children if not expanded
            nChapters += pEntry->GetChildEntries().size();
        if (m_xTreeView->iter_has_child(rEntry) &&
            !m_xTreeView->get_row_expanded(rEntry)) // only count children if not expanded
        {
            nChapters += m_xTreeView->iter_n_children(rEntry);
        }
        m_pActiveShell->SttSelect();
        SwOutlineNodes::size_type nActPos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
        m_pActiveShell->MakeOutlineSel(nActPos, nActPos, !IsExpanded(pEntry), false); // select children if not expanded
        SwOutlineNodes::size_type nActPos = reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(rEntry).toInt64())->GetOutlinePos();
        m_pActiveShell->MakeOutlineSel(nActPos, nActPos, !m_xTreeView->get_row_expanded(rEntry), false); // select children if not expanded
        m_pActiveShell->EndSelect();
    }
        return false;
    });
    m_pActiveShell->LeaveAddMode();
    SwRewriter aRewriter;
    aRewriter.AddRule(UndoArg1, SwResId(STR_CHAPTERS, nChapters));
@@ -3540,7 +3512,6 @@ void SwContentTree::SetOutlineLevel(sal_uInt8 nSet)
}

// Mode Change: Show dropped Doc

void SwContentTree::ShowHiddenShell()
{
    if(m_pHiddenShell)
@@ -3551,7 +3522,6 @@ void SwContentTree::ShowHiddenShell()
}

// Mode Change: Show active view

void SwContentTree::ShowActualView()
{
    m_eState = State::ACTIVE;
@@ -3559,38 +3529,42 @@ void SwContentTree::ShowActualView()
    GetParentWindow()->UpdateListBox();
}

// Here the buttons for moving outlines are en-/disabled.
bool SwContentTree::Select( SvTreeListEntry* pEntry, bool bSelect )
IMPL_LINK_NOARG(SwContentTree, SelectHdl, weld::TreeView&, void)
{
    if(!pEntry)
        return false;
    Select();
}

// Here the buttons for moving outlines are en-/disabled.
void SwContentTree::Select()
{
    std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
    if (!m_xTreeView->get_selected(xEntry.get()))
        return;

    bool bEnable = false;
    SvTreeListEntry* pParentEntry = GetParent(pEntry);
    while(pParentEntry && (!lcl_IsContentType(pParentEntry)))
    {
        pParentEntry = GetParent(pParentEntry);
    }
    std::unique_ptr<weld::TreeIter> xParentEntry(m_xTreeView->make_iterator(xEntry.get()));
    bool bParentEntry = m_xTreeView->iter_parent(*xParentEntry);
    while (bParentEntry && (!lcl_IsContentType(*xParentEntry, *m_xTreeView)))
        bParentEntry = m_xTreeView->iter_parent(*xParentEntry);
    if (!m_bIsLastReadOnly)
    {
        if (!IsVisible())
        if (!m_xTreeView->get_visible())
            bEnable = true;
        else if (pParentEntry)
        else if (bParentEntry)
        {
            if ((m_bIsRoot && m_nRootType == ContentTypeId::OUTLINE) ||
                (lcl_IsContent(pEntry) &&
                    static_cast<SwContentType*>(pParentEntry->GetUserData())->GetType() == ContentTypeId::OUTLINE))
                (lcl_IsContent(*xEntry, *m_xTreeView) &&
                    reinterpret_cast<SwContentType*>(m_xTreeView->get_id(*xParentEntry).toInt64())->GetType() == ContentTypeId::OUTLINE))
            {
                bEnable = true;
            }
        }
    }
    SwNavigationPI* pNavi = GetParentWindow();
    pNavi->m_aContentToolBox->EnableItem(pNavi->m_aContentToolBox->GetItemId("up"),  bEnable);
    pNavi->m_aContentToolBox->EnableItem(pNavi->m_aContentToolBox->GetItemId("down"), bEnable);
    pNavi->m_aContentToolBox->EnableItem(pNavi->m_aContentToolBox->GetItemId("promote"), bEnable);
    pNavi->m_aContentToolBox->EnableItem(pNavi->m_aContentToolBox->GetItemId("demote"), bEnable);

    return SvTreeListBox::Select(pEntry, bSelect);
    pNavi->m_xContent3ToolBox->set_item_sensitive("chapterup",  bEnable);
    pNavi->m_xContent3ToolBox->set_item_sensitive("chapterdown", bEnable);
    pNavi->m_xContent3ToolBox->set_item_sensitive("promote", bEnable);
    pNavi->m_xContent3ToolBox->set_item_sensitive("demote", bEnable);
}

void SwContentTree::SetRootType(ContentTypeId nType)
@@ -3613,9 +3587,9 @@ OUString SwContentType::RemoveNewline(const OUString& rEntry)
    return aEntry.makeStringAndClear();
}

void SwContentTree::EditEntry(SvTreeListEntry const * pEntry, EditEntryMode nMode)
void SwContentTree::EditEntry(const weld::TreeIter& rEntry, EditEntryMode nMode)
{
    SwContent* pCnt = static_cast<SwContent*>(pEntry->GetUserData());
    SwContent* pCnt = reinterpret_cast<SwContent*>(m_xTreeView->get_id(rEntry).toInt64());
    GotoContent(pCnt);
    const ContentTypeId nType = pCnt->GetParent()->GetType();
    sal_uInt16 nSlot = 0;
@@ -3822,7 +3796,7 @@ void SwContentTree::EditEntry(SvTreeListEntry const * pEntry, EditEntryMode nMod
        aObj >>= xTmp;
        uno::Reference< container::XNamed >  xNamed(xTmp, uno::UNO_QUERY);
        SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
        ScopedVclPtr<AbstractSwRenameXNamedDlg> pDlg(pFact->CreateSwRenameXNamedDlg(GetFrameWeld(), xNamed, xNameAccess));
        ScopedVclPtr<AbstractSwRenameXNamedDlg> pDlg(pFact->CreateSwRenameXNamedDlg(GetParentWindow()->GetFrameWeld(), xNamed, xNameAccess));
        if(xSecond.is())
            pDlg->SetAlternativeAccess( xSecond, xThird);

@@ -3843,7 +3817,7 @@ void SwContentTree::EditEntry(SvTreeListEntry const * pEntry, EditEntryMode nMod
        m_bViewHasChanged = true;
        GetParentWindow()->UpdateListBox();
        TimerUpdate(&m_aUpdTimer);
        GrabFocus();
        grab_focus();
    }
}

@@ -4004,59 +3978,6 @@ bool NaviContentBookmark::Paste( TransferableDataHelper& rData )
    return bRet;
}

namespace {

class SwContentLBoxString : public SvLBoxString
{
public:
    explicit SwContentLBoxString(const OUString& rStr) : SvLBoxString(rStr) {}

    virtual void Paint(const Point& rPos, SvTreeListBox& rDev, vcl::RenderContext& rRenderContext,
                       const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) override;
};

}

void SwContentTree::InitEntry(SvTreeListEntry* pEntry,
        const OUString& rStr ,const Image& rImg1,const Image& rImg2)
{
    const size_t nColToHilite = 1; //0==Bitmap;1=="Column1";2=="Column2"
    SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2 );
    SvLBoxString& rCol = static_cast<SvLBoxString&>(pEntry->GetItem( nColToHilite ));
    pEntry->ReplaceItem(std::make_unique<SwContentLBoxString>(rCol.GetText()), nColToHilite);
}

void SwContentLBoxString::Paint(const Point& rPos, SvTreeListBox& rDev, vcl::RenderContext& rRenderContext,
                                const SvViewDataEntry* pView, const SvTreeListEntry& rEntry)
{
    if (lcl_IsContent(&rEntry) && static_cast<SwContent *>(rEntry.GetUserData())->IsInvisible())
    {
        vcl::Font aOldFont(rRenderContext.GetFont());
        vcl::Font aFont(aOldFont);
        aFont.SetColor(COL_LIGHTGRAY);
        rRenderContext.SetFont(aFont );
        rRenderContext.DrawText(rPos, GetText());
        rRenderContext.SetFont(aOldFont);
    }
    else
    {
        SvLBoxString::Paint(rPos, rDev, rRenderContext, pView, rEntry);
    }
}

void SwContentTree::DataChanged(const DataChangedEvent& rDCEvt)
{
    if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
         (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
    {
        FindActiveTypeAndRemoveUserData();

        Display(true);
    }

    SvTreeListBox::DataChanged( rDCEvt );
}

SwNavigationPI* SwContentTree::GetParentWindow()
{
    return m_xDialog;
diff --git a/sw/source/uibase/utlui/glbltree.cxx b/sw/source/uibase/utlui/glbltree.cxx
index 43fd340..77ca254 100644
--- a/sw/source/uibase/utlui/glbltree.cxx
+++ b/sw/source/uibase/utlui/glbltree.cxx
@@ -17,6 +17,7 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <o3tl/safeint.hxx>
#include <svl/stritem.hxx>
#include <sfx2/fcontnr.hxx>
#include <sfx2/linkmgr.hxx>
@@ -24,13 +25,14 @@
#include <sfx2/viewfrm.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/docfilt.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/event.hxx>
#include <vcl/help.hxx>
#include <sot/filelist.hxx>
#include <svl/eitem.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/settings.hxx>

#include <vcl/treelistentry.hxx>
#include <sfx2/docinsert.hxx>
#include <sfx2/filedlghelper.hxx>

@@ -53,56 +55,9 @@

using namespace ::com::sun::star::uno;

// Context menu for GlobalTree
#define CTX_INSERT_ANY_INDEX 10
#define CTX_INSERT_FILE     11
#define CTX_INSERT_NEW_FILE 12
#define CTX_INSERT_TEXT     13

#define CTX_UPDATE_SEL      20
#define CTX_UPDATE_INDEX    21
#define CTX_UPDATE_LINK     22
#define CTX_UPDATE_ALL      23

#define CTX_UPDATE          1
#define CTX_INSERT          2
#define CTX_EDIT            3
#define CTX_DELETE          4
#define CTX_EDIT_LINK       5

#define GLOBAL_UPDATE_TIMEOUT 2000

// TabPos: push to left
#define  GLBL_TABPOS_SUB 5

const SfxObjectShell* SwGlobalTree::pShowShell = nullptr;
static const char* aHelpForMenu[] =
{
    nullptr,
    HID_GLBLTREE_UPDATE,        //CTX_UPDATE
    HID_GLBLTREE_INSERT,        //CTX_INSERT
    HID_GLBLTREE_EDIT,          //CTX_EDIT
    HID_GLBLTREE_DEL,           //CTX_DELETE
    HID_GLBLTREE_EDIT_LINK,     //CTX_EDIT_LINK
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    HID_GLBLTREE_INS_IDX,       //CTX_INSERT_ANY_INDEX
    HID_GLBLTREE_INS_FILE,      //CTX_INSERT_FILE
    HID_GLBLTREE_INS_NEW_FILE,  //CTX_INSERT_NEW_FILE
    HID_GLBLTREE_INS_TEXT,      //CTX_INSERT_TEXT
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    HID_GLBLTREE_UPD_SEL,       //CTX_UPDATE_SEL
    HID_GLBLTREE_UPD_IDX,       //CTX_UPDATE_INDEX
    HID_GLBLTREE_UPD_LINK,      //CTX_UPDATE_LINK
    HID_GLBLTREEUPD_ALL         //CTX_UPDATE_ALL
};

namespace {

@@ -169,18 +124,14 @@ static const char* GLOBAL_CONTEXT_ARY[] =
    STR_EDIT_LINK
};

SwGlobalTree::SwGlobalTree(vcl::Window* pParent, SwNavigationPI* pDialog)
    : SvTreeListBox(pParent)
SwGlobalTree::SwGlobalTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog)
    : m_xTreeView(std::move(xTreeView))
    , m_aDropTargetHelper(*this)
    , m_xDialog(pDialog)
    , m_pActiveShell(nullptr)
    , m_pEmphasisEntry(nullptr)
    , m_pDDSource(nullptr)
    , m_bIsInternalDrag(false)
    , m_bLastEntryEmphasis(false)
{
    SetDragDropMode(DragDropMode::APP_COPY  |
                    DragDropMode::CTRL_MOVE |
                    DragDropMode::ENABLE_TOP );
    Size aSize(m_xDialog->LogicToPixel(Size(110, 112), MapMode(MapUnit::MapAppFont)));;
    m_xTreeView->set_size_request(aSize.Width(), aSize.Height());

    m_aUpdateTimer.SetTimeout(GLOBAL_UPDATE_TIMEOUT);
    m_aUpdateTimer.SetInvokeHandler(LINK(this, SwGlobalTree, Timeout));
@@ -189,68 +140,57 @@ SwGlobalTree::SwGlobalTree(vcl::Window* pParent, SwNavigationPI* pDialog)
    {
        m_aContextStrings[i] = SwResId(GLOBAL_CONTEXT_ARY[i]);
    }
    SetHelpId(HID_NAVIGATOR_GLOB_TREELIST);
    SelectHdl();
    SetDoubleClickHdl(LINK(this, SwGlobalTree, DoubleClickHdl));
    EnableContextMenuHandling();
    m_xTreeView->set_help_id(HID_NAVIGATOR_GLOB_TREELIST);
    Select();
    m_xTreeView->connect_row_activated(LINK(this, SwGlobalTree, DoubleClickHdl));
    m_xTreeView->connect_changed(LINK(this, SwGlobalTree, SelectHdl));
    m_xTreeView->connect_focus_in(LINK(this, SwGlobalTree, FocusInHdl));
    m_xTreeView->connect_key_press(LINK(this, SwGlobalTree, KeyInputHdl));
    m_xTreeView->connect_popup_menu(LINK(this, SwGlobalTree, CommandHdl));
    m_xTreeView->connect_query_tooltip(LINK(this, SwGlobalTree, QueryTooltipHdl));
}

SwGlobalTree::~SwGlobalTree()
{
    disposeOnce();
}

void SwGlobalTree::dispose()
{
    m_pSwGlblDocContents.reset();
    m_pDocInserter.reset();
    m_aUpdateTimer.Stop();
    m_xDialog.clear();
    SvTreeListBox::dispose();
}

Size SwGlobalTree::GetOptimalSize() const
SwGlobalTreeDropTarget::SwGlobalTreeDropTarget(SwGlobalTree& rTreeView)
    : DropTargetHelper(rTreeView.get_widget().get_drop_target())
    , m_rTreeView(rTreeView)
{
    return LogicToPixel(Size(110, 112), MapMode(MapUnit::MapAppFont));
}

sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
sal_Int8 SwGlobalTreeDropTarget::ExecuteDrop( const ExecuteDropEvent& rEvt )
{
    sal_Int8 nRet = DND_ACTION_NONE;
    SvTreeListEntry* pLast = LastVisible();
    if(m_pEmphasisEntry)
    {
        ImplShowTargetEmphasis( Prev(m_pEmphasisEntry), false );
        m_pEmphasisEntry = nullptr;
    }
    else if(m_bLastEntryEmphasis && pLast)
    {
        ImplShowTargetEmphasis( pLast, false);
    }

    SvTreeListEntry* pDropEntry = m_bLastEntryEmphasis ? nullptr : GetEntry(rEvt.maPosPixel);
    if( m_bIsInternalDrag )
    {
        SvTreeListEntry* pDummy = nullptr;
        sal_uLong nInsertionPos = TREELIST_APPEND;
        NotifyMoving( pDropEntry, m_pDDSource, pDummy, nInsertionPos );
    }
    weld::TreeView& rWidget = m_rTreeView.get_widget();
    std::unique_ptr<weld::TreeIter> xDropEntry(rWidget.make_iterator());
    if (!rWidget.get_dest_row_at_pos(rEvt.maPosPixel, xDropEntry.get()))
        xDropEntry.reset();

    if (rWidget.get_drag_source() == &rWidget)  // internal drag
        m_rTreeView.MoveSelectionTo(xDropEntry.get());
    else
    {
        TransferableDataHelper aData( rEvt.maDropEvent.Transferable );

        OUString sFileName;
        const SwGlblDocContent* pCnt = pDropEntry ?
                    static_cast<const SwGlblDocContent*>(pDropEntry->GetUserData()) :
        const SwGlblDocContent* pCnt = xDropEntry ?
                    reinterpret_cast<const SwGlblDocContent*>(rWidget.get_id(*xDropEntry).toInt64()) :
                            nullptr;
        if( aData.HasFormat( SotClipboardFormatId::FILE_LIST ))
        {
            nRet = rEvt.mnAction;
            std::unique_ptr<SwGlblDocContents> pTempContents(new SwGlblDocContents);
            int nAbsContPos = pDropEntry ?
                                static_cast<int>(GetModel()->GetAbsPos(pDropEntry)):
            int nAbsContPos = xDropEntry ?
                                rWidget.get_iter_index_in_parent(*xDropEntry):
                                    - 1;
            sal_uLong nEntryCount = GetEntryCount();
            size_t nEntryCount = rWidget.n_children();

            // Get data
            FileList aFileList;
@@ -258,12 +198,12 @@ sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
            for ( size_t n = aFileList.Count(); n--; )
            {
                sFileName = aFileList.GetFile(n);
                InsertRegion(pCnt, &sFileName);
                m_rTreeView.InsertRegion(pCnt, &sFileName);
                // The list of contents must be newly fetched after inserting,
                // to not work on an old content.
                if(n)
                {
                    m_pActiveShell->GetGlobalDocContent(*pTempContents);
                    m_rTreeView.GetActiveWrtShell()->GetGlobalDocContent(*pTempContents);
                    // If the file was successfully inserted,
                    // then the next content must also be fetched.
                    if(nEntryCount < pTempContents->size())
@@ -283,178 +223,105 @@ sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
            if( !aDesc.Detect() )   // accept no graphics
            {
                nRet = rEvt.mnAction;
                InsertRegion(pCnt, &sFileName);
                m_rTreeView.InsertRegion(pCnt, &sFileName);
            }
        }
    }
    m_bLastEntryEmphasis = false;
    return nRet;

}

sal_Int8 SwGlobalTree::AcceptDrop( const AcceptDropEvent& rEvt )
sal_Int8 SwGlobalTreeDropTarget::AcceptDrop( const AcceptDropEvent& rEvt )
{
    // to enable the autoscroll when we're close to the edges
    weld::TreeView& rWidget = m_rTreeView.get_widget();
    rWidget.get_dest_row_at_pos(rEvt.maPosPixel, nullptr);

    sal_Int8 nRet = rEvt.mnAction;

    //initiate scrolling
    GetDropTarget( rEvt.maPosPixel );
    SvTreeListEntry* pLast = LastVisible();
    if( rEvt.mbLeaving )
    {
        if( m_pEmphasisEntry )
        {
            ImplShowTargetEmphasis( Prev(m_pEmphasisEntry), false );
            m_pEmphasisEntry = nullptr;
        }
        else if(m_bLastEntryEmphasis && pLast)
        {
            ImplShowTargetEmphasis( pLast, false);
        }
        m_bLastEntryEmphasis = false;
    }
    else
    {
        SvTreeListEntry* pDropEntry = GetEntry( rEvt.maPosPixel );
        if(m_bIsInternalDrag)
        {
            if( m_pDDSource != pDropEntry )
                nRet = rEvt.mnAction;
        }
        else if( IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE ) ||
                  IsDropFormatSupported( SotClipboardFormatId::STRING ) ||
                  IsDropFormatSupported( SotClipboardFormatId::FILE_LIST ) ||
                  IsDropFormatSupported( SotClipboardFormatId::SOLK ) ||
                   IsDropFormatSupported( SotClipboardFormatId::NETSCAPE_BOOKMARK )||
                   IsDropFormatSupported( SotClipboardFormatId::FILECONTENT ) ||
                   IsDropFormatSupported( SotClipboardFormatId::FILEGRPDESCRIPTOR ) ||
                   IsDropFormatSupported( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ) ||
                   IsDropFormatSupported( SotClipboardFormatId::FILENAME ))
                nRet = DND_ACTION_LINK;
    if (rWidget.get_drag_source() == &rWidget)  // internal drag
        return nRet;

        if(m_pEmphasisEntry && m_pEmphasisEntry != pDropEntry)
            ImplShowTargetEmphasis( Prev(m_pEmphasisEntry), false );
        else if(pLast && m_bLastEntryEmphasis  && pDropEntry)
        {
            ImplShowTargetEmphasis( pLast, false);
            m_bLastEntryEmphasis = false;
        }

        if(pDropEntry)
            ImplShowTargetEmphasis( Prev(pDropEntry), DND_ACTION_NONE != nRet );
        else if(pLast)
        {
            ImplShowTargetEmphasis( pLast, DND_ACTION_NONE != nRet );
            m_bLastEntryEmphasis = true;
        }
        m_pEmphasisEntry = pDropEntry;
    if (IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE) ||
        IsDropFormatSupported( SotClipboardFormatId::STRING) ||
        IsDropFormatSupported( SotClipboardFormatId::FILE_LIST) ||
        IsDropFormatSupported( SotClipboardFormatId::SOLK) ||
        IsDropFormatSupported( SotClipboardFormatId::NETSCAPE_BOOKMARK )||
        IsDropFormatSupported( SotClipboardFormatId::FILECONTENT) ||
        IsDropFormatSupported( SotClipboardFormatId::FILEGRPDESCRIPTOR) ||
        IsDropFormatSupported( SotClipboardFormatId::UNIFORMRESOURCELOCATOR) ||
        IsDropFormatSupported( SotClipboardFormatId::FILENAME))
    {
        nRet = DND_ACTION_LINK;
    }

    return nRet;
}

VclPtr<PopupMenu> SwGlobalTree::CreateContextMenu()
IMPL_LINK(SwGlobalTree, CommandHdl, const CommandEvent&, rCEvt, bool)
{
    VclPtr<PopupMenu> pPop;
    if(m_pActiveShell &&
        !m_pActiveShell->GetView().GetDocShell()->IsReadOnly())
    if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
        return false;

    bool bPop = false;
    if (m_pActiveShell && !m_pActiveShell->GetView().GetDocShell()->IsReadOnly())
    {
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xTreeView.get(), "modules/swriter/ui/mastercontextmenu.ui"));
        std::unique_ptr<weld::Menu> xPopup = xBuilder->weld_menu("navmenu");

        const MenuEnableFlags nEnableFlags = GetEnableFlags();
        pPop = VclPtr<PopupMenu>::Create();
        VclPtrInstance<PopupMenu> pSubPop1;
        VclPtrInstance<PopupMenu> pSubPop2;

        for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
        {
            pSubPop2->InsertItem( i, m_aContextStrings[IDX_STR_UPDATE_SEL + i - CTX_UPDATE_SEL] );
            pSubPop2->SetHelpId(i, aHelpForMenu[i]);
        }
        pSubPop2->EnableItem(CTX_UPDATE_SEL, bool(nEnableFlags & MenuEnableFlags::UpdateSel));
        xPopup->set_sensitive("updatesel", bool(nEnableFlags & MenuEnableFlags::UpdateSel));

        pSubPop1->InsertItem(CTX_INSERT_ANY_INDEX, m_aContextStrings[IDX_STR_INDEX]);
        pSubPop1->SetHelpId(CTX_INSERT_ANY_INDEX, aHelpForMenu[CTX_INSERT_ANY_INDEX]);
        pSubPop1->InsertItem(CTX_INSERT_FILE, m_aContextStrings[IDX_STR_FILE]);
        pSubPop1->SetHelpId(CTX_INSERT_FILE, aHelpForMenu[CTX_INSERT_FILE]);
        pSubPop1->InsertItem(CTX_INSERT_NEW_FILE, m_aContextStrings[IDX_STR_NEW_FILE]);
        pSubPop1->SetHelpId(CTX_INSERT_NEW_FILE, aHelpForMenu[CTX_INSERT_NEW_FILE]);
        pSubPop1->InsertItem(CTX_INSERT_TEXT, m_aContextStrings[IDX_STR_INSERT_TEXT]);
        pSubPop1->SetHelpId(CTX_INSERT_TEXT, aHelpForMenu[CTX_INSERT_TEXT]);

        pPop->InsertItem(CTX_UPDATE, m_aContextStrings[IDX_STR_UPDATE]);
        pPop->SetHelpId(CTX_UPDATE, aHelpForMenu[CTX_UPDATE]);
        pPop->InsertItem(CTX_EDIT, m_aContextStrings[IDX_STR_EDIT_CONTENT]);
        pPop->SetHelpId(CTX_EDIT, aHelpForMenu[CTX_EDIT]);
        if(nEnableFlags&MenuEnableFlags::EditLink)
        {
            pPop->InsertItem(CTX_EDIT_LINK, m_aContextStrings[IDX_STR_EDIT_LINK]);
            pPop->SetHelpId(CTX_EDIT_LINK, aHelpForMenu[CTX_EDIT_LINK]);
        }
        pPop->InsertItem(CTX_INSERT, m_aContextStrings[IDX_STR_EDIT_INSERT]);
        pPop->SetHelpId(CTX_INSERT, aHelpForMenu[CTX_INSERT]);
        pPop->InsertSeparator() ;
        pPop->InsertItem(CTX_DELETE, m_aContextStrings[IDX_STR_DELETE]);
        pPop->SetHelpId(CTX_DELETE, aHelpForMenu[CTX_DELETE]);
        xPopup->set_sensitive("editlink", bool(nEnableFlags & MenuEnableFlags::EditLink));

        //disabling if applicable
        pSubPop1->EnableItem(CTX_INSERT_ANY_INDEX,  bool(nEnableFlags & MenuEnableFlags::InsertIdx ));
        pSubPop1->EnableItem(CTX_INSERT_TEXT,       bool(nEnableFlags & MenuEnableFlags::InsertText));
        pSubPop1->EnableItem(CTX_INSERT_FILE,       bool(nEnableFlags & MenuEnableFlags::InsertFile));
        pSubPop1->EnableItem(CTX_INSERT_NEW_FILE,   bool(nEnableFlags & MenuEnableFlags::InsertFile));
        xPopup->set_sensitive("insertindex", bool(nEnableFlags & MenuEnableFlags::InsertIdx ));
        xPopup->set_sensitive("insertfile", bool(nEnableFlags & MenuEnableFlags::InsertFile));
        xPopup->set_sensitive("insertnewfile", bool(nEnableFlags & MenuEnableFlags::InsertFile));
        xPopup->set_sensitive("inserttext", bool(nEnableFlags & MenuEnableFlags::InsertText));

        pPop->EnableItem(CTX_UPDATE,    bool(nEnableFlags & MenuEnableFlags::Update));
        pPop->EnableItem(CTX_INSERT,    bool(nEnableFlags & MenuEnableFlags::InsertIdx));
        pPop->EnableItem(CTX_EDIT,      bool(nEnableFlags & MenuEnableFlags::Edit));
        pPop->EnableItem(CTX_DELETE,    bool(nEnableFlags & MenuEnableFlags::Delete));
        xPopup->set_sensitive("update", bool(nEnableFlags & MenuEnableFlags::Update));
        xPopup->set_sensitive("insert", bool(nEnableFlags & MenuEnableFlags::InsertIdx));
        xPopup->set_sensitive("editcontent", bool(nEnableFlags & MenuEnableFlags::Edit));
        xPopup->set_sensitive("deleteentry", bool(nEnableFlags & MenuEnableFlags::Delete));

        pPop->SetPopupMenu( CTX_INSERT, pSubPop1 );
        pPop->SetPopupMenu( CTX_UPDATE, pSubPop2 );
        OString sCommand = xPopup->popup_at_rect(m_xTreeView.get(), tools::Rectangle(rCEvt.GetMousePosPixel(), Size(1,1)));
        if (!sCommand.isEmpty())
            ExecuteContextMenuAction(sCommand);
    }
    return pPop;
    return bPop;
}

void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox)
void SwGlobalTree::TbxMenuHdl(const OString& rCommand, weld::Menu& rMenu)
{
    const MenuEnableFlags nEnableFlags = GetEnableFlags();
    const OUString sCommand(pBox->GetItemCommand(nTbxId));
    if (sCommand == "insert")
    if (rCommand == "insert")
    {
        ScopedVclPtrInstance<PopupMenu> pMenu;
        for (sal_uInt16 i = CTX_INSERT_ANY_INDEX; i <= CTX_INSERT_TEXT; ++i)
        {
            pMenu->InsertItem( i, m_aContextStrings[IDX_STR_INDEX + i - CTX_INSERT_ANY_INDEX] );
            pMenu->SetHelpId(i, aHelpForMenu[i] );
        }
        pMenu->EnableItem(CTX_INSERT_ANY_INDEX, bool(nEnableFlags & MenuEnableFlags::InsertIdx ));
        pMenu->EnableItem(CTX_INSERT_TEXT,      bool(nEnableFlags & MenuEnableFlags::InsertText));
        pMenu->EnableItem(CTX_INSERT_FILE,      bool(nEnableFlags & MenuEnableFlags::InsertFile));
        pMenu->EnableItem(CTX_INSERT_NEW_FILE,  bool(nEnableFlags & MenuEnableFlags::InsertFile));
        pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
        pMenu->Execute(pBox, pBox->GetItemRect(nTbxId));
        pMenu.disposeAndClear();
        pBox->EndSelection();
        pBox->Invalidate();
        rMenu.set_sensitive("insertindex", bool(nEnableFlags & MenuEnableFlags::InsertIdx));
        rMenu.set_sensitive("insertfile", bool(nEnableFlags & MenuEnableFlags::InsertFile));
        rMenu.set_sensitive("insertnewfile", bool(nEnableFlags & MenuEnableFlags::InsertFile));
        rMenu.set_sensitive("inserttext", bool(nEnableFlags & MenuEnableFlags::InsertText));
    }
    else if (sCommand == "update")
    else if (rCommand == "update")
    {
        ScopedVclPtrInstance<PopupMenu> pMenu;
        for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
        {
            pMenu->InsertItem( i, m_aContextStrings[IDX_STR_UPDATE_SEL + i - CTX_UPDATE_SEL] );
            pMenu->SetHelpId(i, aHelpForMenu[i] );
        }
        pMenu->EnableItem(CTX_UPDATE_SEL, bool(nEnableFlags & MenuEnableFlags::UpdateSel));
        pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
        pMenu->Execute(pBox, pBox->GetItemRect(nTbxId));
        pMenu.disposeAndClear();
        pBox->EndSelection();
        pBox->Invalidate();
        rMenu.set_sensitive("updatesel", bool(nEnableFlags & MenuEnableFlags::UpdateSel));
    }
}

MenuEnableFlags  SwGlobalTree::GetEnableFlags() const
MenuEnableFlags SwGlobalTree::GetEnableFlags() const
{
    SvTreeListEntry* pEntry = FirstSelected();
    sal_uLong nSelCount = GetSelectionCount();
    sal_uLong nEntryCount = GetEntryCount();
    SvTreeListEntry* pPrevEntry = pEntry ? Prev(pEntry) : nullptr;
    std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
    bool bEntry = m_xTreeView->get_selected(xEntry.get());

    sal_uLong nSelCount = m_xTreeView->count_selected_rows();
    size_t nEntryCount = m_xTreeView->n_children();
    std::unique_ptr<weld::TreeIter> xPrevEntry;
    bool bPrevEntry = false;
    if (bEntry)
    {
        xPrevEntry = m_xTreeView->make_iterator(xEntry.get());
        bPrevEntry = m_xTreeView->iter_previous(*xPrevEntry);
    }

    MenuEnableFlags nRet = MenuEnableFlags::NONE;
    if(nSelCount == 1 || !nEntryCount)
@@ -462,10 +329,10 @@ MenuEnableFlags  SwGlobalTree::GetEnableFlags() const
    if(nSelCount == 1)
    {
        nRet |= MenuEnableFlags::Edit;
        if (pEntry && static_cast<SwGlblDocContent*>(pEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN &&
                    (!pPrevEntry || static_cast<SwGlblDocContent*>(pPrevEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN))
        if (bEntry && reinterpret_cast<SwGlblDocContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetType() != GLBLDOC_UNKNOWN &&
                    (!bPrevEntry || reinterpret_cast<SwGlblDocContent*>(m_xTreeView->get_id(*xPrevEntry).toInt64())->GetType() != GLBLDOC_UNKNOWN))
            nRet |= MenuEnableFlags::InsertText;
        if (pEntry && GLBLDOC_SECTION == static_cast<SwGlblDocContent*>(pEntry->GetUserData())->GetType())
        if (bEntry && GLBLDOC_SECTION == reinterpret_cast<SwGlblDocContent*>(m_xTreeView->get_id(*xEntry).toInt64())->GetType())
            nRet |= MenuEnableFlags::EditLink;
    }
    else if(!nEntryCount)
@@ -479,255 +346,165 @@ MenuEnableFlags  SwGlobalTree::GetEnableFlags() const
    return nRet;
}

void     SwGlobalTree::RequestHelp( const HelpEvent& rHEvt )
IMPL_LINK(SwGlobalTree, QueryTooltipHdl, const weld::TreeIter&, rIter, OUString)
{
    bool bParent = true;
    Update(true);
    Display(true);
    if( rHEvt.GetMode() & HelpEventMode::QUICK )
    OUString sEntry;

    const SwGlblDocContent* pCont = reinterpret_cast<const SwGlblDocContent*>(m_xTreeView->get_id(rIter).toInt64());
    if (pCont && GLBLDOC_SECTION == pCont->GetType())
    {
        Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
        SvTreeListEntry* pEntry = GetEntry( aPos );
        const SwGlblDocContent* pCont = pEntry ?
                            static_cast<const SwGlblDocContent*>(pEntry->GetUserData()) : nullptr;
        if( pCont &&  GLBLDOC_SECTION == pCont->GetType())
        {
            bParent = false;
            SvLBoxTab* pTab;
            SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
            if (pItem && SvLBoxItemType::String == pItem->GetType())
            {
                const SwSection* pSect = pCont->GetSection();
                OUString sEntry = pSect->GetLinkFileName().getToken(0, sfx2::cTokenSeparator);
                if(!pSect->IsConnectFlag())
                    sEntry = m_aContextStrings[IDX_STR_BROKEN_LINK] + sEntry;
                Point aEntryPos = GetEntryPosition( pEntry );

                aEntryPos.setX( GetTabPos( pEntry, pTab ) );
                Size aSize(pItem->GetWidth(this, pEntry), pItem->GetHeight(this, pEntry));

                if((aEntryPos.X() + aSize.Width()) > GetSizePixel().Width())
                    aSize.setWidth( GetSizePixel().Width() - aEntryPos.X() );

                aEntryPos = OutputToScreenPixel(aEntryPos);
                tools::Rectangle aItemRect( aEntryPos, aSize );
                if(Help::IsBalloonHelpEnabled())
                {
                    aEntryPos.AdjustX(aSize.Width() );
                    Help::ShowBalloon( this, aEntryPos, aItemRect, sEntry );
                }
                else
                    Help::ShowQuickHelp( this, aItemRect, sEntry,
                        QuickHelpFlags::Left|QuickHelpFlags::VCenter );
            }
        }
        const SwSection* pSect = pCont->GetSection();
        sEntry = pSect->GetLinkFileName().getToken(0, sfx2::cTokenSeparator);
        if (!pSect->IsConnectFlag())
            sEntry = m_aContextStrings[IDX_STR_BROKEN_LINK] + sEntry;
    }

    if(bParent)
        SvTreeListBox::RequestHelp(rHEvt);
    return sEntry;
}

void     SwGlobalTree::SelectHdl()
IMPL_LINK_NOARG(SwGlobalTree, SelectHdl, weld::TreeView&, void)
{
    Select();
}

    sal_uLong nSelCount = GetSelectionCount();
    SvTreeListEntry* pSel = FirstSelected();
    sal_uLong nAbsPos = pSel ? GetModel()->GetAbsPos(pSel) : 0;
void SwGlobalTree::Select()
{
    int nSelCount = m_xTreeView->count_selected_rows();
    int nSel = m_xTreeView->get_selected_index();
    int nAbsPos = nSel != -1 ? nSel : 0;
    SwNavigationPI* pNavi = GetParentWindow();
    bool bReadonly = !m_pActiveShell ||
                m_pActiveShell->GetView().GetDocShell()->IsReadOnly();
    pNavi->m_aGlobalToolBox->EnableItem(pNavi->m_aGlobalToolBox->GetItemId("edit"),  nSelCount == 1 && !bReadonly);
    pNavi->m_aGlobalToolBox->EnableItem(pNavi->m_aGlobalToolBox->GetItemId("insert"),  nSelCount <= 1 && !bReadonly);
    pNavi->m_aGlobalToolBox->EnableItem(pNavi->m_aGlobalToolBox->GetItemId("update"),  GetEntryCount() > 0 && !bReadonly);
    pNavi->m_aGlobalToolBox->EnableItem(pNavi->m_aGlobalToolBox->GetItemId("up"),
    pNavi->m_xGlobalToolBox->set_item_sensitive("edit",  nSelCount == 1 && !bReadonly);
    pNavi->m_xGlobalToolBox->set_item_sensitive("insert",  nSelCount <= 1 && !bReadonly);
    pNavi->m_xGlobalToolBox->set_item_sensitive("update",  m_xTreeView->n_children() > 0 && !bReadonly);
    pNavi->m_xGlobalToolBox->set_item_sensitive("moveup",
                    nSelCount == 1 && nAbsPos && !bReadonly);
    pNavi->m_aGlobalToolBox->EnableItem(pNavi->m_aGlobalToolBox->GetItemId("down"),
                    nSelCount == 1 && nAbsPos < GetEntryCount() - 1 && !bReadonly);
    pNavi->m_xGlobalToolBox->set_item_sensitive("movedown",
                    nSelCount == 1 && nAbsPos < m_xTreeView->n_children() - 1 && !bReadonly);

}

void     SwGlobalTree::DeselectHdl()
void SwGlobalTree::MoveSelectionTo(weld::TreeIter* pDropEntry)
{
    SelectHdl();
}
    int nSource = m_xTreeView->get_selected_index();

DragDropMode SwGlobalTree::NotifyStartDrag( TransferDataContainer& ,
                                                SvTreeListEntry* pEntry )
{
    m_bIsInternalDrag = true;
    m_pDDSource = pEntry;
    return DragDropMode::CTRL_MOVE;
}
    int nDest = pDropEntry ? m_xTreeView->get_iter_index_in_parent(*pDropEntry)
                           : m_pSwGlblDocContents->size();

sal_IntPtr SwGlobalTree::GetTabPos( SvTreeListEntry*, SvLBoxTab* pTab)
{
    return pTab->GetPos() - GLBL_TABPOS_SUB;
}

TriState SwGlobalTree::NotifyMoving(   SvTreeListEntry*  pTarget,
                                        SvTreeListEntry*  pSource,
                                        SvTreeListEntry*&,
                                        sal_uLong&
                                    )
{
    SvTreeList* _pModel = GetModel();
    sal_uLong nSource = _pModel->GetAbsPos(pSource);
    sal_uLong nDest   = pTarget ? _pModel->GetAbsPos(pTarget) : m_pSwGlblDocContents->size();

    if( m_pActiveShell->MoveGlobalDocContent(
    if (m_pActiveShell->MoveGlobalDocContent(
            *m_pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
            Update( false ))
        Display();

    return TRISTATE_FALSE;
}

TriState SwGlobalTree::NotifyCopying(  SvTreeListEntry*  /*pTarget*/,
                                        SvTreeListEntry*  /*pEntry*/,
                                        SvTreeListEntry*& /*rpNewParent*/,
                                        sal_uLong&        /*rNewChildPos*/
                                    )
IMPL_LINK_NOARG(SwGlobalTree, FocusInHdl, weld::Widget&, void)
{
    return TRISTATE_FALSE;
}

bool SwGlobalTree::NotifyAcceptDrop( SvTreeListEntry* pEntry)
{
    return pEntry != nullptr;
}

void SwGlobalTree::StartDrag( sal_Int8 nAction, const Point& rPt )
{
    if( 1 == GetSelectionCount() )
        SvTreeListBox::StartDrag( nAction, rPt );
}

void SwGlobalTree::DragFinished( sal_Int8 nAction )
{
    SvTreeListBox::DragFinished( nAction );
    m_bIsInternalDrag = false;
}

// If a Ctrl+DoubleClick is executed in an empty area,
// then the base function of the control should be called.

void  SwGlobalTree::MouseButtonDown( const MouseEvent& rMEvt )
{
    Point aPos( rMEvt.GetPosPixel());
    SvTreeListEntry* pEntry = GetEntry( aPos, true );
    if( !pEntry && rMEvt.IsLeft() && rMEvt.IsMod1() && (rMEvt.GetClicks() % 2) == 0)
        Control::MouseButtonDown( rMEvt );
    else
        SvTreeListBox::MouseButtonDown( rMEvt );
}

void     SwGlobalTree::GetFocus()
{
    if(Update( false ))
    if (Update(false))
        Display();
    SvTreeListBox::GetFocus();
}

void     SwGlobalTree::KeyInput(const KeyEvent& rKEvt)
IMPL_LINK(SwGlobalTree, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
    bool bHandled = false;
    const vcl::KeyCode aCode = rKEvt.GetKeyCode();
    if(aCode.GetCode() == KEY_RETURN)
    if (aCode.GetCode() == KEY_RETURN)
    {
        switch(aCode.GetModifier())
        switch (aCode.GetModifier())
        {
            case KEY_MOD2:
                // Switch boxes
                GetParentWindow()->ToggleTree();
                bHandled = true;
            break;
        }
    }
    else
        SvTreeListBox::KeyInput(rKEvt);
}

void SwGlobalTree::Clear()
{
    m_pEmphasisEntry = nullptr;
    SvTreeListBox::Clear();
    return bHandled;
}

void SwGlobalTree::Display(bool bOnlyUpdateUserData)
{
    size_t nCount = m_pSwGlblDocContents->size();
    if(bOnlyUpdateUserData && GetEntryCount() == m_pSwGlblDocContents->size())
    size_t nChildren = m_xTreeView->n_children();
    if (bOnlyUpdateUserData && nChildren == m_pSwGlblDocContents->size())
    {
        SvTreeListEntry* pEntry = First();
        for (size_t i = 0; i < nCount && pEntry; i++)
        std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
        bool bEntry = m_xTreeView->get_iter_first(*xEntry);
        for (size_t i = 0; i < nCount && bEntry; i++)
        {
            SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i].get();
            pEntry->SetUserData(pCont);
            pEntry = Next(pEntry);
            assert(pEntry || i == nCount - 1);
            const SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i].get();
            OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pCont)));
            m_xTreeView->set_id(*xEntry, sId);
            if (pCont->GetType() == GLBLDOC_SECTION && !pCont->GetSection()->IsConnectFlag())
                m_xTreeView->set_font_color(*xEntry, COL_LIGHTRED);
            else
                m_xTreeView->set_font_color(*xEntry, COL_AUTO);
            bEntry = m_xTreeView->iter_next(*xEntry);
            assert(bEntry || i == nCount - 1);
        }
    }
    else
    {
        SetUpdateMode( false );
        SvTreeListEntry* pOldSelEntry = FirstSelected();
        int nOldSelEntry = m_xTreeView->get_selected_index();
        OUString sEntryName;  // Name of the entry
        sal_uLong nSelPos = TREELIST_ENTRY_NOTFOUND;
        if(pOldSelEntry)
        int nSelPos = -1;
        if (nOldSelEntry != -1)
        {
            sEntryName = GetEntryText(pOldSelEntry);
            nSelPos = GetModel()->GetAbsPos(pOldSelEntry);
            sEntryName = m_xTreeView->get_text(nOldSelEntry);
            nSelPos = nOldSelEntry;
        }
        Clear();
        if(!m_pSwGlblDocContents)
        m_xTreeView->freeze();
        m_xTreeView->clear();
        if (!m_pSwGlblDocContents)
            Update( false );

        SvTreeListEntry* pSelEntry = nullptr;
        for( size_t i = 0; i < nCount; i++)
        int nSelEntry = -1;
        for (size_t i = 0; i < nCount; ++i)
        {
            SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i].get();
            const SwGlblDocContent* pCont = (*m_pSwGlblDocContents)[i].get();

            OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pCont)));
            OUString sEntry;
            Image aImage;
            switch( pCont->GetType()  )
            OUString aImage;
            switch (pCont->GetType())
            {
                case GLBLDOC_UNKNOWN:
                {
                    sEntry = m_aContextStrings[IDX_STR_INSERT_TEXT];
                }
                break;
                case GLBLDOC_TOXBASE:
                {
                    const SwTOXBase* pBase = pCont->GetTOX();
                    sEntry = pBase->GetTitle();
                    aImage = Image(StockImage::Yes, RID_BMP_NAVI_INDEX);
                    aImage = RID_BMP_NAVI_INDEX;
                }
                break;
                case GLBLDOC_SECTION:
                {
                    const SwSection* pSect = pCont->GetSection();
                    sEntry = pSect->GetSectionName();
                    aImage = Image(StockImage::Yes, RID_BMP_DROP_REGION);
                    aImage = RID_BMP_DROP_REGION;
                }
                break;
            }
            SvTreeListEntry* pEntry = InsertEntry(sEntry, aImage, aImage,
                        nullptr, false, TREELIST_APPEND, pCont);
            if(sEntry == sEntryName)
            {
                pSelEntry = pEntry;
            }

            m_xTreeView->append(sId, sEntry);
            if (!aImage.isEmpty())
                m_xTreeView->set_image(i, aImage);

            if (pCont->GetType() == GLBLDOC_SECTION && !pCont->GetSection()->IsConnectFlag())
                m_xTreeView->set_font_color(i, COL_LIGHTRED);

            if (sEntry == sEntryName)
                nSelEntry = i;
        }
        if(pSelEntry)
        {
            Select(pSelEntry);
        }
        else if(nSelPos != TREELIST_ENTRY_NOTFOUND && nSelPos < nCount)
        {
            Select(GetEntry(nSelPos));
        }
        else if(nCount)
            Select(First());
        else
            SelectHdl();
        SetUpdateMode( true );
        m_xTreeView->thaw();
        if (nSelEntry != -1)
            m_xTreeView->select(nSelEntry);
        else if (nSelPos != -1 && o3tl::make_unsigned(nSelPos) < nCount)
            m_xTreeView->select(nSelPos);
        else if (nCount)
            m_xTreeView->select(0);
        Select();
    }
}

@@ -736,7 +513,7 @@ void SwGlobalTree::InsertRegion( const SwGlblDocContent* pCont, const OUString* 
    Sequence< OUString > aFileNames;
    if ( !pFileName )
    {
        m_pDocInserter.reset(new ::sfx2::DocumentInserter(GetFrameWeld(), "swriter", sfx2::DocumentInserter::Mode::InsertMulti));
        m_pDocInserter.reset(new ::sfx2::DocumentInserter(GetParentWindow()->GetFrameWeld(), "swriter", sfx2::DocumentInserter::Mode::InsertMulti));
        m_pDocInserter->StartExecuteModal( LINK( this, SwGlobalTree, DialogClosedHdl ) );
    }
    else if ( !pFileName->isEmpty() )
@@ -749,7 +526,7 @@ void SwGlobalTree::InsertRegion( const SwGlblDocContent* pCont, const OUString* 
    }
}

void    SwGlobalTree::EditContent(const SwGlblDocContent* pCont )
void SwGlobalTree::EditContent(const SwGlblDocContent* pCont )
{
    sal_uInt16 nSlot = 0;
    switch( pCont->GetType() )
@@ -783,18 +560,12 @@ void    SwGlobalTree::EditContent(const SwGlblDocContent* pCont )
    }
}

IMPL_LINK( SwGlobalTree, PopupHdl, Menu* , pMenu, bool)
{
    ExecuteContextMenuAction( pMenu->GetCurItemId());
    return true;
}

void    SwGlobalTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
void SwGlobalTree::ExecuteContextMenuAction(const OString& rSelectedPopupEntry)
{
    bool bUpdateHard = false;

    SvTreeListEntry* pEntry = FirstSelected();
    SwGlblDocContent* pCont = pEntry ? static_cast<SwGlblDocContent*>(pEntry->GetUserData()) : nullptr;
    int nEntry = m_xTreeView->get_selected_index();
    SwGlblDocContent* pCont = nEntry != -1 ? reinterpret_cast<SwGlblDocContent*>(m_xTreeView->get_id(nEntry).toInt64()) : nullptr;
    // If a RequestHelp is called during the dialogue,
    // then the content gets lost. Because of that a copy
    // is created in which only the DocPos is set correctly.
@@ -803,218 +574,195 @@ void    SwGlobalTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
        pContCopy.reset(new SwGlblDocContent(pCont->GetDocPos()));
    SfxDispatcher& rDispatch = *m_pActiveShell->GetView().GetViewFrame()->GetDispatcher();
    sal_uInt16 nSlot = 0;
    switch( nSelectedPopupEntry )
    if (rSelectedPopupEntry == "updatesel")
    {
        case CTX_UPDATE_SEL:
        {
            // Two passes: first update the areas, then the directories.
            SvTreeListEntry* pSelEntry = FirstSelected();
            while( pSelEntry )
        // Two passes: first update the areas, then the directories.
        m_xTreeView->selected_foreach([this](weld::TreeIter& rSelEntry){
            SwGlblDocContent* pContent = reinterpret_cast<SwGlblDocContent*>(m_xTreeView->get_id(rSelEntry).toInt64());
            if (GLBLDOC_SECTION == pContent->GetType() &&
                pContent->GetSection()->IsConnected())
            {
                SwGlblDocContent* pContent = static_cast<SwGlblDocContent*>(pSelEntry->GetUserData());
                if(GLBLDOC_SECTION == pContent->GetType() &&
                    pContent->GetSection()->IsConnected())
                {
                    const_cast<SwSection*>(pContent->GetSection())->UpdateNow();
                }
                const_cast<SwSection*>(pContent->GetSection())->UpdateNow();
            }
            return false;
        });
        m_xTreeView->selected_foreach([this](weld::TreeIter& rSelEntry){
            SwGlblDocContent* pContent = reinterpret_cast<SwGlblDocContent*>(m_xTreeView->get_id(rSelEntry).toInt64());
            if (GLBLDOC_TOXBASE == pContent->GetType())
                m_pActiveShell->UpdateTableOf(*pContent->GetTOX());
            return false;
        });

                pSelEntry = NextSelected(pSelEntry);
            }
            pSelEntry = FirstSelected();
            while( pSelEntry )
            {
                SwGlblDocContent* pContent = static_cast<SwGlblDocContent*>(pSelEntry->GetUserData());
                if(GLBLDOC_TOXBASE == pContent->GetType())
                    m_pActiveShell->UpdateTableOf(*pContent->GetTOX());
                pSelEntry = NextSelected(pSelEntry);
            }
            bUpdateHard = true;
        }
        break;
        case CTX_UPDATE_INDEX:
        {
        bUpdateHard = true;
    }
    else if (rSelectedPopupEntry == "updateindex")
    {
        nSlot = FN_UPDATE_TOX;
        bUpdateHard = true;
    }
    else if (rSelectedPopupEntry == "updatelinks" || rSelectedPopupEntry == "updateall")
    {
        m_pActiveShell->GetLinkManager().UpdateAllLinks(true, false, nullptr);
        if (rSelectedPopupEntry == "updateall")
            nSlot = FN_UPDATE_TOX;
            bUpdateHard = true;
        }
        break;
        case CTX_UPDATE_LINK:
        case CTX_UPDATE_ALL:
        pCont = nullptr;
        bUpdateHard = true;
    }
    else if (rSelectedPopupEntry == "edit")
    {
        OSL_ENSURE(pCont, "edit without entry ? " );
        if (pCont)
        {
            m_pActiveShell->GetLinkManager().UpdateAllLinks(true, false, nullptr);
            if(CTX_UPDATE_ALL == nSelectedPopupEntry)
                nSlot = FN_UPDATE_TOX;
            pCont = nullptr;
            bUpdateHard = true;
            EditContent(pCont);
        }
        break;
        case CTX_EDIT:
    }
    else if (rSelectedPopupEntry == "editlink")
    {
        OSL_ENSURE(pCont, "edit without entry ? " );
        if (pCont)
        {
            OSL_ENSURE(pCont, "edit without entry ? " );
            if (pCont)
            SfxStringItem aName(FN_EDIT_REGION,
                    pCont->GetSection()->GetSectionName());
            rDispatch.ExecuteList(FN_EDIT_REGION, SfxCallMode::ASYNCHRON,
                    { &aName });
        }
    }
    else if (rSelectedPopupEntry == "deleteentry")
    {
        // If several entries selected, then after each delete the array
        // must be refilled. So you do not have to remember anything,
        // deleting begins at the end.
        std::vector<int> aRows = m_xTreeView->get_selected_rows();
        std::sort(aRows.begin(), aRows.end());

        std::unique_ptr<SwGlblDocContents> pTempContents;
        m_pActiveShell->StartAction();
        for (auto iter = aRows.rbegin(); iter != aRows.rend(); ++iter)
        {
            m_pActiveShell->DeleteGlobalDocContent(
                pTempContents ? *pTempContents : *m_pSwGlblDocContents,
                                 *iter);
            pTempContents.reset(new SwGlblDocContents);
            m_pActiveShell->GetGlobalDocContent(*pTempContents);
        }
        pTempContents.reset();
        m_pActiveShell->EndAction();
        pCont = nullptr;
    }
    else if (rSelectedPopupEntry == "insertindex")
    {
        if(pContCopy)
        {
            SfxItemSet aSet(
                m_pActiveShell->GetView().GetPool(),
                svl::Items<
                    RES_FRM_SIZE, RES_FRM_SIZE,
                    RES_LR_SPACE, RES_LR_SPACE,
                    RES_BACKGROUND, RES_BACKGROUND,
                    RES_COL, RES_COL,
                    SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
                    FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE>{});

            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
            ScopedVclPtr<AbstractMultiTOXTabDialog> pDlg(pFact->CreateMultiTOXTabDialog(
                                                    m_xDialog->GetFrameWeld(), aSet,
                                                    *m_pActiveShell,
                                                    nullptr,
                                                    true));
            if(RET_OK == pDlg->Execute())
            {
                EditContent(pCont);
                SwTOXDescription&  rDesc = pDlg->GetTOXDescription(
                                            pDlg->GetCurrentTOXType());
                SwTOXMgr aMgr(m_pActiveShell);
                SwTOXBase* pToInsert = nullptr;
                if(aMgr.UpdateOrInsertTOX(rDesc, &pToInsert, pDlg->GetOutputItemSet()))
                    m_pActiveShell->InsertGlobalDocContent( *pContCopy, *pToInsert );
            }
        }
        break;
        case CTX_EDIT_LINK:
        {
            OSL_ENSURE(pCont, "edit without entry ? " );
            if (pCont)
            {
                SfxStringItem aName(FN_EDIT_REGION,
                        pCont->GetSection()->GetSectionName());
                rDispatch.ExecuteList(FN_EDIT_REGION, SfxCallMode::ASYNCHRON,
                        { &aName });
            }
        }
        break;
        case CTX_DELETE:
        {
            // If several entries selected, then after each delete the array
            // must be refilled. So you do not have to remember anything,
            // deleting begins at the end.
            SvTreeListEntry* pSelEntry = LastSelected();
            std::unique_ptr<SwGlblDocContents> pTempContents;
            m_pActiveShell->StartAction();
            while(pSelEntry)
            {
                m_pActiveShell->DeleteGlobalDocContent(
                    pTempContents ? *pTempContents : *m_pSwGlblDocContents,
                                     GetModel()->GetAbsPos(pSelEntry));
                pSelEntry = PrevSelected(pSelEntry);
                if(pSelEntry)
                {
                    pTempContents.reset(new SwGlblDocContents);
                    m_pActiveShell->GetGlobalDocContent(*pTempContents);
                }
            }
            pTempContents.reset();
            m_pActiveShell->EndAction();
            pCont = nullptr;
        }
        break;
        case CTX_INSERT_ANY_INDEX:
    }
    else if (rSelectedPopupEntry == "insertfile")
    {
        m_pDocContent = std::move(pContCopy);
        InsertRegion( m_pDocContent.get() );
        pCont = nullptr;
    }
    else if (rSelectedPopupEntry == "insertnewfile")
    {
        SfxViewFrame* pGlobFrame = m_pActiveShell->GetView().GetViewFrame();
        SwGlobalFrameListener_Impl aFrameListener(*pGlobFrame);

        // Creating a new doc
        SfxStringItem aFactory(SID_NEWDOCDIRECT,
                        SwDocShell::Factory().GetFilterContainer()->GetName());

        const SfxFrameItem* pItem = static_cast<const SfxFrameItem*>(
                        rDispatch.ExecuteList(SID_NEWDOCDIRECT,
                            SfxCallMode::SYNCHRON, { &aFactory }));

        // save at
        SfxFrame* pFrame = pItem ? pItem->GetFrame() : nullptr;
        SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : nullptr;
        if (pViewFrame)
        {
            if(pContCopy)
            const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(
                    pViewFrame->GetDispatcher()->Execute(
                            SID_SAVEASDOC, SfxCallMode::SYNCHRON ));
            SfxObjectShell& rObj = *pViewFrame->GetObjectShell();
            const SfxMedium* pMedium = rObj.GetMedium();
            OUString sNewFile(pMedium->GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::ToIUri));
            // Insert the area with the Doc-Name
            // Bring the own Doc in the foreground
            if(aFrameListener.IsValid() && !sNewFile.isEmpty())
            {
                SfxItemSet aSet(
                    m_pActiveShell->GetView().GetPool(),
                    svl::Items<
                        RES_FRM_SIZE, RES_FRM_SIZE,
                        RES_LR_SPACE, RES_LR_SPACE,
                        RES_BACKGROUND, RES_BACKGROUND,
                        RES_COL, RES_COL,
                        SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
                        FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE>{});

                SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
                ScopedVclPtr<AbstractMultiTOXTabDialog> pDlg(pFact->CreateMultiTOXTabDialog(
                                                        GetFrameWeld(), aSet,
                                                        *m_pActiveShell,
                                                        nullptr,
                                                        true));
                if(RET_OK == pDlg->Execute())
                pGlobFrame->ToTop();
                // Due to the update the entries are invalid
                if (nEntry != -1)
                {
                    SwTOXDescription&  rDesc = pDlg->GetTOXDescription(
                                                pDlg->GetCurrentTOXType());
                    SwTOXMgr aMgr(m_pActiveShell);
                    SwTOXBase* pToInsert = nullptr;
                    if(aMgr.UpdateOrInsertTOX(rDesc, &pToInsert, pDlg->GetOutputItemSet()))
                        m_pActiveShell->InsertGlobalDocContent( *pContCopy, *pToInsert );
                }
                pCont = nullptr;
            }
        }
        break;
        case CTX_INSERT_FILE:
        {
            m_pDocContent = std::move(pContCopy);
            InsertRegion( m_pDocContent.get() );
            pCont = nullptr;
        }
        break;
        case CTX_INSERT_NEW_FILE:
        {
            SfxViewFrame* pGlobFrame = m_pActiveShell->GetView().GetViewFrame();
            SwGlobalFrameListener_Impl aFrameListener(*pGlobFrame);

            sal_uLong nEntryPos = pEntry ? GetModel()->GetAbsPos(pEntry) : sal_uLong(-1);
            // Creating a new doc
            SfxStringItem aFactory(SID_NEWDOCDIRECT,
                            SwDocShell::Factory().GetFilterContainer()->GetName());

            const SfxFrameItem* pItem = static_cast<const SfxFrameItem*>(
                            rDispatch.ExecuteList(SID_NEWDOCDIRECT,
                                SfxCallMode::SYNCHRON, { &aFactory }));

            // save at
            SfxFrame* pFrame = pItem ? pItem->GetFrame() : nullptr;
            SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : nullptr;
            if (pViewFrame)
            {
                const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(
                        pViewFrame->GetDispatcher()->Execute(
                                SID_SAVEASDOC, SfxCallMode::SYNCHRON ));
                SfxObjectShell& rObj = *pViewFrame->GetObjectShell();
                const SfxMedium* pMedium = rObj.GetMedium();
                OUString sNewFile(pMedium->GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::ToIUri));
                // Insert the area with the Doc-Name
                // Bring the own Doc in the foreground
                if(aFrameListener.IsValid() && !sNewFile.isEmpty())
                {
                    pGlobFrame->ToTop();
                    // Due to the update the entries are invalid
                    if(nEntryPos != sal_uLong(-1))
                    {
                        Update( false );
                        Display();
                        Select(GetModel()->GetEntryAtAbsPos(nEntryPos));
                        pEntry = FirstSelected();
                        pCont = pEntry ? static_cast<SwGlblDocContent*>(pEntry->GetUserData()) : nullptr;
                    }
                    else
                    {
                        pEntry = nullptr;
                        pCont = nullptr;
                    }
                    if(pBool->GetValue())
                    {
                        InsertRegion(pCont, &sNewFile);
                        pViewFrame->ToTop();
                    }
                    else
                        pViewFrame->GetDispatcher()->Execute(SID_CLOSEWIN,
                                                SfxCallMode::SYNCHRON);
                    Update( false );
                    Display();
                    m_xTreeView->select(nEntry);
                    Select();
                    nEntry = m_xTreeView->get_selected_index();
                    pCont = nEntry != -1 ? reinterpret_cast<SwGlblDocContent*>(m_xTreeView->get_id(nEntry).toInt64()) : nullptr;
                }
                else
                {
                    pViewFrame->ToTop();
                    return;
                    nEntry = -1;
                    pCont = nullptr;
                }
                if(pBool->GetValue())
                {
                    InsertRegion(pCont, &sNewFile);
                    pViewFrame->ToTop();
                }
                else
                    pViewFrame->GetDispatcher()->Execute(SID_CLOSEWIN, SfxCallMode::SYNCHRON);
            }
        }
        break;
        case CTX_INSERT_TEXT:
        {
            if(pCont)
                m_pActiveShell->InsertGlobalDocContent(*pCont);
            else
            {
                m_pActiveShell->SplitNode(); // Empty document
                m_pActiveShell->Up( false );
                pViewFrame->ToTop();
                return;
            }
            m_pActiveShell->GetView().GetEditWin().GrabFocus();
        }
        break;
        case CTX_UPDATE:
            pCont = nullptr;
        break;
        default:;
        // here nothing happens
    }
    if(pCont)
    else if (rSelectedPopupEntry == "inserttext")
    {
        if (pCont)
            m_pActiveShell->InsertGlobalDocContent(*pCont);
        else
        {
            m_pActiveShell->SplitNode(); // Empty document
            m_pActiveShell->Up( false );
        }
        m_pActiveShell->GetView().GetEditWin().GrabFocus();
    }
    else if (rSelectedPopupEntry == "update")
        pCont = nullptr;

    if (pCont)
        GotoContent(pCont);
    if(nSlot)
    if (nSlot)
        rDispatch.Execute(nSlot);
    if (Update(bUpdateHard))
        Display();
@@ -1022,7 +770,7 @@ void    SwGlobalTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )

IMPL_LINK_NOARG(SwGlobalTree, Timeout, Timer *, void)
{
    if(!IsDisposed() && !HasFocus() && Update( false ))
    if (!m_xTreeView->has_focus() && Update(false))
        Display();
}

@@ -1048,42 +796,43 @@ void SwGlobalTree::GotoContent(const SwGlblDocContent* pCont)

}

void    SwGlobalTree::ShowTree()
void SwGlobalTree::ShowTree()
{
    m_aUpdateTimer.Start();
    SvTreeListBox::Show();
    m_xTreeView->show();
}

void    SwGlobalTree::HideTree()
void SwGlobalTree::HideTree()
{
    m_aUpdateTimer.Stop();
    SvTreeListBox::Hide();
    m_xTreeView->hide();
}

void    SwGlobalTree::ExecCommand(const OUString &rCmd)
void SwGlobalTree::ExecCommand(const OString &rCmd)
{
    SvTreeListEntry* pEntry = FirstSelected();
    OSL_ENSURE(pEntry, "It explodes in the next moment");
    int nEntry = m_xTreeView->get_selected_index();
    if (nEntry == -1)
        return;
    if (rCmd == "edit")
    {
        const SwGlblDocContent* pCont = static_cast<const SwGlblDocContent*>(
                                                pEntry->GetUserData());
        const SwGlblDocContent* pCont = reinterpret_cast<const SwGlblDocContent*>(
                                                m_xTreeView->get_id(nEntry).toInt64());
        EditContent(pCont);
    }
    else
    {
        if(GetSelectionCount() == 1)
        if (m_xTreeView->count_selected_rows() == 1)
        {
            bool bMove = false;
            sal_uLong nSource = GetModel()->GetAbsPos(pEntry);
            sal_uLong nSource = nEntry;
            sal_uLong nDest = nSource;
            if (rCmd == "down")
            if (rCmd == "movedown")
            {
                sal_uLong nEntryCount = GetEntryCount();
                size_t nEntryCount = m_xTreeView->n_children();
                bMove = nEntryCount > nSource + 1;
                nDest+= 2;
            }
            else if (rCmd == "up")
            else if (rCmd == "moveup")
            {
                bMove = 0 != nSource;
                nDest--;
@@ -1096,7 +845,7 @@ void    SwGlobalTree::ExecCommand(const OUString &rCmd)
    }
}

bool    SwGlobalTree::Update(bool bHard)
bool SwGlobalTree::Update(bool bHard)
{
    SwView* pActView = GetParentWindow()->GetCreateView();
    bool bRet = false;
@@ -1119,8 +868,9 @@ bool    SwGlobalTree::Update(bool bHard)
            bool bCopy = false;
            std::unique_ptr<SwGlblDocContents> pTempContents(new SwGlblDocContents);
            m_pActiveShell->GetGlobalDocContent(*pTempContents);
            if(pTempContents->size() != m_pSwGlblDocContents->size() ||
                    pTempContents->size() != GetEntryCount())
            size_t nChildren = m_xTreeView->n_children();
            if (pTempContents->size() != m_pSwGlblDocContents->size() ||
                    pTempContents->size() != nChildren)
            {
                bRet = true;
                bCopy = true;
@@ -1132,8 +882,7 @@ bool    SwGlobalTree::Update(bool bHard)
                    SwGlblDocContent* pLeft = (*pTempContents)[i].get();
                    SwGlblDocContent* pRight = (*m_pSwGlblDocContents)[i].get();
                    GlobalDocContentType eType = pLeft->GetType();
                    SvTreeListEntry* pEntry = GetEntry(i);
                    OUString sTemp = GetEntryText(pEntry);
                    OUString sTemp = m_xTreeView->get_text(i);
                    if (
                         eType != pRight->GetType() ||
                         (
@@ -1150,7 +899,7 @@ bool    SwGlobalTree::Update(bool bHard)
                    }
                }
            }
            if(bCopy || bHard)
            if (bCopy || bHard)
            {
                *m_pSwGlblDocContents = std::move( *pTempContents );
                bRet = true;
@@ -1159,7 +908,7 @@ bool    SwGlobalTree::Update(bool bHard)
    }
    else
    {
        Clear();
        m_xTreeView->clear();
        if(m_pSwGlblDocContents)
            m_pSwGlblDocContents->clear();
    }
@@ -1180,7 +929,7 @@ void SwGlobalTree::OpenDoc(const SwGlblDocContent* pCont)
        {
            bFound = true;
            SwGlobalTree::SetShowShell(pCurr);
            Application::PostUserEvent( LINK( this, SwGlobalTree, ShowFrameHdl ), nullptr, true );
            Application::PostUserEvent(LINK(this, SwGlobalTree, ShowFrameHdl));
            pCurr = nullptr;
        }
        else
@@ -1198,11 +947,11 @@ void SwGlobalTree::OpenDoc(const SwGlblDocContent* pCont)
    }
}

IMPL_LINK_NOARG( SwGlobalTree, DoubleClickHdl, SvTreeListBox*, bool)
IMPL_LINK_NOARG( SwGlobalTree, DoubleClickHdl, weld::TreeView&, bool)
{
    SvTreeListEntry* pEntry = GetCurEntry();
    SwGlblDocContent* pCont = static_cast<SwGlblDocContent*>(pEntry->GetUserData());
    if(pCont->GetType() == GLBLDOC_SECTION)
    int nEntry = m_xTreeView->get_cursor_index();
    SwGlblDocContent* pCont = nEntry != -1 ? reinterpret_cast<SwGlblDocContent*>(m_xTreeView->get_id(nEntry).toInt64()) : nullptr;
    if (pCont->GetType() == GLBLDOC_SECTION)
        OpenDoc(pCont);
    else
    {
@@ -1225,51 +974,15 @@ IMPL_STATIC_LINK_NOARG(SwGlobalTree, ShowFrameHdl, void*, void)
    SwGlobalTree::SetShowShell(nullptr);
}

void SwGlobalTree::InitEntry(SvTreeListEntry* pEntry,
        const OUString& rStr ,const Image& rImg1,const Image& rImg2)
{
    const size_t nColToHilite = 1; //0==Bitmap;1=="Column1";2=="Column2"
    SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2 );
    SvLBoxString& rCol = static_cast<SvLBoxString&>(pEntry->GetItem( nColToHilite ));
    pEntry->ReplaceItem(std::make_unique<SwLBoxString>(rCol.GetText()), nColToHilite);
}

void SwLBoxString::Paint(const Point& rPos, SvTreeListBox& rDev, vcl::RenderContext& rRenderContext,
                         const SvViewDataEntry* pView, const SvTreeListEntry& rEntry)
{
    SwGlblDocContent* pCont = static_cast<SwGlblDocContent*>(rEntry.GetUserData());
    if (pCont->GetType() == GLBLDOC_SECTION &&
      !pCont->GetSection()->IsConnectFlag())
    {
        rRenderContext.Push(PushFlags::FONT);
        vcl::Font aFont(rRenderContext.GetFont());
        aFont.SetColor(COL_LIGHTRED);
        rRenderContext.SetFont(aFont);
        rRenderContext.DrawText(rPos, GetText());
        rRenderContext.Pop();
    }
    else
        SvLBoxString::Paint(rPos, rDev, rRenderContext, pView, rEntry);
}

void    SwGlobalTree::DataChanged( const DataChangedEvent& rDCEvt )
{
    if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
         (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
    {
        Update(true);
    }
    SvTreeListBox::DataChanged( rDCEvt );
}

void SwGlobalTree::InsertRegion( const SwGlblDocContent* _pContent, const Sequence< OUString >& _rFiles )
{
    sal_Int32 nFiles = _rFiles.getLength();
    if ( !nFiles )
    if (!nFiles)
        return;

    bool bMove = _pContent == nullptr;;
    sal_uLong nEntryCount = GetEntryCount();
    size_t nEntryCount = m_xTreeView->n_children();

    bool bMove = _pContent == nullptr;
    const OUString* pFileNames = _rFiles.getConstArray();
    SwWrtShell& rSh = GetParentWindow()->GetCreateView()->GetWrtShell();
    rSh.StartAction();
diff --git a/sw/source/uibase/utlui/navipi.cxx b/sw/source/uibase/utlui/navipi.cxx
index c9c2cd1..ca52eeb 100644
--- a/sw/source/uibase/utlui/navipi.cxx
+++ b/sw/source/uibase/utlui/navipi.cxx
@@ -35,7 +35,6 @@
#include <navicfg.hxx>
#include <wrtsh.hxx>
#include <docsh.hxx>
#include <actctrl.hxx>
#include <navipi.hxx>
#include <workctrl.hxx>
#include <edtwin.hxx>
@@ -119,7 +118,6 @@ void SwNavigationPI::MoveOutline(SwOutlineNodes::size_type nSource, SwOutlineNod
}

// After goto cancel the status frame selection

static void lcl_UnSelectFrame(SwWrtShell *pSh)
{
    if (pSh->IsFrameSelected())
@@ -130,10 +128,9 @@ static void lcl_UnSelectFrame(SwWrtShell *pSh)
}

// Select the document view

IMPL_LINK( SwNavigationPI, DocListBoxSelectHdl, ListBox&, rBox, void )
IMPL_LINK(SwNavigationPI, DocListBoxSelectHdl, weld::ComboBox&, rBox, void)
{
    int nEntryIdx = rBox.GetSelectedEntryPos();
    int nEntryIdx = rBox.get_active();
    SwView *pView ;
    pView = SwModule::GetFirstView();
    while (nEntryIdx-- && pView)
@@ -143,40 +140,39 @@ IMPL_LINK( SwNavigationPI, DocListBoxSelectHdl, ListBox&, rBox, void )
    if(!pView)
    {
        nEntryIdx == 0 ?
            m_aContentTree->ShowHiddenShell():
                m_aContentTree->ShowActualView();
            m_xContentTree->ShowHiddenShell():
                m_xContentTree->ShowActualView();

    }
    else
    {
        m_aContentTree->SetConstantShell(pView->GetWrtShellPtr());
        m_xContentTree->SetConstantShell(pView->GetWrtShellPtr());
    }
}

// Filling of the list box for outline view or documents
// The PI will be set to full size

void SwNavigationPI::FillBox()
{
    if(m_pContentWrtShell)
    {
        m_aContentTree->SetHiddenShell( m_pContentWrtShell );
        m_aContentTree->Display(  false );
        m_xContentTree->SetHiddenShell( m_pContentWrtShell );
        m_xContentTree->Display(  false );
    }
    else
    {
        SwView *pView = GetCreateView();
        if(!pView)
        {
            m_aContentTree->SetActiveShell(nullptr);
            m_xContentTree->SetActiveShell(nullptr);
        }
        else if( pView != m_pActContView)
        {
            SwWrtShell* pWrtShell = pView->GetWrtShellPtr();
            m_aContentTree->SetActiveShell(pWrtShell);
            m_xContentTree->SetActiveShell(pWrtShell);
        }
        else
            m_aContentTree->Display( true );
            m_xContentTree->Display( true );
        m_pActContView = pView;
    }
}
@@ -185,48 +181,43 @@ void SwNavigationPI::UsePage()
{
    SwView *pView = GetCreateView();
    SwWrtShell *pSh = pView ? &pView->GetWrtShell() : nullptr;
    GetPageEdit().set_value(1);
    m_xEdit->set_value(1);
    if (pSh)
    {
        const sal_uInt16 nPageCnt = pSh->GetPageCnt();
        sal_uInt16 nPhyPage, nVirPage;
        pSh->GetPageNum(nPhyPage, nVirPage);

        GetPageEdit().set_max(nPageCnt);
        GetPageEdit().set_value(nPhyPage);
        m_xEdit->set_max(nPageCnt);
        m_xEdit->set_width_chars(3);
        m_xEdit->set_value(nPhyPage);
    }
}

// Select handler of the toolboxes

IMPL_LINK( SwNavigationPI, ToolBoxSelectHdl, ToolBox *, pBox, void )
IMPL_LINK(SwNavigationPI, ToolBoxSelectHdl, const OString&, rCommand, void)
{
    const sal_uInt16 nCurrItemId = pBox->GetCurItemId();
    const OUString sCommand = pBox->GetItemCommand(nCurrItemId);
    SwView *pView = GetCreateView();
    if (!pView)
        return;
    SwWrtShell &rSh = pView->GetWrtShell();
    // Get MouseModifier for Outline-Move

    // Standard: sublevels are taken
    // do not take sublevels with Ctrl
    bool bOutlineWithChildren  = ( KEY_MOD1 != pBox->GetModifier());
    int nFuncId = 0;
    bool bFocusToDoc = false;
    if (sCommand == ".uno:ScrollToPrevious")
    if (rCommand == ".uno:ScrollToPrevious")
    {
        rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(FN_SCROLL_PREV, SfxCallMode::ASYNCHRON);
    }
    else if (sCommand == ".uno:ScrollToNext")
    else if (rCommand == ".uno:ScrollToNext")
    {
        rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(FN_SCROLL_NEXT, SfxCallMode::ASYNCHRON);
    }
    else if (sCommand == "root")
    else if (rCommand == "root")
    {
        m_aContentTree->ToggleToRoot();
        m_xContentTree->ToggleToRoot();
    }
    else if (sCommand == "listbox")
    else if (rCommand == "listbox")
    {
        if (SfxChildWindowContext::GetFloatingWindow(GetParent()))
        {
@@ -242,7 +233,7 @@ IMPL_LINK( SwNavigationPI, ToolBoxSelectHdl, ToolBox *, pBox, void )
        return;
    }
    // Functions that will trigger a direct action.
    else if (sCommand == "footer")
    else if (rCommand == "footer")
    {
        rSh.MoveCursor();
        const FrameTypeFlags eType = rSh.GetFrameType(nullptr,false);
@@ -255,7 +246,7 @@ IMPL_LINK( SwNavigationPI, ToolBoxSelectHdl, ToolBox *, pBox, void )
            nFuncId = FN_TO_FOOTER;
        bFocusToDoc = true;
    }
    else if (sCommand == "header")
    else if (rCommand == "header")
    {
        rSh.MoveCursor();
        const FrameTypeFlags eType = rSh.GetFrameType(nullptr,false);
@@ -268,7 +259,7 @@ IMPL_LINK( SwNavigationPI, ToolBoxSelectHdl, ToolBox *, pBox, void )
            nFuncId = FN_TO_HEADER;
        bFocusToDoc = true;
    }
    else if (sCommand == "anchor")
    else if (rCommand == "anchor")
    {
        rSh.MoveCursor();
        const FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,false);
@@ -292,32 +283,50 @@ IMPL_LINK( SwNavigationPI, ToolBoxSelectHdl, ToolBox *, pBox, void )
        }
        bFocusToDoc = true;
    }
    else if (sCommand == "reminder")
    else if (rCommand == "reminder")
    {
        rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(FN_SET_REMINDER, SfxCallMode::ASYNCHRON);
    }
    else if (sCommand == "down" ||
             sCommand == "up" ||
             sCommand == "promote" ||
             sCommand == "demote" ||
             sCommand == "edit")
    else if (rCommand == "chapterdown" ||
             rCommand == "movedown" ||
             rCommand == "chapterup" ||
             rCommand == "moveup" ||
             rCommand == "promote" ||
             rCommand == "demote" ||
             rCommand == "edit")
    {
        if (IsGlobalMode())
            m_aGlobalTree->ExecCommand(sCommand);
            m_xGlobalTree->ExecCommand(rCommand);
        else
            m_aContentTree->ExecCommand(sCommand, bOutlineWithChildren);
        {
            // Standard: sublevels are taken
            // do not take sublevels with Ctrl
            bool bOutlineWithChildren = (KEY_MOD1 != m_xContent3ToolBox->get_modifier_state());
            m_xContentTree->ExecCommand(rCommand, bOutlineWithChildren);
        }
    }
    else if (sCommand == "toggle")
    else if (rCommand == "contenttoggle" || rCommand == "globaltoggle")
    {
        ToggleTree();
        m_pConfig->SetGlobalActive(IsGlobalMode());
        bool bGlobalMode = IsGlobalMode();
        m_pConfig->SetGlobalActive(bGlobalMode);
        m_xGlobalToolBox->set_item_active("globaltoggle", bGlobalMode);
        m_xContent1ToolBox->set_item_active("contenttoggle", bGlobalMode);
    }
    else if (sCommand == "save")
    else if (rCommand == "save")
    {
        bool bSave = rSh.IsGlblDocSaveLinks();
        rSh.SetGlblDocSaveLinks( !bSave );
        pBox->CheckItem(nCurrItemId, !bSave );
        m_xGlobalToolBox->set_item_active(rCommand, !bSave);
    }
    else if (rCommand == "dragmode")
        m_xContent3ToolBox->set_menu_item_active("dragmode", !m_xContent3ToolBox->get_menu_item_active("dragmode"));
    else if (rCommand == "headings")
        m_xContent2ToolBox->set_menu_item_active("headings", !m_xContent2ToolBox->get_menu_item_active("headings"));
    else if (rCommand == "update")
        m_xGlobalToolBox->set_menu_item_active("update", !m_xGlobalToolBox->get_menu_item_active("update"));
    else if (rCommand == "insert")
        m_xGlobalToolBox->set_menu_item_active("insert", !m_xGlobalToolBox->get_menu_item_active("insert"));

    if (nFuncId)
        lcl_UnSelectFrame(&rSh);
@@ -326,59 +335,61 @@ IMPL_LINK( SwNavigationPI, ToolBoxSelectHdl, ToolBox *, pBox, void )
}

// Click handler of the toolboxes

IMPL_LINK( SwNavigationPI, ToolBoxClickHdl, ToolBox *, pBox, void )
IMPL_LINK(SwNavigationPI, ToolBoxClickHdl, const OString&, rCommand, void)
{
    const sal_uInt16 nCurrItemId = pBox->GetCurItemId();
    const OUString sCommand = pBox->GetItemCommand(nCurrItemId);
    if (sCommand == "update" || sCommand == "insert")
        m_aGlobalTree->TbxMenuHdl(nCurrItemId, pBox);
    if (!m_xGlobalToolBox->get_menu_item_active(rCommand))
        return;

    if (rCommand == "update")
        m_xGlobalTree->TbxMenuHdl(rCommand, *m_xUpdateMenu);
    else if (rCommand == "insert")
        m_xGlobalTree->TbxMenuHdl(rCommand, *m_xInsertMenu);
}

IMPL_LINK( SwNavigationPI, ToolBoxDropdownClickHdl, ToolBox*, pBox, void )
IMPL_LINK(SwNavigationPI, ToolBox3DropdownClickHdl, const OString&, rCommand, void)
{
    const sal_uInt16 nCurrItemId = pBox->GetCurItemId();
    const OUString sCommand = pBox->GetItemCommand(nCurrItemId);
    if (sCommand == "dragmode")
    if (!m_xContent3ToolBox->get_menu_item_active(rCommand))
        return;

    if (rCommand == "dragmode")
    {
        static const char* aHIDs[] =
        switch (m_nRegionMode)
        {
            HID_NAVI_DRAG_HYP,
            HID_NAVI_DRAG_LINK,
            HID_NAVI_DRAG_COPY,
        };
        ScopedVclPtrInstance<PopupMenu> pMenu;
        for (sal_uInt16 i = 0; i <= static_cast<sal_uInt16>(RegionMode::EMBEDDED); ++i)
        {
            pMenu->InsertItem(i + 1, m_aContextArr[i], MenuItemBits::RADIOCHECK);
            pMenu->SetHelpId(i + 1, aHIDs[i]);
            case RegionMode::NONE:
                m_xDragModeMenu->set_active("hyperlink", true);
                break;
            case RegionMode::LINK:
                m_xDragModeMenu->set_active("link", true);
                break;
            case RegionMode::EMBEDDED:
                m_xDragModeMenu->set_active("copy", true);
                break;
        }
        pMenu->CheckItem( static_cast<int>(m_nRegionMode) + 1 );
        pMenu->SetSelectHdl(LINK(this, SwNavigationPI, MenuSelectHdl));
        pBox->SetItemDown(nCurrItemId, true);
        pMenu->Execute(pBox, pBox->GetItemRect(nCurrItemId), PopupMenuFlags::ExecuteDown);
        pBox->SetItemDown(nCurrItemId, false);
        pBox->EndSelection();
        pMenu.disposeAndClear();
        pBox->Invalidate();
    }
    else if (sCommand == "headings")
    {
        ScopedVclPtrInstance<PopupMenu> pMenu;
        for (sal_uInt16 i = 101; i <= 100 + MAXLEVEL; ++i)
        {
            pMenu->InsertItem(i, OUString::number(i - 100), MenuItemBits::RADIOCHECK);
            pMenu->SetHelpId(i, HID_NAVI_OUTLINES);
        }
        pMenu->CheckItem( m_aContentTree->GetOutlineLevel() + 100 );
        pMenu->SetSelectHdl(LINK(this, SwNavigationPI, MenuSelectHdl));
        pBox->SetItemDown( nCurrItemId, true );
        pMenu->Execute(pBox, pBox->GetItemRect(nCurrItemId), PopupMenuFlags::ExecuteDown);
        pBox->SetItemDown( nCurrItemId, false );
        pMenu.disposeAndClear();
        pBox->EndSelection();
        pBox->Invalidate();
    }
}

IMPL_LINK(SwNavigationPI, DropModeMenuSelectHdl, const OString&, rIdent, void)
{
    if (rIdent == "hyperlink")
        SetRegionDropMode(RegionMode::NONE);
    else if (rIdent == "link")
        SetRegionDropMode(RegionMode::LINK);
    else if (rIdent == "copy")
        SetRegionDropMode(RegionMode::EMBEDDED);
}

IMPL_LINK(SwNavigationPI, GlobalMenuSelectHdl, const OString&, rIdent, void)
{
    m_xGlobalTree->ExecuteContextMenuAction(rIdent);
}

IMPL_LINK(SwNavigationPI, ToolBox2DropdownClickHdl, const OString&, rCommand, void)
{
    if (!m_xContent2ToolBox->get_menu_item_active(rCommand))
        return;

    if (rCommand == "headings")
        m_xHeadingsMenu->set_active(OString::number(m_xContentTree->GetOutlineLevel()), true);
}

FactoryFunction SwNavigationPI::GetUITestFactory() const
@@ -398,7 +409,7 @@ bool SwNavigationPI::EditAction()
        m_aPageChgIdle.Stop();

    SwWrtShell &rSh = m_pCreateView->GetWrtShell();
    sal_uInt16 nNewPage = GetPageEdit().get_value();
    sal_uInt16 nNewPage = m_xEdit->get_value();

    sal_uInt16 nPhyPage, nVirPage;
    rSh.GetPageNum(nPhyPage, nVirPage);
@@ -423,14 +434,14 @@ void SwNavigationPI::ZoomOut()
    FillBox();
    if (IsGlobalMode())
    {
        m_aGlobalBox->Show();
        m_aGlobalTree->ShowTree();
        m_xGlobalBox->show();
        m_xGlobalTree->ShowTree();
    }
    else
    {
        m_aContentBox->Show();
        m_aContentTree->ShowTree();
        m_aDocListBox->Show();
        m_xContentBox->show();
        m_xContentTree->ShowTree();
        m_xDocListBox->show();
    }

    Size aOptimalSize(GetOptimalSize());
@@ -439,11 +450,9 @@ void SwNavigationPI::ZoomOut()
    pNav->SetMinOutputSizePixel(aOptimalSize);
    pNav->SetOutputSizePixel(aNewSize);

    SvTreeListEntry* pFirst = m_aContentTree->FirstSelected();
    if (pFirst)
        m_aContentTree->Select(pFirst); // Enable toolbox
    m_xContentTree->Select(); // Enable toolbox
    m_pConfig->SetSmall(false);
    m_aContentToolBox->CheckItem(m_aContentToolBox->GetItemId("listbox"));
    m_xContent3ToolBox->set_item_active("listbox", true);
}

void SwNavigationPI::ZoomIn()
@@ -456,11 +465,11 @@ void SwNavigationPI::ZoomIn()

    m_aExpandedSize = GetSizePixel();

    m_aContentBox->Hide();
    m_aContentTree->HideTree();
    m_aGlobalBox->Hide();
    m_aGlobalTree->HideTree();
    m_aDocListBox->Hide();
    m_xContentBox->hide();
    m_xContentTree->HideTree();
    m_xGlobalBox->hide();
    m_xGlobalTree->HideTree();
    m_xDocListBox->hide();
    m_bIsZoomedIn = true;

    Size aOptimalSize(GetOptimalSize());
@@ -469,11 +478,10 @@ void SwNavigationPI::ZoomIn()
    pNav->SetMinOutputSizePixel(aOptimalSize);
    pNav->SetOutputSizePixel(aNewSize);

    SvTreeListEntry* pFirst = m_aContentTree->FirstSelected();
    if (pFirst)
        m_aContentTree->Select(pFirst); // Enable toolbox
    m_xContentTree->Select(); // Enable toolbox

    m_pConfig->SetSmall(true);
    m_aContentToolBox->CheckItem(m_aContentToolBox->GetItemId("listbox"), false);
    m_xContent3ToolBox->set_item_active("listbox", false);
}

namespace {
@@ -503,9 +511,24 @@ VclPtr<vcl::Window> SwNavigationPI::Create(vcl::Window* pParent,
SwNavigationPI::SwNavigationPI(vcl::Window* pParent,
    const css::uno::Reference<css::frame::XFrame>& rxFrame,
    SfxBindings* _pBindings)
    : PanelLayout(pParent, "NavigatorPanel", "modules/swriter/ui/navigatorpanel.ui", rxFrame/*, true*/)
    : PanelLayout(pParent, "NavigatorPanel", "modules/swriter/ui/navigatorpanel.ui", rxFrame, true)
    , m_aDocFullName(SID_DOCFULLNAME, *_pBindings, *this)
    , m_aPageStats(FN_STAT_PAGE, *_pBindings, *this)
    , m_xContent1ToolBox(m_xBuilder->weld_toolbar("content1"))
    , m_xContent2ToolBox(m_xBuilder->weld_toolbar("content2"))
    , m_xContent3ToolBox(m_xBuilder->weld_toolbar("content3"))
    , m_xContent1Dispatch(new ToolbarUnoDispatcher(*m_xContent1ToolBox, *m_xBuilder, rxFrame))
    , m_xHeadingsMenu(m_xBuilder->weld_menu("headingsmenu"))
    , m_xDragModeMenu(m_xBuilder->weld_menu("dragmodemenu"))
    , m_xUpdateMenu(m_xBuilder->weld_menu("updatemenu"))
    , m_xInsertMenu(m_xBuilder->weld_menu("insertmenu"))
    , m_xGlobalToolBox(m_xBuilder->weld_toolbar("global"))
    , m_xEdit(m_xBuilder->weld_spin_button("spinbutton"))
    , m_xContentBox(m_xBuilder->weld_widget("contentbox"))
    , m_xContentTree(new SwContentTree(m_xBuilder->weld_tree_view("contenttree"), this))
    , m_xGlobalBox(m_xBuilder->weld_widget("globalbox"))
    , m_xGlobalTree(new SwGlobalTree(m_xBuilder->weld_tree_view("globaltree"), this))
    , m_xDocListBox(m_xBuilder->weld_combo_box("documents"))
    , m_pContentView(nullptr)
    , m_pContentWrtShell(nullptr)
    , m_pActContView(nullptr)
@@ -516,50 +539,26 @@ SwNavigationPI::SwNavigationPI(vcl::Window* pParent,
    , m_bIsZoomedIn(false)
    , m_bGlobalMode(false)
{
    get(m_aContentToolBox, "content");
    m_aContentToolBox->SetLineCount(2);
    m_aContentToolBox->InsertBreak(4);
    get(m_aGlobalToolBox, "global");
    get(m_aDocListBox, "documents");

    get(m_aContentBox, "contentbox");
    m_aContentTree = VclPtr<SwContentTree>::Create(m_aContentBox, this);
    m_aContentTree->set_expand(true);
    get(m_aGlobalBox, "globalbox");
    m_aGlobalTree = VclPtr<SwGlobalTree>::Create(m_aGlobalBox, this);
    m_aGlobalTree->set_expand(true);
    set_id("NavigatorPanelParent"); // for uitest/writer_tests5/tdf114724.py

    GetCreateView();

    m_aContentToolBox->SetHelpId(HID_NAVIGATOR_TOOLBOX);
    m_aGlobalToolBox->SetHelpId(HID_NAVIGATOR_GLOBAL_TOOLBOX);
    m_aDocListBox->SetHelpId(HID_NAVIGATOR_LISTBOX);
    m_aDocListBox->SetDropDownLineCount(9);
    m_aDocListBox->setMaxWidthChars(20);
    m_xContent1ToolBox->set_help_id(HID_NAVIGATOR_TOOLBOX);
    m_xContent2ToolBox->set_help_id(HID_NAVIGATOR_TOOLBOX);
    m_xContent3ToolBox->set_help_id(HID_NAVIGATOR_TOOLBOX);
    m_xGlobalToolBox->set_help_id(HID_NAVIGATOR_GLOBAL_TOOLBOX);
    m_xDocListBox->set_help_id(HID_NAVIGATOR_LISTBOX);
    m_xDocListBox->set_size_request(42, -1); // set a nominal width so it takes width of surroundings

    // Insert the numeric field in the toolbox.
    m_xEdit = VclPtr<NumEditAction>::Create(m_aContentToolBox.get());
    m_xEdit->set_accessible_name(m_xEdit->GetQuickHelpText());
    m_xEdit->set_accessible_name(m_xEdit->get_tooltip_text());
    m_xEdit->set_width_chars(3);
    m_xEdit->connect_value_changed(LINK(this, SwNavigationPI, PageEditModifyHdl));
    m_xEdit->set_help_id("modules/swriter/ui/navigatorpanel/numericfield");

    // Double separators are not allowed, so you have to
    // determine the suitable size differently.
    tools::Rectangle aFirstRect = m_aContentToolBox->GetItemRect(m_aContentToolBox->GetItemId("anchor"));
    tools::Rectangle aSecondRect = m_aContentToolBox->GetItemRect(m_aContentToolBox->GetItemId("header"));
    Size aItemWinSize( aFirstRect.Left() - aSecondRect.Left(),
                       aFirstRect.Bottom() - aFirstRect.Top() );
    Size aOptimalSize(m_xEdit->GetSizePixel());
    aItemWinSize.setWidth( std::max(aItemWinSize.Width(), aOptimalSize.Width()) );
    aItemWinSize.setHeight( std::max(aItemWinSize.Height(), aOptimalSize.Height()) );
    m_xEdit->SetSizePixel(aItemWinSize);
    m_aContentToolBox->InsertSeparator(4);
    m_aContentToolBox->InsertWindow( FN_PAGENUMBER, m_xEdit, ToolBoxItemBits::NONE, 4);
    m_aContentToolBox->InsertSeparator(4);
    m_aContentToolBox->SetHelpId(FN_PAGENUMBER, "modules/swriter/ui/navigatorpanel/numericfield");
    m_aContentToolBox->ShowItem(FN_PAGENUMBER);
    if (!IsGlobalDoc())
    {
        m_aContentToolBox->HideItem(m_aContentToolBox->GetItemId("toggle"));
        m_xContent1ToolBox->set_item_visible("contenttoggle", false);
    }

    const char* REGIONNAME_ARY[] =
@@ -581,77 +580,62 @@ SwNavigationPI::SwNavigationPI(vcl::Window* pParent,

    for (sal_uInt16 i = 0; i <= static_cast<sal_uInt16>(RegionMode::EMBEDDED); ++i)
    {
        m_aContextArr[i] = SwResId(REGIONNAME_ARY[i]);
        m_aStatusArr[i] = SwResId(REGIONMODE_ARY[i]);
    }

    m_aStatusArr[3] = SwResId(STR_ACTIVE_VIEW);

    m_aContentTree->SetStyle(m_aContentTree->GetStyle()|WB_HASBUTTONS|WB_HASBUTTONSATROOT|
                             WB_CLIPCHILDREN|WB_HSCROLL|WB_TABSTOP);
    m_aContentTree->SetForceMakeVisible(true);
    m_aContentTree->SetSpaceBetweenEntries(3);
    m_aContentTree->SetSelectionMode(SelectionMode::Single);
    m_aContentTree->SetDragDropMode(DragDropMode::CTRL_MOVE |
                                    DragDropMode::CTRL_COPY |
                                    DragDropMode::ENABLE_TOP);
    m_aContentTree->EnableAsyncDrag(true);
    m_aContentTree->ShowTree();
    m_aContentToolBox->CheckItem(m_aContentToolBox->GetItemId("listbox"));
    m_aContentToolBox->ShowItem(m_aContentToolBox->GetItemId("listbox"), SfxChildWindowContext::GetFloatingWindow(GetParent()) != nullptr);
    m_xContentTree->set_selection_mode(SelectionMode::Single);
    m_xContentTree->ShowTree();
    m_xContent3ToolBox->set_item_active("listbox", true);
    m_xContent3ToolBox->set_item_sensitive("listbox", SfxChildWindowContext::GetFloatingWindow(GetParent()) != nullptr);

//  TreeListBox for global document
    m_aGlobalTree->SetSelectionMode( SelectionMode::Multiple );
    m_aGlobalTree->SetStyle(m_aGlobalTree->GetStyle()|WB_HASBUTTONS|WB_HASBUTTONSATROOT|
                            WB_CLIPCHILDREN|WB_HSCROLL|WB_TABSTOP);
    m_xGlobalTree->set_selection_mode(SelectionMode::Multiple);

//  Handler
    Link<ToolBox *, void> aLk = LINK(this, SwNavigationPI, ToolBoxSelectHdl);
    m_aContentToolBox->SetSelectHdl( aLk );
    m_aGlobalToolBox->SetSelectHdl( aLk );
    m_aDocListBox->SetSelectHdl(LINK(this, SwNavigationPI,
                                                    DocListBoxSelectHdl));
    m_aContentToolBox->SetClickHdl( LINK(this, SwNavigationPI, ToolBoxClickHdl) );
    m_aContentToolBox->SetDropdownClickHdl( LINK(this, SwNavigationPI, ToolBoxDropdownClickHdl) );
    m_aGlobalToolBox->SetClickHdl( LINK(this, SwNavigationPI, ToolBoxClickHdl) );
    m_aGlobalToolBox->SetDropdownClickHdl( LINK(this, SwNavigationPI, ToolBoxDropdownClickHdl) );
    m_aGlobalToolBox->CheckItem(m_aGlobalToolBox->GetItemId("toggle"));
    Link<const OString&, void> aLk = LINK(this, SwNavigationPI, ToolBoxSelectHdl);
    m_xContent1ToolBox->connect_clicked(aLk);
    m_xContent2ToolBox->connect_clicked(aLk);
    m_xContent3ToolBox->connect_clicked(aLk);
    m_xGlobalToolBox->connect_clicked(aLk);
    m_xDocListBox->connect_changed(LINK(this, SwNavigationPI, DocListBoxSelectHdl));
    m_xContent2ToolBox->set_item_menu("headings", m_xHeadingsMenu.get());
    m_xHeadingsMenu->connect_activate(LINK(this, SwNavigationPI, HeadingsMenuSelectHdl));
    m_xContent2ToolBox->connect_menu_toggled(LINK(this, SwNavigationPI, ToolBox2DropdownClickHdl));
    m_xContent3ToolBox->set_item_menu("dragmode", m_xDragModeMenu.get());
    m_xDragModeMenu->connect_activate(LINK(this, SwNavigationPI, DropModeMenuSelectHdl));
    m_xContent3ToolBox->connect_menu_toggled(LINK(this, SwNavigationPI, ToolBox3DropdownClickHdl));
    m_xGlobalToolBox->set_item_menu("update", m_xUpdateMenu.get());
    m_xUpdateMenu->connect_activate(LINK(this, SwNavigationPI, GlobalMenuSelectHdl));
    m_xGlobalToolBox->set_item_menu("insert", m_xInsertMenu.get());
    m_xInsertMenu->connect_activate(LINK(this, SwNavigationPI, GlobalMenuSelectHdl));
    m_xGlobalToolBox->connect_menu_toggled(LINK(this, SwNavigationPI, ToolBoxClickHdl));
    m_xGlobalToolBox->set_item_active("globaltoggle", true);

    vcl::Font aFont(GetFont());
    aFont.SetWeight(WEIGHT_NORMAL);
    GetPageEdit().SetFont(aFont);
    aFont = m_aContentTree->GetFont();
    aFont.SetWeight(WEIGHT_NORMAL);
    m_aContentTree->SetFont(aFont);
    m_aGlobalTree->SetFont(aFont);
//  set toolbar of both modes to widest of each
    m_xGlobalToolBox->set_size_request(m_xContent1ToolBox->get_preferred_size().Width(), -1);

    StartListening(*SfxGetpApp());

    sal_uInt16 nNavId = m_aContentToolBox->GetItemId("navigation");
    m_aContentToolBox->SetItemBits(nNavId, m_aContentToolBox->GetItemBits(nNavId) | ToolBoxItemBits::DROPDOWNONLY );
    sal_uInt16 nDropId = m_aContentToolBox->GetItemId("dragmode");
    m_aContentToolBox->SetItemBits(nDropId, m_aContentToolBox->GetItemBits(nDropId) | ToolBoxItemBits::DROPDOWNONLY );
    sal_uInt16 nOutlineId = m_aContentToolBox->GetItemId("headings");
    m_aContentToolBox->SetItemBits(nOutlineId, m_aContentToolBox->GetItemBits(nOutlineId) | ToolBoxItemBits::DROPDOWNONLY );

    if(IsGlobalDoc())
    {
        SwView *pActView = GetCreateView();
        m_aGlobalToolBox->CheckItem(m_aGlobalToolBox->GetItemId("save"),
        m_xGlobalToolBox->set_item_active("save",
                    pActView->GetWrtShellPtr()->IsGlblDocSaveLinks());
        if (m_pConfig->IsGlobalActive())
            ToggleTree();
        m_aGlobalTree->GrabFocus();
        m_xGlobalTree->grab_focus();
    }
    else
        m_aContentTree->GrabFocus();
        m_xContentTree->grab_focus();
    UsePage();
    m_aPageChgIdle.SetInvokeHandler(LINK(this, SwNavigationPI, ChangePageHdl));
    m_aPageChgIdle.SetPriority(TaskPriority::LOWEST);

    m_aContentTree->SetAccessibleName(SwResId(STR_ACCESS_TL_CONTENT));
    m_aGlobalTree->SetAccessibleName(SwResId(STR_ACCESS_TL_GLOBAL));
    m_aDocListBox->SetAccessibleName(m_aStatusArr[3]);
    m_xContentTree->set_accessible_name(SwResId(STR_ACCESS_TL_CONTENT));
    m_xGlobalTree->set_accessible_name(SwResId(STR_ACCESS_TL_GLOBAL));
    m_xDocListBox->set_accessible_name(m_aStatusArr[3]);

    m_aExpandedSize = GetOptimalSize();
}
@@ -673,8 +657,6 @@ void SwNavigationPI::dispose()

    EndListening(*SfxGetpApp());

    m_aContentToolBox->GetItemWindow(FN_PAGENUMBER)->disposeOnce();
    m_aContentToolBox->Clear();
    if (m_pxObjectShell)
    {
        if (m_pxObjectShell->Is())
@@ -682,14 +664,21 @@ void SwNavigationPI::dispose()
        m_pxObjectShell.reset();
    }

    m_aDocListBox.clear();
    m_aGlobalTree.disposeAndClear();
    m_aGlobalBox.clear();
    m_aContentTree.disposeAndClear();
    m_aContentBox.clear();
    m_aGlobalToolBox.disposeAndClear();
    m_xEdit.disposeAndClear();
    m_aContentToolBox.clear();
    m_xDocListBox.reset();
    m_xGlobalTree.reset();
    m_xGlobalBox.reset();
    m_xContentTree.reset();
    m_xContentBox.reset();
    m_xGlobalToolBox.reset();
    m_xEdit.reset();
    m_xHeadingsMenu.reset();
    m_xDragModeMenu.reset();
    m_xUpdateMenu.reset();
    m_xInsertMenu.reset();
    m_xContent1Dispatch.reset();
    m_xContent1ToolBox.reset();
    m_xContent2ToolBox.reset();
    m_xContent3ToolBox.reset();

    m_aPageChgIdle.Stop();

@@ -708,21 +697,21 @@ void SwNavigationPI::NotifyItemUpdate(sal_uInt16 nSID, SfxItemState /*eState*/,
        if(pActView)
        {
            SwWrtShell* pWrtShell = pActView->GetWrtShellPtr();
            m_aContentTree->SetActiveShell(pWrtShell);
            m_xContentTree->SetActiveShell(pWrtShell);
            bool bGlobal = IsGlobalDoc();
            m_aContentToolBox->ShowItem(m_aContentToolBox->GetItemId("toggle"), bGlobal);
            m_xContent1ToolBox->set_item_visible("contenttoggle", bGlobal);
            if ((!bGlobal && IsGlobalMode()) || (!IsGlobalMode() && m_pConfig->IsGlobalActive()))
            {
                ToggleTree();
            }
            if (bGlobal)
            {
                m_aGlobalToolBox->CheckItem(m_aGlobalToolBox->GetItemId("save"), pWrtShell->IsGlblDocSaveLinks());
                m_xGlobalToolBox->set_item_active("save", pWrtShell->IsGlblDocSaveLinks());
            }
        }
        else
        {
            m_aContentTree->SetActiveShell(nullptr);
            m_xContentTree->SetActiveShell(nullptr);
        }
        UpdateListBox();
    }
@@ -732,10 +721,10 @@ void SwNavigationPI::NotifyItemUpdate(sal_uInt16 nSID, SfxItemState /*eState*/,
        if(pActView)
        {
            SwWrtShell &rSh = pActView->GetWrtShell();
            GetPageEdit().set_max(rSh.GetPageCnt());
            m_xEdit->set_max(rSh.GetPageCnt());
            m_xEdit->set_width_chars(3);
        }
    }

}

void SwNavigationPI::StateChanged(StateChangedType nStateChange)
@@ -746,15 +735,15 @@ void SwNavigationPI::StateChanged(StateChangedType nStateChange)
        // if the parent isn't a float, then the navigator is displayed in
        // the sidebar or is otherwise docked. While the navigator could change
        // its size, the sidebar can not, and the navigator would just waste
        // space. Therefore hide this button.
        m_aContentToolBox->ShowItem(m_aContentToolBox->GetItemId("listbox"), SfxChildWindowContext::GetFloatingWindow(GetParent()) != nullptr);
        // space. Therefore disable this button.
        m_xContent3ToolBox->set_item_sensitive("listbox", SfxChildWindowContext::GetFloatingWindow(GetParent()) != nullptr);
        // show content if docked
        if (SfxChildWindowContext::GetFloatingWindow(GetParent()) == nullptr && IsZoomedIn())
            ZoomOut();
    }
    else if (nStateChange == StateChangedType::ControlFocus)
    {
        if (m_aContentTree)
        if (m_xContentTree)
        {
            // update documents listbox
            UpdateListBox();
@@ -762,13 +751,6 @@ void SwNavigationPI::StateChanged(StateChangedType nStateChange)
    }
}

// Get the numeric field from the toolbox.

NumEditAction& SwNavigationPI::GetPageEdit()
{
    return *static_cast<NumEditAction*>(m_aContentToolBox->GetItemWindow(FN_PAGENUMBER));
}

// Notification on modified DocInfo
void SwNavigationPI::Notify( SfxBroadcaster& rBrdc, const SfxHint& rHint )
{
@@ -791,15 +773,13 @@ void SwNavigationPI::Notify( SfxBroadcaster& rBrdc, const SfxHint& rHint )
                if(pActView)
                {
                    SwWrtShell* pWrtShell = pActView->GetWrtShellPtr();
                    m_aContentTree->SetActiveShell(pWrtShell);
                    if(m_aGlobalTree->IsVisible())
                    m_xContentTree->SetActiveShell(pWrtShell);
                    if (m_xGlobalTree->get_visible())
                    {
                        if(m_aGlobalTree->Update( false ))
                            m_aGlobalTree->Display();
                        else
                        // If no update is needed, then paint at least,
                        // because of the red entries for the broken links.
                            m_aGlobalTree->Invalidate();
                        bool bUpdateAll = m_xGlobalTree->Update(false);
                        // If no update is needed, then update the font colors
                        // at the entries of broken links.
                        m_xGlobalTree->Display(!bUpdateAll);
                    }
                }
            }
@@ -807,17 +787,10 @@ void SwNavigationPI::Notify( SfxBroadcaster& rBrdc, const SfxHint& rHint )
    }
}

IMPL_LINK( SwNavigationPI, MenuSelectHdl, Menu *, pMenu, bool )
IMPL_LINK( SwNavigationPI, HeadingsMenuSelectHdl, const OString&, rMenuId, void )
{
    sal_uInt16 nMenuId = pMenu->GetCurItemId();
    if(nMenuId != USHRT_MAX)
    {
        if(nMenuId < 100)
            SetRegionDropMode( static_cast<RegionMode>(--nMenuId));
        else
            m_aContentTree->SetOutlineLevel( static_cast< sal_uInt8 >(nMenuId - 100) );
    }
    return false;
    if (!rMenuId.isEmpty())
        m_xContentTree->SetOutlineLevel(rMenuId.toUInt32());
}

void SwNavigationPI::UpdateListBox()
@@ -825,17 +798,17 @@ void SwNavigationPI::UpdateListBox()
    if (isDisposed())
        return;

    m_aDocListBox->SetUpdateMode(false);
    m_aDocListBox->Clear();
    m_xDocListBox->freeze();
    m_xDocListBox->clear();
    SwView *pActView = GetCreateView();
    bool bDisable = pActView == nullptr;
    SwView *pView = SwModule::GetFirstView();
    sal_Int32 nCount = 0;
    sal_Int32 nAct = 0;
    sal_Int32 nConstPos = 0;
    const SwView* pConstView = m_aContentTree->IsConstantView() &&
                                m_aContentTree->GetActiveWrtShell() ?
                                    &m_aContentTree->GetActiveWrtShell()->GetView():
    const SwView* pConstView = m_xContentTree->IsConstantView() &&
                                m_xContentTree->GetActiveWrtShell() ?
                                    &m_xContentTree->GetActiveWrtShell()->GetView():
                                        nullptr;
    while (pView)
    {
@@ -852,7 +825,7 @@ void SwNavigationPI::UpdateListBox()
            else
                sEntry += m_aStatusArr[IDX_STR_INACTIVE];
            sEntry += ")";
            m_aDocListBox->InsertEntry(sEntry);
            m_xDocListBox->append_text(sEntry);

            if (pConstView && pView == pConstView)
                nConstPos = nCount;
@@ -861,33 +834,35 @@ void SwNavigationPI::UpdateListBox()
        }
        pView = SwModule::GetNextView(pView);
    }
    m_aDocListBox->InsertEntry(m_aStatusArr[3]); // "Active Window"
    m_xDocListBox->append_text(m_aStatusArr[3]); // "Active Window"
    nCount++;

    if(m_aContentTree->GetHiddenWrtShell())
    if(m_xContentTree->GetHiddenWrtShell())
    {
        OUString sEntry = m_aContentTree->GetHiddenWrtShell()->GetView().
        OUString sEntry = m_xContentTree->GetHiddenWrtShell()->GetView().
                                        GetDocShell()->GetTitle() +
            " (" +
            m_aStatusArr[IDX_STR_HIDDEN] +
            ")";
        m_aDocListBox->InsertEntry(sEntry);
        m_xDocListBox->append_text(sEntry);
        bDisable = false;
    }
    if(m_aContentTree->IsActiveView())

    m_xDocListBox->thaw();

    if(m_xContentTree->IsActiveView())
    {
        //Either the name of the current Document or "Active Document".
        m_aDocListBox->SelectEntryPos( pActView ? nAct : --nCount );
        m_xDocListBox->set_active(pActView ? nAct : --nCount);
    }
    else if(m_aContentTree->IsHiddenView())
    else if(m_xContentTree->IsHiddenView())
    {
        m_aDocListBox->SelectEntryPos(nCount);
        m_xDocListBox->set_active(nCount);
    }
    else
        m_aDocListBox->SelectEntryPos(nConstPos);
        m_xDocListBox->set_active(nConstPos);

    m_aDocListBox->Enable( !bDisable );
    m_aDocListBox->SetUpdateMode(true);
    m_xDocListBox->set_sensitive(!bDisable);
}

IMPL_LINK(SwNavigationPI, DoneLink, SfxPoolItem const *, pItem, void)
@@ -898,7 +873,7 @@ IMPL_LINK(SwNavigationPI, DoneLink, SfxPoolItem const *, pItem, void)
        SfxViewFrame* pFrame =  pFrameItem->GetFrame();
        if(pFrame)
        {
            m_aContentTree->Clear();
            m_xContentTree->clear();
            m_pContentView = dynamic_cast<SwView*>( pFrame->GetViewShell() );
            OSL_ENSURE(m_pContentView, "no SwView");
            if(m_pContentView)
@@ -907,7 +882,6 @@ IMPL_LINK(SwNavigationPI, DoneLink, SfxPoolItem const *, pItem, void)
                m_pContentWrtShell = nullptr;
            m_pxObjectShell.reset( new SfxObjectShellLock(pFrame->GetObjectShell()) );
            FillBox();
            m_aContentTree->Update();
        }
    }
}
@@ -947,15 +921,15 @@ OUString SwNavigationPI::CreateDropFileName( TransferableDataHelper& rData )

sal_Int8 SwNavigationPI::AcceptDrop()
{
    return ( !SwContentTree::IsInDrag() &&
        ( m_aContentTree->IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE ) ||
          m_aContentTree->IsDropFormatSupported( SotClipboardFormatId::STRING ) ||
          m_aContentTree->IsDropFormatSupported( SotClipboardFormatId::SOLK ) ||
           m_aContentTree->IsDropFormatSupported( SotClipboardFormatId::NETSCAPE_BOOKMARK )||
           m_aContentTree->IsDropFormatSupported( SotClipboardFormatId::FILECONTENT ) ||
           m_aContentTree->IsDropFormatSupported( SotClipboardFormatId::FILEGRPDESCRIPTOR ) ||
           m_aContentTree->IsDropFormatSupported( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ) ||
           m_aContentTree->IsDropFormatSupported( SotClipboardFormatId::FILENAME )))
    return ( !m_xContentTree->IsInDrag() &&
        ( m_xContentTree->IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE ) ||
          m_xContentTree->IsDropFormatSupported( SotClipboardFormatId::STRING ) ||
          m_xContentTree->IsDropFormatSupported( SotClipboardFormatId::SOLK ) ||
           m_xContentTree->IsDropFormatSupported( SotClipboardFormatId::NETSCAPE_BOOKMARK )||
           m_xContentTree->IsDropFormatSupported( SotClipboardFormatId::FILECONTENT ) ||
           m_xContentTree->IsDropFormatSupported( SotClipboardFormatId::FILEGRPDESCRIPTOR ) ||
           m_xContentTree->IsDropFormatSupported( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ) ||
           m_xContentTree->IsDropFormatSupported( SotClipboardFormatId::FILENAME )))
        ? DND_ACTION_COPY
        : DND_ACTION_NONE;
}
@@ -964,7 +938,7 @@ sal_Int8 SwNavigationPI::ExecuteDrop( const ExecuteDropEvent& rEvt )
{
    TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
    sal_Int8 nRet = DND_ACTION_NONE;
    if(SwContentTree::IsInDrag())
    if (m_xContentTree->IsInDrag())
        return nRet;

    OUString sFileName = SwNavigationPI::CreateDropFileName(aData);
@@ -986,7 +960,7 @@ sal_Int8 SwNavigationPI::ExecuteDrop( const ExecuteDropEvent& rEvt )
        m_sContentFileName = sFileName;
        if(m_pxObjectShell)
        {
            m_aContentTree->SetHiddenShell( nullptr );
            m_xContentTree->SetHiddenShell( nullptr );
            (*m_pxObjectShell)->DoClose();
            m_pxObjectShell.reset();
        }
@@ -1019,7 +993,7 @@ void SwNavigationPI::SetRegionDropMode(RegionMode nNewMode)
            sImageId = RID_BMP_DROP_COPY;
            break;
    }
    m_aContentToolBox->SetItemImage(m_aContentToolBox->GetItemId("dragmode"), Image(StockImage::Yes, sImageId));
    m_xContent3ToolBox->set_item_icon_name("dragmode", sImageId);
}

void SwNavigationPI::ToggleTree()
@@ -1030,27 +1004,31 @@ void SwNavigationPI::ToggleTree()
        SetUpdateMode(false);
        if (IsZoomedIn())
            ZoomOut();
        m_aGlobalBox->Show();
        m_aGlobalTree->ShowTree();
        m_aGlobalToolBox->Show();
        m_aContentBox->Hide();
        m_aContentTree->HideTree();
        m_aContentToolBox->Hide();
        m_aDocListBox->Hide();
        m_xGlobalBox->show();
        m_xGlobalTree->ShowTree();
        m_xGlobalToolBox->show();
        m_xContentBox->hide();
        m_xContentTree->HideTree();
        m_xContent1ToolBox->hide();
        m_xContent2ToolBox->hide();
        m_xContent3ToolBox->hide();
        m_xDocListBox->hide();
        SetGlobalMode(true);
        SetUpdateMode(true);
    }
    else
    {
        m_aGlobalBox->Hide();
        m_aGlobalTree->HideTree();
        m_aGlobalToolBox->Hide();
        m_xGlobalBox->hide();
        m_xGlobalTree->HideTree();
        m_xGlobalToolBox->hide();
        if (!IsZoomedIn())
        {
            m_aContentBox->Show();
            m_aContentTree->ShowTree();
            m_aContentToolBox->Show();
            m_aDocListBox->Show();
            m_xContentBox->show();
            m_xContentTree->ShowTree();
            m_xContent1ToolBox->show();
            m_xContent2ToolBox->show();
            m_xContent3ToolBox->show();
            m_xDocListBox->show();
        }
        SetGlobalMode(false);
    }
@@ -1072,9 +1050,8 @@ IMPL_LINK_NOARG(SwNavigationPI, ChangePageHdl, Timer *, void)
{
    if (IsDisposed())
        return;

    if (EditAction())
        GetPageEdit().GrabFocus();
        m_xEdit->grab_focus();
}

IMPL_LINK_NOARG(SwNavigationPI, PageEditModifyHdl, weld::SpinButton&, void)
@@ -1117,17 +1094,14 @@ SwNavigationChild::SwNavigationChild( vcl::Window* pParent,
    const ContentTypeId nRootType = pNaviConfig->GetRootType();
    if( nRootType != ContentTypeId::UNKNOWN )
    {
        pNavi->m_aContentTree->SetRootType(nRootType);
        pNavi->m_aContentToolBox->CheckItem(pNavi->m_aContentToolBox->GetItemId("root"));
        pNavi->m_xContentTree->SetRootType(nRootType);
        pNavi->m_xContent2ToolBox->set_item_active("root", true);
        if (nRootType == ContentTypeId::OUTLINE)
        {
            pNavi->m_aContentTree->SetSelectionMode(SelectionMode::Multiple);
            pNavi->m_aContentTree->SetDragDropMode(DragDropMode::CTRL_MOVE |
                                                   DragDropMode::CTRL_COPY |
                                                   DragDropMode::ENABLE_TOP);
            pNavi->m_xContentTree->set_selection_mode(SelectionMode::Multiple);
        }
    }
    pNavi->m_aContentTree->SetOutlineLevel( static_cast< sal_uInt8 >( pNaviConfig->GetOutlineLevel() ) );
    pNavi->m_xContentTree->SetOutlineLevel( static_cast< sal_uInt8 >( pNaviConfig->GetOutlineLevel() ) );
    pNavi->SetRegionDropMode( pNaviConfig->GetRegionMode() );

    if (SfxNavigator* pNav = dynamic_cast<SfxNavigator*>(pParent))
diff --git a/sw/uiconfig/swriter/ui/mastercontextmenu.ui b/sw/uiconfig/swriter/ui/mastercontextmenu.ui
new file mode 100644
index 0000000..2d346ac
--- /dev/null
+++ b/sw/uiconfig/swriter/ui/mastercontextmenu.ui
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface domain="sw">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkMenu" id="navmenu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkMenuItem" id="update">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="readonlymenu|STR_UPDATE">_Update</property>
        <property name="use_underline">True</property>
        <child type="submenu">
          <object class="GtkMenu" id="updatemenu">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkMenuItem" id="updatesel">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes" context="mastercontextmenu|STR_UPDATE_SEL">Selection</property>
                <property name="use_underline">True</property>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="updateindex">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes" context="mastercontextmenu|STR_UPDATE_INDEX">Indexes</property>
                <property name="use_underline">True</property>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="updatelinks">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes" context="mastercontextmenu|STR_UPDATE_SEL">Links</property>
                <property name="use_underline">True</property>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="updateall">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes" context="mastercontextmenu|STR_UPDATE_ALL">All</property>
                <property name="use_underline">True</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="editcontent">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="mastercontextmenu|STR_EDIT_CONTENT">Edit</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="editlink">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="mastercontextmenu|STR_EDIT_LINK">Edit link</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="insert">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="readonlymenu|STR_EDIT_INSERT">Insert</property>
        <property name="use_underline">True</property>
        <child type="submenu">
          <object class="GtkMenu" id="insertmenu">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkMenuItem" id="insertindex">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes" context="mastercontextmenu|STR_INDEX">_Index</property>
                <property name="use_underline">True</property>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="insertfile">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes" context="mastercontextmenu|STR_FILE">File</property>
                <property name="use_underline">True</property>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="insertnewfile">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes" context="mastercontextmenu|STR_NEW_FILE">New Document</property>
                <property name="use_underline">True</property>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="inserttext">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes" context="mastercontextmenu|STR_INSERT_TEXT">Text</property>
                <property name="use_underline">True</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkSeparatorMenuItem" id="menuitem3">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="deleteentry">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="mastercontextmenu|STR_DELETE_ENTRY">_Delete</property>
        <property name="use_underline">True</property>
      </object>
    </child>
  </object>
</interface>
diff --git a/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui b/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui
new file mode 100644
index 0000000..b324c1a
--- /dev/null
+++ b/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui
@@ -0,0 +1,242 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface domain="sw">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkMenu" id="navmenu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkMenuItem" id="800">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="use_underline">True</property>
        <accelerator key="asterisk" signal="activate" modifiers="GDK_CONTROL_MASK"/>
      </object>
    </child>
    <child>
      <object class="GtkSeparatorMenuItem" id="separator3">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="700">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_SEND_OUTLINE_TO_CLIPBOARD_ENTRY">Send Outline to Clipboard</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="900">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_GOTO">Go to</property>
        <property name="use_underline">True</property>
        <accelerator key="Return" signal="activate"/>
      </object>
    </child>
    <child>
      <object class="GtkSeparatorMenuItem" id="separator2">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="805">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_SELECT">Select</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="806">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_DELETE">Delete</property>
        <property name="use_underline">True</property>
        <accelerator key="Delete" signal="activate"/>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="801">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_PROMOTE_CHAPTER">Promote Chapter</property>
        <property name="use_underline">True</property>
        <accelerator key="Up" signal="activate" modifiers="GDK_CONTROL_MASK"/>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="802">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_DEMOTE_CHAPTER">Demote Chapter</property>
        <property name="use_underline">True</property>
        <accelerator key="Down" signal="activate" modifiers="GDK_CONTROL_MASK"/>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="803">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_PROMOTE_LEVEL">Promote Level</property>
        <property name="use_underline">True</property>
        <accelerator key="Left" signal="activate" modifiers="GDK_CONTROL_MASK"/>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="804">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_DEMOTE_LEVEL">Demote Level</property>
        <property name="use_underline">True</property>
        <accelerator key="Right" signal="activate" modifiers="GDK_CONTROL_MASK"/>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="401">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_REMOVE_INDEX">_Remove Index</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="402">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_UPDATE">_Update</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="403">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_EDIT_ENTRY">Edit...</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="404">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_REMOVE_TBL_PROTECTION">_Unprotect</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkCheckMenuItem" id="405">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_READONLY_IDX">Read-_only</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="501">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_DELETE_ENTRY">_Delete</property>
        <property name="use_underline">True</property>
        <accelerator key="Delete" signal="activate"/>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="502">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_RENAME">_Rename...</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="600">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_POSTIT_SHOW">Show All</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="601">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_POSTIT_HIDE">Hide All</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="602">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_POSTIT_DELETE">Delete All</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkSeparatorMenuItem" id="separator1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="4">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_OUTLINE_TRACKING">Outline Tracking</property>
        <property name="use_underline">True</property>
        <child type="submenu">
          <object class="GtkMenu" id="outlinetracking">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_OUTLINE_LEVEL">Outline Level</property>
        <property name="use_underline">True</property>
        <child type="submenu">
          <object class="GtkMenu" id="outlinelevel">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="2">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_DRAGMODE">Drag Mode</property>
        <property name="use_underline">True</property>
        <child type="submenu">
          <object class="GtkMenu" id="dragmodemenu">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
          </object>
        </child>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="3">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorcontextmenu|STR_DISPLAY">Display</property>
        <property name="use_underline">True</property>
        <child type="submenu">
          <object class="GtkMenu" id="displaymenu">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>
diff --git a/sw/uiconfig/swriter/ui/navigatorpanel.ui b/sw/uiconfig/swriter/ui/navigatorpanel.ui
index 28c08eb2..caac527 100644
--- a/sw/uiconfig/swriter/ui/navigatorpanel.ui
+++ b/sw/uiconfig/swriter/ui/navigatorpanel.ui
@@ -1,11 +1,231 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.22.2 -->
<interface domain="sw">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkAdjustment" id="adjustment1">
    <property name="lower">1</property>
    <property name="upper">100000</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkMenu" id="dragmodemenu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkRadioMenuItem" id="hyperlink">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|hyperlink">Insert as Hyperlink</property>
        <property name="use_underline">True</property>
        <property name="active">True</property>
        <property name="draw_as_radio">True</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="link">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|link">Insert as Link</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">hyperlink</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="copy">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|copy">Insert as Copy</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">hyperlink</property>
      </object>
    </child>
  </object>
  <object class="GtkMenu" id="headingsmenu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkRadioMenuItem" id="1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">1</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="2">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">2</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">1</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="3">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">3</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">1</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="4">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">4</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">1</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="5">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">5</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">1</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="6">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">6</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">1</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="7">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">7</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">1</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="8">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">8</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">1</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="9">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">9</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">1</property>
      </object>
    </child>
    <child>
      <object class="GtkRadioMenuItem" id="10">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label">10</property>
        <property name="use_underline">True</property>
        <property name="draw_as_radio">True</property>
        <property name="group">1</property>
      </object>
    </child>
  </object>
  <object class="GtkMenu" id="insertmenu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkMenuItem" id="insertindex">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|STR_INDEX">_Index</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="insertfile">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|STR_FILE">File</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="insertnewfile">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|STR_NEW_FILE">New Document</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="inserttext">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|STR_INSERT_TEXT">Text</property>
        <property name="use_underline">True</property>
      </object>
    </child>
  </object>
  <object class="GtkTreeStore" id="liststore1">
    <columns>
      <!-- column-name expander -->
      <column type="GdkPixbuf"/>
      <!-- column-name text -->
      <column type="gchararray"/>
      <!-- column-name id -->
      <column type="gchararray"/>
      <!-- column-name weight -->
      <column type="gint"/>
      <!-- column-name sensitive -->
      <column type="gboolean"/>
      <!-- column-name extraindent -->
      <column type="gint"/>
    </columns>
  </object>
  <object class="GtkTreeStore" id="liststore2">
    <columns>
      <!-- column-name expander -->
      <column type="GdkPixbuf"/>
      <!-- column-name text -->
      <column type="gchararray"/>
      <!-- column-name id -->
      <column type="gchararray"/>
      <!-- column-name textcolor -->
      <column type="GdkRGBA"/>
    </columns>
  </object>
  <object class="GtkListStore" id="liststore4">
    <columns>
      <!-- column-name text -->
      <column type="gchararray"/>
      <!-- column-name id -->
      <column type="gchararray"/>
      <!-- column-name image -->
      <column type="GdkPixbuf"/>
      <!-- column-name surface -->
      <column type="CairoSurface"/>
    </columns>
  </object>
  <object class="GtkGrid" id="NavigatorPanel">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="border_width">6</property>
    <property name="hexpand">True</property>
    <property name="vexpand">True</property>
    <child>
      <object class="GtkGrid">
        <property name="visible">True</property>
@@ -23,260 +243,314 @@
            <property name="row_spacing">6</property>
            <property name="column_spacing">12</property>
            <child>
              <object class="sfxlo-SidebarToolBox" id="content">
              <object class="GtkBox">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="toolbar_style">icons</property>
                <property name="can_focus">False</property>
                <property name="hexpand">True</property>
                <property name="orientation">vertical</property>
                <child>
                  <object class="GtkToolButton" id="contenttoggle">
                  <object class="GtkToolbar" id="content1">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|contenttoggle|tooltip_text">Toggle Master View</property>
                    <property name="action_name">toggle</property>
                    <property name="icon_name">sw/res/sc20244.png</property>
                    <property name="can_focus">True</property>
                    <property name="hexpand">True</property>
                    <property name="toolbar_style">icons</property>
                    <child>
                      <object class="GtkToggleToolButton" id="contenttoggle">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|contenttoggle|tooltip_text">Toggle Master View</property>
                        <property name="icon_name">sw/res/sc20244.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolItem" id=".uno:NavElement">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="hexpand">True</property>
                        <child>
                          <object class="GtkComboBox" id="NavElementWidget">
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="hexpand">True</property>
                            <property name="model">liststore4</property>
                            <property name="entry_text_column">0</property>
                            <property name="id_column">1</property>
                            <child>
                              <object class="GtkCellRendererText" id="cellrenderertext3"/>
                              <attributes>
                                <attribute name="text">0</attribute>
                              </attributes>
                            </child>
                            <child>
                              <object class="GtkCellRendererPixbuf" id="cellrenderertext1"/>
                              <attributes>
                                <attribute name="pixbuf">2</attribute>
                              </attributes>
                            </child>
                          </object>
                        </child>
                      </object>
                      <packing>
                        <property name="expand">True</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id=".uno:ScrollToPrevious">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id=".uno:ScrollToNext">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolItem" id="contentedit">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="hexpand">True</property>
                        <child>
                          <object class="GtkSpinButton" id="spinbutton">
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="hexpand">True</property>
                            <property name="adjustment">adjustment1</property>
                          </object>
                        </child>
                      </object>
                      <packing>
                        <property name="expand">True</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                    <property name="expand">True</property>
                    <property name="fill">True</property>
                    <property name="position">0</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id=".uno:NavElement">
                  <object class="GtkToolbar" id="content2">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="action_name">.uno:NavElement</property>
                    <property name="can_focus">True</property>
                    <property name="toolbar_style">icons</property>
                    <child>
                      <object class="GtkToggleToolButton" id="root">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|root|tooltip_text">Content Navigation View</property>
                        <property name="icon_name">sw/res/sc20234.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkSeparatorToolItem" id="separator3">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="header">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|header|tooltip_text">Header</property>
                        <property name="icon_name">sw/res/sc20179.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="footer">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|footer|tooltip_text">Footer</property>
                        <property name="icon_name">sw/res/sc20177.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="anchor">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|anchor|tooltip_text">Anchor&lt;-&gt;Text</property>
                        <property name="icon_name">sw/res/sc20182.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="reminder">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|reminder|tooltip_text">Set Reminder</property>
                        <property name="icon_name">sw/res/sc20183.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkSeparatorToolItem" id="separator5">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkMenuToolButton" id="headings">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|headings|tooltip_text">Heading Levels Shown</property>
                        <property name="icon_name">sw/res/sc20236.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                    <property name="fill">True</property>
                    <property name="position">1</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="back">
                  <object class="GtkToolbar" id="content3">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="action_name">.uno:ScrollToPrevious</property>
                    <property name="can_focus">True</property>
                    <property name="toolbar_style">icons</property>
                    <child>
                      <object class="GtkToggleToolButton" id="listbox">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|listbox|tooltip_text">List Box On/Off</property>
                        <property name="icon_name">sw/res/sc20233.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkSeparatorToolItem" id="separator6">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="promote">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|promote|tooltip_text">Promote Level</property>
                        <property name="icon_name">sw/res/sc20172.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="demote">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|demote|tooltip_text">Demote Level</property>
                        <property name="icon_name">sw/res/sc20173.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="chapterup">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|chapterup|tooltip_text">Promote Chapter</property>
                        <property name="icon_name">sw/res/sc20174.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkToolButton" id="chapterdown">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|chapterdown|tooltip_text">Demote Chapter</property>
                        <property name="icon_name">sw/res/sc20171.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkSeparatorToolItem" id="separator1">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkMenuToolButton" id="dragmode">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="tooltip_text" translatable="yes" context="navigatorpanel|dragmode|tooltip_text">Drag Mode</property>
                        <property name="icon_name">sw/res/sc20235.png</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
                        <property name="homogeneous">False</property>
                      </packing>
                    </child>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="forward">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="action_name">.uno:ScrollToNext</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="listbox">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|listbox|tooltip_text">List Box On/Off</property>
                    <property name="action_name">listbox</property>
                    <property name="icon_name">sw/res/sc20233.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="root">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|root|tooltip_text">Content Navigation View</property>
                    <property name="action_name">root</property>
                    <property name="icon_name">sw/res/sc20234.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkSeparatorToolItem" id="separator2">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="reminder">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|reminder|tooltip_text">Set Reminder</property>
                    <property name="action_name">reminder</property>
                    <property name="icon_name">sw/res/sc20183.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkSeparatorToolItem" id="separator3">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="header">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|header|tooltip_text">Header</property>
                    <property name="action_name">header</property>
                    <property name="icon_name">sw/res/sc20179.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="footer">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|footer|tooltip_text">Footer</property>
                    <property name="action_name">footer</property>
                    <property name="icon_name">sw/res/sc20177.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="anchor">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|anchor|tooltip_text">Anchor&lt;-&gt;Text</property>
                    <property name="action_name">anchor</property>
                    <property name="icon_name">sw/res/sc20182.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkSeparatorToolItem" id="separator4">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkMenuToolButton" id="headings">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|headings|tooltip_text">Heading Levels Shown</property>
                    <property name="action_name">headings</property>
                    <property name="icon_name">sw/res/sc20236.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkSeparatorToolItem" id="separator5">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="dragmode">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|dragmode|tooltip_text">Drag Mode</property>
                    <property name="action_name">dragmode</property>
                    <property name="icon_name">sw/res/sc20235.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkSeparatorToolItem" id="separator6">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="promote">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|promote|tooltip_text">Promote Level</property>
                    <property name="action_name">promote</property>
                    <property name="icon_name">sw/res/sc20172.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="demote">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|demote|tooltip_text">Demote Level</property>
                    <property name="action_name">demote</property>
                    <property name="icon_name">sw/res/sc20173.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="chapterup">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|chapterup|tooltip_text">Promote Chapter</property>
                    <property name="action_name">up</property>
                    <property name="icon_name">sw/res/sc20174.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkToolButton" id="chapterdown">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="tooltip_text" translatable="yes" context="navigatorpanel|chapterdown|tooltip_text">Demote Chapter</property>
                    <property name="action_name">down</property>
                    <property name="icon_name">sw/res/sc20171.png</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="homogeneous">True</property>
                    <property name="fill">True</property>
                    <property name="position">2</property>
                  </packing>
                </child>
              </object>
@@ -292,7 +566,7 @@
          </packing>
        </child>
        <child>
          <object class="GtkComboBox" id="documents">
          <object class="GtkComboBoxText" id="documents">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="tooltip_text" translatable="yes" context="navigatorpanel|documents|tooltip_text">Document</property>
@@ -315,7 +589,58 @@
            <property name="vexpand">True</property>
            <property name="orientation">vertical</property>
            <child>
              <placeholder/>
              <object class="GtkScrolledWindow">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="hexpand">True</property>
                <property name="vexpand">True</property>
                <property name="shadow_type">in</property>
                <child>
                  <object class="GtkTreeView" id="contenttree">
                    <property name="width_request">-1</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <property name="hexpand">True</property>
                    <property name="vexpand">True</property>
                    <property name="model">liststore1</property>
                    <property name="headers_visible">False</property>
                    <property name="reorderable">True</property>
                    <property name="search_column">1</property>
                    <property name="enable_tree_lines">True</property>
                    <child internal-child="selection">
                      <object class="GtkTreeSelection" id="Macro Library List-selection1"/>
                    </child>
                    <child>
                      <object class="GtkTreeViewColumn" id="treeviewcolumn2">
                        <property name="spacing">6</property>
                        <child>
                          <object class="GtkCellRendererPixbuf" id="cellrenderertext4"/>
                          <attributes>
                            <attribute name="sensitive">4</attribute>
                            <attribute name="pixbuf">0</attribute>
                          </attributes>
                        </child>
                        <child>
                          <object class="GtkCellRendererText" id="cellrenderertext2">
                            <property name="xalign">0</property>
                          </object>
                          <attributes>
                            <attribute name="xpad">5</attribute>
                            <attribute name="sensitive">4</attribute>
                            <attribute name="text">1</attribute>
                          </attributes>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
          </object>
          <packing>
@@ -325,20 +650,18 @@
        </child>
        <child>
          <object class="GtkToolbar" id="global">
            <property name="visible">False</property>
            <property name="can_focus">False</property>
            <property name="toolbar_style">icons</property>
            <child>
              <object class="GtkToolButton" id="globaltoggle">
              <object class="GtkToggleToolButton" id="globaltoggle">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="tooltip_text" translatable="yes" context="navigatorpanel|globaltoggle|tooltip_text">Toggle Master View</property>
                <property name="action_name">toggle</property>
                <property name="icon_name">sw/res/sc20244.png</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
            <child>
@@ -348,7 +671,7 @@
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
            <child>
@@ -356,38 +679,35 @@
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="tooltip_text" translatable="yes" context="navigatorpanel|edit|tooltip_text">Edit</property>
                <property name="action_name">edit</property>
                <property name="icon_name">sw/res/sc20245.png</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
            <child>
              <object class="GtkToolButton" id="update">
              <object class="GtkMenuToolButton" id="update">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="tooltip_text" translatable="yes" context="navigatorpanel|update|tooltip_text">Update</property>
                <property name="action_name">update</property>
                <property name="icon_name">sw/res/sc20246.png</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
            <child>
              <object class="GtkToolButton" id="insert">
              <object class="GtkMenuToolButton" id="insert">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="tooltip_text" translatable="yes" context="navigatorpanel|insert|tooltip_text">Insert</property>
                <property name="action_name">insert</property>
                <property name="icon_name">sw/res/sc20247.png</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
            <child>
@@ -397,20 +717,19 @@
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
            <child>
              <object class="GtkToolButton" id="save">
              <object class="GtkToggleToolButton" id="save">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="tooltip_text" translatable="yes" context="navigatorpanel|save|tooltip_text">Save Contents as well</property>
                <property name="action_name">save</property>
                <property name="icon_name">sw/res/sc20248.png</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
            <child>
@@ -420,7 +739,7 @@
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
            <child>
@@ -428,12 +747,11 @@
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="tooltip_text" translatable="yes" context="navigatorpanel|moveup|tooltip_text">Move Up</property>
                <property name="action_name">up</property>
                <property name="icon_name">sw/res/sc20174.png</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
            <child>
@@ -441,12 +759,11 @@
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="tooltip_text" translatable="yes" context="navigatorpanel|movedown|tooltip_text">Move Down</property>
                <property name="action_name">down</property>
                <property name="icon_name">sw/res/sc20171.png</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="homogeneous">True</property>
                <property name="homogeneous">False</property>
              </packing>
            </child>
          </object>
@@ -457,13 +774,59 @@
        </child>
        <child>
          <object class="GtkBox" id="globalbox">
            <property name="visible">False</property>
            <property name="can_focus">False</property>
            <property name="hexpand">True</property>
            <property name="vexpand">True</property>
            <property name="orientation">vertical</property>
            <child>
              <placeholder/>
              <object class="GtkScrolledWindow">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="hexpand">True</property>
                <property name="vexpand">True</property>
                <property name="shadow_type">in</property>
                <child>
                  <object class="GtkTreeView" id="globaltree">
                    <property name="width_request">-1</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <property name="has_tooltip">True</property>
                    <property name="hexpand">True</property>
                    <property name="vexpand">True</property>
                    <property name="model">liststore2</property>
                    <property name="headers_visible">False</property>
                    <property name="reorderable">True</property>
                    <property name="search_column">1</property>
                    <child internal-child="selection">
                      <object class="GtkTreeSelection"/>
                    </child>
                    <child>
                      <object class="GtkTreeViewColumn" id="treeviewcolumn1">
                        <property name="spacing">6</property>
                        <child>
                          <object class="GtkCellRendererPixbuf" id="cellrenderertext5"/>
                          <attributes>
                            <attribute name="pixbuf">0</attribute>
                          </attributes>
                        </child>
                        <child>
                          <object class="GtkCellRendererText" id="cellrenderertext6"/>
                          <attributes>
                            <attribute name="text">1</attribute>
                            <attribute name="foreground-rgba">3</attribute>
                          </attributes>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
          </object>
          <packing>
@@ -478,4 +841,48 @@
      </packing>
    </child>
  </object>
  <object class="GtkSizeGroup" id="sizegroup1">
    <widgets>
      <widget name="content1"/>
      <widget name="content2"/>
      <widget name="content3"/>
      <widget name="global"/>
    </widgets>
  </object>
  <object class="GtkMenu" id="updatemenu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkMenuItem" id="updatesel">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|STR_UPDATE_SEL">Selection</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="updateindex">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|STR_UPDATE_INDEX">Indexes</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="updatelinks">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|STR_UPDATE_SEL">Links</property>
        <property name="use_underline">True</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="updateall">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes" context="navigatorpanel|STR_UPDATE_ALL">All</property>
        <property name="use_underline">True</property>
      </object>
    </child>
  </object>
</interface>
diff --git a/sw/uiconfig/swriter/ui/spinbox.ui b/sw/uiconfig/swriter/ui/spinbox.ui
deleted file mode 100644
index 73a9af9..0000000
--- a/sw/uiconfig/swriter/ui/spinbox.ui
+++ /dev/null
@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface domain="sc">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkAdjustment" id="adjustment1">
    <property name="lower">1</property>
    <property name="upper">100000</property>
    <property name="value">1</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkBox" id="SpinBox">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="hexpand">True</property>
    <property name="spacing">6</property>
    <child>
      <object class="GtkSpinButton" id="spin">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="hexpand">True</property>
        <property name="vexpand">True</property>
        <property name="adjustment">adjustment1</property>
      </object>
      <packing>
        <property name="expand">False</property>
        <property name="fill">True</property>
        <property name="position">0</property>
      </packing>
    </child>
  </object>
</interface>
diff --git a/uitest/writer_tests5/tdf114724.py b/uitest/writer_tests5/tdf114724.py
index 8d67f2a..390e53b 100644
--- a/uitest/writer_tests5/tdf114724.py
+++ b/uitest/writer_tests5/tdf114724.py
@@ -22,7 +22,7 @@ class tdf114724(UITestCase):
        self.xUITest.executeCommand(".uno:Sidebar")
        xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "SwNavigatorPanel"}))

        xNavigatorPanel = xWriterEdit.getChild("NavigatorPanel")
        xNavigatorPanel = xWriterEdit.getChild("NavigatorPanelParent")
        xNavigatorPanel.executeAction("ROOT", tuple())

        xWriterEdit.executeAction("FOCUS", tuple())