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: pagedesc.cxx,v $
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"
36 #include <hintids.hxx>
37 #include <svx/pbinitem.hxx>
38 #include <svx/ulspitem.hxx>
39 #include <svx/boxitem.hxx>
40 #include <svx/brshitem.hxx>
41 #include <svx/shaditem.hxx>
42 #include <svx/lrspitem.hxx>
43 #include "svx/frmdiritem.hxx"
44 #include <fmtclds.hxx>
45 #include <fmtfsize.hxx>
47 #include <pagefrm.hxx>
48 #include <pagedesc.hxx>
50 #include <fmtcol.hxx> // SwTxtFmtColl
52 #include <swtable.hxx>
53 #include <frmtool.hxx>
54 #include <doc.hxx> // fuer GetAttrPool
55 #include <poolfmt.hxx>
57 /*************************************************************************
59 |* SwPageDesc::SwPageDesc()
61 |* Ersterstellung MA 25. Jan. 93
62 |* Letzte Aenderung MA 16. Feb. 94
64 |*************************************************************************/
68 SwPageDesc::SwPageDesc( const String
& rName
, SwFrmFmt
*pFmt
, SwDoc
*pDc
) :
71 aMaster( pDc
->GetAttrPool(), rName
, pFmt
),
72 aLeft( pDc
->GetAttrPool(), rName
, pFmt
),
77 eUse( (UseOnPage
)(nsUseOnPage::PD_ALL
| nsUseOnPage::PD_HEADERSHARE
| nsUseOnPage::PD_FOOTERSHARE
) ),
83 SwPageDesc::SwPageDesc( const SwPageDesc
&rCpy
) :
85 aDescName( rCpy
.GetName() ),
86 aNumType( rCpy
.GetNumType() ),
87 aMaster( rCpy
.GetMaster() ),
88 aLeft( rCpy
.GetLeft() ),
89 aDepend( this, (SwModify
*)rCpy
.aDepend
.GetRegisteredIn() ),
90 pFollow( rCpy
.pFollow
),
91 nRegHeight( rCpy
.GetRegHeight() ),
92 nRegAscent( rCpy
.GetRegAscent() ),
93 eUse( rCpy
.ReadUseOn() ),
94 bLandscape( rCpy
.GetLandscape() ),
95 aFtnInfo( rCpy
.GetFtnInfo() )
99 SwPageDesc
& SwPageDesc::operator = (const SwPageDesc
& rSrc
)
101 aDescName
= rSrc
.aDescName
;
102 aNumType
= rSrc
.aNumType
;
103 aMaster
= rSrc
.aMaster
;
106 if (rSrc
.pFollow
== &rSrc
)
109 pFollow
= rSrc
.pFollow
;
111 nRegHeight
= rSrc
.nRegHeight
;
112 nRegAscent
= rSrc
.nRegAscent
;
114 bLandscape
= rSrc
.bLandscape
;
118 SwPageDesc::~SwPageDesc()
122 /*************************************************************************
124 |* SwPageDesc::Mirror()
126 |* Beschreibung Gespiegelt werden nur die Raender.
127 |* Attribute wie Umrandung und dergleichen werden 1:1 kopiert.
128 |* Ersterstellung MA 25. Jan. 93
129 |* Letzte Aenderung 01. Nov. 94
131 |*************************************************************************/
135 void SwPageDesc::Mirror()
137 //Das Spiegeln findet nur beim RandAttribut statt, alle anderen Werte
138 //werden schlicht uebertragen.
139 SvxLRSpaceItem
aLR( RES_LR_SPACE
);
140 const SvxLRSpaceItem
&rLR
= aMaster
.GetLRSpace();
141 aLR
.SetLeft( rLR
.GetRight() );
142 aLR
.SetRight( rLR
.GetLeft() );
144 SfxItemSet
aSet( *aMaster
.GetAttrSet().GetPool(),
145 aMaster
.GetAttrSet().GetRanges() );
147 aSet
.Put( aMaster
.GetFrmSize() );
148 aSet
.Put( aMaster
.GetPaperBin() );
149 aSet
.Put( aMaster
.GetULSpace() );
150 aSet
.Put( aMaster
.GetBox() );
151 aSet
.Put( aMaster
.GetBackground() );
152 aSet
.Put( aMaster
.GetShadow() );
153 aSet
.Put( aMaster
.GetCol() );
154 aSet
.Put( aMaster
.GetFrmDir() ); // #112217#
155 aLeft
.SetFmtAttr( aSet
);
158 void SwPageDesc::ResetAllAttr( sal_Bool bLeft
)
160 SwFrmFmt
& rFmt
= bLeft
? GetLeft() : GetMaster();
162 // --> OD 2007-01-25 #i73790# - method renamed
163 rFmt
.ResetAllFmtAttr();
165 rFmt
.SetFmtAttr( SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP
, RES_FRAMEDIR
) );
168 /*************************************************************************
170 |* SwPageDesc::GetInfo()
172 |* Beschreibung erfragt Informationen
173 |* Ersterstellung JP 31.03.94
174 |* Letzte Aenderung JP 31.03.94
176 *************************************************************************/
179 // erfrage vom Modify Informationen
180 BOOL
SwPageDesc::GetInfo( SfxPoolItem
& rInfo
) const
182 // if( RES_AUTOFMT_DOCNODE == rInfo.Which() )
184 // dann weiter zum Format
185 if( !aMaster
.GetInfo( rInfo
) )
186 return FALSE
; // gefunden
187 return aLeft
.GetInfo( rInfo
);
189 // return TRUE; // weiter suchen
192 /*************************************************************************
194 |* SwPageDesc::SetRegisterFmtColl()
196 |* Beschreibung setzt die Vorlage fuer die Registerhaltigkeit
197 |* Ersterstellung AMA 22.07.96
198 |* Letzte Aenderung AMA 22.07.96
200 *************************************************************************/
203 void SwPageDesc::SetRegisterFmtColl( const SwTxtFmtColl
* pFmt
)
205 if( pFmt
!= GetRegisterFmtColl() )
208 ((SwTxtFmtColl
*)pFmt
)->Add( &aDepend
);
210 ((SwTxtFmtColl
*)GetRegisterFmtColl())->Remove( &aDepend
);
216 /*************************************************************************
218 |* SwPageDesc::GetRegisterFmtColl()
220 |* Beschreibung holt die Vorlage fuer die Registerhaltigkeit
221 |* Ersterstellung AMA 22.07.96
222 |* Letzte Aenderung AMA 22.07.96
224 *************************************************************************/
227 const SwTxtFmtColl
* SwPageDesc::GetRegisterFmtColl() const
229 const SwModify
* pReg
= aDepend
.GetRegisteredIn();
230 return (SwTxtFmtColl
*)pReg
;
233 /*************************************************************************
235 |* SwPageDesc::RegisterChange()
237 |* Beschreibung benachrichtigt alle betroffenen PageFrames
238 |* Ersterstellung AMA 22.07.96
239 |* Letzte Aenderung AMA 22.07.96
241 *************************************************************************/
244 void SwPageDesc::RegisterChange()
246 // --> OD 2004-06-15 #117072# - During destruction of the document <SwDoc>
247 // the page description is modified. Thus, do nothing, if the document
248 // is in destruction respectively if no viewshell exists.
249 SwDoc
* pDoc
= GetMaster().GetDoc();
250 if ( !pDoc
|| pDoc
->IsInDtor() )
255 pDoc
->GetEditShell( &pSh
);
263 SwClientIter
aIter( GetMaster() );
264 for( SwClient
* pLast
= aIter
.First(TYPE(SwFrm
)); pLast
;
265 pLast
= aIter
.Next() )
267 if( ((SwFrm
*)pLast
)->IsPageFrm() )
268 ((SwPageFrm
*)pLast
)->PrepareRegisterChg();
272 SwClientIter
aIter( GetLeft() );
273 for( SwClient
* pLast
= aIter
.First(TYPE(SwFrm
)); pLast
;
274 pLast
= aIter
.Next() )
276 if( ((SwFrm
*)pLast
)->IsPageFrm() )
277 ((SwPageFrm
*)pLast
)->PrepareRegisterChg();
282 /*************************************************************************
284 |* SwPageDesc::Modify()
286 |* Beschreibung reagiert insbesondere auf Aenderungen
287 |* der Vorlage fuer die Registerhaltigkeit
288 |* Ersterstellung AMA 22.07.96
289 |* Letzte Aenderung AMA 22.07.96
291 *************************************************************************/
294 void SwPageDesc::Modify( SfxPoolItem
*pOld
, SfxPoolItem
*pNew
)
296 const USHORT nWhich
= pOld
? pOld
->Which() : pNew
? pNew
->Which() : 0;
297 SwModify::Modify( pOld
, pNew
);
299 if ( (RES_ATTRSET_CHG
== nWhich
) || (RES_FMT_CHG
== nWhich
)
300 || isCHRATR(nWhich
) || (RES_PARATR_LINESPACING
== nWhich
) )
306 static const SwFrm
* lcl_GetFrmOfNode( const SwNode
& rNd
)
309 USHORT nFrmType
= FRM_CNTNT
;
311 if( rNd
.IsCntntNode() )
313 pMod
= &(SwCntntNode
&)rNd
;
315 else if( rNd
.IsTableNode() )
317 pMod
= ((SwTableNode
&)rNd
).GetTable().GetFrmFmt();
324 return pMod
? ::GetFrmOfModify( *pMod
, nFrmType
, &aNullPt
, 0, FALSE
)
328 const SwPageDesc
* SwPageDesc::GetPageDescOfNode(const SwNode
& rNd
)
330 const SwPageDesc
* pRet
= 0;
331 const SwFrm
* pChkFrm
= lcl_GetFrmOfNode( rNd
);
332 if (pChkFrm
&& 0 != (pChkFrm
= pChkFrm
->FindPageFrm()))
333 pRet
= ((const SwPageFrm
*)pChkFrm
)->GetPageDesc();
337 const SwFrmFmt
* SwPageDesc::GetPageFmtOfNode( const SwNode
& rNd
,
338 BOOL bCheckForThisPgDc
) const
340 // welches PageDescFormat ist fuer diesen Node gueltig?
341 const SwFrmFmt
* pRet
;
342 const SwFrm
* pChkFrm
= lcl_GetFrmOfNode( rNd
);
344 if( pChkFrm
&& 0 != ( pChkFrm
= pChkFrm
->FindPageFrm() ))
346 const SwPageDesc
* pPd
= bCheckForThisPgDc
? this :
347 ((SwPageFrm
*)pChkFrm
)->GetPageDesc();
348 pRet
= &pPd
->GetMaster();
349 ASSERT( ((SwPageFrm
*)pChkFrm
)->GetPageDesc() == pPd
,
350 "Falcher Node fuers erkennen des Seitenformats" );
351 // an welchem Format haengt diese Seite?
352 if( pRet
!= pChkFrm
->GetRegisteredIn() )
354 pRet
= &pPd
->GetLeft();
355 ASSERT( pRet
== pChkFrm
->GetRegisteredIn(),
356 "Falcher Node fuers erkennen des Seitenformats" );
364 BOOL
SwPageDesc::IsFollowNextPageOfNode( const SwNode
& rNd
) const
367 if( GetFollow() && this != GetFollow() )
369 const SwFrm
* pChkFrm
= lcl_GetFrmOfNode( rNd
);
370 if( pChkFrm
&& 0 != ( pChkFrm
= pChkFrm
->FindPageFrm() ) &&
371 pChkFrm
->IsPageFrm() &&
372 ( !pChkFrm
->GetNext() || GetFollow() ==
373 ((SwPageFrm
*)pChkFrm
->GetNext())->GetPageDesc() ))
374 // die Seite gefunden, auf die der Follow verweist
380 /*************************************************************************
382 |* SwPageFtnInfo::SwPageFtnInfo()
384 |* Ersterstellung MA 24. Feb. 93
385 |* Letzte Aenderung MA 24. Feb. 93
387 |*************************************************************************/
391 SwPageFtnInfo::SwPageFtnInfo() :
393 // aPen( PEN_SOLID ),
396 nTopDist( 57 ), //1mm
399 eAdj
= FRMDIR_HORI_RIGHT_TOP
== GetDefaultFrameDirection(GetAppLanguage()) ?
402 // aPen.SetWidth( 10 );
407 SwPageFtnInfo::SwPageFtnInfo( const SwPageFtnInfo
&rCpy
) :
408 nMaxHeight( rCpy
.GetHeight() ),
409 nLineWidth(rCpy
.nLineWidth
),
410 aLineColor(rCpy
.aLineColor
),
411 aWidth( rCpy
.GetWidth() ),
412 eAdj( rCpy
.GetAdj() ),
413 nTopDist( rCpy
.GetTopDist() ),
414 nBottomDist( rCpy
.GetBottomDist() )
418 /*************************************************************************
420 |* SwPageFtnInfo::operator=
422 |* Ersterstellung MA 24. Feb. 93
423 |* Letzte Aenderung MA 24. Feb. 93
425 |*************************************************************************/
429 SwPageFtnInfo
&SwPageFtnInfo::operator=( const SwPageFtnInfo
& rCpy
)
431 nMaxHeight
= rCpy
.GetHeight();
432 nLineWidth
= rCpy
.nLineWidth
;
433 aLineColor
= rCpy
.aLineColor
;
434 aWidth
= rCpy
.GetWidth();
435 eAdj
= rCpy
.GetAdj();
436 nTopDist
= rCpy
.GetTopDist();
437 nBottomDist
= rCpy
.GetBottomDist();
440 /*************************************************************************
442 |* SwPageFtnInfo::operator==
444 |* Ersterstellung MA 01. Mar. 93
445 |* Letzte Aenderung MA 01. Mar. 93
447 |*************************************************************************/
451 BOOL
SwPageFtnInfo::operator==( const SwPageFtnInfo
& rCmp
) const
453 return ( nMaxHeight
== rCmp
.GetHeight() &&
454 nLineWidth
== rCmp
.nLineWidth
&&
455 aLineColor
== rCmp
.aLineColor
&&
456 aWidth
== rCmp
.GetWidth() &&
457 eAdj
== rCmp
.GetAdj() &&
458 nTopDist
== rCmp
.GetTopDist() &&
459 nBottomDist
== rCmp
.GetBottomDist() );
462 SwPageDescExt::SwPageDescExt(const SwPageDesc
& rPageDesc
, SwDoc
* _pDoc
)
463 : aPageDesc(rPageDesc
), pDoc(_pDoc
)
465 SetPageDesc(rPageDesc
);
468 SwPageDescExt::SwPageDescExt(const SwPageDescExt
& rSrc
)
469 : aPageDesc(rSrc
.aPageDesc
), pDoc(rSrc
.pDoc
)
471 SetPageDesc(rSrc
.aPageDesc
);
474 SwPageDescExt::~SwPageDescExt()
478 const String
& SwPageDescExt::GetName() const
480 return aPageDesc
.GetName();
483 void SwPageDescExt::SetPageDesc(const SwPageDesc
& _aPageDesc
)
485 aPageDesc
= _aPageDesc
;
487 if (aPageDesc
.GetFollow())
488 sFollow
= aPageDesc
.GetFollow()->GetName();
491 SwPageDescExt
& SwPageDescExt::operator = (const SwPageDesc
& rSrc
)
498 SwPageDescExt
& SwPageDescExt::operator = (const SwPageDescExt
& rSrc
)
500 SetPageDesc(rSrc
.aPageDesc
);
505 SwPageDescExt::operator SwPageDesc() const
507 SwPageDesc
aResult(aPageDesc
);
509 SwPageDesc
* pPageDesc
= pDoc
->GetPageDesc(sFollow
);
511 if ( 0 != pPageDesc
)
512 aResult
.SetFollow(pPageDesc
);