Related: tdf#133159 minimize jumping around if content doesn't change

when navigator tree is updated

Change-Id: Ie50ad0b4c24da15be575acb1172a28edb2fde05b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94502
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sc/source/ui/inc/content.hxx b/sc/source/ui/inc/content.hxx
index 6abf0fd..7e020781 100644
--- a/sc/source/ui/inc/content.hxx
+++ b/sc/source/ui/inc/content.hxx
@@ -165,7 +165,7 @@ public:
    const OUString& GetHiddenTitle() const    { return aHiddenTitle; }

    /** Applies the navigator settings to the listbox. */
    void ApplyNavigatorSettings();
    void ApplyNavigatorSettings(bool bRestoreScrollPos = false, int nScrollPos = 0);
    /** Stores the current listbox state in the navigator settings. */
    void StoreNavigatorSettings() const;
};
diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx
index edb5745..7feaee0 100644
--- a/sc/source/ui/navipi/content.cxx
+++ b/sc/source/ui/navipi/content.cxx
@@ -659,14 +659,22 @@ void ScContentTree::ObjectFresh(ScContentId nType, const weld::TreeIter* pEntry)
{
    if (bHiddenDoc && !pHiddenDocument)
        return;     // other document displayed

    if (nType == ScContentId::GRAPHIC || nType == ScContentId::OLEOBJECT || nType == ScContentId::DRAWING)
    {
        auto nOldChildren = m_aRootNodes[nType] ? m_xTreeView->iter_n_children(*m_aRootNodes[nType]) : 0;
        auto nOldPos = m_xTreeView->vadjustment_get_value();

        freeze();
        ClearType( nType );
        GetDrawNames( nType/*, nId*/ );
        thaw();

        auto nNewChildren = m_aRootNodes[nType] ? m_xTreeView->iter_n_children(*m_aRootNodes[nType]) : 0;
        bool bRestorePos = nOldChildren == nNewChildren;

        if (!pEntry)
            ApplyNavigatorSettings();
            ApplyNavigatorSettings(bRestorePos, nOldPos);
        if (pEntry)
        {
            weld::TreeIter* pParent = m_aRootNodes[nType].get();
@@ -1562,7 +1570,7 @@ void ScContentTree::SelectEntryByName(const ScContentId nRoot, const OUString& r
    }
}

void ScContentTree::ApplyNavigatorSettings()
void ScContentTree::ApplyNavigatorSettings(bool bRestorePos, int nScrollPos)
{
    const ScNavigatorSettings* pSettings = ScNavigatorDlg::GetNavigatorSettings();
    if( pSettings )
@@ -1602,6 +1610,9 @@ void ScContentTree::ApplyNavigatorSettings()
                // select
                if( nRootSel == nEntry )
                {
                    if (bRestorePos)
                        m_xTreeView->vadjustment_set_value(nScrollPos);

                    std::unique_ptr<weld::TreeIter> xEntry;
                    if (bExp && (nChildSel != SC_CONTENT_NOCHILD))
                    {