LCOV - code coverage report
Current view: top level - sw/source/core/objectpositioning - tolayoutanchoredobjectposition.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 73 85 85.9 %
Date: 2015-06-13 12:38:46 Functions: 5 6 83.3 %
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 <tolayoutanchoredobjectposition.hxx>
      21             : #include <anchoredobject.hxx>
      22             : #include <frame.hxx>
      23             : #include <pagefrm.hxx>
      24             : #include <svx/svdobj.hxx>
      25             : #include <frmfmt.hxx>
      26             : #include <fmtanchr.hxx>
      27             : #include <fmtornt.hxx>
      28             : #include <fmtsrnd.hxx>
      29             : #include <IDocumentSettingAccess.hxx>
      30             : #include <frmatr.hxx>
      31             : #include "viewsh.hxx"
      32             : #include "viewopt.hxx"
      33             : #include "rootfrm.hxx"
      34             : #include <editeng/lrspitem.hxx>
      35             : #include <editeng/ulspitem.hxx>
      36             : 
      37             : using namespace objectpositioning;
      38             : using namespace ::com::sun::star;
      39             : 
      40         109 : SwToLayoutAnchoredObjectPosition::SwToLayoutAnchoredObjectPosition( SdrObject& _rDrawObj )
      41             :     : SwAnchoredObjectPosition( _rDrawObj ),
      42             :       maRelPos( Point() ),
      43             :       // #i26791#
      44         109 :       maOffsetToFrmAnchorPos( Point() )
      45         109 : {}
      46             : 
      47         109 : SwToLayoutAnchoredObjectPosition::~SwToLayoutAnchoredObjectPosition()
      48         109 : {}
      49             : 
      50             : /** calculate position for object position type TO_LAYOUT */
      51         109 : void SwToLayoutAnchoredObjectPosition::CalcPosition()
      52             : {
      53         109 :     const SwRect aObjBoundRect( GetAnchoredObj().GetObjRect() );
      54             : 
      55         109 :     SWRECTFN( (&GetAnchorFrm()) );
      56             : 
      57         109 :     const SwFrameFormat& rFrameFormat = GetFrameFormat();
      58         109 :     const SvxLRSpaceItem &rLR = rFrameFormat.GetLRSpace();
      59         109 :     const SvxULSpaceItem &rUL = rFrameFormat.GetULSpace();
      60             : 
      61         109 :     const bool bFlyAtFly = FLY_AT_FLY == rFrameFormat.GetAnchor().GetAnchorId();
      62             : 
      63             :     // determine position.
      64             :     // 'vertical' and 'horizontal' position are calculated separately
      65         109 :     Point aRelPos;
      66             : 
      67             :     // calculate 'vertical' position
      68         109 :     SwFormatVertOrient aVert( rFrameFormat.GetVertOrient() );
      69             :     {
      70             :         // to-frame anchored objects are *only* vertical positioned centered or
      71             :         // bottom, if its wrap mode is 'throught' and its anchor frame has fixed
      72             :         // size. Otherwise, it's positioned top.
      73         109 :         sal_Int16 eVertOrient = aVert.GetVertOrient();
      74         127 :         if ( ( bFlyAtFly &&
      75          18 :                ( eVertOrient == text::VertOrientation::CENTER ||
      76           0 :                  eVertOrient == text::VertOrientation::BOTTOM ) &&
      77         109 :              SURROUND_THROUGHT != rFrameFormat.GetSurround().GetSurround() &&
      78           0 :              !GetAnchorFrm().HasFixSize() ) )
      79             :         {
      80           0 :             eVertOrient = text::VertOrientation::TOP;
      81             :         }
      82             :         // #i26791# - get vertical offset to frame anchor position.
      83         109 :         SwTwips nVertOffsetToFrmAnchorPos( 0L );
      84             :         SwTwips nRelPosY =
      85         109 :                 _GetVertRelPos( GetAnchorFrm(), GetAnchorFrm(), eVertOrient,
      86         109 :                                 aVert.GetRelationOrient(), aVert.GetPos(),
      87         327 :                                 rLR, rUL, nVertOffsetToFrmAnchorPos );
      88             : 
      89             :         // keep the calculated relative vertical position - needed for filters
      90             :         // (including the xml-filter)
      91             :         {
      92         109 :             SwTwips nAttrRelPosY = nRelPosY - nVertOffsetToFrmAnchorPos;
      93         120 :             if ( aVert.GetVertOrient() != text::VertOrientation::NONE &&
      94          11 :                  aVert.GetPos() != nAttrRelPosY )
      95             :             {
      96           6 :                 aVert.SetPos( nAttrRelPosY );
      97           6 :                 const_cast<SwFrameFormat&>(rFrameFormat).LockModify();
      98           6 :                 const_cast<SwFrameFormat&>(rFrameFormat).SetFormatAttr( aVert );
      99           6 :                 const_cast<SwFrameFormat&>(rFrameFormat).UnlockModify();
     100             :             }
     101             :         }
     102             : 
     103             :         // determine absolute 'vertical' position, depending on layout-direction
     104             :         // #i26791# - determine offset to 'vertical' frame
     105             :         // anchor position, depending on layout-direction
     106         109 :         if( bVert )
     107             :         {
     108             :             OSL_ENSURE( !bRev, "<SwToLayoutAnchoredObjectPosition::CalcPosition()> - reverse layout set." );
     109             : 
     110           0 :             if ( bVertL2R )
     111           0 :                    aRelPos.X() = nRelPosY;
     112             :             else
     113           0 :                    aRelPos.X() = -nRelPosY - aObjBoundRect.Width();
     114           0 :             maOffsetToFrmAnchorPos.X() = nVertOffsetToFrmAnchorPos;
     115             :         }
     116             :         else
     117             :         {
     118         109 :             aRelPos.Y() = nRelPosY;
     119         109 :             maOffsetToFrmAnchorPos.Y() = nVertOffsetToFrmAnchorPos;
     120             :         }
     121             : 
     122             :         // if in online-layout the bottom of to-page anchored object is beyond
     123             :         // the page bottom, the page frame has to grow by growing its body frame.
     124         109 :         const SwViewShell *pSh = GetAnchorFrm().getRootFrm()->GetCurrShell();
     125         309 :         if ( !bFlyAtFly && GetAnchorFrm().IsPageFrm() &&
     126         200 :              pSh && pSh->GetViewOptions()->getBrowseMode() )
     127             :         {
     128           2 :             const long nAnchorBottom = GetAnchorFrm().Frm().Bottom();
     129           4 :             const long nBottom = GetAnchorFrm().Frm().Top() +
     130           4 :                                  aRelPos.Y() + aObjBoundRect.Height();
     131           2 :             if ( nAnchorBottom < nBottom )
     132             :             {
     133           0 :                 static_cast<SwPageFrm&>(GetAnchorFrm()).
     134           0 :                         FindBodyCont()->Grow( nBottom - nAnchorBottom );
     135             :             }
     136             :         }
     137             :     } // end of determination of vertical position
     138             : 
     139             :     // calculate 'horizontal' position
     140         218 :     SwFormatHoriOrient aHori( rFrameFormat.GetHoriOrient() );
     141             :     {
     142             :         // consider toggle of horizontal position for even pages.
     143         109 :         const bool bToggle = aHori.IsPosToggle() &&
     144         109 :                              !GetAnchorFrm().FindPageFrm()->OnRightPage();
     145         109 :         sal_Int16 eHoriOrient = aHori.GetHoriOrient();
     146         109 :         sal_Int16 eRelOrient = aHori.GetRelationOrient();
     147             :         // toggle orientation
     148         109 :         _ToggleHoriOrientAndAlign( bToggle, eHoriOrient, eRelOrient );
     149             : 
     150             :         // determine alignment values:
     151             :         // <nWidth>: 'width' of the alignment area
     152             :         // <nOffset>: offset of alignment area, relative to 'left' of
     153             :         //            frame anchor position
     154             :         SwTwips nWidth, nOffset;
     155             :         {
     156             :             bool bDummy; // in this context irrelevant output parameter
     157         109 :             _GetHoriAlignmentValues( GetAnchorFrm(), GetAnchorFrm(),
     158             :                                      eRelOrient, false,
     159         218 :                                      nWidth, nOffset, bDummy );
     160             :         }
     161             : 
     162         109 :         SwTwips nObjWidth = (aObjBoundRect.*fnRect->fnGetWidth)();
     163             : 
     164             :         // determine relative horizontal position
     165             :         SwTwips nRelPosX;
     166         109 :         if ( text::HoriOrientation::NONE == eHoriOrient )
     167             :         {
     168         204 :             if( bToggle ||
     169         204 :                 ( !aHori.IsPosToggle() && GetAnchorFrm().IsRightToLeft() ) )
     170             :             {
     171           0 :                 nRelPosX = nWidth - nObjWidth - aHori.GetPos();
     172             :             }
     173             :             else
     174             :             {
     175         102 :                 nRelPosX = aHori.GetPos();
     176             :             }
     177             :         }
     178           7 :         else if ( text::HoriOrientation::CENTER == eHoriOrient )
     179           3 :             nRelPosX = (nWidth / 2) - (nObjWidth / 2);
     180           4 :         else if ( text::HoriOrientation::RIGHT == eHoriOrient )
     181           2 :             nRelPosX = nWidth - ( nObjWidth +
     182           2 :                              ( bVert ? rUL.GetLower() : rLR.GetRight() ) );
     183             :         else
     184           2 :             nRelPosX = bVert ? rUL.GetUpper() : rLR.GetLeft();
     185         109 :         nRelPosX += nOffset;
     186             : 
     187             :         // no 'negative' relative horizontal position
     188             :         // OD 06.11.2003 #FollowTextFlowAtFrame# - negative positions allow for
     189             :         // to frame anchored objects.
     190         109 :         if ( !bFlyAtFly && nRelPosX < 0 )
     191             :         {
     192           1 :             nRelPosX = 0;
     193             :         }
     194             : 
     195             :         // determine absolute 'horizontal' position, depending on layout-direction
     196             :         // #i26791# - determine offset to 'horizontal' frame
     197             :         // anchor position, depending on layout-direction
     198         109 :         if( bVert || bVertL2R )
     199             :         {
     200             : 
     201           0 :             aRelPos.Y() = nRelPosX;
     202           0 :             maOffsetToFrmAnchorPos.Y() = nOffset;
     203             :         }
     204             :         else
     205             :         {
     206         109 :             aRelPos.X() = nRelPosX;
     207         109 :             maOffsetToFrmAnchorPos.X() = nOffset;
     208             :         }
     209             : 
     210             :         // keep the calculated relative horizontal position - needed for filters
     211             :         // (including the xml-filter)
     212             :         {
     213         109 :             SwTwips nAttrRelPosX = nRelPosX - nOffset;
     214         116 :             if ( text::HoriOrientation::NONE != aHori.GetHoriOrient() &&
     215           7 :                  aHori.GetPos() != nAttrRelPosX )
     216             :             {
     217           4 :                 aHori.SetPos( nAttrRelPosX );
     218           4 :                 const_cast<SwFrameFormat&>(rFrameFormat).LockModify();
     219           4 :                 const_cast<SwFrameFormat&>(rFrameFormat).SetFormatAttr( aHori );
     220           4 :                 const_cast<SwFrameFormat&>(rFrameFormat).UnlockModify();
     221             :             }
     222             :         }
     223             :     } // end of determination of horizontal position
     224             : 
     225             :     // keep calculate relative position
     226         218 :     maRelPos = aRelPos;
     227         286 : }
     228             : 
     229             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11