Files
libreoffice/sw/source/core/crsr/trvlreg.cxx
Noel Grandin 9eace9e083 convert sw/inc/crsrsh.hxx from String to OUString
Change-Id: Ic3e4e0372593bdc28705ebc8f8f462b062f3da3e
2013-10-15 12:25:39 +02:00

269 lines
8.8 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <crsrsh.hxx>
#include <doc.hxx>
#include <swcrsr.hxx>
#include <docary.hxx>
#include <fmtcntnt.hxx>
#include <viscrs.hxx>
#include <callnk.hxx>
#include <pamtyp.hxx>
#include <section.hxx>
sal_Bool GotoPrevRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
sal_Bool bInReadOnly )
{
SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
if( pNd )
aIdx.Assign( *pNd, - 1 );
do {
while( aIdx.GetIndex() &&
0 == ( pNd = aIdx.GetNode().StartOfSectionNode()->GetSectionNode()) )
aIdx--;
if( pNd ) // is there another section node?
{
if( pNd->GetSection().IsHiddenFlag() ||
( !bInReadOnly &&
pNd->GetSection().IsProtectFlag() ))
{
// skip protected or hidden ones
aIdx.Assign( *pNd, - 1 );
}
else if( fnPosRegion == fnMoveForward )
{
aIdx = *pNd;
SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
sal_True, !bInReadOnly );
if( !pCNd )
{
aIdx--;
continue;
}
rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
}
else
{
aIdx = *pNd->EndOfSectionNode();
SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
sal_True, !bInReadOnly );
if( !pCNd )
{
aIdx.Assign( *pNd, - 1 );
continue;
}
rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
}
rCurCrsr.GetPoint()->nNode = aIdx;
return sal_True;
}
} while( pNd );
return sal_False;
}
sal_Bool GotoNextRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
sal_Bool bInReadOnly )
{
SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
if( pNd )
aIdx.Assign( *pNd->EndOfSectionNode(), - 1 );
sal_uLong nEndCount = aIdx.GetNode().GetNodes().Count()-1;
do {
while( aIdx.GetIndex() < nEndCount &&
0 == ( pNd = aIdx.GetNode().GetSectionNode()) )
++aIdx;
if( pNd ) // is there another section node?
{
if( pNd->GetSection().IsHiddenFlag() ||
( !bInReadOnly &&
pNd->GetSection().IsProtectFlag() ))
{
// skip protected or hidden ones
aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
}
else if( fnPosRegion == fnMoveForward )
{
aIdx = *pNd;
SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
sal_True, !bInReadOnly );
if( !pCNd )
{
aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
continue;
}
rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
}
else
{
aIdx = *pNd->EndOfSectionNode();
SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
sal_True, !bInReadOnly );
if( !pCNd )
{
++aIdx;
continue;
}
rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
}
rCurCrsr.GetPoint()->nNode = aIdx;
return sal_True;
}
} while( pNd );
return sal_False;
}
sal_Bool GotoCurrRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
sal_Bool bInReadOnly )
{
SwSectionNode* pNd = rCurCrsr.GetNode()->FindSectionNode();
if( !pNd )
return sal_False;
SwPosition* pPos = rCurCrsr.GetPoint();
bool bMoveBackward = fnPosRegion == fnMoveBackward;
SwCntntNode* pCNd;
if( bMoveBackward )
{
SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
}
else
{
SwNodeIndex aIdx( *pNd );
pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
}
if( pCNd )
{
pPos->nNode = *pCNd;
xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
pPos->nContent.Assign( pCNd, nTmpPos );
}
return 0 != pCNd;
}
sal_Bool GotoCurrRegionAndSkip( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
sal_Bool bInReadOnly )
{
SwNode* pCurrNd = rCurCrsr.GetNode();
SwSectionNode* pNd = pCurrNd->FindSectionNode();
if( !pNd )
return sal_False;
SwPosition* pPos = rCurCrsr.GetPoint();
xub_StrLen nCurrCnt = pPos->nContent.GetIndex();
bool bMoveBackward = fnPosRegion == fnMoveBackward;
do {
SwCntntNode* pCNd;
if( bMoveBackward ) // to the end of the section
{
SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
if( !pCNd )
return sal_False;
pPos->nNode = aIdx;
}
else
{
SwNodeIndex aIdx( *pNd );
pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
if( !pCNd )
return sal_False;
pPos->nNode = aIdx;
}
xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
pPos->nContent.Assign( pCNd, nTmpPos );
if( &pPos->nNode.GetNode() != pCurrNd ||
pPos->nContent.GetIndex() != nCurrCnt )
// there was a change
return sal_True;
// try also the parent of this section
SwSection* pParent = pNd->GetSection().GetParent();
pNd = pParent ? pParent->GetFmt()->GetSectionNode() : 0;
} while( pNd );
return sal_False;
}
sal_Bool SwCursor::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
{
SwCrsrSaveState aSaveState( *this );
return !dynamic_cast<SwTableCursor*>(this) &&
(*fnWhichRegion)( *this, fnPosRegion, IsReadOnlyAvailable() ) &&
!IsSelOvr() &&
( GetPoint()->nNode.GetIndex() != pSavePos->nNode ||
GetPoint()->nContent.GetIndex() != pSavePos->nCntnt );
}
sal_Bool SwCrsrShell::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
{
SwCallLink aLk( *this ); // watch Crsr-Moves;call Link if needed
sal_Bool bRet = !m_pTblCrsr && m_pCurCrsr->MoveRegion( fnWhichRegion, fnPosRegion );
if( bRet )
UpdateCrsr();
return bRet;
}
bool SwCursor::GotoRegion( const OUString& rName )
{
bool bRet = false;
const SwSectionFmts& rFmts = GetDoc()->GetSections();
for( sal_uInt16 n = rFmts.size(); n; )
{
const SwSectionFmt* pFmt = rFmts[ --n ];
const SwNodeIndex* pIdx = 0;
const SwSection* pSect;
if( 0 != ( pSect = pFmt->GetSection() ) &&
pSect->GetSectionName() == rName &&
0 != ( pIdx = pFmt->GetCntnt().GetCntntIdx() ) &&
pIdx->GetNode().GetNodes().IsDocNodes() )
{
// area in normal nodes array
SwCrsrSaveState aSaveState( *this );
GetPoint()->nNode = *pIdx;
Move( fnMoveForward, fnGoCntnt );
bRet = !IsSelOvr();
}
}
return bRet;
}
bool SwCrsrShell::GotoRegion( const OUString& rName )
{
SwCallLink aLk( *this ); // watch Crsr-Moves;call Link if needed
bool bRet = !m_pTblCrsr && m_pCurCrsr->GotoRegion( rName );
if( bRet )
UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
SwCrsrShell::READONLY );
return bRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */