LCOV - code coverage report
Current view: top level - sw/source/core/layout - calcmove.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 749 920 81.4 %
Date: 2014-04-11 Functions: 20 21 95.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "rootfrm.hxx"
      21             : #include "pagefrm.hxx"
      22             : #include "viewopt.hxx"
      23             : #include "frmtool.hxx"
      24             : #include "txtftn.hxx"
      25             : #include "fmtftn.hxx"
      26             : #include <editeng/ulspitem.hxx>
      27             : #include <editeng/keepitem.hxx>
      28             : #include <svx/sdtaitm.hxx>
      29             : 
      30             : #include <fmtfsize.hxx>
      31             : #include <fmtanchr.hxx>
      32             : #include <fmtclbl.hxx>
      33             : 
      34             : #include "tabfrm.hxx"
      35             : #include "ftnfrm.hxx"
      36             : #include "txtfrm.hxx"
      37             : #include "sectfrm.hxx"
      38             : #include "dbg_lay.hxx"
      39             : 
      40             : // #i28701#
      41             : #include <sortedobjs.hxx>
      42             : #include <layouter.hxx>
      43             : // #i36347#
      44             : #include <flyfrms.hxx>
      45             : 
      46             : // Move methods
      47             : 
      48             : /// Return value tells whether the Frm should be moved.
      49        4304 : bool SwCntntFrm::ShouldBwdMoved( SwLayoutFrm *pNewUpper, bool, bool & )
      50             : {
      51        4304 :     if ( (SwFlowFrm::IsMoveBwdJump() || !IsPrevObjMove()))
      52             :     {
      53             :         // Floating back a frm uses a bit of time unfortunately.
      54             :         // The most common case is the following: The Frm wants to float to
      55             :         // somewhere where the FixSize is the same that the Frm itself has already.
      56             :         // In that case it's pretty easy to check if the Frm has enough space
      57             :         // for its VarSize. If this is NOT the case, we already know that
      58             :         // we don't need to move.
      59             :         // The Frm checks itself whether it has enough space - respecting the fact
      60             :         // that it could possibly split itself if needed.
      61             :         // If, however, the FixSize differs from the Frm or Flys are involved
      62             :         // (either in the old or the new position), checking is pointless,
      63             :         // and we have to move the Frm just to see what happens - if there's
      64             :         // some space available to do it, that is.
      65             : 
      66             :         // The FixSize of the containers of Cntnts is always the width.
      67             : 
      68             :         // If we moved more than one sheet back (for example jumping over empty
      69             :         // pages), we have to move either way. Otherwise, if the Frm doesn't fit
      70             :         // into the page, empty pages wouldn't be respected anymore.
      71        4304 :         sal_uInt8 nMoveAnyway = 0;
      72        4304 :         SwPageFrm * const pNewPage = pNewUpper->FindPageFrm();
      73        4304 :         SwPageFrm *pOldPage = FindPageFrm();
      74             : 
      75        4304 :         if ( SwFlowFrm::IsMoveBwdJump() )
      76        2043 :             return true;
      77             : 
      78        2261 :         if( IsInFtn() && IsInSct() )
      79             :         {
      80           0 :             SwFtnFrm* pFtn = FindFtnFrm();
      81           0 :             SwSectionFrm* pMySect = pFtn->FindSctFrm();
      82           0 :             if( pMySect && pMySect->IsFtnLock() )
      83             :             {
      84           0 :                 SwSectionFrm *pSect = pNewUpper->FindSctFrm();
      85           0 :                 while( pSect && pSect->IsInFtn() )
      86           0 :                     pSect = pSect->GetUpper()->FindSctFrm();
      87             :                 OSL_ENSURE( pSect, "Escaping footnote" );
      88           0 :                 if( pSect != pMySect )
      89           0 :                     return false;
      90             :             }
      91             :         }
      92        2261 :         SWRECTFN( this )
      93        2261 :         SWRECTFNX( pNewUpper )
      94        4522 :         if( std::abs( (pNewUpper->Prt().*fnRectX->fnGetWidth)() -
      95        2261 :                  (GetUpper()->Prt().*fnRect->fnGetWidth)() ) > 1 ) {
      96             :             // In this case, only a _WouldFit with test move is possible
      97         117 :             nMoveAnyway = 2;
      98             :         }
      99             : 
     100             :         // OD 2004-05-26 #i25904# - do *not* move backward,
     101             :         // if <nMoveAnyway> equals 3 and no space is left in new upper.
     102        2261 :         nMoveAnyway |= BwdMoveNecessary( pOldPage, Frm() );
     103             :         {
     104        2261 :             const IDocumentSettingAccess* pIDSA = pNewPage->GetFmt()->getIDocumentSettingAccess();
     105        2261 :             SwTwips nSpace = 0;
     106        2261 :             SwRect aRect( pNewUpper->Prt() );
     107        2261 :             aRect.Pos() += pNewUpper->Frm().Pos();
     108        2261 :             const SwFrm *pPrevFrm = pNewUpper->Lower();
     109       29086 :             while ( pPrevFrm )
     110             :             {
     111       24564 :                 SwTwips nNewTop = (pPrevFrm->Frm().*fnRectX->fnGetBottom)();
     112             :                 // OD 2004-03-01 #106629#:
     113             :                 // consider lower spacing of last frame in a table cell
     114             :                 {
     115             :                     // check, if last frame is inside table and if it includes
     116             :                     // its lower spacing.
     117       24568 :                     if ( !pPrevFrm->GetNext() && pPrevFrm->IsInTab() &&
     118           4 :                          pIDSA->get(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS) )
     119             :                     {
     120           4 :                         const SwFrm* pLastFrm = pPrevFrm;
     121             :                         // if last frame is a section, take its last content
     122           4 :                         if ( pPrevFrm->IsSctFrm() )
     123             :                         {
     124           0 :                             pLastFrm = static_cast<const SwSectionFrm*>(pPrevFrm)->FindLastCntnt();
     125           0 :                             if ( pLastFrm &&
     126           0 :                                  pLastFrm->FindTabFrm() != pPrevFrm->FindTabFrm() )
     127             :                             {
     128           0 :                                 pLastFrm = pLastFrm->FindTabFrm();
     129             :                             }
     130             :                         }
     131             : 
     132           4 :                         if ( pLastFrm )
     133             :                         {
     134           4 :                             SwBorderAttrAccess aAccess( SwFrm::GetCache(), pLastFrm );
     135           4 :                             const SwBorderAttrs& rAttrs = *aAccess.Get();
     136           4 :                             nNewTop -= rAttrs.GetULSpace().GetLower();
     137             :                         }
     138             :                     }
     139             :                 }
     140       24564 :                 (aRect.*fnRectX->fnSetTop)( nNewTop );
     141             : 
     142       24564 :                 pPrevFrm = pPrevFrm->GetNext();
     143             :             }
     144             : 
     145        2261 :             nMoveAnyway |= BwdMoveNecessary( pNewPage, aRect);
     146             : 
     147             :             //determine space left in new upper frame
     148        2261 :             nSpace = (aRect.*fnRectX->fnGetHeight)();
     149        2261 :             const SwViewShell *pSh = pNewUpper->getRootFrm()->GetCurrShell();
     150        6783 :             if ( IsInFtn() ||
     151        4522 :                  (pSh && pSh->GetViewOptions()->getBrowseMode()) ||
     152        6892 :                  pNewUpper->IsCellFrm() ||
     153        2846 :                  ( pNewUpper->IsInSct() && ( pNewUpper->IsSctFrm() ||
     154         476 :                    ( pNewUpper->IsColBodyFrm() &&
     155         406 :                      !pNewUpper->GetUpper()->GetPrev() &&
     156         168 :                      !pNewUpper->GetUpper()->GetNext() ) ) ) )
     157         109 :                 nSpace += pNewUpper->Grow( LONG_MAX, sal_True );
     158             : 
     159        2261 :             if ( nMoveAnyway < 3 )
     160             :             {
     161        2261 :                 if ( nSpace )
     162             :                 {
     163             :                     // Do not notify footnotes which are stuck to the paragraph:
     164             :                     // This would require extremely confusing code, taking into
     165             :                     // account the widths
     166             :                     // and Flys, that in turn influence the footnotes, ...
     167             : 
     168             :                     // _WouldFit can only be used if the width is the same and
     169             :                     // ONLY self-anchored Flys are present.
     170             : 
     171             :                     // _WouldFit can also be used if ONLY Flys anchored
     172             :                     // somewhere else are present.
     173             :                     // In this case, the width doesn't even matter,
     174             :                     // because we're running a TestFormat in the new upper.
     175             :                     const sal_uInt8 nBwdMoveNecessaryResult =
     176        2224 :                                             BwdMoveNecessary( pNewPage, aRect);
     177        2224 :                     const bool bObjsInNewUpper( nBwdMoveNecessaryResult == 2 ||
     178        2224 :                                                 nBwdMoveNecessaryResult == 3 );
     179             : 
     180             :                     return _WouldFit( nSpace, pNewUpper, nMoveAnyway == 2,
     181        2224 :                                       bObjsInNewUpper );
     182             :                 }
     183             :                 // It's impossible for _WouldFit to return a usable result if
     184             :                 // we have a fresh multi-column section - so we really have to
     185             :                 // float back unless there is no space.
     186         111 :                 return pNewUpper->IsInSct() && pNewUpper->IsColBodyFrm() &&
     187          74 :                        !(pNewUpper->Prt().*fnRectX->fnGetWidth)() &&
     188           0 :                        ( pNewUpper->GetUpper()->GetPrev() ||
     189          37 :                          pNewUpper->GetUpper()->GetNext() );
     190             :             }
     191             : 
     192             :             // OD 2004-05-26 #i25904# - check for space left in new upper
     193           0 :             return nSpace != 0;
     194             :         }
     195             :     }
     196           0 :     return false;
     197             : }
     198             : 
     199             : // Calc methods
     200             : 
     201             : // Two little friendships form a secret society
     202       12392 : inline void PrepareLock( SwFlowFrm *pTab )
     203             : {
     204       12392 :     pTab->LockJoin();
     205       12392 : }
     206        2768 : inline void PrepareUnlock( SwFlowFrm *pTab )
     207             : {
     208        2768 :     pTab->UnlockJoin();
     209             : 
     210        2768 : }
     211             : 
     212             : // hopefully, one day this function simply will return 'false'
     213      177293 : static bool lcl_IsCalcUpperAllowed( const SwFrm& rFrm )
     214             : {
     215      348847 :     return !rFrm.GetUpper()->IsSctFrm() &&
     216      338658 :            !rFrm.GetUpper()->IsFooterFrm() &&
     217             :            // #i23129#, #i36347# - no format of upper Writer fly frame
     218      331988 :            !rFrm.GetUpper()->IsFlyFrm() &&
     219      694323 :            !( rFrm.GetUpper()->IsTabFrm() && rFrm.GetUpper()->GetUpper()->IsInTab() ) &&
     220      364647 :            !( rFrm.IsTabFrm() && rFrm.GetUpper()->IsInTab() );
     221             : }
     222             : 
     223             : /** Prepares the Frame for "formatting" (MakeAll()).
     224             :  *
     225             :  * This method serves to save stack space: To calculate the position of the Frm
     226             :  * we have to make sure that the positions of Upper and Prev respectively are
     227             :  * valid. This may require a recursive call (a loop would be quite expensive,
     228             :  * as it's not required very often).
     229             :  *
     230             :  * Every call of MakeAll requires around 500 bytes on the stack - you easily
     231             :  * see where this leads to. This method requires only a little bit of stack
     232             :  * space, so the recursive call should not be a problem here.
     233             :  *
     234             :  * Another advantage is that one nice day, this method and with it the
     235             :  * formatting of predecessors could be avoided. Then it could probably be
     236             :  * possible to jump "quickly" to the document's end.
     237             :  *
     238             :  * @see MakeAll()
     239             :  */
     240       99936 : void SwFrm::PrepareMake()
     241             : {
     242       99936 :     StackHack aHack;
     243       99936 :     if ( GetUpper() )
     244             :     {
     245       88913 :         if ( lcl_IsCalcUpperAllowed( *this ) )
     246       81899 :             GetUpper()->Calc();
     247             :         OSL_ENSURE( GetUpper(), ":-( Layout unstable (Upper gone)." );
     248       88913 :         if ( !GetUpper() )
     249           0 :             return;
     250             : 
     251       88913 :         const bool bCnt = IsCntntFrm();
     252       88913 :         const bool bTab = IsTabFrm();
     253       88913 :         sal_Bool bNoSect = IsInSct();
     254       88913 :         sal_Bool bOldTabLock = sal_False, bFoll = sal_False;
     255       88913 :         SwFlowFrm* pThis = bCnt ? (SwCntntFrm*)this : NULL;
     256             : 
     257       88913 :         if ( bTab )
     258             :         {
     259       12392 :             pThis = (SwTabFrm*)this;
     260       12392 :             bOldTabLock = ((SwTabFrm*)this)->IsJoinLocked();
     261       12392 :             ::PrepareLock( (SwTabFrm*)this );
     262       12392 :             bFoll = pThis->IsFollow();
     263             :         }
     264       76521 :         else if( IsSctFrm() )
     265             :         {
     266         442 :             pThis = (SwSectionFrm*)this;
     267         442 :             bFoll = pThis->IsFollow();
     268         442 :             bNoSect = sal_False;
     269             :         }
     270       77322 :         else if ( bCnt && sal_True == (bFoll = pThis->IsFollow()) &&
     271        1243 :              GetPrev() )
     272             :         {
     273             :             //Do not follow the chain when we need only one instance
     274         376 :             const SwTxtFrm* pMaster = ((SwCntntFrm*)this)->FindMaster();
     275         376 :             if ( pMaster && pMaster->IsLocked() )
     276             :             {
     277         367 :                 MakeAll();
     278         367 :                 return;
     279             :             }
     280             :         }
     281             : 
     282             :         // #i44049# - no format of previous frame, if current
     283             :         // frame is a table frame and its previous frame wants to keep with it.
     284      100938 :         const bool bFormatPrev = !bTab ||
     285       90605 :                                  !GetPrev() ||
     286       90605 :                                  !GetPrev()->GetAttrSet()->GetKeep().GetValue();
     287       88546 :         if ( bFormatPrev )
     288             :         {
     289       88380 :             SwFrm *pFrm = GetUpper()->Lower();
     290      537066 :             while ( pFrm != this )
     291             :             {
     292             :                 OSL_ENSURE( pFrm, ":-( Layout unstable (this not found)." );
     293      360640 :                 if ( !pFrm )
     294           0 :                     return; //Oioioioi ...
     295             : 
     296      360640 :                 if ( !pFrm->IsValid() )
     297             :                 {
     298             :                     // A small interference that hopefully improves on the stability:
     299             :                     // If I'm Follow AND neighbor of a Frm before me, it would delete
     300             :                     // me when formatting. This as you can see could easily become a
     301             :                     // confusing situation that we want to avoid.
     302        5893 :                     if ( bFoll && pFrm->IsFlowFrm() &&
     303         334 :                          (SwFlowFrm::CastFlowFrm(pFrm))->IsAnFollow( pThis ) )
     304         334 :                         break;
     305             : 
     306        5225 :                     pFrm->MakeAll();
     307        5225 :                     if( IsSctFrm() && !((SwSectionFrm*)this)->GetSection() )
     308           0 :                         break;
     309             :                 }
     310             :                 // With CntntFrms, the chain may be broken while walking through
     311             :                 // it. Therefore we have to figure out the follower in a bit more
     312             :                 // complicated way. However, I'll HAVE to get back to myself
     313             :                 // sometime again.
     314      360306 :                 pFrm = pFrm->FindNext();
     315             : 
     316             :                 // If we started out in a SectionFrm, it might have happened that
     317             :                 // we landed in a Section Follow via the MakeAll calls.
     318             :                 // FindNext only gives us the SectionFrm, not it's content - we
     319             :                 // won't find ourselves anymore!
     320      360306 :                 if( bNoSect && pFrm && pFrm->IsSctFrm() )
     321             :                 {
     322           1 :                     SwFrm* pCnt = ((SwSectionFrm*)pFrm)->ContainsAny();
     323           1 :                     if( pCnt )
     324           1 :                         pFrm = pCnt;
     325             :                 }
     326             :             }
     327             :             OSL_ENSURE( GetUpper(), "Layout unstable (Upper gone II)." );
     328       88380 :             if ( !GetUpper() )
     329           0 :                 return;
     330             : 
     331       88380 :             if ( lcl_IsCalcUpperAllowed( *this ) )
     332       81371 :                 GetUpper()->Calc();
     333             : 
     334             :             OSL_ENSURE( GetUpper(), "Layout unstable (Upper gone III)." );
     335             :         }
     336             : 
     337       88546 :         if ( bTab && !bOldTabLock )
     338        2768 :             ::PrepareUnlock( (SwTabFrm*)this );
     339             :     }
     340       99569 :     MakeAll();
     341             : }
     342             : 
     343       22889 : void SwFrm::OptPrepareMake()
     344             : {
     345             :     // #i23129#, #i36347# - no format of upper Writer fly frame
     346       44724 :     if ( GetUpper() && !GetUpper()->IsFooterFrm() &&
     347       21835 :          !GetUpper()->IsFlyFrm() )
     348             :     {
     349       19394 :         GetUpper()->Calc();
     350             :         OSL_ENSURE( GetUpper(), ":-( Layout unstable (Upper gone)." );
     351       19394 :         if ( !GetUpper() )
     352       22889 :             return;
     353             :     }
     354       22889 :     if ( GetPrev() && !GetPrev()->IsValid() )
     355         162 :         PrepareMake();
     356             :     else
     357             :     {
     358       22727 :         StackHack aHack;
     359       22727 :         MakeAll();
     360             :     }
     361             : }
     362             : 
     363          64 : void SwFrm::PrepareCrsr()
     364             : {
     365          64 :     StackHack aHack;
     366          64 :     if( GetUpper() && !GetUpper()->IsSctFrm() )
     367             :     {
     368          48 :         GetUpper()->PrepareCrsr();
     369          48 :         GetUpper()->Calc();
     370             : 
     371             :         OSL_ENSURE( GetUpper(), ":-( Layout unstable (Upper gone)." );
     372          48 :         if ( !GetUpper() )
     373           0 :             return;
     374             : 
     375          48 :         const bool bCnt = IsCntntFrm();
     376          48 :         const bool bTab = IsTabFrm();
     377          48 :         sal_Bool bNoSect = IsInSct();
     378             : 
     379          48 :         sal_Bool bOldTabLock = sal_False, bFoll;
     380          48 :         SwFlowFrm* pThis = bCnt ? (SwCntntFrm*)this : NULL;
     381             : 
     382          48 :         if ( bTab )
     383             :         {
     384           0 :             bOldTabLock = ((SwTabFrm*)this)->IsJoinLocked();
     385           0 :             ::PrepareLock( (SwTabFrm*)this );
     386           0 :             pThis = (SwTabFrm*)this;
     387             :         }
     388          48 :         else if( IsSctFrm() )
     389             :         {
     390           0 :             pThis = (SwSectionFrm*)this;
     391           0 :             bNoSect = sal_False;
     392             :         }
     393          48 :         bFoll = pThis && pThis->IsFollow();
     394             : 
     395          48 :         SwFrm *pFrm = GetUpper()->Lower();
     396         125 :         while ( pFrm != this )
     397             :         {
     398             :             OSL_ENSURE( pFrm, ":-( Layout unstable (this not found)." );
     399          29 :             if ( !pFrm )
     400           0 :                 return; //Oioioioi ...
     401             : 
     402          29 :             if ( !pFrm->IsValid() )
     403             :             {
     404             :                 // A small interference that hopefully improves on the stability:
     405             :                 // If I'm Follow AND neighbor of a Frm before me, it would delete
     406             :                 // me when formatting. This as you can see could easily become a
     407             :                 // confusing situation that we want to avoid.
     408           0 :                 if ( bFoll && pFrm->IsFlowFrm() &&
     409           0 :                      (SwFlowFrm::CastFlowFrm(pFrm))->IsAnFollow( pThis ) )
     410           0 :                     break;
     411             : 
     412           0 :                 pFrm->MakeAll();
     413             :             }
     414             :             // With CntntFrms, the chain may be broken while walking through
     415             :             // it. Therefore we have to figure out the follower in a bit more
     416             :             // complicated way. However, I'll HAVE to get back to myself
     417             :             // sometime again.
     418          29 :             pFrm = pFrm->FindNext();
     419          29 :             if( bNoSect && pFrm && pFrm->IsSctFrm() )
     420             :             {
     421           0 :                 SwFrm* pCnt = ((SwSectionFrm*)pFrm)->ContainsAny();
     422           0 :                 if( pCnt )
     423           0 :                     pFrm = pCnt;
     424             :             }
     425             :         }
     426             :         OSL_ENSURE( GetUpper(), "Layout unstable (Upper gone II)." );
     427          48 :         if ( !GetUpper() )
     428           0 :             return;
     429             : 
     430          48 :         GetUpper()->Calc();
     431             : 
     432             :         OSL_ENSURE( GetUpper(), "Layout unstable (Upper gone III)." );
     433             : 
     434          48 :         if ( bTab && !bOldTabLock )
     435           0 :             ::PrepareUnlock( (SwTabFrm*)this );
     436             :     }
     437          64 :     Calc();
     438             : }
     439             : 
     440             : // Here we return GetPrev(); however we will ignore empty SectionFrms
     441      376086 : static SwFrm* lcl_Prev( SwFrm* pFrm, bool bSectPrv = true )
     442             : {
     443      376086 :     SwFrm* pRet = pFrm->GetPrev();
     444      606211 :     if( !pRet && pFrm->GetUpper() && pFrm->GetUpper()->IsSctFrm() &&
     445      378274 :         bSectPrv && !pFrm->IsColumnFrm() )
     446        1298 :         pRet = pFrm->GetUpper()->GetPrev();
     447      754267 :     while( pRet && pRet->IsSctFrm() &&
     448        1516 :            !((SwSectionFrm*)pRet)->GetSection() )
     449         579 :         pRet = pRet->GetPrev();
     450      376086 :     return pRet;
     451             : }
     452             : 
     453         402 : static SwFrm* lcl_NotHiddenPrev( SwFrm* pFrm )
     454             : {
     455         402 :     SwFrm *pRet = pFrm;
     456         402 :     do
     457             :     {
     458         402 :         pRet = lcl_Prev( pRet );
     459         402 :     } while ( pRet && pRet->IsTxtFrm() && ((SwTxtFrm*)pRet)->IsHiddenNow() );
     460         402 :     return pRet;
     461             : }
     462             : 
     463      102675 : void SwFrm::MakePos()
     464             : {
     465      102675 :     if ( !mbValidPos )
     466             :     {
     467      101444 :         mbValidPos = sal_True;
     468      101444 :         bool bUseUpper = false;
     469      101444 :         SwFrm* pPrv = lcl_Prev( this );
     470      199292 :         if ( pPrv &&
     471       68440 :              ( !pPrv->IsCntntFrm() ||
     472       19516 :                ( ((SwCntntFrm*)pPrv)->GetFollow() != this ) )
     473             :            )
     474             :         {
     475      146772 :             if ( !StackHack::IsLocked() &&
     476       98059 :                  ( !IsInSct() || IsSctFrm() ) &&
     477      136524 :                  !pPrv->IsSctFrm() &&
     478       43688 :                  !pPrv->GetAttrSet()->GetKeep().GetValue()
     479             :                )
     480             :             {
     481       42499 :                 pPrv->Calc();   // This may cause Prev to vanish!
     482             :             }
     483        6425 :             else if ( pPrv->Frm().Top() == 0 )
     484             :             {
     485           1 :                 bUseUpper = true;
     486             :             }
     487             :         }
     488             : 
     489      101444 :         pPrv = lcl_Prev( this, false );
     490      101444 :         sal_uInt16 nMyType = GetType();
     491      101444 :         SWRECTFN( ( IsCellFrm() && GetUpper() ? GetUpper() : this  ) )
     492      101444 :         if ( !bUseUpper && pPrv )
     493             :         {
     494       48737 :             maFrm.Pos( pPrv->Frm().Pos() );
     495       48737 :             if( FRM_NEIGHBOUR & nMyType )
     496             :             {
     497       14035 :                 sal_Bool bR2L = IsRightToLeft();
     498       14035 :                 if( bR2L )
     499           0 :                     (maFrm.*fnRect->fnSetPosX)( (maFrm.*fnRect->fnGetLeft)() -
     500           0 :                                                (maFrm.*fnRect->fnGetWidth)() );
     501             :                 else
     502       14035 :                     (maFrm.*fnRect->fnSetPosX)( (maFrm.*fnRect->fnGetLeft)() +
     503       28070 :                                           (pPrv->Frm().*fnRect->fnGetWidth)() );
     504             : 
     505             :                 // cells may now leave their uppers
     506       14035 :                 if( bVert && FRM_CELL & nMyType && !mbReverse )
     507           0 :                     maFrm.Pos().setX(maFrm.Pos().getX() - maFrm.Width() + pPrv->Frm().Width());
     508             :             }
     509       34702 :             else if( bVert && FRM_NOTE_VERT & nMyType )
     510             :             {
     511           0 :                 if( mbReverse )
     512           0 :                     maFrm.Pos().setX(maFrm.Pos().getX() + pPrv->Frm().Width());
     513             :                 else
     514             :                     //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     515             :                 {
     516           0 :                     if ( bVertL2R )
     517           0 :                            maFrm.Pos().setX(maFrm.Pos().getX() + pPrv->Frm().Width());
     518             :                     else
     519           0 :                            maFrm.Pos().setX(maFrm.Pos().getX() - maFrm.Width());
     520             :                   }
     521             :             }
     522             :             else
     523       34702 :                 maFrm.Pos().setY(maFrm.Pos().getY() + pPrv->Frm().Height());
     524             :         }
     525       52707 :         else if ( GetUpper() )
     526             :         {
     527             :             // OD 15.10.2002 #103517# - add safeguard for <SwFooterFrm::Calc()>
     528             :             // If parent frame is a footer frame and its <ColLocked()>, then
     529             :             // do *not* calculate it.
     530             :             // NOTE: Footer frame is <ColLocked()> during its
     531             :             //     <FormatSize(..)>, which is called from <Format(..)>, which
     532             :             //     is called from <MakeAll()>, which is called from <Calc()>.
     533             :             // #i56850#
     534             :             // - no format of upper Writer fly frame, which is anchored
     535             :             //   at-paragraph or at-character.
     536      155323 :             if ( !GetUpper()->IsTabFrm() &&
     537      102832 :                  !( IsTabFrm() && GetUpper()->IsInTab() ) &&
     538       98143 :                  !GetUpper()->IsSctFrm() &&
     539      242223 :                  !dynamic_cast<SwFlyAtCntFrm*>(GetUpper()) &&
     540       46970 :                  !( GetUpper()->IsFooterFrm() &&
     541        2002 :                     GetUpper()->IsColLocked() )
     542             :                )
     543             :             {
     544       45656 :                 GetUpper()->Calc();
     545             :             }
     546       52707 :             pPrv = lcl_Prev( this, false );
     547       52707 :             if ( !bUseUpper && pPrv )
     548             :             {
     549           0 :                 maFrm.Pos( pPrv->Frm().Pos() );
     550           0 :                 if( FRM_NEIGHBOUR & nMyType )
     551             :                 {
     552           0 :                     sal_Bool bR2L = IsRightToLeft();
     553           0 :                     if( bR2L )
     554           0 :                         (maFrm.*fnRect->fnSetPosX)( (maFrm.*fnRect->fnGetLeft)() -
     555           0 :                                                  (maFrm.*fnRect->fnGetWidth)() );
     556             :                     else
     557           0 :                         (maFrm.*fnRect->fnSetPosX)( (maFrm.*fnRect->fnGetLeft)() +
     558           0 :                                           (pPrv->Frm().*fnRect->fnGetWidth)() );
     559             : 
     560             :                     // cells may now leave their uppers
     561           0 :                     if( bVert && FRM_CELL & nMyType && !mbReverse )
     562           0 :                         maFrm.Pos().setX(maFrm.Pos().getX() - maFrm.Width() + pPrv->Frm().Width());
     563             :                 }
     564           0 :                 else if( bVert && FRM_NOTE_VERT & nMyType )
     565             :                 {
     566           0 :                     if( mbReverse )
     567           0 :                         maFrm.Pos().setX(maFrm.Pos().getX() + pPrv->Frm().Width());
     568             :                     else
     569           0 :                         maFrm.Pos().setX(maFrm.Pos().getX() - maFrm.Width());
     570             :                 }
     571             :                 else
     572           0 :                     maFrm.Pos().setY(maFrm.Pos().getY() + pPrv->Frm().Height());
     573             :             }
     574             :             else
     575             :             {
     576       52707 :                 maFrm.Pos( GetUpper()->Frm().Pos() );
     577       52707 :                 if( GetUpper()->IsFlyFrm() )
     578        2645 :                     maFrm.Pos() += static_cast<SwFlyFrm*>(GetUpper())->ContentPos();
     579             :                 else
     580       50062 :                     maFrm.Pos() += GetUpper()->Prt().Pos();
     581             : 
     582       52707 :                 if( FRM_NEIGHBOUR & nMyType && IsRightToLeft() )
     583             :                 {
     584           0 :                     if( bVert )
     585           0 :                         maFrm.Pos().setY(maFrm.Pos().getY() + GetUpper()->Prt().Height()
     586           0 :                                           - maFrm.Height());
     587             :                     else
     588           0 :                         maFrm.Pos().setX(maFrm.Pos().getX() + GetUpper()->Prt().Width()
     589           0 :                                           - maFrm.Width());
     590             :                 }
     591             :                 //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     592       52707 :                 else if( bVert && !bVertL2R && FRM_NOTE_VERT & nMyType && !mbReverse )
     593           1 :                     maFrm.Pos().setX(maFrm.Pos().getX() - maFrm.Width() + GetUpper()->Prt().Width());
     594             :             }
     595             :         }
     596             :         else
     597             :         {
     598           0 :             maFrm.Pos().setX(0);
     599           0 :             maFrm.Pos().setY(0);
     600             :         }
     601             :         //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     602      101444 :         if( IsBodyFrm() && bVert && !bVertL2R && !mbReverse && GetUpper() )
     603           0 :             maFrm.Pos().setX(maFrm.Pos().getX() + GetUpper()->Prt().Width() - maFrm.Width());
     604      101444 :         mbValidPos = sal_True;
     605             :     }
     606      102675 : }
     607             : 
     608             : // #i28701# - new type <SwSortedObjs>
     609           2 : static void lcl_CheckObjects( SwSortedObjs* pSortedObjs, SwFrm* pFrm, long& rBot )
     610             : {
     611             :     // And then there can be paragraph anchored frames that sit below their paragraph.
     612           2 :     long nMax = 0;
     613           4 :     for ( sal_uInt16 i = 0; i < pSortedObjs->Count(); ++i )
     614             :     {
     615             :         // #i28701# - consider changed type of <SwSortedObjs>
     616             :         // entries.
     617           2 :         SwAnchoredObject* pObj = (*pSortedObjs)[i];
     618           2 :         long nTmp = 0;
     619           2 :         if ( pObj->ISA(SwFlyFrm) )
     620             :         {
     621           2 :             SwFlyFrm *pFly = static_cast<SwFlyFrm*>(pObj);
     622           2 :             if( pFly->Frm().Top() != FAR_AWAY &&
     623           0 :                 ( pFrm->IsPageFrm() ? pFly->IsFlyLayFrm() :
     624           0 :                   ( pFly->IsFlyAtCntFrm() &&
     625           0 :                     ( pFrm->IsBodyFrm() ? pFly->GetAnchorFrm()->IsInDocBody() :
     626           0 :                                           pFly->GetAnchorFrm()->IsInFtn() ) ) ) )
     627             :             {
     628           0 :                 nTmp = pFly->Frm().Bottom();
     629             :             }
     630             :         }
     631             :         else
     632           0 :             nTmp = pObj->GetObjRect().Bottom();
     633           2 :         nMax = std::max( nTmp, nMax );
     634             :     }
     635           2 :     ++nMax; // Lower edge vs. height!
     636           2 :     rBot = std::max( rBot, nMax );
     637           2 : }
     638             : 
     639        5319 : void SwPageFrm::MakeAll()
     640             : {
     641             :     PROTOCOL_ENTER( this, PROT_MAKEALL, 0, 0 )
     642             : 
     643        5319 :     const SwRect aOldRect( Frm() );     // Adjust root size
     644        5319 :     const SwLayNotify aNotify( this );  // takes care of the notification in the dtor
     645        5319 :     SwBorderAttrAccess *pAccess = 0;
     646        5319 :     const SwBorderAttrs*pAttrs = 0;
     647             : 
     648       15957 :     while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
     649             :     {
     650        5319 :         if ( !mbValidPos )
     651             :         {
     652        5225 :             mbValidPos = sal_True; // positioning of the pages is taken care of by the root frame
     653             :         }
     654             : 
     655        5319 :         if ( !mbValidSize || !mbValidPrtArea )
     656             :         {
     657        4525 :             if ( IsEmptyPage() )
     658             :             {
     659           7 :                 Frm().Width( 0 );  Prt().Width( 0 );
     660           7 :                 Frm().Height( 0 ); Prt().Height( 0 );
     661           7 :                 Prt().Left( 0 );   Prt().Top( 0 );
     662           7 :                 mbValidSize = mbValidPrtArea = sal_True;
     663             :             }
     664             :             else
     665             :             {
     666        4518 :                 if ( !pAccess )
     667             :                 {
     668        4518 :                     pAccess = new SwBorderAttrAccess( SwFrm::GetCache(), this );
     669        4518 :                     pAttrs = pAccess->Get();
     670             :                 }
     671             :                 // In BrowseView, we use fixed settings
     672        4518 :                 SwViewShell *pSh = getRootFrm()->GetCurrShell();
     673        4518 :                 if ( pSh && pSh->GetViewOptions()->getBrowseMode() )
     674             :                 {
     675          99 :                     const Size aBorder = pSh->GetOut()->PixelToLogic( pSh->GetBrowseBorder() );
     676          99 :                     const long nTop    = pAttrs->CalcTopLine()   + aBorder.Height();
     677          99 :                     const long nBottom = pAttrs->CalcBottomLine()+ aBorder.Height();
     678             : 
     679          99 :                     long nWidth = GetUpper() ? ((SwRootFrm*)GetUpper())->GetBrowseWidth() : 0;
     680          99 :                     if ( nWidth < pSh->GetBrowseWidth() )
     681          93 :                         nWidth = pSh->GetBrowseWidth();
     682          99 :                     nWidth += + 2 * aBorder.Width();
     683             : 
     684          99 :                     nWidth = std::max( nWidth, 2L * aBorder.Width() + 4L*MM50 );
     685          99 :                     Frm().Width( nWidth );
     686             : 
     687          99 :                     SwLayoutFrm *pBody = FindBodyCont();
     688          99 :                     if ( pBody && pBody->Lower() && pBody->Lower()->IsColumnFrm() )
     689             :                     {
     690             :                         // Columns have a fixed height
     691           0 :                         Frm().Height( pAttrs->GetSize().Height() );
     692             :                     }
     693             :                     else
     694             :                     {
     695             :                         // In pages without columns, the content defines the size.
     696          99 :                         long nBot = Frm().Top() + nTop;
     697          99 :                         SwFrm *pFrm = Lower();
     698         294 :                         while ( pFrm )
     699             :                         {
     700          96 :                             long nTmp = 0;
     701          96 :                             SwFrm *pCnt = ((SwLayoutFrm*)pFrm)->ContainsAny();
     702         298 :                             while ( pCnt && (pCnt->GetUpper() == pFrm ||
     703           0 :                                              ((SwLayoutFrm*)pFrm)->IsAnLower( pCnt )))
     704             :                             {
     705         106 :                                 nTmp += pCnt->Frm().Height();
     706         198 :                                 if( pCnt->IsTxtFrm() &&
     707          92 :                                     ((SwTxtFrm*)pCnt)->IsUndersized() )
     708           0 :                                     nTmp += ((SwTxtFrm*)pCnt)->GetParHeight()
     709           0 :                                             - pCnt->Prt().Height();
     710         120 :                                 else if( pCnt->IsSctFrm() &&
     711          14 :                                          ((SwSectionFrm*)pCnt)->IsUndersized() )
     712           0 :                                     nTmp += ((SwSectionFrm*)pCnt)->Undersize();
     713         106 :                                 pCnt = pCnt->FindNext();
     714             :                             }
     715             :                             // OD 29.10.2002 #97265# - consider invalid body frame properties
     716         288 :                             if ( pFrm->IsBodyFrm() &&
     717         192 :                                  ( !pFrm->GetValidSizeFlag() ||
     718         192 :                                    !pFrm->GetValidPrtAreaFlag() ) &&
     719           0 :                                  ( pFrm->Frm().Height() < pFrm->Prt().Height() )
     720             :                                )
     721             :                             {
     722           0 :                                 nTmp = std::min( nTmp, pFrm->Frm().Height() );
     723             :                             }
     724             :                             else
     725             :                             {
     726             :                                 // OD 30.10.2002 #97265# - assert invalid lower property
     727             :                                 OSL_ENSURE( !(pFrm->Frm().Height() < pFrm->Prt().Height()),
     728             :                                         "SwPageFrm::MakeAll(): Lower with frame height < printing height" );
     729          96 :                                 nTmp += pFrm->Frm().Height() - pFrm->Prt().Height();
     730             :                             }
     731          96 :                             if ( !pFrm->IsBodyFrm() )
     732           0 :                                 nTmp = std::min( nTmp, pFrm->Frm().Height() );
     733          96 :                             nBot += nTmp;
     734             :                             // Here we check whether paragraph anchored objects
     735             :                             // protrude outside the Body/FtnCont.
     736          97 :                             if( pSortedObjs && !pFrm->IsHeaderFrm() &&
     737           1 :                                 !pFrm->IsFooterFrm() )
     738           1 :                                 lcl_CheckObjects( pSortedObjs, pFrm, nBot );
     739          96 :                             pFrm = pFrm->GetNext();
     740             :                         }
     741          99 :                         nBot += nBottom;
     742             :                         // And the page anchored ones
     743          99 :                         if ( pSortedObjs )
     744           1 :                             lcl_CheckObjects( pSortedObjs, this, nBot );
     745          99 :                         nBot -= Frm().Top();
     746             :                         // #i35143# - If second page frame
     747             :                         // exists, the first page doesn't have to fulfill the
     748             :                         // visible area.
     749          99 :                         if ( !GetPrev() && !GetNext() )
     750             :                         {
     751          99 :                             nBot = std::max( nBot, pSh->VisArea().Height() );
     752             :                         }
     753             :                         // #i35143# - Assure, that the page
     754             :                         // doesn't exceed the defined browse height.
     755          99 :                         Frm().Height( std::min( nBot, BROWSE_HEIGHT ) );
     756             :                     }
     757          99 :                     Prt().Left ( pAttrs->CalcLeftLine() + aBorder.Width() );
     758          99 :                     Prt().Top  ( nTop );
     759         198 :                     Prt().Width( Frm().Width() - ( Prt().Left()
     760         198 :                         + pAttrs->CalcRightLine() + aBorder.Width() ) );
     761          99 :                     Prt().Height( Frm().Height() - (nTop + nBottom) );
     762          99 :                     mbValidSize = mbValidPrtArea = sal_True;
     763             :                 }
     764             :                 else
     765             :                 {   // Set FixSize. For pages, this is not done from Upper, but from
     766             :                     // the attribute.
     767        4419 :                     Frm().SSize( pAttrs->GetSize() );
     768        4419 :                     Format( pAttrs );
     769             :                 }
     770             :             }
     771             :         }
     772             :     } //while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
     773        5319 :     delete pAccess;
     774             : 
     775        5319 :     if ( Frm() != aOldRect && GetUpper() )
     776          13 :         static_cast<SwRootFrm*>(GetUpper())->CheckViewLayout( 0, 0 );
     777             : 
     778             :     OSL_ENSURE( !GetUpper() || GetUpper()->Prt().Width() >= maFrm.Width(),
     779        5319 :         "Upper (Root) must be wide enough to contain the widest page");
     780        5319 : }
     781             : 
     782       52656 : void SwLayoutFrm::MakeAll()
     783             : {
     784             :     PROTOCOL_ENTER( this, PROT_MAKEALL, 0, 0 )
     785             : 
     786             :     // takes care of the notification in the dtor
     787       52656 :     const SwLayNotify aNotify( this );
     788       52656 :     bool bVert = IsVertical();
     789             :     //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     790       52656 :     SwRectFn fnRect = ( IsNeighbourFrm() == bVert )? fnRectHori : ( IsVertLR() ? fnRectVertL2R : fnRectVert );
     791             : 
     792       52656 :     SwBorderAttrAccess *pAccess = 0;
     793       52656 :     const SwBorderAttrs*pAttrs = 0;
     794             : 
     795      160365 :     while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
     796             :     {
     797       55053 :         if ( !mbValidPos )
     798       49871 :             MakePos();
     799             : 
     800       55053 :         if ( GetUpper() )
     801             :         {
     802             :             // NEW TABLES
     803       55053 :             if ( IsLeaveUpperAllowed() )
     804             :             {
     805          58 :                 if ( !mbValidSize )
     806          35 :                     mbValidPrtArea = sal_False;
     807             :             }
     808             :             else
     809             :             {
     810       54995 :                 if ( !mbValidSize )
     811             :                 {
     812             :                     // Set FixSize; VarSize is set by Format() after calculating the PrtArea
     813       32117 :                     mbValidPrtArea = sal_False;
     814             : 
     815       32117 :                     SwTwips nPrtWidth = (GetUpper()->Prt().*fnRect->fnGetWidth)();
     816       32117 :                     if( bVert && ( IsBodyFrm() || IsFtnContFrm() ) )
     817             :                     {
     818           0 :                         SwFrm* pNxt = GetPrev();
     819           0 :                         while( pNxt && !pNxt->IsHeaderFrm() )
     820           0 :                             pNxt = pNxt->GetPrev();
     821           0 :                         if( pNxt )
     822           0 :                             nPrtWidth -= pNxt->Frm().Height();
     823           0 :                         pNxt = GetNext();
     824           0 :                         while( pNxt && !pNxt->IsFooterFrm() )
     825           0 :                             pNxt = pNxt->GetNext();
     826           0 :                         if( pNxt )
     827           0 :                             nPrtWidth -= pNxt->Frm().Height();
     828             :                     }
     829             : 
     830       32117 :                     const long nDiff = nPrtWidth - (Frm().*fnRect->fnGetWidth)();
     831             : 
     832       32117 :                     if( IsNeighbourFrm() && IsRightToLeft() )
     833           0 :                         (Frm().*fnRect->fnSubLeft)( nDiff );
     834             :                     else
     835       32117 :                         (Frm().*fnRect->fnAddRight)( nDiff );
     836             :                 }
     837             :                 else
     838             :                 {
     839             :                     // Don't leave your upper
     840       22878 :                     const SwTwips nDeadLine = (GetUpper()->*fnRect->fnGetPrtBottom)();
     841       22878 :                     if( (Frm().*fnRect->fnOverStep)( nDeadLine ) )
     842           0 :                         mbValidSize = sal_False;
     843             :                 }
     844             :             }
     845             :         }
     846       55053 :         if ( !mbValidSize || !mbValidPrtArea )
     847             :         {
     848       42312 :             if ( !pAccess )
     849             :             {
     850       39983 :                 pAccess = new SwBorderAttrAccess( SwFrm::GetCache(), this );
     851       39983 :                 pAttrs  = pAccess->Get();
     852             :             }
     853       42312 :             Format( pAttrs );
     854             :         }
     855             :     } //while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
     856       52656 :     delete pAccess;
     857       52656 : }
     858             : 
     859      111512 : bool SwTxtNode::IsCollapse() const
     860             : {
     861      223024 :     if (GetDoc()->get( IDocumentSettingAccess::COLLAPSE_EMPTY_CELL_PARA )
     862      111512 :         &&  GetTxt().isEmpty())
     863             :     {
     864       78358 :         sal_uLong nIdx=GetIndex();
     865       78358 :         const SwEndNode *pNdBefore=GetNodes()[nIdx-1]->GetEndNode();
     866       78358 :         const SwEndNode *pNdAfter=GetNodes()[nIdx+1]->GetEndNode();
     867             : 
     868             :         // The paragraph is collapsed only if the NdAfter is the end of a cell
     869       78358 :         bool bInTable = this->FindTableNode( ) != NULL;
     870             : 
     871       78358 :         SwSortedObjs* pObjs = this->getLayoutFrm( GetDoc()->GetCurrentLayout() )->GetDrawObjs( );
     872       78358 :         sal_uInt32 nObjs = ( pObjs != NULL ) ? pObjs->Count( ) : 0;
     873             : 
     874       78358 :         return pNdBefore!=NULL && pNdAfter!=NULL && nObjs == 0 && bInTable;
     875             :     }
     876             : 
     877       33154 :     return false;
     878             : }
     879             : 
     880      112160 : bool SwFrm::IsCollapse() const
     881             : {
     882      112160 :     if (!IsTxtFrm())
     883         648 :         return false;
     884             : 
     885      111512 :     const SwTxtFrm *pTxtFrm=(SwTxtFrm*)this;
     886      111512 :     const SwTxtNode *pTxtNode=pTxtFrm->GetTxtNode();
     887      111512 :     return pTxtNode && pTxtNode->IsCollapse();
     888             : }
     889             : 
     890       59619 : sal_Bool SwCntntFrm::MakePrtArea( const SwBorderAttrs &rAttrs )
     891             : {
     892       59619 :     sal_Bool bSizeChgd = sal_False;
     893             : 
     894       59619 :     if ( !mbValidPrtArea )
     895             :     {
     896       59002 :         mbValidPrtArea = sal_True;
     897             : 
     898       59002 :         SWRECTFN( this )
     899       59002 :         const bool bTxtFrm = IsTxtFrm();
     900       59002 :         SwTwips nUpper = 0;
     901       59002 :         if ( bTxtFrm && ((SwTxtFrm*)this)->IsHiddenNow() )
     902             :         {
     903         299 :             if ( ((SwTxtFrm*)this)->HasFollow() )
     904           0 :                 ((SwTxtFrm*)this)->JoinFrm();
     905             : 
     906         299 :             if( (Prt().*fnRect->fnGetHeight)() )
     907          21 :                 ((SwTxtFrm*)this)->HideHidden();
     908         299 :             Prt().Pos().setX(0);
     909         299 :             Prt().Pos().setY(0);
     910         299 :             (Prt().*fnRect->fnSetWidth)( (Frm().*fnRect->fnGetWidth)() );
     911         299 :             (Prt().*fnRect->fnSetHeight)( 0 );
     912         299 :             nUpper = -( (Frm().*fnRect->fnGetHeight)() );
     913             :         }
     914             :         else
     915             :         {
     916             :             // Simplification: CntntFrms are always variable in height!
     917             : 
     918             :             // At the FixSize, the surrounding Frame enforces the size;
     919             :             // the borders are simply subtracted.
     920       58703 :             const long nLeft = rAttrs.CalcLeft( this );
     921       58703 :             const long nRight = ((SwBorderAttrs&)rAttrs).CalcRight( this );
     922       58703 :             (this->*fnRect->fnSetXMargins)( nLeft, nRight );
     923             : 
     924       58703 :             SwViewShell *pSh = getRootFrm()->GetCurrShell();
     925             :             SwTwips nWidthArea;
     926      171442 :             if( pSh && 0!=(nWidthArea=(pSh->VisArea().*fnRect->fnGetWidth)()) &&
     927      137202 :                 GetUpper()->IsPageBodyFrm() && // but not for BodyFrms in Columns
     928       24463 :                 pSh->GetViewOptions()->getBrowseMode() )
     929             :             {
     930             :                 // Do not protrude the edge of the visible area. The page may be
     931             :                 // wider, because there may be objects with excess width
     932             :                 // (RootFrm::ImplCalcBrowseWidth())
     933          29 :                 long nMinWidth = 0;
     934             : 
     935          29 :                 for (sal_uInt16 i = 0; GetDrawObjs() && i < GetDrawObjs()->Count();++i)
     936             :                 {
     937             :                     // #i28701# - consider changed type of
     938             :                     // <SwSortedObjs> entries
     939           0 :                     SwAnchoredObject* pObj = (*GetDrawObjs())[i];
     940           0 :                     const SwFrmFmt& rFmt = pObj->GetFrmFmt();
     941           0 :                     const sal_Bool bFly = pObj->ISA(SwFlyFrm);
     942           0 :                     if ((bFly && (FAR_AWAY == pObj->GetObjRect().Width()))
     943           0 :                         || rFmt.GetFrmSize().GetWidthPercent())
     944             :                     {
     945           0 :                         continue;
     946             :                     }
     947             : 
     948           0 :                     if ( FLY_AS_CHAR == rFmt.GetAnchor().GetAnchorId() )
     949             :                     {
     950             :                         nMinWidth = std::max( nMinWidth,
     951           0 :                                          bFly ? rFmt.GetFrmSize().GetWidth()
     952           0 :                                               : pObj->GetObjRect().Width() );
     953             :                     }
     954             :                 }
     955             : 
     956          29 :                 const Size aBorder = pSh->GetOut()->PixelToLogic( pSh->GetBrowseBorder() );
     957          29 :                 long nWidth = nWidthArea - 2 * ( IsVertical() ? aBorder.Height() : aBorder.Width() );
     958          29 :                 nWidth -= (Prt().*fnRect->fnGetLeft)();
     959          29 :                 nWidth -= rAttrs.CalcRightLine();
     960          29 :                 nWidth = std::max( nMinWidth, nWidth );
     961          29 :                 (Prt().*fnRect->fnSetWidth)( std::min( nWidth,
     962          29 :                                             (Prt().*fnRect->fnGetWidth)() ) );
     963             :             }
     964             : 
     965       58703 :             if ( (Prt().*fnRect->fnGetWidth)() <= MINLAY )
     966             :             {
     967             :                 // The PrtArea should already be at least MINLAY wide, matching the
     968             :                 // minimal values of the UI
     969         332 :                 (Prt().*fnRect->fnSetWidth)( std::min( long(MINLAY),
     970         332 :                                              (Frm().*fnRect->fnGetWidth)() ) );
     971         332 :                 SwTwips nTmp = (Frm().*fnRect->fnGetWidth)() -
     972         332 :                                (Prt().*fnRect->fnGetWidth)();
     973         332 :                 if( (Prt().*fnRect->fnGetLeft)() > nTmp )
     974           1 :                     (Prt().*fnRect->fnSetLeft)( nTmp );
     975             :             }
     976             : 
     977             :             // The following rules apply for VarSize:
     978             :             // 1. The first entry of a chain has no top border
     979             :             // 2. There is never a bottom border
     980             :             // 3. The top border is the maximum of the distance
     981             :             //    of Prev downwards and our own distance upwards
     982             :             // Those three rules apply when calculating spacings
     983             :             // that are given by UL- and LRSpace. There might be a spacing
     984             :             // in all directions however; this may be caused by borders
     985             :             // and / or shadows.
     986             :             // 4. The spacing for TextFrms corresponds to the interline lead,
     987             :             //    at a minimum.
     988             : 
     989       58703 :             nUpper = CalcUpperSpace( &rAttrs, NULL );
     990             : 
     991       58703 :             SwTwips nLower = CalcLowerSpace( &rAttrs );
     992       58703 :             if (IsCollapse()) {
     993          96 :                 nUpper=0;
     994          96 :                 nLower=0;
     995             :             }
     996             : 
     997       58703 :             (Prt().*fnRect->fnSetPosY)( (!bVert || mbReverse) ? nUpper : nLower);
     998       58703 :             nUpper += nLower;
     999       58703 :             nUpper -= (Frm().*fnRect->fnGetHeight)() -
    1000       58703 :                       (Prt().*fnRect->fnGetHeight)();
    1001             :         }
    1002             :         // If there's a difference between old and new size, call Grow() or
    1003             :         // Shrink() respectively.
    1004       59002 :         if ( nUpper )
    1005             :         {
    1006       10362 :             if ( nUpper > 0 )
    1007        9141 :                 GrowFrm( nUpper );
    1008             :             else
    1009        1221 :                 ShrinkFrm( -nUpper );
    1010       10362 :             bSizeChgd = sal_True;
    1011             :         }
    1012             :     }
    1013       59619 :     return bSizeChgd;
    1014             : }
    1015             : 
    1016             : #define STOP_FLY_FORMAT 10
    1017             : // - loop prevention
    1018             : const int cnStopFormat = 15;
    1019             : 
    1020         200 : inline void ValidateSz( SwFrm *pFrm )
    1021             : {
    1022         200 :     if ( pFrm )
    1023             :     {
    1024         200 :         pFrm->mbValidSize = sal_True;
    1025         200 :         pFrm->mbValidPrtArea = sal_True;
    1026             :     }
    1027         200 : }
    1028             : 
    1029       47508 : void SwCntntFrm::MakeAll()
    1030             : {
    1031             :     OSL_ENSURE( GetUpper(), "no Upper?" );
    1032             :     OSL_ENSURE( IsTxtFrm(), "MakeAll(), NoTxt" );
    1033             : 
    1034       47508 :     if ( !IsFollow() && StackHack::IsLocked() )
    1035          62 :         return;
    1036             : 
    1037       47508 :     if ( IsJoinLocked() )
    1038          62 :         return;
    1039             : 
    1040             :     OSL_ENSURE( !((SwTxtFrm*)this)->IsSwapped(), "Calculation of a swapped frame" );
    1041             : 
    1042       47446 :     StackHack aHack;
    1043             : 
    1044       47446 :     if ( ((SwTxtFrm*)this)->IsLocked() )
    1045             :     {
    1046             :         OSL_FAIL( "Format for locked TxtFrm." );
    1047           0 :         return;
    1048             :     }
    1049             : 
    1050       47446 :     LockJoin();
    1051       47446 :     long nFormatCount = 0;
    1052             :     // - loop prevention
    1053       47446 :     int nConsequetiveFormatsWithoutChange = 0;
    1054             :     PROTOCOL_ENTER( this, PROT_MAKEALL, 0, 0 )
    1055             : 
    1056             : #ifdef DBG_UTIL
    1057             :     const SwDoc *pDoc = GetAttrSet()->GetDoc();
    1058             :     if( pDoc )
    1059             :     {
    1060             :         static bool bWarned = false;
    1061             :         if( pDoc->InXMLExport() )
    1062             :         {
    1063             :             SAL_WARN_IF( !bWarned, "sw", "Formatting during XML-export!" );
    1064             :             bWarned = true;
    1065             :         }
    1066             :         else
    1067             :             bWarned = false;
    1068             :     }
    1069             : #endif
    1070             : 
    1071             :     // takes care of the notification in the dtor
    1072       47446 :     SwCntntNotify *pNotify = new SwCntntNotify( this );
    1073             : 
    1074             :     // as long as bMakePage is true, a new page can be created (exactly once)
    1075       47446 :     bool bMakePage = true;
    1076             :     // bMovedBwd gets set to true when the frame flows backwards
    1077       47446 :     bool bMovedBwd = false;
    1078             :     // as long as bMovedFwd is false, the Frm may flow backwards (until
    1079             :     // it has been moved forward once)
    1080       47446 :     bool bMovedFwd  = false;
    1081       47446 :     sal_Bool    bFormatted  = sal_False;    // For the widow/orphan rules, we encourage the
    1082             :                                             // last CntntFrm of a chain to format. This only
    1083             :                                             // needs to happen once. Every time the Frm is
    1084             :                                             // moved, the flag will have to be reset.
    1085       47446 :     bool bMustFit = false;                  // Once the emergency brake is pulled,
    1086             :                                             // no other prepares will be triggered
    1087       47446 :     bool bFitPromise = false;               // If a paragraph didn't fit, but promises
    1088             :                                             // with WouldFit that it would adjust accordingly,
    1089             :                                             // this flag is set. If it turns out that it
    1090             :                                             // didn't keep it's promise, we can act in a
    1091             :                                             // controlled fashion.
    1092             :     bool bMoveable;
    1093       47446 :     const sal_Bool bFly = IsInFly();
    1094       47446 :     const sal_Bool bTab = IsInTab();
    1095       47446 :     const sal_Bool bFtn = IsInFtn();
    1096       47446 :     const sal_Bool bSct = IsInSct();
    1097       47446 :     Point aOldFrmPos;               // This is so we can compare with the last pos
    1098       47446 :     Point aOldPrtPos;               // and determine whether it makes sense to Prepare
    1099             : 
    1100       94892 :     SwBorderAttrAccess aAccess( SwFrm::GetCache(), this );
    1101       47446 :     const SwBorderAttrs &rAttrs = *aAccess.Get();
    1102             : 
    1103             :     // OD 2004-02-26 #i25029#
    1104       47446 :     if ( !IsFollow() && rAttrs.JoinedWithPrev( *(this) ) )
    1105             :     {
    1106       14351 :         pNotify->SetBordersJoinedWithPrev();
    1107             :     }
    1108             : 
    1109       47446 :     const sal_Bool bKeep = IsKeep( rAttrs.GetAttrSet() );
    1110             : 
    1111       47446 :     SwSaveFtnHeight *pSaveFtn = 0;
    1112       47446 :     if ( bFtn )
    1113             :     {
    1114         228 :         SwFtnFrm *pFtn = FindFtnFrm();
    1115         228 :         SwSectionFrm* pSct = pFtn->FindSctFrm();
    1116         228 :         if ( !((SwTxtFrm*)pFtn->GetRef())->IsLocked() )
    1117             :         {
    1118          52 :             SwFtnBossFrm* pBoss = pFtn->GetRef()->FindFtnBossFrm(
    1119         104 :                                     pFtn->GetAttr()->GetFtn().IsEndNote() );
    1120          52 :             if( !pSct || pSct->IsColLocked() || !pSct->Growable() )
    1121             :                 pSaveFtn = new SwSaveFtnHeight( pBoss,
    1122          52 :                     ((SwTxtFrm*)pFtn->GetRef())->GetFtnLine( pFtn->GetAttr() ) );
    1123             :         }
    1124             :     }
    1125             : 
    1126       96069 :     if ( GetUpper()->IsSctFrm() &&
    1127       47446 :          HasFollow() &&
    1128           0 :          GetFollow()->GetFrm() == GetNext() )
    1129             :     {
    1130           0 :         dynamic_cast<SwTxtFrm*>(this)->JoinFrm();
    1131             :     }
    1132             : 
    1133             :     // #i28701# - move master forward, if it has to move,
    1134             :     // because of its object positioning.
    1135       47446 :     if ( !static_cast<SwTxtFrm*>(this)->IsFollow() )
    1136             :     {
    1137       46092 :         sal_uInt32 nToPageNum = 0L;
    1138             :         const bool bMoveFwdByObjPos = SwLayouter::FrmMovedFwdByObjPos(
    1139       46092 :                                                     *(GetAttrSet()->GetDoc()),
    1140             :                                                     *(static_cast<SwTxtFrm*>(this)),
    1141       46092 :                                                     nToPageNum );
    1142             :         // #i58182#
    1143             :         // Also move a paragraph forward, which is the first one inside a table cell.
    1144       46101 :         if ( bMoveFwdByObjPos &&
    1145           9 :              FindPageFrm()->GetPhyPageNum() < nToPageNum &&
    1146           0 :              ( lcl_Prev( this ) ||
    1147           0 :                GetUpper()->IsCellFrm() ||
    1148           0 :                ( GetUpper()->IsSctFrm() &&
    1149       46092 :                  GetUpper()->GetUpper()->IsCellFrm() ) ) &&
    1150           0 :              IsMoveable() )
    1151             :         {
    1152           0 :             bMovedFwd = true;
    1153           0 :             MoveFwd( bMakePage, sal_False );
    1154             :         }
    1155             :     }
    1156             : 
    1157             :     // If a Follow sits next to it's Master and doesn't fit, we know it can
    1158             :     // be moved right now.
    1159       47446 :     if ( lcl_Prev( this ) && ((SwTxtFrm*)this)->IsFollow() && IsMoveable() )
    1160             :     {
    1161         376 :         bMovedFwd = true;
    1162             :         // OD 2004-03-02 #106629# - If follow frame is in table, it's master
    1163             :         // will be the last in the current table cell. Thus, invalidate the
    1164             :         // printing area of the master,
    1165         376 :         if ( IsInTab() )
    1166             :         {
    1167         123 :             lcl_Prev( this )->InvalidatePrt();
    1168             :         }
    1169         376 :         MoveFwd( bMakePage, sal_False );
    1170             :     }
    1171             : 
    1172             :     // OD 08.11.2002 #104840# - check footnote content for forward move.
    1173             :     // If a content of a footnote is on a prior page/column as its invalid
    1174             :     // reference, it can be moved forward.
    1175       47446 :     if ( bFtn && !mbValidPos )
    1176             :     {
    1177         204 :         SwFtnFrm* pFtn = FindFtnFrm();
    1178         204 :         SwCntntFrm* pRefCnt = pFtn ? pFtn->GetRef() : 0;
    1179         204 :         if ( pRefCnt && !pRefCnt->IsValid() )
    1180             :         {
    1181          98 :             SwFtnBossFrm* pFtnBossOfFtn = pFtn->FindFtnBossFrm();
    1182          98 :             SwFtnBossFrm* pFtnBossOfRef = pRefCnt->FindFtnBossFrm();
    1183             :             //<loop of movefwd until condition held or no move>
    1184         196 :             if ( pFtnBossOfFtn && pFtnBossOfRef &&
    1185         101 :                  pFtnBossOfFtn != pFtnBossOfRef &&
    1186           3 :                  pFtnBossOfFtn->IsBefore( pFtnBossOfRef ) )
    1187             :             {
    1188           0 :                 bMovedFwd = true;
    1189           0 :                 MoveFwd( bMakePage, sal_False );
    1190             :             }
    1191             :         }
    1192             :     }
    1193             : 
    1194       47446 :     SWRECTFN( this )
    1195             : 
    1196      167317 :     while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
    1197             :     {
    1198             :         // - loop prevention
    1199       72520 :         SwRect aOldFrm_StopFormat( Frm() );
    1200       72520 :         SwRect aOldPrt_StopFormat( Prt() );
    1201       72520 :         if ( (bMoveable = IsMoveable()) )
    1202             :         {
    1203       40470 :             SwFrm *pPre = GetIndPrev();
    1204       40470 :             if ( CheckMoveFwd( bMakePage, bKeep, bMovedBwd ) )
    1205             :             {
    1206          68 :                 SWREFRESHFN( this )
    1207          68 :                 bMovedFwd = true;
    1208          68 :                 if ( bMovedBwd )
    1209             :                 {
    1210             :                     // While flowing back, the Upper was encouraged to
    1211             :                     // completely re-paint itself. We can skip this now after
    1212             :                     // flowing back and forth.
    1213           7 :                     GetUpper()->ResetCompletePaint();
    1214             :                     // The predecessor was invalidated, so this is obsolete as well now.
    1215             :                     OSL_ENSURE( pPre, "missing old Prev" );
    1216           7 :                     if( !pPre->IsSctFrm() )
    1217           7 :                         ::ValidateSz( pPre );
    1218             :                 }
    1219          68 :                 bMoveable = IsMoveable();
    1220             :             }
    1221             :         }
    1222             : 
    1223       72520 :         aOldFrmPos = (Frm().*fnRect->fnGetPos)();
    1224       72520 :         aOldPrtPos = (Prt().*fnRect->fnGetPos)();
    1225             : 
    1226       72520 :         if ( !mbValidPos )
    1227       43964 :             MakePos();
    1228             : 
    1229             :         //Set FixSize. VarSize is being adjusted by Format().
    1230       72520 :         if ( !mbValidSize )
    1231             :         {
    1232             :             // #125452#
    1233             :             // invalidate printing area flag, if the following conditions are hold:
    1234             :             // - current frame width is 0.
    1235             :             // - current printing area width is 0.
    1236             :             // - frame width is adjusted to a value greater than 0.
    1237             :             // - printing area flag is sal_True.
    1238             :             // Thus, it's assured that the printing area is adjusted, if the
    1239             :             // frame area width changes its width from 0 to something greater
    1240             :             // than 0.
    1241             :             // Note: A text frame can be in such a situation, if the format is
    1242             :             //       triggered by method call <SwCrsrShell::SetCrsr()> after
    1243             :             //       loading the document.
    1244       46313 :             const SwTwips nNewFrmWidth = (GetUpper()->Prt().*fnRect->fnGetWidth)();
    1245       63145 :             if ( mbValidPrtArea && nNewFrmWidth > 0 &&
    1246       54729 :                  (Frm().*fnRect->fnGetWidth)() == 0 &&
    1247           0 :                  (Prt().*fnRect->fnGetWidth)() == 0 )
    1248             :             {
    1249           0 :                 mbValidPrtArea = sal_False;
    1250             :             }
    1251             : 
    1252       46313 :             (Frm().*fnRect->fnSetWidth)( nNewFrmWidth );
    1253             : 
    1254             :             // When a lower of a vertically aligned fly frame changes its size we need to recalculate content pos.
    1255       48327 :             if( GetUpper() && GetUpper()->IsFlyFrm() &&
    1256        2014 :                 GetUpper()->GetFmt()->GetTextVertAdjust().GetValue() != SDRTEXTVERTADJUST_TOP )
    1257             :             {
    1258         337 :                 static_cast<SwFlyFrm*>(GetUpper())->InvalidateContentPos();
    1259         337 :                 GetUpper()->SetCompletePaint();
    1260             :             }
    1261             :         }
    1262       72520 :         if ( !mbValidPrtArea )
    1263             :         {
    1264       57676 :             const long nOldW = (Prt().*fnRect->fnGetWidth)();
    1265             :             // #i34730# - keep current frame height
    1266       57676 :             const SwTwips nOldH = (Frm().*fnRect->fnGetHeight)();
    1267       57676 :             MakePrtArea( rAttrs );
    1268       57676 :             if ( nOldW != (Prt().*fnRect->fnGetWidth)() )
    1269       23064 :                 Prepare( PREP_FIXSIZE_CHG );
    1270             :             // #i34730# - check, if frame height has changed.
    1271             :             // If yes, send a PREP_ADJUST_FRM and invalidate the size flag to
    1272             :             // force a format. The format will check in its method
    1273             :             // <SwTxtFrm::CalcPreps()>, if the already formatted lines still
    1274             :             // fit and if not, performs necessary actions.
    1275             :             // #i40150# - no check, if frame is undersized.
    1276       77192 :             if ( mbValidSize && !IsUndersized() &&
    1277       19516 :                  nOldH != (Frm().*fnRect->fnGetHeight)() )
    1278             :             {
    1279             :                 // #115759# - no PREP_ADJUST_FRM and size
    1280             :                 // invalidation, if height decreases only by the additional
    1281             :                 // lower space as last content of a table cell and an existing
    1282             :                 // follow containing one line exists.
    1283          89 :                 const SwTwips nHDiff = nOldH - (Frm().*fnRect->fnGetHeight)();
    1284             :                 const bool bNoPrepAdjustFrm =
    1285          87 :                     nHDiff > 0 && IsInTab() && GetFollow() &&
    1286         143 :                     ( 1 == static_cast<SwTxtFrm*>(GetFollow())->GetLineCount( COMPLETE_STRING ) || (static_cast<SwTxtFrm*>(GetFollow())->Frm().*fnRect->fnGetWidth)() < 0 ) &&
    1287         107 :                     GetFollow()->CalcAddLowerSpaceAsLastInTableCell() == nHDiff;
    1288          89 :                 if ( !bNoPrepAdjustFrm )
    1289             :                 {
    1290          71 :                     Prepare( PREP_ADJUST_FRM );
    1291          71 :                     mbValidSize = sal_False;
    1292             :                 }
    1293             :             }
    1294             :         }
    1295             : 
    1296             :         // To make the widow and orphan rules work, we need to notify the CntntFrm.
    1297             :         // Criteria:
    1298             :         // - It needs to be movable (otherwise, splitting doesn't make sense)
    1299             :         // - It needs to overlap with the lower edge of the PrtArea of the Upper
    1300       72520 :         if ( !bMustFit )
    1301             :         {
    1302       72084 :             sal_Bool bWidow = sal_True;
    1303       72084 :             const SwTwips nDeadLine = (GetUpper()->*fnRect->fnGetPrtBottom)();
    1304      101489 :             if ( bMoveable && !bFormatted && ( GetFollow() ||
    1305       29405 :                  ( (Frm().*fnRect->fnOverStep)( nDeadLine ) ) ) )
    1306             :             {
    1307        1045 :                 Prepare( PREP_WIDOWS_ORPHANS, 0, false );
    1308        1045 :                 mbValidSize = bWidow = sal_False;
    1309             :             }
    1310      218274 :             if( (Frm().*fnRect->fnGetPos)() != aOldFrmPos ||
    1311      146190 :                 (Prt().*fnRect->fnGetPos)() != aOldPrtPos )
    1312             :             {
    1313             :                 // In this Prepare, an _InvalidateSize() might happen.
    1314             :                 // mbValidSize becomes sal_False and Format() gets called.
    1315       35301 :                 Prepare( PREP_POS_CHGD, (const void*)&bFormatted, false );
    1316       35301 :                 if ( bWidow && GetFollow() )
    1317             :                 {
    1318          54 :                     Prepare( PREP_WIDOWS_ORPHANS, 0, false );
    1319          54 :                     mbValidSize = sal_False;
    1320             :                 }
    1321             :             }
    1322             :         }
    1323       72520 :         if ( !mbValidSize )
    1324             :         {
    1325       46659 :             mbValidSize = bFormatted = sal_True;
    1326       46659 :             ++nFormatCount;
    1327       46659 :             if( nFormatCount > STOP_FLY_FORMAT )
    1328           0 :                 SetFlyLock( sal_True );
    1329             :             // - loop prevention
    1330             :             // No format any longer, if <cnStopFormat> consequetive formats
    1331             :             // without change occur.
    1332       46659 :             if ( nConsequetiveFormatsWithoutChange <= cnStopFormat )
    1333             :             {
    1334       46659 :                 Format();
    1335             :             }
    1336             : #if OSL_DEBUG_LEVEL > 0
    1337             :             else
    1338             :             {
    1339             :                 OSL_FAIL( "debug assertion: <SwCntntFrm::MakeAll()> - format of text frame suppressed by fix b6448963" );
    1340             :             }
    1341             : #endif
    1342             :         }
    1343             : 
    1344             :         // If this is the first one in a chain, check if this can flow
    1345             :         // backwards (if this is movable at all).
    1346             :         // To prevent oscillations/loops, check that this has not just
    1347             :         // flowed forwards.
    1348             :         bool bDummy;
    1349      187218 :         if ( !lcl_Prev( this ) &&
    1350       82046 :              !bMovedFwd &&
    1351       26282 :              ( bMoveable || ( bFly && !bTab ) ) &&
    1352         277 :              ( !bFtn || !GetUpper()->FindFtnFrm()->GetPrev() )
    1353       87537 :              && MoveBwd( bDummy ) )
    1354             :         {
    1355        4202 :             SWREFRESHFN( this )
    1356        4202 :             bMovedBwd = true;
    1357        4202 :             bFormatted = sal_False;
    1358        4202 :             if ( bKeep && bMoveable )
    1359             :             {
    1360         358 :                 if( CheckMoveFwd( bMakePage, sal_False, bMovedBwd ) )
    1361             :                 {
    1362           0 :                     bMovedFwd = true;
    1363           0 :                     bMoveable = IsMoveable();
    1364           0 :                     SWREFRESHFN( this )
    1365             :                 }
    1366         358 :                 Point aOldPos = (Frm().*fnRect->fnGetPos)();
    1367         358 :                 MakePos();
    1368         358 :                 if( aOldPos != (Frm().*fnRect->fnGetPos)() )
    1369             :                 {
    1370         358 :                     Prepare( PREP_POS_CHGD, (const void*)&bFormatted, false );
    1371         358 :                     if ( !mbValidSize )
    1372             :                     {
    1373         716 :                         (Frm().*fnRect->fnSetWidth)( (GetUpper()->
    1374         716 :                                                 Prt().*fnRect->fnGetWidth)() );
    1375         358 :                         if ( !mbValidPrtArea )
    1376             :                         {
    1377         358 :                             const long nOldW = (Prt().*fnRect->fnGetWidth)();
    1378         358 :                             MakePrtArea( rAttrs );
    1379         358 :                             if( nOldW != (Prt().*fnRect->fnGetWidth)() )
    1380           0 :                                 Prepare( PREP_FIXSIZE_CHG, 0, false );
    1381             :                         }
    1382         358 :                         if( GetFollow() )
    1383           0 :                             Prepare( PREP_WIDOWS_ORPHANS, 0, false );
    1384         358 :                         mbValidSize = bFormatted = sal_True;
    1385         358 :                         Format();
    1386             :                     }
    1387             :                 }
    1388         358 :                 SwFrm *pNxt = HasFollow() ? NULL : FindNext();
    1389         730 :                 while( pNxt && pNxt->IsSctFrm() )
    1390             :                 {   // Leave empty sections out, go into the other ones.
    1391          34 :                     if( ((SwSectionFrm*)pNxt)->GetSection() )
    1392             :                     {
    1393          27 :                         SwFrm* pTmp = ((SwSectionFrm*)pNxt)->ContainsAny();
    1394          27 :                         if( pTmp )
    1395             :                         {
    1396          20 :                             pNxt = pTmp;
    1397          20 :                             break;
    1398             :                         }
    1399             :                     }
    1400          14 :                     pNxt = pNxt->FindNext();
    1401             :                 }
    1402         358 :                 if ( pNxt )
    1403             :                 {
    1404         358 :                     pNxt->Calc();
    1405         358 :                     if( mbValidPos && !GetIndNext() )
    1406             :                     {
    1407           0 :                         SwSectionFrm *pSct = FindSctFrm();
    1408           0 :                         if( pSct && !pSct->GetValidSizeFlag() )
    1409             :                         {
    1410           0 :                             SwSectionFrm* pNxtSct = pNxt->FindSctFrm();
    1411           0 :                             if( pNxtSct && pSct->IsAnFollow( pNxtSct ) )
    1412           0 :                                 mbValidPos = sal_False;
    1413             :                         }
    1414             :                         else
    1415           0 :                             mbValidPos = sal_False;
    1416             :                     }
    1417             :                 }
    1418             :             }
    1419             :         }
    1420             : 
    1421             :         // In footnotes, the TxtFrm may validate itself, which can lead to the
    1422             :         // situation that it's position is wrong despite being "valid".
    1423       72520 :         if ( mbValidPos )
    1424             :         {
    1425             :             // #i59341#
    1426             :             // Workaround for inadequate layout algorithm:
    1427             :             // suppress invalidation and calculation of position, if paragraph
    1428             :             // has formatted itself at least STOP_FLY_FORMAT times and
    1429             :             // has anchored objects.
    1430             :             // Thus, the anchored objects get the possibility to format itself
    1431             :             // and this probably solve the layout loop.
    1432       68737 :             if ( bFtn &&
    1433       68737 :                  nFormatCount <= STOP_FLY_FORMAT &&
    1434         311 :                  !GetDrawObjs() )
    1435             :             {
    1436         311 :                 mbValidPos = sal_False;
    1437         311 :                 MakePos();
    1438         311 :                 aOldFrmPos = (Frm().*fnRect->fnGetPos)();
    1439         311 :                 aOldPrtPos = (Prt().*fnRect->fnGetPos)();
    1440             :             }
    1441             :         }
    1442             : 
    1443             :         // - loop prevention
    1444             :         {
    1445      107601 :             if ( aOldFrm_StopFormat == Frm() &&
    1446       35081 :                  aOldPrt_StopFormat == Prt() )
    1447             :             {
    1448       35081 :                 ++nConsequetiveFormatsWithoutChange;
    1449             :             }
    1450             :             else
    1451             :             {
    1452       37439 :                 nConsequetiveFormatsWithoutChange = 0;
    1453             :             }
    1454             :         }
    1455             : 
    1456             :         // Yet again an invalid value? Repeat from the start...
    1457       72520 :         if ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
    1458       95409 :             continue;
    1459             : 
    1460             :         // Done?
    1461             :         // Attention: because height == 0, it's better to use Top()+Height() instead of
    1462             :         // Bottom(). This might happen with undersized TextFrms on the lower edge of a
    1463             :         // multi-column section
    1464       48603 :         const long nPrtBottom = (GetUpper()->*fnRect->fnGetPrtBottom)();
    1465       48603 :         const long nBottomDist =  (Frm().*fnRect->fnBottomDist)( nPrtBottom );
    1466       48603 :         if( nBottomDist >= 0 )
    1467             :         {
    1468       47329 :             if ( bKeep && bMoveable )
    1469             :             {
    1470             :                 // We make sure the successor will be formatted the same.
    1471             :                 // This way, we keep control until (almost) everything is stable,
    1472             :                 // allowing us to avoid endless loops caused by ever repeating
    1473             :                 // retries.
    1474             : 
    1475             :                 // bMoveFwdInvalid is required for #38407#. This was originally solved
    1476             :                 // in flowfrm.cxx rev 1.38, but broke the above schema and
    1477             :                 // preferred to play towers of hanoi (#43669#).
    1478        1621 :                 SwFrm *pNxt = HasFollow() ? NULL : FindNext();
    1479             :                 // For sections we prefer the content, because it can change
    1480             :                 // the page if required.
    1481        3243 :                 while( pNxt && pNxt->IsSctFrm() )
    1482             :                 {
    1483          75 :                     if( ((SwSectionFrm*)pNxt)->GetSection() )
    1484             :                     {
    1485          74 :                         pNxt = ((SwSectionFrm*)pNxt)->ContainsAny();
    1486          74 :                         break;
    1487             :                     }
    1488           1 :                     pNxt = pNxt->FindNext();
    1489             :                 }
    1490        1621 :                 if ( pNxt )
    1491             :                 {
    1492        1562 :                     const bool bMoveFwdInvalid = 0 != GetIndNext();
    1493             :                     const bool bNxtNew =
    1494        2454 :                         ( 0 == (pNxt->Prt().*fnRect->fnGetHeight)() ) &&
    1495        2445 :                         (!pNxt->IsTxtFrm() ||!((SwTxtFrm*)pNxt)->IsHiddenNow());
    1496             : 
    1497        1562 :                     pNxt->Calc();
    1498             : 
    1499        2008 :                     if ( !bMovedBwd &&
    1500        1194 :                          ((bMoveFwdInvalid && !GetIndNext()) ||
    1501             :                           bNxtNew) )
    1502             :                     {
    1503         446 :                         if( bMovedFwd )
    1504           0 :                             pNotify->SetInvaKeep();
    1505         446 :                         bMovedFwd = false;
    1506             :                     }
    1507             :                 }
    1508             :             }
    1509       47329 :             continue;
    1510             :         }
    1511             : 
    1512             :         // I don't fit into my parents, so it's time to make changes
    1513             :         // as constructively as possible.
    1514             : 
    1515             :         //If I'm NOT allowed to leave the parent Frm, I've got a problem.
    1516             :         // Following Arthur Dent, we do the only thing that you can do with
    1517             :         // an unsolvable problem: We ignore it with all our power.
    1518        1274 :         if ( !bMoveable || IsUndersized() )
    1519             :         {
    1520         126 :             if( !bMoveable && IsInTab() )
    1521             :             {
    1522          46 :                 long nDiff = -(Frm().*fnRect->fnBottomDist)(
    1523          46 :                                         (GetUpper()->*fnRect->fnGetPrtBottom)() );
    1524          46 :                 long nReal = GetUpper()->Grow( nDiff );
    1525          46 :                 if( nReal )
    1526          31 :                     continue;
    1527             :             }
    1528         190 :             break;
    1529             :         }
    1530             : 
    1531             :         // If there's no way I can make myself fit into my Upper, the situation
    1532             :         // could still probably be mitigated by splitting up.
    1533             :         // This situation arises with freshly created Follows that had been moved
    1534             :         // to the next page but is still too big for it - ie. needs to be split
    1535             :         // as well.
    1536             : 
    1537             :         // If I'm unable to split (WouldFit()) and can't be fitted, I'm going
    1538             :         // to tell my TxtFrm part that, if possible, we still need to split despite
    1539             :         // the "don't split" attribute.
    1540        1148 :         bool bMoveOrFit = false;
    1541        1148 :         bool bDontMoveMe = !GetIndPrev();
    1542        1148 :         if( bDontMoveMe && IsInSct() )
    1543             :         {
    1544         334 :             SwFtnBossFrm* pBoss = FindFtnBossFrm();
    1545         898 :             bDontMoveMe = !pBoss->IsInSct() ||
    1546        1002 :                           ( !pBoss->Lower()->GetNext() && !pBoss->GetPrev() );
    1547             :         }
    1548             : 
    1549             :         // Finally, we are able to split table rows. Therefore, bDontMoveMe
    1550             :         // can be set to false:
    1551        1216 :         if( bDontMoveMe && IsInTab() &&
    1552          68 :             0 != const_cast<SwCntntFrm*>(this)->GetNextCellLeaf( MAKEPAGE_NONE ) )
    1553          68 :             bDontMoveMe = false;
    1554             : 
    1555        1387 :         if ( bDontMoveMe && (Frm().*fnRect->fnGetHeight)() >
    1556         239 :                             (GetUpper()->Prt().*fnRect->fnGetHeight)() )
    1557             :         {
    1558         239 :             if ( !bFitPromise )
    1559             :             {
    1560         478 :                 SwTwips nTmp = (GetUpper()->Prt().*fnRect->fnGetHeight)() -
    1561         478 :                                (Prt().*fnRect->fnGetTop)();
    1562         239 :                 bool bSplit = !IsFwdMoveAllowed();
    1563         239 :                 if ( nTmp > 0 && WouldFit( nTmp, bSplit, false ) )
    1564             :                 {
    1565           0 :                     Prepare( PREP_WIDOWS_ORPHANS, 0, false );
    1566           0 :                     mbValidSize = sal_False;
    1567           0 :                     bFitPromise = true;
    1568           0 :                     continue;
    1569             :                 }
    1570             :                 /* --------------------------------------------------
    1571             :                  * In earlier days, we never tried to fit TextFrms in
    1572             :                  * frames and sections using bMoveOrFit by ignoring
    1573             :                  * its attributes (Widows, Keep).
    1574             :                  * This should have been done at least for column frames;
    1575             :                  * as it must be tried anyway with linked frames and sections.
    1576             :                  * Exception: If we sit in FormatWidthCols, we must not ignore
    1577             :                  * the attributes.
    1578             :                  * --------------------------------------------------*/
    1579         478 :                 else if ( !bFtn && bMoveable &&
    1580         454 :                       ( !bFly || !FindFlyFrm()->IsColLocked() ) &&
    1581         230 :                       ( !bSct || !FindSctFrm()->IsColLocked() ) )
    1582         215 :                     bMoveOrFit = true;
    1583             :             }
    1584             : #if OSL_DEBUG_LEVEL > 0
    1585             :             else
    1586             :             {
    1587             :                 OSL_FAIL( "+TxtFrm didn't respect WouldFit promise." );
    1588             :             }
    1589             : #endif
    1590             :         }
    1591             : 
    1592             :         // Let's see if I can find some space somewhere...
    1593             :         // footnotes in the neighbourhood are moved into _MoveFtnCntFwd
    1594        1148 :         SwFrm *pPre = GetIndPrev();
    1595        1148 :         SwFrm *pOldUp = GetUpper();
    1596             : 
    1597             : /* MA 13. Oct. 98: What is this supposed to be!?
    1598             :  * AMA 14. Dec 98: If a column section can't find any space for its first ContentFrm, it should be
    1599             :  *                 moved not only to the next column, but probably even to the next page, creating
    1600             :  *                 a section-follow there.
    1601             :  */
    1602        3387 :         if( IsInSct() && bMovedFwd && bMakePage && pOldUp->IsColBodyFrm() &&
    1603         390 :             pOldUp->GetUpper()->GetUpper()->IsSctFrm() &&
    1604        1445 :             ( pPre || pOldUp->GetUpper()->GetPrev() ) &&
    1605         157 :             ((SwSectionFrm*)pOldUp->GetUpper()->GetUpper())->MoveAllowed(this) )
    1606             :         {
    1607         157 :             bMovedFwd = false;
    1608             :         }
    1609             : 
    1610        1148 :         const sal_Bool bCheckForGrownBody = pOldUp->IsBodyFrm();
    1611        1148 :         const long nOldBodyHeight = (pOldUp->Frm().*fnRect->fnGetHeight)();
    1612             : 
    1613        1148 :         if ( !bMovedFwd && !MoveFwd( bMakePage, sal_False ) )
    1614         371 :             bMakePage = false;
    1615        1148 :         SWREFRESHFN( this )
    1616             : 
    1617             :         // If MoveFwd moves the paragraph to the next page, a following
    1618             :         // paragraph, which contains footnotes can can cause the old upper
    1619             :         // frame to grow. In this case we explicitly allow a new check
    1620             :         // for MoveBwd. Robust: We also check the bMovedBwd flag again.
    1621             :         // If pOldUp was a footnote frame, it has been deleted inside MoveFwd.
    1622             :         // Therefore we only check for growing body frames.
    1623        1776 :         if ( bCheckForGrownBody && ! bMovedBwd && pOldUp != GetUpper() &&
    1624         628 :              (pOldUp->Frm().*fnRect->fnGetHeight)() > nOldBodyHeight )
    1625             :         {
    1626           0 :             bMovedFwd = false;
    1627             :         }
    1628             :         else
    1629             :         {
    1630        1148 :             bMovedFwd = true;
    1631             :         }
    1632             : 
    1633        1148 :         bFormatted = sal_False;
    1634        1148 :         if ( bMoveOrFit && GetUpper() == pOldUp )
    1635             :         {
    1636             :             // FME 2007-08-30 #i81146# new loop control
    1637         215 :             if ( nConsequetiveFormatsWithoutChange <= cnStopFormat )
    1638             :             {
    1639         215 :                 Prepare( PREP_MUST_FIT, 0, false );
    1640         215 :                 mbValidSize = sal_False;
    1641         215 :                 bMustFit = true;
    1642         215 :                 continue;
    1643             :             }
    1644             : 
    1645             : #if OSL_DEBUG_LEVEL > 0
    1646             :             OSL_FAIL( "LoopControl in SwCntntFrm::MakeAll" );
    1647             : #endif
    1648             :         }
    1649         933 :         if ( bMovedBwd && GetUpper() )
    1650             :         {   // Retire invalidations that have become useless.
    1651         203 :             GetUpper()->ResetCompletePaint();
    1652         203 :             if( pPre && !pPre->IsSctFrm() )
    1653         193 :                 ::ValidateSz( pPre );
    1654             :         }
    1655             : 
    1656             :     } //while ( !mbValidPos || !mbValidSize || !mbValidPrtArea )
    1657             : 
    1658             :     // NEW: Looping Louie (Light). Should not be applied in balanced sections.
    1659             :     // Should only be applied if there is no better solution!
    1660       47446 :     LOOPING_LOUIE_LIGHT( bMovedFwd && bMovedBwd && !IsInBalancedSection() &&
    1661             :                             (
    1662             : 
    1663             :                                 // #118572#
    1664          55 :                                 ( bFtn && !FindFtnFrm()->GetRef()->IsInSct() ) ||
    1665             : 
    1666             :                                 // #i33887#
    1667          56 :                                 ( IsInSct() && bKeep )
    1668             : 
    1669             :                                 // ... add your conditions here ...
    1670             : 
    1671             :                             ),
    1672       47446 :                          static_cast<SwTxtFrm&>(*this) );
    1673             : 
    1674       47446 :     delete pSaveFtn;
    1675             : 
    1676       47446 :     UnlockJoin();
    1677       47446 :     if ( bMovedFwd || bMovedBwd )
    1678        5231 :         pNotify->SetInvaKeep();
    1679             :     // OD 2004-02-26 #i25029#
    1680       47446 :     if ( bMovedFwd )
    1681             :     {
    1682        1229 :         pNotify->SetInvalidatePrevPrtArea();
    1683             :     }
    1684       47446 :     delete pNotify;
    1685       94892 :     SetFlyLock( sal_False );
    1686             : }
    1687             : 
    1688         402 : void MakeNxt( SwFrm *pFrm, SwFrm *pNxt )
    1689             : {
    1690             :     // fix(25455): Validate, otherwise this leads to a recursion.
    1691             :     // The first try, cancelling with pFrm = 0 if !Valid, leads to a problem, as
    1692             :     // the Keep may not be considered properly anymore (27417).
    1693         402 :     const sal_Bool bOldPos = pFrm->GetValidPosFlag();
    1694         402 :     const sal_Bool bOldSz  = pFrm->GetValidSizeFlag();
    1695         402 :     const sal_Bool bOldPrt = pFrm->GetValidPrtAreaFlag();
    1696         402 :     pFrm->mbValidPos = pFrm->mbValidPrtArea = pFrm->mbValidSize = sal_True;
    1697             : 
    1698             :     // fix(29272): Don't call MakeAll - there, pFrm might be invalidated again, and
    1699             :     // we recursively end up in here again.
    1700         402 :     if ( pNxt->IsCntntFrm() )
    1701             :     {
    1702         402 :         SwCntntNotify aNotify( (SwCntntFrm*)pNxt );
    1703         804 :         SwBorderAttrAccess aAccess( SwFrm::GetCache(), pNxt );
    1704         402 :         const SwBorderAttrs &rAttrs = *aAccess.Get();
    1705         402 :         if ( !pNxt->GetValidSizeFlag() )
    1706             :         {
    1707         400 :             if( pNxt->IsVertical() )
    1708           0 :                 pNxt->Frm().Height( pNxt->GetUpper()->Prt().Height() );
    1709             :             else
    1710         400 :                 pNxt->Frm().Width( pNxt->GetUpper()->Prt().Width() );
    1711             :         }
    1712         402 :         ((SwCntntFrm*)pNxt)->MakePrtArea( rAttrs );
    1713         804 :         pNxt->Format( &rAttrs );
    1714             :     }
    1715             :     else
    1716             :     {
    1717           0 :         SwLayNotify aNotify( (SwLayoutFrm*)pNxt );
    1718           0 :         SwBorderAttrAccess aAccess( SwFrm::GetCache(), pNxt );
    1719           0 :         const SwBorderAttrs &rAttrs = *aAccess.Get();
    1720           0 :         if ( !pNxt->GetValidSizeFlag() )
    1721             :         {
    1722           0 :             if( pNxt->IsVertical() )
    1723           0 :                 pNxt->Frm().Height( pNxt->GetUpper()->Prt().Height() );
    1724             :             else
    1725           0 :                 pNxt->Frm().Width( pNxt->GetUpper()->Prt().Width() );
    1726             :         }
    1727           0 :         pNxt->Format( &rAttrs );
    1728             :     }
    1729             : 
    1730         402 :     pFrm->mbValidPos      = bOldPos;
    1731         402 :     pFrm->mbValidSize     = bOldSz;
    1732         402 :     pFrm->mbValidPrtArea  = bOldPrt;
    1733         402 : }
    1734             : 
    1735             : /// This routine checks whether there are no other FtnBosses
    1736             : /// between the pFrm's FtnBoss and the pNxt's FtnBoss.
    1737           0 : static bool lcl_IsNextFtnBoss( const SwFrm *pFrm, const SwFrm* pNxt )
    1738             : {
    1739             :     OSL_ENSURE( pFrm && pNxt, "lcl_IsNextFtnBoss: No Frames?" );
    1740           0 :     pFrm = pFrm->FindFtnBossFrm();
    1741           0 :     pNxt = pNxt->FindFtnBossFrm();
    1742             :     // If pFrm is a last column, we use the page instead.
    1743           0 :     while( pFrm && pFrm->IsColumnFrm() && !pFrm->GetNext() )
    1744           0 :         pFrm = pFrm->GetUpper()->FindFtnBossFrm();
    1745             :     // If pNxt is a first column, we use the page instead.
    1746           0 :     while( pNxt && pNxt->IsColumnFrm() && !pNxt->GetPrev() )
    1747           0 :         pNxt = pNxt->GetUpper()->FindFtnBossFrm();
    1748             :     // So.. now pFrm and pNxt are either two adjacent pages or columns.
    1749           0 :     return pFrm && pNxt && pFrm->GetNext() == pNxt;
    1750             : }
    1751             : 
    1752        2224 : sal_Bool SwCntntFrm::_WouldFit( SwTwips nSpace,
    1753             :                             SwLayoutFrm *pNewUpper,
    1754             :                             sal_Bool bTstMove,
    1755             :                             const bool bObjsInNewUpper )
    1756             : {
    1757             :     // To have the footnote select it's place carefully, it needs
    1758             :     // to be moved in any case if there is at least one page/column
    1759             :     // between the footnote and the new Upper.
    1760        2224 :     SwFtnFrm* pFtnFrm = 0;
    1761        2224 :     if ( IsInFtn() )
    1762             :     {
    1763           0 :         if( !lcl_IsNextFtnBoss( pNewUpper, this ) )
    1764           0 :             return sal_True;
    1765           0 :         pFtnFrm = FindFtnFrm();
    1766             :     }
    1767             : 
    1768             :     sal_Bool bRet;
    1769        2224 :     bool bSplit = !pNewUpper->Lower();
    1770        2224 :     SwCntntFrm *pFrm = this;
    1771        2224 :     const SwFrm *pTmpPrev = pNewUpper->Lower();
    1772        2224 :     if( pTmpPrev && pTmpPrev->IsFtnFrm() )
    1773           0 :         pTmpPrev = ((SwFtnFrm*)pTmpPrev)->Lower();
    1774       26602 :     while ( pTmpPrev && pTmpPrev->GetNext() )
    1775       22154 :         pTmpPrev = pTmpPrev->GetNext();
    1776        2626 :     do
    1777             :     {
    1778             :         // #i46181#
    1779        2626 :         SwTwips nSecondCheck = 0;
    1780        2626 :         SwTwips nOldSpace = nSpace;
    1781        2626 :         bool bOldSplit = bSplit;
    1782             : 
    1783        3062 :         if ( bTstMove || IsInFly() || ( IsInSct() &&
    1784         374 :              ( pFrm->GetUpper()->IsColBodyFrm() || ( pFtnFrm &&
    1785           0 :                pFtnFrm->GetUpper()->GetUpper()->IsColumnFrm() ) ) ) )
    1786             :         {
    1787             :             // This is going to get a bit insidious now. If you're faint of heart,
    1788             :             // you'd better look away here. If a Fly contains columns, then the Cntnts
    1789             :             // are movable, except ones in the last column (see SwFrm::IsMoveable()).
    1790             :             // Of course they're allowed to float back. WouldFit() only returns a usable
    1791             :             // value if the Frm is movable. To fool WouldFit() into believing there's
    1792             :             // a movable Frm, I'm just going to hang it somewhere else for the time.
    1793             :             // The same procedure applies for column sections to make SwSectionFrm::Growable()
    1794             :             // return the proper value.
    1795             :             // Within footnotes, we may even need to put the SwFtnFrm somewhere else, if
    1796             :             // there's no SwFtnFrm there.
    1797         201 :             SwFrm* pTmpFrm = pFrm->IsInFtn() && !pNewUpper->FindFtnFrm() ?
    1798         201 :                              (SwFrm*)pFrm->FindFtnFrm() : pFrm;
    1799         201 :             SwLayoutFrm *pUp = pTmpFrm->GetUpper();
    1800         201 :             SwFrm *pOldNext = pTmpFrm->GetNext();
    1801         201 :             pTmpFrm->Remove();
    1802         201 :             pTmpFrm->InsertBefore( pNewUpper, 0 );
    1803         308 :             if ( pFrm->IsTxtFrm() &&
    1804          96 :                  ( bTstMove ||
    1805         190 :                    ((SwTxtFrm*)pFrm)->HasFollow() ||
    1806          96 :                    ( !((SwTxtFrm*)pFrm)->HasPara() &&
    1807           2 :                      !((SwTxtFrm*)pFrm)->IsEmpty()
    1808             :                    )
    1809             :                  )
    1810             :                )
    1811             :             {
    1812         107 :                 bTstMove = sal_True;
    1813         107 :                 bRet = ((SwTxtFrm*)pFrm)->TestFormat( pTmpPrev, nSpace, bSplit );
    1814             :             }
    1815             :             else
    1816          94 :                 bRet = pFrm->WouldFit( nSpace, bSplit, false );
    1817             : 
    1818         201 :             pTmpFrm->Remove();
    1819         201 :             pTmpFrm->InsertBefore( pUp, pOldNext );
    1820             :         }
    1821             :         else
    1822             :         {
    1823        2425 :             bRet = pFrm->WouldFit( nSpace, bSplit, false );
    1824        2425 :             nSecondCheck = !bSplit ? 1 : 0;
    1825             :         }
    1826             : 
    1827        2626 :         SwBorderAttrAccess aAccess( SwFrm::GetCache(), pFrm );
    1828        2626 :         const SwBorderAttrs &rAttrs = *aAccess.Get();
    1829             : 
    1830             :         // Sad but true: We need to consider the spacing in our calculation.
    1831             :         // This already happened in TestFormat.
    1832        2626 :         if ( bRet && !bTstMove )
    1833             :         {
    1834             :             SwTwips nUpper;
    1835             : 
    1836        2482 :             if ( pTmpPrev )
    1837             :             {
    1838        2095 :                 nUpper = CalcUpperSpace( NULL, pTmpPrev );
    1839             : 
    1840             :                 // in balanced columned section frames we do not want the
    1841             :                 // common border
    1842        2095 :                 sal_Bool bCommonBorder = sal_True;
    1843        2095 :                 if ( pFrm->IsInSct() && pFrm->GetUpper()->IsColBodyFrm() )
    1844             :                 {
    1845          88 :                     const SwSectionFrm* pSct = pFrm->FindSctFrm();
    1846          88 :                     bCommonBorder = pSct->GetFmt()->GetBalancedColumns().GetValue();
    1847             :                 }
    1848             : 
    1849             :                 // #i46181#
    1850        2004 :                 nSecondCheck = ( 1 == nSecondCheck &&
    1851        1964 :                                  pFrm == this &&
    1852        3928 :                                  IsTxtFrm() &&
    1853        1964 :                                  bCommonBorder &&
    1854        1964 :                                  !static_cast<const SwTxtFrm*>(this)->IsEmpty() ) ?
    1855             :                                  nUpper :
    1856        2700 :                                  0;
    1857             : 
    1858             :                 nUpper += bCommonBorder ?
    1859        2007 :                           rAttrs.GetBottomLine( *(pFrm) ) :
    1860        4102 :                           rAttrs.CalcBottomLine();
    1861             : 
    1862             :             }
    1863             :             else
    1864             :             {
    1865             :                 // #i46181#
    1866         387 :                 nSecondCheck = 0;
    1867             : 
    1868         387 :                 if( pFrm->IsVertical() )
    1869           0 :                     nUpper = pFrm->Frm().Width() - pFrm->Prt().Width();
    1870             :                 else
    1871         387 :                     nUpper = pFrm->Frm().Height() - pFrm->Prt().Height();
    1872             :             }
    1873             : 
    1874        2482 :             nSpace -= nUpper;
    1875             : 
    1876        2482 :             if ( nSpace < 0 )
    1877             :             {
    1878          23 :                 bRet = sal_False;
    1879             : 
    1880             :                 // #i46181#
    1881          23 :                 if ( nSecondCheck > 0 )
    1882             :                 {
    1883             :                     // The following code is intended to solve a (rare) problem
    1884             :                     // causing some frames not to move backward:
    1885             :                     // SwTxtFrm::WouldFit() claims that the whole paragraph
    1886             :                     // fits into the given space and subtracts the height of
    1887             :                     // all lines from nSpace. nSpace - nUpper is not a valid
    1888             :                     // indicator if the frame should be allowed to move backward.
    1889             :                     // We do a second check with the original remaining space
    1890             :                     // reduced by the required upper space:
    1891           9 :                     nOldSpace -= nSecondCheck;
    1892           9 :                     const bool bSecondRet = nOldSpace >= 0 && pFrm->WouldFit( nOldSpace, bOldSplit, false );
    1893           9 :                     if ( bSecondRet && bOldSplit && nOldSpace >= 0 )
    1894             :                     {
    1895           0 :                         bRet = sal_True;
    1896           0 :                         bSplit = true;
    1897             :                     }
    1898             :                 }
    1899             :             }
    1900             :         }
    1901             : 
    1902             :         // OD 2004-03-01 #106629# - also consider lower spacing in table cells
    1903        2626 :         if ( bRet && IsInTab() &&
    1904           0 :              pNewUpper->GetFmt()->getIDocumentSettingAccess()->get(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS) )
    1905             :         {
    1906           0 :             nSpace -= rAttrs.GetULSpace().GetLower();
    1907           0 :             if ( nSpace < 0 )
    1908             :             {
    1909           0 :                 bRet = sal_False;
    1910             :             }
    1911             :         }
    1912             : 
    1913        2626 :         if ( bRet && !bSplit && pFrm->IsKeep( rAttrs.GetAttrSet() ) )
    1914             :         {
    1915         409 :             if( bTstMove )
    1916             :             {
    1917           0 :                 while( pFrm->IsTxtFrm() && ((SwTxtFrm*)pFrm)->HasFollow() )
    1918             :                 {
    1919           0 :                     pFrm = ((SwTxtFrm*)pFrm)->GetFollow();
    1920             :                 }
    1921             :                 // OD 11.04.2003 #108824# - If last follow frame of <this> text
    1922             :                 // frame isn't valid, a formatting of the next content frame
    1923             :                 // doesn't makes sense. Thus, return sal_True.
    1924           0 :                 if ( IsAnFollow( pFrm ) && !pFrm->IsValid() )
    1925             :                 {
    1926             :                     OSL_FAIL( "Only a warning for task 108824:/n<SwCntntFrm::_WouldFit(..) - follow not valid!" );
    1927           0 :                     return sal_True;
    1928             :                 }
    1929             :             }
    1930             :             SwFrm *pNxt;
    1931         811 :             if( 0 != (pNxt = pFrm->FindNext()) && pNxt->IsCntntFrm() &&
    1932           0 :                 ( !pFtnFrm || ( pNxt->IsInFtn() &&
    1933           0 :                   pNxt->FindFtnFrm()->GetAttr() == pFtnFrm->GetAttr() ) ) )
    1934             :             {
    1935             :                 // TestFormat(?) does not like paragraph- or character anchored objects.
    1936             : 
    1937             :                 // current solution for the test formatting doesn't work, if
    1938             :                 // objects are present in the remaining area of the new upper
    1939         402 :                 if ( bTstMove &&
    1940           0 :                      ( pNxt->GetDrawObjs() || bObjsInNewUpper ) )
    1941             :                 {
    1942           0 :                     return sal_True;
    1943             :                 }
    1944             : 
    1945         402 :                 if ( !pNxt->IsValid() )
    1946         402 :                     MakeNxt( pFrm, pNxt );
    1947             : 
    1948             :                 // Little trick: if the next has a predecessor, then the paragraph
    1949             :                 // spacing has been calculated already, and we don't need to re-calculate
    1950             :                 // it in an expensive way.
    1951         402 :                 if( lcl_NotHiddenPrev( pNxt ) )
    1952         362 :                     pTmpPrev = 0;
    1953             :                 else
    1954             :                 {
    1955          40 :                     if( pFrm->IsTxtFrm() && ((SwTxtFrm*)pFrm)->IsHiddenNow() )
    1956           0 :                         pTmpPrev = lcl_NotHiddenPrev( pFrm );
    1957             :                     else
    1958          40 :                         pTmpPrev = pFrm;
    1959             :                 }
    1960         402 :                 pFrm = (SwCntntFrm*)pNxt;
    1961             :             }
    1962             :             else
    1963           7 :                 pFrm = 0;
    1964             :         }
    1965             :         else
    1966        2217 :             pFrm = 0;
    1967             : 
    1968        2561 :     } while ( bRet && pFrm );
    1969             : 
    1970        2224 :     return bRet;
    1971             : }
    1972             : 
    1973             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10