LCOV - code coverage report
Current view: top level - sw/source/core/frmedt - fedesc.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 105 0.0 %
Date: 2014-04-14 Functions: 0 8 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 <hintids.hxx>
      21             : #include <fesh.hxx>
      22             : #include <doc.hxx>
      23             : #include <IDocumentUndoRedo.hxx>
      24             : #include <pagefrm.hxx>
      25             : #include <rootfrm.hxx>
      26             : #include <cntfrm.hxx>
      27             : #include <pam.hxx>
      28             : #include <fmtpdsc.hxx>
      29             : #include <pagedesc.hxx>
      30             : #include <tabfrm.hxx>
      31             : #include <edimp.hxx>
      32             : #include <SwStyleNameMapper.hxx>
      33             : 
      34             : /*************************************************************************
      35             : |*
      36             : |*  SwFEShell::GetPageDescCnt()
      37             : |*
      38             : |*************************************************************************/
      39             : 
      40           0 : sal_uInt16 SwFEShell::GetPageDescCnt() const
      41             : {
      42           0 :     return GetDoc()->GetPageDescCnt();
      43             : }
      44             : 
      45             : /*************************************************************************
      46             : |*
      47             : |*  SwFEShell::ChgCurPageDesc()
      48             : |*
      49             : |*************************************************************************/
      50             : 
      51           0 : void SwFEShell::ChgCurPageDesc( const SwPageDesc& rDesc )
      52             : {
      53             : #if OSL_DEBUG_LEVEL > 0
      54             :     // SS does not change PageDesc, but only sets the attibute.
      55             :     // The Pagedesc should be available in the document
      56             :     bool bFound = false;
      57             :     for ( sal_uInt16 nTst = 0; nTst < GetPageDescCnt(); ++nTst )
      58             :         if ( &rDesc == &GetPageDesc( nTst ) )
      59             :             bFound = true;
      60             :     OSL_ENSURE( bFound, "ChgCurPageDesc with invalid descriptor." );
      61             : #endif
      62             : 
      63           0 :     StartAllAction();
      64             : 
      65           0 :     SwPageFrm *pPage = GetCurrFrm()->FindPageFrm();
      66           0 :     const SwFrm *pFlow = 0;
      67           0 :     ::boost::optional<sal_uInt16> oPageNumOffset;
      68             : 
      69             :     OSL_ENSURE( !GetCrsr()->HasMark(), "ChgCurPageDesc only without selection!");
      70             : 
      71           0 :     SET_CURR_SHELL( this );
      72           0 :     while ( pPage )
      73             :     {
      74           0 :         pFlow = pPage->FindFirstBodyCntnt();
      75           0 :         if ( pFlow )
      76             :         {
      77           0 :             if ( pFlow->IsInTab() )
      78           0 :                 pFlow = pFlow->FindTabFrm();
      79           0 :             const SwFmtPageDesc& rPgDesc = pFlow->GetAttrSet()->GetPageDesc();
      80           0 :             if( rPgDesc.GetPageDesc() )
      81             :             {
      82             :                 // wir haben ihn den Schlingel
      83           0 :                 oPageNumOffset = rPgDesc.GetNumOffset();
      84           0 :                 break;
      85             :             }
      86             :         }
      87           0 :         pPage = (SwPageFrm*) pPage->GetPrev();
      88             :     }
      89           0 :     if ( !pPage )
      90             :     {
      91           0 :         pPage = (SwPageFrm*) (GetLayout()->Lower());
      92           0 :         pFlow = pPage->FindFirstBodyCntnt();
      93           0 :         if ( !pFlow )
      94             :         {
      95           0 :             pPage   = (SwPageFrm*)pPage->GetNext();
      96           0 :             pFlow = pPage->FindFirstBodyCntnt();
      97             :             OSL_ENSURE( pFlow, "Dokuemnt ohne Inhalt?!?" );
      98             :         }
      99             :     }
     100             : 
     101             :     // use pagenumber
     102           0 :     SwFmtPageDesc aNew( &rDesc );
     103           0 :     aNew.SetNumOffset( oPageNumOffset );
     104             : 
     105           0 :     if ( pFlow->IsInTab() )
     106           0 :         GetDoc()->SetAttr( aNew, *(SwFmt*)pFlow->FindTabFrm()->GetFmt() );
     107             :     else
     108             :     {
     109           0 :         SwPaM aPaM( *((SwCntntFrm*)pFlow)->GetNode() );
     110           0 :         GetDoc()->InsertPoolItem( aPaM, aNew, 0 );
     111             :     }
     112           0 :     EndAllActionAndCall();
     113           0 : }
     114             : 
     115             : /*************************************************************************
     116             : |*
     117             : |*  SwFEShell::ChgPageDesc()
     118             : |*
     119             : |*************************************************************************/
     120             : 
     121           0 : void SwFEShell::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
     122             : {
     123           0 :     StartAllAction();
     124           0 :     SET_CURR_SHELL( this );
     125             :     //Fix i64842: because Undo has a very special way to handle header/footer content
     126             :     // we have to copy the page descriptor before calling ChgPageDesc.
     127           0 :     SwPageDesc aDesc( rChged );
     128             :     {
     129           0 :         ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
     130           0 :         GetDoc()->CopyPageDesc(rChged, aDesc);
     131             :     }
     132           0 :     GetDoc()->ChgPageDesc( i, aDesc );
     133           0 :     EndAllActionAndCall();
     134           0 : }
     135             : 
     136             : /*************************************************************************
     137             : |*
     138             : |*  SwFEShell::GetPageDesc(), GetCurPageDesc()
     139             : |*
     140             : |*************************************************************************/
     141             : 
     142           0 : const SwPageDesc& SwFEShell::GetPageDesc( sal_uInt16 i ) const
     143             : {
     144           0 :     return GetDoc()->GetPageDesc( i );
     145             : }
     146             : 
     147           0 : SwPageDesc* SwFEShell::FindPageDescByName( const OUString& rName,
     148             :                                             sal_Bool bGetFromPool,
     149             :                                             sal_uInt16* pPos )
     150             : {
     151           0 :     SwPageDesc* pDesc = GetDoc()->FindPageDescByName( rName, pPos );
     152           0 :     if( !pDesc && bGetFromPool )
     153             :     {
     154           0 :         sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( rName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
     155           0 :         if( USHRT_MAX != nPoolId &&
     156           0 :             0 != (pDesc = GetDoc()->GetPageDescFromPool( nPoolId ))
     157           0 :             && pPos )
     158             :                 // appended always
     159           0 :             *pPos = GetDoc()->GetPageDescCnt() - 1 ;
     160             :     }
     161           0 :     return pDesc;
     162             : }
     163             : 
     164           0 : sal_uInt16 SwFEShell::GetMousePageDesc( const Point &rPt ) const
     165             : {
     166           0 :     if( GetLayout() )
     167             :     {
     168             :         const SwPageFrm* pPage =
     169           0 :             static_cast<const SwPageFrm*>( GetLayout()->Lower() );
     170           0 :         if( pPage )
     171             :         {
     172           0 :             while( pPage->GetNext() && rPt.Y() > pPage->Frm().Bottom() )
     173           0 :                 pPage = static_cast<const SwPageFrm*>( pPage->GetNext() );
     174           0 :             SwDoc *pMyDoc = GetDoc();
     175           0 :             for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
     176             :             {
     177           0 :                 if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) )
     178           0 :                     return i;
     179             :             }
     180             :         }
     181             :     }
     182           0 :     return 0;
     183             : }
     184             : 
     185           0 : sal_uInt16 SwFEShell::GetCurPageDesc( const sal_Bool bCalcFrm ) const
     186             : {
     187           0 :     const SwFrm *pFrm = GetCurrFrm( bCalcFrm );
     188           0 :     if ( pFrm )
     189             :     {
     190           0 :         const SwPageFrm *pPage = pFrm->FindPageFrm();
     191           0 :         if ( pPage )
     192             :         {
     193           0 :             SwDoc *pMyDoc = GetDoc();
     194           0 :             for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
     195             :             {
     196           0 :                 if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) )
     197           0 :                     return i;
     198             :             }
     199             :         }
     200             :     }
     201           0 :     return 0;
     202             : }
     203             : 
     204             : // if inside all selection only one PageDesc, return this.
     205             : // Otherwise return 0 pointer
     206           0 : const SwPageDesc* SwFEShell::GetSelectedPageDescs() const
     207             : {
     208             :     const SwCntntNode* pCNd;
     209             :     const SwFrm* pMkFrm, *pPtFrm;
     210           0 :     const SwPageDesc* pFnd, *pRetDesc = (SwPageDesc*)0xffffffff;
     211           0 :     const Point aNulPt;
     212             : 
     213           0 :     FOREACHPAM_START(GetCrsr())
     214             : 
     215           0 :         if( 0 != (pCNd = PCURCRSR->GetCntntNode() ) &&
     216           0 :             0 != ( pPtFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, false )) )
     217           0 :             pPtFrm = pPtFrm->FindPageFrm();
     218             :         else
     219           0 :             pPtFrm = 0;
     220             : 
     221           0 :         if( PCURCRSR->HasMark() &&
     222           0 :             0 != (pCNd = PCURCRSR->GetCntntNode( false ) ) &&
     223           0 :             0 != ( pMkFrm = pCNd->getLayoutFrm( GetLayout(), &aNulPt, 0, false )) )
     224           0 :             pMkFrm = pMkFrm->FindPageFrm();
     225             :         else
     226           0 :             pMkFrm = pPtFrm;
     227             : 
     228           0 :         if( !pMkFrm || !pPtFrm )
     229           0 :             pFnd = 0;
     230           0 :         else if( pMkFrm == pPtFrm )
     231           0 :             pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc();
     232             :         else
     233             :         {
     234             :             // swap pointer if PtFrm before MkFrm
     235           0 :             if( ((SwPageFrm*)pMkFrm)->GetPhyPageNum() >
     236           0 :                 ((SwPageFrm*)pPtFrm)->GetPhyPageNum() )
     237             :             {
     238           0 :                 const SwFrm* pTmp = pMkFrm; pMkFrm = pPtFrm; pPtFrm = pTmp;
     239             :             }
     240             : 
     241             :             // now check from MkFrm to PtFrm for equal PageDescs
     242           0 :             pFnd = ((SwPageFrm*)pMkFrm)->GetPageDesc();
     243           0 :             while( pFnd && pMkFrm != pPtFrm )
     244             :             {
     245           0 :                 pMkFrm = pMkFrm->GetNext();
     246           0 :                 if( !pMkFrm || pFnd != ((SwPageFrm*)pMkFrm)->GetPageDesc() )
     247           0 :                     pFnd = 0;
     248             :             }
     249             :         }
     250             : 
     251           0 :         if( (SwPageDesc*)0xffffffff == pRetDesc )
     252           0 :             pRetDesc = pFnd;
     253           0 :         else if( pFnd != pRetDesc )
     254             :         {
     255           0 :             pRetDesc = 0;
     256           0 :             break;
     257             :         }
     258             : 
     259           0 :     FOREACHPAM_END()
     260             : 
     261           0 :     return pRetDesc;
     262             : }
     263             : 
     264             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10