diff options
author | Ashod Nakashian <ashodnakashian@yahoo.com> | 2015-11-01 16:33:36 -0500 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-11-18 12:38:34 +0100 |
commit | 7ffb53497fc05f8e0ea367780be076193263292a (patch) | |
tree | fd0b9d6ec8f7bc8ef6613f8abffcb91ab0a0a5ea /sw | |
parent | 98195b6dbdf55d4b32191eef692d6cdb50aae726 (diff) |
SwPageFrm::MakeAll Refactored
Browser and Hide Whitespace page height now use
SwPageFrm::GetContentHeight, which is const.
A few improvements are done for both paths as well.
Reviewed-on: https://gerrit.libreoffice.org/19730
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit f05da45c9c69e66cd5f26fc02c950ccf0c0b946d)
Conflicts:
sw/source/core/layout/calcmove.cxx
Change-Id: I73a8e920ccfa96d76cbbb002bed6a85f2e636ede
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/inc/pagefrm.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/inc/sectfrm.hxx | 11 | ||||
-rw-r--r-- | sw/source/core/layout/calcmove.cxx | 137 | ||||
-rw-r--r-- | sw/source/core/layout/sectfrm.cxx | 25 | ||||
-rw-r--r-- | sw/source/core/layout/wsfrm.cxx | 2 |
5 files changed, 70 insertions, 107 deletions
diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx index e19012d14f02..8afa92bdd3a5 100644 --- a/sw/source/core/inc/pagefrm.hxx +++ b/sw/source/core/inc/pagefrm.hxx @@ -111,7 +111,7 @@ protected: virtual void SwClientNotify(const SwModify&, const SfxHint&) SAL_OVERRIDE; /// Calculate the content height of a page (without columns). - size_t GetContentHeight(); + size_t GetContentHeight(const long nTop, const long nBottom) const; public: DECL_FIXEDMEMPOOL_NEWDEL(SwPageFrm) diff --git a/sw/source/core/inc/sectfrm.hxx b/sw/source/core/inc/sectfrm.hxx index 668578acd815..5e1aeaed0936 100644 --- a/sw/source/core/inc/sectfrm.hxx +++ b/sw/source/core/inc/sectfrm.hxx @@ -118,15 +118,20 @@ public: bool CalcMinDiff( SwTwips& rMinDiff ) const; /** - * If we don't pass a @param bOverSize or false, the return value is > 0 for - * undersized Frames, or 0 + * Returns the size delta that the section would like to be + * greater if it has undersized TextFrms in it. * + * If we don't pass a @param bOverSize or false, the return value + * is > 0 for undersized Frames, or 0 otherwise. * If @param bOverSize == true, we can also get a negative return value, * if the SectionFrm is not completely filled, which happens often for * e.g. SectionFrms with Follows. + * + * If necessary the undersized-flag is corrected. * We need this in the FormatWidthCols to "deflate" columns there. */ - long Undersize( bool bOverSize = false ); + SwTwips Undersize(bool bOverSize = false); + SwTwips Undersize() const; /// Adapt size to surroundings void _CheckClipping( bool bGrow, bool bMaximize ); diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx index 34cd281dce49..0820e38daef6 100644 --- a/sw/source/core/layout/calcmove.cxx +++ b/sw/source/core/layout/calcmove.cxx @@ -636,27 +636,37 @@ static void lcl_CheckObjects( SwSortedObjs* pSortedObjs, const SwFrm* pFrm, long rBot = std::max( rBot, nMax ); } -//TODO: This should really be const, but Undersize modifies the flag. -size_t SwPageFrm::GetContentHeight() +size_t SwPageFrm::GetContentHeight(const long nTop, const long nBottom) const { + OSL_ENSURE(!(FindBodyCont() && FindBodyCont()->Lower() && FindBodyCont()->Lower()->IsColumnFrm()), + "SwPageFrm::GetContentHeight(): No support for columns."); + // In pages without columns, the content defines the size. - long nBot = Frm().Top(); - SwFrm *pFrm = Lower(); + long nBot = Frm().Top() + nTop; + const SwFrm *pFrm = Lower(); while (pFrm) { long nTmp = 0; - SwFrm *pCnt = static_cast<SwLayoutFrm*>(pFrm)->ContainsAny(); + const SwFrm *pCnt = static_cast<const SwLayoutFrm*>(pFrm)->ContainsAny(); while (pCnt && (pCnt->GetUpper() == pFrm || - static_cast<SwLayoutFrm*>(pFrm)->IsAnLower(pCnt))) + static_cast<const SwLayoutFrm*>(pFrm)->IsAnLower(pCnt))) { nTmp += pCnt->Frm().Height(); if (pCnt->IsTextFrm() && - static_cast<SwTextFrm*>(pCnt)->IsUndersized()) - nTmp += static_cast<SwTextFrm*>(pCnt)->GetParHeight() - - pCnt->Prt().Height(); - else if (pCnt->IsSctFrm() && - static_cast<SwSectionFrm*>(pCnt)->IsUndersized()) - nTmp += static_cast<SwSectionFrm*>(pCnt)->Undersize(); + static_cast<const SwTextFrm*>(pCnt)->IsUndersized()) + { + // This TextFrm would like to be a bit bigger. + nTmp += static_cast<const SwTextFrm*>(pCnt)->GetParHeight() + - pCnt->Prt().Height(); + } + else if (pCnt->IsSctFrm()) + { + // Grow if undersized, but don't shrink if oversized. + const auto delta = static_cast<const SwSectionFrm*>(pCnt)->Undersize(); + if (delta > 0) + nTmp += delta; + } + pCnt = pCnt->FindNext(); } // OD 29.10.2002 #97265# - consider invalid body frame properties @@ -685,7 +695,7 @@ size_t SwPageFrm::GetContentHeight() lcl_CheckObjects(pSortedObjs, pFrm, nBot); pFrm = pFrm->GetNext(); } - + nBot += nBottom; // And the page anchored ones if (pSortedObjs) lcl_CheckObjects(pSortedObjs, this, nBot); @@ -721,23 +731,25 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) } else { - if ( !pAccess ) + if (!pAccess) { pAccess = new SwBorderAttrAccess( SwFrm::GetCache(), this ); pAttrs = pAccess->Get(); } assert(pAttrs); - // In BrowseView, we use fixed settings + SwViewShell *pSh = getRootFrm()->GetCurrShell(); - if ( pSh && pSh->GetViewOptions()->getBrowseMode() ) + if (pSh && pSh->GetViewOptions()->getBrowseMode()) { + // In BrowseView, we use fixed settings const Size aBorder = pRenderContext->PixelToLogic( pSh->GetBrowseBorder() ); const long nTop = pAttrs->CalcTopLine() + aBorder.Height(); const long nBottom = pAttrs->CalcBottomLine()+ aBorder.Height(); long nWidth = GetUpper() ? static_cast<SwRootFrm*>(GetUpper())->GetBrowseWidth() : 0; - if ( nWidth < pSh->GetBrowseWidth() ) - nWidth = pSh->GetBrowseWidth(); + const auto nDefWidth = pSh->GetBrowseWidth(); + if (nWidth < nDefWidth) + nWidth = nDefWidth; nWidth += + 2 * aBorder.Width(); nWidth = std::max( nWidth, 2L * aBorder.Width() + 4L*MM50 ); @@ -752,56 +764,8 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) else { // In pages without columns, the content defines the size. - long nBot = Frm().Top() + nTop; - SwFrm *pFrm = Lower(); - while ( pFrm ) - { - long nTmp = 0; - SwFrm *pCnt = static_cast<SwLayoutFrm*>(pFrm)->ContainsAny(); - while ( pCnt && (pCnt->GetUpper() == pFrm || - static_cast<SwLayoutFrm*>(pFrm)->IsAnLower( pCnt ))) - { - nTmp += pCnt->Frm().Height(); - if( pCnt->IsTextFrm() && - static_cast<SwTextFrm*>(pCnt)->IsUndersized() ) - nTmp += static_cast<SwTextFrm*>(pCnt)->GetParHeight() - - pCnt->Prt().Height(); - else if( pCnt->IsSctFrm() && - static_cast<SwSectionFrm*>(pCnt)->IsUndersized() ) - nTmp += static_cast<SwSectionFrm*>(pCnt)->Undersize(); - pCnt = pCnt->FindNext(); - } - // OD 29.10.2002 #97265# - consider invalid body frame properties - if ( pFrm->IsBodyFrm() && - ( !pFrm->GetValidSizeFlag() || - !pFrm->GetValidPrtAreaFlag() ) && - ( pFrm->Frm().Height() < pFrm->Prt().Height() ) - ) - { - nTmp = std::min( nTmp, pFrm->Frm().Height() ); - } - else - { - // OD 30.10.2002 #97265# - assert invalid lower property - OSL_ENSURE( !(pFrm->Frm().Height() < pFrm->Prt().Height()), - "SwPageFrm::MakeAll(): Lower with frame height < printing height" ); - nTmp += pFrm->Frm().Height() - pFrm->Prt().Height(); - } - if ( !pFrm->IsBodyFrm() ) - nTmp = std::min( nTmp, pFrm->Frm().Height() ); - nBot += nTmp; - // Here we check whether paragraph anchored objects - // protrude outside the Body/FootnoteCont. - if( pSortedObjs && !pFrm->IsHeaderFrm() && - !pFrm->IsFooterFrm() ) - lcl_CheckObjects( pSortedObjs, pFrm, nBot ); - pFrm = pFrm->GetNext(); - } - nBot += nBottom; - // And the page anchored ones - if ( pSortedObjs ) - lcl_CheckObjects( pSortedObjs, this, nBot ); - nBot -= Frm().Top(); + long nBot = GetContentHeight(nTop, nBottom); + // #i35143# - If second page frame // exists, the first page doesn't have to fulfill the // visible area. @@ -819,10 +783,11 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) + pAttrs->CalcRightLine() + aBorder.Width() ) ); Prt().Height( Frm().Height() - (nTop + nBottom) ); mbValidSize = mbValidPrtArea = true; + continue; } else if (pSh && pSh->GetViewOptions()->IsWhitespaceHidden()) { - auto height = Frm().Height(); + long height = 0; SwLayoutFrm *pBody = FindBodyCont(); if ( pBody && pBody->Lower() && pBody->Lower()->IsColumnFrm() ) { @@ -831,7 +796,8 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) } else { - height = GetContentHeight(); + // No need for borders. + height = GetContentHeight(0, 0); } if (height > 0) @@ -841,24 +807,19 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) Prt().Height(height); mbValidSize = mbValidPrtArea = true; + continue; } - else - { - // Fallback to default formatting. - // This is especially relevant when - // loading a doc with Hide Whitespace - // is enabled--frame heights are zero. - Frm().SSize(pAttrs->GetSize()); - Format(pRenderContext, pAttrs); - } - } - else - { // Set FixSize. For pages, this is not done from Upper, but from - // the attribute. - //FIXME: This resets the size when (mbValidSize && !mbValidPrtArea). - Frm().SSize( pAttrs->GetSize() ); - Format( pRenderContext, pAttrs ); + + // Fallback to default formatting. Especially relevant + // when loading a doc when Hide Whitespace is enabled. + // Heights are zero initially. } + + // Set FixSize. For pages, this is not done from Upper, but from + // the attribute. + //FIXME: This resets the size when (mbValidSize && !mbValidPrtArea). + Frm().SSize( pAttrs->GetSize() ); + Format( pRenderContext, pAttrs ); } } } //while ( !mbValidPos || !mbValidSize || !mbValidPrtArea ) @@ -1171,8 +1132,8 @@ void SwContentFrm::MakeAll(vcl::RenderContext* /*pRenderContext*/) bool bMovedBwd = false; // as long as bMovedFwd is false, the Frm may flow backwards (until // it has been moved forward once) - bool bMovedFwd = false; - sal_Bool bFormatted = sal_False; // For the widow/orphan rules, we encourage the + bool bMovedFwd = false; + sal_Bool bFormatted = sal_False; // For the widow/orphan rules, we encourage the // last ContentFrm of a chain to format. This only // needs to happen once. Every time the Frm is // moved, the flag will have to be reset. diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx index bef77ba097e2..250d6e1a97f6 100644 --- a/sw/source/core/layout/sectfrm.cxx +++ b/sw/source/core/layout/sectfrm.cxx @@ -2491,21 +2491,18 @@ void SwSectionFrm::InvalidateFootnotePos() } } -/** Returns the value that the section would like to be - * greater if it has undersized TextFrms in it, - * otherwise Null. - * If necessary the undersized-flag is corrected. - */ -long SwSectionFrm::Undersize( bool bOverSize ) +SwTwips SwSectionFrm::Undersize() const { - m_bUndersized = false; - SWRECTFN( this ) - long nRet = InnerHeight() - (Prt().*fnRect->fnGetHeight)(); - if( nRet > 0 ) - m_bUndersized = true; - else if( !bOverSize ) - nRet = 0; - return nRet; + SWRECTFN(this); + return InnerHeight() - (Prt().*fnRect->fnGetHeight)(); +} + +SwTwips SwSectionFrm::Undersize(bool bOverSize) +{ + SWRECTFN(this); + const auto nRet = InnerHeight() - (Prt().*fnRect->fnGetHeight)(); + m_bUndersized = (nRet > 0); + return (nRet <= 0 && !bOverSize) ? 0 : nRet; } void SwSectionFrm::CalcFootnoteContent() diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx index 616fa263afcd..9eed78ee7727 100644 --- a/sw/source/core/layout/wsfrm.cxx +++ b/sw/source/core/layout/wsfrm.cxx @@ -2938,7 +2938,7 @@ void SwLayoutFrm::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorder const sal_uInt16 nRight = (sal_uInt16)pAttrs->CalcRight(this); const sal_uInt16 nLower = pAttrs->CalcBottom(); - bool bVert = IsVertical() && !IsPageFrm(); + const bool bVert = IsVertical() && !IsPageFrm(); SwRectFn fnRect = bVert ? ( IsVertLR() ? fnRectVertL2R : fnRectVert ) : fnRectHori; if ( !mbValidPrtArea ) { |