summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-11-15 20:04:42 +0000
committerCaolán McNamara <caolanm@redhat.com>2012-11-17 20:10:50 +0000
commit052a6a99e65a152aa9a08708ab89c8971b9b2f0a (patch)
tree322adc1a18d4474fc588847e58ce914a633d3f52
parentd00ee312b2b499da11752f89d8791e562c7f70b9 (diff)
honour child alignment in all layout widgets, not just grid
i.e. so that the original cmis checkin dialog of 207ed1b1a17ca6d785cad936ecadcd160acc2b83 would have worked without rework as grid of 5cc34dc91211b6173139d1a1a76c494c4a1f9a75 Change-Id: Ide047cfca63558867c427d4fcbb91ad182fb71e4
-rw-r--r--vcl/inc/vcl/layout.hxx4
-rw-r--r--vcl/source/window/layout.cxx118
2 files changed, 67 insertions, 55 deletions
diff --git a/vcl/inc/vcl/layout.hxx b/vcl/inc/vcl/layout.hxx
index 853bfb122904..04ee7e3fb31f 100644
--- a/vcl/inc/vcl/layout.hxx
+++ b/vcl/inc/vcl/layout.hxx
@@ -33,6 +33,10 @@ public:
//while GetOptimalSize/get_preferred_size and SetPosSizePixel are
//oblivious to them
static Size getLayoutRequisition(const Window &rWindow);
+ static void setLayoutPosSize(Window &rWindow, const Point &rPos, const Size &rSize);
+
+ //applies the allocation pos and size onto rWindow via setLayoutPosSize taking into account
+ //the rWindows alignment desires within that allocation
static void setLayoutAllocation(Window &rWindow, const Point &rPos, const Size &rSize);
protected:
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index 4e7b098c329c..a8ebca94d79a 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -25,7 +25,7 @@ Size VclContainer::GetOptimalSize(WindowSizeType eType) const
return calculateRequisition();
}
-void VclContainer::setLayoutAllocation(Window &rWindow, const Point &rPos, const Size &rSize)
+void VclContainer::setLayoutPosSize(Window &rWindow, const Point &rPos, const Size &rSize)
{
sal_Int32 nBorderWidth = rWindow.get_border_width();
sal_Int32 nLeft = rWindow.get_margin_left() + nBorderWidth;
@@ -37,6 +37,67 @@ void VclContainer::setLayoutAllocation(Window &rWindow, const Point &rPos, const
rWindow.SetPosSizePixel(aPos, aSize);
}
+void VclContainer::setLayoutAllocation(Window &rChild, const Point &rAllocPos, const Size &rChildAlloc)
+{
+ VclAlign eHalign = rChild.get_halign();
+ VclAlign eValign = rChild.get_valign();
+
+ //typical case
+ if (eHalign == VCL_ALIGN_FILL && eValign == VCL_ALIGN_FILL)
+ {
+ setLayoutPosSize(rChild, rAllocPos, rChildAlloc);
+ return;
+ }
+
+ Point aChildPos(rAllocPos);
+ Size aChildSize(rChildAlloc);
+ Size aChildPreferredSize(getLayoutRequisition(rChild));
+
+ switch (eHalign)
+ {
+ case VCL_ALIGN_FILL:
+ break;
+ case VCL_ALIGN_START:
+ if (aChildPreferredSize.Width() < rChildAlloc.Width())
+ aChildSize.Width() = aChildPreferredSize.Width();
+ break;
+ case VCL_ALIGN_END:
+ if (aChildPreferredSize.Width() < rChildAlloc.Width())
+ aChildSize.Width() = aChildPreferredSize.Width();
+ aChildPos.X() += rChildAlloc.Width();
+ aChildPos.X() -= aChildSize.Width();
+ break;
+ case VCL_ALIGN_CENTER:
+ if (aChildPreferredSize.Width() < aChildSize.Width())
+ aChildSize.Width() = aChildPreferredSize.Width();
+ aChildPos.X() += (rChildAlloc.Width() - aChildSize.Width()) / 2;
+ break;
+ }
+
+ switch (eValign)
+ {
+ case VCL_ALIGN_FILL:
+ break;
+ case VCL_ALIGN_START:
+ if (aChildPreferredSize.Height() < rChildAlloc.Height())
+ aChildSize.Height() = aChildPreferredSize.Height();
+ break;
+ case VCL_ALIGN_END:
+ if (aChildPreferredSize.Height() < rChildAlloc.Height())
+ aChildSize.Height() = aChildPreferredSize.Height();
+ aChildPos.Y() += rChildAlloc.Height();
+ aChildPos.Y() -= aChildSize.Height();
+ break;
+ case VCL_ALIGN_CENTER:
+ if (aChildPreferredSize.Height() < aChildSize.Height())
+ aChildSize.Height() = aChildPreferredSize.Height();
+ aChildPos.Y() += (rChildAlloc.Height() - aChildSize.Height()) / 2;
+ break;
+ }
+
+ setLayoutPosSize(rChild, aChildPos, aChildSize);
+}
+
Size VclContainer::getLayoutRequisition(const Window &rWindow)
{
sal_Int32 nBorderWidth = rWindow.get_border_width();
@@ -804,60 +865,7 @@ void VclGrid::setAllocation(const Size& rAllocation)
aChildAlloc.Height() += aHeights[y+nSpanY].m_nValue;
aChildAlloc.Height() += get_row_spacing()*(nHeight-1);
- Point aChildPos(aAllocPos);
- Size aChildSize(aChildAlloc);
-
- VclAlign eHalign = pChild->get_halign();
- VclAlign eValign = pChild->get_valign();
-
- Size aChildPreferredSize;
-
- if (eHalign != VCL_ALIGN_FILL || eValign != VCL_ALIGN_FILL)
- aChildPreferredSize = getLayoutRequisition(*pChild);
-
- switch (eHalign)
- {
- case VCL_ALIGN_FILL:
- break;
- case VCL_ALIGN_START:
- if (aChildPreferredSize.Width() < aChildAlloc.Width())
- aChildSize.Width() = aChildPreferredSize.Width();
- break;
- case VCL_ALIGN_END:
- if (aChildPreferredSize.Width() < aChildAlloc.Width())
- aChildSize.Width() = aChildPreferredSize.Width();
- aChildPos.X() += aChildAlloc.Width();
- aChildPos.X() -= aChildSize.Width();
- break;
- case VCL_ALIGN_CENTER:
- if (aChildPreferredSize.Width() < aChildSize.Width())
- aChildSize.Width() = aChildPreferredSize.Width();
- aChildPos.X() += (aChildAlloc.Width() - aChildSize.Width()) / 2;
- break;
- }
-
- switch (eValign)
- {
- case VCL_ALIGN_FILL:
- break;
- case VCL_ALIGN_START:
- if (aChildPreferredSize.Height() < aChildAlloc.Height())
- aChildSize.Height() = aChildPreferredSize.Height();
- break;
- case VCL_ALIGN_END:
- if (aChildPreferredSize.Height() < aChildAlloc.Height())
- aChildSize.Height() = aChildPreferredSize.Height();
- aChildPos.Y() += aChildAlloc.Height();
- aChildPos.Y() -= aChildSize.Height();
- break;
- case VCL_ALIGN_CENTER:
- if (aChildPreferredSize.Height() < aChildSize.Height())
- aChildSize.Height() = aChildPreferredSize.Height();
- aChildPos.Y() += (aChildAlloc.Height() - aChildSize.Height()) / 2;
- break;
- }
-
- setLayoutAllocation(*pChild, aChildPos, aChildSize);
+ setLayoutAllocation(*pChild, aAllocPos, aChildAlloc);
}
aAllocPos.Y() += aHeights[y].m_nValue + get_row_spacing();
}