LCOV - code coverage report
Current view: top level - sw/source/core/crsr - unocrsr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 95 122 77.9 %
Date: 2012-08-25 Functions: 17 21 81.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 109 256 42.6 %

           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                 :            : #include <unocrsr.hxx>
      30                 :            : #include <doc.hxx>
      31                 :            : #include <swtable.hxx>
      32                 :            : #include <docary.hxx>
      33                 :            : #include <rootfrm.hxx>
      34                 :            : 
      35                 :         73 : IMPL_FIXEDMEMPOOL_NEWDEL( SwUnoCrsr )
      36                 :            : 
      37                 :      38328 : SwUnoCrsr::SwUnoCrsr( const SwPosition &rPos, SwPaM* pRing )
      38                 :            :     : SwCursor( rPos, pRing, false ), SwModify( 0 ),
      39                 :            :     bRemainInSection( sal_True ),
      40                 :            :     bSkipOverHiddenSections( sal_False ),
      41 [ +  - ][ +  - ]:      38328 :     bSkipOverProtectSections( sal_False )
      42                 :            : 
      43                 :      38328 : {}
      44                 :            : 
      45 [ +  - ][ +  - ]:      76609 : SwUnoCrsr::~SwUnoCrsr()
      46                 :            : {
      47                 :      38328 :     SwDoc* pDoc = GetDoc();
      48   [ +  +  +  + ]:      38328 :     if( !pDoc->IsInDtor() )
      49                 :            :     {
      50                 :            :         // then remove cursor from array
      51                 :      34368 :         SwUnoCrsrTbl& rTbl = (SwUnoCrsrTbl&)pDoc->GetUnoCrsrTbl();
      52 [ +  - ][ +  - ]:      34368 :         if( !rTbl.erase( this ) )
      53                 :            :         {
      54                 :            :             OSL_ENSURE( !this, "UNO Cursor nicht mehr im Array" );
      55                 :            :         }
      56                 :            :     }
      57                 :            : 
      58                 :            :     // delete the whole ring
      59 [ +  + ][ -  + ]:      38468 :     while( GetNext() != this )
      60                 :            :     {
      61                 :        140 :         Ring* pNxt = GetNext();
      62   [ +  -  #  # ]:        140 :         pNxt->MoveTo( 0 ); // remove from chain
      63 [ +  - ][ +  - ]:        140 :         delete pNxt;       // and delete
         [ #  # ][ #  # ]
      64                 :            :     }
      65 [ +  - ][ -  + ]:     114890 : }
         [ #  # ][ -  + ]
         [ -  + ][ #  # ]
      66                 :            : 
      67                 :          0 : SwUnoCrsr * SwUnoCrsr::Clone() const
      68                 :            : {
      69                 :          0 :     SwUnoCrsr * pNewCrsr = GetDoc()->CreateUnoCrsr( *GetPoint() );
      70         [ #  # ]:          0 :     if (HasMark())
      71                 :            :     {
      72                 :          0 :         pNewCrsr->SetMark();
      73                 :          0 :         *pNewCrsr->GetMark() = *GetMark();
      74                 :            :     }
      75                 :          0 :     return pNewCrsr;
      76                 :            : }
      77                 :            : 
      78                 :          0 : SwUnoTableCrsr * SwUnoTableCrsr::Clone() const
      79                 :            : {
      80                 :            :     SwUnoTableCrsr * pNewCrsr = dynamic_cast<SwUnoTableCrsr*>(
      81                 :            :         GetDoc()->CreateUnoCrsr(
      82         [ #  # ]:          0 :             *GetPoint(), sal_True /* create SwUnoTableCrsr */ ) );
      83                 :            :     OSL_ENSURE(pNewCrsr, "Clone: cannot create SwUnoTableCrsr?");
      84         [ #  # ]:          0 :     if (HasMark())
      85                 :            :     {
      86                 :          0 :         pNewCrsr->SetMark();
      87                 :          0 :         *pNewCrsr->GetMark() = *GetMark();
      88                 :            :     }
      89                 :          0 :     return pNewCrsr;
      90                 :            : }
      91                 :            : 
      92                 :            : 
      93                 :         46 : bool SwUnoCrsr::IsReadOnlyAvailable() const
      94                 :            : {
      95                 :         46 :     return true;
      96                 :            : }
      97                 :            : 
      98                 :            : const SwCntntFrm*
      99                 :      13334 : SwUnoCrsr::DoSetBidiLevelLeftRight( sal_Bool &, sal_Bool, sal_Bool )
     100                 :            : {
     101                 :      13334 :     return 0; // not for uno cursor
     102                 :            : }
     103                 :            : 
     104                 :          6 : void SwUnoCrsr::DoSetBidiLevelUpDown()
     105                 :            : {
     106                 :          6 :     return; // not for uno cursor
     107                 :            : }
     108                 :            : 
     109                 :      13374 : sal_Bool SwUnoCrsr::IsSelOvr( int eFlags )
     110                 :            : {
     111         [ +  + ]:      13374 :     if( bRemainInSection )
     112                 :            :     {
     113                 :      12875 :         SwDoc* pDoc = GetDoc();
     114 [ +  - ][ +  - ]:      12875 :         SwNodeIndex aOldIdx( *pDoc->GetNodes()[ GetSavePos()->nNode ] );
                 [ +  - ]
     115                 :      12875 :         SwNodeIndex& rPtIdx = GetPoint()->nNode;
     116                 :      12875 :         SwStartNode *pOldSttNd = aOldIdx.GetNode().StartOfSectionNode(),
     117                 :      12875 :                     *pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
     118         [ +  + ]:      12875 :         if( pOldSttNd != pNewSttNd )
     119                 :            :         {
     120                 :        513 :             sal_Bool bMoveDown = GetSavePos()->nNode < rPtIdx.GetIndex();
     121                 :        513 :             sal_Bool bValidPos = sal_False;
     122                 :            : 
     123                 :            :             // search the correct surrounded start node - which the index
     124                 :            :             // can't leave.
     125         [ +  + ]:        636 :             while( pOldSttNd->IsSectionNode() )
     126                 :        123 :                 pOldSttNd = pOldSttNd->StartOfSectionNode();
     127                 :            : 
     128                 :            :             // is the new index inside this surrounded section?
     129         [ +  - ]:       1026 :             if( rPtIdx > *pOldSttNd &&
           [ +  -  +  + ]
         [ +  - ][ +  - ]
           [ +  +  #  # ]
     130                 :        513 :                 rPtIdx < pOldSttNd->EndOfSectionIndex() )
     131                 :            :             {
     132                 :            :                 // check if it a valid move inside this section
     133                 :            :                 // (only over SwSection's !)
     134                 :            :                 const SwStartNode* pInvalidNode;
     135         [ -  + ]:        168 :                 do {
     136                 :        168 :                     pInvalidNode = 0;
     137                 :        168 :                     pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
     138                 :            : 
     139                 :        168 :                     const SwStartNode *pSttNd = pNewSttNd, *pEndNd = pOldSttNd;
     140         [ -  + ]:        336 :                     if( pSttNd->EndOfSectionIndex() >
     141                 :        168 :                         pEndNd->EndOfSectionIndex() )
     142                 :            :                     {
     143                 :          0 :                         pEndNd = pNewSttNd;
     144                 :          0 :                         pSttNd = pOldSttNd;
     145                 :            :                     }
     146                 :            : 
     147         [ +  + ]:        331 :                     while( pSttNd->GetIndex() > pEndNd->GetIndex() )
     148                 :            :                     {
     149         [ +  + ]:        163 :                         if( !pSttNd->IsSectionNode() )
     150                 :         12 :                             pInvalidNode = pSttNd;
     151                 :        163 :                         pSttNd = pSttNd->StartOfSectionNode();
     152                 :            :                     }
     153         [ +  + ]:        168 :                     if( pInvalidNode )
     154                 :            :                     {
     155         [ -  + ]:          6 :                         if( bMoveDown )
     156                 :            :                         {
     157         [ #  # ]:          0 :                             rPtIdx.Assign( *pInvalidNode->EndOfSectionNode(), 1 );
     158                 :            : 
     159         [ #  # ]:          0 :                             if( !rPtIdx.GetNode().IsCntntNode() &&
           [ #  #  #  # ]
                 [ #  # ]
     160 [ #  # ][ #  # ]:          0 :                                 ( !pDoc->GetNodes().GoNextSection( &rPtIdx ) ||
     161                 :          0 :                                   rPtIdx > pOldSttNd->EndOfSectionIndex() ) )
     162                 :          0 :                                 break;
     163                 :            :                         }
     164                 :            :                         else
     165                 :            :                         {
     166         [ +  - ]:          6 :                             rPtIdx.Assign( *pInvalidNode, -1 );
     167                 :            : 
     168         [ +  - ]:         21 :                             if( !rPtIdx.GetNode().IsCntntNode() &&
           [ +  +  +  - ]
                 [ +  - ]
     169 [ +  - ][ +  - ]:          6 :                                 ( !pDoc->GetNodes().GoPrevSection( &rPtIdx ) ||
     170 [ +  - ][ +  + ]:          9 :                                   rPtIdx < *pOldSttNd ) )
         [ +  - ][ #  # ]
     171                 :          6 :                                 break;
     172                 :            :                         }
     173                 :            :                     }
     174                 :            :                     else
     175                 :        162 :                         bValidPos = sal_True;
     176                 :            :                 } while ( pInvalidNode );
     177                 :            :             }
     178                 :            : 
     179         [ +  + ]:        513 :             if( bValidPos )
     180                 :            :             {
     181                 :        162 :                 SwCntntNode* pCNd = GetCntntNode();
     182                 :        162 :                 sal_uInt16 nCnt = 0;
     183 [ +  + ][ +  - ]:        162 :                 if( pCNd && !bMoveDown )
     184         [ +  - ]:         95 :                     nCnt = pCNd->Len();
     185 [ +  - ][ +  - ]:        162 :                 GetPoint()->nContent.Assign( pCNd, nCnt );
     186                 :            :             }
     187                 :            :             else
     188                 :            :             {
     189         [ +  - ]:        351 :                 rPtIdx = GetSavePos()->nNode;
     190 [ +  - ][ +  - ]:        351 :                 GetPoint()->nContent.Assign( GetCntntNode(), GetSavePos()->nCntnt );
     191                 :      12875 :                 return sal_True;
     192                 :            :             }
     193 [ +  - ][ +  + ]:      12875 :         }
     194                 :            :     }
     195                 :      13374 :     return SwCursor::IsSelOvr( eFlags );
     196                 :            : }
     197                 :            : 
     198                 :            : 
     199                 :            : 
     200                 :         47 : SwUnoTableCrsr::SwUnoTableCrsr(const SwPosition& rPos)
     201 [ +  - ][ +  - ]:         47 :     : SwCursor(rPos,0,false), SwUnoCrsr(rPos), SwTableCursor(rPos), aTblSel(rPos,0,false)
         [ +  - ][ #  # ]
     202                 :            : {
     203                 :         47 :     SetRemainInSection(sal_False);
     204                 :         47 : }
     205                 :            : 
     206 [ +  - ][ +  - ]:        188 : SwUnoTableCrsr::~SwUnoTableCrsr()
         [ +  - ][ #  # ]
         [ #  # ][ #  # ]
     207                 :            : {
     208 [ +  + ][ #  # ]:        323 :     while( aTblSel.GetNext() != &aTblSel )
     209 [ +  - ][ +  - ]:        276 :         delete aTblSel.GetNext();
         [ #  # ][ #  # ]
     210 [ +  - ][ +  - ]:        235 : }
         [ +  - ][ -  + ]
           [ #  #  #  #  
           #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
     211                 :            : 
     212                 :         30 : sal_Bool SwUnoTableCrsr::IsSelOvr( int eFlags )
     213                 :            : {
     214                 :         30 :     sal_Bool bRet = SwUnoCrsr::IsSelOvr( eFlags );
     215         [ +  - ]:         30 :     if( !bRet )
     216                 :            :     {
     217                 :         30 :         const SwTableNode* pTNd = GetPoint()->nNode.GetNode().FindTableNode();
     218                 :         30 :         bRet = !(pTNd == GetDoc()->GetNodes()[ GetSavePos()->nNode ]->
     219                 :         60 :                 FindTableNode() && (!HasMark() ||
     220         [ -  + ]:         60 :                 pTNd == GetMark()->nNode.GetNode().FindTableNode() ));
           [ +  -  +  + ]
     221                 :            :     }
     222                 :         30 :     return bRet;
     223                 :            : }
     224                 :            : 
     225                 :        663 : void SwUnoTableCrsr::MakeBoxSels()
     226                 :            : {
     227                 :            :     const SwCntntNode* pCNd;
     228                 :        663 :     bool bMakeTblCrsrs = true;
     229 [ +  - ][ +  - ]:       1989 :     if( GetPoint()->nNode.GetIndex() && GetMark()->nNode.GetIndex() &&
           [ +  -  +  - ]
           [ +  -  +  - ]
                 [ +  - ]
     230                 :        663 :             0 != ( pCNd = GetCntntNode() ) && pCNd->getLayoutFrm( pCNd->GetDoc()->GetCurrentLayout() ) &&
     231                 :        663 :             0 != ( pCNd = GetCntntNode(sal_False) ) && pCNd->getLayoutFrm( pCNd->GetDoc()->GetCurrentLayout() ) )
     232                 :        663 :         bMakeTblCrsrs = GetDoc()->GetCurrentLayout()->MakeTblCrsrs( *this );
     233                 :            : 
     234         [ -  + ]:        663 :     if ( !bMakeTblCrsrs )
     235                 :            :     {
     236                 :          0 :         SwSelBoxes& rTmpBoxes = (SwSelBoxes&)GetBoxes();
     237                 :          0 :         sal_uInt16 nCount = 0;
     238         [ #  # ]:          0 :         while( nCount < rTmpBoxes.size() )
     239                 :          0 :             DeleteBox( nCount );
     240                 :            :     }
     241                 :            : 
     242         [ +  + ]:        663 :     if( IsChgd() )
     243                 :            :     {
     244                 :         61 :         SwTableCursor::MakeBoxSels( &aTblSel );
     245         [ -  + ]:         61 :         if( !GetBoxesCount() )
     246                 :            :         {
     247                 :            :             const SwTableBox* pBox;
     248                 :          0 :             const SwNode* pBoxNd = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
     249         [ #  # ]:          0 :             const SwTableNode* pTblNd = pBoxNd ? pBoxNd->FindTableNode() : 0;
     250 [ #  # ][ #  # ]:          0 :             if( pTblNd && 0 != ( pBox = pTblNd->GetTable().GetTblBox( pBoxNd->GetIndex() )) )
                 [ #  # ]
     251                 :          0 :                 InsertBox( *pBox );
     252                 :            :         }
     253                 :            :     }
     254                 :        663 : }
     255                 :            : 
     256                 :       1458 : SwUnoCrsrTbl::~SwUnoCrsrTbl()
     257                 :            : {
     258         [ +  + ]:       5418 :     while (!empty())
     259                 :            :     {
     260 [ +  - ][ +  - ]:       3960 :         delete *begin();
     261         [ +  - ]:       3960 :         erase( begin() );
     262                 :            :     }
     263 [ +  - ][ +  - ]:       1677 : }
     264                 :            : 
     265                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10