LCOV - code coverage report
Current view: top level - sw/source/core/layout - findfrm.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 641 773 82.9 %
Date: 2014-04-11 Functions: 45 46 97.8 %
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 "pagefrm.hxx"
      21             : #include "rootfrm.hxx"
      22             : #include <cellfrm.hxx>
      23             : #include <rowfrm.hxx>
      24             : #include <swtable.hxx>
      25             : 
      26             : #include "tabfrm.hxx"
      27             : #include "sectfrm.hxx"
      28             : #include "flyfrms.hxx"
      29             : #include "ftnfrm.hxx"
      30             : #include "txtftn.hxx"
      31             : #include "fmtftn.hxx"
      32             : #include <txtfrm.hxx>
      33             : #include <switerator.hxx>
      34             : 
      35             : /// Searches the first CntntFrm in BodyText below the page.
      36       50640 : SwLayoutFrm *SwFtnBossFrm::FindBodyCont()
      37             : {
      38       50640 :     SwFrm *pLay = Lower();
      39      109181 :     while ( pLay && !pLay->IsBodyFrm() )
      40        7901 :         pLay = pLay->GetNext();
      41       50640 :     return (SwLayoutFrm*)pLay;
      42             : }
      43             : 
      44             : /// Searches the last CntntFrm in BodyText below the page.
      45           2 : SwCntntFrm *SwPageFrm::FindLastBodyCntnt()
      46             : {
      47           2 :     SwCntntFrm *pRet = FindFirstBodyCntnt();
      48           2 :     SwCntntFrm *pNxt = pRet;
      49          16 :     while ( pNxt && pNxt->IsInDocBody() && IsAnLower( pNxt ) )
      50          12 :     {   pRet = pNxt;
      51          12 :         pNxt = pNxt->FindNextCnt();
      52             :     }
      53           2 :     return pRet;
      54             : }
      55             : 
      56             : /**
      57             :  * Checks if the frame contains one or more CntntFrm's anywhere in his
      58             :  * subsidiary structure; if so the first found CntntFrm is returned.
      59             :  */
      60      116343 : const SwCntntFrm *SwLayoutFrm::ContainsCntnt() const
      61             : {
      62             :     //Search downwards the layout leaf and if there is no content, jump to the
      63             :     //next leaf until content is found or we leave "this".
      64             :     //Sections: Cntnt next to sections would not be found this way (empty
      65             :     //sections directly next to CntntFrm) therefore we need to recursively
      66             :     //search for them even if it's more complex.
      67             : 
      68      116343 :     const SwLayoutFrm *pLayLeaf = this;
      69        4526 :     do
      70             :     {
      71      676185 :         while ( (!pLayLeaf->IsSctFrm() || pLayLeaf == this ) &&
      72      530854 :                 pLayLeaf->Lower() && pLayLeaf->Lower()->IsLayoutFrm() )
      73       62792 :             pLayLeaf = (SwLayoutFrm*)pLayLeaf->Lower();
      74             : 
      75      120869 :         if( pLayLeaf->IsSctFrm() && pLayLeaf != this )
      76             :         {
      77        2285 :             const SwCntntFrm *pCnt = pLayLeaf->ContainsCntnt();
      78        2285 :             if( pCnt )
      79        1189 :                 return pCnt;
      80        1096 :             if( pLayLeaf->GetNext() )
      81             :             {
      82         951 :                 if( pLayLeaf->GetNext()->IsLayoutFrm() )
      83             :                 {
      84         900 :                     pLayLeaf = (SwLayoutFrm*)pLayLeaf->GetNext();
      85         900 :                     continue;
      86             :                 }
      87             :                 else
      88          51 :                     return (SwCntntFrm*)pLayLeaf->GetNext();
      89             :             }
      90             :         }
      91      118584 :         else if ( pLayLeaf->Lower() )
      92      103025 :             return (SwCntntFrm*)pLayLeaf->Lower();
      93             : 
      94       15704 :         pLayLeaf = pLayLeaf->GetNextLayoutLeaf();
      95       15704 :         if( !IsAnLower( pLayLeaf) )
      96       12078 :             return 0;
      97             :     } while( pLayLeaf );
      98           0 :     return 0;
      99             : }
     100             : 
     101             : /**
     102             :  * Calls ContainsAny first to reach the innermost cell. From there we walk back
     103             :  * up to the first SwCellFrm. Since we use SectionFrms, ContainsCntnt()->GetUpper()
     104             :  * is not enough anymore.
     105             :  */
     106          56 : const SwCellFrm *SwLayoutFrm::FirstCell() const
     107             : {
     108          56 :     const SwFrm* pCnt = ContainsAny();
     109         168 :     while( pCnt && !pCnt->IsCellFrm() )
     110          56 :         pCnt = pCnt->GetUpper();
     111          56 :     return (const SwCellFrm*)pCnt;
     112             : }
     113             : 
     114             : /** return CntntFrms, sections, and tables.
     115             :  *
     116             :  * @param _bInvestigateFtnForSections controls investigation of content of footnotes for sections.
     117             :  * @see ContainsCntnt
     118             :  */
     119        5232 : const SwFrm *SwLayoutFrm::ContainsAny( const bool _bInvestigateFtnForSections ) const
     120             : {
     121             :     //Search downwards the layout leaf and if there is no content, jump to the
     122             :     //next leaf until content is found, we leave "this" or until we found
     123             :     //a SectionFrm or a TabFrm.
     124             : 
     125        5232 :     const SwLayoutFrm *pLayLeaf = this;
     126             :     // #130797#
     127        5232 :     const bool bNoFtn = IsSctFrm() && !_bInvestigateFtnForSections;
     128        1563 :     do
     129             :     {
     130       38153 :         while ( ( (!pLayLeaf->IsSctFrm() && !pLayLeaf->IsTabFrm())
     131       16798 :                  || pLayLeaf == this ) &&
     132       33400 :                 pLayLeaf->Lower() && pLayLeaf->Lower()->IsLayoutFrm() )
     133        5238 :             pLayLeaf = (SwLayoutFrm*)pLayLeaf->Lower();
     134             : 
     135       20373 :         if( ( pLayLeaf->IsTabFrm() || pLayLeaf->IsSctFrm() )
     136        8969 :             && pLayLeaf != this )
     137             :         {
     138             :             // Now we also return "deleted" SectionFrms so they can be
     139             :             // maintained on SaveCntnt and RestoreCntnt
     140          16 :             return pLayLeaf;
     141             :         }
     142        6779 :         else if ( pLayLeaf->Lower() )
     143        4112 :             return (SwCntntFrm*)pLayLeaf->Lower();
     144             : 
     145        2667 :         pLayLeaf = pLayLeaf->GetNextLayoutLeaf();
     146        2667 :         if( bNoFtn && pLayLeaf && pLayLeaf->IsInFtn() )
     147             :         {
     148           0 :             do
     149             :             {
     150           0 :                 pLayLeaf = pLayLeaf->GetNextLayoutLeaf();
     151           0 :             } while( pLayLeaf && pLayLeaf->IsInFtn() );
     152             :         }
     153        2667 :         if( !IsAnLower( pLayLeaf) )
     154        1104 :             return 0;
     155             :     } while( pLayLeaf );
     156           0 :     return 0;
     157             : }
     158             : 
     159       34290 : const SwFrm* SwFrm::GetLower() const
     160             : {
     161       34290 :     return IsLayoutFrm() ? ((SwLayoutFrm*)this)->Lower() : 0;
     162             : }
     163             : 
     164       34800 : SwFrm* SwFrm::GetLower()
     165             : {
     166       34800 :     return IsLayoutFrm() ? ((SwLayoutFrm*)this)->Lower() : 0;
     167             : }
     168             : 
     169      496704 : sal_Bool SwLayoutFrm::IsAnLower( const SwFrm *pAssumed ) const
     170             : {
     171      496704 :     const SwFrm *pUp = pAssumed;
     172     2706701 :     while ( pUp )
     173             :     {
     174     1981322 :         if ( pUp == this )
     175      268029 :             return sal_True;
     176     1713293 :         if ( pUp->IsFlyFrm() )
     177       17962 :             pUp = ((SwFlyFrm*)pUp)->GetAnchorFrm();
     178             :         else
     179     1695331 :             pUp = pUp->GetUpper();
     180             :     }
     181      228675 :     return sal_False;
     182             : }
     183             : 
     184             : /** method to check relative position of layout frame to
     185             :     a given layout frame.
     186             : 
     187             :     OD 08.11.2002 - refactoring of pseudo-local method <lcl_Apres(..)> in
     188             :     <txtftn.cxx> for #104840#.
     189             : 
     190             :     @param _aCheckRefLayFrm
     191             :     constant reference of an instance of class <SwLayoutFrm> which
     192             :     is used as the reference for the relative position check.
     193             : 
     194             :     @return true, if <this> is positioned before the layout frame <p>
     195             : */
     196          30 : bool SwLayoutFrm::IsBefore( const SwLayoutFrm* _pCheckRefLayFrm ) const
     197             : {
     198             :     OSL_ENSURE( !IsRootFrm() , "<IsBefore> called at a <SwRootFrm>.");
     199             :     OSL_ENSURE( !_pCheckRefLayFrm->IsRootFrm() , "<IsBefore> called with a <SwRootFrm>.");
     200             : 
     201             :     bool bReturn;
     202             : 
     203             :     // check, if on different pages
     204          30 :     const SwPageFrm *pMyPage = FindPageFrm();
     205          30 :     const SwPageFrm *pCheckRefPage = _pCheckRefLayFrm->FindPageFrm();
     206          30 :     if( pMyPage != pCheckRefPage )
     207             :     {
     208             :         // being on different page as check reference
     209          30 :         bReturn = pMyPage->GetPhyPageNum() < pCheckRefPage->GetPhyPageNum();
     210             :     }
     211             :     else
     212             :     {
     213             :         // being on same page as check reference
     214             :         // --> search my supreme parent <pUp>, which doesn't contain check reference.
     215           0 :         const SwLayoutFrm* pUp = this;
     216           0 :         while ( pUp->GetUpper() &&
     217           0 :                 !pUp->GetUpper()->IsAnLower( _pCheckRefLayFrm )
     218             :               )
     219           0 :             pUp = pUp->GetUpper();
     220           0 :         if( !pUp->GetUpper() )
     221             :         {
     222             :             // can occur, if <this> is a fly frm
     223           0 :             bReturn = false;
     224             :         }
     225             :         else
     226             :         {
     227             :             // travel through the next's of <pUp> and check if one of these
     228             :             // contain the check reference.
     229           0 :             SwLayoutFrm* pUpNext = (SwLayoutFrm*)pUp->GetNext();
     230           0 :             while ( pUpNext &&
     231           0 :                     !pUpNext->IsAnLower( _pCheckRefLayFrm ) )
     232             :             {
     233           0 :                 pUpNext = (SwLayoutFrm*)pUpNext->GetNext();
     234             :             }
     235           0 :             bReturn = pUpNext != 0;
     236             :         }
     237             :     }
     238             : 
     239          30 :     return bReturn;
     240             : }
     241             : 
     242             : // Local helper functions for GetNextLayoutLeaf
     243             : 
     244     1561106 : static const SwFrm* lcl_FindLayoutFrame( const SwFrm* pFrm, bool bNext )
     245             : {
     246     1561106 :     const SwFrm* pRet = 0;
     247     1561106 :     if ( pFrm->IsFlyFrm() )
     248       23010 :         pRet = bNext ? ((SwFlyFrm*)pFrm)->GetNextLink() : ((SwFlyFrm*)pFrm)->GetPrevLink();
     249             :     else
     250     1538096 :         pRet = bNext ? pFrm->GetNext() : pFrm->GetPrev();
     251             : 
     252     1561106 :     return pRet;
     253             : }
     254             : 
     255     1448590 : static const SwFrm* lcl_GetLower( const SwFrm* pFrm, bool bFwd )
     256             : {
     257     1448590 :     if ( !pFrm->IsLayoutFrm() )
     258      545482 :         return 0;
     259             : 
     260             :     return bFwd ?
     261             :            static_cast<const SwLayoutFrm*>(pFrm)->Lower() :
     262      903108 :            static_cast<const SwLayoutFrm*>(pFrm)->GetLastLower();
     263             : }
     264             : 
     265             : /**
     266             :  * Finds the next layout leaf. This is a layout frame, which does not
     267             :  * have a lower which is a LayoutFrame. That means, pLower can be 0 or a
     268             :  * content frame.
     269             :  *
     270             :  * However, pLower may be a TabFrm
     271             :  */
     272       62823 : const SwLayoutFrm *SwFrm::ImplGetNextLayoutLeaf( bool bFwd ) const
     273             : {
     274       62823 :     const SwFrm       *pFrm = this;
     275       62823 :     const SwLayoutFrm *pLayoutFrm = 0;
     276       62823 :     const SwFrm       *p = 0;
     277       62823 :     bool bGoingUp = !bFwd;          // false for forward, true for backward
     278      186407 :     do {
     279             : 
     280      203567 :          bool bGoingFwdOrBwd = false;
     281             : 
     282      203567 :          bool bGoingDown = ( !bGoingUp && ( 0 != (p = lcl_GetLower( pFrm, bFwd ) ) ) );
     283      203567 :          if ( !bGoingDown )
     284             :          {
     285             :              // I cannot go down, because either I'm currently going up or
     286             :              // because the is no lower.
     287             :              // I'll try to go forward:
     288      172334 :              bGoingFwdOrBwd = (0 != (p = lcl_FindLayoutFrame( pFrm, bFwd ) ) );
     289      172334 :              if ( !bGoingFwdOrBwd )
     290             :              {
     291             :                  // I cannot go forward, because there is no next frame.
     292             :                  // I'll try to go up:
     293       94448 :                  bGoingUp = (0 != (p = pFrm->GetUpper() ) );
     294       94448 :                  if ( !bGoingUp )
     295             :                  {
     296             :                     // I cannot go up, because there is no upper frame.
     297       17160 :                     return 0;
     298             :                  }
     299             :              }
     300             :          }
     301             : 
     302             :         // If I could not go down or forward, I'll have to go up
     303      186407 :         bGoingUp = !bGoingFwdOrBwd && !bGoingDown;
     304             : 
     305      186407 :         pFrm = p;
     306      186407 :         p = lcl_GetLower( pFrm, true );
     307             : 
     308      133665 :     } while( ( p && !p->IsFlowFrm() ) ||
     309      103875 :              pFrm == this ||
     310      355308 :              0 == ( pLayoutFrm = pFrm->IsLayoutFrm() ? (SwLayoutFrm*)pFrm : 0 ) ||
     311       65026 :              pLayoutFrm->IsAnLower( this ) );
     312             : 
     313       45663 :     return pLayoutFrm;
     314             : }
     315             : 
     316             : /**
     317             :  * Walk back inside the tree: grab the subordinate Frm if one exists and the
     318             :  * last step was not moving up a level (this would lead to an infinite up/down
     319             :  * loop!). With this we ensure that during walking back we search through all
     320             :  * sub trees. If we walked downwards we have to go to the end of the chain first
     321             :  * because we go backwards from the last Frm inside another Frm. Walking
     322             :  * forward works the same.
     323             :  *
     324             :  * @warning fixes here may also need to be applied to the @{lcl_NextFrm} method above
     325             :  */
     326      467134 : const SwCntntFrm* SwCntntFrm::ImplGetNextCntntFrm( bool bFwd ) const
     327             : {
     328      467134 :     const SwFrm *pFrm = this;
     329             :     // #100926#
     330      467134 :     SwCntntFrm *pCntntFrm = 0;
     331      467134 :     bool bGoingUp = false;
     332     1944484 :     do {
     333     2011332 :         const SwFrm *p = 0;
     334     2011332 :         bool bGoingFwdOrBwd = false;
     335             : 
     336     2011332 :         bool bGoingDown = ( !bGoingUp && ( 0 != ( p = lcl_GetLower( pFrm, true ) ) ) );
     337     2011332 :         if ( !bGoingDown )
     338             :         {
     339     1388772 :             bGoingFwdOrBwd = ( 0 != ( p = lcl_FindLayoutFrame( pFrm, bFwd ) ) );
     340     1388772 :             if ( !bGoingFwdOrBwd )
     341             :             {
     342      905099 :                 bGoingUp = ( 0 != ( p = pFrm->GetUpper() ) );
     343      905099 :                 if ( !bGoingUp )
     344             :                 {
     345       66848 :                     return 0;
     346             :                 }
     347             :             }
     348             :         }
     349             : 
     350     1944484 :         bGoingUp = !(bGoingFwdOrBwd || bGoingDown);
     351             : 
     352     1944484 :         if ( !bFwd )
     353             :         {
     354     1194465 :             if( bGoingDown && p )
     355     1732393 :                 while ( p->GetNext() )
     356      958437 :                     p = p->GetNext();
     357             :         }
     358             : 
     359     1944484 :         pFrm = p;
     360     1944484 :     } while ( 0 == (pCntntFrm = (pFrm->IsCntntFrm() ? (SwCntntFrm*)pFrm:0) ));
     361             : 
     362      400286 :     return pCntntFrm;
     363             : }
     364             : 
     365     1094113 : SwPageFrm* SwFrm::FindPageFrm()
     366             : {
     367     1094113 :     SwFrm *pRet = this;
     368     5223173 :     while ( pRet && !pRet->IsPageFrm() )
     369             :     {
     370     3057418 :         if ( pRet->GetUpper() )
     371     2950128 :             pRet = pRet->GetUpper();
     372      107290 :         else if ( pRet->IsFlyFrm() )
     373             :         {
     374             :             // #i28701# - use new method <GetPageFrm()>
     375       84819 :             if ( static_cast<SwFlyFrm*>(pRet)->GetPageFrm() )
     376       67112 :                 pRet = static_cast<SwFlyFrm*>(pRet)->GetPageFrm();
     377             :             else
     378       17707 :                 pRet = static_cast<SwFlyFrm*>(pRet)->AnchorFrm();
     379             :         }
     380             :         else
     381       22471 :             return 0;
     382             :     }
     383     1071642 :     return (SwPageFrm*)pRet;
     384             : }
     385             : 
     386       26006 : SwFtnBossFrm* SwFrm::FindFtnBossFrm( sal_Bool bFootnotes )
     387             : {
     388       26006 :     SwFrm *pRet = this;
     389             :     // Footnote bosses can't exist inside a table; also sections with columns
     390             :     // don't contain footnote texts there
     391       26006 :     if( pRet->IsInTab() )
     392        3524 :         pRet = pRet->FindTabFrm();
     393      100776 :     while ( pRet && !pRet->IsFtnBossFrm() )
     394             :     {
     395       48764 :         if ( pRet->GetUpper() )
     396       46943 :             pRet = pRet->GetUpper();
     397        1821 :         else if ( pRet->IsFlyFrm() )
     398             :         {
     399             :             // #i28701# - use new method <GetPageFrm()>
     400        1821 :             if ( static_cast<SwFlyFrm*>(pRet)->GetPageFrm() )
     401        1760 :                 pRet = static_cast<SwFlyFrm*>(pRet)->GetPageFrm();
     402             :             else
     403          61 :                 pRet = static_cast<SwFlyFrm*>(pRet)->AnchorFrm();
     404             :         }
     405             :         else
     406           0 :             return 0;
     407             :     }
     408       32142 :     if( bFootnotes && pRet && pRet->IsColumnFrm() &&
     409       28435 :         !pRet->GetNext() && !pRet->GetPrev() )
     410             :     {
     411           0 :         SwSectionFrm* pSct = pRet->FindSctFrm();
     412             :         OSL_ENSURE( pSct, "FindFtnBossFrm: Single column outside section?" );
     413           0 :         if( !pSct->IsFtnAtEnd() )
     414           0 :             return pSct->FindFtnBossFrm( sal_True );
     415             :     }
     416       26006 :     return (SwFtnBossFrm*)pRet;
     417             : }
     418             : 
     419      295261 : SwTabFrm* SwFrm::ImplFindTabFrm()
     420             : {
     421      295261 :     SwFrm *pRet = this;
     422     1218700 :     while ( !pRet->IsTabFrm() )
     423             :     {
     424      628178 :         pRet = pRet->GetUpper();
     425      628178 :         if ( !pRet )
     426           0 :             return 0;
     427             :     }
     428      295261 :     return (SwTabFrm*)pRet;
     429             : }
     430             : 
     431       28231 : SwSectionFrm* SwFrm::ImplFindSctFrm()
     432             : {
     433       28231 :     SwFrm *pRet = this;
     434      114586 :     while ( !pRet->IsSctFrm() )
     435             :     {
     436       58124 :         pRet = pRet->GetUpper();
     437       58124 :         if ( !pRet )
     438           0 :             return 0;
     439             :     }
     440       28231 :     return (SwSectionFrm*)pRet;
     441             : }
     442             : 
     443        2943 : SwFtnFrm *SwFrm::ImplFindFtnFrm()
     444             : {
     445        2943 :     SwFrm *pRet = this;
     446        8489 :     while ( !pRet->IsFtnFrm() )
     447             :     {
     448        2724 :         pRet = pRet->GetUpper();
     449        2724 :         if ( !pRet )
     450         121 :             return 0;
     451             :     }
     452        2822 :     return (SwFtnFrm*)pRet;
     453             : }
     454             : 
     455      143751 : SwFlyFrm *SwFrm::ImplFindFlyFrm()
     456             : {
     457      143751 :     const SwFrm *pRet = this;
     458      593155 :     do
     459             :     {
     460      632483 :         if ( pRet->IsFlyFrm() )
     461       39328 :             return (SwFlyFrm*)pRet;
     462             :         else
     463      593155 :             pRet = pRet->GetUpper();
     464             :     } while ( pRet );
     465      104423 :     return 0;
     466             : }
     467             : 
     468       94592 : SwFrm *SwFrm::FindColFrm()
     469             : {
     470       94592 :     SwFrm *pFrm = this;
     471      333322 :     do
     472      333322 :     {   pFrm = pFrm->GetUpper();
     473      333322 :     } while ( pFrm && !pFrm->IsColumnFrm() );
     474       94592 :     return pFrm;
     475             : }
     476             : 
     477       51579 : SwRowFrm *SwFrm::FindRowFrm()
     478             : {
     479       51579 :     SwFrm *pFrm = this;
     480      202454 :     do
     481      202454 :     {   pFrm = pFrm->GetUpper();
     482      202454 :     } while ( pFrm && !pFrm->IsRowFrm() );
     483       51579 :     return dynamic_cast< SwRowFrm* >( pFrm );
     484             : }
     485             : 
     486       99358 : SwFrm* SwFrm::FindFooterOrHeader()
     487             : {
     488       99358 :     SwFrm* pRet = this;
     489      281211 :     do
     490      380569 :     {   if ( pRet->GetType() & 0x0018 ) //header and footer
     491       23986 :             return pRet;
     492      356583 :         else if ( pRet->GetUpper() )
     493      276033 :             pRet = pRet->GetUpper();
     494       80550 :         else if ( pRet->IsFlyFrm() )
     495        5178 :             pRet = ((SwFlyFrm*)pRet)->AnchorFrm();
     496             :         else
     497       75372 :             return 0;
     498             :     } while ( pRet );
     499           0 :     return pRet;
     500             : }
     501             : 
     502           0 : const SwFtnFrm* SwFtnContFrm::FindFootNote() const
     503             : {
     504           0 :     const SwFtnFrm* pRet = (SwFtnFrm*)Lower();
     505           0 :     if( pRet && !pRet->GetAttr()->GetFtn().IsEndNote() )
     506           0 :         return pRet;
     507           0 :     return NULL;
     508             : }
     509             : 
     510        1644 : const SwPageFrm* SwRootFrm::GetPageAtPos( const Point& rPt, const Size* pSize, bool bExtend ) const
     511             : {
     512        1644 :     const SwPageFrm* pRet = 0;
     513             : 
     514        1644 :     SwRect aRect;
     515        1644 :     if ( pSize )
     516             :     {
     517         161 :         aRect.Pos()  = rPt;
     518         161 :         aRect.SSize() = *pSize;
     519             :     }
     520             : 
     521        1644 :     const SwFrm* pPage = Lower();
     522             : 
     523        1644 :     if ( !bExtend )
     524             :     {
     525        1224 :         if( !Frm().IsInside( rPt ) )
     526        1224 :             return 0;
     527             : 
     528             :         // skip pages above point:
     529           0 :         while( pPage && rPt.Y() > pPage->Frm().Bottom() )
     530           0 :             pPage = pPage->GetNext();
     531             :     }
     532             : 
     533             :     OSL_ENSURE( GetPageNum() <= maPageRects.size(), "number of pages differes from page rect array size" );
     534         420 :     sal_uInt16 nPageIdx = 0;
     535             : 
     536        1262 :     while ( pPage && !pRet )
     537             :     {
     538         422 :         const SwRect& rBoundRect = bExtend ? maPageRects[ nPageIdx++ ] : pPage->Frm();
     539             : 
     540         840 :         if ( (!pSize && rBoundRect.IsInside(rPt)) ||
     541         163 :               (pSize && rBoundRect.IsOver(aRect)) )
     542             :         {
     543         418 :             pRet = static_cast<const SwPageFrm*>(pPage);
     544             :         }
     545             : 
     546         422 :         pPage = pPage->GetNext();
     547             :     }
     548             : 
     549         420 :     return pRet;
     550             : }
     551             : 
     552      686557 : const SwAttrSet* SwFrm::GetAttrSet() const
     553             : {
     554      686557 :     if ( IsCntntFrm() )
     555      539849 :         return &((const SwCntntFrm*)this)->GetNode()->GetSwAttrSet();
     556             :     else
     557      146708 :         return &((const SwLayoutFrm*)this)->GetFmt()->GetAttrSet();
     558             : }
     559             : 
     560             : /*************************************************************************
     561             : |*
     562             : |*  SwFrm::_FindNext(), _FindPrev(), InvalidateNextPos()
     563             : |*         _FindNextCnt() visits tables and sections and only returns SwCntntFrms.
     564             : |*
     565             : |*  Description         Invalidates the position of the next frame.
     566             : |*      This is the direct successor or in case of CntntFrms the next
     567             : |*      CntntFrm which sits in the same flow as I do:
     568             : |*      - body,
     569             : |*      - footnote,
     570             : |*      - in headers/footers the notification only needs to be forwarded
     571             : |*        inside the section
     572             : |*      - same for Flys
     573             : |*      - Cntnts in tabs remain only inside their cell
     574             : |*      - in principle tables behave exactly like the Cntnts
     575             : |*      - sections also
     576             : |*************************************************************************/
     577             : 
     578             : // This helper function is an equivalent to the ImplGetNextCntntFrm() method,
     579             : // besides ContentFrames this function also returns TabFrms and SectionFrms.
     580      164450 : static SwFrm* lcl_NextFrm( SwFrm* pFrm )
     581             : {
     582      164450 :     SwFrm *pRet = 0;
     583      164450 :     bool bGoingUp = false;
     584      532855 :     do {
     585      549229 :         SwFrm *p = 0;
     586             : 
     587      549229 :         bool bGoingFwd = false;
     588      549229 :         bool bGoingDown = (!bGoingUp && ( 0 != (p = pFrm->IsLayoutFrm() ? ((SwLayoutFrm*)pFrm)->Lower() : 0)));
     589             : 
     590      549229 :         if( !bGoingDown )
     591             :         {
     592      395223 :             bGoingFwd = (0 != (p = ( pFrm->IsFlyFrm() ? ((SwFlyFrm*)pFrm)->GetNextLink() : pFrm->GetNext())));
     593      395223 :             if ( !bGoingFwd )
     594             :             {
     595      228230 :                 bGoingUp = (0 != (p = pFrm->GetUpper()));
     596      228230 :                 if ( !bGoingUp )
     597             :                 {
     598       16374 :                     return 0;
     599             :                 }
     600             :             }
     601             :         }
     602      532855 :         bGoingUp = !(bGoingFwd || bGoingDown);
     603      532855 :         pFrm = p;
     604      864012 :     } while ( 0 == (pRet = ( ( pFrm->IsCntntFrm() || ( !bGoingUp &&
     605      358721 :             ( pFrm->IsTabFrm() || pFrm->IsSctFrm() ) ) )? pFrm : 0 ) ) );
     606      148076 :     return pRet;
     607             : }
     608             : 
     609       70642 : SwFrm *SwFrm::_FindNext()
     610             : {
     611       70642 :     bool bIgnoreTab = false;
     612       70642 :     SwFrm *pThis = this;
     613             : 
     614       70642 :     if ( IsTabFrm() )
     615             :     {
     616             :         //The last Cntnt of the table gets picked up and his follower is
     617             :         //returned. To be able to deactivate the special case for tables
     618             :         //(see below) bIgnoreTab will be set.
     619        2762 :         if ( ((SwTabFrm*)this)->GetFollow() )
     620         491 :             return ((SwTabFrm*)this)->GetFollow();
     621             : 
     622        2271 :         pThis = ((SwTabFrm*)this)->FindLastCntnt();
     623        2271 :         if ( !pThis )
     624           6 :             pThis = this;
     625        2271 :         bIgnoreTab = true;
     626             :     }
     627       67880 :     else if ( IsSctFrm() )
     628             :     {
     629             :         //The last Cntnt of the section gets picked and his follower is returned.
     630        1471 :         if ( ((SwSectionFrm*)this)->GetFollow() )
     631          93 :             return ((SwSectionFrm*)this)->GetFollow();
     632             : 
     633        1378 :         pThis = ((SwSectionFrm*)this)->FindLastCntnt();
     634        1378 :         if ( !pThis )
     635         989 :             pThis = this;
     636             :     }
     637       66409 :     else if ( IsCntntFrm() )
     638             :     {
     639       50846 :         if( ((SwCntntFrm*)this)->GetFollow() )
     640         488 :             return ((SwCntntFrm*)this)->GetFollow();
     641             :     }
     642       15563 :     else if ( IsRowFrm() )
     643             :     {
     644         884 :         SwFrm* pMyUpper = GetUpper();
     645         884 :         if ( pMyUpper->IsTabFrm() && ((SwTabFrm*)pMyUpper)->GetFollow() )
     646          60 :             return ((SwTabFrm*)pMyUpper)->GetFollow()->GetLower();
     647         824 :         else return NULL;
     648             :     }
     649             :     else
     650       14679 :         return NULL;
     651             : 
     652       54007 :     SwFrm* pRet = NULL;
     653       54007 :     const sal_Bool bFtn  = pThis->IsInFtn();
     654       54007 :     if ( !bIgnoreTab && pThis->IsInTab() )
     655             :     {
     656       21791 :         SwLayoutFrm *pUp = pThis->GetUpper();
     657       43583 :         while ( !pUp->IsCellFrm() )
     658           1 :             pUp = pUp->GetUpper();
     659             :         OSL_ENSURE( pUp, "Cntnt in Tabelle aber nicht in Zelle." );
     660       21791 :         SwFrm* pNxt = ((SwCellFrm*)pUp)->GetFollowCell();
     661       21791 :         if ( pNxt )
     662         391 :             pNxt = ((SwCellFrm*)pNxt)->ContainsCntnt();
     663       21791 :         if ( !pNxt )
     664             :         {
     665       21788 :             pNxt = lcl_NextFrm( pThis );
     666       21788 :             if ( pUp->IsAnLower( pNxt ) )
     667           1 :                 pRet = pNxt;
     668             :         }
     669             :         else
     670           3 :             pRet = pNxt;
     671             :     }
     672             :     else
     673             :     {
     674       32216 :         const bool bBody = pThis->IsInDocBody();
     675       32216 :         SwFrm *pNxtCnt = lcl_NextFrm( pThis );
     676       32216 :         if ( pNxtCnt )
     677             :         {
     678       16735 :             if ( bBody || bFtn )
     679             :             {
     680      139694 :                 while ( pNxtCnt )
     681             :                 {
     682             :                     // OD 02.04.2003 #108446# - check for endnote, only if found
     683             :                     // next content isn't contained in a section, that collect its
     684             :                     // endnotes at its end.
     685      133930 :                     bool bEndn = IsInSct() && !IsSctFrm() &&
     686        8317 :                                  ( !pNxtCnt->IsInSct() ||
     687        3482 :                                    !pNxtCnt->FindSctFrm()->IsEndnAtEnd()
     688      124264 :                                  );
     689      248587 :                     if ( ( bBody && pNxtCnt->IsInDocBody() ) ||
     690      110712 :                          ( pNxtCnt->IsInFtn() &&
     691         154 :                            ( bFtn ||
     692          12 :                              ( bEndn && pNxtCnt->FindFtnFrm()->GetAttr()->GetFtn().IsEndNote() )
     693             :                            )
     694             :                          )
     695             :                        )
     696             :                     {
     697       13818 :                         pRet = pNxtCnt->IsInTab() ? pNxtCnt->FindTabFrm()
     698       13818 :                                                     : (SwFrm*)pNxtCnt;
     699       13818 :                         break;
     700             :                     }
     701      110446 :                     pNxtCnt = lcl_NextFrm( pNxtCnt );
     702       14624 :                 }
     703             :             }
     704        2111 :             else if ( pThis->IsInFly() )
     705             :             {
     706           6 :                 pRet = pNxtCnt->IsInTab() ? pNxtCnt->FindTabFrm()
     707           6 :                                             : (SwFrm*)pNxtCnt;
     708             :             }
     709             :             else    //footer-/or header section
     710             :             {
     711        2105 :                 const SwFrm *pUp = pThis->GetUpper();
     712        2105 :                 const SwFrm *pCntUp = pNxtCnt->GetUpper();
     713        8429 :                 while ( pUp && pUp->GetUpper() &&
     714        4288 :                         !pUp->IsHeaderFrm() && !pUp->IsFooterFrm() )
     715           3 :                     pUp = pUp->GetUpper();
     716        9316 :                 while ( pCntUp && pCntUp->GetUpper() &&
     717        6986 :                         !pCntUp->IsHeaderFrm() && !pCntUp->IsFooterFrm() )
     718         358 :                     pCntUp = pCntUp->GetUpper();
     719        2105 :                 if ( pCntUp == pUp )
     720             :                 {
     721           0 :                     pRet = pNxtCnt->IsInTab() ? pNxtCnt->FindTabFrm()
     722           0 :                                                 : (SwFrm*)pNxtCnt;
     723             :                 }
     724             :             }
     725             :         }
     726             :     }
     727       54007 :     if( pRet && pRet->IsInSct() )
     728             :     {
     729        3677 :         SwSectionFrm* pSct = pRet->FindSctFrm();
     730             :         //Footnotes in frames with columns must not return the section which
     731             :         //contains the footnote
     732        6371 :         if( !pSct->IsAnLower( this ) &&
     733           0 :             (!bFtn || pSct->IsInFtn() ) )
     734        2694 :             return pSct;
     735             :     }
     736       51313 :     return pRet;
     737             : }
     738             : 
     739             : // #i27138# - add parameter <_bInSameFtn>
     740       49265 : SwCntntFrm *SwFrm::_FindNextCnt( const bool _bInSameFtn )
     741             : {
     742       49265 :     SwFrm *pThis = this;
     743             : 
     744       49265 :     if ( IsTabFrm() )
     745             :     {
     746        1245 :         if ( ((SwTabFrm*)this)->GetFollow() )
     747             :         {
     748         653 :             pThis = ((SwTabFrm*)this)->GetFollow()->ContainsCntnt();
     749         653 :             if( pThis )
     750         231 :                 return (SwCntntFrm*)pThis;
     751             :         }
     752        1014 :         pThis = ((SwTabFrm*)this)->FindLastCntnt();
     753        1014 :         if ( !pThis )
     754           0 :             return 0;
     755             :     }
     756       48020 :     else if ( IsSctFrm() )
     757             :     {
     758           0 :         if ( ((SwSectionFrm*)this)->GetFollow() )
     759             :         {
     760           0 :             pThis = ((SwSectionFrm*)this)->GetFollow()->ContainsCntnt();
     761           0 :             if( pThis )
     762           0 :                 return (SwCntntFrm*)pThis;
     763             :         }
     764           0 :         pThis = ((SwSectionFrm*)this)->FindLastCntnt();
     765           0 :         if ( !pThis )
     766           0 :             return 0;
     767             :     }
     768       48020 :     else if ( IsCntntFrm() && ((SwCntntFrm*)this)->GetFollow() )
     769         437 :         return ((SwCntntFrm*)this)->GetFollow();
     770             : 
     771       48597 :     if ( pThis->IsCntntFrm() )
     772             :     {
     773       48597 :         const bool bBody = pThis->IsInDocBody();
     774       48597 :         const sal_Bool bFtn  = pThis->IsInFtn();
     775       48597 :         SwCntntFrm *pNxtCnt = ((SwCntntFrm*)pThis)->GetNextCntntFrm();
     776       48597 :         if ( pNxtCnt )
     777             :         {
     778             :             // #i27138#
     779       44374 :             if ( bBody || ( bFtn && !_bInSameFtn ) )
     780             :             {
     781             :                 // handling for environments 'footnotes' and 'document body frames':
     782      121482 :                 while ( pNxtCnt )
     783             :                 {
     784      120962 :                     if ( (bBody && pNxtCnt->IsInDocBody()) ||
     785         638 :                          (bFtn  && pNxtCnt->IsInFtn()) )
     786       40919 :                         return pNxtCnt;
     787       39124 :                     pNxtCnt = pNxtCnt->GetNextCntntFrm();
     788             :                 }
     789             :             }
     790             :             // #i27138#
     791        2935 :             else if ( bFtn && _bInSameFtn )
     792             :             {
     793             :                 // handling for environments 'each footnote':
     794             :                 // Assure that found next content frame belongs to the same footnotes
     795           0 :                 const SwFtnFrm* pFtnFrmOfNext( pNxtCnt->FindFtnFrm() );
     796           0 :                 const SwFtnFrm* pFtnFrmOfCurr( pThis->FindFtnFrm() );
     797             :                 OSL_ENSURE( pFtnFrmOfCurr,
     798             :                         "<SwFrm::_FindNextCnt() - unknown layout situation: current frame has to have an upper footnote frame." );
     799           0 :                 if ( pFtnFrmOfNext == pFtnFrmOfCurr )
     800             :                 {
     801           0 :                     return pNxtCnt;
     802             :                 }
     803           0 :                 else if ( pFtnFrmOfCurr->GetFollow() )
     804             :                 {
     805             :                     // next content frame has to be the first content frame
     806             :                     // in the follow footnote, which contains a content frame.
     807             :                     SwFtnFrm* pFollowFtnFrmOfCurr(
     808           0 :                                         const_cast<SwFtnFrm*>(pFtnFrmOfCurr) );
     809           0 :                     pNxtCnt = 0L;
     810           0 :                     do {
     811           0 :                         pFollowFtnFrmOfCurr = pFollowFtnFrmOfCurr->GetFollow();
     812           0 :                         pNxtCnt = pFollowFtnFrmOfCurr->ContainsCntnt();
     813           0 :                     } while ( !pNxtCnt && pFollowFtnFrmOfCurr->GetFollow() );
     814           0 :                     return pNxtCnt;
     815             :                 }
     816             :                 else
     817             :                 {
     818             :                     // current content frame is the last content frame in the
     819             :                     // footnote - no next content frame exists.
     820           0 :                     return 0L;
     821             :                 }
     822             :             }
     823        2935 :             else if ( pThis->IsInFly() )
     824             :                 // handling for environments 'unlinked fly frame' and
     825             :                 // 'group of linked fly frames':
     826        1621 :                 return pNxtCnt;
     827             :             else
     828             :             {
     829             :                 // handling for environments 'page header' and 'page footer':
     830        1314 :                 const SwFrm *pUp = pThis->GetUpper();
     831        1314 :                 const SwFrm *pCntUp = pNxtCnt->GetUpper();
     832       12843 :                 while ( pUp && pUp->GetUpper() &&
     833       10313 :                         !pUp->IsHeaderFrm() && !pUp->IsFooterFrm() )
     834        2529 :                     pUp = pUp->GetUpper();
     835       11392 :                 while ( pCntUp && pCntUp->GetUpper() &&
     836        9306 :                         !pCntUp->IsHeaderFrm() && !pCntUp->IsFooterFrm() )
     837        2054 :                     pCntUp = pCntUp->GetUpper();
     838        1314 :                 if ( pCntUp == pUp )
     839         838 :                     return pNxtCnt;
     840             :             }
     841             :         }
     842             :     }
     843        5219 :     return 0;
     844             : }
     845             : 
     846             : /** method to determine previous content frame in the same environment
     847             :     for a flow frame (content frame, table frame, section frame)
     848             : 
     849             :     OD 2005-11-30 #i27138#
     850             : */
     851           2 : SwCntntFrm* SwFrm::_FindPrevCnt( const bool _bInSameFtn )
     852             : {
     853           2 :     if ( !IsFlowFrm() )
     854             :     {
     855             :         // nothing to do, if current frame isn't a flow frame.
     856           0 :         return 0L;
     857             :     }
     858             : 
     859           2 :     SwCntntFrm* pPrevCntntFrm( 0L );
     860             : 
     861             :     // Because method <SwCntntFrm::GetPrevCntntFrm()> is used to travel
     862             :     // through the layout, a content frame, at which the travel starts, is needed.
     863           2 :     SwCntntFrm* pCurrCntntFrm = dynamic_cast<SwCntntFrm*>(this);
     864             : 
     865             :     // perform shortcut, if current frame is a follow, and
     866             :     // determine <pCurrCntntFrm>, if current frame is a table or section frame
     867           2 :     if ( pCurrCntntFrm && pCurrCntntFrm->IsFollow() )
     868             :     {
     869             :         // previous content frame is its master content frame
     870           0 :         pPrevCntntFrm = pCurrCntntFrm->FindMaster();
     871             :     }
     872           2 :     else if ( IsTabFrm() )
     873             :     {
     874           0 :         SwTabFrm* pTabFrm( static_cast<SwTabFrm*>(this) );
     875           0 :         if ( pTabFrm->IsFollow() )
     876             :         {
     877             :             // previous content frame is the last content of its master table frame
     878           0 :             pPrevCntntFrm = pTabFrm->FindMaster()->FindLastCntnt();
     879             :         }
     880             :         else
     881             :         {
     882             :             // start content frame for the search is the first content frame of
     883             :             // the table frame.
     884           0 :             pCurrCntntFrm = pTabFrm->ContainsCntnt();
     885             :         }
     886             :     }
     887           2 :     else if ( IsSctFrm() )
     888             :     {
     889           0 :         SwSectionFrm* pSectFrm( static_cast<SwSectionFrm*>(this) );
     890           0 :         if ( pSectFrm->IsFollow() )
     891             :         {
     892             :             // previous content frame is the last content of its master section frame
     893           0 :             pPrevCntntFrm = pSectFrm->FindMaster()->FindLastCntnt();
     894             :         }
     895             :         else
     896             :         {
     897             :             // start content frame for the search is the first content frame of
     898             :             // the section frame.
     899           0 :             pCurrCntntFrm = pSectFrm->ContainsCntnt();
     900             :         }
     901             :     }
     902             : 
     903             :     // search for next content frame, depending on the environment, in which
     904             :     // the current frame is in.
     905           2 :     if ( !pPrevCntntFrm && pCurrCntntFrm )
     906             :     {
     907           2 :         pPrevCntntFrm = pCurrCntntFrm->GetPrevCntntFrm();
     908           2 :         if ( pPrevCntntFrm )
     909             :         {
     910           0 :             if ( pCurrCntntFrm->IsInFly() )
     911             :             {
     912             :                 // handling for environments 'unlinked fly frame' and
     913             :                 // 'group of linked fly frames':
     914             :                 // Nothing to do, <pPrevCntntFrm> is the one
     915             :             }
     916             :             else
     917             :             {
     918           0 :                 const bool bInDocBody = pCurrCntntFrm->IsInDocBody();
     919           0 :                 const bool bInFtn  = pCurrCntntFrm->IsInFtn();
     920           0 :                 if ( bInDocBody || ( bInFtn && !_bInSameFtn ) )
     921             :                 {
     922             :                     // handling for environments 'footnotes' and 'document body frames':
     923             :                     // Assure that found previous frame is also in one of these
     924             :                     // environments. Otherwise, travel further
     925           0 :                     while ( pPrevCntntFrm )
     926             :                     {
     927           0 :                         if ( ( bInDocBody && pPrevCntntFrm->IsInDocBody() ) ||
     928           0 :                              ( bInFtn && pPrevCntntFrm->IsInFtn() ) )
     929             :                         {
     930           0 :                             break;
     931             :                         }
     932           0 :                         pPrevCntntFrm = pPrevCntntFrm->GetPrevCntntFrm();
     933             :                     }
     934             :                 }
     935           0 :                 else if ( bInFtn && _bInSameFtn )
     936             :                 {
     937             :                     // handling for environments 'each footnote':
     938             :                     // Assure that found next content frame belongs to the same footnotes
     939           0 :                     const SwFtnFrm* pFtnFrmOfPrev( pPrevCntntFrm->FindFtnFrm() );
     940           0 :                     const SwFtnFrm* pFtnFrmOfCurr( pCurrCntntFrm->FindFtnFrm() );
     941           0 :                     if ( pFtnFrmOfPrev != pFtnFrmOfCurr )
     942             :                     {
     943           0 :                         if ( pFtnFrmOfCurr->GetMaster() )
     944             :                         {
     945             :                             SwFtnFrm* pMasterFtnFrmOfCurr(
     946           0 :                                         const_cast<SwFtnFrm*>(pFtnFrmOfCurr) );
     947           0 :                             pPrevCntntFrm = 0L;
     948             :                             // #146872#
     949             :                             // correct wrong loop-condition
     950           0 :                             do {
     951           0 :                                 pMasterFtnFrmOfCurr = pMasterFtnFrmOfCurr->GetMaster();
     952           0 :                                 pPrevCntntFrm = pMasterFtnFrmOfCurr->FindLastCntnt();
     953           0 :                             } while ( !pPrevCntntFrm &&
     954           0 :                                       pMasterFtnFrmOfCurr->GetMaster() );
     955             :                         }
     956             :                         else
     957             :                         {
     958             :                             // current content frame is the first content in the
     959             :                             // footnote - no previous content exists.
     960           0 :                             pPrevCntntFrm = 0L;;
     961             :                         }
     962           0 :                     }
     963             :                 }
     964             :                 else
     965             :                 {
     966             :                     // handling for environments 'page header' and 'page footer':
     967             :                     // Assure that found previous frame is also in the same
     968             :                     // page header respectively page footer as <pCurrCntntFrm>
     969             :                     // Note: At this point its clear, that <pCurrCntntFrm> has
     970             :                     //       to be inside a page header or page footer and that
     971             :                     //       neither <pCurrCntntFrm> nor <pPrevCntntFrm> are
     972             :                     //       inside a fly frame.
     973             :                     //       Thus, method <FindFooterOrHeader()> can be used.
     974             :                     OSL_ENSURE( pCurrCntntFrm->FindFooterOrHeader(),
     975             :                             "<SwFrm::_FindPrevCnt()> - unknown layout situation: current frame should be in page header or page footer" );
     976             :                     OSL_ENSURE( !pPrevCntntFrm->IsInFly(),
     977             :                             "<SwFrm::_FindPrevCnt()> - unknown layout situation: found previous frame should *not* be inside a fly frame." );
     978           0 :                     if ( pPrevCntntFrm->FindFooterOrHeader() !=
     979           0 :                                             pCurrCntntFrm->FindFooterOrHeader() )
     980             :                     {
     981           0 :                         pPrevCntntFrm = 0L;
     982             :                     }
     983             :                 }
     984             :             }
     985             :         }
     986             :     }
     987             : 
     988           2 :     return pPrevCntntFrm;
     989             : }
     990             : 
     991      117828 : SwFrm *SwFrm::_FindPrev()
     992             : {
     993      117828 :     bool bIgnoreTab = false;
     994      117828 :     SwFrm *pThis = this;
     995             : 
     996      117828 :     if ( IsTabFrm() )
     997             :     {
     998             :         //The first Cntnt of the table gets picked up and his predecessor is
     999             :         //returnd. To be able to deactivate the special case for tables
    1000             :         //(see below) bIgnoreTab will be set.
    1001        6843 :         if ( ((SwTabFrm*)this)->IsFollow() )
    1002         840 :             return ((SwTabFrm*)this)->FindMaster();
    1003             :         else
    1004        6003 :             pThis = ((SwTabFrm*)this)->ContainsCntnt();
    1005        6003 :         bIgnoreTab = true;
    1006             :     }
    1007             : 
    1008      116988 :     if ( pThis && pThis->IsCntntFrm() )
    1009             :     {
    1010      116987 :         SwCntntFrm *pPrvCnt = ((SwCntntFrm*)pThis)->GetPrevCntntFrm();
    1011      116987 :         if( !pPrvCnt )
    1012       25280 :             return 0;
    1013       91707 :         if ( !bIgnoreTab && pThis->IsInTab() )
    1014             :         {
    1015       13098 :             SwLayoutFrm *pUp = pThis->GetUpper();
    1016       26196 :             while ( !pUp->IsCellFrm() )
    1017           0 :                 pUp = pUp->GetUpper();
    1018             :             OSL_ENSURE( pUp, "Cntnt in table but not in cell." );
    1019       13098 :             if ( pUp->IsAnLower( pPrvCnt ) )
    1020           0 :                 return pPrvCnt;
    1021             :         }
    1022             :         else
    1023             :         {
    1024             :             SwFrm* pRet;
    1025       78609 :             const bool bBody = pThis->IsInDocBody();
    1026       78609 :             const sal_Bool bFtn  = bBody ? sal_False : pThis->IsInFtn();
    1027       81372 :             if ( bBody || bFtn )
    1028             :             {
    1029      440442 :                 while ( pPrvCnt )
    1030             :                 {
    1031      434916 :                     if ( (bBody && pPrvCnt->IsInDocBody()) ||
    1032         140 :                             (bFtn   && pPrvCnt->IsInFtn()) )
    1033             :                     {
    1034       72901 :                         pRet = pPrvCnt->IsInTab() ? pPrvCnt->FindTabFrm()
    1035       72901 :                                                   : (SwFrm*)pPrvCnt;
    1036       72298 :                         return pRet;
    1037             :                     }
    1038      290320 :                     pPrvCnt = pPrvCnt->GetPrevCntntFrm();
    1039             :                 }
    1040             :             }
    1041        3548 :             else if ( pThis->IsInFly() )
    1042             :             {
    1043          22 :                 pRet = pPrvCnt->IsInTab() ? pPrvCnt->FindTabFrm()
    1044          22 :                                             : (SwFrm*)pPrvCnt;
    1045          22 :                 return pRet;
    1046             :             }
    1047             :             else // footer or header or Fly
    1048             :             {
    1049        3526 :                 const SwFrm *pUp = pThis->GetUpper();
    1050        3526 :                 const SwFrm *pCntUp = pPrvCnt->GetUpper();
    1051       16390 :                 while ( pUp && pUp->GetUpper() &&
    1052       12076 :                         !pUp->IsHeaderFrm() && !pUp->IsFooterFrm() )
    1053         762 :                     pUp = pUp->GetUpper();
    1054       14437 :                 while ( pCntUp && pCntUp->GetUpper() )
    1055        7385 :                     pCntUp = pCntUp->GetUpper();
    1056        3526 :                 if ( pCntUp == pUp )
    1057             :                 {
    1058           0 :                     pRet = pPrvCnt->IsInTab() ? pPrvCnt->FindTabFrm()
    1059           0 :                                                 : (SwFrm*)pPrvCnt;
    1060           0 :                     return pRet;
    1061             :                 }
    1062             :             }
    1063             :         }
    1064             :     }
    1065       19388 :     return 0;
    1066             : }
    1067             : 
    1068       62029 : void SwFrm::ImplInvalidateNextPos( sal_Bool bNoFtn )
    1069             : {
    1070             :     SwFrm *pFrm;
    1071       62029 :     if ( 0 != (pFrm = _FindNext()) )
    1072             :     {
    1073       12449 :         if( pFrm->IsSctFrm() )
    1074             :         {
    1075        7136 :             while( pFrm && pFrm->IsSctFrm() )
    1076             :             {
    1077        4660 :                 if( ((SwSectionFrm*)pFrm)->GetSection() )
    1078             :                 {
    1079        1028 :                     SwFrm* pTmp = ((SwSectionFrm*)pFrm)->ContainsAny();
    1080        1028 :                     if( pTmp )
    1081         940 :                         pTmp->InvalidatePos();
    1082          88 :                     else if( !bNoFtn )
    1083          88 :                         ((SwSectionFrm*)pFrm)->InvalidateFtnPos();
    1084        1028 :                     if( !IsInSct() || FindSctFrm()->GetFollow() != pFrm )
    1085         408 :                         pFrm->InvalidatePos();
    1086       63057 :                     return;
    1087             :                 }
    1088        3632 :                 pFrm = pFrm->FindNext();
    1089             :             }
    1090         724 :             if( pFrm )
    1091             :             {
    1092         178 :                 if ( pFrm->IsSctFrm())
    1093             :                 {
    1094             :                     // We need to invalidate the section's content so it gets
    1095             :                     // the chance to flow to a different page.
    1096           0 :                     SwFrm* pTmp = ((SwSectionFrm*)pFrm)->ContainsAny();
    1097           0 :                     if( pTmp )
    1098           0 :                         pTmp->InvalidatePos();
    1099           0 :                     if( !IsInSct() || FindSctFrm()->GetFollow() != pFrm )
    1100           0 :                         pFrm->InvalidatePos();
    1101             :                 }
    1102             :                 else
    1103         178 :                     pFrm->InvalidatePos();
    1104             :             }
    1105             :         }
    1106             :         else
    1107       10697 :             pFrm->InvalidatePos();
    1108             :     }
    1109             : }
    1110             : 
    1111             : /** method to invalidate printing area of next frame
    1112             : 
    1113             :     OD 09.01.2004 #i11859#
    1114             : 
    1115             :     FME 2004-04-19 #i27145# Moved function from SwTxtFrm to SwFrm
    1116             : */
    1117        8483 : void SwFrm::InvalidateNextPrtArea()
    1118             : {
    1119             :     // determine next frame
    1120        8483 :     SwFrm* pNextFrm = FindNext();
    1121             :     // skip empty section frames and hidden text frames
    1122             :     {
    1123       22193 :         while ( pNextFrm &&
    1124        4909 :                 ( ( pNextFrm->IsSctFrm() &&
    1125        4427 :                     !static_cast<SwSectionFrm*>(pNextFrm)->GetSection() ) ||
    1126        7355 :                   ( pNextFrm->IsTxtFrm() &&
    1127        3574 :                     static_cast<SwTxtFrm*>(pNextFrm)->IsHiddenNow() ) ) )
    1128             :         {
    1129         482 :             pNextFrm = pNextFrm->FindNext();
    1130             :         }
    1131             :     }
    1132             : 
    1133             :     // Invalidate printing area of found next frame
    1134        8483 :     if ( pNextFrm )
    1135             :     {
    1136        3781 :         if ( pNextFrm->IsSctFrm() )
    1137             :         {
    1138             :             // Invalidate printing area of found section frame, if
    1139             :             // (1) this text frame isn't in a section OR
    1140             :             // (2) found section frame isn't a follow of the section frame this
    1141             :             //     text frame is in.
    1142         164 :             if ( !IsInSct() || FindSctFrm()->GetFollow() != pNextFrm )
    1143             :             {
    1144          98 :                 pNextFrm->InvalidatePrt();
    1145             :             }
    1146             : 
    1147             :             // Invalidate printing area of first content in found section.
    1148             :             SwFrm* pFstCntntOfSctFrm =
    1149         164 :                     static_cast<SwSectionFrm*>(pNextFrm)->ContainsAny();
    1150         164 :             if ( pFstCntntOfSctFrm )
    1151             :             {
    1152         158 :                 pFstCntntOfSctFrm->InvalidatePrt();
    1153             :             }
    1154             :         }
    1155             :         else
    1156             :         {
    1157        3617 :             pNextFrm->InvalidatePrt();
    1158             :         }
    1159             :     }
    1160        8483 : }
    1161             : 
    1162             : /// @returns true if the frame _directly_ sits in a section with columns
    1163             : ///     but not if it sits in a table which itself sits in a section with columns.
    1164       20782 : static bool lcl_IsInColSct( const SwFrm *pUp )
    1165             : {
    1166       20782 :     bool bRet = false;
    1167       74447 :     while( pUp )
    1168             :     {
    1169       53665 :         if( pUp->IsColumnFrm() )
    1170       16307 :             bRet = true;
    1171       37358 :         else if( pUp->IsSctFrm() )
    1172       20657 :             return bRet;
    1173       16701 :         else if( pUp->IsTabFrm() )
    1174         125 :             return false;
    1175       32883 :         pUp = pUp->GetUpper();
    1176             :     }
    1177           0 :     return false;
    1178             : }
    1179             : 
    1180             : /** determine, if frame is moveable in given environment
    1181             : 
    1182             :     OD 08.08.2003 #110978#
    1183             :     method replaced 'old' method <sal_Bool IsMoveable() const>.
    1184             :     Determines, if frame is moveable in given environment. if no environment
    1185             :     is given (parameter _pLayoutFrm == 0L), the movability in the actual
    1186             :     environment (<this->GetUpper()) is checked.
    1187             : */
    1188      188997 : bool SwFrm::IsMoveable( const SwLayoutFrm* _pLayoutFrm ) const
    1189             : {
    1190      188997 :     bool bRetVal = false;
    1191             : 
    1192      188997 :     if ( !_pLayoutFrm )
    1193             :     {
    1194      188997 :         _pLayoutFrm = GetUpper();
    1195             :     }
    1196             : 
    1197      188997 :     if ( _pLayoutFrm && IsFlowFrm() )
    1198             :     {
    1199      168895 :         if ( _pLayoutFrm->IsInSct() && lcl_IsInColSct( _pLayoutFrm ) )
    1200             :         {
    1201       16307 :             bRetVal = true;
    1202             :         }
    1203      448084 :         else if ( _pLayoutFrm->IsInFly() ||
    1204      168592 :                   _pLayoutFrm->IsInDocBody() ||
    1205       16004 :                   _pLayoutFrm->IsInFtn() )
    1206             :         {
    1207      211044 :             if ( _pLayoutFrm->IsInTab() && !IsTabFrm() &&
    1208       75588 :                  ( !IsCntntFrm() || !const_cast<SwFrm*>(this)->GetNextCellLeaf( MAKEPAGE_NONE ) ) )
    1209             :             {
    1210       36127 :                 bRetVal = false;
    1211             :             }
    1212             :             else
    1213             :             {
    1214      100996 :                 if ( _pLayoutFrm->IsInFly() )
    1215             :                 {
    1216             :                     // if fly frame has a follow (next linked fly frame),
    1217             :                     // frame is moveable.
    1218        7879 :                     if ( const_cast<SwLayoutFrm*>(_pLayoutFrm)->FindFlyFrm()->GetNextLink() )
    1219             :                     {
    1220           4 :                         bRetVal = true;
    1221             :                     }
    1222             :                     else
    1223             :                     {
    1224             :                         // if environment is columned, frame is moveable, if
    1225             :                         // it isn't in last column.
    1226             :                         // search for column frame
    1227        7875 :                         const SwFrm* pCol = _pLayoutFrm;
    1228       23652 :                         while ( pCol && !pCol->IsColumnFrm() )
    1229             :                         {
    1230        7902 :                             pCol = pCol->GetUpper();
    1231             :                         }
    1232             :                         // frame is moveable, if found column frame isn't last one.
    1233        7875 :                         if ( pCol && pCol->GetNext() )
    1234             :                         {
    1235           0 :                             bRetVal = true;
    1236             :                         }
    1237             :                     }
    1238             :                 }
    1239             :                 else
    1240             :                 {
    1241       93117 :                     bRetVal = true;
    1242             :                 }
    1243             :             }
    1244             :         }
    1245             :     }
    1246             : 
    1247      188997 :     return bRetVal;
    1248             : }
    1249             : 
    1250       52267 : void SwFrm::SetInfFlags()
    1251             : {
    1252       52267 :     if ( !IsFlyFrm() && !GetUpper() ) //not yet pasted, no information available
    1253       61612 :         return;
    1254             : 
    1255       42922 :     mbInfInvalid = mbInfBody = mbInfTab = mbInfFly = mbInfFtn = mbInfSct = sal_False;
    1256             : 
    1257       42922 :     SwFrm *pFrm = this;
    1258       42922 :     if( IsFtnContFrm() )
    1259          50 :         mbInfFtn = sal_True;
    1260      126890 :     do
    1261             :     {
    1262             :         // mbInfBody is only set in the page body, but not in the column body
    1263      287971 :         if ( pFrm->IsBodyFrm() && !mbInfFtn && pFrm->GetUpper()
    1264      161073 :              && pFrm->GetUpper()->IsPageFrm() )
    1265       32967 :             mbInfBody = sal_True;
    1266       93923 :         else if ( pFrm->IsTabFrm() || pFrm->IsCellFrm() )
    1267             :         {
    1268       33545 :             mbInfTab = sal_True;
    1269             :         }
    1270       60378 :         else if ( pFrm->IsFlyFrm() )
    1271        3886 :             mbInfFly = sal_True;
    1272       56492 :         else if ( pFrm->IsSctFrm() )
    1273        3091 :             mbInfSct = sal_True;
    1274       53401 :         else if ( pFrm->IsFtnFrm() )
    1275         164 :             mbInfFtn = sal_True;
    1276             : 
    1277      126890 :         pFrm = pFrm->GetUpper();
    1278             : 
    1279      126890 :     } while ( pFrm && !pFrm->IsPageFrm() ); //there is nothing above the page
    1280             : }
    1281             : 
    1282             : /** Updates the vertical or the righttoleft-flags.
    1283             :  *
    1284             :  * If the property is derived, it's from the upper or (for fly frames) from
    1285             :  * the anchor. Otherwise we've to call a virtual method to check the property.
    1286             :  */
    1287      884226 : void SwFrm::SetDirFlags( sal_Bool bVert )
    1288             : {
    1289      884226 :     if( bVert )
    1290             :     {
    1291             :         // OD 2004-01-21 #114969# - if derived, valid vertical flag only if
    1292             :         // vertical flag of upper/anchor is valid.
    1293      817368 :         if( mbDerivedVert )
    1294             :         {
    1295      515435 :             const SwFrm* pAsk = IsFlyFrm() ?
    1296      515435 :                           ((SwFlyFrm*)this)->GetAnchorFrm() : GetUpper();
    1297             : 
    1298             :             OSL_ENSURE( pAsk != this, "Autsch! Stack overflow is about to happen" );
    1299             : 
    1300      515435 :             if( pAsk )
    1301             :             {
    1302      505126 :                 mbVertical = pAsk->IsVertical() ? 1 : 0;
    1303      505126 :                 mbReverse  = pAsk->IsReverse()  ? 1 : 0;
    1304             : 
    1305      505126 :                 mbVertLR  = pAsk->IsVertLR() ? 1 : 0;
    1306             :                 //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
    1307      505126 :                 if ( !pAsk->mbInvalidVert )
    1308      146553 :                     mbInvalidVert = sal_False;
    1309             :             }
    1310             :         }
    1311             :         else
    1312      301933 :             CheckDirection( bVert );
    1313             :     }
    1314             :     else
    1315             :     {
    1316       66858 :         sal_Bool bInv = 0;
    1317       66858 :         if( !mbDerivedR2L ) // CheckDirection is able to set bDerivedR2L!
    1318       44920 :             CheckDirection( bVert );
    1319       66858 :         if( mbDerivedR2L )
    1320             :         {
    1321       34189 :             const SwFrm* pAsk = IsFlyFrm() ?
    1322       34189 :                           ((SwFlyFrm*)this)->GetAnchorFrm() : GetUpper();
    1323             : 
    1324             :             OSL_ENSURE( pAsk != this, "Oops! Stack overflow is about to happen" );
    1325             : 
    1326       34189 :             if( pAsk )
    1327       28997 :                 mbRightToLeft = pAsk->IsRightToLeft() ? 1 : 0;
    1328       34189 :             if( !pAsk || pAsk->mbInvalidR2L )
    1329        5212 :                 bInv = mbInvalidR2L;
    1330             :         }
    1331       66858 :         mbInvalidR2L = bInv;
    1332             :     }
    1333      884226 : }
    1334             : 
    1335       46159 : SwLayoutFrm* SwFrm::GetNextCellLeaf( MakePageType )
    1336             : {
    1337       46159 :     SwFrm* pTmpFrm = this;
    1338      138423 :     while ( !pTmpFrm->IsCellFrm() )
    1339       46105 :         pTmpFrm = pTmpFrm->GetUpper();
    1340             : 
    1341             :     OSL_ENSURE( pTmpFrm, "SwFrm::GetNextCellLeaf() without cell" );
    1342       46159 :     return ((SwCellFrm*)pTmpFrm)->GetFollowCell();
    1343             : }
    1344             : 
    1345         246 : SwLayoutFrm* SwFrm::GetPrevCellLeaf( MakePageType )
    1346             : {
    1347         246 :     SwFrm* pTmpFrm = this;
    1348         738 :     while ( !pTmpFrm->IsCellFrm() )
    1349         246 :         pTmpFrm = pTmpFrm->GetUpper();
    1350             : 
    1351             :     OSL_ENSURE( pTmpFrm, "SwFrm::GetNextPreviousLeaf() without cell" );
    1352         246 :     return ((SwCellFrm*)pTmpFrm)->GetPreviousCell();
    1353             : }
    1354             : 
    1355        2940 : static SwCellFrm* lcl_FindCorrespondingCellFrm( const SwRowFrm& rOrigRow,
    1356             :                                          const SwCellFrm& rOrigCell,
    1357             :                                          const SwRowFrm& rCorrRow,
    1358             :                                          bool bInFollow )
    1359             : {
    1360        2940 :     SwCellFrm* pRet = NULL;
    1361        2940 :     SwCellFrm* pCell = (SwCellFrm*)rOrigRow.Lower();
    1362        2940 :     SwCellFrm* pCorrCell = (SwCellFrm*)rCorrRow.Lower();
    1363             : 
    1364        8913 :     while ( pCell != &rOrigCell && !pCell->IsAnLower( &rOrigCell ) )
    1365             :     {
    1366        3033 :         pCell = (SwCellFrm*)pCell->GetNext();
    1367        3033 :         pCorrCell = (SwCellFrm*)pCorrCell->GetNext();
    1368             :     }
    1369             : 
    1370             :     OSL_ENSURE( pCell && pCorrCell, "lcl_FindCorrespondingCellFrm does not work" );
    1371             : 
    1372        2940 :     if ( pCell != &rOrigCell )
    1373             :     {
    1374             :         // rOrigCell must be a lower of pCell. We need to recurse into the rows:
    1375             :         OSL_ENSURE( pCell->Lower() && pCell->Lower()->IsRowFrm(),
    1376             :                 "lcl_FindCorrespondingCellFrm does not work" );
    1377             : 
    1378           0 :         SwRowFrm* pRow = (SwRowFrm*)pCell->Lower();
    1379           0 :         while ( !pRow->IsAnLower( &rOrigCell ) )
    1380           0 :             pRow = (SwRowFrm*)pRow->GetNext();
    1381             : 
    1382           0 :         SwRowFrm* pCorrRow = 0;
    1383           0 :         if ( bInFollow )
    1384           0 :             pCorrRow = pRow->GetFollowRow();
    1385             :         else
    1386             :         {
    1387           0 :             SwRowFrm* pTmpRow = static_cast<SwRowFrm*>(pCorrCell->GetLastLower());
    1388             : 
    1389           0 :             if ( pTmpRow && pTmpRow->GetFollowRow() == pRow )
    1390           0 :                 pCorrRow = pTmpRow;
    1391             :         }
    1392             : 
    1393           0 :         if ( pCorrRow )
    1394           0 :             pRet = lcl_FindCorrespondingCellFrm( *pRow, rOrigCell, *pCorrRow, bInFollow );
    1395             :     }
    1396             :     else
    1397        2940 :         pRet = pCorrCell;
    1398             : 
    1399        2940 :     return pRet;
    1400             : }
    1401             : 
    1402             : // VERSION OF GetFollowCell() that assumes that we always have a follow flow line:
    1403       67950 : SwCellFrm* SwCellFrm::GetFollowCell() const
    1404             : {
    1405       67950 :     SwCellFrm* pRet = NULL;
    1406             : 
    1407             :     // NEW TABLES
    1408             :     // Covered cells do not have follow cells!
    1409       67950 :     const long nRowSpan = GetLayoutRowSpan();
    1410       67950 :     if ( nRowSpan < 1 )
    1411         130 :         return NULL;
    1412             : 
    1413             :     // find most upper row frame
    1414       67820 :     const SwFrm* pRow = GetUpper();
    1415      135640 :     while( !pRow->IsRowFrm() || !pRow->GetUpper()->IsTabFrm() )
    1416           0 :         pRow = pRow->GetUpper();
    1417             : 
    1418       67820 :     if ( !pRow )
    1419           0 :         return NULL;
    1420             : 
    1421       67820 :     const SwTabFrm* pTabFrm = static_cast<const SwTabFrm*>( pRow->GetUpper() );
    1422       67820 :     if ( !pRow || !pTabFrm->GetFollow() || !pTabFrm->HasFollowFlowLine() )
    1423       63597 :         return NULL;
    1424             : 
    1425        4223 :     const SwCellFrm* pThisCell = this;
    1426             : 
    1427             :     // Get last cell of the current table frame that belongs to the rowspan:
    1428        4223 :     if ( nRowSpan > 1 )
    1429             :     {
    1430             :         // optimization: Will end of row span be in last row or exceed row?
    1431           0 :         long nMax = 0;
    1432           0 :         while ( pRow->GetNext() && ++nMax < nRowSpan )
    1433           0 :             pRow = pRow->GetNext();
    1434             : 
    1435           0 :         if ( !pRow->GetNext() )
    1436             :         {
    1437           0 :             pThisCell = &pThisCell->FindStartEndOfRowSpanCell( false, true );
    1438           0 :             pRow = pThisCell->GetUpper();
    1439             :         }
    1440             :     }
    1441             : 
    1442        4223 :     const SwRowFrm* pFollowRow = NULL;
    1443       11331 :     if ( !pRow->GetNext() &&
    1444        9993 :          NULL != ( pFollowRow = pRow->IsInSplitTableRow() ) &&
    1445        2885 :          ( !pFollowRow->IsRowSpanLine() || nRowSpan > 1 ) )
    1446        2885 :          pRet = lcl_FindCorrespondingCellFrm( *((SwRowFrm*)pRow), *pThisCell, *pFollowRow, true );
    1447             : 
    1448        4223 :     return pRet;
    1449             : }
    1450             : 
    1451             : // VERSION OF GetPreviousCell() THAT ASSUMES THAT WE ALWAYS HAVE A FFL
    1452         260 : SwCellFrm* SwCellFrm::GetPreviousCell() const
    1453             : {
    1454         260 :     SwCellFrm* pRet = NULL;
    1455             : 
    1456             :     // NEW TABLES
    1457             :     // Covered cells do not have previous cells!
    1458         260 :     if ( GetLayoutRowSpan() < 1 )
    1459           0 :         return NULL;
    1460             : 
    1461             :     // find most upper row frame
    1462         260 :     const SwFrm* pRow = GetUpper();
    1463         520 :     while( !pRow->IsRowFrm() || !pRow->GetUpper()->IsTabFrm() )
    1464           0 :         pRow = pRow->GetUpper();
    1465             : 
    1466             :     OSL_ENSURE( pRow->GetUpper() && pRow->GetUpper()->IsTabFrm(), "GetPreviousCell without Table" );
    1467             : 
    1468         260 :     SwTabFrm* pTab = (SwTabFrm*)pRow->GetUpper();
    1469             : 
    1470         260 :     if ( pTab->IsFollow() )
    1471             :     {
    1472          85 :         const SwFrm* pTmp = pTab->GetFirstNonHeadlineRow();
    1473          85 :         const bool bIsInFirstLine = ( pTmp == pRow );
    1474             : 
    1475          85 :         if ( bIsInFirstLine )
    1476             :         {
    1477          85 :             SwTabFrm *pMaster = (SwTabFrm*)pTab->FindMaster();
    1478          85 :             if ( pMaster && pMaster->HasFollowFlowLine() )
    1479             :             {
    1480          55 :                 SwRowFrm* pMasterRow = static_cast<SwRowFrm*>(pMaster->GetLastLower());
    1481          55 :                 if ( pMasterRow )
    1482          55 :                     pRet = lcl_FindCorrespondingCellFrm( *((SwRowFrm*)pRow), *this, *pMasterRow, false );
    1483          55 :                 if ( pRet && pRet->GetTabBox()->getRowSpan() < 1 )
    1484           0 :                     pRet = &const_cast<SwCellFrm&>(pRet->FindStartEndOfRowSpanCell( true, true ));
    1485             :             }
    1486             :         }
    1487             :     }
    1488             : 
    1489         260 :     return pRet;
    1490             : }
    1491             : 
    1492             : // --> NEW TABLES
    1493         291 : const SwCellFrm& SwCellFrm::FindStartEndOfRowSpanCell( bool bStart, bool bCurrentTableOnly ) const
    1494             : {
    1495         291 :     const SwCellFrm* pRet = 0;
    1496             : 
    1497         291 :     const SwTabFrm* pTableFrm = dynamic_cast<const SwTabFrm*>(GetUpper()->GetUpper());
    1498             : 
    1499         291 :     if ( !bStart && pTableFrm && pTableFrm->IsFollow() && pTableFrm->IsInHeadline( *this ) )
    1500           0 :         return *this;
    1501             : 
    1502             :     OSL_ENSURE( pTableFrm &&
    1503             :             (  (bStart && GetTabBox()->getRowSpan() < 1) ||
    1504             :               (!bStart && GetLayoutRowSpan() > 1) ),
    1505             :             "SwCellFrm::FindStartRowSpanCell: No rowspan, no table, no cookies" );
    1506             : 
    1507         291 :     if ( pTableFrm )
    1508             :     {
    1509         291 :         const SwTable* pTable = pTableFrm->GetTable();
    1510             : 
    1511         291 :         sal_uInt16 nMax = USHRT_MAX;
    1512         291 :         if ( bCurrentTableOnly )
    1513             :         {
    1514         291 :             const SwFrm* pCurrentRow = GetUpper();
    1515         291 :             const bool bDoNotEnterHeadline = bStart && pTableFrm->IsFollow() &&
    1516         291 :                                         !pTableFrm->IsInHeadline( *pCurrentRow );
    1517             : 
    1518             :             // check how many rows we are allowed to go up or down until we reach the end of
    1519             :             // the current table frame:
    1520         291 :             nMax = 0;
    1521        1116 :             while ( bStart ? pCurrentRow->GetPrev() : pCurrentRow->GetNext() )
    1522             :             {
    1523         534 :                 if ( bStart )
    1524             :                 {
    1525             :                     // do not enter a repeated headline:
    1526         438 :                     if ( bDoNotEnterHeadline && pTableFrm->IsFollow() &&
    1527           0 :                          pTableFrm->IsInHeadline( *pCurrentRow->GetPrev() ) )
    1528           0 :                         break;
    1529             : 
    1530         438 :                     pCurrentRow = pCurrentRow->GetPrev();
    1531             :                 }
    1532             :                 else
    1533          96 :                     pCurrentRow = pCurrentRow->GetNext();
    1534             : 
    1535         534 :                 ++nMax;
    1536             :             }
    1537             :         }
    1538             : 
    1539             :         // By passing the nMax value for Find*OfRowSpan (in case of bCurrentTableOnly
    1540             :         // is set) we assure that we find a rMasterBox that has a SwCellFrm in
    1541             :         // the current table frame:
    1542             :         const SwTableBox& rMasterBox = bStart ?
    1543         249 :                                        GetTabBox()->FindStartOfRowSpan( *pTable, nMax ) :
    1544         540 :                                        GetTabBox()->FindEndOfRowSpan( *pTable, nMax );
    1545             : 
    1546         291 :         SwIterator<SwCellFrm,SwFmt> aIter( *rMasterBox.GetFrmFmt() );
    1547             : 
    1548         291 :         for ( SwCellFrm* pMasterCell = aIter.First(); pMasterCell; pMasterCell = aIter.Next() )
    1549             :         {
    1550         291 :             if ( pMasterCell->GetTabBox() == &rMasterBox )
    1551             :             {
    1552         291 :                 const SwTabFrm* pMasterTable = static_cast<const SwTabFrm*>(pMasterCell->GetUpper()->GetUpper());
    1553             : 
    1554         291 :                 if ( bCurrentTableOnly )
    1555             :                 {
    1556         291 :                     if ( pMasterTable == pTableFrm )
    1557             :                     {
    1558         291 :                         pRet = pMasterCell;
    1559         291 :                         break;
    1560             :                     }
    1561             :                 }
    1562             :                 else
    1563             :                 {
    1564           0 :                     if ( pMasterTable == pTableFrm ||
    1565           0 :                          (  (bStart && pMasterTable->IsAnFollow(pTableFrm)) ||
    1566           0 :                            (!bStart && pTableFrm->IsAnFollow(pMasterTable)) ) )
    1567             :                     {
    1568           0 :                         pRet = pMasterCell;
    1569           0 :                         break;
    1570             :                     }
    1571             :                 }
    1572             :             }
    1573         291 :         }
    1574             :     }
    1575             : 
    1576             :     OSL_ENSURE( pRet, "SwCellFrm::FindStartRowSpanCell: No result" );
    1577             : 
    1578         291 :     return *pRet;
    1579             : }
    1580             : // <-- NEW TABLES
    1581             : 
    1582       13380 : const SwRowFrm* SwFrm::IsInSplitTableRow() const
    1583             : {
    1584             :     OSL_ENSURE( IsInTab(), "IsInSplitTableRow should only be called for frames in tables" );
    1585             : 
    1586       13380 :     const SwFrm* pRow = this;
    1587             : 
    1588             :     // find most upper row frame
    1589       27586 :     while( pRow && ( !pRow->IsRowFrm() || !pRow->GetUpper()->IsTabFrm() ) )
    1590         826 :         pRow = pRow->GetUpper();
    1591             : 
    1592       13380 :     if ( !pRow ) return NULL;
    1593             : 
    1594             :     OSL_ENSURE( pRow->GetUpper()->IsTabFrm(), "Confusion in table layout" );
    1595             : 
    1596       13380 :     const SwTabFrm* pTab = (SwTabFrm*)pRow->GetUpper();
    1597             : 
    1598             :     // If most upper row frame is a headline row, the current frame
    1599             :     // can't be in a splitted table row. Thus, add corresponding condition.
    1600       35746 :     if ( pRow->GetNext() ||
    1601             :          pTab->GetTable()->IsHeadline(
    1602       17972 :                     *(static_cast<const SwRowFrm*>(pRow)->GetTabLine()) ) ||
    1603       28704 :          !pTab->HasFollowFlowLine() ||
    1604        6338 :          !pTab->GetFollow() )
    1605        7042 :         return NULL;
    1606             : 
    1607             :     // skip headline
    1608        6338 :     const SwRowFrm* pFollowRow = pTab->GetFollow()->GetFirstNonHeadlineRow();
    1609             : 
    1610             :     OSL_ENSURE( pFollowRow, "SwFrm::IsInSplitTableRow() does not work" );
    1611             : 
    1612        6338 :     return pFollowRow;
    1613             : }
    1614             : 
    1615        8283 : const SwRowFrm* SwFrm::IsInFollowFlowRow() const
    1616             : {
    1617             :     OSL_ENSURE( IsInTab(), "IsInSplitTableRow should only be called for frames in tables" );
    1618             : 
    1619             :     // find most upper row frame
    1620        8283 :     const SwFrm* pRow = this;
    1621       31546 :     while( pRow && ( !pRow->IsRowFrm() || !pRow->GetUpper()->IsTabFrm() ) )
    1622       14980 :         pRow = pRow->GetUpper();
    1623             : 
    1624        8283 :     if ( !pRow ) return NULL;
    1625             : 
    1626             :     OSL_ENSURE( pRow->GetUpper()->IsTabFrm(), "Confusion in table layout" );
    1627             : 
    1628        8283 :     const SwTabFrm* pTab = (SwTabFrm*)pRow->GetUpper();
    1629             : 
    1630        8283 :     const SwTabFrm* pMaster = pTab->IsFollow() ? pTab->FindMaster() : 0;
    1631             : 
    1632        8283 :     if ( !pMaster || !pMaster->HasFollowFlowLine() )
    1633        7170 :         return NULL;
    1634             : 
    1635        1113 :     const SwFrm* pTmp = pTab->GetFirstNonHeadlineRow();
    1636        1113 :     const bool bIsInFirstLine = ( pTmp == pRow );
    1637             : 
    1638        1113 :     if ( !bIsInFirstLine )
    1639         860 :         return NULL;
    1640             : 
    1641         253 :     const SwRowFrm* pMasterRow = static_cast<const SwRowFrm*>(pMaster->GetLastLower());
    1642         253 :     return pMasterRow;
    1643             : }
    1644             : 
    1645         200 : bool SwFrm::IsInBalancedSection() const
    1646             : {
    1647         200 :     bool bRet = false;
    1648             : 
    1649         200 :     if ( IsInSct() )
    1650             :     {
    1651         146 :         const SwSectionFrm* pSectionFrm = FindSctFrm();
    1652         146 :         if ( pSectionFrm )
    1653         146 :             bRet = pSectionFrm->IsBalancedSection();
    1654             :     }
    1655         200 :     return bRet;
    1656             : }
    1657             : 
    1658       17409 : const SwFrm* SwLayoutFrm::GetLastLower() const
    1659             : {
    1660       17409 :     const SwFrm* pRet = Lower();
    1661       17409 :     if ( !pRet )
    1662          74 :         return 0;
    1663      118229 :     while ( pRet->GetNext() )
    1664       83559 :         pRet = pRet->GetNext();
    1665       17335 :     return pRet;
    1666             : }
    1667             : 
    1668             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10