LCOV - code coverage report
Current view: top level - sw/source/core/layout - hffrm.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 340 0.0 %
Date: 2014-04-14 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10