xref: /aoo42x/main/sw/source/core/crsr/swcrsr.cxx (revision 150c6d32)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir #include <editeng/protitem.hxx>
30cdf0e10cSrcweir #include <com/sun/star/i18n/WordType.hdl>
31cdf0e10cSrcweir #include <com/sun/star/i18n/CharType.hdl>
32cdf0e10cSrcweir #include <unotools/charclass.hxx>
33cdf0e10cSrcweir #include <svl/ctloptions.hxx>
34cdf0e10cSrcweir #include <swmodule.hxx>
35cdf0e10cSrcweir #include <fmtcntnt.hxx>
36cdf0e10cSrcweir #include <swtblfmt.hxx>
37cdf0e10cSrcweir #include <swcrsr.hxx>
38cdf0e10cSrcweir #include <unocrsr.hxx>
39cdf0e10cSrcweir #include <doc.hxx>
40cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
41cdf0e10cSrcweir #include <docary.hxx>
42cdf0e10cSrcweir #include <ndtxt.hxx>
43cdf0e10cSrcweir #include <section.hxx>
44cdf0e10cSrcweir #include <swtable.hxx>
45cdf0e10cSrcweir #include <cntfrm.hxx>
46cdf0e10cSrcweir #include <rootfrm.hxx>
47cdf0e10cSrcweir #include <txtfrm.hxx>
48cdf0e10cSrcweir #include <scriptinfo.hxx>
49cdf0e10cSrcweir #include <crstate.hxx>
50cdf0e10cSrcweir #include <docsh.hxx>
51cdf0e10cSrcweir #include <viewsh.hxx>
52cdf0e10cSrcweir #include <frmatr.hxx>
53cdf0e10cSrcweir #include <breakit.hxx>
54cdf0e10cSrcweir #include <crsskip.hxx>
55cdf0e10cSrcweir #include <vcl/msgbox.hxx>
56cdf0e10cSrcweir #include <mdiexp.hxx>			// ...Percent()
57cdf0e10cSrcweir #include <statstr.hrc>			// ResId fuer Statusleiste
58cdf0e10cSrcweir #include <redline.hxx>      // SwRedline
5969a74367SOliver-Rainer Wittmann #include <txatbase.hxx>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir using namespace ::com::sun::star::i18n;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 
65cdf0e10cSrcweir static const sal_uInt16 coSrchRplcThreshold = 60000;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir struct _PercentHdl
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	SwDocShell* pDSh;
70cdf0e10cSrcweir 	sal_uLong nActPos;
71cdf0e10cSrcweir 	sal_Bool bBack, bNodeIdx;
72cdf0e10cSrcweir 
_PercentHdl_PercentHdl73cdf0e10cSrcweir 	_PercentHdl( sal_uLong nStt, sal_uLong nEnd, SwDocShell* pSh )
74cdf0e10cSrcweir 		: pDSh( pSh )
75cdf0e10cSrcweir 	{
76cdf0e10cSrcweir 		nActPos = nStt;
77cdf0e10cSrcweir 		if( 0 != ( bBack = (nStt > nEnd )) )
78cdf0e10cSrcweir 		{
79cdf0e10cSrcweir 			sal_uLong n = nStt; nStt = nEnd; nEnd = n;
80cdf0e10cSrcweir 		}
81cdf0e10cSrcweir 		::StartProgress( STR_STATSTR_SEARCH, nStt, nEnd, 0 );
82cdf0e10cSrcweir 	}
83cdf0e10cSrcweir 
_PercentHdl_PercentHdl84cdf0e10cSrcweir 	_PercentHdl( const SwPaM& rPam )
85cdf0e10cSrcweir 		: pDSh( (SwDocShell*)rPam.GetDoc()->GetDocShell() )
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir 		sal_uLong nStt, nEnd;
88cdf0e10cSrcweir 		if( rPam.GetPoint()->nNode == rPam.GetMark()->nNode )
89cdf0e10cSrcweir 		{
90cdf0e10cSrcweir 			bNodeIdx = sal_False;
91cdf0e10cSrcweir 			nStt = rPam.GetMark()->nContent.GetIndex();
92cdf0e10cSrcweir 			nEnd = rPam.GetPoint()->nContent.GetIndex();
93cdf0e10cSrcweir 		}
94cdf0e10cSrcweir 		else
95cdf0e10cSrcweir 		{
96cdf0e10cSrcweir             bNodeIdx = sal_True;
97cdf0e10cSrcweir             nStt = rPam.GetMark()->nNode.GetIndex();
98cdf0e10cSrcweir 			nEnd = rPam.GetPoint()->nNode.GetIndex();
99cdf0e10cSrcweir 		}
100cdf0e10cSrcweir 		nActPos = nStt;
101cdf0e10cSrcweir 		if( 0 != ( bBack = (nStt > nEnd )) )
102cdf0e10cSrcweir 		{
103cdf0e10cSrcweir 			sal_uLong n = nStt; nStt = nEnd; nEnd = n;
104cdf0e10cSrcweir 		}
105cdf0e10cSrcweir 		::StartProgress( STR_STATSTR_SEARCH, nStt, nEnd, pDSh );
106cdf0e10cSrcweir 	}
107cdf0e10cSrcweir 
~_PercentHdl_PercentHdl108cdf0e10cSrcweir 	~_PercentHdl()  					{ ::EndProgress( pDSh ); }
109cdf0e10cSrcweir 
NextPos_PercentHdl110cdf0e10cSrcweir 	void NextPos( sal_uLong nPos ) const
111cdf0e10cSrcweir 		{ ::SetProgressState( bBack ? nActPos - nPos : nPos, pDSh ); }
112cdf0e10cSrcweir 
NextPos_PercentHdl113cdf0e10cSrcweir 	void NextPos( SwPosition& rPos ) const
114cdf0e10cSrcweir 		{
115cdf0e10cSrcweir 			sal_uLong nPos;
116cdf0e10cSrcweir 			if( bNodeIdx )
117cdf0e10cSrcweir 				nPos = rPos.nNode.GetIndex();
118cdf0e10cSrcweir 			else
119cdf0e10cSrcweir 				nPos = rPos.nContent.GetIndex();
120cdf0e10cSrcweir 			::SetProgressState( bBack ? nActPos - nPos : nPos, pDSh );
121cdf0e10cSrcweir 		}
122cdf0e10cSrcweir };
123cdf0e10cSrcweir 
SwCursor(const SwPosition & rPos,SwPaM * pRing,bool bColumnSel)124cdf0e10cSrcweir SwCursor::SwCursor( const SwPosition &rPos, SwPaM* pRing, bool bColumnSel )
125cdf0e10cSrcweir     : SwPaM( rPos, pRing ), pSavePos( 0 ), mnRowSpanOffset( 0 ), nCursorBidiLevel( 0 ),
126cdf0e10cSrcweir     mbColumnSelection( bColumnSel )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir // @@@ semantic: no copy ctor.
SwCursor(SwCursor & rCpy)131cdf0e10cSrcweir SwCursor::SwCursor( SwCursor& rCpy )
132cdf0e10cSrcweir     : SwPaM( rCpy ), pSavePos( 0 ), mnRowSpanOffset( rCpy.mnRowSpanOffset ),
133cdf0e10cSrcweir     nCursorBidiLevel( rCpy.nCursorBidiLevel ), mbColumnSelection( rCpy.mbColumnSelection )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
~SwCursor()137cdf0e10cSrcweir SwCursor::~SwCursor()
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	while( pSavePos )
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir         _SwCursor_SavePos* pNxt = pSavePos->pNext;
142cdf0e10cSrcweir 		delete pSavePos;
143cdf0e10cSrcweir         pSavePos = pNxt;
144cdf0e10cSrcweir 	}
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
Create(SwPaM * pRing) const147cdf0e10cSrcweir SwCursor* SwCursor::Create( SwPaM* pRing ) const
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	return new SwCursor( *GetPoint(), pRing, false );
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
IsReadOnlyAvailable() const152cdf0e10cSrcweir bool SwCursor::IsReadOnlyAvailable() const
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     return false;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
IsSkipOverHiddenSections() const157cdf0e10cSrcweir sal_Bool SwCursor::IsSkipOverHiddenSections() const
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     return sal_True;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
IsSkipOverProtectSections() const162cdf0e10cSrcweir sal_Bool SwCursor::IsSkipOverProtectSections() const
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     return !IsReadOnlyAvailable();
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168cdf0e10cSrcweir // Sicher die aktuelle Position, damit ggfs. auf diese zurueck
169cdf0e10cSrcweir // gefallen werden kann. Die SavePos Objekte werden als Stack verwaltet,
170cdf0e10cSrcweir // damit das auch alles bei verschachtelten Aufrufen funktioniert.
171cdf0e10cSrcweir // Das CreateNewSavePos ist virtual, damit abgeleitete Klassen vom Cursor
172cdf0e10cSrcweir // gegebenenfalls eigene SaveObjecte anlegen und in den virtuellen
173cdf0e10cSrcweir // Check-Routinen verwenden koennen.
174cdf0e10cSrcweir 
SaveState()175cdf0e10cSrcweir void SwCursor::SaveState()
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	_SwCursor_SavePos* pNew = CreateNewSavePos();
178cdf0e10cSrcweir 	pNew->pNext = pSavePos;
179cdf0e10cSrcweir 	pSavePos = pNew;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
RestoreState()182cdf0e10cSrcweir void SwCursor::RestoreState()
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     if( pSavePos ) // Robust
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         _SwCursor_SavePos* pDel = pSavePos;
187cdf0e10cSrcweir         pSavePos = pSavePos->pNext;
188cdf0e10cSrcweir         delete pDel;
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
CreateNewSavePos() const192cdf0e10cSrcweir _SwCursor_SavePos* SwCursor::CreateNewSavePos() const
193cdf0e10cSrcweir {
194cdf0e10cSrcweir 	return new _SwCursor_SavePos( *this );
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir // stelle fest, ob sich der Point ausserhalb des Content-Bereichs
198cdf0e10cSrcweir // vom Nodes-Array befindet
IsNoCntnt() const199cdf0e10cSrcweir sal_Bool SwCursor::IsNoCntnt() const
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	return GetPoint()->nNode.GetIndex() <
202cdf0e10cSrcweir 			GetDoc()->GetNodes().GetEndOfExtras().GetIndex();
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
IsSelOvrCheck(int)205cdf0e10cSrcweir bool SwCursor::IsSelOvrCheck(int)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     return false;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir // extracted from IsSelOvr()
IsSelOvrCheck(int eFlags)211cdf0e10cSrcweir bool SwTableCursor::IsSelOvrCheck(int eFlags)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     SwNodes& rNds = GetDoc()->GetNodes();
214cdf0e10cSrcweir     // check sections of nodes array
215cdf0e10cSrcweir     if( (nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION & eFlags)
216cdf0e10cSrcweir         && HasMark() )
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         SwNodeIndex aOldPos( rNds, GetSavePos()->nNode );
219cdf0e10cSrcweir         if( !CheckNodesRange( aOldPos, GetPoint()->nNode, sal_True ))
220cdf0e10cSrcweir         {
221cdf0e10cSrcweir             GetPoint()->nNode = aOldPos;
222cdf0e10cSrcweir             GetPoint()->nContent.Assign( GetCntntNode(), GetSavePos()->nCntnt );
223cdf0e10cSrcweir             return true;
224cdf0e10cSrcweir         }
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir     return SwCursor::IsSelOvrCheck(eFlags);
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
IsSelOvr(int eFlags)229cdf0e10cSrcweir sal_Bool SwCursor::IsSelOvr( int eFlags )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	SwDoc* pDoc = GetDoc();
232cdf0e10cSrcweir 	SwNodes& rNds = pDoc->GetNodes();
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     sal_Bool bSkipOverHiddenSections = IsSkipOverHiddenSections();
235cdf0e10cSrcweir     sal_Bool bSkipOverProtectSections = IsSkipOverProtectSections();
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     if ( IsSelOvrCheck( eFlags ) )
238cdf0e10cSrcweir     {
239cdf0e10cSrcweir         return sal_True;
240cdf0e10cSrcweir     }
241cdf0e10cSrcweir 
24269a74367SOliver-Rainer Wittmann     if( pSavePos->nNode != GetPoint()->nNode.GetIndex()
24369a74367SOliver-Rainer Wittmann         && ( !pDoc->GetDocShell()
24469a74367SOliver-Rainer Wittmann              || !pDoc->GetDocShell()->IsReadOnlyUI() ) )
24569a74367SOliver-Rainer Wittmann     {
24669a74367SOliver-Rainer Wittmann         // teste doch mal die neuen Sections:
24769a74367SOliver-Rainer Wittmann         SwNodeIndex& rPtIdx = GetPoint()->nNode;
24869a74367SOliver-Rainer Wittmann         const SwSectionNode* pSectNd = rPtIdx.GetNode().FindSectionNode();
24969a74367SOliver-Rainer Wittmann         if( pSectNd &&
25069a74367SOliver-Rainer Wittmann             ((bSkipOverHiddenSections && pSectNd->GetSection().IsHiddenFlag() ) ||
25169a74367SOliver-Rainer Wittmann             (bSkipOverProtectSections && pSectNd->GetSection().IsProtectFlag() )))
25269a74367SOliver-Rainer Wittmann         {
253cdf0e10cSrcweir             if( 0 == ( nsSwCursorSelOverFlags::SELOVER_CHANGEPOS & eFlags ) )
25469a74367SOliver-Rainer Wittmann             {
25569a74367SOliver-Rainer Wittmann                 // dann wars das schon
25669a74367SOliver-Rainer Wittmann                 RestoreSavePos();
25769a74367SOliver-Rainer Wittmann                 return sal_True;
25869a74367SOliver-Rainer Wittmann             }
259cdf0e10cSrcweir 
26069a74367SOliver-Rainer Wittmann             // dann setze den Cursor auf die neue Position:
26169a74367SOliver-Rainer Wittmann             SwNodeIndex aIdx( rPtIdx );
26269a74367SOliver-Rainer Wittmann             xub_StrLen nCntntPos = pSavePos->nCntnt;
26369a74367SOliver-Rainer Wittmann             int bGoNxt = pSavePos->nNode < rPtIdx.GetIndex();
26469a74367SOliver-Rainer Wittmann             SwCntntNode* pCNd = bGoNxt
26569a74367SOliver-Rainer Wittmann                 ? rNds.GoNextSection( &rPtIdx, bSkipOverHiddenSections, bSkipOverProtectSections)
26669a74367SOliver-Rainer Wittmann                 : rNds.GoPrevSection( &rPtIdx, bSkipOverHiddenSections, bSkipOverProtectSections);
267cdf0e10cSrcweir             if( !pCNd && ( nsSwCursorSelOverFlags::SELOVER_ENABLEREVDIREKTION & eFlags ))
26869a74367SOliver-Rainer Wittmann             {
26969a74367SOliver-Rainer Wittmann                 bGoNxt = !bGoNxt;
27069a74367SOliver-Rainer Wittmann                 pCNd = bGoNxt ? rNds.GoNextSection( &rPtIdx, bSkipOverHiddenSections, bSkipOverProtectSections)
27169a74367SOliver-Rainer Wittmann                     : rNds.GoPrevSection( &rPtIdx, bSkipOverHiddenSections, bSkipOverProtectSections);
27269a74367SOliver-Rainer Wittmann             }
273cdf0e10cSrcweir 
27469a74367SOliver-Rainer Wittmann             int bIsValidPos = 0 != pCNd;
27569a74367SOliver-Rainer Wittmann             sal_Bool bValidNodesRange = bIsValidPos &&
27669a74367SOliver-Rainer Wittmann                 ::CheckNodesRange( rPtIdx, aIdx, sal_True );
27769a74367SOliver-Rainer Wittmann             if( !bValidNodesRange )
27869a74367SOliver-Rainer Wittmann             {
27969a74367SOliver-Rainer Wittmann                 rPtIdx = pSavePos->nNode;
28069a74367SOliver-Rainer Wittmann                 if( 0 == ( pCNd = rPtIdx.GetNode().GetCntntNode() ) )
28169a74367SOliver-Rainer Wittmann                 {
28269a74367SOliver-Rainer Wittmann                     bIsValidPos = sal_False;
28369a74367SOliver-Rainer Wittmann                     nCntntPos = 0;
28469a74367SOliver-Rainer Wittmann                     rPtIdx = aIdx;
28569a74367SOliver-Rainer Wittmann                     if( 0 == ( pCNd = rPtIdx.GetNode().GetCntntNode() ) )
28669a74367SOliver-Rainer Wittmann                     {
28769a74367SOliver-Rainer Wittmann                         // dann auf den Anfang vom Doc
28869a74367SOliver-Rainer Wittmann                         rPtIdx = rNds.GetEndOfExtras();
28969a74367SOliver-Rainer Wittmann                         pCNd = rNds.GoNext( &rPtIdx );
29069a74367SOliver-Rainer Wittmann                     }
29169a74367SOliver-Rainer Wittmann                 }
29269a74367SOliver-Rainer Wittmann             }
293cdf0e10cSrcweir 
29469a74367SOliver-Rainer Wittmann             // ContentIndex noch anmelden:
29569a74367SOliver-Rainer Wittmann             xub_StrLen nTmpPos = bIsValidPos ? (bGoNxt ? 0 : pCNd->Len()) : nCntntPos;
29669a74367SOliver-Rainer Wittmann             GetPoint()->nContent.Assign( pCNd, nTmpPos );
29769a74367SOliver-Rainer Wittmann             if( !bIsValidPos || !bValidNodesRange ||
29869a74367SOliver-Rainer Wittmann                 // sollten wir in einer Tabelle gelandet sein?
29969a74367SOliver-Rainer Wittmann                     IsInProtectTable( sal_True ) )
30069a74367SOliver-Rainer Wittmann                     return sal_True;
30169a74367SOliver-Rainer Wittmann         }
302cdf0e10cSrcweir 
30369a74367SOliver-Rainer Wittmann         // oder sollte eine geschuetzte Section innerhalb der Selektion liegen?
30469a74367SOliver-Rainer Wittmann         if( HasMark() && bSkipOverProtectSections)
30569a74367SOliver-Rainer Wittmann         {
30669a74367SOliver-Rainer Wittmann             sal_uLong nSttIdx = GetMark()->nNode.GetIndex(),
30769a74367SOliver-Rainer Wittmann                 nEndIdx = GetPoint()->nNode.GetIndex();
30869a74367SOliver-Rainer Wittmann             if( nEndIdx <= nSttIdx )
30969a74367SOliver-Rainer Wittmann             {
31069a74367SOliver-Rainer Wittmann                 sal_uLong nTmp = nSttIdx;
31169a74367SOliver-Rainer Wittmann                 nSttIdx = nEndIdx;
31269a74367SOliver-Rainer Wittmann                 nEndIdx = nTmp;
31369a74367SOliver-Rainer Wittmann             }
314cdf0e10cSrcweir 
31569a74367SOliver-Rainer Wittmann             const SwSectionFmts& rFmts = pDoc->GetSections();
31669a74367SOliver-Rainer Wittmann             for( sal_uInt16 n = 0; n < rFmts.Count(); ++n )
31769a74367SOliver-Rainer Wittmann             {
31869a74367SOliver-Rainer Wittmann                 const SwSectionFmt* pFmt = rFmts[n];
31969a74367SOliver-Rainer Wittmann                 const SvxProtectItem& rProtect = pFmt->GetProtect();
32069a74367SOliver-Rainer Wittmann                 if( rProtect.IsCntntProtected() )
32169a74367SOliver-Rainer Wittmann                 {
32269a74367SOliver-Rainer Wittmann                     const SwFmtCntnt& rCntnt = pFmt->GetCntnt(sal_False);
32369a74367SOliver-Rainer Wittmann                     ASSERT( rCntnt.GetCntntIdx(), "wo ist der SectionNode?" );
32469a74367SOliver-Rainer Wittmann                     sal_uLong nIdx = rCntnt.GetCntntIdx()->GetIndex();
32569a74367SOliver-Rainer Wittmann                     if( nSttIdx <= nIdx && nEndIdx >= nIdx )
32669a74367SOliver-Rainer Wittmann                     {
32769a74367SOliver-Rainer Wittmann                         // ist es keine gelinkte Section, dann kann sie auch
32869a74367SOliver-Rainer Wittmann                         // nicht mitselektiert werden
32969a74367SOliver-Rainer Wittmann                         const SwSection& rSect = *pFmt->GetSection();
33069a74367SOliver-Rainer Wittmann                         if( CONTENT_SECTION == rSect.GetType() )
33169a74367SOliver-Rainer Wittmann                         {
33269a74367SOliver-Rainer Wittmann                             RestoreSavePos();
33369a74367SOliver-Rainer Wittmann                             return sal_True;
33469a74367SOliver-Rainer Wittmann                         }
33569a74367SOliver-Rainer Wittmann                     }
33669a74367SOliver-Rainer Wittmann                 }
33769a74367SOliver-Rainer Wittmann             }
33869a74367SOliver-Rainer Wittmann         }
339cdf0e10cSrcweir 
34069a74367SOliver-Rainer Wittmann     }
341cdf0e10cSrcweir 
34269a74367SOliver-Rainer Wittmann     const SwNode* pNd = &GetPoint()->nNode.GetNode();
343cdf0e10cSrcweir     if( pNd->IsCntntNode() && !dynamic_cast<SwUnoCrsr*>(this) )
34469a74367SOliver-Rainer Wittmann     {
34569a74367SOliver-Rainer Wittmann         const SwCntntFrm* pFrm = ((SwCntntNode*)pNd)->getLayoutFrm( pDoc->GetCurrentLayout() );
346*150c6d32SOliver-Rainer Wittmann         if( pFrm != NULL
347*150c6d32SOliver-Rainer Wittmann             && pFrm->IsValid()
34869a74367SOliver-Rainer Wittmann             && 0 == pFrm->Frm().Height()
34969a74367SOliver-Rainer Wittmann             && 0 != ( nsSwCursorSelOverFlags::SELOVER_CHANGEPOS & eFlags ) )
35069a74367SOliver-Rainer Wittmann         {
351cdf0e10cSrcweir             // skip to the next / prev valid paragraph with a layout
35269a74367SOliver-Rainer Wittmann             SwNodeIndex& rPtIdx = GetPoint()->nNode;
35369a74367SOliver-Rainer Wittmann             int bGoNxt = pSavePos->nNode < rPtIdx.GetIndex();
35469a74367SOliver-Rainer Wittmann             while( 0 != ( pFrm = ( bGoNxt ? pFrm->GetNextCntntFrm() : pFrm->GetPrevCntntFrm() ))
35569a74367SOliver-Rainer Wittmann                    && 0 == pFrm->Frm().Height() )
35669a74367SOliver-Rainer Wittmann                 ;
357cdf0e10cSrcweir 
358cdf0e10cSrcweir             // --> LIJIAN/FME 2007-11-27 #i72394# skip to prev /next valid paragraph
359cdf0e10cSrcweir             // with a layout in case the first search did not succeed:
360*150c6d32SOliver-Rainer Wittmann             if ( pFrm == NULL )
361cdf0e10cSrcweir             {
362cdf0e10cSrcweir                 bGoNxt = !bGoNxt;
363cdf0e10cSrcweir                 pFrm = ((SwCntntNode*)pNd)->getLayoutFrm( pDoc->GetCurrentLayout() );
364*150c6d32SOliver-Rainer Wittmann                 while ( pFrm != NULL
365*150c6d32SOliver-Rainer Wittmann                         && 0 == pFrm->Frm().Height() )
366cdf0e10cSrcweir                 {
367*150c6d32SOliver-Rainer Wittmann                     pFrm = bGoNxt ? pFrm->GetNextCntntFrm() : pFrm->GetPrevCntntFrm();
368cdf0e10cSrcweir                 }
369cdf0e10cSrcweir             }
370cdf0e10cSrcweir             // <--
371cdf0e10cSrcweir 
372*150c6d32SOliver-Rainer Wittmann             SwCntntNode* pCNd = (pFrm != NULL) ? (SwCntntNode*)pFrm->GetNode() : NULL;
373*150c6d32SOliver-Rainer Wittmann             if ( pCNd != NULL )
37469a74367SOliver-Rainer Wittmann             {
37569a74367SOliver-Rainer Wittmann                 // set this cntntNode as new position
37669a74367SOliver-Rainer Wittmann                 rPtIdx = *pCNd;
377cdf0e10cSrcweir                 pNd = pCNd;
378cdf0e10cSrcweir 
379*150c6d32SOliver-Rainer Wittmann                 // assign corresponding ContentIndex
380*150c6d32SOliver-Rainer Wittmann                 const xub_StrLen nTmpPos = bGoNxt ? 0 : pCNd->Len();
38169a74367SOliver-Rainer Wittmann                 GetPoint()->nContent.Assign( pCNd, nTmpPos );
382cdf0e10cSrcweir 
383*150c6d32SOliver-Rainer Wittmann                 if ( rPtIdx.GetIndex() == pSavePos->nNode
384*150c6d32SOliver-Rainer Wittmann                      && nTmpPos == pSavePos->nCntnt )
385*150c6d32SOliver-Rainer Wittmann                 {
386*150c6d32SOliver-Rainer Wittmann                     // new position equals saved one
387*150c6d32SOliver-Rainer Wittmann                     // --> trigger restore of saved pos by setting <pFrm> to NULL - see below
388*150c6d32SOliver-Rainer Wittmann                     pFrm = NULL;
389*150c6d32SOliver-Rainer Wittmann                 }
390*150c6d32SOliver-Rainer Wittmann 
391*150c6d32SOliver-Rainer Wittmann                 if ( IsInProtectTable( sal_True ) )
392*150c6d32SOliver-Rainer Wittmann                 {
393*150c6d32SOliver-Rainer Wittmann                     // new position in protected table
394*150c6d32SOliver-Rainer Wittmann                     // --> trigger restore of saved pos by setting <pFrm> to NULL - see below
395*150c6d32SOliver-Rainer Wittmann                     pFrm = NULL;
396*150c6d32SOliver-Rainer Wittmann                 }
39769a74367SOliver-Rainer Wittmann             }
39869a74367SOliver-Rainer Wittmann         }
399cdf0e10cSrcweir 
400*150c6d32SOliver-Rainer Wittmann         if( pFrm == NULL )
40169a74367SOliver-Rainer Wittmann         {
40269a74367SOliver-Rainer Wittmann             DeleteMark();
40369a74367SOliver-Rainer Wittmann             RestoreSavePos();
404*150c6d32SOliver-Rainer Wittmann             return sal_True;
40569a74367SOliver-Rainer Wittmann         }
40669a74367SOliver-Rainer Wittmann     }
407cdf0e10cSrcweir 
40869a74367SOliver-Rainer Wittmann     // darf der Cursor in geschuetzen "Nodes" stehen?
409cdf0e10cSrcweir     if( 0 == ( nsSwCursorSelOverFlags::SELOVER_CHANGEPOS & eFlags ) && !IsAtValidPos() )
41069a74367SOliver-Rainer Wittmann     {
41169a74367SOliver-Rainer Wittmann         DeleteMark();
41269a74367SOliver-Rainer Wittmann         RestoreSavePos();
41369a74367SOliver-Rainer Wittmann         return sal_True;
41469a74367SOliver-Rainer Wittmann     }
415cdf0e10cSrcweir 
41669a74367SOliver-Rainer Wittmann     if( !HasMark() )
41769a74367SOliver-Rainer Wittmann         return sal_False;
418cdf0e10cSrcweir 
41969a74367SOliver-Rainer Wittmann     //JP 19.08.98: teste mal auf ungueltige Selektion - sprich ueber
42069a74367SOliver-Rainer Wittmann     // 				GrundSections:
42169a74367SOliver-Rainer Wittmann     if( !::CheckNodesRange( GetMark()->nNode, GetPoint()->nNode, sal_True ))
42269a74367SOliver-Rainer Wittmann     {
42369a74367SOliver-Rainer Wittmann         DeleteMark();
42469a74367SOliver-Rainer Wittmann         RestoreSavePos();
42569a74367SOliver-Rainer Wittmann         return sal_True;		// ohne Frames geht gar nichts!
42669a74367SOliver-Rainer Wittmann     }
427cdf0e10cSrcweir 
42869a74367SOliver-Rainer Wittmann     if( (pNd = &GetMark()->nNode.GetNode())->IsCntntNode()
42969a74367SOliver-Rainer Wittmann         && !((SwCntntNode*)pNd)->getLayoutFrm( pDoc->GetCurrentLayout() )
43069a74367SOliver-Rainer Wittmann         && !dynamic_cast<SwUnoCrsr*>(this) )
43169a74367SOliver-Rainer Wittmann     {
43269a74367SOliver-Rainer Wittmann         DeleteMark();
43369a74367SOliver-Rainer Wittmann         RestoreSavePos();
43469a74367SOliver-Rainer Wittmann         return sal_True;		// ohne Frames geht gar nichts!
43569a74367SOliver-Rainer Wittmann     }
436cdf0e10cSrcweir 
43769a74367SOliver-Rainer Wittmann     // assure that selection is only inside an InputField or contains the InputField completely
43869a74367SOliver-Rainer Wittmann     {
43969a74367SOliver-Rainer Wittmann         const SwTxtAttr* pInputFldTxtAttrAtPoint = NULL;
44069a74367SOliver-Rainer Wittmann         SwTxtNode* pTxtNdAtPoint = GetPoint()->nNode.GetNode().GetTxtNode();
44169a74367SOliver-Rainer Wittmann         if ( pTxtNdAtPoint != NULL )
44269a74367SOliver-Rainer Wittmann         {
44369a74367SOliver-Rainer Wittmann             pInputFldTxtAttrAtPoint =
44469a74367SOliver-Rainer Wittmann                 pTxtNdAtPoint->GetTxtAttrAt( GetPoint()->nContent.GetIndex(), RES_TXTATR_INPUTFIELD, SwTxtNode::PARENT );
44569a74367SOliver-Rainer Wittmann         }
446cdf0e10cSrcweir 
44769a74367SOliver-Rainer Wittmann         const SwTxtAttr* pInputFldTxtAttrAtMark = NULL;
44869a74367SOliver-Rainer Wittmann         SwTxtNode* pTxtNdAtMark = GetMark()->nNode.GetNode().GetTxtNode();
44969a74367SOliver-Rainer Wittmann         if ( pTxtNdAtMark != NULL )
45069a74367SOliver-Rainer Wittmann         {
45169a74367SOliver-Rainer Wittmann             pInputFldTxtAttrAtMark =
45269a74367SOliver-Rainer Wittmann                 pTxtNdAtMark->GetTxtAttrAt( GetMark()->nContent.GetIndex(), RES_TXTATR_INPUTFIELD, SwTxtNode::PARENT );
45369a74367SOliver-Rainer Wittmann         }
454cdf0e10cSrcweir 
45569a74367SOliver-Rainer Wittmann         if ( pInputFldTxtAttrAtPoint != pInputFldTxtAttrAtMark )
45669a74367SOliver-Rainer Wittmann         {
45769a74367SOliver-Rainer Wittmann             const sal_uLong nRefNodeIdx =
45869a74367SOliver-Rainer Wittmann                 ( nsSwCursorSelOverFlags::SELOVER_TOGGLE & eFlags )
45969a74367SOliver-Rainer Wittmann                 ? pSavePos->nNode
46069a74367SOliver-Rainer Wittmann                 : GetMark()->nNode.GetIndex();
46169a74367SOliver-Rainer Wittmann             const xub_StrLen nRefContentIdx =
46269a74367SOliver-Rainer Wittmann                 ( nsSwCursorSelOverFlags::SELOVER_TOGGLE & eFlags )
46369a74367SOliver-Rainer Wittmann                 ? pSavePos->nCntnt
46469a74367SOliver-Rainer Wittmann                 : GetMark()->nContent.GetIndex();
46569a74367SOliver-Rainer Wittmann             const bool bIsForwardSelection =
46669a74367SOliver-Rainer Wittmann                 nRefNodeIdx < GetPoint()->nNode.GetIndex()
46769a74367SOliver-Rainer Wittmann                 || ( nRefNodeIdx == GetPoint()->nNode.GetIndex()
46869a74367SOliver-Rainer Wittmann                      && nRefContentIdx < GetPoint()->nContent.GetIndex() );
46969a74367SOliver-Rainer Wittmann 
47069a74367SOliver-Rainer Wittmann             if ( pInputFldTxtAttrAtPoint != NULL )
47169a74367SOliver-Rainer Wittmann             {
47269a74367SOliver-Rainer Wittmann                 const xub_StrLen nNewPointPos =
47369a74367SOliver-Rainer Wittmann                     bIsForwardSelection ? *(pInputFldTxtAttrAtPoint->End()) : *(pInputFldTxtAttrAtPoint->GetStart());
47469a74367SOliver-Rainer Wittmann                 GetPoint()->nContent.Assign( pTxtNdAtPoint, nNewPointPos );
47569a74367SOliver-Rainer Wittmann             }
476cdf0e10cSrcweir 
47769a74367SOliver-Rainer Wittmann             if ( pInputFldTxtAttrAtMark != NULL )
47869a74367SOliver-Rainer Wittmann             {
47969a74367SOliver-Rainer Wittmann                 const xub_StrLen nNewMarkPos =
48069a74367SOliver-Rainer Wittmann                     bIsForwardSelection ? *(pInputFldTxtAttrAtMark->GetStart()) : *(pInputFldTxtAttrAtMark->End());
48169a74367SOliver-Rainer Wittmann                 GetMark()->nContent.Assign( pTxtNdAtMark, nNewMarkPos );
48269a74367SOliver-Rainer Wittmann             }
48369a74367SOliver-Rainer Wittmann         }
48469a74367SOliver-Rainer Wittmann     }
485cdf0e10cSrcweir 
486bb494cbeSOliver-Rainer Wittmann     const SwTableNode* pPtNd = GetPoint()->nNode.GetNode().FindTableNode();
487bb494cbeSOliver-Rainer Wittmann     const SwTableNode* pMrkNd = GetMark()->nNode.GetNode().FindTableNode();
48869a74367SOliver-Rainer Wittmann     // beide in keinem oder beide im gleichen TableNode
48969a74367SOliver-Rainer Wittmann     if( ( !pMrkNd && !pPtNd ) || pPtNd == pMrkNd )
49069a74367SOliver-Rainer Wittmann         return sal_False;
49169a74367SOliver-Rainer Wittmann 
49269a74367SOliver-Rainer Wittmann     // in unterschiedlichen Tabellen oder nur Mark in der Tabelle
49369a74367SOliver-Rainer Wittmann     if( ( pPtNd && pMrkNd ) || pMrkNd )
49469a74367SOliver-Rainer Wittmann     {
49569a74367SOliver-Rainer Wittmann         // dann lasse das nicht zu, alte Pos zurueck
49669a74367SOliver-Rainer Wittmann         RestoreSavePos();
49769a74367SOliver-Rainer Wittmann         // Crsr bleibt an der alten Position
49869a74367SOliver-Rainer Wittmann         return sal_True;
49969a74367SOliver-Rainer Wittmann     }
50069a74367SOliver-Rainer Wittmann 
50169a74367SOliver-Rainer Wittmann     // ACHTUNG: dieses kann nicht im TableMode geschehen !!
50269a74367SOliver-Rainer Wittmann     if( pPtNd )		// nur Point in Tabelle, dann gehe hinter/vor diese
50369a74367SOliver-Rainer Wittmann     {
504cdf0e10cSrcweir         if( nsSwCursorSelOverFlags::SELOVER_CHANGEPOS & eFlags )
50569a74367SOliver-Rainer Wittmann         {
50669a74367SOliver-Rainer Wittmann             sal_Bool bSelTop = GetPoint()->nNode.GetIndex() <
50769a74367SOliver-Rainer Wittmann                 (( nsSwCursorSelOverFlags::SELOVER_TOGGLE & eFlags ) ? pSavePos->nNode
50869a74367SOliver-Rainer Wittmann                 : GetMark()->nNode.GetIndex());
509cdf0e10cSrcweir 
51069a74367SOliver-Rainer Wittmann             do {
51169a74367SOliver-Rainer Wittmann                 // in Schleife fuer Tabelle hinter Tabelle
51269a74367SOliver-Rainer Wittmann                 sal_uLong nSEIdx = pPtNd->EndOfSectionIndex();
51369a74367SOliver-Rainer Wittmann                 sal_uLong nSttEndTbl = nSEIdx + 1; // dflt. Sel. nach unten
514cdf0e10cSrcweir 
51569a74367SOliver-Rainer Wittmann                 if( bSelTop )								// Sel. nach oben
51669a74367SOliver-Rainer Wittmann                     nSttEndTbl = rNds[ nSEIdx ]->StartOfSectionIndex() - 1;
517cdf0e10cSrcweir 
51869a74367SOliver-Rainer Wittmann                 GetPoint()->nNode = nSttEndTbl;
519cdf0e10cSrcweir                 const SwNode* pMyNd = GetNode();
520cdf0e10cSrcweir 
521cdf0e10cSrcweir                 if( pMyNd->IsSectionNode() || ( pMyNd->IsEndNode() &&
522cdf0e10cSrcweir                     pMyNd->StartOfSectionNode()->IsSectionNode() ) )
52369a74367SOliver-Rainer Wittmann                 {
52469a74367SOliver-Rainer Wittmann                     // die lassen wir zu:
525cdf0e10cSrcweir                     pMyNd = bSelTop
52669a74367SOliver-Rainer Wittmann                         ? rNds.GoPrevSection( &GetPoint()->nNode,sal_True,sal_False )
52769a74367SOliver-Rainer Wittmann                         : rNds.GoNextSection( &GetPoint()->nNode,sal_True,sal_False );
528cdf0e10cSrcweir 
529cdf0e10cSrcweir                     /* #i12312# Handle failure of Go{Prev|Next}Section */
530cdf0e10cSrcweir                     if ( 0 == pMyNd)
531cdf0e10cSrcweir                         break;
532cdf0e10cSrcweir 
533cdf0e10cSrcweir                     if( 0 != ( pPtNd = pMyNd->FindTableNode() ))
53469a74367SOliver-Rainer Wittmann                         continue;
53569a74367SOliver-Rainer Wittmann                 }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir                 if( pMyNd->IsCntntNode() &&      // ist es ein ContentNode ??
53869a74367SOliver-Rainer Wittmann                     ::CheckNodesRange( GetMark()->nNode,
53969a74367SOliver-Rainer Wittmann                     GetPoint()->nNode, sal_True ))
54069a74367SOliver-Rainer Wittmann                 {
541cdf0e10cSrcweir                     // TABLE IN TABLE
542cdf0e10cSrcweir                     const SwTableNode* pOuterTableNd = pMyNd->FindTableNode();
54369a74367SOliver-Rainer Wittmann                     if ( pOuterTableNd )
544cdf0e10cSrcweir                         pMyNd = pOuterTableNd;
545cdf0e10cSrcweir                     else
546cdf0e10cSrcweir                     {
547cdf0e10cSrcweir                         SwCntntNode* pCNd = (SwCntntNode*)pMyNd;
54869a74367SOliver-Rainer Wittmann                         xub_StrLen nTmpPos = bSelTop ? pCNd->Len() : 0;
54969a74367SOliver-Rainer Wittmann                         GetPoint()->nContent.Assign( pCNd, nTmpPos );
55069a74367SOliver-Rainer Wittmann                         return sal_False;
551cdf0e10cSrcweir                     }
55269a74367SOliver-Rainer Wittmann                 }
55369a74367SOliver-Rainer Wittmann                 if( bSelTop
554cdf0e10cSrcweir                     ? ( !pMyNd->IsEndNode() || 0 == ( pPtNd = pMyNd->FindTableNode() ))
555cdf0e10cSrcweir                     : 0 == ( pPtNd = pMyNd->GetTableNode() ))
55669a74367SOliver-Rainer Wittmann                     break;
55769a74367SOliver-Rainer Wittmann             } while( sal_True );
55869a74367SOliver-Rainer Wittmann         }
559cdf0e10cSrcweir 
56069a74367SOliver-Rainer Wittmann         // dann verbleibe auf der alten Position
56169a74367SOliver-Rainer Wittmann         RestoreSavePos();
56269a74367SOliver-Rainer Wittmann         return sal_True;		// Crsr bleibt an der alten Position
56369a74367SOliver-Rainer Wittmann     }
56469a74367SOliver-Rainer Wittmann 
56569a74367SOliver-Rainer Wittmann     return sal_False;
566cdf0e10cSrcweir }
567cdf0e10cSrcweir 
568cdf0e10cSrcweir #if defined( UNX )
569cdf0e10cSrcweir #define IDX     (*pCellStt)
570cdf0e10cSrcweir #else
571cdf0e10cSrcweir #define IDX     aCellStt
572cdf0e10cSrcweir #endif
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 
IsInProtectTable(sal_Bool bMove,sal_Bool bChgCrsr)575cdf0e10cSrcweir sal_Bool SwCursor::IsInProtectTable( sal_Bool bMove, sal_Bool bChgCrsr )
576cdf0e10cSrcweir {
577cdf0e10cSrcweir 	SwCntntNode* pCNd = GetCntntNode();
578cdf0e10cSrcweir 	if( !pCNd )
579cdf0e10cSrcweir         return sal_False;
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 	// No table, no protected cell:
582cdf0e10cSrcweir     const SwTableNode* pTableNode = pCNd->FindTableNode();
583cdf0e10cSrcweir     if ( !pTableNode )
584cdf0e10cSrcweir         return sal_False;
585cdf0e10cSrcweir 
586cdf0e10cSrcweir     // Current position == last save position?
587cdf0e10cSrcweir     if ( pSavePos->nNode == GetPoint()->nNode.GetIndex() )
588cdf0e10cSrcweir         return sal_False;
589cdf0e10cSrcweir 
590cdf0e10cSrcweir     // Check for convered cell:
591cdf0e10cSrcweir     bool bInCoveredCell = false;
592cdf0e10cSrcweir     const SwStartNode* pTmpSttNode = pCNd->FindTableBoxStartNode();
593cdf0e10cSrcweir     ASSERT( pTmpSttNode, "In table, therefore I expect to get a SwTableBoxStartNode" )
594cdf0e10cSrcweir     const SwTableBox* pBox = pTmpSttNode ? pTableNode->GetTable().GetTblBox( pTmpSttNode->GetIndex() ) : 0; //Robust #151355
595cdf0e10cSrcweir     if ( pBox && pBox->getRowSpan() < 1 ) // Robust #151270
596cdf0e10cSrcweir         bInCoveredCell = true;
597cdf0e10cSrcweir 
598cdf0e10cSrcweir     // Positions of covered cells are not acceptable:
599cdf0e10cSrcweir     if ( !bInCoveredCell )
600cdf0e10cSrcweir     {
601cdf0e10cSrcweir         // Position not protected?
602cdf0e10cSrcweir         if ( !pCNd->IsProtect() )
603cdf0e10cSrcweir 		    return sal_False;
604cdf0e10cSrcweir 
605cdf0e10cSrcweir         // Cursor in protected cells allowed?
606cdf0e10cSrcweir         if ( IsReadOnlyAvailable() )
607cdf0e10cSrcweir             return sal_False;
608cdf0e10cSrcweir     }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir     // If we reach this point, we are in a protected or covered table cell!
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 	if( !bMove )
613cdf0e10cSrcweir 	{
614cdf0e10cSrcweir 		if( bChgCrsr )
615cdf0e10cSrcweir 			// restore the last save position
616cdf0e10cSrcweir 			RestoreSavePos();
617cdf0e10cSrcweir 		return sal_True;		// Crsr bleibt an der alten Position
618cdf0e10cSrcweir 	}
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 	// wir stehen in einer geschuetzten TabellenZelle
621cdf0e10cSrcweir 	// von Oben nach Unten Traveln ?
622cdf0e10cSrcweir 	if( pSavePos->nNode < GetPoint()->nNode.GetIndex() )
623cdf0e10cSrcweir 	{
624cdf0e10cSrcweir 		// suche die naechste "gueltige" Box
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 		// folgt nach dem EndNode der Zelle ein weiterer StartNode, dann
627cdf0e10cSrcweir 		// gibt es auch eine naechste Zelle
628cdf0e10cSrcweir #if defined( UNX )
629cdf0e10cSrcweir 		SwNodeIndex* pCellStt = new SwNodeIndex( *GetNode()->
630cdf0e10cSrcweir 						FindTableBoxStartNode()->EndOfSectionNode(), 1 );
631cdf0e10cSrcweir #else
632cdf0e10cSrcweir 		SwNodeIndex aCellStt( *GetNode()->FindTableBoxStartNode()->EndOfSectionNode(), 1 );
633cdf0e10cSrcweir #endif
634cdf0e10cSrcweir 		sal_Bool bProt = sal_True;
635cdf0e10cSrcweir GoNextCell:
636cdf0e10cSrcweir 		do {
637cdf0e10cSrcweir 			if( !IDX.GetNode().IsStartNode() )
638cdf0e10cSrcweir 				break;
639cdf0e10cSrcweir 			IDX++;
640cdf0e10cSrcweir 			if( 0 == ( pCNd = IDX.GetNode().GetCntntNode() ))
641cdf0e10cSrcweir 				pCNd = IDX.GetNodes().GoNext( &IDX );
642cdf0e10cSrcweir 			if( 0 == ( bProt = pCNd->IsProtect() ))
643cdf0e10cSrcweir 				break;
644cdf0e10cSrcweir 			IDX.Assign( *pCNd->FindTableBoxStartNode()->EndOfSectionNode(), 1 );
645cdf0e10cSrcweir 		} while( bProt );
646cdf0e10cSrcweir 
647cdf0e10cSrcweir SetNextCrsr:
648cdf0e10cSrcweir 		if( !bProt )		// eine freie Zelle gefunden
649cdf0e10cSrcweir 		{
650cdf0e10cSrcweir 			GetPoint()->nNode = IDX;
651cdf0e10cSrcweir #if defined( UNX )
652cdf0e10cSrcweir 			delete pCellStt;
653cdf0e10cSrcweir #endif
654cdf0e10cSrcweir             SwCntntNode* pTmpCNd = GetCntntNode();
655cdf0e10cSrcweir             if( pTmpCNd )
656cdf0e10cSrcweir 			{
657cdf0e10cSrcweir                 GetPoint()->nContent.Assign( pTmpCNd, 0 );
658cdf0e10cSrcweir 				return sal_False;
659cdf0e10cSrcweir 			}
660cdf0e10cSrcweir             return IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
661cdf0e10cSrcweir                              nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
662cdf0e10cSrcweir 		}
663cdf0e10cSrcweir 		// am Ende der Tabelle, also setze hinter diese
664cdf0e10cSrcweir 		IDX++;     // auf den naechsten Node
665cdf0e10cSrcweir 		SwNode* pNd;
666cdf0e10cSrcweir 		if( ( pNd = &IDX.GetNode())->IsEndNode() || HasMark())
667cdf0e10cSrcweir 		{
668cdf0e10cSrcweir 			// Tabelle allein in einem FlyFrame oder SSelection,
669cdf0e10cSrcweir 			// dann verbleibe auf der alten Position
670cdf0e10cSrcweir 			if( bChgCrsr )
671cdf0e10cSrcweir 				RestoreSavePos();
672cdf0e10cSrcweir #if defined( UNX )
673cdf0e10cSrcweir 			delete pCellStt;
674cdf0e10cSrcweir #endif
675cdf0e10cSrcweir 			return sal_True;        // Crsr bleibt an der alten Position
676cdf0e10cSrcweir 		}
677cdf0e10cSrcweir 		else if( pNd->IsTableNode() && IDX++ )
678cdf0e10cSrcweir 			goto GoNextCell;
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 		bProt = sal_False;		// Index steht jetzt auf einem ContentNode
681cdf0e10cSrcweir 		goto SetNextCrsr;
682cdf0e10cSrcweir 	}
683cdf0e10cSrcweir 
684cdf0e10cSrcweir 	// suche die vorherige "gueltige" Box
685cdf0e10cSrcweir 	{
686cdf0e10cSrcweir 		// liegt vor dem StartNode der Zelle ein weiterer EndNode, dann
687cdf0e10cSrcweir 		// gibt es auch eine vorherige Zelle
688cdf0e10cSrcweir #if defined( UNX )
689cdf0e10cSrcweir 		SwNodeIndex* pCellStt = new SwNodeIndex(
690cdf0e10cSrcweir 					*GetNode()->FindTableBoxStartNode(), -1 );
691cdf0e10cSrcweir #else
692cdf0e10cSrcweir 		SwNodeIndex aCellStt( *GetNode()->FindTableBoxStartNode(), -1 );
693cdf0e10cSrcweir #endif
694cdf0e10cSrcweir 		SwNode* pNd;
695cdf0e10cSrcweir 		sal_Bool bProt = sal_True;
696cdf0e10cSrcweir GoPrevCell:
697cdf0e10cSrcweir 		do {
698cdf0e10cSrcweir 			if( !( pNd = &IDX.GetNode())->IsEndNode() )
699cdf0e10cSrcweir 				break;
700cdf0e10cSrcweir 			IDX.Assign( *pNd->StartOfSectionNode(), +1 );
701cdf0e10cSrcweir 			if( 0 == ( pCNd = IDX.GetNode().GetCntntNode() ))
702cdf0e10cSrcweir 				pCNd = pNd->GetNodes().GoNext( &IDX );
703cdf0e10cSrcweir 			if( 0 == ( bProt = pCNd->IsProtect() ))
704cdf0e10cSrcweir 				break;
705cdf0e10cSrcweir 			IDX.Assign( *pNd->FindTableBoxStartNode(), -1 );
706cdf0e10cSrcweir 		} while( bProt );
707cdf0e10cSrcweir 
708cdf0e10cSrcweir SetPrevCrsr:
709cdf0e10cSrcweir 		if( !bProt )		// eine freie Zelle gefunden
710cdf0e10cSrcweir 		{
711cdf0e10cSrcweir 			GetPoint()->nNode = IDX;
712cdf0e10cSrcweir #if defined( UNX )
713cdf0e10cSrcweir 			delete pCellStt;
714cdf0e10cSrcweir #endif
715cdf0e10cSrcweir             SwCntntNode* pTmpCNd = GetCntntNode();
716cdf0e10cSrcweir             if( pTmpCNd )
717cdf0e10cSrcweir 			{
718cdf0e10cSrcweir                 GetPoint()->nContent.Assign( pTmpCNd, 0 );
719cdf0e10cSrcweir 				return sal_False;
720cdf0e10cSrcweir 			}
721cdf0e10cSrcweir             return IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
722cdf0e10cSrcweir                              nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
723cdf0e10cSrcweir 		}
724cdf0e10cSrcweir 		// am Start der Tabelle, also setze vor diese
725cdf0e10cSrcweir 		IDX--;     // auf den naechsten Node
726cdf0e10cSrcweir 		if( ( pNd = &IDX.GetNode())->IsStartNode() || HasMark() )
727cdf0e10cSrcweir 		{
728cdf0e10cSrcweir 			// Tabelle allein in einem FlyFrame oder Selektion,
729cdf0e10cSrcweir 			// dann verbleibe auf der alten Position
730cdf0e10cSrcweir 			if( bChgCrsr )
731cdf0e10cSrcweir 				RestoreSavePos();
732cdf0e10cSrcweir #if defined( UNX )
733cdf0e10cSrcweir 			delete pCellStt;
734cdf0e10cSrcweir #endif
735cdf0e10cSrcweir 			return sal_True;        // Crsr bleibt an der alten Position
736cdf0e10cSrcweir 		}
737cdf0e10cSrcweir 		else if( pNd->StartOfSectionNode()->IsTableNode() && IDX-- )
738cdf0e10cSrcweir 			goto GoPrevCell;
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 		bProt = sal_False;		// Index steht jetzt auf einem ContentNode
741cdf0e10cSrcweir 		goto SetPrevCrsr;
742cdf0e10cSrcweir 	}
743cdf0e10cSrcweir }
744cdf0e10cSrcweir 
745cdf0e10cSrcweir // sal_True: an die Position kann der Cursor gesetzt werden
IsAtValidPos(sal_Bool bPoint) const746cdf0e10cSrcweir sal_Bool SwCursor::IsAtValidPos( sal_Bool bPoint ) const
747cdf0e10cSrcweir {
748cdf0e10cSrcweir 	const SwDoc* pDoc = GetDoc();
749cdf0e10cSrcweir 	const SwPosition* pPos = bPoint ? GetPoint() : GetMark();
750cdf0e10cSrcweir 	const SwNode* pNd = &pPos->nNode.GetNode();
751cdf0e10cSrcweir 
752cdf0e10cSrcweir 	if( pNd->IsCntntNode() && !((SwCntntNode*)pNd)->getLayoutFrm( pDoc->GetCurrentLayout() ) &&
753cdf0e10cSrcweir         !dynamic_cast<const SwUnoCrsr*>(this) )
754cdf0e10cSrcweir     {
755cdf0e10cSrcweir 		return sal_False;
756cdf0e10cSrcweir     }
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 		//JP 28.10.97: Bug 45129 - im UI-ReadOnly ist alles erlaubt
759cdf0e10cSrcweir 	if( !pDoc->GetDocShell() || !pDoc->GetDocShell()->IsReadOnlyUI() )
760cdf0e10cSrcweir 		return sal_True;
761cdf0e10cSrcweir 
762cdf0e10cSrcweir 	sal_Bool bCrsrInReadOnly = IsReadOnlyAvailable();
763cdf0e10cSrcweir 	if( !bCrsrInReadOnly && pNd->IsProtect() )
764cdf0e10cSrcweir 		return sal_False;
765cdf0e10cSrcweir 
766cdf0e10cSrcweir 	const SwSectionNode* pSectNd = pNd->FindSectionNode();
767cdf0e10cSrcweir 	if( pSectNd && (pSectNd->GetSection().IsHiddenFlag() ||
768cdf0e10cSrcweir 					( !bCrsrInReadOnly && pSectNd->GetSection().IsProtectFlag() )))
769cdf0e10cSrcweir 		return sal_False;
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 	return sal_True;
772cdf0e10cSrcweir }
773cdf0e10cSrcweir 
SaveTblBoxCntnt(const SwPosition *)774cdf0e10cSrcweir void SwCursor::SaveTblBoxCntnt( const SwPosition* )	{}
775cdf0e10cSrcweir 
776cdf0e10cSrcweir // setze den SRange fuer das Suchen im Dokument
MakeFindRange(SwDocPositions nStart,SwDocPositions nEnd,SwPaM * pRange) const777cdf0e10cSrcweir SwMoveFnCollection* SwCursor::MakeFindRange( SwDocPositions nStart,
778cdf0e10cSrcweir 								SwDocPositions nEnd, SwPaM* pRange ) const
779cdf0e10cSrcweir {
780cdf0e10cSrcweir 	pRange->SetMark();
781cdf0e10cSrcweir 	FillFindPos( nStart, *pRange->GetMark() );
782cdf0e10cSrcweir 	FillFindPos( nEnd, *pRange->GetPoint() );
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 	// bestimme die Richtung, in der zu suchen ist
785cdf0e10cSrcweir 	// ( GetPoint > GetMark -> vorwaerts, sonst rueckwaerts )
786cdf0e10cSrcweir 	return ( DOCPOS_START == nStart || DOCPOS_OTHERSTART == nStart ||
787cdf0e10cSrcweir 			  (DOCPOS_CURR == nStart &&
788cdf0e10cSrcweir 				(DOCPOS_END == nEnd || DOCPOS_OTHEREND == nEnd ) ))
789cdf0e10cSrcweir 				? fnMoveForward : fnMoveBackward;
790cdf0e10cSrcweir }
791cdf0e10cSrcweir 
792cdf0e10cSrcweir 
lcl_FindSelection(SwFindParas & rParas,SwCursor * pCurCrsr,SwMoveFn fnMove,SwCursor * & pFndRing,SwPaM & aRegion,FindRanges eFndRngs,sal_Bool bInReadOnly,sal_Bool & bCancel)793cdf0e10cSrcweir sal_uLong lcl_FindSelection( SwFindParas& rParas, SwCursor* pCurCrsr,
794cdf0e10cSrcweir 						SwMoveFn fnMove, SwCursor*& pFndRing,
795cdf0e10cSrcweir 						SwPaM& aRegion, FindRanges eFndRngs,
796cdf0e10cSrcweir                         sal_Bool bInReadOnly, sal_Bool& bCancel )
797cdf0e10cSrcweir {
798cdf0e10cSrcweir 	SwDoc* pDoc = pCurCrsr->GetDoc();
799cdf0e10cSrcweir     bool const bDoesUndo = pDoc->GetIDocumentUndoRedo().DoesUndo();
800cdf0e10cSrcweir 	int nFndRet = 0;
801cdf0e10cSrcweir 	sal_uLong nFound = 0;
802cdf0e10cSrcweir 	int bSrchBkwrd = fnMove == fnMoveBackward, bEnde = sal_False;
803cdf0e10cSrcweir 	SwPaM *pTmpCrsr = pCurCrsr, *pSaveCrsr = pCurCrsr;
804cdf0e10cSrcweir 
805cdf0e10cSrcweir     // only create progress-bar for ShellCrsr
806cdf0e10cSrcweir     bool bIsUnoCrsr = 0 != dynamic_cast<SwUnoCrsr*>(pCurCrsr);
807cdf0e10cSrcweir 	_PercentHdl* pPHdl = 0;
808cdf0e10cSrcweir 	sal_uInt16 nCrsrCnt = 0;
809cdf0e10cSrcweir 	if( FND_IN_SEL & eFndRngs )
810cdf0e10cSrcweir 	{
811cdf0e10cSrcweir 		while( pCurCrsr != ( pTmpCrsr = (SwPaM*)pTmpCrsr->GetNext() ))
812cdf0e10cSrcweir 			++nCrsrCnt;
813cdf0e10cSrcweir 		if( nCrsrCnt && !bIsUnoCrsr )
814cdf0e10cSrcweir 			pPHdl = new _PercentHdl( 0, nCrsrCnt, pDoc->GetDocShell() );
815cdf0e10cSrcweir 	}
816cdf0e10cSrcweir     else
817cdf0e10cSrcweir         pSaveCrsr = (SwPaM*)pSaveCrsr->GetPrev();
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 	do {
820cdf0e10cSrcweir 		aRegion.SetMark();
821cdf0e10cSrcweir 		// egal in welche Richtung, SPoint ist immer groesser als Mark,
822cdf0e10cSrcweir 		// wenn der Suchbereich gueltig ist !!
823cdf0e10cSrcweir 		SwPosition *pSttPos = aRegion.GetMark(),
824cdf0e10cSrcweir 						*pEndPos = aRegion.GetPoint();
825cdf0e10cSrcweir 		*pSttPos = *pTmpCrsr->Start();
826cdf0e10cSrcweir 		*pEndPos = *pTmpCrsr->End();
827cdf0e10cSrcweir 		if( bSrchBkwrd )
828cdf0e10cSrcweir 			aRegion.Exchange();
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 		if( !nCrsrCnt && !pPHdl && !bIsUnoCrsr )
831cdf0e10cSrcweir 			pPHdl = new _PercentHdl( aRegion );
832cdf0e10cSrcweir 
833cdf0e10cSrcweir 		// solange gefunden und nicht auf gleicher Position haengen bleibt
834cdf0e10cSrcweir 		while(  *pSttPos <= *pEndPos &&
835cdf0e10cSrcweir 				0 != ( nFndRet = rParas.Find( pCurCrsr, fnMove,
836cdf0e10cSrcweir 											&aRegion, bInReadOnly )) &&
837cdf0e10cSrcweir 				( !pFndRing ||
838cdf0e10cSrcweir 					*pFndRing->GetPoint() != *pCurCrsr->GetPoint() ||
839cdf0e10cSrcweir 					*pFndRing->GetMark() != *pCurCrsr->GetMark() ))
840cdf0e10cSrcweir 		{
841cdf0e10cSrcweir 			if( !( FIND_NO_RING & nFndRet ))
842cdf0e10cSrcweir 			{
843cdf0e10cSrcweir 				// Bug 24084: Ring richtig herum aufbauen -> gleiche Mimik
844cdf0e10cSrcweir 				//			  wie beim CreateCrsr !!!!
845cdf0e10cSrcweir 
846cdf0e10cSrcweir 				SwCursor* pNew = pCurCrsr->Create( pFndRing );
847cdf0e10cSrcweir 				if( !pFndRing )
848cdf0e10cSrcweir 					pFndRing = pNew;
849cdf0e10cSrcweir 
850cdf0e10cSrcweir 				pNew->SetMark();
851cdf0e10cSrcweir 				*pNew->GetMark() = *pCurCrsr->GetMark();
852cdf0e10cSrcweir 			}
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 			++nFound;
855cdf0e10cSrcweir 
856cdf0e10cSrcweir 			if( !( eFndRngs & FND_IN_SELALL) )
857cdf0e10cSrcweir 			{
858cdf0e10cSrcweir 				bEnde = sal_True;
859cdf0e10cSrcweir 				break;
860cdf0e10cSrcweir 			}
861cdf0e10cSrcweir 
862cdf0e10cSrcweir             if ((coSrchRplcThreshold == nFound)
863cdf0e10cSrcweir                 && pDoc->GetIDocumentUndoRedo().DoesUndo()
864cdf0e10cSrcweir                 && rParas.IsReplaceMode())
865cdf0e10cSrcweir             {
866cdf0e10cSrcweir                 short nRet = pCurCrsr->MaxReplaceArived();
867cdf0e10cSrcweir                 if( RET_YES == nRet )
868cdf0e10cSrcweir                 {
869cdf0e10cSrcweir                     pDoc->GetIDocumentUndoRedo().DelAllUndoObj();
870cdf0e10cSrcweir                     pDoc->GetIDocumentUndoRedo().DoUndo(false);
871cdf0e10cSrcweir                 }
872cdf0e10cSrcweir                 else
873cdf0e10cSrcweir                 {
874cdf0e10cSrcweir                     bEnde = sal_True;
875cdf0e10cSrcweir                     if(RET_CANCEL == nRet)
876cdf0e10cSrcweir                     {
877cdf0e10cSrcweir                         bCancel = sal_True;
878cdf0e10cSrcweir                         //unwind() ??
879cdf0e10cSrcweir                     }
880cdf0e10cSrcweir                     break;
881cdf0e10cSrcweir                 }
882cdf0e10cSrcweir             }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 			if( bSrchBkwrd )
885cdf0e10cSrcweir 				// bewege pEndPos vor den gefundenen Bereich
886cdf0e10cSrcweir 				*pEndPos = *pCurCrsr->Start();
887cdf0e10cSrcweir 			else
888cdf0e10cSrcweir 				// bewege pSttPos hinter den gefundenen Bereich
889cdf0e10cSrcweir 				*pSttPos = *pCurCrsr->End();
890cdf0e10cSrcweir 
891cdf0e10cSrcweir 			if( *pSttPos == *pEndPos )		// im Bereich, aber am Ende
892cdf0e10cSrcweir 				break;						// fertig
893cdf0e10cSrcweir 
894cdf0e10cSrcweir             if( !nCrsrCnt && pPHdl )
895cdf0e10cSrcweir             {
896cdf0e10cSrcweir 				pPHdl->NextPos( *aRegion.GetMark() );
897cdf0e10cSrcweir             }
898cdf0e10cSrcweir 		}
899cdf0e10cSrcweir 
900cdf0e10cSrcweir 		if( bEnde || !( eFndRngs & ( FND_IN_SELALL | FND_IN_SEL )) )
901cdf0e10cSrcweir 			break;
902cdf0e10cSrcweir 
903cdf0e10cSrcweir 		pTmpCrsr = ((SwPaM*)pTmpCrsr->GetNext());
904cdf0e10cSrcweir         if( nCrsrCnt && pPHdl )
905cdf0e10cSrcweir         {
906cdf0e10cSrcweir 			pPHdl->NextPos( ++pPHdl->nActPos );
907cdf0e10cSrcweir         }
908cdf0e10cSrcweir 
909cdf0e10cSrcweir 	} while( pTmpCrsr != pSaveCrsr );
910cdf0e10cSrcweir 
911cdf0e10cSrcweir 	if( nFound && !pFndRing )		// falls kein Ring aufgebaut werden soll
912cdf0e10cSrcweir 		pFndRing = pCurCrsr->Create();
913cdf0e10cSrcweir 
914cdf0e10cSrcweir 	delete pPHdl;
915cdf0e10cSrcweir     pDoc->GetIDocumentUndoRedo().DoUndo(bDoesUndo);
916cdf0e10cSrcweir 	return nFound;
917cdf0e10cSrcweir }
918cdf0e10cSrcweir 
919cdf0e10cSrcweir 
lcl_MakeSelFwrd(const SwNode & rSttNd,const SwNode & rEndNd,SwPaM & rPam,int bFirst)920cdf0e10cSrcweir int lcl_MakeSelFwrd( const SwNode& rSttNd, const SwNode& rEndNd,
921cdf0e10cSrcweir 						SwPaM& rPam, int bFirst )
922cdf0e10cSrcweir {
923cdf0e10cSrcweir 	if( rSttNd.GetIndex() + 1 == rEndNd.GetIndex() )
924cdf0e10cSrcweir 		return sal_False;
925cdf0e10cSrcweir 
926cdf0e10cSrcweir 	SwNodes& rNds = rPam.GetDoc()->GetNodes();
927cdf0e10cSrcweir 	rPam.DeleteMark();
928cdf0e10cSrcweir 	SwCntntNode* pCNd;
929cdf0e10cSrcweir 	if( !bFirst )
930cdf0e10cSrcweir 	{
931cdf0e10cSrcweir 		rPam.GetPoint()->nNode = rSttNd;
932cdf0e10cSrcweir 		pCNd = rNds.GoNext( &rPam.GetPoint()->nNode );
933cdf0e10cSrcweir 		if( !pCNd )
934cdf0e10cSrcweir 			return sal_False;
935cdf0e10cSrcweir 		pCNd->MakeStartIndex( &rPam.GetPoint()->nContent );
936cdf0e10cSrcweir 	}
937cdf0e10cSrcweir 	else if( rSttNd.GetIndex() > rPam.GetPoint()->nNode.GetIndex() ||
938cdf0e10cSrcweir 			 rPam.GetPoint()->nNode.GetIndex() >= rEndNd.GetIndex() )
939cdf0e10cSrcweir 		return sal_False;		// steht nicht in dieser Section
940cdf0e10cSrcweir 
941cdf0e10cSrcweir 	rPam.SetMark();
942cdf0e10cSrcweir 	rPam.GetPoint()->nNode = rEndNd;
943cdf0e10cSrcweir 	pCNd = rNds.GoPrevious( &rPam.GetPoint()->nNode );
944cdf0e10cSrcweir 	if( !pCNd )
945cdf0e10cSrcweir 		return sal_False;
946cdf0e10cSrcweir 	pCNd->MakeEndIndex( &rPam.GetPoint()->nContent );
947cdf0e10cSrcweir 
948cdf0e10cSrcweir 	return *rPam.GetMark() < *rPam.GetPoint();
949cdf0e10cSrcweir }
950cdf0e10cSrcweir 
951cdf0e10cSrcweir 
lcl_MakeSelBkwrd(const SwNode & rSttNd,const SwNode & rEndNd,SwPaM & rPam,int bFirst)952cdf0e10cSrcweir int lcl_MakeSelBkwrd( const SwNode& rSttNd, const SwNode& rEndNd,
953cdf0e10cSrcweir 						SwPaM& rPam, int bFirst )
954cdf0e10cSrcweir {
955cdf0e10cSrcweir 	if( rEndNd.GetIndex() + 1 == rSttNd.GetIndex() )
956cdf0e10cSrcweir 		return sal_False;
957cdf0e10cSrcweir 
958cdf0e10cSrcweir 	SwNodes& rNds = rPam.GetDoc()->GetNodes();
959cdf0e10cSrcweir 	rPam.DeleteMark();
960cdf0e10cSrcweir 	SwCntntNode* pCNd;
961cdf0e10cSrcweir 	if( !bFirst )
962cdf0e10cSrcweir 	{
963cdf0e10cSrcweir 		rPam.GetPoint()->nNode = rSttNd;
964cdf0e10cSrcweir 		pCNd = rNds.GoPrevious( &rPam.GetPoint()->nNode );
965cdf0e10cSrcweir 		if( !pCNd )
966cdf0e10cSrcweir 			return sal_False;
967cdf0e10cSrcweir 		pCNd->MakeEndIndex( &rPam.GetPoint()->nContent );
968cdf0e10cSrcweir 	}
969cdf0e10cSrcweir 	else if( rEndNd.GetIndex() > rPam.GetPoint()->nNode.GetIndex() ||
970cdf0e10cSrcweir 			 rPam.GetPoint()->nNode.GetIndex() >= rSttNd.GetIndex() )
971cdf0e10cSrcweir 		return sal_False;		// steht nicht in dieser Section
972cdf0e10cSrcweir 
973cdf0e10cSrcweir 	rPam.SetMark();
974cdf0e10cSrcweir 	rPam.GetPoint()->nNode = rEndNd;
975cdf0e10cSrcweir 	pCNd = rNds.GoNext( &rPam.GetPoint()->nNode );
976cdf0e10cSrcweir 	if( !pCNd )
977cdf0e10cSrcweir 		return sal_False;
978cdf0e10cSrcweir 	pCNd->MakeStartIndex( &rPam.GetPoint()->nContent );
979cdf0e10cSrcweir 
980cdf0e10cSrcweir 	return *rPam.GetPoint() < *rPam.GetMark();
981cdf0e10cSrcweir }
982cdf0e10cSrcweir 
983cdf0e10cSrcweir 
984cdf0e10cSrcweir // diese Methode "sucht" fuer alle Anwendungsfaelle, denn in SwFindParas
985cdf0e10cSrcweir // steht immer die richtigen Parameter und die entsprechende Find-Methode
986cdf0e10cSrcweir 
FindAll(SwFindParas & rParas,SwDocPositions nStart,SwDocPositions nEnde,FindRanges eFndRngs,sal_Bool & bCancel)987cdf0e10cSrcweir sal_uLong SwCursor::FindAll( SwFindParas& rParas,
988cdf0e10cSrcweir 							SwDocPositions nStart, SwDocPositions nEnde,
989cdf0e10cSrcweir                             FindRanges eFndRngs, sal_Bool& bCancel )
990cdf0e10cSrcweir {
991cdf0e10cSrcweir     bCancel = sal_False;
992cdf0e10cSrcweir     SwCrsrSaveState aSaveState( *this );
993cdf0e10cSrcweir 
994cdf0e10cSrcweir 	// Region erzeugen, ohne das diese in den Ring aufgenommen wird !
995cdf0e10cSrcweir 	SwPaM aRegion( *GetPoint() );
996cdf0e10cSrcweir 	SwMoveFn fnMove = MakeFindRange( nStart, nEnde, &aRegion );
997cdf0e10cSrcweir 
998cdf0e10cSrcweir 	sal_uLong nFound = 0;
999cdf0e10cSrcweir 	int bMvBkwrd = fnMove == fnMoveBackward;
1000cdf0e10cSrcweir 	sal_Bool bInReadOnly = IsReadOnlyAvailable();
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir 	SwCursor* pFndRing = 0;
1003cdf0e10cSrcweir 	SwNodes& rNds = GetDoc()->GetNodes();
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir 	// suche in Bereichen ?
1006cdf0e10cSrcweir 	if( FND_IN_SEL & eFndRngs )
1007cdf0e10cSrcweir 	{
1008cdf0e10cSrcweir 		// String nicht im Bereich gefunden, dann erhalte alle Bereiche,
1009cdf0e10cSrcweir 		// der Cursor beleibt unveraendert
1010cdf0e10cSrcweir 		if( 0 == ( nFound = lcl_FindSelection( rParas, this, fnMove,
1011cdf0e10cSrcweir 												pFndRing, aRegion, eFndRngs,
1012cdf0e10cSrcweir                                                 bInReadOnly, bCancel ) ))
1013cdf0e10cSrcweir 			return nFound;
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir 		// der String wurde ein- bis mehrmals gefunden. Das steht alles
1016cdf0e10cSrcweir 		// im neuen Crsr-Ring. Darum hebe erstmal den alten Ring auf
1017cdf0e10cSrcweir 		while( GetNext() != this )
1018cdf0e10cSrcweir 			delete GetNext();
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir 		*GetPoint() = *pFndRing->GetPoint();
1021cdf0e10cSrcweir 		SetMark();
1022cdf0e10cSrcweir 		*GetMark() = *pFndRing->GetMark();
1023cdf0e10cSrcweir 		pFndRing->MoveRingTo( this );
1024cdf0e10cSrcweir 		delete pFndRing;
1025cdf0e10cSrcweir 	}
1026cdf0e10cSrcweir 	else if( FND_IN_OTHER & eFndRngs )
1027cdf0e10cSrcweir 	{
1028cdf0e10cSrcweir 		// Cursor als Kopie vom akt. und in den Ring aufnehmen
1029cdf0e10cSrcweir 		// Verkettung zeigt immer auf den zuerst erzeugten, also vorwaerts
1030cdf0e10cSrcweir 		std::auto_ptr< SwCursor > pSav( Create( this ) ); 	// save the current cursor
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir 		// wenn schon ausserhalb vom Bodytext, suche von der Position,
1033cdf0e10cSrcweir 		// ansonsten beginne mit der 1. GrundSection
1034cdf0e10cSrcweir 		if( bMvBkwrd
1035cdf0e10cSrcweir 			? lcl_MakeSelBkwrd( rNds.GetEndOfExtras(),
1036cdf0e10cSrcweir 					*rNds.GetEndOfPostIts().StartOfSectionNode(),
1037cdf0e10cSrcweir 					 *this, rNds.GetEndOfExtras().GetIndex() >=
1038cdf0e10cSrcweir 					GetPoint()->nNode.GetIndex() )
1039cdf0e10cSrcweir 			: lcl_MakeSelFwrd( *rNds.GetEndOfPostIts().StartOfSectionNode(),
1040cdf0e10cSrcweir 					rNds.GetEndOfExtras(), *this,
1041cdf0e10cSrcweir 					rNds.GetEndOfExtras().GetIndex() >=
1042cdf0e10cSrcweir 					GetPoint()->nNode.GetIndex() ))
1043cdf0e10cSrcweir 		{
1044cdf0e10cSrcweir 			nFound = lcl_FindSelection( rParas, this, fnMove, pFndRing,
1045cdf0e10cSrcweir                                         aRegion, eFndRngs, bInReadOnly, bCancel );
1046cdf0e10cSrcweir 		}
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir 		if( !nFound )
1049cdf0e10cSrcweir 		{
1050cdf0e10cSrcweir 			// den alten wieder zurueck
1051cdf0e10cSrcweir 			*GetPoint() = *pSav->GetPoint();
1052cdf0e10cSrcweir 			if( pSav->HasMark() )
1053cdf0e10cSrcweir 			{
1054cdf0e10cSrcweir 				SetMark();
1055cdf0e10cSrcweir 				*GetMark() = *pSav->GetMark();
1056cdf0e10cSrcweir 			}
1057cdf0e10cSrcweir 			else
1058cdf0e10cSrcweir 				DeleteMark();
1059cdf0e10cSrcweir 			return 0;
1060cdf0e10cSrcweir 		}
1061cdf0e10cSrcweir         pSav.release();
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir 		if( !( FND_IN_SELALL & eFndRngs ))
1064cdf0e10cSrcweir 		{
1065cdf0e10cSrcweir 			// es sollte nur einer gesucht werden, also fuege in dazu
1066cdf0e10cSrcweir 			// egal in welche Richtung, SPoint ist immer groesser als Mark,
1067cdf0e10cSrcweir 			// wenn der Suchbereich gueltig ist !!
1068cdf0e10cSrcweir 			*GetPoint() = *pFndRing->GetPoint();
1069cdf0e10cSrcweir 			SetMark();
1070cdf0e10cSrcweir 			*GetMark() = *pFndRing->GetMark();
1071cdf0e10cSrcweir 		}
1072cdf0e10cSrcweir 		else
1073cdf0e10cSrcweir 		{
1074cdf0e10cSrcweir 			// es  wurde ein- bis mehrmals gefunden. Das steht alles
1075cdf0e10cSrcweir 			// im neuen Crsr-Ring. Darum hebe erstmal den alten Ring auf
1076cdf0e10cSrcweir 			while( GetNext() != this )
1077cdf0e10cSrcweir 				delete GetNext();
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir 			*GetPoint() = *pFndRing->GetPoint();
1080cdf0e10cSrcweir 			SetMark();
1081cdf0e10cSrcweir 			*GetMark() = *pFndRing->GetMark();
1082cdf0e10cSrcweir 			pFndRing->MoveRingTo( this );
1083cdf0e10cSrcweir 		}
1084cdf0e10cSrcweir 		delete pFndRing;
1085cdf0e10cSrcweir 	}
1086cdf0e10cSrcweir 	else if( FND_IN_SELALL & eFndRngs )
1087cdf0e10cSrcweir 	{
1088cdf0e10cSrcweir 		::std::auto_ptr< SwCursor> pSav( Create( this ) ); 	// save the current cursor
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir 		const SwNode* pSttNd = ( FND_IN_BODYONLY & eFndRngs )
1091cdf0e10cSrcweir 							? rNds.GetEndOfContent().StartOfSectionNode()
1092cdf0e10cSrcweir 							: rNds.GetEndOfPostIts().StartOfSectionNode();
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir 		if( bMvBkwrd
1095cdf0e10cSrcweir 			? lcl_MakeSelBkwrd( rNds.GetEndOfContent(), *pSttNd,*this, sal_False )
1096cdf0e10cSrcweir 			: lcl_MakeSelFwrd( *pSttNd, rNds.GetEndOfContent(), *this, sal_False ))
1097cdf0e10cSrcweir 		{
1098cdf0e10cSrcweir 			nFound = lcl_FindSelection( rParas, this, fnMove, pFndRing,
1099cdf0e10cSrcweir                                         aRegion, eFndRngs, bInReadOnly, bCancel );
1100cdf0e10cSrcweir 		}
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir 		if( !nFound )
1103cdf0e10cSrcweir 		{
1104cdf0e10cSrcweir 			// den alten wieder zurueck
1105cdf0e10cSrcweir 			*GetPoint() = *pSav->GetPoint();
1106cdf0e10cSrcweir 			if( pSav->HasMark() )
1107cdf0e10cSrcweir 			{
1108cdf0e10cSrcweir 				SetMark();
1109cdf0e10cSrcweir 				*GetMark() = *pSav->GetMark();
1110cdf0e10cSrcweir 			}
1111cdf0e10cSrcweir 			else
1112cdf0e10cSrcweir 				DeleteMark();
1113cdf0e10cSrcweir 			return 0;
1114cdf0e10cSrcweir 		}
1115cdf0e10cSrcweir         pSav.release();
1116cdf0e10cSrcweir 		while( GetNext() != this )
1117cdf0e10cSrcweir 			delete GetNext();
1118cdf0e10cSrcweir 
1119cdf0e10cSrcweir 		*GetPoint() = *pFndRing->GetPoint();
1120cdf0e10cSrcweir 		SetMark();
1121cdf0e10cSrcweir 		*GetMark() = *pFndRing->GetMark();
1122cdf0e10cSrcweir 		pFndRing->MoveRingTo( this );
1123cdf0e10cSrcweir 		delete pFndRing;
1124cdf0e10cSrcweir 	}
1125cdf0e10cSrcweir 	else
1126cdf0e10cSrcweir 	{
1127cdf0e10cSrcweir 		// ist ein GetMark gesetzt, dann wird bei gefundenem Object
1128cdf0e10cSrcweir 		// der GetMark beibehalten !! Dadurch kann ein Bereich mit der Suche
1129cdf0e10cSrcweir 		// aufgespannt werden.
1130cdf0e10cSrcweir 		SwPosition aMarkPos( *GetMark() );
1131cdf0e10cSrcweir 		int bMarkPos = HasMark() && !eFndRngs;
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir 		if( 0 != (nFound = rParas.Find( this, fnMove,
1134cdf0e10cSrcweir 										&aRegion, bInReadOnly ) ? 1 : 0)
1135cdf0e10cSrcweir 			&& bMarkPos )
1136cdf0e10cSrcweir 			*GetMark() = aMarkPos;
1137cdf0e10cSrcweir 	}
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir     if( nFound && SwCursor::IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE ) )
1140cdf0e10cSrcweir         nFound = 0;
1141cdf0e10cSrcweir 	return nFound;
1142cdf0e10cSrcweir }
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir 
FillFindPos(SwDocPositions ePos,SwPosition & rPos) const1145cdf0e10cSrcweir void SwCursor::FillFindPos( SwDocPositions ePos, SwPosition& rPos ) const
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir 	sal_Bool bIsStart = sal_True;
1148cdf0e10cSrcweir 	SwCntntNode* pCNd = 0;
1149cdf0e10cSrcweir 	SwNodes& rNds = GetDoc()->GetNodes();
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 	switch( ePos )
1152cdf0e10cSrcweir 	{
1153cdf0e10cSrcweir 	case DOCPOS_START:
1154cdf0e10cSrcweir 		rPos.nNode = *rNds.GetEndOfContent().StartOfSectionNode();
1155cdf0e10cSrcweir 		pCNd = rNds.GoNext( &rPos.nNode );
1156cdf0e10cSrcweir 		break;
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir 	case DOCPOS_END:
1159cdf0e10cSrcweir 		rPos.nNode = rNds.GetEndOfContent();
1160cdf0e10cSrcweir 		pCNd = rNds.GoPrevious( &rPos.nNode );
1161cdf0e10cSrcweir 		bIsStart = sal_False;
1162cdf0e10cSrcweir 		break;
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir 	case DOCPOS_OTHERSTART:
1165cdf0e10cSrcweir 		rPos.nNode = *rNds[ sal_uLong(0) ];
1166cdf0e10cSrcweir 		pCNd = rNds.GoNext( &rPos.nNode );
1167cdf0e10cSrcweir 		break;
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir 	case DOCPOS_OTHEREND:
1170cdf0e10cSrcweir 		rPos.nNode = *rNds.GetEndOfContent().StartOfSectionNode();
1171cdf0e10cSrcweir 		pCNd = rNds.GoPrevious( &rPos.nNode );
1172cdf0e10cSrcweir 		bIsStart = sal_False;
1173cdf0e10cSrcweir 		break;
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir //	case DOCPOS_CURR:
1176cdf0e10cSrcweir 	default:
1177cdf0e10cSrcweir 		rPos = *GetPoint();
1178cdf0e10cSrcweir 	}
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir 	if( pCNd )
1181cdf0e10cSrcweir 	{
1182cdf0e10cSrcweir 		xub_StrLen nCPos = 0;
1183cdf0e10cSrcweir 		if( !bIsStart )
1184cdf0e10cSrcweir 			nCPos = pCNd->Len();
1185cdf0e10cSrcweir 		rPos.nContent.Assign( pCNd, nCPos );
1186cdf0e10cSrcweir 	}
1187cdf0e10cSrcweir }
1188cdf0e10cSrcweir 
MaxReplaceArived()1189cdf0e10cSrcweir short SwCursor::MaxReplaceArived()
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir     return RET_YES;
1192cdf0e10cSrcweir }
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir 
IsStartWord(sal_Int16 nWordType) const1195cdf0e10cSrcweir sal_Bool SwCursor::IsStartWord( sal_Int16 nWordType ) const
1196cdf0e10cSrcweir {
1197cdf0e10cSrcweir     return IsStartWordWT( nWordType );
1198cdf0e10cSrcweir }
1199cdf0e10cSrcweir 
IsEndWord(sal_Int16 nWordType) const1200cdf0e10cSrcweir sal_Bool SwCursor::IsEndWord( sal_Int16 nWordType ) const
1201cdf0e10cSrcweir {
1202cdf0e10cSrcweir     return IsEndWordWT( nWordType );
1203cdf0e10cSrcweir }
1204cdf0e10cSrcweir 
IsInWord(sal_Int16 nWordType) const1205cdf0e10cSrcweir sal_Bool SwCursor::IsInWord( sal_Int16 nWordType ) const
1206cdf0e10cSrcweir {
1207cdf0e10cSrcweir     return IsInWordWT( nWordType );
1208cdf0e10cSrcweir }
1209cdf0e10cSrcweir 
GoStartWord()1210cdf0e10cSrcweir sal_Bool SwCursor::GoStartWord()
1211cdf0e10cSrcweir {
1212cdf0e10cSrcweir     return GoStartWordWT( WordType::ANYWORD_IGNOREWHITESPACES );
1213cdf0e10cSrcweir }
1214cdf0e10cSrcweir 
GoEndWord()1215cdf0e10cSrcweir sal_Bool SwCursor::GoEndWord()
1216cdf0e10cSrcweir {
1217cdf0e10cSrcweir     return GoEndWordWT( WordType::ANYWORD_IGNOREWHITESPACES );
1218cdf0e10cSrcweir }
1219cdf0e10cSrcweir 
GoNextWord()1220cdf0e10cSrcweir sal_Bool SwCursor::GoNextWord()
1221cdf0e10cSrcweir {
1222cdf0e10cSrcweir     return GoNextWordWT( WordType::ANYWORD_IGNOREWHITESPACES );
1223cdf0e10cSrcweir }
1224cdf0e10cSrcweir 
GoPrevWord()1225cdf0e10cSrcweir sal_Bool SwCursor::GoPrevWord()
1226cdf0e10cSrcweir {
1227cdf0e10cSrcweir     return GoPrevWordWT( WordType::ANYWORD_IGNOREWHITESPACES );
1228cdf0e10cSrcweir }
1229cdf0e10cSrcweir 
SelectWord(ViewShell * pViewShell,const Point * pPt)1230cdf0e10cSrcweir sal_Bool SwCursor::SelectWord( ViewShell* pViewShell, const Point* pPt )
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir     return SelectWordWT( pViewShell, WordType::ANYWORD_IGNOREWHITESPACES, pPt );
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir 
IsStartWordWT(sal_Int16 nWordType) const1235cdf0e10cSrcweir sal_Bool SwCursor::IsStartWordWT( sal_Int16 nWordType ) const
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1238cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetNode()->GetTxtNode();
1239cdf0e10cSrcweir 	if( pTxtNd && pBreakIt->GetBreakIter().is() )
1240cdf0e10cSrcweir 	{
1241cdf0e10cSrcweir 		xub_StrLen nPtPos = GetPoint()->nContent.GetIndex();
1242cdf0e10cSrcweir 		bRet = pBreakIt->GetBreakIter()->isBeginWord(
1243cdf0e10cSrcweir 							pTxtNd->GetTxt(), nPtPos,
1244cdf0e10cSrcweir 							pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos )),
1245cdf0e10cSrcweir                             nWordType );
1246cdf0e10cSrcweir 	}
1247cdf0e10cSrcweir 	return bRet;
1248cdf0e10cSrcweir }
1249cdf0e10cSrcweir 
IsEndWordWT(sal_Int16 nWordType) const1250cdf0e10cSrcweir sal_Bool SwCursor::IsEndWordWT( sal_Int16 nWordType ) const
1251cdf0e10cSrcweir {
1252cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1253cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetNode()->GetTxtNode();
1254cdf0e10cSrcweir 	if( pTxtNd && pBreakIt->GetBreakIter().is() )
1255cdf0e10cSrcweir 	{
1256cdf0e10cSrcweir 		xub_StrLen nPtPos = GetPoint()->nContent.GetIndex();
1257cdf0e10cSrcweir 		bRet = pBreakIt->GetBreakIter()->isEndWord(
1258cdf0e10cSrcweir 							pTxtNd->GetTxt(), nPtPos,
1259cdf0e10cSrcweir 							pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos ) ),
1260cdf0e10cSrcweir                             nWordType );
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir 	}
1263cdf0e10cSrcweir 	return bRet;
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir 
IsInWordWT(sal_Int16 nWordType) const1266cdf0e10cSrcweir sal_Bool SwCursor::IsInWordWT( sal_Int16 nWordType ) const
1267cdf0e10cSrcweir {
1268cdf0e10cSrcweir     sal_Bool bRet = sal_False;
1269cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetNode()->GetTxtNode();
1270cdf0e10cSrcweir 	if( pTxtNd && pBreakIt->GetBreakIter().is() )
1271cdf0e10cSrcweir 	{
1272cdf0e10cSrcweir 		xub_StrLen nPtPos = GetPoint()->nContent.GetIndex();
1273cdf0e10cSrcweir         Boundary aBoundary = pBreakIt->GetBreakIter()->getWordBoundary(
1274cdf0e10cSrcweir 							pTxtNd->GetTxt(), nPtPos,
1275cdf0e10cSrcweir 							pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos ) ),
1276cdf0e10cSrcweir                             nWordType,
1277cdf0e10cSrcweir                             sal_True );
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir         bRet = aBoundary.startPos != aBoundary.endPos &&
1280cdf0e10cSrcweir                 aBoundary.startPos <= nPtPos &&
1281cdf0e10cSrcweir                     nPtPos <= aBoundary.endPos;
1282cdf0e10cSrcweir         if(bRet)
1283cdf0e10cSrcweir         {
1284cdf0e10cSrcweir             const CharClass& rCC = GetAppCharClass();
1285cdf0e10cSrcweir             bRet = rCC.isLetterNumeric( pTxtNd->GetTxt(), static_cast<xub_StrLen>(aBoundary.startPos) );
1286cdf0e10cSrcweir         }
1287cdf0e10cSrcweir 	}
1288cdf0e10cSrcweir 	return bRet;
1289cdf0e10cSrcweir }
1290cdf0e10cSrcweir 
IsStartEndSentence(bool bEnd) const1291cdf0e10cSrcweir sal_Bool SwCursor::IsStartEndSentence( bool bEnd ) const
1292cdf0e10cSrcweir {
1293cdf0e10cSrcweir     sal_Bool bRet = bEnd ?
1294cdf0e10cSrcweir                     GetCntntNode() && GetPoint()->nContent == GetCntntNode()->Len() :
1295cdf0e10cSrcweir                     GetPoint()->nContent.GetIndex() == 0;
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir     if( !bRet )
1298cdf0e10cSrcweir     {
1299cdf0e10cSrcweir         SwCursor aCrsr(*GetPoint(), 0, false);
1300cdf0e10cSrcweir         SwPosition aOrigPos = *aCrsr.GetPoint();
1301cdf0e10cSrcweir         aCrsr.GoSentence( bEnd ? SwCursor::END_SENT : SwCursor::START_SENT );
1302cdf0e10cSrcweir         bRet = aOrigPos == *aCrsr.GetPoint();
1303cdf0e10cSrcweir     }
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir     return bRet;
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir 
GoStartWordWT(sal_Int16 nWordType)1308cdf0e10cSrcweir sal_Bool SwCursor::GoStartWordWT( sal_Int16 nWordType )
1309cdf0e10cSrcweir {
1310cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1311cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetNode()->GetTxtNode();
1312cdf0e10cSrcweir 	if( pTxtNd && pBreakIt->GetBreakIter().is() )
1313cdf0e10cSrcweir 	{
1314cdf0e10cSrcweir 		SwCrsrSaveState aSave( *this );
1315cdf0e10cSrcweir 		xub_StrLen nPtPos = GetPoint()->nContent.GetIndex();
1316cdf0e10cSrcweir 		nPtPos = (xub_StrLen)pBreakIt->GetBreakIter()->getWordBoundary(
1317cdf0e10cSrcweir 							pTxtNd->GetTxt(), nPtPos,
1318cdf0e10cSrcweir 							pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos ) ),
1319cdf0e10cSrcweir                             nWordType,
1320cdf0e10cSrcweir 							sal_False ).startPos;
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir         if( nPtPos < pTxtNd->GetTxt().Len() )
1323cdf0e10cSrcweir 		{
1324cdf0e10cSrcweir 			GetPoint()->nContent = nPtPos;
1325cdf0e10cSrcweir 			if( !IsSelOvr() )
1326cdf0e10cSrcweir 				bRet = sal_True;
1327cdf0e10cSrcweir 		}
1328cdf0e10cSrcweir 	}
1329cdf0e10cSrcweir 	return bRet;
1330cdf0e10cSrcweir }
1331cdf0e10cSrcweir 
GoEndWordWT(sal_Int16 nWordType)1332cdf0e10cSrcweir sal_Bool SwCursor::GoEndWordWT( sal_Int16 nWordType )
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1335cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetNode()->GetTxtNode();
1336cdf0e10cSrcweir 	if( pTxtNd && pBreakIt->GetBreakIter().is() )
1337cdf0e10cSrcweir 	{
1338cdf0e10cSrcweir 		SwCrsrSaveState aSave( *this );
1339cdf0e10cSrcweir 		xub_StrLen nPtPos = GetPoint()->nContent.GetIndex();
1340cdf0e10cSrcweir 		nPtPos = (xub_StrLen)pBreakIt->GetBreakIter()->getWordBoundary(
1341cdf0e10cSrcweir 							pTxtNd->GetTxt(), nPtPos,
1342cdf0e10cSrcweir 							pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos ) ),
1343cdf0e10cSrcweir                             nWordType,
1344cdf0e10cSrcweir 							sal_True ).endPos;
1345cdf0e10cSrcweir 
1346cdf0e10cSrcweir         if( nPtPos <= pTxtNd->GetTxt().Len() &&
1347cdf0e10cSrcweir 			GetPoint()->nContent.GetIndex() != nPtPos )
1348cdf0e10cSrcweir 		{
1349cdf0e10cSrcweir 			GetPoint()->nContent = nPtPos;
1350cdf0e10cSrcweir 			if( !IsSelOvr() )
1351cdf0e10cSrcweir 				bRet = sal_True;
1352cdf0e10cSrcweir 		}
1353cdf0e10cSrcweir 	}
1354cdf0e10cSrcweir 	return bRet;
1355cdf0e10cSrcweir }
1356cdf0e10cSrcweir 
GoNextWordWT(sal_Int16 nWordType)1357cdf0e10cSrcweir sal_Bool SwCursor::GoNextWordWT( sal_Int16 nWordType )
1358cdf0e10cSrcweir {
1359cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1360cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetNode()->GetTxtNode();
1361cdf0e10cSrcweir 	if( pTxtNd && pBreakIt->GetBreakIter().is() )
1362cdf0e10cSrcweir 	{
1363cdf0e10cSrcweir 		SwCrsrSaveState aSave( *this );
1364cdf0e10cSrcweir 		xub_StrLen nPtPos = GetPoint()->nContent.GetIndex();
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir 		nPtPos = (xub_StrLen)pBreakIt->GetBreakIter()->nextWord(
1367cdf0e10cSrcweir 								pTxtNd->GetTxt(), nPtPos,
1368cdf0e10cSrcweir             pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos, 1 ) ),
1369cdf0e10cSrcweir                     nWordType ).startPos;
1370cdf0e10cSrcweir 
1371cdf0e10cSrcweir         if( nPtPos < pTxtNd->GetTxt().Len() )
1372cdf0e10cSrcweir 		{
1373cdf0e10cSrcweir 			GetPoint()->nContent = nPtPos;
1374cdf0e10cSrcweir 			if( !IsSelOvr() )
1375cdf0e10cSrcweir 				bRet = sal_True;
1376cdf0e10cSrcweir 		}
1377cdf0e10cSrcweir 	}
1378cdf0e10cSrcweir 	return bRet;
1379cdf0e10cSrcweir }
1380cdf0e10cSrcweir 
GoPrevWordWT(sal_Int16 nWordType)1381cdf0e10cSrcweir sal_Bool SwCursor::GoPrevWordWT( sal_Int16 nWordType )
1382cdf0e10cSrcweir {
1383cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1384cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetNode()->GetTxtNode();
1385cdf0e10cSrcweir 	if( pTxtNd && pBreakIt->GetBreakIter().is() )
1386cdf0e10cSrcweir 	{
1387cdf0e10cSrcweir 		SwCrsrSaveState aSave( *this );
1388cdf0e10cSrcweir 		xub_StrLen nPtPos = GetPoint()->nContent.GetIndex();
1389cdf0e10cSrcweir         const xub_StrLen nPtStart = nPtPos;
1390cdf0e10cSrcweir 
1391cdf0e10cSrcweir         if( nPtPos )
1392cdf0e10cSrcweir             --nPtPos;
1393cdf0e10cSrcweir 		nPtPos = (xub_StrLen)pBreakIt->GetBreakIter()->previousWord(
1394cdf0e10cSrcweir                                 pTxtNd->GetTxt(), nPtStart,
1395cdf0e10cSrcweir             pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos, 1 ) ),
1396cdf0e10cSrcweir                     nWordType ).startPos;
1397cdf0e10cSrcweir 
1398cdf0e10cSrcweir         if( nPtPos < pTxtNd->GetTxt().Len() )
1399cdf0e10cSrcweir 		{
1400cdf0e10cSrcweir 			GetPoint()->nContent = nPtPos;
1401cdf0e10cSrcweir 			if( !IsSelOvr() )
1402cdf0e10cSrcweir 				bRet = sal_True;
1403cdf0e10cSrcweir 		}
1404cdf0e10cSrcweir 	}
1405cdf0e10cSrcweir 	return bRet;
1406cdf0e10cSrcweir }
1407cdf0e10cSrcweir 
SelectWordWT(ViewShell * pViewShell,sal_Int16 nWordType,const Point * pPt)1408cdf0e10cSrcweir sal_Bool SwCursor::SelectWordWT( ViewShell* pViewShell, sal_Int16 nWordType, const Point* pPt )
1409cdf0e10cSrcweir {
1410cdf0e10cSrcweir 	SwCrsrSaveState aSave( *this );
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1413cdf0e10cSrcweir 	sal_Bool bForward = sal_True;
1414cdf0e10cSrcweir 	DeleteMark();
1415cdf0e10cSrcweir 	const SwRootFrm* pLayout = pViewShell->GetLayout();
1416cdf0e10cSrcweir 	if( pPt && 0 != pLayout )
1417cdf0e10cSrcweir 	{
1418cdf0e10cSrcweir 		// set the cursor to the layout position
1419cdf0e10cSrcweir 		Point aPt( *pPt );
1420cdf0e10cSrcweir 		pLayout->GetCrsrOfst( GetPoint(), aPt );
1421cdf0e10cSrcweir 	}	//swmod 071107//swmod 071225
1422cdf0e10cSrcweir 
1423cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetNode()->GetTxtNode();
1424cdf0e10cSrcweir 	if( pTxtNd && pBreakIt->GetBreakIter().is() )
1425cdf0e10cSrcweir 	{
1426cdf0e10cSrcweir 		xub_StrLen nPtPos = GetPoint()->nContent.GetIndex();
1427cdf0e10cSrcweir 		Boundary aBndry( pBreakIt->GetBreakIter()->getWordBoundary(
1428cdf0e10cSrcweir 							pTxtNd->GetTxt(), nPtPos,
1429cdf0e10cSrcweir 							pBreakIt->GetLocale( pTxtNd->GetLang( nPtPos ) ),
1430cdf0e10cSrcweir                             nWordType,
1431cdf0e10cSrcweir 							bForward ));
1432cdf0e10cSrcweir 
1433cdf0e10cSrcweir 		if( aBndry.startPos != aBndry.endPos )
1434cdf0e10cSrcweir 		{
1435cdf0e10cSrcweir 			GetPoint()->nContent = (xub_StrLen)aBndry.endPos;
1436cdf0e10cSrcweir 			if( !IsSelOvr() )
1437cdf0e10cSrcweir 			{
1438cdf0e10cSrcweir 				SetMark();
1439cdf0e10cSrcweir 				GetMark()->nContent = (xub_StrLen)aBndry.startPos;
1440cdf0e10cSrcweir 				if( !IsSelOvr() )
1441cdf0e10cSrcweir 					bRet = sal_True;
1442cdf0e10cSrcweir 			}
1443cdf0e10cSrcweir 		}
1444cdf0e10cSrcweir 	}
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 	if( !bRet )
1447cdf0e10cSrcweir 	{
1448cdf0e10cSrcweir 		DeleteMark();
1449cdf0e10cSrcweir 		RestoreSavePos();
1450cdf0e10cSrcweir 	}
1451cdf0e10cSrcweir 	return bRet;
1452cdf0e10cSrcweir }
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir //-----------------------------------------------------------------------------
1455cdf0e10cSrcweir 
lcl_MaskDeletedRedlines(const SwTxtNode * pTxtNd)1456cdf0e10cSrcweir static String lcl_MaskDeletedRedlines( const SwTxtNode* pTxtNd )
1457cdf0e10cSrcweir {
1458cdf0e10cSrcweir     String aRes;
1459cdf0e10cSrcweir 	if (pTxtNd)
1460cdf0e10cSrcweir 	{
1461cdf0e10cSrcweir         //mask deleted redlines
1462cdf0e10cSrcweir         String sNodeText(pTxtNd->GetTxt());
1463cdf0e10cSrcweir         const SwDoc& rDoc = *pTxtNd->GetDoc();
1464cdf0e10cSrcweir         const bool nShowChg = IDocumentRedlineAccess::IsShowChanges( rDoc.GetRedlineMode() );
1465cdf0e10cSrcweir         if ( nShowChg )
1466cdf0e10cSrcweir         {
1467cdf0e10cSrcweir             sal_uInt16 nAct = rDoc.GetRedlinePos( *pTxtNd, USHRT_MAX );
1468cdf0e10cSrcweir             for ( ; nAct < rDoc.GetRedlineTbl().Count(); nAct++ )
1469cdf0e10cSrcweir             {
1470cdf0e10cSrcweir                 const SwRedline* pRed = rDoc.GetRedlineTbl()[ nAct ];
1471cdf0e10cSrcweir                 if ( pRed->Start()->nNode > pTxtNd->GetIndex() )
1472cdf0e10cSrcweir                     break;
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir                 if( nsRedlineType_t::REDLINE_DELETE == pRed->GetType() )
1475cdf0e10cSrcweir                 {
1476cdf0e10cSrcweir                     xub_StrLen nStart, nEnd;
1477cdf0e10cSrcweir                     pRed->CalcStartEnd( pTxtNd->GetIndex(), nStart, nEnd );
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir                     while ( nStart < nEnd && nStart < sNodeText.Len() )
1480cdf0e10cSrcweir                         sNodeText.SetChar( nStart++, CH_TXTATR_INWORD );
1481cdf0e10cSrcweir                 }
1482cdf0e10cSrcweir             }
1483cdf0e10cSrcweir         }
1484cdf0e10cSrcweir         aRes = sNodeText;
1485cdf0e10cSrcweir     }
1486cdf0e10cSrcweir     return aRes;
1487cdf0e10cSrcweir }
1488cdf0e10cSrcweir 
GoSentence(SentenceMoveType eMoveType)1489cdf0e10cSrcweir sal_Bool SwCursor::GoSentence( SentenceMoveType eMoveType )
1490cdf0e10cSrcweir {
1491cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1492cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetNode()->GetTxtNode();
1493cdf0e10cSrcweir 	if( pTxtNd && pBreakIt->GetBreakIter().is() )
1494cdf0e10cSrcweir 	{
1495cdf0e10cSrcweir         String sNodeText( lcl_MaskDeletedRedlines( pTxtNd ) );
1496cdf0e10cSrcweir 
1497cdf0e10cSrcweir         SwCrsrSaveState aSave( *this );
1498cdf0e10cSrcweir 		xub_StrLen nPtPos = GetPoint()->nContent.GetIndex();
1499cdf0e10cSrcweir 		switch ( eMoveType )
1500cdf0e10cSrcweir 		{
1501cdf0e10cSrcweir 		case START_SENT: /* when modifying: see also ExpandToSentenceBorders below! */
1502cdf0e10cSrcweir 			nPtPos = (xub_StrLen)pBreakIt->GetBreakIter()->beginOfSentence(
1503cdf0e10cSrcweir                                     sNodeText,
1504cdf0e10cSrcweir 									nPtPos, pBreakIt->GetLocale(
1505cdf0e10cSrcweir 											pTxtNd->GetLang( nPtPos ) ));
1506cdf0e10cSrcweir 			break;
1507cdf0e10cSrcweir 		case END_SENT: /* when modifying: see also ExpandToSentenceBorders below! */
1508cdf0e10cSrcweir             nPtPos = (xub_StrLen)pBreakIt->GetBreakIter()->endOfSentence(
1509cdf0e10cSrcweir                                     sNodeText,
1510cdf0e10cSrcweir                                     nPtPos, pBreakIt->GetLocale(
1511cdf0e10cSrcweir                                                 pTxtNd->GetLang( nPtPos ) ));
1512cdf0e10cSrcweir 			break;
1513cdf0e10cSrcweir 		case NEXT_SENT:
1514cdf0e10cSrcweir 			{
1515cdf0e10cSrcweir 				nPtPos = (xub_StrLen)pBreakIt->GetBreakIter()->endOfSentence(
1516cdf0e10cSrcweir                                         sNodeText,
1517cdf0e10cSrcweir 										nPtPos, pBreakIt->GetLocale(
1518cdf0e10cSrcweir 													pTxtNd->GetLang( nPtPos ) ));
1519cdf0e10cSrcweir                 while (nPtPos != (sal_uInt16) -1 && ++nPtPos < sNodeText.Len()
1520cdf0e10cSrcweir                        && sNodeText.GetChar(nPtPos)== ' ' /*isWhiteSpace( aTxt.GetChar(nPtPos)*/ )
1521cdf0e10cSrcweir 					;
1522cdf0e10cSrcweir 				break;
1523cdf0e10cSrcweir 			}
1524cdf0e10cSrcweir 		case PREV_SENT:
1525cdf0e10cSrcweir 			nPtPos = (xub_StrLen)pBreakIt->GetBreakIter()->beginOfSentence(
1526cdf0e10cSrcweir                                     sNodeText,
1527cdf0e10cSrcweir                                     nPtPos, pBreakIt->GetLocale(
1528cdf0e10cSrcweir                                                 pTxtNd->GetLang( nPtPos ) ));
1529cdf0e10cSrcweir 			if (nPtPos == 0)
1530cdf0e10cSrcweir 				return sal_False;	// the previous sentence is not in this paragraph
1531cdf0e10cSrcweir 			if (nPtPos > 0)
1532cdf0e10cSrcweir 				nPtPos = (xub_StrLen)pBreakIt->GetBreakIter()->beginOfSentence(
1533cdf0e10cSrcweir                                     sNodeText,
1534cdf0e10cSrcweir                                     nPtPos - 1, pBreakIt->GetLocale(
1535cdf0e10cSrcweir                                                 pTxtNd->GetLang( nPtPos ) ));
1536cdf0e10cSrcweir 			break;
1537cdf0e10cSrcweir 		}
1538cdf0e10cSrcweir 
1539cdf0e10cSrcweir 		// it is allowed to place the PaM just behind the last
1540cdf0e10cSrcweir 		// character in the text thus <= ...Len
1541cdf0e10cSrcweir         if( nPtPos <= pTxtNd->GetTxt().Len() )
1542cdf0e10cSrcweir 		{
1543cdf0e10cSrcweir 			GetPoint()->nContent = nPtPos;
1544cdf0e10cSrcweir 			if( !IsSelOvr() )
1545cdf0e10cSrcweir 				bRet = sal_True;
1546cdf0e10cSrcweir 		}
1547cdf0e10cSrcweir 	}
1548cdf0e10cSrcweir 	return bRet;
1549cdf0e10cSrcweir }
1550cdf0e10cSrcweir 
1551cdf0e10cSrcweir 
ExpandToSentenceBorders()1552cdf0e10cSrcweir sal_Bool SwCursor::ExpandToSentenceBorders()
1553cdf0e10cSrcweir {
1554cdf0e10cSrcweir     sal_Bool bRes = sal_False;
1555cdf0e10cSrcweir 	const SwTxtNode* pStartNd = Start()->nNode.GetNode().GetTxtNode();
1556cdf0e10cSrcweir 	const SwTxtNode* pEndNd   = End()->nNode.GetNode().GetTxtNode();
1557cdf0e10cSrcweir 	if (pStartNd && pEndNd && pBreakIt->GetBreakIter().is())
1558cdf0e10cSrcweir 	{
1559cdf0e10cSrcweir         if (!HasMark())
1560cdf0e10cSrcweir             SetMark();
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir         String sStartText( lcl_MaskDeletedRedlines( pStartNd ) );
1563cdf0e10cSrcweir         String sEndText( pStartNd == pEndNd? sStartText : lcl_MaskDeletedRedlines( pEndNd ) );
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir         SwCrsrSaveState aSave( *this );
1566cdf0e10cSrcweir 		xub_StrLen nStartPos = Start()->nContent.GetIndex();
1567cdf0e10cSrcweir 		xub_StrLen nEndPos   = End()->nContent.GetIndex();
1568cdf0e10cSrcweir 
1569cdf0e10cSrcweir         nStartPos = (xub_StrLen)pBreakIt->GetBreakIter()->beginOfSentence(
1570cdf0e10cSrcweir                                 sStartText, nStartPos,
1571cdf0e10cSrcweir                                 pBreakIt->GetLocale( pStartNd->GetLang( nStartPos ) ) );
1572cdf0e10cSrcweir 		nEndPos   = (xub_StrLen)pBreakIt->GetBreakIter()->endOfSentence(
1573cdf0e10cSrcweir                                 sEndText, nEndPos,
1574cdf0e10cSrcweir                                 pBreakIt->GetLocale( pEndNd->GetLang( nEndPos ) ) );
1575cdf0e10cSrcweir 
1576cdf0e10cSrcweir 		// it is allowed to place the PaM just behind the last
1577cdf0e10cSrcweir 		// character in the text thus <= ...Len
1578cdf0e10cSrcweir         bool bChanged = false;
1579cdf0e10cSrcweir         if (nStartPos <= pStartNd->GetTxt().Len())
1580cdf0e10cSrcweir 		{
1581cdf0e10cSrcweir 			GetMark()->nContent = nStartPos;
1582cdf0e10cSrcweir             bChanged = true;
1583cdf0e10cSrcweir 		}
1584cdf0e10cSrcweir         if (nEndPos <= pEndNd->GetTxt().Len())
1585cdf0e10cSrcweir 		{
1586cdf0e10cSrcweir 			GetPoint()->nContent = nEndPos;
1587cdf0e10cSrcweir             bChanged = true;
1588cdf0e10cSrcweir 		}
1589cdf0e10cSrcweir 		if (bChanged && !IsSelOvr())
1590cdf0e10cSrcweir             bRes = sal_True;
1591cdf0e10cSrcweir     }
1592cdf0e10cSrcweir     return bRes;
1593cdf0e10cSrcweir }
1594cdf0e10cSrcweir 
1595cdf0e10cSrcweir 
LeftRight(sal_Bool bLeft,sal_uInt16 nCnt,sal_uInt16,sal_Bool,sal_Bool,sal_Bool)1596cdf0e10cSrcweir sal_Bool SwTableCursor::LeftRight( sal_Bool bLeft, sal_uInt16 nCnt, sal_uInt16 /*nMode*/,
1597cdf0e10cSrcweir     sal_Bool /*bVisualAllowed*/, sal_Bool /*bSkipHidden*/, sal_Bool /*bInsertCrsr*/ )
1598cdf0e10cSrcweir {
1599cdf0e10cSrcweir     return bLeft ? GoPrevCell( nCnt )
1600cdf0e10cSrcweir                  : GoNextCell( nCnt );
1601cdf0e10cSrcweir }
1602cdf0e10cSrcweir 
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir // calculate cursor bidi level: extracted from LeftRight()
1605cdf0e10cSrcweir const SwCntntFrm*
DoSetBidiLevelLeftRight(sal_Bool & io_rbLeft,sal_Bool bVisualAllowed,sal_Bool bInsertCrsr)1606cdf0e10cSrcweir SwCursor::DoSetBidiLevelLeftRight(
1607cdf0e10cSrcweir     sal_Bool & io_rbLeft, sal_Bool bVisualAllowed, sal_Bool bInsertCrsr)
1608cdf0e10cSrcweir {
1609cdf0e10cSrcweir     // calculate cursor bidi level
1610cdf0e10cSrcweir     const SwCntntFrm* pSttFrm = NULL;
1611cdf0e10cSrcweir     SwNode& rNode = GetPoint()->nNode.GetNode();
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir     if( rNode.IsTxtNode() )
1614cdf0e10cSrcweir     {
1615cdf0e10cSrcweir         const SwTxtNode& rTNd = *rNode.GetTxtNode();
1616cdf0e10cSrcweir         SwIndex& rIdx = GetPoint()->nContent;
1617cdf0e10cSrcweir         xub_StrLen nPos = rIdx.GetIndex();
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir         const SvtCTLOptions& rCTLOptions = SW_MOD()->GetCTLOptions();
1620cdf0e10cSrcweir         if ( bVisualAllowed && rCTLOptions.IsCTLFontEnabled() &&
1621cdf0e10cSrcweir              SvtCTLOptions::MOVEMENT_VISUAL ==
1622cdf0e10cSrcweir              rCTLOptions.GetCTLCursorMovement() )
1623cdf0e10cSrcweir         {
1624cdf0e10cSrcweir             // for visual cursor travelling (used in bidi layout)
1625cdf0e10cSrcweir             // we first have to convert the logic to a visual position
1626cdf0e10cSrcweir             Point aPt;
1627cdf0e10cSrcweir             pSttFrm = rTNd.getLayoutFrm( GetDoc()->GetCurrentLayout(), &aPt, GetPoint() );
1628cdf0e10cSrcweir             if( pSttFrm )
1629cdf0e10cSrcweir             {
1630cdf0e10cSrcweir                 sal_uInt8 nCrsrLevel = GetCrsrBidiLevel();
1631cdf0e10cSrcweir                 sal_Bool bForward = ! io_rbLeft;
1632cdf0e10cSrcweir                 ((SwTxtFrm*)pSttFrm)->PrepareVisualMove( nPos, nCrsrLevel,
1633cdf0e10cSrcweir                                                          bForward, bInsertCrsr );
1634cdf0e10cSrcweir                 rIdx = nPos;
1635cdf0e10cSrcweir                 SetCrsrBidiLevel( nCrsrLevel );
1636cdf0e10cSrcweir                 io_rbLeft = ! bForward;
1637cdf0e10cSrcweir             }
1638cdf0e10cSrcweir         }
1639cdf0e10cSrcweir         else
1640cdf0e10cSrcweir         {
1641cdf0e10cSrcweir             const SwScriptInfo* pSI = SwScriptInfo::GetScriptInfo( rTNd );
1642cdf0e10cSrcweir             if ( pSI )
1643cdf0e10cSrcweir             {
1644cdf0e10cSrcweir                 const xub_StrLen nMoveOverPos = io_rbLeft ?
1645cdf0e10cSrcweir                                                ( nPos ? nPos - 1 : 0 ) :
1646cdf0e10cSrcweir                                                 nPos;
1647cdf0e10cSrcweir                 SetCrsrBidiLevel( pSI->DirType( nMoveOverPos ) );
1648cdf0e10cSrcweir             }
1649cdf0e10cSrcweir         }
1650cdf0e10cSrcweir     }
1651cdf0e10cSrcweir     return pSttFrm;
1652cdf0e10cSrcweir }
1653cdf0e10cSrcweir 
LeftRight(sal_Bool bLeft,sal_uInt16 nCnt,sal_uInt16 nMode,sal_Bool bVisualAllowed,sal_Bool bSkipHidden,sal_Bool bInsertCrsr)1654cdf0e10cSrcweir sal_Bool SwCursor::LeftRight( sal_Bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
1655cdf0e10cSrcweir                           sal_Bool bVisualAllowed,sal_Bool bSkipHidden, sal_Bool bInsertCrsr )
1656cdf0e10cSrcweir {
1657cdf0e10cSrcweir     // calculate cursor bidi level
1658cdf0e10cSrcweir     SwNode& rNode = GetPoint()->nNode.GetNode();
1659cdf0e10cSrcweir     const SwCntntFrm* pSttFrm = // may side-effect bLeft!
1660cdf0e10cSrcweir         DoSetBidiLevelLeftRight(bLeft, bVisualAllowed, bInsertCrsr);
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir 	// kann der Cursor n-mal weiterverschoben werden ?
1663cdf0e10cSrcweir     SwCrsrSaveState aSave( *this );
1664cdf0e10cSrcweir     SwMoveFn fnMove = bLeft ? fnMoveBackward : fnMoveForward;
1665cdf0e10cSrcweir 
1666cdf0e10cSrcweir     SwGoInDoc fnGo;
1667cdf0e10cSrcweir     if ( bSkipHidden )
1668cdf0e10cSrcweir         fnGo = CRSR_SKIP_CELLS == nMode ? fnGoCntntCellsSkipHidden : fnGoCntntSkipHidden;
1669cdf0e10cSrcweir     else
1670cdf0e10cSrcweir         fnGo = CRSR_SKIP_CELLS == nMode ? fnGoCntntCells : fnGoCntnt;
1671cdf0e10cSrcweir 
1672cdf0e10cSrcweir     // ASSERT( not in covered cell )
1673cdf0e10cSrcweir 
1674cdf0e10cSrcweir     while( nCnt )
1675cdf0e10cSrcweir     {
1676cdf0e10cSrcweir         SwNodeIndex aOldNodeIdx( GetPoint()->nNode );
1677cdf0e10cSrcweir 
1678cdf0e10cSrcweir         bool bSuccess = Move( fnMove, fnGo );
1679cdf0e10cSrcweir         if ( !bSuccess )
1680cdf0e10cSrcweir             break;
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir         // If we were located inside a covered cell but our position has been
1683cdf0e10cSrcweir         // corrected, we check if the last move has moved the cursor to a different
1684cdf0e10cSrcweir         // table cell. In this case we set the cursor to the stored covered position
1685cdf0e10cSrcweir         // and redo the move:
1686cdf0e10cSrcweir         if ( mnRowSpanOffset )
1687cdf0e10cSrcweir         {
1688cdf0e10cSrcweir             const SwNode* pOldTabBoxSttNode = aOldNodeIdx.GetNode().FindTableBoxStartNode();
1689cdf0e10cSrcweir             const SwTableNode* pOldTabSttNode = pOldTabBoxSttNode ? pOldTabBoxSttNode->FindTableNode() : 0;
1690cdf0e10cSrcweir             const SwNode* pNewTabBoxSttNode = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
1691cdf0e10cSrcweir             const SwTableNode* pNewTabSttNode = pNewTabBoxSttNode ? pNewTabBoxSttNode->FindTableNode() : 0;
1692cdf0e10cSrcweir 
1693cdf0e10cSrcweir             const bool bCellChanged = pOldTabSttNode && pNewTabSttNode &&
1694cdf0e10cSrcweir                                       pOldTabSttNode == pNewTabSttNode &&
1695cdf0e10cSrcweir                                       pOldTabBoxSttNode && pNewTabBoxSttNode &&
1696cdf0e10cSrcweir                                       pOldTabBoxSttNode != pNewTabBoxSttNode;
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir             if ( bCellChanged )
1699cdf0e10cSrcweir             {
1700cdf0e10cSrcweir                 // Set cursor to start/end of covered cell:
1701cdf0e10cSrcweir                 SwTableBox* pTableBox = pOldTabBoxSttNode->GetTblBox();
1702cdf0e10cSrcweir                 const long nRowSpan = pTableBox->getRowSpan();
1703cdf0e10cSrcweir                 if ( nRowSpan > 1 )
1704cdf0e10cSrcweir                 {
1705cdf0e10cSrcweir                     pTableBox = & pTableBox->FindEndOfRowSpan( pOldTabSttNode->GetTable(), (sal_uInt16)(pTableBox->getRowSpan() + mnRowSpanOffset ) );
1706cdf0e10cSrcweir             	    SwNodeIndex& rPtIdx = GetPoint()->nNode;
1707cdf0e10cSrcweir                     SwNodeIndex aNewIdx( *pTableBox->GetSttNd() );
1708cdf0e10cSrcweir                     rPtIdx = aNewIdx;
1709cdf0e10cSrcweir 
1710cdf0e10cSrcweir                     GetDoc()->GetNodes().GoNextSection( &rPtIdx, sal_False, sal_False );
1711cdf0e10cSrcweir                     SwCntntNode* pCntntNode = GetCntntNode();
1712cdf0e10cSrcweir                     if ( pCntntNode )
1713cdf0e10cSrcweir                     {
1714cdf0e10cSrcweir                         const xub_StrLen nTmpPos = bLeft ? pCntntNode->Len() : 0;
1715cdf0e10cSrcweir 		        		GetPoint()->nContent.Assign( pCntntNode, nTmpPos );
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir                         // Redo the move:
1718cdf0e10cSrcweir                         bSuccess = Move( fnMove, fnGo );
1719cdf0e10cSrcweir                         if ( !bSuccess )
1720cdf0e10cSrcweir                             break;
1721cdf0e10cSrcweir                     }
1722cdf0e10cSrcweir                 }
1723cdf0e10cSrcweir 
1724cdf0e10cSrcweir                 mnRowSpanOffset = 0;
1725cdf0e10cSrcweir             }
1726cdf0e10cSrcweir         }
1727cdf0e10cSrcweir 
1728cdf0e10cSrcweir         // Check if I'm inside a covered cell. Correct cursor if necessary and
1729cdf0e10cSrcweir         // store covered cell:
1730cdf0e10cSrcweir         const SwNode* pTableBoxStartNode = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
1731cdf0e10cSrcweir         if ( pTableBoxStartNode )
1732cdf0e10cSrcweir         {
1733cdf0e10cSrcweir             const SwTableBox* pTableBox = pTableBoxStartNode->GetTblBox();
1734cdf0e10cSrcweir             if ( pTableBox->getRowSpan() < 1 )
1735cdf0e10cSrcweir             {
1736cdf0e10cSrcweir                 // Store the row span offset:
1737cdf0e10cSrcweir                 mnRowSpanOffset = pTableBox->getRowSpan();
1738cdf0e10cSrcweir 
1739cdf0e10cSrcweir                 // Move cursor to non-covered cell:
1740cdf0e10cSrcweir                 const SwTableNode* pTblNd = pTableBoxStartNode->FindTableNode();
1741cdf0e10cSrcweir                 pTableBox = & pTableBox->FindStartOfRowSpan( pTblNd->GetTable(), USHRT_MAX );
1742cdf0e10cSrcweir          	    SwNodeIndex& rPtIdx = GetPoint()->nNode;
1743cdf0e10cSrcweir                 SwNodeIndex aNewIdx( *pTableBox->GetSttNd() );
1744cdf0e10cSrcweir                 rPtIdx = aNewIdx;
1745cdf0e10cSrcweir 
1746cdf0e10cSrcweir                 GetDoc()->GetNodes().GoNextSection( &rPtIdx, sal_False, sal_False );
1747cdf0e10cSrcweir                 SwCntntNode* pCntntNode = GetCntntNode();
1748cdf0e10cSrcweir                 if ( pCntntNode )
1749cdf0e10cSrcweir                 {
1750cdf0e10cSrcweir                     const xub_StrLen nTmpPos = bLeft ? pCntntNode->Len() : 0;
1751cdf0e10cSrcweir                		GetPoint()->nContent.Assign( pCntntNode, nTmpPos );
1752cdf0e10cSrcweir                 }
1753cdf0e10cSrcweir             }
1754cdf0e10cSrcweir         }
1755cdf0e10cSrcweir 
1756cdf0e10cSrcweir         --nCnt;
1757cdf0e10cSrcweir     }
1758cdf0e10cSrcweir 
1759cdf0e10cSrcweir     // here come some special rules for visual cursor travelling
1760cdf0e10cSrcweir     if ( pSttFrm )
1761cdf0e10cSrcweir     {
1762cdf0e10cSrcweir         SwNode& rTmpNode = GetPoint()->nNode.GetNode();
1763cdf0e10cSrcweir         if ( &rTmpNode != &rNode && rTmpNode.IsTxtNode() )
1764cdf0e10cSrcweir         {
1765cdf0e10cSrcweir             Point aPt;
1766cdf0e10cSrcweir             const SwCntntFrm* pEndFrm = ((SwTxtNode&)rTmpNode).getLayoutFrm( GetDoc()->GetCurrentLayout(), &aPt, GetPoint() );
1767cdf0e10cSrcweir             if ( pEndFrm )
1768cdf0e10cSrcweir             {
1769cdf0e10cSrcweir                 if ( ! pEndFrm->IsRightToLeft() != ! pSttFrm->IsRightToLeft() )
1770cdf0e10cSrcweir                 {
1771cdf0e10cSrcweir                     if ( ! bLeft )
1772cdf0e10cSrcweir                         pEndFrm->RightMargin( this );
1773cdf0e10cSrcweir                     else
1774cdf0e10cSrcweir                         pEndFrm->LeftMargin( this );
1775cdf0e10cSrcweir                 }
1776cdf0e10cSrcweir             }
1777cdf0e10cSrcweir         }
1778cdf0e10cSrcweir     }
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir 	return 0 == nCnt && !IsInProtectTable( sal_True ) &&
1781cdf0e10cSrcweir             !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
1782cdf0e10cSrcweir                        nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
1783cdf0e10cSrcweir }
1784cdf0e10cSrcweir 
1785cdf0e10cSrcweir // calculate cursor bidi level: extracted from UpDown()
DoSetBidiLevelUpDown()1786cdf0e10cSrcweir void SwCursor::DoSetBidiLevelUpDown()
1787cdf0e10cSrcweir {
1788cdf0e10cSrcweir     SwNode& rNode = GetPoint()->nNode.GetNode();
1789cdf0e10cSrcweir     if ( rNode.IsTxtNode() )
1790cdf0e10cSrcweir     {
1791cdf0e10cSrcweir         const SwScriptInfo* pSI =
1792cdf0e10cSrcweir             SwScriptInfo::GetScriptInfo( (SwTxtNode&)rNode );
1793cdf0e10cSrcweir         if ( pSI )
1794cdf0e10cSrcweir         {
1795cdf0e10cSrcweir             SwIndex& rIdx = GetPoint()->nContent;
1796cdf0e10cSrcweir             xub_StrLen nPos = rIdx.GetIndex();
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir             if( nPos && nPos < ((SwTxtNode&)rNode).GetTxt().Len() )
1799cdf0e10cSrcweir             {
1800cdf0e10cSrcweir                 const sal_uInt8 nCurrLevel = pSI->DirType( nPos );
1801cdf0e10cSrcweir                 const sal_uInt8 nPrevLevel = pSI->DirType( nPos - 1 );
1802cdf0e10cSrcweir 
1803cdf0e10cSrcweir                 if ( nCurrLevel % 2 != nPrevLevel % 2 )
1804cdf0e10cSrcweir                 {
1805cdf0e10cSrcweir                     // set cursor level to the lower of the two levels
1806cdf0e10cSrcweir                     SetCrsrBidiLevel( Min( nCurrLevel, nPrevLevel ) );
1807cdf0e10cSrcweir                 }
1808cdf0e10cSrcweir                 else
1809cdf0e10cSrcweir                     SetCrsrBidiLevel( nCurrLevel );
1810cdf0e10cSrcweir             }
1811cdf0e10cSrcweir         }
1812cdf0e10cSrcweir     }
1813cdf0e10cSrcweir }
1814cdf0e10cSrcweir 
UpDown(sal_Bool bUp,sal_uInt16 nCnt,Point * pPt,long nUpDownX)1815cdf0e10cSrcweir sal_Bool SwCursor::UpDown( sal_Bool bUp, sal_uInt16 nCnt,
1816cdf0e10cSrcweir 							Point* pPt, long nUpDownX )
1817cdf0e10cSrcweir {
1818cdf0e10cSrcweir     SwTableCursor* pTblCrsr = dynamic_cast<SwTableCursor*>(this);
1819cdf0e10cSrcweir     sal_Bool bAdjustTableCrsr = sal_False;
1820cdf0e10cSrcweir 
1821cdf0e10cSrcweir 	// vom Tabellen Crsr Point/Mark in der gleichen Box ??
1822cdf0e10cSrcweir 	// dann stelle den Point an den Anfang der Box
1823cdf0e10cSrcweir     if( pTblCrsr && GetNode( sal_True )->StartOfSectionNode() ==
1824cdf0e10cSrcweir                     GetNode( sal_False )->StartOfSectionNode() )
1825cdf0e10cSrcweir     {
1826cdf0e10cSrcweir         if ( End() != GetPoint() )
1827cdf0e10cSrcweir             Exchange();
1828cdf0e10cSrcweir         bAdjustTableCrsr = sal_True;
1829cdf0e10cSrcweir     }
1830cdf0e10cSrcweir 
1831cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1832cdf0e10cSrcweir 	Point aPt;
1833cdf0e10cSrcweir 	if( pPt )
1834cdf0e10cSrcweir 		aPt = *pPt;
1835cdf0e10cSrcweir 	SwCntntFrm* pFrm = GetCntntNode()->getLayoutFrm( GetDoc()->GetCurrentLayout(), &aPt, GetPoint() );
1836cdf0e10cSrcweir 
1837cdf0e10cSrcweir 	if( pFrm )
1838cdf0e10cSrcweir 	{
1839cdf0e10cSrcweir 		SwCrsrSaveState aSave( *this );
1840cdf0e10cSrcweir 
1841cdf0e10cSrcweir 		if( !pPt )
1842cdf0e10cSrcweir 		{
1843cdf0e10cSrcweir 			SwRect aTmpRect;
1844cdf0e10cSrcweir 			pFrm->GetCharRect( aTmpRect, *GetPoint() );
1845cdf0e10cSrcweir 			aPt = aTmpRect.Pos();
1846cdf0e10cSrcweir 
1847cdf0e10cSrcweir             nUpDownX = pFrm->IsVertical() ?
1848cdf0e10cSrcweir                 aPt.Y() - pFrm->Frm().Top() :
1849cdf0e10cSrcweir                 aPt.X() - pFrm->Frm().Left();
1850cdf0e10cSrcweir 		}
1851cdf0e10cSrcweir 
1852cdf0e10cSrcweir 		// Bei Fussnoten ist auch die Bewegung in eine andere Fussnote erlaubt.
1853cdf0e10cSrcweir 		// aber keine Selection!!
1854cdf0e10cSrcweir 		const sal_Bool bChkRange = pFrm->IsInFtn() && !HasMark()
1855cdf0e10cSrcweir 									? sal_False : sal_True;
1856cdf0e10cSrcweir 		const SwPosition aOldPos( *GetPoint() );
1857cdf0e10cSrcweir 		sal_Bool bInReadOnly = IsReadOnlyAvailable();
1858cdf0e10cSrcweir 
1859cdf0e10cSrcweir         if ( bAdjustTableCrsr && !bUp )
1860cdf0e10cSrcweir         {
1861cdf0e10cSrcweir             // Special case: We have a table cursor but the start box
1862cdf0e10cSrcweir             // has more than one paragraph. If we want to go down, we have to
1863cdf0e10cSrcweir             // set the point to the last frame in the table box. This is
1864cdf0e10cSrcweir             // only necessary if we do not already have a table selection
1865cdf0e10cSrcweir             const SwStartNode* pTblNd = GetNode( sal_True )->FindTableBoxStartNode();
1866cdf0e10cSrcweir             ASSERT( pTblNd, "pTblCrsr without SwTableNode?" )
1867cdf0e10cSrcweir 
1868cdf0e10cSrcweir             if ( pTblNd ) // safety first
1869cdf0e10cSrcweir             {
1870cdf0e10cSrcweir                 const SwNode* pEndNd = pTblNd->EndOfSectionNode();
1871cdf0e10cSrcweir                 GetPoint()->nNode = *pEndNd;
1872cdf0e10cSrcweir                 pTblCrsr->Move( fnMoveBackward, fnGoNode );
1873cdf0e10cSrcweir    			    pFrm = GetCntntNode()->getLayoutFrm( GetDoc()->GetCurrentLayout(), &aPt, GetPoint() );
1874cdf0e10cSrcweir             }
1875cdf0e10cSrcweir         }
1876cdf0e10cSrcweir 
1877cdf0e10cSrcweir         while( nCnt &&
1878cdf0e10cSrcweir                (bUp ? pFrm->UnitUp( this, nUpDownX, bInReadOnly )
1879cdf0e10cSrcweir 		            : pFrm->UnitDown( this, nUpDownX, bInReadOnly ) ) &&
1880cdf0e10cSrcweir     		    CheckNodesRange( aOldPos.nNode, GetPoint()->nNode, bChkRange ))
1881cdf0e10cSrcweir 	    {
1882cdf0e10cSrcweir    			pFrm = GetCntntNode()->getLayoutFrm( GetDoc()->GetCurrentLayout(), &aPt, GetPoint() );
1883cdf0e10cSrcweir 		    --nCnt;
1884cdf0e10cSrcweir 	    }
1885cdf0e10cSrcweir 
1886cdf0e10cSrcweir         if( !nCnt && !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
1887cdf0e10cSrcweir                                 nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ) )  // die gesamte Anzahl durchlaufen ?
1888cdf0e10cSrcweir 		{
1889cdf0e10cSrcweir 			if( !pTblCrsr )
1890cdf0e10cSrcweir 			{
1891cdf0e10cSrcweir 				// dann versuche den Cursor auf die Position zu setzen,
1892cdf0e10cSrcweir 				// auf halber Heohe vom Char-Rectangle
1893cdf0e10cSrcweir 				pFrm = GetCntntNode()->getLayoutFrm( GetDoc()->GetCurrentLayout(), &aPt, GetPoint() );
1894cdf0e10cSrcweir 				SwCrsrMoveState eTmpState( MV_UPDOWN );
1895cdf0e10cSrcweir 				eTmpState.bSetInReadOnly = bInReadOnly;
1896cdf0e10cSrcweir 				SwRect aTmpRect;
1897cdf0e10cSrcweir 				pFrm->GetCharRect( aTmpRect, *GetPoint(), &eTmpState );
1898cdf0e10cSrcweir                 if ( pFrm->IsVertical() )
1899cdf0e10cSrcweir                 {
1900cdf0e10cSrcweir                     aPt.X() = aTmpRect.Center().X();
1901cdf0e10cSrcweir                     pFrm->Calc();
1902cdf0e10cSrcweir                     aPt.Y() = pFrm->Frm().Top() + nUpDownX;
1903cdf0e10cSrcweir                 }
1904cdf0e10cSrcweir                 else
1905cdf0e10cSrcweir                 {
1906cdf0e10cSrcweir                     aPt.Y() = aTmpRect.Center().Y();
1907cdf0e10cSrcweir                     pFrm->Calc();
1908cdf0e10cSrcweir                     aPt.X() = pFrm->Frm().Left() + nUpDownX;
1909cdf0e10cSrcweir                 }
1910cdf0e10cSrcweir                 pFrm->GetCrsrOfst( GetPoint(), aPt, &eTmpState );
191169a74367SOliver-Rainer Wittmann             }
191269a74367SOliver-Rainer Wittmann             bRet = !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE | nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
191369a74367SOliver-Rainer Wittmann         }
191469a74367SOliver-Rainer Wittmann         else
191569a74367SOliver-Rainer Wittmann             *GetPoint() = aOldPos;
1916cdf0e10cSrcweir 
1917cdf0e10cSrcweir         DoSetBidiLevelUpDown(); // calculate cursor bidi level
1918cdf0e10cSrcweir     }
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir 	return bRet;
1921cdf0e10cSrcweir }
1922cdf0e10cSrcweir 
LeftRightMargin(sal_Bool bLeft,sal_Bool bAPI)1923cdf0e10cSrcweir sal_Bool SwCursor::LeftRightMargin( sal_Bool bLeft, sal_Bool bAPI )
1924cdf0e10cSrcweir {
1925cdf0e10cSrcweir     Point aPt;
1926cdf0e10cSrcweir     SwCntntFrm * pFrm = GetCntntNode()->getLayoutFrm( GetDoc()->GetCurrentLayout(), &aPt, GetPoint() );
1927cdf0e10cSrcweir 
1928cdf0e10cSrcweir     // calculate cursor bidi level
1929cdf0e10cSrcweir     if ( pFrm )
1930cdf0e10cSrcweir         SetCrsrBidiLevel( pFrm->IsRightToLeft() ? 1 : 0 );
1931cdf0e10cSrcweir 
193269a74367SOliver-Rainer Wittmann     SwCrsrSaveState aSave( *this );
193369a74367SOliver-Rainer Wittmann     return pFrm
193469a74367SOliver-Rainer Wittmann            && (bLeft ? pFrm->LeftMargin( this ) : pFrm->RightMargin( this, bAPI ) )
193569a74367SOliver-Rainer Wittmann            && !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE | nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
1936cdf0e10cSrcweir }
1937cdf0e10cSrcweir 
IsAtLeftRightMargin(sal_Bool bLeft,sal_Bool bAPI) const1938cdf0e10cSrcweir sal_Bool SwCursor::IsAtLeftRightMargin( sal_Bool bLeft, sal_Bool bAPI ) const
1939cdf0e10cSrcweir {
1940cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1941cdf0e10cSrcweir 	Point aPt;
1942cdf0e10cSrcweir 	SwCntntFrm * pFrm = GetCntntNode()->getLayoutFrm( GetDoc()->GetCurrentLayout(), &aPt, GetPoint() );
1943cdf0e10cSrcweir 	if( pFrm )
1944cdf0e10cSrcweir 	{
1945cdf0e10cSrcweir 		SwPaM aPam( *GetPoint() );
1946cdf0e10cSrcweir 		if( !bLeft && aPam.GetPoint()->nContent.GetIndex() )
1947cdf0e10cSrcweir 			aPam.GetPoint()->nContent--;
1948cdf0e10cSrcweir 		bRet = (bLeft ? pFrm->LeftMargin( &aPam )
1949cdf0e10cSrcweir 					  : pFrm->RightMargin( &aPam, bAPI ))
1950cdf0e10cSrcweir 				&& *aPam.GetPoint() == *GetPoint();
1951cdf0e10cSrcweir 	}
1952cdf0e10cSrcweir 	return bRet;
1953cdf0e10cSrcweir }
1954cdf0e10cSrcweir 
SttEndDoc(sal_Bool bStt)1955cdf0e10cSrcweir sal_Bool SwCursor::SttEndDoc( sal_Bool bStt )
1956cdf0e10cSrcweir {
1957cdf0e10cSrcweir 	SwCrsrSaveState aSave( *this );
1958cdf0e10cSrcweir 
1959cdf0e10cSrcweir 	// Springe beim Selektieren nie ueber Section-Grenzen !!
1960cdf0e10cSrcweir 	// kann der Cursor weiterverschoben werden ?
1961cdf0e10cSrcweir 	SwMoveFn fnMove = bStt ? fnMoveBackward : fnMoveForward;
1962cdf0e10cSrcweir 	sal_Bool bRet = (!HasMark() || !IsNoCntnt() ) &&
1963cdf0e10cSrcweir 					Move( fnMove, fnGoDoc ) &&
1964cdf0e10cSrcweir 					!IsInProtectTable( sal_True ) &&
1965cdf0e10cSrcweir                     !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
1966cdf0e10cSrcweir                                nsSwCursorSelOverFlags::SELOVER_CHANGEPOS |
1967cdf0e10cSrcweir                                nsSwCursorSelOverFlags::SELOVER_ENABLEREVDIREKTION );
1968cdf0e10cSrcweir 
1969cdf0e10cSrcweir 	return bRet;
1970cdf0e10cSrcweir }
1971cdf0e10cSrcweir 
GoPrevNextCell(sal_Bool bNext,sal_uInt16 nCnt)1972cdf0e10cSrcweir sal_Bool SwCursor::GoPrevNextCell( sal_Bool bNext, sal_uInt16 nCnt )
1973cdf0e10cSrcweir {
1974cdf0e10cSrcweir 	const SwTableNode* pTblNd = GetPoint()->nNode.GetNode().FindTableNode();
1975cdf0e10cSrcweir 	if( !pTblNd )
1976cdf0e10cSrcweir 		return sal_False;
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir 	// liegt vor dem StartNode der Cell ein weiterer EndNode, dann
1979cdf0e10cSrcweir 	// gibt es auch eine vorherige Celle
1980cdf0e10cSrcweir 	SwCrsrSaveState aSave( *this );
1981cdf0e10cSrcweir 	SwNodeIndex& rPtIdx = GetPoint()->nNode;
1982cdf0e10cSrcweir 
1983cdf0e10cSrcweir     while( nCnt-- )
1984cdf0e10cSrcweir 	{
1985cdf0e10cSrcweir         const SwNode* pTableBoxStartNode = rPtIdx.GetNode().FindTableBoxStartNode();
1986cdf0e10cSrcweir         const SwTableBox* pTableBox = pTableBoxStartNode->GetTblBox();
1987cdf0e10cSrcweir 
1988cdf0e10cSrcweir         // Check if we have to move the cursor to a covered cell before
1989cdf0e10cSrcweir         // proceeding:
1990cdf0e10cSrcweir         if ( mnRowSpanOffset )
1991cdf0e10cSrcweir         {
1992cdf0e10cSrcweir             if ( pTableBox->getRowSpan() > 1 )
1993cdf0e10cSrcweir             {
1994cdf0e10cSrcweir                 pTableBox = & pTableBox->FindEndOfRowSpan( pTblNd->GetTable(), (sal_uInt16)(pTableBox->getRowSpan() + mnRowSpanOffset) );
1995cdf0e10cSrcweir                 SwNodeIndex aNewIdx( *pTableBox->GetSttNd() );
1996cdf0e10cSrcweir                 rPtIdx = aNewIdx;
1997cdf0e10cSrcweir                 pTableBoxStartNode = rPtIdx.GetNode().FindTableBoxStartNode();
1998cdf0e10cSrcweir             }
1999cdf0e10cSrcweir             mnRowSpanOffset = 0;
2000cdf0e10cSrcweir         }
2001cdf0e10cSrcweir 
2002cdf0e10cSrcweir         const SwNode* pTmpNode = bNext ?
2003cdf0e10cSrcweir                                  pTableBoxStartNode->EndOfSectionNode() :
2004cdf0e10cSrcweir                                  pTableBoxStartNode;
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir         SwNodeIndex aCellIdx( *pTmpNode, bNext ? 1 : -1 );
2007cdf0e10cSrcweir 		if(  (bNext && !aCellIdx.GetNode().IsStartNode()) ||
2008cdf0e10cSrcweir             (!bNext && !aCellIdx.GetNode().IsEndNode()) )
2009cdf0e10cSrcweir 			return sal_False;
2010cdf0e10cSrcweir 
2011cdf0e10cSrcweir         rPtIdx = bNext ? aCellIdx : SwNodeIndex(*aCellIdx.GetNode().StartOfSectionNode());
2012cdf0e10cSrcweir 
2013cdf0e10cSrcweir         pTableBoxStartNode = rPtIdx.GetNode().FindTableBoxStartNode();
2014cdf0e10cSrcweir         pTableBox = pTableBoxStartNode->GetTblBox();
2015cdf0e10cSrcweir         if ( pTableBox->getRowSpan() < 1 )
2016cdf0e10cSrcweir         {
2017cdf0e10cSrcweir             mnRowSpanOffset = pTableBox->getRowSpan();
2018cdf0e10cSrcweir             // move cursor to non-covered cell:
2019cdf0e10cSrcweir             pTableBox = & pTableBox->FindStartOfRowSpan( pTblNd->GetTable(), USHRT_MAX );
2020cdf0e10cSrcweir             SwNodeIndex aNewIdx( *pTableBox->GetSttNd() );
2021cdf0e10cSrcweir             rPtIdx = aNewIdx;
2022cdf0e10cSrcweir         }
2023cdf0e10cSrcweir     }
2024cdf0e10cSrcweir 
2025cdf0e10cSrcweir 	rPtIdx++;
2026cdf0e10cSrcweir 	if( !rPtIdx.GetNode().IsCntntNode() )
2027cdf0e10cSrcweir 		GetDoc()->GetNodes().GoNextSection( &rPtIdx, sal_True, sal_False );
2028cdf0e10cSrcweir 	GetPoint()->nContent.Assign( GetCntntNode(), 0 );
2029cdf0e10cSrcweir 
2030cdf0e10cSrcweir 	return !IsInProtectTable( sal_True );
2031cdf0e10cSrcweir }
2032cdf0e10cSrcweir 
GotoTable(const String &)2033cdf0e10cSrcweir sal_Bool SwTableCursor::GotoTable( const String& /*rName*/ )
2034cdf0e10cSrcweir {
2035cdf0e10cSrcweir     return sal_False; // invalid action
2036cdf0e10cSrcweir }
2037cdf0e10cSrcweir 
GotoTable(const String & rName)2038cdf0e10cSrcweir sal_Bool SwCursor::GotoTable( const String& rName )
2039cdf0e10cSrcweir {
2040cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2041cdf0e10cSrcweir     if ( !HasMark() )
2042cdf0e10cSrcweir 	{
2043cdf0e10cSrcweir 		SwTable* pTmpTbl = SwTable::FindTable( GetDoc()->FindTblFmtByName( rName ) );
2044cdf0e10cSrcweir 		if( pTmpTbl )
2045cdf0e10cSrcweir 		{
2046cdf0e10cSrcweir 			// eine Tabelle im normalen NodesArr
2047cdf0e10cSrcweir 			SwCrsrSaveState aSave( *this );
2048cdf0e10cSrcweir 			GetPoint()->nNode = *pTmpTbl->GetTabSortBoxes()[ 0 ]->
2049cdf0e10cSrcweir 								GetSttNd()->FindTableNode();
2050cdf0e10cSrcweir 			Move( fnMoveForward, fnGoCntnt );
2051cdf0e10cSrcweir 			bRet = !IsSelOvr();
2052cdf0e10cSrcweir 		}
2053cdf0e10cSrcweir 	}
2054cdf0e10cSrcweir 	return bRet;
2055cdf0e10cSrcweir }
2056cdf0e10cSrcweir 
GotoTblBox(const String & rName)2057cdf0e10cSrcweir sal_Bool SwCursor::GotoTblBox( const String& rName )
2058cdf0e10cSrcweir {
2059cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2060cdf0e10cSrcweir 	const SwTableNode* pTblNd = GetPoint()->nNode.GetNode().FindTableNode();
2061cdf0e10cSrcweir 	if( pTblNd )
2062cdf0e10cSrcweir 	{
2063cdf0e10cSrcweir 		// erfrage die Box, mit dem Nanen
2064cdf0e10cSrcweir 		const SwTableBox* pTblBox = pTblNd->GetTable().GetTblBox( rName );
2065cdf0e10cSrcweir 		if( pTblBox && pTblBox->GetSttNd() &&
2066cdf0e10cSrcweir 			( !pTblBox->GetFrmFmt()->GetProtect().IsCntntProtected() ||
2067cdf0e10cSrcweir 			  IsReadOnlyAvailable() ) )
2068cdf0e10cSrcweir 		{
2069cdf0e10cSrcweir 			SwCrsrSaveState aSave( *this );
2070cdf0e10cSrcweir 			GetPoint()->nNode = *pTblBox->GetSttNd();
2071cdf0e10cSrcweir 			Move( fnMoveForward, fnGoCntnt );
2072cdf0e10cSrcweir 			bRet = !IsSelOvr();
2073cdf0e10cSrcweir 		}
2074cdf0e10cSrcweir 	}
2075cdf0e10cSrcweir 	return bRet;
2076cdf0e10cSrcweir }
2077cdf0e10cSrcweir 
MovePara(SwWhichPara fnWhichPara,SwPosPara fnPosPara)2078cdf0e10cSrcweir sal_Bool SwCursor::MovePara(SwWhichPara fnWhichPara, SwPosPara fnPosPara )
2079cdf0e10cSrcweir {
2080cdf0e10cSrcweir 	//JP 28.8.2001: for optimization test something before
2081cdf0e10cSrcweir     const SwNode* pNd = &GetPoint()->nNode.GetNode();
2082cdf0e10cSrcweir     bool bShortCut = false;
2083cdf0e10cSrcweir     if ( fnWhichPara == fnParaCurr )
2084cdf0e10cSrcweir     {
2085cdf0e10cSrcweir         // --> FME 2005-02-21 #i41048#
2086cdf0e10cSrcweir         // If fnWhichPara == fnParaCurr, (*fnWhichPara)( *this, fnPosPara )
2087cdf0e10cSrcweir         // can already move the cursor to a different text node. In this case
2088cdf0e10cSrcweir         // we better check if IsSelOvr().
2089cdf0e10cSrcweir         const SwCntntNode* pCntntNd = pNd->GetCntntNode();
2090cdf0e10cSrcweir         if ( pCntntNd )
2091cdf0e10cSrcweir         {
2092cdf0e10cSrcweir             const xub_StrLen nSttEnd = fnPosPara == fnMoveForward ? 0 : pCntntNd->Len();
2093cdf0e10cSrcweir             if ( GetPoint()->nContent.GetIndex() != nSttEnd )
2094cdf0e10cSrcweir                 bShortCut = true;
2095cdf0e10cSrcweir         }
2096cdf0e10cSrcweir         // <--
2097cdf0e10cSrcweir     }
2098cdf0e10cSrcweir     else
2099cdf0e10cSrcweir     {
2100cdf0e10cSrcweir         if ( pNd->IsTxtNode() &&
2101cdf0e10cSrcweir              pNd->GetNodes()[ pNd->GetIndex() +
2102cdf0e10cSrcweir                     (fnWhichPara == fnParaNext ? 1 : -1 ) ]->IsTxtNode() )
2103cdf0e10cSrcweir             bShortCut = true;
2104cdf0e10cSrcweir     }
2105cdf0e10cSrcweir 
2106cdf0e10cSrcweir     if ( bShortCut )
2107cdf0e10cSrcweir         return (*fnWhichPara)( *this, fnPosPara );
2108cdf0e10cSrcweir 
2109cdf0e10cSrcweir     // else we must use the SaveStructure, because the next/prev is not
2110cdf0e10cSrcweir 	// a same node type.
2111cdf0e10cSrcweir 	SwCrsrSaveState aSave( *this );
2112cdf0e10cSrcweir 	return (*fnWhichPara)( *this, fnPosPara ) &&
2113cdf0e10cSrcweir 			!IsInProtectTable( sal_True ) &&
2114cdf0e10cSrcweir             !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
2115cdf0e10cSrcweir                        nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
2116cdf0e10cSrcweir }
2117cdf0e10cSrcweir 
2118cdf0e10cSrcweir 
MoveSection(SwWhichSection fnWhichSect,SwPosSection fnPosSect)2119cdf0e10cSrcweir sal_Bool SwCursor::MoveSection( SwWhichSection fnWhichSect,
2120cdf0e10cSrcweir 								SwPosSection fnPosSect)
2121cdf0e10cSrcweir {
2122cdf0e10cSrcweir 	SwCrsrSaveState aSave( *this );
2123cdf0e10cSrcweir 	return (*fnWhichSect)( *this, fnPosSect ) &&
2124cdf0e10cSrcweir 			!IsInProtectTable( sal_True ) &&
2125cdf0e10cSrcweir             !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
2126cdf0e10cSrcweir                        nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
2127cdf0e10cSrcweir }
2128cdf0e10cSrcweir 
2129cdf0e10cSrcweir /*
2130cdf0e10cSrcweir 	sal_Bool MoveTable( SwWhichTable, SwPosTable );
2131cdf0e10cSrcweir 	sal_Bool MoveColumn( SwWhichColumn, SwPosColumn );
2132cdf0e10cSrcweir 	sal_Bool MoveRegion( SwWhichRegion, SwPosRegion );
2133cdf0e10cSrcweir */
2134cdf0e10cSrcweir 
RestoreSavePos()2135cdf0e10cSrcweir void SwCursor::RestoreSavePos()		// Point auf die SavePos setzen
2136cdf0e10cSrcweir {
2137cdf0e10cSrcweir 	if( pSavePos )
2138cdf0e10cSrcweir 	{
2139cdf0e10cSrcweir 		GetPoint()->nNode = pSavePos->nNode;
2140cdf0e10cSrcweir 		GetPoint()->nContent.Assign( GetCntntNode(), pSavePos->nCntnt );
2141cdf0e10cSrcweir 	}
2142cdf0e10cSrcweir }
2143cdf0e10cSrcweir 
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir /*  */
2146cdf0e10cSrcweir 
SwTableCursor(const SwPosition & rPos,SwPaM * pRing)2147cdf0e10cSrcweir SwTableCursor::SwTableCursor( const SwPosition &rPos, SwPaM* pRing )
2148cdf0e10cSrcweir 	: SwCursor( rPos, pRing, false )
2149cdf0e10cSrcweir {
2150cdf0e10cSrcweir 	bParked = sal_False;
2151cdf0e10cSrcweir 	bChg = sal_False;
2152cdf0e10cSrcweir 	nTblPtNd = 0, nTblMkNd = 0;
2153cdf0e10cSrcweir 	nTblPtCnt = 0, nTblMkCnt = 0;
2154cdf0e10cSrcweir }
2155cdf0e10cSrcweir 
~SwTableCursor()2156cdf0e10cSrcweir SwTableCursor::~SwTableCursor() {}
2157cdf0e10cSrcweir 
2158cdf0e10cSrcweir 
lcl_SeekEntry(const SwSelBoxes & rTmp,const SwStartNode * pSrch,sal_uInt16 & rFndPos)2159cdf0e10cSrcweir sal_Bool lcl_SeekEntry( const SwSelBoxes& rTmp, const SwStartNode* pSrch, sal_uInt16& rFndPos )
2160cdf0e10cSrcweir {
2161cdf0e10cSrcweir 	sal_uLong nIdx = pSrch->GetIndex();
2162cdf0e10cSrcweir 
2163cdf0e10cSrcweir 	sal_uInt16 nO = rTmp.Count(), nM, nU = 0;
2164cdf0e10cSrcweir 	if( nO > 0 )
2165cdf0e10cSrcweir 	{
2166cdf0e10cSrcweir 		nO--;
2167cdf0e10cSrcweir 		while( nU <= nO )
2168cdf0e10cSrcweir 		{
2169cdf0e10cSrcweir 			nM = nU + ( nO - nU ) / 2;
2170cdf0e10cSrcweir 			if( rTmp[ nM ]->GetSttNd() == pSrch )
2171cdf0e10cSrcweir 			{
2172cdf0e10cSrcweir 				rFndPos = nM;
2173cdf0e10cSrcweir 				return sal_True;
2174cdf0e10cSrcweir 			}
2175cdf0e10cSrcweir 			else if( rTmp[ nM ]->GetSttIdx() < nIdx )
2176cdf0e10cSrcweir 				nU = nM + 1;
2177cdf0e10cSrcweir 			else if( nM == 0 )
2178cdf0e10cSrcweir 				return sal_False;
2179cdf0e10cSrcweir 			else
2180cdf0e10cSrcweir 				nO = nM - 1;
2181cdf0e10cSrcweir 		}
2182cdf0e10cSrcweir 	}
2183cdf0e10cSrcweir 	return sal_False;
2184cdf0e10cSrcweir }
2185cdf0e10cSrcweir 
2186cdf0e10cSrcweir 
MakeBoxSels(SwCursor * pAktCrsr)2187cdf0e10cSrcweir SwCursor* SwTableCursor::MakeBoxSels( SwCursor* pAktCrsr )
2188cdf0e10cSrcweir {
2189cdf0e10cSrcweir 	if( bChg )		// ???
2190cdf0e10cSrcweir 	{
2191cdf0e10cSrcweir 		if( bParked )
2192cdf0e10cSrcweir 		{
2193cdf0e10cSrcweir 			// wieder in den Inhalt schieben
2194cdf0e10cSrcweir 			Exchange();
2195cdf0e10cSrcweir 			Move( fnMoveForward );
2196cdf0e10cSrcweir 			Exchange();
2197cdf0e10cSrcweir 			Move( fnMoveForward );
2198cdf0e10cSrcweir 			bParked = sal_False;
2199cdf0e10cSrcweir 		}
2200cdf0e10cSrcweir 
2201cdf0e10cSrcweir 		bChg = sal_False;
2202cdf0e10cSrcweir 
2203cdf0e10cSrcweir 		// temp Kopie anlegen, damit alle Boxen, fuer die schon Cursor
2204cdf0e10cSrcweir 		// existieren, entfernt werden koennen.
2205cdf0e10cSrcweir 		SwSelBoxes aTmp;
2206cdf0e10cSrcweir 		aTmp.Insert( &aSelBoxes );
2207cdf0e10cSrcweir 
2208cdf0e10cSrcweir 		//Jetzt die Alten und die neuen abgleichen.
2209cdf0e10cSrcweir 		SwNodes& rNds = pAktCrsr->GetDoc()->GetNodes();
2210cdf0e10cSrcweir 		sal_uInt16 nPos;
2211cdf0e10cSrcweir 		const SwStartNode* pSttNd;
2212cdf0e10cSrcweir 		SwPaM* pCur = pAktCrsr;
2213cdf0e10cSrcweir 		do {
2214cdf0e10cSrcweir 			sal_Bool bDel = sal_False;
2215cdf0e10cSrcweir 			pSttNd = pCur->GetPoint()->nNode.GetNode().FindTableBoxStartNode();
2216cdf0e10cSrcweir 			if( !pCur->HasMark() || !pSttNd ||
2217cdf0e10cSrcweir 				pSttNd != pCur->GetMark()->nNode.GetNode().FindTableBoxStartNode() )
2218cdf0e10cSrcweir 				bDel = sal_True;
2219cdf0e10cSrcweir 
2220cdf0e10cSrcweir 			else if( lcl_SeekEntry( aTmp, pSttNd, nPos ))
2221cdf0e10cSrcweir 			{
2222cdf0e10cSrcweir 				SwNodeIndex aIdx( *pSttNd, 1 );
2223cdf0e10cSrcweir 				const SwNode* pNd = &aIdx.GetNode();
2224cdf0e10cSrcweir 				if( !pNd->IsCntntNode() )
2225cdf0e10cSrcweir 					pNd = rNds.GoNextSection( &aIdx, sal_True, sal_False );
2226cdf0e10cSrcweir 
2227cdf0e10cSrcweir 				SwPosition* pPos = pCur->GetMark();
2228cdf0e10cSrcweir 				if( pNd != &pPos->nNode.GetNode() )
2229cdf0e10cSrcweir 					pPos->nNode = *pNd;
2230cdf0e10cSrcweir 				pPos->nContent.Assign( (SwCntntNode*)pNd, 0 );
2231cdf0e10cSrcweir 
2232cdf0e10cSrcweir 				aIdx.Assign( *pSttNd->EndOfSectionNode(), - 1 );
2233cdf0e10cSrcweir 				if( !( pNd = &aIdx.GetNode())->IsCntntNode() )
2234cdf0e10cSrcweir 					pNd = rNds.GoPrevSection( &aIdx, sal_True, sal_False );
2235cdf0e10cSrcweir 
2236cdf0e10cSrcweir 				pPos = pCur->GetPoint();
2237cdf0e10cSrcweir 				if( pNd != &pPos->nNode.GetNode() )
2238cdf0e10cSrcweir 					pPos->nNode = *pNd;
2239cdf0e10cSrcweir 				pPos->nContent.Assign( (SwCntntNode*)pNd, ((SwCntntNode*)pNd)->Len() );
2240cdf0e10cSrcweir 
2241cdf0e10cSrcweir 				aTmp.Remove( nPos );
2242cdf0e10cSrcweir 			}
2243cdf0e10cSrcweir 			else
2244cdf0e10cSrcweir 				bDel = sal_True;
2245cdf0e10cSrcweir 
2246cdf0e10cSrcweir 			pCur = (SwPaM*)pCur->GetNext();
2247cdf0e10cSrcweir 			if( bDel )
2248cdf0e10cSrcweir 			{
2249cdf0e10cSrcweir 				SwPaM* pDel = (SwPaM*)pCur->GetPrev();
2250cdf0e10cSrcweir /*
2251cdf0e10cSrcweir JP 20.07.98: der alte Code geht mit dem UNO-TableCrsr nicht
2252cdf0e10cSrcweir 				if( pDel == pAktCrsr )
2253cdf0e10cSrcweir 				{
2254cdf0e10cSrcweir 					if( pAktCrsr->GetNext() == pAktCrsr )
2255cdf0e10cSrcweir 					{
2256cdf0e10cSrcweir 						pAktCrsr->DeleteMark();
2257cdf0e10cSrcweir 						break;		// es gibt nichts mehr zu loeschen!
2258cdf0e10cSrcweir 					}
2259cdf0e10cSrcweir 					pAktCrsr = (SwCursor*)pDel->GetPrev();
2260cdf0e10cSrcweir 				}
2261cdf0e10cSrcweir 				delete pDel;
2262cdf0e10cSrcweir */
2263cdf0e10cSrcweir 
2264cdf0e10cSrcweir 				if( pDel == pAktCrsr )
2265cdf0e10cSrcweir 					pAktCrsr->DeleteMark();
2266cdf0e10cSrcweir 				else
2267cdf0e10cSrcweir 					delete pDel;
2268cdf0e10cSrcweir 			}
2269cdf0e10cSrcweir 		} while ( pAktCrsr != pCur );
2270cdf0e10cSrcweir 
2271cdf0e10cSrcweir 		for( nPos = 0; nPos < aTmp.Count(); ++nPos )
2272cdf0e10cSrcweir 		{
2273cdf0e10cSrcweir 			pSttNd = aTmp[ nPos ]->GetSttNd();
2274cdf0e10cSrcweir 
2275cdf0e10cSrcweir 			SwNodeIndex aIdx( *pSttNd, 1 );
2276cdf0e10cSrcweir             if( &aIdx.GetNodes() != &rNds )
2277cdf0e10cSrcweir                 break;
2278cdf0e10cSrcweir 			const SwNode* pNd = &aIdx.GetNode();
2279cdf0e10cSrcweir 			if( !pNd->IsCntntNode() )
2280cdf0e10cSrcweir 				pNd = rNds.GoNextSection( &aIdx, sal_True, sal_False );
2281cdf0e10cSrcweir 
2282cdf0e10cSrcweir 			SwPaM* pNew;
2283cdf0e10cSrcweir 			if( pAktCrsr->GetNext() == pAktCrsr && !pAktCrsr->HasMark() )
2284cdf0e10cSrcweir 			{
2285cdf0e10cSrcweir 				pNew = pAktCrsr;
2286cdf0e10cSrcweir 				pNew->GetPoint()->nNode = *pNd;
2287cdf0e10cSrcweir 				pNew->GetPoint()->nContent.Assign( (SwCntntNode*)pNd, 0 );
2288cdf0e10cSrcweir 			}
2289cdf0e10cSrcweir 			else
2290cdf0e10cSrcweir 			{
2291cdf0e10cSrcweir 				pNew = pAktCrsr->Create( pAktCrsr );
2292cdf0e10cSrcweir 				pNew->GetPoint()->nNode = *pNd;
2293cdf0e10cSrcweir 				pNew->GetPoint()->nContent.Assign( (SwCntntNode*)pNd, 0 );
2294cdf0e10cSrcweir 			}
2295cdf0e10cSrcweir 			pNew->SetMark();
2296cdf0e10cSrcweir 
2297cdf0e10cSrcweir 			SwPosition* pPos = pNew->GetPoint();
2298cdf0e10cSrcweir 			pPos->nNode.Assign( *pSttNd->EndOfSectionNode(), - 1 );
2299cdf0e10cSrcweir 			if( !( pNd = &pPos->nNode.GetNode())->IsCntntNode() )
2300cdf0e10cSrcweir 				pNd = rNds.GoPrevSection( &pPos->nNode, sal_True, sal_False );
2301cdf0e10cSrcweir 
2302cdf0e10cSrcweir 			pPos->nContent.Assign( (SwCntntNode*)pNd, ((SwCntntNode*)pNd)->Len() );
2303cdf0e10cSrcweir 		}
2304cdf0e10cSrcweir 	}
2305cdf0e10cSrcweir 	return pAktCrsr;
2306cdf0e10cSrcweir }
2307cdf0e10cSrcweir 
2308cdf0e10cSrcweir 
InsertBox(const SwTableBox & rTblBox)2309cdf0e10cSrcweir void SwTableCursor::InsertBox( const SwTableBox& rTblBox )
2310cdf0e10cSrcweir {
2311cdf0e10cSrcweir 	SwTableBox* pBox = (SwTableBox*)&rTblBox;
2312cdf0e10cSrcweir 	aSelBoxes.Insert( pBox );
2313cdf0e10cSrcweir 	bChg = sal_True;
2314cdf0e10cSrcweir }
2315cdf0e10cSrcweir 
NewTableSelection()2316cdf0e10cSrcweir bool SwTableCursor::NewTableSelection()
2317cdf0e10cSrcweir {
2318cdf0e10cSrcweir     bool bRet = false;
2319cdf0e10cSrcweir 	const SwNode *pStart = GetCntntNode()->FindTableBoxStartNode();
2320cdf0e10cSrcweir 	const SwNode *pEnd = GetCntntNode(sal_False)->FindTableBoxStartNode();
2321cdf0e10cSrcweir     if( pStart && pEnd )
2322cdf0e10cSrcweir     {
2323cdf0e10cSrcweir         const SwTableNode *pTableNode = pStart->FindTableNode();
2324cdf0e10cSrcweir         if( pTableNode == pEnd->FindTableNode() &&
2325cdf0e10cSrcweir             pTableNode->GetTable().IsNewModel() )
2326cdf0e10cSrcweir         {
2327cdf0e10cSrcweir             bRet = true;
2328cdf0e10cSrcweir             SwSelBoxes aNew;
2329cdf0e10cSrcweir             aNew.Insert( &aSelBoxes );
2330cdf0e10cSrcweir             pTableNode->GetTable().CreateSelection( pStart, pEnd, aNew,
2331cdf0e10cSrcweir                 SwTable::SEARCH_NONE, false );
2332cdf0e10cSrcweir             ActualizeSelection( aNew );
2333cdf0e10cSrcweir         }
2334cdf0e10cSrcweir     }
2335cdf0e10cSrcweir     return bRet;
2336cdf0e10cSrcweir }
2337cdf0e10cSrcweir 
ActualizeSelection(const SwSelBoxes & rNew)2338cdf0e10cSrcweir void SwTableCursor::ActualizeSelection( const SwSelBoxes &rNew )
2339cdf0e10cSrcweir {
2340cdf0e10cSrcweir     sal_uInt16 nOld = 0, nNew = 0;
2341cdf0e10cSrcweir     while ( nOld < aSelBoxes.Count() && nNew < rNew.Count() )
2342cdf0e10cSrcweir     {
2343cdf0e10cSrcweir         const SwTableBox* pPOld = *( aSelBoxes.GetData() + nOld );
2344cdf0e10cSrcweir         const SwTableBox* pPNew = *( rNew.GetData() + nNew );
2345cdf0e10cSrcweir         if( pPOld == pPNew )
2346cdf0e10cSrcweir         {   // this box will stay
2347cdf0e10cSrcweir             ++nOld;
2348cdf0e10cSrcweir             ++nNew;
2349cdf0e10cSrcweir         }
2350cdf0e10cSrcweir         else if( pPOld->GetSttIdx() < pPNew->GetSttIdx() )
2351cdf0e10cSrcweir             DeleteBox( nOld ); // this box has to go
2352cdf0e10cSrcweir         else
2353cdf0e10cSrcweir         {
2354cdf0e10cSrcweir             InsertBox( *pPNew ); // this is a new one
2355cdf0e10cSrcweir             ++nOld;
2356cdf0e10cSrcweir             ++nNew;
2357cdf0e10cSrcweir         }
2358cdf0e10cSrcweir     }
2359cdf0e10cSrcweir 
2360cdf0e10cSrcweir     while( nOld < aSelBoxes.Count() )
2361cdf0e10cSrcweir         DeleteBox( nOld ); // some more to delete
2362cdf0e10cSrcweir 
2363cdf0e10cSrcweir     for( ; nNew < rNew.Count(); ++nNew ) // some more to insert
2364cdf0e10cSrcweir         InsertBox( **( rNew.GetData() + nNew ) );
2365cdf0e10cSrcweir }
2366cdf0e10cSrcweir 
IsCrsrMovedUpdt()2367cdf0e10cSrcweir sal_Bool SwTableCursor::IsCrsrMovedUpdt()
2368cdf0e10cSrcweir {
2369cdf0e10cSrcweir 	if( !IsCrsrMoved() )
2370cdf0e10cSrcweir 		return sal_False;
2371cdf0e10cSrcweir 
2372cdf0e10cSrcweir 	nTblMkNd = GetMark()->nNode.GetIndex();
2373cdf0e10cSrcweir 	nTblPtNd = GetPoint()->nNode.GetIndex();
2374cdf0e10cSrcweir 	nTblMkCnt = GetMark()->nContent.GetIndex();
2375cdf0e10cSrcweir 	nTblPtCnt = GetPoint()->nContent.GetIndex();
2376cdf0e10cSrcweir 	return sal_True;
2377cdf0e10cSrcweir }
2378cdf0e10cSrcweir 
2379cdf0e10cSrcweir 
2380cdf0e10cSrcweir // Parke den Tabellen-Cursor auf dem StartNode der Boxen.
ParkCrsr()2381cdf0e10cSrcweir void SwTableCursor::ParkCrsr()
2382cdf0e10cSrcweir {
2383cdf0e10cSrcweir 	// Index aus dem TextNode abmelden
2384cdf0e10cSrcweir 	SwNode* pNd = &GetPoint()->nNode.GetNode();
2385cdf0e10cSrcweir 	if( !pNd->IsStartNode() )
2386cdf0e10cSrcweir 		pNd = pNd->StartOfSectionNode();
2387cdf0e10cSrcweir 	GetPoint()->nNode = *pNd;
2388cdf0e10cSrcweir 	GetPoint()->nContent.Assign( 0, 0 );
2389cdf0e10cSrcweir 
2390cdf0e10cSrcweir 	pNd = &GetMark()->nNode.GetNode();
2391cdf0e10cSrcweir 	if( !pNd->IsStartNode() )
2392cdf0e10cSrcweir 		pNd = pNd->StartOfSectionNode();
2393cdf0e10cSrcweir 	GetMark()->nNode = *pNd;
2394cdf0e10cSrcweir 	GetMark()->nContent.Assign( 0, 0 );
2395cdf0e10cSrcweir 
2396cdf0e10cSrcweir 	bChg = sal_True;
2397cdf0e10cSrcweir 	bParked = sal_True;
2398cdf0e10cSrcweir }
2399cdf0e10cSrcweir 
2400cdf0e10cSrcweir 
HasReadOnlyBoxSel() const2401cdf0e10cSrcweir sal_Bool SwTableCursor::HasReadOnlyBoxSel() const
2402cdf0e10cSrcweir {
2403cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2404cdf0e10cSrcweir 	for( sal_uInt16 n = aSelBoxes.Count(); n;  )
2405cdf0e10cSrcweir 		if( aSelBoxes[ --n ]->GetFrmFmt()->GetProtect().IsCntntProtected() )
2406cdf0e10cSrcweir 		{
2407cdf0e10cSrcweir 			bRet = sal_True;
2408cdf0e10cSrcweir 			break;
2409cdf0e10cSrcweir 		}
2410cdf0e10cSrcweir 	return bRet;
2411cdf0e10cSrcweir }
2412cdf0e10cSrcweir 
2413cdf0e10cSrcweir 
2414