LCOV - code coverage report
Current view: top level - sw/source/core/layout - frmtool.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1323 1611 82.1 %
Date: 2014-04-11 Functions: 74 78 94.9 %
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 <svx/svdmodel.hxx>
      21             : #include <svx/svdpage.hxx>
      22             : #include <editeng/brushitem.hxx>
      23             : #include <editeng/shaditem.hxx>
      24             : #include <editeng/ulspitem.hxx>
      25             : #include <editeng/boxitem.hxx>
      26             : #include <editeng/lspcitem.hxx>
      27             : 
      28             : #include <fmtornt.hxx>
      29             : #include <fmthdft.hxx>
      30             : #include <fmtfsize.hxx>
      31             : #include <fmtsrnd.hxx>
      32             : #include <docary.hxx>
      33             : #include <lineinfo.hxx>
      34             : #include <swmodule.hxx>
      35             : #include "pagefrm.hxx"
      36             : #include "colfrm.hxx"
      37             : #include "fesh.hxx"
      38             : #include "viewimp.hxx"
      39             : #include "viewopt.hxx"
      40             : #include "dflyobj.hxx"
      41             : #include "dcontact.hxx"
      42             : #include "frmtool.hxx"
      43             : #include "tabfrm.hxx"
      44             : #include "rowfrm.hxx"
      45             : #include "ftnfrm.hxx"
      46             : #include "txtfrm.hxx"
      47             : #include "notxtfrm.hxx"
      48             : #include "flyfrms.hxx"
      49             : #include "layact.hxx"
      50             : #include "pagedesc.hxx"
      51             : #include "section.hxx"
      52             : #include "sectfrm.hxx"
      53             : #include "node2lay.hxx"
      54             : #include "ndole.hxx"
      55             : #include "hints.hxx"
      56             : #include <layhelp.hxx>
      57             : #include <laycache.hxx>
      58             : #include <rootfrm.hxx>
      59             : #include <paratr.hxx>
      60             : #include <sortedobjs.hxx>
      61             : #include <objectformatter.hxx>
      62             : #include <switerator.hxx>
      63             : 
      64             : // ftnfrm.cxx:
      65             : void sw_RemoveFtns( SwFtnBossFrm* pBoss, sal_Bool bPageOnly, sal_Bool bEndNotes );
      66             : 
      67             : using namespace ::com::sun::star;
      68             : 
      69             : bool bObjsDirect = true;
      70             : bool bDontCreateObjects = false;
      71             : bool bSetCompletePaintOnInvalidate = false;
      72             : 
      73             : sal_uInt8 StackHack::nCnt = 0;
      74             : sal_Bool StackHack::bLocked = sal_False;
      75             : 
      76      115870 : SwFrmNotify::SwFrmNotify( SwFrm *pF ) :
      77             :     pFrm( pF ),
      78      115870 :     aFrm( pF->Frm() ),
      79      115870 :     aPrt( pF->Prt() ),
      80             :     bInvaKeep( sal_False ),
      81      115870 :     bValidSize( pF->GetValidSizeFlag() ),
      82      463480 :     mbFrmDeleted( false )     // #i49383#
      83             : {
      84      115870 :     if ( pF->IsTxtFrm() )
      85             :     {
      86       47848 :         mnFlyAnchorOfst = ((SwTxtFrm*)pF)->GetBaseOfstForFly( true );
      87       47848 :         mnFlyAnchorOfstNoWrap = ((SwTxtFrm*)pF)->GetBaseOfstForFly( false );
      88             :     }
      89             :     else
      90             :     {
      91       68022 :         mnFlyAnchorOfst = 0;
      92       68022 :         mnFlyAnchorOfstNoWrap = 0;
      93             :     }
      94             : 
      95      115870 :     bHadFollow = pF->IsCntntFrm() ?
      96       49031 :                     (((SwCntntFrm*)pF)->GetFollow() ? sal_True : sal_False) :
      97      164901 :                     sal_False;
      98      115870 : }
      99             : 
     100      115870 : SwFrmNotify::~SwFrmNotify()
     101             : {
     102             :     // #i49383#
     103      115870 :     if ( mbFrmDeleted )
     104             :     {
     105           0 :         return;
     106             :     }
     107             : 
     108      115870 :     SWRECTFN( pFrm )
     109      115870 :     const bool bAbsP = POS_DIFF( aFrm, pFrm->Frm() );
     110             :     const bool bChgWidth =
     111      115870 :             (aFrm.*fnRect->fnGetWidth)() != (pFrm->Frm().*fnRect->fnGetWidth)();
     112             :     const bool bChgHeight =
     113      115870 :             (aFrm.*fnRect->fnGetHeight)()!=(pFrm->Frm().*fnRect->fnGetHeight)();
     114      163775 :     const bool bChgFlyBasePos = pFrm->IsTxtFrm() &&
     115       95676 :        ( ( mnFlyAnchorOfst != ((SwTxtFrm*)pFrm)->GetBaseOfstForFly( true ) ) ||
     116      163698 :          ( mnFlyAnchorOfstNoWrap != ((SwTxtFrm*)pFrm)->GetBaseOfstForFly( false ) ) );
     117             : 
     118      115870 :     if ( pFrm->IsFlowFrm() && !pFrm->IsInFtn() )
     119             :     {
     120       52497 :         SwFlowFrm *pFlow = SwFlowFrm::CastFlowFrm( pFrm );
     121             : 
     122       52497 :         if ( !pFlow->IsFollow() )
     123             :         {
     124       50808 :             if ( !pFrm->GetIndPrev() )
     125             :             {
     126       27910 :                 if ( bInvaKeep )
     127             :                 {
     128        2909 :                     SwFrm *pPre = pFrm->FindPrev();
     129        2909 :                     if ( pPre && pPre->IsFlowFrm() )
     130             :                     {
     131             :                         // 1. pPre wants to keep with me:
     132        1049 :                         bool bInvalidPrePos = SwFlowFrm::CastFlowFrm( pPre )->IsKeep( *pPre->GetAttrSet() ) && pPre->GetIndPrev();
     133             : 
     134             :                         // 2. pPre is a table and the last row wants to keep with me:
     135        1049 :                         if ( !bInvalidPrePos && pPre->IsTabFrm() )
     136             :                         {
     137         170 :                             SwTabFrm* pPreTab = static_cast<SwTabFrm*>(pPre);
     138         170 :                             if ( pPreTab->GetFmt()->GetDoc()->get(IDocumentSettingAccess::TABLE_ROW_KEEP) )
     139             :                             {
     140         163 :                                 SwRowFrm* pLastRow = static_cast<SwRowFrm*>(pPreTab->GetLastLower());
     141         163 :                                 if ( pLastRow && pLastRow->ShouldRowKeepWithNext() )
     142           0 :                                     bInvalidPrePos = true;
     143             :                             }
     144             :                         }
     145             : 
     146        1049 :                         if ( bInvalidPrePos )
     147           6 :                             pPre->InvalidatePos();
     148             :                     }
     149             :                 }
     150             :             }
     151       22898 :             else if ( !pFlow->HasFollow() )
     152             :             {
     153       22506 :                 long nOldHeight = (aFrm.*fnRect->fnGetHeight)();
     154       22506 :                 long nNewHeight = (pFrm->Frm().*fnRect->fnGetHeight)();
     155       22506 :                 if( (nOldHeight > nNewHeight) || (!nOldHeight && nNewHeight) )
     156       12603 :                     pFlow->CheckKeep();
     157             :             }
     158             :         }
     159             :     }
     160             : 
     161      115870 :     if ( bAbsP )
     162             :     {
     163       69219 :         pFrm->SetCompletePaint();
     164             : 
     165       69219 :         SwFrm* pNxt = pFrm->GetIndNext();
     166             :         // #121888# - skip empty section frames
     167      172786 :         while ( pNxt &&
     168       70893 :                 pNxt->IsSctFrm() && !static_cast<SwSectionFrm*>(pNxt)->GetSection() )
     169             :         {
     170         666 :             pNxt = pNxt->GetIndNext();
     171             :         }
     172             : 
     173       69219 :         if ( pNxt )
     174       33016 :             pNxt->InvalidatePos();
     175             :         else
     176             :         {
     177             :             // #104100# - correct condition for setting retouche
     178             :             // flag for vertical layout.
     179       56986 :             if( pFrm->IsRetoucheFrm() &&
     180       20783 :                 (aFrm.*fnRect->fnTopDist)( (pFrm->Frm().*fnRect->fnGetTop)() ) > 0 )
     181             :             {
     182        7764 :                 pFrm->SetRetouche();
     183             :             }
     184             : 
     185             :             // A fresh follow frame does not have to be invalidated, because
     186             :             // it is already formatted:
     187       36203 :             if ( bHadFollow || !pFrm->IsCntntFrm() || !((SwCntntFrm*)pFrm)->GetFollow() )
     188             :             {
     189       36114 :                 if ( !pFrm->IsTabFrm() || !((SwTabFrm*)pFrm)->GetFollow() )
     190       36063 :                     pFrm->InvalidateNextPos();
     191             :             }
     192             :         }
     193             :     }
     194             : 
     195             :     //For each resize of the background graphics is a repaint necessary.
     196             :     const bool bPrtWidth =
     197      115870 :             (aPrt.*fnRect->fnGetWidth)() != (pFrm->Prt().*fnRect->fnGetWidth)();
     198             :     const bool bPrtHeight =
     199      115870 :             (aPrt.*fnRect->fnGetHeight)()!=(pFrm->Prt().*fnRect->fnGetHeight)();
     200      115870 :     if ( bPrtWidth || bPrtHeight )
     201             :     {
     202       55227 :         const SvxGraphicPosition ePos = pFrm->GetAttrSet()->GetBackground().GetGraphicPos();
     203       55227 :         if ( GPOS_NONE != ePos && GPOS_TILED != ePos )
     204           6 :             pFrm->SetCompletePaint();
     205             :     }
     206             :     else
     207             :     {
     208             :         // #97597# - consider case that *only* margins between
     209             :         // frame and printing area has changed. Then, frame has to be repainted,
     210             :         // in order to force paint of the margin areas.
     211       60643 :         if ( !bAbsP && (bChgWidth || bChgHeight) )
     212             :         {
     213         217 :             pFrm->SetCompletePaint();
     214             :         }
     215             :     }
     216             : 
     217      115870 :     const bool bPrtP = POS_DIFF( aPrt, pFrm->Prt() );
     218      115870 :     if ( bAbsP || bPrtP || bChgWidth || bChgHeight ||
     219       40509 :          bPrtWidth || bPrtHeight || bChgFlyBasePos )
     220             :     {
     221       80915 :         if( pFrm->IsAccessibleFrm() )
     222             :         {
     223       62864 :             SwRootFrm *pRootFrm = pFrm->getRootFrm();
     224       62865 :             if( pRootFrm && pRootFrm->IsAnyShellAccessible() &&
     225           1 :                 pRootFrm->GetCurrShell() )
     226             :             {
     227           1 :                 pRootFrm->GetCurrShell()->Imp()->MoveAccessibleFrm( pFrm, aFrm );
     228             :             }
     229             :         }
     230             : 
     231             :         // Notification of anchored objects
     232       80915 :         if ( pFrm->GetDrawObjs() )
     233             :         {
     234        1826 :             const SwSortedObjs &rObjs = *pFrm->GetDrawObjs();
     235        1826 :             SwPageFrm* pPageFrm = 0;
     236        4396 :             for ( sal_uInt32 i = 0; i < rObjs.Count(); ++i )
     237             :             {
     238             :                 // OD 2004-03-31 #i26791# - no general distinction between
     239             :                 // Writer fly frames and drawing objects
     240        2570 :                 bool bNotify = false;
     241        2570 :                 bool bNotifySize = false;
     242        2570 :                 SwAnchoredObject* pObj = rObjs[i];
     243        2570 :                 SwContact* pContact = ::GetUserCall( pObj->GetDrawObj() );
     244             :                 // #115759#
     245        2570 :                 const bool bAnchoredAsChar = pContact->ObjAnchoredAsChar();
     246        2570 :                 if ( !bAnchoredAsChar )
     247             :                 {
     248             :                     // Notify object, which aren't anchored as-character:
     249             : 
     250             :                     // always notify objects, if frame position has changed
     251             :                     // or if the object is to-page|to-fly anchored.
     252        1653 :                     if ( bAbsP ||
     253        1635 :                          pContact->ObjAnchoredAtPage() ||
     254         216 :                          pContact->ObjAnchoredAtFly() )
     255             :                     {
     256        1203 :                         bNotify = true;
     257             : 
     258             :                         // assure that to-fly anchored Writer fly frames are
     259             :                         // registered at the correct page frame, if frame
     260             :                         // position has changed.
     261        1203 :                         if ( bAbsP && pContact->ObjAnchoredAtFly() &&
     262           0 :                              pObj->ISA(SwFlyFrm) )
     263             :                         {
     264             :                             // determine to-fly anchored Writer fly frame
     265           0 :                             SwFlyFrm* pFlyFrm = static_cast<SwFlyFrm*>(pObj);
     266             :                             // determine page frame of to-fly anchored
     267             :                             // Writer fly frame
     268           0 :                             SwPageFrm* pFlyPageFrm = pFlyFrm->FindPageFrm();
     269             :                             // determine page frame, if needed.
     270           0 :                             if ( !pPageFrm )
     271             :                             {
     272           0 :                                 pPageFrm = pFrm->FindPageFrm();
     273             :                             }
     274           0 :                             if ( pPageFrm != pFlyPageFrm )
     275             :                             {
     276             :                                 OSL_ENSURE( pFlyPageFrm, "~SwFrmNotify: Fly from Nowhere" );
     277           0 :                                 if( pFlyPageFrm )
     278           0 :                                     pFlyPageFrm->MoveFly( pFlyFrm, pPageFrm );
     279             :                                 else
     280           0 :                                     pPageFrm->AppendFlyToPage( pFlyFrm );
     281             :                             }
     282             :                         }
     283             :                     }
     284             :                     // otherwise the objects are notified in dependence to
     285             :                     // its positioning and alignment
     286             :                     else
     287             :                     {
     288             :                         const SwFmtVertOrient& rVert =
     289         216 :                                         pContact->GetFmt()->GetVertOrient();
     290         561 :                         if ( ( rVert.GetVertOrient() == text::VertOrientation::CENTER ||
     291         258 :                                rVert.GetVertOrient() == text::VertOrientation::BOTTOM ||
     292         521 :                                rVert.GetRelationOrient() == text::RelOrientation::PRINT_AREA ) &&
     293           0 :                              ( bChgHeight || bPrtHeight ) )
     294             :                         {
     295          88 :                             bNotify = true;
     296             :                         }
     297         216 :                         if ( !bNotify )
     298             :                         {
     299             :                             const SwFmtHoriOrient& rHori =
     300         128 :                                         pContact->GetFmt()->GetHoriOrient();
     301         362 :                             if ( ( rHori.GetHoriOrient() != text::HoriOrientation::NONE ||
     302         212 :                                    rHori.GetRelationOrient()== text::RelOrientation::PRINT_AREA ||
     303         366 :                                    rHori.GetRelationOrient()== text::RelOrientation::FRAME ) &&
     304         104 :                                  ( bChgWidth || bPrtWidth || bChgFlyBasePos ) )
     305             :                             {
     306          28 :                                 bNotify = true;
     307             :                             }
     308             :                         }
     309             :                     }
     310             :                 }
     311        1151 :                 else if ( bPrtWidth )
     312             :                 {
     313             :                     // Notify as-character anchored objects, if printing area
     314             :                     // width has changed.
     315         716 :                     bNotify = true;
     316         716 :                     bNotifySize = true;
     317             :                 }
     318             : 
     319             :                 // perform notification via the corresponding invalidations
     320        2570 :                 if ( bNotify )
     321             :                 {
     322        2035 :                     if ( pObj->ISA(SwFlyFrm) )
     323             :                     {
     324        1309 :                         SwFlyFrm* pFlyFrm = static_cast<SwFlyFrm*>(pObj);
     325        1309 :                         if ( bNotifySize )
     326         538 :                             pFlyFrm->_InvalidateSize();
     327             :                         // #115759# - no invalidation of
     328             :                         // position for as-character anchored objects.
     329        1309 :                         if ( !bAnchoredAsChar )
     330             :                         {
     331         771 :                             pFlyFrm->_InvalidatePos();
     332             :                         }
     333        1309 :                         pFlyFrm->_Invalidate();
     334             :                     }
     335         726 :                     else if ( pObj->ISA(SwAnchoredDrawObject) )
     336             :                     {
     337             :                         // #115759# - no invalidation of
     338             :                         // position for as-character anchored objects.
     339         726 :                         if ( !bAnchoredAsChar )
     340             :                         {
     341         548 :                             pObj->InvalidateObjPos();
     342             :                         }
     343             :                     }
     344             :                     else
     345             :                     {
     346             :                         OSL_FAIL( "<SwCntntNotify::~SwCntntNotify()> - unknown anchored object type. Please inform OD." );
     347             :                     }
     348             :                 }
     349             :             }
     350       80915 :         }
     351             :     }
     352       34955 :     else if( pFrm->IsTxtFrm() && bValidSize != pFrm->GetValidSizeFlag() )
     353             :     {
     354       12450 :         SwRootFrm *pRootFrm = pFrm->getRootFrm();
     355       12450 :         if( pRootFrm && pRootFrm->IsAnyShellAccessible() &&
     356           0 :             pRootFrm->GetCurrShell() )
     357             :         {
     358           0 :             pRootFrm->GetCurrShell()->Imp()->InvalidateAccessibleFrmContent( pFrm );
     359             :         }
     360             :     }
     361             : 
     362             :     // #i9046# Automatic frame width
     363      115870 :     SwFlyFrm* pFly = 0;
     364             :     // #i35879# Do not trust the inf flags. pFrm does not
     365             :     // necessarily have to have an upper!
     366      115870 :     if ( !pFrm->IsFlyFrm() && 0 != ( pFly = pFrm->ImplFindFlyFrm() ) )
     367             :     {
     368             :         // #i61999#
     369             :         // no invalidation of columned Writer fly frames, because automatic
     370             :         // width doesn't make sense for such Writer fly frames.
     371        5873 :         if ( pFly->Lower() && !pFly->Lower()->IsColumnFrm() )
     372             :         {
     373        5873 :             const SwFmtFrmSize &rFrmSz = pFly->GetFmt()->GetFrmSize();
     374             : 
     375             :             // This could be optimized. Basically the fly frame only has to
     376             :             // be invalidated, if the first line of pFrm (if pFrm is a content
     377             :             // frame, for other frame types its the print area) has changed its
     378             :             // size and pFrm was responsible for the current width of pFly. On
     379             :             // the other hand, this is only rarely used and re-calculation of
     380             :             // the fly frame does not cause too much trouble. So we keep it this
     381             :             // way:
     382        5873 :             if ( ATT_FIX_SIZE != rFrmSz.GetWidthSizeType() )
     383             :             {
     384             :                 // #i50668#, #i50998# - invalidation of position
     385             :                 // of as-character anchored fly frames not needed and can cause
     386             :                 // layout loops
     387         199 :                 if ( !pFly->ISA(SwFlyInCntFrm) )
     388             :                 {
     389         199 :                     pFly->InvalidatePos();
     390             :                 }
     391         199 :                 pFly->InvalidateSize();
     392             :             }
     393             :         }
     394             :     }
     395      115870 : }
     396             : 
     397       66839 : SwLayNotify::SwLayNotify( SwLayoutFrm *pLayFrm ) :
     398             :     SwFrmNotify( pLayFrm ),
     399       66839 :     bLowersComplete( sal_False )
     400             : {
     401       66839 : }
     402             : 
     403             : // OD 2004-05-11 #i28701# - local method to invalidate the position of all
     404             : // frames inclusive its floating screen objects, which are lowers of the given
     405             : // layout frame
     406         164 : static void lcl_InvalidatePosOfLowers( SwLayoutFrm& _rLayoutFrm )
     407             : {
     408         164 :     if( _rLayoutFrm.IsFlyFrm() && _rLayoutFrm.GetDrawObjs() )
     409             :     {
     410           0 :         _rLayoutFrm.InvalidateObjs( true, false );
     411             :     }
     412             : 
     413         164 :     SwFrm* pLowerFrm = _rLayoutFrm.Lower();
     414         524 :     while ( pLowerFrm )
     415             :     {
     416         196 :         pLowerFrm->InvalidatePos();
     417         196 :         if ( pLowerFrm->IsTxtFrm() )
     418             :         {
     419         192 :             static_cast<SwTxtFrm*>(pLowerFrm)->Prepare( PREP_POS_CHGD );
     420             :         }
     421           4 :         else if ( pLowerFrm->IsTabFrm() )
     422             :         {
     423           0 :             pLowerFrm->InvalidatePrt();
     424             :         }
     425             : 
     426         196 :         pLowerFrm->InvalidateObjs( true, false );
     427             : 
     428         196 :         pLowerFrm = pLowerFrm->GetNext();
     429             :     };
     430         164 : }
     431             : 
     432      133678 : SwLayNotify::~SwLayNotify()
     433             : {
     434             :     // #i49383#
     435       66839 :     if ( mbFrmDeleted )
     436             :     {
     437           0 :         return;
     438             :     }
     439             : 
     440       66839 :     SwLayoutFrm *pLay = GetLay();
     441       66839 :     SWRECTFN( pLay )
     442       66839 :     bool bNotify = false;
     443       66839 :     if ( pLay->Prt().SSize() != aPrt.SSize() )
     444             :     {
     445       27580 :         if ( !IsLowersComplete() )
     446             :         {
     447             :             bool bInvaPercent;
     448             : 
     449       27547 :             if ( pLay->IsRowFrm() )
     450             :             {
     451        2537 :                 bInvaPercent = true;
     452        2537 :                 long nNew = (pLay->Prt().*fnRect->fnGetHeight)();
     453        2537 :                 if( nNew != (aPrt.*fnRect->fnGetHeight)() )
     454        2255 :                      ((SwRowFrm*)pLay)->AdjustCells( nNew, sal_True);
     455        5074 :                 if( (pLay->Prt().*fnRect->fnGetWidth)()
     456        2537 :                     != (aPrt.*fnRect->fnGetWidth)() )
     457        2353 :                      ((SwRowFrm*)pLay)->AdjustCells( 0, sal_False );
     458             :             }
     459             :             else
     460             :             {
     461             :                 //Proportional adoption of the internal.
     462             :                 //1. If the formatted is no Fly
     463             :                 //2. If he contains no columns
     464             :                 //3. If the Fly has a fixed hight and the columns
     465             :                 //   are next to be.
     466             :                 //   Hoehe danebenliegen.
     467             :                 //4. Never at SectionFrms.
     468             :                 bool bLow;
     469       25010 :                 if( pLay->IsFlyFrm() )
     470             :                 {
     471        1928 :                     if ( pLay->Lower() )
     472             :                     {
     473        1927 :                         bLow = !pLay->Lower()->IsColumnFrm() ||
     474           0 :                             (pLay->Lower()->Frm().*fnRect->fnGetHeight)()
     475        1927 :                              != (pLay->Prt().*fnRect->fnGetHeight)();
     476             :                     }
     477             :                     else
     478           1 :                         bLow = false;
     479             :                 }
     480       23082 :                 else if( pLay->IsSctFrm() )
     481             :                 {
     482         112 :                     if ( pLay->Lower() )
     483             :                     {
     484         112 :                         if( pLay->Lower()->IsColumnFrm() && pLay->Lower()->GetNext() )
     485          48 :                             bLow = pLay->Lower()->Frm().Height() != pLay->Prt().Height();
     486             :                         else
     487          64 :                             bLow = pLay->Prt().Width() != aPrt.Width();
     488             :                     }
     489             :                     else
     490           0 :                         bLow = false;
     491             :                 }
     492       22970 :                 else if( pLay->IsFooterFrm() && !pLay->HasFixSize() )
     493         626 :                     bLow = pLay->Prt().Width() != aPrt.Width();
     494             :                 else
     495       22344 :                     bLow = true;
     496       25010 :                 bInvaPercent = bLow;
     497       25010 :                 if ( bLow )
     498             :                 {
     499       24903 :                     pLay->ChgLowersProp( aPrt.SSize() );
     500             :                 }
     501             :                 // If the PrtArea has been extended, it might be possible that the chain of parts
     502             :                 // can take another frame. As a result, the "possible right one" needs to be
     503             :                 // invalidated. This only pays off if this or its Uppers are moveable sections.
     504             :                 // A PrtArea has been extended if width or height are larger than before.
     505       57931 :                 if ( (pLay->Prt().Height() > aPrt.Height() ||
     506       48032 :                       pLay->Prt().Width()  > aPrt.Width()) &&
     507       40869 :                      (pLay->IsMoveable() || pLay->IsFlyFrm()) )
     508             :                 {
     509        2363 :                     SwFrm *pTmpFrm = pLay->Lower();
     510        2363 :                     if ( pTmpFrm && pTmpFrm->IsFlowFrm() )
     511             :                     {
     512        5732 :                         while ( pTmpFrm->GetNext() )
     513        1882 :                             pTmpFrm = pTmpFrm->GetNext();
     514        1925 :                         pTmpFrm->InvalidateNextPos();
     515             :                     }
     516             :                 }
     517             :             }
     518       27547 :             bNotify = true;
     519             :             //EXPENSIVE!! But how we do it more elegant?
     520       27547 :             if( bInvaPercent )
     521       27440 :                 pLay->InvaPercentLowers( pLay->Prt().Height() - aPrt.Height() );
     522             :         }
     523       27580 :         if ( pLay->IsTabFrm() )
     524             :             //So that _only_ the shadow is drawn while resizing.
     525         635 :             ((SwTabFrm*)pLay)->SetComplete();
     526             :         else
     527             :         {
     528       26945 :             const SwViewShell *pSh = pLay->getRootFrm()->GetCurrShell();
     529       26996 :             if( !( pSh && pSh->GetViewOptions()->getBrowseMode() ) ||
     530          51 :                   !(pLay->GetType() & (FRM_BODY | FRM_PAGE)) )
     531             :             //Thereby the subordinates are retouched clean.
     532             :             //Example problem: Take the Flys with the handles and downsize.
     533             :             //Not for body and page, otherwise it flickers when loading HTML.
     534       26907 :             pLay->SetCompletePaint();
     535             :         }
     536             :     }
     537             :     //Notify Lower if the position has changed.
     538       66839 :     const bool bPrtPos = POS_DIFF( aPrt, pLay->Prt() );
     539       66839 :     const bool bPos = bPrtPos || POS_DIFF( aFrm, pLay->Frm() );
     540       66839 :     const bool bSize = pLay->Frm().SSize() != aFrm.SSize();
     541             : 
     542       66839 :     if ( bPos && pLay->Lower() && !IsLowersComplete() )
     543       33952 :         pLay->Lower()->InvalidatePos();
     544             : 
     545       66839 :     if ( bPrtPos )
     546       10458 :         pLay->SetCompletePaint();
     547             : 
     548             :     //Inform the Follower if the SSize has changed.
     549       66839 :     if ( bSize )
     550             :     {
     551       13121 :         if( pLay->GetNext() )
     552             :         {
     553        7573 :             if ( pLay->GetNext()->IsLayoutFrm() )
     554        6861 :                 pLay->GetNext()->_InvalidatePos();
     555             :             else
     556         712 :                 pLay->GetNext()->InvalidatePos();
     557             :         }
     558        5548 :         else if( pLay->IsSctFrm() )
     559          91 :             pLay->InvalidateNextPos();
     560             :     }
     561      200482 :     if ( !IsLowersComplete() &&
     562       72970 :          !(pLay->GetType()&(FRM_FLY|FRM_SECTION) &&
     563       12322 :             pLay->Lower() && pLay->Lower()->IsColumnFrm()) &&
     564       93679 :          (bPos || bNotify) && !(pLay->GetType() & 0x1823) )  //Tab, Row, FtnCont, Root, Page
     565             :     {
     566             :         // #i44016# - force unlock of position of lower objects.
     567             :         // #i43913# - no unlock of position of objects,
     568             :         // if <pLay> is a cell frame, and its table frame resp. its parent table
     569             :         // frame is locked.
     570             :         // #i47458# - force unlock of position of lower objects,
     571             :         // only if position of layout frame has changed.
     572       34451 :         bool bUnlockPosOfObjs( bPos );
     573       34451 :         if ( bUnlockPosOfObjs && pLay->IsCellFrm() )
     574             :         {
     575       20058 :             SwTabFrm* pTabFrm( pLay->FindTabFrm() );
     576       54153 :             if ( pTabFrm &&
     577       26079 :                  ( pTabFrm->IsJoinLocked() ||
     578        6107 :                    ( pTabFrm->IsFollow() &&
     579          86 :                      pTabFrm->FindMaster()->IsJoinLocked() ) ) )
     580             :             {
     581       14037 :                 bUnlockPosOfObjs = false;
     582             :             }
     583             :         }
     584             :         // #i49383# - check for footnote frame, if unlock
     585             :         // of position of lower objects is allowed.
     586       14393 :         else if ( bUnlockPosOfObjs && pLay->IsFtnFrm() )
     587             :         {
     588         164 :             bUnlockPosOfObjs = static_cast<SwFtnFrm*>(pLay)->IsUnlockPosOfLowerObjs();
     589             :         }
     590             :         // #i51303# - no unlock of object positions for sections
     591       14229 :         else if ( bUnlockPosOfObjs && pLay->IsSctFrm() )
     592             :         {
     593         285 :             bUnlockPosOfObjs = false;
     594             :         }
     595       34451 :         pLay->NotifyLowerObjs( bUnlockPosOfObjs );
     596             :     }
     597       66839 :     if ( bPos && pLay->IsFtnFrm() && pLay->Lower() )
     598             :     {
     599             :         // OD 2004-05-11 #i28701#
     600         164 :         ::lcl_InvalidatePosOfLowers( *pLay );
     601             :     }
     602       93724 :     if( ( bPos || bSize ) && pLay->IsFlyFrm() && ((SwFlyFrm*)pLay)->GetAnchorFrm()
     603       69808 :           && ((SwFlyFrm*)pLay)->GetAnchorFrm()->IsFlyFrm() )
     604           0 :         ((SwFlyFrm*)pLay)->AnchorFrm()->InvalidateSize();
     605       66839 : }
     606             : 
     607        5574 : SwFlyNotify::SwFlyNotify( SwFlyFrm *pFlyFrm ) :
     608             :     SwLayNotify( pFlyFrm ),
     609             :     // #115759# - keep correct page frame - the page frame
     610             :     // the Writer fly frame is currently registered at.
     611        5574 :     pOldPage( pFlyFrm->GetPageFrm() ),
     612       11148 :     aFrmAndSpace( pFlyFrm->GetObjRectWithSpaces() )
     613             : {
     614        5574 : }
     615             : 
     616       11148 : SwFlyNotify::~SwFlyNotify()
     617             : {
     618             :     // #i49383#
     619        5574 :     if ( mbFrmDeleted )
     620             :     {
     621           0 :         return;
     622             :     }
     623             : 
     624        5574 :     SwFlyFrm *pFly = GetFly();
     625        5574 :     if ( pFly->IsNotifyBack() )
     626             :     {
     627        3161 :         SwViewShell *pSh = pFly->getRootFrm()->GetCurrShell();
     628        3161 :         SwViewImp *pImp = pSh ? pSh->Imp() : 0;
     629        3161 :         if ( !pImp || !pImp->IsAction() || !pImp->GetLayAction().IsAgain() )
     630             :         {
     631             :             //If in the LayAction the IsAgain is set it can be
     632             :             //that the old page is destroyed in the meantime!
     633        3145 :             ::Notify( pFly, pOldPage, aFrmAndSpace, &aPrt );
     634             :             // #i35640# - additional notify anchor text frame,
     635             :             // if Writer fly frame has changed its page
     636        6181 :             if ( pFly->GetAnchorFrm()->IsTxtFrm() &&
     637        3036 :                  pFly->GetPageFrm() != pOldPage )
     638             :             {
     639          18 :                 pFly->AnchorFrm()->Prepare( PREP_FLY_LEAVE );
     640             :             }
     641             :         }
     642        3161 :         pFly->ResetNotifyBack();
     643             :     }
     644             : 
     645             :     //Have the size or the positon changed,
     646             :     //so should the view know this.
     647        5574 :     SWRECTFN( pFly )
     648        5574 :     const bool bPosChgd = POS_DIFF( aFrm, pFly->Frm() );
     649        5574 :     const bool bFrmChgd = pFly->Frm().SSize() != aFrm.SSize();
     650        5574 :     const bool bPrtChgd = aPrt != pFly->Prt();
     651        5574 :     if ( bPosChgd || bFrmChgd || bPrtChgd )
     652             :     {
     653        3017 :         pFly->NotifyDrawObj();
     654             :     }
     655        5574 :     if ( bPosChgd && aFrm.Pos().X() != FAR_AWAY )
     656             :     {
     657             :         // OD 2004-05-10 #i28701# - no direct move of lower Writer fly frames.
     658             :         // reason: New positioning and alignment (e.g. to-paragraph anchored,
     659             :         // but aligned at page) are introduced.
     660             :         // <SwLayNotify::~SwLayNotify()> takes care of invalidation of lower
     661             :         // floating screen objects by calling method <SwLayoutFrm::NotifyLowerObjs()>.
     662             : 
     663        1127 :         if ( pFly->IsFlyAtCntFrm() )
     664             :         {
     665         166 :             SwFrm *pNxt = pFly->AnchorFrm()->FindNext();
     666         166 :             if ( pNxt )
     667             :             {
     668         126 :                 pNxt->InvalidatePos();
     669             :             }
     670             :         }
     671             : 
     672             :         // #i26945# - notify anchor.
     673             :         // Needed for negative positioned Writer fly frames
     674        1127 :         if ( pFly->GetAnchorFrm()->IsTxtFrm() )
     675             :         {
     676        1125 :             pFly->AnchorFrm()->Prepare( PREP_FLY_LEAVE );
     677             :         }
     678             :     }
     679             : 
     680             :     // OD 2004-05-13 #i28701#
     681             :     // #i45180# - no adjustment of layout process flags and
     682             :     // further notifications/invalidations, if format is called by grow/shrink
     683        7346 :     if ( pFly->ConsiderObjWrapInfluenceOnObjPos() &&
     684        2280 :          ( !pFly->ISA(SwFlyFreeFrm) ||
     685        1140 :            !static_cast<SwFlyFreeFrm*>(pFly)->IsNoMoveOnCheckClip() ) )
     686             :     {
     687             :         // #i54138# - suppress restart of the layout process
     688             :         // on changed frame height.
     689             :         // Note: It doesn't seem to be necessary and can cause layout loops.
     690         632 :         if ( bPosChgd )
     691             :         {
     692             :             // indicate a restart of the layout process
     693         308 :             pFly->SetRestartLayoutProcess( true );
     694             :         }
     695             :         else
     696             :         {
     697             :             // lock position
     698         324 :             pFly->LockPosition();
     699             : 
     700         324 :             if ( !pFly->ConsiderForTextWrap() )
     701             :             {
     702             :                 // indicate that object has to be considered for text wrap
     703         297 :                 pFly->SetConsiderForTextWrap( true );
     704             :                 // invalidate 'background' in order to allow its 'background'
     705             :                 // to wrap around it.
     706             :                 pFly->NotifyBackground( pFly->GetPageFrm(),
     707         297 :                                         pFly->GetObjRectWithSpaces(),
     708         594 :                                         PREP_FLY_ARRIVE );
     709             :                 // invalidate position of anchor frame in order to force
     710             :                 // a re-format of the anchor frame, which also causes a
     711             :                 // re-format of the invalid previous frames of the anchor frame.
     712         297 :                 pFly->AnchorFrm()->InvalidatePos();
     713             :             }
     714             :         }
     715             :     }
     716        5574 : }
     717             : 
     718       49031 : SwCntntNotify::SwCntntNotify( SwCntntFrm *pCntntFrm ) :
     719             :     SwFrmNotify( pCntntFrm ),
     720             :     // OD 08.01.2004 #i11859#
     721             :     mbChkHeightOfLastLine( false ),
     722             :     mnHeightOfLastLine( 0L ),
     723             :     // OD 2004-02-26 #i25029#
     724             :     mbInvalidatePrevPrtArea( false ),
     725       49031 :     mbBordersJoinedWithPrev( false )
     726             : {
     727             :     // OD 08.01.2004 #i11859#
     728       49031 :     if ( pCntntFrm->IsTxtFrm() )
     729             :     {
     730       47848 :         SwTxtFrm* pTxtFrm = static_cast<SwTxtFrm*>(pCntntFrm);
     731       47848 :         if ( !pTxtFrm->GetTxtNode()->getIDocumentSettingAccess()->get(IDocumentSettingAccess::OLD_LINE_SPACING) )
     732             :         {
     733       47835 :             const SwAttrSet* pSet = pTxtFrm->GetAttrSet();
     734       47835 :             const SvxLineSpacingItem &rSpace = pSet->GetLineSpacing();
     735       47835 :             if ( rSpace.GetInterLineSpaceRule() == SVX_INTER_LINE_SPACE_PROP )
     736             :             {
     737       16721 :                 mbChkHeightOfLastLine = true;
     738       16721 :                 mnHeightOfLastLine = pTxtFrm->GetHeightOfLastLine();
     739             :             }
     740             :         }
     741             :     }
     742       49031 : }
     743             : 
     744       98062 : SwCntntNotify::~SwCntntNotify()
     745             : {
     746             :     // #i49383#
     747       49031 :     if ( mbFrmDeleted )
     748             :     {
     749           0 :         return;
     750             :     }
     751             : 
     752       49031 :     SwCntntFrm *pCnt = GetCnt();
     753       49031 :     if ( bSetCompletePaintOnInvalidate )
     754         260 :         pCnt->SetCompletePaint();
     755             : 
     756       49031 :     SWRECTFN( pCnt )
     757       53669 :     if ( pCnt->IsInTab() && ( POS_DIFF( pCnt->Frm(), aFrm ) ||
     758        4638 :                              pCnt->Frm().SSize() != aFrm.SSize()))
     759             :     {
     760       11795 :         SwLayoutFrm* pCell = pCnt->GetUpper();
     761       23592 :         while( !pCell->IsCellFrm() && pCell->GetUpper() )
     762           2 :             pCell = pCell->GetUpper();
     763             :         OSL_ENSURE( pCell->IsCellFrm(), "Where's my cell?" );
     764       11795 :         if ( text::VertOrientation::NONE != pCell->GetFmt()->GetVertOrient().GetVertOrient() )
     765        3462 :             pCell->InvalidatePrt(); //for the vertical allign.
     766             :     }
     767             : 
     768             :     // OD 2004-02-26 #i25029#
     769       50566 :     if ( mbInvalidatePrevPrtArea && mbBordersJoinedWithPrev &&
     770         612 :          pCnt->IsTxtFrm() &&
     771       49643 :          !pCnt->IsFollow() && !pCnt->GetIndPrev() )
     772             :     {
     773             :         // determine previous frame
     774         306 :         SwFrm* pPrevFrm = pCnt->FindPrev();
     775             :         // skip empty section frames and hidden text frames
     776             :         {
     777         915 :             while ( pPrevFrm &&
     778         303 :                     ( ( pPrevFrm->IsSctFrm() &&
     779         303 :                         !static_cast<SwSectionFrm*>(pPrevFrm)->GetSection() ) ||
     780         606 :                       ( pPrevFrm->IsTxtFrm() &&
     781         303 :                         static_cast<SwTxtFrm*>(pPrevFrm)->IsHiddenNow() ) ) )
     782             :             {
     783           0 :                 pPrevFrm = pPrevFrm->FindPrev();
     784             :             }
     785             :         }
     786             : 
     787             :         // Invalidate printing area of found previous frame
     788         306 :         if ( pPrevFrm )
     789             :         {
     790         303 :             if ( pPrevFrm->IsSctFrm() )
     791             :             {
     792           0 :                 if ( pCnt->IsInSct() )
     793             :                 {
     794             :                     // Note: found previous frame is a section frame and
     795             :                     //       <pCnt> is also inside a section.
     796             :                     //       Thus due to <mbBordersJoinedWithPrev>,
     797             :                     //       <pCnt> had joined its borders/shadow with the
     798             :                     //       last content of the found section.
     799             :                     // Invalidate printing area of last content in found section.
     800             :                     SwFrm* pLstCntntOfSctFrm =
     801           0 :                             static_cast<SwSectionFrm*>(pPrevFrm)->FindLastCntnt();
     802           0 :                     if ( pLstCntntOfSctFrm )
     803             :                     {
     804           0 :                         pLstCntntOfSctFrm->InvalidatePrt();
     805             :                     }
     806             :                 }
     807             :             }
     808             :             else
     809             :             {
     810         303 :                 pPrevFrm->InvalidatePrt();
     811             :             }
     812             :         }
     813             :     }
     814             : 
     815       49031 :     const bool bFirst = (aFrm.*fnRect->fnGetWidth)() == 0;
     816             : 
     817       49031 :     if ( pCnt->IsNoTxtFrm() )
     818             :     {
     819             :         //Active PlugIn's or OLE-Objects should know something of the change
     820             :         //thereby they move their window appropriate.
     821        1183 :         SwViewShell *pSh  = pCnt->getRootFrm()->GetCurrShell();
     822        1183 :         if ( pSh )
     823             :         {
     824             :             SwOLENode *pNd;
     825        2587 :             if ( 0 != (pNd = pCnt->GetNode()->GetOLENode()) &&
     826         702 :                  (pNd->GetOLEObj().IsOleRef() ||
     827           0 :                   pNd->IsOLESizeInvalid()) )
     828             :             {
     829             :                 const bool bNoTxtFrmPrtAreaChanged =
     830        1040 :                         ( aPrt.SSize().Width() != 0 &&
     831        1040 :                           aPrt.SSize().Height() != 0 ) &&
     832        1040 :                         aPrt.SSize() != pCnt->Prt().SSize();
     833             :                 OSL_ENSURE( pCnt->IsInFly(), "OLE not in FlyFrm" );
     834         702 :                 SwFlyFrm *pFly = pCnt->FindFlyFrm();
     835         702 :                 svt::EmbeddedObjectRef& xObj = pNd->GetOLEObj().GetObject();
     836         702 :                 SwFEShell *pFESh = 0;
     837         702 :                 SwViewShell *pTmp = pSh;
     838         702 :                 do
     839         702 :                 {   if ( pTmp->ISA( SwCrsrShell ) )
     840             :                     {
     841         693 :                         pFESh = (SwFEShell*)pTmp;
     842             :                         // #108369#: Here used to be the condition if (!bFirst).
     843             :                         // I think this should mean "do not call CalcAndSetScale"
     844             :                         // if the frame is formatted for the first time.
     845             :                         // Unfortunately this is not valid anymore since the
     846             :                         // SwNoTxtFrm already gets a width during CalcLowerPreps.
     847             :                         // Nevertheless, the indention of !bFirst seemed to be
     848             :                         // to assure that the OLE objects have already been notified
     849             :                         // if necessary before calling CalcAndSetScale.
     850             :                         // So I replaced !bFirst by !IsOLESizeInvalid. There is
     851             :                         // one additional problem specific to the word import:
     852             :                         // The layout is calculated _before_ calling PrtOLENotify,
     853             :                         // and the OLE objects are not invalidated during import.
     854             :                         // Therefore I added the condition !IsUpdateExpFld,
     855             :                         // have a look at the occurrence of CalcLayout in
     856             :                         // uiview/view.cxx.
     857        1377 :                         if ( !pNd->IsOLESizeInvalid() &&
     858         684 :                              !pSh->GetDoc()->IsUpdateExpFld() )
     859             :                             pFESh->CalcAndSetScale( xObj,
     860         684 :                                                     &pFly->Prt(), &pFly->Frm(),
     861        1368 :                                                     bNoTxtFrmPrtAreaChanged );
     862             :                     }
     863         702 :                     pTmp = (SwViewShell*)pTmp->GetNext();
     864             :                 } while ( pTmp != pSh );
     865             : 
     866         702 :                 if ( pFESh && pNd->IsOLESizeInvalid() )
     867             :                 {
     868           9 :                     pNd->SetOLESizeInvalid( sal_False );
     869           9 :                     pFESh->CalcAndSetScale( xObj ); // create client
     870             :                 }
     871             :             }
     872             :             //dito animated graphics
     873        1183 :             if ( Frm().HasArea() && ((SwNoTxtFrm*)pCnt)->HasAnimation() )
     874             :             {
     875           0 :                 ((SwNoTxtFrm*)pCnt)->StopAnimation();
     876           0 :                 pSh->InvalidateWindows( Frm() );
     877             :             }
     878             :         }
     879             :     }
     880             : 
     881       49031 :     if ( bFirst )
     882             :     {
     883       22906 :         pCnt->SetRetouche();    //fix(13870)
     884             : 
     885       22906 :         SwDoc *pDoc = pCnt->GetNode()->GetDoc();
     886       58961 :         if ( !pDoc->GetSpzFrmFmts()->empty() &&
     887       22906 :              pDoc->DoesContainAtPageObjWithContentAnchor() && !pDoc->IsNewDoc() )
     888             :         {
     889             :             // If certain import filters for foreign file format import
     890             :             // AT_PAGE anchored objects, the corresponding page number is
     891             :             // typically not known. In this case the content position is
     892             :             // stored at which the anchored object is found in the
     893             :             // imported document.
     894             :             // When this content is formatted it is the time at which
     895             :             // the page is known. Thus, this data can be corrected now.
     896             : 
     897           0 :             const SwPageFrm *pPage = 0;
     898           0 :             SwNodeIndex *pIdx  = 0;
     899           0 :             SwFrmFmts *pTbl = pDoc->GetSpzFrmFmts();
     900             : 
     901           0 :             for ( sal_uInt16 i = 0; i < pTbl->size(); ++i )
     902             :             {
     903           0 :                 SwFrmFmt *pFmt = (*pTbl)[i];
     904           0 :                 const SwFmtAnchor &rAnch = pFmt->GetAnchor();
     905           0 :                 if ( FLY_AT_PAGE != rAnch.GetAnchorId() ||
     906           0 :                      rAnch.GetCntntAnchor() == 0 )
     907             :                 {
     908           0 :                     continue;
     909             :                 }
     910             : 
     911           0 :                 if ( !pIdx )
     912             :                 {
     913           0 :                     pIdx = new SwNodeIndex( *pCnt->GetNode() );
     914             :                 }
     915           0 :                 if ( rAnch.GetCntntAnchor()->nNode == *pIdx )
     916             :                 {
     917             :                     OSL_FAIL( "<SwCntntNotify::~SwCntntNotify()> - to page anchored object with content position. Please inform OD." );
     918           0 :                     if ( !pPage )
     919             :                     {
     920           0 :                         pPage = pCnt->FindPageFrm();
     921             :                     }
     922           0 :                     SwFmtAnchor aAnch( rAnch );
     923           0 :                     aAnch.SetAnchor( 0 );
     924           0 :                     aAnch.SetPageNum( pPage->GetPhyPageNum() );
     925           0 :                     pFmt->SetFmtAttr( aAnch );
     926           0 :                     if ( RES_DRAWFRMFMT != pFmt->Which() )
     927             :                     {
     928           0 :                         pFmt->MakeFrms();
     929           0 :                     }
     930             :                 }
     931             :             }
     932           0 :             delete pIdx;
     933             :         }
     934             :     }
     935             : 
     936             :     // OD 12.01.2004 #i11859# - invalidate printing area of following frame,
     937             :     //  if height of last line has changed.
     938       49031 :     if ( pCnt->IsTxtFrm() && mbChkHeightOfLastLine )
     939             :     {
     940       16721 :         if ( mnHeightOfLastLine != static_cast<SwTxtFrm*>(pCnt)->GetHeightOfLastLine() )
     941             :         {
     942        8427 :             pCnt->InvalidateNextPrtArea();
     943             :         }
     944             :     }
     945             : 
     946             :     // #i44049#
     947       49031 :     if ( pCnt->IsTxtFrm() && POS_DIFF( aFrm, pCnt->Frm() ) )
     948             :     {
     949       30744 :         pCnt->InvalidateObjs( true );
     950             :     }
     951             : 
     952             :     // #i43255# - move code to invalidate at-character
     953             :     // anchored objects due to a change of its anchor character from
     954             :     // method <SwTxtFrm::Format(..)>.
     955       49031 :     if ( pCnt->IsTxtFrm() )
     956             :     {
     957       47848 :         SwTxtFrm* pMasterFrm = pCnt->IsFollow()
     958        1354 :                                ? static_cast<SwTxtFrm*>(pCnt)->FindMaster()
     959       49202 :                                : static_cast<SwTxtFrm*>(pCnt);
     960       95696 :         if ( pMasterFrm && !pMasterFrm->IsFlyLock() &&
     961       47848 :              pMasterFrm->GetDrawObjs() )
     962             :         {
     963        3580 :             SwSortedObjs* pObjs = pMasterFrm->GetDrawObjs();
     964       22844 :             for ( sal_uInt32 i = 0; i < pObjs->Count(); ++i )
     965             :             {
     966       19264 :                 SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     967       19264 :                 if ( pAnchoredObj->GetFrmFmt().GetAnchor().GetAnchorId()
     968             :                         == FLY_AT_CHAR )
     969             :                 {
     970        1114 :                     pAnchoredObj->CheckCharRectAndTopOfLine( !pMasterFrm->IsEmpty() );
     971             :                 }
     972             :             }
     973             :         }
     974             :     }
     975       49031 : }
     976             : 
     977       11490 : void AppendObjs( const SwFrmFmts *pTbl, sal_uLong nIndex,
     978             :                         SwFrm *pFrm, SwPageFrm *pPage )
     979             : {
     980      130491 :     for ( sal_uInt16 i = 0; i < pTbl->size(); ++i )
     981             :     {
     982      119001 :         SwFrmFmt *pFmt = (SwFrmFmt*)(*pTbl)[i];
     983      119001 :         const SwFmtAnchor &rAnch = pFmt->GetAnchor();
     984      227934 :         if ( rAnch.GetCntntAnchor() &&
     985      108933 :              (rAnch.GetCntntAnchor()->nNode.GetIndex() == nIndex) )
     986             :         {
     987         692 :             const bool bFlyAtFly = rAnch.GetAnchorId() == FLY_AT_FLY; // LAYER_IMPL
     988             :             //Is a frame or a SdrObject described?
     989         692 :             const bool bSdrObj = RES_DRAWFRMFMT == pFmt->Which();
     990             :             // OD 23.06.2003 #108784# - append also drawing objects anchored
     991             :             // as character.
     992        1032 :             const bool bDrawObjInCntnt = bSdrObj &&
     993        1032 :                                          (rAnch.GetAnchorId() == FLY_AS_CHAR);
     994             : 
     995        1384 :             if( bFlyAtFly ||
     996        1079 :                 (rAnch.GetAnchorId() == FLY_AT_PARA) ||
     997        1271 :                 (rAnch.GetAnchorId() == FLY_AT_CHAR) ||
     998             :                 bDrawObjInCntnt )
     999             :             {
    1000         590 :                 SdrObject* pSdrObj = 0;
    1001         590 :                 if ( bSdrObj && 0 == (pSdrObj = pFmt->FindSdrObject()) )
    1002             :                 {
    1003             :                     OSL_ENSURE( !bSdrObj, "DrawObject not found." );
    1004           0 :                     pFmt->GetDoc()->DelFrmFmt( pFmt );
    1005           0 :                     --i;
    1006           0 :                     continue;
    1007             :                 }
    1008         590 :                 if ( pSdrObj )
    1009             :                 {
    1010         340 :                     if ( !pSdrObj->GetPage() )
    1011             :                     {
    1012           0 :                         pFmt->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage(0)->
    1013           0 :                                 InsertObject(pSdrObj, pSdrObj->GetOrdNumDirect());
    1014             :                     }
    1015             : 
    1016             :                     SwDrawContact* pNew =
    1017         340 :                         static_cast<SwDrawContact*>(GetUserCall( pSdrObj ));
    1018         340 :                     if ( !pNew->GetAnchorFrm() )
    1019             :                     {
    1020         290 :                         pFrm->AppendDrawObj( *(pNew->GetAnchoredObj( 0L )) );
    1021             :                     }
    1022             :                     // OD 19.06.2003 #108784# - add 'virtual' drawing object,
    1023             :                     // if necessary. But control objects have to be excluded.
    1024         150 :                     else if ( !::CheckControlLayer( pSdrObj ) &&
    1025         100 :                               pNew->GetAnchorFrm() != pFrm &&
    1026          50 :                               !pNew->GetDrawObjectByAnchorFrm( *pFrm ) )
    1027             :                     {
    1028          50 :                         SwDrawVirtObj* pDrawVirtObj = pNew->AddVirtObj();
    1029          50 :                         pFrm->AppendDrawObj( *(pNew->GetAnchoredObj( pDrawVirtObj )) );
    1030             : 
    1031          50 :                         pDrawVirtObj->ActionChanged();
    1032             :                     }
    1033             : 
    1034             :                 }
    1035             :                 else
    1036             :                 {
    1037             :                     SwFlyFrm *pFly;
    1038         250 :                     if( bFlyAtFly )
    1039           0 :                         pFly = new SwFlyLayFrm( (SwFlyFrmFmt*)pFmt, pFrm, pFrm );
    1040             :                     else
    1041         250 :                         pFly = new SwFlyAtCntFrm( (SwFlyFrmFmt*)pFmt, pFrm, pFrm );
    1042         250 :                     pFly->Lock();
    1043         250 :                     pFrm->AppendFly( pFly );
    1044         250 :                     pFly->Unlock();
    1045         250 :                     if ( pPage )
    1046          66 :                         ::RegistFlys( pPage, pFly );
    1047             :                 }
    1048             :             }
    1049             :         }
    1050             :     }
    1051       11490 : }
    1052             : 
    1053        1640 : static bool lcl_ObjConnected( SwFrmFmt *pFmt, const SwFrm* pSib )
    1054             : {
    1055        1640 :     SwIterator<SwFlyFrm,SwFmt> aIter( *pFmt );
    1056        1640 :     if ( RES_FLYFRMFMT == pFmt->Which() )
    1057             :     {
    1058         936 :         const SwRootFrm* pRoot = pSib ? pSib->getRootFrm() : 0;
    1059             :         const SwFlyFrm* pTmpFrm;
    1060         936 :         for( pTmpFrm = aIter.First(); pTmpFrm; pTmpFrm = aIter.Next() )
    1061             :         {
    1062         559 :             if(! pRoot || pRoot == pTmpFrm->getRootFrm() )
    1063         559 :                 return true;
    1064             :         }
    1065             :     }
    1066             :     else
    1067             :     {
    1068         704 :         SwDrawContact *pContact = SwIterator<SwDrawContact,SwFmt>::FirstElement(*pFmt);
    1069         704 :         if ( pContact )
    1070         704 :             return pContact->GetAnchorFrm() != 0;
    1071             :     }
    1072         377 :     return false;
    1073             : }
    1074             : 
    1075             : /** helper method to determine, if a <SwFrmFmt>, which has an object connected,
    1076             :     is located in header or footer.
    1077             : 
    1078             :     OD 23.06.2003 #108784#
    1079             : */
    1080         344 : static bool lcl_InHeaderOrFooter( SwFrmFmt& _rFmt )
    1081             : {
    1082         344 :     bool bRetVal = false;
    1083             : 
    1084         344 :     const SwFmtAnchor& rAnch = _rFmt.GetAnchor();
    1085             : 
    1086         344 :     if (rAnch.GetAnchorId() != FLY_AT_PAGE)
    1087             :     {
    1088         344 :         bRetVal = _rFmt.GetDoc()->IsInHeaderFooter( rAnch.GetCntntAnchor()->nNode );
    1089             :     }
    1090             : 
    1091         344 :     return bRetVal;
    1092             : }
    1093             : 
    1094        1740 : void AppendAllObjs( const SwFrmFmts *pTbl, const SwFrm* pSib )
    1095             : {
    1096             :     //Connecting of all Objects, which are described in the SpzTbl with the
    1097             :     //layout.
    1098             :     //If nothing happens anymore we can stop. Then formats can still remain,
    1099             :     //because we neither use character bound frames nor objects which
    1100             :     //are anchored to character bounds.
    1101             : 
    1102        1740 :     SwFrmFmts aCpy( *pTbl );
    1103             : 
    1104        1740 :     sal_uInt16 nOldCnt = USHRT_MAX;
    1105             : 
    1106        4137 :     while ( !aCpy.empty() && aCpy.size() != nOldCnt )
    1107             :     {
    1108         657 :         nOldCnt = aCpy.size();
    1109        2318 :         for ( int i = 0; i < int(aCpy.size()); ++i )
    1110             :         {
    1111        1661 :             SwFrmFmt *pFmt = (SwFrmFmt*)aCpy[ sal_uInt16(i) ];
    1112        1661 :             const SwFmtAnchor &rAnch = pFmt->GetAnchor();
    1113        1661 :             sal_Bool bRemove = sal_False;
    1114        3303 :             if ((rAnch.GetAnchorId() == FLY_AT_PAGE) ||
    1115        1642 :                 (rAnch.GetAnchorId() == FLY_AS_CHAR))
    1116             :             {
    1117             :                 //Page bounded are already anchored, character bounded
    1118             :                 //I don't want here.
    1119         712 :                 bRemove = sal_True;
    1120             :             }
    1121        1293 :             else if ( sal_False == (bRemove = ::lcl_ObjConnected( pFmt, pSib )) ||
    1122         344 :                       ::lcl_InHeaderOrFooter( *pFmt ) )
    1123             :             {
    1124             :             // OD 23.06.2003 #108784# - correction: for objects in header
    1125             :             // or footer create frames, in spite of the fact that an connected
    1126             :             // objects already exists.
    1127             :                 //Call for Flys and DrawObjs only a MakeFrms if nor
    1128             :                 //no dependent exists, otherwise, or if the MakeDrms creates no
    1129             :                 //dependents, remove.
    1130         691 :                 pFmt->MakeFrms();
    1131         691 :                 bRemove = ::lcl_ObjConnected( pFmt, pSib );
    1132             :             }
    1133        1661 :             if ( bRemove )
    1134             :             {
    1135        1633 :                 aCpy.erase( aCpy.begin() + i );
    1136        1633 :                 --i;
    1137             :             }
    1138             :         }
    1139             :     }
    1140        1740 :     aCpy.clear();
    1141        1740 : }
    1142             : 
    1143             : /** local method to set 'working' position for newly inserted frames
    1144             : 
    1145             :     OD 12.08.2003 #i17969#
    1146             : */
    1147       24898 : static void lcl_SetPos( SwFrm&             _rNewFrm,
    1148             :                  const SwLayoutFrm& _rLayFrm )
    1149             : {
    1150       24898 :     SWRECTFN( (&_rLayFrm) )
    1151       24898 :     (_rNewFrm.Frm().*fnRect->fnSetPos)( (_rLayFrm.Frm().*fnRect->fnGetPos)() );
    1152             :     // move position by one SwTwip in text flow direction in order to get
    1153             :     // notifications for a new calculated position after its formatting.
    1154       24898 :     if ( bVert )
    1155           1 :         _rNewFrm.Frm().Pos().X() -= 1;
    1156             :     else
    1157       24897 :         _rNewFrm.Frm().Pos().Y() += 1;
    1158       24898 : }
    1159             : 
    1160       12414 : void _InsertCnt( SwLayoutFrm *pLay, SwDoc *pDoc,
    1161             :                              sal_uLong nIndex, sal_Bool bPages, sal_uLong nEndIndex,
    1162             :                              SwFrm *pPrv )
    1163             : {
    1164       12414 :     pDoc->BlockIdling();
    1165       12414 :     SwRootFrm* pLayout = pLay->getRootFrm();
    1166       12414 :     const sal_Bool bOldCallbackActionEnabled = pLayout ? pLayout->IsCallbackActionEnabled() : sal_False;
    1167       12414 :     if( bOldCallbackActionEnabled )
    1168        1460 :         pLayout->SetCallbackActionEnabled( sal_False );
    1169             : 
    1170             :     //In the generation of the Layout will be bPage with sal_True handed over.
    1171             :     //Then will be new pages generated all x paragraphs already times in advance.
    1172             :     //On breaks and/or pagedescriptorchanges the correspondig will be generated
    1173             :     //immediately.
    1174             :     //The advantage is, that on one hand already a nearly realistic number of
    1175             :     //pages are created, but above all there are no almost endless long chain
    1176             :     //of paragraphs, which must be moved expensively until it reaches a tolarable
    1177             :     //reduced level.
    1178             :     //We'd like to think that 20 Paragraphs fit on one page.
    1179             :     //So that it does not become in extremly situations so violent we calculate depending
    1180             :     //on the node something to it.
    1181             :     //If in the DocStatistik a usable given pagenumber
    1182             :     //(Will be cared for while writing), so it will be presumed that this will be
    1183             :     //number of pages.
    1184       12414 :     const bool bStartPercent = bPages && !nEndIndex;
    1185             : 
    1186       12414 :     SwPageFrm *pPage = pLay->FindPageFrm();
    1187       12414 :     const SwFrmFmts *pTbl = pDoc->GetSpzFrmFmts();
    1188       12414 :     SwFrm       *pFrm = 0;
    1189       12414 :     sal_Bool   bBreakAfter   = sal_False;
    1190             : 
    1191       12414 :     SwActualSection *pActualSection = 0;
    1192             :     SwLayHelper *pPageMaker;
    1193             : 
    1194             :     //If the layout will be created (bPages == sal_True) we do head on the progress
    1195             :     //Flys and DrawObjekte are not connected immediately, this
    1196             :     //happens only at the end of the function.
    1197       12414 :     if ( bPages )
    1198             :     {
    1199             :         // Attention: the SwLayHelper class uses references to the content-,
    1200             :         // page-, layout-frame etc. and may change them!
    1201             :         pPageMaker = new SwLayHelper( pDoc, pFrm, pPrv, pPage, pLay,
    1202        1732 :                 pActualSection, bBreakAfter, nIndex, 0 == nEndIndex );
    1203        1732 :         if( bStartPercent )
    1204             :         {
    1205        1732 :             const sal_uLong nPageCount = pPageMaker->CalcPageCount();
    1206        1732 :             if( nPageCount )
    1207         596 :                 bObjsDirect = false;
    1208             :         }
    1209             :     }
    1210             :     else
    1211       10682 :         pPageMaker = NULL;
    1212             : 
    1213       12420 :     if( pLay->IsInSct() &&
    1214           3 :         ( pLay->IsSctFrm() || pLay->GetUpper() ) ) // Hereby will newbies
    1215             :             // be intercepted, of which flags could not determined yet,
    1216             :             // for e.g. while inserting a table
    1217             :     {
    1218           3 :         SwSectionFrm* pSct = pLay->FindSctFrm();
    1219             :         // If content will be inserted in a footnote, which in an column area,
    1220             :         // the column area it is not allowed to be broken up.
    1221             :         // Only if in the inner of the footnote lies an area, is this a candidate
    1222             :         // for pActualSection.
    1223             :         // The same applies for areas in tables, if inside the table will be
    1224             :         // something inserted, it's only allowed to break up areas, which
    1225             :         // lies in the inside also.
    1226           9 :         if( ( !pLay->IsInFtn() || pSct->IsInFtn() ) &&
    1227           3 :             ( !pLay->IsInTab() || pSct->IsInTab() ) )
    1228             :         {
    1229           3 :             pActualSection = new SwActualSection( 0, pSct, 0 );
    1230             :             OSL_ENSURE( !pLay->Lower() || !pLay->Lower()->IsColumnFrm(),
    1231             :                 "_InsertCnt: Wrong Call" );
    1232             :         }
    1233             :     }
    1234             : 
    1235             :     //If a section is "open", the pActualSection points to an SwActualSection.
    1236             :     //If the page breaks, for "open" sections a follow will created.
    1237             :     //For nested sections (which have, however, not a nested layout),
    1238             :     //the SwActualSection class has a member, which points to an upper(section).
    1239             :     //When the "inner" section finishs, the upper will used instead.
    1240             : 
    1241             :     while( true )
    1242             :     {
    1243       38753 :         SwNode *pNd = pDoc->GetNodes()[nIndex];
    1244       38753 :         if ( pNd->IsCntntNode() )
    1245             :         {
    1246       24211 :             SwCntntNode* pNode = (SwCntntNode*)pNd;
    1247       24211 :             pFrm = pNode->MakeFrm(pLay);
    1248       24211 :             if( pPageMaker )
    1249       11773 :                 pPageMaker->CheckInsert( nIndex );
    1250             : 
    1251       24211 :             pFrm->InsertBehind( pLay, pPrv );
    1252             :             // #i27138#
    1253             :             // notify accessibility paragraphs objects about changed
    1254             :             // CONTENT_FLOWS_FROM/_TO relation.
    1255             :             // Relation CONTENT_FLOWS_FROM for next paragraph will change
    1256             :             // and relation CONTENT_FLOWS_TO for previous paragraph will change.
    1257       24211 :             if ( pFrm->IsTxtFrm() )
    1258             :             {
    1259       23499 :                 SwViewShell* pViewShell( pFrm->getRootFrm()->GetCurrShell() );
    1260             :                 // no notification, if <SwViewShell> is in construction
    1261       47870 :                 if ( pViewShell && !pViewShell->IsInConstructor() &&
    1262       25245 :                      pViewShell->GetLayout() &&
    1263         873 :                      pViewShell->GetLayout()->IsAnyShellAccessible() )
    1264             :                 {
    1265             :                     pViewShell->InvalidateAccessibleParaFlowRelation(
    1266           0 :                         dynamic_cast<SwTxtFrm*>(pFrm->FindNextCnt( true )),
    1267           0 :                         dynamic_cast<SwTxtFrm*>(pFrm->FindPrevCnt( true )) );
    1268             :                     // #i68958#
    1269             :                     // The information flags of the text frame are validated
    1270             :                     // in methods <FindNextCnt(..)> and <FindPrevCnt(..)>.
    1271             :                     // The information flags have to be invalidated, because
    1272             :                     // it is possible, that the one of its upper frames
    1273             :                     // isn't inserted into the layout.
    1274           0 :                     pFrm->InvalidateInfFlags();
    1275             :                 }
    1276             :             }
    1277             :             // OD 12.08.2003 #i17969# - consider horizontal/vertical layout
    1278             :             // for setting position at newly inserted frame
    1279       24211 :             lcl_SetPos( *pFrm, *pLay );
    1280       24211 :             pPrv = pFrm;
    1281             : 
    1282       24211 :             if ( !pTbl->empty() && bObjsDirect && !bDontCreateObjects )
    1283       10525 :                 AppendObjs( pTbl, nIndex, pFrm, pPage );
    1284             :         }
    1285       14542 :         else if ( pNd->IsTableNode() )
    1286             :         {   //Should we have encountered a table?
    1287         436 :             SwTableNode *pTblNode = (SwTableNode*)pNd;
    1288             : 
    1289             :             // #108116# loading may produce table structures that GCLines
    1290             :             // needs to clean up. To keep table formulas correct, change
    1291             :             // all table formulas to internal (BOXPTR) representation.
    1292         436 :             SwTableFmlUpdate aMsgHnt( &pTblNode->GetTable() );
    1293         436 :             aMsgHnt.eFlags = TBL_BOXPTR;
    1294         436 :             pDoc->UpdateTblFlds( &aMsgHnt );
    1295         436 :             pTblNode->GetTable().GCLines();
    1296             : 
    1297         436 :             pFrm = pTblNode->MakeFrm( pLay );
    1298             : 
    1299         436 :             if( pPageMaker )
    1300         304 :                 pPageMaker->CheckInsert( nIndex );
    1301             : 
    1302         436 :             pFrm->InsertBehind( pLay, pPrv );
    1303             :             // #i27138#
    1304             :             // notify accessibility paragraphs objects about changed
    1305             :             // CONTENT_FLOWS_FROM/_TO relation.
    1306             :             // Relation CONTENT_FLOWS_FROM for next paragraph will change
    1307             :             // and relation CONTENT_FLOWS_TO for previous paragraph will change.
    1308             :             {
    1309         436 :                 SwViewShell* pViewShell( pFrm->getRootFrm()->GetCurrShell() );
    1310             :                 // no notification, if <SwViewShell> is in construction
    1311         876 :                 if ( pViewShell && !pViewShell->IsInConstructor() &&
    1312         444 :                      pViewShell->GetLayout() &&
    1313           4 :                      pViewShell->GetLayout()->IsAnyShellAccessible() )
    1314             :                 {
    1315             :                     pViewShell->InvalidateAccessibleParaFlowRelation(
    1316           0 :                             dynamic_cast<SwTxtFrm*>(pFrm->FindNextCnt( true )),
    1317           0 :                             dynamic_cast<SwTxtFrm*>(pFrm->FindPrevCnt( true )) );
    1318             :                 }
    1319             :             }
    1320         436 :             if ( bObjsDirect && !pTbl->empty() )
    1321         126 :                 ((SwTabFrm*)pFrm)->RegistFlys();
    1322             :             // OD 12.08.2003 #i17969# - consider horizontal/vertical layout
    1323             :             // for setting position at newly inserted frame
    1324         436 :             lcl_SetPos( *pFrm, *pLay );
    1325             : 
    1326         436 :             pPrv = pFrm;
    1327             :             //Set the index to the endnode of the table section.
    1328         436 :             nIndex = pTblNode->EndOfSectionIndex();
    1329             : 
    1330         436 :             SwTabFrm* pTmpFrm = (SwTabFrm*)pFrm;
    1331        1368 :             while ( pTmpFrm )
    1332             :             {
    1333         496 :                 pTmpFrm->CheckDirChange();
    1334         496 :                 pTmpFrm = pTmpFrm->IsFollow() ? pTmpFrm->FindMaster() : NULL;
    1335         436 :             }
    1336             : 
    1337             :         }
    1338       14106 :         else if ( pNd->IsSectionNode() )
    1339             :         {
    1340         211 :             SwSectionNode *pNode = (SwSectionNode*)pNd;
    1341         211 :             if( pNode->GetSection().CalcHiddenFlag() )
    1342             :                 // is hidden, skip the area
    1343           0 :                 nIndex = pNode->EndOfSectionIndex();
    1344             :             else
    1345             :             {
    1346         211 :                 pFrm = pNode->MakeFrm( pLay );
    1347             :                 pActualSection = new SwActualSection( pActualSection,
    1348         211 :                                                 (SwSectionFrm*)pFrm, pNode );
    1349         211 :                 if ( pActualSection->GetUpper() )
    1350             :                 {
    1351             :                     //Insert behind the Upper, the "Follow" of the Upper will be
    1352             :                     //generated at the EndNode.
    1353          40 :                     SwSectionFrm *pTmp = pActualSection->GetUpper()->GetSectionFrm();
    1354          40 :                     pFrm->InsertBehind( pTmp->GetUpper(), pTmp );
    1355             :                     // OD 25.03.2003 #108339# - direct initialization of section
    1356             :                     // after insertion in the layout
    1357          40 :                     static_cast<SwSectionFrm*>(pFrm)->Init();
    1358             :                 }
    1359             :                 else
    1360             :                 {
    1361         171 :                     pFrm->InsertBehind( pLay, pPrv );
    1362             :                     // OD 25.03.2003 #108339# - direct initialization of section
    1363             :                     // after insertion in the layout
    1364         171 :                     static_cast<SwSectionFrm*>(pFrm)->Init();
    1365             : 
    1366             :                     // #i33963#
    1367             :                     // Do not trust the IsInFtn flag. If we are currently
    1368             :                     // building up a table, the upper of pPrv may be a cell
    1369             :                     // frame, but the cell frame does not have an upper yet.
    1370         171 :                     if( pPrv && 0 != pPrv->ImplFindFtnFrm() )
    1371             :                     {
    1372           0 :                         if( pPrv->IsSctFrm() )
    1373           0 :                             pPrv = ((SwSectionFrm*)pPrv)->ContainsCntnt();
    1374           0 :                         if( pPrv && pPrv->IsTxtFrm() )
    1375           0 :                             ((SwTxtFrm*)pPrv)->Prepare( PREP_QUOVADIS, 0, false );
    1376             :                     }
    1377             :                 }
    1378             :                 // #i27138#
    1379             :                 // notify accessibility paragraphs objects about changed
    1380             :                 // CONTENT_FLOWS_FROM/_TO relation.
    1381             :                 // Relation CONTENT_FLOWS_FROM for next paragraph will change
    1382             :                 // and relation CONTENT_FLOWS_TO for previous paragraph will change.
    1383             :                 {
    1384         211 :                     SwViewShell* pViewShell( pFrm->getRootFrm()->GetCurrShell() );
    1385             :                     // no notification, if <SwViewShell> is in construction
    1386         465 :                     if ( pViewShell && !pViewShell->IsInConstructor() &&
    1387         297 :                          pViewShell->GetLayout() &&
    1388          43 :                          pViewShell->GetLayout()->IsAnyShellAccessible() )
    1389             :                     {
    1390             :                         pViewShell->InvalidateAccessibleParaFlowRelation(
    1391           0 :                             dynamic_cast<SwTxtFrm*>(pFrm->FindNextCnt( true )),
    1392           0 :                             dynamic_cast<SwTxtFrm*>(pFrm->FindPrevCnt( true )) );
    1393             :                     }
    1394             :                 }
    1395         211 :                 pFrm->CheckDirChange();
    1396             : 
    1397             :                 // OD 12.08.2003 #i17969# - consider horizontal/vertical layout
    1398             :                 // for setting position at newly inserted frame
    1399         211 :                 lcl_SetPos( *pFrm, *pLay );
    1400             : 
    1401             :                 // OD 20.11.2002 #105405# - no page, no invalidate.
    1402         211 :                 if ( pPage )
    1403             :                 {
    1404             :                     // OD 18.09.2002 #100522#
    1405             :                     // invalidate page in order to force format and paint of
    1406             :                     // inserted section frame
    1407         211 :                     pFrm->InvalidatePage( pPage );
    1408             : 
    1409             :                     // FME 10.11.2003 #112243#
    1410             :                     // Invalidate fly content flag:
    1411         211 :                     if ( pFrm->IsInFly() )
    1412           2 :                         pPage->InvalidateFlyCntnt();
    1413             : 
    1414             :                     // OD 14.11.2002 #104684# - invalidate page content in order to
    1415             :                     // force format and paint of section content.
    1416         211 :                     pPage->InvalidateCntnt();
    1417             :                 }
    1418             : 
    1419         211 :                 pLay = (SwLayoutFrm*)pFrm;
    1420         211 :                 if ( pLay->Lower() && pLay->Lower()->IsLayoutFrm() )
    1421          41 :                     pLay = pLay->GetNextLayoutLeaf();
    1422         211 :                 pPrv = 0;
    1423             :             }
    1424             :         }
    1425       13895 :         else if ( pNd->IsEndNode() && pNd->StartOfSectionNode()->IsSectionNode() )
    1426             :         {
    1427             :             OSL_ENSURE( pActualSection, "Sectionende ohne Anfang?" );
    1428             :             OSL_ENSURE( pActualSection->GetSectionNode() == pNd->StartOfSectionNode(),
    1429             :                             "Sectionende mit falschen Start Node?" );
    1430             : 
    1431             :             //Close the section, where appropriate activate the surrounding
    1432             :             //section again.
    1433         211 :             SwActualSection *pTmp = pActualSection ? pActualSection->GetUpper() : NULL;
    1434         211 :             delete pActualSection;
    1435         211 :             pLay = pLay->FindSctFrm();
    1436         211 :             if ( 0 != (pActualSection = pTmp) )
    1437             :             {
    1438             :                 //Could be, that the last SectionFrm remains empty.
    1439             :                 //Then now is the time to remove them.
    1440          40 :                 if ( !pLay->ContainsCntnt() )
    1441             :                 {
    1442           0 :                     SwFrm *pTmpFrm = pLay;
    1443           0 :                     pLay = pTmpFrm->GetUpper();
    1444           0 :                     pPrv = pTmpFrm->GetPrev();
    1445           0 :                     pTmpFrm->Remove();
    1446           0 :                     delete pTmpFrm;
    1447             :                 }
    1448             :                 else
    1449             :                 {
    1450          40 :                     pPrv = pLay;
    1451          40 :                     pLay = pLay->GetUpper();
    1452             :                 }
    1453             : 
    1454             :                 // new section frame
    1455          40 :                 pFrm = pActualSection->GetSectionNode()->MakeFrm( pLay );
    1456          40 :                 pFrm->InsertBehind( pLay, pPrv );
    1457          40 :                 static_cast<SwSectionFrm*>(pFrm)->Init();
    1458             : 
    1459             :                 // OD 12.08.2003 #i17969# - consider horizontal/vertical layout
    1460             :                 // for setting position at newly inserted frame
    1461          40 :                 lcl_SetPos( *pFrm, *pLay );
    1462             : 
    1463          40 :                 SwSectionFrm* pOuterSectionFrm = pActualSection->GetSectionFrm();
    1464             : 
    1465             :                 // a follow has to be appended to the new section frame
    1466          40 :                 SwSectionFrm* pFollow = pOuterSectionFrm->GetFollow();
    1467          40 :                 if ( pFollow )
    1468             :                 {
    1469           0 :                     pOuterSectionFrm->SetFollow( NULL );
    1470           0 :                     pOuterSectionFrm->InvalidateSize();
    1471           0 :                     ((SwSectionFrm*)pFrm)->SetFollow( pFollow );
    1472             :                 }
    1473             : 
    1474             :                 // We don't want to leave empty parts back.
    1475          77 :                 if( ! pOuterSectionFrm->IsColLocked() &&
    1476          37 :                     ! pOuterSectionFrm->ContainsCntnt() )
    1477             :                 {
    1478          19 :                     pOuterSectionFrm->DelEmpty( sal_True );
    1479          19 :                     delete pOuterSectionFrm;
    1480             :                 }
    1481          40 :                 pActualSection->SetSectionFrm( (SwSectionFrm*)pFrm );
    1482             : 
    1483          40 :                 pLay = (SwLayoutFrm*)pFrm;
    1484          40 :                 if ( pLay->Lower() && pLay->Lower()->IsLayoutFrm() )
    1485           0 :                     pLay = pLay->GetNextLayoutLeaf();
    1486          40 :                 pPrv = 0;
    1487             :             }
    1488             :             else
    1489             :             {
    1490             :                 //Nothing more with sections, it goes on right behind
    1491             :                 //the SectionFrame.
    1492         171 :                 pPrv = pLay;
    1493         171 :                 pLay = pLay->GetUpper();
    1494             :             }
    1495             :         }
    1496       14993 :         else if( pNd->IsStartNode() &&
    1497        1309 :                  SwFlyStartNode == ((SwStartNode*)pNd)->GetStartNodeType() )
    1498             :         {
    1499        1309 :             if ( !pTbl->empty() && bObjsDirect && !bDontCreateObjects )
    1500             :             {
    1501         965 :                 SwFlyFrm* pFly = pLay->FindFlyFrm();
    1502         965 :                 if( pFly )
    1503         965 :                     AppendObjs( pTbl, nIndex, pFly, pPage );
    1504             :             }
    1505             :         }
    1506             :         else
    1507             :             // Neither Cntnt nor table nor section,
    1508             :             // so we have to be ready.
    1509       12375 :             break;
    1510             : 
    1511       26378 :         ++nIndex;
    1512             :         // Do not consider the end node. The caller (section/MakeFrms()) has to ensure that the end
    1513             :         // of this area is positioned before EndIndex!
    1514       26378 :         if ( nEndIndex && nIndex >= nEndIndex )
    1515          39 :             break;
    1516             :     }
    1517             : 
    1518       12414 :     if ( pActualSection )
    1519             :     {
    1520             :         // Might happen that an empty (Follow-)Section is left over.
    1521           3 :         if ( !(pLay = pActualSection->GetSectionFrm())->ContainsCntnt() )
    1522             :         {
    1523           3 :             pLay->Remove();
    1524           3 :             delete pLay;
    1525             :         }
    1526           3 :         delete pActualSection;
    1527             :     }
    1528             : 
    1529       12414 :     if ( bPages ) // let the Flys connect to each other
    1530             :     {
    1531        1732 :         if ( !bDontCreateObjects )
    1532        1732 :             AppendAllObjs( pTbl, pLayout );
    1533        1732 :         bObjsDirect = true;
    1534             :     }
    1535             : 
    1536       12414 :     if( pPageMaker )
    1537             :     {
    1538        1732 :         pPageMaker->CheckFlyCache( pPage );
    1539        1732 :         delete pPageMaker;
    1540        1732 :         if( pDoc->GetLayoutCache() )
    1541             :         {
    1542             : #ifdef DBG_UTIL
    1543             :             pDoc->GetLayoutCache()->CompareLayout( *pDoc );
    1544             : #endif
    1545          10 :             pDoc->GetLayoutCache()->ClearImpl();
    1546             :         }
    1547             :     }
    1548             : 
    1549       12414 :     pDoc->UnblockIdling();
    1550       12414 :     if( bOldCallbackActionEnabled )
    1551       27799 :         pLayout->SetCallbackActionEnabled( bOldCallbackActionEnabled );
    1552       12414 : }
    1553             : 
    1554          37 : void MakeFrms( SwDoc *pDoc, const SwNodeIndex &rSttIdx,
    1555             :                const SwNodeIndex &rEndIdx )
    1556             : {
    1557          37 :     bObjsDirect = false;
    1558             : 
    1559          37 :     SwNodeIndex aTmp( rSttIdx );
    1560          37 :     sal_uLong nEndIdx = rEndIdx.GetIndex();
    1561          37 :     SwNode* pNd = pDoc->GetNodes().FindPrvNxtFrmNode( aTmp,
    1562          74 :                                             pDoc->GetNodes()[ nEndIdx-1 ]);
    1563          37 :     if ( pNd )
    1564             :     {
    1565          35 :         sal_Bool bApres = aTmp < rSttIdx;
    1566          35 :         SwNode2Layout aNode2Layout( *pNd, rSttIdx.GetIndex() );
    1567             :         SwFrm* pFrm;
    1568         105 :         while( 0 != (pFrm = aNode2Layout.NextFrm()) )
    1569             :         {
    1570          35 :             SwLayoutFrm *pUpper = pFrm->GetUpper();
    1571          35 :             SwFtnFrm* pFtnFrm = pUpper->FindFtnFrm();
    1572             :             sal_Bool bOldLock, bOldFtn;
    1573          35 :             if( pFtnFrm )
    1574             :             {
    1575           2 :                 bOldFtn = pFtnFrm->IsColLocked();
    1576           2 :                 pFtnFrm->ColLock();
    1577             :             }
    1578             :             else
    1579          33 :                 bOldFtn = sal_True;
    1580          35 :             SwSectionFrm* pSct = pUpper->FindSctFrm();
    1581             :             // Inside of footnotes only those areas are interesting that are inside of them. But
    1582             :             // not the ones (e.g. column areas) in which are the footnote containers positioned.
    1583             :             // #109767# Table frame is in section, insert section in cell frame.
    1584          35 :             if( pSct && ((pFtnFrm && !pSct->IsInFtn()) || pUpper->IsCellFrm()) )
    1585           0 :                 pSct = NULL;
    1586          35 :             if( pSct )
    1587             :             {   // to prevent pTmp->MoveFwd from destroying the SectionFrm
    1588           3 :                 bOldLock = pSct->IsColLocked();
    1589           3 :                 pSct->ColLock();
    1590             :             }
    1591             :             else
    1592          32 :                 bOldLock = sal_True;
    1593             : 
    1594             :             // If pFrm cannot be moved, it is not possible to move it to the next page. This applies
    1595             :             // also for frames (in the first column of a frame pFrm is moveable) and column
    1596             :             // sections of tables (also here pFrm is moveable).
    1597          35 :             bool bMoveNext = nEndIdx - rSttIdx.GetIndex() > 120;
    1598          97 :             bool bAllowMove = !pFrm->IsInFly() && pFrm->IsMoveable() &&
    1599          66 :                  (!pFrm->IsInTab() || pFrm->IsTabFrm() );
    1600          35 :             if ( bMoveNext && bAllowMove )
    1601             :             {
    1602           0 :                 SwFrm *pMove = pFrm;
    1603           0 :                 SwFrm *pPrev = pFrm->GetPrev();
    1604           0 :                 SwFlowFrm *pTmp = SwFlowFrm::CastFlowFrm( pMove );
    1605             :                 OSL_ENSURE( pTmp, "Missing FlowFrm" );
    1606             : 
    1607           0 :                 if ( bApres )
    1608             :                 {
    1609             :                     // The rest of this page should be empty. Thus, the following one has to move to
    1610             :                     // the next page (it might also be located in the following column).
    1611             :                     OSL_ENSURE( !pTmp->HasFollow(), "Follows forbidden" );
    1612           0 :                     pPrev = pFrm;
    1613             :                     // If the surrounding SectionFrm has a "next" one,
    1614             :                     // so this one needs to be moved as well.
    1615           0 :                     pMove = pFrm->GetIndNext();
    1616           0 :                     SwColumnFrm* pCol = (SwColumnFrm*)pFrm->FindColFrm();
    1617           0 :                     if( pCol )
    1618           0 :                         pCol = (SwColumnFrm*)pCol->GetNext();
    1619           0 :                     do
    1620             :                     {
    1621           0 :                         if( pCol && !pMove )
    1622             :                         {   // No successor so far, look into the next column
    1623           0 :                             pMove = pCol->ContainsAny();
    1624           0 :                             if( pCol->GetNext() )
    1625           0 :                                 pCol = (SwColumnFrm*)pCol->GetNext();
    1626           0 :                             else if( pCol->IsInSct() )
    1627             :                             {   // If there is no following column but we are in a column frame,
    1628             :                                 // there might be (page) columns outside of it.
    1629           0 :                                 pCol = (SwColumnFrm*)pCol->FindSctFrm()->FindColFrm();
    1630           0 :                                 if( pCol )
    1631           0 :                                     pCol = (SwColumnFrm*)pCol->GetNext();
    1632             :                             }
    1633             :                             else
    1634           0 :                                 pCol = NULL;
    1635             :                         }
    1636             :                         // skip invalid SectionFrms
    1637           0 :                         while( pMove && pMove->IsSctFrm() &&
    1638           0 :                                !((SwSectionFrm*)pMove)->GetSection() )
    1639           0 :                             pMove = pMove->GetNext();
    1640           0 :                     } while( !pMove && pCol );
    1641             : 
    1642           0 :                     if( pMove )
    1643             :                     {
    1644           0 :                         if ( pMove->IsCntntFrm() )
    1645           0 :                             pTmp = (SwCntntFrm*)pMove;
    1646           0 :                         else if ( pMove->IsTabFrm() )
    1647           0 :                             pTmp = (SwTabFrm*)pMove;
    1648           0 :                         else if ( pMove->IsSctFrm() )
    1649             :                         {
    1650           0 :                             pMove = ((SwSectionFrm*)pMove)->ContainsAny();
    1651           0 :                             if( pMove )
    1652           0 :                                 pTmp = SwFlowFrm::CastFlowFrm( pMove );
    1653             :                             else
    1654           0 :                                 pTmp = NULL;
    1655             :                         }
    1656             :                     }
    1657             :                     else
    1658           0 :                         pTmp = 0;
    1659             :                 }
    1660             :                 else
    1661             :                 {
    1662             :                     OSL_ENSURE( !pTmp->IsFollow(), "Follows really forbidden" );
    1663             :                     // move the _content_ of a section frame
    1664           0 :                     if( pMove->IsSctFrm() )
    1665             :                     {
    1666           0 :                         while( pMove && pMove->IsSctFrm() &&
    1667           0 :                                !((SwSectionFrm*)pMove)->GetSection() )
    1668           0 :                             pMove = pMove->GetNext();
    1669           0 :                         if( pMove && pMove->IsSctFrm() )
    1670           0 :                             pMove = ((SwSectionFrm*)pMove)->ContainsAny();
    1671           0 :                         if( pMove )
    1672           0 :                             pTmp = SwFlowFrm::CastFlowFrm( pMove );
    1673             :                         else
    1674           0 :                             pTmp = NULL;
    1675             :                     }
    1676             :                 }
    1677             : 
    1678           0 :                 if( pTmp )
    1679             :                 {
    1680           0 :                     SwFrm* pOldUp = pTmp->GetFrm()->GetUpper();
    1681             :                     // MoveFwd==sal_True means that we are still on the same page.
    1682             :                     // But since we want to move if possible!
    1683           0 :                     sal_Bool bTmpOldLock = pTmp->IsJoinLocked();
    1684           0 :                     pTmp->LockJoin();
    1685           0 :                     while( pTmp->MoveFwd( sal_True, sal_False, sal_True ) )
    1686             :                     {
    1687           0 :                         if( pOldUp == pTmp->GetFrm()->GetUpper() )
    1688           0 :                             break;
    1689           0 :                         pOldUp = pTmp->GetFrm()->GetUpper();
    1690             :                     }
    1691           0 :                     if( !bTmpOldLock )
    1692           0 :                         pTmp->UnlockJoin();
    1693             :                 }
    1694             :                 ::_InsertCnt( pUpper, pDoc, rSttIdx.GetIndex(),
    1695           0 :                               pFrm->IsInDocBody(), nEndIdx, pPrev );
    1696             :             }
    1697             :             else
    1698             :             {
    1699             :                 sal_Bool bSplit;
    1700          35 :                 SwFrm* pPrv = bApres ? pFrm : pFrm->GetPrev();
    1701             :                 // If the section frame is inserted into another one, it must be split.
    1702          35 :                 if( pSct && rSttIdx.GetNode().IsSectionNode() )
    1703             :                 {
    1704           3 :                     bSplit = pSct->SplitSect( pFrm, bApres );
    1705           3 :                     if( !bSplit && !bApres )
    1706             :                     {
    1707           0 :                         pUpper = pSct->GetUpper();
    1708           0 :                         pPrv = pSct->GetPrev();
    1709             :                     }
    1710             :                 }
    1711             :                 else
    1712          32 :                     bSplit = sal_False;
    1713             : 
    1714             :                 ::_InsertCnt( pUpper, pDoc, rSttIdx.GetIndex(), sal_False,
    1715          35 :                               nEndIdx, pPrv );
    1716             :                 // OD 23.06.2003 #108784# - correction: append objects doesn't
    1717             :                 // depend on value of <bAllowMove>
    1718          35 :                 if( !bDontCreateObjects )
    1719             :                 {
    1720          35 :                     const SwFrmFmts *pTbl = pDoc->GetSpzFrmFmts();
    1721          35 :                     if( !pTbl->empty() )
    1722           8 :                         AppendAllObjs( pTbl, pUpper );
    1723             :                 }
    1724             : 
    1725             :                 // If nothing was added (e.g. a hidden section), the split must be reversed.
    1726          38 :                 if( bSplit && pSct && pSct->GetNext()
    1727          38 :                     && pSct->GetNext()->IsSctFrm() )
    1728           3 :                     pSct->MergeNext( (SwSectionFrm*)pSct->GetNext() );
    1729          35 :                 if( pFrm->IsInFly() )
    1730           2 :                     pFrm->FindFlyFrm()->_Invalidate();
    1731          35 :                 if( pFrm->IsInTab() )
    1732           2 :                     pFrm->InvalidateSize();
    1733             :             }
    1734             : 
    1735          35 :             SwPageFrm *pPage = pUpper->FindPageFrm();
    1736          35 :             SwFrm::CheckPageDescs( pPage, sal_False );
    1737          35 :             if( !bOldFtn )
    1738           2 :                 pFtnFrm->ColUnlock();
    1739          35 :             if( !bOldLock )
    1740             :             {
    1741           3 :                 pSct->ColUnlock();
    1742             :                 // pSct might be empty (e.g. when inserting linked section containing further
    1743             :                 // sections) and can be destroyed in such cases.
    1744           3 :                 if( !pSct->ContainsCntnt() )
    1745             :                 {
    1746           0 :                     pSct->DelEmpty( sal_True );
    1747           0 :                     pUpper->getRootFrm()->RemoveFromList( pSct );
    1748           0 :                     delete pSct;
    1749             :                 }
    1750             :             }
    1751          35 :         }
    1752             :     }
    1753             : 
    1754          37 :     bObjsDirect = true;
    1755          37 : }
    1756             : 
    1757       59017 : SwBorderAttrs::SwBorderAttrs( const SwModify *pMod, const SwFrm *pConstructor ) :
    1758             :     SwCacheObj( pMod ),
    1759       59017 :     rAttrSet( pConstructor->IsCntntFrm()
    1760       27585 :                     ? ((SwCntntFrm*)pConstructor)->GetNode()->GetSwAttrSet()
    1761       31432 :                     : ((SwLayoutFrm*)pConstructor)->GetFmt()->GetAttrSet() ),
    1762       59017 :     rUL     ( rAttrSet.GetULSpace() ),
    1763             :     // #i96772#
    1764             :     // LRSpaceItem is copied due to the possibility that it is adjusted - see below
    1765       59017 :     rLR     ( rAttrSet.GetLRSpace() ),
    1766       59017 :     rBox    ( rAttrSet.GetBox()     ),
    1767       59017 :     rShadow ( rAttrSet.GetShadow()  ),
    1768      413119 :     aFrmSize( rAttrSet.GetFrmSize().GetSize() )
    1769             : {
    1770             :     // #i96772#
    1771       59017 :     const SwTxtFrm* pTxtFrm = dynamic_cast<const SwTxtFrm*>(pConstructor);
    1772       59017 :     if ( pTxtFrm )
    1773             :     {
    1774       26957 :         pTxtFrm->GetTxtNode()->ClearLRSpaceItemDueToListLevelIndents( rLR );
    1775             :     }
    1776       32060 :     else if ( pConstructor->IsNoTxtFrm() )
    1777             :     {
    1778         628 :         rLR = SvxLRSpaceItem ( RES_LR_SPACE );
    1779             :     }
    1780             : 
    1781             :     // Caution: The USHORTs for the cached values are not initialized by intention!
    1782             : 
    1783             :     // everything needs to be calculated at least once:
    1784             :     bTopLine = bBottomLine = bLeftLine = bRightLine =
    1785       59017 :     bTop     = bBottom     = bLine   = sal_True;
    1786             : 
    1787       59017 :     bCacheGetLine = bCachedGetTopLine = bCachedGetBottomLine = sal_False;
    1788             :     // OD 21.05.2003 #108789# - init cache status for values <bJoinedWithPrev>
    1789             :     // and <bJoinedWithNext>, which aren't initialized by default.
    1790       59017 :     bCachedJoinedWithPrev = sal_False;
    1791       59017 :     bCachedJoinedWithNext = sal_False;
    1792             : 
    1793       59017 :     bBorderDist = 0 != (pConstructor->GetType() & (FRM_CELL));
    1794       59017 : }
    1795             : 
    1796      177051 : SwBorderAttrs::~SwBorderAttrs()
    1797             : {
    1798       59017 :     ((SwModify*)pOwner)->SetInCache( sal_False );
    1799      118034 : }
    1800             : 
    1801             : /* All calc methods calculate a safety distance in addition to the values given by the attributes.
    1802             :  * This safety distance is only added when working with borders and/or shadows to prevent that
    1803             :  * e.g. borders are painted over.
    1804             :  */
    1805             : 
    1806        3047 : void SwBorderAttrs::_CalcTop()
    1807             : {
    1808        3047 :     nTop = CalcTopLine() + rUL.GetUpper();
    1809        3047 :     bTop = sal_False;
    1810        3047 : }
    1811             : 
    1812        3047 : void SwBorderAttrs::_CalcBottom()
    1813             : {
    1814        3047 :     nBottom = CalcBottomLine() + rUL.GetLower();
    1815        3047 :     bBottom = sal_False;
    1816        3047 : }
    1817             : 
    1818      187231 : long SwBorderAttrs::CalcRight( const SwFrm* pCaller ) const
    1819             : {
    1820      187231 :     long nRight=0;
    1821             : 
    1822      187231 :     if (!pCaller->IsTxtFrm() || !((SwTxtFrm*)pCaller)->GetTxtNode()->GetDoc()->get(IDocumentSettingAccess::INVERT_BORDER_SPACING)) {
    1823             :     // OD 23.01.2003 #106895# - for cell frame in R2L text direction the left
    1824             :     // and right border are painted on the right respectively left.
    1825       46605 :     if ( pCaller->IsCellFrm() && pCaller->IsRightToLeft() )
    1826           0 :         nRight = CalcLeftLine();
    1827             :     else
    1828       46605 :         nRight = CalcRightLine();
    1829             : 
    1830             :     }
    1831             :     // for paragraphs, "left" is "before text" and "right" is "after text"
    1832      187231 :     if ( pCaller->IsTxtFrm() && pCaller->IsRightToLeft() )
    1833         129 :         nRight += rLR.GetLeft();
    1834             :     else
    1835      187102 :         nRight += rLR.GetRight();
    1836             : 
    1837             :     // correction: retrieve left margin for numbering in R2L-layout
    1838      187231 :     if ( pCaller->IsTxtFrm() && pCaller->IsRightToLeft() )
    1839             :     {
    1840         129 :         nRight += ((SwTxtFrm*)pCaller)->GetTxtNode()->GetLeftMarginWithNum();
    1841             :     }
    1842             : 
    1843      187231 :     return nRight;
    1844             : }
    1845             : 
    1846             : /// Tries to detect if this paragraph has a floating table attached.
    1847      270563 : static bool lcl_hasTabFrm(const SwTxtFrm* pTxtFrm)
    1848             : {
    1849      270563 :     if (pTxtFrm->GetDrawObjs())
    1850             :     {
    1851       11902 :         const SwSortedObjs* pSortedObjs = pTxtFrm->GetDrawObjs();
    1852       11902 :         if (pSortedObjs->Count() > 0)
    1853             :         {
    1854       11902 :             SwAnchoredObject* pObject = (*pSortedObjs)[0];
    1855       11902 :             if (pObject->IsA(TYPE(SwFlyFrm)))
    1856             :             {
    1857        8447 :                 SwFlyFrm* pFly = (SwFlyFrm*)pObject;
    1858        8447 :                 if (pFly->Lower() && pFly->Lower()->IsTabFrm())
    1859         604 :                     return true;
    1860             :             }
    1861             :         }
    1862             :     }
    1863      269959 :     return false;
    1864             : }
    1865             : 
    1866      207020 : long SwBorderAttrs::CalcLeft( const SwFrm *pCaller ) const
    1867             : {
    1868      207020 :     long nLeft=0;
    1869             : 
    1870      207020 :     if (!pCaller->IsTxtFrm() || !((SwTxtFrm*)pCaller)->GetTxtNode()->GetDoc()->get(IDocumentSettingAccess::INVERT_BORDER_SPACING)) {
    1871             :     // OD 23.01.2003 #106895# - for cell frame in R2L text direction the left
    1872             :     // and right border are painted on the right respectively left.
    1873       51569 :     if ( pCaller->IsCellFrm() && pCaller->IsRightToLeft() )
    1874           0 :         nLeft = CalcRightLine();
    1875             :     else
    1876       51569 :         nLeft = CalcLeftLine();
    1877             :     }
    1878             : 
    1879             :     // for paragraphs, "left" is "before text" and "right" is "after text"
    1880      207020 :     if ( pCaller->IsTxtFrm() && pCaller->IsRightToLeft() )
    1881         164 :         nLeft += rLR.GetRight();
    1882             :     else
    1883             :     {
    1884      206856 :         bool bIgnoreMargin = false;
    1885      206856 :         if (pCaller->IsTxtFrm())
    1886             :         {
    1887      194519 :             const SwTxtFrm* pTxtFrm = (const SwTxtFrm*)pCaller;
    1888      194519 :             if (pTxtFrm->GetTxtNode()->GetDoc()->get(IDocumentSettingAccess::FLOATTABLE_NOMARGINS))
    1889             :             {
    1890             :                 // If this is explicitly requested, ignore the margins next to the floating table.
    1891      147104 :                 if (lcl_hasTabFrm(pTxtFrm))
    1892         364 :                     bIgnoreMargin = true;
    1893             :                 // TODO here we only handle the first two paragraphs, would be nice to generalize this.
    1894      146740 :                 else if (pTxtFrm->FindPrev() && pTxtFrm->FindPrev()->IsTxtFrm() && lcl_hasTabFrm((const SwTxtFrm*)pTxtFrm->FindPrev()))
    1895         240 :                     bIgnoreMargin = true;
    1896             :             }
    1897             :         }
    1898      206856 :         if (!bIgnoreMargin)
    1899      206252 :             nLeft += rLR.GetLeft();
    1900             :     }
    1901             : 
    1902             :     // correction: do not retrieve left margin for numbering in R2L-layout
    1903      207020 :     if ( pCaller->IsTxtFrm() && !pCaller->IsRightToLeft() )
    1904             :     {
    1905      194519 :         nLeft += ((SwTxtFrm*)pCaller)->GetTxtNode()->GetLeftMarginWithNum();
    1906             :     }
    1907             : 
    1908      207020 :     return nLeft;
    1909             : }
    1910             : 
    1911             : /* Calculated values for borders and shadows.
    1912             :  * It might be that a distance is wanted even without lines. This will be
    1913             :  * considered here and not by the attribute (e.g. bBorderDist for cells).
    1914             :  */
    1915             : 
    1916       29343 : void SwBorderAttrs::_CalcTopLine()
    1917             : {
    1918          25 :     nTopLine = (bBorderDist && !rBox.GetTop())
    1919          13 :                             ? rBox.GetDistance  (BOX_LINE_TOP)
    1920       29356 :                             : rBox.CalcLineSpace(BOX_LINE_TOP);
    1921       29343 :     nTopLine = nTopLine + rShadow.CalcShadowSpace(SHADOW_TOP);
    1922       29343 :     bTopLine = sal_False;
    1923       29343 : }
    1924             : 
    1925       29287 : void SwBorderAttrs::_CalcBottomLine()
    1926             : {
    1927          25 :     nBottomLine = (bBorderDist && !rBox.GetBottom())
    1928          13 :                             ? rBox.GetDistance  (BOX_LINE_BOTTOM)
    1929       29300 :                             : rBox.CalcLineSpace(BOX_LINE_BOTTOM);
    1930       29287 :     nBottomLine = nBottomLine + rShadow.CalcShadowSpace(SHADOW_BOTTOM);
    1931       29287 :     bBottomLine = sal_False;
    1932       29287 : }
    1933             : 
    1934       11303 : void SwBorderAttrs::_CalcLeftLine()
    1935             : {
    1936          11 :     nLeftLine = (bBorderDist && !rBox.GetLeft())
    1937          11 :                             ? rBox.GetDistance  (BOX_LINE_LEFT)
    1938       11314 :                             : rBox.CalcLineSpace(BOX_LINE_LEFT);
    1939       11303 :     nLeftLine = nLeftLine + rShadow.CalcShadowSpace(SHADOW_LEFT);
    1940       11303 :     bLeftLine = sal_False;
    1941       11303 : }
    1942             : 
    1943       11303 : void SwBorderAttrs::_CalcRightLine()
    1944             : {
    1945          11 :     nRightLine = (bBorderDist && !rBox.GetRight())
    1946          11 :                             ? rBox.GetDistance  (BOX_LINE_RIGHT)
    1947       11314 :                             : rBox.CalcLineSpace(BOX_LINE_RIGHT);
    1948       11303 :     nRightLine = nRightLine + rShadow.CalcShadowSpace(SHADOW_RIGHT);
    1949       11303 :     bRightLine = sal_False;
    1950       11303 : }
    1951             : 
    1952        5473 : void SwBorderAttrs::_IsLine()
    1953             : {
    1954       16142 :     bIsLine = rBox.GetTop() || rBox.GetBottom() ||
    1955       16135 :               rBox.GetLeft()|| rBox.GetRight();
    1956        5473 :     bLine = sal_False;
    1957        5473 : }
    1958             : 
    1959             : /* The borders of neighboring paragraphs are condensed by following algorithm:
    1960             :  *
    1961             :  * 1. No top border if the predecessor has the same top border and (3) applies.
    1962             :  *    In addition, the paragraph needs to have a border at at least one side (left/right/bottom).
    1963             :  * 2. No bottom border if the successor has the same bottom border and (3) applies.
    1964             :  *    In addition, the paragraph needs to have a border at at least one side (left/right/top).
    1965             :  * 3. The borders on the left and right side are identical between the current and the
    1966             :  *    pre-/succeeding paragraph.
    1967             :  */
    1968             : 
    1969      273401 : inline bool CmpLines( const editeng::SvxBorderLine *pL1, const editeng::SvxBorderLine *pL2 )
    1970             : {
    1971      273401 :     return ( ((pL1 && pL2) && (*pL1 == *pL2)) || (!pL1 && !pL2) );
    1972             : }
    1973             : 
    1974             : // OD 21.05.2003 #108789# - change name of 1st parameter - "rAttrs" -> "rCmpAttrs"
    1975             : // OD 21.05.2003 #108789# - compare <CalcRight()> and <rCmpAttrs.CalcRight()>
    1976             : //          instead of only the right LR-spacing, because R2L-layout has to be
    1977             : //          considered.
    1978       68207 : sal_Bool SwBorderAttrs::CmpLeftRight( const SwBorderAttrs &rCmpAttrs,
    1979             :                                   const SwFrm *pCaller,
    1980             :                                   const SwFrm *pCmp ) const
    1981             : {
    1982      136414 :     return ( CmpLines( rCmpAttrs.GetBox().GetLeft(), GetBox().GetLeft()  ) &&
    1983      136414 :              CmpLines( rCmpAttrs.GetBox().GetRight(),GetBox().GetRight() ) &&
    1984      196642 :              CalcLeft( pCaller ) == rCmpAttrs.CalcLeft( pCmp ) &&
    1985             :              // OD 21.05.2003 #108789# - compare <CalcRight> with <rCmpAttrs.CalcRight>.
    1986      128435 :              CalcRight( pCaller ) == rCmpAttrs.CalcRight( pCmp ) );
    1987             : }
    1988             : 
    1989       68678 : sal_Bool SwBorderAttrs::_JoinWithCmp( const SwFrm& _rCallerFrm,
    1990             :                                   const SwFrm& _rCmpFrm ) const
    1991             : {
    1992       68678 :     sal_Bool bReturnVal = sal_False;
    1993             : 
    1994       68678 :     SwBorderAttrAccess aCmpAccess( SwFrm::GetCache(), &_rCmpFrm );
    1995       68678 :     const SwBorderAttrs &rCmpAttrs = *aCmpAccess.Get();
    1996      205958 :     if ( rShadow == rCmpAttrs.GetShadow() &&
    1997      136987 :          CmpLines( rBox.GetTop(), rCmpAttrs.GetBox().GetTop() ) &&
    1998      205270 :          CmpLines( rBox.GetBottom(), rCmpAttrs.GetBox().GetBottom() ) &&
    1999       68207 :          CmpLeftRight( rCmpAttrs, &_rCallerFrm, &_rCmpFrm )
    2000             :        )
    2001             :     {
    2002       59906 :         bReturnVal = sal_True;
    2003             :     }
    2004             : 
    2005       68678 :     return bReturnVal;
    2006             : }
    2007             : 
    2008             : // OD 21.05.2003 #108789# - method to determine, if borders are joined with
    2009             : // previous frame. Calculated value saved in cached value <bJoinedWithPrev>
    2010             : // OD 2004-02-26 #i25029# - add 2nd parameter <_pPrevFrm>
    2011      112008 : void SwBorderAttrs::_CalcJoinedWithPrev( const SwFrm& _rFrm,
    2012             :                                          const SwFrm* _pPrevFrm )
    2013             : {
    2014             :     // set default
    2015      112008 :     bJoinedWithPrev = sal_False;
    2016             : 
    2017      112008 :     if ( _rFrm.IsTxtFrm() )
    2018             :     {
    2019             :         // text frame can potentially join with previous text frame, if
    2020             :         // corresponding attribute set is set at previous text frame.
    2021             :         // OD 2004-02-26 #i25029# - If parameter <_pPrevFrm> is set, take this
    2022             :         // one as previous frame.
    2023      107348 :         const SwFrm* pPrevFrm = _pPrevFrm ? _pPrevFrm : _rFrm.GetPrev();
    2024             :         // OD 2004-02-13 #i25029# - skip hidden text frames.
    2025      259094 :         while ( pPrevFrm && pPrevFrm->IsTxtFrm() &&
    2026       44389 :                 static_cast<const SwTxtFrm*>(pPrevFrm)->IsHiddenNow() )
    2027             :         {
    2028           9 :             pPrevFrm = pPrevFrm->GetPrev();
    2029             :         }
    2030      151728 :         if ( pPrevFrm && pPrevFrm->IsTxtFrm() &&
    2031       44380 :              pPrevFrm->GetAttrSet()->GetParaConnectBorder().GetValue()
    2032             :            )
    2033             :         {
    2034       44380 :             bJoinedWithPrev = _JoinWithCmp( _rFrm, *(pPrevFrm) );
    2035             :         }
    2036             :     }
    2037             : 
    2038             :     // valid cache status, if demanded
    2039             :     // OD 2004-02-26 #i25029# - Do not validate cache, if parameter <_pPrevFrm>
    2040             :     // is set.
    2041      112008 :     bCachedJoinedWithPrev = bCacheGetLine && !_pPrevFrm;
    2042      112008 : }
    2043             : 
    2044             : // OD 21.05.2003 #108789# - method to determine, if borders are joined with
    2045             : // next frame. Calculated value saved in cached value <bJoinedWithNext>
    2046       55617 : void SwBorderAttrs::_CalcJoinedWithNext( const SwFrm& _rFrm )
    2047             : {
    2048             :     // set default
    2049       55617 :     bJoinedWithNext = sal_False;
    2050             : 
    2051       55617 :     if ( _rFrm.IsTxtFrm() )
    2052             :     {
    2053             :         // text frame can potentially join with next text frame, if
    2054             :         // corresponding attribute set is set at current text frame.
    2055             :         // OD 2004-02-13 #i25029# - get next frame, but skip hidden text frames.
    2056       54961 :         const SwFrm* pNextFrm = _rFrm.GetNext();
    2057      134220 :         while ( pNextFrm && pNextFrm->IsTxtFrm() &&
    2058       24298 :                 static_cast<const SwTxtFrm*>(pNextFrm)->IsHiddenNow() )
    2059             :         {
    2060           0 :             pNextFrm = pNextFrm->GetNext();
    2061             :         }
    2062       79259 :         if ( pNextFrm && pNextFrm->IsTxtFrm() &&
    2063       24298 :              _rFrm.GetAttrSet()->GetParaConnectBorder().GetValue()
    2064             :            )
    2065             :         {
    2066       24298 :             bJoinedWithNext = _JoinWithCmp( _rFrm, *(pNextFrm) );
    2067             :         }
    2068             :     }
    2069             : 
    2070             :     // valid cache status, if demanded
    2071       55617 :     bCachedJoinedWithNext = bCacheGetLine;
    2072       55617 : }
    2073             : 
    2074             : // OD 21.05.2003 #108789# - accessor for cached values <bJoinedWithPrev>
    2075             : // OD 2004-02-26 #i25029# - add 2nd parameter <_pPrevFrm>, which is passed to
    2076             : // method <_CalcJoindWithPrev(..)>.
    2077      112072 : sal_Bool SwBorderAttrs::JoinedWithPrev( const SwFrm& _rFrm,
    2078             :                                     const SwFrm* _pPrevFrm ) const
    2079             : {
    2080      112072 :     if ( !bCachedJoinedWithPrev || _pPrevFrm )
    2081             :     {
    2082             :         // OD 2004-02-26 #i25029# - pass <_pPrevFrm> as 2nd parameter
    2083      112008 :         const_cast<SwBorderAttrs*>(this)->_CalcJoinedWithPrev( _rFrm, _pPrevFrm );
    2084             :     }
    2085             : 
    2086      112072 :     return bJoinedWithPrev;
    2087             : }
    2088             : 
    2089       55681 : sal_Bool SwBorderAttrs::JoinedWithNext( const SwFrm& _rFrm ) const
    2090             : {
    2091       55681 :     if ( !bCachedJoinedWithNext )
    2092             :     {
    2093       55617 :         const_cast<SwBorderAttrs*>(this)->_CalcJoinedWithNext( _rFrm );
    2094             :     }
    2095             : 
    2096       55681 :     return bJoinedWithNext;
    2097             : }
    2098             : 
    2099             : // OD 2004-02-26 #i25029# - added 2nd parameter <_pPrevFrm>, which is passed to
    2100             : // method <JoinedWithPrev>
    2101       65908 : void SwBorderAttrs::_GetTopLine( const SwFrm& _rFrm,
    2102             :                                  const SwFrm* _pPrevFrm )
    2103             : {
    2104       65908 :     sal_uInt16 nRet = CalcTopLine();
    2105             : 
    2106             :     // OD 21.05.2003 #108789# - use new method <JoinWithPrev()>
    2107             :     // OD 2004-02-26 #i25029# - add 2nd parameter
    2108       65908 :     if ( JoinedWithPrev( _rFrm, _pPrevFrm ) )
    2109             :     {
    2110       24030 :         nRet = 0;
    2111             :     }
    2112             : 
    2113       65908 :     bCachedGetTopLine = bCacheGetLine;
    2114             : 
    2115       65908 :     nGetTopLine = nRet;
    2116       65908 : }
    2117             : 
    2118       55609 : void SwBorderAttrs::_GetBottomLine( const SwFrm& _rFrm )
    2119             : {
    2120       55609 :     sal_uInt16 nRet = CalcBottomLine();
    2121             : 
    2122             :     // OD 21.05.2003 #108789# - use new method <JoinWithPrev()>
    2123       55609 :     if ( JoinedWithNext( _rFrm ) )
    2124             :     {
    2125       21525 :         nRet = 0;
    2126             :     }
    2127             : 
    2128       55609 :     bCachedGetBottomLine = bCacheGetLine;
    2129             : 
    2130       55609 :     nGetBottomLine = nRet;
    2131       55609 : }
    2132             : 
    2133             : /*************************************************************************/
    2134             : 
    2135      283846 : SwBorderAttrAccess::SwBorderAttrAccess( SwCache &rCach, const SwFrm *pFrm ) :
    2136      283846 :     SwCacheAccess( rCach, (pFrm->IsCntntFrm() ?
    2137             :                                 (void*)((SwCntntFrm*)pFrm)->GetNode() :
    2138      128296 :                                 (void*)((SwLayoutFrm*)pFrm)->GetFmt()),
    2139      283846 :                            (sal_Bool)(pFrm->IsCntntFrm() ?
    2140      155550 :                 ((SwModify*)((SwCntntFrm*)pFrm)->GetNode())->IsInCache() :
    2141      128296 :                 ((SwModify*)((SwLayoutFrm*)pFrm)->GetFmt())->IsInCache()) ),
    2142      979834 :     pConstructor( pFrm )
    2143             : {
    2144      283846 : }
    2145             : 
    2146       59017 : SwCacheObj *SwBorderAttrAccess::NewObj()
    2147             : {
    2148       59017 :     ((SwModify*)pOwner)->SetInCache( sal_True );
    2149       59017 :     return new SwBorderAttrs( (SwModify*)pOwner, pConstructor );
    2150             : }
    2151             : 
    2152      283846 : SwBorderAttrs *SwBorderAttrAccess::Get()
    2153             : {
    2154      283846 :     return (SwBorderAttrs*)SwCacheAccess::Get();
    2155             : }
    2156             : 
    2157        1268 : SwOrderIter::SwOrderIter( const SwPageFrm *pPg, sal_Bool bFlys ) :
    2158             :     pPage( pPg ),
    2159             :     pCurrent( 0 ),
    2160        1268 :     bFlysOnly( bFlys )
    2161             : {
    2162        1268 : }
    2163             : 
    2164           4 : const SdrObject *SwOrderIter::Top()
    2165             : {
    2166           4 :     pCurrent = 0;
    2167           4 :     if ( pPage->GetSortedObjs() )
    2168             :     {
    2169           4 :         const SwSortedObjs *pObjs = pPage->GetSortedObjs();
    2170           4 :         if ( pObjs->Count() )
    2171             :         {
    2172           4 :             sal_uInt32 nTopOrd = 0;
    2173           4 :             (*pObjs)[0]->GetDrawObj()->GetOrdNum();  // force updating
    2174          14 :             for ( sal_uInt16 i = 0; i < pObjs->Count(); ++i )
    2175             :             {
    2176          10 :                 const SdrObject* pObj = (*pObjs)[i]->GetDrawObj();
    2177          10 :                 if ( bFlysOnly && !pObj->ISA(SwVirtFlyDrawObj) )
    2178           0 :                     continue;
    2179          10 :                 sal_uInt32 nTmp = pObj->GetOrdNumDirect();
    2180          10 :                 if ( nTmp >= nTopOrd )
    2181             :                 {
    2182          10 :                     nTopOrd = nTmp;
    2183          10 :                     pCurrent = pObj;
    2184             :                 }
    2185             :             }
    2186             :         }
    2187             :     }
    2188           4 :     return pCurrent;
    2189             : }
    2190             : 
    2191         168 : const SdrObject *SwOrderIter::Bottom()
    2192             : {
    2193         168 :     pCurrent = 0;
    2194         168 :     if ( pPage->GetSortedObjs() )
    2195             :     {
    2196         168 :         sal_uInt32 nBotOrd = USHRT_MAX;
    2197         168 :         const SwSortedObjs *pObjs = pPage->GetSortedObjs();
    2198         168 :         if ( pObjs->Count() )
    2199             :         {
    2200         168 :             (*pObjs)[0]->GetDrawObj()->GetOrdNum();  // force updating
    2201         543 :             for ( sal_uInt16 i = 0; i < pObjs->Count(); ++i )
    2202             :             {
    2203         375 :                 const SdrObject* pObj = (*pObjs)[i]->GetDrawObj();
    2204         375 :                 if ( bFlysOnly && !pObj->ISA(SwVirtFlyDrawObj) )
    2205         128 :                     continue;
    2206         247 :                 sal_uInt32 nTmp = pObj->GetOrdNumDirect();
    2207         247 :                 if ( nTmp < nBotOrd )
    2208             :                 {
    2209         229 :                     nBotOrd = nTmp;
    2210         229 :                     pCurrent = pObj;
    2211             :                 }
    2212             :             }
    2213             :         }
    2214             :     }
    2215         168 :     return pCurrent;
    2216             : }
    2217             : 
    2218        8852 : const SdrObject *SwOrderIter::Next()
    2219             : {
    2220        8852 :     const sal_uInt32 nCurOrd = pCurrent ? pCurrent->GetOrdNumDirect() : 0;
    2221        8852 :     pCurrent = 0;
    2222        8852 :     if ( pPage->GetSortedObjs() )
    2223             :     {
    2224        8852 :         sal_uInt32 nOrd = USHRT_MAX;
    2225        8852 :         const SwSortedObjs *pObjs = pPage->GetSortedObjs();
    2226        8852 :         if ( pObjs->Count() )
    2227             :         {
    2228        8852 :             (*pObjs)[0]->GetDrawObj()->GetOrdNum();  // force updating
    2229      624045 :             for ( sal_uInt16 i = 0; i < pObjs->Count(); ++i )
    2230             :             {
    2231      615193 :                 const SdrObject* pObj = (*pObjs)[i]->GetDrawObj();
    2232      615193 :                 if ( bFlysOnly && !pObj->ISA(SwVirtFlyDrawObj) )
    2233      274148 :                     continue;
    2234      341045 :                 sal_uInt32 nTmp = pObj->GetOrdNumDirect();
    2235      341045 :                 if ( nTmp > nCurOrd && nTmp < nOrd )
    2236             :                 {
    2237       39976 :                     nOrd = nTmp;
    2238       39976 :                     pCurrent = pObj;
    2239             :                 }
    2240             :             }
    2241             :         }
    2242             :     }
    2243        8852 :     return pCurrent;
    2244             : }
    2245             : 
    2246          10 : const SdrObject *SwOrderIter::Prev()
    2247             : {
    2248          10 :     const sal_uInt32 nCurOrd = pCurrent ? pCurrent->GetOrdNumDirect() : 0;
    2249          10 :     pCurrent = 0;
    2250          10 :     if ( pPage->GetSortedObjs() )
    2251             :     {
    2252          10 :         const SwSortedObjs *pObjs = pPage->GetSortedObjs();
    2253          10 :         if ( pObjs->Count() )
    2254             :         {
    2255          10 :             sal_uInt32 nOrd = 0;
    2256          10 :             (*pObjs)[0]->GetDrawObj()->GetOrdNum();  // force updating
    2257          36 :             for ( sal_uInt16 i = 0; i < pObjs->Count(); ++i )
    2258             :             {
    2259          26 :                 const SdrObject* pObj = (*pObjs)[i]->GetDrawObj();
    2260          26 :                 if ( bFlysOnly && !pObj->ISA(SwVirtFlyDrawObj) )
    2261           0 :                     continue;
    2262          26 :                 sal_uInt32 nTmp = pObj->GetOrdNumDirect();
    2263          26 :                 if ( nTmp < nCurOrd && nTmp >= nOrd )
    2264             :                 {
    2265           8 :                     nOrd = nTmp;
    2266           8 :                     pCurrent = pObj;
    2267             :                 }
    2268             :             }
    2269             :         }
    2270             :     }
    2271          10 :     return pCurrent;
    2272             : }
    2273             : 
    2274             : /// Keep and restore the substructure of a layout frame for an action.
    2275             : // New algorithm:
    2276             : //   Do not look at each neighbor one by one to set all pointers correctly.
    2277             : //   It is sufficient to detach a part of a chain and check if another chain needs to be added
    2278             : //   when attaching it again. Only the pointers necessary for the chain connection need to be
    2279             : //   adjusted. The correction happens in RestoreCntnt(). In between all access is restricted.
    2280             : //   During this action, the Flys are detached from the page.
    2281             : 
    2282             : // #115759# - 'remove' also drawing object from page and
    2283             : // at-fly anchored objects from page
    2284           6 : static void lcl_RemoveObjsFromPage( SwFrm* _pFrm )
    2285             : {
    2286             :     OSL_ENSURE( _pFrm->GetDrawObjs(), "no DrawObjs in lcl_RemoveObjsFromPage." );
    2287           6 :     SwSortedObjs &rObjs = *_pFrm->GetDrawObjs();
    2288          18 :     for ( sal_uInt16 i = 0; i < rObjs.Count(); ++i )
    2289             :     {
    2290          12 :         SwAnchoredObject* pObj = rObjs[i];
    2291             :         // #115759# - reset member, at which the anchored
    2292             :         // object orients its vertical position
    2293          12 :         pObj->ClearVertPosOrientFrm();
    2294             :         // #i43913#
    2295          12 :         pObj->ResetLayoutProcessBools();
    2296             :         // #115759# - remove also lower objects of as-character
    2297             :         // anchored Writer fly frames from page
    2298          12 :         if ( pObj->ISA(SwFlyFrm) )
    2299             :         {
    2300           0 :             SwFlyFrm* pFlyFrm = static_cast<SwFlyFrm*>(pObj);
    2301             : 
    2302             :             // #115759# - remove also direct lowers of Writer
    2303             :             // fly frame from page
    2304           0 :             if ( pFlyFrm->GetDrawObjs() )
    2305             :             {
    2306           0 :                 ::lcl_RemoveObjsFromPage( pFlyFrm );
    2307             :             }
    2308             : 
    2309           0 :             SwCntntFrm* pCnt = pFlyFrm->ContainsCntnt();
    2310           0 :             while ( pCnt )
    2311             :             {
    2312           0 :                 if ( pCnt->GetDrawObjs() )
    2313           0 :                     ::lcl_RemoveObjsFromPage( pCnt );
    2314           0 :                 pCnt = pCnt->GetNextCntntFrm();
    2315             :             }
    2316           0 :             if ( pFlyFrm->IsFlyFreeFrm() )
    2317             :             {
    2318             :                 // #i28701# - use new method <GetPageFrm()>
    2319           0 :                 pFlyFrm->GetPageFrm()->RemoveFlyFromPage( pFlyFrm );
    2320             :             }
    2321             :         }
    2322             :         // #115759# - remove also drawing objects from page
    2323          12 :         else if ( pObj->ISA(SwAnchoredDrawObject) )
    2324             :         {
    2325          12 :             if (pObj->GetFrmFmt().GetAnchor().GetAnchorId() != FLY_AS_CHAR)
    2326             :             {
    2327             :                 pObj->GetPageFrm()->RemoveDrawObjFromPage(
    2328           0 :                                 *(static_cast<SwAnchoredDrawObject*>(pObj)) );
    2329             :             }
    2330             :         }
    2331             :     }
    2332           6 : }
    2333             : 
    2334         509 : SwFrm *SaveCntnt( SwLayoutFrm *pLay, SwFrm *pStart )
    2335             : {
    2336         509 :     if( pLay->IsSctFrm() && pLay->Lower() && pLay->Lower()->IsColumnFrm() )
    2337           9 :         sw_RemoveFtns( (SwColumnFrm*)pLay->Lower(), sal_True, sal_True );
    2338             : 
    2339             :     SwFrm *pSav;
    2340         509 :     if ( 0 == (pSav = pLay->ContainsAny()) )
    2341         340 :         return 0;
    2342             : 
    2343         169 :     if( pSav->IsInFtn() && !pLay->IsInFtn() )
    2344             :     {
    2345           0 :         do
    2346           0 :             pSav = pSav->FindNext();
    2347           0 :         while( pSav && pSav->IsInFtn() );
    2348           0 :         if( !pSav || !pLay->IsAnLower( pSav ) )
    2349           0 :             return NULL;
    2350             :     }
    2351             : 
    2352             :     // Tables should be saved as a whole, expection:
    2353             :     // The contents of a section or a cell inside a table should be saved
    2354         169 :     if ( pSav->IsInTab() && !( ( pLay->IsSctFrm() || pLay->IsCellFrm() ) && pLay->IsInTab() ) )
    2355           0 :         while ( !pSav->IsTabFrm() )
    2356           0 :             pSav = pSav->GetUpper();
    2357             : 
    2358         169 :     if( pSav->IsInSct() )
    2359             :     { // search the upmost section inside of pLay
    2360          22 :         SwFrm* pSect = pLay->FindSctFrm();
    2361          22 :         SwFrm *pTmp = pSav;
    2362          22 :         do
    2363             :         {
    2364          22 :             pSav = pTmp;
    2365          22 :             pTmp = (pSav && pSav->GetUpper()) ? pSav->GetUpper()->FindSctFrm() : NULL;
    2366             :         } while ( pTmp != pSect );
    2367             :     }
    2368             : 
    2369         169 :     SwFrm *pFloat = pSav;
    2370         169 :     if( !pStart )
    2371         166 :         pStart = pSav;
    2372         169 :     bool bGo = pStart == pSav;
    2373         169 :     do
    2374             :     {
    2375         169 :         if( bGo )
    2376         166 :             pFloat->GetUpper()->pLower = 0; // detach the chain part
    2377             : 
    2378             :         // search the end of the chain part, remove Flys on the way
    2379          13 :         do
    2380             :         {
    2381         182 :             if( bGo )
    2382             :             {
    2383         179 :                 if ( pFloat->IsCntntFrm() )
    2384             :                 {
    2385         179 :                     if ( pFloat->GetDrawObjs() )
    2386           6 :                         ::lcl_RemoveObjsFromPage( (SwCntntFrm*)pFloat );
    2387             :                 }
    2388           0 :                 else if ( pFloat->IsTabFrm() || pFloat->IsSctFrm() )
    2389             :                 {
    2390           0 :                     SwCntntFrm *pCnt = ((SwLayoutFrm*)pFloat)->ContainsCntnt();
    2391           0 :                     if( pCnt )
    2392             :                     {
    2393           0 :                         do
    2394           0 :                         {   if ( pCnt->GetDrawObjs() )
    2395           0 :                                 ::lcl_RemoveObjsFromPage( pCnt );
    2396           0 :                             pCnt = pCnt->GetNextCntntFrm();
    2397           0 :                         } while ( pCnt && ((SwLayoutFrm*)pFloat)->IsAnLower( pCnt ) );
    2398             :                     }
    2399             :                 }
    2400             :                 else {
    2401             :                     OSL_ENSURE( !pFloat, "new FloatFrame?" );
    2402             :                 }
    2403             :             }
    2404         182 :             if ( pFloat->GetNext()  )
    2405             :             {
    2406          13 :                 if( bGo )
    2407          10 :                     pFloat->mpUpper = NULL;
    2408          13 :                 pFloat = pFloat->GetNext();
    2409          13 :                 if( !bGo && pFloat == pStart )
    2410             :                 {
    2411           3 :                     bGo = true;
    2412           3 :                     pFloat->mpPrev->mpNext = NULL;
    2413           3 :                     pFloat->mpPrev = NULL;
    2414             :                 }
    2415             :             }
    2416             :             else
    2417         169 :                 break;
    2418             : 
    2419             :         } while ( pFloat );
    2420             : 
    2421             :         // search next chain part and connect both chains
    2422         169 :         SwFrm *pTmp = pFloat->FindNext();
    2423         169 :         if( bGo )
    2424         169 :             pFloat->mpUpper = NULL;
    2425             : 
    2426         169 :         if( !pLay->IsInFtn() )
    2427         336 :             while( pTmp && pTmp->IsInFtn() )
    2428           0 :                 pTmp = pTmp->FindNext();
    2429             : 
    2430         169 :         if ( !pLay->IsAnLower( pTmp ) )
    2431         169 :             pTmp = 0;
    2432             : 
    2433         169 :         if ( pTmp && bGo )
    2434             :         {
    2435           0 :             pFloat->mpNext = pTmp; // connect both chains
    2436           0 :             pFloat->mpNext->mpPrev = pFloat;
    2437             :         }
    2438         169 :         pFloat = pTmp;
    2439         169 :         bGo = bGo || ( pStart == pFloat );
    2440             :     }  while ( pFloat );
    2441             : 
    2442         169 :     return bGo ? pStart : NULL;
    2443             : }
    2444             : 
    2445             : // #115759# - add also drawing objects to page and at-fly
    2446             : // anchored objects to page
    2447           6 : static void lcl_AddObjsToPage( SwFrm* _pFrm, SwPageFrm* _pPage )
    2448             : {
    2449             :     OSL_ENSURE( _pFrm->GetDrawObjs(), "no DrawObjs in lcl_AddObjsToPage." );
    2450           6 :     SwSortedObjs &rObjs = *_pFrm->GetDrawObjs();
    2451          18 :     for ( sal_uInt16 i = 0; i < rObjs.Count(); ++i )
    2452             :     {
    2453          12 :         SwAnchoredObject* pObj = rObjs[i];
    2454             : 
    2455             :         // #115759# - unlock position of anchored object
    2456             :         // in order to get the object's position calculated.
    2457          12 :         pObj->UnlockPosition();
    2458             :         // #115759# - add also lower objects of as-character
    2459             :         // anchored Writer fly frames from page
    2460          12 :         if ( pObj->ISA(SwFlyFrm) )
    2461             :         {
    2462           0 :             SwFlyFrm* pFlyFrm = static_cast<SwFlyFrm*>(pObj);
    2463           0 :             if ( pObj->ISA(SwFlyFreeFrm) )
    2464             :             {
    2465           0 :                 _pPage->AppendFlyToPage( pFlyFrm );
    2466             :             }
    2467           0 :             pFlyFrm->_InvalidatePos();
    2468           0 :             pFlyFrm->_InvalidateSize();
    2469           0 :             pFlyFrm->InvalidatePage( _pPage );
    2470             : 
    2471             :             // #115759# - add also at-fly anchored objects
    2472             :             // to page
    2473           0 :             if ( pFlyFrm->GetDrawObjs() )
    2474             :             {
    2475           0 :                 ::lcl_AddObjsToPage( pFlyFrm, _pPage );
    2476             :             }
    2477             : 
    2478           0 :             SwCntntFrm *pCnt = pFlyFrm->ContainsCntnt();
    2479           0 :             while ( pCnt )
    2480             :             {
    2481           0 :                 if ( pCnt->GetDrawObjs() )
    2482           0 :                     ::lcl_AddObjsToPage( pCnt, _pPage );
    2483           0 :                 pCnt = pCnt->GetNextCntntFrm();
    2484             :             }
    2485             :         }
    2486             :         // #115759# - remove also drawing objects from page
    2487          12 :         else if ( pObj->ISA(SwAnchoredDrawObject) )
    2488             :         {
    2489          12 :             if (pObj->GetFrmFmt().GetAnchor().GetAnchorId() != FLY_AS_CHAR)
    2490             :             {
    2491           0 :                 pObj->InvalidateObjPos();
    2492             :                 _pPage->AppendDrawObjToPage(
    2493           0 :                                 *(static_cast<SwAnchoredDrawObject*>(pObj)) );
    2494             :             }
    2495             :         }
    2496             :     }
    2497           6 : }
    2498             : 
    2499         169 : void RestoreCntnt( SwFrm *pSav, SwLayoutFrm *pParent, SwFrm *pSibling, bool bGrow )
    2500             : {
    2501             :     OSL_ENSURE( pSav && pParent, "no Save or Parent provided for RestoreCntnt." );
    2502         169 :     SWRECTFN( pParent )
    2503             : 
    2504             :     // If there are already FlowFrms below the new parent, so add the chain (starting with pSav)
    2505             :     // after the last one. The parts are inserted and invalidated if needed.
    2506             :     // On the way, the Flys of the CntntFrms are registered at the page.
    2507             : 
    2508         169 :     SwPageFrm *pPage = pParent->FindPageFrm();
    2509             : 
    2510         169 :     if ( pPage )
    2511         169 :         pPage->InvalidatePage( pPage );
    2512             : 
    2513             :     // determine predecessor and establish connection or initialize
    2514         169 :     pSav->mpPrev = pSibling;
    2515             :     SwFrm* pNxt;
    2516         169 :     if ( pSibling )
    2517             :     {
    2518          84 :         pNxt = pSibling->mpNext;
    2519          84 :         pSibling->mpNext = pSav;
    2520          84 :         pSibling->_InvalidatePrt();
    2521          84 :         ((SwCntntFrm*)pSibling)->InvalidatePage( pPage );
    2522          84 :         if ( ((SwCntntFrm*)pSibling)->GetFollow() )
    2523          76 :             pSibling->Prepare( PREP_CLEAR, 0, false );
    2524             :     }
    2525             :     else
    2526          85 :     {   pNxt = pParent->pLower;
    2527          85 :         pParent->pLower = pSav;
    2528          85 :         pSav->mpUpper = pParent; // set here already, so that it is explicit when invalidating
    2529             : 
    2530          85 :         if ( pSav->IsCntntFrm() )
    2531          85 :             ((SwCntntFrm*)pSav)->InvalidatePage( pPage );
    2532             :         else
    2533             :         {   // pSav might be an empty SectFrm
    2534           0 :             SwCntntFrm* pCnt = pParent->ContainsCntnt();
    2535           0 :             if( pCnt )
    2536           0 :                 pCnt->InvalidatePage( pPage );
    2537             :         }
    2538             :     }
    2539             : 
    2540             :     // the parent needs to grow appropiately
    2541         169 :     SwTwips nGrowVal = 0;
    2542             :     SwFrm* pLast;
    2543         179 :     do
    2544         179 :     {   pSav->mpUpper = pParent;
    2545         179 :         nGrowVal += (pSav->Frm().*fnRect->fnGetHeight)();
    2546         179 :         pSav->_InvalidateAll();
    2547             : 
    2548             :         // register Flys, if TxtFrms than also invalidate appropriately
    2549         179 :         if ( pSav->IsCntntFrm() )
    2550             :         {
    2551         358 :             if ( pSav->IsTxtFrm() &&
    2552         179 :                  ((SwTxtFrm*)pSav)->GetCacheIdx() != USHRT_MAX )
    2553         135 :                 ((SwTxtFrm*)pSav)->Init();  // I am its friend
    2554             : 
    2555         179 :             if ( pPage && pSav->GetDrawObjs() )
    2556           6 :                 ::lcl_AddObjsToPage( (SwCntntFrm*)pSav, pPage );
    2557             :         }
    2558             :         else
    2559           0 :         {   SwCntntFrm *pBlub = ((SwLayoutFrm*)pSav)->ContainsCntnt();
    2560           0 :             if( pBlub )
    2561             :             {
    2562           0 :                 do
    2563           0 :                 {   if ( pPage && pBlub->GetDrawObjs() )
    2564           0 :                         ::lcl_AddObjsToPage( pBlub, pPage );
    2565           0 :                     if( pBlub->IsTxtFrm() && ((SwTxtFrm*)pBlub)->HasFtn() &&
    2566           0 :                          ((SwTxtFrm*)pBlub)->GetCacheIdx() != USHRT_MAX )
    2567           0 :                         ((SwTxtFrm*)pBlub)->Init(); // I am its friend
    2568           0 :                     pBlub = pBlub->GetNextCntntFrm();
    2569           0 :                 } while ( pBlub && ((SwLayoutFrm*)pSav)->IsAnLower( pBlub ));
    2570             :             }
    2571             :         }
    2572         179 :         pLast = pSav;
    2573         179 :         pSav = pSav->GetNext();
    2574             : 
    2575             :     } while ( pSav );
    2576             : 
    2577         169 :     if( pNxt )
    2578             :     {
    2579           4 :         pLast->mpNext = pNxt;
    2580           4 :         pNxt->mpPrev = pLast;
    2581             :     }
    2582             : 
    2583         169 :     if ( bGrow )
    2584         169 :         pParent->Grow( nGrowVal );
    2585         169 : }
    2586             : 
    2587        2409 : SwPageFrm * InsertNewPage( SwPageDesc &rDesc, SwFrm *pUpper,
    2588             :                           bool bOdd, bool bFirst, bool bInsertEmpty, sal_Bool bFtn,
    2589             :                           SwFrm *pSibling )
    2590             : {
    2591             :     SwPageFrm *pRet;
    2592        2409 :     SwDoc *pDoc = ((SwLayoutFrm*)pUpper)->GetFmt()->GetDoc();
    2593        2409 :     if (bFirst)
    2594             :     {
    2595        1756 :         if (rDesc.IsFirstShared())
    2596             :         {
    2597             :             // We need to fallback to left or right page format, decide it now.
    2598             :             // FIXME: is this still needed?
    2599        1702 :             if (bOdd)
    2600             :             {
    2601        1669 :                 rDesc.GetFirstMaster().SetFmtAttr( rDesc.GetMaster().GetHeader() );
    2602        1669 :                 rDesc.GetFirstMaster().SetFmtAttr( rDesc.GetMaster().GetFooter() );
    2603             :                 // fdo#60250 copy margins for mirrored pages
    2604        1669 :                 rDesc.GetFirstMaster().SetFmtAttr( rDesc.GetMaster().GetLRSpace() );
    2605             :             }
    2606             :             else
    2607             :             {
    2608          33 :                 rDesc.GetFirstLeft().SetFmtAttr( rDesc.GetLeft().GetHeader() );
    2609          33 :                 rDesc.GetFirstLeft().SetFmtAttr( rDesc.GetLeft().GetFooter() );
    2610          33 :                 rDesc.GetFirstLeft().SetFmtAttr( rDesc.GetLeft().GetLRSpace() );
    2611             :             }
    2612             :         }
    2613             :     }
    2614        2409 :     SwFrmFmt *pFmt(bOdd ? rDesc.GetRightFmt(bFirst) : rDesc.GetLeftFmt(bFirst));
    2615             :     // If there is no FrmFmt for this page, add an empty page
    2616        2409 :     if ( !pFmt )
    2617             :     {
    2618           1 :         pFmt = bOdd ? rDesc.GetLeftFmt() : rDesc.GetRightFmt();
    2619             :         OSL_ENSURE( pFmt, "Descriptor without any format?!" );
    2620           1 :         bInsertEmpty = !bInsertEmpty;
    2621             :     }
    2622        2409 :     if( bInsertEmpty )
    2623             :     {
    2624           0 :         SwPageDesc *pTmpDesc = pSibling && pSibling->GetPrev() ?
    2625           1 :                 ((SwPageFrm*)pSibling->GetPrev())->GetPageDesc() : &rDesc;
    2626           1 :         pRet = new SwPageFrm( pDoc->GetEmptyPageFmt(), pUpper, pTmpDesc );
    2627           1 :         pRet->Paste( pUpper, pSibling );
    2628           1 :         pRet->PreparePage( bFtn );
    2629             :     }
    2630        2409 :     pRet = new SwPageFrm( pFmt, pUpper, &rDesc );
    2631        2409 :     pRet->Paste( pUpper, pSibling );
    2632        2409 :     pRet->PreparePage( bFtn );
    2633        2409 :     if ( pRet->GetNext() )
    2634           0 :         ((SwRootFrm*)pRet->GetUpper())->AssertPageFlys( pRet );
    2635        2409 :     return pRet;
    2636             : }
    2637             : 
    2638             : /* The following two methods search the layout structure recursively and
    2639             :  * register all Flys at the page that have a Frm in this structure as an anchor.
    2640             :  */
    2641             : 
    2642         226 : static void lcl_Regist( SwPageFrm *pPage, const SwFrm *pAnch )
    2643             : {
    2644         226 :     SwSortedObjs *pObjs = (SwSortedObjs*)pAnch->GetDrawObjs();
    2645         500 :     for ( sal_uInt16 i = 0; i < pObjs->Count(); ++i )
    2646             :     {
    2647         274 :         SwAnchoredObject* pObj = (*pObjs)[i];
    2648         274 :         if ( pObj->ISA(SwFlyFrm) )
    2649             :         {
    2650         184 :             SwFlyFrm *pFly = static_cast<SwFlyFrm*>(pObj);
    2651             :             // register (not if already known)
    2652             :             // #i28701# - use new method <GetPageFrm()>
    2653         184 :             SwPageFrm *pPg = pFly->IsFlyFreeFrm()
    2654         184 :                              ? pFly->GetPageFrm() : pFly->FindPageFrm();
    2655         184 :             if ( pPg != pPage )
    2656             :             {
    2657         184 :                 if ( pPg )
    2658           0 :                     pPg->RemoveFlyFromPage( pFly );
    2659         184 :                 pPage->AppendFlyToPage( pFly );
    2660             :             }
    2661         184 :             ::RegistFlys( pPage, pFly );
    2662             :         }
    2663             :         else
    2664             :         {
    2665             :             // #i87493#
    2666          90 :             if ( pPage != pObj->GetPageFrm() )
    2667             :             {
    2668             :                 // #i28701#
    2669          90 :                 if ( pObj->GetPageFrm() )
    2670           0 :                     pObj->GetPageFrm()->RemoveDrawObjFromPage( *pObj );
    2671          90 :                 pPage->AppendDrawObjToPage( *pObj );
    2672             :             }
    2673             :         }
    2674             : 
    2675         274 :         const SwFlyFrm* pFly = pAnch->FindFlyFrm();
    2676         278 :         if ( pFly &&
    2677         274 :              pObj->GetDrawObj()->GetOrdNum() < pFly->GetVirtDrawObj()->GetOrdNum() &&
    2678           0 :              pObj->GetDrawObj()->GetPage() )
    2679             :         {
    2680             :             //#i119945# set pFly's OrdNum to pObj's. So when pFly is removed by Undo, the original OrdNum will not be changed.
    2681           0 :             pObj->DrawObj()->GetPage()->SetObjectOrdNum( pFly->GetVirtDrawObj()->GetOrdNumDirect(),
    2682           0 :                                                          pObj->GetDrawObj()->GetOrdNumDirect() );
    2683             :         }
    2684             :     }
    2685         226 : }
    2686             : 
    2687       25604 : void RegistFlys( SwPageFrm *pPage, const SwLayoutFrm *pLay )
    2688             : {
    2689       25604 :     if ( pLay->GetDrawObjs() )
    2690           0 :         ::lcl_Regist( pPage, pLay );
    2691       25604 :     const SwFrm *pFrm = pLay->Lower();
    2692       88632 :     while ( pFrm )
    2693             :     {
    2694       37424 :         if ( pFrm->IsLayoutFrm() )
    2695       20807 :             ::RegistFlys( pPage, (const SwLayoutFrm*)pFrm );
    2696       16617 :         else if ( pFrm->GetDrawObjs() )
    2697         226 :             ::lcl_Regist( pPage, pFrm );
    2698       37424 :         pFrm = pFrm->GetNext();
    2699             :     }
    2700       25604 : }
    2701             : 
    2702             : /// Notify the background based on the difference between old and new rectangle
    2703        3724 : void Notify( SwFlyFrm *pFly, SwPageFrm *pOld, const SwRect &rOld,
    2704             :              const SwRect* pOldPrt )
    2705             : {
    2706        3724 :     const SwRect aFrm( pFly->GetObjRectWithSpaces() );
    2707        3724 :     if ( rOld.Pos() != aFrm.Pos() )
    2708             :     {   // changed position, invalidate old and new area
    2709        2622 :         if ( rOld.HasArea() &&
    2710        1311 :              rOld.Left()+pFly->GetFmt()->GetLRSpace().GetLeft() < FAR_AWAY )
    2711             :         {
    2712         157 :             pFly->NotifyBackground( pOld, rOld, PREP_FLY_LEAVE );
    2713             :         }
    2714        1311 :         pFly->NotifyBackground( pFly->FindPageFrm(), aFrm, PREP_FLY_ARRIVE );
    2715             :     }
    2716        2413 :     else if ( rOld.SSize() != aFrm.SSize() )
    2717             :     {   // changed size, invalidate the area that was left or is now overlapped
    2718             :         // For simplicity, we purposely invalidate a Twip even if not needed.
    2719             : 
    2720         994 :         SwViewShell *pSh = pFly->getRootFrm()->GetCurrShell();
    2721         994 :         if( pSh && rOld.HasArea() )
    2722         994 :             pSh->InvalidateWindows( rOld );
    2723             : 
    2724             :         // #i51941# - consider case that fly frame isn't
    2725             :         // registered at the old page <pOld>
    2726         994 :         SwPageFrm* pPageFrm = pFly->FindPageFrm();
    2727         994 :         if ( pOld != pPageFrm )
    2728             :         {
    2729          24 :             pFly->NotifyBackground( pPageFrm, aFrm, PREP_FLY_ARRIVE );
    2730             :         }
    2731             : 
    2732         994 :         if ( rOld.Left() != aFrm.Left() )
    2733             :         {
    2734           0 :             SwRect aTmp( rOld );
    2735           0 :             aTmp.Union( aFrm );
    2736           0 :             aTmp.Left(  std::min(aFrm.Left(), rOld.Left()) );
    2737           0 :             aTmp.Right( std::max(aFrm.Left(), rOld.Left()) );
    2738           0 :             pFly->NotifyBackground( pOld, aTmp, PREP_FLY_CHGD );
    2739             :         }
    2740         994 :         SwTwips nOld = rOld.Right();
    2741         994 :         SwTwips nNew = aFrm.Right();
    2742         994 :         if ( nOld != nNew )
    2743             :         {
    2744           9 :             SwRect aTmp( rOld );
    2745           9 :             aTmp.Union( aFrm );
    2746           9 :             aTmp.Left(  std::min(nNew, nOld) );
    2747           9 :             aTmp.Right( std::max(nNew, nOld) );
    2748           9 :             pFly->NotifyBackground( pOld, aTmp, PREP_FLY_CHGD );
    2749             :         }
    2750         994 :         if ( rOld.Top() != aFrm.Top() )
    2751             :         {
    2752           0 :             SwRect aTmp( rOld );
    2753           0 :             aTmp.Union( aFrm );
    2754           0 :             aTmp.Top(    std::min(aFrm.Top(), rOld.Top()) );
    2755           0 :             aTmp.Bottom( std::max(aFrm.Top(), rOld.Top()) );
    2756           0 :             pFly->NotifyBackground( pOld, aTmp, PREP_FLY_CHGD );
    2757             :         }
    2758         994 :         nOld = rOld.Bottom();
    2759         994 :         nNew = aFrm.Bottom();
    2760         994 :         if ( nOld != nNew )
    2761             :         {
    2762         990 :             SwRect aTmp( rOld );
    2763         990 :             aTmp.Union( aFrm );
    2764         990 :             aTmp.Top(    std::min(nNew, nOld) );
    2765         990 :             aTmp.Bottom( std::max(nNew, nOld) );
    2766         990 :             pFly->NotifyBackground( pOld, aTmp, PREP_FLY_CHGD );
    2767             :         }
    2768             :     }
    2769        1468 :     else if ( pOldPrt && *pOldPrt != pFly->Prt() &&
    2770          49 :               pFly->GetFmt()->GetSurround().IsContour() )
    2771             :     {
    2772             :         // #i24097#
    2773           0 :         pFly->NotifyBackground( pFly->FindPageFrm(), aFrm, PREP_FLY_ARRIVE );
    2774             :     }
    2775        3724 : }
    2776             : 
    2777        6282 : static void lcl_CheckFlowBack( SwFrm* pFrm, const SwRect &rRect )
    2778             : {
    2779        6282 :     SwTwips nBottom = rRect.Bottom();
    2780       40518 :     while( pFrm )
    2781             :     {
    2782       27954 :         if( pFrm->IsLayoutFrm() )
    2783             :         {
    2784       13914 :             if( rRect.IsOver( pFrm->Frm() ) )
    2785        4196 :                 lcl_CheckFlowBack( ((SwLayoutFrm*)pFrm)->Lower(), rRect );
    2786             :         }
    2787       14040 :         else if( !pFrm->GetNext() && nBottom > pFrm->Frm().Bottom() )
    2788             :         {
    2789        1397 :             if( pFrm->IsCntntFrm() && ((SwCntntFrm*)pFrm)->HasFollow() )
    2790           6 :                 pFrm->InvalidateSize();
    2791             :             else
    2792        1391 :                 pFrm->InvalidateNextPos();
    2793             :         }
    2794       27954 :         pFrm = pFrm->GetNext();
    2795             :     }
    2796        6282 : }
    2797             : 
    2798       66018 : static void lcl_NotifyCntnt( const SdrObject *pThis, SwCntntFrm *pCnt,
    2799             :     const SwRect &rRect, const PrepareHint eHint )
    2800             : {
    2801       66018 :     if ( pCnt->IsTxtFrm() )
    2802             :     {
    2803       65619 :         SwRect aCntPrt( pCnt->Prt() );
    2804       65619 :         aCntPrt.Pos() += pCnt->Frm().Pos();
    2805       65619 :         if ( eHint == PREP_FLY_ATTR_CHG )
    2806             :         {
    2807             :             // #i35640# - use given rectangle <rRect> instead
    2808             :             // of current bound rectangle
    2809          38 :             if ( aCntPrt.IsOver( rRect ) )
    2810          20 :                 pCnt->Prepare( PREP_FLY_ATTR_CHG );
    2811             :         }
    2812             :         // #i23129# - only invalidate, if the text frame
    2813             :         // printing area overlaps with the given rectangle.
    2814       65581 :         else if ( aCntPrt.IsOver( rRect ) )
    2815        3644 :             pCnt->Prepare( eHint, (void*)&aCntPrt._Intersection( rRect ) );
    2816       65619 :         if ( pCnt->GetDrawObjs() )
    2817             :         {
    2818        7304 :             const SwSortedObjs &rObjs = *pCnt->GetDrawObjs();
    2819       83280 :             for ( sal_uInt16 i = 0; i < rObjs.Count(); ++i )
    2820             :             {
    2821       75976 :                 SwAnchoredObject* pObj = rObjs[i];
    2822       75976 :                 if ( pObj->ISA(SwFlyFrm) )
    2823             :                 {
    2824       35313 :                     SwFlyFrm *pFly = static_cast<SwFlyFrm*>(pObj);
    2825       35313 :                     if ( pFly->IsFlyInCntFrm() )
    2826             :                     {
    2827         135 :                         SwCntntFrm *pCntnt = pFly->ContainsCntnt();
    2828         410 :                         while ( pCntnt )
    2829             :                         {
    2830         140 :                             ::lcl_NotifyCntnt( pThis, pCntnt, rRect, eHint );
    2831         140 :                             pCntnt = pCntnt->GetNextCntntFrm();
    2832             :                         }
    2833             :                     }
    2834             :                 }
    2835             :             }
    2836             :         }
    2837             :     }
    2838       66018 : }
    2839             : 
    2840        4519 : void Notify_Background( const SdrObject* pObj,
    2841             :                         SwPageFrm* pPage,
    2842             :                         const SwRect& rRect,
    2843             :                         const PrepareHint eHint,
    2844             :                         const sal_Bool bInva )
    2845             : {
    2846             :     // If the frame was positioned correctly for the first time, do not inform the old area
    2847        4519 :     if ( eHint == PREP_FLY_LEAVE && rRect.Top() == FAR_AWAY )
    2848        4557 :          return;
    2849             : 
    2850             :     SwLayoutFrm* pArea;
    2851        4481 :     SwFlyFrm *pFlyFrm = 0;
    2852             :     SwFrm* pAnchor;
    2853        4481 :     if( pObj->ISA(SwVirtFlyDrawObj) )
    2854             :     {
    2855        2696 :         pFlyFrm = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm();
    2856        2696 :         pAnchor = pFlyFrm->AnchorFrm();
    2857             :     }
    2858             :     else
    2859             :     {
    2860        1785 :         pFlyFrm = NULL;
    2861             :         pAnchor = const_cast<SwFrm*>(
    2862        1785 :                     GetUserCall(pObj)->GetAnchoredObj( pObj )->GetAnchorFrm() );
    2863             :     }
    2864        4481 :     if( PREP_FLY_LEAVE != eHint && pAnchor->IsInFly() )
    2865          13 :         pArea = pAnchor->FindFlyFrm();
    2866             :     else
    2867        4468 :         pArea = pPage;
    2868        4481 :     SwCntntFrm *pCnt = 0;
    2869        4481 :     if ( pArea )
    2870             :     {
    2871        4481 :         if( PREP_FLY_ARRIVE != eHint )
    2872        2086 :             lcl_CheckFlowBack( pArea, rRect );
    2873             : 
    2874             :         // Only the Flys following this anchor are reacting. Thus, those do not
    2875             :         // need to be processed.
    2876             :         // An exception is LEAVE, since the Fly might come "from above".
    2877             :         // If the anchor is positioned on the previous page, the whole page
    2878             :         // needs to be processed (47722).
    2879             :         // OD 2004-05-13 #i28701# - If the wrapping style has to be considered
    2880             :         // on the object positioning, the complete area has to be processed,
    2881             :         // because content frames before the anchor frame also have to consider
    2882             :         // the object for the text wrapping.
    2883             :         // #i3317# - The complete area has always been
    2884             :         // processed.
    2885             :         {
    2886        4481 :             pCnt = pArea->ContainsCntnt();
    2887             :         }
    2888             :     }
    2889        4481 :     SwFrm *pLastTab = 0;
    2890             : 
    2891       62031 :     while ( pCnt && pArea && pArea->IsAnLower( pCnt ) )
    2892             :     {
    2893       53069 :         ::lcl_NotifyCntnt( pObj, pCnt, rRect, eHint );
    2894       53069 :         if ( pCnt->IsInTab() )
    2895             :         {
    2896       11840 :             SwLayoutFrm* pCell = pCnt->GetUpper();
    2897             :             // #i40606# - use <GetLastBoundRect()>
    2898             :             // instead of <GetCurrentBoundRect()>, because a recalculation
    2899             :             // of the bounding rectangle isn't intended here.
    2900       47981 :             if ( pCell->IsCellFrm() &&
    2901       58643 :                  ( pCell->Frm().IsOver( pObj->GetLastBoundRect() ) ||
    2902       11283 :                    pCell->Frm().IsOver( rRect ) ) )
    2903             :             {
    2904         621 :                 const SwFmtVertOrient &rOri = pCell->GetFmt()->GetVertOrient();
    2905         621 :                 if ( text::VertOrientation::NONE != rOri.GetVertOrient() )
    2906         188 :                     pCell->InvalidatePrt();
    2907             :             }
    2908       11840 :             SwTabFrm *pTab = pCnt->FindTabFrm();
    2909       11840 :             if ( pTab != pLastTab )
    2910             :             {
    2911         545 :                 pLastTab = pTab;
    2912             :                 // #i40606# - use <GetLastBoundRect()>
    2913             :                 // instead of <GetCurrentBoundRect()>, because a recalculation
    2914             :                 // of the bounding rectangle isn't intended here.
    2915         922 :                 if ( pTab->Frm().IsOver( pObj->GetLastBoundRect() ) ||
    2916         377 :                      pTab->Frm().IsOver( rRect ) )
    2917             :                 {
    2918         172 :                     if ( !pFlyFrm || !pFlyFrm->IsLowerOf( pTab ) )
    2919         138 :                         pTab->InvalidatePrt();
    2920             :                 }
    2921             :             }
    2922             :         }
    2923       53069 :         pCnt = pCnt->GetNextCntntFrm();
    2924             :     }
    2925             :     // #128702# - make code robust
    2926        4481 :     if ( pPage && pPage->GetSortedObjs() )
    2927             :     {
    2928        4466 :         pObj->GetOrdNum();
    2929        4466 :         const SwSortedObjs &rObjs = *pPage->GetSortedObjs();
    2930       81263 :         for ( sal_uInt16 i = 0; i < rObjs.Count(); ++i )
    2931             :         {
    2932       76797 :             SwAnchoredObject* pAnchoredObj = rObjs[i];
    2933       76797 :             if ( pAnchoredObj->ISA(SwFlyFrm) )
    2934             :             {
    2935       36013 :                 if( pAnchoredObj->GetDrawObj() == pObj )
    2936        2693 :                     continue;
    2937       33320 :                 SwFlyFrm *pFly = static_cast<SwFlyFrm*>(pAnchoredObj);
    2938       33320 :                 if ( pFly->Frm().Top() == FAR_AWAY )
    2939       17198 :                     continue;
    2940             : 
    2941       34794 :                 if ( !pFlyFrm ||
    2942       15164 :                         (!pFly->IsLowerOf( pFlyFrm ) &&
    2943        7580 :                         pFly->GetVirtDrawObj()->GetOrdNumDirect() < pObj->GetOrdNumDirect()))
    2944             :                 {
    2945       11088 :                     pCnt = pFly->ContainsCntnt();
    2946       34985 :                     while ( pCnt )
    2947             :                     {
    2948       12809 :                         ::lcl_NotifyCntnt( pObj, pCnt, rRect, eHint );
    2949       12809 :                         pCnt = pCnt->GetNextCntntFrm();
    2950             :                     }
    2951             :                 }
    2952       16122 :                 if( pFly->IsFlyLayFrm() )
    2953             :                 {
    2954        1527 :                     if( pFly->Lower() && pFly->Lower()->IsColumnFrm() &&
    2955           0 :                         pFly->Frm().Bottom() >= rRect.Top() &&
    2956           0 :                         pFly->Frm().Top() <= rRect.Bottom() &&
    2957         509 :                         pFly->Frm().Right() >= rRect.Left() &&
    2958           0 :                         pFly->Frm().Left() <= rRect.Right() )
    2959             :                      {
    2960           0 :                         pFly->InvalidateSize();
    2961             :                      }
    2962             :                 }
    2963             :                 // Flys above myself might sidestep if they have an automatic
    2964             :                 // alignment. This happens independently of my attributes since
    2965             :                 // this might have been changed as well.
    2966       46839 :                 else if ( pFly->IsFlyAtCntFrm() &&
    2967       15613 :                         pObj->GetOrdNumDirect() <
    2968       21317 :                         pFly->GetVirtDrawObj()->GetOrdNumDirect() &&
    2969       20257 :                         pFlyFrm && !pFly->IsLowerOf( pFlyFrm ) )
    2970             :                 {
    2971        4640 :                     const SwFmtHoriOrient &rH = pFly->GetFmt()->GetHoriOrient();
    2972        9312 :                     if ( text::HoriOrientation::NONE != rH.GetHoriOrient()  &&
    2973          44 :                             text::HoriOrientation::CENTER != rH.GetHoriOrient()  &&
    2974        4664 :                             ( !pFly->IsAutoPos() || text::RelOrientation::CHAR != rH.GetRelationOrient() ) &&
    2975          12 :                             (pFly->Frm().Bottom() >= rRect.Top() &&
    2976           0 :                             pFly->Frm().Top() <= rRect.Bottom()) )
    2977           0 :                         pFly->InvalidatePos();
    2978             :                 }
    2979             :             }
    2980             :         }
    2981             :     }
    2982        4481 :     if ( pFlyFrm && pAnchor->GetUpper() && pAnchor->IsInTab() )//MA_FLY_HEIGHT
    2983          35 :         pAnchor->GetUpper()->InvalidateSize();
    2984             : 
    2985             :     // #i82258# - make code robust
    2986        4481 :     SwViewShell* pSh = 0;
    2987        8962 :     if ( bInva && pPage &&
    2988        4481 :         0 != (pSh = pPage->getRootFrm()->GetCurrShell()) )
    2989             :     {
    2990        4365 :         pSh->InvalidateWindows( rRect );
    2991             :     }
    2992             : }
    2993             : 
    2994             : /// Provides the Upper of an anchor in paragraph-bound objects. If the latter
    2995             : /// is a chained border or a footnote, the "virtual" Upper might be returne.
    2996        6333 : const SwFrm* GetVirtualUpper( const SwFrm* pFrm, const Point& rPos )
    2997             : {
    2998        6333 :     if( pFrm->IsTxtFrm() )
    2999             :     {
    3000        6282 :         pFrm = pFrm->GetUpper();
    3001        6282 :         if( !pFrm->Frm().IsInside( rPos ) )
    3002             :         {
    3003        1302 :             if( pFrm->IsFtnFrm() )
    3004             :             {
    3005           0 :                 const SwFtnFrm* pTmp = ((SwFtnFrm*)pFrm)->GetFollow();
    3006           0 :                 while( pTmp )
    3007             :                 {
    3008           0 :                     if( pTmp->Frm().IsInside( rPos ) )
    3009           0 :                         return pTmp;
    3010           0 :                     pTmp = pTmp->GetFollow();
    3011             :                 }
    3012             :             }
    3013             :             else
    3014             :             {
    3015        1302 :                 SwFlyFrm* pTmp = (SwFlyFrm*)pFrm->FindFlyFrm();
    3016        2606 :                 while( pTmp )
    3017             :                 {
    3018           2 :                     if( pTmp->Frm().IsInside( rPos ) )
    3019           0 :                         return pTmp;
    3020           2 :                     pTmp = pTmp->GetNextLink();
    3021             :                 }
    3022             :             }
    3023             :         }
    3024             :     }
    3025        6333 :     return pFrm;
    3026             : }
    3027             : 
    3028        6245 : bool Is_Lower_Of( const SwFrm *pCurrFrm, const SdrObject* pObj )
    3029             : {
    3030        6245 :     Point aPos;
    3031             :     const SwFrm* pFrm;
    3032        6245 :     if( pObj->ISA(SwVirtFlyDrawObj) )
    3033             :     {
    3034        3395 :         const SwFlyFrm* pFly = ( (SwVirtFlyDrawObj*)pObj )->GetFlyFrm();
    3035        3395 :         pFrm = pFly->GetAnchorFrm();
    3036        3395 :         aPos = pFly->Frm().Pos();
    3037             :     }
    3038             :     else
    3039             :     {
    3040        2850 :         pFrm = ( (SwDrawContact*)GetUserCall(pObj) )->GetAnchorFrm(pObj);
    3041        2850 :         aPos = pObj->GetCurrentBoundRect().TopLeft();
    3042             :     }
    3043             :     OSL_ENSURE( pFrm, "8-( Fly is lost in Space." );
    3044        6245 :     pFrm = GetVirtualUpper( pFrm, aPos );
    3045       18698 :     do
    3046       18704 :     {   if ( pFrm == pCurrFrm )
    3047           6 :             return true;
    3048       18698 :         if( pFrm->IsFlyFrm() )
    3049             :         {
    3050           1 :             aPos = pFrm->Frm().Pos();
    3051           1 :             pFrm = GetVirtualUpper( ((const SwFlyFrm*)pFrm)->GetAnchorFrm(), aPos );
    3052             :         }
    3053             :         else
    3054       18697 :             pFrm = pFrm->GetUpper();
    3055             :     } while ( pFrm );
    3056        6239 :     return false;
    3057             : }
    3058             : 
    3059             : /// provides the area of a frame in that no Fly from another area can overlap
    3060       39103 : const SwFrm *FindKontext( const SwFrm *pFrm, sal_uInt16 nAdditionalKontextTyp )
    3061             : {
    3062             :     const sal_uInt16 nTyp = FRM_ROOT | FRM_HEADER   | FRM_FOOTER | FRM_FTNCONT  |
    3063             :                         FRM_FTN  | FRM_FLY      |
    3064             :                         FRM_TAB  | FRM_ROW      | FRM_CELL |
    3065       39103 :                         nAdditionalKontextTyp;
    3066       79140 :     do
    3067      118243 :     {   if ( pFrm->GetType() & nTyp )
    3068       39103 :             break;
    3069       79140 :         pFrm = pFrm->GetUpper();
    3070             :     } while( pFrm );
    3071       39103 :     return pFrm;
    3072             : }
    3073             : 
    3074        9545 : bool IsFrmInSameKontext( const SwFrm *pInnerFrm, const SwFrm *pFrm )
    3075             : {
    3076        9545 :     const SwFrm *pKontext = FindKontext( pInnerFrm, 0 );
    3077             : 
    3078             :     const sal_uInt16 nTyp = FRM_ROOT | FRM_HEADER   | FRM_FOOTER | FRM_FTNCONT  |
    3079             :                         FRM_FTN  | FRM_FLY      |
    3080        9545 :                         FRM_TAB  | FRM_ROW      | FRM_CELL;
    3081       37457 :     do
    3082       37821 :     {   if ( pFrm->GetType() & nTyp )
    3083             :         {
    3084        9599 :             if( pFrm == pKontext )
    3085         100 :                 return true;
    3086        9499 :             if( pFrm->IsCellFrm() )
    3087         264 :                 return false;
    3088             :         }
    3089       37457 :         if( pFrm->IsFlyFrm() )
    3090             :         {
    3091          54 :             Point aPos( pFrm->Frm().Pos() );
    3092          54 :             pFrm = GetVirtualUpper( ((const SwFlyFrm*)pFrm)->GetAnchorFrm(), aPos );
    3093             :         }
    3094             :         else
    3095       37403 :             pFrm = pFrm->GetUpper();
    3096             :     } while( pFrm );
    3097             : 
    3098        9181 :     return false;
    3099             : }
    3100             : 
    3101           0 : static SwTwips lcl_CalcCellRstHeight( SwLayoutFrm *pCell )
    3102             : {
    3103           0 :     if ( pCell->Lower()->IsCntntFrm() || pCell->Lower()->IsSctFrm() )
    3104             :     {
    3105           0 :         SwFrm *pLow = pCell->Lower();
    3106           0 :         long nHeight = 0, nFlyAdd = 0;
    3107           0 :         do
    3108             :         {
    3109           0 :             long nLow = pLow->Frm().Height();
    3110           0 :             if( pLow->IsTxtFrm() && ((SwTxtFrm*)pLow)->IsUndersized() )
    3111           0 :                 nLow += ((SwTxtFrm*)pLow)->GetParHeight()-pLow->Prt().Height();
    3112           0 :             else if( pLow->IsSctFrm() && ((SwSectionFrm*)pLow)->IsUndersized() )
    3113           0 :                 nLow += ((SwSectionFrm*)pLow)->Undersize();
    3114           0 :             nFlyAdd = std::max( 0L, nFlyAdd - nLow );
    3115           0 :             nFlyAdd = std::max( nFlyAdd, ::CalcHeightWidthFlys( pLow ) );
    3116           0 :             nHeight += nLow;
    3117           0 :             pLow = pLow->GetNext();
    3118             :         } while ( pLow );
    3119           0 :         if ( nFlyAdd )
    3120           0 :             nHeight += nFlyAdd;
    3121             : 
    3122             :         // The border cannot be calculated based on PrtArea and Frm, since both can be invalid.
    3123           0 :         SwBorderAttrAccess aAccess( SwFrm::GetCache(), pCell );
    3124           0 :         const SwBorderAttrs &rAttrs = *aAccess.Get();
    3125           0 :         nHeight += rAttrs.CalcTop() + rAttrs.CalcBottom();
    3126             : 
    3127           0 :         return pCell->Frm().Height() - nHeight;
    3128             :     }
    3129             :     else
    3130             :     {
    3131           0 :         long nRstHeight = 0;
    3132           0 :         SwFrm *pLow = pCell->Lower();
    3133           0 :         do
    3134           0 :         {   nRstHeight += ::CalcRowRstHeight( (SwLayoutFrm*)pLow );
    3135           0 :             pLow = pLow->GetNext();
    3136             : 
    3137             :         } while ( pLow );
    3138             : 
    3139           0 :         return nRstHeight;
    3140             :     }
    3141             : }
    3142             : 
    3143           0 : SwTwips CalcRowRstHeight( SwLayoutFrm *pRow )
    3144             : {
    3145           0 :     SwTwips nRstHeight = LONG_MAX;
    3146           0 :     SwLayoutFrm *pLow = (SwLayoutFrm*)pRow->Lower();
    3147           0 :     while ( pLow )
    3148             :     {
    3149           0 :         nRstHeight = std::min( nRstHeight, ::lcl_CalcCellRstHeight( pLow ) );
    3150           0 :         pLow = (SwLayoutFrm*)pLow->GetNext();
    3151             :     }
    3152           0 :     return nRstHeight;
    3153             : }
    3154             : 
    3155         819 : const SwFrm* FindPage( const SwRect &rRect, const SwFrm *pPage )
    3156             : {
    3157         819 :     if ( !rRect.IsOver( pPage->Frm() ) )
    3158             :     {
    3159         161 :         const SwRootFrm* pRootFrm = static_cast<const SwRootFrm*>(pPage->GetUpper());
    3160         161 :         const SwFrm* pTmpPage = pRootFrm ? pRootFrm->GetPageAtPos( rRect.TopLeft(), &rRect.SSize(), true ) : 0;
    3161         161 :         if ( pTmpPage )
    3162         161 :             pPage = pTmpPage;
    3163             :     }
    3164             : 
    3165         819 :     return pPage;
    3166             : }
    3167             : 
    3168      438329 : class SwFrmHolder : private SfxListener
    3169             : {
    3170             :     SwFrm* pFrm;
    3171             :     bool bSet;
    3172             :     virtual void Notify(  SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
    3173             : public:
    3174      438329 :     SwFrmHolder() : pFrm(0), bSet(false) {}
    3175             :     void SetFrm( SwFrm* pHold );
    3176        1012 :     SwFrm* GetFrm() { return pFrm; }
    3177             :     void Reset();
    3178      143885 :     bool IsSet() { return bSet; }
    3179             : };
    3180             : 
    3181        1012 : void SwFrmHolder::SetFrm( SwFrm* pHold )
    3182             : {
    3183        1012 :     bSet = true;
    3184        1012 :     pFrm = pHold;
    3185        1012 :     StartListening(*pHold);
    3186        1012 : }
    3187             : 
    3188      581202 : void SwFrmHolder::Reset()
    3189             : {
    3190      581202 :     if (pFrm)
    3191           0 :         EndListening(*pFrm);
    3192      581202 :     bSet = false;
    3193      581202 :     pFrm = 0;
    3194      581202 : }
    3195             : 
    3196           0 : void SwFrmHolder::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
    3197             : {
    3198           0 :     if ( rHint.IsA(TYPE(SfxSimpleHint)) )
    3199             :     {
    3200           0 :         if ( ( (SfxSimpleHint&) rHint ).GetId() == SFX_HINT_DYING && &rBC == pFrm )
    3201           0 :             pFrm = 0;
    3202             :     }
    3203           0 : }
    3204             : 
    3205      438329 : SwFrm* GetFrmOfModify( const SwRootFrm* pLayout, SwModify const& rMod, sal_uInt16 const nFrmType,
    3206             :         const Point* pPoint, const SwPosition *pPos, const sal_Bool bCalcFrm )
    3207             : {
    3208      438329 :     SwFrm *pMinFrm = 0, *pTmpFrm;
    3209      438329 :     SwFrmHolder aHolder;
    3210      438329 :     SwRect aCalcRect;
    3211      438329 :     bool bClientIterChanged = false;
    3212             : 
    3213      876658 :     SwIterator<SwFrm,SwModify> aIter( rMod );
    3214      438329 :     do {
    3215      438329 :         pMinFrm = 0;
    3216      438329 :         aHolder.Reset();
    3217      438329 :         sal_uInt64 nMinDist = 0;
    3218      438329 :         bClientIterChanged = false;
    3219             : 
    3220      533120 :         for( pTmpFrm = aIter.First(); pTmpFrm; pTmpFrm = aIter.Next() )
    3221             :         {
    3222     1296174 :             if( pTmpFrm->GetType() & nFrmType &&
    3223     1695397 :                 ( !pLayout || pLayout == pTmpFrm->getRootFrm() ) &&
    3224      862924 :                 (!pTmpFrm->IsFlowFrm() ||
    3225      430866 :                  !SwFlowFrm::CastFlowFrm( pTmpFrm )->IsFollow() ))
    3226             :             {
    3227      401324 :                 if( pPoint )
    3228             :                 {
    3229             :                     // watch for Frm being deleted
    3230      143885 :                     if ( pMinFrm )
    3231        1012 :                         aHolder.SetFrm( pMinFrm );
    3232             :                     else
    3233      142873 :                         aHolder.Reset();
    3234             : 
    3235      143885 :                     if( bCalcFrm )
    3236             :                     {
    3237             :                         // - format parent Writer
    3238             :                         // fly frame, if it isn't been formatted yet.
    3239             :                         // Note: The Writer fly frame could be the frame itself.
    3240        4789 :                         SwFlyFrm* pFlyFrm( pTmpFrm->FindFlyFrm() );
    3241        4789 :                         if ( pFlyFrm &&
    3242        4789 :                              pFlyFrm->Frm().Pos().X() == FAR_AWAY &&
    3243           0 :                              pFlyFrm->Frm().Pos().Y() == FAR_AWAY )
    3244             :                         {
    3245           0 :                             SwObjectFormatter::FormatObj( *pFlyFrm );
    3246             :                         }
    3247        4789 :                         pTmpFrm->Calc();
    3248             :                     }
    3249             : 
    3250             :                     // #127369#
    3251             :                     // aIter.IsChanged checks if the current pTmpFrm has been deleted while
    3252             :                     // it is the current iterator
    3253             :                     // FrmHolder watches for deletion of the current pMinFrm
    3254      143885 :                     if( aIter.IsChanged() || ( aHolder.IsSet() && !aHolder.GetFrm() ) )
    3255             :                     {
    3256             :                         // restart iteration
    3257           0 :                         bClientIterChanged = true;
    3258       79828 :                         break;
    3259             :                     }
    3260             : 
    3261             :                     // for Flys go via the parent if the Fly is not yet "formatted"
    3262      283931 :                     if( !bCalcFrm && nFrmType & FRM_FLY &&
    3263        1846 :                         ((SwFlyFrm*)pTmpFrm)->GetAnchorFrm() &&
    3264      144781 :                         FAR_AWAY == pTmpFrm->Frm().Pos().getX() &&
    3265           0 :                         FAR_AWAY == pTmpFrm->Frm().Pos().getY() )
    3266           0 :                         aCalcRect = ((SwFlyFrm*)pTmpFrm)->GetAnchorFrm()->Frm();
    3267             :                     else
    3268      143885 :                         aCalcRect = pTmpFrm->Frm();
    3269             : 
    3270      143885 :                     if ( aCalcRect.IsInside( *pPoint ) )
    3271             :                     {
    3272       79828 :                         pMinFrm = pTmpFrm;
    3273       79828 :                         break;
    3274             :                     }
    3275             : 
    3276             :                     // Point not in rectangle. Compare distances:
    3277       64057 :                     const Point aCalcRectCenter = aCalcRect.Center();
    3278       64057 :                     const Point aDiff = aCalcRectCenter - *pPoint;
    3279       64057 :                     const sal_uInt64 nCurrentDist = aDiff.getX() * aDiff.getX() + aDiff.getY() * aDiff.getY(); // opt: no sqrt
    3280       64057 :                     if ( !pMinFrm || nCurrentDist < nMinDist )
    3281             :                     {
    3282       63108 :                         pMinFrm = pTmpFrm;
    3283       63108 :                         nMinDist = nCurrentDist;
    3284             :                     }
    3285             :                 }
    3286             :                 else
    3287             :                 {
    3288             :                     // if no pPoint is provided, take the first one
    3289      257439 :                     pMinFrm = pTmpFrm;
    3290      257439 :                     break;
    3291             :                 }
    3292             :             }
    3293             :         }
    3294             :     } while( bClientIterChanged );
    3295             : 
    3296      438329 :     if( pPos && pMinFrm && pMinFrm->IsTxtFrm() )
    3297      141285 :         return ((SwTxtFrm*)pMinFrm)->GetFrmAtPos( *pPos );
    3298             : 
    3299      735373 :     return pMinFrm;
    3300             : }
    3301             : 
    3302       60263 : bool IsExtraData( const SwDoc *pDoc )
    3303             : {
    3304       60263 :     const SwLineNumberInfo &rInf = pDoc->GetLineNumberInfo();
    3305      120401 :     return rInf.IsPaintLineNumbers() ||
    3306      121218 :            rInf.IsCountInFlys() ||
    3307      120276 :            ((sal_Int16)SW_MOD()->GetRedlineMarkPos() != text::HoriOrientation::NONE &&
    3308      120401 :             !pDoc->GetRedlineTbl().empty());
    3309             : }
    3310             : 
    3311             : // OD 22.09.2003 #110978#
    3312           9 : const SwRect SwPageFrm::PrtWithoutHeaderAndFooter() const
    3313             : {
    3314           9 :     SwRect aPrtWithoutHeaderFooter( Prt() );
    3315           9 :     aPrtWithoutHeaderFooter.Pos() += Frm().Pos();
    3316             : 
    3317           9 :     const SwFrm* pLowerFrm = Lower();
    3318          27 :     while ( pLowerFrm )
    3319             :     {
    3320             :         // Note: independent on text direction page header and page footer are
    3321             :         //       always at top respectively at bottom of the page frame.
    3322           9 :         if ( pLowerFrm->IsHeaderFrm() )
    3323             :         {
    3324           0 :             aPrtWithoutHeaderFooter.Top( aPrtWithoutHeaderFooter.Top() +
    3325           0 :                                          pLowerFrm->Frm().Height() );
    3326             :         }
    3327           9 :         if ( pLowerFrm->IsFooterFrm() )
    3328             :         {
    3329           0 :             aPrtWithoutHeaderFooter.Bottom( aPrtWithoutHeaderFooter.Bottom() -
    3330           0 :                                             pLowerFrm->Frm().Height() );
    3331             :         }
    3332             : 
    3333           9 :         pLowerFrm = pLowerFrm->GetNext();
    3334             :     }
    3335             : 
    3336           9 :     return aPrtWithoutHeaderFooter;
    3337             : }
    3338             : 
    3339             : /** method to determine the spacing values of a frame
    3340             : 
    3341             :     OD 2004-03-10 #i28701#
    3342             :     OD 2009-08-28 #i102458#
    3343             :     Add output parameter <obIsLineSpacingProportional>
    3344             : */
    3345       33317 : void GetSpacingValuesOfFrm( const SwFrm& rFrm,
    3346             :                             SwTwips& onLowerSpacing,
    3347             :                             SwTwips& onLineSpacing,
    3348             :                             bool& obIsLineSpacingProportional )
    3349             : {
    3350       33317 :     if ( !rFrm.IsFlowFrm() )
    3351             :     {
    3352           0 :         onLowerSpacing = 0;
    3353           0 :         onLineSpacing = 0;
    3354             :     }
    3355             :     else
    3356             :     {
    3357       33317 :         const SvxULSpaceItem& rULSpace = rFrm.GetAttrSet()->GetULSpace();
    3358       33317 :         onLowerSpacing = rULSpace.GetLower();
    3359             : 
    3360       33317 :         onLineSpacing = 0;
    3361       33317 :         obIsLineSpacingProportional = false;
    3362       33317 :         if ( rFrm.IsTxtFrm() )
    3363             :         {
    3364       32240 :             onLineSpacing = static_cast<const SwTxtFrm&>(rFrm).GetLineSpace();
    3365             :             obIsLineSpacingProportional =
    3366       43544 :                 onLineSpacing != 0 &&
    3367       43544 :                 static_cast<const SwTxtFrm&>(rFrm).GetLineSpace( true ) == 0;
    3368             :         }
    3369             : 
    3370             :         OSL_ENSURE( onLowerSpacing >= 0 && onLineSpacing >= 0,
    3371             :                 "<GetSpacingValuesOfFrm(..)> - spacing values aren't positive!" );
    3372             :     }
    3373       33317 : }
    3374             : 
    3375             : /// get the content of the table cell, skipping content from nested tables
    3376           1 : const SwCntntFrm* GetCellCntnt( const SwLayoutFrm& rCell )
    3377             : {
    3378           1 :     const SwCntntFrm* pCntnt = rCell.ContainsCntnt();
    3379           1 :     const SwTabFrm* pTab = rCell.FindTabFrm();
    3380             : 
    3381           2 :     while ( pCntnt && rCell.IsAnLower( pCntnt ) )
    3382             :     {
    3383           1 :         const SwTabFrm* pTmpTab = pCntnt->FindTabFrm();
    3384           1 :         if ( pTmpTab != pTab )
    3385             :         {
    3386           0 :             pCntnt = pTmpTab->FindLastCntnt();
    3387           0 :             if ( pCntnt )
    3388             : 
    3389           0 :                 pCntnt = pCntnt->FindNextCnt();
    3390             : 
    3391             :         }
    3392             :         else
    3393           1 :             break;
    3394             :     }
    3395           1 :     return pCntnt;
    3396             : }
    3397             : 
    3398             : /// Can be used to check if a frame has been deleted
    3399           1 : bool SwDeletionChecker::HasBeenDeleted()
    3400             : {
    3401           1 :     if ( !mpFrm || !mpRegIn )
    3402           0 :         return false;
    3403             : 
    3404           1 :     SwIterator<SwFrm,SwModify> aIter(*mpRegIn);
    3405           1 :     SwFrm* pLast = aIter.First();
    3406           2 :     while ( pLast )
    3407             :     {
    3408           1 :         if ( pLast == mpFrm )
    3409           1 :             return false;
    3410           0 :         pLast = aIter.Next();
    3411             :     }
    3412             : 
    3413           0 :     return true;
    3414             : }
    3415             : 
    3416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10