sw/source/core/layout/fly.cxx     |  233 ++++++++++++++++++--------------------
 sw/source/core/layout/sectfrm.cxx |  228 ++++++++++++++++++-------------------
 2 files changed, 230 insertions(+), 231 deletions(-)

New commits:
commit bc473907dbd5ca1048243d13b7cbe00d74a3d157
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Aug 24 00:34:44 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Aug 24 08:06:56 2024 +0200

    Flatten SwSectionFrame::Grow_
    
    Change-Id: Ia83785525cbb49a02a10b6c248fe2060bc6407d9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172339
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/core/layout/sectfrm.cxx 
b/sw/source/core/layout/sectfrm.cxx
index 4dc31c4256fd..2fc5ac4f6afa 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -2256,137 +2256,139 @@ SwTwips SwSectionFrame::Grow_( SwTwips nDist, bool 
bTst )
         return 0;
     }
 
-    if ( !IsColLocked() && !HasFixSize() )
+    if (IsColLocked() || HasFixSize())
     {
-        SwRectFnSet aRectFnSet(this);
-        tools::Long nFrameHeight = aRectFnSet.GetHeight(getFrameArea());
-        if( nFrameHeight > 0 && nDist > (LONG_MAX - nFrameHeight) )
-            nDist = LONG_MAX - nFrameHeight;
+        return 0;
+    }
 
-        if ( nDist <= 0 )
-            return 0;
+    SwRectFnSet aRectFnSet(this);
+    tools::Long nFrameHeight = aRectFnSet.GetHeight(getFrameArea());
+    if( nFrameHeight > 0 && nDist > (LONG_MAX - nFrameHeight) )
+        nDist = LONG_MAX - nFrameHeight;
+
+    if ( nDist <= 0 )
+        return 0;
 
