[Libreoffice-commits] .: Branch 'feature/cmclayouttrans' - vcl/inc vcl/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Aug 24 05:42:13 PDT 2012
vcl/inc/vcl/layout.hxx | 7 ++
vcl/source/window/dialog.cxx | 4 -
vcl/source/window/layout.cxx | 105 ++++++++++++++++++++----------------------
vcl/source/window/tabpage.cxx | 6 +-
4 files changed, 64 insertions(+), 58 deletions(-)
New commits:
commit 0cfefc22cef81d66486791693e8c5157f1b06345
Author: Caolán McNamara <caolanm at redhat.com>
Date: Fri Aug 24 13:40:42 2012 +0100
calculate and position taking external margins into account
Change-Id: I64acc2bc19051626e6c175b5d84f09c4dbbeb908
diff --git a/vcl/inc/vcl/layout.hxx b/vcl/inc/vcl/layout.hxx
index 9c89ce9..db35196 100644
--- a/vcl/inc/vcl/layout.hxx
+++ b/vcl/inc/vcl/layout.hxx
@@ -46,6 +46,13 @@ public:
{
m_bLayoutDirty = true;
}
+
+ //These take into account the external margins of the rWindow widget
+ //while GetOptimalSize/get_preferred_size and SetPosSizePixel are
+ //oblivious to them
+ static Size getLayoutRequisition(const Window &rWindow);
+ static void setLayoutAllocation(Window &rWindow, const Point &rPos, const Size &rSize);
+
protected:
virtual Size calculateRequisition() const = 0;
virtual void setAllocation(const Size &rAllocation) = 0;
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 72e3af2..6c94a17 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -1192,7 +1192,7 @@ Size Dialog::GetOptimalSize(WindowSizeType eType) const
if (eType == WINDOWSIZE_MAXIMUM || !isLayoutEnabled())
return SystemWindow::GetOptimalSize(eType);
- Size aSize = GetWindow(WINDOW_FIRSTCHILD)->GetOptimalSize(eType);
+ Size aSize = VclContainer::getLayoutRequisition(*GetWindow(WINDOW_FIRSTCHILD));
sal_Int32 nBorderWidth = get_border_width();
@@ -1216,7 +1216,7 @@ void Dialog::setPosSizeOnContainee(Size aSize, VclContainer &rBox)
Point aPos(mpWindowImpl->mnLeftBorder + nBorderWidth,
mpWindowImpl->mnTopBorder + nBorderWidth);
- rBox.SetPosSizePixel(aPos, aSize);
+ VclContainer::setLayoutAllocation(rBox, aPos, aSize);
}
IMPL_LINK( Dialog, ImplHandleLayoutTimerHdl, void*, EMPTYARG )
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index 303f057..bd27819 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -41,40 +41,39 @@ Size VclContainer::GetOptimalSize(WindowSizeType eType) const
{
if (eType == WINDOWSIZE_MAXIMUM)
return Window::GetOptimalSize(eType);
-
- Size aSize = calculateRequisition();
- sal_Int32 nBorderWidth = get_border_width();
- aSize.Width() += nBorderWidth*2 + get_margin_left() + get_margin_right();
- aSize.Height() += nBorderWidth*2 + get_margin_top() + get_margin_top();
- return aSize;
+ return calculateRequisition();
}
-void VclContainer::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
+void VclContainer::setLayoutAllocation(Window &rWindow, const Point &rPos, const Size &rSize)
{
- Size aAllocation = rAllocation;
- sal_Int32 nBorderWidth = get_border_width();
- sal_Int32 nLeft = get_margin_left();
- sal_Int32 nTop = get_margin_top();
-
- aAllocation.Width() -= nBorderWidth*2 + nLeft + get_margin_right();
- aAllocation.Height() -= nBorderWidth*2 + nTop + get_margin_bottom();
-
- Point aAllocPos = rAllocPos;
- aAllocPos.X() += nBorderWidth + nLeft;
- aAllocPos.Y() += nBorderWidth + nTop;
+ sal_Int32 nBorderWidth = rWindow.get_border_width();
+ sal_Int32 nLeft = rWindow.get_margin_left() + nBorderWidth;
+ sal_Int32 nTop = rWindow.get_margin_top() + nBorderWidth;
+ sal_Int32 nRight = rWindow.get_margin_right() + nBorderWidth;
+ sal_Int32 nBottom = rWindow.get_margin_bottom() + nBorderWidth;
+ Point aPos(rPos.X() + nLeft, rPos.Y() + nTop);
+ Size aSize(rSize.Width() - nLeft - nRight, rSize.Height() - nTop - nBottom);
+ rWindow.SetPosSizePixel(aPos, aSize);
+}
- bool bPosChanged = aAllocPos != GetPosPixel();
- bool bSizeChanged = aAllocation != GetSizePixel();
- if (bPosChanged && bSizeChanged)
- Window::SetPosSizePixel(aAllocPos, aAllocation);
- else if (bPosChanged)
- Window::SetPosPixel(aAllocPos);
- else if (bSizeChanged)
- Window::SetSizePixel(aAllocation);
+Size VclContainer::getLayoutRequisition(const Window &rWindow)
+{
+ sal_Int32 nBorderWidth = rWindow.get_border_width();
+ sal_Int32 nLeft = rWindow.get_margin_left() + nBorderWidth;
+ sal_Int32 nTop = rWindow.get_margin_top() + nBorderWidth;
+ sal_Int32 nRight = rWindow.get_margin_right() + nBorderWidth;
+ sal_Int32 nBottom = rWindow.get_margin_bottom() + nBorderWidth;
+ Size aSize(rWindow.get_preferred_size());
+ return Size(aSize.Width() + nLeft + nRight, aSize.Height() + nTop + nBottom);
+}
+void VclContainer::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
+{
+ bool bSizeChanged = rAllocation != GetOutputSizePixel();
+ Window::SetPosSizePixel(rAllocPos, rAllocation);
if (m_bLayoutDirty || bSizeChanged)
{
- setAllocation(aAllocation);
+ setAllocation(rAllocation);
m_bLayoutDirty = false;
}
}
@@ -118,7 +117,7 @@ Size VclBox::calculateRequisition() const
if (!pChild->IsVisible())
continue;
++nVisibleChildren;
- Size aChildSize = pChild->get_preferred_size();
+ Size aChildSize = getLayoutRequisition(*pChild);
long nSecondaryDimension = getSecondaryDimension(aChildSize);
if (nSecondaryDimension > getSecondaryDimension(aSize))
setSecondaryDimension(aSize, nSecondaryDimension);
@@ -210,7 +209,7 @@ void VclBox::setAllocation(const Size &rAllocation)
setPrimaryDimension(aBoxSize, nHomogeneousDimension);
else
{
- aBoxSize = pChild->get_preferred_size();
+ aBoxSize = getLayoutRequisition(*pChild);
long nPrimaryDimension = getPrimaryDimension(aBoxSize);
nPrimaryDimension += nPadding;
bool bExpand = pChild->get_expand();
@@ -234,7 +233,7 @@ void VclBox::setAllocation(const Size &rAllocation)
else
{
setPrimaryDimension(aChildSize,
- getPrimaryDimension(pChild->get_preferred_size()));
+ getPrimaryDimension(getLayoutRequisition(*pChild)));
setPrimaryCoordinate(aChildPos, nPrimaryCoordinate +
(getPrimaryDimension(aBoxSize) - getPrimaryDimension(aChildSize)) / 2);
@@ -250,7 +249,7 @@ void VclBox::setAllocation(const Size &rAllocation)
getPrimaryDimension(aBoxSize));
}
- pChild->SetPosSizePixel(aChildPos, aChildSize);
+ setLayoutAllocation(*pChild, aChildPos, aChildSize);
}
}
}
@@ -284,7 +283,7 @@ Size VclButtonBox::calculateRequisition() const
if (!pChild->IsVisible())
continue;
++nVisibleChildren;
- Size aChildSize = pChild->get_preferred_size();
+ Size aChildSize = getLayoutRequisition(*pChild);
if (aChildSize.Width() > aSize.Width())
aSize.Width() = aChildSize.Width();
if (aChildSize.Height() > aSize.Height())
@@ -377,7 +376,7 @@ void VclButtonBox::setAllocation(const Size &rAllocation)
setSecondaryDimension(aChildSize, getSecondaryDimension(aSize));
setPrimaryDimension(aChildSize, nHomogeneousDimension);
- pChild->SetPosSizePixel(aPos, aChildSize);
+ setLayoutAllocation(*pChild, aPos, aChildSize);
nPrimaryCoordinate = getPrimaryCoordinate(aPos);
setPrimaryCoordinate(aPos, nPrimaryCoordinate + nHomogeneousDimension + m_nSpacing);
@@ -490,7 +489,7 @@ void VclGrid::calcMaxs(const array_type &A, std::vector<Value> &rWidths, std::ve
const Window *pChild = A[x][y];
if (!pChild)
continue;
- Size aChildSize = pChild->get_preferred_size();
+ Size aChildSize = getLayoutRequisition(*pChild);
sal_Int32 nWidth = pChild->get_grid_width();
for (sal_Int32 nSpanX = 0; nSpanX < nWidth; ++nSpanX)
@@ -666,7 +665,7 @@ void VclGrid::setAllocation(const Size& rAllocation)
Size aChildPreferredSize;
if (eHalign != VCL_ALIGN_FILL || eValign != VCL_ALIGN_FILL)
- aChildPreferredSize = pChild->GetOptimalSize(WINDOWSIZE_PREFERRED);
+ aChildPreferredSize = getLayoutRequisition(*pChild);
switch (eHalign)
{
@@ -710,7 +709,7 @@ void VclGrid::setAllocation(const Size& rAllocation)
break;
}
- pChild->SetPosSizePixel(aChildPos, aChildSize);
+ setLayoutAllocation(*pChild, aChildPos, aChildSize);
}
aAllocPos.Y() += aHeights[y].m_nValue + get_row_spacing();
}
@@ -765,7 +764,7 @@ Size VclBin::calculateRequisition() const
{
const Window *pChild = get_child();
if (pChild && pChild->IsVisible())
- return pChild->GetOptimalSize(WINDOWSIZE_PREFERRED);
+ return getLayoutRequisition(*pChild);
return Size(0, 0);
}
@@ -773,7 +772,7 @@ void VclBin::setAllocation(const Size &rAllocation)
{
Window *pChild = get_child();
if (pChild && pChild->IsVisible())
- pChild->SetPosSizePixel(Point(0, 0), rAllocation);
+ setLayoutAllocation(*pChild, Point(0, 0), rAllocation);
}
//To-Do, hook a DecorationView into VclFrame ?
@@ -788,11 +787,11 @@ Size VclFrame::calculateRequisition() const
const Window *pLabel = pChild != pWindowImpl->mpLastChild ? pWindowImpl->mpLastChild : NULL;
if (pChild && pChild->IsVisible())
- aRet = pChild->GetOptimalSize(WINDOWSIZE_PREFERRED);
+ aRet = getLayoutRequisition(*pChild);
if (pLabel && pLabel->IsVisible())
{
- Size aLabelSize = pLabel->GetOptimalSize(WINDOWSIZE_PREFERRED);
+ Size aLabelSize = getLayoutRequisition(*pLabel);
aRet.Height() += aLabelSize.Height();
aRet.Width() = std::max(aLabelSize.Width(), aRet.Width());
}
@@ -823,16 +822,16 @@ void VclFrame::setAllocation(const Size &rAllocation)
if (pLabel && pLabel->IsVisible())
{
- Size aLabelSize = pLabel->GetOptimalSize(WINDOWSIZE_PREFERRED);
+ Size aLabelSize = getLayoutRequisition(*pLabel);
aLabelSize.Height() = std::min(aLabelSize.Height(), aAllocation.Height());
aLabelSize.Width() = std::min(aLabelSize.Width(), aAllocation.Width());
- pLabel->SetPosSizePixel(aChildPos, aLabelSize);
+ setLayoutAllocation(*pLabel, aChildPos, aLabelSize);
aAllocation.Height() -= aLabelSize.Height();
aChildPos.Y() += aLabelSize.Height();
}
if (pChild && pChild->IsVisible())
- pChild->SetPosSizePixel(aChildPos, aAllocation);
+ setLayoutAllocation(*pChild, aChildPos, aAllocation);
}
Size VclAlignment::calculateRequisition() const
@@ -843,7 +842,7 @@ Size VclAlignment::calculateRequisition() const
const Window *pChild = get_child();
if (pChild && pChild->IsVisible())
{
- Size aChildSize = pChild->GetOptimalSize(WINDOWSIZE_PREFERRED);
+ Size aChildSize = getLayoutRequisition(*pChild);
aRet.Width() += aChildSize.Width();
aRet.Height() += aChildSize.Height();
}
@@ -863,7 +862,7 @@ void VclAlignment::setAllocation(const Size &rAllocation)
aAllocation.Width() = rAllocation.Width() - (m_nLeftPadding + m_nRightPadding);
aAllocation.Height() = rAllocation.Height() - (m_nTopPadding + m_nBottomPadding);
- pChild->SetPosSizePixel(aChildPos, aAllocation);
+ setLayoutAllocation(*pChild, aChildPos, aAllocation);
}
bool VclAlignment::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
@@ -913,13 +912,13 @@ Size VclExpander::calculateRequisition() const
const Window *pLabel = pChild != pWindowImpl->mpLastChild ? pWindowImpl->mpLastChild : NULL;
if (pChild && pChild->IsVisible() && m_aDisclosureButton.IsChecked())
- aRet = pChild->GetOptimalSize(WINDOWSIZE_PREFERRED);
+ aRet = getLayoutRequisition(*pChild);
- Size aExpanderSize = m_aDisclosureButton.GetOptimalSize(WINDOWSIZE_PREFERRED);
+ Size aExpanderSize = getLayoutRequisition(m_aDisclosureButton);
if (pLabel && pLabel->IsVisible())
{
- Size aLabelSize = pLabel->GetOptimalSize(WINDOWSIZE_PREFERRED);
+ Size aLabelSize = getLayoutRequisition(*pLabel);
aExpanderSize.Height() = std::max(aExpanderSize.Height(), aLabelSize.Height());
aExpanderSize.Width() += aLabelSize.Width();
}
@@ -949,12 +948,12 @@ void VclExpander::setAllocation(const Size &rAllocation)
Window *pChild = get_child();
Window *pLabel = pChild != pWindowImpl->mpLastChild ? pWindowImpl->mpLastChild : NULL;
- Size aButtonSize = m_aDisclosureButton.GetOptimalSize(WINDOWSIZE_PREFERRED);
+ Size aButtonSize = getLayoutRequisition(m_aDisclosureButton);
Size aLabelSize;
Size aExpanderSize = aButtonSize;
if (pLabel && pLabel->IsVisible())
{
- aLabelSize = pLabel->GetOptimalSize(WINDOWSIZE_PREFERRED);
+ aLabelSize = getLayoutRequisition(*pLabel);
aExpanderSize.Height() = std::max(aExpanderSize.Height(), aLabelSize.Height());
aExpanderSize.Width() += aLabelSize.Width();
}
@@ -967,7 +966,7 @@ void VclExpander::setAllocation(const Size &rAllocation)
long nExtraExpanderHeight = aExpanderSize.Height() - aButtonSize.Height();
Point aButtonPos(aChildPos.X(), aChildPos.Y() + nExtraExpanderHeight/2);
- m_aDisclosureButton.SetPosSizePixel(aButtonPos, aButtonSize);
+ setLayoutAllocation(m_aDisclosureButton, aButtonPos, aButtonSize);
if (pLabel && pLabel->IsVisible())
{
@@ -977,7 +976,7 @@ void VclExpander::setAllocation(const Size &rAllocation)
long nExtraLabelHeight = aExpanderSize.Height() - aLabelSize.Height();
Point aLabelPos(aChildPos.X() + aButtonSize.Width(), aChildPos.Y() + nExtraLabelHeight/2);
- pLabel->SetPosSizePixel(aLabelPos, aLabelSize);
+ setLayoutAllocation(*pLabel, aLabelPos, aLabelSize);
}
aAllocation.Height() -= aExpanderSize.Height();
@@ -987,7 +986,7 @@ void VclExpander::setAllocation(const Size &rAllocation)
{
if (!m_aDisclosureButton.IsChecked())
aAllocation = Size();
- pChild->SetPosSizePixel(aChildPos, aAllocation);
+ setLayoutAllocation(*pChild, aChildPos, aAllocation);
}
}
diff --git a/vcl/source/window/tabpage.cxx b/vcl/source/window/tabpage.cxx
index d3395fd..8d5baf8 100644
--- a/vcl/source/window/tabpage.cxx
+++ b/vcl/source/window/tabpage.cxx
@@ -234,21 +234,21 @@ void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
{
Window::SetPosSizePixel(rAllocPos, rAllocation);
if (isLayoutEnabled())
- GetWindow(WINDOW_FIRSTCHILD)->SetPosSizePixel(Point(0, 0), rAllocation);
+ VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), rAllocation);
}
void TabPage::SetSizePixel(const Size& rAllocation)
{
Window::SetSizePixel(rAllocation);
if (isLayoutEnabled())
- GetWindow(WINDOW_FIRSTCHILD)->SetPosSizePixel(Point(0, 0), rAllocation);
+ VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), rAllocation);
}
void TabPage::SetPosPixel(const Point& rAllocPos)
{
Window::SetPosPixel(rAllocPos);
if (isLayoutEnabled())
- GetWindow(WINDOW_FIRSTCHILD)->SetPosSizePixel(Point(0, 0), GetOutputSizePixel());
+ VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), GetOutputSizePixel());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list