update dev300-m58
[ooovba.git] / sw / source / core / crsr / trvlreg.cxx
blob3fc27beadcd1ba1df31d70738b457c5341b442ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: trvlreg.cxx,v $
10 * $Revision: 1.7 $
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"
35 #include <crsrsh.hxx>
36 #include <doc.hxx>
37 #include <swcrsr.hxx>
38 #include <docary.hxx>
39 #include <fmtcntnt.hxx>
40 #include <viscrs.hxx>
41 #include <callnk.hxx>
42 #include <pamtyp.hxx>
43 #include <section.hxx>
47 BOOL GotoPrevRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
48 BOOL bInReadOnly )
50 SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
51 SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
52 if( pNd )
53 aIdx.Assign( *pNd, - 1 );
55 do {
56 while( aIdx.GetIndex() &&
57 0 == ( pNd = aIdx.GetNode().StartOfSectionNode()->GetSectionNode()) )
58 aIdx--;
60 if( pNd ) // gibt einen weiteren SectionNode ?
62 if( pNd->GetSection().IsHiddenFlag() ||
63 ( !bInReadOnly &&
64 pNd->GetSection().IsProtectFlag() ))
66 // geschuetzte/versteckte ueberspringen wir
67 aIdx.Assign( *pNd, - 1 );
69 else if( fnPosRegion == fnMoveForward )
71 aIdx = *pNd;
72 SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
73 TRUE, !bInReadOnly );
74 if( !pCNd )
76 aIdx--;
77 continue;
79 rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
81 else
83 aIdx = *pNd->EndOfSectionNode();
84 SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
85 TRUE, !bInReadOnly );
86 if( !pCNd )
88 aIdx.Assign( *pNd, - 1 );
89 continue;
91 rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
94 rCurCrsr.GetPoint()->nNode = aIdx;
95 return TRUE;
97 } while( pNd );
98 return FALSE;
102 BOOL GotoNextRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
103 BOOL bInReadOnly )
105 SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
106 SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
107 if( pNd )
108 aIdx.Assign( *pNd->EndOfSectionNode(), - 1 );
110 ULONG nEndCount = aIdx.GetNode().GetNodes().Count()-1;
111 do {
112 while( aIdx.GetIndex() < nEndCount &&
113 0 == ( pNd = aIdx.GetNode().GetSectionNode()) )
114 aIdx++;
116 if( pNd ) // gibt einen weiteren SectionNode ?
118 if( pNd->GetSection().IsHiddenFlag() ||
119 ( !bInReadOnly &&
120 pNd->GetSection().IsProtectFlag() ))
122 // geschuetzte/versteckte ueberspringen wir
123 aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
125 else if( fnPosRegion == fnMoveForward )
127 aIdx = *pNd;
128 SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
129 TRUE, !bInReadOnly );
130 if( !pCNd )
132 aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
133 continue;
135 rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
137 else
139 aIdx = *pNd->EndOfSectionNode();
140 SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
141 TRUE, !bInReadOnly );
142 if( !pCNd )
144 aIdx++;
145 continue;
147 rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
150 rCurCrsr.GetPoint()->nNode = aIdx;
151 return TRUE;
153 } while( pNd );
154 return FALSE;
158 BOOL GotoCurrRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
159 BOOL bInReadOnly )
161 SwSectionNode* pNd = rCurCrsr.GetNode()->FindSectionNode();
162 if( !pNd )
163 return FALSE;
165 SwPosition* pPos = rCurCrsr.GetPoint();
166 BOOL bMoveBackward = fnPosRegion == fnMoveBackward;
168 SwCntntNode* pCNd;
169 if( bMoveBackward )
171 SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
172 pCNd = pNd->GetNodes().GoPrevSection( &aIdx, TRUE, !bInReadOnly );
174 else
176 SwNodeIndex aIdx( *pNd );
177 pCNd = pNd->GetNodes().GoNextSection( &aIdx, TRUE, !bInReadOnly );
180 if( pCNd )
182 pPos->nNode = *pCNd;
183 xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
184 pPos->nContent.Assign( pCNd, nTmpPos );
186 return 0 != pCNd;
190 BOOL GotoCurrRegionAndSkip( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
191 BOOL bInReadOnly )
193 SwNode* pCurrNd = rCurCrsr.GetNode();
194 SwSectionNode* pNd = pCurrNd->FindSectionNode();
195 if( !pNd )
196 return FALSE;
198 SwPosition* pPos = rCurCrsr.GetPoint();
199 xub_StrLen nCurrCnt = pPos->nContent.GetIndex();
200 BOOL bMoveBackward = fnPosRegion == fnMoveBackward;
202 do {
203 SwCntntNode* pCNd;
204 if( bMoveBackward ) // ans Ende vom Bereich
206 SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
207 pCNd = pNd->GetNodes().GoPrevSection( &aIdx, TRUE, !bInReadOnly );
208 if( !pCNd )
209 return FALSE;
210 pPos->nNode = aIdx;
212 else
214 SwNodeIndex aIdx( *pNd );
215 pCNd = pNd->GetNodes().GoNextSection( &aIdx, TRUE, !bInReadOnly );
216 if( !pCNd )
217 return FALSE;
218 pPos->nNode = aIdx;
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
227 return TRUE;
229 // dann versuche mal den "Parent" dieser Section
230 SwSection* pParent = pNd->GetSection().GetParent();
231 pNd = pParent ? pParent->GetFmt()->GetSectionNode() : 0;
232 } while( pNd );
233 return FALSE;
238 BOOL SwCursor::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
240 SwCrsrSaveState aSaveState( *this );
241 return !dynamic_cast<SwTableCursor*>(this) &&
242 (*fnWhichRegion)( *this, fnPosRegion, IsReadOnlyAvailable() ) &&
243 !IsSelOvr() &&
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 );
252 if( bRet )
253 UpdateCrsr();
254 return bRet;
258 BOOL SwCursor::GotoRegion( const String& rName )
260 BOOL bRet = FALSE;
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 );
277 bRet = !IsSelOvr();
280 return bRet;
283 BOOL SwCrsrShell::GotoRegion( const String& rName )
285 SwCallLink aLk( *this ); // Crsr-Moves ueberwachen,
286 BOOL bRet = !pTblCrsr && pCurCrsr->GotoRegion( rName );
287 if( bRet )
288 UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
289 SwCrsrShell::READONLY ); // und den akt. Updaten
290 return bRet;