xref: /AOO42X/main/sw/source/core/crsr/trvlreg.cxx (revision b1c5455db1639c48e26c568e4fa7ee78ca5d60ee)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <crsrsh.hxx>
29cdf0e10cSrcweir #include <doc.hxx>
30cdf0e10cSrcweir #include <swcrsr.hxx>
31cdf0e10cSrcweir #include <docary.hxx>
32cdf0e10cSrcweir #include <fmtcntnt.hxx>
33cdf0e10cSrcweir #include <viscrs.hxx>
34cdf0e10cSrcweir #include <callnk.hxx>
35cdf0e10cSrcweir #include <pamtyp.hxx>
36cdf0e10cSrcweir #include <section.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
GotoPrevRegion(SwPaM & rCurCrsr,SwPosRegion fnPosRegion,sal_Bool bInReadOnly)40cdf0e10cSrcweir sal_Bool GotoPrevRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
41cdf0e10cSrcweir                         sal_Bool bInReadOnly )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
44cdf0e10cSrcweir     SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
45cdf0e10cSrcweir     if( pNd )
46cdf0e10cSrcweir         aIdx.Assign( *pNd, - 1 );
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     do {
49cdf0e10cSrcweir         while( aIdx.GetIndex() &&
50cdf0e10cSrcweir             0 == ( pNd = aIdx.GetNode().StartOfSectionNode()->GetSectionNode()) )
51cdf0e10cSrcweir             aIdx--;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         if( pNd )       // gibt einen weiteren SectionNode ?
54cdf0e10cSrcweir         {
55cdf0e10cSrcweir             if( pNd->GetSection().IsHiddenFlag() ||
56cdf0e10cSrcweir                 ( !bInReadOnly &&
57cdf0e10cSrcweir                   pNd->GetSection().IsProtectFlag() ))
58cdf0e10cSrcweir             {
59cdf0e10cSrcweir                 // geschuetzte/versteckte ueberspringen wir
60cdf0e10cSrcweir                 aIdx.Assign( *pNd, - 1 );
61cdf0e10cSrcweir             }
62cdf0e10cSrcweir             else if( fnPosRegion == fnMoveForward )
63cdf0e10cSrcweir             {
64cdf0e10cSrcweir                 aIdx = *pNd;
65cdf0e10cSrcweir                 SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
66cdf0e10cSrcweir                                                 sal_True, !bInReadOnly );
67cdf0e10cSrcweir                 if( !pCNd )
68cdf0e10cSrcweir                 {
69cdf0e10cSrcweir                     aIdx--;
70cdf0e10cSrcweir                     continue;
71cdf0e10cSrcweir                 }
72cdf0e10cSrcweir                 rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
73cdf0e10cSrcweir             }
74cdf0e10cSrcweir             else
75cdf0e10cSrcweir             {
76cdf0e10cSrcweir                 aIdx = *pNd->EndOfSectionNode();
77cdf0e10cSrcweir                 SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
78cdf0e10cSrcweir                                                 sal_True, !bInReadOnly );
79cdf0e10cSrcweir                 if( !pCNd )
80cdf0e10cSrcweir                 {
81cdf0e10cSrcweir                     aIdx.Assign( *pNd, - 1 );
82cdf0e10cSrcweir                     continue;
83cdf0e10cSrcweir                 }
84cdf0e10cSrcweir                 rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
85cdf0e10cSrcweir             }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir             rCurCrsr.GetPoint()->nNode = aIdx;
88cdf0e10cSrcweir             return sal_True;
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir     } while( pNd );
91cdf0e10cSrcweir     return sal_False;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
GotoNextRegion(SwPaM & rCurCrsr,SwPosRegion fnPosRegion,sal_Bool bInReadOnly)95cdf0e10cSrcweir sal_Bool GotoNextRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
96cdf0e10cSrcweir                         sal_Bool bInReadOnly )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     SwNodeIndex aIdx( rCurCrsr.GetPoint()->nNode );
99cdf0e10cSrcweir     SwSectionNode* pNd = aIdx.GetNode().FindSectionNode();
100cdf0e10cSrcweir     if( pNd )
101cdf0e10cSrcweir         aIdx.Assign( *pNd->EndOfSectionNode(), - 1 );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     sal_uLong nEndCount = aIdx.GetNode().GetNodes().Count()-1;
104cdf0e10cSrcweir     do {
105cdf0e10cSrcweir         while( aIdx.GetIndex() < nEndCount &&
106cdf0e10cSrcweir                 0 == ( pNd = aIdx.GetNode().GetSectionNode()) )
107cdf0e10cSrcweir             aIdx++;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         if( pNd )       // gibt einen weiteren SectionNode ?
110cdf0e10cSrcweir         {
111cdf0e10cSrcweir             if( pNd->GetSection().IsHiddenFlag() ||
112cdf0e10cSrcweir                 ( !bInReadOnly &&
113cdf0e10cSrcweir                   pNd->GetSection().IsProtectFlag() ))
114cdf0e10cSrcweir             {
115cdf0e10cSrcweir                 // geschuetzte/versteckte ueberspringen wir
116cdf0e10cSrcweir                 aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
117cdf0e10cSrcweir             }
118cdf0e10cSrcweir             else if( fnPosRegion == fnMoveForward )
119cdf0e10cSrcweir             {
120cdf0e10cSrcweir                 aIdx = *pNd;
121cdf0e10cSrcweir                 SwCntntNode* pCNd = pNd->GetNodes().GoNextSection( &aIdx,
122cdf0e10cSrcweir                                                 sal_True, !bInReadOnly );
123cdf0e10cSrcweir                 if( !pCNd )
124cdf0e10cSrcweir                 {
125cdf0e10cSrcweir                     aIdx.Assign( *pNd->EndOfSectionNode(), +1 );
126cdf0e10cSrcweir                     continue;
127cdf0e10cSrcweir                 }
128cdf0e10cSrcweir                 rCurCrsr.GetPoint()->nContent.Assign( pCNd, 0 );
129cdf0e10cSrcweir             }
130cdf0e10cSrcweir             else
131cdf0e10cSrcweir             {
132cdf0e10cSrcweir                 aIdx = *pNd->EndOfSectionNode();
133cdf0e10cSrcweir                 SwCntntNode* pCNd = pNd->GetNodes().GoPrevSection( &aIdx,
134cdf0e10cSrcweir                                                 sal_True, !bInReadOnly );
135cdf0e10cSrcweir                 if( !pCNd )
136cdf0e10cSrcweir                 {
137cdf0e10cSrcweir                     aIdx++;
138cdf0e10cSrcweir                     continue;
139cdf0e10cSrcweir                 }
140cdf0e10cSrcweir                 rCurCrsr.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
141cdf0e10cSrcweir             }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir             rCurCrsr.GetPoint()->nNode = aIdx;
144cdf0e10cSrcweir             return sal_True;
145cdf0e10cSrcweir         }
146cdf0e10cSrcweir     } while( pNd );
147cdf0e10cSrcweir     return sal_False;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
GotoCurrRegion(SwPaM & rCurCrsr,SwPosRegion fnPosRegion,sal_Bool bInReadOnly)151cdf0e10cSrcweir sal_Bool GotoCurrRegion( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
152cdf0e10cSrcweir                         sal_Bool bInReadOnly )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     SwSectionNode* pNd = rCurCrsr.GetNode()->FindSectionNode();
155cdf0e10cSrcweir     if( !pNd )
156cdf0e10cSrcweir         return sal_False;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     SwPosition* pPos = rCurCrsr.GetPoint();
159cdf0e10cSrcweir     sal_Bool bMoveBackward = fnPosRegion == fnMoveBackward;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     SwCntntNode* pCNd;
162cdf0e10cSrcweir     if( bMoveBackward )
163cdf0e10cSrcweir     {
164cdf0e10cSrcweir         SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
165cdf0e10cSrcweir         pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir     else
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         SwNodeIndex aIdx( *pNd );
170cdf0e10cSrcweir         pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
171cdf0e10cSrcweir     }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     if( pCNd )
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         pPos->nNode = *pCNd;
176cdf0e10cSrcweir         xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
177cdf0e10cSrcweir         pPos->nContent.Assign( pCNd, nTmpPos );
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir     return 0 != pCNd;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 
GotoCurrRegionAndSkip(SwPaM & rCurCrsr,SwPosRegion fnPosRegion,sal_Bool bInReadOnly)183cdf0e10cSrcweir sal_Bool GotoCurrRegionAndSkip( SwPaM& rCurCrsr, SwPosRegion fnPosRegion,
184cdf0e10cSrcweir                                 sal_Bool bInReadOnly )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     SwNode* pCurrNd = rCurCrsr.GetNode();
187cdf0e10cSrcweir     SwSectionNode* pNd = pCurrNd->FindSectionNode();
188cdf0e10cSrcweir     if( !pNd )
189cdf0e10cSrcweir         return sal_False;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     SwPosition* pPos = rCurCrsr.GetPoint();
192cdf0e10cSrcweir     xub_StrLen nCurrCnt = pPos->nContent.GetIndex();
193cdf0e10cSrcweir     sal_Bool bMoveBackward = fnPosRegion == fnMoveBackward;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     do {
196cdf0e10cSrcweir         SwCntntNode* pCNd;
197cdf0e10cSrcweir         if( bMoveBackward ) // ans Ende vom Bereich
198cdf0e10cSrcweir         {
199cdf0e10cSrcweir             SwNodeIndex aIdx( *pNd->EndOfSectionNode() );
200cdf0e10cSrcweir             pCNd = pNd->GetNodes().GoPrevSection( &aIdx, sal_True, !bInReadOnly );
201cdf0e10cSrcweir             if( !pCNd )
202cdf0e10cSrcweir                 return sal_False;
203cdf0e10cSrcweir             pPos->nNode = aIdx;
204cdf0e10cSrcweir         }
205cdf0e10cSrcweir         else
206cdf0e10cSrcweir         {
207cdf0e10cSrcweir             SwNodeIndex aIdx( *pNd );
208cdf0e10cSrcweir             pCNd = pNd->GetNodes().GoNextSection( &aIdx, sal_True, !bInReadOnly );
209cdf0e10cSrcweir             if( !pCNd )
210cdf0e10cSrcweir                 return sal_False;
211cdf0e10cSrcweir             pPos->nNode = aIdx;
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         xub_StrLen nTmpPos = bMoveBackward ? pCNd->Len() : 0;
215cdf0e10cSrcweir         pPos->nContent.Assign( pCNd, nTmpPos );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         if( &pPos->nNode.GetNode() != pCurrNd ||
218cdf0e10cSrcweir             pPos->nContent.GetIndex() != nCurrCnt )
219cdf0e10cSrcweir             // es gab eine Veraenderung
220cdf0e10cSrcweir             return sal_True;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         // dann versuche mal den "Parent" dieser Section
223cdf0e10cSrcweir         SwSection* pParent = pNd->GetSection().GetParent();
224cdf0e10cSrcweir         pNd = pParent ? pParent->GetFmt()->GetSectionNode() : 0;
225cdf0e10cSrcweir     } while( pNd );
226cdf0e10cSrcweir     return sal_False;
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 
MoveRegion(SwWhichRegion fnWhichRegion,SwPosRegion fnPosRegion)231cdf0e10cSrcweir sal_Bool SwCursor::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir     SwCrsrSaveState aSaveState( *this );
234cdf0e10cSrcweir     return !dynamic_cast<SwTableCursor*>(this) &&
235cdf0e10cSrcweir             (*fnWhichRegion)( *this, fnPosRegion, IsReadOnlyAvailable()  ) &&
236cdf0e10cSrcweir             !IsSelOvr() &&
237cdf0e10cSrcweir             ( GetPoint()->nNode.GetIndex() != pSavePos->nNode ||
238cdf0e10cSrcweir                 GetPoint()->nContent.GetIndex() != pSavePos->nCntnt );
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
MoveRegion(SwWhichRegion fnWhichRegion,SwPosRegion fnPosRegion)241cdf0e10cSrcweir sal_Bool SwCrsrShell::MoveRegion( SwWhichRegion fnWhichRegion, SwPosRegion fnPosRegion )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     SwCallLink aLk( *this );        // Crsr-Moves ueberwachen, evt. Link callen
244cdf0e10cSrcweir     sal_Bool bRet = !pTblCrsr && pCurCrsr->MoveRegion( fnWhichRegion, fnPosRegion );
245cdf0e10cSrcweir     if( bRet )
246cdf0e10cSrcweir         UpdateCrsr();
247cdf0e10cSrcweir     return bRet;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 
GotoRegion(const String & rName)251cdf0e10cSrcweir sal_Bool SwCursor::GotoRegion( const String& rName )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir     sal_Bool bRet = sal_False;
254cdf0e10cSrcweir     const SwSectionFmts& rFmts = GetDoc()->GetSections();
255cdf0e10cSrcweir     for( sal_uInt16 n = rFmts.Count(); n; )
256cdf0e10cSrcweir     {
257cdf0e10cSrcweir         const SwSectionFmt* pFmt = rFmts[ --n ];
258cdf0e10cSrcweir         const SwNodeIndex* pIdx;
259cdf0e10cSrcweir         const SwSection* pSect;
260cdf0e10cSrcweir         if( 0 != ( pSect = pFmt->GetSection() ) &&
261cdf0e10cSrcweir             pSect->GetSectionName() == rName &&
262cdf0e10cSrcweir             0 != ( pIdx = pFmt->GetCntnt().GetCntntIdx() ) &&
263cdf0e10cSrcweir             pIdx->GetNode().GetNodes().IsDocNodes() )
264cdf0e10cSrcweir         {
265cdf0e10cSrcweir             // ein Bereich im normalen NodesArr
266cdf0e10cSrcweir             SwCrsrSaveState aSaveState( *this );
267cdf0e10cSrcweir 
268cdf0e10cSrcweir             GetPoint()->nNode = *pIdx;
269cdf0e10cSrcweir             Move( fnMoveForward, fnGoCntnt );
270cdf0e10cSrcweir             bRet = !IsSelOvr();
271cdf0e10cSrcweir         }
272cdf0e10cSrcweir     }
273cdf0e10cSrcweir     return bRet;
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
GotoRegion(const String & rName)276cdf0e10cSrcweir sal_Bool SwCrsrShell::GotoRegion( const String& rName )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir     SwCallLink aLk( *this );        // Crsr-Moves ueberwachen,
279cdf0e10cSrcweir     sal_Bool bRet = !pTblCrsr && pCurCrsr->GotoRegion( rName );
280cdf0e10cSrcweir     if( bRet )
281cdf0e10cSrcweir         UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
282cdf0e10cSrcweir                     SwCrsrShell::READONLY ); // und den akt. Updaten
283cdf0e10cSrcweir     return bRet;
284cdf0e10cSrcweir }
285