Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sw / source / core / crsr / trvlreg.cxx
blobc9174131cea14ff66a724b4cb1e499d3aaf09d96
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
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>
32 sal_Bool GotoPrevRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
33 sal_Bool bInReadOnly )
35 SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
36 SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
37 if( pNd )
38 aIdx.Assign( *pNd, - 1 );
40 do {
41 while( aIdx.GetIndex() &&
42 0 == ( pNd = aIdx.GetNode().StartOfSectionNode()->GetSectionNode()) )
43 aIdx--;
45 if( pNd ) // is there another section node?
47 if( pNd->GetSection().IsHiddenFlag() ||
48 ( !bInReadOnly &&
49 pNd->GetSection().IsProtectFlag() ))
51 // skip protected or hidden ones
52 aIdx.Assign( *pNd, - 1 );
54 else if( fnPosRegion == fnMoveForward )
56 aIdx = *pNd;
57 SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
58 sal_True, !bInReadOnly );
59 if( !pCNd )
61 aIdx--;
62 continue;
64 rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
66 else
68 aIdx = *pNd->EndOfSectionNode();
69 SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
70 sal_True, !bInReadOnly );
71 if( !pCNd )
73 aIdx.Assign( *pNd, - 1 );
74 continue;
76 rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
79 rCurCrsr.GetPoint()->nNode = aIdx;
80 return sal_True;
82 } while( pNd );
83 return sal_False;
87 sal_Bool GotoNextRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
88 sal_Bool bInReadOnly )
90 SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
91 SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
92 if( pNd )
93 aIdx.Assign( *pNd->EndOfSectionNode(), - 1 );
95 sal_uLong nEndCount = aIdx.GetNode().GetNodes().Count()-1;
96 do {
97 while( aIdx.GetIndex() < nEndCount &&
98 0 == ( pNd = aIdx.GetNode().GetSectionNode()) )
99 ++aIdx;
101 if( pNd ) // is there another section node?
103 if( pNd->GetSection().IsHiddenFlag() ||
104 ( !bInReadOnly &&
105 pNd->GetSection().IsProtectFlag() ))
107 // skip protected or hidden ones
108 aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
110 else if( fnPosRegion == fnMoveForward )
112 aIdx = *pNd;
113 SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
114 sal_True, !bInReadOnly );
115 if( !pCNd )
117 aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
118 continue;
120 rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
122 else
124 aIdx = *pNd->EndOfSectionNode();
125 SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
126 sal_True, !bInReadOnly );
127 if( !pCNd )
129 ++aIdx;
130 continue;
132 rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
135 rCurCrsr.GetPoint()->nNode = aIdx;
136 return sal_True;
138 } while( pNd );
139 return sal_False;
143 sal_Bool GotoCurrRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
144 sal_Bool bInReadOnly )
146 SwSectionNode* pNd = rCurCrsr.GetNode()->FindSectionNode();
147 if( !pNd )
148 return sal_False;
150 SwPosition* pPos = rCurCrsr.GetPoint();
151 bool bMoveBackward = fnPosRegion == fnMoveBackward;
153 SwCntntNode* pCNd;
154 if( bMoveBackward )
156 SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
157 pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
159 else
161 SwNodeIndex aIdx( *pNd );
162 pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
165 if( pCNd )
167 pPos->nNode = *pCNd;
168 xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
169 pPos->nContent.Assign( pCNd, nTmpPos );
171 return 0 != pCNd;
175 sal_Bool GotoCurrRegionAndSkip( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
176 sal_Bool bInReadOnly )
178 SwNode* pCurrNd = rCurCrsr.GetNode();
179 SwSectionNode* pNd = pCurrNd->FindSectionNode();
180 if( !pNd )
181 return sal_False;
183 SwPosition* pPos = rCurCrsr.GetPoint();
184 xub_StrLen nCurrCnt = pPos->nContent.GetIndex();
185 bool bMoveBackward = fnPosRegion == fnMoveBackward;
187 do {
188 SwCntntNode* pCNd;
189 if( bMoveBackward ) // to the end of the section
191 SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
192 pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
193 if( !pCNd )
194 return sal_False;
195 pPos->nNode = aIdx;
197 else
199 SwNodeIndex aIdx( *pNd );
200 pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
201 if( !pCNd )
202 return sal_False;
203 pPos->nNode = aIdx;
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
212 return sal_True;
214 // try also the parent of this section
215 SwSection* pParent = pNd->GetSection().GetParent();
216 pNd = pParent ? pParent->GetFmt()->GetSectionNode() : 0;
217 } while( pNd );
218 return sal_False;
223 sal_Bool SwCursor::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
225 SwCrsrSaveState aSaveState( *this );
226 return !dynamic_cast<SwTableCursor*>(this) &&
227 (*fnWhichRegion)( *this, fnPosRegion, IsReadOnlyAvailable() ) &&
228 !IsSelOvr() &&
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 );
237 if( bRet )
238 UpdateCrsr();
239 return bRet;
243 bool SwCursor::GotoRegion( const String& rName )
245 bool bRet = false;
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 );
262 bRet = !IsSelOvr();
265 return bRet;
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 );
272 if( bRet )
273 UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
274 SwCrsrShell::READONLY );
275 return bRet;
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */