LCOV - code coverage report
Current view: top level - sw/source/core/layout - anchoredobject.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 277 358 77.4 %
Date: 2014-04-11 Functions: 53 65 81.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <txtfrm.hxx>
      21             : #include <fmtornt.hxx>
      22             : // --> #i28701#
      23             : #include <doc.hxx>
      24             : #include <fmtsrnd.hxx>
      25             : #include <dcontact.hxx>
      26             : #include <editeng/ulspitem.hxx>
      27             : #include <editeng/lrspitem.hxx>
      28             : #include <sortedobjs.hxx>
      29             : #include <pagefrm.hxx>
      30             : // --> #i35911#
      31             : #include <layouter.hxx>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35             : // --> #i28701# -
      36             : // implementation of helper class <SwObjPositioningInProgress>
      37             : 
      38        4723 : SwObjPositioningInProgress::SwObjPositioningInProgress( SdrObject& _rSdrObj ) :
      39             :     mpAnchoredObj( 0L ),
      40             :     // --> #i52904#
      41        4723 :     mbOldObjPositioningInProgress( false )
      42             : {
      43        4723 :     mpAnchoredObj = ::GetUserCall( &_rSdrObj )->GetAnchoredObj( &_rSdrObj );
      44             :     // --> #i52904#
      45        4723 :     mbOldObjPositioningInProgress = mpAnchoredObj->IsPositioningInProgress();
      46        4723 :     mpAnchoredObj->SetPositioningInProgress( true );
      47        4723 : }
      48        1993 : SwObjPositioningInProgress::SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj ) :
      49             :     mpAnchoredObj( &_rAnchoredObj ),
      50             :     // --> #i52904#
      51        1993 :     mbOldObjPositioningInProgress( false )
      52             : {
      53             :     // --> #i52904#
      54        1993 :     mbOldObjPositioningInProgress = mpAnchoredObj->IsPositioningInProgress();
      55        1993 :     mpAnchoredObj->SetPositioningInProgress( true );
      56        1993 : }
      57             : 
      58        6716 : SwObjPositioningInProgress::~SwObjPositioningInProgress()
      59             : {
      60        6716 :     if ( mpAnchoredObj )
      61             :     {
      62             :         // --> #i52904#
      63        6716 :         mpAnchoredObj->SetPositioningInProgress( mbOldObjPositioningInProgress );
      64             :     }
      65        6716 : }
      66             : 
      67             : // SwAnchoredObject
      68             : 
      69      228306 : TYPEINIT0(SwAnchoredObject);
      70             : 
      71        2576 : SwAnchoredObject::SwAnchoredObject() :
      72             :     mpDrawObj( 0L ),
      73             :     mpAnchorFrm( 0L ),
      74             :     // --> #i28701#
      75             :     mpPageFrm( 0L ),
      76             :     maRelPos(),
      77             :     maLastCharRect(),
      78             :     mnLastTopOfLine( 0L ),
      79             :     mpVertPosOrientFrm( 0L ),
      80             :     // --> #i28701#
      81             :     mbPositioningInProgress( false ),
      82             :     mbConsiderForTextWrap( false ),
      83             :     mbPositionLocked( false ),
      84             :     // --> #i40147#
      85             :     mbKeepPositionLockedForSection( false ),
      86             :     mbRestartLayoutProcess( false ),
      87             :     // --> #i35911#
      88             :     mbClearedEnvironment( false ),
      89             :     // --> #i3317#
      90             :     mbTmpConsiderWrapInfluence( false ),
      91             :     // --> #i68520#
      92             :     maObjRectWithSpaces(),
      93             :     mbObjRectWithSpacesValid( false ),
      94        2576 :     maLastObjRect()
      95             : {
      96        2576 : }
      97             : 
      98        5720 : void SwAnchoredObject::ClearVertPosOrientFrm()
      99             : {
     100        5720 :     if (mpVertPosOrientFrm)
     101             :     {
     102        1966 :         const_cast<SwLayoutFrm*>(mpVertPosOrientFrm)->ClearVertPosOrientFrmFor(this);
     103        1966 :         mpVertPosOrientFrm = NULL;
     104             :     }
     105        5720 : }
     106             : 
     107        2575 : SwAnchoredObject::~SwAnchoredObject()
     108             : {
     109        2575 :     ClearVertPosOrientFrm();
     110        2575 : }
     111             : 
     112        2576 : void SwAnchoredObject::SetDrawObj( SdrObject& _rDrawObj )
     113             : {
     114        2576 :     mpDrawObj = &_rDrawObj;
     115        2576 : }
     116             : 
     117     1330766 : const SdrObject* SwAnchoredObject::GetDrawObj() const
     118             : {
     119     1330766 :     return mpDrawObj;
     120             : }
     121             : 
     122      126353 : SdrObject* SwAnchoredObject::DrawObj()
     123             : {
     124      126353 :     return mpDrawObj;
     125             : }
     126             : 
     127      239201 : const SwFrm* SwAnchoredObject::GetAnchorFrm() const
     128             : {
     129      239201 :     return mpAnchorFrm;
     130             : }
     131             : 
     132      123591 : SwFrm* SwAnchoredObject::AnchorFrm()
     133             : {
     134      123591 :     return mpAnchorFrm;
     135             : }
     136             : 
     137        4746 : void SwAnchoredObject::ChgAnchorFrm( SwFrm* _pNewAnchorFrm )
     138             : {
     139        4746 :     mpAnchorFrm = _pNewAnchorFrm;
     140             : 
     141        4746 :     if ( mpAnchorFrm )
     142             :     {
     143        2373 :         ObjectAttachedToAnchorFrame();
     144             :     }
     145        4746 : }
     146             : 
     147             : /** determine anchor frame containing the anchor position
     148             : 
     149             :     #i26945#
     150             :     the anchor frame, which is determined, is <mpAnchorFrm>
     151             :     for an at-page, at-frame or at-paragraph anchored object
     152             :     and the anchor character frame for an at-character and as-character
     153             :     anchored object.
     154             : */
     155       56836 : SwFrm* SwAnchoredObject::GetAnchorFrmContainingAnchPos()
     156             : {
     157       56836 :     SwFrm* pAnchorFrmContainingAnchPos = FindAnchorCharFrm();
     158       56836 :     if ( !pAnchorFrmContainingAnchPos )
     159             :     {
     160       40971 :         pAnchorFrmContainingAnchPos = AnchorFrm();
     161             :     }
     162             : 
     163       56836 :     return pAnchorFrmContainingAnchPos;
     164             : }
     165             : 
     166      184595 : SwPageFrm* SwAnchoredObject::GetPageFrm()
     167             : {
     168      184595 :     return mpPageFrm;
     169             : }
     170             : 
     171        5680 : const SwPageFrm* SwAnchoredObject::GetPageFrm() const
     172             : {
     173        5680 :     return mpPageFrm;
     174             : }
     175             : 
     176        2827 : void SwAnchoredObject::SetPageFrm( SwPageFrm* _pNewPageFrm )
     177             : {
     178        2827 :     if ( mpPageFrm != _pNewPageFrm )
     179             :     {
     180             :         // clear member, which denotes the layout frame at which the vertical
     181             :         // position is oriented at, if it doesn't fit to the new page frame.
     182        3981 :         if ( GetVertPosOrientFrm() &&
     183          18 :              ( !_pNewPageFrm ||
     184          18 :                _pNewPageFrm != GetVertPosOrientFrm()->FindPageFrm() ) )
     185             :         {
     186        1167 :             ClearVertPosOrientFrm();
     187             :         }
     188             : 
     189             :         // assign new page frame
     190        2814 :         mpPageFrm = _pNewPageFrm;
     191             :     }
     192        2827 : }
     193             : 
     194        1248 : const SwRect& SwAnchoredObject::GetLastCharRect() const
     195             : {
     196        1248 :     return maLastCharRect;
     197             : }
     198             : 
     199           0 : SwTwips SwAnchoredObject::GetRelCharX( const SwFrm* pFrm ) const
     200             : {
     201           0 :     return maLastCharRect.Left() - pFrm->Frm().Left();
     202             : }
     203             : 
     204           0 : SwTwips SwAnchoredObject::GetRelCharY( const SwFrm* pFrm ) const
     205             : {
     206           0 :     return maLastCharRect.Bottom() - pFrm->Frm().Top();
     207             : }
     208             : 
     209         137 : void SwAnchoredObject::AddLastCharY( long nDiff )
     210             : {
     211         137 :     maLastCharRect.Pos().Y() += nDiff;
     212         137 : }
     213             : 
     214           0 : void SwAnchoredObject::ResetLastCharRectHeight()
     215             : {
     216           0 :     maLastCharRect.Height( 0 );
     217           0 : }
     218             : 
     219        1966 : void SwAnchoredObject::SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm )
     220             : {
     221        1966 :     ClearVertPosOrientFrm();
     222             : 
     223        1966 :     mpVertPosOrientFrm = &_rVertPosOrientFrm;
     224        1966 :     const_cast<SwLayoutFrm*>(mpVertPosOrientFrm)->SetVertPosOrientFrmFor(this);
     225             : 
     226             :     // #i28701# - take over functionality of deleted method
     227             :     // <SwFlyAtCntFrm::AssertPage()>: assure for at-paragraph and at-character
     228             :     // an anchored object, that it is registered at the correct page frame
     229        1966 :     RegisterAtCorrectPage();
     230        1966 : }
     231             : 
     232        1158 : SwTwips SwAnchoredObject::GetLastTopOfLine() const
     233             : {
     234        1158 :     return mnLastTopOfLine;
     235             : }
     236             : 
     237             : // #i28701# - follow-up of #i22341#
     238         137 : void SwAnchoredObject::AddLastTopOfLineY( SwTwips _nDiff )
     239             : {
     240         137 :     mnLastTopOfLine += _nDiff;
     241         137 : }
     242             : 
     243             : /** check anchor character rectangle and top of line
     244             : 
     245             :     #i26791
     246             :     For to-character anchored Writer fly frames the members <maLastCharRect>
     247             :     and <maLastTopOfLine> are updated. These are checked for change and
     248             :     depending on the applied positioning, it's decided, if the Writer fly
     249             :     frame has to be invalidated.
     250             : 
     251             :     add parameter <_bCheckForParaPorInf>, default value <true>
     252             : */
     253        1146 : void SwAnchoredObject::CheckCharRectAndTopOfLine(
     254             :                                         const bool _bCheckForParaPorInf )
     255             : {
     256        2292 :     if ( GetAnchorFrm() &&
     257        1146 :          GetAnchorFrm()->IsTxtFrm() )
     258             :     {
     259        1146 :         const SwFmtAnchor& rAnch = GetFrmFmt().GetAnchor();
     260        2292 :         if ( (rAnch.GetAnchorId() == FLY_AT_CHAR) &&
     261        1146 :              rAnch.GetCntntAnchor() )
     262             :         {
     263             :             // --> if requested, assure that anchor frame,
     264             :             // which contains the anchor character, has a paragraph portion information.
     265             :             // The paragraph portion information is needed to determine the
     266             :             // anchor character rectangle respectively the top of the line.
     267             :             // Thus, a format of this frame is avoided to determine the
     268             :             // paragraph portion information.
     269             :             // --> #i26945# - use new method <FindAnchorCharFrm()>
     270        1146 :             const SwTxtFrm& aAnchorCharFrm = *(FindAnchorCharFrm());
     271        1146 :             if ( !_bCheckForParaPorInf || aAnchorCharFrm.HasPara() )
     272             :             {
     273        1132 :                 _CheckCharRect( rAnch, aAnchorCharFrm );
     274        1132 :                 _CheckTopOfLine( rAnch, aAnchorCharFrm );
     275             :             }
     276             :         }
     277             :     }
     278        1146 : }
     279             : 
     280             : /** check anchor character rectangle
     281             : 
     282             :     #i22341#
     283             :     helper method for method <CheckCharRectAndTopOfLine()>
     284             :     For to-character anchored Writer fly frames the member <maLastCharRect>
     285             :     is updated. This is checked for change and depending on the applied
     286             :     positioning, it's decided, if the Writer fly frame has to be invalidated.
     287             : 
     288             :     improvement - add second parameter <_rAnchorCharFrm>
     289             : */
     290        1132 : void SwAnchoredObject::_CheckCharRect( const SwFmtAnchor& _rAnch,
     291             :                                        const SwTxtFrm& _rAnchorCharFrm )
     292             : {
     293             :     // determine rectangle of anchor character. If not exist, abort operation
     294        1132 :     SwRect aCharRect;
     295        1132 :     if ( !_rAnchorCharFrm.GetAutoPos( aCharRect, *_rAnch.GetCntntAnchor() ) )
     296             :     {
     297        1132 :         return;
     298             :     }
     299             :     // check, if anchor character rectangle has changed
     300        1132 :     if ( aCharRect != maLastCharRect )
     301             :     {
     302             :         // check positioning and alignment for invalidation of position
     303             :         {
     304         599 :             SWRECTFN( (&_rAnchorCharFrm) );
     305             :             // determine positioning and alignment
     306         599 :             SwFmtVertOrient aVert( GetFrmFmt().GetVertOrient() );
     307        1198 :             SwFmtHoriOrient aHori( GetFrmFmt().GetHoriOrient() );
     308             :             // check for anchor character rectangle changes for certain
     309             :             // positionings and alignments
     310             :             // add condition to invalidate position,
     311             :             // if vertical aligned at frame/page area and vertical position
     312             :             // of anchor character has changed.
     313         599 :             const sal_Int16 eVertRelOrient = aVert.GetRelationOrient();
     314        1204 :             if ( ( aHori.GetRelationOrient() == text::RelOrientation::CHAR &&
     315           6 :                    (aCharRect.*fnRect->fnGetLeft)() !=
     316         602 :                         (maLastCharRect.*fnRect->fnGetLeft)() ) ||
     317           0 :                  ( eVertRelOrient == text::RelOrientation::CHAR &&
     318           0 :                    ( (aCharRect.*fnRect->fnGetTop)() !=
     319           0 :                         (maLastCharRect.*fnRect->fnGetTop)() ||
     320           0 :                      (aCharRect.*fnRect->fnGetHeight)() !=
     321        1586 :                         (maLastCharRect.*fnRect->fnGetHeight)() ) ) ||
     322         335 :                  ( ( ( eVertRelOrient == text::RelOrientation::FRAME ) ||
     323         312 :                      ( eVertRelOrient == text::RelOrientation::PRINT_AREA ) ||
     324         248 :                      ( eVertRelOrient == text::RelOrientation::PAGE_FRAME ) ||
     325         593 :                      ( eVertRelOrient == text::RelOrientation::PAGE_PRINT_AREA ) ) &&
     326         593 :                    ( (aCharRect.*fnRect->fnGetTop)() !=
     327         593 :                         (maLastCharRect.*fnRect->fnGetTop)() ) ) )
     328             :             {
     329             :                 // #i26945#, #i35911# - unlock position of
     330             :                 // anchored object, if it isn't registered at the page,
     331             :                 // where its anchor character frame is on.
     332         391 :                 if ( GetPageFrm() != _rAnchorCharFrm.FindPageFrm() )
     333             :                 {
     334           8 :                     UnlockPosition();
     335             :                 }
     336         391 :                 InvalidateObjPos();
     337         599 :             }
     338             :         }
     339             :         // keep new anchor character rectangle
     340         599 :         maLastCharRect = aCharRect;
     341             :     }
     342             : }
     343             : 
     344             : /** check top of line
     345             : 
     346             :     #i22341#
     347             :     helper method for method <CheckCharRectAndTopOfLine()>
     348             :     For to-character anchored Writer fly frames the member <mnLastTopOfLine>
     349             :     is updated. This is checked for change and depending on the applied
     350             :     positioning, it's decided, if the Writer fly frame has to be invalidated.
     351             : 
     352             :     improvement - add second parameter <_rAnchorCharFrm>
     353             : */
     354        1132 : void SwAnchoredObject::_CheckTopOfLine( const SwFmtAnchor& _rAnch,
     355             :                                         const SwTxtFrm& _rAnchorCharFrm )
     356             : {
     357        1132 :     SwTwips nTopOfLine = 0L;
     358        1132 :     if ( _rAnchorCharFrm.GetTopOfLine( nTopOfLine, *_rAnch.GetCntntAnchor() ) )
     359             :     {
     360        1132 :         if ( nTopOfLine != mnLastTopOfLine )
     361             :         {
     362             :             // check alignment for invalidation of position
     363         391 :             if ( GetFrmFmt().GetVertOrient().GetRelationOrient() == text::RelOrientation::TEXT_LINE )
     364             :             {
     365             :                 // #i26945#, #i35911# - unlock position of
     366             :                 // anchored object, if it isn't registered at the page,
     367             :                 // where its anchor character frame is on.
     368           3 :                 if ( GetPageFrm() != _rAnchorCharFrm.FindPageFrm() )
     369             :                 {
     370           0 :                     UnlockPosition();
     371             :                 }
     372           3 :                 InvalidateObjPos();
     373             :             }
     374             :             // keep new top of line value
     375         391 :             mnLastTopOfLine = nTopOfLine;
     376             :         }
     377             :     }
     378        1132 : }
     379             : 
     380          48 : void SwAnchoredObject::ClearCharRectAndTopOfLine()
     381             : {
     382          48 :     maLastCharRect.Clear();
     383          48 :     mnLastTopOfLine = 0;
     384          48 : }
     385             : 
     386        5374 : const Point SwAnchoredObject::GetCurrRelPos() const
     387             : {
     388        5374 :     return maRelPos;
     389             : }
     390        3753 : void SwAnchoredObject::SetCurrRelPos( Point _aRelPos )
     391             : {
     392        3753 :     maRelPos = _aRelPos;
     393        3753 : }
     394             : 
     395        2373 : void SwAnchoredObject::ObjectAttachedToAnchorFrame()
     396             : {
     397             :     // default behaviour:
     398             :     // update layout direction, the anchored object is assigned to
     399        2373 :     UpdateLayoutDir();
     400        2373 : }
     401             : 
     402             : /** method update layout direction the layout direction, the anchored
     403             :     object is in
     404             : 
     405             :     #i31698#
     406             :     method has typically to be called, if the anchored object gets its
     407             :     anchor frame assigned.
     408             : */
     409        2373 : void SwAnchoredObject::UpdateLayoutDir()
     410             : {
     411        2373 :     SwFrmFmt::tLayoutDir nLayoutDir = SwFrmFmt::HORI_L2R;
     412        2373 :     const SwFrm* pAnchorFrm = GetAnchorFrm();
     413        2373 :     if ( pAnchorFrm )
     414             :     {
     415        2373 :         const bool bVert = pAnchorFrm->IsVertical();
     416        2373 :         const bool bR2L = pAnchorFrm->IsRightToLeft();
     417        2373 :         if ( bVert )
     418             :         {
     419           0 :             nLayoutDir = SwFrmFmt::VERT_R2L;
     420             :         }
     421        2373 :         else if ( bR2L )
     422             :         {
     423           0 :             nLayoutDir = SwFrmFmt::HORI_R2L;
     424             :         }
     425             :     }
     426        2373 :     GetFrmFmt().SetLayoutDir( nLayoutDir );
     427        2373 : }
     428             : 
     429             : /** method to perform necessary invalidations for the positioning of
     430             :     objects, for whose the wrapping style influence has to be considered
     431             :     on the object positioning.
     432             : 
     433             :     #i28701#
     434             : */
     435         408 : void SwAnchoredObject::InvalidateObjPosForConsiderWrapInfluence(
     436             :                                                     const bool _bNotifyBackgrd )
     437             : {
     438         408 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     439             :     {
     440             :         // indicate that object has not to be considered for text wrap
     441         364 :         SetConsiderForTextWrap( false );
     442             :         // unlock position
     443         364 :         UnlockPosition();
     444             :         // invalidate position
     445         364 :         InvalidateObjPos();
     446             :         // invalidate 'background', if requested
     447         364 :         if ( _bNotifyBackgrd )
     448             :         {
     449         364 :             NotifyBackground( GetPageFrm(), GetObjRectWithSpaces(), PREP_FLY_LEAVE );
     450             :         }
     451             :     }
     452         408 : }
     453             : 
     454             : /** method to determine, if wrapping style influence of the anchored
     455             :     object has to be considered on the object positioning
     456             : 
     457             :     #i28701#
     458             :     Note: result of this method also decides, if the booleans for the
     459             :     layout process are of relevance.
     460             : */
     461      210966 : bool SwAnchoredObject::ConsiderObjWrapInfluenceOnObjPos() const
     462             : {
     463      210966 :     bool bRet( false );
     464             : 
     465      210966 :     const SwFrmFmt& rObjFmt = GetFrmFmt();
     466             : 
     467             :     // --> #i3317# - add condition <IsTmpConsiderWrapInfluence()>
     468             :     // --> #i55204#
     469             :     // - correction: wrapping style influence has been considered, if condition
     470             :     //   <IsTmpConsiderWrapInfluence()> is hold, regardless of its anchor type
     471             :     //   or its wrapping style.
     472      210966 :     if ( IsTmpConsiderWrapInfluence() )
     473             :     {
     474           0 :         bRet = true;
     475             :     }
     476      210966 :     else if ( rObjFmt.getIDocumentSettingAccess()->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) )
     477             :     {
     478      199820 :         const SwFmtAnchor& rAnchor = rObjFmt.GetAnchor();
     479      581435 :         if ( ((rAnchor.GetAnchorId() == FLY_AT_CHAR) ||
     480      392938 :               (rAnchor.GetAnchorId() == FLY_AT_PARA)) &&
     481      193118 :              rObjFmt.GetSurround().GetSurround() != SURROUND_THROUGHT )
     482             :         {
     483             :             // --> #i34520# - text also wraps around anchored
     484             :             // objects in the layer Hell - see the text formatting.
     485             :             // Thus, it hasn't to be checked here.
     486       21752 :             bRet = true;
     487             :         }
     488             :     }
     489             : 
     490      210966 :     return bRet;
     491             : }
     492             : 
     493             : /** method to determine, if other anchored objects, also attached at
     494             :     to the anchor frame, have to consider its wrap influence.
     495             : 
     496             :     // --> #i43255#
     497             : */
     498        1418 : bool SwAnchoredObject::ConsiderObjWrapInfluenceOfOtherObjs() const
     499             : {
     500        1418 :     bool bRet( false );
     501             : 
     502        1418 :     const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
     503        1418 :     if ( pObjs->Count() > 1 )
     504             :     {
     505         813 :         sal_uInt32 i = 0;
     506       39175 :         for ( ; i < pObjs->Count(); ++i )
     507             :         {
     508       38364 :             SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     509       75917 :             if ( pAnchoredObj != this &&
     510       37553 :                  pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
     511             :             {
     512           2 :                 bRet = true;
     513           2 :                 break;
     514             :             }
     515             :         }
     516             :     }
     517             : 
     518        1418 :     return bRet;
     519             : }
     520             : 
     521      138572 : bool SwAnchoredObject::ConsiderForTextWrap() const
     522             : {
     523      138572 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     524       13456 :         return mbConsiderForTextWrap;
     525             :     else
     526      125116 :         return true;
     527             : }
     528             : 
     529         724 : void SwAnchoredObject::SetConsiderForTextWrap( const bool _bConsiderForTextWrap )
     530             : {
     531         724 :     mbConsiderForTextWrap = _bConsiderForTextWrap;
     532         724 : }
     533             : 
     534        2113 : bool SwAnchoredObject::PositionLocked() const
     535             : {
     536        2113 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     537        1473 :         return mbPositionLocked;
     538             :     else
     539         640 :         return false;
     540             : }
     541             : 
     542        7660 : bool SwAnchoredObject::RestartLayoutProcess() const
     543             : {
     544        7660 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     545        1471 :         return mbRestartLayoutProcess;
     546             :     else
     547        6189 :         return false;
     548             : }
     549             : 
     550        8151 : void SwAnchoredObject::SetRestartLayoutProcess( const bool _bRestartLayoutProcess )
     551             : {
     552        8151 :     mbRestartLayoutProcess = _bRestartLayoutProcess;
     553        8151 : }
     554             : 
     555             : // --> #i35911#
     556        1903 : bool SwAnchoredObject::ClearedEnvironment() const
     557             : {
     558        1903 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     559         748 :         return mbClearedEnvironment;
     560             :     else
     561        1155 :         return false;
     562             : }
     563           4 : void SwAnchoredObject::SetClearedEnvironment( const bool _bClearedEnvironment )
     564             : {
     565           4 :     mbClearedEnvironment = _bClearedEnvironment;
     566           4 : }
     567             : 
     568             : /** method to determine, if due to anchored object size and wrapping
     569             :     style, its layout environment is cleared.
     570             : 
     571             :     #i35911#
     572             : */
     573          11 : bool SwAnchoredObject::HasClearedEnvironment() const
     574             : {
     575          11 :     bool bHasClearedEnvironment( false );
     576             : 
     577             :     // --> #i43913# - layout frame, vertical position is orient at, has to be set.
     578             :     OSL_ENSURE( GetVertPosOrientFrm(),
     579             :             "<SwAnchoredObject::HasClearedEnvironment()> - layout frame missing, at which the vertical position is oriented at." );
     580          33 :     if ( GetVertPosOrientFrm() &&
     581          22 :          GetAnchorFrm()->IsTxtFrm() &&
     582          33 :          !static_cast<const SwTxtFrm*>(GetAnchorFrm())->IsFollow() &&
     583          11 :          static_cast<const SwTxtFrm*>(GetAnchorFrm())->FindPageFrm()->GetPhyPageNum() >=
     584          11 :                 GetPageFrm()->GetPhyPageNum() )
     585             :     {
     586          11 :         const SwFrm* pTmpFrm = GetVertPosOrientFrm()->Lower();
     587          22 :         while ( pTmpFrm && pTmpFrm->IsLayoutFrm() && !pTmpFrm->IsTabFrm() )
     588             :         {
     589           0 :             pTmpFrm = static_cast<const SwLayoutFrm*>(pTmpFrm)->Lower();
     590             :         }
     591          11 :         if ( !pTmpFrm )
     592             :         {
     593           0 :             bHasClearedEnvironment = true;
     594             :         }
     595          11 :         else if ( pTmpFrm->IsTxtFrm() && !pTmpFrm->GetNext() )
     596             :         {
     597           8 :             const SwTxtFrm* pTmpTxtFrm = static_cast<const SwTxtFrm*>(pTmpFrm);
     598          22 :             if ( pTmpTxtFrm->IsUndersized() ||
     599          14 :                  ( pTmpTxtFrm->GetFollow() &&
     600           6 :                    pTmpTxtFrm->GetFollow()->GetOfst() == 0 ) )
     601             :             {
     602           6 :                 bHasClearedEnvironment = true;
     603             :             }
     604             :         }
     605             :     }
     606             : 
     607          11 :     return bHasClearedEnvironment;
     608             : }
     609             : 
     610             : /** method to add spacing to object area
     611             : 
     612             :     #i28701#
     613             :     #i68520# - return constant reference and use cache
     614             : */
     615      409588 : const SwRect& SwAnchoredObject::GetObjRectWithSpaces() const
     616             : {
     617     1631634 :     if ( mbObjRectWithSpacesValid &&
     618     1618198 :          maLastObjRect != GetObjRect() )
     619             :     {
     620             :         OSL_FAIL( "<SwAnchoredObject::GetObjRectWithSpaces> - cache for object rectangle inclusive spaces marked as valid, but it couldn't be. Missing invalidation of cache. Please inform OD." );
     621           0 :         InvalidateObjRectWithSpaces();
     622             :     }
     623      409588 :     if ( !mbObjRectWithSpacesValid )
     624             :     {
     625        6718 :         maObjRectWithSpaces = GetObjBoundRect();
     626        6718 :         const SwFrmFmt& rFmt = GetFrmFmt();
     627        6718 :         const SvxULSpaceItem& rUL = rFmt.GetULSpace();
     628        6718 :         const SvxLRSpaceItem& rLR = rFmt.GetLRSpace();
     629             :         {
     630        6718 :             maObjRectWithSpaces.Top ( std::max( maObjRectWithSpaces.Top() - long(rUL.GetUpper()), 0L ));
     631        6718 :             maObjRectWithSpaces.Left( std::max( maObjRectWithSpaces.Left()- long(rLR.GetLeft()),  0L ));
     632        6718 :             maObjRectWithSpaces.SSize().Height() += rUL.GetLower();
     633        6718 :             maObjRectWithSpaces.SSize().Width()  += rLR.GetRight();
     634             :         }
     635             : 
     636        6718 :         mbObjRectWithSpacesValid = true;
     637        6718 :         maLastObjRect = GetObjRect();
     638             :     }
     639             : 
     640      409588 :     return maObjRectWithSpaces;
     641             : }
     642             : 
     643             : // --> #i68520#
     644        5860 : void SwAnchoredObject::SetObjTop( const SwTwips _nTop)
     645             : {
     646        5860 :     const bool bTopChanged( _SetObjTop( _nTop ) );
     647        5860 :     if ( bTopChanged )
     648             :     {
     649        1305 :         mbObjRectWithSpacesValid = false;
     650             :     }
     651        5860 : }
     652             : 
     653        2006 : void SwAnchoredObject::SetObjLeft( const SwTwips _nLeft)
     654             : {
     655        2006 :     const bool bLeftChanged( _SetObjLeft( _nLeft ) );
     656        2006 :     if ( bLeftChanged )
     657             :     {
     658        1146 :         mbObjRectWithSpacesValid = false;
     659             :     }
     660        2006 : }
     661             : 
     662             : /** method to update anchored object in the <SwSortedObjs> lists
     663             : 
     664             :     #i28701#
     665             :     If document compatibility option 'Consider wrapping style influence
     666             :     on object positioning' is ON, additionally all anchored objects
     667             :     at the anchor frame and all following anchored objects on the page
     668             :     frame are invalidated.
     669             : */
     670          81 : void SwAnchoredObject::UpdateObjInSortedList()
     671             : {
     672          81 :     if ( GetAnchorFrm() )
     673             :     {
     674          81 :         if ( GetFrmFmt().getIDocumentSettingAccess()->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) )
     675             :         {
     676             :             // invalidate position of all anchored objects at anchor frame
     677           0 :             if ( GetAnchorFrm()->GetDrawObjs() )
     678             :             {
     679           0 :                 const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
     680             :                 // determine start index
     681           0 :                 sal_uInt32 i = 0;
     682           0 :                 for ( ; i < pObjs->Count(); ++i )
     683             :                 {
     684           0 :                     SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     685           0 :                     if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
     686           0 :                         pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence( true );
     687             :                     else
     688           0 :                         pAnchoredObj->InvalidateObjPos();
     689             :                 }
     690             :             }
     691             :             // invalidate all following anchored objects on the page frame
     692           0 :             if ( GetPageFrm() && GetPageFrm()->GetSortedObjs() )
     693             :             {
     694           0 :                 const SwSortedObjs* pObjs = GetPageFrm()->GetSortedObjs();
     695             :                 // determine start index
     696           0 :                 sal_uInt32 i = pObjs->ListPosOf( *this ) + 1;
     697           0 :                 for ( ; i < pObjs->Count(); ++i )
     698             :                 {
     699           0 :                     SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     700           0 :                     if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
     701           0 :                         pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence( true );
     702             :                     else
     703           0 :                         pAnchoredObj->InvalidateObjPos();
     704             :                 }
     705             :             }
     706             :         }
     707             :         // update its position in the sorted object list of its anchor frame
     708          81 :         AnchorFrm()->GetDrawObjs()->Update( *this );
     709             :         // update its position in the sorted object list of its page frame
     710             :         // note: as-character anchored object aren't registered at a page frame
     711          81 :         if ( GetFrmFmt().GetAnchor().GetAnchorId() != FLY_AS_CHAR )
     712             :         {
     713          62 :             GetPageFrm()->GetSortedObjs()->Update( *this );
     714             :         }
     715             :     }
     716          81 : }
     717             : 
     718             : /** method to determine, if invalidation of position is allowed
     719             : 
     720             :     #i28701#
     721             : */
     722        1741 : bool SwAnchoredObject::InvalidationOfPosAllowed() const
     723             : {
     724             :     // --> Check, if page frame layout is in progress,
     725             :     // isn't needed, because of anchored object, whose are moved forward.
     726        1741 :     return !PositionLocked();
     727             : }
     728             : 
     729             : /** method to determine the page frame, on which the 'anchor' of
     730             :     the given anchored object is.
     731             : 
     732             :     #i28701#
     733             :     #i33751#, #i34060#
     734             :     Adjust meaning of method and thus its name: If the anchored object
     735             :     or its anchor isn't correctly inserted in the layout, no page frame
     736             :     can be found. Thus, the return type changed to be a pointer and can
     737             :     be NULL.
     738             : */
     739       21775 : SwPageFrm* SwAnchoredObject::FindPageFrmOfAnchor()
     740             : {
     741       21775 :     SwPageFrm* pRetPageFrm = 0L;
     742             : 
     743             :     // --> #i44339# - check, if anchor frame exists.
     744       21775 :     if ( mpAnchorFrm )
     745             :     {
     746             :         // --> #i26945# - use new method <GetAnchorFrmContainingAnchPos()>
     747       21775 :         pRetPageFrm = GetAnchorFrmContainingAnchPos()->FindPageFrm();
     748             :     }
     749             : 
     750       21775 :     return pRetPageFrm;
     751             : }
     752             : 
     753             : /** get frame, which contains the anchor character, if the object
     754             :     is anchored at-character or as-character.
     755             : 
     756             :     #i26945#
     757             : 
     758             :     @return SwTxtFrm*
     759             :     text frame containing the anchor character. It's NULL, if the object
     760             :     isn't anchored at-character resp. as-character.
     761             : */
     762       73010 : SwTxtFrm* SwAnchoredObject::FindAnchorCharFrm()
     763             : {
     764       73010 :     SwTxtFrm* pAnchorCharFrm( 0L );
     765             : 
     766             :     // --> #i44339# - check, if anchor frame exists.
     767       73010 :     if ( mpAnchorFrm )
     768             :     {
     769       73010 :         const SwFmtAnchor& rAnch = GetFrmFmt().GetAnchor();
     770      132862 :         if ((rAnch.GetAnchorId() == FLY_AT_CHAR) ||
     771       59852 :             (rAnch.GetAnchorId() == FLY_AS_CHAR))
     772             :         {
     773       23638 :             pAnchorCharFrm = &(static_cast<SwTxtFrm*>(AnchorFrm())->
     774       47276 :                         GetFrmAtOfst( rAnch.GetCntntAnchor()->nContent.GetIndex() ));
     775             :         }
     776             :     }
     777             : 
     778       73010 :     return pAnchorCharFrm;
     779             : }
     780             : 
     781             : /** method to determine, if a format on the anchored object is possible
     782             : 
     783             :     #i28701#
     784             :     A format is possible, if anchored object is in an invisible layer.
     785             :     Note: method is virtual to refine the conditions for the sub-classes.
     786             : */
     787        9221 : bool SwAnchoredObject::IsFormatPossible() const
     788             : {
     789        9221 :     return GetFrmFmt().GetDoc()->IsVisibleLayerId( GetDrawObj()->GetLayer() );
     790             : }
     791             : 
     792             : // --> #i3317#
     793          48 : void SwAnchoredObject::SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence )
     794             : {
     795          48 :     mbTmpConsiderWrapInfluence = _bTmpConsiderWrapInfluence;
     796             :     // --> #i35911#
     797          48 :     if ( mbTmpConsiderWrapInfluence )
     798             :     {
     799           0 :         SwLayouter::InsertObjForTmpConsiderWrapInfluence( *(GetFrmFmt().GetDoc()),
     800           0 :                                                           *this );
     801             :     }
     802          48 : }
     803             : 
     804      210966 : bool SwAnchoredObject::IsTmpConsiderWrapInfluence() const
     805             : {
     806      210966 :     return mbTmpConsiderWrapInfluence;
     807             : }
     808             : 
     809           0 : void SwAnchoredObject::SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence )
     810             : {
     811           0 :     const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
     812           0 :     if ( pObjs->Count() > 1 )
     813             :     {
     814           0 :         sal_uInt32 i = 0;
     815           0 :         for ( ; i < pObjs->Count(); ++i )
     816             :         {
     817           0 :             SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     818           0 :             if ( pAnchoredObj != this )
     819             :             {
     820           0 :                 pAnchoredObj->SetTmpConsiderWrapInfluence( bTmpConsiderWrapInfluence );
     821             :             }
     822             :         }
     823             :     }
     824           0 : }
     825             : 
     826             : /** method to determine, if the anchored object is overlapping with a
     827             :     previous column
     828             : 
     829             :     #i3317#
     830             :     overlapping with a previous column means, that the object overlaps
     831             :     with a column, which is a previous one of the column its anchor
     832             :     frame is in.
     833             :     Only applied for at-paragraph and at-character anchored objects.
     834             : */
     835        1427 : bool SwAnchoredObject::OverlapsPrevColumn() const
     836             : {
     837        1427 :     bool bOverlapsPrevColumn( false );
     838             : 
     839        1427 :     if ( mpAnchorFrm && mpAnchorFrm->IsTxtFrm() )
     840             :     {
     841        1427 :         const SwFrm* pColFrm = mpAnchorFrm->FindColFrm();
     842        1427 :         if ( pColFrm && pColFrm->GetPrev() )
     843             :         {
     844           0 :             const SwFrm* pTmpColFrm = pColFrm->GetPrev();
     845           0 :             SwRect aChkRect;
     846           0 :             while ( pTmpColFrm )
     847             :             {
     848           0 :                 aChkRect.Union( pTmpColFrm->Frm() );
     849           0 :                 pTmpColFrm = pTmpColFrm->GetPrev();
     850             :             }
     851           0 :             bOverlapsPrevColumn = GetObjRect().IsOver( aChkRect );
     852             :         }
     853             :     }
     854             : 
     855        1427 :     return bOverlapsPrevColumn;
     856             : }
     857             : 
     858             : /** method to determine position of anchored object relative to
     859             :     anchor frame
     860             : 
     861             :     #i30669#
     862             :     Usage: Needed layout information for WW8 export
     863             : */
     864           0 : Point SwAnchoredObject::GetRelPosToAnchorFrm() const
     865             : {
     866           0 :     Point aRelPos;
     867             : 
     868             :     OSL_ENSURE( GetAnchorFrm(),
     869             :             "<SwAnchoredObject::GetRelPosToAnchorFrm()> - missing anchor frame." );
     870           0 :     aRelPos = GetObjRect().Pos();
     871           0 :     aRelPos -= GetAnchorFrm()->Frm().Pos();
     872             : 
     873           0 :     return aRelPos;
     874             : }
     875             : 
     876             : /** method to determine position of anchored object relative to
     877             :     page frame
     878             : 
     879             :     #i30669#
     880             :     Usage: Needed layout information for WW8 export
     881             :     #i33818# - add parameters <_bFollowTextFlow> and
     882             :     <_obRelToTableCell>
     883             :     If <_bFollowTextFlow> is set and object is anchored inside table,
     884             :     the position relative to the table cell is determined. Output
     885             :     parameter <_obRelToTableCell> reflects this situation
     886             : */
     887           0 : Point SwAnchoredObject::GetRelPosToPageFrm( const bool _bFollowTextFlow,
     888             :                                             bool& _obRelToTableCell ) const
     889             : {
     890           0 :     Point aRelPos;
     891           0 :     _obRelToTableCell = false;
     892             : 
     893             :     OSL_ENSURE( GetAnchorFrm(),
     894             :             "<SwAnchoredObject::GetRelPosToPageFrm()> - missing anchor frame." );
     895             :     OSL_ENSURE( GetAnchorFrm()->FindPageFrm(),
     896             :             "<SwAnchoredObject::GetRelPosToPageFrm()> - missing page frame." );
     897             : 
     898           0 :     aRelPos = GetObjRect().Pos();
     899             :     // --> #i33818# - search for cell frame, if object has to
     900             :     // follow the text flow.
     901           0 :     const SwFrm* pFrm( 0L );
     902           0 :     if ( _bFollowTextFlow && !GetAnchorFrm()->IsPageFrm() )
     903             :     {
     904           0 :         pFrm = GetAnchorFrm()->GetUpper();
     905           0 :         while ( !pFrm->IsCellFrm() && !pFrm->IsPageFrm() )
     906             :         {
     907           0 :             pFrm = pFrm->GetUpper();
     908             :         }
     909             :     }
     910             :     else
     911             :     {
     912           0 :         pFrm = GetAnchorFrm()->FindPageFrm();
     913             :     }
     914           0 :     if ( pFrm->IsCellFrm() )
     915             :     {
     916           0 :         aRelPos -= ( pFrm->Frm().Pos() + pFrm->Prt().Pos() );
     917           0 :         _obRelToTableCell = true;
     918             :     }
     919             :     else
     920             :     {
     921           0 :         aRelPos -= pFrm->Frm().Pos();
     922             :     }
     923             : 
     924           0 :     return aRelPos;
     925             : }
     926             : 
     927             : /** method to determine position of anchored object relative to
     928             :     anchor character
     929             : 
     930             :     #i30669#
     931             :     Usage: Needed layout information for WW8 export
     932             : */
     933           0 : Point SwAnchoredObject::GetRelPosToChar() const
     934             : {
     935           0 :     Point aRelPos;
     936             : 
     937           0 :     aRelPos = GetObjRect().Pos();
     938           0 :     aRelPos -= GetLastCharRect().Pos();
     939             : 
     940           0 :     return aRelPos;
     941             : }
     942             : 
     943             : /** method to determine position of anchored object relative to
     944             :     top of line
     945             : 
     946             :     #i30669#
     947             :     Usage: Needed layout information for WW8 export
     948             : */
     949           0 : Point SwAnchoredObject::GetRelPosToLine() const
     950             : {
     951           0 :     Point aRelPos;
     952             : 
     953           0 :     aRelPos = GetObjRect().Pos();
     954           0 :     aRelPos.Y() -= GetLastTopOfLine();
     955             : 
     956           0 :     return aRelPos;
     957             : }
     958             : 
     959             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10