Kaydet (Commit) 7ffb5349 authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Miklos Vajna

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/19730Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
(cherry picked from commit f05da45c)

Conflicts:
	sw/source/core/layout/calcmove.cxx

Change-Id: I73a8e920ccfa96d76cbbb002bed6a85f2e636ede
üst 98195b6d
...@@ -111,7 +111,7 @@ protected: ...@@ -111,7 +111,7 @@ protected:
virtual void SwClientNotify(const SwModify&, const SfxHint&) SAL_OVERRIDE; virtual void SwClientNotify(const SwModify&, const SfxHint&) SAL_OVERRIDE;
/// Calculate the content height of a page (without columns). /// Calculate the content height of a page (without columns).
size_t GetContentHeight(); size_t GetContentHeight(const long nTop, const long nBottom) const;
public: public:
DECL_FIXEDMEMPOOL_NEWDEL(SwPageFrm) DECL_FIXEDMEMPOOL_NEWDEL(SwPageFrm)
......
...@@ -118,15 +118,20 @@ public: ...@@ -118,15 +118,20 @@ public:
bool CalcMinDiff( SwTwips& rMinDiff ) const; bool CalcMinDiff( SwTwips& rMinDiff ) const;
/** /**
* If we don't pass a @param bOverSize or false, the return value is > 0 for * Returns the size delta that the section would like to be
* undersized Frames, or 0 * 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 @param bOverSize == true, we can also get a negative return value,
* if the SectionFrm is not completely filled, which happens often for * if the SectionFrm is not completely filled, which happens often for
* e.g. SectionFrms with Follows. * e.g. SectionFrms with Follows.
*
* If necessary the undersized-flag is corrected.
* We need this in the FormatWidthCols to "deflate" columns there. * 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 /// Adapt size to surroundings
void _CheckClipping( bool bGrow, bool bMaximize ); void _CheckClipping( bool bGrow, bool bMaximize );
......
...@@ -636,27 +636,37 @@ static void lcl_CheckObjects( SwSortedObjs* pSortedObjs, const SwFrm* pFrm, long ...@@ -636,27 +636,37 @@ static void lcl_CheckObjects( SwSortedObjs* pSortedObjs, const SwFrm* pFrm, long
rBot = std::max( rBot, nMax ); rBot = std::max( rBot, nMax );
} }
//TODO: This should really be const, but Undersize modifies the flag. size_t SwPageFrm::GetContentHeight(const long nTop, const long nBottom) const
size_t SwPageFrm::GetContentHeight()
{ {
OSL_ENSURE(!(FindBodyCont() && FindBodyCont()->Lower() && FindBodyCont()->Lower()->IsColumnFrm()),
"SwPageFrm::GetContentHeight(): No support for columns.");
// In pages without columns, the content defines the size. // In pages without columns, the content defines the size.
long nBot = Frm().Top(); long nBot = Frm().Top() + nTop;
SwFrm *pFrm = Lower(); const SwFrm *pFrm = Lower();
while (pFrm) while (pFrm)
{ {
long nTmp = 0; long nTmp = 0;
SwFrm *pCnt = static_cast<SwLayoutFrm*>(pFrm)->ContainsAny(); const SwFrm *pCnt = static_cast<const SwLayoutFrm*>(pFrm)->ContainsAny();
while (pCnt && (pCnt->GetUpper() == pFrm || while (pCnt && (pCnt->GetUpper() == pFrm ||
static_cast<SwLayoutFrm*>(pFrm)->IsAnLower(pCnt))) static_cast<const SwLayoutFrm*>(pFrm)->IsAnLower(pCnt)))
{ {
nTmp += pCnt->Frm().Height(); nTmp += pCnt->Frm().Height();
if (pCnt->IsTextFrm() && if (pCnt->IsTextFrm() &&
static_cast<SwTextFrm*>(pCnt)->IsUndersized()) static_cast<const SwTextFrm*>(pCnt)->IsUndersized())
nTmp += static_cast<SwTextFrm*>(pCnt)->GetParHeight() {
- pCnt->Prt().Height(); // This TextFrm would like to be a bit bigger.
else if (pCnt->IsSctFrm() && nTmp += static_cast<const SwTextFrm*>(pCnt)->GetParHeight()
static_cast<SwSectionFrm*>(pCnt)->IsUndersized()) - pCnt->Prt().Height();
nTmp += static_cast<SwSectionFrm*>(pCnt)->Undersize(); }
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(); pCnt = pCnt->FindNext();
} }
// OD 29.10.2002 #97265# - consider invalid body frame properties // OD 29.10.2002 #97265# - consider invalid body frame properties
...@@ -685,7 +695,7 @@ size_t SwPageFrm::GetContentHeight() ...@@ -685,7 +695,7 @@ size_t SwPageFrm::GetContentHeight()
lcl_CheckObjects(pSortedObjs, pFrm, nBot); lcl_CheckObjects(pSortedObjs, pFrm, nBot);
pFrm = pFrm->GetNext(); pFrm = pFrm->GetNext();
} }
nBot += nBottom;
// And the page anchored ones // And the page anchored ones
if (pSortedObjs) if (pSortedObjs)
lcl_CheckObjects(pSortedObjs, this, nBot); lcl_CheckObjects(pSortedObjs, this, nBot);
...@@ -721,23 +731,25 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) ...@@ -721,23 +731,25 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
} }
else else
{ {
if ( !pAccess ) if (!pAccess)
{ {
pAccess = new SwBorderAttrAccess( SwFrm::GetCache(), this ); pAccess = new SwBorderAttrAccess( SwFrm::GetCache(), this );
pAttrs = pAccess->Get(); pAttrs = pAccess->Get();
} }
assert(pAttrs); assert(pAttrs);
// In BrowseView, we use fixed settings
SwViewShell *pSh = getRootFrm()->GetCurrShell(); 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 Size aBorder = pRenderContext->PixelToLogic( pSh->GetBrowseBorder() );
const long nTop = pAttrs->CalcTopLine() + aBorder.Height(); const long nTop = pAttrs->CalcTopLine() + aBorder.Height();
const long nBottom = pAttrs->CalcBottomLine()+ aBorder.Height(); const long nBottom = pAttrs->CalcBottomLine()+ aBorder.Height();
long nWidth = GetUpper() ? static_cast<SwRootFrm*>(GetUpper())->GetBrowseWidth() : 0; long nWidth = GetUpper() ? static_cast<SwRootFrm*>(GetUpper())->GetBrowseWidth() : 0;
if ( nWidth < pSh->GetBrowseWidth() ) const auto nDefWidth = pSh->GetBrowseWidth();
nWidth = pSh->GetBrowseWidth(); if (nWidth < nDefWidth)
nWidth = nDefWidth;
nWidth += + 2 * aBorder.Width(); nWidth += + 2 * aBorder.Width();
nWidth = std::max( nWidth, 2L * aBorder.Width() + 4L*MM50 ); nWidth = std::max( nWidth, 2L * aBorder.Width() + 4L*MM50 );
...@@ -752,56 +764,8 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) ...@@ -752,56 +764,8 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
else else
{ {
// In pages without columns, the content defines the size. // In pages without columns, the content defines the size.
long nBot = Frm().Top() + nTop; long nBot = GetContentHeight(nTop, nBottom);
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();
// #i35143# - If second page frame // #i35143# - If second page frame
// exists, the first page doesn't have to fulfill the // exists, the first page doesn't have to fulfill the
// visible area. // visible area.
...@@ -819,10 +783,11 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) ...@@ -819,10 +783,11 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
+ pAttrs->CalcRightLine() + aBorder.Width() ) ); + pAttrs->CalcRightLine() + aBorder.Width() ) );
Prt().Height( Frm().Height() - (nTop + nBottom) ); Prt().Height( Frm().Height() - (nTop + nBottom) );
mbValidSize = mbValidPrtArea = true; mbValidSize = mbValidPrtArea = true;
continue;
} }
else if (pSh && pSh->GetViewOptions()->IsWhitespaceHidden()) else if (pSh && pSh->GetViewOptions()->IsWhitespaceHidden())
{ {
auto height = Frm().Height(); long height = 0;
SwLayoutFrm *pBody = FindBodyCont(); SwLayoutFrm *pBody = FindBodyCont();
if ( pBody && pBody->Lower() && pBody->Lower()->IsColumnFrm() ) if ( pBody && pBody->Lower() && pBody->Lower()->IsColumnFrm() )
{ {
...@@ -831,7 +796,8 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) ...@@ -831,7 +796,8 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
} }
else else
{ {
height = GetContentHeight(); // No need for borders.
height = GetContentHeight(0, 0);
} }
if (height > 0) if (height > 0)
...@@ -841,24 +807,19 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext) ...@@ -841,24 +807,19 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
Prt().Height(height); Prt().Height(height);
mbValidSize = mbValidPrtArea = true; mbValidSize = mbValidPrtArea = true;
continue;
} }
else
{ // Fallback to default formatting. Especially relevant
// Fallback to default formatting. // when loading a doc when Hide Whitespace is enabled.
// This is especially relevant when // Heights are zero initially.
// 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 );
} }
// 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 ) } //while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
...@@ -1171,8 +1132,8 @@ void SwContentFrm::MakeAll(vcl::RenderContext* /*pRenderContext*/) ...@@ -1171,8 +1132,8 @@ void SwContentFrm::MakeAll(vcl::RenderContext* /*pRenderContext*/)
bool bMovedBwd = false; bool bMovedBwd = false;
// as long as bMovedFwd is false, the Frm may flow backwards (until // as long as bMovedFwd is false, the Frm may flow backwards (until
// it has been moved forward once) // it has been moved forward once)
bool bMovedFwd = false; bool bMovedFwd = false;
sal_Bool bFormatted = sal_False; // For the widow/orphan rules, we encourage the sal_Bool bFormatted = sal_False; // For the widow/orphan rules, we encourage the
// last ContentFrm of a chain to format. This only // last ContentFrm of a chain to format. This only
// needs to happen once. Every time the Frm is // needs to happen once. Every time the Frm is
// moved, the flag will have to be reset. // moved, the flag will have to be reset.
......
...@@ -2491,21 +2491,18 @@ void SwSectionFrm::InvalidateFootnotePos() ...@@ -2491,21 +2491,18 @@ void SwSectionFrm::InvalidateFootnotePos()
} }
} }
/** Returns the value that the section would like to be SwTwips SwSectionFrm::Undersize() const
* greater if it has undersized TextFrms in it,
* otherwise Null.
* If necessary the undersized-flag is corrected.
*/
long SwSectionFrm::Undersize( bool bOverSize )
{ {
m_bUndersized = false; SWRECTFN(this);
SWRECTFN( this ) return InnerHeight() - (Prt().*fnRect->fnGetHeight)();
long nRet = InnerHeight() - (Prt().*fnRect->fnGetHeight)(); }
if( nRet > 0 )
m_bUndersized = true; SwTwips SwSectionFrm::Undersize(bool bOverSize)
else if( !bOverSize ) {
nRet = 0; SWRECTFN(this);
return nRet; const auto nRet = InnerHeight() - (Prt().*fnRect->fnGetHeight)();
m_bUndersized = (nRet > 0);
return (nRet <= 0 && !bOverSize) ? 0 : nRet;
} }
void SwSectionFrm::CalcFootnoteContent() void SwSectionFrm::CalcFootnoteContent()
......
...@@ -2938,7 +2938,7 @@ void SwLayoutFrm::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorder ...@@ -2938,7 +2938,7 @@ void SwLayoutFrm::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorder
const sal_uInt16 nRight = (sal_uInt16)pAttrs->CalcRight(this); const sal_uInt16 nRight = (sal_uInt16)pAttrs->CalcRight(this);
const sal_uInt16 nLower = pAttrs->CalcBottom(); const sal_uInt16 nLower = pAttrs->CalcBottom();
bool bVert = IsVertical() && !IsPageFrm(); const bool bVert = IsVertical() && !IsPageFrm();
SwRectFn fnRect = bVert ? ( IsVertLR() ? fnRectVertL2R : fnRectVert ) : fnRectHori; SwRectFn fnRect = bVert ? ( IsVertLR() ? fnRectVertL2R : fnRectVert ) : fnRectHori;
if ( !mbValidPrtArea ) if ( !mbValidPrtArea )
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment