summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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();
}