Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <hintids.hxx>
30 : : #include <editeng/protitem.hxx>
31 : : #include <cntfrm.hxx>
32 : : #include <pagefrm.hxx>
33 : : #include <doc.hxx>
34 : : #include <docary.hxx>
35 : : #include <pam.hxx>
36 : : #include <pamtyp.hxx>
37 : : #include <txtfrm.hxx>
38 : : #include <fmtcntnt.hxx>
39 : : #include <frmatr.hxx>
40 : : #include <swtable.hxx>
41 : : #include <crsskip.hxx>
42 : :
43 : : // Formular view
44 : : #include <flyfrm.hxx>
45 : : #include <fmteiro.hxx>
46 : : #include <section.hxx>
47 : : #include <sectfrm.hxx>
48 : : #include <ndtxt.hxx>
49 : :
50 : : #include <IMark.hxx>
51 : : #include <hints.hxx>
52 : :
53 : : #include <xmloff/odffields.hxx>
54 : :
55 : : // for the dump "MSC-" compiler
56 : 49445 : inline xub_StrLen GetSttOrEnd( sal_Bool bCondition, const SwCntntNode& rNd )
57 : : {
58 [ + + ]: 49445 : return bCondition ? 0 : rNd.Len();
59 : : }
60 : :
61 : 29432 : SwPosition::SwPosition( const SwNodeIndex & rNodeIndex, const SwIndex & rCntnt )
62 [ + - ]: 29432 : : nNode( rNodeIndex ), nContent( rCntnt )
63 : : {
64 : 29432 : }
65 : :
66 : 401966 : SwPosition::SwPosition( const SwNodeIndex & rNodeIndex )
67 [ + + ][ + - ]: 401966 : : nNode( rNodeIndex ), nContent( nNode.GetNode().GetCntntNode() )
68 : : {
69 : 401966 : }
70 : :
71 : 178721 : SwPosition::SwPosition( const SwNode& rNode )
72 [ + + ][ + - ]: 178721 : : nNode( rNode ), nContent( nNode.GetNode().GetCntntNode() )
73 : : {
74 : 178721 : }
75 : :
76 : 9609 : SwPosition::SwPosition( SwCntntNode & rNode, const xub_StrLen nOffset )
77 [ + - ]: 9609 : : nNode( rNode ), nContent( &rNode, nOffset )
78 : : {
79 : 9609 : }
80 : :
81 : :
82 : 1030890 : SwPosition::SwPosition( const SwPosition & rPos )
83 [ + - ]: 1030890 : : nNode( rPos.nNode ), nContent( rPos.nContent )
84 : : {
85 : 1030890 : }
86 : :
87 : 244031 : SwPosition &SwPosition::operator=(const SwPosition &rPos)
88 : : {
89 : 244031 : nNode = rPos.nNode;
90 : 244031 : nContent = rPos.nContent;
91 : 244031 : return *this;
92 : : }
93 : :
94 : :
95 : 956098 : sal_Bool SwPosition::operator<(const SwPosition &rPos) const
96 : : {
97 [ + + ]: 956098 : if( nNode < rPos.nNode )
98 : 77759 : return sal_True;
99 [ + + ]: 878339 : if( nNode == rPos.nNode )
100 : : {
101 : : // note that positions with text node but no SwIndex registered are
102 : : // created for text frames anchored at para (see SwXFrame::getAnchor())
103 : 838014 : SwIndexReg const*const pThisReg(nContent.GetIdxReg());
104 : 838014 : SwIndexReg const*const pOtherReg(rPos.nContent.GetIdxReg());
105 [ + - ][ + + ]: 838014 : if (pThisReg && pOtherReg)
106 : : {
107 : 837936 : return (nContent < rPos.nContent);
108 : : }
109 : : else // by convention position with no index is smaller
110 : : {
111 [ - + ]: 78 : return (pOtherReg) ? sal_True : sal_False;
112 : : }
113 : : }
114 : 956098 : return sal_False;
115 : : }
116 : :
117 : :
118 : 235872 : sal_Bool SwPosition::operator>(const SwPosition &rPos) const
119 : : {
120 [ + + ]: 235872 : if(nNode > rPos.nNode )
121 : 54714 : return sal_True;
122 [ + + ]: 181158 : if( nNode == rPos.nNode )
123 : : {
124 : : // note that positions with text node but no SwIndex registered are
125 : : // created for text frames anchored at para (see SwXFrame::getAnchor())
126 : 178014 : SwIndexReg const*const pThisReg(nContent.GetIdxReg());
127 : 178014 : SwIndexReg const*const pOtherReg(rPos.nContent.GetIdxReg());
128 [ + - ][ + + ]: 178014 : if (pThisReg && pOtherReg)
129 : : {
130 : 170165 : return (nContent > rPos.nContent);
131 : : }
132 : : else // by convention position with no index is smaller
133 : : {
134 [ - + ]: 7849 : return (pThisReg) ? sal_True : sal_False;
135 : : }
136 : : }
137 : 235872 : return sal_False;
138 : : }
139 : :
140 : :
141 : 2456997 : sal_Bool SwPosition::operator<=(const SwPosition &rPos) const
142 : : {
143 [ + + ]: 2456997 : if(nNode < rPos.nNode )
144 : 553278 : return sal_True;
145 [ + + ]: 1903719 : if( nNode == rPos.nNode )
146 : : {
147 : : // note that positions with text node but no SwIndex registered are
148 : : // created for text frames anchored at para (see SwXFrame::getAnchor())
149 : 568239 : SwIndexReg const*const pThisReg(nContent.GetIdxReg());
150 : 568239 : SwIndexReg const*const pOtherReg(rPos.nContent.GetIdxReg());
151 [ + - ][ + + ]: 568239 : if (pThisReg && pOtherReg)
152 : : {
153 : 561760 : return (nContent <= rPos.nContent);
154 : : }
155 : : else // by convention position with no index is smaller
156 : : {
157 : 6479 : return (pThisReg) ? sal_False : sal_True;
158 : : }
159 : : }
160 : 2456997 : return sal_False;
161 : : }
162 : :
163 : :
164 : 5332154 : sal_Bool SwPosition::operator>=(const SwPosition &rPos) const
165 : : {
166 [ + + ]: 5332154 : if(nNode > rPos.nNode )
167 : 27 : return sal_True;
168 [ + + ]: 5332127 : if( nNode == rPos.nNode )
169 : : {
170 : : // note that positions with text node but no SwIndex registered are
171 : : // created for text frames anchored at para (see SwXFrame::getAnchor())
172 : 5275089 : SwIndexReg const*const pThisReg(nContent.GetIdxReg());
173 : 5275089 : SwIndexReg const*const pOtherReg(rPos.nContent.GetIdxReg());
174 [ + - ][ + + ]: 5275089 : if (pThisReg && pOtherReg)
175 : : {
176 : 5270257 : return (nContent >= rPos.nContent);
177 : : }
178 : : else // by convention position with no index is smaller
179 : : {
180 : 4832 : return (pOtherReg) ? sal_False : sal_True;
181 : : }
182 : : }
183 : 5332154 : return sal_False;
184 : : }
185 : :
186 : :
187 : 14092 : sal_Bool SwPosition::operator==(const SwPosition &rPos) const
188 : : {
189 : 14092 : return (nNode == rPos.nNode)
190 : : // GetIndexReg may be null for FLY_AT_PARA frame anchor position
191 : 13624 : && (nContent.GetIdxReg() == rPos.nContent.GetIdxReg())
192 [ + + ]: 27716 : && (nContent == rPos.nContent);
[ + + + + ]
193 : : }
194 : :
195 : :
196 : 191780 : sal_Bool SwPosition::operator!=(const SwPosition &rPos) const
197 : : {
198 : 191780 : return (nNode != rPos.nNode)
199 : : // GetIndexReg may be null for FLY_AT_PARA frame anchor position
200 : 191290 : || (nContent.GetIdxReg() != rPos.nContent.GetIdxReg())
201 [ + + ]: 383070 : || (nContent != rPos.nContent);
[ + + + - ]
202 : : }
203 : :
204 : 2731 : SwDoc * SwPosition::GetDoc() const
205 : : {
206 : 2731 : return nNode.GetNode().GetDoc();
207 : : }
208 : :
209 : :
210 : : enum CHKSECTION { Chk_Both, Chk_One, Chk_None };
211 : :
212 : :
213 : 13097 : CHKSECTION lcl_TstIdx( sal_uLong nSttIdx, sal_uLong nEndIdx, const SwNode& rEndNd )
214 : : {
215 : 13097 : sal_uLong nStt = rEndNd.StartOfSectionIndex(), nEnd = rEndNd.GetIndex();
216 [ + + ][ + + ]: 13097 : CHKSECTION eSec = nStt < nSttIdx && nEnd >= nSttIdx ? Chk_One : Chk_None;
217 [ + + ][ + + ]: 13097 : if( nStt < nEndIdx && nEnd >= nEndIdx )
218 : 12544 : return( eSec == Chk_One ? Chk_Both : Chk_One );
219 : 13097 : return eSec;
220 : : }
221 : :
222 : :
223 : 359 : sal_Bool lcl_ChkOneRange( CHKSECTION eSec, sal_Bool bChkSections,
224 : : const SwNode& rBaseEnd, sal_uLong nStt, sal_uLong nEnd )
225 : : {
226 [ + + ]: 359 : if( eSec != Chk_Both )
227 : 3 : return sal_False;
228 : :
229 [ - + ]: 356 : if( !bChkSections )
230 : 0 : return sal_True;
231 : :
232 : : // search the surrounding section
233 : 356 : const SwNodes& rNds = rBaseEnd.GetNodes();
234 : 356 : const SwNode *pTmp, *pNd = rNds[ nStt ];
235 [ + + ]: 356 : if( !pNd->IsStartNode() )
236 : 353 : pNd = pNd->StartOfSectionNode();
237 : :
238 [ + + ]: 356 : if( pNd == rNds[ nEnd ]->StartOfSectionNode() )
239 : 298 : return sal_True; // same StartNode, same section
240 : :
241 : : // already on a base node => error
242 [ - + ]: 58 : if( !pNd->StartOfSectionIndex() )
243 : 0 : return sal_False;
244 : :
245 [ - + ]: 58 : while( ( pTmp = pNd->StartOfSectionNode())->EndOfSectionNode() !=
246 : : &rBaseEnd )
247 : 0 : pNd = pTmp;
248 : :
249 : 58 : sal_uLong nSttIdx = pNd->GetIndex(), nEndIdx = pNd->EndOfSectionIndex();
250 : : return nSttIdx <= nStt && nStt <= nEndIdx &&
251 [ + - ][ + + ]: 359 : nSttIdx <= nEnd && nEnd <= nEndIdx ? sal_True : sal_False;
[ + + ][ + - ]
252 : : }
253 : :
254 : :
255 : 12550 : sal_Bool CheckNodesRange( const SwNodeIndex& rStt,
256 : : const SwNodeIndex& rEnd, sal_Bool bChkSection )
257 : : {
258 : 12550 : const SwNodes& rNds = rStt.GetNodes();
259 : 12550 : sal_uLong nStt = rStt.GetIndex(), nEnd = rEnd.GetIndex();
260 : 12550 : CHKSECTION eSec = lcl_TstIdx( nStt, nEnd, rNds.GetEndOfContent() );
261 [ + + ][ + + ]: 12550 : if( Chk_None != eSec ) return eSec == Chk_Both ? sal_True : sal_False;
262 : :
263 : 359 : eSec = lcl_TstIdx( nStt, nEnd, rNds.GetEndOfAutotext() );
264 [ + + ]: 359 : if( Chk_None != eSec )
265 : : return lcl_ChkOneRange( eSec, bChkSection,
266 : 265 : rNds.GetEndOfAutotext(), nStt, nEnd );
267 : :
268 : 94 : eSec = lcl_TstIdx( nStt, nEnd, rNds.GetEndOfPostIts() );
269 [ - + ]: 94 : if( Chk_None != eSec )
270 : : return lcl_ChkOneRange( eSec, bChkSection,
271 : 0 : rNds.GetEndOfPostIts(), nStt, nEnd );
272 : :
273 : 94 : eSec = lcl_TstIdx( nStt, nEnd, rNds.GetEndOfInserts() );
274 [ + - ]: 94 : if( Chk_None != eSec )
275 : : return lcl_ChkOneRange( eSec, bChkSection,
276 : 94 : rNds.GetEndOfInserts(), nStt, nEnd );
277 : :
278 : 0 : eSec = lcl_TstIdx( nStt, nEnd, rNds.GetEndOfRedlines() );
279 [ # # ]: 0 : if( Chk_None != eSec )
280 : : return lcl_ChkOneRange( eSec, bChkSection,
281 : 0 : rNds.GetEndOfRedlines(), nStt, nEnd );
282 : :
283 : 12550 : return sal_False; // somewhere in between => error
284 : : }
285 : :
286 : :
287 : 97023 : sal_Bool GoNext(SwNode* pNd, SwIndex * pIdx, sal_uInt16 nMode )
288 : : {
289 [ + + ]: 97023 : if( pNd->IsCntntNode() )
290 [ + - ]: 97001 : return ((SwCntntNode*)pNd)->GoNext( pIdx, nMode );
291 : 97023 : return sal_False;
292 : : }
293 : :
294 : :
295 : 68508 : sal_Bool GoPrevious( SwNode* pNd, SwIndex * pIdx, sal_uInt16 nMode )
296 : : {
297 [ + + ]: 68508 : if( pNd->IsCntntNode() )
298 [ + - ]: 68494 : return ((SwCntntNode*)pNd)->GoPrevious( pIdx, nMode );
299 : 68508 : return sal_False;
300 : : }
301 : :
302 : :
303 : 18971 : SwCntntNode* GoNextNds( SwNodeIndex* pIdx, sal_Bool bChk )
304 : : {
305 [ + - ]: 18971 : SwNodeIndex aIdx( *pIdx );
306 [ + - ]: 18971 : SwCntntNode* pNd = aIdx.GetNodes().GoNext( &aIdx );
307 [ + + ]: 18971 : if( pNd )
308 : : {
309 [ + + ][ + + ]: 15781 : if( bChk && 1 != aIdx.GetIndex() - pIdx->GetIndex() &&
[ + + ][ + + ]
310 [ + - ]: 1858 : !CheckNodesRange( *pIdx, aIdx, sal_True ) )
311 : 253 : pNd = 0;
312 : : else
313 [ + - ]: 13670 : *pIdx = aIdx;
314 : : }
315 [ + - ]: 18971 : return pNd;
316 : : }
317 : :
318 : :
319 : 37095 : SwCntntNode* GoPreviousNds( SwNodeIndex * pIdx, sal_Bool bChk )
320 : : {
321 [ + - ]: 37095 : SwNodeIndex aIdx( *pIdx );
322 [ + - ]: 37095 : SwCntntNode* pNd = aIdx.GetNodes().GoPrevious( &aIdx );
323 [ + + ]: 37095 : if( pNd )
324 : : {
325 [ + - ][ + + ]: 37173 : if( bChk && 1 != pIdx->GetIndex() - aIdx.GetIndex() &&
[ + + ][ + + ]
326 [ + - ]: 119 : !CheckNodesRange( *pIdx, aIdx, sal_True ) )
327 : 18 : pNd = 0;
328 : : else
329 [ + - ]: 37036 : *pIdx = aIdx;
330 : : }
331 [ + - ]: 37095 : return pNd;
332 : : }
333 : :
334 : :
335 : 195204 : SwPaM::SwPaM( const SwPosition& rPos, SwPaM* pRing )
336 : : : Ring( pRing )
337 : : , m_Bound1( rPos )
338 : 195204 : , m_Bound2( rPos.nNode.GetNode().GetNodes() ) // default initialize
339 : : , m_pPoint( &m_Bound1 )
340 : : , m_pMark( m_pPoint )
341 [ + - + - ]: 390408 : , m_bIsInFrontOfLabel( false )
[ + - ][ + - ]
342 : : {
343 : 195204 : }
344 : :
345 : 48775 : SwPaM::SwPaM( const SwPosition& rMark, const SwPosition& rPoint, SwPaM* pRing )
346 : : : Ring( pRing )
347 : : , m_Bound1( rMark )
348 : : , m_Bound2( rPoint )
349 : : , m_pPoint( &m_Bound2 )
350 : : , m_pMark( &m_Bound1 )
351 [ + - ][ + - ]: 48775 : , m_bIsInFrontOfLabel( false )
352 : : {
353 : 48775 : }
354 : :
355 : 146 : SwPaM::SwPaM( const SwNodeIndex& rMark, const SwNodeIndex& rPoint,
356 : : long nMarkOffset, long nPointOffset, SwPaM* pRing )
357 : : : Ring( pRing )
358 : : , m_Bound1( rMark )
359 : : , m_Bound2( rPoint )
360 : : , m_pPoint( &m_Bound2 )
361 : : , m_pMark( &m_Bound1 )
362 [ + - ][ + - ]: 146 : , m_bIsInFrontOfLabel( false )
363 : : {
364 [ - + ]: 146 : if ( nMarkOffset )
365 : : {
366 [ # # ]: 0 : m_pMark->nNode += nMarkOffset;
367 : : }
368 [ - + ]: 146 : if ( nPointOffset )
369 : : {
370 [ # # ]: 0 : m_pPoint->nNode += nPointOffset;
371 : : }
372 : :
373 [ + + ][ + - ]: 146 : m_Bound1.nContent.Assign( m_Bound1.nNode.GetNode().GetCntntNode(), 0 );
374 [ + + ][ + - ]: 146 : m_Bound2.nContent.Assign( m_Bound2.nNode.GetNode().GetCntntNode(), 0 );
375 : 146 : }
376 : :
377 : 11983 : SwPaM::SwPaM( const SwNode& rMark, const SwNode& rPoint,
378 : : long nMarkOffset, long nPointOffset, SwPaM* pRing )
379 : : : Ring( pRing )
380 : : , m_Bound1( rMark )
381 : : , m_Bound2( rPoint )
382 : : , m_pPoint( &m_Bound2 )
383 : : , m_pMark( &m_Bound1 )
384 [ + - ][ + - ]: 11983 : , m_bIsInFrontOfLabel( false )
385 : : {
386 [ - + ]: 11983 : if ( nMarkOffset )
387 : : {
388 [ # # ]: 0 : m_pMark->nNode += nMarkOffset;
389 : : }
390 [ - + ]: 11983 : if ( nPointOffset )
391 : : {
392 [ # # ]: 0 : m_pPoint->nNode += nPointOffset;
393 : : }
394 : :
395 [ - + ][ + - ]: 11983 : m_Bound1.nContent.Assign( m_Bound1.nNode.GetNode().GetCntntNode(), 0 );
396 [ - + ][ + - ]: 11983 : m_Bound2.nContent.Assign( m_Bound2.nNode.GetNode().GetCntntNode(), 0 );
397 : 11983 : }
398 : :
399 : 3553 : SwPaM::SwPaM( const SwNodeIndex& rMark , xub_StrLen nMarkCntnt,
400 : : const SwNodeIndex& rPoint, xub_StrLen nPointCntnt, SwPaM* pRing )
401 : : : Ring( pRing )
402 : : , m_Bound1( rMark )
403 : : , m_Bound2( rPoint )
404 : : , m_pPoint( &m_Bound2 )
405 : : , m_pMark( &m_Bound1 )
406 [ + - ][ + - ]: 3553 : , m_bIsInFrontOfLabel( false )
407 : : {
408 [ + + ][ + - ]: 3553 : m_pPoint->nContent.Assign( rPoint.GetNode().GetCntntNode(), nPointCntnt);
409 [ + + ][ + - ]: 3553 : m_pMark ->nContent.Assign( rMark .GetNode().GetCntntNode(), nMarkCntnt );
410 : 3553 : }
411 : :
412 : 47 : SwPaM::SwPaM( const SwNode& rMark , xub_StrLen nMarkCntnt,
413 : : const SwNode& rPoint, xub_StrLen nPointCntnt, SwPaM* pRing )
414 : : : Ring( pRing )
415 : : , m_Bound1( rMark )
416 : : , m_Bound2( rPoint )
417 : : , m_pPoint( &m_Bound2 )
418 : : , m_pMark( &m_Bound1 )
419 [ + - ][ + - ]: 47 : , m_bIsInFrontOfLabel( false )
420 : : {
421 : 47 : m_pPoint->nContent.Assign( m_pPoint->nNode.GetNode().GetCntntNode(),
422 [ + - ][ + - ]: 47 : nPointCntnt);
423 : 47 : m_pMark ->nContent.Assign( m_pMark ->nNode.GetNode().GetCntntNode(),
424 [ + - ][ + - ]: 47 : nMarkCntnt );
425 : 47 : }
426 : :
427 : 16448 : SwPaM::SwPaM( const SwNode& rNode, xub_StrLen nCntnt, SwPaM* pRing )
428 : : : Ring( pRing )
429 : : , m_Bound1( rNode )
430 : 16448 : , m_Bound2( m_Bound1.nNode.GetNode().GetNodes() ) // default initialize
431 : : , m_pPoint( &m_Bound1 )
432 : : , m_pMark( &m_Bound1 )
433 [ + - + - ]: 32896 : , m_bIsInFrontOfLabel( false )
[ + - ][ + - ]
434 : : {
435 : 16448 : m_pPoint->nContent.Assign( m_pPoint->nNode.GetNode().GetCntntNode(),
436 [ + - ][ + + ]: 16448 : nCntnt );
437 : 16448 : }
438 : :
439 : 84217 : SwPaM::SwPaM( const SwNodeIndex& rNodeIdx, xub_StrLen nCntnt, SwPaM* pRing )
440 : : : Ring( pRing )
441 : : , m_Bound1( rNodeIdx )
442 : 84217 : , m_Bound2( rNodeIdx.GetNode().GetNodes() ) // default initialize
443 : : , m_pPoint( &m_Bound1 )
444 : : , m_pMark( &m_Bound1 )
445 [ + - + - ]: 168434 : , m_bIsInFrontOfLabel( false )
[ + - ][ + - ]
446 : : {
447 [ + + ][ + - ]: 84217 : m_pPoint->nContent.Assign( rNodeIdx.GetNode().GetCntntNode(), nCntnt );
448 : 84217 : }
449 : :
450 [ + - ][ + - ]: 384933 : SwPaM::~SwPaM() {}
[ - + ]
451 : :
452 : : // @@@ semantic: no copy ctor.
453 : 277 : SwPaM::SwPaM( SwPaM &rPam )
454 : : : Ring( &rPam )
455 : : , m_Bound1( *(rPam.m_pPoint) )
456 : : , m_Bound2( *(rPam.m_pMark) )
457 : 277 : , m_pPoint( &m_Bound1 ), m_pMark( rPam.HasMark() ? &m_Bound2 : m_pPoint )
458 [ + - ]: 554 : , m_bIsInFrontOfLabel( false )
[ + - + + ]
459 : : {
460 : 277 : }
461 : :
462 : : // @@@ semantic: no copy assignment for super class Ring.
463 : 14 : SwPaM &SwPaM::operator=( const SwPaM &rPam )
464 : : {
465 : 14 : *m_pPoint = *( rPam.m_pPoint );
466 [ + + ]: 14 : if ( rPam.HasMark() )
467 : : {
468 : 4 : SetMark();
469 : 4 : *m_pMark = *( rPam.m_pMark );
470 : : }
471 : : else
472 : : {
473 : 10 : DeleteMark();
474 : : }
475 : 14 : return *this;
476 : : }
477 : :
478 : 130879 : void SwPaM::SetMark()
479 : : {
480 [ + + ]: 130879 : if (m_pPoint == &m_Bound1)
481 : : {
482 : 130791 : m_pMark = &m_Bound2;
483 : : }
484 : : else
485 : : {
486 : 88 : m_pMark = &m_Bound1;
487 : : }
488 : 130879 : (*m_pMark) = (*m_pPoint);
489 : 130879 : }
490 : :
491 : : #ifdef DBG_UTIL
492 : :
493 : : void SwPaM::Exchange()
494 : : {
495 : : if (m_pPoint != m_pMark)
496 : : {
497 : : SwPosition *pTmp = m_pPoint;
498 : : m_pPoint = m_pMark;
499 : : m_pMark = pTmp;
500 : : }
501 : : }
502 : : #endif
503 : :
504 : : /// movement of cursor
505 : 225720 : sal_Bool SwPaM::Move( SwMoveFn fnMove, SwGoInDoc fnGo )
506 : : {
507 : 225720 : sal_Bool bRet = (*fnGo)( *this, fnMove );
508 : :
509 : 225720 : m_bIsInFrontOfLabel = false;
510 : :
511 : 225720 : return bRet;
512 : : }
513 : :
514 : : /** make a new region
515 : :
516 : : Sets the first SwPaM onto the given SwPaM, or to the beginning or end of a
517 : : document. SPoint stays at its position, GetMark will be changed respectively.
518 : :
519 : : @param fnMove Contains information if beginning or end of document.
520 : : @param pOrigRg The given region.
521 : :
522 : : @return Newly created area.
523 : : */
524 : 180 : SwPaM* SwPaM::MakeRegion( SwMoveFn fnMove, const SwPaM * pOrigRg )
525 : : {
526 : : SwPaM* pPam;
527 [ - + ]: 180 : if( pOrigRg == 0 )
528 : : {
529 [ # # ]: 0 : pPam = new SwPaM( *m_pPoint );
530 : 0 : pPam->SetMark(); // set beginning
531 : 0 : pPam->Move( fnMove, fnGoSection); // to beginning or end of a node
532 : :
533 : : // set SPoint onto its old position; set GetMark to the "end"
534 : 0 : pPam->Exchange();
535 : : }
536 : : else
537 : : {
538 [ + - ]: 180 : pPam = new SwPaM( *(SwPaM*)pOrigRg ); // given search area
539 : : // make sure that SPoint is on the "real" start position
540 : : // FORWARD: SPoint always smaller than GetMark
541 : : // BACKWARD: SPoint always bigger than GetMark
542 [ + - ][ + - ]: 180 : if( (pPam->GetMark()->*fnMove->fnCmpOp)( *pPam->GetPoint() ) )
543 : 180 : pPam->Exchange();
544 : : }
545 : 180 : return pPam;
546 : : }
547 : :
548 : 6525 : SwPaM & SwPaM::Normalize(sal_Bool bPointFirst)
549 : : {
550 [ + + ]: 6525 : if (HasMark())
551 [ + + ][ + + ]: 12234 : if ( ( bPointFirst && *m_pPoint > *m_pMark) ||
[ + + + + ]
[ + + ]
552 : 6081 : (!bPointFirst && *m_pPoint < *m_pMark) )
553 : : {
554 : 630 : Exchange();
555 : : }
556 : :
557 : 6525 : return *this;
558 : : }
559 : :
560 : : /// return page number at cursor (for reader and page bound frames)
561 : 11 : sal_uInt16 SwPaM::GetPageNum( sal_Bool bAtPoint, const Point* pLayPos )
562 : : {
563 : : const SwCntntFrm* pCFrm;
564 : : const SwPageFrm *pPg;
565 : : const SwCntntNode *pNd ;
566 [ + - ]: 11 : const SwPosition* pPos = bAtPoint ? m_pPoint : m_pMark;
567 : :
568 [ + - + - ]: 22 : if( 0 != ( pNd = pPos->nNode.GetNode().GetCntntNode() ) &&
[ + - ][ + - ]
569 : 11 : 0 != ( pCFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout(), pLayPos, pPos, sal_False )) &&
570 : 11 : 0 != ( pPg = pCFrm->FindPageFrm() ))
571 : 11 : return pPg->GetPhyPageNum();
572 : 11 : return 0;
573 : : }
574 : :
575 : : // Formular view - See also SwCrsrShell::IsCrsrReadonly()
576 : 0 : const SwFrm* lcl_FindEditInReadonlyFrm( const SwFrm& rFrm )
577 : : {
578 : 0 : const SwFrm* pRet = 0;
579 : :
580 : : const SwFlyFrm* pFly;
581 : : const SwSectionFrm* pSectionFrm;
582 : :
583 [ # # ][ # # : 0 : if( rFrm.IsInFly() &&
# # # # ]
[ # # ]
584 : 0 : (pFly = rFrm.FindFlyFrm())->GetFmt()->GetEditInReadonly().GetValue() &&
585 : 0 : pFly->Lower() &&
586 : 0 : !pFly->Lower()->IsNoTxtFrm() )
587 : : {
588 : 0 : pRet = pFly;
589 : : }
590 [ # # ]: 0 : else if ( rFrm.IsInSct() &&
[ # # # # ]
[ # # ]
591 : 0 : 0 != ( pSectionFrm = rFrm.FindSctFrm() )->GetSection() &&
592 : 0 : pSectionFrm->GetSection()->IsEditInReadonlyFlag() )
593 : : {
594 : 0 : pRet = pSectionFrm;
595 : : }
596 : :
597 : 0 : return pRet;
598 : : }
599 : :
600 : : /// is in protected section or selection surrounds something protected
601 : 23596 : sal_Bool SwPaM::HasReadonlySel( bool bFormView ) const
602 : : {
603 : 23596 : sal_Bool bRet = sal_False;
604 : 23596 : Point aTmpPt;
605 : : const SwCntntNode *pNd;
606 : : const SwCntntFrm *pFrm;
607 : :
608 [ + - ]: 23596 : if( 0 != ( pNd = GetPoint()->nNode.GetNode().GetCntntNode() ))
609 [ + - ][ + - ]: 23596 : pFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout(), &aTmpPt, GetPoint(), sal_False );
610 : : else
611 : 0 : pFrm = 0;
612 : :
613 : : // Will be set if point/mark are inside edit-in-readonly environment
614 : 23596 : const SwFrm* pSttEIRFrm = 0;
615 : 23596 : const SwFrm* pEndEIRFrm = 0;
616 : :
617 [ + - ][ + - ]: 23596 : if( pFrm && ( pFrm->IsProtected() ||
[ + - ][ - + ]
[ # # ][ # # ]
[ - + ]
618 : 0 : ( bFormView && 0 == ( pSttEIRFrm = lcl_FindEditInReadonlyFrm( *pFrm ) ) ) ) )
619 : 0 : bRet = sal_True;
620 [ + - ]: 23596 : else if( pNd )
621 : : {
622 : 23596 : const SwSectionNode* pSNd = pNd->GetSectionNode();
623 [ # # ]: 23596 : if( pSNd && ( pSNd->GetSection().IsProtectFlag() ||
[ # # # # ]
[ - + ][ - + ]
624 : 0 : (bFormView && !pSNd->GetSection().IsEditInReadonlyFlag()) ) )
625 : 0 : bRet = sal_True;
626 : : }
627 : :
628 [ + - ][ + + ]: 23596 : if( !bRet && HasMark() && GetPoint()->nNode != GetMark()->nNode )
[ + + ][ + + ]
629 : : {
630 [ + - ]: 22 : if( 0 != ( pNd = GetMark()->nNode.GetNode().GetCntntNode() ))
631 [ + - ][ + - ]: 22 : pFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout(), &aTmpPt, GetMark(), sal_False );
632 : : else
633 : 0 : pFrm = 0;
634 : :
635 [ + - ][ + - ]: 22 : if( pFrm && ( pFrm->IsProtected() ||
[ + - ][ - + ]
[ # # ][ # # ]
[ - + ]
636 : 0 : ( bFormView && 0 == ( pEndEIRFrm = lcl_FindEditInReadonlyFrm( *pFrm ) ) ) ) )
637 : 0 : bRet = sal_True;
638 [ + - ]: 22 : else if( pNd )
639 : : {
640 : 22 : const SwSectionNode* pSNd = pNd->GetSectionNode();
641 [ # # ]: 22 : if( pSNd && ( pSNd->GetSection().IsProtectFlag() ||
[ # # # # ]
[ - + ][ - + ]
642 : 0 : (bFormView && !pSNd->GetSection().IsEditInReadonlyFlag()) ) )
643 : 0 : bRet = sal_True;
644 : : }
645 : :
646 [ + - ][ - + ]: 22 : if ( !bRet && bFormView )
647 : : {
648 : : // Check if start and end frame are inside the _same_
649 : : // edit-in-readonly-environment. Otherwise we better return 'true'
650 [ # # ]: 0 : if ( pSttEIRFrm != pEndEIRFrm )
651 : 0 : bRet = sal_True;
652 : : }
653 : :
654 : : // protected section in selection
655 [ + - ]: 22 : if( !bRet )
656 : : {
657 : 22 : sal_uLong nSttIdx = GetMark()->nNode.GetIndex(),
658 : 22 : nEndIdx = GetPoint()->nNode.GetIndex();
659 [ - + ]: 22 : if( nEndIdx <= nSttIdx )
660 : : {
661 : 0 : sal_uLong nTmp = nSttIdx;
662 : 0 : nSttIdx = nEndIdx;
663 : 0 : nEndIdx = nTmp;
664 : : }
665 : :
666 : : // If a protected section should be between nodes, then the
667 : : // selection needs to contain already x nodes.
668 : : // (TxtNd, SectNd, TxtNd, EndNd, TxtNd )
669 [ + - ]: 22 : if( nSttIdx + 3 < nEndIdx )
670 : : {
671 : 22 : const SwSectionFmts& rFmts = GetDoc()->GetSections();
672 [ - + ]: 22 : for( sal_uInt16 n = rFmts.size(); n; )
673 : : {
674 : 0 : const SwSectionFmt* pFmt = rFmts[ --n ];
675 [ # # ][ # # ]: 0 : if( pFmt->GetProtect().IsCntntProtected() )
676 : : {
677 [ # # ]: 0 : const SwFmtCntnt& rCntnt = pFmt->GetCntnt(sal_False);
678 : : OSL_ENSURE( rCntnt.GetCntntIdx(), "wo ist der SectionNode?" );
679 : 0 : sal_uLong nIdx = rCntnt.GetCntntIdx()->GetIndex();
680 [ # # ][ # # ]: 0 : if( nSttIdx <= nIdx && nEndIdx >= nIdx &&
[ # # ][ # # ]
681 [ # # ]: 0 : rCntnt.GetCntntIdx()->GetNode().GetNodes().IsDocNodes() )
682 : : {
683 : 0 : bRet = sal_True;
684 : 0 : break;
685 : : }
686 : : }
687 : : }
688 : : }
689 : : }
690 : : }
691 : : //FIXME FieldBk
692 : : // TODO: Form Protection when Enhanced Fields are enabled
693 : 23596 : const SwDoc *pDoc = GetDoc();
694 : 23596 : sw::mark::IMark* pA = NULL;
695 : 23596 : sw::mark::IMark* pB = NULL;
696 : 23596 : bool bUnhandledMark = false;
697 [ + - ]: 23596 : if ( pDoc )
698 : : {
699 [ + - ]: 23596 : const IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess( );
700 [ + - ][ + - ]: 23596 : pA = GetPoint() ? pMarksAccess->getFieldmarkFor( *GetPoint( ) ) : NULL;
[ + + ]
701 [ + - ][ + - ]: 23596 : pB = GetMark( ) ? pMarksAccess->getFieldmarkFor( *GetMark( ) ) : pA;
[ + + ]
702 : :
703 [ + - ]: 23596 : sw::mark::IFieldmark* pFieldmark = pMarksAccess->getFieldmarkFor( *GetPoint() );
704 [ + + ]: 23596 : if ( pFieldmark )
705 [ + - ]: 6 : bUnhandledMark = pFieldmark->GetFieldname( ) == ODF_UNHANDLED;
706 : : }
707 : :
708 [ + - ]: 23596 : if (!bRet)
709 : : {
710 : : // Unhandled fieldmarks case shouldn't be edited manually to avoid breaking anything
711 [ + - ][ - + ]: 23596 : if ( ( pA == pB ) && bUnhandledMark )
712 : 0 : bRet = sal_True;
713 : : else
714 : : {
715 : : // Form protection case
716 [ + + ][ + - ]: 23596 : bool bAtStartA = pA != NULL && pA->GetMarkStart() == *GetPoint();
[ + - ][ + - ]
717 [ + + ][ + - ]: 23596 : bool bAtStartB = pB != NULL && pB->GetMarkStart() == *GetMark();
[ + - ][ + - ]
718 [ + - ][ + + ]: 23596 : bRet = ( pA != pB ) || bAtStartA || bAtStartB;
[ - + ]
719 [ + - ]: 23596 : bool bProtectForm = pDoc->get( IDocumentSettingAccess::PROTECT_FORM );
720 [ - + ]: 23596 : if ( bProtectForm )
721 [ # # ][ # # ]: 23596 : bRet |= ( pA == NULL || pB == NULL );
722 : : }
723 : : }
724 : : else
725 : : {
726 [ # # ][ # # ]: 0 : bRet = !( pA == pB && pA != NULL );
727 : : }
728 : 23596 : return bRet;
729 : : }
730 : :
731 : : /// This function returns the next node in direction of search. If there is no
732 : : /// left or the next is out of the area, then a null-pointer is returned.
733 : : /// @param rbFirst If <true> than first time request. If so than the position of
734 : : /// the PaM must not be changed!
735 : 604 : SwCntntNode* GetNode( SwPaM & rPam, sal_Bool& rbFirst, SwMoveFn fnMove,
736 : : sal_Bool bInReadOnly )
737 : : {
738 : 604 : SwCntntNode * pNd = 0;
739 : : SwCntntFrm* pFrm;
740 [ + - ]: 608 : if( ((*rPam.GetPoint()).*fnMove->fnCmpOp)( *rPam.GetMark() ) ||
[ + + + - ]
[ + + ][ + + ]
741 : 4 : ( *rPam.GetPoint() == *rPam.GetMark() && rbFirst ) )
742 : : {
743 [ + + ]: 602 : if( rbFirst )
744 : : {
745 : 180 : rbFirst = sal_False;
746 : 180 : pNd = rPam.GetCntntNode();
747 [ + - ]: 180 : if( pNd )
748 : : {
749 [ + + + - : 768 : if(
+ - + - ]
[ + + + +
- + ][ - + ]
[ + - ]
750 : : (
751 : 180 : 0 == ( pFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout() ) ) ||
752 : 92 : ( !bInReadOnly && pFrm->IsProtected() ) ||
753 : 360 : (pFrm->IsTxtFrm() && ((SwTxtFrm*)pFrm)->IsHiddenNow())
754 : : ) ||
755 : 92 : ( !bInReadOnly && pNd->FindSectionNode() &&
756 : 44 : pNd->FindSectionNode()->GetSection().IsProtect()
757 : : )
758 : : )
759 : : {
760 : 0 : pNd = 0;
761 : : }
762 : : }
763 : : }
764 : :
765 [ + + ]: 602 : if( !pNd ) // is the cursor not on a CntntNode?
766 : : {
767 [ + - ]: 422 : SwPosition aPos( *rPam.GetPoint() );
768 : 422 : sal_Bool bSrchForward = fnMove == fnMoveForward;
769 : 422 : SwNodes& rNodes = aPos.nNode.GetNodes();
770 : :
771 : : // go to next/previous CntntNode
772 : 0 : while( sal_True )
773 : : {
774 : : pNd = bSrchForward
775 : 422 : ? rNodes.GoNextSection( &aPos.nNode, sal_True, !bInReadOnly )
776 [ + - ][ + - ]: 422 : : rNodes.GoPrevSection( &aPos.nNode, sal_True, !bInReadOnly );
[ # # ]
777 [ + - ]: 422 : if( pNd )
778 : : {
779 [ + - ][ + - ]: 422 : aPos.nContent.Assign( pNd, ::GetSttOrEnd( bSrchForward,*pNd ));
[ + - ]
780 : : // is the position still in the area
781 [ + - ][ + - ]: 422 : if( (aPos.*fnMove->fnCmpOp)( *rPam.GetMark() ) )
[ + + ]
782 : : {
783 : : // only in AutoTextSection can be nodes that are hidden
784 [ + - ][ + - ]: 1388 : if( 0 == ( pFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout() ) ) ||
[ + - ][ + + ]
[ + - + + ]
[ - + ][ - + ]
785 [ + - ]: 160 : ( !bInReadOnly && pFrm->IsProtected() ) ||
786 : 412 : ( pFrm->IsTxtFrm() &&
787 [ + - ]: 404 : ((SwTxtFrm*)pFrm)->IsHiddenNow() ) )
788 : : {
789 : 0 : pNd = 0;
790 : 0 : continue;
791 : : }
792 [ + - ]: 412 : *(SwPosition*)rPam.GetPoint() = aPos;
793 : : }
794 : : else
795 : 10 : pNd = 0; // no valid node
796 : 422 : break;
797 : : }
798 : 0 : break;
799 [ + - ]: 422 : }
800 : : }
801 : : }
802 : 604 : return pNd;
803 : : }
804 : :
805 : :
806 : 10844 : void GoStartDoc( SwPosition * pPos )
807 : : {
808 : 10844 : SwNodes& rNodes = pPos->nNode.GetNodes();
809 : 10844 : pPos->nNode = *rNodes.GetEndOfContent().StartOfSectionNode();
810 : : // we always need to find a ContentNode!
811 : 10844 : SwCntntNode* pCNd = rNodes.GoNext( &pPos->nNode );
812 [ + - ]: 10844 : if( pCNd )
813 : 10844 : pCNd->MakeStartIndex( &pPos->nContent );
814 : 10844 : }
815 : :
816 : :
817 : 4086 : void GoEndDoc( SwPosition * pPos )
818 : : {
819 : 4086 : SwNodes& rNodes = pPos->nNode.GetNodes();
820 : 4086 : pPos->nNode = rNodes.GetEndOfContent();
821 : 4086 : SwCntntNode* pCNd = GoPreviousNds( &pPos->nNode, sal_True );
822 [ + - ]: 4086 : if( pCNd )
823 : 4086 : pCNd->MakeEndIndex( &pPos->nContent );
824 : 4086 : }
825 : :
826 : :
827 : 0 : void GoStartSection( SwPosition * pPos )
828 : : {
829 : : // jump to section's beginning
830 : 0 : SwNodes& rNodes = pPos->nNode.GetNodes();
831 : 0 : sal_uInt16 nLevel = rNodes.GetSectionLevel( pPos->nNode );
832 [ # # ]: 0 : if( pPos->nNode < rNodes.GetEndOfContent().StartOfSectionIndex() )
833 : 0 : nLevel--;
834 [ # # ]: 0 : do { rNodes.GoStartOfSection( &pPos->nNode ); } while( nLevel-- );
835 : :
836 : : // already on a CntntNode
837 : 0 : pPos->nNode.GetNode().GetCntntNode()->MakeStartIndex( &pPos->nContent );
838 : 0 : }
839 : :
840 : : /// go to the end of the current base section
841 : 0 : void GoEndSection( SwPosition * pPos )
842 : : {
843 : : // jump to section's beginning/end
844 : 0 : SwNodes& rNodes = pPos->nNode.GetNodes();
845 : 0 : sal_uInt16 nLevel = rNodes.GetSectionLevel( pPos->nNode );
846 [ # # ]: 0 : if( pPos->nNode < rNodes.GetEndOfContent().StartOfSectionIndex() )
847 : 0 : nLevel--;
848 [ # # ]: 0 : do { rNodes.GoEndOfSection( &pPos->nNode ); } while( nLevel-- );
849 : :
850 : : // now on a EndNode, thus to the previous CntntNode
851 [ # # ]: 0 : if( GoPreviousNds( &pPos->nNode, sal_True ) )
852 : 0 : pPos->nNode.GetNode().GetCntntNode()->MakeEndIndex( &pPos->nContent );
853 : 0 : }
854 : :
855 : :
856 : :
857 : 14930 : sal_Bool GoInDoc( SwPaM & rPam, SwMoveFn fnMove )
858 : : {
859 : 14930 : (*fnMove->fnDoc)( rPam.GetPoint() );
860 : 14930 : return sal_True;
861 : : }
862 : :
863 : :
864 : 0 : sal_Bool GoInSection( SwPaM & rPam, SwMoveFn fnMove )
865 : : {
866 : 0 : (*fnMove->fnSections)( (SwPosition*)rPam.GetPoint() );
867 : 0 : return sal_True;
868 : : }
869 : :
870 : :
871 : 49074 : sal_Bool GoInNode( SwPaM & rPam, SwMoveFn fnMove )
872 : : {
873 : 49074 : SwCntntNode *pNd = (*fnMove->fnNds)( &rPam.GetPoint()->nNode, sal_True );
874 [ + + ]: 49074 : if( pNd )
875 : 45680 : rPam.GetPoint()->nContent.Assign( pNd,
876 [ + - ]: 91360 : ::GetSttOrEnd( fnMove == fnMoveForward, *pNd ) );
877 : 49074 : return 0 != pNd;
878 : : }
879 : :
880 : :
881 : 165497 : sal_Bool GoInCntnt( SwPaM & rPam, SwMoveFn fnMove )
882 : : {
883 [ + + ]: 330994 : if( (*fnMove->fnNd)( &rPam.GetPoint()->nNode.GetNode(),
884 : 330994 : &rPam.GetPoint()->nContent, CRSR_SKIP_CHARS ))
885 : 161686 : return sal_True;
886 : 165497 : return GoInNode( rPam, fnMove );
887 : : }
888 : :
889 : 0 : sal_Bool GoInCntntCells( SwPaM & rPam, SwMoveFn fnMove )
890 : : {
891 [ # # ]: 0 : if( (*fnMove->fnNd)( &rPam.GetPoint()->nNode.GetNode(),
892 : 0 : &rPam.GetPoint()->nContent, CRSR_SKIP_CELLS ))
893 : 0 : return sal_True;
894 : 0 : return GoInNode( rPam, fnMove );
895 : : }
896 : :
897 : 34 : sal_Bool GoInCntntSkipHidden( SwPaM & rPam, SwMoveFn fnMove )
898 : : {
899 [ + + ]: 68 : if( (*fnMove->fnNd)( &rPam.GetPoint()->nNode.GetNode(),
900 : 68 : &rPam.GetPoint()->nContent, CRSR_SKIP_CHARS | CRSR_SKIP_HIDDEN ) )
901 : 30 : return sal_True;
902 : 34 : return GoInNode( rPam, fnMove );
903 : : }
904 : :
905 : 0 : sal_Bool GoInCntntCellsSkipHidden( SwPaM & rPam, SwMoveFn fnMove )
906 : : {
907 [ # # ]: 0 : if( (*fnMove->fnNd)( &rPam.GetPoint()->nNode.GetNode(),
908 : 0 : &rPam.GetPoint()->nContent, CRSR_SKIP_CELLS | CRSR_SKIP_HIDDEN ) )
909 : 0 : return sal_True;
910 : 0 : return GoInNode( rPam, fnMove );
911 : : }
912 : :
913 : :
914 : :
915 : :
916 : :
917 : 16 : sal_Bool GoPrevPara( SwPaM & rPam, SwPosPara aPosPara )
918 : : {
919 [ + - ]: 16 : if( rPam.Move( fnMoveBackward, fnGoNode ) )
920 : : {
921 : : // always on a CntntNode
922 : 16 : SwPosition& rPos = *rPam.GetPoint();
923 : 16 : SwCntntNode * pNd = rPos.nNode.GetNode().GetCntntNode();
924 : : rPos.nContent.Assign( pNd,
925 [ + - ]: 16 : ::GetSttOrEnd( aPosPara == fnMoveForward, *pNd ) );
926 : 16 : return sal_True;
927 : : }
928 : 16 : return sal_False;
929 : : }
930 : :
931 : :
932 : 4844 : sal_Bool GoCurrPara( SwPaM & rPam, SwPosPara aPosPara )
933 : : {
934 : 4844 : SwPosition& rPos = *rPam.GetPoint();
935 : 4844 : SwCntntNode * pNd = rPos.nNode.GetNode().GetCntntNode();
936 [ + - ]: 4844 : if( pNd )
937 : : {
938 : 4844 : xub_StrLen nOld = rPos.nContent.GetIndex(),
939 [ + + ]: 4844 : nNew = aPosPara == fnMoveForward ? 0 : pNd->Len();
940 : : // if already at beginning/end then to the next/previous
941 [ + + ]: 4844 : if( nOld != nNew )
942 : : {
943 [ + - ]: 2878 : rPos.nContent.Assign( pNd, nNew );
944 : 2878 : return sal_True;
945 : : }
946 : : }
947 : : // move node to next/previous CntntNode
948 [ - + ][ # # ]: 1966 : if( ( aPosPara==fnParaStart && 0 != ( pNd =
[ + - ][ - + ]
[ - + ]
949 : 0 : GoPreviousNds( &rPos.nNode, sal_True ))) ||
950 : : ( aPosPara==fnParaEnd && 0 != ( pNd =
951 : 1966 : GoNextNds( &rPos.nNode, sal_True ))) )
952 : : {
953 : : rPos.nContent.Assign( pNd,
954 [ # # ]: 0 : ::GetSttOrEnd( aPosPara == fnMoveForward, *pNd ));
955 : 0 : return sal_True;
956 : : }
957 : 4844 : return sal_False;
958 : : }
959 : :
960 : :
961 : 2962 : sal_Bool GoNextPara( SwPaM & rPam, SwPosPara aPosPara )
962 : : {
963 [ + + ]: 2962 : if( rPam.Move( fnMoveForward, fnGoNode ) )
964 : : {
965 : : // always on a CntntNode
966 : 2356 : SwPosition& rPos = *rPam.GetPoint();
967 : 2356 : SwCntntNode * pNd = rPos.nNode.GetNode().GetCntntNode();
968 : : rPos.nContent.Assign( pNd,
969 [ + - ]: 2356 : ::GetSttOrEnd( aPosPara == fnMoveForward, *pNd ) );
970 : 2356 : return sal_True;
971 : : }
972 : 2962 : return sal_False;
973 : : }
974 : :
975 : :
976 : :
977 : 971 : sal_Bool GoCurrSection( SwPaM & rPam, SwMoveFn fnMove )
978 : : {
979 : 971 : SwPosition& rPos = *rPam.GetPoint();
980 [ + - ]: 971 : SwPosition aSavePos( rPos ); // position for comparison
981 : 971 : SwNodes& rNds = aSavePos.nNode.GetNodes();
982 [ + - ][ + - ]: 971 : (rNds.*fnMove->fnSection)( &rPos.nNode );
983 : : SwCntntNode *pNd;
984 [ + + ][ + - ]: 971 : if( 0 == ( pNd = rPos.nNode.GetNode().GetCntntNode()) &&
[ - + ][ - + ]
985 : 930 : 0 == ( pNd = (*fnMove->fnNds)( &rPos.nNode, sal_True )) )
986 : : {
987 [ # # ]: 0 : rPos = aSavePos; // do not change cursor
988 : 0 : return sal_False;
989 : : }
990 : :
991 : : rPos.nContent.Assign( pNd,
992 [ + - ][ + - ]: 971 : ::GetSttOrEnd( fnMove == fnMoveForward, *pNd ) );
[ + - ]
993 [ + - ][ + - ]: 971 : return aSavePos != rPos;
994 : : }
995 : :
996 : :
997 : 0 : sal_Bool GoNextSection( SwPaM & rPam, SwMoveFn fnMove )
998 : : {
999 : 0 : SwPosition& rPos = *rPam.GetPoint();
1000 [ # # ]: 0 : SwPosition aSavePos( rPos ); // position for comparison
1001 : 0 : SwNodes& rNds = aSavePos.nNode.GetNodes();
1002 [ # # ]: 0 : rNds.GoEndOfSection( &rPos.nNode );
1003 : :
1004 : : // no other CntntNode existent?
1005 [ # # ][ # # ]: 0 : if( !GoInCntnt( rPam, fnMoveForward ) )
1006 : : {
1007 [ # # ]: 0 : rPos = aSavePos; // do not change cursor
1008 : 0 : return sal_False;
1009 : : }
1010 [ # # ][ # # ]: 0 : (rNds.*fnMove->fnSection)( &rPos.nNode );
1011 : 0 : SwCntntNode *pNd = rPos.nNode.GetNode().GetCntntNode();
1012 : : rPos.nContent.Assign( pNd,
1013 [ # # ][ # # ]: 0 : ::GetSttOrEnd( fnMove == fnMoveForward, *pNd ) );
[ # # ]
1014 [ # # ]: 0 : return sal_True;
1015 : : }
1016 : :
1017 : :
1018 : 0 : sal_Bool GoPrevSection( SwPaM & rPam, SwMoveFn fnMove )
1019 : : {
1020 : 0 : SwPosition& rPos = *rPam.GetPoint();
1021 [ # # ]: 0 : SwPosition aSavePos( rPos ); // position for comparison
1022 : 0 : SwNodes& rNds = aSavePos.nNode.GetNodes();
1023 [ # # ]: 0 : rNds.GoStartOfSection( &rPos.nNode );
1024 : :
1025 : : // no further CntntNode existent?
1026 [ # # ][ # # ]: 0 : if( !GoInCntnt( rPam, fnMoveBackward ))
1027 : : {
1028 [ # # ]: 0 : rPos = aSavePos; // do not change cursor
1029 : 0 : return sal_False;
1030 : : }
1031 [ # # ][ # # ]: 0 : (rNds.*fnMove->fnSection)( &rPos.nNode );
1032 : 0 : SwCntntNode *pNd = rPos.nNode.GetNode().GetCntntNode();
1033 : : rPos.nContent.Assign( pNd,
1034 [ # # ][ # # ]: 0 : ::GetSttOrEnd( fnMove == fnMoveForward, *pNd ));
[ # # ]
1035 [ # # ]: 0 : return sal_True;
1036 : : }
1037 : :
1038 : 0 : String SwPaM::GetTxt() const
1039 : : {
1040 [ # # ]: 0 : String aResult;
1041 : :
1042 [ # # ][ # # ]: 0 : SwNodeIndex aNodeIndex = Start()->nNode;
1043 : :
1044 : : // The first node can be already the end node.
1045 : : // A first end node must be handled, too. Therefore do-while and no
1046 : : // incrementing of aNodeIndex in the first pass.
1047 : 0 : bool bFirst = true;
1048 [ # # ]: 0 : do
1049 : : {
1050 [ # # ]: 0 : if (! bFirst)
1051 : : {
1052 [ # # ]: 0 : aNodeIndex++;
1053 : : }
1054 : :
1055 : 0 : bFirst = false;
1056 : :
1057 : 0 : SwTxtNode * pTxtNode = aNodeIndex.GetNode().GetTxtNode();
1058 : :
1059 [ # # ]: 0 : if (pTxtNode != NULL)
1060 : : {
1061 : 0 : const String & aTmpStr = pTxtNode->GetTxt();
1062 : :
1063 [ # # ][ # # ]: 0 : if (aNodeIndex == Start()->nNode)
1064 : : {
1065 : : xub_StrLen nEnd;
1066 [ # # ][ # # ]: 0 : if (End()->nNode == aNodeIndex)
1067 [ # # ]: 0 : nEnd = End()->nContent.GetIndex();
1068 : : else
1069 : 0 : nEnd = aTmpStr.Len();
1070 : :
1071 [ # # ]: 0 : aResult += aTmpStr.Copy(Start()->nContent.GetIndex(),
1072 [ # # ][ # # ]: 0 : nEnd - Start()->nContent.GetIndex()) ;
[ # # ][ # # ]
1073 : : }
1074 [ # # ][ # # ]: 0 : else if (aNodeIndex == End()->nNode)
1075 [ # # ][ # # ]: 0 : aResult += aTmpStr.Copy(0, End()->nContent.GetIndex());
[ # # ][ # # ]
1076 : : else
1077 [ # # ]: 0 : aResult += aTmpStr;
1078 : : }
1079 : : }
1080 [ # # ]: 0 : while (aNodeIndex != End()->nNode);
1081 : :
1082 [ # # ]: 0 : return aResult;
1083 : : }
1084 : :
1085 : 0 : void SwPaM::InvalidatePaM()
1086 : : {
1087 : 0 : const SwNode *_pNd=this->GetNode();
1088 [ # # ]: 0 : const SwTxtNode *_pTxtNd=(_pNd!=NULL?_pNd->GetTxtNode():NULL);
1089 [ # # ]: 0 : if (_pTxtNd!=NULL)
1090 : : {
1091 : : // pretent that the PaM marks inserted text to recalc the portion...
1092 [ # # ]: 0 : SwInsTxt aHint( Start()->nContent.GetIndex(),
1093 [ # # ][ # # ]: 0 : End()->nContent.GetIndex() - Start()->nContent.GetIndex() + 1 );
[ # # ]
1094 : 0 : SwModify *_pModify=(SwModify*)_pTxtNd;
1095 [ # # ][ # # ]: 0 : _pModify->ModifyNotification( 0, &aHint);
1096 : : }
1097 : 0 : }
1098 : :
1099 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|