LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/layout - anchoreddrawobject.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 208 301 69.1 %
Date: 2012-12-27 Functions: 28 35 80.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10