LCOV - code coverage report
Current view: top level - sw/source/core/layout - pagedesc.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 195 235 83.0 %
Date: 2015-06-13 12:38:46 Functions: 31 35 88.6 %
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 <IDocumentLayoutAccess.hxx>
      35             : #include <IDocumentStylePoolAccess.hxx>
      36             : #include <poolfmt.hxx>
      37             : #include <calbck.hxx>
      38             : 
      39             : using namespace ::com::sun::star;
      40             : 
      41       69380 : SwPageDesc::SwPageDesc(const OUString& rName, SwFrameFormat *pFormat, SwDoc *const pDoc)
      42             :     : SwModify(nullptr)
      43             :     , m_StyleName( rName )
      44       69380 :     , m_Master( pDoc->GetAttrPool(), rName, pFormat )
      45       69380 :     , m_Left( pDoc->GetAttrPool(), rName, pFormat )
      46       69380 :     , m_FirstMaster( pDoc->GetAttrPool(), rName, pFormat )
      47       69380 :     , m_FirstLeft( pDoc->GetAttrPool(), rName, pFormat )
      48             :     , m_Depend( this, 0 )
      49             :     , m_pFollow( this )
      50             :     , m_nRegHeight( 0 )
      51             :     , m_nRegAscent( 0 )
      52             :     , m_eUse( (UseOnPage)(nsUseOnPage::PD_ALL | nsUseOnPage::PD_HEADERSHARE | nsUseOnPage::PD_FOOTERSHARE | nsUseOnPage::PD_FIRSTSHARE) )
      53             :     , m_IsLandscape( false )
      54      346900 :     , m_IsHidden( false )
      55             : {
      56       69380 : }
      57             : 
      58        7783 : SwPageDesc::SwPageDesc( const SwPageDesc &rCpy )
      59             :     : SwModify(nullptr)
      60             :     , m_StyleName( rCpy.GetName() )
      61        7783 :     , m_NumType( rCpy.GetNumType() )
      62        7783 :     , m_Master( rCpy.GetMaster() )
      63        7783 :     , m_Left( rCpy.GetLeft() )
      64        7783 :     , m_FirstMaster( rCpy.GetFirstMaster() )
      65        7783 :     , m_FirstLeft( rCpy.GetFirstLeft() )
      66        7783 :     , m_Depend( this, const_cast<SwModify*>(rCpy.m_Depend.GetRegisteredIn()) )
      67             :     , m_pFollow( rCpy.m_pFollow )
      68        7783 :     , m_nRegHeight( rCpy.GetRegHeight() )
      69        7783 :     , m_nRegAscent( rCpy.GetRegAscent() )
      70        7783 :     , m_eUse( rCpy.ReadUseOn() )
      71        7783 :     , m_IsLandscape( rCpy.GetLandscape() )
      72        7783 :     , m_IsHidden( rCpy.IsHidden() )
      73       93396 :     , m_IsFootnoteInfo( rCpy.GetFootnoteInfo() )
      74             : {
      75        7783 : }
      76             : 
      77         350 : SwPageDesc & SwPageDesc::operator = (const SwPageDesc & rSrc)
      78             : {
      79         350 :     m_StyleName = rSrc.m_StyleName;
      80         350 :     m_NumType = rSrc.m_NumType;
      81         350 :     m_Master = rSrc.m_Master;
      82         350 :     m_Left = rSrc.m_Left;
      83         350 :     m_FirstMaster = rSrc.m_FirstMaster;
      84         350 :     m_FirstLeft = rSrc.m_FirstLeft;
      85             : 
      86         350 :     if (rSrc.m_pFollow == &rSrc)
      87         343 :         m_pFollow = this;
      88             :     else
      89           7 :         m_pFollow = rSrc.m_pFollow;
      90             : 
      91         350 :     m_nRegHeight = rSrc.m_nRegHeight;
      92         350 :     m_nRegAscent = rSrc.m_nRegAscent;
      93         350 :     m_eUse = rSrc.m_eUse;
      94         350 :     m_IsLandscape = rSrc.m_IsLandscape;
      95         350 :     return *this;
      96             : }
      97             : 
      98      153890 : SwPageDesc::~SwPageDesc()
      99             : {
     100      153890 : }
     101             : 
     102             : /// Only the margin is mirrored.
     103             : /// Attributes like borders and so on are copied 1:1.
     104         191 : void SwPageDesc::Mirror()
     105             : {
     106             :     //Only the margins are mirrored, all other values are just copied.
     107         191 :     SvxLRSpaceItem aLR( RES_LR_SPACE );
     108         191 :     const SvxLRSpaceItem &rLR = m_Master.GetLRSpace();
     109         191 :     aLR.SetLeft(  rLR.GetRight() );
     110         191 :     aLR.SetRight( rLR.GetLeft() );
     111             : 
     112         191 :     SfxItemSet aSet( *m_Master.GetAttrSet().GetPool(),
     113         573 :                      m_Master.GetAttrSet().GetRanges() );
     114         191 :     aSet.Put( aLR );
     115         191 :     aSet.Put( m_Master.GetFrmSize() );
     116         191 :     aSet.Put( m_Master.GetPaperBin() );
     117         191 :     aSet.Put( m_Master.GetULSpace() );
     118         191 :     aSet.Put( m_Master.GetBox() );
     119         191 :     aSet.Put( m_Master.makeBackgroundBrushItem() );
     120         191 :     aSet.Put( m_Master.GetShadow() );
     121         191 :     aSet.Put( m_Master.GetCol() );
     122         191 :     aSet.Put( m_Master.GetFrmDir() );    // #112217#
     123         382 :     m_Left.SetFormatAttr( aSet );
     124         191 : }
     125             : 
     126         540 : void SwPageDesc::ResetAllAttr( bool bLeft )
     127             : {
     128         540 :     SwFrameFormat& rFormat = bLeft ? GetLeft() : GetMaster();
     129             : 
     130             :     // #i73790# - method renamed
     131         540 :     rFormat.ResetAllFormatAttr();
     132         540 :     rFormat.SetFormatAttr( SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP, RES_FRAMEDIR) );
     133         540 : }
     134             : 
     135             : // gets information from Modify
     136         420 : bool SwPageDesc::GetInfo( SfxPoolItem & rInfo ) const
     137             : {
     138         420 :     if (!m_Master.GetInfo(rInfo))
     139           6 :         return false;       // found
     140         414 :     if (!m_Left.GetInfo(rInfo))
     141          26 :         return false ;
     142         388 :     if ( !m_FirstMaster.GetInfo( rInfo ) )
     143         105 :         return false;
     144         283 :     return m_FirstLeft.GetInfo( rInfo );
     145             : }
     146             : 
     147             : /// set the style for the grid alignment
     148       15482 : void SwPageDesc::SetRegisterFormatColl( const SwTextFormatColl* pFormat )
     149             : {
     150       15482 :     if( pFormat != GetRegisterFormatColl() )
     151             :     {
     152          18 :         if( pFormat )
     153          18 :             const_cast<SwTextFormatColl*>(pFormat)->Add(&m_Depend);
     154             :         else
     155           0 :             const_cast<SwTextFormatColl*>(GetRegisterFormatColl())->Remove(&m_Depend);
     156             : 
     157          18 :         RegisterChange();
     158             :     }
     159       15482 : }
     160             : 
     161             : /// retrieve the style for the grid alignment
     162       43045 : const SwTextFormatColl* SwPageDesc::GetRegisterFormatColl() const
     163             : {
     164       43045 :     const SwModify* pReg = m_Depend.GetRegisteredIn();
     165       43045 :     return static_cast<const SwTextFormatColl*>(pReg);
     166             : }
     167             : 
     168             : /// notifie all affected page frames
     169          45 : void SwPageDesc::RegisterChange()
     170             : {
     171             :     // #117072# - During destruction of the document <SwDoc>
     172             :     // the page description is modified. Thus, do nothing, if the document
     173             :     // is in destruction respectively if no viewshell exists.
     174          45 :     SwDoc* pDoc = GetMaster().GetDoc();
     175          45 :     if ( !pDoc || pDoc->IsInDtor() )
     176             :     {
     177           0 :         return;
     178             :     }
     179          45 :     SwViewShell* pSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
     180          45 :     if ( !pSh )
     181             :     {
     182          45 :         return;
     183             :     }
     184             : 
     185           0 :     m_nRegHeight = 0;
     186             :     {
     187           0 :         SwIterator<SwFrm,SwFormat> aIter( GetMaster() );
     188           0 :         for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
     189             :         {
     190           0 :             if( pLast->IsPageFrm() )
     191           0 :                 static_cast<SwPageFrm*>(pLast)->PrepareRegisterChg();
     192           0 :         }
     193             :     }
     194             :     {
     195           0 :         SwIterator<SwFrm,SwFormat> aIter( GetLeft() );
     196           0 :         for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
     197             :         {
     198           0 :             if( pLast->IsPageFrm() )
     199           0 :                 static_cast<SwPageFrm*>(pLast)->PrepareRegisterChg();
     200           0 :         }
     201             :     }
     202             :     {
     203           0 :         SwIterator<SwFrm,SwFormat> aIter( GetFirstMaster() );
     204           0 :         for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
     205             :         {
     206           0 :             if( pLast->IsPageFrm() )
     207           0 :                 static_cast<SwPageFrm*>(pLast)->PrepareRegisterChg();
     208           0 :         }
     209             :     }
     210             :     {
     211           0 :         SwIterator<SwFrm,SwFormat> aIter( GetFirstLeft() );
     212           0 :         for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
     213             :         {
     214           0 :             if( pLast->IsPageFrm() )
     215           0 :                 static_cast<SwPageFrm*>(pLast)->PrepareRegisterChg();
     216           0 :         }
     217             :     }
     218             : }
     219             : 
     220             : /// special handling if the style of the grid alignment changes
     221          27 : void SwPageDesc::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
     222             : {
     223          27 :     const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
     224          27 :     NotifyClients( pOld, pNew );
     225             : 
     226          36 :     if ( (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich)
     227          27 :         || isCHRATR(nWhich) || (RES_PARATR_LINESPACING == nWhich) )
     228             :     {
     229          27 :         RegisterChange();
     230             :     }
     231          27 : }
     232             : 
     233         458 : static const SwFrm* lcl_GetFrmOfNode( const SwNode& rNd )
     234             : {
     235             :     const SwModify* pMod;
     236         458 :     sal_uInt16 nFrmType = FRM_CNTNT;
     237             : 
     238         458 :     if( rNd.IsContentNode() )
     239             :     {
     240         427 :         pMod = &static_cast<const SwContentNode&>(rNd);
     241             :     }
     242          31 :     else if( rNd.IsTableNode() )
     243             :     {
     244           7 :         pMod = static_cast<const SwTableNode&>(rNd).GetTable().GetFrameFormat();
     245           7 :         nFrmType = FRM_TAB;
     246             :     }
     247             :     else
     248          24 :         pMod = 0;
     249             : 
     250         458 :     Point aNullPt;
     251         434 :     return pMod ? ::GetFrmOfModify( 0, *pMod, nFrmType, &aNullPt, 0, false )
     252         892 :                 : 0;
     253             : }
     254             : 
     255         111 : const SwPageDesc* SwPageDesc::GetPageDescOfNode(const SwNode& rNd)
     256             : {
     257         111 :     const SwPageDesc* pRet = 0;
     258         111 :     const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
     259         111 :     if (pChkFrm && 0 != (pChkFrm = pChkFrm->FindPageFrm()))
     260         102 :         pRet = static_cast<const SwPageFrm*>(pChkFrm)->GetPageDesc();
     261         111 :     return pRet;
     262             : }
     263             : 
     264         301 : const SwFrameFormat* SwPageDesc::GetPageFormatOfNode( const SwNode& rNd,
     265             :                                               bool bCheckForThisPgDc ) const
     266             : {
     267             :     // which PageDescFormat is valid for this node?
     268             :     const SwFrameFormat* pRet;
     269         301 :     const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
     270             : 
     271         301 :     if( pChkFrm && 0 != ( pChkFrm = pChkFrm->FindPageFrm() ))
     272             :     {
     273             :         const SwPageDesc* pPd = bCheckForThisPgDc ? this :
     274          41 :                                 static_cast<const SwPageFrm*>(pChkFrm)->GetPageDesc();
     275          41 :         pRet = &pPd->GetMaster();
     276             :         OSL_ENSURE( static_cast<const SwPageFrm*>(pChkFrm)->GetPageDesc() == pPd, "Wrong node for detection of page format!" );
     277             :         // this page is assigned to which format?
     278          41 :         if( !pChkFrm->KnowsFormat(*pRet) )
     279             :         {
     280          40 :             pRet = &pPd->GetLeft();
     281             :             OSL_ENSURE( pChkFrm->KnowsFormat(*pRet), "Wrong node for detection of page format!" );
     282             :         }
     283             :     }
     284             :     else
     285         260 :         pRet = &GetMaster();
     286         301 :     return pRet;
     287             : }
     288             : 
     289          46 : bool SwPageDesc::IsFollowNextPageOfNode( const SwNode& rNd ) const
     290             : {
     291          46 :     bool bRet = false;
     292          46 :     if( GetFollow() && this != GetFollow() )
     293             :     {
     294          46 :         const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
     295         136 :         if( pChkFrm && 0 != ( pChkFrm = pChkFrm->FindPageFrm() ) &&
     296         180 :             pChkFrm->IsPageFrm() &&
     297          83 :             ( !pChkFrm->GetNext() || GetFollow() ==
     298          19 :                         static_cast<const SwPageFrm*>(pChkFrm->GetNext())->GetPageDesc() ))
     299             :             // the page on which the follow points was found
     300          44 :             bRet = true;
     301             :     }
     302          46 :     return bRet;
     303             : }
     304             : 
     305        6253 : SwFrameFormat *SwPageDesc::GetLeftFormat(bool const bFirst)
     306             : {
     307        6253 :     return (nsUseOnPage::PD_LEFT & m_eUse)
     308             :             ? ((bFirst) ? &m_FirstLeft : &m_Left)
     309        6253 :             : 0;
     310             : }
     311             : 
     312        8868 : SwFrameFormat *SwPageDesc::GetRightFormat(bool const bFirst)
     313             : {
     314        8868 :     return (nsUseOnPage::PD_RIGHT & m_eUse)
     315             :             ? ((bFirst) ? &m_FirstMaster : &m_Master)
     316        8868 :             : 0;
     317             : }
     318             : 
     319       74004 : bool SwPageDesc::IsFirstShared() const
     320             : {
     321       74004 :     return (m_eUse & nsUseOnPage::PD_FIRSTSHARE) != 0;
     322             : }
     323             : 
     324       11535 : void SwPageDesc::ChgFirstShare( bool bNew )
     325             : {
     326       11535 :     if ( bNew )
     327       11427 :         m_eUse = (UseOnPage) (m_eUse | nsUseOnPage::PD_FIRSTSHARE);
     328             :     else
     329         108 :         m_eUse = (UseOnPage) (m_eUse & nsUseOnPage::PD_NOFIRSTSHARE);
     330       11535 : }
     331             : 
     332        2276 : SwPageDesc* SwPageDesc::GetByName(SwDoc& rDoc, const OUString& rName)
     333             : {
     334        2276 :     const size_t nDCount = rDoc.GetPageDescCnt();
     335             : 
     336        3716 :     for( size_t i = 0; i < nDCount; i++ )
     337             :     {
     338        3712 :         SwPageDesc* pDsc = &rDoc.GetPageDesc( i );
     339        3712 :         if(pDsc->GetName() == rName)
     340             :         {
     341        2272 :             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           4 :             return rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( static_cast< sal_uInt16 >(
     350           4 :                         i - RC_POOLPAGEDESC_BEGIN + RES_POOLPAGE_BEGIN) );
     351             :         }
     352             :     }
     353             : 
     354           0 :     return 0;
     355             : }
     356             : 
     357       69380 : SwPageFootnoteInfo::SwPageFootnoteInfo()
     358             :     : m_nMaxHeight( 0 )
     359             :     , m_nLineWidth(10)
     360             :     , m_eLineStyle( table::BorderLineStyle::SOLID )
     361             :     , m_Width( 25, 100 )
     362             :     , m_nTopDist( 57 )         //1mm
     363       69380 :     , m_nBottomDist( 57 )
     364             : {
     365       69380 :     m_eAdjust = FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) ?
     366             :            FTNADJ_RIGHT :
     367       69380 :            FTNADJ_LEFT;
     368       69380 : }
     369             : 
     370       75880 : SwPageFootnoteInfo::SwPageFootnoteInfo( const SwPageFootnoteInfo &rCpy )
     371       75880 :     : m_nMaxHeight(rCpy.GetHeight())
     372             :     , m_nLineWidth(rCpy.m_nLineWidth)
     373             :     , m_eLineStyle(rCpy.m_eLineStyle)
     374             :     , m_LineColor(rCpy.m_LineColor)
     375       75880 :     , m_Width(rCpy.GetWidth())
     376       75880 :     , m_eAdjust(rCpy.GetAdj())
     377       75880 :     , m_nTopDist(rCpy.GetTopDist())
     378      303520 :     , m_nBottomDist(rCpy.GetBottomDist())
     379             : {
     380       75880 : }
     381             : 
     382        9994 : SwPageFootnoteInfo &SwPageFootnoteInfo::operator=( const SwPageFootnoteInfo& rCpy )
     383             : {
     384        9994 :     m_nMaxHeight  = rCpy.GetHeight();
     385        9994 :     m_nLineWidth  = rCpy.m_nLineWidth;
     386        9994 :     m_eLineStyle  = rCpy.m_eLineStyle;
     387        9994 :     m_LineColor   = rCpy.m_LineColor;
     388        9994 :     m_Width       = rCpy.GetWidth();
     389        9994 :     m_eAdjust     = rCpy.GetAdj();
     390        9994 :     m_nTopDist    = rCpy.GetTopDist();
     391        9994 :     m_nBottomDist = rCpy.GetBottomDist();
     392        9994 :     return *this;
     393             : }
     394             : 
     395       22644 : bool SwPageFootnoteInfo::operator==( const SwPageFootnoteInfo& rCmp ) const
     396             : {
     397       22644 :     return m_nMaxHeight == rCmp.GetHeight()
     398       22642 :         && m_nLineWidth == rCmp.m_nLineWidth
     399       22526 :         && m_eLineStyle == rCmp.m_eLineStyle
     400       21846 :         && m_LineColor  == rCmp.m_LineColor
     401       21846 :         && m_Width      == rCmp.GetWidth()
     402       17462 :         && m_eAdjust    == rCmp.GetAdj()
     403       17460 :         && m_nTopDist   == rCmp.GetTopDist()
     404       40042 :         && m_nBottomDist== rCmp.GetBottomDist();
     405             : }
     406             : 
     407         349 : SwPageDescExt::SwPageDescExt(const SwPageDesc & rPageDesc, SwDoc *const pDoc)
     408             :     : m_PageDesc(rPageDesc)
     409         349 :     , m_pDoc(pDoc)
     410             : {
     411         349 :     SetPageDesc(rPageDesc);
     412         349 : }
     413             : 
     414           0 : SwPageDescExt::SwPageDescExt(const SwPageDescExt & rSrc)
     415             :     : m_PageDesc(rSrc.m_PageDesc)
     416           0 :     , m_pDoc(rSrc.m_pDoc)
     417             : {
     418           0 :     SetPageDesc(rSrc.m_PageDesc);
     419           0 : }
     420             : 
     421         349 : SwPageDescExt::~SwPageDescExt()
     422             : {
     423         349 : }
     424             : 
     425         468 : OUString SwPageDescExt::GetName() const
     426             : {
     427         468 :     return m_PageDesc.GetName();
     428             : }
     429             : 
     430         349 : void SwPageDescExt::SetPageDesc(const SwPageDesc & rPageDesc)
     431             : {
     432         349 :     m_PageDesc = rPageDesc;
     433             : 
     434         349 :     if (m_PageDesc.GetFollow())
     435         349 :         m_sFollow = m_PageDesc.GetFollow()->GetName();
     436         349 : }
     437             : 
     438           0 : SwPageDescExt & SwPageDescExt::operator = (const SwPageDesc & rSrc)
     439             : {
     440           0 :     SetPageDesc(rSrc);
     441             : 
     442           0 :     return *this;
     443             : }
     444             : 
     445           0 : SwPageDescExt & SwPageDescExt::operator = (const SwPageDescExt & rSrc)
     446             : {
     447           0 :     SetPageDesc(rSrc.m_PageDesc);
     448             : 
     449           0 :     return *this;
     450             : }
     451             : 
     452           0 : SwPageDescExt::operator SwPageDesc() const
     453             : {
     454           0 :     SwPageDesc aResult(m_PageDesc);
     455             : 
     456           0 :     SwPageDesc * pPageDesc = m_pDoc->FindPageDesc(m_sFollow);
     457             : 
     458           0 :     if ( 0 != pPageDesc )
     459           0 :         aResult.SetFollow(pPageDesc);
     460             : 
     461           0 :     return aResult;
     462         177 : }
     463             : 
     464             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11