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