LCOV - code coverage report
Current view: top level - sw/source/core/frmedt - fedesc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 14 103 13.6 %
Date: 2012-08-25 Functions: 3 8 37.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 170 2.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <hintids.hxx>
      31                 :            : #include <fesh.hxx>
      32                 :            : #include <doc.hxx>
      33                 :            : #include <IDocumentUndoRedo.hxx>
      34                 :            : #include <pagefrm.hxx>
      35                 :            : #include <rootfrm.hxx>
      36                 :            : #include <cntfrm.hxx>
      37                 :            : #include <pam.hxx>
      38                 :            : #include <fmtpdsc.hxx>
      39                 :            : #include <pagedesc.hxx>
      40                 :            : #include <tabfrm.hxx>
      41                 :            : #include <edimp.hxx>
      42                 :            : #include <SwStyleNameMapper.hxx>
      43                 :            : 
      44                 :            : /*************************************************************************
      45                 :            : |*
      46                 :            : |*  SwFEShell::GetPageDescCnt()
      47                 :            : |*
      48                 :            : |*************************************************************************/
      49                 :            : 
      50                 :       3659 : sal_uInt16 SwFEShell::GetPageDescCnt() const
      51                 :            : {
      52                 :       3659 :     return GetDoc()->GetPageDescCnt();
      53                 :            : }
      54                 :            : 
      55                 :            : /*************************************************************************
      56                 :            : |*
      57                 :            : |*  SwFEShell::ChgCurPageDesc()
      58                 :            : |*
      59                 :            : |*************************************************************************/
      60                 :            : 
      61                 :          0 : void SwFEShell::ChgCurPageDesc( const SwPageDesc& rDesc )
      62                 :            : {
      63                 :            : #if OSL_DEBUG_LEVEL > 0
      64                 :            :     // SS does not change PageDesc, but only sets the attibute.
      65                 :            :     // The Pagedesc should be available in the document
      66                 :            :     sal_Bool bFound = sal_False;
      67                 :            :     for ( sal_uInt16 nTst = 0; nTst < GetPageDescCnt(); ++nTst )
      68                 :            :         if ( &rDesc == &GetPageDesc( nTst ) )
      69                 :            :             bFound = sal_True;
      70                 :            :     OSL_ENSURE( bFound, "ChgCurPageDesc with invalid descriptor." );
      71                 :            : #endif
      72                 :            : 
      73         [ #  # ]:          0 :     StartAllAction();
      74                 :            : 
      75 [ #  # ][ #  # ]:          0 :     SwPageFrm *pPage = GetCurrFrm()->FindPageFrm();
      76                 :          0 :     const SwFrm *pFlow = 0;
      77                 :          0 :     sal_uInt16 nPageNmOffset = 0;
      78                 :            : 
      79                 :            :     OSL_ENSURE( !GetCrsr()->HasMark(), "ChgCurPageDesc only without selection!");
      80                 :            : 
      81         [ #  # ]:          0 :     SET_CURR_SHELL( this );
      82         [ #  # ]:          0 :     while ( pPage )
      83                 :            :     {
      84         [ #  # ]:          0 :         pFlow = pPage->FindFirstBodyCntnt();
      85         [ #  # ]:          0 :         if ( pFlow )
      86                 :            :         {
      87 [ #  # ][ #  # ]:          0 :             if ( pFlow->IsInTab() )
      88         [ #  # ]:          0 :                 pFlow = pFlow->FindTabFrm();
      89 [ #  # ][ #  # ]:          0 :             const SwFmtPageDesc& rPgDesc = pFlow->GetAttrSet()->GetPageDesc();
      90         [ #  # ]:          0 :             if( rPgDesc.GetPageDesc() )
      91                 :            :             {
      92                 :            :                 // wir haben ihn den Schlingel
      93                 :          0 :                 nPageNmOffset = rPgDesc.GetNumOffset();
      94                 :          0 :                 break;
      95                 :            :             }
      96                 :            :         }
      97                 :          0 :         pPage = (SwPageFrm*) pPage->GetPrev();
      98                 :            :     }
      99         [ #  # ]:          0 :     if ( !pPage )
     100                 :            :     {
     101         [ #  # ]:          0 :         pPage = (SwPageFrm*) (GetLayout()->Lower());
     102         [ #  # ]:          0 :         pFlow = pPage->FindFirstBodyCntnt();
     103         [ #  # ]:          0 :         if ( !pFlow )
     104                 :            :         {
     105                 :          0 :             pPage   = (SwPageFrm*)pPage->GetNext();
     106         [ #  # ]:          0 :             pFlow = pPage->FindFirstBodyCntnt();
     107                 :            :             OSL_ENSURE( pFlow, "Dokuemnt ohne Inhalt?!?" );
     108                 :            :         }
     109                 :            :     }
     110                 :            : 
     111                 :            :     // use pagenumber
     112         [ #  # ]:          0 :     SwFmtPageDesc aNew( &rDesc );
     113                 :          0 :     aNew.SetNumOffset( nPageNmOffset );
     114                 :            : 
     115 [ #  # ][ #  # ]:          0 :     if ( pFlow->IsInTab() )
     116 [ #  # ][ #  # ]:          0 :         GetDoc()->SetAttr( aNew, *(SwFmt*)pFlow->FindTabFrm()->GetFmt() );
                 [ #  # ]
     117                 :            :     else
     118                 :            :     {
     119         [ #  # ]:          0 :         SwPaM aPaM( *((SwCntntFrm*)pFlow)->GetNode() );
     120 [ #  # ][ #  # ]:          0 :         GetDoc()->InsertPoolItem( aPaM, aNew, 0 );
     121                 :            :     }
     122 [ #  # ][ #  # ]:          0 :     EndAllActionAndCall();
                 [ #  # ]
     123                 :          0 : }
     124                 :            : 
     125                 :            : /*************************************************************************
     126                 :            : |*
     127                 :            : |*  SwFEShell::ChgPageDesc()
     128                 :            : |*
     129                 :            : |*************************************************************************/
     130                 :            : 
     131                 :          0 : void SwFEShell::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
     132                 :            : {
     133         [ #  # ]:          0 :     StartAllAction();
     134         [ #  # ]:          0 :     SET_CURR_SHELL( this );
     135                 :            :     //Fix i64842: because Undo has a very special way to handle header/footer content
     136                 :            :     // we have to copy the page descriptor before calling ChgPageDesc.
     137         [ #  # ]:          0 :     SwPageDesc aDesc( rChged );
     138                 :            :     {
     139 [ #  # ][ #  # ]:          0 :         ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
     140 [ #  # ][ #  # ]:          0 :         GetDoc()->CopyPageDesc(rChged, aDesc);
     141                 :            :     }
     142         [ #  # ]:          0 :     GetDoc()->ChgPageDesc( i, aDesc );
     143 [ #  # ][ #  # ]:          0 :     EndAllActionAndCall();
                 [ #  # ]
     144                 :          0 : }
     145                 :            : 
     146                 :            : /*************************************************************************
     147                 :            : |*
     148                 :            : |*  SwFEShell::GetPageDesc(), GetCurPageDesc()
     149                 :            : |*
     150                 :            : |*************************************************************************/
     151                 :            : 
     152                 :       5812 : const SwPageDesc& SwFEShell::GetPageDesc( sal_uInt16 i ) const
     153                 :            : {
     154                 :       5812 :     return GetDoc()->GetPageDesc( i );
     155                 :            : }
     156                 :            : 
     157                 :          0 : SwPageDesc* SwFEShell::FindPageDescByName( const String& rName,
     158                 :            :                                             sal_Bool bGetFromPool,
     159                 :            :                                             sal_uInt16* pPos )
     160                 :            : {
     161                 :          0 :     SwPageDesc* pDesc = GetDoc()->FindPageDescByName( rName, pPos );
     162 [ #  # ][ #  # ]:          0 :     if( !pDesc && bGetFromPool )
     163                 :            :     {
     164                 :          0 :         sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( rName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
     165 [ #  # ][ #  # ]:          0 :         if( USHRT_MAX != nPoolId &&
           [ #  #  #  # ]
     166                 :          0 :             0 != (pDesc = GetDoc()->GetPageDescFromPool( nPoolId ))
     167                 :            :             && pPos )
     168                 :            :                 // appended always
     169                 :          0 :             *pPos = GetDoc()->GetPageDescCnt() - 1 ;
     170                 :            :     }
     171                 :          0 :     return pDesc;
     172                 :            : }
     173                 :            : 
     174                 :          0 : sal_uInt16 SwFEShell::GetMousePageDesc( const Point &rPt ) const
     175                 :            : {
     176         [ #  # ]:          0 :     if( GetLayout() )
     177                 :            :     {
     178                 :            :         const SwPageFrm* pPage =
     179                 :          0 :             static_cast<const SwPageFrm*>( GetLayout()->Lower() );
     180         [ #  # ]:          0 :         if( pPage )
     181                 :            :         {
     182 [ #  # ][ #  # ]:          0 :             while( pPage->GetNext() && rPt.Y() > pPage->Frm().Bottom() )
                 [ #  # ]
     183                 :          0 :                 pPage = static_cast<const SwPageFrm*>( pPage->GetNext() );
     184                 :          0 :             SwDoc *pMyDoc = GetDoc();
     185         [ #  # ]:          0 :             for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
     186                 :            :             {
     187         [ #  # ]:          0 :                 if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) )
     188                 :          0 :                     return i;
     189                 :            :             }
     190                 :            :         }
     191                 :            :     }
     192                 :          0 :     return 0;
     193                 :            : }
     194                 :            : 
     195                 :       5812 : sal_uInt16 SwFEShell::GetCurPageDesc( const sal_Bool bCalcFrm ) const
     196                 :            : {
     197                 :       5812 :     const SwFrm *pFrm = GetCurrFrm( bCalcFrm );
     198         [ +  - ]:       5812 :     if ( pFrm )
     199                 :            :     {
     200                 :       5812 :         const SwPageFrm *pPage = pFrm->FindPageFrm();
     201         [ +  - ]:       5812 :         if ( pPage )
     202                 :            :         {
     203                 :       5812 :             SwDoc *pMyDoc = GetDoc();
     204         [ +  - ]:       5846 :             for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
     205                 :            :             {
     206         [ +  + ]:       5846 :                 if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) )
     207                 :       5812 :                     return i;
     208                 :            :             }
     209                 :            :         }
     210                 :            :     }
     211                 :       5812 :     return 0;
     212                 :            : }
     213                 :            : 
     214                 :            : // if inside all selection only one PageDesc, return this.
     215                 :            : // Otherwise return 0 pointer
     216                 :          0 : const SwPageDesc* SwFEShell::GetSelectedPageDescs() const
     217                 :            : {
     218                 :            :     const SwCntntNode* pCNd;
     219                 :            :     const SwFrm* pMkFrm, *pPtFrm;
     220                 :          0 :     const SwPageDesc* pFnd, *pRetDesc = (SwPageDesc*)0xffffffff;
     221                 :          0 :     const Point aNulPt;
     222                 :            : 
     223 [ #  # ][ #  # ]:          0 :     FOREACHPAM_START(this)
     224                 :            : 
     225 [ #  # ][ #  # ]:          0 :         if( 0 != (pCNd = PCURCRSR->GetCntntNode() ) &&
         [ #  # ][ #  # ]
     226         [ #  # ]:          0 :             0 != ( pPtFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, sal_False )) )
     227         [ #  # ]:          0 :             pPtFrm = pPtFrm->FindPageFrm();
     228                 :            :         else
     229                 :          0 :             pPtFrm = 0;
     230                 :            : 
     231 [ #  # ][ #  # ]:          0 :         if( PCURCRSR->HasMark() &&
         [ #  # ][ #  # ]
                 [ #  # ]
     232                 :            :             0 != (pCNd = PCURCRSR->GetCntntNode( sal_False ) ) &&
     233         [ #  # ]:          0 :             0 != ( pMkFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, sal_False )) )
     234         [ #  # ]:          0 :             pMkFrm = pMkFrm->FindPageFrm();
     235                 :            :         else
     236                 :          0 :             pMkFrm = pPtFrm;
     237                 :            : 
     238                 :            : 
     239 [ #  # ][ #  # ]:          0 :         if( !pMkFrm || !pPtFrm )
     240                 :          0 :             pFnd = 0;
     241         [ #  # ]:          0 :         else if( pMkFrm == pPtFrm )
     242                 :          0 :             pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc();
     243                 :            :         else
     244                 :            :         {
     245                 :            :             // swap pointer if PtFrm before MkFrm
     246         [ #  # ]:          0 :             if( ((SwPageFrm*)pMkFrm)->GetPhyPageNum() >
     247                 :          0 :                 ((SwPageFrm*)pPtFrm)->GetPhyPageNum() )
     248                 :            :             {
     249                 :          0 :                 const SwFrm* pTmp = pMkFrm; pMkFrm = pPtFrm; pPtFrm = pTmp;
     250                 :            :             }
     251                 :            : 
     252                 :            :             // now check from MkFrm to PtFrm for equal PageDescs
     253                 :          0 :             pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc();
     254 [ #  # ][ #  # ]:          0 :             while( pFnd && pMkFrm != pPtFrm )
                 [ #  # ]
     255                 :            :             {
     256                 :          0 :                 pMkFrm = pMkFrm->GetNext();
     257 [ #  # ][ #  # ]:          0 :                 if( !pMkFrm || pFnd != ((SwPageFrm*)pMkFrm)->GetPageDesc() )
                 [ #  # ]
     258                 :          0 :                     pFnd = 0;
     259                 :            :             }
     260                 :            :         }
     261                 :            : 
     262         [ #  # ]:          0 :         if( (SwPageDesc*)0xffffffff == pRetDesc )
     263                 :          0 :             pRetDesc = pFnd;
     264         [ #  # ]:          0 :         else if( pFnd != pRetDesc )
     265                 :            :         {
     266                 :          0 :             pRetDesc = 0;
     267                 :          0 :             break;
     268                 :            :         }
     269                 :            : 
     270                 :          0 :     FOREACHPAM_END()
     271                 :            : 
     272                 :          0 :     return pRetDesc;
     273                 :            : }
     274                 :            : 
     275                 :            : 
     276                 :            : 
     277                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10