-        bool bInCalcContent = GetUpper() && IsInFly() && 
FindFlyFrame()->IsLocked();
-        // OD 2004-03-15 #116561# - allow grow in online layout
-        bool bGrow = !Lower() || !Lower()->IsColumnFrame() || 
!Lower()->GetNext();
-        if (!bGrow)
+    bool bInCalcContent = GetUpper() && IsInFly() && 
FindFlyFrame()->IsLocked();
+    // OD 2004-03-15 #116561# - allow grow in online layout
+    bool bGrow = !Lower() || !Lower()->IsColumnFrame() || !Lower()->GetNext();
+    if (!bGrow)
+    {
+        SwSection* pSection = GetSection();
+        bGrow = pSection && 
pSection->GetFormat()->GetBalancedColumns().GetValue();
+    }
+    if( !bGrow )
+    {
+         const SwViewShell *pSh = getRootFrame()->GetCurrShell();
+         bGrow = pSh && pSh->GetViewOptions()->getBrowseMode();
+    }
+    if (!bGrow)
+    {
+        if (!bTst)
         {
-            SwSection* pSection = GetSection();
-            bGrow = pSection && 
pSection->GetFormat()->GetBalancedColumns().GetValue();
+            if (bInCalcContent)
+                InvalidateSize_();
+            else
+                InvalidateSize();
         }
-        if( !bGrow )
+        return 0;
+    }
+    SwTwips nGrow;
+    if( IsInFootnote() )
+        nGrow = 0;
+    else
+    {
+        nGrow = lcl_DeadLine( this );
+        nGrow = aRectFnSet.YDiff( nGrow, aRectFnSet.GetBottom(getFrameArea()) 
);
+    }
+    SwTwips nSpace = nGrow;
+    if( !bInCalcContent && nGrow < nDist && GetUpper() )
+        nGrow = o3tl::saturating_add(
+            nGrow, GetUpper()->Grow( LONG_MAX, true ));
+
+    if( nGrow > nDist )
+        nGrow = nDist;
+    if( nGrow <= 0 )
+    {
+        nGrow = 0;
+        if (!bTst)
         {
-             const SwViewShell *pSh = getRootFrame()->GetCurrShell();
-             bGrow = pSh && pSh->GetViewOptions()->getBrowseMode();
+            if( bInCalcContent )
+                InvalidateSize_();
+            else
+                InvalidateSize();
         }
-        if( bGrow )
+    }
+    else if( !bTst )
+    {
+        if( bInCalcContent )
+            InvalidateSize_();
+        else if( nSpace < nGrow &&  nDist != nSpace + GetUpper()->
+                 Grow( nGrow - nSpace ) )
+            InvalidateSize();
+        else
         {
-            SwTwips nGrow;
-            if( IsInFootnote() )
-                nGrow = 0;
-            else
-            {
-                nGrow = lcl_DeadLine( this );
-                nGrow = aRectFnSet.YDiff( nGrow, 
aRectFnSet.GetBottom(getFrameArea()) );
-            }
-            SwTwips nSpace = nGrow;
-            if( !bInCalcContent && nGrow < nDist && GetUpper() )
-                nGrow = o3tl::saturating_add(
-                    nGrow, GetUpper()->Grow( LONG_MAX, true ));
-
-            if( nGrow > nDist )
-                nGrow = nDist;
-            if( nGrow <= 0 )
+            const SvxGraphicPosition ePos =
+                GetAttrSet()->GetBackground().GetGraphicPos();
+            if ( GPOS_RT < ePos && GPOS_TILED != ePos )
             {
-                nGrow = 0;
-                if (!bTst)
-                {
-                    if( bInCalcContent )
-                        InvalidateSize_();
-                    else
-                        InvalidateSize();
-                }
+                SetCompletePaint();
+                InvalidatePage();
             }
-            else if( !bTst )
-            {
-                if( bInCalcContent )
-                    InvalidateSize_();
-                else if( nSpace < nGrow &&  nDist != nSpace + GetUpper()->
-                         Grow( nGrow - nSpace ) )
-                    InvalidateSize();
-                else
-                {
-                    const SvxGraphicPosition ePos =
-                        GetAttrSet()->GetBackground().GetGraphicPos();
-                    if ( GPOS_RT < ePos && GPOS_TILED != ePos )
-                    {
-                        SetCompletePaint();
-                        InvalidatePage();
-                    }
-                    if( GetUpper() && GetUpper()->IsHeaderFrame() )
-                        GetUpper()->InvalidateSize();
-                }
+            if( GetUpper() && GetUpper()->IsHeaderFrame() )
+                GetUpper()->InvalidateSize();
+        }
 
-                {
-                    SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
-                    aRectFnSet.AddBottom( aFrm, nGrow );
-                }
+        {
+            SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
+            aRectFnSet.AddBottom( aFrm, nGrow );
+        }
 
-                {
-                    const tools::Long nPrtHeight = 
aRectFnSet.GetHeight(getFramePrintArea()) + nGrow;
-                    SwFrameAreaDefinition::FramePrintAreaWriteAccess 
aPrt(*this);
-                    aRectFnSet.SetHeight( aPrt, nPrtHeight );
-                }
+        {
+            const tools::Long nPrtHeight = 
aRectFnSet.GetHeight(getFramePrintArea()) + nGrow;
+            SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this);
+            aRectFnSet.SetHeight( aPrt, nPrtHeight );
+        }
 
-                if( Lower() && Lower()->IsColumnFrame() && Lower()->GetNext() )
-                {
-                    SwFrame* pTmp = Lower();
-                    do
-                    {
-                        pTmp->InvalidateSize_();
-                        pTmp = pTmp->GetNext();
-                    } while ( pTmp );
-                    InvalidateSize_();
-                }
-                if( GetNext() )
-                {
-                    // Own height changed, need to invalidate the position of
-                    // next frames.
-                    SwFrame *pFrame = GetNext();
-                    while( pFrame && pFrame->IsSctFrame() && 
!static_cast<SwSectionFrame*>(pFrame)->GetSection() )
-                    {
-                        // Invalidate all in-between frames, otherwise position
-                        // calculation (which only looks back to one relative
-                        // frame) will have an incorrect result.
-                        InvalidateFramePos(pFrame, bInCalcContent);
-                        pFrame = pFrame->GetNext();
-                    }
-                    if( pFrame )
-                    {
-                        InvalidateFramePos(pFrame, bInCalcContent);
-                    }
-                }
-                // #i28701# - Due to the new object positioning
-                // the frame on the next page/column can flow backward (e.g. it
-                // was moved forward due to the positioning of its objects ).
-                // Thus, invalivate this next frame, if document compatibility
-                // option 'Consider wrapping style influence on object 
positioning' is ON.
-                else if ( 
GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION)
 )
