LCOV - code coverage report
Current view: top level - sw/source/core/crsr - trvlreg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 140 11.4 %
Date: 2012-08-25 Functions: 3 8 37.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 260 5.4 %

           Branch data     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 <crsrsh.hxx>
      21                 :            : #include <doc.hxx>
      22                 :            : #include <swcrsr.hxx>
      23                 :            : #include <docary.hxx>
      24                 :            : #include <fmtcntnt.hxx>
      25                 :            : #include <viscrs.hxx>
      26                 :            : #include <callnk.hxx>
      27                 :            : #include <pamtyp.hxx>
      28                 :            : #include <section.hxx>
      29                 :            : 
      30                 :            : 
      31                 :            : 
      32                 :          0 : sal_Bool GotoPrevRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
      33                 :            :                         sal_Bool bInReadOnly )
      34                 :            : {
      35         [ #  # ]:          0 :     SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
      36         [ #  # ]:          0 :     SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
      37         [ #  # ]:          0 :     if( pNd )
      38         [ #  # ]:          0 :         aIdx.Assign( *pNd, - 1 );
      39                 :            : 
      40         [ #  # ]:          0 :     do {
      41   [ #  #  #  # ]:          0 :         while( aIdx.GetIndex() &&
                 [ #  # ]
      42                 :          0 :             0 == ( pNd = aIdx.GetNode().StartOfSectionNode()->GetSectionNode()) )
      43         [ #  # ]:          0 :             aIdx--;
      44                 :            : 
      45         [ #  # ]:          0 :         if( pNd ) // is there another section node?
      46                 :            :         {
      47         [ #  # ]:          0 :             if( pNd->GetSection().IsHiddenFlag() ||
           [ #  #  #  # ]
                 [ #  # ]
      48                 :            :                 ( !bInReadOnly &&
      49                 :          0 :                   pNd->GetSection().IsProtectFlag() ))
      50                 :            :             {
      51                 :            :                 // skip protected or hidden ones
      52         [ #  # ]:          0 :                 aIdx.Assign( *pNd, - 1 );
      53                 :            :             }
      54         [ #  # ]:          0 :             else if( fnPosRegion == fnMoveForward )
      55                 :            :             {
      56         [ #  # ]:          0 :                 aIdx = *pNd;
      57                 :          0 :                 SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
      58         [ #  # ]:          0 :                                                 sal_True, !bInReadOnly );
      59         [ #  # ]:          0 :                 if( !pCNd )
      60                 :            :                 {
      61         [ #  # ]:          0 :                     aIdx--;
      62                 :          0 :                     continue;
      63                 :            :                 }
      64 [ #  # ][ #  # ]:          0 :                 rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
      65                 :            :             }
      66                 :            :             else
      67                 :            :             {
      68         [ #  # ]:          0 :                 aIdx = *pNd->EndOfSectionNode();
      69                 :          0 :                 SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
      70         [ #  # ]:          0 :                                                 sal_True, !bInReadOnly );
      71         [ #  # ]:          0 :                 if( !pCNd )
      72                 :            :                 {
      73         [ #  # ]:          0 :                     aIdx.Assign( *pNd, - 1 );
      74                 :          0 :                     continue;
      75                 :            :                 }
      76 [ #  # ][ #  # ]:          0 :                 rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
                 [ #  # ]
      77                 :            :             }
      78                 :            : 
      79         [ #  # ]:          0 :             rCurCrsr.GetPoint()->nNode = aIdx;
      80                 :          0 :             return sal_True;
      81                 :            :         }
      82                 :            :     } while( pNd );
      83         [ #  # ]:          0 :     return sal_False;
      84                 :            : }
      85                 :            : 
      86                 :            : 
      87                 :          0 : sal_Bool GotoNextRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
      88                 :            :                         sal_Bool bInReadOnly )
      89                 :            : {
      90         [ #  # ]:          0 :     SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
      91         [ #  # ]:          0 :     SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
      92         [ #  # ]:          0 :     if( pNd )
      93         [ #  # ]:          0 :         aIdx.Assign( *pNd->EndOfSectionNode(), - 1 );
      94                 :            : 
      95                 :          0 :     sal_uLong nEndCount = aIdx.GetNode().GetNodes().Count()-1;
      96         [ #  # ]:          0 :     do {
      97   [ #  #  #  # ]:          0 :         while( aIdx.GetIndex() < nEndCount &&
                 [ #  # ]
      98                 :          0 :                 0 == ( pNd = aIdx.GetNode().GetSectionNode()) )
      99         [ #  # ]:          0 :             aIdx++;
     100                 :            : 
     101         [ #  # ]:          0 :         if( pNd ) // is there another section node?
     102                 :            :         {
     103         [ #  # ]:          0 :             if( pNd->GetSection().IsHiddenFlag() ||
           [ #  #  #  # ]
                 [ #  # ]
     104                 :            :                 ( !bInReadOnly &&
     105                 :          0 :                   pNd->GetSection().IsProtectFlag() ))
     106                 :            :             {
     107                 :            :                 // skip protected or hidden ones
     108         [ #  # ]:          0 :                 aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
     109                 :            :             }
     110         [ #  # ]:          0 :             else if( fnPosRegion == fnMoveForward )
     111                 :            :             {
     112         [ #  # ]:          0 :                 aIdx = *pNd;
     113                 :          0 :                 SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
     114         [ #  # ]:          0 :                                                 sal_True, !bInReadOnly );
     115         [ #  # ]:          0 :                 if( !pCNd )
     116                 :            :                 {
     117         [ #  # ]:          0 :                     aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
     118                 :          0 :                     continue;
     119                 :            :                 }
     120 [ #  # ][ #  # ]:          0 :                 rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
     121                 :            :             }
     122                 :            :             else
     123                 :            :             {
     124         [ #  # ]:          0 :                 aIdx = *pNd->EndOfSectionNode();
     125                 :          0 :                 SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
     126         [ #  # ]:          0 :                                                 sal_True, !bInReadOnly );
     127         [ #  # ]:          0 :                 if( !pCNd )
     128                 :            :                 {
     129         [ #  # ]:          0 :                     aIdx++;
     130                 :          0 :                     continue;
     131                 :            :                 }
     132 [ #  # ][ #  # ]:          0 :                 rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
                 [ #  # ]
     133                 :            :             }
     134                 :            : 
     135         [ #  # ]:          0 :             rCurCrsr.GetPoint()->nNode = aIdx;
     136                 :          0 :             return sal_True;
     137                 :            :         }
     138                 :            :     } while( pNd );
     139         [ #  # ]:          0 :     return sal_False;
     140                 :            : }
     141                 :            : 
     142                 :            : 
     143                 :          0 : sal_Bool GotoCurrRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
     144                 :            :                         sal_Bool bInReadOnly )
     145                 :            : {
     146                 :          0 :     SwSectionNode* pNd = rCurCrsr.GetNode()->FindSectionNode();
     147         [ #  # ]:          0 :     if( !pNd )
     148                 :          0 :         return sal_False;
     149                 :            : 
     150                 :          0 :     SwPosition* pPos = rCurCrsr.GetPoint();
     151                 :          0 :     sal_Bool bMoveBackward = fnPosRegion == fnMoveBackward;
     152                 :            : 
     153                 :            :     SwCntntNode* pCNd;
     154         [ #  # ]:          0 :     if( bMoveBackward )
     155                 :            :     {
     156         [ #  # ]:          0 :         SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
     157 [ #  # ][ #  # ]:          0 :         pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
     158                 :            :     }
     159                 :            :     else
     160                 :            :     {
     161         [ #  # ]:          0 :         SwNodeIndex aIdx( *pNd );
     162 [ #  # ][ #  # ]:          0 :         pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
     163                 :            :     }
     164                 :            : 
     165         [ #  # ]:          0 :     if( pCNd )
     166                 :            :     {
     167                 :          0 :         pPos->nNode = *pCNd;
     168         [ #  # ]:          0 :         xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
     169         [ #  # ]:          0 :         pPos->nContent.Assign( pCNd, nTmpPos );
     170                 :            :     }
     171                 :          0 :     return 0 != pCNd;
     172                 :            : }
     173                 :            : 
     174                 :            : 
     175                 :         32 : sal_Bool GotoCurrRegionAndSkip( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
     176                 :            :                                 sal_Bool bInReadOnly )
     177                 :            : {
     178                 :         32 :     SwNode* pCurrNd = rCurCrsr.GetNode();
     179                 :         32 :     SwSectionNode* pNd = pCurrNd->FindSectionNode();
     180         [ +  - ]:         32 :     if( !pNd )
     181                 :         32 :         return sal_False;
     182                 :            : 
     183                 :          0 :     SwPosition* pPos = rCurCrsr.GetPoint();
     184                 :          0 :     xub_StrLen nCurrCnt = pPos->nContent.GetIndex();
     185                 :          0 :     sal_Bool bMoveBackward = fnPosRegion == fnMoveBackward;
     186                 :            : 
     187         [ #  # ]:          0 :     do {
     188                 :            :         SwCntntNode* pCNd;
     189         [ #  # ]:          0 :         if( bMoveBackward ) // to the end of the section
     190                 :            :         {
     191         [ #  # ]:          0 :             SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
     192         [ #  # ]:          0 :             pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
     193         [ #  # ]:          0 :             if( !pCNd )
     194                 :          0 :                 return sal_False;
     195 [ #  # ][ #  # ]:          0 :             pPos->nNode = aIdx;
                 [ #  # ]
     196                 :            :         }
     197                 :            :         else
     198                 :            :         {
     199         [ #  # ]:          0 :             SwNodeIndex aIdx( *pNd );
     200         [ #  # ]:          0 :             pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
     201         [ #  # ]:          0 :             if( !pCNd )
     202                 :          0 :                 return sal_False;
     203 [ #  # ][ #  # ]:          0 :             pPos->nNode = aIdx;
                 [ #  # ]
     204                 :            :         }
     205                 :            : 
     206         [ #  # ]:          0 :         xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
     207         [ #  # ]:          0 :         pPos->nContent.Assign( pCNd, nTmpPos );
     208                 :            : 
     209         [ #  # ]:          0 :         if( &pPos->nNode.GetNode() != pCurrNd ||
           [ #  #  #  # ]
     210                 :          0 :             pPos->nContent.GetIndex() != nCurrCnt )
     211                 :            :             // there was a change
     212                 :          0 :             return sal_True;
     213                 :            : 
     214                 :            :         // try also the parent of this section
     215                 :          0 :         SwSection* pParent = pNd->GetSection().GetParent();
     216         [ #  # ]:          0 :         pNd = pParent ? pParent->GetFmt()->GetSectionNode() : 0;
     217                 :            :     } while( pNd );
     218                 :         32 :     return sal_False;
     219                 :            : }
     220                 :            : 
     221                 :            : 
     222                 :            : 
     223                 :         32 : sal_Bool SwCursor::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
     224                 :            : {
     225         [ +  - ]:         32 :     SwCrsrSaveState aSaveState( *this );
     226         [ +  - ]:         32 :     return !dynamic_cast<SwTableCursor*>(this) &&
     227 [ +  - ][ +  - ]:         32 :             (*fnWhichRegion)( *this, fnPosRegion, IsReadOnlyAvailable()  ) &&
     228         [ #  # ]:          0 :             !IsSelOvr() &&
     229                 :          0 :             ( GetPoint()->nNode.GetIndex() != pSavePos->nNode ||
     230 [ +  - ][ -  + ]:         64 :                 GetPoint()->nContent.GetIndex() != pSavePos->nCntnt );
           [ #  #  #  # ]
         [ #  # ][ +  - ]
     231                 :            : }
     232                 :            : 
     233                 :         32 : sal_Bool SwCrsrShell::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
     234                 :            : {
     235         [ +  - ]:         32 :     SwCallLink aLk( *this ); // watch Crsr-Moves;call Link if needed
     236 [ +  - ][ +  - ]:         32 :     sal_Bool bRet = !pTblCrsr && pCurCrsr->MoveRegion( fnWhichRegion, fnPosRegion );
                 [ -  + ]
     237         [ -  + ]:         32 :     if( bRet )
     238         [ #  # ]:          0 :         UpdateCrsr();
     239         [ +  - ]:         32 :     return bRet;
     240                 :            : }
     241                 :            : 
     242                 :            : 
     243                 :          0 : sal_Bool SwCursor::GotoRegion( const String& rName )
     244                 :            : {
     245                 :          0 :     sal_Bool bRet = sal_False;
     246                 :          0 :     const SwSectionFmts& rFmts = GetDoc()->GetSections();
     247         [ #  # ]:          0 :     for( sal_uInt16 n = rFmts.size(); n; )
     248                 :            :     {
     249                 :          0 :         const SwSectionFmt* pFmt = rFmts[ --n ];
     250                 :            :         const SwNodeIndex* pIdx;
     251                 :            :         const SwSection* pSect;
     252 [ #  # ][ #  #  :          0 :         if( 0 != ( pSect = pFmt->GetSection() ) &&
          #  #  #  #  #  
                      # ]
     253                 :          0 :             pSect->GetSectionName() == rName &&
     254                 :          0 :             0 != ( pIdx = pFmt->GetCntnt().GetCntntIdx() ) &&
     255                 :          0 :             pIdx->GetNode().GetNodes().IsDocNodes() )
     256                 :            :         {
     257                 :            :             // area in normal nodes array
     258         [ #  # ]:          0 :             SwCrsrSaveState aSaveState( *this );
     259                 :            : 
     260         [ #  # ]:          0 :             GetPoint()->nNode = *pIdx;
     261         [ #  # ]:          0 :             Move( fnMoveForward, fnGoCntnt );
     262 [ #  # ][ #  # ]:          0 :             bRet = !IsSelOvr();
     263                 :            :         }
     264                 :            :     }
     265                 :          0 :     return bRet;
     266                 :            : }
     267                 :            : 
     268                 :          0 : sal_Bool SwCrsrShell::GotoRegion( const String& rName )
     269                 :            : {
     270         [ #  # ]:          0 :     SwCallLink aLk( *this ); // watch Crsr-Moves;call Link if needed
     271 [ #  # ][ #  # ]:          0 :     sal_Bool bRet = !pTblCrsr && pCurCrsr->GotoRegion( rName );
                 [ #  # ]
     272         [ #  # ]:          0 :     if( bRet )
     273                 :            :         UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
     274         [ #  # ]:          0 :                     SwCrsrShell::READONLY );
     275         [ #  # ]:          0 :     return bRet;
     276                 :            : }
     277                 :            : 
     278                 :            : 
     279                 :            : 
     280                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10