LCOV - code coverage report
Current view: top level - sw/source/core/layout - anchoredobject.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 271 335 80.9 %
Date: 2014-11-03 Functions: 45 57 78.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10