Update ooo320-m1
[ooovba.git] / sw / source / core / attr / swatrset.cxx
blob2388a1ae096feaaccf58feadb846c2f6fbc7aaf1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swatrset.cxx,v $
10 * $Revision: 1.16.140.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <svtools/whiter.hxx>
37 #include <svx/colritem.hxx>
38 #include <svx/brshitem.hxx>
39 #include <svx/bolnitem.hxx>
40 #include <svx/boxitem.hxx>
41 #include <svx/xtable.hxx>
42 #include <fmtpdsc.hxx>
43 #include <pagedesc.hxx>
44 #include <charfmt.hxx>
45 #include <doc.hxx>
46 #include <node.hxx>
47 #include <paratr.hxx> // fuer SetModifyAtAttr
48 #include <cellatr.hxx> // fuer SetModifyAtAttr
49 #ifndef _CMDID_H
50 #include <cmdid.h>
51 #endif
52 #include <istyleaccess.hxx>
53 #include <numrule.hxx>
54 // --> OD 2008-03-19 #refactorlists#
55 #include <list.hxx>
56 // <--
59 SwAttrPool::SwAttrPool( SwDoc* pD )
60 : SfxItemPool( String::CreateFromAscii(
61 RTL_CONSTASCII_STRINGPARAM( "SWG" )),
62 POOLATTR_BEGIN, POOLATTR_END-1,
63 aSlotTab, aAttrTab ),
64 pDoc( pD )
66 SetVersionMap( 1, 1, 60, pVersionMap1 );
67 SetVersionMap( 2, 1, 75, pVersionMap2 );
68 SetVersionMap( 3, 1, 86, pVersionMap3 );
69 SetVersionMap( 4, 1,121, pVersionMap4 );
70 // OD 2004-01-21 #i18732# - apply new version map
71 SetVersionMap( 5, 1,130, pVersionMap5 );
72 SetVersionMap( 6, 1,136, pVersionMap6 );
75 SwAttrPool::~SwAttrPool()
79 SwAttrSet::SwAttrSet( SwAttrPool& rPool, USHORT nWh1, USHORT nWh2 )
80 : SfxItemSet( rPool, nWh1, nWh2 ), pOldSet( 0 ), pNewSet( 0 )
85 SwAttrSet::SwAttrSet( SwAttrPool& rPool, const USHORT* nWhichPairTable )
86 : SfxItemSet( rPool, nWhichPairTable ), pOldSet( 0 ), pNewSet( 0 )
91 SwAttrSet::SwAttrSet( const SwAttrSet& rSet )
92 : SfxItemSet( rSet ), pOldSet( 0 ), pNewSet( 0 )
96 SfxItemSet* SwAttrSet::Clone( BOOL bItems, SfxItemPool *pToPool ) const
98 if ( pToPool && pToPool != GetPool() )
100 SwAttrPool* pAttrPool = dynamic_cast< SwAttrPool* >(pToPool);
101 SfxItemSet* pTmpSet = 0;
102 if ( !pAttrPool )
103 pTmpSet = SfxItemSet::Clone( bItems, pToPool );
104 else
106 pTmpSet = new SwAttrSet( *pAttrPool, GetRanges() );
107 if ( bItems )
109 SfxWhichIter aIter(*pTmpSet);
110 USHORT nWhich = aIter.FirstWhich();
111 while ( nWhich )
113 const SfxPoolItem* pItem;
114 if ( SFX_ITEM_SET == GetItemState( nWhich, FALSE, &pItem ) )
115 pTmpSet->Put( *pItem, pItem->Which() );
116 nWhich = aIter.NextWhich();
120 return pTmpSet;
122 else
123 return bItems
124 ? new SwAttrSet( *this )
125 : new SwAttrSet( *GetPool(), GetRanges() );
128 int SwAttrSet::Put_BC( const SfxPoolItem& rAttr,
129 SwAttrSet* pOld, SwAttrSet* pNew )
131 pNewSet = pNew;
132 pOldSet = pOld;
133 int nRet = 0 != SfxItemSet::Put( rAttr );
134 pOldSet = pNewSet = 0;
135 return nRet;
139 int SwAttrSet::Put_BC( const SfxItemSet& rSet,
140 SwAttrSet* pOld, SwAttrSet* pNew )
142 pNewSet = pNew;
143 pOldSet = pOld;
144 int nRet = 0 != SfxItemSet::Put( rSet );
145 pOldSet = pNewSet = 0;
146 return nRet;
151 USHORT SwAttrSet::ClearItem_BC( USHORT nWhich,
152 SwAttrSet* pOld, SwAttrSet* pNew )
154 pNewSet = pNew;
155 pOldSet = pOld;
156 USHORT nRet = SfxItemSet::ClearItem( nWhich );
157 pOldSet = pNewSet = 0;
158 return nRet;
162 USHORT SwAttrSet::ClearItem_BC( USHORT nWhich1, USHORT nWhich2,
163 SwAttrSet* pOld, SwAttrSet* pNew )
165 ASSERT( nWhich1 <= nWhich2, "kein gueltiger Bereich" );
166 pNewSet = pNew;
167 pOldSet = pOld;
168 USHORT nRet = 0;
169 for( ; nWhich1 <= nWhich2; ++nWhich1 )
170 nRet = nRet + SfxItemSet::ClearItem( nWhich1 );
171 pOldSet = pNewSet = 0;
172 return nRet;
177 int SwAttrSet::Intersect_BC( const SfxItemSet& rSet,
178 SwAttrSet* pOld, SwAttrSet* pNew )
180 pNewSet = pNew;
181 pOldSet = pOld;
182 SfxItemSet::Intersect( rSet );
183 pOldSet = pNewSet = 0;
184 return pNew ? pNew->Count() : ( pOld ? pOld->Count() : 0 );
187 // Notification-Callback
188 void SwAttrSet::Changed( const SfxPoolItem& rOld,
189 const SfxPoolItem& rNew )
191 if( pOldSet )
192 pOldSet->PutChgd( rOld );
194 if( pNewSet )
195 pNewSet->PutChgd( rNew );
199 // ----------------------------------------------------------------
200 // Sonderbehandlung fuer einige Attribute
201 // Setze den Modify-Pointer (alten pDefinedIn) bei folgenden Attributen:
202 // - SwFmtDropCaps
203 // - SwFmtPageDesc
204 // (Wird beim Einfuegen in Formate/Nodes gerufen)
205 // ----------------------------------------------------------------
207 bool SwAttrSet::SetModifyAtAttr( const SwModify* pModify )
209 bool bSet = false;
211 const SfxPoolItem* pItem;
212 if( SFX_ITEM_SET == GetItemState( RES_PAGEDESC, FALSE, &pItem ) &&
213 ((SwFmtPageDesc*)pItem)->GetDefinedIn() != pModify )
215 ((SwFmtPageDesc*)pItem)->ChgDefinedIn( pModify );
216 bSet = true;
219 if( SFX_ITEM_SET == GetItemState( RES_PARATR_DROP, FALSE, &pItem ) &&
220 ((SwFmtDrop*)pItem)->GetDefinedIn() != pModify )
222 // CharFormat gesetzt und dann noch in unterschiedlichen
223 // Attribut Pools, dann muss das CharFormat kopiert werden!
224 SwCharFmt* pCharFmt;
225 if( 0 != ( pCharFmt = ((SwFmtDrop*)pItem)->GetCharFmt() )
226 && GetPool() != pCharFmt->GetAttrSet().GetPool() )
228 pCharFmt = GetDoc()->CopyCharFmt( *pCharFmt );
229 ((SwFmtDrop*)pItem)->SetCharFmt( pCharFmt );
231 ((SwFmtDrop*)pItem)->ChgDefinedIn( pModify );
232 bSet = true;
235 if( SFX_ITEM_SET == GetItemState( RES_BOXATR_FORMULA, FALSE, &pItem ) &&
236 ((SwTblBoxFormula*)pItem)->GetDefinedIn() != pModify )
238 ((SwTblBoxFormula*)pItem)->ChgDefinedIn( pModify );
239 bSet = true;
242 return bSet;
245 void SwAttrSet::CopyToModify( SwModify& rMod ) const
247 // kopiere die Attribute ggfs. ueber Dokumentgrenzen
248 SwCntntNode* pCNd = PTR_CAST( SwCntntNode, &rMod );
249 SwFmt* pFmt = PTR_CAST( SwFmt, &rMod );
251 if( pCNd || pFmt )
253 if( Count() )
255 // --> OD 2008-08-15 #i92811#
256 SfxStringItem* pNewListIdItem( 0 );
257 // <--
259 const SfxPoolItem* pItem;
260 const SwDoc *pSrcDoc = GetDoc();
261 SwDoc *pDstDoc = pCNd ? pCNd->GetDoc() : pFmt->GetDoc();
263 // muss die NumRule kopiert werden?
264 if( pSrcDoc != pDstDoc && SFX_ITEM_SET == GetItemState(
265 RES_PARATR_NUMRULE, FALSE, &pItem ) )
267 const String& rNm = ((SwNumRuleItem*)pItem)->GetValue();
268 if( rNm.Len() )
270 SwNumRule* pDestRule = pDstDoc->FindNumRulePtr( rNm );
271 if( pDestRule )
272 pDestRule->SetInvalidRule( TRUE );
273 else
274 pDstDoc->MakeNumRule( rNm,
275 pSrcDoc->FindNumRulePtr( rNm ) );
279 // --> OD 2008-03-19 #refactorlists#
280 // copy list and if needed also the corresponding list style
281 // for text nodes
282 if ( pSrcDoc != pDstDoc &&
283 pCNd && pCNd->IsTxtNode() &&
284 GetItemState( RES_PARATR_LIST_ID, FALSE, &pItem ) == SFX_ITEM_SET )
286 const String& sListId =
287 dynamic_cast<const SfxStringItem*>(pItem)->GetValue();
288 if ( sListId.Len() > 0 &&
289 !pDstDoc->getListByName( sListId ) )
291 const SwList* pList = pSrcDoc->getListByName( sListId );
292 // copy list style, if needed
293 const String sDefaultListStyleName =
294 pList->GetDefaultListStyleName();
295 // --> OD 2008-08-15 #i92811#
296 const SwNumRule* pDstDocNumRule =
297 pDstDoc->FindNumRulePtr( sDefaultListStyleName );
298 if ( !pDstDocNumRule )
300 pDstDoc->MakeNumRule( sDefaultListStyleName,
301 pSrcDoc->FindNumRulePtr( sDefaultListStyleName ) );
303 else
305 const SwNumRule* pSrcDocNumRule =
306 pSrcDoc->FindNumRulePtr( sDefaultListStyleName );
307 // If list id of text node equals the list style's
308 // default list id in the source document, the same
309 // should be hold in the destination document.
310 // Thus, create new list id item.
311 if ( sListId == pSrcDocNumRule->GetDefaultListId() )
313 pNewListIdItem = new SfxStringItem (
314 RES_PARATR_LIST_ID,
315 pDstDocNumRule->GetDefaultListId() );
318 // check again, if list exist, because <SwDoc::MakeNumRule(..)>
319 // could have also created it.
320 if ( pNewListIdItem == 0 &&
321 !pDstDoc->getListByName( sListId ) )
323 // copy list
324 pDstDoc->createList( sListId, sDefaultListStyleName );
326 // <--
329 // <--
331 // JP 04.02.99: Task #61467# Seitenvorlagenwechsel mit kopieren
332 // Gegenueber dem alten Verhalten, sie zu entfernen
333 const SwPageDesc* pPgDesc;
334 if( pSrcDoc != pDstDoc && SFX_ITEM_SET == GetItemState(
335 RES_PAGEDESC, FALSE, &pItem ) &&
336 0 != ( pPgDesc = ((SwFmtPageDesc*)pItem)->GetPageDesc()) )
338 SfxItemSet aTmpSet( *this );
340 SwPageDesc* pDstPgDesc = pDstDoc->FindPageDescByName(
341 pPgDesc->GetName() );
342 if( !pDstPgDesc )
344 // dann kopieren, ansonsten den benutzen
345 pDstPgDesc = &pDstDoc->_GetPageDesc( pDstDoc->MakePageDesc(
346 pPgDesc->GetName() ));
347 pDstDoc->CopyPageDesc( *pPgDesc, *pDstPgDesc );
349 SwFmtPageDesc aDesc( pDstPgDesc );
350 aDesc.SetNumOffset( ((SwFmtPageDesc*)pItem)->GetNumOffset() );
351 aTmpSet.Put( aDesc );
353 if( pCNd )
355 // --> OD 2008-08-15 #i92811#
356 if ( pNewListIdItem != 0 )
358 aTmpSet.Put( *pNewListIdItem );
360 // <--
361 pCNd->SetAttr( aTmpSet );
363 else
364 pFmt->SetFmtAttr( aTmpSet );
366 else if( pCNd )
368 // --> OD 2008-08-15 #i92811#
369 if ( pNewListIdItem != 0 )
371 SfxItemSet aTmpSet( *this );
372 aTmpSet.Put( *pNewListIdItem );
373 pCNd->SetAttr( aTmpSet );
375 else
377 pCNd->SetAttr( *this );
379 // <--
381 else
382 pFmt->SetFmtAttr( *this );
384 // --> OD 2008-08-15 #i92811#
385 delete pNewListIdItem;
386 pNewListIdItem = 0;
387 // <--
390 #ifndef PRODUCT
391 else
392 ASSERT( !this, "weder Format noch ContentNode - keine Attribute kopiert");
393 #endif
396 // check if ID is InRange of AttrSet-Ids
397 BOOL IsInRange( const USHORT* pRange, const USHORT nId )
399 while( *pRange )
401 if( *pRange <= nId && nId <= *(pRange+1) )
402 return TRUE;
403 pRange += 2;
405 return FALSE;