xref: /aoo41x/main/sw/source/core/layout/hffrm.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 #include "pagefrm.hxx"
32 #include "viewsh.hxx"
33 #include "doc.hxx"
34 #include "errhdl.hxx"
35 #include <fmtcntnt.hxx>
36 #include <fmthdft.hxx>
37 #include <fmtfsize.hxx>
38 #include "viewopt.hxx"
39 #include "hffrm.hxx"
40 #include "rootfrm.hxx"
41 #include "txtfrm.hxx"
42 #include "sectfrm.hxx"
43 #include "flyfrm.hxx"
44 #include "frmtool.hxx"
45 #include "dflyobj.hxx"
46 #include "frmfmt.hxx"
47 #include "ndindex.hxx"
48 #include "hfspacingitem.hxx"
49 // OD 2004-05-24 #i28701#
50 #include <sortedobjs.hxx>
51 // --> OD 2005-03-03 #i43771#
52 #include <objectformatter.hxx>
53 // <--
54 
55 extern sal_Bool bObjsDirect;	//frmtool.cxx
56 
57 static SwTwips lcl_GetFrmMinHeight(const SwLayoutFrm & rFrm)
58 {
59     const SwFmtFrmSize &rSz = rFrm.GetFmt()->GetFrmSize();
60     SwTwips nMinHeight;
61 
62     switch (rSz.GetHeightSizeType())
63     {
64     case ATT_MIN_SIZE:
65         nMinHeight = rSz.GetHeight();
66 
67         break;
68 
69     default:
70         nMinHeight = 0;
71     }
72 
73 
74     return nMinHeight;
75 }
76 
77 
78 static SwTwips lcl_CalcContentHeight(SwLayoutFrm & frm)
79 {
80     SwFrm* pFrm = frm.Lower();
81 
82     SwTwips nRemaining = 0;
83     sal_uInt16 nNum = 0;
84     pFrm = frm.Lower();
85     while ( pFrm )
86     {
87         SwTwips nTmp;
88 
89         nTmp = pFrm->Frm().Height();
90         nRemaining += nTmp;
91         if( pFrm->IsTxtFrm() && ((SwTxtFrm*)pFrm)->IsUndersized() )
92         {
93             nTmp = ((SwTxtFrm*)pFrm)->GetParHeight()
94                 - pFrm->Prt().Height();
95             // Dieser TxtFrm waere gern ein bisschen groesser
96             nRemaining += nTmp;
97         }
98         else if( pFrm->IsSctFrm() && ((SwSectionFrm*)pFrm)->IsUndersized() )
99         {
100             nTmp = ((SwSectionFrm*)pFrm)->Undersize();
101             nRemaining += nTmp;
102         }
103         pFrm = pFrm->GetNext();
104 
105         nNum++;
106     }
107 
108     return nRemaining;
109 }
110 
111 static void lcl_LayoutFrmEnsureMinHeight(SwLayoutFrm & rFrm,
112                                          const SwBorderAttrs * )
113 {
114     SwTwips nMinHeight = lcl_GetFrmMinHeight(rFrm);
115 
116     if (rFrm.Frm().Height() < nMinHeight)
117     {
118         rFrm.Grow(nMinHeight - rFrm.Frm().Height());
119     }
120 }
121 
122 SwHeadFootFrm::SwHeadFootFrm( SwFrmFmt * pFmt, SwFrm* pSib, sal_uInt16 nTypeIn)
123     : SwLayoutFrm( pFmt, pSib )
124 {
125     nType = nTypeIn;
126     SetDerivedVert( sal_False );
127 
128 	const SwFmtCntnt &rCnt = pFmt->GetCntnt();
129 
130 	ASSERT( rCnt.GetCntntIdx(), "Kein Inhalt fuer Header." );
131 
132 	//Fuer Header Footer die Objekte gleich erzeugen lassen.
133 	sal_Bool bOld = bObjsDirect;
134 	bObjsDirect = sal_True;
135 	sal_uLong nIndex = rCnt.GetCntntIdx()->GetIndex();
136 	::_InsertCnt( this, pFmt->GetDoc(), ++nIndex );
137 	bObjsDirect = bOld;
138 }
139 
140 void SwHeadFootFrm::FormatPrt(SwTwips & nUL, const SwBorderAttrs * pAttrs)
141 {
142     if (GetEatSpacing())
143     {
144         /* The minimal height of the print area is the minimal height of the
145            frame without the height needed for borders and shadow. */
146         SwTwips nMinHeight = lcl_GetFrmMinHeight(*this);
147 
148         nMinHeight -= pAttrs->CalcTop();
149         nMinHeight -= pAttrs->CalcBottom();
150 
151         /* If the minimal height of the print area is negative, try to
152            compensate by overlapping */
153         SwTwips nOverlap = 0;
154         if (nMinHeight < 0)
155         {
156             nOverlap = -nMinHeight;
157             nMinHeight = 0;
158         }
159 
160         /* Calculate desired height of content. The minimal height has to be
161            adhered. */
162         SwTwips nHeight;
163 
164         if ( ! HasFixSize() )
165             nHeight = lcl_CalcContentHeight(*this);
166         else
167             nHeight = nMinHeight;
168 
169         if (nHeight < nMinHeight)
170             nHeight = nMinHeight;
171 
172         /* calculate initial spacing/line space */
173         SwTwips nSpace, nLine;
174 
175         if (IsHeaderFrm())
176         {
177             nSpace = pAttrs->CalcBottom();
178             nLine = pAttrs->CalcBottomLine();
179         }
180         else
181         {
182             nSpace = pAttrs->CalcTop();
183             nLine = pAttrs->CalcTopLine();
184         }
185 
186         /* calculate overlap and correct spacing */
187         nOverlap += nHeight - nMinHeight;
188         if (nOverlap < nSpace - nLine)
189             nSpace -= nOverlap;
190         else
191             nSpace = nLine;
192 
193         /* calculate real vertical space between frame and print area */
194         if (IsHeaderFrm())
195             nUL = pAttrs->CalcTop() + nSpace;
196         else
197             nUL = pAttrs->CalcBottom() + nSpace;
198 
199         /* set print area */
200         // OD 23.01.2003 #106895# - add first parameter to <SwBorderAttrs::CalcRight(..)>
201         SwTwips nLR = pAttrs->CalcLeft( this ) + pAttrs->CalcRight( this );
202 
203         aPrt.Left(pAttrs->CalcLeft(this));
204 
205         if (IsHeaderFrm())
206             aPrt.Top(pAttrs->CalcTop());
207         else
208             aPrt.Top(nSpace);
209 
210         aPrt.Width(aFrm.Width() - nLR);
211 
212         SwTwips nNewHeight;
213 
214         if (nUL < aFrm.Height())
215             nNewHeight = aFrm.Height() - nUL;
216         else
217             nNewHeight = 0;
218 
219         aPrt.Height(nNewHeight);
220 
221     }
222     else
223     {
224 		//Position einstellen.
225 		aPrt.Left( pAttrs->CalcLeft( this ) );
226 		aPrt.Top ( pAttrs->CalcTop()  );
227 
228 		//Sizes einstellen; die Groesse gibt der umgebende Frm vor, die
229 		//die Raender werden einfach abgezogen.
230         // OD 23.01.2003 #106895# - add first parameter to <SwBorderAttrs::CalcRight(..)>
231         SwTwips nLR = pAttrs->CalcLeft( this ) + pAttrs->CalcRight( this );
232 		aPrt.Width ( aFrm.Width() - nLR );
233 		aPrt.Height( aFrm.Height()- nUL );
234 
235     }
236 
237     bValidPrtArea = sal_True;
238 }
239 
240 void SwHeadFootFrm::FormatSize(SwTwips nUL, const SwBorderAttrs * pAttrs)
241 {
242     if ( !HasFixSize() )
243     {
244         if( !IsColLocked() )
245         {
246             bValidSize = bValidPrtArea = sal_True;
247 
248             const SwTwips nBorder = nUL;
249             SwTwips nMinHeight = lcl_GetFrmMinHeight(*this);
250             nMinHeight -= pAttrs->CalcTop();
251             nMinHeight -= pAttrs->CalcBottom();
252 
253             if (nMinHeight < 0)
254                 nMinHeight = 0;
255 
256             ColLock();
257 
258             SwTwips nMaxHeight = LONG_MAX;
259             SwTwips nRemaining, nOldHeight;
260             // --> OD 2006-05-24 #i64301#
261             // use the position of the footer printing area to control invalidation
262             // of the first footer content.
263             Point aOldFooterPrtPos;
264             // <--
265 
266             do
267             {
268                 nOldHeight = Prt().Height();
269                 SwFrm* pFrm = Lower();
270                 // --> OD 2006-05-24 #i64301#
271                 if ( pFrm &&
272                      aOldFooterPrtPos != ( Frm().Pos() + Prt().Pos() ) )
273                 {
274                     pFrm->_InvalidatePos();
275                     aOldFooterPrtPos = Frm().Pos() + Prt().Pos();
276                 }
277                 // <--
278                 while( pFrm )
279                 {
280                     pFrm->Calc();
281                     // --> OD 2005-03-03 #i43771# - format also object anchored
282                     // at the frame
283                     // --> OD 2005-05-03 #i46941# - frame has to be valid.
284                     // Note: frame could be invalid after calling its format,
285                     //       if it's locked
286                     ASSERT( StackHack::IsLocked() || !pFrm->IsTxtFrm() ||
287                             pFrm->IsValid() ||
288                             static_cast<SwTxtFrm*>(pFrm)->IsJoinLocked(),
289                             "<SwHeadFootFrm::FormatSize(..)> - text frame invalid and not locked." );
290                     if ( pFrm->IsTxtFrm() && pFrm->IsValid() )
291                     {
292                         if ( !SwObjectFormatter::FormatObjsAtFrm( *pFrm,
293                                                                   *(pFrm->FindPageFrm()) ) )
294                         {
295                             // restart format with first content
296                             pFrm = Lower();
297                             continue;
298                         }
299                     }
300                     // <--
301                     pFrm = pFrm->GetNext();
302                 }
303                 nRemaining = 0;
304                 pFrm = Lower();
305 
306                 while ( pFrm )
307                 {
308                     nRemaining += pFrm->Frm().Height();
309 
310                     if( pFrm->IsTxtFrm() &&
311                         ((SwTxtFrm*)pFrm)->IsUndersized() )
312                         // Dieser TxtFrm waere gern ein bisschen groesser
313                         nRemaining += ((SwTxtFrm*)pFrm)->GetParHeight()
314                             - pFrm->Prt().Height();
315                     else if( pFrm->IsSctFrm() &&
316                              ((SwSectionFrm*)pFrm)->IsUndersized() )
317                         nRemaining += ((SwSectionFrm*)pFrm)->Undersize();
318                     pFrm = pFrm->GetNext();
319                 }
320                 if ( nRemaining < nMinHeight )
321                     nRemaining = nMinHeight;
322 
323                 SwTwips nDiff = nRemaining - nOldHeight;
324 
325                 if( !nDiff )
326                     break;
327                 if( nDiff < 0 )
328                 {
329                     nMaxHeight = nOldHeight;
330 
331                     if( nRemaining <= nMinHeight )
332                         nRemaining = ( nMaxHeight + nMinHeight + 1 ) / 2;
333                 }
334                 else
335                 {
336                     if (nOldHeight > nMinHeight)
337                         nMinHeight = nOldHeight;
338 
339                     if( nRemaining >= nMaxHeight )
340                         nRemaining = ( nMaxHeight + nMinHeight + 1 ) / 2;
341                 }
342 
343                 nDiff = nRemaining - nOldHeight;
344 
345                 if ( nDiff )
346                 {
347                     ColUnlock();
348                     if ( nDiff > 0 )
349                     {
350                         if ( Grow( nDiff ) )
351 						{
352                             pFrm = Lower();
353 
354                             while ( pFrm )
355                             {
356                                 if( pFrm->IsTxtFrm())
357                                 {
358                                     SwTxtFrm * pTmpFrm = (SwTxtFrm*) pFrm;
359                                     if (pTmpFrm->IsUndersized() )
360                                     {
361                                         pTmpFrm->InvalidateSize();
362                                         pTmpFrm->Prepare(PREP_ADJUST_FRM);
363                                     }
364                                 }
365 								/* #i3568# Undersized sections need to be
366                                    invalidated too. */
367 								else if (pFrm->IsSctFrm())
368 								{
369                                     SwSectionFrm * pTmpFrm =
370 										(SwSectionFrm*) pFrm;
371                                     if (pTmpFrm->IsUndersized() )
372                                     {
373                                         pTmpFrm->InvalidateSize();
374                                         pTmpFrm->Prepare(PREP_ADJUST_FRM);
375                                     }
376 								}
377                                 pFrm = pFrm->GetNext();
378                             }
379                         }
380                     }
381                     else
382                         Shrink( -nDiff );
383                     //Schnell auf dem kurzen Dienstweg die Position updaten.
384 
385                     MakePos();
386                     ColLock();
387                 }
388                 else
389                     break;
390                 //Unterkante des Uppers nicht ueberschreiten.
391                 if ( GetUpper() && Frm().Height() )
392                 {
393                     const SwTwips nDeadLine = GetUpper()->Frm().Top() +
394                         GetUpper()->Prt().Bottom();
395                     const SwTwips nBot = Frm().Bottom();
396                     if ( nBot > nDeadLine )
397                     {
398                         Frm().Bottom( nDeadLine );
399                         Prt().SSize().Height() = Frm().Height() - nBorder;
400                     }
401                 }
402                 bValidSize = bValidPrtArea = sal_True;
403             } while( nRemaining<=nMaxHeight && nOldHeight!=Prt().Height() );
404             ColUnlock();
405         }
406         bValidSize = bValidPrtArea = sal_True;
407     }
408     else //if ( GetType() & 0x0018 )
409     {
410         do
411         {
412             if ( Frm().Height() != pAttrs->GetSize().Height() )
413                 ChgSize( Size( Frm().Width(), pAttrs->GetSize().Height()));
414             bValidSize = sal_True;
415             MakePos();
416         } while ( !bValidSize );
417     }
418 }
419 
420 void SwHeadFootFrm::Format(const SwBorderAttrs * pAttrs)
421 {
422 	ASSERT( pAttrs, "SwFooterFrm::Format, pAttrs ist 0." );
423 
424 	if ( bValidPrtArea && bValidSize )
425 		return;
426 
427     if ( ! GetEatSpacing() && IsHeaderFrm())
428     {
429         SwLayoutFrm::Format(pAttrs);
430     }
431     else
432     {
433         lcl_LayoutFrmEnsureMinHeight(*this, pAttrs);
434 
435         long nUL = pAttrs->CalcTop()  + pAttrs->CalcBottom();
436 
437         if ( !bValidPrtArea )
438             FormatPrt(nUL, pAttrs);
439 
440         if ( !bValidSize )
441             FormatSize(nUL, pAttrs);
442     }
443 }
444 
445 SwTwips SwHeadFootFrm::GrowFrm( SwTwips nDist, sal_Bool bTst,  sal_Bool bInfo )
446 {
447     SwTwips nResult;
448 
449     if ( IsColLocked() )
450     {
451         nResult = 0;
452     }
453     else if (!GetEatSpacing())
454     {
455         nResult = SwLayoutFrm::GrowFrm(nDist, bTst, bInfo);
456     }
457     else
458     {
459         nResult = 0;
460 
461         SwBorderAttrAccess * pAccess =
462             new SwBorderAttrAccess( SwFrm::GetCache(), this );
463         ASSERT(pAccess, "no border attributes");
464 
465         SwBorderAttrs * pAttrs = pAccess->Get();
466 
467         /* First assume the whole amount to grow can be provided by eating
468            spacing. */
469         SwTwips nEat = nDist;
470         SwTwips nMaxEat;
471 
472         /* calculate maximum eatable spacing */
473         if (IsHeaderFrm())
474             nMaxEat = aFrm.Height() - aPrt.Top() - aPrt.Height() - pAttrs->CalcBottomLine();
475         else
476             nMaxEat = aPrt.Top() - pAttrs->CalcTopLine();
477 
478         delete pAccess;
479 
480         if (nMaxEat < 0)
481             nMaxEat = 0;
482 
483         /* If the frame is too small, eat less spacing thus letting the frame
484            grow more. */
485         SwTwips nMinHeight = lcl_GetFrmMinHeight(*this);
486         SwTwips nFrameTooSmall = nMinHeight - Frm().Height();
487 
488         if (nFrameTooSmall > 0)
489             nEat -= nFrameTooSmall;
490 
491         /* No negative eating, not eating more than allowed. */
492         if (nEat < 0)
493             nEat = 0;
494         else if (nEat > nMaxEat)
495             nEat = nMaxEat;
496 
497         // OD 10.04.2003 #108719# - Notify fly frame, if header frame
498         // grows. Consider, that 'normal' grow of layout frame already notifys
499         // the fly frames.
500         sal_Bool bNotifyFlys = sal_False;
501         if (nEat > 0)
502         {
503             if ( ! bTst)
504             {
505                 if (! IsHeaderFrm())
506                 {
507                     aPrt.Top(aPrt.Top() - nEat);
508                     aPrt.Height(aPrt.Height() - nEat);
509                 }
510 
511                 InvalidateAll();
512             }
513 
514             nResult += nEat;
515             // OD 14.04.2003 #108719# - trigger fly frame notify.
516             if ( IsHeaderFrm() )
517             {
518                 bNotifyFlys = sal_True;
519             }
520         }
521 
522         if (nDist - nEat > 0)
523         {
524             SwTwips nFrmGrow =
525                 SwLayoutFrm::GrowFrm( nDist - nEat, bTst, bInfo );
526 
527             nResult += nFrmGrow;
528             if ( nFrmGrow > 0 )
529             {
530                 bNotifyFlys = sal_False;
531             }
532         }
533 
534         // OD 10.04.2003 #108719# - notify fly frames, if necessary and triggered.
535         if ( ( nResult > 0 ) && bNotifyFlys )
536         {
537             NotifyLowerObjs();
538         }
539     }
540 
541 	if ( nResult && !bTst )
542 		SetCompletePaint();
543 
544     return nResult;
545 }
546 
547 SwTwips SwHeadFootFrm::ShrinkFrm( SwTwips nDist, sal_Bool bTst, sal_Bool bInfo )
548 {
549     SwTwips nResult;
550 
551     if ( IsColLocked() )
552     {
553         nResult = 0;
554     }
555     else if (! GetEatSpacing())
556     {
557         nResult = SwLayoutFrm::ShrinkFrm(nDist, bTst, bInfo);
558     }
559     else
560     {
561         nResult = 0;
562 
563         SwTwips nMinHeight = lcl_GetFrmMinHeight(*this);
564         SwTwips nOldHeight = Frm().Height();
565         SwTwips nRest = 0; // Amount to shrink by spitting out spacing
566 
567         if ( nOldHeight >= nMinHeight )
568         {
569             /* If the frame's height is bigger than its minimum height, shrink
570                the frame towards its minimum height. If this is not sufficient
571                to provide the shrinking requested provide the rest by spitting
572                out spacing. */
573 
574             SwTwips nBiggerThanMin = nOldHeight - nMinHeight;
575 
576             if (nBiggerThanMin < nDist)
577             {
578                 nRest = nDist - nBiggerThanMin;
579             }
580             /* info: declaration of nRest -> else nRest = 0 */
581         }
582         else
583             /* The frame cannot shrink. Provide shrinking by spitting out
584                spacing. */
585             nRest = nDist;
586 
587         // OD 10.04.2003 #108719# - Notify fly frame, if header/footer frame
588         // shrinks. Consider, that 'normal' shrink of layout frame already notifys
589         // the fly frames.
590         sal_Bool bNotifyFlys = sal_False;
591         if (nRest > 0)
592         {
593 
594             SwBorderAttrAccess * pAccess =
595                 new SwBorderAttrAccess( SwFrm::GetCache(), this );
596             ASSERT(pAccess, "no border attributes");
597 
598             SwBorderAttrs * pAttrs = pAccess->Get();
599 
600             /* minimal height of print area */
601             SwTwips nMinPrtHeight = nMinHeight
602                 - pAttrs->CalcTop()
603                 - pAttrs->CalcBottom();
604 
605             if (nMinPrtHeight < 0)
606                 nMinPrtHeight = 0;
607 
608             delete pAccess;
609 
610             /* assume all shrinking can be provided */
611             SwTwips nShrink = nRest;
612 
613             /* calculate maximum shrinking */
614             SwTwips nMaxShrink = aPrt.Height() - nMinPrtHeight;
615 
616             /* shrink no more than maximum shrinking */
617             if (nShrink > nMaxShrink)
618             {
619                 //nRest -= nShrink - nMaxShrink;
620                 nShrink = nMaxShrink;
621             }
622 
623             if (!bTst)
624             {
625                 if (! IsHeaderFrm() )
626                 {
627                     aPrt.Top(aPrt.Top() + nShrink);
628                     aPrt.Height(aPrt.Height() - nShrink);
629                 }
630 
631                 InvalidateAll();
632             }
633             nResult += nShrink;
634             // OD 14.04.2003 #108719# - trigger fly frame notify.
635             if ( IsHeaderFrm() )
636             {
637                 bNotifyFlys = sal_True;
638             }
639         }
640 
641         /* The shrinking not providable by spitting out spacing has to be done
642            by the frame. */
643         if (nDist - nRest > 0)
644         {
645             SwTwips nShrinkAmount = SwLayoutFrm::ShrinkFrm( nDist - nRest, bTst, bInfo );
646             nResult += nShrinkAmount;
647             if ( nShrinkAmount > 0 )
648             {
649                 bNotifyFlys = sal_False;
650             }
651         }
652 
653         // OD 10.04.2003 #108719# - notify fly frames, if necessary.
654         if ( ( nResult > 0 ) && bNotifyFlys )
655         {
656             NotifyLowerObjs();
657         }
658     }
659 
660     return nResult;
661 }
662 
663 sal_Bool SwHeadFootFrm::GetEatSpacing() const
664 {
665     const SwFrmFmt * pFmt = GetFmt();
666     ASSERT(pFmt, "SwHeadFootFrm: no format?");
667 
668     if (pFmt->GetHeaderAndFooterEatSpacing().GetValue())
669         return sal_True;
670 
671     return sal_False;
672 }
673 
674 
675 /*************************************************************************
676 |*
677 |*	SwPageFrm::PrepareHeader()
678 |*
679 |*	Beschreibung		Erzeugt oder Entfernt Header
680 |*	Ersterstellung		MA 04. Feb. 93
681 |*	Letzte Aenderung	MA 12. May. 96
682 |*
683 |*************************************************************************/
684 
685 
686 void DelFlys( SwLayoutFrm *pFrm, SwPageFrm *pPage )
687 {
688 	for ( int i = 0; pPage->GetSortedObjs() &&
689 						pPage->GetSortedObjs()->Count() &&
690 						i < (int)pPage->GetSortedObjs()->Count(); ++i )
691 	{
692         SwAnchoredObject* pObj = (*pPage->GetSortedObjs())[i];
693         if ( pObj->ISA(SwFlyFrm) )
694 		{
695             SwFlyFrm* pFlyFrm = static_cast<SwFlyFrm*>(pObj);
696             if ( pFrm->IsAnLower( pFlyFrm ) )
697 			{
698                 delete pFlyFrm;
699 				--i;
700 			}
701 		}
702 	}
703 }
704 
705 
706 
707 void SwPageFrm::PrepareHeader()
708 {
709 	SwLayoutFrm *pLay = (SwLayoutFrm*)Lower();
710 	if ( !pLay )
711 		return;
712 
713 	const SwFmtHeader &rH = ((SwFrmFmt*)GetRegisteredIn())->GetHeader();
714 
715     const ViewShell *pSh = getRootFrm()->GetCurrShell();
716     const sal_Bool bOn = !(pSh && pSh->GetViewOptions()->getBrowseMode());
717 
718 	if ( bOn && rH.IsActive() )
719 	{	//Header einsetzen, vorher entfernen falls vorhanden.
720 		ASSERT( rH.GetHeaderFmt(), "FrmFmt fuer Header nicht gefunden." );
721 
722 		if ( pLay->GetFmt() == (SwFrmFmt*)rH.GetHeaderFmt() )
723 			return;	//Der Footer ist bereits der richtige
724 
725 		if ( pLay->IsHeaderFrm() )
726 		{	SwLayoutFrm *pDel = pLay;
727 			pLay = (SwLayoutFrm*)pLay->GetNext();
728 			::DelFlys( pDel, this );
729 			pDel->Cut();
730 			delete pDel;
731 		}
732 		ASSERT( pLay, "Wohin mit dem Header?" );
733 		SwHeaderFrm *pH = new SwHeaderFrm( (SwFrmFmt*)rH.GetHeaderFmt(), this );
734 		pH->Paste( this, pLay );
735 		if ( GetUpper() )
736 			::RegistFlys( this, pH );
737 	}
738 	else if ( pLay && pLay->IsHeaderFrm() )
739 	{	//Header entfernen falls vorhanden.
740 		::DelFlys( pLay, this );
741 		pLay->Cut();
742 		delete pLay;
743 	}
744 }
745 /*************************************************************************
746 |*
747 |*	SwPageFrm::PrepareFooter()
748 |*
749 |*	Beschreibung		Erzeugt oder Entfernt Footer
750 |*	Ersterstellung		MA 04. Feb. 93
751 |*	Letzte Aenderung	MA 12. May. 96
752 |*
753 |*************************************************************************/
754 
755 
756 void SwPageFrm::PrepareFooter()
757 {
758 	SwLayoutFrm *pLay = (SwLayoutFrm*)Lower();
759 	if ( !pLay )
760 		return;
761 
762 	const SwFmtFooter &rF = ((SwFrmFmt*)GetRegisteredIn())->GetFooter();
763 	while ( pLay->GetNext() )
764 		pLay = (SwLayoutFrm*)pLay->GetNext();
765 
766     const ViewShell *pSh = getRootFrm()->GetCurrShell();
767     const sal_Bool bOn = !(pSh && pSh->GetViewOptions()->getBrowseMode());
768 
769 	if ( bOn && rF.IsActive() )
770 	{	//Footer einsetzen, vorher entfernen falls vorhanden.
771 		ASSERT( rF.GetFooterFmt(), "FrmFmt fuer Footer nicht gefunden." );
772 
773 		if ( pLay->GetFmt() == (SwFrmFmt*)rF.GetFooterFmt() )
774 			return; //Der Footer ist bereits der richtige.
775 
776 		if ( pLay->IsFooterFrm() )
777 		{	::DelFlys( pLay, this );
778 			pLay->Cut();
779 			delete pLay;
780 		}
781 		SwFooterFrm *pF = new SwFooterFrm( (SwFrmFmt*)rF.GetFooterFmt(), this );
782 		pF->Paste( this );
783 		if ( GetUpper() )
784 			::RegistFlys( this, pF );
785 	}
786 	else if ( pLay && pLay->IsFooterFrm() )
787 	{	//Footer entfernen falls vorhanden.
788 		::DelFlys( pLay, this );
789 		ViewShell *pShell;
790 		if ( pLay->GetPrev() && 0 != (pShell = getRootFrm()->GetCurrShell()) &&
791 			 pShell->VisArea().HasArea() )
792 			pShell->InvalidateWindows( pShell->VisArea() );
793 		pLay->Cut();
794 		delete pLay;
795 	}
796 }
797 
798 
799 
800