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

Generated by: LCOV version 1.10