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>
47 #include <paratr.hxx> // fuer SetModifyAtAttr
48 #include <cellatr.hxx> // fuer SetModifyAtAttr
52 #include <istyleaccess.hxx>
53 #include <numrule.hxx>
54 // --> OD 2008-03-19 #refactorlists#
59 SwAttrPool::SwAttrPool( SwDoc
* pD
)
60 : SfxItemPool( String::CreateFromAscii(
61 RTL_CONSTASCII_STRINGPARAM( "SWG" )),
62 POOLATTR_BEGIN
, POOLATTR_END
-1,
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;
103 pTmpSet
= SfxItemSet::Clone( bItems
, pToPool
);
106 pTmpSet
= new SwAttrSet( *pAttrPool
, GetRanges() );
109 SfxWhichIter
aIter(*pTmpSet
);
110 USHORT nWhich
= aIter
.FirstWhich();
113 const SfxPoolItem
* pItem
;
114 if ( SFX_ITEM_SET
== GetItemState( nWhich
, FALSE
, &pItem
) )
115 pTmpSet
->Put( *pItem
, pItem
->Which() );
116 nWhich
= aIter
.NextWhich();
124 ? new SwAttrSet( *this )
125 : new SwAttrSet( *GetPool(), GetRanges() );
128 int SwAttrSet::Put_BC( const SfxPoolItem
& rAttr
,
129 SwAttrSet
* pOld
, SwAttrSet
* pNew
)
133 int nRet
= 0 != SfxItemSet::Put( rAttr
);
134 pOldSet
= pNewSet
= 0;
139 int SwAttrSet::Put_BC( const SfxItemSet
& rSet
,
140 SwAttrSet
* pOld
, SwAttrSet
* pNew
)
144 int nRet
= 0 != SfxItemSet::Put( rSet
);
145 pOldSet
= pNewSet
= 0;
151 USHORT
SwAttrSet::ClearItem_BC( USHORT nWhich
,
152 SwAttrSet
* pOld
, SwAttrSet
* pNew
)
156 USHORT nRet
= SfxItemSet::ClearItem( nWhich
);
157 pOldSet
= pNewSet
= 0;
162 USHORT
SwAttrSet::ClearItem_BC( USHORT nWhich1
, USHORT nWhich2
,
163 SwAttrSet
* pOld
, SwAttrSet
* pNew
)
165 ASSERT( nWhich1
<= nWhich2
, "kein gueltiger Bereich" );
169 for( ; nWhich1
<= nWhich2
; ++nWhich1
)
170 nRet
= nRet
+ SfxItemSet::ClearItem( nWhich1
);
171 pOldSet
= pNewSet
= 0;
177 int SwAttrSet::Intersect_BC( const SfxItemSet
& rSet
,
178 SwAttrSet
* pOld
, SwAttrSet
* pNew
)
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
)
192 pOldSet
->PutChgd( rOld
);
195 pNewSet
->PutChgd( rNew
);
199 // ----------------------------------------------------------------
200 // Sonderbehandlung fuer einige Attribute
201 // Setze den Modify-Pointer (alten pDefinedIn) bei folgenden Attributen:
204 // (Wird beim Einfuegen in Formate/Nodes gerufen)
205 // ----------------------------------------------------------------
207 bool SwAttrSet::SetModifyAtAttr( const SwModify
* pModify
)
211 const SfxPoolItem
* pItem
;
212 if( SFX_ITEM_SET
== GetItemState( RES_PAGEDESC
, FALSE
, &pItem
) &&
213 ((SwFmtPageDesc
*)pItem
)->GetDefinedIn() != pModify
)
215 ((SwFmtPageDesc
*)pItem
)->ChgDefinedIn( pModify
);
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!
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
);
235 if( SFX_ITEM_SET
== GetItemState( RES_BOXATR_FORMULA
, FALSE
, &pItem
) &&
236 ((SwTblBoxFormula
*)pItem
)->GetDefinedIn() != pModify
)
238 ((SwTblBoxFormula
*)pItem
)->ChgDefinedIn( pModify
);
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
);
255 // --> OD 2008-08-15 #i92811#
256 SfxStringItem
* pNewListIdItem( 0 );
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();
270 SwNumRule
* pDestRule
= pDstDoc
->FindNumRulePtr( rNm
);
272 pDestRule
->SetInvalidRule( TRUE
);
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
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
) );
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 (
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
) )
324 pDstDoc
->createList( sListId
, sDefaultListStyleName
);
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() );
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
);
355 // --> OD 2008-08-15 #i92811#
356 if ( pNewListIdItem
!= 0 )
358 aTmpSet
.Put( *pNewListIdItem
);
361 pCNd
->SetAttr( aTmpSet
);
364 pFmt
->SetFmtAttr( aTmpSet
);
368 // --> OD 2008-08-15 #i92811#
369 if ( pNewListIdItem
!= 0 )
371 SfxItemSet
aTmpSet( *this );
372 aTmpSet
.Put( *pNewListIdItem
);
373 pCNd
->SetAttr( aTmpSet
);
377 pCNd
->SetAttr( *this );
382 pFmt
->SetFmtAttr( *this );
384 // --> OD 2008-08-15 #i92811#
385 delete pNewListIdItem
;
392 ASSERT( !this, "weder Format noch ContentNode - keine Attribute kopiert");
396 // check if ID is InRange of AttrSet-Ids
397 BOOL
IsInRange( const USHORT
* pRange
, const USHORT nId
)
401 if( *pRange
<= nId
&& nId
<= *(pRange
+1) )