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

Generated by: LCOV version 1.10