LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/attr - swatrset.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 91 162 56.2 %
Date: 2012-12-27 Functions: 15 16 93.8 %
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 <cellatr.hxx>
      21             : #include <charfmt.hxx>
      22             : #include <cmdid.h>
      23             : #include <doc.hxx>
      24             : #include <editeng/colritem.hxx>
      25             : #include <editeng/brshitem.hxx>
      26             : #include <editeng/bolnitem.hxx>
      27             : #include <editeng/boxitem.hxx>
      28             : #include <fmtpdsc.hxx>
      29             : #include <hintids.hxx>
      30             : #include <istyleaccess.hxx>
      31             : #include <list.hxx>
      32             : #include <node.hxx>
      33             : #include <numrule.hxx>
      34             : #include <pagedesc.hxx>
      35             : #include <paratr.hxx>
      36             : #include <svl/whiter.hxx>
      37             : #include <svx/xtable.hxx>
      38             : 
      39             : // ----------
      40             : // SwAttrPool
      41             : // ----------
      42             : 
      43         286 : SwAttrPool::SwAttrPool( SwDoc* pD )
      44             :     : SfxItemPool( rtl::OUString("SWG"),
      45             :                     POOLATTR_BEGIN, POOLATTR_END-1,
      46             :                     aSlotTab, aAttrTab ),
      47         286 :     pDoc( pD )
      48             : {
      49         286 :     SetVersionMap( 1, 1, 60, pVersionMap1 );
      50         286 :     SetVersionMap( 2, 1, 75, pVersionMap2 );
      51         286 :     SetVersionMap( 3, 1, 86, pVersionMap3 );
      52         286 :     SetVersionMap( 4, 1,121, pVersionMap4 );
      53             :     // #i18732# - apply new version map
      54         286 :     SetVersionMap( 5, 1,130, pVersionMap5 );
      55         286 :     SetVersionMap( 6, 1,136, pVersionMap6 );
      56         286 : }
      57             : 
      58         224 : SwAttrPool::~SwAttrPool()
      59             : {
      60         224 : }
      61             : 
      62             : // ---------
      63             : // SwAttrSet
      64             : // ---------
      65             : 
      66           0 : SwAttrSet::SwAttrSet( SwAttrPool& rPool, sal_uInt16 nWh1, sal_uInt16 nWh2 )
      67           0 :     : SfxItemSet( rPool, nWh1, nWh2 ), pOldSet( 0 ), pNewSet( 0 )
      68             : {
      69           0 : }
      70             : 
      71      151140 : SwAttrSet::SwAttrSet( SwAttrPool& rPool, const sal_uInt16* nWhichPairTable )
      72      151140 :     : SfxItemSet( rPool, nWhichPairTable ), pOldSet( 0 ), pNewSet( 0 )
      73             : {
      74      151140 : }
      75             : 
      76       83405 : SwAttrSet::SwAttrSet( const SwAttrSet& rSet )
      77       83405 :     : SfxItemSet( rSet ), pOldSet( 0 ), pNewSet( 0 )
      78             : {
      79       83405 : }
      80             : 
      81        2033 : SfxItemSet* SwAttrSet::Clone( sal_Bool bItems, SfxItemPool *pToPool ) const
      82             : {
      83        2033 :     if ( pToPool && pToPool != GetPool() )
      84             :     {
      85           0 :         SwAttrPool* pAttrPool = dynamic_cast< SwAttrPool* >(pToPool);
      86           0 :         SfxItemSet* pTmpSet = 0;
      87           0 :         if ( !pAttrPool )
      88           0 :             pTmpSet = SfxItemSet::Clone( bItems, pToPool );
      89             :         else
      90             :         {
      91           0 :             pTmpSet = new SwAttrSet( *pAttrPool, GetRanges() );
      92           0 :             if ( bItems )
      93             :             {
      94           0 :                 SfxWhichIter aIter(*pTmpSet);
      95           0 :                 sal_uInt16 nWhich = aIter.FirstWhich();
      96           0 :                 while ( nWhich )
      97             :                 {
      98             :                     const SfxPoolItem* pItem;
      99           0 :                     if ( SFX_ITEM_SET == GetItemState( nWhich, sal_False, &pItem ) )
     100           0 :                         pTmpSet->Put( *pItem, pItem->Which() );
     101           0 :                     nWhich = aIter.NextWhich();
     102           0 :                 }
     103             :             }
     104             :         }
     105           0 :         return pTmpSet;
     106             :     }
     107             :     else
     108             :         return bItems
     109        2033 :                 ? new SwAttrSet( *this )
     110        4066 :                 : new SwAttrSet( *GetPool(), GetRanges() );
     111             : }
     112             : 
     113       30285 : int SwAttrSet::Put_BC( const SfxPoolItem& rAttr,
     114             :                        SwAttrSet* pOld, SwAttrSet* pNew )
     115             : {
     116       30285 :     pNewSet = pNew;
     117       30285 :     pOldSet = pOld;
     118       30285 :     int nRet = 0 != SfxItemSet::Put( rAttr );
     119       30285 :     pOldSet = pNewSet = 0;
     120       30285 :     return nRet;
     121             : }
     122             : 
     123             : 
     124        9165 : int SwAttrSet::Put_BC( const SfxItemSet& rSet,
     125             :                        SwAttrSet* pOld, SwAttrSet* pNew )
     126             : {
     127        9165 :     pNewSet = pNew;
     128        9165 :     pOldSet = pOld;
     129        9165 :     int nRet = 0 != SfxItemSet::Put( rSet );
     130        9165 :     pOldSet = pNewSet = 0;
     131        9165 :     return nRet;
     132             : }
     133             : 
     134        3387 : sal_uInt16 SwAttrSet::ClearItem_BC( sal_uInt16 nWhich,
     135             :                                     SwAttrSet* pOld, SwAttrSet* pNew )
     136             : {
     137        3387 :     pNewSet = pNew;
     138        3387 :     pOldSet = pOld;
     139        3387 :     sal_uInt16 nRet = SfxItemSet::ClearItem( nWhich );
     140        3387 :     pOldSet = pNewSet = 0;
     141        3387 :     return nRet;
     142             : }
     143             : 
     144       23361 : sal_uInt16 SwAttrSet::ClearItem_BC( sal_uInt16 nWhich1, sal_uInt16 nWhich2,
     145             :                                     SwAttrSet* pOld, SwAttrSet* pNew )
     146             : {
     147             :     OSL_ENSURE( nWhich1 <= nWhich2, "no valid range" );
     148       23361 :     pNewSet = pNew;
     149       23361 :     pOldSet = pOld;
     150       23361 :     sal_uInt16 nRet = 0;
     151       47449 :     for( ; nWhich1 <= nWhich2; ++nWhich1 )
     152       24088 :         nRet = nRet + SfxItemSet::ClearItem( nWhich1 );
     153       23361 :     pOldSet = pNewSet = 0;
     154       23361 :     return nRet;
     155             : }
     156             : 
     157        1659 : int SwAttrSet::Intersect_BC( const SfxItemSet& rSet,
     158             :                              SwAttrSet* pOld, SwAttrSet* pNew )
     159             : {
     160        1659 :     pNewSet = pNew;
     161        1659 :     pOldSet = pOld;
     162        1659 :     SfxItemSet::Intersect( rSet );
     163        1659 :     pOldSet = pNewSet = 0;
     164        1659 :     return pNew ? pNew->Count() : ( pOld ? pOld->Count() : 0 );
     165             : }
     166             : 
     167             : /// Notification callback
     168       92417 : void  SwAttrSet::Changed( const SfxPoolItem& rOld, const SfxPoolItem& rNew )
     169             : {
     170       92417 :     if( pOldSet )
     171       36848 :         pOldSet->PutChgd( rOld );
     172       92417 :     if( pNewSet )
     173       36848 :         pNewSet->PutChgd( rNew );
     174       92417 : }
     175             : 
     176             : /** special treatment for some attributes
     177             : 
     178             :     Set the Modify pointer (old pDefinedIn) for the following attributes:
     179             :      - SwFmtDropCaps
     180             :      - SwFmtPageDesc
     181             : 
     182             :     (Is called at inserts into formats/nodes)
     183             : */
     184       45871 : bool SwAttrSet::SetModifyAtAttr( const SwModify* pModify )
     185             : {
     186       45871 :     bool bSet = false;
     187             : 
     188             :     const SfxPoolItem* pItem;
     189       47206 :     if( SFX_ITEM_SET == GetItemState( RES_PAGEDESC, sal_False, &pItem ) &&
     190        1335 :         ((SwFmtPageDesc*)pItem)->GetDefinedIn() != pModify  )
     191             :     {
     192        1335 :         ((SwFmtPageDesc*)pItem)->ChgDefinedIn( pModify );
     193        1335 :         bSet = true;
     194             :     }
     195             : 
     196       45871 :     if( SFX_ITEM_SET == GetItemState( RES_PARATR_DROP, sal_False, &pItem ) &&
     197           0 :         ((SwFmtDrop*)pItem)->GetDefinedIn() != pModify )
     198             :     {
     199             :         // If CharFormat is set and it is set in different attribute pools then
     200             :         // the CharFormat has to be copied.
     201             :         SwCharFmt* pCharFmt;
     202           0 :         if( 0 != ( pCharFmt = ((SwFmtDrop*)pItem)->GetCharFmt() )
     203           0 :             && GetPool() != pCharFmt->GetAttrSet().GetPool() )
     204             :         {
     205           0 :            pCharFmt = GetDoc()->CopyCharFmt( *pCharFmt );
     206           0 :            ((SwFmtDrop*)pItem)->SetCharFmt( pCharFmt );
     207             :         }
     208           0 :         ((SwFmtDrop*)pItem)->ChgDefinedIn( pModify );
     209           0 :         bSet = true;
     210             :     }
     211             : 
     212       45871 :     if( SFX_ITEM_SET == GetItemState( RES_BOXATR_FORMULA, sal_False, &pItem ) &&
     213           0 :         ((SwTblBoxFormula*)pItem)->GetDefinedIn() != pModify )
     214             :     {
     215           0 :         ((SwTblBoxFormula*)pItem)->ChgDefinedIn( pModify );
     216           0 :         bSet = true;
     217             :     }
     218             : 
     219       45871 :     return bSet;
     220             : }
     221             : 
     222          50 : void SwAttrSet::CopyToModify( SwModify& rMod ) const
     223             : {
     224             :     // copy attributes across multiple documents if needed
     225          50 :     SwCntntNode* pCNd = PTR_CAST( SwCntntNode, &rMod );
     226          50 :     SwFmt* pFmt = PTR_CAST( SwFmt, &rMod );
     227             : 
     228          50 :     if( pCNd || pFmt )
     229             :     {
     230          50 :         if( Count() )
     231             :         {
     232             :             // #i92811#
     233          50 :             SfxStringItem* pNewListIdItem( 0 );
     234             : 
     235             :             const SfxPoolItem* pItem;
     236          50 :             const SwDoc *pSrcDoc = GetDoc();
     237          50 :             SwDoc *pDstDoc = pCNd ? pCNd->GetDoc() : pFmt->GetDoc();
     238             : 
     239             :             // Does the NumRule has to be copied?
     240          50 :             if( pSrcDoc != pDstDoc &&
     241           0 :                 SFX_ITEM_SET == GetItemState( RES_PARATR_NUMRULE, sal_False, &pItem ) )
     242             :             {
     243           0 :                 const String& rNm = ((SwNumRuleItem*)pItem)->GetValue();
     244           0 :                 if( rNm.Len() )
     245             :                 {
     246           0 :                     SwNumRule* pDestRule = pDstDoc->FindNumRulePtr( rNm );
     247           0 :                     if( pDestRule )
     248           0 :                         pDestRule->SetInvalidRule( sal_True );
     249             :                     else
     250           0 :                         pDstDoc->MakeNumRule( rNm, pSrcDoc->FindNumRulePtr( rNm ) );
     251             :                 }
     252             :             }
     253             : 
     254             :             // copy list and if needed also the corresponding list style
     255             :             // for text nodes
     256          50 :             if ( pSrcDoc != pDstDoc &&
     257           0 :                  pCNd && pCNd->IsTxtNode() &&
     258           0 :                  GetItemState( RES_PARATR_LIST_ID, sal_False, &pItem ) == SFX_ITEM_SET )
     259             :             {
     260             :                 const String& sListId =
     261           0 :                         dynamic_cast<const SfxStringItem*>(pItem)->GetValue();
     262           0 :                 if ( sListId.Len() > 0 &&
     263           0 :                      !pDstDoc->getListByName( sListId ) )
     264             :                 {
     265           0 :                     const SwList* pList = pSrcDoc->getListByName( sListId );
     266             :                     // copy list style, if needed
     267             :                     const String sDefaultListStyleName =
     268           0 :                                             pList->GetDefaultListStyleName();
     269             :                     // #i92811#
     270             :                     const SwNumRule* pDstDocNumRule =
     271           0 :                                 pDstDoc->FindNumRulePtr( sDefaultListStyleName );
     272           0 :                     if ( !pDstDocNumRule )
     273             :                     {
     274             :                         pDstDoc->MakeNumRule( sDefaultListStyleName,
     275           0 :                                               pSrcDoc->FindNumRulePtr( sDefaultListStyleName ) );
     276             :                     }
     277             :                     else
     278             :                     {
     279             :                         const SwNumRule* pSrcDocNumRule =
     280           0 :                                 pSrcDoc->FindNumRulePtr( sDefaultListStyleName );
     281             :                         // If list id of text node equals the list style's
     282             :                         // default list id in the source document, the same
     283             :                         // should be hold in the destination document.
     284             :                         // Thus, create new list id item.
     285           0 :                         if ( sListId == pSrcDocNumRule->GetDefaultListId() )
     286             :                         {
     287             :                             pNewListIdItem = new SfxStringItem (
     288             :                                             RES_PARATR_LIST_ID,
     289           0 :                                             pDstDocNumRule->GetDefaultListId() );
     290             :                         }
     291             :                     }
     292             :                     // check again, if list exist, because <SwDoc::MakeNumRule(..)>
     293             :                     // could have also created it.
     294           0 :                     if ( pNewListIdItem == 0 &&
     295           0 :                          !pDstDoc->getListByName( sListId ) )
     296             :                     {
     297             :                         // copy list
     298           0 :                         pDstDoc->createList( sListId, sDefaultListStyleName );
     299           0 :                     }
     300             :                 }
     301             :             }
     302             : 
     303             :             const SwPageDesc* pPgDesc;
     304          50 :             if( pSrcDoc != pDstDoc && SFX_ITEM_SET == GetItemState(
     305           0 :                                             RES_PAGEDESC, sal_False, &pItem ) &&
     306           0 :                 0 != ( pPgDesc = ((SwFmtPageDesc*)pItem)->GetPageDesc()) )
     307             :             {
     308           0 :                 SfxItemSet aTmpSet( *this );
     309             : 
     310             :                 SwPageDesc* pDstPgDesc = pDstDoc->FindPageDescByName(
     311           0 :                                                     pPgDesc->GetName() );
     312           0 :                 if( !pDstPgDesc )
     313             :                 {
     314             :                     pDstPgDesc = &pDstDoc->GetPageDesc(
     315           0 :                                    pDstDoc->MakePageDesc( pPgDesc->GetName() ));
     316           0 :                     pDstDoc->CopyPageDesc( *pPgDesc, *pDstPgDesc );
     317             :                 }
     318           0 :                 SwFmtPageDesc aDesc( pDstPgDesc );
     319           0 :                 aDesc.SetNumOffset( ((SwFmtPageDesc*)pItem)->GetNumOffset() );
     320           0 :                 aTmpSet.Put( aDesc );
     321             : 
     322           0 :                 if( pCNd )
     323             :                 {
     324             :                     // #i92811#
     325           0 :                     if ( pNewListIdItem != 0 )
     326             :                     {
     327           0 :                         aTmpSet.Put( *pNewListIdItem );
     328             :                     }
     329           0 :                     pCNd->SetAttr( aTmpSet );
     330             :                 }
     331             :                 else
     332             :                 {
     333           0 :                     pFmt->SetFmtAttr( aTmpSet );
     334           0 :                 }
     335             :             }
     336          50 :             else if( pCNd )
     337             :             {
     338             :                 // #i92811#
     339          50 :                 if ( pNewListIdItem != 0 )
     340             :                 {
     341           0 :                     SfxItemSet aTmpSet( *this );
     342           0 :                     aTmpSet.Put( *pNewListIdItem );
     343           0 :                     pCNd->SetAttr( aTmpSet );
     344             :                 }
     345             :                 else
     346             :                 {
     347          50 :                     pCNd->SetAttr( *this );
     348             :                 }
     349             :             }
     350             :             else
     351             :             {
     352           0 :                 pFmt->SetFmtAttr( *this );
     353             :             }
     354             : 
     355             :             // #i92811#
     356          50 :             delete pNewListIdItem;
     357          50 :             pNewListIdItem = 0;
     358             :         }
     359             :     }
     360             : #if OSL_DEBUG_LEVEL > 0
     361             :     else
     362             :         OSL_FAIL("neither Format nor ContentNode - no Attributes copied");
     363             : #endif
     364          50 : }
     365             : 
     366             : /// check if ID is in range of attribute set IDs
     367         575 : bool IsInRange( const sal_uInt16* pRange, const sal_uInt16 nId )
     368             : {
     369        2264 :     while( *pRange )
     370             :     {
     371        1132 :         if( *pRange <= nId && nId <= *(pRange+1) )
     372          18 :             return true;
     373        1114 :         pRange += 2;
     374             :     }
     375         557 :     return false;
     376             : }
     377             : 
     378             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10