LCOV - code coverage report
Current view: top level - sw/source/core/layout - anchoredobject.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 287 335 85.7 %
Date: 2015-06-13 12:38:46 Functions: 47 57 82.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             : #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        7116 : SwObjPositioningInProgress::SwObjPositioningInProgress( SdrObject& _rSdrObj ) :
      39             :     mpAnchoredObj( 0L ),
      40             :     // --> #i52904#
      41        7116 :     mbOldObjPositioningInProgress( false )
      42             : {
      43        7116 :     mpAnchoredObj = ::GetUserCall( &_rSdrObj )->GetAnchoredObj( &_rSdrObj );
      44             :     // --> #i52904#
      45        7116 :     mbOldObjPositioningInProgress = mpAnchoredObj->IsPositioningInProgress();
      46        7116 :     mpAnchoredObj->SetPositioningInProgress( true );
      47        7116 : }
      48        3710 : SwObjPositioningInProgress::SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj ) :
      49             :     mpAnchoredObj( &_rAnchoredObj ),
      50             :     // --> #i52904#
      51        3710 :     mbOldObjPositioningInProgress( false )
      52             : {
      53             :     // --> #i52904#
      54        3710 :     mbOldObjPositioningInProgress = mpAnchoredObj->IsPositioningInProgress();
      55        3710 :     mpAnchoredObj->SetPositioningInProgress( true );
      56        3710 : }
      57             : 
      58       10826 : SwObjPositioningInProgress::~SwObjPositioningInProgress()
      59             : {
      60       10826 :     if ( mpAnchoredObj )
      61             :     {
      62             :         // --> #i52904#
      63       10826 :         mpAnchoredObj->SetPositioningInProgress( mbOldObjPositioningInProgress );
      64             :     }
      65       10826 : }
      66             : 
      67      803302 : TYPEINIT0(SwAnchoredObject);
      68             : 
      69        4771 : 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        4771 :     maLastObjRect()
      93             : {
      94        4771 : }
      95             : 
      96       12081 : void SwAnchoredObject::ClearVertPosOrientFrm()
      97             : {
      98       12081 :     if (mpVertPosOrientFrm)
      99             :     {
     100        4587 :         const_cast<SwLayoutFrm*>(mpVertPosOrientFrm)->ClearVertPosOrientFrmFor(this);
     101        4587 :         mpVertPosOrientFrm = NULL;
     102             :     }
     103       12081 : }
     104             : 
     105        4770 : SwAnchoredObject::~SwAnchoredObject()
     106             : {
     107        4770 :     ClearVertPosOrientFrm();
     108        4770 : }
     109             : 
     110        4771 : void SwAnchoredObject::SetDrawObj( SdrObject& _rDrawObj )
     111             : {
     112        4771 :     mpDrawObj = &_rDrawObj;
     113        4771 : }
     114             : 
     115             : 
     116             : 
     117             : 
     118             : 
     119        8788 : void SwAnchoredObject::ChgAnchorFrm( SwFrm* _pNewAnchorFrm )
     120             : {
     121        8788 :     mpAnchorFrm = _pNewAnchorFrm;
     122             : 
     123        8788 :     if ( mpAnchorFrm )
     124             :     {
     125        4394 :         ObjectAttachedToAnchorFrame();
     126             :     }
     127        8788 : }
     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      131804 : SwFrm* SwAnchoredObject::GetAnchorFrmContainingAnchPos()
     138             : {
     139      131804 :     SwFrm* pAnchorFrmContainingAnchPos = FindAnchorCharFrm();
     140      131804 :     if ( !pAnchorFrmContainingAnchPos )
     141             :     {
     142       91986 :         pAnchorFrmContainingAnchPos = AnchorFrm();
     143             :     }
     144             : 
     145      131804 :     return pAnchorFrmContainingAnchPos;
     146             : }
     147             : 
     148             : 
     149             : 
     150        6190 : void SwAnchoredObject::SetPageFrm( SwPageFrm* _pNewPageFrm )
     151             : {
     152        6190 :     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        8904 :         if ( GetVertPosOrientFrm() &&
     157          16 :              ( !_pNewPageFrm ||
     158          16 :                _pNewPageFrm != GetVertPosOrientFrm()->FindPageFrm() ) )
     159             :         {
     160        2714 :             ClearVertPosOrientFrm();
     161             :         }
     162             : 
     163             :         // assign new page frame
     164        6190 :         mpPageFrm = _pNewPageFrm;
     165             :     }
     166        6190 : }
     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         240 : void SwAnchoredObject::AddLastCharY( long nDiff )
     180             : {
     181         240 :     maLastCharRect.Pos().Y() += nDiff;
     182         240 : }
     183             : 
     184           0 : void SwAnchoredObject::ResetLastCharRectHeight()
     185             : {
     186           0 :     maLastCharRect.Height( 0 );
     187           0 : }
     188             : 
     189        4587 : void SwAnchoredObject::SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm )
     190             : {
     191        4587 :     ClearVertPosOrientFrm();
     192             : 
     193        4587 :     mpVertPosOrientFrm = &_rVertPosOrientFrm;
     194        4587 :     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        4587 :     RegisterAtCorrectPage();
     200        4587 : }
     201             : 
     202             : 
     203             : // #i28701# - follow-up of #i22341#
     204         240 : void SwAnchoredObject::AddLastTopOfLineY( SwTwips _nDiff )
     205             : {
     206         240 :     mnLastTopOfLine += _nDiff;
     207         240 : }
     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        1925 : void SwAnchoredObject::CheckCharRectAndTopOfLine(
     220             :                                         const bool _bCheckForParaPorInf )
     221             : {
     222        3850 :     if ( GetAnchorFrm() &&
     223        1925 :          GetAnchorFrm()->IsTextFrm() )
     224             :     {
     225        1925 :         const SwFormatAnchor& rAnch = GetFrameFormat().GetAnchor();
     226        3850 :         if ( (rAnch.GetAnchorId() == FLY_AT_CHAR) &&
     227        1925 :              rAnch.GetContentAnchor() )
     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        1925 :             const SwTextFrm& aAnchorCharFrm = *(FindAnchorCharFrm());
     237        1925 :             if ( !_bCheckForParaPorInf || aAnchorCharFrm.HasPara() )
     238             :             {
     239        1925 :                 _CheckCharRect( rAnch, aAnchorCharFrm );
     240        1925 :                 _CheckTopOfLine( rAnch, aAnchorCharFrm );
     241             :             }
     242             :         }
     243             :     }
     244        1925 : }
     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        1925 : void SwAnchoredObject::_CheckCharRect( const SwFormatAnchor& _rAnch,
     257             :                                        const SwTextFrm& _rAnchorCharFrm )
     258             : {
     259             :     // determine rectangle of anchor character. If not exist, abort operation
     260        1925 :     SwRect aCharRect;
     261        1925 :     if ( !_rAnchorCharFrm.GetAutoPos( aCharRect, *_rAnch.GetContentAnchor() ) )
     262             :     {
     263        1925 :         return;
     264             :     }
     265             :     // check, if anchor character rectangle has changed
     266        1925 :     if ( aCharRect != maLastCharRect )
     267             :     {
     268             :         // check positioning and alignment for invalidation of position
     269             :         {
     270         977 :             SWRECTFN( (&_rAnchorCharFrm) );
     271             :             // determine positioning and alignment
     272         977 :             SwFormatVertOrient aVert( GetFrameFormat().GetVertOrient() );
     273        1954 :             SwFormatHoriOrient aHori( GetFrameFormat().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         977 :             const sal_Int16 eVertRelOrient = aVert.GetRelationOrient();
     280        1960 :             if ( ( aHori.GetRelationOrient() == text::RelOrientation::CHAR &&
     281           6 :                    (aCharRect.*fnRect->fnGetLeft)() !=
     282         980 :                         (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        2620 :                         (maLastCharRect.*fnRect->fnGetHeight)() ) ) ||
     288         489 :                  ( ( ( eVertRelOrient == text::RelOrientation::FRAME ) ||
     289         457 :                      ( eVertRelOrient == text::RelOrientation::PRINT_AREA ) ||
     290         269 :                      ( eVertRelOrient == text::RelOrientation::PAGE_FRAME ) ||
     291         970 :                      ( eVertRelOrient == text::RelOrientation::PAGE_PRINT_AREA ) ) &&
     292         970 :                    ( (aCharRect.*fnRect->fnGetTop)() !=
     293         970 :                         (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         669 :                 if ( GetPageFrm() != _rAnchorCharFrm.FindPageFrm() )
     299             :                 {
     300          14 :                     UnlockPosition();
     301             :                 }
     302         669 :                 InvalidateObjPos();
     303         977 :             }
     304             :         }
     305             :         // keep new anchor character rectangle
     306         977 :         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        1925 : void SwAnchoredObject::_CheckTopOfLine( const SwFormatAnchor& _rAnch,
     321             :                                         const SwTextFrm& _rAnchorCharFrm )
     322             : {
     323        1925 :     SwTwips nTopOfLine = 0L;
     324        1925 :     if ( _rAnchorCharFrm.GetTopOfLine( nTopOfLine, *_rAnch.GetContentAnchor() ) )
     325             :     {
     326        1925 :         if ( nTopOfLine != mnLastTopOfLine )
     327             :         {
     328             :             // check alignment for invalidation of position
     329         669 :             if ( GetFrameFormat().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           4 :                 if ( GetPageFrm() != _rAnchorCharFrm.FindPageFrm() )
     335             :                 {
     336           1 :                     UnlockPosition();
     337             :                 }
     338           4 :                 InvalidateObjPos();
     339             :             }
     340             :             // keep new top of line value
     341         669 :             mnLastTopOfLine = nTopOfLine;
     342             :         }
     343             :     }
     344        1925 : }
     345             : 
     346          49 : void SwAnchoredObject::ClearCharRectAndTopOfLine()
     347             : {
     348          49 :     maLastCharRect.Clear();
     349          49 :     mnLastTopOfLine = 0;
     350          49 : }
     351             : 
     352        6962 : void SwAnchoredObject::SetCurrRelPos( Point _aRelPos )
     353             : {
     354        6962 :     maRelPos = _aRelPos;
     355        6962 : }
     356             : 
     357        4394 : void SwAnchoredObject::ObjectAttachedToAnchorFrame()
     358             : {
     359             :     // default behaviour:
     360             :     // update layout direction, the anchored object is assigned to
     361        4394 :     UpdateLayoutDir();
     362        4394 : }
     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        4394 : void SwAnchoredObject::UpdateLayoutDir()
     372             : {
     373        4394 :     SwFrameFormat::tLayoutDir nLayoutDir = SwFrameFormat::HORI_L2R;
     374        4394 :     const SwFrm* pAnchorFrm = GetAnchorFrm();
     375        4394 :     if ( pAnchorFrm )
     376             :     {
     377        4394 :         const bool bVert = pAnchorFrm->IsVertical();
     378        4394 :         const bool bR2L = pAnchorFrm->IsRightToLeft();
     379        4394 :         if ( bVert )
     380             :         {
     381           0 :             nLayoutDir = SwFrameFormat::VERT_R2L;
     382             :         }
     383        4394 :         else if ( bR2L )
     384             :         {
     385           3 :             nLayoutDir = SwFrameFormat::HORI_R2L;
     386             :         }
     387             :     }
     388        4394 :     GetFrameFormat().SetLayoutDir( nLayoutDir );
     389        4394 : }
     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         985 : void SwAnchoredObject::InvalidateObjPosForConsiderWrapInfluence(
     398             :                                                     const bool _bNotifyBackgrd )
     399             : {
     400         985 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     401             :     {
     402             :         // indicate that object has not to be considered for text wrap
     403         702 :         SetConsiderForTextWrap( false );
     404             :         // unlock position
     405         702 :         UnlockPosition();
     406             :         // invalidate position
     407         702 :         InvalidateObjPos();
     408             :         // invalidate 'background', if requested
     409         702 :         if ( _bNotifyBackgrd )
     410             :         {
     411         702 :             NotifyBackground( GetPageFrm(), GetObjRectWithSpaces(), PREP_FLY_LEAVE );
     412             :         }
     413             :     }
     414         985 : }
     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      539260 : bool SwAnchoredObject::ConsiderObjWrapInfluenceOnObjPos() const
     424             : {
     425      539260 :     bool bRet( false );
     426             : 
     427      539260 :     const SwFrameFormat& rObjFormat = GetFrameFormat();
     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      539260 :     if ( IsTmpConsiderWrapInfluence() )
     435             :     {
     436          72 :         bRet = true;
     437             :     }
     438      539188 :     else if ( rObjFormat.getIDocumentSettingAccess()->get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION) )
     439             :     {
     440      518549 :         const SwFormatAnchor& rAnchor = rObjFormat.GetAnchor();
     441     1507455 :         if ( ((rAnchor.GetAnchorId() == FLY_AT_CHAR) ||
     442     1025242 :               (rAnchor.GetAnchorId() == FLY_AT_PARA)) &&
     443      506693 :              rObjFormat.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       31028 :             bRet = true;
     449             :         }
     450             :     }
     451             : 
     452      539260 :     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        3905 : bool SwAnchoredObject::ConsiderObjWrapInfluenceOfOtherObjs() const
     461             : {
     462        3905 :     bool bRet( false );
     463             : 
     464        3905 :     const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
     465        3905 :     if ( pObjs->size() > 1 )
     466             :     {
     467      107161 :         for ( size_t i = 0; i < pObjs->size(); ++i )
     468             :         {
     469      104386 :             SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     470      205826 :             if ( pAnchoredObj != this &&
     471      101440 :                  pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
     472             :             {
     473         364 :                 bRet = true;
     474         364 :                 break;
     475             :             }
     476             :         }
     477             :     }
     478             : 
     479        3905 :     return bRet;
     480             : }
     481             : 
     482      371492 : bool SwAnchoredObject::ConsiderForTextWrap() const
     483             : {
     484      371492 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     485       18952 :         return mbConsiderForTextWrap;
     486             :     else
     487      352540 :         return true;
     488             : }
     489             : 
     490        1320 : void SwAnchoredObject::SetConsiderForTextWrap( const bool _bConsiderForTextWrap )
     491             : {
     492        1320 :     mbConsiderForTextWrap = _bConsiderForTextWrap;
     493        1320 : }
     494             : 
     495        3849 : bool SwAnchoredObject::PositionLocked() const
     496             : {
     497        3849 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     498        1997 :         return mbPositionLocked;
     499             :     else
     500        1852 :         return false;
     501             : }
     502             : 
     503       14223 : bool SwAnchoredObject::RestartLayoutProcess() const
     504             : {
     505       14223 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     506        2172 :         return mbRestartLayoutProcess;
     507             :     else
     508       12051 :         return false;
     509             : }
     510             : 
     511       15663 : void SwAnchoredObject::SetRestartLayoutProcess( const bool _bRestartLayoutProcess )
     512             : {
     513       15663 :     mbRestartLayoutProcess = _bRestartLayoutProcess;
     514       15663 : }
     515             : 
     516             : // --> #i35911#
     517        4138 : bool SwAnchoredObject::ClearedEnvironment() const
     518             : {
     519        4138 :     if ( ConsiderObjWrapInfluenceOnObjPos() )
     520         963 :         return mbClearedEnvironment;
     521             :     else
     522        3175 :         return false;
     523             : }
     524           7 : void SwAnchoredObject::SetClearedEnvironment( const bool _bClearedEnvironment )
     525             : {
     526           7 :     mbClearedEnvironment = _bClearedEnvironment;
     527           7 : }
     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          20 : bool SwAnchoredObject::HasClearedEnvironment() const
     535             : {
     536          20 :     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          60 :     if ( GetVertPosOrientFrm() &&
     542          40 :          GetAnchorFrm()->IsTextFrm() &&
     543          60 :          !static_cast<const SwTextFrm*>(GetAnchorFrm())->IsFollow() &&
     544          20 :          static_cast<const SwTextFrm*>(GetAnchorFrm())->FindPageFrm()->GetPhyPageNum() >=
     545          20 :                 GetPageFrm()->GetPhyPageNum() )
     546             :     {
     547          20 :         const SwFrm* pTmpFrm = GetVertPosOrientFrm()->Lower();
     548          41 :         while ( pTmpFrm && pTmpFrm->IsLayoutFrm() && !pTmpFrm->IsTabFrm() )
     549             :         {
     550           1 :             pTmpFrm = static_cast<const SwLayoutFrm*>(pTmpFrm)->Lower();
     551             :         }
     552          20 :         if ( !pTmpFrm )
     553             :         {
     554           0 :             bHasClearedEnvironment = true;
     555             :         }
     556          20 :         else if ( pTmpFrm->IsTextFrm() && !pTmpFrm->GetNext() )
     557             :         {
     558           8 :             const SwTextFrm* pTmpTextFrm = static_cast<const SwTextFrm*>(pTmpFrm);
     559          22 :             if ( pTmpTextFrm->IsUndersized() ||
     560          14 :                  ( pTmpTextFrm->GetFollow() &&
     561           6 :                    pTmpTextFrm->GetFollow()->GetOfst() == 0 ) )
     562             :             {
     563           6 :                 bHasClearedEnvironment = true;
     564             :             }
     565             :         }
     566             :     }
     567             : 
     568          20 :     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     1689585 : const SwRect& SwAnchoredObject::GetObjRectWithSpaces() const
     577             : {
     578     6745722 :     if ( mbObjRectWithSpacesValid &&
     579     6720486 :          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         131 :         InvalidateObjRectWithSpaces();
     583             :     }
     584     1689585 :     if ( !mbObjRectWithSpacesValid )
     585             :     {
     586       12749 :         maObjRectWithSpaces = GetObjBoundRect();
     587       12749 :         const SwFrameFormat& rFormat = GetFrameFormat();
     588       12749 :         const SvxULSpaceItem& rUL = rFormat.GetULSpace();
     589       12749 :         const SvxLRSpaceItem& rLR = rFormat.GetLRSpace();
     590             :         {
     591       12749 :             maObjRectWithSpaces.Top ( std::max( maObjRectWithSpaces.Top() - long(rUL.GetUpper()), 0L ));
     592       12749 :             maObjRectWithSpaces.Left( std::max( maObjRectWithSpaces.Left()- long(rLR.GetLeft()),  0L ));
     593       12749 :             maObjRectWithSpaces.SSize().Height() += rUL.GetLower();
     594       12749 :             maObjRectWithSpaces.SSize().Width()  += rLR.GetRight();
     595             :         }
     596             : 
     597       12749 :         mbObjRectWithSpacesValid = true;
     598       12749 :         maLastObjRect = GetObjRect();
     599             :     }
     600             : 
     601     1689585 :     return maObjRectWithSpaces;
     602             : }
     603             : 
     604             : // --> #i68520#
     605       13820 : void SwAnchoredObject::SetObjTop( const SwTwips _nTop)
     606             : {
     607       13820 :     const bool bTopChanged( _SetObjTop( _nTop ) );
     608       13820 :     if ( bTopChanged )
     609             :     {
     610        2976 :         mbObjRectWithSpacesValid = false;
     611             :     }
     612       13820 : }
     613             : 
     614        4693 : void SwAnchoredObject::SetObjLeft( const SwTwips _nLeft)
     615             : {
     616        4693 :     const bool bLeftChanged( _SetObjLeft( _nLeft ) );
     617        4693 :     if ( bLeftChanged )
     618             :     {
     619        2514 :         mbObjRectWithSpacesValid = false;
     620             :     }
     621        4693 : }
     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          79 : void SwAnchoredObject::UpdateObjInSortedList()
     632             : {
     633          79 :     if ( GetAnchorFrm() )
     634             :     {
     635          79 :         if ( GetFrameFormat().getIDocumentSettingAccess()->get(DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION) )
     636             :         {
     637             :             // invalidate position of all anchored objects at anchor frame
     638          29 :             if ( GetAnchorFrm()->GetDrawObjs() )
     639             :             {
     640          29 :                 const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
     641             :                 // determine start index
     642          99 :                 for ( size_t i = 0; i < pObjs->size(); ++i )
     643             :                 {
     644          70 :                     SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     645          70 :                     if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
     646          13 :                         pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence( true );
     647             :                     else
     648          57 :                         pAnchoredObj->InvalidateObjPos();
     649             :                 }
     650             :             }
     651             :             // invalidate all following anchored objects on the page frame
     652          29 :             if ( GetPageFrm() && GetPageFrm()->GetSortedObjs() )
     653             :             {
     654          29 :                 const SwSortedObjs* pObjs = GetPageFrm()->GetSortedObjs();
     655             :                 // determine start index
     656          53 :                 for ( size_t i = pObjs->ListPosOf( *this ) + 1; i < pObjs->size(); ++i )
     657             :                 {
     658          24 :                     SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
     659          24 :                     if ( pAnchoredObj->ConsiderObjWrapInfluenceOnObjPos() )
     660           4 :                         pAnchoredObj->InvalidateObjPosForConsiderWrapInfluence( true );
     661             :                     else
     662          20 :                         pAnchoredObj->InvalidateObjPos();
     663             :                 }
     664             :             }
     665             :         }
     666             :         // update its position in the sorted object list of its anchor frame
     667          79 :         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          79 :         if ( GetFrameFormat().GetAnchor().GetAnchorId() != FLY_AS_CHAR )
     671             :         {
     672          72 :             GetPageFrm()->GetSortedObjs()->Update( *this );
     673             :         }
     674             :     }
     675          79 : }
     676             : 
     677             : /** method to determine, if invalidation of position is allowed
     678             : 
     679             :     #i28701#
     680             : */
     681        3201 : 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        3201 :     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       43008 : SwPageFrm* SwAnchoredObject::FindPageFrmOfAnchor()
     699             : {
     700       43008 :     SwPageFrm* pRetPageFrm = 0L;
     701             : 
     702             :     // --> #i44339# - check, if anchor frame exists.
     703       43008 :     if ( mpAnchorFrm )
     704             :     {
     705             :         // --> #i26945# - use new method <GetAnchorFrmContainingAnchPos()>
     706       43008 :         pRetPageFrm = GetAnchorFrmContainingAnchPos()->FindPageFrm();
     707             :     }
     708             : 
     709       43008 :     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 SwTextFrm*
     718             :     text frame containing the anchor character. It's NULL, if the object
     719             :     isn't anchored at-character resp. as-character.
     720             : */
     721      163014 : SwTextFrm* SwAnchoredObject::FindAnchorCharFrm()
     722             : {
     723      163014 :     SwTextFrm* pAnchorCharFrm( 0L );
     724             : 
     725             :     // --> #i44339# - check, if anchor frame exists.
     726      163014 :     if ( mpAnchorFrm )
     727             :     {
     728      163014 :         const SwFormatAnchor& rAnch = GetFrameFormat().GetAnchor();
     729      289702 :         if ((rAnch.GetAnchorId() == FLY_AT_CHAR) ||
     730      126688 :             (rAnch.GetAnchorId() == FLY_AS_CHAR))
     731             :         {
     732       52992 :             pAnchorCharFrm = &(static_cast<SwTextFrm*>(AnchorFrm())->
     733      105984 :                         GetFrmAtOfst( rAnch.GetContentAnchor()->nContent.GetIndex() ));
     734             :         }
     735             :     }
     736             : 
     737      163014 :     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       22066 : bool SwAnchoredObject::IsFormatPossible() const
     747             : {
     748       22066 :     return GetFrameFormat().GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId( GetDrawObj()->GetLayer() );
     749             : }
     750             : 
     751             : // --> #i3317#
     752          96 : void SwAnchoredObject::SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence )
     753             : {
     754          96 :     mbTmpConsiderWrapInfluence = _bTmpConsiderWrapInfluence;
     755             :     // --> #i35911#
     756          96 :     if ( mbTmpConsiderWrapInfluence )
     757             :     {
     758           1 :         SwLayouter::InsertObjForTmpConsiderWrapInfluence( *(GetFrameFormat().GetDoc()),
     759           1 :                                                           *this );
     760             :     }
     761          96 : }
     762             : 
     763             : 
     764           1 : void SwAnchoredObject::SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence )
     765             : {
     766           1 :     const SwSortedObjs* pObjs = GetAnchorFrm()->GetDrawObjs();
     767           1 :     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           1 : }
     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        3966 : bool SwAnchoredObject::OverlapsPrevColumn() const
     790             : {
     791        3966 :     bool bOverlapsPrevColumn( false );
     792             : 
     793        3966 :     if ( mpAnchorFrm && mpAnchorFrm->IsTextFrm() )
     794             :     {
     795        3966 :         const SwFrm* pColFrm = mpAnchorFrm->FindColFrm();
     796        3966 :         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        3966 :     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           6 : Point SwAnchoredObject::GetRelPosToAnchorFrm() const
     819             : {
     820           6 :     Point aRelPos;
     821             : 
     822             :     OSL_ENSURE( GetAnchorFrm(),
     823             :             "<SwAnchoredObject::GetRelPosToAnchorFrm()> - missing anchor frame." );
     824           6 :     aRelPos = GetObjRect().Pos();
     825           6 :     aRelPos -= GetAnchorFrm()->Frm().Pos();
     826             : 
     827           6 :     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         177 : }
     912             : 
     913             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11