diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-08-24 13:40:42 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-09-28 08:48:39 +0100 |
commit | a216f1db779cb74523dad94cc1f93233d3826c78 (patch) | |
tree | a6119e3f4ecb26c07240cdb484d3cdf3e73d35d5 /vcl | |
parent | 2f002e3a49da3fb797d564864acb34f6dc61f9de (diff) |
calculate and position taking external margins into account
Change-Id: I64acc2bc19051626e6c175b5d84f09c4dbbeb908
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/layout.hxx | 7 | ||||
-rw-r--r-- | vcl/source/window/dialog.cxx | 4 | ||||
-rw-r--r-- | vcl/source/window/layout.cxx | 105 | ||||
-rw-r--r-- | vcl/source/window/tabpage.cxx | 6 |
4 files changed, 64 insertions, 58 deletions
diff --git a/vcl/inc/vcl/layout.hxx b/vcl/inc/vcl/layout.hxx index 9c89ce98efd0..db35196c661f 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 2db5186d39b0..11cf7da33b63 100644 --- a/vcl/source/window/dialog.cxx +++ b/vcl/source/window/dialog.cxx @@ -1181,7 +1181,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(); @@ -1205,7 +1205,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 303f0574a2ea..bd278196aac4 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 d3395fd3dd8a..8d5baf81b5ee 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: */ |