1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: trvlreg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
39 #include <fmtcntnt.hxx>
43 #include <section.hxx>
47 BOOL
GotoPrevRegion( SwPaM
& rCurCrsr
, SwPosRegion fnPosRegion
,
50 SwNodeIndex
aIdx( rCurCrsr
.GetPoint()->nNode
);
51 SwSectionNode
* pNd
= aIdx
.GetNode().FindSectionNode();
53 aIdx
.Assign( *pNd
, - 1 );
56 while( aIdx
.GetIndex() &&
57 0 == ( pNd
= aIdx
.GetNode().StartOfSectionNode()->GetSectionNode()) )
60 if( pNd
) // gibt einen weiteren SectionNode ?
62 if( pNd
->GetSection().IsHiddenFlag() ||
64 pNd
->GetSection().IsProtectFlag() ))
66 // geschuetzte/versteckte ueberspringen wir
67 aIdx
.Assign( *pNd
, - 1 );
69 else if( fnPosRegion
== fnMoveForward
)
72 SwCntntNode
* pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
,
79 rCurCrsr
.GetPoint()->nContent
.Assign( pCNd
, 0 );
83 aIdx
= *pNd
->EndOfSectionNode();
84 SwCntntNode
* pCNd
= pNd
->GetNodes().GoPrevSection( &aIdx
,
88 aIdx
.Assign( *pNd
, - 1 );
91 rCurCrsr
.GetPoint()->nContent
.Assign( pCNd
, pCNd
->Len() );
94 rCurCrsr
.GetPoint()->nNode
= aIdx
;
102 BOOL
GotoNextRegion( SwPaM
& rCurCrsr
, SwPosRegion fnPosRegion
,
105 SwNodeIndex
aIdx( rCurCrsr
.GetPoint()->nNode
);
106 SwSectionNode
* pNd
= aIdx
.GetNode().FindSectionNode();
108 aIdx
.Assign( *pNd
->EndOfSectionNode(), - 1 );
110 ULONG nEndCount
= aIdx
.GetNode().GetNodes().Count()-1;
112 while( aIdx
.GetIndex() < nEndCount
&&
113 0 == ( pNd
= aIdx
.GetNode().GetSectionNode()) )
116 if( pNd
) // gibt einen weiteren SectionNode ?
118 if( pNd
->GetSection().IsHiddenFlag() ||
120 pNd
->GetSection().IsProtectFlag() ))
122 // geschuetzte/versteckte ueberspringen wir
123 aIdx
.Assign( *pNd
->EndOfSectionNode(), +1 );
125 else if( fnPosRegion
== fnMoveForward
)
128 SwCntntNode
* pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
,
129 TRUE
, !bInReadOnly
);
132 aIdx
.Assign( *pNd
->EndOfSectionNode(), +1 );
135 rCurCrsr
.GetPoint()->nContent
.Assign( pCNd
, 0 );
139 aIdx
= *pNd
->EndOfSectionNode();
140 SwCntntNode
* pCNd
= pNd
->GetNodes().GoPrevSection( &aIdx
,
141 TRUE
, !bInReadOnly
);
147 rCurCrsr
.GetPoint()->nContent
.Assign( pCNd
, pCNd
->Len() );
150 rCurCrsr
.GetPoint()->nNode
= aIdx
;
158 BOOL
GotoCurrRegion( SwPaM
& rCurCrsr
, SwPosRegion fnPosRegion
,
161 SwSectionNode
* pNd
= rCurCrsr
.GetNode()->FindSectionNode();
165 SwPosition
* pPos
= rCurCrsr
.GetPoint();
166 BOOL bMoveBackward
= fnPosRegion
== fnMoveBackward
;
171 SwNodeIndex
aIdx( *pNd
->EndOfSectionNode() );
172 pCNd
= pNd
->GetNodes().GoPrevSection( &aIdx
, TRUE
, !bInReadOnly
);
176 SwNodeIndex
aIdx( *pNd
);
177 pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
, TRUE
, !bInReadOnly
);
183 xub_StrLen nTmpPos
= bMoveBackward
? pCNd
->Len() : 0;
184 pPos
->nContent
.Assign( pCNd
, nTmpPos
);
190 BOOL
GotoCurrRegionAndSkip( SwPaM
& rCurCrsr
, SwPosRegion fnPosRegion
,
193 SwNode
* pCurrNd
= rCurCrsr
.GetNode();
194 SwSectionNode
* pNd
= pCurrNd
->FindSectionNode();
198 SwPosition
* pPos
= rCurCrsr
.GetPoint();
199 xub_StrLen nCurrCnt
= pPos
->nContent
.GetIndex();
200 BOOL bMoveBackward
= fnPosRegion
== fnMoveBackward
;
204 if( bMoveBackward
) // ans Ende vom Bereich
206 SwNodeIndex
aIdx( *pNd
->EndOfSectionNode() );
207 pCNd
= pNd
->GetNodes().GoPrevSection( &aIdx
, TRUE
, !bInReadOnly
);
214 SwNodeIndex
aIdx( *pNd
);
215 pCNd
= pNd
->GetNodes().GoNextSection( &aIdx
, TRUE
, !bInReadOnly
);
221 xub_StrLen nTmpPos
= bMoveBackward
? pCNd
->Len() : 0;
222 pPos
->nContent
.Assign( pCNd
, nTmpPos
);
224 if( &pPos
->nNode
.GetNode() != pCurrNd
||
225 pPos
->nContent
.GetIndex() != nCurrCnt
)
226 // es gab eine Veraenderung
229 // dann versuche mal den "Parent" dieser Section
230 SwSection
* pParent
= pNd
->GetSection().GetParent();
231 pNd
= pParent
? pParent
->GetFmt()->GetSectionNode() : 0;
238 BOOL
SwCursor::MoveRegion( SwWhichRegion fnWhichRegion
, SwPosRegion fnPosRegion
)
240 SwCrsrSaveState
aSaveState( *this );
241 return !dynamic_cast<SwTableCursor
*>(this) &&
242 (*fnWhichRegion
)( *this, fnPosRegion
, IsReadOnlyAvailable() ) &&
244 ( GetPoint()->nNode
.GetIndex() != pSavePos
->nNode
||
245 GetPoint()->nContent
.GetIndex() != pSavePos
->nCntnt
);
248 BOOL
SwCrsrShell::MoveRegion( SwWhichRegion fnWhichRegion
, SwPosRegion fnPosRegion
)
250 SwCallLink
aLk( *this ); // Crsr-Moves ueberwachen, evt. Link callen
251 BOOL bRet
= !pTblCrsr
&& pCurCrsr
->MoveRegion( fnWhichRegion
, fnPosRegion
);
258 BOOL
SwCursor::GotoRegion( const String
& rName
)
261 const SwSectionFmts
& rFmts
= GetDoc()->GetSections();
262 for( USHORT n
= rFmts
.Count(); n
; )
264 const SwSectionFmt
* pFmt
= rFmts
[ --n
];
265 const SwNodeIndex
* pIdx
;
266 const SwSection
* pSect
;
267 if( 0 != ( pSect
= pFmt
->GetSection() ) &&
268 pSect
->GetName() == rName
&&
269 0 != ( pIdx
= pFmt
->GetCntnt().GetCntntIdx() ) &&
270 pIdx
->GetNode().GetNodes().IsDocNodes() )
272 // ein Bereich im normalen NodesArr
273 SwCrsrSaveState
aSaveState( *this );
275 GetPoint()->nNode
= *pIdx
;
276 Move( fnMoveForward
, fnGoCntnt
);
283 BOOL
SwCrsrShell::GotoRegion( const String
& rName
)
285 SwCallLink
aLk( *this ); // Crsr-Moves ueberwachen,
286 BOOL bRet
= !pTblCrsr
&& pCurCrsr
->GotoRegion( rName
);
288 UpdateCrsr( SwCrsrShell::SCROLLWIN
| SwCrsrShell::CHKRANGE
|
289 SwCrsrShell::READONLY
); // und den akt. Updaten