Related: tdf#146648 let SetWindowState size trump the initial layout pref size

so a size can be restored from config and overrule the initial layout
size which is calculated on first show.

for existing cases, this changes behaviour if a dialog is shown,
hidden, layout changed and then reshown and the new layout is smaller
than the old layout. But that should align the behaviour of vcl
layout-enabled widgets with gtk ones.

Change-Id: I526f16dba91ccfd6d52c63a17e5dc51bf79750a7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129037
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/vcl/syswin.hxx b/include/vcl/syswin.hxx
index 0c35073..7166190 100644
--- a/include/vcl/syswin.hxx
+++ b/include/vcl/syswin.hxx
@@ -103,6 +103,7 @@ private:
    bool            mbHideBtn;
    bool            mbSysChild;
    bool            mbIsCalculatingInitialLayoutSize;
    bool            mbInitialLayoutSizeCalculated;
    bool            mbPaintComplete;
    MenuBarMode     mnMenuBarMode;
    sal_uInt16      mnIcon;
diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx
index c624c37..f691f62 100644
--- a/vcl/source/window/syswin.cxx
+++ b/vcl/source/window/syswin.cxx
@@ -70,6 +70,7 @@ SystemWindow::SystemWindow(WindowType nType, const char* pIdleDebugName)
    , mbHideBtn(false)
    , mbSysChild(false)
    , mbIsCalculatingInitialLayoutSize(false)
    , mbInitialLayoutSizeCalculated(false)
    , mbPaintComplete(false)
    , mnMenuBarMode(MenuBarMode::Normal)
    , mnIcon(0)
@@ -746,6 +747,11 @@ void SystemWindow::SetWindowStateData( const WindowStateData& rData )
            nY = rGeom.nHeight - nHeight;
        setPosSizePixel( nX, nY, nWidth, nHeight, nPosSize );
    }

    // tdf#146648 if an explicit size state was set, then use it as the preferred
    // size for layout
    if (nValidMask & WindowStateMask::Size)
        mbInitialLayoutSizeCalculated = true;
}

void SystemWindow::GetWindowStateData( WindowStateData& rData ) const
@@ -1081,6 +1087,16 @@ void SystemWindow::setOptimalLayoutSize()
    aSize.setHeight( std::min(aMax.Height(), aSize.Height()) );

    SetMinOutputSizePixel(aSize);

    if (!mbInitialLayoutSizeCalculated)
        mbInitialLayoutSizeCalculated = true;
    else
    {
        Size aCurrentSize = GetSizePixel();
        aSize.setWidth(std::max(aSize.Width(), aCurrentSize.Width()));
        aSize.setHeight(std::max(aSize.Height(), aCurrentSize.Height()));
    }

    SetSizePixel(aSize);
    setPosSizeOnContainee(aSize, *pBox);
}