tdf#136962 only do implicit SetUpdateMode optimization if the widget is hidden

callers can always opt-in with freeze/thaw for the lesser optimization
available if shown

Change-Id: Ib9317451a3059cc33f70d0c23543d8024bd21ede
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105487
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 61a1e52..fd9b277 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -3336,7 +3336,9 @@ static SalInstanceTreeView* g_DragSource;

namespace
{
    class UpdateGuard
    // tdf#131581 if the TreeView is hidden then there are possibly additional
    // optimizations available
    class UpdateGuardIfHidden
    {
    private:
        SvTabListBox& m_rTreeView;
@@ -3344,10 +3346,11 @@ namespace
        bool m_bOrigEnableInvalidate;

    public:
        UpdateGuard(SvTabListBox& rTreeView)
        UpdateGuardIfHidden(SvTabListBox& rTreeView)
            : m_rTreeView(rTreeView)
            , m_bOrigUpdate(m_rTreeView.IsUpdateMode())
            // tdf#137432 only do the EnableInvalidate(false) optimization if the widget is currently hidden
            // tdf#136962 only do SetUpdateMode(false) optimization if the widget is currently hidden
            , m_bOrigUpdate(!m_rTreeView.IsVisible() && m_rTreeView.IsUpdateMode())
            // tdf#137432 only do EnableInvalidate(false) optimization if the widget is currently hidden
            , m_bOrigEnableInvalidate(!m_rTreeView.IsVisible() && m_rTreeView.GetModel()->IsEnableInvalidate())
        {
            if (m_bOrigUpdate)
@@ -3356,7 +3359,7 @@ namespace
                m_rTreeView.GetModel()->EnableInvalidate(false);
        }

        ~UpdateGuard()
        ~UpdateGuardIfHidden()
        {
            if (m_bOrigEnableInvalidate)
                m_rTreeView.GetModel()->EnableInvalidate(true);
@@ -4594,7 +4597,7 @@ public:

    virtual void all_foreach(const std::function<bool(weld::TreeIter&)>& func) override
    {
        UpdateGuard aGuard(*m_xTreeView);
        UpdateGuardIfHidden aGuard(*m_xTreeView);

        SalInstanceTreeIter aVclIter(m_xTreeView->First());
        while (aVclIter.iter)
@@ -4607,7 +4610,7 @@ public:

    virtual void selected_foreach(const std::function<bool(weld::TreeIter&)>& func) override
    {
        UpdateGuard aGuard(*m_xTreeView);
        UpdateGuardIfHidden aGuard(*m_xTreeView);

        SalInstanceTreeIter aVclIter(m_xTreeView->FirstSelected());
        while (aVclIter.iter)
@@ -4620,7 +4623,7 @@ public:

    virtual void visible_foreach(const std::function<bool(weld::TreeIter&)>& func) override
    {
        UpdateGuard aGuard(*m_xTreeView);
        UpdateGuardIfHidden aGuard(*m_xTreeView);

        SalInstanceTreeIter aVclIter(m_xTreeView->GetFirstEntryInView());
        while (aVclIter.iter)