LCOV - code coverage report
Current view: top level - sw/source/core/layout - pagedesc.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 179 238 75.2 %
Date: 2014-04-11 Functions: 28 34 82.4 %
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 <editeng/pbinitem.hxx>
      21             : #include <editeng/ulspitem.hxx>
      22             : #include <editeng/boxitem.hxx>
      23             : #include <editeng/brushitem.hxx>
      24             : #include <editeng/shaditem.hxx>
      25             : #include "editeng/frmdiritem.hxx"
      26             : #include <fmtclds.hxx>
      27             : #include <fmtfsize.hxx>
      28             : #include <pagefrm.hxx>
      29             : #include <pagedesc.hxx>
      30             : #include <swtable.hxx>
      31             : #include <frmtool.hxx>
      32             : #include <doc.hxx>
      33             : #include <poolfmt.hrc>
      34             : #include <poolfmt.hxx>
      35             : #include <switerator.hxx>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39        2349 : SwPageDesc::SwPageDesc( const OUString& rName, SwFrmFmt *pFmt, SwDoc *pDc ) :
      40             :     SwModify( 0 ),
      41             :     aDescName( rName ),
      42        2349 :     aMaster( pDc->GetAttrPool(), rName, pFmt ),
      43        2349 :     aLeft( pDc->GetAttrPool(), rName, pFmt ),
      44        2349 :     m_FirstMaster( pDc->GetAttrPool(), rName, pFmt ),
      45        2349 :     m_FirstLeft( pDc->GetAttrPool(), rName, pFmt ),
      46             :     aDepend( this, 0 ),
      47             :     pFollow( this ),
      48             :     nRegHeight( 0 ),
      49             :     nRegAscent( 0 ),
      50             :     eUse( (UseOnPage)(nsUseOnPage::PD_ALL | nsUseOnPage::PD_HEADERSHARE | nsUseOnPage::PD_FOOTERSHARE | nsUseOnPage::PD_FIRSTSHARE ) ),
      51             :     bLandscape( sal_False ),
      52             :     bHidden( sal_False ),
      53       11745 :     aFtnInfo()
      54             : {
      55        2349 : }
      56             : 
      57        3432 : SwPageDesc::SwPageDesc( const SwPageDesc &rCpy ) :
      58             :     SwModify( 0 ),
      59             :     aDescName( rCpy.GetName() ),
      60        3432 :     aNumType( rCpy.GetNumType() ),
      61        3432 :     aMaster( rCpy.GetMaster() ),
      62        3432 :     aLeft( rCpy.GetLeft() ),
      63        3432 :     m_FirstMaster( rCpy.GetFirstMaster() ),
      64        3432 :     m_FirstLeft( rCpy.GetFirstLeft() ),
      65        3432 :     aDepend( this, (SwModify*)rCpy.aDepend.GetRegisteredIn() ),
      66             :     pFollow( rCpy.pFollow ),
      67        3432 :     nRegHeight( rCpy.GetRegHeight() ),
      68        3432 :     nRegAscent( rCpy.GetRegAscent() ),
      69        3432 :     eUse( rCpy.ReadUseOn() ),
      70        3432 :     bLandscape( rCpy.GetLandscape() ),
      71        3432 :     bHidden( rCpy.IsHidden() ),
      72       41184 :     aFtnInfo( rCpy.GetFtnInfo() )
      73             : {
      74        3432 : }
      75             : 
      76         153 : SwPageDesc & SwPageDesc::operator = (const SwPageDesc & rSrc)
      77             : {
      78         153 :     aDescName = rSrc.aDescName;
      79         153 :     aNumType = rSrc.aNumType;
      80         153 :     aMaster = rSrc.aMaster;
      81         153 :     aLeft = rSrc.aLeft;
      82         153 :     m_FirstMaster = rSrc.m_FirstMaster;
      83         153 :     m_FirstLeft = rSrc.m_FirstLeft;
      84             : 
      85         153 :     if (rSrc.pFollow == &rSrc)
      86         139 :         pFollow = this;
      87             :     else
      88          14 :         pFollow = rSrc.pFollow;
      89             : 
      90         153 :     nRegHeight = rSrc.nRegHeight;
      91         153 :     nRegAscent = rSrc.nRegAscent;
      92         153 :     eUse = rSrc.eUse;
      93         153 :     bLandscape = rSrc.bLandscape;
      94         153 :     return *this;
      95             : }
      96             : 
      97       11380 : SwPageDesc::~SwPageDesc()
      98             : {
      99       11380 : }
     100             : 
     101             : /// Only the margin is mirrored.
     102             : /// Attributes like borders and so on are copied 1:1.
     103          59 : void SwPageDesc::Mirror()
     104             : {
     105             :     //Only the margins are mirrored, all other values are just copied.
     106          59 :     SvxLRSpaceItem aLR( RES_LR_SPACE );
     107          59 :     const SvxLRSpaceItem &rLR = aMaster.GetLRSpace();
     108          59 :     aLR.SetLeft(  rLR.GetRight() );
     109          59 :     aLR.SetRight( rLR.GetLeft() );
     110             : 
     111          59 :     SfxItemSet aSet( *aMaster.GetAttrSet().GetPool(),
     112         177 :                      aMaster.GetAttrSet().GetRanges() );
     113          59 :     aSet.Put( aLR );
     114          59 :     aSet.Put( aMaster.GetFrmSize() );
     115          59 :     aSet.Put( aMaster.GetPaperBin() );
     116          59 :     aSet.Put( aMaster.GetULSpace() );
     117          59 :     aSet.Put( aMaster.GetBox() );
     118          59 :     aSet.Put( aMaster.GetBackground() );
     119          59 :     aSet.Put( aMaster.GetShadow() );
     120          59 :     aSet.Put( aMaster.GetCol() );
     121          59 :     aSet.Put( aMaster.GetFrmDir() );    // #112217#
     122         118 :     aLeft.SetFmtAttr( aSet );
     123          59 : }
     124             : 
     125         215 : void SwPageDesc::ResetAllAttr( sal_Bool bLeft )
     126             : {
     127         215 :     SwFrmFmt& rFmt = bLeft ? GetLeft() : GetMaster();
     128             : 
     129             :     // #i73790# - method renamed
     130         215 :     rFmt.ResetAllFmtAttr();
     131         215 :     rFmt.SetFmtAttr( SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP, RES_FRAMEDIR) );
     132         215 : }
     133             : 
     134             : // gets information from Modify
     135         194 : bool SwPageDesc::GetInfo( SfxPoolItem & rInfo ) const
     136             : {
     137         194 :     if( !aMaster.GetInfo( rInfo ) )
     138           4 :         return false;       // found
     139         190 :     if ( !aLeft.GetInfo( rInfo ) )
     140           2 :         return false ;
     141         188 :     if ( !m_FirstMaster.GetInfo( rInfo ) )
     142          37 :         return false;
     143         151 :     return m_FirstLeft.GetInfo( rInfo );
     144             : }
     145             : 
     146             : /// set the style for the grid alignment
     147        6837 : void SwPageDesc::SetRegisterFmtColl( const SwTxtFmtColl* pFmt )
     148             : {
     149        6837 :     if( pFmt != GetRegisterFmtColl() )
     150             :     {
     151           0 :         if( pFmt )
     152           0 :             ((SwTxtFmtColl*)pFmt)->Add( &aDepend );
     153             :         else
     154           0 :             ((SwTxtFmtColl*)GetRegisterFmtColl())->Remove( &aDepend );
     155             : 
     156           0 :         RegisterChange();
     157             :     }
     158        6837 : }
     159             : 
     160             : /// retrieve the style for the grid alignment
     161       17896 : const SwTxtFmtColl* SwPageDesc::GetRegisterFmtColl() const
     162             : {
     163       17896 :     const SwModify* pReg = aDepend.GetRegisteredIn();
     164       17896 :     return (SwTxtFmtColl*)pReg;
     165             : }
     166             : 
     167             : /// notifie all affected page frames
     168           0 : void SwPageDesc::RegisterChange()
     169             : {
     170             :     // #117072# - During destruction of the document <SwDoc>
     171             :     // the page description is modified. Thus, do nothing, if the document
     172             :     // is in destruction respectively if no viewshell exists.
     173           0 :     SwDoc* pDoc = GetMaster().GetDoc();
     174           0 :     if ( !pDoc || pDoc->IsInDtor() )
     175             :     {
     176           0 :         return;
     177             :     }
     178           0 :     SwViewShell* pSh = 0L;
     179           0 :     pDoc->GetEditShell( &pSh );
     180           0 :     if ( !pSh )
     181             :     {
     182           0 :         return;
     183             :     }
     184             : 
     185           0 :     nRegHeight = 0;
     186             :     {
     187           0 :         SwIterator<SwFrm,SwFmt> aIter( GetMaster() );
     188           0 :         for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
     189             :         {
     190           0 :             if( pLast->IsPageFrm() )
     191           0 :                 ((SwPageFrm*)pLast)->PrepareRegisterChg();
     192           0 :         }
     193             :     }
     194             :     {
     195           0 :         SwIterator<SwFrm,SwFmt> aIter( GetLeft() );
     196           0 :         for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
     197             :         {
     198           0 :             if( pLast->IsPageFrm() )
     199           0 :                 ((SwPageFrm*)pLast)->PrepareRegisterChg();
     200           0 :         }
     201             :     }
     202             :     {
     203           0 :         SwIterator<SwFrm,SwFmt> aIter( GetFirstMaster() );
     204           0 :         for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
     205             :         {
     206           0 :             if( pLast->IsPageFrm() )
     207           0 :                 ((SwPageFrm*)pLast)->PrepareRegisterChg();
     208           0 :         }
     209             :     }
     210             :     {
     211           0 :         SwIterator<SwFrm,SwFmt> aIter( GetFirstLeft() );
     212           0 :         for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
     213             :         {
     214           0 :             if( pLast->IsPageFrm() )
     215           0 :                 ((SwPageFrm*)pLast)->PrepareRegisterChg();
     216           0 :         }
     217             :     }
     218             : }
     219             : 
     220             : /// special handling if the style of the grid alignment changes
     221           0 : void SwPageDesc::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
     222             : {
     223           0 :     const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
     224           0 :     NotifyClients( pOld, pNew );
     225             : 
     226           0 :     if ( (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich)
     227           0 :         || isCHRATR(nWhich) || (RES_PARATR_LINESPACING == nWhich) )
     228             :     {
     229           0 :         RegisterChange();
     230             :     }
     231           0 : }
     232             : 
     233         189 : static const SwFrm* lcl_GetFrmOfNode( const SwNode& rNd )
     234             : {
     235             :     SwModify* pMod;
     236         189 :     sal_uInt16 nFrmType = FRM_CNTNT;
     237             : 
     238         189 :     if( rNd.IsCntntNode() )
     239             :     {
     240         183 :         pMod = &(SwCntntNode&)rNd;
     241             :     }
     242           6 :     else if( rNd.IsTableNode() )
     243             :     {
     244           6 :         pMod = ((SwTableNode&)rNd).GetTable().GetFrmFmt();
     245           6 :         nFrmType = FRM_TAB;
     246             :     }
     247             :     else
     248           0 :         pMod = 0;
     249             : 
     250         189 :     Point aNullPt;
     251         189 :     return pMod ? ::GetFrmOfModify( 0, *pMod, nFrmType, &aNullPt, 0, sal_False )
     252         378 :                 : 0;
     253             : }
     254             : 
     255          89 : const SwPageDesc* SwPageDesc::GetPageDescOfNode(const SwNode& rNd)
     256             : {
     257          89 :     const SwPageDesc* pRet = 0;
     258          89 :     const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
     259          89 :     if (pChkFrm && 0 != (pChkFrm = pChkFrm->FindPageFrm()))
     260          89 :         pRet = ((const SwPageFrm*)pChkFrm)->GetPageDesc();
     261          89 :     return pRet;
     262             : }
     263             : 
     264          76 : const SwFrmFmt* SwPageDesc::GetPageFmtOfNode( const SwNode& rNd,
     265             :                                               sal_Bool bCheckForThisPgDc ) const
     266             : {
     267             :     // which PageDescFormat is valid for this node?
     268             :     const SwFrmFmt* pRet;
     269          76 :     const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
     270             : 
     271          76 :     if( pChkFrm && 0 != ( pChkFrm = pChkFrm->FindPageFrm() ))
     272             :     {
     273             :         const SwPageDesc* pPd = bCheckForThisPgDc ? this :
     274          24 :                                 ((SwPageFrm*)pChkFrm)->GetPageDesc();
     275          24 :         pRet = &pPd->GetMaster();
     276             :         OSL_ENSURE( ((SwPageFrm*)pChkFrm)->GetPageDesc() == pPd, "Wrong node for detection of page format!" );
     277             :         // this page is assigned to which format?
     278          24 :         if( !pChkFrm->KnowsFormat(*pRet) )
     279             :         {
     280          23 :             pRet = &pPd->GetLeft();
     281             :             OSL_ENSURE( pChkFrm->KnowsFormat(*pRet), "Wrong node for detection of page format!" );
     282             :         }
     283             :     }
     284             :     else
     285          52 :         pRet = &GetMaster();
     286          76 :     return pRet;
     287             : }
     288             : 
     289          24 : sal_Bool SwPageDesc::IsFollowNextPageOfNode( const SwNode& rNd ) const
     290             : {
     291          24 :     sal_Bool bRet = sal_False;
     292          24 :     if( GetFollow() && this != GetFollow() )
     293             :     {
     294          24 :         const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
     295          72 :         if( pChkFrm && 0 != ( pChkFrm = pChkFrm->FindPageFrm() ) &&
     296          96 :             pChkFrm->IsPageFrm() &&
     297          42 :             ( !pChkFrm->GetNext() || GetFollow() ==
     298           9 :                         ((SwPageFrm*)pChkFrm->GetNext())->GetPageDesc() ))
     299             :             // the page on which the follow points was found
     300          24 :             bRet = sal_True;
     301             :     }
     302          24 :     return bRet;
     303             : }
     304             : 
     305        2391 : SwFrmFmt *SwPageDesc::GetLeftFmt(bool const bFirst)
     306             : {
     307        2391 :     return (nsUseOnPage::PD_LEFT & eUse)
     308             :             ? ((bFirst) ? &m_FirstLeft : &aLeft)
     309        2391 :             : 0;
     310             : }
     311             : 
     312        3876 : SwFrmFmt *SwPageDesc::GetRightFmt(bool const bFirst)
     313             : {
     314        3876 :     return (nsUseOnPage::PD_RIGHT & eUse)
     315             :             ? ((bFirst) ? &m_FirstMaster : &aMaster)
     316        3876 :             : 0;
     317             : }
     318             : 
     319       32672 : sal_Bool SwPageDesc::IsFirstShared() const
     320             : {
     321       32672 :     return eUse & nsUseOnPage::PD_FIRSTSHARE ? sal_True : sal_False;
     322             : }
     323             : 
     324        5038 : void SwPageDesc::ChgFirstShare( sal_Bool bNew )
     325             : {
     326        5038 :     if ( bNew )
     327        4765 :         eUse = (UseOnPage) (eUse | nsUseOnPage::PD_FIRSTSHARE);
     328             :     else
     329         273 :         eUse = (UseOnPage) (eUse & nsUseOnPage::PD_NOFIRSTSHARE);
     330        5038 : }
     331             : 
     332        1360 : SwPageDesc* SwPageDesc::GetByName(SwDoc& rDoc, const OUString& rName)
     333             : {
     334        1360 :     const sal_uInt16 nDCount = rDoc.GetPageDescCnt();
     335             : 
     336        2430 :     for( sal_uInt16 i = 0; i < nDCount; i++ )
     337             :     {
     338        2426 :         SwPageDesc* pDsc = &rDoc.GetPageDesc( i );
     339        2426 :         if(pDsc->GetName() == rName)
     340             :         {
     341        1356 :             return pDsc;
     342             :         }
     343             :     }
     344             : 
     345          16 :     for( sal_Int32 i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i)
     346             :     {
     347          16 :         if (rName==SW_RESSTR(i))
     348             :         {
     349             :             return rDoc.GetPageDescFromPool( static_cast< sal_uInt16 >(
     350           4 :                         i - RC_POOLPAGEDESC_BEGIN + RES_POOLPAGE_BEGIN) );
     351             :         }
     352             :     }
     353             : 
     354           0 :     return 0;
     355             : }
     356             : 
     357        2349 : SwPageFtnInfo::SwPageFtnInfo() :
     358             :     nMaxHeight( 0 ),
     359             :     nLineWidth(10),
     360             :     eLineStyle( table::BorderLineStyle::SOLID ),
     361             :     aWidth( 25, 100 ),
     362             :     nTopDist( 57 ),         //1mm
     363        2349 :     nBottomDist( 57 )
     364             : {
     365        2349 :     eAdj = FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) ?
     366             :            FTNADJ_RIGHT :
     367        2349 :            FTNADJ_LEFT;
     368        2349 : }
     369             : 
     370       29674 : SwPageFtnInfo::SwPageFtnInfo( const SwPageFtnInfo &rCpy ) :
     371       29674 :     nMaxHeight( rCpy.GetHeight() ),
     372             :     nLineWidth(rCpy.nLineWidth),
     373             :     eLineStyle(rCpy.eLineStyle),
     374             :     aLineColor(rCpy.aLineColor),
     375       29674 :     aWidth( rCpy.GetWidth() ),
     376       29674 :     eAdj( rCpy.GetAdj() ),
     377       29674 :     nTopDist( rCpy.GetTopDist() ),
     378      118696 :     nBottomDist( rCpy.GetBottomDist() )
     379             : {
     380       29674 : }
     381             : 
     382        4719 : SwPageFtnInfo &SwPageFtnInfo::operator=( const SwPageFtnInfo& rCpy )
     383             : {
     384        4719 :     nMaxHeight  = rCpy.GetHeight();
     385        4719 :     nLineWidth  = rCpy.nLineWidth;
     386        4719 :     eLineStyle  = rCpy.eLineStyle;
     387        4719 :     aLineColor  = rCpy.aLineColor;
     388        4719 :     aWidth      = rCpy.GetWidth();
     389        4719 :     eAdj        = rCpy.GetAdj();
     390        4719 :     nTopDist    = rCpy.GetTopDist();
     391        4719 :     nBottomDist = rCpy.GetBottomDist();
     392        4719 :     return *this;
     393             : }
     394             : 
     395       10083 : sal_Bool SwPageFtnInfo::operator==( const SwPageFtnInfo& rCmp ) const
     396             : {
     397       20164 :     return ( nMaxHeight == rCmp.GetHeight() &&
     398       20156 :              nLineWidth == rCmp.nLineWidth &&
     399       19715 :              eLineStyle == rCmp.eLineStyle &&
     400       19280 :              aLineColor == rCmp.aLineColor &&
     401       16626 :              aWidth     == rCmp.GetWidth() &&
     402       13972 :              eAdj       == rCmp.GetAdj() &&
     403       24055 :              nTopDist   == rCmp.GetTopDist() &&
     404       17069 :              nBottomDist== rCmp.GetBottomDist() );
     405             : }
     406             : 
     407         153 : SwPageDescExt::SwPageDescExt(const SwPageDesc & rPageDesc, SwDoc * _pDoc)
     408         153 :     : aPageDesc(rPageDesc), pDoc(_pDoc)
     409             : {
     410         153 :     SetPageDesc(rPageDesc);
     411         153 : }
     412             : 
     413           0 : SwPageDescExt::SwPageDescExt(const SwPageDescExt & rSrc)
     414           0 :     : aPageDesc(rSrc.aPageDesc), pDoc(rSrc.pDoc)
     415             : {
     416           0 :     SetPageDesc(rSrc.aPageDesc);
     417           0 : }
     418             : 
     419         153 : SwPageDescExt::~SwPageDescExt()
     420             : {
     421         153 : }
     422             : 
     423         216 : OUString SwPageDescExt::GetName() const
     424             : {
     425         216 :     return aPageDesc.GetName();
     426             : }
     427             : 
     428         153 : void SwPageDescExt::SetPageDesc(const SwPageDesc & _aPageDesc)
     429             : {
     430         153 :     aPageDesc = _aPageDesc;
     431             : 
     432         153 :     if (aPageDesc.GetFollow())
     433         153 :         sFollow = aPageDesc.GetFollow()->GetName();
     434         153 : }
     435             : 
     436           0 : SwPageDescExt & SwPageDescExt::operator = (const SwPageDesc & rSrc)
     437             : {
     438           0 :     SetPageDesc(rSrc);
     439             : 
     440           0 :     return *this;
     441             : }
     442             : 
     443           0 : SwPageDescExt & SwPageDescExt::operator = (const SwPageDescExt & rSrc)
     444             : {
     445           0 :     SetPageDesc(rSrc.aPageDesc);
     446             : 
     447           0 :     return *this;
     448             : }
     449             : 
     450           0 : SwPageDescExt::operator SwPageDesc() const
     451             : {
     452           0 :     SwPageDesc aResult(aPageDesc);
     453             : 
     454           0 :     SwPageDesc * pPageDesc = pDoc->GetPageDesc(sFollow);
     455             : 
     456           0 :     if ( 0 != pPageDesc )
     457           0 :         aResult.SetFollow(pPageDesc);
     458             : 
     459           0 :     return aResult;
     460             : }
     461             : 
     462        3696 : SwPageDescs::~SwPageDescs()
     463             : {
     464        1848 :     for(const_iterator it = begin(); it != end(); ++it)
     465           0 :         delete *it;
     466        1848 : }
     467             : 
     468             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10