From 98b86bff2c7350ad9a22eb0db7f7696672c6db51 Mon Sep 17 00:00:00 2001 From: Rashesh Date: Sat, 8 Mar 2025 21:27:41 +0530 Subject: [PATCH] tdf#165606 sd: fix master slide panel doesn't resized correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ifb26d80f431f0fe6c4e58e58621e170e5a33a718 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182671 Reviewed-by: Tomaž Vajngerl Tested-by: Jenkins CollaboraOffice (cherry picked from commit a5a15bf521510530d33aa4f21a37f168ddc1bb68) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182727 Tested-by: Jenkins --- sd/source/ui/sidebar/MasterPagesSelector.cxx | 22 ++++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/sd/source/ui/sidebar/MasterPagesSelector.cxx b/sd/source/ui/sidebar/MasterPagesSelector.cxx index e429dfa4aec3..b3eb88c61e0c 100644 --- a/sd/source/ui/sidebar/MasterPagesSelector.cxx +++ b/sd/source/ui/sidebar/MasterPagesSelector.cxx @@ -584,16 +584,20 @@ void MasterPagesSelector::UpdateItemList (::std::unique_ptr && pNewIte css::ui::LayoutSize MasterPagesSelector::GetHeightForWidth(const sal_Int32 nWidth) { - if (maIconViewId == "masterpageall_icons") - return css::ui::LayoutSize(-1, -1, -1); + // there is no way to get margin of item programatically, we use value provided in ui file. + const int nMargin = 6; + sal_Int32 nColumnCount = nWidth / (mxPreviewIconView->get_item_width() + (5 * nMargin)); + if (nColumnCount < 1) + nColumnCount = 1; - const sal_uInt32 nItemWidth = mxPreviewIconView->get_item_width(); - sal_Int32 nMinimumHeight = mxPreviewIconView->get_preferred_size().getHeight(); - const sal_Int32 itemsInRows = floor(nWidth / nItemWidth); - sal_Int32 totalItems = mxPreviewIconView->n_children(); - if (itemsInRows > 0) - nMinimumHeight = ((totalItems / itemsInRows) + 1) * nMinimumHeight; - return css::ui::LayoutSize(nMinimumHeight, nMinimumHeight, nMinimumHeight); + sal_Int32 nTotalItems = mxPreviewIconView->n_children(); + sal_Int32 nRowCount = (nTotalItems + nColumnCount - 1) / nColumnCount; + if (nRowCount < 1) + nRowCount = 1; + + sal_Int32 nPreferedHeight + = nRowCount * (mxPreviewIconView->get_rect(nTotalItems - 1).GetHeight() + (2 * nMargin)); + return css::ui::LayoutSize(nPreferedHeight, nPreferedHeight, nPreferedHeight); } } // end of namespace sd::sidebar