-                {
-                    InvalidateNextPos();
-                }
+        if( Lower() && Lower()->IsColumnFrame() && Lower()->GetNext() )
+        {
+            SwFrame* pTmp = Lower();
+            do
+            {
+                pTmp->InvalidateSize_();
+                pTmp = pTmp->GetNext();
+            } while ( pTmp );
+            InvalidateSize_();
+        }
+        if( GetNext() )
+        {
+            // Own height changed, need to invalidate the position of
+            // next frames.
+            SwFrame *pFrame = GetNext();
+            while( pFrame && pFrame->IsSctFrame() && 
!static_cast<SwSectionFrame*>(pFrame)->GetSection() )
+            {
+                // Invalidate all in-between frames, otherwise position
+                // calculation (which only looks back to one relative
+                // frame) will have an incorrect result.
+                InvalidateFramePos(pFrame, bInCalcContent);
+                pFrame = pFrame->GetNext();
+            }
+            if( pFrame )
+            {
+                InvalidateFramePos(pFrame, bInCalcContent);
             }
-            return nGrow;
         }
-        if ( !bTst )
+        // #i28701# - Due to the new object positioning
+        // the frame on the next page/column can flow backward (e.g. it
+        // was moved forward due to the positioning of its objects ).
+        // Thus, invalivate this next frame, if document compatibility
+        // option 'Consider wrapping style influence on object positioning' is 
ON.
+        else if ( 
GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION)
 )
         {
-            if( bInCalcContent )
-                InvalidateSize_();
-            else
-                InvalidateSize();
+            InvalidateNextPos();
         }
     }
-    return 0;
+    return nGrow;
 }
 
 SwTwips SwSectionFrame::Shrink_( SwTwips nDist, bool bTst )
