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

Generated by: LCOV version 1.10