LCOV - code coverage report
Current view: top level - sw/source/core/objectpositioning - tolayoutanchoredobjectposition.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 87 0.0 %
Date: 2014-04-14 Functions: 0 5 0.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 <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           0 : SwToLayoutAnchoredObjectPosition::SwToLayoutAnchoredObjectPosition( SdrObject& _rDrawObj )
      41             :     : SwAnchoredObjectPosition( _rDrawObj ),
      42             :       maRelPos( Point() ),
      43             :       // #i26791#
      44           0 :       maOffsetToFrmAnchorPos( Point() )
      45           0 : {}
      46             : 
      47           0 : SwToLayoutAnchoredObjectPosition::~SwToLayoutAnchoredObjectPosition()
      48           0 : {}
      49             : 
      50             : /** calculate position for object position type TO_LAYOUT */
      51           0 : void SwToLayoutAnchoredObjectPosition::CalcPosition()
      52             : {
      53           0 :     const SwRect aObjBoundRect( GetAnchoredObj().GetObjRect() );
      54             : 
      55           0 :     SWRECTFN( (&GetAnchorFrm()) );
      56             : 
      57           0 :     const SwFrmFmt& rFrmFmt = GetFrmFmt();
      58           0 :     const SvxLRSpaceItem &rLR = rFrmFmt.GetLRSpace();
      59           0 :     const SvxULSpaceItem &rUL = rFrmFmt.GetULSpace();
      60             : 
      61           0 :     const bool bFlyAtFly = FLY_AT_FLY == rFrmFmt.GetAnchor().GetAnchorId();
      62             : 
      63             :     // determine position.
      64             :     // 'vertical' and 'horizontal' position are calculated separately
      65           0 :     Point aRelPos;
      66             : 
      67             :     // calculate 'vertical' position
      68           0 :     SwFmtVertOrient aVert( rFrmFmt.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           0 :         sal_Int16 eVertOrient = aVert.GetVertOrient();
      74           0 :         if ( ( bFlyAtFly &&
      75           0 :                ( eVertOrient == text::VertOrientation::CENTER ||
      76           0 :                  eVertOrient == text::VertOrientation::BOTTOM ) &&
      77           0 :              SURROUND_THROUGHT != rFrmFmt.GetSurround().GetSurround() &&
      78           0 :              !GetAnchorFrm().HasFixSize() ) )
      79             :         {
      80           0 :             eVertOrient = text::VertOrientation::TOP;
      81             :         }
      82             :         // #i26791# - get vertical offset to frame anchor position.
      83           0 :         SwTwips nVertOffsetToFrmAnchorPos( 0L );
      84             :         SwTwips nRelPosY =
      85           0 :                 _GetVertRelPos( GetAnchorFrm(), GetAnchorFrm(), eVertOrient,
      86           0 :                                 aVert.GetRelationOrient(), aVert.GetPos(),
      87           0 :                                 rLR, rUL, nVertOffsetToFrmAnchorPos );
      88             : 
      89             :         // keep the calculated relative vertical position - needed for filters
      90             :         // (including the xml-filter)
      91             :         {
      92           0 :             SwTwips nAttrRelPosY = nRelPosY - nVertOffsetToFrmAnchorPos;
      93           0 :             if ( aVert.GetVertOrient() != text::VertOrientation::NONE &&
      94           0 :                  aVert.GetPos() != nAttrRelPosY )
      95             :             {
      96           0 :                 aVert.SetPos( nAttrRelPosY );
      97           0 :                 const_cast<SwFrmFmt&>(rFrmFmt).LockModify();
      98           0 :                 const_cast<SwFrmFmt&>(rFrmFmt).SetFmtAttr( aVert );
      99           0 :                 const_cast<SwFrmFmt&>(rFrmFmt).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           0 :         if( bVert )
     107             :         {
     108             :             OSL_ENSURE( !bRev, "<SwToLayoutAnchoredObjectPosition::CalcPosition()> - reverse layout set." );
     109             :             //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     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           0 :             aRelPos.Y() = nRelPosY;
     119           0 :             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           0 :         const SwViewShell *pSh = GetAnchorFrm().getRootFrm()->GetCurrShell();
     125           0 :         if ( !bFlyAtFly && GetAnchorFrm().IsPageFrm() &&
     126           0 :              pSh && pSh->GetViewOptions()->getBrowseMode() )
     127             :         {
     128           0 :             const long nAnchorBottom = GetAnchorFrm().Frm().Bottom();
     129           0 :             const long nBottom = GetAnchorFrm().Frm().Top() +
     130           0 :                                  aRelPos.Y() + aObjBoundRect.Height();
     131           0 :             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           0 :     SwFmtHoriOrient aHori( rFrmFmt.GetHoriOrient() );
     141             :     {
     142             :         // consider toggle of horizontal position for even pages.
     143           0 :         const bool bToggle = aHori.IsPosToggle() &&
     144           0 :                              !GetAnchorFrm().FindPageFrm()->OnRightPage();
     145           0 :         sal_Int16 eHoriOrient = aHori.GetHoriOrient();
     146           0 :         sal_Int16 eRelOrient = aHori.GetRelationOrient();
     147             :         // toggle orientation
     148           0 :         _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           0 :             _GetHoriAlignmentValues( GetAnchorFrm(), GetAnchorFrm(),
     158             :                                      eRelOrient, false,
     159           0 :                                      nWidth, nOffset, bDummy );
     160             :         }
     161             : 
     162           0 :         SwTwips nObjWidth = (aObjBoundRect.*fnRect->fnGetWidth)();
     163             : 
     164             :         // determine relative horizontal position
     165             :         SwTwips nRelPosX;
     166           0 :         if ( text::HoriOrientation::NONE == eHoriOrient )
     167             :         {
     168           0 :             if( bToggle ||
     169           0 :                 ( !aHori.IsPosToggle() && GetAnchorFrm().IsRightToLeft() ) )
     170             :             {
     171           0 :                 nRelPosX = nWidth - nObjWidth - aHori.GetPos();
     172             :             }
     173             :             else
     174             :             {
     175           0 :                 nRelPosX = aHori.GetPos();
     176             :             }
     177             :         }
     178           0 :         else if ( text::HoriOrientation::CENTER == eHoriOrient )
     179           0 :             nRelPosX = (nWidth / 2) - (nObjWidth / 2);
     180           0 :         else if ( text::HoriOrientation::RIGHT == eHoriOrient )
     181           0 :             nRelPosX = nWidth - ( nObjWidth +
     182           0 :                              ( bVert ? rUL.GetLower() : rLR.GetRight() ) );
     183             :         else
     184           0 :             nRelPosX = bVert ? rUL.GetUpper() : rLR.GetLeft();
     185           0 :         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           0 :         if ( !bFlyAtFly && nRelPosX < 0 )
     191             :         {
     192           0 :             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             :         //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     199             :         // --> OD 2009-09-04 #mongolianlayout#
     200           0 :         if( bVert || bVertL2R )
     201             :         {
     202             : 
     203           0 :             aRelPos.Y() = nRelPosX;
     204           0 :             maOffsetToFrmAnchorPos.Y() = nOffset;
     205             :         }
     206             :         else
     207             :         {
     208           0 :             aRelPos.X() = nRelPosX;
     209           0 :             maOffsetToFrmAnchorPos.X() = nOffset;
     210             :         }
     211             : 
     212             :         // keep the calculated relative horizontal position - needed for filters
     213             :         // (including the xml-filter)
     214             :         {
     215           0 :             SwTwips nAttrRelPosX = nRelPosX - nOffset;
     216           0 :             if ( text::HoriOrientation::NONE != aHori.GetHoriOrient() &&
     217           0 :                  aHori.GetPos() != nAttrRelPosX )
     218             :             {
     219           0 :                 aHori.SetPos( nAttrRelPosX );
     220           0 :                 const_cast<SwFrmFmt&>(rFrmFmt).LockModify();
     221           0 :                 const_cast<SwFrmFmt&>(rFrmFmt).SetFmtAttr( aHori );
     222           0 :                 const_cast<SwFrmFmt&>(rFrmFmt).UnlockModify();
     223             :             }
     224             :         }
     225             :     } // end of determination of horizontal position
     226             : 
     227             :     // keep calculate relative position
     228           0 :     maRelPos = aRelPos;
     229           0 : }
     230             : 
     231             : /** calculated relative position for object position */
     232           0 : Point SwToLayoutAnchoredObjectPosition::GetRelPos() const
     233             : {
     234           0 :     return maRelPos;
     235             : }
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10