tdf#124263 Respect XSidebarPanel::getMinimalWidth

even if it's larger than max sidebar width (increase max sidebar width in that case).

Change-Id: I2efbd546596f756df205196fae3e545beddd2f7c
Reviewed-on: https://gerrit.libreoffice.org/69551
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
diff --git a/include/sfx2/sidebar/SidebarController.hxx b/include/sfx2/sidebar/SidebarController.hxx
index 68e97c5..eaed146 100644
--- a/include/sfx2/sidebar/SidebarController.hxx
+++ b/include/sfx2/sidebar/SidebarController.hxx
@@ -169,6 +169,7 @@
    css::uno::Reference<css::frame::XFrame> getXFrame() {return mxFrame;}

    sal_Int32 getMaximumWidth() { return mnMaximumSidebarWidth; }
    void setMaximumWidth(sal_Int32 nMaximumWidth) { mnMaximumSidebarWidth = nMaximumWidth; }

private:
    SidebarController(
diff --git a/offapi/com/sun/star/ui/XSidebarPanel.idl b/offapi/com/sun/star/ui/XSidebarPanel.idl
index aa60b328..da8f19a 100644
--- a/offapi/com/sun/star/ui/XSidebarPanel.idl
+++ b/offapi/com/sun/star/ui/XSidebarPanel.idl
@@ -40,7 +40,12 @@
    */
    LayoutSize getHeightForWidth ( [in] long nWidth);

    /** Minimal possible width of this panel.
    /** Minimal possible width of this panel in pixels.

        If this value is smaller than the maximum allowed size of the Sidebar
        (see config option 'org.openoffice.Office.UI.Sidebar.General.MaximumWidth'),
        the config option will be ignored and the new maximum Sidebar width will be
        getMinimalWidth() + 100px.
    */
    long getMinimalWidth();
} ;
diff --git a/officecfg/registry/schema/org/openoffice/Office/UI/Sidebar.xcs b/officecfg/registry/schema/org/openoffice/Office/UI/Sidebar.xcs
index 2eeed453..6ed1d79 100644
--- a/officecfg/registry/schema/org/openoffice/Office/UI/Sidebar.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/UI/Sidebar.xcs
@@ -237,7 +237,8 @@
      </info>
      <prop oor:name="MaximumWidth" oor:type="xs:int" oor:nillable="false">
        <info>
          <desc>Maximum width the sidebar can ever have</desc>
          <desc>Maximum width the sidebar can have.
          Note that this can be overridden by extensions returning a larger value in XSidebarPanel::getMinimalWidth()</desc>
        </info>
        <value>500</value>
      </prop>
diff --git a/sfx2/source/sidebar/DeckLayouter.cxx b/sfx2/source/sidebar/DeckLayouter.cxx
index 3d40cd1..c3649aa 100644
--- a/sfx2/source/sidebar/DeckLayouter.cxx
+++ b/sfx2/source/sidebar/DeckLayouter.cxx
@@ -22,10 +22,17 @@
#include <sfx2/sidebar/Panel.hxx>
#include <sfx2/sidebar/PanelTitleBar.hxx>
#include <sfx2/sidebar/Deck.hxx>
#include <sfx2/sidebar/SidebarController.hxx>

#include <comphelper/processfactory.hxx>
#include <vcl/window.hxx>
#include <vcl/scrbar.hxx>

#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XDesktop2.hpp>
#include <com/sun/star/frame/XFrame.hpp>

using namespace css;
using namespace css::uno;

@@ -369,8 +376,23 @@
                if (xPanel.is())
                {
                    aLayoutSize = xPanel->getHeightForWidth(rContentBox.GetWidth());

                    sal_Int32 nWidth = xPanel->getMinimalWidth();

                    uno::Reference<frame::XDesktop2> xDesktop
                        = frame::Desktop::create(comphelper::getProcessComponentContext());
                    uno::Reference<frame::XFrame> xFrame = xDesktop->getActiveFrame();
                    if (xFrame.is())
                    {
                        SidebarController* pController
                            = SidebarController::GetSidebarControllerForFrame(xFrame);
                        if (pController && pController->getMaximumWidth() < nWidth)
                        {
                            // Add 100 extra pixels to still have the sidebar resizable
                            // (See also documentation of XSidebarPanel::getMinimalWidth)
                            pController->setMaximumWidth(nWidth + 100);
                        }
                    }

                    if (nWidth > rMinimalWidth)
                        rMinimalWidth = nWidth;
                }