LCOV - code coverage report
Current view: top level - sw/source/core/layout - fly.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1002 1360 73.7 %
Date: 2015-06-13 12:38:46 Functions: 63 69 91.3 %
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 <svl/itemiter.hxx>
      21             : #include <svtools/imap.hxx>
      22             : #include <tools/helpers.hxx>
      23             : #include <editeng/protitem.hxx>
      24             : #include <editeng/opaqitem.hxx>
      25             : #include <editeng/ulspitem.hxx>
      26             : #include <editeng/frmdiritem.hxx>
      27             : #include <drawdoc.hxx>
      28             : #include <fmtfsize.hxx>
      29             : #include <fmtclds.hxx>
      30             : #include <fmtcntnt.hxx>
      31             : #include <fmturl.hxx>
      32             : #include <fmtsrnd.hxx>
      33             : #include <fmtornt.hxx>
      34             : #include <fmtcnct.hxx>
      35             : #include <layhelp.hxx>
      36             : #include <ndgrf.hxx>
      37             : #include <tolayoutanchoredobjectposition.hxx>
      38             : #include <fmtfollowtextflow.hxx>
      39             : #include <sortedobjs.hxx>
      40             : #include <objectformatter.hxx>
      41             : #include <ndole.hxx>
      42             : #include <swtable.hxx>
      43             : #include <svx/svdpage.hxx>
      44             : #include <svx/svdoashp.hxx>
      45             : #include "layouter.hxx"
      46             : #include "pagefrm.hxx"
      47             : #include "rootfrm.hxx"
      48             : #include "viewimp.hxx"
      49             : #include "viewopt.hxx"
      50             : #include "dcontact.hxx"
      51             : #include "dflyobj.hxx"
      52             : #include "dview.hxx"
      53             : #include "frmtool.hxx"
      54             : #include "hints.hxx"
      55             : #include "tabfrm.hxx"
      56             : #include "txtfrm.hxx"
      57             : #include "notxtfrm.hxx"
      58             : #include "flyfrms.hxx"
      59             : #include "sectfrm.hxx"
      60             : #include <vcl/svapp.hxx>
      61             : #include <calbck.hxx>
      62             : #include <IDocumentSettingAccess.hxx>
      63             : #include <IDocumentLayoutAccess.hxx>
      64             : #include <textboxhelper.hxx>
      65             : #include <txtfly.hxx>
      66             : 
      67             : using namespace ::com::sun::star;
      68             : 
      69    18380734 : TYPEINIT2(SwFlyFrm,SwLayoutFrm,SwAnchoredObject);
      70             : 
      71        2107 : SwFlyFrm::SwFlyFrm( SwFlyFrameFormat *pFormat, SwFrm* pSib, SwFrm *pAnch ) :
      72             :     SwLayoutFrm( pFormat, pSib ),
      73             :     SwAnchoredObject(), // #i26791#
      74             :     pPrevLink( 0 ),
      75             :     pNextLink( 0 ),
      76             :     bInCnt( false ),
      77             :     bAtCnt( false ),
      78             :     bLayout( false ),
      79             :     bAutoPosition( false ),
      80             :     bNoShrink( false ),
      81             :     bLockDeleteContent( false ),
      82        2107 :     m_bValidContentPos( false )
      83             : {
      84        2107 :     mnFrmType = FRM_FLY;
      85             : 
      86        2107 :     bInvalid = bNotifyBack = true;
      87             :     bLocked  = bMinHeight =
      88        2107 :     bHeightClipped = bWidthClipped = bFormatHeightOnly = false;
      89             : 
      90             :     // Size setting: Fixed size is always the width
      91        2107 :     const SwFormatFrmSize &rFrmSize = pFormat->GetFrmSize();
      92             :     const sal_uInt16 nDir =
      93        2107 :         static_cast<const SvxFrameDirectionItem&>(pFormat->GetFormatAttr( RES_FRAMEDIR )).GetValue();
      94        2107 :     if( FRMDIR_ENVIRONMENT == nDir )
      95             :     {
      96        2060 :         mbDerivedVert = true;
      97        2060 :         mbDerivedR2L = true;
      98             :     }
      99             :     else
     100             :     {
     101          47 :         mbInvalidVert = false;
     102          47 :         mbDerivedVert = false;
     103          47 :         mbDerivedR2L = false;
     104          47 :         if( FRMDIR_HORI_LEFT_TOP == nDir || FRMDIR_HORI_RIGHT_TOP == nDir )
     105             :         {
     106          46 :             mbVertLR = false;
     107          46 :             mbVertical = false;
     108             :         }
     109             :         else
     110             :         {
     111           1 :             const SwViewShell *pSh = getRootFrm() ? getRootFrm()->GetCurrShell() : 0;
     112           1 :             if( pSh && pSh->GetViewOptions()->getBrowseMode() )
     113             :             {
     114           0 :                 mbVertLR = false;
     115           0 :                 mbVertical = false;
     116             :             }
     117             :             else
     118             :             {
     119           1 :                 mbVertical = true;
     120             : 
     121           1 :                 if ( FRMDIR_VERT_TOP_LEFT == nDir )
     122           0 :                     mbVertLR = true;
     123             :                 else
     124           1 :                     mbVertLR = false;
     125             :             }
     126             :         }
     127             : 
     128          47 :         mbInvalidR2L = false;
     129          47 :         if( FRMDIR_HORI_RIGHT_TOP == nDir )
     130           0 :             mbRightToLeft = true;
     131             :         else
     132          47 :             mbRightToLeft = false;
     133             :     }
     134             : 
     135        2107 :     Frm().Width( rFrmSize.GetWidth() );
     136        2107 :     Frm().Height( rFrmSize.GetHeightSizeType() == ATT_VAR_SIZE ? MINFLY : rFrmSize.GetHeight() );
     137             : 
     138             :     // Fixed or variable Height?
     139        2107 :     if ( rFrmSize.GetHeightSizeType() == ATT_MIN_SIZE )
     140         120 :         bMinHeight = true;
     141        1987 :     else if ( rFrmSize.GetHeightSizeType() == ATT_FIX_SIZE )
     142         772 :         mbFixSize = true;
     143             : 
     144             :     // insert columns, if necessary
     145        2107 :     InsertColumns();
     146             : 
     147             :     // First the Init, then the Content:
     148             :     // This is due to the fact that the Content may have Objects/Frames,
     149             :     // which are then registered
     150        2107 :     InitDrawObj( false );
     151             : 
     152        2107 :     Chain( pAnch );
     153             : 
     154        2107 :     InsertCnt();
     155             : 
     156             :     // Put it somewhere outside so that out document is not formatted unnecessarily often
     157        2107 :     Frm().Pos().setX(FAR_AWAY);
     158        2107 :     Frm().Pos().setY(FAR_AWAY);
     159        2107 : }
     160             : 
     161        2107 : void SwFlyFrm::Chain( SwFrm* _pAnch )
     162             : {
     163             :     // Connect to chain neighboors.
     164             :     // No problem, if a neighboor doesn't exist - the construction of the
     165             :     // neighboor will make the connection
     166        2107 :     const SwFormatChain& rChain = GetFormat()->GetChain();
     167        2107 :     if ( rChain.GetPrev() || rChain.GetNext() )
     168             :     {
     169           8 :         if ( rChain.GetNext() )
     170             :         {
     171           4 :             SwFlyFrm* pFollow = FindChainNeighbour( *rChain.GetNext(), _pAnch );
     172           4 :             if ( pFollow )
     173             :             {
     174             :                 OSL_ENSURE( !pFollow->GetPrevLink(), "wrong chain detected" );
     175           2 :                 if ( !pFollow->GetPrevLink() )
     176           2 :                     SwFlyFrm::ChainFrames( this, pFollow );
     177             :             }
     178             :         }
     179           8 :         if ( rChain.GetPrev() )
     180             :         {
     181           4 :             SwFlyFrm *pMaster = FindChainNeighbour( *rChain.GetPrev(), _pAnch );
     182           4 :             if ( pMaster )
     183             :             {
     184             :                 OSL_ENSURE( !pMaster->GetNextLink(), "wrong chain detected" );
     185           2 :                 if ( !pMaster->GetNextLink() )
     186           2 :                     SwFlyFrm::ChainFrames( pMaster, this );
     187             :             }
     188             :         }
     189             :     }
     190        2107 : }
     191             : 
     192        2107 : void SwFlyFrm::InsertCnt()
     193             : {
     194        2107 :     if ( !GetPrevLink() )
     195             :     {
     196        2105 :         const SwFormatContent& rContent = GetFormat()->GetContent();
     197             :         OSL_ENSURE( rContent.GetContentIdx(), ":-( no content prepared." );
     198        2105 :         sal_uLong nIndex = rContent.GetContentIdx()->GetIndex();
     199             :         // Lower() means SwColumnFrm; the Content then needs to be inserted into the (Column)BodyFrm
     200        2105 :         ::_InsertCnt( Lower() ? static_cast<SwLayoutFrm*>(static_cast<SwLayoutFrm*>(Lower())->Lower()) : static_cast<SwLayoutFrm*>(this),
     201        4210 :                       GetFormat()->GetDoc(), nIndex );
     202             : 
     203             :         // NoText always have a fixed height.
     204        2105 :         if ( Lower() && Lower()->IsNoTextFrm() )
     205             :         {
     206        1029 :             mbFixSize = true;
     207        1029 :             bMinHeight = false;
     208             :         }
     209             :     }
     210        2107 : }
     211             : 
     212        2107 : void SwFlyFrm::InsertColumns()
     213             : {
     214             :     // #i97379#
     215             :     // Check, if column are allowed.
     216             :     // Columns are not allowed for fly frames, which represent graphics or embedded objects.
     217        2107 :     const SwFormatContent& rContent = GetFormat()->GetContent();
     218             :     OSL_ENSURE( rContent.GetContentIdx(), "<SwFlyFrm::InsertColumns()> - no content prepared." );
     219        2107 :     SwNodeIndex aFirstContent( *(rContent.GetContentIdx()), 1 );
     220        2107 :     if ( aFirstContent.GetNode().IsNoTextNode() )
     221             :     {
     222        3136 :         return;
     223             :     }
     224             : 
     225        1078 :     const SwFormatCol &rCol = GetFormat()->GetCol();
     226        1078 :     if ( rCol.GetNumCols() > 1 )
     227             :     {
     228             :         // Start off PrtArea to be as large as Frm, so that we can put in the columns
     229             :         // properly. It'll adjust later on.
     230           0 :         Prt().Width( Frm().Width() );
     231           0 :         Prt().Height( Frm().Height() );
     232           0 :         const SwFormatCol aOld; // ChgColumns() also needs an old value passed
     233           0 :         ChgColumns( aOld, rCol );
     234        1078 :     }
     235             : }
     236             : 
     237        2107 : void SwFlyFrm::DestroyImpl()
     238             : {
     239             :     // Accessible objects for fly frames will be destroyed in this destructor.
     240             :     // For frames bound as char or frames that don't have an anchor we have
     241             :     // to do that ourselves. For any other frame the call RemoveFly at the
     242             :     // anchor will do that.
     243        2107 :     if( IsAccessibleFrm() && GetFormat() && (IsFlyInCntFrm() || !GetAnchorFrm()) )
     244             :     {
     245         774 :         SwRootFrm *pRootFrm = getRootFrm();
     246         774 :         if( pRootFrm && pRootFrm->IsAnyShellAccessible() )
     247             :         {
     248           0 :             SwViewShell *pVSh = pRootFrm->GetCurrShell();
     249           0 :             if( pVSh && pVSh->Imp() )
     250             :             {
     251             :                 // Lowers aren't disposed already, so we have to do a recursive
     252             :                 // dispose
     253           0 :                 pVSh->Imp()->DisposeAccessibleFrm( this, true );
     254             :             }
     255             :         }
     256             :     }
     257             : 
     258        2107 :     if( GetFormat() && !GetFormat()->GetDoc()->IsInDtor() )
     259             :     {
     260             :         // OD 2004-01-19 #110582#
     261        2107 :         Unchain();
     262             : 
     263             :         // OD 2004-01-19 #110582#
     264        2107 :         DeleteCnt();
     265             : 
     266        2107 :         if ( GetAnchorFrm() )
     267        2107 :             AnchorFrm()->RemoveFly( this );
     268             :     }
     269             : 
     270        2107 :     FinitDrawObj();
     271             : 
     272        2107 :     SwLayoutFrm::DestroyImpl();
     273        2107 : }
     274             : 
     275        2107 : SwFlyFrm::~SwFlyFrm()
     276             : {
     277        2107 : }
     278             : 
     279           0 : const IDocumentDrawModelAccess* SwFlyFrm::getIDocumentDrawModelAccess()
     280             : {
     281           0 :     return GetFormat()->getIDocumentDrawModelAccess();
     282             : }
     283             : 
     284             : // OD 2004-01-19 #110582#
     285        2107 : void SwFlyFrm::Unchain()
     286             : {
     287        2107 :     if ( GetPrevLink() )
     288           2 :         UnchainFrames( GetPrevLink(), this );
     289        2107 :     if ( GetNextLink() )
     290           2 :         UnchainFrames( this, GetNextLink() );
     291        2107 : }
     292             : 
     293             : // OD 2004-01-19 #110582#
     294        2107 : void SwFlyFrm::DeleteCnt()
     295             : {
     296             :     // #110582#-2
     297        2107 :     if ( IsLockDeleteContent() )
     298        2107 :         return;
     299             : 
     300        2107 :     SwFrm* pFrm = m_pLower;
     301        6799 :     while ( pFrm )
     302             :     {
     303        5356 :         while ( pFrm->GetDrawObjs() && pFrm->GetDrawObjs()->size() )
     304             :         {
     305         186 :             SwAnchoredObject *pAnchoredObj = (*pFrm->GetDrawObjs())[0];
     306         186 :             if ( pAnchoredObj->ISA(SwFlyFrm) )
     307             :             {
     308         169 :                 SwFrm::DestroyFrm(static_cast<SwFlyFrm*>(pAnchoredObj));
     309             :             }
     310          17 :             else if ( pAnchoredObj->ISA(SwAnchoredDrawObject) )
     311             :             {
     312             :                 // OD 23.06.2003 #108784# - consider 'virtual' drawing objects
     313          17 :                 SdrObject* pObj = pAnchoredObj->DrawObj();
     314          17 :                 if ( pObj->ISA(SwDrawVirtObj) )
     315             :                 {
     316           0 :                     SwDrawVirtObj* pDrawVirtObj = static_cast<SwDrawVirtObj*>(pObj);
     317           0 :                     pDrawVirtObj->RemoveFromWriterLayout();
     318           0 :                     pDrawVirtObj->RemoveFromDrawingPage();
     319             :                 }
     320             :                 else
     321             :                 {
     322             :                     SwDrawContact* pContact =
     323          17 :                             static_cast<SwDrawContact*>(::GetUserCall( pObj ));
     324          17 :                     if ( pContact )
     325             :                     {
     326          17 :                         pContact->DisconnectFromLayout();
     327             :                     }
     328             :                 }
     329             :             }
     330             :         }
     331             : 
     332        2585 :         pFrm->RemoveFromLayout();
     333        2585 :         SwFrm::DestroyFrm(pFrm);
     334        2585 :         pFrm = m_pLower;
     335             :     }
     336             : 
     337        2107 :     InvalidatePage();
     338             : }
     339             : 
     340        1066 : sal_uInt32 SwFlyFrm::_GetOrdNumForNewRef( const SwFlyDrawContact* pContact )
     341             : {
     342        1066 :     sal_uInt32 nOrdNum( 0L );
     343             : 
     344             :     // search for another Writer fly frame registered at same frame format
     345        1066 :     SwIterator<SwFlyFrm,SwFormat> aIter( *pContact->GetFormat() );
     346        1066 :     const SwFlyFrm* pFlyFrm( 0L );
     347        2127 :     for ( pFlyFrm = aIter.First(); pFlyFrm; pFlyFrm = aIter.Next() )
     348             :     {
     349        1458 :         if ( pFlyFrm != this )
     350             :         {
     351         397 :             break;
     352             :         }
     353             :     }
     354             : 
     355        1066 :     if ( pFlyFrm )
     356             :     {
     357             :         // another Writer fly frame found. Take its order number
     358         397 :         nOrdNum = pFlyFrm->GetVirtDrawObj()->GetOrdNum();
     359             :     }
     360             :     else
     361             :     {
     362             :         // no other Writer fly frame found. Take order number of 'master' object
     363             :         // #i35748# - use method <GetOrdNumDirect()> instead
     364             :         // of method <GetOrdNum()> to avoid a recalculation of the order number,
     365             :         // which isn't intended.
     366         669 :         nOrdNum = pContact->GetMaster()->GetOrdNumDirect();
     367             :     }
     368             : 
     369        1066 :     return nOrdNum;
     370             : }
     371             : 
     372        2107 : SwVirtFlyDrawObj* SwFlyFrm::CreateNewRef( SwFlyDrawContact *pContact )
     373             : {
     374        2107 :     SwVirtFlyDrawObj *pDrawObj = new SwVirtFlyDrawObj( *pContact->GetMaster(), this );
     375        2107 :     pDrawObj->SetModel( pContact->GetMaster()->GetModel() );
     376        2107 :     pDrawObj->SetUserCall( pContact );
     377             : 
     378             :     // The Reader creates the Masters and inserts them into the Page in
     379             :     // order to transport the z-order.
     380             :     // After creating the first Reference the Masters are removed from the
     381             :     // List and are not important anymore.
     382        2107 :     SdrPage* pPg( 0L );
     383        2107 :     if ( 0 != ( pPg = pContact->GetMaster()->GetPage() ) )
     384             :     {
     385        1041 :         const size_t nOrdNum = pContact->GetMaster()->GetOrdNum();
     386        1041 :         pPg->ReplaceObject( pDrawObj, nOrdNum );
     387             :     }
     388             :     // #i27030# - insert new <SwVirtFlyDrawObj> instance
     389             :     // into drawing page with correct order number
     390             :     else
     391             :     {
     392        1066 :         pContact->GetFormat()->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage( 0 )->
     393        1066 :                         InsertObject( pDrawObj, _GetOrdNumForNewRef( pContact ) );
     394             :     }
     395             :     // #i38889# - assure, that new <SwVirtFlyDrawObj> instance
     396             :     // is in a visible layer.
     397        2107 :     pContact->MoveObjToVisibleLayer( pDrawObj );
     398        2107 :     return pDrawObj;
     399             : }
     400             : 
     401        2107 : void SwFlyFrm::InitDrawObj( bool bNotify )
     402             : {
     403             :     // Find ContactObject from the Format. If there's already one, we just
     404             :     // need to create a new Ref, else we create the Contact now.
     405             : 
     406        2107 :     IDocumentDrawModelAccess* pIDDMA = GetFormat()->getIDocumentDrawModelAccess();
     407        2107 :     SwFlyDrawContact *pContact = SwIterator<SwFlyDrawContact,SwFormat>( *GetFormat() ).First();
     408        2107 :     if ( !pContact )
     409             :     {
     410             :         // #i52858# - method name changed
     411         520 :         pContact = new SwFlyDrawContact( GetFormat(),
     412         520 :                                           pIDDMA->GetOrCreateDrawModel() );
     413             :     }
     414             :     OSL_ENSURE( pContact, "InitDrawObj failed" );
     415             :     // OD 2004-03-22 #i26791#
     416        2107 :     SetDrawObj( *(CreateNewRef( pContact )) );
     417             : 
     418             :     // Set the right Layer
     419             :     // OD 2004-01-19 #110582#
     420        2107 :     SdrLayerID nHeavenId = pIDDMA->GetHeavenId();
     421        2107 :     SdrLayerID nHellId = pIDDMA->GetHellId();
     422             :     // OD 2004-03-22 #i26791#
     423        4214 :     GetVirtDrawObj()->SetLayer( GetFormat()->GetOpaque().GetValue()
     424             :                                 ? nHeavenId
     425        4214 :                                 : nHellId );
     426        2107 :     if ( bNotify )
     427           0 :         NotifyDrawObj();
     428        2107 : }
     429             : 
     430        2107 : void SwFlyFrm::FinitDrawObj()
     431             : {
     432        2107 :     if ( !GetVirtDrawObj() )
     433        2107 :         return;
     434             : 
     435             :     // Deregister from SdrPageViews if the Objects is still selected there.
     436        2107 :     if ( !GetFormat()->GetDoc()->IsInDtor() )
     437             :     {
     438        2107 :         SwViewShell *p1St = getRootFrm()->GetCurrShell();
     439        2107 :         if ( p1St )
     440             :         {
     441         146 :             for(SwViewShell& rCurrentShell : p1St->GetRingContainer())
     442             :             {   // At the moment the Drawing can do just do an Unmark on everything,
     443             :                 // as the Object was already removed
     444          73 :                 if( rCurrentShell.HasDrawView() )
     445          73 :                     rCurrentShell.Imp()->GetDrawView()->UnmarkAll();
     446             :             }
     447             :         }
     448             :     }
     449             : 
     450             :     // Take VirtObject to the grave.
     451             :     // If the last VirtObject is destroyed, the DrawObject and the DrawContact
     452             :     // also need to be destroyed.
     453        2107 :     SwFlyDrawContact *pMyContact = 0;
     454        2107 :     if ( GetFormat() )
     455             :     {
     456        2107 :         bool bContinue = true;
     457        2107 :         SwIterator<SwFrm,SwFormat> aFrmIter( *GetFormat() );
     458        3869 :         for ( SwFrm* pFrm = aFrmIter.First(); pFrm; pFrm = aFrmIter.Next() )
     459        2159 :             if ( pFrm != this )
     460             :             {
     461             :                 // don't delete Contact if there is still a Frm
     462         397 :                 bContinue = false;
     463         397 :                 break;
     464             :             }
     465             : 
     466        2107 :         if ( bContinue )
     467             :             // no Frm left, find Contact object to destroy
     468        1710 :             pMyContact = SwIterator<SwFlyDrawContact,SwFormat>( *GetFormat() ).First();
     469             :     }
     470             : 
     471             :     // OD, OS 2004-03-31 #116203# - clear user call of Writer fly frame 'master'
     472             :     // <SdrObject> to assure, that a <SwXFrame::dispose()> doesn't delete the
     473             :     // Writer fly frame again.
     474        2107 :     if ( pMyContact )
     475             :     {
     476        1710 :         pMyContact->GetMaster()->SetUserCall( 0 );
     477             :     }
     478        2107 :     GetVirtDrawObj()->SetUserCall( 0 ); // Else calls delete of the ContactObj
     479        2107 :     delete GetVirtDrawObj();            // Deregisters itself at the Master
     480        2107 :     delete pMyContact;                  // Destroys the Master itself
     481             : }
     482             : 
     483           4 : void SwFlyFrm::ChainFrames( SwFlyFrm *pMaster, SwFlyFrm *pFollow )
     484             : {
     485             :     OSL_ENSURE( pMaster && pFollow, "uncomplete chain" );
     486             :     OSL_ENSURE( !pMaster->GetNextLink(), "link can not be changed" );
     487             :     OSL_ENSURE( !pFollow->GetPrevLink(), "link can not be changed" );
     488             : 
     489           4 :     pMaster->pNextLink = pFollow;
     490           4 :     pFollow->pPrevLink = pMaster;
     491             : 
     492           4 :     if ( pMaster->ContainsContent() )
     493             :     {
     494             :         // To get a text flow we need to invalidate
     495           2 :         SwFrm *pInva = pMaster->FindLastLower();
     496           2 :         SWRECTFN( pMaster )
     497           2 :         const long nBottom = (pMaster->*fnRect->fnGetPrtBottom)();
     498           6 :         while ( pInva )
     499             :         {
     500           2 :             if( (pInva->Frm().*fnRect->fnBottomDist)( nBottom ) <= 0 )
     501             :             {
     502           0 :                 pInva->InvalidateSize();
     503           0 :                 pInva->Prepare( PREP_CLEAR );
     504           0 :                 pInva = pInva->FindPrev();
     505             :             }
     506             :             else
     507           2 :                 pInva = 0;
     508             :         }
     509             :     }
     510             : 
     511           4 :     if ( pFollow->ContainsContent() )
     512             :     {
     513             :         // There's only the content from the Masters left; the content from the Follow
     514             :         // does not have any Frames left (should always be exactly one empty TextNode).
     515           2 :         SwFrm *pFrm = pFollow->ContainsContent();
     516             :         OSL_ENSURE( !pFrm->IsTabFrm() && !pFrm->FindNext(), "follow in chain contains content" );
     517           2 :         pFrm->Cut();
     518           2 :         SwFrm::DestroyFrm(pFrm);
     519             :     }
     520             : 
     521             :     // invalidate accessible relation set (accessibility wrapper)
     522           4 :     SwViewShell* pSh = pMaster->getRootFrm()->GetCurrShell();
     523           4 :     if( pSh )
     524             :     {
     525           4 :         SwRootFrm* pLayout = pMaster->getRootFrm();
     526           4 :         if( pLayout && pLayout->IsAnyShellAccessible() )
     527           0 :         pSh->Imp()->InvalidateAccessibleRelationSet( pMaster, pFollow );
     528             :     }
     529           4 : }
     530             : 
     531           4 : void SwFlyFrm::UnchainFrames( SwFlyFrm *pMaster, SwFlyFrm *pFollow )
     532             : {
     533           4 :     pMaster->pNextLink = 0;
     534           4 :     pFollow->pPrevLink = 0;
     535             : 
     536           4 :     if ( pFollow->ContainsContent() )
     537             :     {
     538             :         // The Master sucks up the content of the Follow
     539           3 :         SwLayoutFrm *pUpper = pMaster;
     540           3 :         if ( pUpper->Lower()->IsColumnFrm() )
     541             :         {
     542           0 :             pUpper = static_cast<SwLayoutFrm*>(pUpper->GetLastLower());
     543           0 :             pUpper = static_cast<SwLayoutFrm*>(pUpper->Lower()); // The (Column)BodyFrm
     544             :             OSL_ENSURE( pUpper && pUpper->IsColBodyFrm(), "Missing ColumnBody" );
     545             :         }
     546           3 :         SwFlyFrm *pFoll = pFollow;
     547           9 :         while ( pFoll )
     548             :         {
     549           3 :             SwFrm *pTmp = ::SaveContent( pFoll );
     550           3 :             if ( pTmp )
     551           3 :                 ::RestoreContent( pTmp, pUpper, pMaster->FindLastLower(), true );
     552           3 :             pFoll->SetCompletePaint();
     553           3 :             pFoll->InvalidateSize();
     554           3 :             pFoll = pFoll->GetNextLink();
     555             :         }
     556             :     }
     557             : 
     558             :     // The Follow needs his own content to be served
     559           4 :     const SwFormatContent &rContent = pFollow->GetFormat()->GetContent();
     560             :     OSL_ENSURE( rContent.GetContentIdx(), ":-( No content prepared." );
     561           4 :     sal_uLong nIndex = rContent.GetContentIdx()->GetIndex();
     562             :     // Lower() means SwColumnFrm: this one contains another SwBodyFrm
     563           4 :     ::_InsertCnt( pFollow->Lower() ? const_cast<SwLayoutFrm*>(static_cast<const SwLayoutFrm*>(static_cast<const SwLayoutFrm*>(pFollow->Lower())->Lower()))
     564             :                                    : static_cast<SwLayoutFrm*>(pFollow),
     565           8 :                   pFollow->GetFormat()->GetDoc(), ++nIndex );
     566             : 
     567             :     // invalidate accessible relation set (accessibility wrapper)
     568           4 :     SwViewShell* pSh = pMaster->getRootFrm()->GetCurrShell();
     569           4 :     if( pSh )
     570             :     {
     571           0 :         SwRootFrm* pLayout = pMaster->getRootFrm();
     572           0 :         if( pLayout && pLayout->IsAnyShellAccessible() )
     573           0 :         pSh->Imp()->InvalidateAccessibleRelationSet( pMaster, pFollow );
     574             :     }
     575           4 : }
     576             : 
     577           8 : SwFlyFrm *SwFlyFrm::FindChainNeighbour( SwFrameFormat &rChain, SwFrm *pAnch )
     578             : {
     579             :     // We look for the Fly that's in the same Area.
     580             :     // Areas can for now only be Head/Footer or Flys.
     581             : 
     582           8 :     if ( !pAnch ) // If an Anchor was passed along, that one counts (ctor!)
     583           0 :         pAnch = AnchorFrm();
     584             : 
     585             :     SwLayoutFrm *pLay;
     586           8 :     if ( pAnch->IsInFly() )
     587           0 :         pLay = pAnch->FindFlyFrm();
     588             :     else
     589             :     {
     590             :         // FindFooterOrHeader is not appropriate here, as we may not have a
     591             :         // connection to the Anchor yet.
     592           8 :         pLay = pAnch->GetUpper();
     593          40 :         while ( pLay && !(pLay->GetType() & (FRM_HEADER|FRM_FOOTER)) )
     594          24 :             pLay = pLay->GetUpper();
     595             :     }
     596             : 
     597           8 :     SwIterator<SwFlyFrm,SwFormat> aIter( rChain );
     598           8 :     SwFlyFrm *pFly = aIter.First();
     599           8 :     if ( pLay )
     600             :     {
     601           0 :         while ( pFly )
     602             :         {
     603           0 :             if ( pFly->GetAnchorFrm() )
     604             :             {
     605           0 :                 if ( pFly->GetAnchorFrm()->IsInFly() )
     606             :                 {
     607           0 :                     if ( pFly->AnchorFrm()->FindFlyFrm() == pLay )
     608           0 :                         break;
     609             :                 }
     610           0 :                 else if ( pLay == pFly->FindFooterOrHeader() )
     611           0 :                     break;
     612             :             }
     613           0 :             pFly = aIter.Next();
     614             :         }
     615             :     }
     616             :     else if ( pFly )
     617             :     {
     618             :         OSL_ENSURE( !aIter.Next(), "chain with more than one instance" );
     619             :     }
     620           8 :     return pFly;
     621             : }
     622             : 
     623           5 : SwFrm *SwFlyFrm::FindLastLower()
     624             : {
     625           5 :     SwFrm *pRet = ContainsAny();
     626           5 :     if ( pRet && pRet->IsInTab() )
     627           0 :         pRet = pRet->FindTabFrm();
     628           5 :     SwFrm *pNxt = pRet;
     629          90 :     while ( pNxt && IsAnLower( pNxt ) )
     630          80 :     {   pRet = pNxt;
     631          80 :         pNxt = pNxt->FindNext();
     632             :     }
     633           5 :     return pRet;
     634             : }
     635             : 
     636          49 : bool SwFlyFrm::FrmSizeChg( const SwFormatFrmSize &rFrmSize )
     637             : {
     638          49 :     bool bRet = false;
     639          49 :     SwTwips nDiffHeight = Frm().Height();
     640          49 :     if ( rFrmSize.GetHeightSizeType() == ATT_VAR_SIZE )
     641          21 :         mbFixSize = bMinHeight = false;
     642             :     else
     643             :     {
     644          28 :         if ( rFrmSize.GetHeightSizeType() == ATT_FIX_SIZE )
     645             :         {
     646          28 :             mbFixSize = true;
     647          28 :             bMinHeight = false;
     648             :         }
     649           0 :         else if ( rFrmSize.GetHeightSizeType() == ATT_MIN_SIZE )
     650             :         {
     651           0 :             mbFixSize = false;
     652           0 :             bMinHeight = true;
     653             :         }
     654          28 :         nDiffHeight -= rFrmSize.GetHeight();
     655             :     }
     656             :     // If the Fly contains columns, we already need to set the Fly
     657             :     // and the Columns to the required value or else we run into problems.
     658          49 :     if ( Lower() )
     659             :     {
     660          46 :         if ( Lower()->IsColumnFrm() )
     661             :         {
     662           0 :             const SwRect aOld( GetObjRectWithSpaces() );
     663           0 :             const Size   aOldSz( Prt().SSize() );
     664           0 :             const SwTwips nDiffWidth = Frm().Width() - rFrmSize.GetWidth();
     665           0 :             maFrm.Height( maFrm.Height() - nDiffHeight );
     666           0 :             maFrm.Width ( maFrm.Width()  - nDiffWidth  );
     667             :             // #i68520#
     668           0 :             InvalidateObjRectWithSpaces();
     669           0 :             maPrt.Height( maPrt.Height() - nDiffHeight );
     670           0 :             maPrt.Width ( maPrt.Width()  - nDiffWidth  );
     671           0 :             ChgLowersProp( aOldSz );
     672           0 :             ::Notify( this, FindPageFrm(), aOld );
     673           0 :             mbValidPos = false;
     674           0 :             bRet = true;
     675             :         }
     676          46 :         else if ( Lower()->IsNoTextFrm() )
     677             :         {
     678          20 :             mbFixSize = true;
     679          20 :             bMinHeight = false;
     680             :         }
     681             :     }
     682          49 :     return bRet;
     683             : }
     684             : 
     685         167 : void SwFlyFrm::Modify( const SfxPoolItem* pOld, const SfxPoolItem * pNew )
     686             : {
     687         167 :     sal_uInt8 nInvFlags = 0;
     688             : 
     689         167 :     if (pNew && pOld && RES_ATTRSET_CHG == pNew->Which())
     690             :     {
     691          59 :         SfxItemIter aNIter( *static_cast<const SwAttrSetChg*>(pNew)->GetChgSet() );
     692         118 :         SfxItemIter aOIter( *static_cast<const SwAttrSetChg*>(pOld)->GetChgSet() );
     693         118 :         SwAttrSetChg aOldSet( *static_cast<const SwAttrSetChg*>(pOld) );
     694         118 :         SwAttrSetChg aNewSet( *static_cast<const SwAttrSetChg*>(pNew) );
     695             :         while( true )
     696             :         {
     697             :             _UpdateAttr( aOIter.GetCurItem(),
     698             :                          aNIter.GetCurItem(), nInvFlags,
     699          73 :                          &aOldSet, &aNewSet );
     700          73 :             if( aNIter.IsAtEnd() )
     701          59 :                 break;
     702          14 :             aNIter.NextItem();
     703          14 :             aOIter.NextItem();
     704             :         }
     705          59 :         if ( aOldSet.Count() || aNewSet.Count() )
     706          59 :             SwLayoutFrm::Modify( &aOldSet, &aNewSet );
     707             :     }
     708             :     else
     709         108 :         _UpdateAttr( pOld, pNew, nInvFlags );
     710             : 
     711         167 :     if ( nInvFlags != 0 )
     712             :     {
     713          64 :         _Invalidate();
     714          64 :         if ( nInvFlags & 0x01 )
     715             :         {
     716          62 :             _InvalidatePos();
     717             :             // #i68520#
     718          62 :             InvalidateObjRectWithSpaces();
     719             :         }
     720          64 :         if ( nInvFlags & 0x02 )
     721             :         {
     722          49 :             _InvalidateSize();
     723             :             // #i68520#
     724          49 :             InvalidateObjRectWithSpaces();
     725             :         }
     726          64 :         if ( nInvFlags & 0x04 )
     727          49 :             _InvalidatePrt();
     728          64 :         if ( nInvFlags & 0x08 )
     729          58 :             SetNotifyBack();
     730          64 :         if ( nInvFlags & 0x10 )
     731          49 :             SetCompletePaint();
     732          64 :         if ( ( nInvFlags & 0x40 ) && Lower() && Lower()->IsNoTextFrm() )
     733          24 :             ClrContourCache( GetVirtDrawObj() );
     734             :         SwRootFrm *pRoot;
     735          64 :         if ( nInvFlags & 0x20 && 0 != (pRoot = getRootFrm()) )
     736          49 :             pRoot->InvalidateBrowseWidth();
     737             :         // #i28701#
     738          64 :         if ( nInvFlags & 0x80 )
     739             :         {
     740             :             // update sorted object lists, the Writer fly frame is registered at.
     741          55 :             UpdateObjInSortedList();
     742             :         }
     743             : 
     744             :         // #i87645# - reset flags for the layout process (only if something has been invalidated)
     745          64 :         ResetLayoutProcessBools();
     746             :     }
     747         167 : }
     748             : 
     749         181 : void SwFlyFrm::_UpdateAttr( const SfxPoolItem *pOld, const SfxPoolItem *pNew,
     750             :                             sal_uInt8 &rInvFlags,
     751             :                             SwAttrSetChg *pOldSet, SwAttrSetChg *pNewSet )
     752             : {
     753         181 :     bool bClear = true;
     754         181 :     const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
     755         181 :     SwViewShell *pSh = getRootFrm()->GetCurrShell();
     756         181 :     switch( nWhich )
     757             :     {
     758             :         case RES_VERT_ORIENT:
     759             :         case RES_HORI_ORIENT:
     760             :         // OD 22.09.2003 #i18732# - consider new option 'follow text flow'
     761             :         case RES_FOLLOW_TEXT_FLOW:
     762             :         {
     763             :             // ATTENTION: Always also change Action in ChgRePos()!
     764          23 :             rInvFlags |= 0x09;
     765             :         }
     766          23 :         break;
     767             :         // OD 2004-07-01 #i28701# - consider new option 'wrap influence on position'
     768             :         case RES_WRAP_INFLUENCE_ON_OBJPOS:
     769             :         {
     770           0 :             rInvFlags |= 0x89;
     771             :         }
     772           0 :         break;
     773             :         case RES_SURROUND:
     774             :         {
     775             :             // OD 2004-05-13 #i28701# - invalidate position on change of
     776             :             // wrapping style.
     777             :             //rInvFlags |= 0x40;
     778           4 :             rInvFlags |= 0x41;
     779             :             // The background needs to messaged and invalidated
     780           4 :             const SwRect aTmp( GetObjRectWithSpaces() );
     781           4 :             NotifyBackground( FindPageFrm(), aTmp, PREP_FLY_ATTR_CHG );
     782             : 
     783             :             // By changing the flow of frame-bound Frames, a vertical alignment
     784             :             // can be activated/deactivated => MakeFlyPos
     785           4 :             if( FLY_AT_FLY == GetFormat()->GetAnchor().GetAnchorId() )
     786           0 :                 rInvFlags |= 0x09;
     787             : 
     788             :             // Delete contour in the Node if necessary
     789           8 :             if ( Lower() && Lower()->IsNoTextFrm() &&
     790           4 :                  !GetFormat()->GetSurround().IsContour() )
     791             :             {
     792           4 :                 SwNoTextNode *pNd = static_cast<SwNoTextNode*>(static_cast<SwContentFrm*>(Lower())->GetNode());
     793           4 :                 if ( pNd->HasContour() )
     794           0 :                     pNd->SetContour( 0 );
     795             :             }
     796             :             // #i28701# - perform reorder of object lists
     797             :             // at anchor frame and at page frame.
     798           4 :             rInvFlags |= 0x80;
     799             :         }
     800           4 :         break;
     801             : 
     802             :         case RES_PROTECT:
     803           0 :             if (pNew)
     804             :             {
     805           0 :                 const SvxProtectItem *pP = static_cast<const SvxProtectItem*>(pNew);
     806           0 :                 GetVirtDrawObj()->SetMoveProtect( pP->IsPosProtected()   );
     807           0 :                 GetVirtDrawObj()->SetResizeProtect( pP->IsSizeProtected() );
     808           0 :                 if( pSh )
     809             :                 {
     810           0 :                     SwRootFrm* pLayout = getRootFrm();
     811           0 :                     if( pLayout && pLayout->IsAnyShellAccessible() )
     812           0 :                     pSh->Imp()->InvalidateAccessibleEditableState( true, this );
     813             :                 }
     814             :             }
     815           0 :             break;
     816             :         case RES_COL:
     817           0 :             if (pOld && pNew)
     818             :             {
     819           0 :                 ChgColumns( *static_cast<const SwFormatCol*>(pOld), *static_cast<const SwFormatCol*>(pNew) );
     820           0 :                 const SwFormatFrmSize &rNew = GetFormat()->GetFrmSize();
     821           0 :                 if ( FrmSizeChg( rNew ) )
     822           0 :                     NotifyDrawObj();
     823           0 :                 rInvFlags |= 0x1A;
     824           0 :                 break;
     825             :             }
     826             : 
     827             :         case RES_FRM_SIZE:
     828             :         case RES_FMT_CHG:
     829             :         {
     830          49 :             const SwFormatFrmSize &rNew = GetFormat()->GetFrmSize();
     831          49 :             if ( FrmSizeChg( rNew ) )
     832           0 :                 NotifyDrawObj();
     833          49 :             rInvFlags |= 0x7F;
     834          49 :             if ( RES_FMT_CHG == nWhich )
     835             :             {
     836           5 :                 SwRect aNew( GetObjRectWithSpaces() );
     837           5 :                 SwRect aOld( maFrm );
     838           5 :                 const SvxULSpaceItem &rUL = static_cast<const SwFormatChg*>(pOld)->pChangedFormat->GetULSpace();
     839           5 :                 aOld.Top( std::max( aOld.Top() - long(rUL.GetUpper()), 0L ) );
     840           5 :                 aOld.SSize().Height()+= rUL.GetLower();
     841           5 :                 const SvxLRSpaceItem &rLR = static_cast<const SwFormatChg*>(pOld)->pChangedFormat->GetLRSpace();
     842           5 :                 aOld.Left  ( std::max( aOld.Left() - long(rLR.GetLeft()), 0L ) );
     843           5 :                 aOld.SSize().Width() += rLR.GetRight();
     844           5 :                 aNew.Union( aOld );
     845           5 :                 NotifyBackground( FindPageFrm(), aNew, PREP_CLEAR );
     846             : 
     847             :                 // Special case:
     848             :                 // When assigning a template we cannot rely on the old column
     849             :                 // attribute. As there need to be at least enough for ChgColumns,
     850             :                 // we need to create a temporary attribute.
     851           5 :                 SwFormatCol aCol;
     852           5 :                 if ( Lower() && Lower()->IsColumnFrm() )
     853             :                 {
     854           0 :                     sal_uInt16 nCol = 0;
     855           0 :                     SwFrm *pTmp = Lower();
     856           0 :                     do
     857           0 :                     {   ++nCol;
     858           0 :                         pTmp = pTmp->GetNext();
     859             :                     } while ( pTmp );
     860           0 :                     aCol.Init( nCol, 0, 1000 );
     861             :                 }
     862           5 :                 ChgColumns( aCol, GetFormat()->GetCol() );
     863             :             }
     864             : 
     865          49 :             SwFormatURL aURL( GetFormat()->GetURL() );
     866             : 
     867          49 :             SwFormatFrmSize *pNewFormatFrmSize = NULL;
     868          49 :             SwFormatChg *pOldFormatChg = NULL;
     869          49 :             if (nWhich == RES_FRM_SIZE)
     870          44 :                 pNewFormatFrmSize = const_cast<SwFormatFrmSize*>(static_cast<const SwFormatFrmSize*>(pNew));
     871             :             else
     872           5 :                 pOldFormatChg = const_cast<SwFormatChg*>(static_cast<const SwFormatChg*>(pOld));
     873             : 
     874          49 :             if (aURL.GetMap() && (pNewFormatFrmSize || pOldFormatChg))
     875             :             {
     876             :                 const SwFormatFrmSize &rOld = pNewFormatFrmSize ?
     877             :                                 *pNewFormatFrmSize :
     878           0 :                                 pOldFormatChg->pChangedFormat->GetFrmSize();
     879             :                 //#35091# Can be "times zero", when loading the template
     880           0 :                 if ( rOld.GetWidth() && rOld.GetHeight() )
     881             :                 {
     882             : 
     883           0 :                     Fraction aScaleX( rOld.GetWidth(), rNew.GetWidth() );
     884           0 :                     Fraction aScaleY( rOld.GetHeight(), rOld.GetHeight() );
     885           0 :                     aURL.GetMap()->Scale( aScaleX, aScaleY );
     886           0 :                     SwFrameFormat *pFormat = GetFormat();
     887           0 :                     pFormat->LockModify();
     888           0 :                     pFormat->SetFormatAttr( aURL );
     889           0 :                     pFormat->UnlockModify();
     890             :                 }
     891             :             }
     892          49 :             const SvxProtectItem &rP = GetFormat()->GetProtect();
     893          49 :             GetVirtDrawObj()->SetMoveProtect( rP.IsPosProtected()    );
     894          49 :             GetVirtDrawObj()->SetResizeProtect( rP.IsSizeProtected() );
     895             : 
     896          49 :             if ( pSh )
     897          49 :                 pSh->InvalidateWindows( Frm() );
     898          49 :             const IDocumentDrawModelAccess* pIDDMA = GetFormat()->getIDocumentDrawModelAccess();
     899          49 :             const sal_uInt8 nId = GetFormat()->GetOpaque().GetValue() ?
     900          45 :                              pIDDMA->GetHeavenId() :
     901          94 :                              pIDDMA->GetHellId();
     902          49 :             GetVirtDrawObj()->SetLayer( nId );
     903             : 
     904          49 :             if ( Lower() )
     905             :             {
     906             :                 // Delete contour in the Node if necessary
     907          66 :                 if( Lower()->IsNoTextFrm() &&
     908          20 :                      !GetFormat()->GetSurround().IsContour() )
     909             :                 {
     910          20 :                     SwNoTextNode *pNd = static_cast<SwNoTextNode*>(static_cast<SwContentFrm*>(Lower())->GetNode());
     911          20 :                     if ( pNd->HasContour() )
     912           0 :                         pNd->SetContour( 0 );
     913             :                 }
     914          26 :                 else if( !Lower()->IsColumnFrm() )
     915             :                 {
     916          26 :                     SwFrm* pFrm = GetLastLower();
     917          26 :                     if( pFrm->IsTextFrm() && static_cast<SwTextFrm*>(pFrm)->IsUndersized() )
     918           6 :                         pFrm->Prepare( PREP_ADJUST_FRM );
     919             :                 }
     920             :             }
     921             : 
     922             :             // #i28701# - perform reorder of object lists
     923             :             // at anchor frame and at page frame.
     924          49 :             rInvFlags |= 0x80;
     925             : 
     926          49 :             break;
     927             :         }
     928             :         case RES_UL_SPACE:
     929             :         case RES_LR_SPACE:
     930             :         {
     931           0 :             rInvFlags |= 0x41;
     932           0 :             if( pSh && pSh->GetViewOptions()->getBrowseMode() )
     933           0 :                 getRootFrm()->InvalidateBrowseWidth();
     934           0 :             SwRect aNew( GetObjRectWithSpaces() );
     935           0 :             SwRect aOld( maFrm );
     936           0 :             if (pNew)
     937             :             {
     938           0 :                 if ( RES_UL_SPACE == nWhich )
     939             :                 {
     940           0 :                     const SvxULSpaceItem &rUL = *static_cast<const SvxULSpaceItem*>(pNew);
     941           0 :                     aOld.Top( std::max( aOld.Top() - long(rUL.GetUpper()), 0L ) );
     942           0 :                     aOld.SSize().Height()+= rUL.GetLower();
     943             :                 }
     944             :                 else
     945             :                 {
     946           0 :                     const SvxLRSpaceItem &rLR = *static_cast<const SvxLRSpaceItem*>(pNew);
     947           0 :                     aOld.Left  ( std::max( aOld.Left() - long(rLR.GetLeft()), 0L ) );
     948           0 :                     aOld.SSize().Width() += rLR.GetRight();
     949             :                 }
     950             :             }
     951           0 :             aNew.Union( aOld );
     952           0 :             NotifyBackground( FindPageFrm(), aNew, PREP_CLEAR );
     953             :         }
     954           0 :         break;
     955             : 
     956             :         case RES_TEXT_VERT_ADJUST:
     957             :         {
     958           0 :             InvalidateContentPos();
     959           0 :             rInvFlags |= 0x10;
     960             :         }
     961           0 :         break;
     962             : 
     963             :         case RES_BOX:
     964             :         case RES_SHADOW:
     965           0 :             rInvFlags |= 0x17;
     966           0 :             break;
     967             : 
     968             :         case RES_FRAMEDIR :
     969           0 :             SetDerivedVert( false );
     970           0 :             SetDerivedR2L( false );
     971           0 :             CheckDirChange();
     972           0 :             break;
     973             : 
     974             :         case RES_OPAQUE:
     975             :             {
     976           2 :                 if ( pSh )
     977           2 :                     pSh->InvalidateWindows( Frm() );
     978             : 
     979           2 :                 const IDocumentDrawModelAccess* pIDDMA = GetFormat()->getIDocumentDrawModelAccess();
     980           2 :                 const sal_uInt8 nId = static_cast<const SvxOpaqueItem*>(pNew)->GetValue() ?
     981           0 :                                     pIDDMA->GetHeavenId() :
     982           2 :                                     pIDDMA->GetHellId();
     983           2 :                 GetVirtDrawObj()->SetLayer( nId );
     984           2 :                 if( pSh )
     985             :                 {
     986           2 :                     SwRootFrm* pLayout = getRootFrm();
     987           2 :                     if( pLayout && pLayout->IsAnyShellAccessible() )
     988             :                 {
     989           0 :                     pSh->Imp()->DisposeAccessibleFrm( this );
     990           0 :                     pSh->Imp()->AddAccessibleFrm( this );
     991             :                 }
     992             :                 }
     993             :                 // #i28701# - perform reorder of object lists
     994             :                 // at anchor frame and at page frame.
     995           2 :                 rInvFlags |= 0x80;
     996             :             }
     997           2 :             break;
     998             : 
     999             :         case RES_URL:
    1000             :             // The interface changes the frame size when interacting with text frames,
    1001             :             // the Map, however, needs to be relative to FrmSize().
    1002           0 :             if ( (!Lower() || !Lower()->IsNoTextFrm()) && pNew && pOld &&
    1003           0 :                  static_cast<const SwFormatURL*>(pNew)->GetMap() && static_cast<const SwFormatURL*>(pOld)->GetMap() )
    1004             :             {
    1005           0 :                 const SwFormatFrmSize &rSz = GetFormat()->GetFrmSize();
    1006           0 :                 if ( rSz.GetHeight() != Frm().Height() ||
    1007           0 :                      rSz.GetWidth()  != Frm().Width() )
    1008             :                 {
    1009           0 :                     SwFormatURL aURL( GetFormat()->GetURL() );
    1010           0 :                     Fraction aScaleX( Frm().Width(),  rSz.GetWidth() );
    1011           0 :                     Fraction aScaleY( Frm().Height(), rSz.GetHeight() );
    1012           0 :                     aURL.GetMap()->Scale( aScaleX, aScaleY );
    1013           0 :                     SwFrameFormat *pFormat = GetFormat();
    1014           0 :                     pFormat->LockModify();
    1015           0 :                     pFormat->SetFormatAttr( aURL );
    1016           0 :                     pFormat->UnlockModify();
    1017             :                 }
    1018             :             }
    1019             :             // No invalidation necessary
    1020           0 :             break;
    1021             : 
    1022             :         case RES_CHAIN:
    1023           0 :             if (pNew)
    1024             :             {
    1025           0 :                 const SwFormatChain *pChain = static_cast<const SwFormatChain*>(pNew);
    1026           0 :                 if ( pChain->GetNext() )
    1027             :                 {
    1028           0 :                     SwFlyFrm *pFollow = FindChainNeighbour( *pChain->GetNext() );
    1029           0 :                     if ( GetNextLink() && pFollow != GetNextLink() )
    1030           0 :                         SwFlyFrm::UnchainFrames( this, GetNextLink());
    1031           0 :                     if ( pFollow )
    1032             :                     {
    1033           0 :                         if ( pFollow->GetPrevLink() &&
    1034           0 :                              pFollow->GetPrevLink() != this )
    1035             :                             SwFlyFrm::UnchainFrames( pFollow->GetPrevLink(),
    1036           0 :                                                      pFollow );
    1037           0 :                         if ( !GetNextLink() )
    1038           0 :                             SwFlyFrm::ChainFrames( this, pFollow );
    1039             :                     }
    1040             :                 }
    1041           0 :                 else if ( GetNextLink() )
    1042           0 :                     SwFlyFrm::UnchainFrames( this, GetNextLink() );
    1043           0 :                 if ( pChain->GetPrev() )
    1044             :                 {
    1045           0 :                     SwFlyFrm *pMaster = FindChainNeighbour( *pChain->GetPrev() );
    1046           0 :                     if ( GetPrevLink() && pMaster != GetPrevLink() )
    1047           0 :                         SwFlyFrm::UnchainFrames( GetPrevLink(), this );
    1048           0 :                     if ( pMaster )
    1049             :                     {
    1050           0 :                         if ( pMaster->GetNextLink() &&
    1051           0 :                              pMaster->GetNextLink() != this )
    1052             :                             SwFlyFrm::UnchainFrames( pMaster,
    1053           0 :                                                      pMaster->GetNextLink() );
    1054           0 :                         if ( !GetPrevLink() )
    1055           0 :                             SwFlyFrm::ChainFrames( pMaster, this );
    1056             :                     }
    1057             :                 }
    1058           0 :                 else if ( GetPrevLink() )
    1059           0 :                     SwFlyFrm::UnchainFrames( GetPrevLink(), this );
    1060             :             }
    1061             :             //fall-through
    1062             :         default:
    1063         103 :             bClear = false;
    1064             :     }
    1065         181 :     if ( bClear )
    1066             :     {
    1067          78 :         if ( pOldSet || pNewSet )
    1068             :         {
    1069          73 :             if ( pOldSet )
    1070          73 :                 pOldSet->ClearItem( nWhich );
    1071         146 :             if ( pNewSet )
    1072          73 :                 pNewSet->ClearItem( nWhich );
    1073             :         }
    1074             :         else
    1075           5 :             SwLayoutFrm::Modify( pOld, pNew );
    1076             :     }
    1077         181 : }
    1078             : 
    1079             : /// Gets information from the Modify
    1080          73 : bool SwFlyFrm::GetInfo( SfxPoolItem & rInfo ) const
    1081             : {
    1082          73 :     if( RES_AUTOFMT_DOCNODE == rInfo.Which() )
    1083          73 :         return false;   // There's a FlyFrm, so use it
    1084           0 :     return true;        // Continue searching
    1085             : }
    1086             : 
    1087        6688 : void SwFlyFrm::_Invalidate( SwPageFrm *pPage )
    1088             : {
    1089        6688 :     InvalidatePage( pPage );
    1090        6688 :     bNotifyBack = bInvalid = true;
    1091             : 
    1092             :     SwFlyFrm *pFrm;
    1093        6688 :     if ( GetAnchorFrm() && 0 != (pFrm = AnchorFrm()->FindFlyFrm()) )
    1094             :     {
    1095             :         // Very bad case: If the Fly is bound within another Fly which
    1096             :         // contains columns, the Format should be from that one.
    1097         820 :         if ( !pFrm->IsLocked() && !pFrm->IsColLocked() &&
    1098         615 :              pFrm->Lower() && pFrm->Lower()->IsColumnFrm() )
    1099           0 :             pFrm->InvalidateSize();
    1100             :     }
    1101             : 
    1102             :     // #i85216#
    1103             :     // if vertical position is oriented at a layout frame inside a ghost section,
    1104             :     // assure that the position is invalidated and that the information about
    1105             :     // the vertical position oriented frame is cleared
    1106        6688 :     if ( GetVertPosOrientFrm() && GetVertPosOrientFrm()->IsLayoutFrm() )
    1107             :     {
    1108        3363 :         const SwSectionFrm* pSectFrm( GetVertPosOrientFrm()->FindSctFrm() );
    1109        3363 :         if ( pSectFrm && pSectFrm->GetSection() == 0 )
    1110             :         {
    1111           0 :             InvalidatePos();
    1112           0 :             ClearVertPosOrientFrm();
    1113             :         }
    1114             :     }
    1115        6688 : }
    1116             : 
    1117             : /** Change the relative position
    1118             :  *
    1119             :  * The position will be Fix automatically and the attribute is changed accordingly.
    1120             :  */
    1121           0 : void SwFlyFrm::ChgRelPos( const Point &rNewPos )
    1122             : {
    1123           0 :     if ( GetCurrRelPos() != rNewPos )
    1124             :     {
    1125           0 :         SwFrameFormat *pFormat = GetFormat();
    1126           0 :         const bool bVert = GetAnchorFrm()->IsVertical();
    1127           0 :         const SwTwips nNewY = bVert ? rNewPos.X() : rNewPos.Y();
    1128           0 :         SwTwips nTmpY = nNewY == LONG_MAX ? 0 : nNewY;
    1129           0 :         if( bVert )
    1130           0 :             nTmpY = -nTmpY;
    1131           0 :         SfxItemSet aSet( pFormat->GetDoc()->GetAttrPool(),
    1132           0 :                          RES_VERT_ORIENT, RES_HORI_ORIENT);
    1133             : 
    1134           0 :         SwFormatVertOrient aVert( pFormat->GetVertOrient() );
    1135           0 :         const SwTextFrm *pAutoFrm = NULL;
    1136             :         // #i34948# - handle also at-page and at-fly anchored
    1137             :         // Writer fly frames
    1138           0 :         const RndStdIds eAnchorType = GetFrameFormat().GetAnchor().GetAnchorId();
    1139           0 :         if ( eAnchorType == FLY_AT_PAGE )
    1140             :         {
    1141           0 :             aVert.SetVertOrient( text::VertOrientation::NONE );
    1142           0 :             aVert.SetRelationOrient( text::RelOrientation::PAGE_FRAME );
    1143             :         }
    1144           0 :         else if ( eAnchorType == FLY_AT_FLY )
    1145             :         {
    1146           0 :             aVert.SetVertOrient( text::VertOrientation::NONE );
    1147           0 :             aVert.SetRelationOrient( text::RelOrientation::FRAME );
    1148             :         }
    1149           0 :         else if ( IsFlyAtCntFrm() || text::VertOrientation::NONE != aVert.GetVertOrient() )
    1150             :         {
    1151           0 :             if( text::RelOrientation::CHAR == aVert.GetRelationOrient() && IsAutoPos() )
    1152             :             {
    1153           0 :                 if( LONG_MAX != nNewY )
    1154             :                 {
    1155           0 :                     aVert.SetVertOrient( text::VertOrientation::NONE );
    1156             :                     sal_Int32 nOfs =
    1157           0 :                         pFormat->GetAnchor().GetContentAnchor()->nContent.GetIndex();
    1158             :                     OSL_ENSURE( GetAnchorFrm()->IsTextFrm(), "TextFrm expected" );
    1159           0 :                     pAutoFrm = static_cast<const SwTextFrm*>(GetAnchorFrm());
    1160           0 :                     while( pAutoFrm->GetFollow() &&
    1161           0 :                            pAutoFrm->GetFollow()->GetOfst() <= nOfs )
    1162             :                     {
    1163           0 :                         if( pAutoFrm == GetAnchorFrm() )
    1164           0 :                             nTmpY += pAutoFrm->GetRelPos().Y();
    1165           0 :                         nTmpY -= pAutoFrm->GetUpper()->Prt().Height();
    1166           0 :                         pAutoFrm = pAutoFrm->GetFollow();
    1167             :                     }
    1168           0 :                     nTmpY = static_cast<SwFlyAtCntFrm*>(this)->GetRelCharY(pAutoFrm)-nTmpY;
    1169             :                 }
    1170             :                 else
    1171           0 :                     aVert.SetVertOrient( text::VertOrientation::CHAR_BOTTOM );
    1172             :             }
    1173             :             else
    1174             :             {
    1175           0 :                 aVert.SetVertOrient( text::VertOrientation::NONE );
    1176           0 :                 aVert.SetRelationOrient( text::RelOrientation::FRAME );
    1177             :             }
    1178             :         }
    1179           0 :         aVert.SetPos( nTmpY );
    1180           0 :         aSet.Put( aVert );
    1181             : 
    1182             :         // For Flys in the Cnt, the horizontal orientation is of no interest,
    1183             :         // as it's always 0
    1184           0 :         if ( !IsFlyInCntFrm() )
    1185             :         {
    1186           0 :             const SwTwips nNewX = bVert ? rNewPos.Y() : rNewPos.X();
    1187           0 :             SwTwips nTmpX = nNewX == LONG_MAX ? 0 : nNewX;
    1188           0 :             SwFormatHoriOrient aHori( pFormat->GetHoriOrient() );
    1189             :             // #i34948# - handle also at-page and at-fly anchored
    1190             :             // Writer fly frames
    1191           0 :             if ( eAnchorType == FLY_AT_PAGE )
    1192             :             {
    1193           0 :                 aHori.SetHoriOrient( text::HoriOrientation::NONE );
    1194           0 :                 aHori.SetRelationOrient( text::RelOrientation::PAGE_FRAME );
    1195           0 :                 aHori.SetPosToggle( false );
    1196             :             }
    1197           0 :             else if ( eAnchorType == FLY_AT_FLY )
    1198             :             {
    1199           0 :                 aHori.SetHoriOrient( text::HoriOrientation::NONE );
    1200           0 :                 aHori.SetRelationOrient( text::RelOrientation::FRAME );
    1201           0 :                 aHori.SetPosToggle( false );
    1202             :             }
    1203           0 :             else if ( IsFlyAtCntFrm() || text::HoriOrientation::NONE != aHori.GetHoriOrient() )
    1204             :             {
    1205           0 :                 aHori.SetHoriOrient( text::HoriOrientation::NONE );
    1206           0 :                 if( text::RelOrientation::CHAR == aHori.GetRelationOrient() && IsAutoPos() )
    1207             :                 {
    1208           0 :                     if( LONG_MAX != nNewX )
    1209             :                     {
    1210           0 :                         if( !pAutoFrm )
    1211             :                         {
    1212           0 :                             sal_Int32 nOfs = pFormat->GetAnchor().GetContentAnchor()
    1213           0 :                                           ->nContent.GetIndex();
    1214             :                             OSL_ENSURE( GetAnchorFrm()->IsTextFrm(), "TextFrm expected");
    1215           0 :                             pAutoFrm = static_cast<const SwTextFrm*>(GetAnchorFrm());
    1216           0 :                             while( pAutoFrm->GetFollow() &&
    1217           0 :                                    pAutoFrm->GetFollow()->GetOfst() <= nOfs )
    1218           0 :                                 pAutoFrm = pAutoFrm->GetFollow();
    1219             :                         }
    1220           0 :                         nTmpX -= static_cast<SwFlyAtCntFrm*>(this)->GetRelCharX(pAutoFrm);
    1221             :                     }
    1222             :                 }
    1223             :                 else
    1224           0 :                     aHori.SetRelationOrient( text::RelOrientation::FRAME );
    1225           0 :                 aHori.SetPosToggle( false );
    1226             :             }
    1227           0 :             aHori.SetPos( nTmpX );
    1228           0 :             aSet.Put( aHori );
    1229             :         }
    1230           0 :         SetCurrRelPos( rNewPos );
    1231           0 :         pFormat->GetDoc()->SetAttr( aSet, *pFormat );
    1232             :     }
    1233           0 : }
    1234             : 
    1235             : /** "Formats" the Frame; Frm and PrtArea.
    1236             :  *
    1237             :  * The FixSize is not inserted here.
    1238             :  */
    1239        5374 : void SwFlyFrm::Format( const SwBorderAttrs *pAttrs )
    1240             : {
    1241             :     OSL_ENSURE( pAttrs, "FlyFrm::Format, pAttrs is 0." );
    1242             : 
    1243        5374 :     ColLock();
    1244             : 
    1245        5374 :     if ( !mbValidSize )
    1246             :     {
    1247        5374 :         if ( Frm().Top() == FAR_AWAY && Frm().Left() == FAR_AWAY )
    1248             :         {
    1249             :             // Remove safety switch (see SwFrm::CTor)
    1250        1962 :             Frm().Pos().setX(0);
    1251        1962 :             Frm().Pos().setY(0);
    1252             :             // #i68520#
    1253        1962 :             InvalidateObjRectWithSpaces();
    1254             :         }
    1255             : 
    1256             :         // Check column width and set it if needed
    1257        5374 :         if ( Lower() && Lower()->IsColumnFrm() )
    1258           0 :             AdjustColumns( 0, false );
    1259             : 
    1260        5374 :         mbValidSize = true;
    1261             : 
    1262        5374 :         const SwTwips nUL = pAttrs->CalcTopLine()  + pAttrs->CalcBottomLine();
    1263        5374 :         const SwTwips nLR = pAttrs->CalcLeftLine() + pAttrs->CalcRightLine();
    1264        5374 :         const SwFormatFrmSize &rFrmSz = GetFormat()->GetFrmSize();
    1265        5374 :         Size aRelSize( CalcRel( rFrmSz ) );
    1266             : 
    1267             :         OSL_ENSURE( pAttrs->GetSize().Height() != 0 || rFrmSz.GetHeightPercent(), "FrameAttr height is 0." );
    1268             :         OSL_ENSURE( pAttrs->GetSize().Width()  != 0 || rFrmSz.GetWidthPercent(), "FrameAttr width is 0." );
    1269             : 
    1270        5374 :         SWRECTFN( this )
    1271        5374 :         if( !HasFixSize() )
    1272             :         {
    1273        1905 :             long nMinHeight = 0;
    1274        1905 :             if( IsMinHeight() )
    1275         331 :                 nMinHeight = bVert ? aRelSize.Width() : aRelSize.Height();
    1276             : 
    1277        1905 :             SwTwips nRemaining = CalcContentHeight(pAttrs, nMinHeight, nUL);
    1278        1905 :             if( IsMinHeight() && (nRemaining + nUL) < nMinHeight )
    1279         244 :                 nRemaining = nMinHeight - nUL;
    1280             :             // Because the Grow/Shrink of the Flys does not directly
    1281             :             // set the size - only indirectly by triggering a Format()
    1282             :             // via Invalidate() - the sizes need to be set here.
    1283             :             // Notification is running along already.
    1284             :             // As we already got a lot of zeros per attribute, we block them
    1285             :             // from now on.
    1286             : 
    1287        1905 :             if ( nRemaining < MINFLY )
    1288         492 :                 nRemaining = MINFLY;
    1289             : 
    1290        1905 :             (Prt().*fnRect->fnSetHeight)( nRemaining );
    1291        1905 :             nRemaining -= (Frm().*fnRect->fnGetHeight)();
    1292        1905 :             (Frm().*fnRect->fnAddBottom)( nRemaining + nUL );
    1293             :             // #i68520#
    1294        1905 :             if ( nRemaining + nUL != 0 )
    1295             :             {
    1296         719 :                 InvalidateObjRectWithSpaces();
    1297             :             }
    1298        1905 :             mbValidSize = true;
    1299             : 
    1300        1905 :             std::map<SwFrameFormat*, SwFrameFormat*> aShapes = SwTextBoxHelper::findShapes(GetFormat()->GetDoc());
    1301        1905 :             if (aShapes.find(GetFormat()) != aShapes.end())
    1302             :             {
    1303             :                 // This fly is a textbox of a draw shape.
    1304         538 :                 SdrObject* pShape = aShapes[GetFormat()]->FindSdrObject();
    1305         538 :                 if (SdrObjCustomShape* pCustomShape = PTR_CAST(SdrObjCustomShape, pShape))
    1306             :                 {
    1307             :                     // The shape is a customshape: then inform it about the calculated fly size.
    1308         538 :                     Size aSize((Frm().*fnRect->fnGetWidth)(), (Frm().*fnRect->fnGetHeight)());
    1309         538 :                     pCustomShape->SuggestTextFrameSize(aSize);
    1310             :                     // Do the calculations normally done after touching editeng text of the shape.
    1311         538 :                     pCustomShape->NbcSetOutlinerParaObjectForText(0, 0);
    1312             :                 }
    1313        1905 :             }
    1314             :         }
    1315             :         else
    1316             :         {
    1317        3469 :             mbValidSize = true;  // Fixed Frms do not Format itself
    1318             :             // Flys set their size using the attr
    1319        3469 :             SwTwips nNewSize = bVert ? aRelSize.Width() : aRelSize.Height();
    1320        3469 :             nNewSize -= nUL;
    1321        3469 :             if( nNewSize < MINFLY )
    1322          10 :                 nNewSize = MINFLY;
    1323        3469 :             (Prt().*fnRect->fnSetHeight)( nNewSize );
    1324        3469 :             nNewSize += nUL - (Frm().*fnRect->fnGetHeight)();
    1325        3469 :             (Frm().*fnRect->fnAddBottom)( nNewSize );
    1326             :             // #i68520#
    1327        3469 :             if ( nNewSize != 0 )
    1328             :             {
    1329         940 :                 InvalidateObjRectWithSpaces();
    1330             :             }
    1331             :         }
    1332             : 
    1333        5374 :         if ( !bFormatHeightOnly )
    1334             :         {
    1335             :             OSL_ENSURE( aRelSize == CalcRel( rFrmSz ), "SwFlyFrm::Format CalcRel problem" );
    1336        5199 :             SwTwips nNewSize = bVert ? aRelSize.Height() : aRelSize.Width();
    1337             : 
    1338        5199 :             if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
    1339             :             {
    1340             :                 // #i9046# Autowidth for fly frames
    1341         454 :                 const SwTwips nAutoWidth = CalcAutoWidth();
    1342         454 :                 if ( nAutoWidth )
    1343             :                 {
    1344         454 :                     if( ATT_MIN_SIZE == rFrmSz.GetWidthSizeType() )
    1345         454 :                         nNewSize = std::max( nNewSize - nLR, nAutoWidth );
    1346             :                     else
    1347           0 :                         nNewSize = nAutoWidth;
    1348             :                 }
    1349             :             }
    1350             :             else
    1351        4745 :                 nNewSize -= nLR;
    1352             : 
    1353        5199 :             if( nNewSize < MINFLY )
    1354          12 :                 nNewSize = MINFLY;
    1355        5199 :             (Prt().*fnRect->fnSetWidth)( nNewSize );
    1356        5199 :             nNewSize += nLR - (Frm().*fnRect->fnGetWidth)();
    1357        5199 :             (Frm().*fnRect->fnAddRight)( nNewSize );
    1358             :             // #i68520#
    1359        5199 :             if ( nNewSize != 0 )
    1360             :             {
    1361         120 :                 InvalidateObjRectWithSpaces();
    1362             :             }
    1363             :         }
    1364             :     }
    1365        5374 :     ColUnlock();
    1366        5374 : }
    1367             : 
    1368             : // OD 14.03.2003 #i11760# - change parameter <bNoColl>: type <bool>;
    1369             : //                          default value = false.
    1370             : // OD 14.03.2003 #i11760# - add new parameter <bNoCalcFollow> with
    1371             : //                          default value = false.
    1372             : // OD 11.04.2003 #108824# - new parameter <bNoCalcFollow> was used by method
    1373             : //                          <FormatWidthCols(..)> to avoid follow formatting
    1374             : //                          for text frames. But, unformatted follows causes
    1375             : //                          problems in method <SwContentFrm::_WouldFit(..)>,
    1376             : //                          which assumes that the follows are formatted.
    1377             : //                          Thus, <bNoCalcFollow> no longer used by <FormatWidthCols(..)>.
    1378         916 : void CalcContent( SwLayoutFrm *pLay,
    1379             :                 bool bNoColl,
    1380             :                 bool bNoCalcFollow )
    1381             : {
    1382             :     SwSectionFrm* pSect;
    1383         916 :     bool bCollect = false;
    1384         916 :     if( pLay->IsSctFrm() )
    1385             :     {
    1386         916 :         pSect = static_cast<SwSectionFrm*>(pLay);
    1387         916 :         if( pSect->IsEndnAtEnd() && !bNoColl )
    1388             :         {
    1389          15 :             bCollect = true;
    1390          15 :             SwLayouter::CollectEndnotes( pLay->GetFormat()->GetDoc(), pSect );
    1391             :         }
    1392         916 :         pSect->CalcFootnoteContent();
    1393             :     }
    1394             :     else
    1395           0 :         pSect = NULL;
    1396         916 :     SwFrm *pFrm = pLay->ContainsAny();
    1397         916 :     if ( !pFrm )
    1398             :     {
    1399         100 :         if( pSect )
    1400             :         {
    1401         100 :             if( pSect->HasFollow() )
    1402          56 :                 pFrm = pSect->GetFollow()->ContainsAny();
    1403         100 :             if( !pFrm )
    1404             :             {
    1405          44 :                 if( pSect->IsEndnAtEnd() )
    1406             :                 {
    1407           0 :                     if( bCollect )
    1408           0 :                         pLay->GetFormat()->GetDoc()->getIDocumentLayoutAccess().GetLayouter()->
    1409           0 :                             InsertEndnotes( pSect );
    1410           0 :                     bool bLock = pSect->IsFootnoteLock();
    1411           0 :                     pSect->SetFootnoteLock( true );
    1412           0 :                     pSect->CalcFootnoteContent();
    1413           0 :                     pSect->CalcFootnoteContent();
    1414           0 :                     pSect->SetFootnoteLock( bLock );
    1415             :                 }
    1416          44 :                 return;
    1417             :             }
    1418          56 :             pFrm->_InvalidatePos();
    1419             :         }
    1420             :         else
    1421           0 :             return;
    1422             :     }
    1423         872 :     pFrm->InvalidatePage();
    1424             : 
    1425             :     do
    1426             :     {
    1427             :         // local variables to avoid loops caused by anchored object positioning
    1428         887 :         SwAnchoredObject* pAgainObj1 = 0;
    1429         887 :         SwAnchoredObject* pAgainObj2 = 0;
    1430             : 
    1431             :         // FME 2007-08-30 #i81146# new loop control
    1432         887 :         int nLoopControlRuns = 0;
    1433         887 :         const int nLoopControlMax = 20;
    1434         887 :         const SwFrm* pLoopControlCond = 0;
    1435             : 
    1436             :         SwFrm* pLast;
    1437        4673 :         do
    1438             :         {
    1439        4673 :             pLast = pFrm;
    1440        9346 :             if( pFrm->IsVertical() ?
    1441           0 :                 ( pFrm->GetUpper()->Prt().Height() != pFrm->Frm().Height() )
    1442        4673 :                 : ( pFrm->GetUpper()->Prt().Width() != pFrm->Frm().Width() ) )
    1443             :             {
    1444         481 :                 pFrm->Prepare( PREP_FIXSIZE_CHG );
    1445         481 :                 pFrm->_InvalidateSize();
    1446             :             }
    1447             : 
    1448        4673 :             if ( pFrm->IsTabFrm() )
    1449             :             {
    1450          21 :                 static_cast<SwTabFrm*>(pFrm)->m_bCalcLowers = true;
    1451             :                 // OD 26.08.2003 #i18103# - lock move backward of follow table,
    1452             :                 // if no section content is formatted or follow table belongs
    1453             :                 // to the section, which content is formatted.
    1454          21 :                 if ( static_cast<SwTabFrm*>(pFrm)->IsFollow() &&
    1455           0 :                      ( !pSect || pSect == pFrm->FindSctFrm() ) )
    1456             :                 {
    1457           0 :                     static_cast<SwTabFrm*>(pFrm)->m_bLockBackMove = true;
    1458             :                 }
    1459             :             }
    1460             : 
    1461             :             // OD 14.03.2003 #i11760# - forbid format of follow, if requested.
    1462        4673 :             if ( bNoCalcFollow && pFrm->IsTextFrm() )
    1463           0 :                 static_cast<SwTextFrm*>(pFrm)->ForbidFollowFormat();
    1464             : 
    1465        4673 :             pFrm->Calc();
    1466             : 
    1467             :             // OD 14.03.2003 #i11760# - reset control flag for follow format.
    1468        4673 :             if ( pFrm->IsTextFrm() )
    1469             :             {
    1470        4652 :                 static_cast<SwTextFrm*>(pFrm)->AllowFollowFormat();
    1471             :             }
    1472             : 
    1473             :             // #111937# The keep-attribute can cause the position
    1474             :             // of the prev to be invalid:
    1475             :             // OD 2004-03-15 #116560# - Do not consider invalid previous frame
    1476             :             // due to its keep-attribute, if current frame is a follow or is locked.
    1477             :             // #i44049# - do not consider invalid previous
    1478             :             // frame due to its keep-attribute, if it can't move forward.
    1479             :             // #i57765# - do not consider invalid previous
    1480             :             // frame, if current frame has a column/page break before attribute.
    1481        4673 :             SwFrm* pTmpPrev = pFrm->FindPrev();
    1482        4673 :             SwFlowFrm* pTmpPrevFlowFrm = pTmpPrev && pTmpPrev->IsFlowFrm() ? SwFlowFrm::CastFlowFrm(pTmpPrev) : 0;
    1483        4673 :             SwFlowFrm* pTmpFlowFrm     = pFrm->IsFlowFrm() ? SwFlowFrm::CastFlowFrm(pFrm) : 0;
    1484             : 
    1485        8978 :             bool bPrevInvalid = pTmpPrevFlowFrm && pTmpFlowFrm &&
    1486        8864 :                                !pTmpFlowFrm->IsFollow() &&
    1487        8750 :                                !StackHack::IsLocked() && // #i76382#
    1488        8528 :                                !pTmpFlowFrm->IsJoinLocked() &&
    1489        4157 :                                !pTmpPrev->GetValidPosFlag() &&
    1490           6 :                                 pLay->IsAnLower( pTmpPrev ) &&
    1491        4675 :                                 pTmpPrevFlowFrm->IsKeep( *pTmpPrev->GetAttrSet() ) &&
    1492        4673 :                                 pTmpPrevFlowFrm->IsKeepFwdMoveAllowed();
    1493             : 
    1494             :             // format floating screen objects anchored to the frame.
    1495        4673 :             bool bRestartLayoutProcess = false;
    1496        4673 :             if ( !bPrevInvalid && pFrm->GetDrawObjs() && pLay->IsAnLower( pFrm ) )
    1497             :             {
    1498          72 :                 bool bAgain = false;
    1499          72 :                 SwPageFrm* pPageFrm = pFrm->FindPageFrm();
    1500          72 :                 size_t nCnt = pFrm->GetDrawObjs()->size();
    1501          72 :                 size_t i = 0;
    1502         207 :                 while ( i < nCnt )
    1503             :                 {
    1504             :                     // #i28701#
    1505          72 :                     SwAnchoredObject* pAnchoredObj = (*pFrm->GetDrawObjs())[i];
    1506             : 
    1507             :                     // determine if anchored object has to be
    1508             :                     // formatted and, in case, format it
    1509          72 :                     if ( !pAnchoredObj->PositionLocked() && pAnchoredObj->IsFormatPossible() )
    1510             :                     {
    1511             :                         // #i43737# - no invalidation of
    1512             :                         // anchored object needed - causes loops for as-character
    1513             :                         // anchored objects.
    1514             :                         //pAnchoredObj->InvalidateObjPos();
    1515          39 :                         SwRect aRect( pAnchoredObj->GetObjRect() );
    1516          39 :                         if ( !SwObjectFormatter::FormatObj( *pAnchoredObj, pFrm, pPageFrm ) )
    1517             :                         {
    1518           5 :                             bRestartLayoutProcess = true;
    1519          14 :                             break;
    1520             :                         }
    1521             :                         // #i3317# - restart layout process,
    1522             :                         // if the position of the anchored object is locked now.
    1523          34 :                         if ( pAnchoredObj->PositionLocked() )
    1524             :                         {
    1525           4 :                             bRestartLayoutProcess = true;
    1526           4 :                             break;
    1527             :                         }
    1528             : 
    1529          30 :                         if ( aRect != pAnchoredObj->GetObjRect() )
    1530             :                         {
    1531           0 :                             bAgain = true;
    1532           0 :                             if ( pAgainObj2 == pAnchoredObj )
    1533             :                             {
    1534             :                                 OSL_FAIL( "::CalcContent(..) - loop detected, perform attribute changes to avoid the loop" );
    1535             :                                 // Prevent oscillation
    1536           0 :                                 SwFrameFormat& rFormat = pAnchoredObj->GetFrameFormat();
    1537           0 :                                 SwFormatSurround aAttr( rFormat.GetSurround() );
    1538           0 :                                 if( SURROUND_THROUGHT != aAttr.GetSurround() )
    1539             :                                 {
    1540             :                                     // When on auto position, we can only set it to
    1541             :                                     // flow through
    1542           0 :                                     if ((rFormat.GetAnchor().GetAnchorId() ==
    1543           0 :                                             FLY_AT_CHAR) &&
    1544             :                                         (SURROUND_PARALLEL ==
    1545           0 :                                             aAttr.GetSurround()))
    1546             :                                     {
    1547           0 :                                         aAttr.SetSurround( SURROUND_THROUGHT );
    1548             :                                     }
    1549             :                                     else
    1550             :                                     {
    1551           0 :                                         aAttr.SetSurround( SURROUND_PARALLEL );
    1552             :                                     }
    1553           0 :                                     rFormat.LockModify();
    1554           0 :                                     rFormat.SetFormatAttr( aAttr );
    1555           0 :                                     rFormat.UnlockModify();
    1556           0 :                                 }
    1557             :                             }
    1558             :                             else
    1559             :                             {
    1560           0 :                                 if ( pAgainObj1 == pAnchoredObj )
    1561           0 :                                     pAgainObj2 = pAnchoredObj;
    1562           0 :                                 pAgainObj1 = pAnchoredObj;
    1563             :                             }
    1564             :                         }
    1565             : 
    1566          30 :                         if ( !pFrm->GetDrawObjs() )
    1567           0 :                             break;
    1568          30 :                         if ( pFrm->GetDrawObjs()->size() < nCnt )
    1569             :                         {
    1570           0 :                             --nCnt;
    1571             :                             // Do not increment index, in this case
    1572           0 :                             continue;
    1573             :                         }
    1574             :                     }
    1575          63 :                     ++i;
    1576             :                 }
    1577             : 
    1578             :                 // #i28701# - restart layout process, if
    1579             :                 // requested by floating screen object formatting
    1580          72 :                 if ( bRestartLayoutProcess )
    1581             :                 {
    1582           9 :                     pFrm = pLay->ContainsAny();
    1583           9 :                     pAgainObj1 = 0L;
    1584           9 :                     pAgainObj2 = 0L;
    1585           9 :                     continue;
    1586             :                 }
    1587             : 
    1588             :                 // OD 2004-05-17 #i28701# - format anchor frame after its objects
    1589             :                 // are formatted, if the wrapping style influence has to be considered.
    1590          63 :                 if ( pLay->GetFormat()->getIDocumentSettingAccess()->get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION) )
    1591             :                 {
    1592          33 :                     pFrm->Calc();
    1593             :                 }
    1594             : 
    1595          63 :                 if ( bAgain )
    1596             :                 {
    1597           0 :                     pFrm = pLay->ContainsContent();
    1598           0 :                     if ( pFrm && pFrm->IsInTab() )
    1599           0 :                         pFrm = pFrm->FindTabFrm();
    1600           0 :                     if( pFrm && pFrm->IsInSct() )
    1601             :                     {
    1602           0 :                         SwSectionFrm* pTmp = pFrm->FindSctFrm();
    1603           0 :                         if( pTmp != pLay && pLay->IsAnLower( pTmp ) )
    1604           0 :                             pFrm = pTmp;
    1605             :                     }
    1606             : 
    1607           0 :                     if ( pFrm == pLoopControlCond )
    1608           0 :                         ++nLoopControlRuns;
    1609             :                     else
    1610             :                     {
    1611           0 :                         nLoopControlRuns = 0;
    1612           0 :                         pLoopControlCond = pFrm;
    1613             :                     }
    1614             : 
    1615           0 :                     if ( nLoopControlRuns < nLoopControlMax )
    1616           0 :                         continue;
    1617             : 
    1618             :                     OSL_FAIL( "LoopControl in CalcContent" );
    1619             :                 }
    1620             :             }
    1621        4664 :             if ( pFrm->IsTabFrm() )
    1622             :             {
    1623          21 :                 if ( static_cast<SwTabFrm*>(pFrm)->IsFollow() )
    1624           0 :                     static_cast<SwTabFrm*>(pFrm)->m_bLockBackMove = false;
    1625             :             }
    1626             : 
    1627        4664 :             pFrm = bPrevInvalid ? pTmpPrev : pFrm->FindNext();
    1628        4664 :             if( !bPrevInvalid && pFrm && pFrm->IsSctFrm() && pSect )
    1629             :             {
    1630             :                 // Empty SectionFrms could be present here
    1631        2815 :                 while( pFrm && pFrm->IsSctFrm() && !static_cast<SwSectionFrm*>(pFrm)->GetSection() )
    1632        1089 :                     pFrm = pFrm->FindNext();
    1633             : 
    1634             :                 // If FindNext returns the Follow of the original Area, we want to
    1635             :                 // continue with this content as long as it flows back.
    1636        1296 :                 if( pFrm && pFrm->IsSctFrm() && ( pFrm == pSect->GetFollow() ||
    1637         433 :                     static_cast<SwSectionFrm*>(pFrm)->IsAnFollow( pSect ) ) )
    1638             :                 {
    1639         364 :                     pFrm = static_cast<SwSectionFrm*>(pFrm)->ContainsAny();
    1640         364 :                     if( pFrm )
    1641         326 :                         pFrm->_InvalidatePos();
    1642             :                 }
    1643             :             }
    1644             :           // Stay in the pLay
    1645             :           // Except for SectionFrms with Follow: the first ContentFrm of the Follow
    1646             :           // will be formatted, so that it get's a chance to load in the pLay.
    1647             :           // As long as these Frames are loading in pLay, we continue
    1648       12968 :         } while ( pFrm &&
    1649        5542 :                   ( pLay->IsAnLower( pFrm ) ||
    1650        1033 :                     ( pSect &&
    1651        1530 :                       ( ( pSect->HasFollow() &&
    1652         684 :                           ( pLay->IsAnLower( pLast ) ||
    1653         374 :                             ( pLast->IsInSct() &&
    1654         497 :                               pLast->FindSctFrm()->IsAnFollow(pSect) ) ) &&
    1655        1033 :                           pSect->GetFollow()->IsAnLower( pFrm )  ) ||
    1656        1246 :                         ( pFrm->IsInSct() &&
    1657         523 :                           pFrm->FindSctFrm()->IsAnFollow( pSect ) ) ) ) ) );
    1658         887 :         if( pSect )
    1659             :         {
    1660         887 :             if( bCollect )
    1661             :             {
    1662          15 :                 pLay->GetFormat()->GetDoc()->getIDocumentLayoutAccess().GetLayouter()->InsertEndnotes(pSect);
    1663          15 :                 pSect->CalcFootnoteContent();
    1664             :             }
    1665         887 :             if( pSect->HasFollow() )
    1666             :             {
    1667         213 :                 SwSectionFrm* pNxt = pSect->GetFollow();
    1668         444 :                 while( pNxt && !pNxt->ContainsContent() )
    1669          18 :                     pNxt = pNxt->GetFollow();
    1670         213 :                 if( pNxt )
    1671         195 :                     pNxt->CalcFootnoteContent();
    1672             :             }
    1673         887 :             if( bCollect )
    1674             :             {
    1675          15 :                 pFrm = pLay->ContainsAny();
    1676          15 :                 bCollect = false;
    1677          15 :                 if( pFrm )
    1678          15 :                     continue;
    1679             :             }
    1680             :         }
    1681         872 :         break;
    1682             :     }
    1683          15 :     while( true );
    1684             : }
    1685             : 
    1686             : // OD 2004-03-23 #i26791#
    1687          52 : void SwFlyFrm::MakeObjPos()
    1688             : {
    1689          52 :     if ( !mbValidPos )
    1690             :     {
    1691          52 :         mbValidPos = true;
    1692             : 
    1693             :         // OD 29.10.2003 #113049# - use new class to position object
    1694          52 :         GetAnchorFrm()->Calc();
    1695             :         objectpositioning::SwToLayoutAnchoredObjectPosition
    1696          52 :                 aObjPositioning( *GetVirtDrawObj() );
    1697          52 :         aObjPositioning.CalcPosition();
    1698             : 
    1699             :         // #i58280#
    1700             :         // update relative position
    1701          52 :         SetCurrRelPos( aObjPositioning.GetRelPos() );
    1702             : 
    1703          52 :         SWRECTFN( GetAnchorFrm() );
    1704          52 :         maFrm.Pos( aObjPositioning.GetRelPos() );
    1705          52 :         maFrm.Pos() += (GetAnchorFrm()->Frm().*fnRect->fnGetPos)();
    1706             :         // #i69335#
    1707          52 :         InvalidateObjRectWithSpaces();
    1708             :     }
    1709          52 : }
    1710             : 
    1711        5374 : void SwFlyFrm::MakePrtArea( const SwBorderAttrs &rAttrs )
    1712             : {
    1713        5374 :     if ( !mbValidPrtArea )
    1714             :     {
    1715        5374 :         mbValidPrtArea = true;
    1716             : 
    1717             :         // OD 31.07.2003 #110978# - consider vertical layout
    1718        5374 :         SWRECTFN( this )
    1719        5374 :         (this->*fnRect->fnSetXMargins)( rAttrs.CalcLeftLine(),
    1720       10748 :                                         rAttrs.CalcRightLine() );
    1721        5374 :         (this->*fnRect->fnSetYMargins)( rAttrs.CalcTopLine(),
    1722       10748 :                                         rAttrs.CalcBottomLine() );
    1723             :     }
    1724        5374 : }
    1725             : 
    1726        5876 : void SwFlyFrm::MakeContentPos( const SwBorderAttrs &rAttrs )
    1727             : {
    1728        5876 :     if ( !m_bValidContentPos )
    1729             :     {
    1730        5876 :         m_bValidContentPos = true;
    1731             : 
    1732        5876 :         const SwTwips nUL = rAttrs.CalcTopLine()  + rAttrs.CalcBottomLine();
    1733        5876 :         Size aRelSize( CalcRel( GetFormat()->GetFrmSize() ) );
    1734             : 
    1735        5876 :         SWRECTFN( this )
    1736        5876 :         long nMinHeight = 0;
    1737        5876 :         if( IsMinHeight() )
    1738         331 :             nMinHeight = bVert ? aRelSize.Width() : aRelSize.Height();
    1739             : 
    1740        5876 :         Point aNewContentPos;
    1741        5876 :         aNewContentPos = Prt().Pos();
    1742        5876 :         const SdrTextVertAdjust nAdjust = GetFormat()->GetTextVertAdjust().GetValue();
    1743             : 
    1744        5876 :         if( nAdjust != SDRTEXTVERTADJUST_TOP )
    1745             :         {
    1746        1023 :             const SwTwips nContentHeight = CalcContentHeight(&rAttrs, nMinHeight, nUL);
    1747        1023 :             SwTwips nDiff = 0;
    1748             : 
    1749        1023 :             if( nContentHeight != 0)
    1750         517 :                 nDiff = (Prt().*fnRect->fnGetHeight)() - nContentHeight;
    1751             : 
    1752        1023 :             if( nDiff > 0 )
    1753             :             {
    1754         480 :                 if( nAdjust == SDRTEXTVERTADJUST_CENTER )
    1755             :                 {
    1756         442 :                     if( bVertL2R )
    1757           0 :                         aNewContentPos.setX(aNewContentPos.getX() + nDiff/2);
    1758         442 :                     else if( bVert )
    1759           0 :                         aNewContentPos.setX(aNewContentPos.getX() - nDiff/2);
    1760             :                     else
    1761         442 :                         aNewContentPos.setY(aNewContentPos.getY() + nDiff/2);
    1762             :                 }
    1763          38 :                 else if( nAdjust == SDRTEXTVERTADJUST_BOTTOM )
    1764             :                 {
    1765          38 :                     if( bVertL2R )
    1766           0 :                         aNewContentPos.setX(aNewContentPos.getX() + nDiff);
    1767          38 :                     else if( bVert )
    1768           0 :                         aNewContentPos.setX(aNewContentPos.getX() - nDiff);
    1769             :                     else
    1770          38 :                         aNewContentPos.setY(aNewContentPos.getY() + nDiff);
    1771             :                 }
    1772             :             }
    1773             :         }
    1774        5876 :         if( aNewContentPos != ContentPos() )
    1775             :         {
    1776         468 :             ContentPos() = aNewContentPos;
    1777        1105 :             for( SwFrm *pFrm = Lower(); pFrm; pFrm = pFrm->GetNext())
    1778             :             {
    1779         637 :                 pFrm->InvalidatePos();
    1780             :             }
    1781             :         }
    1782             :     }
    1783        5876 : }
    1784             : 
    1785         663 : void SwFlyFrm::InvalidateContentPos()
    1786             : {
    1787         663 :     m_bValidContentPos = false;
    1788         663 :     _Invalidate();
    1789         663 : }
    1790             : 
    1791         809 : SwTwips SwFlyFrm::_Grow( SwTwips nDist, bool bTst )
    1792             : {
    1793         809 :     SWRECTFN( this )
    1794         809 :     if ( Lower() && !IsColLocked() && !HasFixSize() )
    1795             :     {
    1796         655 :         SwTwips nSize = (Frm().*fnRect->fnGetHeight)();
    1797         655 :         if( nSize > 0 && nDist > ( LONG_MAX - nSize ) )
    1798           0 :             nDist = LONG_MAX - nSize;
    1799             : 
    1800         655 :         if ( nDist <= 0L )
    1801           0 :             return 0L;
    1802             : 
    1803         655 :         if ( Lower()->IsColumnFrm() )
    1804             :         {   // If it's a Column Frame, the Format takes control of the
    1805             :             // resizing (due to the adjustment).
    1806           0 :             if ( !bTst )
    1807             :             {
    1808             :                 // #i28701# - unlock position of Writer fly frame
    1809           0 :                 UnlockPosition();
    1810           0 :                 _InvalidatePos();
    1811           0 :                 InvalidateSize();
    1812             :             }
    1813           0 :             return 0L;
    1814             :         }
    1815             : 
    1816         655 :         if ( !bTst )
    1817             :         {
    1818         655 :             const SwRect aOld( GetObjRectWithSpaces() );
    1819         655 :             _InvalidateSize();
    1820         655 :             const bool bOldLock = bLocked;
    1821         655 :             Unlock();
    1822         655 :             if ( IsFlyFreeFrm() )
    1823             :             {
    1824             :                 // #i37068# - no format of position here
    1825             :                 // and prevent move in method <CheckClip(..)>.
    1826             :                 // This is needed to prevent layout loop caused by nested
    1827             :                 // Writer fly frames - inner Writer fly frames format its
    1828             :                 // anchor, which grows/shrinks the outer Writer fly frame.
    1829             :                 // Note: position will be invalidated below.
    1830         640 :                 mbValidPos = true;
    1831             :                 // #i55416#
    1832             :                 // Suppress format of width for autowidth frame, because the
    1833             :                 // format of the width would call <SwTextFrm::CalcFitToContent()>
    1834             :                 // for the lower frame, which initiated this grow.
    1835         640 :                 const bool bOldFormatHeightOnly = bFormatHeightOnly;
    1836         640 :                 const SwFormatFrmSize& rFrmSz = GetFormat()->GetFrmSize();
    1837         640 :                 if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
    1838             :                 {
    1839         174 :                     bFormatHeightOnly = true;
    1840             :                 }
    1841         640 :                 static_cast<SwFlyFreeFrm*>(this)->SetNoMoveOnCheckClip( true );
    1842         640 :                 static_cast<SwFlyFreeFrm*>(this)->SwFlyFreeFrm::MakeAll();
    1843         640 :                 static_cast<SwFlyFreeFrm*>(this)->SetNoMoveOnCheckClip( false );
    1844             :                 // #i55416#
    1845         640 :                 if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
    1846             :                 {
    1847         174 :                     bFormatHeightOnly = bOldFormatHeightOnly;
    1848             :                 }
    1849             :             }
    1850             :             else
    1851          15 :                 MakeAll();
    1852         655 :             _InvalidateSize();
    1853         655 :             InvalidatePos();
    1854         655 :             if ( bOldLock )
    1855           0 :                 Lock();
    1856         655 :             const SwRect aNew( GetObjRectWithSpaces() );
    1857         655 :             if ( aOld != aNew )
    1858         445 :                 ::Notify( this, FindPageFrm(), aOld );
    1859         655 :             return (aNew.*fnRect->fnGetHeight)()-(aOld.*fnRect->fnGetHeight)();
    1860             :         }
    1861           0 :         return nDist;
    1862             :     }
    1863         154 :     return 0L;
    1864             : }
    1865             : 
    1866           6 : SwTwips SwFlyFrm::_Shrink( SwTwips nDist, bool bTst )
    1867             : {
    1868           6 :     if( Lower() && !IsColLocked() && !HasFixSize() && !IsNoShrink() )
    1869             :     {
    1870           4 :         SWRECTFN( this )
    1871           4 :         SwTwips nHeight = (Frm().*fnRect->fnGetHeight)();
    1872           4 :         if ( nDist > nHeight )
    1873           0 :             nDist = nHeight;
    1874             : 
    1875           4 :         SwTwips nVal = nDist;
    1876           4 :         if ( IsMinHeight() )
    1877             :         {
    1878           4 :             const SwFormatFrmSize& rFormatSize = GetFormat()->GetFrmSize();
    1879           4 :             SwTwips nFormatHeight = bVert ? rFormatSize.GetWidth() : rFormatSize.GetHeight();
    1880             : 
    1881           4 :             nVal = std::min( nDist, nHeight - nFormatHeight );
    1882             :         }
    1883             : 
    1884           4 :         if ( nVal <= 0L )
    1885           0 :             return 0L;
    1886             : 
    1887           4 :         if ( Lower()->IsColumnFrm() )
    1888             :         {   // If it's a Column Frame, the Format takes control of the
    1889             :             // resizing (due to the adjustment).
    1890           0 :             if ( !bTst )
    1891             :             {
    1892           0 :                 SwRect aOld( GetObjRectWithSpaces() );
    1893           0 :                 (Frm().*fnRect->fnSetHeight)( nHeight - nVal );
    1894             :                 // #i68520#
    1895           0 :                 if ( nHeight - nVal != 0 )
    1896             :                 {
    1897           0 :                     InvalidateObjRectWithSpaces();
    1898             :                 }
    1899           0 :                 nHeight = (Prt().*fnRect->fnGetHeight)();
    1900           0 :                 (Prt().*fnRect->fnSetHeight)( nHeight - nVal );
    1901           0 :                 _InvalidatePos();
    1902           0 :                 InvalidateSize();
    1903           0 :                 ::Notify( this, FindPageFrm(), aOld );
    1904           0 :                 NotifyDrawObj();
    1905           0 :                 if ( GetAnchorFrm()->IsInFly() )
    1906           0 :                     AnchorFrm()->FindFlyFrm()->Shrink( nDist, bTst );
    1907             :             }
    1908           0 :             return 0L;
    1909             :         }
    1910             : 
    1911           4 :         if ( !bTst )
    1912             :         {
    1913           4 :             const SwRect aOld( GetObjRectWithSpaces() );
    1914           4 :             _InvalidateSize();
    1915           4 :             const bool bOldLocked = bLocked;
    1916           4 :             Unlock();
    1917           4 :             if ( IsFlyFreeFrm() )
    1918             :             {
    1919             :                 // #i37068# - no format of position here
    1920             :                 // and prevent move in method <CheckClip(..)>.
    1921             :                 // This is needed to prevent layout loop caused by nested
    1922             :                 // Writer fly frames - inner Writer fly frames format its
    1923             :                 // anchor, which grows/shrinks the outer Writer fly frame.
    1924             :                 // Note: position will be invalidated below.
    1925           2 :                 mbValidPos = true;
    1926             :                 // #i55416#
    1927             :                 // Suppress format of width for autowidth frame, because the
    1928             :                 // format of the width would call <SwTextFrm::CalcFitToContent()>
    1929             :                 // for the lower frame, which initiated this shrink.
    1930           2 :                 const bool bOldFormatHeightOnly = bFormatHeightOnly;
    1931           2 :                 const SwFormatFrmSize& rFrmSz = GetFormat()->GetFrmSize();
    1932           2 :                 if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
    1933             :                 {
    1934           1 :                     bFormatHeightOnly = true;
    1935             :                 }
    1936           2 :                 static_cast<SwFlyFreeFrm*>(this)->SetNoMoveOnCheckClip( true );
    1937           2 :                 static_cast<SwFlyFreeFrm*>(this)->SwFlyFreeFrm::MakeAll();
    1938           2 :                 static_cast<SwFlyFreeFrm*>(this)->SetNoMoveOnCheckClip( false );
    1939             :                 // #i55416#
    1940           2 :                 if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
    1941             :                 {
    1942           1 :                     bFormatHeightOnly = bOldFormatHeightOnly;
    1943             :                 }
    1944             :             }
    1945             :             else
    1946           2 :                 MakeAll();
    1947           4 :             _InvalidateSize();
    1948           4 :             InvalidatePos();
    1949           4 :             if ( bOldLocked )
    1950           0 :                 Lock();
    1951           4 :             const SwRect aNew( GetObjRectWithSpaces() );
    1952           4 :             if ( aOld != aNew )
    1953             :             {
    1954           4 :                 ::Notify( this, FindPageFrm(), aOld );
    1955           4 :                 if ( GetAnchorFrm()->IsInFly() )
    1956           0 :                     AnchorFrm()->FindFlyFrm()->Shrink( nDist, bTst );
    1957             :             }
    1958           4 :             return (aOld.*fnRect->fnGetHeight)() -
    1959           4 :                    (aNew.*fnRect->fnGetHeight)();
    1960             :         }
    1961           0 :         return nVal;
    1962             :     }
    1963           2 :     return 0L;
    1964             : }
    1965             : 
    1966           9 : Size SwFlyFrm::ChgSize( const Size& aNewSize )
    1967             : {
    1968             :     // #i53298#
    1969             :     // If the fly frame anchored at-paragraph or at-character contains an OLE
    1970             :     // object, assure that the new size fits into the current clipping area
    1971             :     // of the fly frame
    1972           9 :     Size aAdjustedNewSize( aNewSize );
    1973             :     {
    1974          19 :         if ( dynamic_cast<SwFlyAtCntFrm*>(this) &&
    1975          20 :              Lower() && dynamic_cast<SwNoTextFrm*>(Lower()) &&
    1976           1 :              static_cast<SwNoTextFrm*>(Lower())->GetNode()->GetOLENode() )
    1977             :         {
    1978           1 :             SwRect aClipRect;
    1979           1 :             ::CalcClipRect( GetVirtDrawObj(), aClipRect, false );
    1980           1 :             if ( aAdjustedNewSize.Width() > aClipRect.Width() )
    1981             :             {
    1982           0 :                 aAdjustedNewSize.setWidth( aClipRect.Width() );
    1983             :             }
    1984           1 :             if ( aAdjustedNewSize.Height() > aClipRect.Height() )
    1985             :             {
    1986           0 :                 aAdjustedNewSize.setWidth( aClipRect.Height() );
    1987             :             }
    1988             :         }
    1989             :     }
    1990           9 :     if ( aAdjustedNewSize != Frm().SSize() )
    1991             :     {
    1992           9 :         SwFrameFormat *pFormat = GetFormat();
    1993           9 :         SwFormatFrmSize aSz( pFormat->GetFrmSize() );
    1994           9 :         aSz.SetWidth( aAdjustedNewSize.Width() );
    1995           9 :         aSz.SetHeight( aAdjustedNewSize.Height() );
    1996             :         // go via the Doc for UNDO
    1997           9 :         pFormat->GetDoc()->SetAttr( aSz, *pFormat );
    1998           9 :         return aSz.GetSize();
    1999             :     }
    2000             :     else
    2001           0 :         return Frm().SSize();
    2002             : }
    2003             : 
    2004        6878 : bool SwFlyFrm::IsLowerOf( const SwLayoutFrm* pUpperFrm ) const
    2005             : {
    2006             :     OSL_ENSURE( GetAnchorFrm(), "8-( Fly is lost in Space." );
    2007        6878 :     const SwFrm* pFrm = GetAnchorFrm();
    2008       28706 :     do
    2009             :     {
    2010       28751 :         if ( pFrm == pUpperFrm )
    2011          45 :             return true;
    2012       28706 :         pFrm = pFrm->IsFlyFrm()
    2013           1 :                ? static_cast<const SwFlyFrm*>(pFrm)->GetAnchorFrm()
    2014       28707 :                : pFrm->GetUpper();
    2015             :     } while ( pFrm );
    2016        6833 :     return false;
    2017             : }
    2018             : 
    2019          11 : void SwFlyFrm::Cut()
    2020             : {
    2021          11 : }
    2022             : 
    2023        2214 : void SwFrm::AppendFly( SwFlyFrm *pNew )
    2024             : {
    2025        2214 :     if ( !mpDrawObjs )
    2026        1207 :         mpDrawObjs = new SwSortedObjs();
    2027        2214 :     mpDrawObjs->Insert( *pNew );
    2028        2214 :     pNew->ChgAnchorFrm( this );
    2029             : 
    2030             :     // Register at the page
    2031             :     // If there's none present, register via SwPageFrm::PreparePage
    2032        2214 :     SwPageFrm* pPage = FindPageFrm();
    2033        2214 :     if ( pPage != NULL )
    2034             :     {
    2035        1808 :         pPage->AppendFlyToPage( pNew );
    2036             :     }
    2037        2214 : }
    2038             : 
    2039        2214 : void SwFrm::RemoveFly( SwFlyFrm *pToRemove )
    2040             : {
    2041             :     // Deregister from the page
    2042             :     // Could already have happened, if the page was already destructed
    2043        2214 :     SwPageFrm *pPage = pToRemove->FindPageFrm();
    2044        2214 :     if ( pPage && pPage->GetSortedObjs() )
    2045             :     {
    2046         183 :         pPage->RemoveFlyFromPage( pToRemove );
    2047             :     }
    2048             :     // #i73201#
    2049             :     else
    2050             :     {
    2051        6093 :         if ( pToRemove->IsAccessibleFrm() &&
    2052        4062 :              pToRemove->GetFormat() &&
    2053        2031 :              !pToRemove->IsFlyInCntFrm() )
    2054             :         {
    2055        1217 :             SwRootFrm *pRootFrm = getRootFrm();
    2056        1217 :             if( pRootFrm && pRootFrm->IsAnyShellAccessible() )
    2057             :             {
    2058           0 :                 SwViewShell *pVSh = pRootFrm->GetCurrShell();
    2059           0 :                 if( pVSh && pVSh->Imp() )
    2060             :                 {
    2061           0 :                     pVSh->Imp()->DisposeAccessibleFrm( pToRemove );
    2062             :                 }
    2063             :             }
    2064             :         }
    2065             :     }
    2066             : 
    2067        2214 :     mpDrawObjs->Remove( *pToRemove );
    2068        2214 :     if ( !mpDrawObjs->size() )
    2069        1253 :         DELETEZ( mpDrawObjs );
    2070             : 
    2071        2214 :     pToRemove->ChgAnchorFrm( 0 );
    2072             : 
    2073        2214 :     if ( !pToRemove->IsFlyInCntFrm() && GetUpper() && IsInTab() )//MA_FLY_HEIGHT
    2074          16 :         GetUpper()->InvalidateSize();
    2075        2214 : }
    2076             : 
    2077        2180 : void SwFrm::AppendDrawObj( SwAnchoredObject& _rNewObj )
    2078             : {
    2079             :     assert(!mpDrawObjs || mpDrawObjs->is_sorted());
    2080             : 
    2081        2180 :     if ( !_rNewObj.ISA(SwAnchoredDrawObject) )
    2082             :     {
    2083             :         OSL_FAIL( "SwFrm::AppendDrawObj(..) - anchored object of unexpected type -> object not appended" );
    2084        2180 :         return;
    2085             :     }
    2086             : 
    2087        6177 :     if ( !_rNewObj.GetDrawObj()->ISA(SwDrawVirtObj) &&
    2088        2180 :          _rNewObj.GetAnchorFrm() && _rNewObj.GetAnchorFrm() != this )
    2089             :     {
    2090             :         assert(!mpDrawObjs || mpDrawObjs->is_sorted());
    2091             :         // perform disconnect from layout, if 'master' drawing object is appended
    2092             :         // to a new frame.
    2093           0 :         static_cast<SwDrawContact*>(::GetUserCall( _rNewObj.GetDrawObj() ))->
    2094           0 :                                                 DisconnectFromLayout( false );
    2095             :         assert(!mpDrawObjs || mpDrawObjs->is_sorted());
    2096             :     }
    2097             : 
    2098        2180 :     if ( _rNewObj.GetAnchorFrm() != this )
    2099             :     {
    2100        2180 :         if ( !mpDrawObjs )
    2101        1247 :             mpDrawObjs = new SwSortedObjs();
    2102        2180 :         mpDrawObjs->Insert( _rNewObj );
    2103        2180 :         _rNewObj.ChgAnchorFrm( this );
    2104             :     }
    2105             : 
    2106             :     // #i113730#
    2107             :     // Assure the control objects and group objects containing controls are on the control layer
    2108        2180 :     if ( ::CheckControlLayer( _rNewObj.DrawObj() ) )
    2109             :     {
    2110         271 :         const IDocumentDrawModelAccess* pIDDMA = getIDocumentDrawModelAccess();
    2111         271 :         const SdrLayerID aCurrentLayer(_rNewObj.DrawObj()->GetLayer());
    2112         271 :         const SdrLayerID aControlLayerID(pIDDMA->GetControlsId());
    2113         271 :         const SdrLayerID aInvisibleControlLayerID(pIDDMA->GetInvisibleControlsId());
    2114             : 
    2115         271 :         if(aCurrentLayer != aControlLayerID && aCurrentLayer != aInvisibleControlLayerID)
    2116             :         {
    2117           0 :             if ( aCurrentLayer == pIDDMA->GetInvisibleHellId() ||
    2118           0 :                  aCurrentLayer == pIDDMA->GetInvisibleHeavenId() )
    2119             :             {
    2120           0 :                 _rNewObj.DrawObj()->SetLayer(aInvisibleControlLayerID);
    2121             :             }
    2122             :             else
    2123             :             {
    2124           0 :                 _rNewObj.DrawObj()->SetLayer(aControlLayerID);
    2125             :             }
    2126             :             //The layer is part of the key used to sort the obj, so update
    2127             :             //its position if the layer changed.
    2128           0 :             mpDrawObjs->Update(_rNewObj);
    2129             :         }
    2130             :     }
    2131             : 
    2132             :     // no direct positioning needed, but invalidate the drawing object position
    2133        2180 :     _rNewObj.InvalidateObjPos();
    2134             : 
    2135             :     // register at page frame
    2136        2180 :     SwPageFrm* pPage = FindPageFrm();
    2137        2180 :     if ( pPage )
    2138             :     {
    2139        1809 :         pPage->AppendDrawObjToPage( _rNewObj );
    2140             :     }
    2141             : 
    2142             :     // Notify accessible layout.
    2143        2180 :     SwViewShell* pSh = getRootFrm()->GetCurrShell();
    2144        2180 :     if( pSh )
    2145             :     {
    2146        2100 :         SwRootFrm* pLayout = getRootFrm();
    2147        2100 :         if( pLayout && pLayout->IsAnyShellAccessible() )
    2148           0 :         pSh->Imp()->AddAccessibleObj( _rNewObj.GetDrawObj() );
    2149             :     }
    2150             : 
    2151             :     assert(!mpDrawObjs || mpDrawObjs->is_sorted());
    2152             : }
    2153             : 
    2154        2180 : void SwFrm::RemoveDrawObj( SwAnchoredObject& _rToRemoveObj )
    2155             : {
    2156             :     // Notify accessible layout.
    2157        2180 :     SwViewShell* pSh = getRootFrm()->GetCurrShell();
    2158        2180 :     if( pSh )
    2159             :     {
    2160         326 :         SwRootFrm* pLayout = getRootFrm();
    2161         326 :         if( pLayout && pLayout->IsAnyShellAccessible() )
    2162           0 :         pSh->Imp()->DisposeAccessibleObj( _rToRemoveObj.GetDrawObj() );
    2163             :     }
    2164             : 
    2165             :     // deregister from page frame
    2166        2180 :     SwPageFrm* pPage = _rToRemoveObj.GetPageFrm();
    2167        2180 :     if ( pPage && pPage->GetSortedObjs() )
    2168         383 :         pPage->RemoveDrawObjFromPage( _rToRemoveObj );
    2169             : 
    2170        2180 :     mpDrawObjs->Remove( _rToRemoveObj );
    2171        2180 :     if ( !mpDrawObjs->size() )
    2172        1201 :         DELETEZ( mpDrawObjs );
    2173             : 
    2174        2180 :     _rToRemoveObj.ChgAnchorFrm( 0 );
    2175             : 
    2176             :     assert(!mpDrawObjs || mpDrawObjs->is_sorted());
    2177        2180 : }
    2178             : 
    2179       41856 : void SwFrm::InvalidateObjs( const bool _bInvaPosOnly,
    2180             :                             const bool _bNoInvaOfAsCharAnchoredObjs )
    2181             : {
    2182       41856 :     if ( GetDrawObjs() )
    2183             :     {
    2184             :         // #i26945# - determine page the frame is on,
    2185             :         // in order to check, if anchored object is registered at the same
    2186             :         // page.
    2187        2550 :         const SwPageFrm* pPageFrm = FindPageFrm();
    2188             :         // #i28701# - re-factoring
    2189        6643 :         for ( size_t i = 0; i < GetDrawObjs()->size(); ++i )
    2190             :         {
    2191        4093 :             SwAnchoredObject* pAnchoredObj = (*GetDrawObjs())[i];
    2192        8186 :             if ( _bNoInvaOfAsCharAnchoredObjs &&
    2193        4093 :                  (pAnchoredObj->GetFrameFormat().GetAnchor().GetAnchorId()
    2194             :                     == FLY_AS_CHAR) )
    2195             :             {
    2196        1208 :                 continue;
    2197             :             }
    2198             :             // #i26945# - no invalidation, if anchored object
    2199             :             // isn't registered at the same page and instead is registered at
    2200             :             // the page, where its anchor character text frame is on.
    2201        5770 :             if ( pAnchoredObj->GetPageFrm() &&
    2202        2885 :                  pAnchoredObj->GetPageFrm() != pPageFrm )
    2203             :             {
    2204          36 :                 SwTextFrm* pAnchorCharFrm = pAnchoredObj->FindAnchorCharFrm();
    2205          47 :                 if ( pAnchorCharFrm &&
    2206          11 :                      pAnchoredObj->GetPageFrm() == pAnchorCharFrm->FindPageFrm() )
    2207             :                 {
    2208           0 :                     continue;
    2209             :                 }
    2210             :                 // #115759# - unlock its position, if anchored
    2211             :                 // object isn't registered at the page, where its anchor
    2212             :                 // character text frame is on, respectively if it has no
    2213             :                 // anchor character text frame.
    2214             :                 else
    2215             :                 {
    2216          36 :                     pAnchoredObj->UnlockPosition();
    2217             :                 }
    2218             :             }
    2219             :             // #i51474# - reset flag, that anchored object
    2220             :             // has cleared environment, and unlock its position, if the anchored
    2221             :             // object is registered at the same page as the anchor frame is on.
    2222        5770 :             if ( pAnchoredObj->ClearedEnvironment() &&
    2223        2885 :                  pAnchoredObj->GetPageFrm() &&
    2224           0 :                  pAnchoredObj->GetPageFrm() == pPageFrm )
    2225             :             {
    2226           0 :                 pAnchoredObj->UnlockPosition();
    2227           0 :                 pAnchoredObj->SetClearedEnvironment( false );
    2228             :             }
    2229             :             // distinguish between writer fly frames and drawing objects
    2230        2885 :             if ( pAnchoredObj->ISA(SwFlyFrm) )
    2231             :             {
    2232        1478 :                 SwFlyFrm* pFly = static_cast<SwFlyFrm*>(pAnchoredObj);
    2233        1478 :                 pFly->_Invalidate();
    2234        1478 :                 pFly->_InvalidatePos();
    2235        1478 :                 if ( !_bInvaPosOnly )
    2236           0 :                     pFly->_InvalidateSize();
    2237             :             }
    2238             :             else
    2239             :             {
    2240        1407 :                 pAnchoredObj->InvalidateObjPos();
    2241             :             }
    2242             :         } // end of loop on objects, which are connected to the frame
    2243             :     }
    2244       41856 : }
    2245             : 
    2246             : // #i26945# - correct check, if anchored object is a lower
    2247             : // of the layout frame. E.g., anchor character text frame can be a follow text
    2248             : // frame.
    2249             : // #i44016# - add parameter <_bUnlockPosOfObjs> to
    2250             : // force an unlockposition call for the lower objects.
    2251       54960 : void SwLayoutFrm::NotifyLowerObjs( const bool _bUnlockPosOfObjs )
    2252             : {
    2253             :     // invalidate lower floating screen objects
    2254       54960 :     SwPageFrm* pPageFrm = FindPageFrm();
    2255       54960 :     if ( pPageFrm && pPageFrm->GetSortedObjs() )
    2256             :     {
    2257       16226 :         SwSortedObjs& rObjs = *(pPageFrm->GetSortedObjs());
    2258       84372 :         for ( size_t i = 0; i < rObjs.size(); ++i )
    2259             :         {
    2260       68146 :             SwAnchoredObject* pObj = rObjs[i];
    2261             :             // #i26945# - check, if anchored object is a lower
    2262             :             // of the layout frame is changed to check, if its anchor frame
    2263             :             // is a lower of the layout frame.
    2264             :             // determine the anchor frame - usually it's the anchor frame,
    2265             :             // for at-character/as-character anchored objects the anchor character
    2266             :             // text frame is taken.
    2267       68146 :             const SwFrm* pAnchorFrm = pObj->GetAnchorFrmContainingAnchPos();
    2268       68146 :             if ( pObj->ISA(SwFlyFrm) )
    2269             :             {
    2270       33310 :                 SwFlyFrm* pFly = static_cast<SwFlyFrm*>(pObj);
    2271             : 
    2272       33310 :                 if ( pFly->Frm().Left() == FAR_AWAY )
    2273       10553 :                     continue;
    2274             : 
    2275       22757 :                 if ( pFly->IsAnLower( this ) )
    2276        3265 :                     continue;
    2277             : 
    2278             :                 // #i26945# - use <pAnchorFrm> to check, if
    2279             :                 // fly frame is lower of layout frame resp. if fly frame is
    2280             :                 // at a different page registered as its anchor frame is on.
    2281       19492 :                 const bool bLow = IsAnLower( pAnchorFrm );
    2282       19492 :                 if ( bLow || pAnchorFrm->FindPageFrm() != pPageFrm )
    2283             :                 {
    2284        1090 :                     pFly->_Invalidate( pPageFrm );
    2285        1090 :                     if ( !bLow || pFly->IsFlyAtCntFrm() )
    2286             :                     {
    2287             :                         // #i44016#
    2288        1090 :                         if ( _bUnlockPosOfObjs )
    2289             :                         {
    2290         396 :                             pFly->UnlockPosition();
    2291             :                         }
    2292        1090 :                         pFly->_InvalidatePos();
    2293             :                     }
    2294             :                     else
    2295           0 :                         pFly->_InvalidatePrt();
    2296             :                 }
    2297             :             }
    2298             :             else
    2299             :             {
    2300             :                 OSL_ENSURE( pObj->ISA(SwAnchoredDrawObject),
    2301             :                         "<SwLayoutFrm::NotifyFlys() - anchored object of unexpected type" );
    2302             :                 // #i26945# - use <pAnchorFrm> to check, if
    2303             :                 // fly frame is lower of layout frame resp. if fly frame is
    2304             :                 // at a different page registered as its anchor frame is on.
    2305       68581 :                 if ( IsAnLower( pAnchorFrm ) ||
    2306       33745 :                      pAnchorFrm->FindPageFrm() != pPageFrm )
    2307             :                 {
    2308             :                     // #i44016#
    2309        1094 :                     if ( _bUnlockPosOfObjs )
    2310             :                     {
    2311         375 :                         pObj->UnlockPosition();
    2312             :                     }
    2313        1094 :                     pObj->InvalidateObjPos();
    2314             :                 }
    2315             :             }
    2316             :         }
    2317             :     }
    2318       54960 : }
    2319             : 
    2320        4829 : void SwFlyFrm::NotifyDrawObj()
    2321             : {
    2322        4829 :     SwVirtFlyDrawObj* pObj = GetVirtDrawObj();
    2323        4829 :     pObj->SetRect();
    2324        4829 :     pObj->SetRectsDirty();
    2325        4829 :     pObj->SetChanged();
    2326        4829 :     pObj->BroadcastObjectChange();
    2327        4829 :     if ( GetFormat()->GetSurround().IsContour() )
    2328          13 :         ClrContourCache( pObj );
    2329        4829 : }
    2330             : 
    2331       11250 : Size SwFlyFrm::CalcRel( const SwFormatFrmSize &rSz ) const
    2332             : {
    2333       11250 :     Size aRet( rSz.GetSize() );
    2334             : 
    2335       11250 :     const SwFrm *pRel = IsFlyLayFrm() ? GetAnchorFrm() : GetAnchorFrm()->GetUpper();
    2336       11250 :     if( pRel ) // LAYER_IMPL
    2337             :     {
    2338       11250 :         long nRelWidth = LONG_MAX, nRelHeight = LONG_MAX;
    2339       11250 :         const SwViewShell *pSh = getRootFrm()->GetCurrShell();
    2340       27245 :         if ( ( pRel->IsBodyFrm() || pRel->IsPageFrm() ) &&
    2341       17981 :              pSh && pSh->GetViewOptions()->getBrowseMode() &&
    2342           8 :              pSh->VisArea().HasArea() )
    2343             :         {
    2344           8 :             nRelWidth  = pSh->GetBrowseWidth();
    2345           8 :             nRelHeight = pSh->VisArea().Height();
    2346           8 :             Size aBorder = pSh->GetOut()->PixelToLogic( pSh->GetBrowseBorder() );
    2347           8 :             long nDiff = nRelWidth - pRel->Prt().Width();
    2348           8 :             if ( nDiff > 0 )
    2349           0 :                 nRelWidth -= nDiff;
    2350           8 :             nRelHeight -= 2*aBorder.Height();
    2351           8 :             nDiff = nRelHeight - pRel->Prt().Height();
    2352           8 :             if ( nDiff > 0 )
    2353           0 :                 nRelHeight -= nDiff;
    2354             :         }
    2355             : 
    2356             :         // At the moment only the "== PAGE_FRAME" and "!= PAGE_FRAME" cases are handled.
    2357             :         // When size is a relative to page size, ignore size of SwBodyFrm.
    2358       11250 :         if (rSz.GetWidthPercentRelation() != text::RelOrientation::PAGE_FRAME)
    2359       11226 :             nRelWidth  = std::min( nRelWidth,  pRel->Prt().Width() );
    2360       11250 :         if (rSz.GetHeightPercentRelation() != text::RelOrientation::PAGE_FRAME)
    2361       11238 :             nRelHeight = std::min( nRelHeight, pRel->Prt().Height() );
    2362       11250 :         if( !pRel->IsPageFrm() )
    2363             :         {
    2364       11032 :             const SwPageFrm* pPage = FindPageFrm();
    2365       11032 :             if( pPage )
    2366             :             {
    2367       11032 :                 if (rSz.GetWidthPercentRelation() == text::RelOrientation::PAGE_FRAME)
    2368             :                     // Ignore margins of pPage.
    2369          24 :                     nRelWidth  = std::min( nRelWidth,  pPage->Frm().Width() );
    2370             :                 else
    2371       11008 :                     nRelWidth  = std::min( nRelWidth,  pPage->Prt().Width() );
    2372       11032 :                 if (rSz.GetHeightPercentRelation() == text::RelOrientation::PAGE_FRAME)
    2373             :                     // Ignore margins of pPage.
    2374          12 :                     nRelHeight = std::min( nRelHeight, pPage->Frm().Height() );
    2375             :                 else
    2376       11020 :                     nRelHeight = std::min( nRelHeight, pPage->Prt().Height() );
    2377             :             }
    2378             :         }
    2379             : 
    2380       11250 :         if ( rSz.GetWidthPercent() && rSz.GetWidthPercent() != 0xFF )
    2381          94 :             aRet.Width() = nRelWidth * rSz.GetWidthPercent() / 100;
    2382       11250 :         if ( rSz.GetHeightPercent() && rSz.GetHeightPercent() != 0xFF )
    2383          36 :             aRet.Height() = nRelHeight * rSz.GetHeightPercent() / 100;
    2384             : 
    2385       11250 :         if ( rSz.GetWidthPercent() == 0xFF )
    2386             :         {
    2387           4 :             aRet.Width() *= aRet.Height();
    2388           4 :             aRet.Width() /= rSz.GetHeight();
    2389             :         }
    2390       11246 :         else if ( rSz.GetHeightPercent() == 0xFF )
    2391             :         {
    2392          12 :             aRet.Height() *= aRet.Width();
    2393          12 :             aRet.Height() /= rSz.GetWidth();
    2394             :         }
    2395             :     }
    2396       11250 :     return aRet;
    2397             : }
    2398             : 
    2399         454 : static SwTwips lcl_CalcAutoWidth( const SwLayoutFrm& rFrm )
    2400             : {
    2401         454 :     SwTwips nRet = 0;
    2402         454 :     SwTwips nMin = 0;
    2403         454 :     const SwFrm* pFrm = rFrm.Lower();
    2404             : 
    2405             :     // No autowidth defined for columned frames
    2406         454 :     if ( !pFrm || pFrm->IsColumnFrm() )
    2407           0 :         return nRet;
    2408             : 
    2409        1462 :     while ( pFrm )
    2410             :     {
    2411         554 :         if ( pFrm->IsSctFrm() )
    2412             :         {
    2413           0 :             nMin = lcl_CalcAutoWidth( *static_cast<const SwSectionFrm*>(pFrm) );
    2414             :         }
    2415         554 :         if ( pFrm->IsTextFrm() )
    2416             :         {
    2417         542 :             nMin = const_cast<SwTextFrm*>(static_cast<const SwTextFrm*>(pFrm))->CalcFitToContent();
    2418             :             const SvxLRSpaceItem &rSpace =
    2419         542 :                 static_cast<const SwTextFrm*>(pFrm)->GetTextNode()->GetSwAttrSet().GetLRSpace();
    2420         542 :             if (!static_cast<const SwTextFrm*>(pFrm)->IsLocked())
    2421         542 :                 nMin += rSpace.GetRight() + rSpace.GetTextLeft() + rSpace.GetTextFirstLineOfst();
    2422             :         }
    2423          12 :         else if ( pFrm->IsTabFrm() )
    2424             :         {
    2425          12 :             const SwFormatFrmSize& rTableFormatSz = static_cast<const SwTabFrm*>(pFrm)->GetTable()->GetFrameFormat()->GetFrmSize();
    2426          18 :             if ( USHRT_MAX == rTableFormatSz.GetSize().Width() ||
    2427           6 :                  text::HoriOrientation::NONE == static_cast<const SwTabFrm*>(pFrm)->GetFormat()->GetHoriOrient().GetHoriOrient() )
    2428             :             {
    2429           6 :                 const SwPageFrm* pPage = rFrm.FindPageFrm();
    2430             :                 // auto width table
    2431           6 :                 nMin = pFrm->GetUpper()->IsVertical() ?
    2432           0 :                     pPage->Prt().Height() :
    2433           6 :                     pPage->Prt().Width();
    2434             :             }
    2435             :             else
    2436             :             {
    2437           6 :                 nMin = rTableFormatSz.GetSize().Width();
    2438             :             }
    2439             :         }
    2440             : 
    2441         554 :         if ( nMin > nRet )
    2442         454 :             nRet = nMin;
    2443             : 
    2444         554 :         pFrm = pFrm->GetNext();
    2445             :     }
    2446             : 
    2447         454 :     return nRet;
    2448             : }
    2449             : 
    2450         454 : SwTwips SwFlyFrm::CalcAutoWidth() const
    2451             : {
    2452         454 :     return lcl_CalcAutoWidth( *this );
    2453             : }
    2454             : 
    2455             : /// OD 16.04.2003 #i13147# - If called for paint and the <SwNoTextFrm> contains
    2456             : /// a graphic, load of intrinsic graphic has to be avoided.
    2457         152 : bool SwFlyFrm::GetContour( tools::PolyPolygon&   rContour,
    2458             :                            const bool _bForPaint ) const
    2459             : {
    2460         152 :     bool bRet = false;
    2461         158 :     if( GetFormat()->GetSurround().IsContour() && Lower() &&
    2462           6 :         Lower()->IsNoTextFrm() )
    2463             :     {
    2464           6 :         SwNoTextNode *pNd = const_cast<SwNoTextNode*>(static_cast<const SwNoTextNode*>(static_cast<const SwContentFrm*>(Lower())->GetNode()));
    2465             :         // OD 16.04.2003 #i13147# - determine <GraphicObject> instead of <Graphic>
    2466             :         // in order to avoid load of graphic, if <SwNoTextNode> contains a graphic
    2467             :         // node and method is called for paint.
    2468           6 :         const GraphicObject* pGrfObj = NULL;
    2469           6 :         bool bGrfObjCreated = false;
    2470           6 :         const SwGrfNode* pGrfNd = pNd->GetGrfNode();
    2471           6 :         if ( pGrfNd && _bForPaint )
    2472             :         {
    2473           0 :             pGrfObj = &(pGrfNd->GetGrfObj());
    2474             :         }
    2475             :         else
    2476             :         {
    2477           6 :             pGrfObj = new GraphicObject( pNd->GetGraphic() );
    2478           6 :             bGrfObjCreated = true;
    2479             :         }
    2480             :         OSL_ENSURE( pGrfObj, "SwFlyFrm::GetContour() - No Graphic/GraphicObject found at <SwNoTextNode>." );
    2481           6 :         if ( pGrfObj && pGrfObj->GetType() != GRAPHIC_NONE )
    2482             :         {
    2483           6 :             if( !pNd->HasContour() )
    2484             :             {
    2485             :                 // OD 16.04.2003 #i13147# - no <CreateContour> for a graphic
    2486             :                 // during paint. Thus, return (value of <bRet> should be <false>).
    2487           0 :                 if ( pGrfNd && _bForPaint )
    2488             :                 {
    2489             :                     OSL_FAIL( "SwFlyFrm::GetContour() - No Contour found at <SwNoTextNode> during paint." );
    2490           0 :                     return bRet;
    2491             :                 }
    2492           0 :                 pNd->CreateContour();
    2493             :             }
    2494           6 :             pNd->GetContour( rContour );
    2495             :             // The Node holds the Polygon matching the original size of the graphic
    2496             :             // We need to include the scaling here
    2497           6 :             SwRect aClip;
    2498           6 :             SwRect aOrig;
    2499           6 :             Lower()->Calc();
    2500           6 :             static_cast<const SwNoTextFrm*>(Lower())->GetGrfArea( aClip, &aOrig, false );
    2501             :             // OD 16.04.2003 #i13147# - copy method code <SvxContourDlg::ScaleContour(..)>
    2502             :             // in order to avoid that graphic has to be loaded for contour scale.
    2503             :             //SvxContourDlg::ScaleContour( rContour, aGrf, MAP_TWIP, aOrig.SSize() );
    2504             :             {
    2505           6 :                 OutputDevice*   pOutDev = Application::GetDefaultDevice();
    2506           6 :                 const MapMode   aDispMap( MAP_TWIP );
    2507          12 :                 const MapMode   aGrfMap( pGrfObj->GetPrefMapMode() );
    2508           6 :                 const Size      aGrfSize( pGrfObj->GetPrefSize() );
    2509           6 :                 Size            aOrgSize;
    2510           6 :                 Point           aNewPoint;
    2511           6 :                 bool            bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
    2512             : 
    2513           6 :                 if ( bPixelMap )
    2514           0 :                     aOrgSize = pOutDev->PixelToLogic( aGrfSize, aDispMap );
    2515             :                 else
    2516           6 :                     aOrgSize = OutputDevice::LogicToLogic( aGrfSize, aGrfMap, aDispMap );
    2517             : 
    2518           6 :                 if ( aOrgSize.Width() && aOrgSize.Height() )
    2519             :                 {
    2520           6 :                     double fScaleX = (double) aOrig.Width() / aOrgSize.Width();
    2521           6 :                     double fScaleY = (double) aOrig.Height() / aOrgSize.Height();
    2522             : 
    2523          12 :                     for ( sal_uInt16 j = 0, nPolyCount = rContour.Count(); j < nPolyCount; j++ )
    2524             :                     {
    2525           6 :                         Polygon& rPoly = rContour[ j ];
    2526             : 
    2527          72 :                         for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
    2528             :                         {
    2529          66 :                             if ( bPixelMap )
    2530           0 :                                 aNewPoint = pOutDev->PixelToLogic( rPoly[ i ], aDispMap  );
    2531             :                             else
    2532          66 :                                 aNewPoint = OutputDevice::LogicToLogic( rPoly[ i ], aGrfMap, aDispMap  );
    2533             : 
    2534          66 :                             rPoly[ i ] = Point( FRound( aNewPoint.getX() * fScaleX ), FRound( aNewPoint.getY() * fScaleY ) );
    2535             :                         }
    2536             :                     }
    2537           6 :                 }
    2538             :             }
    2539             :             // OD 17.04.2003 #i13147# - destroy created <GraphicObject>.
    2540           6 :             if ( bGrfObjCreated )
    2541             :             {
    2542           6 :                 delete pGrfObj;
    2543             :             }
    2544           6 :             rContour.Move( aOrig.Left(), aOrig.Top() );
    2545           6 :             if( !aClip.Width() )
    2546           0 :                 aClip.Width( 1 );
    2547           6 :             if( !aClip.Height() )
    2548           0 :                 aClip.Height( 1 );
    2549           6 :             rContour.Clip( aClip.SVRect() );
    2550           6 :             rContour.Optimize(PolyOptimizeFlags::CLOSE);
    2551           6 :             bRet = true;
    2552             :         }
    2553             :     }
    2554         152 :     return bRet;
    2555             : }
    2556             : 
    2557             : // OD 2004-03-25 #i26791#
    2558        2076 : const SwVirtFlyDrawObj* SwFlyFrm::GetVirtDrawObj() const
    2559             : {
    2560        2076 :     return static_cast<const SwVirtFlyDrawObj*>(GetDrawObj());
    2561             : }
    2562       83637 : SwVirtFlyDrawObj* SwFlyFrm::GetVirtDrawObj()
    2563             : {
    2564       83637 :     return static_cast<SwVirtFlyDrawObj*>(DrawObj());
    2565             : }
    2566             : 
    2567             : // OD 2004-03-24 #i26791# - implementation of pure virtual method declared in
    2568             : // base class <SwAnchoredObject>
    2569             : 
    2570         864 : void SwFlyFrm::InvalidateObjPos()
    2571             : {
    2572         864 :     InvalidatePos();
    2573             :     // #i68520#
    2574         864 :     InvalidateObjRectWithSpaces();
    2575         864 : }
    2576             : 
    2577      165043 : SwFrameFormat& SwFlyFrm::GetFrameFormat()
    2578             : {
    2579             :     OSL_ENSURE( GetFormat(),
    2580             :             "<SwFlyFrm::GetFrameFormat()> - missing frame format -> crash." );
    2581      165043 :     return *GetFormat();
    2582             : }
    2583      330346 : const SwFrameFormat& SwFlyFrm::GetFrameFormat() const
    2584             : {
    2585             :     OSL_ENSURE( GetFormat(),
    2586             :             "<SwFlyFrm::GetFrameFormat()> - missing frame format -> crash." );
    2587      330346 :     return *GetFormat();
    2588             : }
    2589             : 
    2590      549805 : const SwRect SwFlyFrm::GetObjRect() const
    2591             : {
    2592      549805 :     return Frm();
    2593             : }
    2594             : 
    2595             : // #i70122#
    2596             : // for Writer fly frames the bounding rectangle equals the object rectangles
    2597        7282 : const SwRect SwFlyFrm::GetObjBoundRect() const
    2598             : {
    2599        7282 :     return GetObjRect();
    2600             : }
    2601             : 
    2602             : // #i68520#
    2603        7376 : bool SwFlyFrm::_SetObjTop( const SwTwips _nTop )
    2604             : {
    2605        7376 :     const bool bChanged( Frm().Pos().getY() != _nTop );
    2606             : 
    2607        7376 :     Frm().Pos().setY(_nTop);
    2608             : 
    2609        7376 :     return bChanged;
    2610             : }
    2611        2461 : bool SwFlyFrm::_SetObjLeft( const SwTwips _nLeft )
    2612             : {
    2613        2461 :     const bool bChanged( Frm().Pos().getX() != _nLeft );
    2614             : 
    2615        2461 :     Frm().Pos().setX(_nLeft);
    2616             : 
    2617        2461 :     return bChanged;
    2618             : }
    2619             : 
    2620             : /** method to assure that anchored object is registered at the correct
    2621             :     page frame
    2622             : 
    2623             :     OD 2004-07-02 #i28701#
    2624             : */
    2625           0 : void SwFlyFrm::RegisterAtCorrectPage()
    2626             : {
    2627             :     // default behaviour is to do nothing.
    2628           0 : }
    2629             : 
    2630             : /** method to determine, if a <MakeAll()> on the Writer fly frame is possible
    2631             : 
    2632             :     OD 2004-05-11 #i28701#
    2633             : */
    2634       11540 : bool SwFlyFrm::IsFormatPossible() const
    2635             : {
    2636       23080 :     return SwAnchoredObject::IsFormatPossible() &&
    2637       23080 :            !IsLocked() && !IsColLocked();
    2638             : }
    2639             : 
    2640          18 : void SwFlyFrm::GetAnchoredObjects( std::list<SwAnchoredObject*>& aList, const SwFormat& rFormat )
    2641             : {
    2642          18 :     SwIterator<SwFlyFrm,SwFormat> aIter( rFormat );
    2643          36 :     for( SwFlyFrm* pFlyFrm = aIter.First(); pFlyFrm; pFlyFrm = aIter.Next() )
    2644          36 :         aList.push_back( pFlyFrm );
    2645          18 : }
    2646             : 
    2647      410086 : const SwFlyFrameFormat * SwFlyFrm::GetFormat() const
    2648             : {
    2649      410086 :     return static_cast< const SwFlyFrameFormat * >( GetDep() );
    2650             : }
    2651             : 
    2652      285588 : SwFlyFrameFormat * SwFlyFrm::GetFormat()
    2653             : {
    2654      285588 :     return static_cast< SwFlyFrameFormat * >( GetDep() );
    2655             : }
    2656             : 
    2657        9077 : void SwFlyFrm::Calc() const
    2658             : {
    2659        9077 :     if ( !m_bValidContentPos )
    2660        2533 :         const_cast<SwFlyFrm*>(this)->PrepareMake();
    2661             :     else
    2662        6544 :         SwLayoutFrm::Calc();
    2663        9077 : }
    2664             : 
    2665        2928 : SwTwips SwFlyFrm::CalcContentHeight(const SwBorderAttrs *pAttrs, const SwTwips nMinHeight, const SwTwips nUL)
    2666             : {
    2667        2928 :     SWRECTFN( this )
    2668        2928 :     SwTwips nHeight = 0;
    2669        2928 :     if ( Lower() )
    2670             :     {
    2671        2926 :         if ( Lower()->IsColumnFrm() )
    2672             :         {
    2673           0 :             FormatWidthCols( *pAttrs, nUL, nMinHeight );
    2674           0 :             nHeight = (Lower()->Frm().*fnRect->fnGetHeight)();
    2675             :         }
    2676             :         else
    2677             :         {
    2678        2926 :             SwFrm *pFrm = Lower();
    2679        9995 :             while ( pFrm )
    2680             :             {
    2681        4143 :                 nHeight += (pFrm->Frm().*fnRect->fnGetHeight)();
    2682        4143 :                 if( pFrm->IsTextFrm() && static_cast<SwTextFrm*>(pFrm)->IsUndersized() )
    2683             :                 // This TextFrm would like to be a bit larger
    2684         298 :                     nHeight += static_cast<SwTextFrm*>(pFrm)->GetParHeight()
    2685         298 :                             - (pFrm->Prt().*fnRect->fnGetHeight)();
    2686        3845 :                 else if( pFrm->IsSctFrm() && static_cast<SwSectionFrm*>(pFrm)->IsUndersized() )
    2687           0 :                     nHeight += static_cast<SwSectionFrm*>(pFrm)->Undersize();
    2688        4143 :                 pFrm = pFrm->GetNext();
    2689             :             }
    2690             :         }
    2691        2926 :         if ( GetDrawObjs() )
    2692             :         {
    2693           9 :             const size_t nCnt = GetDrawObjs()->size();
    2694           9 :             SwTwips nTop = (Frm().*fnRect->fnGetTop)();
    2695           9 :             SwTwips nBorder = (Frm().*fnRect->fnGetHeight)() -
    2696           9 :             (Prt().*fnRect->fnGetHeight)();
    2697          18 :             for ( size_t i = 0; i < nCnt; ++i )
    2698             :             {
    2699           9 :                 SwAnchoredObject* pAnchoredObj = (*GetDrawObjs())[i];
    2700           9 :                 if ( pAnchoredObj->ISA(SwFlyFrm) )
    2701             :                 {
    2702           0 :                     SwFlyFrm* pFly = static_cast<SwFlyFrm*>(pAnchoredObj);
    2703             :                     // OD 06.11.2003 #i22305# - consider
    2704             :                     // only Writer fly frames, which follow the text flow.
    2705           0 :                     if ( pFly->IsFlyLayFrm() &&
    2706           0 :                         pFly->Frm().Top() != FAR_AWAY &&
    2707           0 :                         pFly->GetFormat()->GetFollowTextFlow().GetValue() )
    2708             :                     {
    2709           0 :                         SwTwips nDist = -(pFly->Frm().*fnRect->
    2710           0 :                             fnBottomDist)( nTop );
    2711           0 :                         if( nDist > nBorder + nHeight )
    2712           0 :                             nHeight = nDist - nBorder;
    2713             :                     }
    2714             :                 }
    2715             :             }
    2716             :         }
    2717             :     }
    2718        2928 :     return nHeight;
    2719         177 : }
    2720             : 
    2721             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11