commit e725fb61365032343256b929b009cff07bbaa799
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Aug 23 23:30:26 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Aug 24 08:06:50 2024 +0200

    Flatten SwFlyFrame::Grow_
    
    Change-Id: I6fe29fef686e00dce30a024063f684f1eeaf3f64
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172338
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 5ad4d6e096b3..2036a089b83e 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -2183,140 +2183,137 @@ SwFlyAtContentFrame* 
SwFlyFrame::DynCastFlyAtContentFrame()
 
 SwTwips SwFlyFrame::Grow_( SwTwips nDist, bool bTst )
 {
-    SwRectFnSet aRectFnSet(this);
-    if ( Lower() && !IsColLocked() && !HasFixSize() )
-    {
-        SwTwips nSize = aRectFnSet.GetHeight(getFrameArea());
-        if( nSize > 0 && nDist > ( LONG_MAX - nSize ) )
-            nDist = LONG_MAX - nSize;
+    if (!Lower() || IsColLocked() || HasFixSize())
+        return 0;
 
-        if ( nDist <= 0 )
-            return 0;
+    SwRectFnSet aRectFnSet(this);
+    SwTwips nSize = aRectFnSet.GetHeight(getFrameArea());
+    if( nSize > 0 && nDist > ( LONG_MAX - nSize ) )
+        nDist = LONG_MAX - nSize;
 
-        if ( Lower()->IsColumnFrame() )
-        {   // If it's a Column Frame, the Format takes control of the
-            // resizing (due to the adjustment).
-            if ( !bTst )
-            {
-                // #i28701# - unlock position of Writer fly frame
-                UnlockPosition();
-                InvalidatePos_();
-                InvalidateSize();
-            }
-            return 0;
-        }
+    if ( nDist <= 0 )
+        return 0;
 
+    if ( Lower()->IsColumnFrame() )
+    {   // If it's a Column Frame, the Format takes control of the
+        // resizing (due to the adjustment).
         if ( !bTst )
         {
-            const SwRect aOld( GetObjRectWithSpaces() );
-            InvalidateSize_();
-            const bool bOldLock = m_bLocked;
-            Unlock();
-            if ( IsFlyFreeFrame() )
-            {
-                // #i37068# - no format of position here
-                // and prevent move in method <CheckClip(..)>.
-                // This is needed to prevent layout loop caused by nested
-                // Writer fly frames - inner Writer fly frames format its
-                // anchor, which grows/shrinks the outer Writer fly frame.
-                // Note: position will be invalidated below.
-                setFrameAreaPositionValid(true);
+            // #i28701# - unlock position of Writer fly frame
+            UnlockPosition();
+            InvalidatePos_();
+            InvalidateSize();
+        }
+        return 0;
+    }
 
-                // #i55416#
-                // Suppress format of width for autowidth frame, because the
-                // format of the width would call 
<SwTextFrame::CalcFitToContent()>
-                // for the lower frame, which initiated this grow.
-                const bool bOldFormatHeightOnly = m_bFormatHeightOnly;
-                const SwFormatFrameSize& rFrameSz = 
GetFormat()->GetFrameSize();
-                if ( rFrameSz.GetWidthSizeType() != SwFrameSize::Fixed )
-                {
-                    m_bFormatHeightOnly = true;
-                }
-                SwViewShell* pSh = getRootFrame()->GetCurrShell();
-                if (pSh)
-                {
-                    static_cast<SwFlyFreeFrame*>(this)->SetNoMoveOnCheckClip( 
true );
-                    
static_cast<SwFlyFreeFrame*>(this)->SwFlyFreeFrame::MakeAll(pSh->GetOut());
-                    static_cast<SwFlyFreeFrame*>(this)->SetNoMoveOnCheckClip( 
false );
-                }
-                // #i55416#
-                if ( rFrameSz.GetWidthSizeType() != SwFrameSize::Fixed )
-                {
-                    m_bFormatHeightOnly = bOldFormatHeightOnly;
-                }
-            }
-            else
-                MakeAll(getRootFrame()->GetCurrShell()->GetOut());
-            InvalidateSize_();
-            InvalidatePos();
-            if ( bOldLock )
-                Lock();
-            SwRect aNew(GetObjRectWithSpaces());
-            if (IsFlySplitAllowed() && aNew.Height() - aOld.Height() < nDist)
+    if (bTst)
+    {
+        // We're in test mode. Don't promise infinite growth for split flys, 
rather limit the
+        // max size to the bottom of the upper.
+        const SwFrame* pAnchor = GetAnchorFrame();
+        if (SwFrame* pAnchorChar = FindAnchorCharFrame())
+        {
+            pAnchor = pAnchorChar;
+        }
+        if (pAnchor && IsFlySplitAllowed())
+        {
+            SwTwips nDeadline = GetFlyAnchorBottom(this, *pAnchor);
+            SwTwips nTop = aRectFnSet.GetTop(getFrameArea());
+            SwTwips nBottom = nTop + aRectFnSet.GetHeight(getFrameArea());
+            // Calculate max grow and compare to the requested growth, adding 
to nDist may
+            // overflow when it's LONG_MAX.
+            SwTwips nMaxGrow = nDeadline - nBottom;
+            if (nDist > nMaxGrow)
             {
-                // We are allowed to split and the actual growth is less than 
the requested growth.
-                const SwFrame* pAnchor = GetAnchorFrame();
-                if (SwFrame* pAnchorChar = FindAnchorCharFrame())
-                {
-                    pAnchor = pAnchorChar;
-                }
-                if (pAnchor)
-                {
-                    SwTwips nDeadline = GetFlyAnchorBottom(this, *pAnchor);
-                    SwTwips nTop = aRectFnSet.GetTop(getFrameArea());
-                    SwTwips nBottom = nTop + 
aRectFnSet.GetHeight(getFrameArea());
-                    SwTwips nMaxGrow = nDeadline - nBottom;
-                    if (nDist > nMaxGrow)
-                    {
-                        // The requested growth is more than what we can 
provide, limit it.
-                        nDist = nMaxGrow;
-                    }
-                    // Grow & invalidate the size.
-                    SwTwips nRemaining = nDist - (aNew.Height() - 
aOld.Height());
-                    {
-                        SwFrameAreaDefinition::FrameAreaWriteAccess 
aFrm(*this);
-                        aRectFnSet.AddBottom(aFrm, nRemaining);
-                    }
-                    InvalidateObjRectWithSpaces();
-                    {
-                        // Margins are unchanged, so increase the print height 
similar to the frame
-                        // height.
-                        SwFrameAreaDefinition::FramePrintAreaWriteAccess 
aPrt(*this);
-                        aRectFnSet.AddBottom(aPrt, nRemaining );
-                    }
-                    aNew = GetObjRectWithSpaces();
-                }
+                nDist = nMaxGrow;
             }
-            if ( aOld != aNew )
-                ::Notify( this, FindPageFrame(), aOld );
-            return aRectFnSet.GetHeight(aNew)-aRectFnSet.GetHeight(aOld);
         }
-        else
+        return nDist;
+    }
+
+    const SwRect aOld( GetObjRectWithSpaces() );
+    InvalidateSize_();
+    const bool bOldLock = m_bLocked;
+    Unlock();
+    if ( IsFlyFreeFrame() )
+    {
+        // #i37068# - no format of position here
+        // and prevent move in method <CheckClip(..)>.
+        // This is needed to prevent layout loop caused by nested
+        // Writer fly frames - inner Writer fly frames format its
+        // anchor, which grows/shrinks the outer Writer fly frame.
+        // Note: position will be invalidated below.
+        setFrameAreaPositionValid(true);
+
+        // #i55416#
+        // Suppress format of width for autowidth frame, because the
+        // format of the width would call <SwTextFrame::CalcFitToContent()>
+        // for the lower frame, which initiated this grow.
+        const bool bOldFormatHeightOnly = m_bFormatHeightOnly;
+        const SwFormatFrameSize& rFrameSz = GetFormat()->GetFrameSize();
+        if ( rFrameSz.GetWidthSizeType() != SwFrameSize::Fixed )
         {
-            // We're in test mode. Don't promise infinite growth for split 
flys, rather limit the
-            // max size to the bottom of the upper.
-            const SwFrame* pAnchor = GetAnchorFrame();
-            if (SwFrame* pAnchorChar = FindAnchorCharFrame())
+            m_bFormatHeightOnly = true;
+        }
+        SwViewShell* pSh = getRootFrame()->GetCurrShell();
+        if (pSh)
+        {
+            static_cast<SwFlyFreeFrame*>(this)->SetNoMoveOnCheckClip( true );
+            
static_cast<SwFlyFreeFrame*>(this)->SwFlyFreeFrame::MakeAll(pSh->GetOut());
+            static_cast<SwFlyFreeFrame*>(this)->SetNoMoveOnCheckClip( false );
+        }
+        // #i55416#
+        if ( rFrameSz.GetWidthSizeType() != SwFrameSize::Fixed )
+        {
+            m_bFormatHeightOnly = bOldFormatHeightOnly;
+        }
+    }
+    else
+        MakeAll(getRootFrame()->GetCurrShell()->GetOut());
+    InvalidateSize_();
+    InvalidatePos();
+    if ( bOldLock )
+        Lock();
+    SwRect aNew(GetObjRectWithSpaces());
+    if (IsFlySplitAllowed() && aNew.Height() - aOld.Height() < nDist)
+    {
+        // We are allowed to split and the actual growth is less than the 
requested growth.
+        const SwFrame* pAnchor = GetAnchorFrame();
+        if (SwFrame* pAnchorChar = FindAnchorCharFrame())
+        {
+            pAnchor = pAnchorChar;
+        }
+        if (pAnchor)
+        {
+            SwTwips nDeadline = GetFlyAnchorBottom(this, *pAnchor);
+            SwTwips nTop = aRectFnSet.GetTop(getFrameArea());
+            SwTwips nBottom = nTop + aRectFnSet.GetHeight(getFrameArea());
+            SwTwips nMaxGrow = nDeadline - nBottom;
+            if (nDist > nMaxGrow)
             {
-                pAnchor = pAnchorChar;
+                // The requested growth is more than what we can provide, 
limit it.
+                nDist = nMaxGrow;
             }
-            if (pAnchor && IsFlySplitAllowed())
+            // Grow & invalidate the size.
+            SwTwips nRemaining = nDist - (aNew.Height() - aOld.Height());
             {
-                SwTwips nDeadline = GetFlyAnchorBottom(this, *pAnchor);
-                SwTwips nTop = aRectFnSet.GetTop(getFrameArea());
-                SwTwips nBottom = nTop + aRectFnSet.GetHeight(getFrameArea());
-                // Calculate max grow and compare to the requested growth, 
adding to nDist may
-                // overflow when it's LONG_MAX.
-                SwTwips nMaxGrow = nDeadline - nBottom;
-                if (nDist > nMaxGrow)
-                {
-                    nDist = nMaxGrow;
-                }
+                SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
+                aRectFnSet.AddBottom(aFrm, nRemaining);
             }
+            InvalidateObjRectWithSpaces();
+            {
+                // Margins are unchanged, so increase the print height similar 
to the frame
+                // height.
+                SwFrameAreaDefinition::FramePrintAreaWriteAccess aPrt(*this);
+                aRectFnSet.AddBottom(aPrt, nRemaining );
+            }
+            aNew = GetObjRectWithSpaces();
         }
-        return nDist;
     }
-    return 0;
+    if ( aOld != aNew )
+        ::Notify( this, FindPageFrame(), aOld );
+    return aRectFnSet.GetHeight(aNew)-aRectFnSet.GetHeight(aOld);
 }
 
 SwTwips SwFlyFrame::Shrink_( SwTwips nDist, bool bTst )

Reply via email to