LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/layout - flycnt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 106 707 15.0 %
Date: 2012-12-27 Functions: 13 26 50.0 %
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             : 
      21             : #include <tools/bigint.hxx>
      22             : #include "pagefrm.hxx"
      23             : #include "cntfrm.hxx"
      24             : #include "flyfrm.hxx"
      25             : #include "txtfrm.hxx"
      26             : #include <doc.hxx>
      27             : #include <IDocumentUndoRedo.hxx>
      28             : #include "viewsh.hxx"
      29             : #include "viewimp.hxx"
      30             : #include "pam.hxx"
      31             : #include "frmfmt.hxx"
      32             : #include "frmtool.hxx"
      33             : #include "dflyobj.hxx"
      34             : #include "hints.hxx"
      35             : #include "ndtxt.hxx"
      36             : #include "swundo.hxx"
      37             : #include <editeng/ulspitem.hxx>
      38             : #include <editeng/lrspitem.hxx>
      39             : #include <fmtanchr.hxx>
      40             : #include <fmtornt.hxx>
      41             : #include <fmtfsize.hxx>
      42             : #include <fmtsrnd.hxx>
      43             : 
      44             : #include "tabfrm.hxx"
      45             : #include "flyfrms.hxx"
      46             : #include "crstate.hxx"
      47             : #include "sectfrm.hxx"
      48             : 
      49             : #include <tocntntanchoredobjectposition.hxx>
      50             : #include <dcontact.hxx>
      51             : #include <sortedobjs.hxx>
      52             : #include <layouter.hxx>
      53             : #include <objectformattertxtfrm.hxx>
      54             : #include <HandleAnchorNodeChg.hxx>
      55             : 
      56             : using namespace ::com::sun::star;
      57             : 
      58             : 
      59             : /*************************************************************************
      60             : |*
      61             : |*  SwFlyAtCntFrm::SwFlyAtCntFrm()
      62             : |*
      63             : |*************************************************************************/
      64             : 
      65          35 : SwFlyAtCntFrm::SwFlyAtCntFrm( SwFlyFrmFmt *pFmt, SwFrm* pSib, SwFrm *pAnch ) :
      66          35 :     SwFlyFreeFrm( pFmt, pSib, pAnch )
      67             : {
      68          35 :     bAtCnt = sal_True;
      69          35 :     bAutoPosition = (FLY_AT_CHAR == pFmt->GetAnchor().GetAnchorId());
      70          35 : }
      71             : 
      72             : // #i28701#
      73        3558 : TYPEINIT1(SwFlyAtCntFrm,SwFlyFreeFrm);
      74             : /*************************************************************************
      75             : |*
      76             : |*  SwFlyAtCntFrm::Modify()
      77             : |*
      78             : |*************************************************************************/
      79             : 
      80           0 : void SwFlyAtCntFrm::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
      81             : {
      82           0 :     sal_uInt16 nWhich = pNew ? pNew->Which() : 0;
      83           0 :     const SwFmtAnchor *pAnch = 0;
      84             : 
      85           0 :     if( RES_ATTRSET_CHG == nWhich && SFX_ITEM_SET ==
      86           0 :         ((SwAttrSetChg*)pNew)->GetChgSet()->GetItemState( RES_ANCHOR, sal_False,
      87           0 :             (const SfxPoolItem**)&pAnch ))
      88             :         ;       // The anchor pointer is set at GetItemState!
      89             : 
      90           0 :     else if( RES_ANCHOR == nWhich )
      91             :     {
      92             :         //Change anchor, I move myself to a new place.
      93             :         //The anchor type must not change, this is only possible using
      94             :         //SwFEShell.
      95           0 :         pAnch = (const SwFmtAnchor*)pNew;
      96             :     }
      97             : 
      98           0 :     if( pAnch )
      99             :     {
     100             :         OSL_ENSURE( pAnch->GetAnchorId() == GetFmt()->GetAnchor().GetAnchorId(),
     101             :                 "Illegal change of anchor type. " );
     102             : 
     103             :         //Unregister, get hold of a new anchor and attach it
     104           0 :         SwRect aOld( GetObjRectWithSpaces() );
     105           0 :         SwPageFrm *pOldPage = FindPageFrm();
     106           0 :         const SwFrm *pOldAnchor = GetAnchorFrm();
     107           0 :         SwCntntFrm *pCntnt = (SwCntntFrm*)GetAnchorFrm();
     108           0 :         AnchorFrm()->RemoveFly( this );
     109             : 
     110           0 :         const bool bBodyFtn = (pCntnt->IsInDocBody() || pCntnt->IsInFtn());
     111             : 
     112             :         // Search the new anchor using the NodeIdx; the relation between old
     113             :         // and new NodeIdx determines the search direction
     114           0 :         const SwNodeIndex aNewIdx( pAnch->GetCntntAnchor()->nNode );
     115           0 :         SwNodeIndex aOldIdx( *pCntnt->GetNode() );
     116             : 
     117             :         //fix: depending on which index was smaller, searching in the do-while
     118             :         //loop previously was done forward or backwards respectively. This however
     119             :         //could lead to an infinite loop. To at least avoid the loop, searching
     120             :         //is now done in only one direction. Getting hold of a frame from the node
     121             :         //is still possible if the new anchor could not be found. Chances are
     122             :         //good that this will be the correct one.
     123           0 :         const bool bNext = aOldIdx < aNewIdx;
     124             :         // consider the case that at found anchor frame candidate already a
     125             :         // fly frame of the given fly format is registered.
     126             :         // consider, that <pCntnt> is the already
     127             :         // the new anchor frame.
     128           0 :         bool bFound( aOldIdx == aNewIdx );
     129           0 :         while ( pCntnt && !bFound )
     130             :         {
     131           0 :             do
     132             :             {
     133           0 :                 if ( bNext )
     134           0 :                     pCntnt = pCntnt->GetNextCntntFrm();
     135             :                 else
     136           0 :                     pCntnt = pCntnt->GetPrevCntntFrm();
     137             :             } while ( pCntnt &&
     138           0 :                       !( bBodyFtn == ( pCntnt->IsInDocBody() ||
     139           0 :                                        pCntnt->IsInFtn() ) ) );
     140           0 :             if ( pCntnt )
     141           0 :                 aOldIdx = *pCntnt->GetNode();
     142             : 
     143             :             // check, if at found anchor frame candidate already a fly frame
     144             :             // of the given fly frame format is registered.
     145           0 :             bFound = aOldIdx == aNewIdx;
     146           0 :             if ( bFound && pCntnt->GetDrawObjs() )
     147             :             {
     148           0 :                 SwFrmFmt* pMyFlyFrmFmt( &GetFrmFmt() );
     149           0 :                 SwSortedObjs &rObjs = *pCntnt->GetDrawObjs();
     150           0 :                 for( sal_uInt16 i = 0; i < rObjs.Count(); ++i)
     151             :                 {
     152           0 :                     SwFlyFrm* pFlyFrm = dynamic_cast<SwFlyFrm*>(rObjs[i]);
     153           0 :                     if ( pFlyFrm &&
     154           0 :                          &(pFlyFrm->GetFrmFmt()) == pMyFlyFrmFmt )
     155             :                     {
     156           0 :                         bFound = false;
     157           0 :                         break;
     158             :                     }
     159             :                 }
     160             :             }
     161             :         }
     162           0 :         if ( !pCntnt )
     163             :         {
     164           0 :             SwCntntNode *pNode = aNewIdx.GetNode().GetCntntNode();
     165           0 :             pCntnt = pNode->getLayoutFrm( getRootFrm(), &pOldAnchor->Frm().Pos(), 0, sal_False );
     166             :             OSL_ENSURE( pCntnt, "Neuen Anker nicht gefunden" );
     167             :         }
     168             :         //Flys are never attached to a follow, but always on the master which
     169             :         //we are going to search now.
     170           0 :         SwCntntFrm* pFlow = pCntnt;
     171           0 :         while ( pFlow->IsFollow() )
     172           0 :             pFlow = pFlow->FindMaster();
     173           0 :         pCntnt = pFlow;
     174             : 
     175             :         //and *puff* it's attached...
     176           0 :         pCntnt->AppendFly( this );
     177           0 :         if ( pOldPage && pOldPage != FindPageFrm() )
     178           0 :             NotifyBackground( pOldPage, aOld, PREP_FLY_LEAVE );
     179             : 
     180             :         //Fix(3495)
     181           0 :         _InvalidatePos();
     182           0 :         InvalidatePage();
     183           0 :         SetNotifyBack();
     184             :         // #i28701# - reset member <maLastCharRect> and
     185             :         // <mnLastTopOfLine> for to-character anchored objects.
     186           0 :         ClearCharRectAndTopOfLine();
     187             :     }
     188             :     else
     189           0 :         SwFlyFrm::Modify( pOld, pNew );
     190           0 : }
     191             : 
     192             : /*************************************************************************
     193             : |*
     194             : |*  SwFlyAtCntFrm::MakeAll()
     195             : |*
     196             : |*  Description         With a paragraph-anchored fly it's absolutely possible that
     197             : |*      the anchor reacts to changes of the fly. To this reaction the fly must
     198             : |*      certaily react too. Sadly this can lead to oscillations; for example the
     199             : |*      fly wants to go down therefore the content can go up - this leads to a
     200             : |*      smaller TxtFrm thus the fly needs to go up again whereby the text will
     201             : |*      get pushed down...
     202             : |*      To avoid such oscillations, a small position stack is built. If the fly
     203             : |*      reaches a position which it already had once, the action is stopped.
     204             : |*      To not run into problems, the stack is designed to hold five positions.
     205             : |*      If the stack flows over, the action is stopped too.
     206             : |*      Cancellation leads to the situation that the fly has a bad position in
     207             : |*      the end. In case of cancellation, the frame is set to automatic top
     208             : |*      alignment to not trigger a 'big oscillation' when calling from outside
     209             : |*      again.
     210             : |*************************************************************************/
     211             : //We need some helper classes to monitor the oscillation and a few functions
     212             : //to not get lost.
     213             : 
     214             : // #i3317# - re-factoring of the position stack
     215             : class SwOszControl
     216             : {
     217             :     static const SwFlyFrm *pStk1;
     218             :     static const SwFlyFrm *pStk2;
     219             :     static const SwFlyFrm *pStk3;
     220             :     static const SwFlyFrm *pStk4;
     221             :     static const SwFlyFrm *pStk5;
     222             : 
     223             :     const SwFlyFrm *pFly;
     224             :     // #i3317#
     225             :     sal_uInt8 mnPosStackSize;
     226             :     std::vector<Point*> maObjPositions;
     227             : 
     228             : public:
     229             :     SwOszControl( const SwFlyFrm *pFrm );
     230             :     ~SwOszControl();
     231             :     bool ChkOsz();
     232             :     static bool IsInProgress( const SwFlyFrm *pFly );
     233             : };
     234             : const SwFlyFrm *SwOszControl::pStk1 = 0;
     235             : const SwFlyFrm *SwOszControl::pStk2 = 0;
     236             : const SwFlyFrm *SwOszControl::pStk3 = 0;
     237             : const SwFlyFrm *SwOszControl::pStk4 = 0;
     238             : const SwFlyFrm *SwOszControl::pStk5 = 0;
     239             : 
     240          33 : SwOszControl::SwOszControl( const SwFlyFrm *pFrm )
     241             :     : pFly( pFrm ),
     242             :       // #i3317#
     243          33 :       mnPosStackSize( 20 )
     244             : {
     245          33 :     if ( !SwOszControl::pStk1 )
     246          33 :         SwOszControl::pStk1 = pFly;
     247           0 :     else if ( !SwOszControl::pStk2 )
     248           0 :         SwOszControl::pStk2 = pFly;
     249           0 :     else if ( !SwOszControl::pStk3 )
     250           0 :         SwOszControl::pStk3 = pFly;
     251           0 :     else if ( !SwOszControl::pStk4 )
     252           0 :         SwOszControl::pStk4 = pFly;
     253           0 :     else if ( !SwOszControl::pStk5 )
     254           0 :         SwOszControl::pStk5 = pFly;
     255          33 : }
     256             : 
     257          66 : SwOszControl::~SwOszControl()
     258             : {
     259          33 :     if ( SwOszControl::pStk1 == pFly )
     260          33 :         SwOszControl::pStk1 = 0;
     261           0 :     else if ( SwOszControl::pStk2 == pFly )
     262           0 :         SwOszControl::pStk2 = 0;
     263           0 :     else if ( SwOszControl::pStk3 == pFly )
     264           0 :         SwOszControl::pStk3 = 0;
     265           0 :     else if ( SwOszControl::pStk4 == pFly )
     266           0 :         SwOszControl::pStk4 = 0;
     267           0 :     else if ( SwOszControl::pStk5 == pFly )
     268           0 :         SwOszControl::pStk5 = 0;
     269             :     // #i3317#
     270          92 :     while ( !maObjPositions.empty() )
     271             :     {
     272          26 :         Point* pPos = maObjPositions.back();
     273          26 :         delete pPos;
     274             : 
     275          26 :         maObjPositions.pop_back();
     276             :     }
     277          33 : }
     278             : 
     279         136 : bool SwOszControl::IsInProgress( const SwFlyFrm *pFly )
     280             : {
     281         136 :     if ( SwOszControl::pStk1 && !pFly->IsLowerOf( SwOszControl::pStk1 ) )
     282           0 :         return true;
     283         136 :     if ( SwOszControl::pStk2 && !pFly->IsLowerOf( SwOszControl::pStk2 ) )
     284           0 :         return true;
     285         136 :     if ( SwOszControl::pStk3 && !pFly->IsLowerOf( SwOszControl::pStk3 ) )
     286           0 :         return true;
     287         136 :     if ( SwOszControl::pStk4 && !pFly->IsLowerOf( SwOszControl::pStk4 ) )
     288           0 :         return true;
     289         136 :     if ( SwOszControl::pStk5 && !pFly->IsLowerOf( SwOszControl::pStk5 ) )
     290           0 :         return true;
     291         136 :     return false;
     292             : }
     293             : 
     294          26 : bool SwOszControl::ChkOsz()
     295             : {
     296          26 :     bool bOscillationDetected = false;
     297             : 
     298          26 :     if ( maObjPositions.size() == mnPosStackSize )
     299             :     {
     300             :         // position stack is full -> oscillation
     301           0 :         bOscillationDetected = true;
     302             :     }
     303             :     else
     304             :     {
     305          26 :         Point* pNewObjPos = new Point( pFly->GetObjRect().Pos() );
     306          78 :         for ( std::vector<Point*>::iterator aObjPosIter = maObjPositions.begin();
     307          52 :               aObjPosIter != maObjPositions.end();
     308             :               ++aObjPosIter )
     309             :         {
     310           0 :             if ( *(pNewObjPos) == *(*aObjPosIter) )
     311             :             {
     312             :                 // position already occurred -> oscillation
     313           0 :                 bOscillationDetected = true;
     314           0 :                 delete pNewObjPos;
     315           0 :                 break;
     316             :             }
     317             :         }
     318          26 :         if ( !bOscillationDetected )
     319             :         {
     320          26 :             maObjPositions.push_back( pNewObjPos );
     321             :         }
     322             :     }
     323             : 
     324          26 :     return bOscillationDetected;
     325             : }
     326             : 
     327          33 : void SwFlyAtCntFrm::MakeAll()
     328             : {
     329          33 :     if ( !GetFmt()->GetDoc()->IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
     330             :     {
     331          33 :         return;
     332             :     }
     333             : 
     334          33 :     if ( !SwOszControl::IsInProgress( this ) && !IsLocked() && !IsColLocked() )
     335             :     {
     336             :         // #i28701# - use new method <GetPageFrm()>
     337          33 :         if( !GetPageFrm() && GetAnchorFrm() && GetAnchorFrm()->IsInFly() )
     338             :         {
     339           0 :             SwFlyFrm* pFly = AnchorFrm()->FindFlyFrm();
     340           0 :             SwPageFrm *pTmpPage = pFly ? pFly->FindPageFrm() : NULL;
     341           0 :             if( pTmpPage )
     342           0 :                 pTmpPage->AppendFlyToPage( this );
     343             :         }
     344             :         // #i28701# - use new method <GetPageFrm()>
     345          33 :         if( GetPageFrm() )
     346             :         {
     347          33 :             bSetCompletePaintOnInvalidate = true;
     348             :             {
     349          33 :                 SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
     350          33 :                 const SwFmtFrmSize &rFrmSz = GetFmt()->GetFrmSize();
     351          66 :                 if( rFrmSz.GetHeightPercent() != 0xFF &&
     352          33 :                     rFrmSz.GetHeightPercent() >= 100 )
     353             :                 {
     354           0 :                     pFmt->LockModify();
     355           0 :                     SwFmtSurround aMain( pFmt->GetSurround() );
     356           0 :                     if ( aMain.GetSurround() == SURROUND_NONE )
     357             :                     {
     358           0 :                         aMain.SetSurround( SURROUND_THROUGHT );
     359           0 :                         pFmt->SetFmtAttr( aMain );
     360             :                     }
     361           0 :                     pFmt->UnlockModify();
     362             :                 }
     363             :             }
     364             : 
     365          33 :             SwOszControl aOszCntrl( this );
     366             : 
     367             :             // #i43255#
     368             :             // #i50356# - format the anchor frame, which
     369             :             // contains the anchor position. E.g., for at-character anchored
     370             :             // object this can be the follow frame of the anchor frame.
     371             :             const bool bFormatAnchor =
     372          33 :                     !static_cast<const SwTxtFrm*>( GetAnchorFrmContainingAnchPos() )->IsAnyJoinLocked() &&
     373          33 :                     !ConsiderObjWrapInfluenceOnObjPos() &&
     374          66 :                     !ConsiderObjWrapInfluenceOfOtherObjs();
     375             : 
     376          33 :             const SwFrm* pFooter = GetAnchorFrm()->FindFooterOrHeader();
     377          33 :             if( pFooter && !pFooter->IsFooterFrm() )
     378           2 :                 pFooter = NULL;
     379          33 :             bool bOsz = false;
     380          33 :             bool bExtra = Lower() && Lower()->IsColumnFrm();
     381             :             // #i3317# - boolean, to apply temporarly the
     382             :             // 'straightforward positioning process' for the frame due to its
     383             :             // overlapping with a previous column.
     384          33 :             bool bConsiderWrapInfluenceDueToOverlapPrevCol( false );
     385             :             //  #i35911# - boolean, to apply temporarly the
     386             :             // 'straightforward positioning process' for the frame due to fact
     387             :             // that it causes the complete content of its layout environment
     388             :             // to move forward.
     389             :             // #i40444# - extend usage of this boolean:
     390             :             // apply temporarly the 'straightforward positioning process' for
     391             :             // the frame due to the fact that the frame clears the area for
     392             :             // the anchor frame, thus it has to move forward.
     393          33 :             bool bConsiderWrapInfluenceDueToMovedFwdAnchor( false );
     394          99 :             do {
     395          33 :                 SWRECTFN( this )
     396          33 :                 Point aOldPos( (Frm().*fnRect->fnGetPos)() );
     397          33 :                 SwFlyFreeFrm::MakeAll();
     398             :                 const bool bPosChgDueToOwnFormat =
     399          33 :                                         aOldPos != (Frm().*fnRect->fnGetPos)();
     400             :                 // #i3317#
     401          64 :                 if ( !ConsiderObjWrapInfluenceOnObjPos() &&
     402          31 :                      OverlapsPrevColumn() )
     403             :                 {
     404           0 :                     bConsiderWrapInfluenceDueToOverlapPrevCol = true;
     405             :                 }
     406             :                 // #i28701# - no format of anchor frame, if
     407             :                 // wrapping style influence is considered on object positioning
     408          33 :                 if ( bFormatAnchor )
     409             :                 {
     410             :                     SwTxtFrm* pAnchPosAnchorFrm =
     411          31 :                             dynamic_cast<SwTxtFrm*>(GetAnchorFrmContainingAnchPos());
     412             :                     OSL_ENSURE( pAnchPosAnchorFrm,
     413             :                             "<SwFlyAtCntFrm::MakeAll()> - anchor frame of wrong type -> crash" );
     414             :                     // #i58182# - For the usage of new method
     415             :                     // <SwObjectFormatterTxtFrm::CheckMovedFwdCondition(..)>
     416             :                     // to check move forward of anchor frame due to the object
     417             :                     // positioning it's needed to know, if the object is anchored
     418             :                     // at the master frame before the anchor frame is formatted.
     419          31 :                     const bool bAnchoredAtMaster( !pAnchPosAnchorFrm->IsFollow() );
     420             : 
     421             :                     // #i56300#
     422             :                     // perform complete format of anchor text frame and its
     423             :                     // previous frames, which have become invalid due to the
     424             :                     // fly frame format.
     425          31 :                     SwObjectFormatterTxtFrm::FormatAnchorFrmAndItsPrevs( *pAnchPosAnchorFrm );
     426             :                     // #i35911#
     427             :                     // #i40444#
     428             :                     // #i58182# - usage of new method
     429             :                     // <SwObjectFormatterTxtFrm::CheckMovedFwdCondition(..)>
     430          31 :                     sal_uInt32 nToPageNum( 0L );
     431          31 :                     bool bDummy( false );
     432          31 :                     if ( SwObjectFormatterTxtFrm::CheckMovedFwdCondition(
     433          31 :                                         *this, GetPageFrm()->GetPhyPageNum(),
     434          62 :                                         bAnchoredAtMaster, nToPageNum, bDummy ) )
     435             :                     {
     436           0 :                         bConsiderWrapInfluenceDueToMovedFwdAnchor = true;
     437             :                         // mark anchor text frame
     438             :                         // directly, that it is moved forward by object positioning.
     439           0 :                         SwTxtFrm* pAnchorTxtFrm( static_cast<SwTxtFrm*>(AnchorFrm()) );
     440           0 :                         bool bInsert( true );
     441           0 :                         sal_uInt32 nAnchorFrmToPageNum( 0L );
     442           0 :                         const SwDoc& rDoc = *(GetFrmFmt().GetDoc());
     443           0 :                         if ( SwLayouter::FrmMovedFwdByObjPos(
     444             :                                                 rDoc, *pAnchorTxtFrm, nAnchorFrmToPageNum ) )
     445             :                         {
     446           0 :                             if ( nAnchorFrmToPageNum < nToPageNum )
     447           0 :                                 SwLayouter::RemoveMovedFwdFrm( rDoc, *pAnchorTxtFrm );
     448             :                             else
     449           0 :                                 bInsert = false;
     450             :                         }
     451           0 :                         if ( bInsert )
     452             :                         {
     453             :                             SwLayouter::InsertMovedFwdFrm( rDoc, *pAnchorTxtFrm,
     454           0 :                                                            nToPageNum );
     455             :                         }
     456             :                     }
     457             :                 }
     458             : 
     459          40 :                 if ( aOldPos != (Frm().*fnRect->fnGetPos)() ||
     460           7 :                      ( !GetValidPosFlag() &&
     461             :                        ( pFooter || bPosChgDueToOwnFormat ) ) )
     462             :                 {
     463          26 :                     bOsz = aOszCntrl.ChkOsz();
     464             : 
     465             :                     // special loop prevention for dedicated document:
     466          26 :                     if ( bOsz &&
     467           0 :                          HasFixSize() && IsClipped() &&
     468           0 :                          GetAnchorFrm()->GetUpper()->IsCellFrm() )
     469             :                     {
     470           0 :                         SwFrmFmt* pFmt = GetFmt();
     471           0 :                         const SwFmtFrmSize& rFrmSz = pFmt->GetFrmSize();
     472           0 :                         if ( rFrmSz.GetWidthPercent() &&
     473           0 :                              rFrmSz.GetHeightPercent() == 0xFF )
     474             :                         {
     475           0 :                             SwFmtSurround aSurround( pFmt->GetSurround() );
     476           0 :                             if ( aSurround.GetSurround() == SURROUND_NONE )
     477             :                             {
     478           0 :                                 pFmt->LockModify();
     479           0 :                                 aSurround.SetSurround( SURROUND_THROUGHT );
     480           0 :                                 pFmt->SetFmtAttr( aSurround );
     481           0 :                                 pFmt->UnlockModify();
     482           0 :                                 bOsz = false;
     483             :                                 OSL_FAIL( "<SwFlyAtCntFrm::MakeAll()> - special loop prevention for dedicated document of b6403541 applied" );
     484           0 :                             }
     485             :                         }
     486             :                     }
     487             :                 }
     488             : 
     489          33 :                 if ( bExtra && Lower() && !Lower()->GetValidPosFlag() )
     490             :                 {
     491             :                     // If a multi column frame leaves invalid columns because of
     492             :                     // a position change, we loop once more and format
     493             :                     // our content using FormatWidthCols again.
     494           0 :                     _InvalidateSize();
     495           0 :                     bExtra = false; // Ensure only one additional loop run
     496             :                 }
     497          33 :             } while ( !IsValid() && !bOsz &&
     498             :                       // #i3317#
     499           0 :                       !bConsiderWrapInfluenceDueToOverlapPrevCol &&
     500             :                       // #i40444#
     501           0 :                       !bConsiderWrapInfluenceDueToMovedFwdAnchor &&
     502          33 :                       GetFmt()->GetDoc()->IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) );
     503             : 
     504             :             // #i3317# - instead of attribute change apply
     505             :             // temporarly the 'straightforward positioning process'.
     506             :             // #i80924#
     507             :             // handle special case during splitting of table rows
     508          33 :             if ( bConsiderWrapInfluenceDueToMovedFwdAnchor &&
     509           0 :                  GetAnchorFrm()->IsInTab() &&
     510           0 :                  GetAnchorFrm()->IsInFollowFlowRow() )
     511             :             {
     512           0 :                 const SwFrm* pCellFrm = GetAnchorFrm();
     513           0 :                 while ( pCellFrm && !pCellFrm->IsCellFrm() )
     514             :                 {
     515           0 :                     pCellFrm = pCellFrm->GetUpper();
     516             :                 }
     517           0 :                 if ( pCellFrm )
     518             :                 {
     519           0 :                     SWRECTFN( pCellFrm )
     520           0 :                     if ( (pCellFrm->Frm().*fnRect->fnGetTop)() == 0 &&
     521           0 :                          (pCellFrm->Frm().*fnRect->fnGetHeight)() == 0 )
     522             :                     {
     523           0 :                         bConsiderWrapInfluenceDueToMovedFwdAnchor = false;
     524             :                     }
     525             :                 }
     526             :             }
     527          33 :             if ( bOsz || bConsiderWrapInfluenceDueToOverlapPrevCol ||
     528             :                  // #i40444#
     529             :                  bConsiderWrapInfluenceDueToMovedFwdAnchor )
     530             :             {
     531           0 :                 SetTmpConsiderWrapInfluence( true );
     532           0 :                 SetRestartLayoutProcess( true );
     533           0 :                 SetTmpConsiderWrapInfluenceOfOtherObjs( true );
     534             :             }
     535          33 :             bSetCompletePaintOnInvalidate = false;
     536             :         }
     537             :     }
     538             : }
     539             : 
     540             : /** method to determine, if a <MakeAll()> on the Writer fly frame is possible
     541             : 
     542             :     #i28701#
     543             : */
     544         103 : bool SwFlyAtCntFrm::IsFormatPossible() const
     545             : {
     546         103 :     return SwFlyFreeFrm::IsFormatPossible() &&
     547         103 :            !SwOszControl::IsInProgress( this );
     548             : }
     549             : 
     550             : /*************************************************************************
     551             : |*
     552             : |*  FindAnchor() und Hilfsfunktionen.
     553             : |*
     554             : |*  Description:        Searches an anchor for paragraph bound objects
     555             : |*      starting from pOldAnch. This is used to show anchors as well as changing
     556             : |*      anchors when dragging paragraph bound objects.
     557             : |*
     558             : |*************************************************************************/
     559             : 
     560             : class SwDistance
     561             : {
     562             : public:
     563             :     SwTwips nMain, nSub;
     564           0 :     SwDistance() { nMain = nSub = 0; }
     565           0 :     SwDistance& operator=( const SwDistance &rTwo )
     566           0 :         { nMain = rTwo.nMain; nSub = rTwo.nSub; return *this; }
     567           0 :     bool operator<( const SwDistance& rTwo ) const
     568             :         { return nMain < rTwo.nMain || ( nMain == rTwo.nMain && nSub &&
     569           0 :           rTwo.nSub && nSub < rTwo.nSub ); }
     570           0 :     bool operator<=( const SwDistance& rTwo ) const
     571           0 :         { return nMain < rTwo.nMain || ( nMain == rTwo.nMain && ( !nSub ||
     572           0 :           !rTwo.nSub || nSub <= rTwo.nSub ) ); }
     573             : };
     574             : 
     575           0 : static const SwFrm * lcl_CalcDownDist( SwDistance &rRet,
     576             :                                          const Point &rPt,
     577             :                                          const SwCntntFrm *pCnt )
     578             : {
     579           0 :     rRet.nSub = 0;
     580             :     //If the point stays inside the Cnt everything is clear already; the Cntnt
     581             :     //automatically has a distance of 0.
     582           0 :     if ( pCnt->Frm().IsInside( rPt ) )
     583             :     {
     584           0 :         rRet.nMain = 0;
     585           0 :         return pCnt;
     586             :     }
     587             :     else
     588             :     {
     589           0 :         const SwLayoutFrm *pUp = pCnt->IsInTab() ? pCnt->FindTabFrm()->GetUpper() : pCnt->GetUpper();
     590             :         // single column sections need to interconnect to their upper
     591           0 :         while( pUp->IsSctFrm() )
     592           0 :             pUp = pUp->GetUpper();
     593           0 :         const bool bVert = pUp->IsVertical();
     594             :         //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     595           0 :         const bool bVertL2R = pUp->IsVertLR();
     596             : 
     597             :         //Follow the text flow.
     598             :         // #i70582#
     599             :         // --> OD 2009-03-05 - adopted for Support for Classical Mongolian Script
     600             :         const SwTwips nTopForObjPos =
     601             :             bVert
     602             :             ? ( bVertL2R
     603           0 :                 ? ( pCnt->Frm().Left() +
     604           0 :                     pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() )
     605           0 :                 : ( pCnt->Frm().Left() +
     606           0 :                     pCnt->Frm().Width() -
     607           0 :                     pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() ) )
     608           0 :             : ( pCnt->Frm().Top() +
     609           0 :                 pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() );
     610           0 :         if ( pUp->Frm().IsInside( rPt ) )
     611             :         {
     612             :             // <rPt> point is inside environment of given content frame
     613             :             // #i70582#
     614           0 :             if( bVert )
     615             :             //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     616             :             {
     617           0 :                    if ( bVertL2R )
     618           0 :                     rRet.nMain =  rPt.X() - nTopForObjPos;
     619             :                 else
     620           0 :                     rRet.nMain =  nTopForObjPos - rPt.X();
     621             :             }
     622             :             else
     623           0 :                 rRet.nMain =  rPt.Y() - nTopForObjPos;
     624           0 :             return pCnt;
     625             :         }
     626           0 :         else if ( rPt.Y() <= pUp->Frm().Top() )
     627             :         {
     628             :             // <rPt> point is above environment of given content frame
     629             :             // correct for vertical layout?
     630           0 :             rRet.nMain = LONG_MAX;
     631             :         }
     632           0 :         else if( rPt.X() < pUp->Frm().Left() &&
     633           0 :                  rPt.Y() <= ( bVert ? pUp->Frm().Top() : pUp->Frm().Bottom() ) )
     634             :         {
     635             :             // <rPt> point is left of environment of given content frame
     636             :             // seems not to be correct for vertical layout!?
     637           0 :             const SwFrm *pLay = pUp->GetLeaf( MAKEPAGE_NONE, sal_False, pCnt );
     638           0 :             if( !pLay ||
     639           0 :                 (bVert && (pLay->Frm().Top() + pLay->Prt().Bottom()) <rPt.Y())||
     640           0 :                 (!bVert && (pLay->Frm().Left() + pLay->Prt().Right())<rPt.X()) )
     641             :             {
     642             :                 // <rPt> point is in left border of environment
     643             :                 // #i70582#
     644           0 :                 if( bVert )
     645             :                 //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     646             :                 {
     647           0 :                        if ( bVertL2R )
     648           0 :                         rRet.nMain = rPt.X() - nTopForObjPos;
     649             :                     else
     650           0 :                         rRet.nMain =  nTopForObjPos - rPt.X();
     651             :                 }
     652             :                 else
     653           0 :                     rRet.nMain = rPt.Y() - nTopForObjPos;
     654           0 :                 return pCnt;
     655             :             }
     656             :             else
     657           0 :                 rRet.nMain = LONG_MAX;
     658             :         }
     659             :         else
     660             :         {
     661             :             // Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     662             :             rRet.nMain = bVert
     663             :                 ? ( bVertL2R
     664           0 :                     ? ( (pUp->Frm().Left() + pUp->Prt().Right()) - nTopForObjPos )
     665           0 :                     : ( nTopForObjPos - (pUp->Frm().Left() + pUp->Prt().Left() ) ) )
     666           0 :                 : ( (pUp->Frm().Top() + pUp->Prt().Bottom()) - nTopForObjPos );
     667             : 
     668           0 :             const SwFrm *pPre = pCnt;
     669           0 :             const SwFrm *pLay = pUp->GetLeaf( MAKEPAGE_NONE, sal_True, pCnt );
     670           0 :             SwTwips nFrmTop = 0;
     671           0 :             SwTwips nPrtHeight = 0;
     672           0 :             bool bSct = false;
     673           0 :             const SwSectionFrm *pSect = pUp->FindSctFrm();
     674           0 :             if( pSect )
     675             :             {
     676           0 :                 rRet.nSub = rRet.nMain;
     677           0 :                 rRet.nMain = 0;
     678             :             }
     679           0 :             if( pSect && !pSect->IsAnLower( pLay ) )
     680             :             {
     681           0 :                 bSct = false;
     682           0 :                 const SwSectionFrm* pNxtSect = pLay ? pLay->FindSctFrm() : 0;
     683           0 :                 if( pSect->IsAnFollow( pNxtSect ) )
     684             :                 {
     685           0 :                     if( pLay->IsVertical() )
     686             :                     {
     687             :                         //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     688           0 :                         if ( pLay->IsVertLR() )
     689           0 :                             nFrmTop = pLay->Frm().Left();
     690             :                         else
     691           0 :                             nFrmTop = pLay->Frm().Left() + pLay->Frm().Width();
     692           0 :                         nPrtHeight = pLay->Prt().Width();
     693             :                     }
     694             :                     else
     695             :                     {
     696           0 :                         nFrmTop = pLay->Frm().Top();
     697           0 :                         nPrtHeight = pLay->Prt().Height();
     698             :                     }
     699           0 :                     pSect = pNxtSect;
     700             :                 }
     701             :                 else
     702             :                 {
     703           0 :                     pLay = pSect->GetUpper();
     704           0 :                     if( pLay->IsVertical() )
     705             :                     {
     706             :                         //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     707           0 :                         if ( pLay->IsVertLR() )
     708             :                         {
     709           0 :                             nFrmTop = pSect->Frm().Right();
     710           0 :                             nPrtHeight = pLay->Frm().Left() + pLay->Prt().Left()
     711           0 :                                          + pLay->Prt().Width() - pSect->Frm().Left()
     712           0 :                                          - pSect->Frm().Width();
     713             :                          }
     714             :                          else
     715             :                          {
     716           0 :                              nFrmTop = pSect->Frm().Left();
     717           0 :                              nPrtHeight = pSect->Frm().Left() - pLay->Frm().Left()
     718           0 :                                      - pLay->Prt().Left();
     719             :                           }
     720             :                     }
     721             :                     else
     722             :                     {
     723           0 :                         nFrmTop = pSect->Frm().Bottom();
     724           0 :                         nPrtHeight = pLay->Frm().Top() + pLay->Prt().Top()
     725           0 :                                      + pLay->Prt().Height() - pSect->Frm().Top()
     726           0 :                                      - pSect->Frm().Height();
     727             :                     }
     728           0 :                     pSect = 0;
     729             :                 }
     730             :             }
     731           0 :             else if( pLay )
     732             :             {
     733           0 :                 if( pLay->IsVertical() )
     734             :                 {
     735             :                     //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     736           0 :                     if ( pLay->IsVertLR() )
     737             :                     {
     738           0 :                         nFrmTop = pLay->Frm().Left();
     739           0 :                         nPrtHeight = pLay->Prt().Width();
     740             :                     }
     741             :                     else
     742             :                     {
     743           0 :                         nFrmTop = pLay->Frm().Left() + pLay->Frm().Width();
     744           0 :                         nPrtHeight = pLay->Prt().Width();
     745             :                     }
     746             :                 }
     747             :                 else
     748             :                 {
     749           0 :                     nFrmTop = pLay->Frm().Top();
     750           0 :                     nPrtHeight = pLay->Prt().Height();
     751             :                 }
     752           0 :                 bSct = 0 != pSect;
     753             :             }
     754           0 :             while ( pLay && !pLay->Frm().IsInside( rPt ) &&
     755           0 :                     ( pLay->Frm().Top() <= rPt.Y() || pLay->IsInFly() ||
     756           0 :                       ( pLay->IsInSct() &&
     757           0 :                       pLay->FindSctFrm()->GetUpper()->Frm().Top() <= rPt.Y())) )
     758             :             {
     759           0 :                 if ( pLay->IsFtnContFrm() )
     760             :                 {
     761           0 :                     if ( !((SwLayoutFrm*)pLay)->Lower() )
     762             :                     {
     763           0 :                         SwFrm *pDel = (SwFrm*)pLay;
     764           0 :                         pDel->Cut();
     765           0 :                         delete pDel;
     766           0 :                         return pPre;
     767             :                     }
     768           0 :                     return 0;
     769             :                 }
     770             :                 else
     771             :                 {
     772           0 :                     if( bSct || pSect )
     773           0 :                         rRet.nSub += nPrtHeight;
     774             :                     else
     775           0 :                         rRet.nMain += nPrtHeight;
     776           0 :                     pPre = pLay;
     777           0 :                     pLay = pLay->GetLeaf( MAKEPAGE_NONE, sal_True, pCnt );
     778           0 :                     if( pSect && !pSect->IsAnLower( pLay ) )
     779             :                     {   // If we're leaving a SwSectionFrm, the next Leaf-Frm
     780             :                         // is the part of the upper below the SectionFrm.
     781             :                         const SwSectionFrm* pNxtSect = pLay ?
     782           0 :                             pLay->FindSctFrm() : NULL;
     783           0 :                         bSct = false;
     784           0 :                         if( pSect->IsAnFollow( pNxtSect ) )
     785             :                         {
     786           0 :                             pSect = pNxtSect;
     787           0 :                             if( pLay->IsVertical() )
     788             :                             {
     789             :                                 //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     790           0 :                                 if ( pLay->IsVertLR() )
     791             :                                 {
     792           0 :                                     nFrmTop = pLay->Frm().Left();
     793           0 :                                     nPrtHeight = pLay->Prt().Width();
     794             :                                 }
     795             :                                 else
     796             :                                 {
     797           0 :                                     nFrmTop = pLay->Frm().Left() + pLay->Frm().Width();
     798           0 :                                     nPrtHeight = pLay->Prt().Width();
     799             :                                 }
     800             :                             }
     801             :                             else
     802             :                             {
     803           0 :                                 nFrmTop = pLay->Frm().Top();
     804           0 :                                 nPrtHeight = pLay->Prt().Height();
     805             :                             }
     806             :                         }
     807             :                         else
     808             :                         {
     809           0 :                             pLay = pSect->GetUpper();
     810           0 :                             if( pLay->IsVertical() )
     811             :                             {
     812             :                                 //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     813           0 :                                 if ( pLay->IsVertLR() )
     814             :                                 {
     815           0 :                                     nFrmTop = pSect->Frm().Right();
     816           0 :                                     nPrtHeight = pLay->Frm().Left()+pLay->Prt().Left()
     817           0 :                                              + pLay->Prt().Width() - pSect->Frm().Left()
     818           0 :                                              - pSect->Frm().Width();
     819             :                                 }
     820             :                                 else
     821             :                                 {
     822           0 :                                     nFrmTop = pSect->Frm().Left();
     823           0 :                                     nPrtHeight = pSect->Frm().Left() -
     824           0 :                                             pLay->Frm().Left() - pLay->Prt().Left();
     825             :                                 }
     826             :                             }
     827             :                             else
     828             :                             {
     829           0 :                                 nFrmTop = pSect->Frm().Bottom();
     830           0 :                                 nPrtHeight = pLay->Frm().Top()+pLay->Prt().Top()
     831           0 :                                      + pLay->Prt().Height() - pSect->Frm().Top()
     832           0 :                                      - pSect->Frm().Height();
     833             :                             }
     834           0 :                             pSect = 0;
     835             :                         }
     836             :                     }
     837           0 :                     else if( pLay )
     838             :                     {
     839           0 :                         if( pLay->IsVertical() )
     840             :                         {
     841             :                              //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     842           0 :                              if ( pLay->IsVertLR() )
     843             :                               {
     844           0 :                                  nFrmTop = pLay->Frm().Left();
     845           0 :                                  nPrtHeight = pLay->Prt().Width();
     846             :                              }
     847             :                              else
     848             :                              {
     849           0 :                                  nFrmTop = pLay->Frm().Left() + pLay->Frm().Width();
     850           0 :                                  nPrtHeight = pLay->Prt().Width();
     851             :                              }
     852             :                         }
     853             :                         else
     854             :                         {
     855           0 :                             nFrmTop = pLay->Frm().Top();
     856           0 :                             nPrtHeight = pLay->Prt().Height();
     857             :                         }
     858           0 :                         bSct = 0 != pSect;
     859             :                     }
     860             :                 }
     861             :             }
     862           0 :             if ( pLay )
     863             :             {
     864           0 :                 if ( pLay->Frm().IsInside( rPt ) )
     865             :                 {
     866             :                     //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     867           0 :                     SwTwips nDiff = pLay->IsVertical() ? ( pLay->IsVertLR() ? ( rPt.X() - nFrmTop ) : ( nFrmTop - rPt.X() ) )
     868           0 :                                                        : ( rPt.Y() - nFrmTop );
     869           0 :                     if( bSct || pSect )
     870           0 :                         rRet.nSub += nDiff;
     871             :                     else
     872           0 :                         rRet.nMain += nDiff;
     873             :                 }
     874           0 :                 if ( pLay->IsFtnContFrm() && !((SwLayoutFrm*)pLay)->Lower() )
     875             :                 {
     876           0 :                     SwFrm *pDel = (SwFrm*)pLay;
     877           0 :                     pDel->Cut();
     878           0 :                     delete pDel;
     879           0 :                     return 0;
     880             :                 }
     881           0 :                 return pLay;
     882             :             }
     883             :             else
     884           0 :                 rRet.nMain = LONG_MAX;
     885             :         }
     886             :     }
     887           0 :     return 0;
     888             : }
     889             : 
     890           0 : static sal_uLong lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay,
     891             :                           const SwCntntFrm *& rpCnt,
     892             :                           const bool bBody, const sal_Bool bFtn )
     893             : {
     894             :     // Searches below pLay the nearest Cnt to the point. The reference point of
     895             :     //the Cntnts is always the left upper corner.
     896             :     //The Cnt should preferably be above the point.
     897             : 
     898             : #if OSL_DEBUG_LEVEL > 1
     899             :     Point arPoint( rPt );
     900             : #endif
     901             : 
     902           0 :     rpCnt = 0;
     903           0 :     sal_uLong nDistance = ULONG_MAX;
     904           0 :     sal_uLong nNearest  = ULONG_MAX;
     905           0 :     const SwCntntFrm *pCnt = pLay->ContainsCntnt();
     906             : 
     907           0 :     while ( pCnt && (bBody != pCnt->IsInDocBody() || bFtn != pCnt->IsInFtn()))
     908             :     {
     909           0 :         pCnt = pCnt->GetNextCntntFrm();
     910           0 :         if ( !pLay->IsAnLower( pCnt ) )
     911           0 :             pCnt = 0;
     912             :     }
     913           0 :     const SwCntntFrm *pNearest = pCnt;
     914           0 :     if ( pCnt )
     915             :     {
     916           0 :         do
     917             :         {
     918             :             //Calculate the distance between those two points.
     919             :             //'delta' X^2 + 'delta' Y^2 = 'distance'^2
     920           0 :             sal_uInt32 dX = Max( pCnt->Frm().Left(), rPt.X() ) -
     921           0 :                        Min( pCnt->Frm().Left(), rPt.X() ),
     922           0 :                   dY = Max( pCnt->Frm().Top(), rPt.Y() ) -
     923           0 :                        Min( pCnt->Frm().Top(), rPt.Y() );
     924           0 :             BigInt dX1( dX ), dY1( dY );
     925           0 :             dX1 *= dX1; dY1 *= dY1;
     926           0 :             const sal_uLong nDiff = ::SqRt( dX1 + dY1 );
     927           0 :             if ( pCnt->Frm().Top() <= rPt.Y() )
     928             :             {
     929           0 :                 if ( nDiff < nDistance )
     930             :                 {
     931             :                     //This one is the nearer one
     932           0 :                     nDistance = nNearest = nDiff;
     933           0 :                     rpCnt = pNearest = pCnt;
     934             :                 }
     935             :             }
     936           0 :             else if ( nDiff < nNearest )
     937             :             {
     938           0 :                 nNearest = nDiff;
     939           0 :                 pNearest = pCnt;
     940             :             }
     941           0 :             pCnt = pCnt->GetNextCntntFrm();
     942           0 :             while ( pCnt &&
     943           0 :                     (bBody != pCnt->IsInDocBody() || bFtn != pCnt->IsInFtn()))
     944           0 :                 pCnt = pCnt->GetNextCntntFrm();
     945             : 
     946           0 :         }  while ( pCnt && pLay->IsAnLower( pCnt ) );
     947             :     }
     948           0 :     if ( nDistance == ULONG_MAX )
     949           0 :     {   rpCnt = pNearest;
     950           0 :         return nNearest;
     951             :     }
     952           0 :     return nDistance;
     953             : }
     954             : 
     955           0 : static const SwCntntFrm * lcl_FindCnt( const Point &rPt, const SwCntntFrm *pCnt,
     956             :                                   const bool bBody, const sal_Bool bFtn )
     957             : {
     958             :     //Starting from pCnt searches the CntntFrm whose left upper corner is the
     959             :     //nearest to the point.
     960             :     //Always returns a CntntFrm.
     961             : 
     962             :     //First the nearest Cntnt inside the page which contains the Cntnt is
     963             :     //searched. Starting from this page the pages in both directions need to
     964             :     //be considered. If possible a Cntnt is returned whose Y-position is
     965             :     //above the point.
     966             :     const SwCntntFrm  *pRet, *pNew;
     967           0 :     const SwLayoutFrm *pLay = pCnt->FindPageFrm();
     968             :     sal_uLong nDist;
     969             : 
     970           0 :     nDist = ::lcl_FindCntDiff( rPt, pLay, pNew, bBody, bFtn );
     971           0 :     if ( pNew )
     972           0 :         pRet = pNew;
     973             :     else
     974           0 :     {   pRet  = pCnt;
     975           0 :         nDist = ULONG_MAX;
     976             :     }
     977           0 :     const SwCntntFrm *pNearest = pRet;
     978           0 :     sal_uLong nNearest = nDist;
     979             : 
     980           0 :     if ( pLay )
     981             :     {
     982           0 :         const SwLayoutFrm *pPge = pLay;
     983           0 :         sal_uLong nOldNew = ULONG_MAX;
     984           0 :         for ( sal_uInt16 i = 0; pPge->GetPrev() && (i < 3); ++i )
     985             :         {
     986           0 :             pPge = (SwLayoutFrm*)pPge->GetPrev();
     987           0 :             const sal_uLong nNew = ::lcl_FindCntDiff( rPt, pPge, pNew, bBody, bFtn );
     988           0 :             if ( nNew < nDist )
     989             :             {
     990           0 :                 if ( pNew->Frm().Top() <= rPt.Y() )
     991             :                 {
     992           0 :                     pRet = pNearest = pNew;
     993           0 :                     nDist = nNearest = nNew;
     994             :                 }
     995           0 :                 else if ( nNew < nNearest )
     996             :                 {
     997           0 :                     pNearest = pNew;
     998           0 :                     nNearest = nNew;
     999             :                 }
    1000             :             }
    1001           0 :             else if ( nOldNew != ULONG_MAX && nNew > nOldNew )
    1002           0 :                 break;
    1003             :             else
    1004           0 :                 nOldNew = nNew;
    1005             : 
    1006             :         }
    1007           0 :         pPge = pLay;
    1008           0 :         nOldNew = ULONG_MAX;
    1009           0 :         for ( sal_uInt16 j = 0; pPge->GetNext() && (j < 3); ++j )
    1010             :         {
    1011           0 :             pPge = (SwLayoutFrm*)pPge->GetNext();
    1012           0 :             const sal_uLong nNew = ::lcl_FindCntDiff( rPt, pPge, pNew, bBody, bFtn );
    1013           0 :             if ( nNew < nDist )
    1014             :             {
    1015           0 :                 if ( pNew->Frm().Top() <= rPt.Y() )
    1016             :                 {
    1017           0 :                     pRet = pNearest = pNew;
    1018           0 :                     nDist = nNearest = nNew;
    1019             :                 }
    1020           0 :                 else if ( nNew < nNearest )
    1021             :                 {
    1022           0 :                     pNearest = pNew;
    1023           0 :                     nNearest = nNew;
    1024             :                 }
    1025             :             }
    1026           0 :             else if ( nOldNew != ULONG_MAX && nNew > nOldNew )
    1027           0 :                 break;
    1028             :             else
    1029           0 :                 nOldNew = nNew;
    1030             :         }
    1031             :     }
    1032           0 :     if ( (pRet->Frm().Top() > rPt.Y()) )
    1033           0 :         return pNearest;
    1034             :     else
    1035           0 :         return pRet;
    1036             : }
    1037             : 
    1038           0 : static void lcl_PointToPrt( Point &rPoint, const SwFrm *pFrm )
    1039             : {
    1040           0 :     SwRect aTmp( pFrm->Prt() );
    1041           0 :     aTmp += pFrm->Frm().Pos();
    1042           0 :     if ( rPoint.X() < aTmp.Left() )
    1043           0 :         rPoint.X() = aTmp.Left();
    1044           0 :     else if ( rPoint.X() > aTmp.Right() )
    1045           0 :         rPoint.X() = aTmp.Right();
    1046           0 :     if ( rPoint.Y() < aTmp.Top() )
    1047           0 :         rPoint.Y() = aTmp.Top();
    1048           0 :     else if ( rPoint.Y() > aTmp.Bottom() )
    1049           0 :         rPoint.Y() = aTmp.Bottom();
    1050             : 
    1051           0 : }
    1052             : 
    1053           0 : const SwCntntFrm *FindAnchor( const SwFrm *pOldAnch, const Point &rNew,
    1054             :                               const sal_Bool bBodyOnly )
    1055             : {
    1056             :     //Search the nearest Cnt around the given document position in the text
    1057             :     //flow. The given anchor is the starting Frm.
    1058             :     const SwCntntFrm* pCnt;
    1059           0 :     if ( pOldAnch->IsCntntFrm() )
    1060             :     {
    1061           0 :         pCnt = (const SwCntntFrm*)pOldAnch;
    1062             :     }
    1063             :     else
    1064             :     {
    1065           0 :         Point aTmp( rNew );
    1066           0 :         SwLayoutFrm *pTmpLay = (SwLayoutFrm*)pOldAnch;
    1067           0 :         if( pTmpLay->IsRootFrm() )
    1068             :         {
    1069           0 :             SwRect aTmpRect( aTmp, Size(0,0) );
    1070           0 :             pTmpLay = (SwLayoutFrm*)::FindPage( aTmpRect, pTmpLay->Lower() );
    1071             :         }
    1072           0 :         pCnt = pTmpLay->GetCntntPos( aTmp, sal_False, bBodyOnly );
    1073             :     }
    1074             : 
    1075             :     //Take care to use meaningful ranges during search. This means to not enter
    1076             :     //or leave header/footer in this case.
    1077           0 :     const bool bBody = pCnt->IsInDocBody() || bBodyOnly;
    1078           0 :     const sal_Bool bFtn  = !bBodyOnly && pCnt->IsInFtn();
    1079             : 
    1080           0 :     Point aNew( rNew );
    1081           0 :     if ( bBody )
    1082             :     {
    1083             :         //#38848 drag from page margin into the body.
    1084           0 :         const SwFrm *pPage = pCnt->FindPageFrm();
    1085           0 :         ::lcl_PointToPrt( aNew, pPage->GetUpper() );
    1086           0 :         SwRect aTmp( aNew, Size( 0, 0 ) );
    1087           0 :         pPage = ::FindPage( aTmp, pPage );
    1088           0 :         ::lcl_PointToPrt( aNew, pPage );
    1089             :     }
    1090             : 
    1091           0 :     if ( pCnt->IsInDocBody() == bBody && pCnt->Frm().IsInside( aNew ) )
    1092           0 :         return pCnt;
    1093           0 :     else if ( pOldAnch->IsInDocBody() || pOldAnch->IsPageFrm() )
    1094             :     {
    1095             :         // Maybe the selected anchor is on the same page as the current anchor.
    1096             :         // With this we won't run into problems with the columns.
    1097           0 :         Point aTmp( aNew );
    1098           0 :         const SwCntntFrm *pTmp = pCnt->FindPageFrm()->
    1099           0 :                                         GetCntntPos( aTmp, sal_False, sal_True, sal_False );
    1100           0 :         if ( pTmp && pTmp->Frm().IsInside( aNew ) )
    1101           0 :             return pTmp;
    1102             :     }
    1103             : 
    1104             :     //Starting from the anchor we now search in both directions until we found
    1105             :     //the nearest one respectively.
    1106             :     //Not the direct distance is relevant but the distance which needs to be
    1107             :     //traveled through the text flow.
    1108             :     const SwCntntFrm *pUpLst;
    1109           0 :     const SwCntntFrm *pUpFrm = pCnt;
    1110           0 :     SwDistance nUp, nUpLst;
    1111           0 :     ::lcl_CalcDownDist( nUp, aNew, pUpFrm );
    1112           0 :     SwDistance nDown = nUp;
    1113           0 :     bool bNegAllowed = true;// Make it possible to leave the negative section once.
    1114           0 :     do
    1115             :     {
    1116           0 :         pUpLst = pUpFrm; nUpLst = nUp;
    1117           0 :         pUpFrm = pUpLst->GetPrevCntntFrm();
    1118           0 :         while ( pUpFrm &&
    1119           0 :                 (bBody != pUpFrm->IsInDocBody() || bFtn != pUpFrm->IsInFtn()))
    1120           0 :             pUpFrm = pUpFrm->GetPrevCntntFrm();
    1121           0 :         if ( pUpFrm )
    1122             :         {
    1123           0 :             ::lcl_CalcDownDist( nUp, aNew, pUpFrm );
    1124             :             //It makes sense to search further, if the distance grows inside
    1125             :             //a table.
    1126           0 :             if ( pUpLst->IsInTab() && pUpFrm->IsInTab() )
    1127             :             {
    1128           0 :                 while ( pUpFrm && ((nUpLst < nUp && pUpFrm->IsInTab()) ||
    1129           0 :                         bBody != pUpFrm->IsInDocBody()) )
    1130             :                 {
    1131           0 :                     pUpFrm = pUpFrm->GetPrevCntntFrm();
    1132           0 :                     if ( pUpFrm )
    1133           0 :                         ::lcl_CalcDownDist( nUp, aNew, pUpFrm );
    1134             :                 }
    1135             :             }
    1136             :         }
    1137           0 :         if ( !pUpFrm )
    1138           0 :             nUp.nMain = LONG_MAX;
    1139           0 :         if ( nUp.nMain >= 0 && LONG_MAX != nUp.nMain )
    1140             :         {
    1141           0 :             bNegAllowed = false;
    1142           0 :             if ( nUpLst.nMain < 0 ) //don't take the wrong one, if the value
    1143             :                                     //just changed from negative to positive.
    1144           0 :             {   pUpLst = pUpFrm;
    1145           0 :                 nUpLst = nUp;
    1146             :             }
    1147             :         }
    1148           0 :     } while ( pUpFrm && ( ( bNegAllowed && nUp.nMain < 0 ) || ( nUp <= nUpLst ) ) );
    1149             : 
    1150             :     const SwCntntFrm *pDownLst;
    1151           0 :     const SwCntntFrm *pDownFrm = pCnt;
    1152           0 :     SwDistance nDownLst;
    1153           0 :     if ( nDown.nMain < 0 )
    1154           0 :         nDown.nMain = LONG_MAX;
    1155           0 :     do
    1156             :     {
    1157           0 :         pDownLst = pDownFrm; nDownLst = nDown;
    1158           0 :         pDownFrm = pDownLst->GetNextCntntFrm();
    1159           0 :         while ( pDownFrm &&
    1160           0 :                 (bBody != pDownFrm->IsInDocBody() || bFtn != pDownFrm->IsInFtn()))
    1161           0 :             pDownFrm = pDownFrm->GetNextCntntFrm();
    1162           0 :         if ( pDownFrm )
    1163             :         {
    1164           0 :             ::lcl_CalcDownDist( nDown, aNew, pDownFrm );
    1165           0 :             if ( nDown.nMain < 0 )
    1166           0 :                 nDown.nMain = LONG_MAX;
    1167             :             //It makes sense to search further, if the distance grows inside
    1168             :             //a table.
    1169           0 :             if ( pDownLst->IsInTab() && pDownFrm->IsInTab() )
    1170             :             {
    1171           0 :                 while ( pDownFrm && ( ( nDown.nMain != LONG_MAX && pDownFrm->IsInTab()) || bBody != pDownFrm->IsInDocBody() ) )
    1172             :                 {
    1173           0 :                     pDownFrm = pDownFrm->GetNextCntntFrm();
    1174           0 :                     if ( pDownFrm )
    1175           0 :                         ::lcl_CalcDownDist( nDown, aNew, pDownFrm );
    1176           0 :                     if ( nDown.nMain < 0 )
    1177           0 :                         nDown.nMain = LONG_MAX;
    1178             :                 }
    1179             :             }
    1180             :         }
    1181           0 :         if ( !pDownFrm )
    1182           0 :             nDown.nMain = LONG_MAX;
    1183             : 
    1184           0 :     } while ( pDownFrm && nDown <= nDownLst &&
    1185             :               nDown.nMain != LONG_MAX && nDownLst.nMain != LONG_MAX );
    1186             : 
    1187             :     //If we couldn't find one in both directions, we'll search the Cntnt whose
    1188             :     //left upper corner is the nearest to the point. Such a situation may
    1189             :     //happen, if the point doesn't lay in the text flow but in any margin.
    1190           0 :     if ( nDownLst.nMain == LONG_MAX && nUpLst.nMain == LONG_MAX )
    1191             :     {
    1192             :         // If an OLE objects, which is contained in a fly frame
    1193             :         // is resized in inplace mode and the new Position is outside the
    1194             :         // fly frame, we do not want to leave our fly frame.
    1195           0 :         if ( pCnt->IsInFly() )
    1196           0 :             return pCnt;
    1197             : 
    1198           0 :         return ::lcl_FindCnt( aNew, pCnt, bBody, bFtn );
    1199             :     }
    1200             :     else
    1201           0 :         return nDownLst < nUpLst ? pDownLst : pUpLst;
    1202             : }
    1203             : 
    1204             : /*************************************************************************
    1205             : |*
    1206             : |*  SwFlyAtCntFrm::SetAbsPos()
    1207             : |*
    1208             : |*************************************************************************/
    1209             : 
    1210           0 : void SwFlyAtCntFrm::SetAbsPos( const Point &rNew )
    1211             : {
    1212           0 :     SwPageFrm *pOldPage = FindPageFrm();
    1213           0 :     const SwRect aOld( GetObjRectWithSpaces() );
    1214           0 :     Point aNew( rNew );
    1215             :     //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
    1216           0 :       if( ( GetAnchorFrm()->IsVertical() && !GetAnchorFrm()->IsVertLR() ) || GetAnchorFrm()->IsRightToLeft() )
    1217           0 :         aNew.X() += Frm().Width();
    1218           0 :     SwCntntFrm *pCnt = (SwCntntFrm*)::FindAnchor( GetAnchorFrm(), aNew );
    1219           0 :     if( pCnt->IsProtected() )
    1220           0 :         pCnt = (SwCntntFrm*)GetAnchorFrm();
    1221             : 
    1222           0 :     SwPageFrm *pTmpPage = 0;
    1223           0 :     const bool bVert = pCnt->IsVertical();
    1224             :     //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
    1225           0 :     const bool bVertL2R = pCnt->IsVertLR();
    1226           0 :     const sal_Bool bRTL = pCnt->IsRightToLeft();
    1227             : 
    1228           0 :     if( ( !bVert != !GetAnchorFrm()->IsVertical() ) ||
    1229           0 :         ( !bRTL !=  !GetAnchorFrm()->IsRightToLeft() ) )
    1230             :     {
    1231           0 :         if( bVert || bRTL )
    1232           0 :             aNew.X() += Frm().Width();
    1233             :         else
    1234           0 :             aNew.X() -= Frm().Width();
    1235             :     }
    1236             : 
    1237           0 :     if ( pCnt->IsInDocBody() )
    1238             :     {
    1239             :         //#38848 drag from page margin into the body.
    1240           0 :         pTmpPage = pCnt->FindPageFrm();
    1241           0 :         ::lcl_PointToPrt( aNew, pTmpPage->GetUpper() );
    1242           0 :         SwRect aTmp( aNew, Size( 0, 0 ) );
    1243           0 :         pTmpPage = (SwPageFrm*)::FindPage( aTmp, pTmpPage );
    1244           0 :         ::lcl_PointToPrt( aNew, pTmpPage );
    1245             :     }
    1246             : 
    1247             :     //Setup RelPos, only invalidate if requested.
    1248             :     //rNew is an absolute position. We need to calculate the distance from rNew
    1249             :     //to the anchor inside the text flow to correctly set RelPos.
    1250             : //!!!!!We can optimize here: FindAnchor could also return RelPos!
    1251           0 :     const SwFrm *pFrm = 0;
    1252             :     SwTwips nY;
    1253           0 :     if ( pCnt->Frm().IsInside( aNew ) )
    1254             :     {
    1255             :         // #i70582#
    1256             :         const SwTwips nTopForObjPos =
    1257             :                 bVert
    1258             :                 ? ( bVertL2R
    1259           0 :                     ? ( pCnt->Frm().Left() +
    1260           0 :                         pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() )
    1261           0 :                     : ( pCnt->Frm().Left() +
    1262           0 :                         pCnt->Frm().Width() -
    1263           0 :                         pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() ) )
    1264           0 :                 : ( pCnt->Frm().Top() +
    1265           0 :                     pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() );
    1266           0 :         if( bVert )
    1267             :         //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
    1268             :         {
    1269           0 :             if ( bVertL2R )
    1270           0 :                 nY = rNew.X() - nTopForObjPos;
    1271             :             else
    1272           0 :                 nY = nTopForObjPos - rNew.X() - Frm().Width();
    1273             :         }
    1274             :         else
    1275             :         {
    1276           0 :             nY = rNew.Y() - nTopForObjPos;
    1277             :         }
    1278             :     }
    1279             :     else
    1280             :     {
    1281           0 :         SwDistance aDist;
    1282           0 :         pFrm = ::lcl_CalcDownDist( aDist, aNew, pCnt );
    1283           0 :         nY = aDist.nMain + aDist.nSub;
    1284             :     }
    1285             : 
    1286           0 :     SwTwips nX = 0;
    1287             : 
    1288           0 :     if ( pCnt->IsFollow() )
    1289             :     {
    1290             :         // Flys are never attached to the follow but always to the master,
    1291             :         // which we're going to search now.
    1292           0 :         const SwCntntFrm *pOriginal = pCnt;
    1293           0 :         const SwCntntFrm *pFollow = pCnt;
    1294           0 :         while ( pCnt->IsFollow() )
    1295             :         {
    1296           0 :             do
    1297           0 :             {   pCnt = pCnt->GetPrevCntntFrm();
    1298           0 :             } while ( pCnt->GetFollow() != pFollow );
    1299           0 :             pFollow = pCnt;
    1300             :         }
    1301           0 :         SwTwips nDiff = 0;
    1302           0 :         do
    1303           0 :         {   const SwFrm *pUp = pFollow->GetUpper();
    1304           0 :             if( pUp->IsVertical() )
    1305             :             //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
    1306             :             {
    1307           0 :                 if ( pUp->IsVertLR()  )
    1308           0 :                     nDiff += pUp->Prt().Width() - pFollow->GetRelPos().X();
    1309             :                 else
    1310           0 :                        nDiff += pFollow->Frm().Left() + pFollow->Frm().Width()
    1311           0 :                              - pUp->Frm().Left() - pUp->Prt().Left();
    1312             :             }
    1313             :             else
    1314           0 :                 nDiff += pUp->Prt().Height() - pFollow->GetRelPos().Y();
    1315           0 :             pFollow = pFollow->GetFollow();
    1316             :         } while ( pFollow != pOriginal );
    1317           0 :         nY += nDiff;
    1318           0 :         if( bVert )
    1319           0 :             nX = pCnt->Frm().Top() - pOriginal->Frm().Top();
    1320             :         else
    1321           0 :             nX = pCnt->Frm().Left() - pOriginal->Frm().Left();
    1322             :     }
    1323             : 
    1324           0 :     if ( nY == LONG_MAX )
    1325             :     {
    1326             :         // #i70582#
    1327             :         const SwTwips nTopForObjPos =
    1328             :                 bVert
    1329             :                 ? ( bVertL2R
    1330           0 :                     ? ( pCnt->Frm().Left() +
    1331           0 :                         pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() )
    1332           0 :                     : ( pCnt->Frm().Left() +
    1333           0 :                         pCnt->Frm().Width() -
    1334           0 :                         pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() ) )
    1335           0 :                 : ( pCnt->Frm().Top() +
    1336           0 :                     pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() );
    1337           0 :         if( bVert )
    1338             :         //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
    1339             :         {
    1340           0 :             if ( bVertL2R )
    1341           0 :                 nY = rNew.X() - nTopForObjPos;
    1342             :             else
    1343           0 :                 nY = nTopForObjPos - rNew.X();
    1344             :         }
    1345             :         else
    1346             :         {
    1347           0 :             nY = rNew.Y() - nTopForObjPos;
    1348             :         }
    1349             :     }
    1350             : 
    1351           0 :     SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
    1352           0 :     const SwFmtSurround& rSurround = pFmt->GetSurround();
    1353             :     const sal_Bool bWrapThrough =
    1354           0 :         rSurround.GetSurround() == SURROUND_THROUGHT;
    1355           0 :     SwTwips nBaseOfstForFly = 0;
    1356           0 :     const SwFrm* pTmpFrm = pFrm ? pFrm : pCnt;
    1357           0 :     if ( pTmpFrm->IsTxtFrm() )
    1358             :         nBaseOfstForFly =
    1359           0 :             ((SwTxtFrm*)pTmpFrm)->GetBaseOfstForFly( !bWrapThrough );
    1360             : 
    1361           0 :     if( bVert )
    1362             :     {
    1363           0 :         if( !pFrm )
    1364           0 :             nX += rNew.Y() - pCnt->Frm().Top() - nBaseOfstForFly;
    1365             :         else
    1366           0 :             nX = rNew.Y() - pFrm->Frm().Top() - nBaseOfstForFly;
    1367             :     }
    1368             :     else
    1369             :     {
    1370           0 :         if( !pFrm )
    1371             :         {
    1372           0 :             if ( pCnt->IsRightToLeft() )
    1373           0 :                 nX += pCnt->Frm().Right() - rNew.X() - Frm().Width() +
    1374           0 :                       nBaseOfstForFly;
    1375             :             else
    1376           0 :                 nX += rNew.X() - pCnt->Frm().Left() - nBaseOfstForFly;
    1377             :         }
    1378             :         else
    1379             :         {
    1380           0 :             if ( pFrm->IsRightToLeft() )
    1381           0 :                 nX += pFrm->Frm().Right() - rNew.X() - Frm().Width() +
    1382           0 :                       nBaseOfstForFly;
    1383             :             else
    1384           0 :                 nX = rNew.X() - pFrm->Frm().Left() - nBaseOfstForFly;
    1385             :         }
    1386             :     }
    1387           0 :     GetFmt()->GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
    1388             : 
    1389           0 :     if( pCnt != GetAnchorFrm() || ( IsAutoPos() && pCnt->IsTxtFrm() &&
    1390           0 :                                   GetFmt()->getIDocumentSettingAccess()->get(IDocumentSettingAccess::HTML_MODE)) )
    1391             :     {
    1392             :         //Set the anchor attribute according to the new Cnt.
    1393           0 :         SwFmtAnchor aAnch( pFmt->GetAnchor() );
    1394           0 :         SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
    1395           0 :         if( IsAutoPos() && pCnt->IsTxtFrm() )
    1396             :         {
    1397           0 :             SwCrsrMoveState eTmpState( MV_SETONLYTEXT );
    1398           0 :             Point aPt( rNew );
    1399           0 :             if( pCnt->GetCrsrOfst( pPos, aPt, &eTmpState )
    1400           0 :                 && pPos->nNode == *pCnt->GetNode() )
    1401             :             {
    1402           0 :                 ResetLastCharRectHeight();
    1403           0 :                 if( text::RelOrientation::CHAR == pFmt->GetVertOrient().GetRelationOrient() )
    1404           0 :                     nY = LONG_MAX;
    1405           0 :                 if( text::RelOrientation::CHAR == pFmt->GetHoriOrient().GetRelationOrient() )
    1406           0 :                     nX = LONG_MAX;
    1407             :             }
    1408             :             else
    1409             :             {
    1410           0 :                 pPos->nNode = *pCnt->GetNode();
    1411           0 :                 pPos->nContent.Assign( pCnt->GetNode(), 0 );
    1412             :             }
    1413             :         }
    1414             :         else
    1415             :         {
    1416           0 :             pPos->nNode = *pCnt->GetNode();
    1417           0 :             pPos->nContent.Assign( pCnt->GetNode(), 0 );
    1418             :         }
    1419             : 
    1420             :         // handle change of anchor node:
    1421             :         // if count of the anchor frame also change, the fly frames have to be
    1422             :         // re-created. Thus, delete all fly frames except the <this> before the
    1423             :         // anchor attribute is change and re-create them afterwards.
    1424             :         {
    1425           0 :             SwHandleAnchorNodeChg aHandleAnchorNodeChg( *pFmt, aAnch, this );
    1426           0 :             pFmt->GetDoc()->SetAttr( aAnch, *pFmt );
    1427           0 :         }
    1428             :     }
    1429             :     // #i28701# - use new method <GetPageFrm()>
    1430           0 :     else if ( pTmpPage && pTmpPage != GetPageFrm() )
    1431           0 :         GetPageFrm()->MoveFly( this, pTmpPage );
    1432             : 
    1433           0 :     const Point aRelPos = bVert ? Point( -nY, nX ) : Point( nX, nY );
    1434             : 
    1435           0 :     ChgRelPos( aRelPos );
    1436             : 
    1437           0 :     GetFmt()->GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
    1438             : 
    1439           0 :     if ( pOldPage != FindPageFrm() )
    1440           0 :         ::Notify_Background( GetVirtDrawObj(), pOldPage, aOld, PREP_FLY_LEAVE,
    1441           0 :                              sal_False );
    1442           0 : }
    1443             : 
    1444             : /** method to assure that anchored object is registered at the correct
    1445             :     page frame
    1446             : 
    1447             :     #i28701#
    1448             :     takes over functionality of deleted method <SwFlyAtCntFrm::AssertPage()>
    1449             : */
    1450          33 : void SwFlyAtCntFrm::RegisterAtCorrectPage()
    1451             : {
    1452          33 :     SwPageFrm* pPageFrm( 0L );
    1453          33 :     if ( GetVertPosOrientFrm() )
    1454             :     {
    1455          33 :         pPageFrm = const_cast<SwPageFrm*>(GetVertPosOrientFrm()->FindPageFrm());
    1456             :     }
    1457          33 :     if ( pPageFrm && GetPageFrm() != pPageFrm )
    1458             :     {
    1459           0 :         if ( GetPageFrm() )
    1460           0 :             GetPageFrm()->MoveFly( this, pPageFrm );
    1461             :         else
    1462           0 :             pPageFrm->AppendFlyToPage( this );
    1463             :     }
    1464          33 : }
    1465             : 
    1466             : // #i26791#
    1467             : //void SwFlyAtCntFrm::MakeFlyPos()
    1468          33 : void SwFlyAtCntFrm::MakeObjPos()
    1469             : {
    1470             :     // if fly frame position is valid, nothing is to do. Thus, return
    1471          33 :     if ( bValidPos )
    1472             :     {
    1473             :         return;
    1474             :     }
    1475             : 
    1476             :     // #i26791# - validate position flag here.
    1477          33 :     bValidPos = sal_True;
    1478             : 
    1479             :     // #i35911# - no calculation of new position, if
    1480             :     // anchored object is marked that it clears its environment and its
    1481             :     // environment is already cleared.
    1482             :     // before checking for cleared environment
    1483             :     // check, if member <mpVertPosOrientFrm> is set.
    1484          41 :     if ( GetVertPosOrientFrm() &&
    1485           8 :          ClearedEnvironment() && HasClearedEnvironment() )
    1486             :     {
    1487             :         return;
    1488             :     }
    1489             : 
    1490             :     // use new class to position object
    1491             :     objectpositioning::SwToCntntAnchoredObjectPosition
    1492          33 :             aObjPositioning( *GetVirtDrawObj() );
    1493          33 :     aObjPositioning.CalcPosition();
    1494             : 
    1495          33 :     SetVertPosOrientFrm ( aObjPositioning.GetVertPosOrientFrm() );
    1496             : }
    1497             : 
    1498             : // #i28701#
    1499          27 : bool SwFlyAtCntFrm::_InvalidationAllowed( const InvalidationType _nInvalid ) const
    1500             : {
    1501          27 :     bool bAllowed( SwFlyFreeFrm::_InvalidationAllowed( _nInvalid ) );
    1502             : 
    1503             :     // forbiddance of base instance can't be over ruled.
    1504          27 :     if ( bAllowed )
    1505             :     {
    1506          27 :         if ( _nInvalid == INVALID_POS ||
    1507             :              _nInvalid == INVALID_ALL )
    1508             :         {
    1509          15 :             bAllowed = InvalidationOfPosAllowed();
    1510             :         }
    1511             :     }
    1512             : 
    1513          27 :     return bAllowed;
    1514             : }
    1515             : 
    1516             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10