tdf#134413 must add scrollbar width on turning it off to occupy the same space

when scrollbars have width

Change-Id: I3f9f6951add23f8ac93a03cf3356add5a2b3ddd8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102275
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx
index 128ffcb..d0320fd 100644
--- a/include/svtools/valueset.hxx
+++ b/include/svtools/valueset.hxx
@@ -255,6 +255,8 @@ private:
    SVT_DLLPRIVATE void         QueueReformat();
    SVT_DLLPRIVATE void         SetFirstLine(sal_uInt16 nNewFirstLine); // set mnFirstLine and update scrollbar to match
    SVT_DLLPRIVATE void         RecalcScrollBar();
    SVT_DLLPRIVATE void         TurnOffScrollBar();
    SVT_DLLPRIVATE void         TurnOnScrollBar();
    DECL_DLLPRIVATE_LINK(ImplScrollHdl, weld::ScrolledWindow&, void);

    Size           GetLargestItemSize();
diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx
index a995881..2eb875e 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -552,13 +552,29 @@ void ValueSet::RemoveItem( sal_uInt16 nItemId )
    QueueReformat();
}

void ValueSet::TurnOffScrollBar()
{
    mxScrolledWindow->set_vpolicy(VclPolicyType::NEVER);
    weld::DrawingArea* pDrawingArea = GetDrawingArea();
    Size aPrefSize(pDrawingArea->get_preferred_size());
    pDrawingArea->set_size_request(aPrefSize.Width() + GetScrollWidth(), aPrefSize.Height());
}

void ValueSet::TurnOnScrollBar()
{
    mxScrolledWindow->set_vpolicy(VclPolicyType::ALWAYS);
    weld::DrawingArea* pDrawingArea = GetDrawingArea();
    Size aPrefSize(pDrawingArea->get_preferred_size());
    pDrawingArea->set_size_request(aPrefSize.Width() - GetScrollWidth(), aPrefSize.Height());
}

void ValueSet::RecalcScrollBar()
{
    // reset scrolled window state to initial value
    // so it will get configured to the right adjustment
    WinBits nStyle = GetStyle();
    if (mxScrolledWindow && (nStyle & WB_VSCROLL))
        mxScrolledWindow->set_vpolicy(VclPolicyType::NEVER);
        TurnOffScrollBar();
}

void ValueSet::Clear()
@@ -854,11 +870,7 @@ void ValueSet::Format(vcl::RenderContext const & rRenderContext)
    long nNoneSpace;

    if (mxScrolledWindow && !(nStyle & WB_VSCROLL) && mxScrolledWindow->get_vpolicy() != VclPolicyType::NEVER)
    {
        mxScrolledWindow->set_vpolicy(VclPolicyType::NEVER);
        Size aPrefSize(GetDrawingArea()->get_preferred_size());
        GetDrawingArea()->set_size_request(aPrefSize.Width() + GetScrollWidth(), aPrefSize.Height());
    }
        TurnOffScrollBar();

    // calculate item offset
    if (nStyle & WB_ITEMBORDER)
@@ -1008,11 +1020,7 @@ void ValueSet::Format(vcl::RenderContext const & rRenderContext)
        }

        if (mxScrolledWindow && mxScrolledWindow->get_vpolicy() != VclPolicyType::NEVER)
        {
            mxScrolledWindow->set_vpolicy(VclPolicyType::NEVER);
            Size aPrefSize(GetDrawingArea()->get_preferred_size());
            GetDrawingArea()->set_size_request(aPrefSize.Width() + GetScrollWidth(), aPrefSize.Height());
        }
            TurnOffScrollBar();
    }
    else
    {
@@ -1164,11 +1172,7 @@ void ValueSet::Format(vcl::RenderContext const & rRenderContext)
            }

            if (bTurnScrollbarOn)
            {
                mxScrolledWindow->set_vpolicy(VclPolicyType::ALWAYS);
                Size aPrefSize(GetDrawingArea()->get_preferred_size());
                GetDrawingArea()->set_size_request(aPrefSize.Width() - GetScrollWidth(), aPrefSize.Height());
            }
                TurnOnScrollBar();
        }
    }