[Libreoffice-commits] core.git: sw/source

Ashod Nakashian ashodnakashian at yahoo.com
Thu Nov 12 04:27:19 PST 2015


 sw/source/core/inc/pagefrm.hxx     |    2 
 sw/source/core/inc/sectfrm.hxx     |   11 ++
 sw/source/core/layout/calcmove.cxx |  137 +++++++++++++------------------------
 sw/source/core/layout/sectfrm.cxx  |   25 ++----
 sw/source/core/layout/wsfrm.cxx    |    2 
 5 files changed, 70 insertions(+), 107 deletions(-)

New commits:
commit f05da45c9c69e66cd5f26fc02c950ccf0c0b946d
Author: Ashod Nakashian <ashodnakashian at yahoo.com>
Date:   Sun Nov 1 16:33:36 2015 -0500

    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.
    
    Change-Id: I73a8e920ccfa96d76cbbb002bed6a85f2e636ede
    Reviewed-on: https://gerrit.libreoffice.org/19730
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index 0d08e00..3e60e02 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&) 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 3abdd37..9330196 100644
--- a/sw/source/core/inc/sectfrm.hxx
+++ b/sw/source/core/inc/sectfrm.hxx
@@ -116,15 +116,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 d0d7c15..2ac5a3f 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -638,27 +638,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
@@ -687,7 +697,7 @@ size_t SwPageFrm::GetContentHeight()
             lcl_CheckObjects(m_pSortedObjs, pFrm, nBot);
         pFrm = pFrm->GetNext();
     }
-
+    nBot += nBottom;
     // And the page anchored ones
     if (m_pSortedObjs)
         lcl_CheckObjects(m_pSortedObjs, this, nBot);
@@ -723,23 +733,25 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
             }
             else
             {
-                if ( !pAccess )
+                if (!pAccess)
                 {
                     pAccess = o3tl::make_unique<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 );
@@ -754,56 +766,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( m_pSortedObjs && !pFrm->IsHeaderFrm() &&
-                                !pFrm->IsFooterFrm() )
-                                lcl_CheckObjects( m_pSortedObjs, pFrm, nBot );
-                            pFrm = pFrm->GetNext();
-                        }
-                        nBot += nBottom;
-                        // And the page anchored ones
-                        if ( m_pSortedObjs )
-                            lcl_CheckObjects( m_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.
@@ -821,10 +785,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() )
                     {
@@ -833,7 +798,8 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
                     }
                     else
                     {
-                        height = GetContentHeight();
+                        // No need for borders.
+                        height = GetContentHeight(0, 0);
                     }
 
                     if (height > 0)
@@ -843,24 +809,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 )
@@ -1172,8 +1133,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 f32e2b2..1b3e9dd 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -2492,21 +2492,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 446ac29..ac3d1c8 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 )
     {


More information about the Libreoffice-commits mailing list