summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2013-07-25 16:58:36 +0100
committerMiklos Vajna <vmiklos@suse.cz>2013-07-26 08:29:41 +0000
commita0fbb8b460114838a1c3fabb57274b04a78d3182 (patch)
tree80ad448f9aefa0854e6df35256ddc7cf6a033a92 /vcl
parent80328f390eceb32e1530ca182e6b135c3a0b0264 (diff)
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 <vmiklos@suse.cz> Tested-by: Miklos Vajna <vmiklos@suse.cz>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/window/layout.cxx58
1 files changed, 46 insertions, 12 deletions
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index bc92d8c2bb04..ae79e8fdabb9 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;
}
}