1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
24 #include <fmtcntnt.hxx>
28 #include <section.hxx>
32 sal_Bool
GotoPrevRegion( SwPaM
& rCurCrsr
, SwPosRegion fnPosRegion
,
33 sal_Bool bInReadOnly
)
35 SwNodeIndex
aIdx( rCurCrsr
.GetPoint()->nNode
);
36 SwSectionNode
* pNd
= aIdx
.GetNode().FindSectionNode();
38 aIdx
.Assign( *pNd
, - 1 );
41 while( aIdx
.GetIndex() &&
42 0 == ( pNd
= aIdx
.GetNode().StartOfSectionNode()->GetSectionNode()) )
45 if( pNd
) // is there another section node?
47 if( pNd
->GetSection().IsHiddenFlag() ||
49 pNd
->GetSection().IsProtectFlag() ))
51 // skip protected or hidden ones
52 aIdx
.Assign( *pNd
, - 1 );
54 else if( fnPosRegion
== fnMoveForward
)
57 SwCntntNode
* pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
,
58 sal_True
, !bInReadOnly
);
64 rCurCrsr
.GetPoint()->nContent
.Assign( pCNd
, 0 );
68 aIdx
= *pNd
->EndOfSectionNode();
69 SwCntntNode
* pCNd
= pNd
->GetNodes().GoPrevSection( &aIdx
,
70 sal_True
, !bInReadOnly
);
73 aIdx
.Assign( *pNd
, - 1 );
76 rCurCrsr
.GetPoint()->nContent
.Assign( pCNd
, pCNd
->Len() );
79 rCurCrsr
.GetPoint()->nNode
= aIdx
;
87 sal_Bool
GotoNextRegion( SwPaM
& rCurCrsr
, SwPosRegion fnPosRegion
,
88 sal_Bool bInReadOnly
)
90 SwNodeIndex
aIdx( rCurCrsr
.GetPoint()->nNode
);
91 SwSectionNode
* pNd
= aIdx
.GetNode().FindSectionNode();
93 aIdx
.Assign( *pNd
->EndOfSectionNode(), - 1 );
95 sal_uLong nEndCount
= aIdx
.GetNode().GetNodes().Count()-1;
97 while( aIdx
.GetIndex() < nEndCount
&&
98 0 == ( pNd
= aIdx
.GetNode().GetSectionNode()) )
101 if( pNd
) // is there another section node?
103 if( pNd
->GetSection().IsHiddenFlag() ||
105 pNd
->GetSection().IsProtectFlag() ))
107 // skip protected or hidden ones
108 aIdx
.Assign( *pNd
->EndOfSectionNode(), +1 );
110 else if( fnPosRegion
== fnMoveForward
)
113 SwCntntNode
* pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
,
114 sal_True
, !bInReadOnly
);
117 aIdx
.Assign( *pNd
->EndOfSectionNode(), +1 );
120 rCurCrsr
.GetPoint()->nContent
.Assign( pCNd
, 0 );
124 aIdx
= *pNd
->EndOfSectionNode();
125 SwCntntNode
* pCNd
= pNd
->GetNodes().GoPrevSection( &aIdx
,
126 sal_True
, !bInReadOnly
);
132 rCurCrsr
.GetPoint()->nContent
.Assign( pCNd
, pCNd
->Len() );
135 rCurCrsr
.GetPoint()->nNode
= aIdx
;
143 sal_Bool
GotoCurrRegion( SwPaM
& rCurCrsr
, SwPosRegion fnPosRegion
,
144 sal_Bool bInReadOnly
)
146 SwSectionNode
* pNd
= rCurCrsr
.GetNode()->FindSectionNode();
150 SwPosition
* pPos
= rCurCrsr
.GetPoint();
151 bool bMoveBackward
= fnPosRegion
== fnMoveBackward
;
156 SwNodeIndex
aIdx( *pNd
->EndOfSectionNode() );
157 pCNd
= pNd
->GetNodes().GoPrevSection( &aIdx
, sal_True
, !bInReadOnly
);
161 SwNodeIndex
aIdx( *pNd
);
162 pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
, sal_True
, !bInReadOnly
);
168 xub_StrLen nTmpPos
= bMoveBackward
? pCNd
->Len() : 0;
169 pPos
->nContent
.Assign( pCNd
, nTmpPos
);
175 sal_Bool
GotoCurrRegionAndSkip( SwPaM
& rCurCrsr
, SwPosRegion fnPosRegion
,
176 sal_Bool bInReadOnly
)
178 SwNode
* pCurrNd
= rCurCrsr
.GetNode();
179 SwSectionNode
* pNd
= pCurrNd
->FindSectionNode();
183 SwPosition
* pPos
= rCurCrsr
.GetPoint();
184 xub_StrLen nCurrCnt
= pPos
->nContent
.GetIndex();
185 bool bMoveBackward
= fnPosRegion
== fnMoveBackward
;
189 if( bMoveBackward
) // to the end of the section
191 SwNodeIndex
aIdx( *pNd
->EndOfSectionNode() );
192 pCNd
= pNd
->GetNodes().GoPrevSection( &aIdx
, sal_True
, !bInReadOnly
);
199 SwNodeIndex
aIdx( *pNd
);
200 pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
, sal_True
, !bInReadOnly
);
206 xub_StrLen nTmpPos
= bMoveBackward
? pCNd
->Len() : 0;
207 pPos
->nContent
.Assign( pCNd
, nTmpPos
);
209 if( &pPos
->nNode
.GetNode() != pCurrNd
||
210 pPos
->nContent
.GetIndex() != nCurrCnt
)
211 // there was a change
214 // try also the parent of this section
215 SwSection
* pParent
= pNd
->GetSection().GetParent();
216 pNd
= pParent
? pParent
->GetFmt()->GetSectionNode() : 0;
223 sal_Bool
SwCursor::MoveRegion( SwWhichRegion fnWhichRegion
, SwPosRegion fnPosRegion
)
225 SwCrsrSaveState
aSaveState( *this );
226 return !dynamic_cast<SwTableCursor
*>(this) &&
227 (*fnWhichRegion
)( *this, fnPosRegion
, IsReadOnlyAvailable() ) &&
229 ( GetPoint()->nNode
.GetIndex() != pSavePos
->nNode
||
230 GetPoint()->nContent
.GetIndex() != pSavePos
->nCntnt
);
233 sal_Bool
SwCrsrShell::MoveRegion( SwWhichRegion fnWhichRegion
, SwPosRegion fnPosRegion
)
235 SwCallLink
aLk( *this ); // watch Crsr-Moves;call Link if needed
236 sal_Bool bRet
= !pTblCrsr
&& pCurCrsr
->MoveRegion( fnWhichRegion
, fnPosRegion
);
243 bool SwCursor::GotoRegion( const String
& rName
)
246 const SwSectionFmts
& rFmts
= GetDoc()->GetSections();
247 for( sal_uInt16 n
= rFmts
.size(); n
; )
249 const SwSectionFmt
* pFmt
= rFmts
[ --n
];
250 const SwNodeIndex
* pIdx
;
251 const SwSection
* pSect
;
252 if( 0 != ( pSect
= pFmt
->GetSection() ) &&
253 pSect
->GetSectionName() == rName
&&
254 0 != ( pIdx
= pFmt
->GetCntnt().GetCntntIdx() ) &&
255 pIdx
->GetNode().GetNodes().IsDocNodes() )
257 // area in normal nodes array
258 SwCrsrSaveState
aSaveState( *this );
260 GetPoint()->nNode
= *pIdx
;
261 Move( fnMoveForward
, fnGoCntnt
);
268 bool SwCrsrShell::GotoRegion( const String
& rName
)
270 SwCallLink
aLk( *this ); // watch Crsr-Moves;call Link if needed
271 bool bRet
= !pTblCrsr
&& pCurCrsr
->GotoRegion( rName
);
273 UpdateCrsr( SwCrsrShell::SCROLLWIN
| SwCrsrShell::CHKRANGE
|
274 SwCrsrShell::READONLY
);
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */