xref: /aoo41x/main/sw/source/core/layout/pagedesc.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 
33 #include <hintids.hxx>
34 #include <editeng/pbinitem.hxx>
35 #include <editeng/ulspitem.hxx>
36 #include <editeng/boxitem.hxx>
37 #include <editeng/brshitem.hxx>
38 #include <editeng/shaditem.hxx>
39 #include <editeng/lrspitem.hxx>
40 #include "editeng/frmdiritem.hxx"
41 #include <fmtclds.hxx>
42 #include <fmtfsize.hxx>
43 #include <frmatr.hxx>
44 #include <pagefrm.hxx>
45 #include <pagedesc.hxx>
46 #include <frmfmt.hxx>
47 #include <fmtcol.hxx>	// SwTxtFmtColl
48 #include <node.hxx>
49 #include <swtable.hxx>
50 #include <frmtool.hxx>
51 #include <doc.hxx>			// fuer GetAttrPool
52 #include <poolfmt.hxx>
53 #include <switerator.hxx>
54 
55 /*************************************************************************
56 |*
57 |*	SwPageDesc::SwPageDesc()
58 |*
59 |*	Ersterstellung		MA 25. Jan. 93
60 |*	Letzte Aenderung	MA 16. Feb. 94
61 |*
62 |*************************************************************************/
63 
64 
65 
66 SwPageDesc::SwPageDesc( const String& rName, SwFrmFmt *pFmt, SwDoc *pDc ) :
67 	SwModify( 0 ),
68 	aDescName( rName ),
69     aMaster( pDc->GetAttrPool(), rName, pFmt ),
70     aLeft( pDc->GetAttrPool(), rName, pFmt ),
71     aDepend( this, 0 ),
72     pFollow( this ),
73     nRegHeight( 0 ),
74 	nRegAscent( 0 ),
75     eUse( (UseOnPage)(nsUseOnPage::PD_ALL | nsUseOnPage::PD_HEADERSHARE | nsUseOnPage::PD_FOOTERSHARE) ),
76     bLandscape( sal_False ),
77     aFtnInfo()
78 {
79 }
80 
81 SwPageDesc::SwPageDesc( const SwPageDesc &rCpy ) :
82 	SwModify( 0 ),
83     aDescName( rCpy.GetName() ),
84     aNumType( rCpy.GetNumType() ),
85     aMaster( rCpy.GetMaster() ),
86     aLeft( rCpy.GetLeft() ),
87     aDepend( this, (SwModify*)rCpy.aDepend.GetRegisteredIn() ),
88     pFollow( rCpy.pFollow ),
89     nRegHeight( rCpy.GetRegHeight() ),
90 	nRegAscent( rCpy.GetRegAscent() ),
91     eUse( rCpy.ReadUseOn() ),
92     bLandscape( rCpy.GetLandscape() ),
93     aFtnInfo( rCpy.GetFtnInfo() )
94 {
95 }
96 
97 SwPageDesc & SwPageDesc::operator = (const SwPageDesc & rSrc)
98 {
99     aDescName = rSrc.aDescName;
100     aNumType = rSrc.aNumType;
101     aMaster = rSrc.aMaster;
102     aLeft = rSrc.aLeft;
103 
104     if (rSrc.pFollow == &rSrc)
105         pFollow = this;
106     else
107         pFollow = rSrc.pFollow;
108 
109     nRegHeight = rSrc.nRegHeight;
110     nRegAscent = rSrc.nRegAscent;
111     eUse = rSrc.eUse;
112     bLandscape = rSrc.bLandscape;
113 	return *this;
114 }
115 
116 SwPageDesc::~SwPageDesc()
117 {
118 }
119 
120 /*************************************************************************
121 |*
122 |*	SwPageDesc::Mirror()
123 |*
124 |* 	Beschreibung		Gespiegelt werden nur die Raender.
125 |* 		Attribute wie Umrandung und dergleichen werden 1:1 kopiert.
126 |*	Ersterstellung		MA 25. Jan. 93
127 |*	Letzte Aenderung	01. Nov. 94
128 |*
129 |*************************************************************************/
130 
131 
132 
133 void SwPageDesc::Mirror()
134 {
135 	//Das Spiegeln findet nur beim RandAttribut statt, alle anderen Werte
136 	//werden schlicht uebertragen.
137     SvxLRSpaceItem aLR( RES_LR_SPACE );
138 	const SvxLRSpaceItem &rLR = aMaster.GetLRSpace();
139 	aLR.SetLeft(  rLR.GetRight() );
140 	aLR.SetRight( rLR.GetLeft() );
141 
142 	SfxItemSet aSet( *aMaster.GetAttrSet().GetPool(),
143 					 aMaster.GetAttrSet().GetRanges() );
144 	aSet.Put( aLR );
145 	aSet.Put( aMaster.GetFrmSize() );
146 	aSet.Put( aMaster.GetPaperBin() );
147 	aSet.Put( aMaster.GetULSpace() );
148 	aSet.Put( aMaster.GetBox() );
149 	aSet.Put( aMaster.GetBackground() );
150 	aSet.Put( aMaster.GetShadow() );
151 	aSet.Put( aMaster.GetCol() );
152 	aSet.Put( aMaster.GetFrmDir() );    // #112217#
153     aLeft.SetFmtAttr( aSet );
154 }
155 
156 void SwPageDesc::ResetAllAttr( sal_Bool bLeft )
157 {
158 	SwFrmFmt& rFmt = bLeft ? GetLeft() : GetMaster();
159 
160     // --> OD 2007-01-25 #i73790# - method renamed
161     rFmt.ResetAllFmtAttr();
162     // <--
163     rFmt.SetFmtAttr( SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP, RES_FRAMEDIR) );
164 }
165 
166 /*************************************************************************
167 |*
168 |*                SwPageDesc::GetInfo()
169 |*
170 |*    Beschreibung      erfragt Informationen
171 |*    Ersterstellung    JP 31.03.94
172 |*    Letzte Aenderung	JP 31.03.94
173 |*
174 *************************************************************************/
175 
176 
177 	// erfrage vom Modify Informationen
178 sal_Bool SwPageDesc::GetInfo( SfxPoolItem & rInfo ) const
179 {
180 //    if( RES_AUTOFMT_DOCNODE == rInfo.Which() )
181 //    {
182 		// dann weiter zum Format
183 		if( !aMaster.GetInfo( rInfo ) )
184 			return sal_False;		// gefunden
185 		return aLeft.GetInfo( rInfo );
186 //    }
187 //    return sal_True;        // weiter suchen
188 }
189 
190 /*************************************************************************
191 |*
192 |*                SwPageDesc::SetRegisterFmtColl()
193 |*
194 |*    Beschreibung      setzt die Vorlage fuer die Registerhaltigkeit
195 |*    Ersterstellung    AMA 22.07.96
196 |*    Letzte Aenderung	AMA 22.07.96
197 |*
198 *************************************************************************/
199 
200 
201 void SwPageDesc::SetRegisterFmtColl( const SwTxtFmtColl* pFmt )
202 {
203 	if( pFmt != GetRegisterFmtColl() )
204 	{
205 		if( pFmt )
206 			((SwTxtFmtColl*)pFmt)->Add( &aDepend );
207 		else
208 			((SwTxtFmtColl*)GetRegisterFmtColl())->Remove( &aDepend );
209 
210 		RegisterChange();
211 	}
212 }
213 
214 /*************************************************************************
215 |*
216 |*                SwPageDesc::GetRegisterFmtColl()
217 |*
218 |*    Beschreibung      holt die Vorlage fuer die Registerhaltigkeit
219 |*    Ersterstellung    AMA 22.07.96
220 |*    Letzte Aenderung	AMA 22.07.96
221 |*
222 *************************************************************************/
223 
224 
225 const SwTxtFmtColl* SwPageDesc::GetRegisterFmtColl() const
226 {
227 	const SwModify* pReg = aDepend.GetRegisteredIn();
228 	return (SwTxtFmtColl*)pReg;
229 }
230 
231 /*************************************************************************
232 |*
233 |*                SwPageDesc::RegisterChange()
234 |*
235 |*    Beschreibung      benachrichtigt alle betroffenen PageFrames
236 |*    Ersterstellung    AMA 22.07.96
237 |*    Letzte Aenderung	AMA 22.07.96
238 |*
239 *************************************************************************/
240 
241 
242 void SwPageDesc::RegisterChange()
243 {
244     // --> OD 2004-06-15 #117072# - During destruction of the document <SwDoc>
245     // the page description is modified. Thus, do nothing, if the document
246     // is in destruction respectively if no viewshell exists.
247     SwDoc* pDoc = GetMaster().GetDoc();
248     if ( !pDoc || pDoc->IsInDtor() )
249     {
250         return;
251     }
252     ViewShell* pSh = 0L;
253     pDoc->GetEditShell( &pSh );
254     if ( !pSh )
255     {
256         return;
257     }
258 
259     nRegHeight = 0;
260 	{
261 		SwIterator<SwFrm,SwFmt> aIter( GetMaster() );
262 		for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
263 		{
264 			if( pLast->IsPageFrm() )
265 				((SwPageFrm*)pLast)->PrepareRegisterChg();
266 		}
267 	}
268 	{
269 		SwIterator<SwFrm,SwFmt> aIter( GetLeft() );
270 		for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
271 		{
272 			if( pLast->IsPageFrm() )
273 				((SwPageFrm*)pLast)->PrepareRegisterChg();
274 		}
275 	}
276 }
277 
278 /*************************************************************************
279 |*
280 |*                SwPageDesc::Modify()
281 |*
282 |*    Beschreibung      reagiert insbesondere auf Aenderungen
283 |* 	                    der Vorlage fuer die Registerhaltigkeit
284 |*    Ersterstellung    AMA 22.07.96
285 |*    Letzte Aenderung	AMA 22.07.96
286 |*
287 *************************************************************************/
288 
289 
290 void SwPageDesc::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
291 {
292 	const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
293 	NotifyClients( pOld, pNew );
294 
295     if ( (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich)
296         || isCHRATR(nWhich) || (RES_PARATR_LINESPACING == nWhich) )
297     {
298         RegisterChange();
299     }
300 }
301 
302 static const SwFrm* lcl_GetFrmOfNode( const SwNode& rNd )
303 {
304 	SwModify* pMod;
305     sal_uInt16 nFrmType = FRM_CNTNT;
306 
307 	if( rNd.IsCntntNode() )
308 	{
309 		pMod = &(SwCntntNode&)rNd;
310     }
311 	else if( rNd.IsTableNode() )
312 	{
313 		pMod = ((SwTableNode&)rNd).GetTable().GetFrmFmt();
314 		nFrmType = FRM_TAB;
315 	}
316 	else
317 		pMod = 0;
318 
319 	Point aNullPt;
320 	return pMod ? ::GetFrmOfModify( 0, *pMod, nFrmType, &aNullPt, 0, sal_False )
321 				: 0;
322 }
323 
324 const SwPageDesc* SwPageDesc::GetPageDescOfNode(const SwNode& rNd)
325 {
326 	const SwPageDesc* pRet = 0;
327 	const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
328 	if (pChkFrm && 0 != (pChkFrm = pChkFrm->FindPageFrm()))
329 		pRet = ((const SwPageFrm*)pChkFrm)->GetPageDesc();
330 	return pRet;
331 }
332 
333 const SwFrmFmt* SwPageDesc::GetPageFmtOfNode( const SwNode& rNd,
334 											  sal_Bool bCheckForThisPgDc ) const
335 {
336 	// welches PageDescFormat ist fuer diesen Node gueltig?
337 	const SwFrmFmt* pRet;
338 	const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
339 
340 	if( pChkFrm && 0 != ( pChkFrm = pChkFrm->FindPageFrm() ))
341 	{
342 		const SwPageDesc* pPd = bCheckForThisPgDc ? this :
343 								((SwPageFrm*)pChkFrm)->GetPageDesc();
344 		pRet = &pPd->GetMaster();
345 		ASSERT( ((SwPageFrm*)pChkFrm)->GetPageDesc() == pPd, "Wrong node for detection of page format!" );
346 		// an welchem Format haengt diese Seite?
347         if( !pChkFrm->KnowsFormat(*pRet) )
348 		{
349 			pRet = &pPd->GetLeft();
350 			ASSERT( pChkFrm->KnowsFormat(*pRet), "Wrong node for detection of page format!" );
351 		}
352 	}
353 	else
354 		pRet = &GetMaster();
355 	return pRet;
356 }
357 
358 sal_Bool SwPageDesc::IsFollowNextPageOfNode( const SwNode& rNd ) const
359 {
360 	sal_Bool bRet = sal_False;
361 	if( GetFollow() && this != GetFollow() )
362 	{
363 		const SwFrm* pChkFrm = lcl_GetFrmOfNode( rNd );
364 		if( pChkFrm && 0 != ( pChkFrm = pChkFrm->FindPageFrm() ) &&
365 			pChkFrm->IsPageFrm() &&
366 			( !pChkFrm->GetNext() || GetFollow() ==
367 						((SwPageFrm*)pChkFrm->GetNext())->GetPageDesc() ))
368 			// die Seite gefunden, auf die der Follow verweist
369 			bRet = sal_True;
370 	}
371 	return bRet;
372 }
373 
374 /*************************************************************************
375 |*
376 |*	SwPageFtnInfo::SwPageFtnInfo()
377 |*
378 |*	Ersterstellung		MA 24. Feb. 93
379 |*	Letzte Aenderung	MA 24. Feb. 93
380 |*
381 |*************************************************************************/
382 
383 
384 
385 SwPageFtnInfo::SwPageFtnInfo() :
386 	nMaxHeight( 0 ),
387 //	aPen( PEN_SOLID ),
388 	nLineWidth(10),
389 	aWidth( 25, 100 ),
390     nTopDist( 57 ),         //1mm
391 	nBottomDist( 57 )
392 {
393     eAdj = FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) ?
394            FTNADJ_RIGHT :
395            FTNADJ_LEFT;
396 //	aPen.SetWidth( 10 );
397 }
398 
399 
400 
401 SwPageFtnInfo::SwPageFtnInfo( const SwPageFtnInfo &rCpy ) :
402 	nMaxHeight( rCpy.GetHeight() ),
403 	nLineWidth(rCpy.nLineWidth),
404 	aLineColor(rCpy.aLineColor),
405 	aWidth( rCpy.GetWidth() ),
406 	eAdj( rCpy.GetAdj() ),
407 	nTopDist( rCpy.GetTopDist() ),
408 	nBottomDist( rCpy.GetBottomDist() )
409 {
410 }
411 
412 /*************************************************************************
413 |*
414 |*	SwPageFtnInfo::operator=
415 |*
416 |*	Ersterstellung		MA 24. Feb. 93
417 |*	Letzte Aenderung	MA 24. Feb. 93
418 |*
419 |*************************************************************************/
420 
421 
422 
423 SwPageFtnInfo &SwPageFtnInfo::operator=( const SwPageFtnInfo& rCpy )
424 {
425 	nMaxHeight	= rCpy.GetHeight();
426 	nLineWidth 	= rCpy.nLineWidth;
427 	aLineColor 	= rCpy.aLineColor;
428 	aWidth		= rCpy.GetWidth();
429 	eAdj		= rCpy.GetAdj();
430 	nTopDist	= rCpy.GetTopDist();
431 	nBottomDist = rCpy.GetBottomDist();
432 	return *this;
433 }
434 /*************************************************************************
435 |*
436 |*	SwPageFtnInfo::operator==
437 |*
438 |*	Ersterstellung		MA 01. Mar. 93
439 |*	Letzte Aenderung	MA 01. Mar. 93
440 |*
441 |*************************************************************************/
442 
443 
444 
445 sal_Bool SwPageFtnInfo::operator==( const SwPageFtnInfo& rCmp ) const
446 {
447 	return ( nMaxHeight == rCmp.GetHeight() &&
448 			 nLineWidth == rCmp.nLineWidth &&
449 			 aLineColor == rCmp.aLineColor &&
450 			 aWidth     == rCmp.GetWidth() &&
451 			 eAdj       == rCmp.GetAdj() &&
452 			 nTopDist   == rCmp.GetTopDist() &&
453 			 nBottomDist== rCmp.GetBottomDist() );
454 }
455 
456 SwPageDescExt::SwPageDescExt(const SwPageDesc & rPageDesc, SwDoc * _pDoc)
457     : aPageDesc(rPageDesc), pDoc(_pDoc)
458 {
459     SetPageDesc(rPageDesc);
460 }
461 
462 SwPageDescExt::SwPageDescExt(const SwPageDescExt & rSrc)
463     : aPageDesc(rSrc.aPageDesc), pDoc(rSrc.pDoc)
464 {
465     SetPageDesc(rSrc.aPageDesc);
466 }
467 
468 SwPageDescExt::~SwPageDescExt()
469 {
470 }
471 
472 const String & SwPageDescExt::GetName() const
473 {
474     return aPageDesc.GetName();
475 }
476 
477 void SwPageDescExt::SetPageDesc(const SwPageDesc & _aPageDesc)
478 {
479     aPageDesc = _aPageDesc;
480 
481     if (aPageDesc.GetFollow())
482         sFollow = aPageDesc.GetFollow()->GetName();
483 }
484 
485 SwPageDescExt & SwPageDescExt::operator = (const SwPageDesc & rSrc)
486 {
487     SetPageDesc(rSrc);
488 
489     return *this;
490 }
491 
492 SwPageDescExt & SwPageDescExt::operator = (const SwPageDescExt & rSrc)
493 {
494     SetPageDesc(rSrc.aPageDesc);
495 
496     return *this;
497 }
498 
499 SwPageDescExt::operator SwPageDesc() const
500 {
501     SwPageDesc aResult(aPageDesc);
502 
503     SwPageDesc * pPageDesc = pDoc->GetPageDesc(sFollow);
504 
505     if ( 0 != pPageDesc )
506         aResult.SetFollow(pPageDesc);
507 
508     return aResult;
509 }
510