include/vcl/layout.hxx | 1 vcl/source/window/layout.cxx | 58 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 12 deletions(-)
New commits: commit a0fbb8b460114838a1c3fabb57274b04a78d3182 Author: Caolán McNamara <caol...@redhat.com> Date: Thu Jul 25 16:58:36 2013 +0100 Resolves: fdo#61544 improve handling of grid's not enough layout space (cherry picked from commit b64adf65afb1cfe1bd48fed0d71ac333ad962776) Conflicts: vcl/source/window/layout.cxx Change-Id: I9a73e90f639bb853b67daa98d5daac155dab5900 Reviewed-on: https://gerrit.libreoffice.org/5119 Reviewed-by: Miklos Vajna <vmik...@suse.cz> Tested-by: Miklos Vajna <vmik...@suse.cz> diff --git a/include/vcl/layout.hxx b/include/vcl/layout.hxx index 5237c72..dd2c0bc 100644 --- a/include/vcl/layout.hxx +++ b/include/vcl/layout.hxx @@ -388,6 +388,7 @@ public: private: void calcMaxs(const array_type &A, std::vector<Value> &rWidths, std::vector<Value> &rHeights) const; + Size calculateRequisitionForSpacings(sal_Int32 nRowSpacing, sal_Int32 nColSpacing) const; virtual Size calculateRequisition() const; virtual void setAllocation(const Size &rAllocation); public: diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx index bc92d8c..ae79e8f 100644 --- a/vcl/source/window/layout.cxx +++ b/vcl/source/window/layout.cxx @@ -984,6 +984,11 @@ VclGrid::Value accumulateValues(const VclGrid::Value &i, const VclGrid::Value &j Size VclGrid::calculateRequisition() const { + return calculateRequisitionForSpacings(get_row_spacing(), get_column_spacing()); +} + +Size VclGrid::calculateRequisitionForSpacings(sal_Int32 nRowSpacing, sal_Int32 nColSpacing) const +{ array_type A = assembleGrid(); if (isNullGrid(A)) @@ -1004,7 +1009,7 @@ Size VclGrid::calculateRequisition() const nTotalWidth = std::accumulate(aWidths.begin(), aWidths.end(), Value(), accumulateValues).m_nValue; } - nTotalWidth += get_column_spacing() * (aWidths.size()-1); + nTotalWidth += nColSpacing * (aWidths.size()-1); long nTotalHeight = 0; if (get_row_homogeneous()) @@ -1017,7 +1022,7 @@ Size VclGrid::calculateRequisition() const nTotalHeight = std::accumulate(aHeights.begin(), aHeights.end(), Value(), accumulateValues).m_nValue; } - nTotalHeight += get_row_spacing() * (aHeights.size()-1); + nTotalHeight += nRowSpacing * (aHeights.size()-1); return Size(nTotalWidth, nTotalHeight); } @@ -1041,7 +1046,12 @@ void VclGrid::setAllocation(const Size& rAllocation) calcMaxs(A, aWidths, aHeights); } - long nAvailableWidth = rAllocation.Width() - (get_column_spacing() * nMaxX); + sal_Int32 nColSpacing(get_column_spacing()); + sal_Int32 nRowSpacing(get_row_spacing()); + + long nAvailableWidth = rAllocation.Width(); + if (nMaxX) + nAvailableWidth -= nColSpacing * (nMaxX - 1); if (get_column_homogeneous()) { for (sal_Int32 x = 0; x < nMaxX; ++x) @@ -1055,9 +1065,20 @@ void VclGrid::setAllocation(const Size& rAllocation) ++nExpandables; long nExtraWidthForExpanders = nExpandables ? (rAllocation.Width() - aRequisition.Width()) / nExpandables : 0; - if (rAllocation.Width() < aRequisition.Width()) + //We don't fit and there is no volunteer to be shrunk + if (!nExpandables && rAllocation.Width() < aRequisition.Width()) { - long nExtraWidth = (rAllocation.Width() - aRequisition.Width() - nExtraWidthForExpanders * nExpandables) / nMaxX; + //first reduce spacing, to a min of 3 + while (nColSpacing >= 6) + { + nColSpacing /= 2; + aRequisition = calculateRequisitionForSpacings(nRowSpacing, nColSpacing); + if (aRequisition.Width() >= rAllocation.Width()) + break; + } + + //share out the remaining pain to everyone + long nExtraWidth = (rAllocation.Width() - aRequisition.Width()) / nMaxX; for (sal_Int32 x = 0; x < nMaxX; ++x) aWidths[x].m_nValue += nExtraWidth; @@ -1071,7 +1092,9 @@ void VclGrid::setAllocation(const Size& rAllocation) } } - long nAvailableHeight = rAllocation.Height() - (get_row_spacing() * nMaxY); + long nAvailableHeight = rAllocation.Height(); + if (nMaxY) + nAvailableHeight -= nRowSpacing * (nMaxY - 1); if (get_row_homogeneous()) { for (sal_Int32 y = 0; y < nMaxY; ++y) @@ -1085,9 +1108,20 @@ void VclGrid::setAllocation(const Size& rAllocation) ++nExpandables; long nExtraHeightForExpanders = nExpandables ? (rAllocation.Height() - aRequisition.Height()) / nExpandables : 0; - if (rAllocation.Height() < aRequisition.Height()) + //We don't fit and there is no volunteer to be shrunk + if (!nExpandables && rAllocation.Height() < aRequisition.Height()) { - long nExtraHeight = (rAllocation.Height() - aRequisition.Height() - nExtraHeightForExpanders * nExpandables) / nMaxY; + //first reduce spacing, to a min of 3 + while (nRowSpacing >= 6) + { + nRowSpacing /= 2; + aRequisition = calculateRequisitionForSpacings(nRowSpacing, nColSpacing); + if (aRequisition.Height() >= rAllocation.Height()) + break; + } + + //share out the remaining pain to everyone + long nExtraHeight = (rAllocation.Height() - aRequisition.Height()) / nMaxY; for (sal_Int32 y = 0; y < nMaxY; ++y) aHeights[y].m_nValue += nExtraHeight; @@ -1115,18 +1149,18 @@ void VclGrid::setAllocation(const Size& rAllocation) sal_Int32 nWidth = rEntry.nSpanWidth; for (sal_Int32 nSpanX = 0; nSpanX < nWidth; ++nSpanX) aChildAlloc.Width() += aWidths[x+nSpanX].m_nValue; - aChildAlloc.Width() += get_column_spacing()*(nWidth-1); + aChildAlloc.Width() += nColSpacing*(nWidth-1); sal_Int32 nHeight = rEntry.nSpanHeight; for (sal_Int32 nSpanY = 0; nSpanY < nHeight; ++nSpanY) aChildAlloc.Height() += aHeights[y+nSpanY].m_nValue; - aChildAlloc.Height() += get_row_spacing()*(nHeight-1); + aChildAlloc.Height() += nRowSpacing*(nHeight-1); setLayoutAllocation(*pChild, aAllocPos, aChildAlloc); } - aAllocPos.Y() += aHeights[y].m_nValue + get_row_spacing(); + aAllocPos.Y() += aHeights[y].m_nValue + nRowSpacing; } - aAllocPos.X() += aWidths[x].m_nValue + get_column_spacing(); + aAllocPos.X() += aWidths[x].m_nValue + nColSpacing; aAllocPos.Y() = 0; } }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits