LCOV - code coverage report
Current view: top level - sw/source/core/layout - anchoreddrawobject.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 247 308 80.2 %
Date: 2014-04-11 Functions: 29 35 82.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 <dcontact.hxx>
      21             : #include <rootfrm.hxx>
      22             : #include <pagefrm.hxx>
      23             : #include <tocntntanchoredobjectposition.hxx>
      24             : #include <tolayoutanchoredobjectposition.hxx>
      25             : #include <frmtool.hxx>
      26             : #include <fmtornt.hxx>
      27             : // --> #i32795#
      28             : #include <txtfrm.hxx>
      29             : // --> #i32795#
      30             : #include <vector>
      31             : #include <svx/svdogrp.hxx>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35             : /// helper class for correct notification due to the positioning of
      36             : /// the anchored drawing object
      37             : class SwPosNotify
      38             : {
      39             :     private:
      40             :         SwAnchoredDrawObject* mpAnchoredDrawObj;
      41             :         SwRect maOldObjRect;
      42             :         SwPageFrm* mpOldPageFrm;
      43             : 
      44             :     public:
      45             :         SwPosNotify( SwAnchoredDrawObject* _pAnchoredDrawObj );
      46             :         ~SwPosNotify();
      47             :         // #i32795#
      48             :         Point LastObjPos() const;
      49             : };
      50             : 
      51         631 : SwPosNotify::SwPosNotify( SwAnchoredDrawObject* _pAnchoredDrawObj ) :
      52         631 :     mpAnchoredDrawObj( _pAnchoredDrawObj )
      53             : {
      54         631 :     maOldObjRect = mpAnchoredDrawObj->GetObjRect();
      55             :     // --> #i35640# - determine correct page frame
      56         631 :     mpOldPageFrm = mpAnchoredDrawObj->GetPageFrm();
      57         631 : }
      58             : 
      59         631 : SwPosNotify::~SwPosNotify()
      60             : {
      61         631 :     if ( maOldObjRect != mpAnchoredDrawObj->GetObjRect() )
      62             :     {
      63         544 :         if( maOldObjRect.HasArea() && mpOldPageFrm )
      64             :         {
      65             :             mpAnchoredDrawObj->NotifyBackground( mpOldPageFrm, maOldObjRect,
      66         474 :                                                  PREP_FLY_LEAVE );
      67             :         }
      68         544 :         SwRect aNewObjRect( mpAnchoredDrawObj->GetObjRect() );
      69         544 :         if( aNewObjRect.HasArea() )
      70             :         {
      71             :             // --> #i35640# - determine correct page frame
      72         474 :             SwPageFrm* pNewPageFrm = mpAnchoredDrawObj->GetPageFrm();
      73         474 :             if( pNewPageFrm )
      74             :                 mpAnchoredDrawObj->NotifyBackground( pNewPageFrm, aNewObjRect,
      75         474 :                                                      PREP_FLY_ARRIVE );
      76             :         }
      77             : 
      78         544 :         ::ClrContourCache( mpAnchoredDrawObj->GetDrawObj() );
      79             : 
      80             :         // --> #i35640# - additional notify anchor text frame
      81             :         // Needed for negative positioned drawing objects
      82             :         // --> #i43255# - refine condition to avoid unneeded
      83             :         // invalidations: anchored object had to be on the page of its anchor
      84             :         // text frame.
      85        1081 :         if ( mpAnchoredDrawObj->GetAnchorFrm()->IsTxtFrm() &&
      86         537 :              mpOldPageFrm == mpAnchoredDrawObj->GetAnchorFrm()->FindPageFrm() )
      87             :         {
      88         535 :             mpAnchoredDrawObj->AnchorFrm()->Prepare( PREP_FLY_LEAVE );
      89             :         }
      90             : 
      91             :         // indicate a restart of the layout process
      92         544 :         mpAnchoredDrawObj->SetRestartLayoutProcess( true );
      93             :     }
      94             :     else
      95             :     {
      96             :         // lock position
      97          87 :         mpAnchoredDrawObj->LockPosition();
      98             : 
      99          87 :         if ( !mpAnchoredDrawObj->ConsiderForTextWrap() )
     100             :         {
     101             :             // indicate that object has to be considered for text wrap
     102          15 :             mpAnchoredDrawObj->SetConsiderForTextWrap( true );
     103             :             // invalidate 'background' in order to allow its 'background'
     104             :             // to wrap around it.
     105             :             mpAnchoredDrawObj->NotifyBackground( mpAnchoredDrawObj->GetPageFrm(),
     106          15 :                                     mpAnchoredDrawObj->GetObjRectWithSpaces(),
     107          30 :                                     PREP_FLY_ARRIVE );
     108             :             // invalidate position of anchor frame in order to force
     109             :             // a re-format of the anchor frame, which also causes a
     110             :             // re-format of the invalid previous frames of the anchor frame.
     111          15 :             mpAnchoredDrawObj->AnchorFrm()->InvalidatePos();
     112             :         }
     113             :     }
     114         631 : }
     115             : 
     116             : // --> #i32795#
     117         624 : Point SwPosNotify::LastObjPos() const
     118             : {
     119         624 :     return maOldObjRect.Pos();
     120             : }
     121             : 
     122             : // #i32795#
     123             : /// helper class for oscillation control on object positioning
     124             : class SwObjPosOscillationControl
     125             : {
     126             :     private:
     127             :         sal_uInt8 mnPosStackSize;
     128             : 
     129             :         const SwAnchoredDrawObject* mpAnchoredDrawObj;
     130             : 
     131             :         std::vector<Point*> maObjPositions;
     132             : 
     133             :     public:
     134             :         SwObjPosOscillationControl( const SwAnchoredDrawObject& _rAnchoredDrawObj );
     135             :         ~SwObjPosOscillationControl();
     136             : 
     137             :         bool OscillationDetected();
     138             : };
     139             : 
     140         624 : SwObjPosOscillationControl::SwObjPosOscillationControl(
     141             :                                 const SwAnchoredDrawObject& _rAnchoredDrawObj )
     142             :     : mnPosStackSize( 20 ),
     143         624 :       mpAnchoredDrawObj( &_rAnchoredDrawObj )
     144             : {
     145         624 : }
     146             : 
     147        1248 : SwObjPosOscillationControl::~SwObjPosOscillationControl()
     148             : {
     149        1785 :     while ( !maObjPositions.empty() )
     150             :     {
     151         537 :         Point* pPos = maObjPositions.back();
     152         537 :         delete pPos;
     153             : 
     154         537 :         maObjPositions.pop_back();
     155             :     }
     156         624 : }
     157             : 
     158         537 : bool SwObjPosOscillationControl::OscillationDetected()
     159             : {
     160         537 :     bool bOscillationDetected = false;
     161             : 
     162         537 :     if ( maObjPositions.size() == mnPosStackSize )
     163             :     {
     164             :         // position stack is full -> oscillation
     165           0 :         bOscillationDetected = true;
     166             :     }
     167             :     else
     168             :     {
     169         537 :         Point* pNewObjPos = new Point( mpAnchoredDrawObj->GetObjRect().Pos() );
     170        1611 :         for ( std::vector<Point*>::iterator aObjPosIter = maObjPositions.begin();
     171        1074 :               aObjPosIter != maObjPositions.end();
     172             :               ++aObjPosIter )
     173             :         {
     174           0 :             if ( *(pNewObjPos) == *(*aObjPosIter) )
     175             :             {
     176             :                 // position already occurred -> oscillation
     177           0 :                 bOscillationDetected = true;
     178           0 :                 delete pNewObjPos;
     179           0 :                 break;
     180             :             }
     181             :         }
     182         537 :         if ( !bOscillationDetected )
     183             :         {
     184         537 :             maObjPositions.push_back( pNewObjPos );
     185             :         }
     186             :     }
     187             : 
     188         537 :     return bOscillationDetected;
     189             : }
     190             : 
     191             : // class <SwAnchoredDrawObject>
     192             : 
     193      357896 : TYPEINIT1(SwAnchoredDrawObject,SwAnchoredObject);
     194             : 
     195        1266 : SwAnchoredDrawObject::SwAnchoredDrawObject() :
     196             :     SwAnchoredObject(),
     197             :     mbValidPos( false ),
     198             :     // --> #i34748#
     199             :     mpLastObjRect( 0L ),
     200             :     mbNotYetAttachedToAnchorFrame( true ),
     201             :     // --> #i28749#
     202             :     mbNotYetPositioned( true ),
     203             :     // --> #i62875#
     204        1266 :     mbCaptureAfterLayoutDirChange( false )
     205             : {
     206        1266 : }
     207             : 
     208        2530 : SwAnchoredDrawObject::~SwAnchoredDrawObject()
     209             : {
     210             :     // #i34748#
     211        1265 :     delete mpLastObjRect;
     212        1265 : }
     213             : 
     214             : // --> #i62875#
     215         974 : void SwAnchoredDrawObject::UpdateLayoutDir()
     216             : {
     217         974 :     SwFrmFmt::tLayoutDir nOldLayoutDir( GetFrmFmt().GetLayoutDir() );
     218             : 
     219         974 :     SwAnchoredObject::UpdateLayoutDir();
     220             : 
     221        2045 :     if ( !NotYetPositioned() &&
     222          97 :          GetFrmFmt().GetLayoutDir() != nOldLayoutDir &&
     223         974 :          GetFrmFmt().GetDoc()->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
     224           0 :          !IsOutsidePage() )
     225             :     {
     226           0 :         mbCaptureAfterLayoutDirChange = true;
     227             :     }
     228         974 : }
     229             : 
     230             : // --> #i62875#
     231           0 : bool SwAnchoredDrawObject::IsOutsidePage() const
     232             : {
     233           0 :     bool bOutsidePage( false );
     234             : 
     235           0 :     if ( !NotYetPositioned() && GetPageFrm() )
     236             :     {
     237           0 :         SwRect aTmpRect( GetObjRect() );
     238             :         bOutsidePage =
     239           0 :             ( aTmpRect.Intersection( GetPageFrm()->Frm() ) != GetObjRect() );
     240             :     }
     241             : 
     242           0 :     return bOutsidePage;
     243             : }
     244             : 
     245        4990 : void SwAnchoredDrawObject::MakeObjPos()
     246             : {
     247        4990 :     if ( IsPositioningInProgress() )
     248             :     {
     249             :         // nothind to do - positioning already in progress
     250           0 :         return;
     251             :     }
     252             : 
     253        4990 :     if ( mbValidPos )
     254             :     {
     255             :         // nothing to do - position is valid
     256        3854 :         return;
     257             :     }
     258             : 
     259             :     // --> #i28749# - anchored drawing object has to be attached
     260             :     // to anchor frame
     261        1136 :     if ( mbNotYetAttachedToAnchorFrame )
     262             :     {
     263             :         OSL_FAIL( "<SwAnchoredDrawObject::MakeObjPos() - drawing object not yet attached to anchor frame -> no positioning" );
     264           0 :         return;
     265             :     }
     266             : 
     267             :     SwDrawContact* pDrawContact =
     268        1136 :                         static_cast<SwDrawContact*>(::GetUserCall( GetDrawObj() ));
     269             : 
     270             :     // --> #i28749# - if anchored drawing object hasn't been yet
     271             :     // positioned, convert its positioning attributes, if its positioning
     272             :     // attributes are given in horizontal left-to-right layout.
     273             :     // --> #i36010# - Note: horizontal left-to-right layout is made
     274             :     // the default layout direction for <SwDrawFrmFmt> instances. Thus, it has
     275             :     // to be adjusted manually, if no adjustment of the positioning attributes
     276             :     // have to be performed here.
     277             :     // --> #i35635# - additionally move drawing object to the visible layer.
     278        1136 :     if ( mbNotYetPositioned )
     279             :     {
     280             :         // --> #i35635#
     281         872 :         pDrawContact->MoveObjToVisibleLayer( DrawObj() );
     282             :         // --> perform conversion of positioning
     283             :         // attributes only for 'master' drawing objects
     284             :         // #i44334#, #i44681# - check, if positioning
     285             :         // attributes already have been set.
     286        1694 :         if ( !GetDrawObj()->ISA(SwDrawVirtObj) &&
     287         822 :              !static_cast<SwDrawFrmFmt&>(GetFrmFmt()).IsPosAttrSet() )
     288             :         {
     289         797 :             _SetPositioningAttr();
     290             :         }
     291             :         // -->
     292             :         // - reset internal flag after all needed actions are performed to
     293             :         //   avoid callbacks from drawing layer
     294         872 :         mbNotYetPositioned = false;
     295             :     }
     296             : 
     297             :     // indicate that positioning is in progress
     298             :     {
     299        1136 :         SwObjPositioningInProgress aObjPosInProgress( *this );
     300             : 
     301             :         // determine relative position of drawing object and set it
     302        1136 :         switch ( pDrawContact->GetAnchorId() )
     303             :         {
     304             :             case FLY_AS_CHAR:
     305             :             {
     306             :                 // indicate that position will be valid after positioning is performed
     307         505 :                 mbValidPos = true;
     308             :                 // nothing to do, because as-character anchored objects are positioned
     309             :                 // during the format of its anchor frame - see <SwFlyCntPortion::SetBase(..)>
     310             :             }
     311         505 :             break;
     312             :             case FLY_AT_PARA:
     313             :             case FLY_AT_CHAR:
     314             :             {
     315             :                 // --> #i32795# - move intrinsic positioning to
     316             :                 // helper method <_MakeObjPosAnchoredAtPara()>
     317         624 :                 _MakeObjPosAnchoredAtPara();
     318             :             }
     319         624 :             break;
     320             :             case FLY_AT_PAGE:
     321             :             case FLY_AT_FLY:
     322             :             {
     323             :                 // --> #i32795# - move intrinsic positioning to
     324             :                 // helper method <_MakeObjPosAnchoredAtLayout()>
     325           7 :                 _MakeObjPosAnchoredAtLayout();
     326             :             }
     327           7 :             break;
     328             :             default:
     329             :             {
     330             :                 OSL_FAIL( "<SwAnchoredDrawObject::MakeObjPos()> - unknown anchor type - please inform OD." );
     331             :             }
     332             :         }
     333             : 
     334             :         // keep, current object rectangle
     335             :         // --> #i34748# - use new method <SetLastObjRect(..)>
     336        1136 :         SetLastObjRect( GetObjRect().SVRect() );
     337             : 
     338             :         // Assure for 'master' drawing object, that it's registered at the correct page.
     339             :         // Perform check not for as-character anchored drawing objects and only if
     340             :         // the anchor frame is valid.
     341        3258 :         if ( !GetDrawObj()->ISA(SwDrawVirtObj) &&
     342        1617 :              !pDrawContact->ObjAnchoredAsChar() &&
     343         481 :              GetAnchorFrm()->IsValid() )
     344             :         {
     345         450 :             pDrawContact->ChkPage();
     346        1136 :         }
     347             :     }
     348             : 
     349             :     // --> #i62875#
     350        1136 :     if ( mbCaptureAfterLayoutDirChange &&
     351           0 :          GetPageFrm() )
     352             :     {
     353           0 :         SwRect aPageRect( GetPageFrm()->Frm() );
     354           0 :         SwRect aObjRect( GetObjRect() );
     355           0 :         if ( aObjRect.Right() >= aPageRect.Right() + 10 )
     356             :         {
     357           0 :             Size aSize( aPageRect.Right() - aObjRect.Right(), 0 );
     358           0 :             DrawObj()->Move( aSize );
     359           0 :             aObjRect = GetObjRect();
     360             :         }
     361             : 
     362           0 :         if ( aObjRect.Left() + 10 <= aPageRect.Left() )
     363             :         {
     364           0 :             Size aSize( aPageRect.Left() - aObjRect.Left(), 0 );
     365           0 :             DrawObj()->Move( aSize );
     366             :         }
     367             : 
     368           0 :         mbCaptureAfterLayoutDirChange = false;
     369             :     }
     370             : }
     371             : 
     372             : /** method for the intrinsic positioning of a at-paragraph|at-character
     373             :     anchored drawing object
     374             : 
     375             :     #i32795# - helper method for method <MakeObjPos>
     376             : */
     377         624 : void SwAnchoredDrawObject::_MakeObjPosAnchoredAtPara()
     378             : {
     379             :     // --> #i32795# - adopt positioning algorithm from Writer
     380             :     // fly frames, which are anchored at paragraph|at character
     381             : 
     382             :     // Determine, if anchor frame can/has to be formatted.
     383             :     // If yes, after each object positioning the anchor frame is formatted.
     384             :     // If after the anchor frame format the object position isn't valid, the
     385             :     // object is positioned again.
     386             :     // --> #i43255# - refine condition: anchor frame format not
     387             :     // allowed, if another anchored object, has to be consider its wrap influence
     388             :     // --> #i50356# - format anchor frame containing the anchor
     389             :     // position. E.g., for at-character anchored object this can be the follow
     390             :     // frame of the anchor frame, which contains the anchor character.
     391             :     const bool bFormatAnchor =
     392        1248 :             !static_cast<const SwTxtFrm*>( GetAnchorFrmContainingAnchPos() )->IsAnyJoinLocked() &&
     393        1218 :             !ConsiderObjWrapInfluenceOnObjPos() &&
     394        1218 :             !ConsiderObjWrapInfluenceOfOtherObjs();
     395             : 
     396         624 :     if ( bFormatAnchor )
     397             :     {
     398             :         // --> #i50356#
     399         593 :         GetAnchorFrmContainingAnchPos()->Calc();
     400             :     }
     401             : 
     402         624 :     bool bOscillationDetected = false;
     403         624 :     SwObjPosOscillationControl aObjPosOscCtrl( *this );
     404             :     // --> #i3317# - boolean, to apply temporarly the
     405             :     // 'straightforward positioning process' for the frame due to its
     406             :     // overlapping with a previous column.
     407         624 :     bool bConsiderWrapInfluenceDueToOverlapPrevCol( false );
     408         624 :     do {
     409             :         // indicate that position will be valid after positioning is performed
     410         624 :         mbValidPos = true;
     411             : 
     412             :         // --> #i35640# - correct scope for <SwPosNotify> instance
     413             :         {
     414             :             // create instance of <SwPosNotify> for correct notification
     415         624 :             SwPosNotify aPosNotify( this );
     416             : 
     417             :             // determine and set position
     418             :             objectpositioning::SwToCntntAnchoredObjectPosition
     419        1248 :                     aObjPositioning( *DrawObj() );
     420         624 :             aObjPositioning.CalcPosition();
     421             : 
     422             :             // get further needed results of the positioning algorithm
     423         624 :             SetVertPosOrientFrm ( aObjPositioning.GetVertPosOrientFrm() );
     424         624 :             _SetDrawObjAnchor();
     425             : 
     426             :             // check for object position oscillation, if position has changed.
     427         624 :             if ( GetObjRect().Pos() != aPosNotify.LastObjPos() )
     428             :             {
     429         537 :                 bOscillationDetected = aObjPosOscCtrl.OscillationDetected();
     430         624 :             }
     431             :         }
     432             :         // format anchor frame, if requested.
     433             :         // Note: the format of the anchor frame can cause the object position
     434             :         // to be invalid.
     435         624 :         if ( bFormatAnchor )
     436             :         {
     437             :             // --> #i50356#
     438         593 :             GetAnchorFrmContainingAnchPos()->Calc();
     439             :         }
     440             : 
     441             :         // --> #i3317#
     442        1218 :         if ( !ConsiderObjWrapInfluenceOnObjPos() &&
     443         594 :              OverlapsPrevColumn() )
     444             :         {
     445           0 :             bConsiderWrapInfluenceDueToOverlapPrevCol = true;
     446             :         }
     447         624 :     } while ( !mbValidPos && !bOscillationDetected &&
     448           0 :               !bConsiderWrapInfluenceDueToOverlapPrevCol );
     449             : 
     450             :     // --> #i3317# - consider a detected oscillation and overlapping
     451             :     // with previous column.
     452             :     // temporarly consider the anchored objects wrapping style influence
     453         624 :     if ( bOscillationDetected || bConsiderWrapInfluenceDueToOverlapPrevCol )
     454             :     {
     455           0 :         SetTmpConsiderWrapInfluence( true );
     456           0 :         SetRestartLayoutProcess( true );
     457         624 :     }
     458         624 : }
     459             : 
     460             : /** method for the intrinsic positioning of a at-page|at-frame anchored
     461             :     drawing object
     462             : 
     463             :     #i32795# - helper method for method <MakeObjPos>
     464             : */
     465           7 : void SwAnchoredDrawObject::_MakeObjPosAnchoredAtLayout()
     466             : {
     467             :     // indicate that position will be valid after positioning is performed
     468           7 :     mbValidPos = true;
     469             : 
     470             :     // create instance of <SwPosNotify> for correct notification
     471           7 :     SwPosNotify aPosNotify( this );
     472             : 
     473             :     // determine position
     474             :     objectpositioning::SwToLayoutAnchoredObjectPosition
     475          14 :             aObjPositioning( *DrawObj() );
     476           7 :     aObjPositioning.CalcPosition();
     477             : 
     478             :     // set position
     479             : 
     480             :     // --> #i31698#
     481             :     // --> #i34995# - setting anchor position needed for filters,
     482             :     // especially for the xml-filter to the OpenOffice.org file format
     483             :     {
     484             :         const Point aNewAnchorPos =
     485           7 :                     GetAnchorFrm()->GetFrmAnchorPos( ::HasWrap( GetDrawObj() ) );
     486           7 :         DrawObj()->SetAnchorPos( aNewAnchorPos );
     487             :         // --> #i70122# - missing invalidation
     488           7 :         InvalidateObjRectWithSpaces();
     489             :     }
     490           7 :     SetCurrRelPos( aObjPositioning.GetRelPos() );
     491           7 :     const SwFrm* pAnchorFrm = GetAnchorFrm();
     492           7 :     SWRECTFN( pAnchorFrm );
     493           7 :     const Point aAnchPos( (pAnchorFrm->Frm().*fnRect->fnGetPos)() );
     494           7 :     SetObjLeft( aAnchPos.X() + GetCurrRelPos().X() );
     495          14 :     SetObjTop( aAnchPos.Y() + GetCurrRelPos().Y() );
     496           7 : }
     497             : 
     498         624 : void SwAnchoredDrawObject::_SetDrawObjAnchor()
     499             : {
     500             :     // new anchor position
     501             :     // --> #i31698# -
     502             :     Point aNewAnchorPos =
     503         624 :                 GetAnchorFrm()->GetFrmAnchorPos( ::HasWrap( GetDrawObj() ) );
     504         624 :     Point aCurrAnchorPos = GetDrawObj()->GetAnchorPos();
     505         624 :     if ( aNewAnchorPos != aCurrAnchorPos )
     506             :     {
     507             :         // determine movement to be applied after setting the new anchor position
     508         527 :         Size aMove( aCurrAnchorPos.getX() - aNewAnchorPos.getX(),
     509        1054 :                     aCurrAnchorPos.getY() - aNewAnchorPos.getY() );
     510             :         // set new anchor position
     511         527 :         DrawObj()->SetAnchorPos( aNewAnchorPos );
     512             :         // correct object position, caused by setting new anchor position
     513         527 :         DrawObj()->Move( aMove );
     514             :         // --> #i70122# - missing invalidation
     515         527 :         InvalidateObjRectWithSpaces();
     516             :     }
     517         624 : }
     518             : 
     519             : /** method to invalidate the given page frame
     520             : 
     521             :     #i28701#
     522             : */
     523         268 : void SwAnchoredDrawObject::_InvalidatePage( SwPageFrm* _pPageFrm )
     524             : {
     525         268 :     if ( _pPageFrm && !_pPageFrm->GetFmt()->GetDoc()->IsInDtor() )
     526             :     {
     527         268 :         if ( _pPageFrm->GetUpper() )
     528             :         {
     529             :             // --> #i35007# - correct invalidation for as-character
     530             :             // anchored objects.
     531         268 :             if ( GetFrmFmt().GetAnchor().GetAnchorId() == FLY_AS_CHAR )
     532             :             {
     533         117 :                 _pPageFrm->InvalidateFlyInCnt();
     534             :             }
     535             :             else
     536             :             {
     537         151 :                 _pPageFrm->InvalidateFlyLayout();
     538             :             }
     539             : 
     540         268 :             SwRootFrm* pRootFrm = static_cast<SwRootFrm*>(_pPageFrm->GetUpper());
     541         268 :             pRootFrm->DisallowTurbo();
     542         268 :             if ( pRootFrm->GetTurbo() )
     543             :             {
     544           0 :                 const SwCntntFrm* pTmpFrm = pRootFrm->GetTurbo();
     545           0 :                 pRootFrm->ResetTurbo();
     546           0 :                 pTmpFrm->InvalidatePage();
     547             :             }
     548         268 :             pRootFrm->SetIdleFlags();
     549             :         }
     550             :     }
     551         268 : }
     552             : 
     553        4513 : void SwAnchoredDrawObject::InvalidateObjPos()
     554             : {
     555             :     // --> #i28701# - check, if invalidation is allowed
     556        4788 :     if ( mbValidPos &&
     557         275 :          InvalidationOfPosAllowed() )
     558             :     {
     559         268 :         mbValidPos = false;
     560             :         // --> #i68520#
     561         268 :         InvalidateObjRectWithSpaces();
     562             : 
     563             :         // --> #i44339# - check, if anchor frame exists.
     564         268 :         if ( GetAnchorFrm() )
     565             :         {
     566             :             // --> #118547# - notify anchor frame of as-character
     567             :             // anchored object, because its positioned by the format of its anchor frame.
     568             :             // --> #i44559# - assure, that text hint is already
     569             :             // existing in the text frame
     570         536 :             if ( GetAnchorFrm()->ISA(SwTxtFrm) &&
     571         268 :                  (GetFrmFmt().GetAnchor().GetAnchorId() == FLY_AS_CHAR) )
     572             :             {
     573         117 :                 SwTxtFrm* pAnchorTxtFrm( static_cast<SwTxtFrm*>(AnchorFrm()) );
     574         234 :                 if ( pAnchorTxtFrm->GetTxtNode()->GetpSwpHints() &&
     575         117 :                      pAnchorTxtFrm->CalcFlyPos( &GetFrmFmt() ) != COMPLETE_STRING )
     576             :                 {
     577         117 :                     AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, &GetFrmFmt() );
     578             :                 }
     579             :             }
     580             : 
     581         268 :             SwPageFrm* pPageFrm = AnchorFrm()->FindPageFrm();
     582         268 :             _InvalidatePage( pPageFrm );
     583             : 
     584             :             // --> #i32270# - also invalidate page frame, at which the
     585             :             // drawing object is registered at.
     586         268 :             SwPageFrm* pPageFrmRegisteredAt = GetPageFrm();
     587         268 :             if ( pPageFrmRegisteredAt &&
     588             :                  pPageFrmRegisteredAt != pPageFrm )
     589             :             {
     590           0 :                 _InvalidatePage( pPageFrmRegisteredAt );
     591             :             }
     592             :             // #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
     593             :             // is replaced by method <FindPageFrmOfAnchor()>. It's return value
     594             :             // have to be checked.
     595         268 :             SwPageFrm* pPageFrmOfAnchor = FindPageFrmOfAnchor();
     596         268 :             if ( pPageFrmOfAnchor &&
     597           0 :                  pPageFrmOfAnchor != pPageFrm &&
     598             :                  pPageFrmOfAnchor != pPageFrmRegisteredAt )
     599             :             {
     600           0 :                 _InvalidatePage( pPageFrmOfAnchor );
     601             :             }
     602             :         }
     603             :     }
     604        4513 : }
     605             : 
     606       72537 : SwFrmFmt& SwAnchoredDrawObject::GetFrmFmt()
     607             : {
     608             :     OSL_ENSURE( static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFmt(),
     609             :             "<SwAnchoredDrawObject::GetFrmFmt()> - missing frame format -> crash." );
     610       72537 :     return *(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFmt());
     611             : }
     612      142473 : const SwFrmFmt& SwAnchoredDrawObject::GetFrmFmt() const
     613             : {
     614             :     OSL_ENSURE( static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFmt(),
     615             :             "<SwAnchoredDrawObject::GetFrmFmt()> - missing frame format -> crash." );
     616      142473 :     return *(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFmt());
     617             : }
     618             : 
     619      236015 : const SwRect SwAnchoredDrawObject::GetObjRect() const
     620             : {
     621             :     // use geometry of drawing object
     622             :     //return GetDrawObj()->GetCurrentBoundRect();
     623      236015 :     return GetDrawObj()->GetSnapRect();
     624             : }
     625             : 
     626             : // --> #i70122#
     627        1673 : const SwRect SwAnchoredDrawObject::GetObjBoundRect() const
     628             : {
     629        1673 :     bool bGroupShape = PTR_CAST(SdrObjGroup, GetDrawObj());
     630             :     // Resize objects with relative width or height
     631        1673 :     if ( !bGroupShape && GetPageFrm( ) && ( GetDrawObj( )->GetRelativeWidth( ) || GetDrawObj()->GetRelativeHeight( ) ) )
     632             :     {
     633          26 :         Rectangle aCurrObjRect = GetDrawObj()->GetCurrentBoundRect();
     634             : 
     635          26 :         long nTargetWidth = aCurrObjRect.GetWidth( );
     636          26 :         if ( GetDrawObj( )->GetRelativeWidth( ) )
     637             :         {
     638          26 :             Rectangle aPageRect;
     639          26 :             if (GetDrawObj()->GetRelativeWidthRelation() == text::RelOrientation::FRAME)
     640             :                 // Exclude margins.
     641          12 :                 aPageRect = GetPageFrm()->Prt().SVRect();
     642             :             else
     643          14 :                 aPageRect = GetPageFrm( )->GetBoundRect( ).SVRect();
     644          26 :             nTargetWidth = aPageRect.GetWidth( ) * GetDrawObj( )->GetRelativeWidth( ).get( );
     645             :         }
     646             : 
     647          26 :         long nTargetHeight = aCurrObjRect.GetHeight( );
     648          26 :         if ( GetDrawObj( )->GetRelativeHeight( ) )
     649             :         {
     650          20 :             Rectangle aPageRect;
     651          20 :             if (GetDrawObj()->GetRelativeHeightRelation() == text::RelOrientation::FRAME)
     652             :                 // Exclude margins.
     653           6 :                 aPageRect = GetPageFrm()->Prt().SVRect();
     654             :             else
     655          14 :                 aPageRect = GetPageFrm( )->GetBoundRect( ).SVRect();
     656          20 :             nTargetHeight = aPageRect.GetHeight( ) * GetDrawObj( )->GetRelativeHeight( ).get( );
     657             :         }
     658             : 
     659          26 :         if ( nTargetWidth != aCurrObjRect.GetWidth( ) || nTargetHeight != aCurrObjRect.GetHeight( ) )
     660             :         {
     661          21 :             const_cast< SdrObject* >( GetDrawObj() )->Resize( aCurrObjRect.TopLeft(),
     662             :                     Fraction( nTargetWidth, aCurrObjRect.GetWidth() ),
     663          21 :                     Fraction( nTargetHeight, aCurrObjRect.GetHeight() ), false );
     664             :         }
     665             :     }
     666        1673 :     return GetDrawObj()->GetCurrentBoundRect();
     667             : }
     668             : 
     669             : // --> #i68520#
     670        1879 : bool SwAnchoredDrawObject::_SetObjTop( const SwTwips _nTop )
     671             : {
     672        1879 :     SwTwips nDiff = _nTop - GetObjRect().Top();
     673        1879 :     DrawObj()->Move( Size( 0, nDiff ) );
     674             : 
     675        1879 :     return nDiff != 0;
     676             : }
     677         679 : bool SwAnchoredDrawObject::_SetObjLeft( const SwTwips _nLeft )
     678             : {
     679         679 :     SwTwips nDiff = _nLeft - GetObjRect().Left();
     680         679 :     DrawObj()->Move( Size( nDiff, 0 ) );
     681             : 
     682         679 :     return nDiff != 0;
     683             : }
     684             : 
     685             : /** adjust positioning and alignment attributes for new anchor frame
     686             : 
     687             :     #i33313# - add second optional parameter <_pNewObjRect>
     688             : */
     689           0 : void SwAnchoredDrawObject::AdjustPositioningAttr( const SwFrm* _pNewAnchorFrm,
     690             :                                                   const SwRect* _pNewObjRect )
     691             : {
     692           0 :     SwTwips nHoriRelPos = 0;
     693           0 :     SwTwips nVertRelPos = 0;
     694           0 :     const Point aAnchorPos = _pNewAnchorFrm->GetFrmAnchorPos( ::HasWrap( GetDrawObj() ) );
     695             :     // --> #i33313#
     696           0 :     const SwRect aObjRect( _pNewObjRect ? *_pNewObjRect : GetObjRect() );
     697           0 :     const bool bVert = _pNewAnchorFrm->IsVertical();
     698           0 :     const bool bR2L = _pNewAnchorFrm->IsRightToLeft();
     699           0 :     if ( bVert )
     700             :     {
     701           0 :         nHoriRelPos = aObjRect.Top() - aAnchorPos.Y();
     702           0 :         nVertRelPos = aAnchorPos.X() - aObjRect.Right();
     703             :     }
     704           0 :     else if ( bR2L )
     705             :     {
     706           0 :         nHoriRelPos = aAnchorPos.X() - aObjRect.Right();
     707           0 :         nVertRelPos = aObjRect.Top() - aAnchorPos.Y();
     708             :     }
     709             :     else
     710             :     {
     711           0 :         nHoriRelPos = aObjRect.Left() - aAnchorPos.X();
     712           0 :         nVertRelPos = aObjRect.Top() - aAnchorPos.Y();
     713             :     }
     714             : 
     715           0 :     GetFrmFmt().SetFmtAttr( SwFmtHoriOrient( nHoriRelPos, text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
     716           0 :     GetFrmFmt().SetFmtAttr( SwFmtVertOrient( nVertRelPos, text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
     717           0 : }
     718             : 
     719             : // --> #i34748# - change return type
     720           0 : const Rectangle* SwAnchoredDrawObject::GetLastObjRect() const
     721             : {
     722           0 :     return mpLastObjRect;
     723             : }
     724             : 
     725             : // --> #i34748# - change return type.
     726             : // If member <mpLastObjRect> is NULL, create one.
     727        3243 : void SwAnchoredDrawObject::SetLastObjRect( const Rectangle& _rNewLastRect )
     728             : {
     729        3243 :     if ( !mpLastObjRect )
     730             :     {
     731         872 :         mpLastObjRect = new Rectangle;
     732             :     }
     733        3243 :     *(mpLastObjRect) = _rNewLastRect;
     734        3243 : }
     735             : 
     736         974 : void SwAnchoredDrawObject::ObjectAttachedToAnchorFrame()
     737             : {
     738             :     // --> #i31698#
     739         974 :     SwAnchoredObject::ObjectAttachedToAnchorFrame();
     740             : 
     741         974 :     if ( mbNotYetAttachedToAnchorFrame )
     742             :     {
     743         877 :         mbNotYetAttachedToAnchorFrame = false;
     744             :     }
     745         974 : }
     746             : 
     747             : /** method to set positioning attributes
     748             : 
     749             :     #i35798#
     750             :     During load the positioning attributes aren't set.
     751             :     Thus, the positioning attributes are set by the current object geometry.
     752             :     This method is also used for the conversion for drawing objects
     753             :     (not anchored as-character) imported from OpenOffice.org file format
     754             :     once and directly before the first positioning.
     755             : */
     756         797 : void SwAnchoredDrawObject::_SetPositioningAttr()
     757             : {
     758             :     SwDrawContact* pDrawContact =
     759         797 :                         static_cast<SwDrawContact*>(GetUserCall( GetDrawObj() ));
     760             : 
     761         797 :     if ( !pDrawContact->ObjAnchoredAsChar() )
     762             :     {
     763         410 :         SwRect aObjRect( GetObjRect() );
     764             : 
     765         410 :         SwTwips nHoriPos = aObjRect.Left();
     766         410 :         SwTwips nVertPos = aObjRect.Top();
     767             :         // #i44334#, #i44681#
     768             :         // perform conversion only if position is in horizontal-left-to-right-layout.
     769         410 :         if ( GetFrmFmt().GetPositionLayoutDir() ==
     770             :                 text::PositionLayoutDir::PositionInHoriL2R )
     771             :         {
     772           3 :             SwFrmFmt::tLayoutDir eLayoutDir = GetFrmFmt().GetLayoutDir();
     773           3 :             switch ( eLayoutDir )
     774             :             {
     775             :                 case SwFrmFmt::HORI_L2R:
     776             :                 {
     777             :                     // nothing to do
     778             :                 }
     779           3 :                 break;
     780             :                 case SwFrmFmt::HORI_R2L:
     781             :                 {
     782           0 :                     nHoriPos = -aObjRect.Left() - aObjRect.Width();
     783             :                 }
     784           0 :                 break;
     785             :                 case SwFrmFmt::VERT_R2L:
     786             :                 {
     787           0 :                     nHoriPos = aObjRect.Top();
     788           0 :                     nVertPos = -aObjRect.Left() - aObjRect.Width();
     789             :                 }
     790           0 :                 break;
     791             :                 default:
     792             :                 {
     793             :                     OSL_FAIL( "<SwAnchoredDrawObject::_SetPositioningAttr()> - unsupported layout direction" );
     794             :                 }
     795             :             }
     796             :         }
     797             : 
     798             :         // --> #i71182#
     799             :         // only change position - do not lose other attributes
     800         410 :         SwFmtHoriOrient aHori( GetFrmFmt().GetHoriOrient() );
     801         410 :         aHori.SetPos( nHoriPos );
     802         410 :         GetFrmFmt().SetFmtAttr( aHori );
     803             : 
     804         820 :         SwFmtVertOrient aVert( GetFrmFmt().GetVertOrient() );
     805             : 
     806         410 :         aVert.SetPos( nVertPos );
     807         410 :         GetFrmFmt().SetFmtAttr( aVert );
     808             : 
     809             :         // --> #i36010# - set layout direction of the position
     810         410 :         GetFrmFmt().SetPositionLayoutDir(
     811         820 :             text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
     812             :     }
     813             :     // --> #i65798# - also for as-character anchored objects
     814             :     // --> #i45952# - indicate that position
     815             :     // attributes are set now.
     816         797 :     static_cast<SwDrawFrmFmt&>(GetFrmFmt()).PosAttrSet();
     817         797 : }
     818             : 
     819         987 : void SwAnchoredDrawObject::NotifyBackground( SwPageFrm* _pPageFrm,
     820             :                                              const SwRect& _rRect,
     821             :                                              PrepareHint _eHint )
     822             : {
     823         987 :     ::Notify_Background( GetDrawObj(), _pPageFrm, _rRect, _eHint, sal_True );
     824         987 : }
     825             : 
     826             : /** method to assure that anchored object is registered at the correct
     827             :     page frame
     828             : 
     829             :     #i28701#
     830             : */
     831         624 : void SwAnchoredDrawObject::RegisterAtCorrectPage()
     832             : {
     833         624 :     SwPageFrm* pPageFrm( 0L );
     834         624 :     if ( GetVertPosOrientFrm() )
     835             :     {
     836         624 :         pPageFrm = const_cast<SwPageFrm*>(GetVertPosOrientFrm()->FindPageFrm());
     837             :     }
     838         624 :     if ( pPageFrm && GetPageFrm() != pPageFrm )
     839             :     {
     840           2 :         if ( GetPageFrm() )
     841           2 :             GetPageFrm()->RemoveDrawObjFromPage( *this );
     842           2 :         pPageFrm->AppendDrawObjToPage( *this );
     843             :     }
     844         624 : }
     845             : 
     846             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10