Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sw / source / core / crsr / crstrvl.cxx
blob5229fc97728eefd58b1d3c1298c91f360e4068b1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <hintids.hxx>
21 #include <comphelper/string.hxx>
22 #include <svl/itemiter.hxx>
23 #include <editeng/lrspitem.hxx>
24 #include <editeng/adjitem.hxx>
25 #include <editeng/brkitem.hxx>
26 #include <svx/svdobj.hxx>
27 #include <crsrsh.hxx>
28 #include <doc.hxx>
29 #include <IDocumentUndoRedo.hxx>
30 #include <pagefrm.hxx>
31 #include <cntfrm.hxx>
32 #include <rootfrm.hxx>
33 #include <pam.hxx>
34 #include <ndtxt.hxx>
35 #include <fldbas.hxx>
36 #include <swtable.hxx>
37 #include <docary.hxx>
38 #include <txtfld.hxx>
39 #include <fmtfld.hxx>
40 #include <txtftn.hxx>
41 #include <txtinet.hxx>
42 #include <fmtinfmt.hxx>
43 #include <txttxmrk.hxx>
44 #include <frmfmt.hxx>
45 #include <flyfrm.hxx>
46 #include <viscrs.hxx>
47 #include <callnk.hxx>
48 #include <doctxm.hxx>
49 #include <docfld.hxx>
50 #include <expfld.hxx>
51 #include <reffld.hxx>
52 #include <flddat.hxx>
53 #include <cellatr.hxx>
54 #include <swundo.hxx>
55 #include <redline.hxx>
56 #include <fmtcntnt.hxx>
57 #include <fmthdft.hxx>
58 #include <pagedesc.hxx>
59 #include <fesh.hxx>
60 #include <charfmt.hxx>
61 #include <fmturl.hxx>
62 #include "txtfrm.hxx"
63 #include <wrong.hxx>
64 #include <switerator.hxx>
65 #include <vcl/window.hxx>
66 #include <docufld.hxx>
68 using namespace ::com::sun::star;
70 /// go to next/previous point on the same level
71 bool SwCrsrShell::GotoNextNum()
73 bool bRet = GetDoc()->GotoNextNum( *pCurCrsr->GetPoint() );
74 if( bRet )
76 SwCallLink aLk( *this ); // watch Crsr-Moves
77 SwCrsrSaveState aSaveState( *pCurCrsr );
78 if( !ActionPend() )
80 SET_CURR_SHELL( this );
81 // try to set cursor onto this position, at half of the char-
82 // SRectangle's height
83 Point aPt( pCurCrsr->GetPtPos() );
84 SwCntntFrm * pFrm = pCurCrsr->GetCntntNode()->getLayoutFrm( GetLayout(), &aPt,
85 pCurCrsr->GetPoint() );
86 pFrm->GetCharRect( aCharRect, *pCurCrsr->GetPoint() );
87 pFrm->Calc();
88 if( pFrm->IsVertical() )
90 aPt.X() = aCharRect.Center().X();
91 aPt.Y() = pFrm->Frm().Top() + nUpDownX;
93 else
95 aPt.Y() = aCharRect.Center().Y();
96 aPt.X() = pFrm->Frm().Left() + nUpDownX;
98 pFrm->GetCrsrOfst( pCurCrsr->GetPoint(), aPt );
99 bRet = !pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
100 nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
101 if( bRet )
102 UpdateCrsr(SwCrsrShell::UPDOWN |
103 SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
104 SwCrsrShell::READONLY );
107 return bRet;
111 bool SwCrsrShell::GotoPrevNum()
113 bool bRet = GetDoc()->GotoPrevNum( *pCurCrsr->GetPoint() );
114 if( bRet )
116 SwCallLink aLk( *this ); // watch Crsr-Moves
117 SwCrsrSaveState aSaveState( *pCurCrsr );
118 if( !ActionPend() )
120 SET_CURR_SHELL( this );
121 // try to set cursor onto this position, at half of the char-
122 // SRectangle's height
123 Point aPt( pCurCrsr->GetPtPos() );
124 SwCntntFrm * pFrm = pCurCrsr->GetCntntNode()->getLayoutFrm( GetLayout(), &aPt,
125 pCurCrsr->GetPoint() );
126 pFrm->GetCharRect( aCharRect, *pCurCrsr->GetPoint() );
127 pFrm->Calc();
128 if( pFrm->IsVertical() )
130 aPt.X() = aCharRect.Center().X();
131 aPt.Y() = pFrm->Frm().Top() + nUpDownX;
133 else
135 aPt.Y() = aCharRect.Center().Y();
136 aPt.X() = pFrm->Frm().Left() + nUpDownX;
138 pFrm->GetCrsrOfst( pCurCrsr->GetPoint(), aPt );
139 bRet = !pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
140 nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
141 if( bRet )
142 UpdateCrsr(SwCrsrShell::UPDOWN |
143 SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
144 SwCrsrShell::READONLY );
147 return bRet;
150 /// jump from content to header
151 sal_Bool SwCrsrShell::GotoHeaderTxt()
153 const SwFrm* pFrm = GetCurrFrm()->FindPageFrm();
154 while( pFrm && !pFrm->IsHeaderFrm() )
155 pFrm = pFrm->GetLower();
156 // found header, search 1. content frame
157 while( pFrm && !pFrm->IsCntntFrm() )
158 pFrm = pFrm->GetLower();
159 if( pFrm )
161 SET_CURR_SHELL( this );
162 // get header frame
163 SwCallLink aLk( *this ); // watch Crsr-Moves
164 SwCursor *pTmpCrsr = getShellCrsr( true );
165 SwCrsrSaveState aSaveState( *pTmpCrsr );
166 pFrm->Calc();
167 Point aPt( pFrm->Frm().Pos() + pFrm->Prt().Pos() );
168 pFrm->GetCrsrOfst( pTmpCrsr->GetPoint(), aPt );
169 if( !pTmpCrsr->IsSelOvr() )
170 UpdateCrsr();
171 else
172 pFrm = 0;
174 return 0 != pFrm;
177 /// jump from content to footer
178 sal_Bool SwCrsrShell::GotoFooterTxt()
180 const SwPageFrm* pFrm = GetCurrFrm()->FindPageFrm();
181 if( pFrm )
183 const SwFrm* pLower = pFrm->GetLastLower();
185 while( pLower && !pLower->IsFooterFrm() )
186 pLower = pLower->GetLower();
187 // found footer, search 1. content frame
188 while( pLower && !pLower->IsCntntFrm() )
189 pLower = pLower->GetLower();
191 if( pLower )
193 SwCursor *pTmpCrsr = getShellCrsr( true );
194 SET_CURR_SHELL( this );
195 // get position in footer
196 SwCallLink aLk( *this ); // watch Crsr-Moves
197 SwCrsrSaveState aSaveState( *pTmpCrsr );
198 pLower->Calc();
199 Point aPt( pLower->Frm().Pos() + pLower->Prt().Pos() );
200 pLower->GetCrsrOfst( pTmpCrsr->GetPoint(), aPt );
201 if( !pTmpCrsr->IsSelOvr() )
202 UpdateCrsr();
203 else
204 pFrm = 0;
206 else
207 pFrm = 0;
209 else
210 pFrm = 0;
211 return 0 != pFrm;
214 sal_Bool SwCrsrShell::SetCrsrInHdFt( sal_uInt16 nDescNo, sal_Bool bInHeader )
216 sal_Bool bRet = sal_False;
217 SwDoc *pMyDoc = GetDoc();
219 SET_CURR_SHELL( this );
221 if( USHRT_MAX == nDescNo )
223 // take the current one
224 const SwPageFrm* pPage = GetCurrFrm()->FindPageFrm();
225 if( pPage )
226 for( sal_uInt16 i = 0; i < pMyDoc->GetPageDescCnt(); ++i )
227 if( pPage->GetPageDesc() == &pMyDoc->GetPageDesc( i ) )
229 nDescNo = i;
230 break;
234 if( USHRT_MAX != nDescNo && nDescNo < pMyDoc->GetPageDescCnt() )
236 // check if the attribute exists
237 const SwPageDesc& rDesc = const_cast<const SwDoc *>(pMyDoc)
238 ->GetPageDesc( nDescNo );
239 const SwFmtCntnt* pCnt = 0;
240 if( bInHeader )
242 // mirrored pages? ignore for now
243 const SwFmtHeader& rHd = rDesc.GetMaster().GetHeader();
244 if( rHd.GetHeaderFmt() )
245 pCnt = &rHd.GetHeaderFmt()->GetCntnt();
247 else
249 const SwFmtFooter& rFt = rDesc.GetMaster().GetFooter();
250 if( rFt.GetFooterFmt() )
251 pCnt = &rFt.GetFooterFmt()->GetCntnt();
254 if( pCnt && pCnt->GetCntntIdx() )
256 SwNodeIndex aIdx( *pCnt->GetCntntIdx(), 1 );
257 SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
258 if( !pCNd )
259 pCNd = pMyDoc->GetNodes().GoNext( &aIdx );
261 const SwFrm* pFrm;
262 Point aPt( pCurCrsr->GetPtPos() );
264 if( pCNd && 0 != ( pFrm = pCNd->getLayoutFrm( GetLayout(), &aPt, 0, sal_False ) ))
266 // then we can set the cursor in here
267 SwCallLink aLk( *this ); // watch Crsr-Moves
268 SwCrsrSaveState aSaveState( *pCurCrsr );
270 ClearMark();
272 SwPosition& rPos = *pCurCrsr->GetPoint();
273 rPos.nNode = *pCNd;
274 rPos.nContent.Assign( pCNd, 0 );
276 bRet = !pCurCrsr->IsSelOvr();
277 if( bRet )
278 UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
279 SwCrsrShell::READONLY );
283 return bRet;
286 /// jump to the next index
287 sal_Bool SwCrsrShell::GotoNextTOXBase( const String* pName )
289 sal_Bool bRet = sal_False;
291 const SwSectionFmts& rFmts = GetDoc()->GetSections();
292 SwCntntNode* pFnd = 0;
293 for( sal_uInt16 n = rFmts.size(); n; )
295 const SwSection* pSect = rFmts[ --n ]->GetSection();
296 const SwSectionNode* pSectNd;
297 if( TOX_CONTENT_SECTION == pSect->GetType() &&
298 0 != ( pSectNd = pSect->GetFmt()->GetSectionNode() ) &&
299 pCurCrsr->GetPoint()->nNode < pSectNd->GetIndex() &&
300 ( !pFnd || pFnd->GetIndex() > pSectNd->GetIndex() ) &&
301 ( !pName || *pName == ((SwTOXBaseSection*)pSect)->GetTOXName() )
304 SwNodeIndex aIdx( *pSectNd, 1 );
305 SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
306 if( !pCNd )
307 pCNd = GetDoc()->GetNodes().GoNext( &aIdx );
308 const SwCntntFrm* pCFrm;
309 if( pCNd &&
310 pCNd->EndOfSectionIndex() <= pSectNd->EndOfSectionIndex() &&
311 0 != ( pCFrm = pCNd->getLayoutFrm( GetLayout() ) ) &&
312 ( IsReadOnlyAvailable() || !pCFrm->IsProtected() ))
314 pFnd = pCNd;
318 if( pFnd )
320 SwCallLink aLk( *this ); // watch Crsr-Moves
321 SwCrsrSaveState aSaveState( *pCurCrsr );
322 pCurCrsr->GetPoint()->nNode = *pFnd;
323 pCurCrsr->GetPoint()->nContent.Assign( pFnd, 0 );
324 bRet = !pCurCrsr->IsSelOvr();
325 if( bRet )
326 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
328 return bRet;
331 /// jump to previous index
332 sal_Bool SwCrsrShell::GotoPrevTOXBase( const String* pName )
334 sal_Bool bRet = sal_False;
336 const SwSectionFmts& rFmts = GetDoc()->GetSections();
337 SwCntntNode* pFnd = 0;
338 for( sal_uInt16 n = rFmts.size(); n; )
340 const SwSection* pSect = rFmts[ --n ]->GetSection();
341 const SwSectionNode* pSectNd;
342 if( TOX_CONTENT_SECTION == pSect->GetType() &&
343 0 != ( pSectNd = pSect->GetFmt()->GetSectionNode() ) &&
344 pCurCrsr->GetPoint()->nNode > pSectNd->EndOfSectionIndex() &&
345 ( !pFnd || pFnd->GetIndex() < pSectNd->GetIndex() ) &&
346 ( !pName || *pName == ((SwTOXBaseSection*)pSect)->GetTOXName() )
349 SwNodeIndex aIdx( *pSectNd, 1 );
350 SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
351 if( !pCNd )
352 pCNd = GetDoc()->GetNodes().GoNext( &aIdx );
353 const SwCntntFrm* pCFrm;
354 if( pCNd &&
355 pCNd->EndOfSectionIndex() <= pSectNd->EndOfSectionIndex() &&
356 0 != ( pCFrm = pCNd->getLayoutFrm( GetLayout() ) ) &&
357 ( IsReadOnlyAvailable() || !pCFrm->IsProtected() ))
359 pFnd = pCNd;
364 if( pFnd )
366 SwCallLink aLk( *this ); // watch Crsr-Moves
367 SwCrsrSaveState aSaveState( *pCurCrsr );
368 pCurCrsr->GetPoint()->nNode = *pFnd;
369 pCurCrsr->GetPoint()->nContent.Assign( pFnd, 0 );
370 bRet = !pCurCrsr->IsSelOvr();
371 if( bRet )
372 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
374 return bRet;
377 /// jump to index of TOXMark
378 sal_Bool SwCrsrShell::GotoTOXMarkBase()
380 sal_Bool bRet = sal_False;
382 SwTOXMarks aMarks;
383 sal_uInt16 nCnt = GetDoc()->GetCurTOXMark( *pCurCrsr->GetPoint(), aMarks );
384 if( nCnt )
386 // Take the 1. and get the index type. Search in its dependency list
387 // for the actual index
388 const SwTOXType* pType = aMarks[0]->GetTOXType();
389 SwIterator<SwTOXBase,SwTOXType> aIter( *pType );
390 const SwSectionNode* pSectNd;
391 const SwSectionFmt* pSectFmt;
393 for( SwTOXBase* pTOX = aIter.First(); pTOX; pTOX = aIter.Next() )
395 if( pTOX->ISA( SwTOXBaseSection ) &&
396 0 != ( pSectFmt = ((SwTOXBaseSection*)pTOX)->GetFmt() ) &&
397 0 != ( pSectNd = pSectFmt->GetSectionNode() ))
399 SwNodeIndex aIdx( *pSectNd, 1 );
400 SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
401 if( !pCNd )
402 pCNd = GetDoc()->GetNodes().GoNext( &aIdx );
403 const SwCntntFrm* pCFrm;
404 if( pCNd &&
405 pCNd->EndOfSectionIndex() < pSectNd->EndOfSectionIndex() &&
406 0 != ( pCFrm = pCNd->getLayoutFrm( GetLayout() ) ) &&
407 ( IsReadOnlyAvailable() || !pCFrm->IsProtected() ))
409 SwCallLink aLk( *this ); // watch Crsr-Moves
410 SwCrsrSaveState aSaveState( *pCurCrsr );
411 pCurCrsr->GetPoint()->nNode = *pCNd;
412 pCurCrsr->GetPoint()->nContent.Assign( pCNd, 0 );
413 bRet = !pCurCrsr->IsInProtectTable() &&
414 !pCurCrsr->IsSelOvr();
415 if( bRet )
416 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
417 break;
422 return bRet;
425 /// Jump to next/previous table formula
426 /// Optionally it is possible to also jump to broken formulas
427 sal_Bool SwCrsrShell::GotoNxtPrvTblFormula( sal_Bool bNext, sal_Bool bOnlyErrors )
429 if( IsTableMode() )
430 return sal_False;
432 sal_Bool bFnd = sal_False;
433 SwPosition& rPos = *pCurCrsr->GetPoint();
435 Point aPt;
436 SwPosition aFndPos( GetDoc()->GetNodes().GetEndOfContent() );
437 if( !bNext )
438 aFndPos.nNode = 0;
439 _SetGetExpFld aFndGEF( aFndPos ), aCurGEF( rPos );
442 const SwNode* pSttNd = rPos.nNode.GetNode().FindTableBoxStartNode();
443 if( pSttNd )
445 const SwTableBox* pTBox = pSttNd->FindTableNode()->GetTable().
446 GetTblBox( pSttNd->GetIndex() );
447 if( pTBox )
448 aCurGEF = _SetGetExpFld( *pTBox );
452 if( rPos.nNode < GetDoc()->GetNodes().GetEndOfExtras() )
453 // also at collection use only the first frame
454 aCurGEF.SetBodyPos( *rPos.nNode.GetNode().GetCntntNode()->getLayoutFrm( GetLayout(),
455 &aPt, &rPos, sal_False ) );
457 const SfxPoolItem* pItem;
458 const SwTableBox* pTBox;
459 sal_uInt32 n, nMaxItems = GetDoc()->GetAttrPool().GetItemCount2( RES_BOXATR_FORMULA );
461 for( n = 0; n < nMaxItems; ++n )
462 if( 0 != (pItem = GetDoc()->GetAttrPool().GetItem2(
463 RES_BOXATR_FORMULA, n ) ) &&
464 0 != (pTBox = ((SwTblBoxFormula*)pItem)->GetTableBox() ) &&
465 pTBox->GetSttNd() &&
466 pTBox->GetSttNd()->GetNodes().IsDocNodes() &&
467 ( !bOnlyErrors ||
468 !((SwTblBoxFormula*)pItem)->HasValidBoxes() ) )
470 const SwCntntFrm* pCFrm;
471 SwNodeIndex aIdx( *pTBox->GetSttNd() );
472 const SwCntntNode* pCNd = GetDoc()->GetNodes().GoNext( &aIdx );
473 if( pCNd && 0 != ( pCFrm = pCNd->getLayoutFrm( GetLayout(), &aPt, 0, sal_False ) ) &&
474 (IsReadOnlyAvailable() || !pCFrm->IsProtected() ))
476 _SetGetExpFld aCmp( *pTBox );
477 aCmp.SetBodyPos( *pCFrm );
479 if( bNext ? ( aCurGEF < aCmp && aCmp < aFndGEF )
480 : ( aCmp < aCurGEF && aFndGEF < aCmp ))
482 aFndGEF = aCmp;
483 bFnd = sal_True;
489 if( bFnd )
491 SET_CURR_SHELL( this );
492 SwCallLink aLk( *this ); // watch Crsr-Moves
493 SwCrsrSaveState aSaveState( *pCurCrsr );
495 aFndGEF.GetPosOfContent( rPos );
496 pCurCrsr->DeleteMark();
498 bFnd = !pCurCrsr->IsSelOvr();
499 if( bFnd )
500 UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
501 SwCrsrShell::READONLY );
503 return bFnd;
506 /// jump to next/previous index marker
507 sal_Bool SwCrsrShell::GotoNxtPrvTOXMark( sal_Bool bNext )
509 if( IsTableMode() )
510 return sal_False;
512 sal_Bool bFnd = sal_False;
513 SwPosition& rPos = *pCurCrsr->GetPoint();
515 Point aPt;
516 SwPosition aFndPos( GetDoc()->GetNodes().GetEndOfContent() );
517 if( !bNext )
518 aFndPos.nNode = 0;
519 _SetGetExpFld aFndGEF( aFndPos ), aCurGEF( rPos );
521 if( rPos.nNode.GetIndex() < GetDoc()->GetNodes().GetEndOfExtras().GetIndex() )
522 // also at collection use only the first frame
523 aCurGEF.SetBodyPos( *rPos.nNode.GetNode().
524 GetCntntNode()->getLayoutFrm( GetLayout(), &aPt, &rPos, sal_False ) );
526 const SfxPoolItem* pItem;
527 const SwCntntFrm* pCFrm;
528 const SwTxtNode* pTxtNd;
529 const SwTxtTOXMark* pTxtTOX;
530 sal_uInt32 n, nMaxItems = GetDoc()->GetAttrPool().GetItemCount2( RES_TXTATR_TOXMARK );
532 for( n = 0; n < nMaxItems; ++n )
533 if( 0 != (pItem = GetDoc()->GetAttrPool().GetItem2(
534 RES_TXTATR_TOXMARK, n ) ) &&
535 0 != (pTxtTOX = ((SwTOXMark*)pItem)->GetTxtTOXMark() ) &&
536 ( pTxtNd = &pTxtTOX->GetTxtNode())->GetNodes().IsDocNodes() &&
537 0 != ( pCFrm = pTxtNd->getLayoutFrm( GetLayout(), &aPt, 0, sal_False )) &&
538 ( IsReadOnlyAvailable() || !pCFrm->IsProtected() ))
540 SwNodeIndex aNdIndex( *pTxtNd ); // UNIX needs this object
541 _SetGetExpFld aCmp( aNdIndex, *pTxtTOX, 0 );
542 aCmp.SetBodyPos( *pCFrm );
544 if( bNext ? ( aCurGEF < aCmp && aCmp < aFndGEF )
545 : ( aCmp < aCurGEF && aFndGEF < aCmp ))
547 aFndGEF = aCmp;
548 bFnd = sal_True;
553 if( bFnd )
555 SET_CURR_SHELL( this );
556 SwCallLink aLk( *this ); // watch Crsr-Moves
557 SwCrsrSaveState aSaveState( *pCurCrsr );
559 aFndGEF.GetPosOfContent( rPos );
561 bFnd = !pCurCrsr->IsSelOvr();
562 if( bFnd )
563 UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
564 SwCrsrShell::READONLY );
566 return bFnd;
569 /// traveling between marks
570 const SwTOXMark& SwCrsrShell::GotoTOXMark( const SwTOXMark& rStart,
571 SwTOXSearch eDir )
573 SET_CURR_SHELL( this );
574 SwCallLink aLk( *this ); // watch Crsr-Moves
575 SwCrsrSaveState aSaveState( *pCurCrsr );
577 const SwTOXMark& rNewMark = GetDoc()->GotoTOXMark( rStart, eDir,
578 IsReadOnlyAvailable() );
579 // set position
580 SwPosition& rPos = *GetCrsr()->GetPoint();
581 rPos.nNode = rNewMark.GetTxtTOXMark()->GetTxtNode();
582 rPos.nContent.Assign( rPos.nNode.GetNode().GetCntntNode(),
583 *rNewMark.GetTxtTOXMark()->GetStart() );
585 if( !pCurCrsr->IsSelOvr() )
586 UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
587 SwCrsrShell::READONLY );
589 return rNewMark;
592 /// jump to next/previous field type
593 static void lcl_MakeFldLst( _SetGetExpFlds& rLst, const SwFieldType& rFldType,
594 sal_uInt16 nSubType, sal_Bool bInReadOnly,
595 sal_Bool bChkInpFlag = sal_False )
597 // always search the 1. frame
598 Point aPt;
599 SwTxtFld* pTxtFld;
600 SwIterator<SwFmtFld,SwFieldType> aIter(rFldType);
601 bool bSubType = nSubType != USHRT_MAX;
602 for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
603 if( 0 != ( pTxtFld = pFmtFld->GetTxtFld() ) &&
604 ( !bChkInpFlag || ((SwSetExpField*)pTxtFld->GetFld().GetFld())
605 ->GetInputFlag() ) &&
606 (!bSubType || (pFmtFld->GetFld()->GetSubType()
607 & 0xff ) == nSubType ))
609 SwCntntFrm* pCFrm;
610 const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
611 if( 0 != ( pCFrm = rTxtNode.getLayoutFrm( rTxtNode.GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False )) &&
612 ( bInReadOnly || !pCFrm->IsProtected() ))
614 _SetGetExpFld* pNew = new _SetGetExpFld(
615 SwNodeIndex( rTxtNode ), pTxtFld );
616 pNew->SetBodyPos( *pCFrm );
617 rLst.insert( pNew );
623 sal_Bool SwCrsrShell::MoveFldType( const SwFieldType* pFldType, sal_Bool bNext,
624 sal_uInt16 nSubType, sal_uInt16 nResType )
626 // sorted list of all fields
627 _SetGetExpFlds aSrtLst;
629 if (pFldType)
631 if( RES_INPUTFLD != pFldType->Which() && !pFldType->GetDepends() )
632 return sal_False;
634 // found Modify object, add all fields to array
635 ::lcl_MakeFldLst( aSrtLst, *pFldType, nSubType, IsReadOnlyAvailable() );
637 if( RES_INPUTFLD == pFldType->Which() )
639 // there are hidden input fields in the set exp. fields
640 const SwFldTypes& rFldTypes = *pDoc->GetFldTypes();
641 const sal_uInt16 nSize = rFldTypes.size();
643 // iterate over all types
644 for( sal_uInt16 i=0; i < nSize; ++i )
645 if( RES_SETEXPFLD == ( pFldType = rFldTypes[ i ] )->Which() )
646 ::lcl_MakeFldLst( aSrtLst, *pFldType, nSubType,
647 IsReadOnlyAvailable(), sal_True );
650 else
652 const SwFldTypes& rFldTypes = *pDoc->GetFldTypes();
653 const sal_uInt16 nSize = rFldTypes.size();
655 // iterate over all types
656 for( sal_uInt16 i=0; i < nSize; ++i )
657 if( nResType == ( pFldType = rFldTypes[ i ] )->Which() )
658 ::lcl_MakeFldLst( aSrtLst, *pFldType, nSubType,
659 IsReadOnlyAvailable() );
662 // found no fields?
663 if( aSrtLst.empty() )
664 return sal_False;
666 _SetGetExpFlds::const_iterator it;
667 SwCursor* pCrsr = getShellCrsr( true );
669 // (1998): Always use field for search so that the right one is found as
670 // well some are in frames that are anchored to a paragraph that has a
671 // field
672 const SwPosition& rPos = *pCrsr->GetPoint();
674 SwTxtNode* pTNd = rPos.nNode.GetNode().GetTxtNode();
675 OSL_ENSURE( pTNd, "No CntntNode" );
677 SwTxtFld * pTxtFld = static_cast<SwTxtFld *>(
678 pTNd->GetTxtAttrForCharAt(rPos.nContent.GetIndex(),
679 RES_TXTATR_FIELD));
680 bool bDelFld = 0 == pTxtFld;
681 if( bDelFld )
683 SwFmtFld* pFmtFld = new SwFmtFld( SwDateTimeField(
684 (SwDateTimeFieldType*)pDoc->GetSysFldType( RES_DATETIMEFLD ) ) );
686 pTxtFld = new SwTxtFld( *pFmtFld, rPos.nContent.GetIndex(),
687 pDoc->IsClipBoard() );
688 pTxtFld->ChgTxtNode( pTNd );
691 _SetGetExpFld aSrch( rPos.nNode, pTxtFld, &rPos.nContent );
692 if( rPos.nNode.GetIndex() < pDoc->GetNodes().GetEndOfExtras().GetIndex() )
694 // also at collection use only the first frame
695 Point aPt;
696 aSrch.SetBodyPos( *pTNd->getLayoutFrm( GetLayout(), &aPt, &rPos, sal_False ) );
699 it = aSrtLst.lower_bound( &aSrch );
700 if( bDelFld )
702 delete (SwFmtFld*)&pTxtFld->GetAttr();
703 delete pTxtFld;
706 if( it != aSrtLst.end() && **it == aSrch ) // found
708 if( bNext )
710 if( ++it == aSrtLst.end() )
711 return sal_False; // already at the end
713 else
715 if( it == aSrtLst.begin() )
716 return sal_False; // no more steps backward possible
717 --it;
720 else // not found
722 if( bNext )
724 if( it == aSrtLst.end() )
725 return sal_False;
727 else
729 if( it == aSrtLst.begin() )
730 return sal_False; // no more steps backward possible
731 --it;
735 const _SetGetExpFld& rFnd = **it;
738 SET_CURR_SHELL( this );
739 SwCallLink aLk( *this ); // watch Crsr-Moves
740 SwCrsrSaveState aSaveState( *pCrsr );
742 rFnd.GetPosOfContent( *pCrsr->GetPoint() );
743 sal_Bool bRet = !pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
744 nsSwCursorSelOverFlags::SELOVER_TOGGLE );
745 if( bRet )
746 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
747 return bRet;
751 sal_Bool SwCrsrShell::GotoFld( const SwFmtFld& rFld )
753 sal_Bool bRet = sal_False;
754 if( rFld.GetTxtFld() )
756 SET_CURR_SHELL( this );
757 SwCallLink aLk( *this ); // watch Crsr-Moves
759 SwCursor* pCrsr = getShellCrsr( true );
760 SwCrsrSaveState aSaveState( *pCrsr );
762 SwTxtNode* pTNd = (SwTxtNode*)rFld.GetTxtFld()->GetpTxtNode();
763 pCrsr->GetPoint()->nNode = *pTNd;
764 pCrsr->GetPoint()->nContent.Assign( pTNd, *rFld.GetTxtFld()->GetStart() );
766 bRet = !pCrsr->IsSelOvr();
767 if( bRet )
768 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
770 return bRet;
774 void SwCrsrShell::GotoOutline( sal_uInt16 nIdx )
776 SwCursor* pCrsr = getShellCrsr( true );
778 SET_CURR_SHELL( this );
779 SwCallLink aLk( *this ); // watch Crsr-Moves
780 SwCrsrSaveState aSaveState( *pCrsr );
782 const SwNodes& rNds = GetDoc()->GetNodes();
783 SwTxtNode* pTxtNd = (SwTxtNode*)rNds.GetOutLineNds()[ nIdx ]->GetTxtNode();
784 pCrsr->GetPoint()->nNode = *pTxtNd;
785 pCrsr->GetPoint()->nContent.Assign( pTxtNd, 0 );
787 if( !pCrsr->IsSelOvr() )
788 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
792 bool SwCrsrShell::GotoOutline( const String& rName )
794 SwCursor* pCrsr = getShellCrsr( true );
796 SET_CURR_SHELL( this );
797 SwCallLink aLk( *this ); // watch Crsr-Moves
798 SwCrsrSaveState aSaveState( *pCrsr );
800 bool bRet = false;
801 if( pDoc->GotoOutline( *pCrsr->GetPoint(), rName ) && !pCrsr->IsSelOvr() )
803 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
804 bRet = true;
806 return bRet;
809 /// jump to next node with outline num.
810 sal_Bool SwCrsrShell::GotoNextOutline()
812 SwCursor* pCrsr = getShellCrsr( true );
813 const SwNodes& rNds = GetDoc()->GetNodes();
815 SwNode* pNd = pCrsr->GetNode();
816 sal_uInt16 nPos;
817 if( rNds.GetOutLineNds().Seek_Entry( pNd, &nPos ))
818 ++nPos;
820 if( nPos == rNds.GetOutLineNds().size() )
821 return sal_False;
823 pNd = rNds.GetOutLineNds()[ nPos ];
825 SET_CURR_SHELL( this );
826 SwCallLink aLk( *this ); // watch Crsr-Moves
827 SwCrsrSaveState aSaveState( *pCrsr );
828 pCrsr->GetPoint()->nNode = *pNd;
829 pCrsr->GetPoint()->nContent.Assign( (SwTxtNode*)pNd, 0 );
831 sal_Bool bRet = !pCrsr->IsSelOvr();
832 if( bRet )
833 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
834 return bRet;
837 /// jump to previous node with outline num.
838 sal_Bool SwCrsrShell::GotoPrevOutline()
840 SwCursor* pCrsr = getShellCrsr( true );
841 const SwNodes& rNds = GetDoc()->GetNodes();
843 SwNode* pNd = pCrsr->GetNode();
844 sal_uInt16 nPos;
845 rNds.GetOutLineNds().Seek_Entry( pNd, &nPos );
847 sal_Bool bRet = sal_False;
848 if( nPos )
850 --nPos; // before
852 pNd = rNds.GetOutLineNds()[ nPos ];
853 if( pNd->GetIndex() > pCrsr->GetPoint()->nNode.GetIndex() )
854 return sal_False;
856 SET_CURR_SHELL( this );
857 SwCallLink aLk( *this ); // watch Crsr-Moves
858 SwCrsrSaveState aSaveState( *pCrsr );
859 pCrsr->GetPoint()->nNode = *pNd;
860 pCrsr->GetPoint()->nContent.Assign( (SwTxtNode*)pNd, 0 );
862 bRet = !pCrsr->IsSelOvr();
863 if( bRet )
864 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
866 return bRet;
869 /// search "outline position" before previous outline node at given level
870 sal_uInt16 SwCrsrShell::GetOutlinePos( sal_uInt8 nLevel )
872 SwPaM* pCrsr = getShellCrsr( true );
873 const SwNodes& rNds = GetDoc()->GetNodes();
875 SwNode* pNd = pCrsr->GetNode();
876 sal_uInt16 nPos;
877 if( rNds.GetOutLineNds().Seek_Entry( pNd, &nPos ))
878 nPos++; // is at correct position; take next for while
880 while( nPos-- ) // check the one in front of the current
882 pNd = rNds.GetOutLineNds()[ nPos ];
884 if( ((SwTxtNode*)pNd)->GetAttrOutlineLevel()-1 <= nLevel )
885 return nPos;
888 return USHRT_MAX; // no more left
892 sal_Bool SwCrsrShell::MakeOutlineSel( sal_uInt16 nSttPos, sal_uInt16 nEndPos,
893 sal_Bool bWithChildren )
895 const SwNodes& rNds = GetDoc()->GetNodes();
896 const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds();
897 if( rOutlNds.empty() )
898 return sal_False;
900 SET_CURR_SHELL( this );
901 SwCallLink aLk( *this ); // watch Crsr-Moves
903 if( nSttPos > nEndPos ) // parameters switched?
905 OSL_ENSURE( !this, "Start > End for array access" );
906 sal_uInt16 nTmp = nSttPos;
907 nSttPos = nEndPos;
908 nEndPos = nTmp;
911 SwNode* pSttNd = rOutlNds[ nSttPos ];
912 SwNode* pEndNd = rOutlNds[ nEndPos ];
914 if( bWithChildren )
916 const int nLevel = pEndNd->GetTxtNode()->GetAttrOutlineLevel()-1;
917 for( ++nEndPos; nEndPos < rOutlNds.size(); ++nEndPos )
919 pEndNd = rOutlNds[ nEndPos ];
920 const int nNxtLevel = pEndNd->GetTxtNode()->GetAttrOutlineLevel()-1;
921 if( nNxtLevel <= nLevel )
922 break; // EndPos is now on the next one
925 // if without children then set onto next one
926 else if( ++nEndPos < rOutlNds.size() )
927 pEndNd = rOutlNds[ nEndPos ];
929 if( nEndPos == rOutlNds.size() ) // no end found
930 pEndNd = &rNds.GetEndOfContent();
932 KillPams();
934 SwCrsrSaveState aSaveState( *pCurCrsr );
936 // set end to the end of the previous content node
937 pCurCrsr->GetPoint()->nNode = *pSttNd;
938 pCurCrsr->GetPoint()->nContent.Assign( pSttNd->GetCntntNode(), 0 );
939 pCurCrsr->SetMark();
940 pCurCrsr->GetPoint()->nNode = *pEndNd;
941 pCurCrsr->Move( fnMoveBackward, fnGoNode ); // end of predecessor
943 // and everything is already selected
944 sal_Bool bRet = !pCurCrsr->IsSelOvr();
945 if( bRet )
946 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
947 return bRet;
951 /// jump to reference marker
952 sal_Bool SwCrsrShell::GotoRefMark( const String& rRefMark, sal_uInt16 nSubType,
953 sal_uInt16 nSeqNo )
955 SET_CURR_SHELL( this );
956 SwCallLink aLk( *this ); // watch Crsr-Moves
957 SwCrsrSaveState aSaveState( *pCurCrsr );
959 sal_uInt16 nPos;
960 SwTxtNode* pTxtNd = SwGetRefFieldType::FindAnchor( GetDoc(), rRefMark,
961 nSubType, nSeqNo, &nPos );
962 if( pTxtNd && pTxtNd->GetNodes().IsDocNodes() )
964 pCurCrsr->GetPoint()->nNode = *pTxtNd;
965 pCurCrsr->GetPoint()->nContent.Assign( pTxtNd, nPos );
967 if( !pCurCrsr->IsSelOvr() )
969 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
970 return sal_True;
973 return sal_False;
976 sal_Bool SwCrsrShell::IsPageAtPos( const Point &rPt ) const
978 if( GetLayout() )
979 return 0 != GetLayout()->GetPageAtPos( rPt );
980 return sal_False;
983 sal_Bool SwCrsrShell::GetContentAtPos( const Point& rPt,
984 SwContentAtPos& rCntntAtPos,
985 sal_Bool bSetCrsr,
986 SwRect* pFldRect )
988 SET_CURR_SHELL( this );
989 sal_Bool bRet = sal_False;
991 if( !IsTableMode() )
993 Point aPt( rPt );
994 SwPosition aPos( *pCurCrsr->GetPoint() );
996 SwTxtNode* pTxtNd;
997 SwCntntFrm *pFrm(0);
998 SwTxtAttr* pTxtAttr;
999 SwCrsrMoveState aTmpState;
1000 aTmpState.bFieldInfo = sal_True;
1001 aTmpState.bExactOnly = !( SwContentAtPos::SW_OUTLINE & rCntntAtPos.eCntntAtPos );
1002 aTmpState.bCntntCheck = (SwContentAtPos::SW_CONTENT_CHECK & rCntntAtPos.eCntntAtPos) ? sal_True : sal_False;
1003 aTmpState.bSetInReadOnly = IsReadOnlyAvailable();
1005 SwSpecialPos aSpecialPos;
1006 aTmpState.pSpecialPos = ( SwContentAtPos::SW_SMARTTAG & rCntntAtPos.eCntntAtPos ) ?
1007 &aSpecialPos : 0;
1009 const sal_Bool bCrsrFoundExact = GetLayout()->GetCrsrOfst( &aPos, aPt, &aTmpState );
1010 pTxtNd = aPos.nNode.GetNode().GetTxtNode();
1012 const SwNodes& rNds = GetDoc()->GetNodes();
1013 if( pTxtNd && SwContentAtPos::SW_OUTLINE & rCntntAtPos.eCntntAtPos
1014 && !rNds.GetOutLineNds().empty() )
1016 const SwTxtNode* pONd = pTxtNd->FindOutlineNodeOfLevel( MAXLEVEL-1);
1017 if( pONd )
1019 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_OUTLINE;
1020 rCntntAtPos.sStr = pONd->GetExpandTxt( 0, STRING_LEN, true, true );
1021 bRet = sal_True;
1024 // #i43742# New function
1025 else if ( SwContentAtPos::SW_CONTENT_CHECK & rCntntAtPos.eCntntAtPos &&
1026 bCrsrFoundExact )
1028 bRet = sal_True;
1030 // #i23726#
1031 else if( pTxtNd &&
1032 SwContentAtPos::SW_NUMLABEL & rCntntAtPos.eCntntAtPos)
1034 bRet = aTmpState.bInNumPortion;
1035 rCntntAtPos.aFnd.pNode = pTxtNd;
1037 Size aSizeLogic(aTmpState.nInNumPostionOffset, 0);
1038 Size aSizePixel = GetWin()->LogicToPixel(aSizeLogic);
1039 rCntntAtPos.nDist = aSizePixel.Width();
1041 else if( bCrsrFoundExact && pTxtNd )
1043 if( !aTmpState.bPosCorr )
1045 if( !bRet && SwContentAtPos::SW_SMARTTAG & rCntntAtPos.eCntntAtPos
1046 && !aTmpState.bFtnNoInfo )
1048 const SwWrongList* pSmartTagList = pTxtNd->GetSmartTags();
1049 xub_StrLen nCurrent = aPos.nContent.GetIndex();
1050 xub_StrLen nBegin = nCurrent;
1051 xub_StrLen nLen = 1;
1053 if ( pSmartTagList && pSmartTagList->InWrongWord( nCurrent, nLen ) && !pTxtNd->IsSymbol(nBegin) )
1055 const sal_uInt16 nIndex = pSmartTagList->GetWrongPos( nBegin );
1056 const SwWrongList* pSubList = pSmartTagList->SubList( nIndex );
1057 if ( pSubList )
1059 nCurrent = aTmpState.pSpecialPos->nCharOfst;
1061 if ( pSubList->InWrongWord( nCurrent, nLen ) )
1062 bRet = sal_True;
1064 else
1065 bRet = sal_True;
1067 if( bRet && bSetCrsr )
1069 SwCrsrSaveState aSaveState( *pCurCrsr );
1070 SwCallLink aLk( *this ); // watch Crsr-Moves
1071 pCurCrsr->DeleteMark();
1072 *pCurCrsr->GetPoint() = aPos;
1073 if( pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
1074 nsSwCursorSelOverFlags::SELOVER_TOGGLE) )
1075 bRet = sal_False;
1076 else
1077 UpdateCrsr();
1079 if( bRet )
1081 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_SMARTTAG;
1083 if( pFldRect && 0 != ( pFrm = pTxtNd->getLayoutFrm( GetLayout(), &aPt ) ) )
1084 pFrm->GetCharRect( *pFldRect, aPos, &aTmpState );
1089 if( !bRet && ( SwContentAtPos::SW_FIELD | SwContentAtPos::SW_CLICKFIELD )
1090 & rCntntAtPos.eCntntAtPos && !aTmpState.bFtnNoInfo )
1092 pTxtAttr = pTxtNd->GetTxtAttrForCharAt(
1093 aPos.nContent.GetIndex(), RES_TXTATR_FIELD );
1094 const SwField* pFld = pTxtAttr
1095 ? pTxtAttr->GetFld().GetFld()
1096 : 0;
1097 if( SwContentAtPos::SW_CLICKFIELD & rCntntAtPos.eCntntAtPos &&
1098 pFld && !pFld->HasClickHdl() )
1099 pFld = 0;
1101 if( pFld )
1103 if( pFldRect && 0 != ( pFrm = pTxtNd->getLayoutFrm( GetLayout(), &aPt ) ) )
1104 pFrm->GetCharRect( *pFldRect, aPos, &aTmpState );
1106 if( bSetCrsr )
1108 SwCallLink aLk( *this ); // watch Crsr-Moves
1109 SwCrsrSaveState aSaveState( *pCurCrsr );
1110 pCurCrsr->DeleteMark();
1111 *pCurCrsr->GetPoint() = aPos;
1112 if( pCurCrsr->IsSelOvr() )
1114 // allow click fields in protected sections
1115 // only placeholder is not possible
1116 if( SwContentAtPos::SW_FIELD & rCntntAtPos.eCntntAtPos
1117 || RES_JUMPEDITFLD == pFld->Which() )
1118 pFld = 0;
1120 else
1121 UpdateCrsr();
1123 else if( RES_TABLEFLD == pFld->Which() &&
1124 ((SwTblField*)pFld)->IsIntrnlName() )
1126 // create from internal (for CORE) the external
1127 // (for UI) formula
1128 const SwTableNode* pTblNd = pTxtNd->FindTableNode();
1129 if( pTblNd ) // steht in einer Tabelle
1130 ((SwTblField*)pFld)->PtrToBoxNm( &pTblNd->GetTable() );
1134 if( pFld )
1136 rCntntAtPos.aFnd.pFld = pFld;
1137 rCntntAtPos.pFndTxtAttr = pTxtAttr;
1138 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_FIELD;
1139 bRet = sal_True;
1143 if( !bRet && SwContentAtPos::SW_FORMCTRL & rCntntAtPos.eCntntAtPos )
1145 IDocumentMarkAccess* pMarksAccess = GetDoc()->getIDocumentMarkAccess( );
1146 sw::mark::IFieldmark* pFldBookmark = pMarksAccess->getFieldmarkFor( aPos );
1147 if( bCrsrFoundExact && pTxtNd && pFldBookmark) {
1148 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_FORMCTRL;
1149 rCntntAtPos.aFnd.pFldmark = pFldBookmark;
1150 bRet=sal_True;
1154 if( !bRet && SwContentAtPos::SW_FTN & rCntntAtPos.eCntntAtPos )
1156 if( aTmpState.bFtnNoInfo )
1158 // over the footnote's char
1159 bRet = sal_True;
1160 if( bSetCrsr )
1162 *pCurCrsr->GetPoint() = aPos;
1163 if( !GotoFtnAnchor() )
1164 bRet = sal_False;
1166 if( bRet )
1167 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_FTN;
1169 else if ( 0 != ( pTxtAttr = pTxtNd->GetTxtAttrForCharAt(
1170 aPos.nContent.GetIndex(), RES_TXTATR_FTN )) )
1172 bRet = sal_True;
1173 if( bSetCrsr )
1175 SwCallLink aLk( *this ); // watch Crsr-Moves
1176 SwCrsrSaveState aSaveState( *pCurCrsr );
1177 pCurCrsr->GetPoint()->nNode = *((SwTxtFtn*)pTxtAttr)->GetStartNode();
1178 SwCntntNode* pCNd = GetDoc()->GetNodes().GoNextSection(
1179 &pCurCrsr->GetPoint()->nNode,
1180 sal_True, !IsReadOnlyAvailable() );
1182 if( pCNd )
1184 pCurCrsr->GetPoint()->nContent.Assign( pCNd, 0 );
1185 if( pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
1186 nsSwCursorSelOverFlags::SELOVER_TOGGLE ))
1187 bRet = sal_False;
1188 else
1189 UpdateCrsr();
1191 else
1192 bRet = sal_False;
1195 if( bRet )
1197 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_FTN;
1198 rCntntAtPos.pFndTxtAttr = pTxtAttr;
1199 rCntntAtPos.aFnd.pAttr = &pTxtAttr->GetAttr();
1201 if( pFldRect && 0 != ( pFrm = pTxtNd->getLayoutFrm( GetLayout(), &aPt ) ) )
1202 pFrm->GetCharRect( *pFldRect, aPos, &aTmpState );
1207 if( !bRet && ( SwContentAtPos::SW_TOXMARK |
1208 SwContentAtPos::SW_REFMARK ) &
1209 rCntntAtPos.eCntntAtPos && !aTmpState.bFtnNoInfo )
1211 pTxtAttr = 0;
1212 if( SwContentAtPos::SW_TOXMARK & rCntntAtPos.eCntntAtPos )
1214 ::std::vector<SwTxtAttr *> const marks(
1215 pTxtNd->GetTxtAttrsAt(
1216 aPos.nContent.GetIndex(), RES_TXTATR_TOXMARK));
1217 if (marks.size())
1218 { // hmm... can only return 1 here
1219 pTxtAttr = *marks.begin();
1223 if( !pTxtAttr &&
1224 SwContentAtPos::SW_REFMARK & rCntntAtPos.eCntntAtPos )
1226 ::std::vector<SwTxtAttr *> const marks(
1227 pTxtNd->GetTxtAttrsAt(
1228 aPos.nContent.GetIndex(), RES_TXTATR_REFMARK));
1229 if (marks.size())
1230 { // hmm... can only return 1 here
1231 pTxtAttr = *marks.begin();
1235 if( pTxtAttr )
1237 bRet = sal_True;
1238 if( bSetCrsr )
1240 SwCallLink aLk( *this ); // watch Crsr-Moves
1241 SwCrsrSaveState aSaveState( *pCurCrsr );
1242 pCurCrsr->DeleteMark();
1243 *pCurCrsr->GetPoint() = aPos;
1244 if( pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
1245 nsSwCursorSelOverFlags::SELOVER_TOGGLE ) )
1246 bRet = sal_False;
1247 else
1248 UpdateCrsr();
1251 if( bRet )
1253 const xub_StrLen* pEnd = pTxtAttr->GetEnd();
1254 if( pEnd )
1255 rCntntAtPos.sStr = pTxtNd->GetExpandTxt(
1256 *pTxtAttr->GetStart(),
1257 *pEnd - *pTxtAttr->GetStart() );
1258 else if( RES_TXTATR_TOXMARK == pTxtAttr->Which())
1259 rCntntAtPos.sStr = pTxtAttr->GetTOXMark().
1260 GetAlternativeText();
1262 rCntntAtPos.eCntntAtPos =
1263 RES_TXTATR_TOXMARK == pTxtAttr->Which()
1264 ? SwContentAtPos::SW_TOXMARK
1265 : SwContentAtPos::SW_REFMARK;
1266 rCntntAtPos.pFndTxtAttr = pTxtAttr;
1267 rCntntAtPos.aFnd.pAttr = &pTxtAttr->GetAttr();
1269 if( pFldRect && 0 != ( pFrm = pTxtNd->getLayoutFrm( GetLayout(), &aPt ) ) )
1270 pFrm->GetCharRect( *pFldRect, aPos, &aTmpState );
1275 if( !bRet && SwContentAtPos::SW_INETATTR & rCntntAtPos.eCntntAtPos
1276 && !aTmpState.bFtnNoInfo )
1278 pTxtAttr = pTxtNd->GetTxtAttrAt(
1279 aPos.nContent.GetIndex(), RES_TXTATR_INETFMT);
1280 // "detect" only INetAttrs with URLs
1281 if( pTxtAttr && pTxtAttr->GetINetFmt().GetValue().Len() )
1283 bRet = sal_True;
1284 if( bSetCrsr )
1286 SwCrsrSaveState aSaveState( *pCurCrsr );
1287 SwCallLink aLk( *this ); // watch Crsr-Moves
1288 pCurCrsr->DeleteMark();
1289 *pCurCrsr->GetPoint() = aPos;
1290 if( pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
1291 nsSwCursorSelOverFlags::SELOVER_TOGGLE) )
1292 bRet = sal_False;
1293 else
1294 UpdateCrsr();
1296 if( bRet )
1298 rCntntAtPos.sStr = pTxtNd->GetExpandTxt(
1299 *pTxtAttr->GetStart(),
1300 *pTxtAttr->GetEnd() - *pTxtAttr->GetStart() );
1302 rCntntAtPos.aFnd.pAttr = &pTxtAttr->GetAttr();
1303 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_INETATTR;
1304 rCntntAtPos.pFndTxtAttr = pTxtAttr;
1306 if( pFldRect && 0 != ( pFrm = pTxtNd->getLayoutFrm( GetLayout(), &aPt ) ) )
1307 pFrm->GetCharRect( *pFldRect, aPos, &aTmpState );
1312 if( !bRet && SwContentAtPos::SW_REDLINE & rCntntAtPos.eCntntAtPos )
1314 const SwRedline* pRedl = GetDoc()->GetRedline(aPos, NULL);
1315 if( pRedl )
1317 rCntntAtPos.aFnd.pRedl = pRedl;
1318 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_REDLINE;
1319 rCntntAtPos.pFndTxtAttr = 0;
1320 bRet = sal_True;
1322 if( pFldRect && 0 != ( pFrm = pTxtNd->getLayoutFrm( GetLayout(), &aPt ) ) )
1323 pFrm->GetCharRect( *pFldRect, aPos, &aTmpState );
1328 if( !bRet && (
1329 SwContentAtPos::SW_TABLEBOXFML & rCntntAtPos.eCntntAtPos
1330 #ifdef DBG_UTIL
1331 || SwContentAtPos::SW_TABLEBOXVALUE & rCntntAtPos.eCntntAtPos
1332 #endif
1335 const SwTableNode* pTblNd;
1336 const SwTableBox* pBox;
1337 const SwStartNode* pSttNd = pTxtNd->FindTableBoxStartNode();
1338 const SfxPoolItem* pItem;
1339 if( pSttNd && 0 != ( pTblNd = pTxtNd->FindTableNode()) &&
1340 0 != ( pBox = pTblNd->GetTable().GetTblBox(
1341 pSttNd->GetIndex() )) &&
1342 #ifdef DBG_UTIL
1343 ( SFX_ITEM_SET == pBox->GetFrmFmt()->GetItemState(
1344 RES_BOXATR_FORMULA, sal_False, &pItem ) ||
1345 SFX_ITEM_SET == pBox->GetFrmFmt()->GetItemState(
1346 RES_BOXATR_VALUE, sal_False, &pItem ))
1347 #else
1348 SFX_ITEM_SET == pBox->GetFrmFmt()->GetItemState(
1349 RES_BOXATR_FORMULA, sal_False, &pItem )
1350 #endif
1353 SwFrm* pF = pTxtNd->getLayoutFrm( GetLayout(), &aPt );
1354 if( pF )
1356 // then the CellFrame
1357 pFrm = (SwCntntFrm*)pF;
1358 while( pF && !pF->IsCellFrm() )
1359 pF = pF->GetUpper();
1362 if( aTmpState.bPosCorr )
1364 if( pF && !pF->Frm().IsInside( aPt ))
1365 pF = 0;
1367 else if( !pF )
1368 pF = pFrm;
1370 if( pF ) // only then it is valid
1372 // create from internal (for CORE) the external
1373 // (for UI) formula
1374 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_TABLEBOXFML;
1375 #ifdef DBG_UTIL
1376 if( RES_BOXATR_VALUE == pItem->Which() )
1377 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_TABLEBOXVALUE;
1378 else
1379 #endif
1380 ((SwTblBoxFormula*)pItem)->PtrToBoxNm( &pTblNd->GetTable() );
1382 bRet = sal_True;
1383 if( bSetCrsr )
1385 SwCallLink aLk( *this ); // watch Crsr-Moves
1386 SwCrsrSaveState aSaveState( *pCurCrsr );
1387 *pCurCrsr->GetPoint() = aPos;
1388 if( pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
1389 nsSwCursorSelOverFlags::SELOVER_TOGGLE) )
1390 bRet = sal_False;
1391 else
1392 UpdateCrsr();
1395 if( bRet )
1397 if( pFldRect )
1399 *pFldRect = pF->Prt();
1400 *pFldRect += pF->Frm().Pos();
1402 rCntntAtPos.pFndTxtAttr = 0;
1403 rCntntAtPos.aFnd.pAttr = pItem;
1409 #ifdef DBG_UTIL
1410 if( !bRet && SwContentAtPos::SW_CURR_ATTRS & rCntntAtPos.eCntntAtPos )
1412 xub_StrLen n = aPos.nContent.GetIndex();
1413 SfxItemSet aSet( GetDoc()->GetAttrPool(), POOLATTR_BEGIN,
1414 POOLATTR_END - 1 );
1415 if( pTxtNd->GetpSwpHints() )
1417 for( sal_uInt16 i = 0; i < pTxtNd->GetSwpHints().Count(); ++i )
1419 const SwTxtAttr* pHt = pTxtNd->GetSwpHints()[i];
1420 xub_StrLen nAttrStart = *pHt->GetStart();
1421 if( nAttrStart > n ) // over the section
1422 break;
1424 if( 0 != pHt->GetEnd() && (
1425 ( nAttrStart < n &&
1426 ( pHt->DontExpand() ? n < *pHt->GetEnd()
1427 : n <= *pHt->GetEnd() )) ||
1428 ( n == nAttrStart &&
1429 ( nAttrStart == *pHt->GetEnd() || !n ))) )
1431 aSet.Put( pHt->GetAttr() );
1434 if( pTxtNd->HasSwAttrSet() &&
1435 pTxtNd->GetpSwAttrSet()->Count() )
1437 SfxItemSet aFmtSet( pTxtNd->GetSwAttrSet() );
1438 // remove all from format set that are also in TextSet
1439 aFmtSet.Differentiate( aSet );
1440 // now merge all together
1441 aSet.Put( aFmtSet );
1444 else
1445 pTxtNd->SwCntntNode::GetAttr( aSet );
1447 rCntntAtPos.sStr.AssignAscii(
1448 RTL_CONSTASCII_STRINGPARAM( "Pos: (" ));
1449 rCntntAtPos.sStr += String::CreateFromInt32( aPos.nNode.GetIndex());
1450 rCntntAtPos.sStr += ':';
1451 rCntntAtPos.sStr += String::CreateFromInt32( aPos.nContent.GetIndex());
1452 rCntntAtPos.sStr += ')';
1453 rCntntAtPos.sStr.AppendAscii(
1454 RTL_CONSTASCII_STRINGPARAM( "\nAbs.Vorl.: " )); // translation *might be* "paragraph template"
1455 rCntntAtPos.sStr += pTxtNd->GetFmtColl()->GetName();
1456 if( pTxtNd->GetCondFmtColl() )
1457 rCntntAtPos.sStr.AppendAscii(
1458 RTL_CONSTASCII_STRINGPARAM( "\nBed.Vorl.: " )) // translation *might be* "conditional template"
1459 += pTxtNd->GetCondFmtColl()->GetName();
1461 if( aSet.Count() )
1463 String sAttrs;
1464 SfxItemIter aIter( aSet );
1465 const SfxPoolItem* pItem = aIter.FirstItem();
1466 while( sal_True )
1468 if( !IsInvalidItem( pItem ))
1470 String aStr;
1471 GetDoc()->GetAttrPool().GetPresentation( *pItem,
1472 SFX_ITEM_PRESENTATION_COMPLETE,
1473 SFX_MAPUNIT_CM, aStr );
1474 if( sAttrs.Len() )
1475 sAttrs.AppendAscii(
1476 RTL_CONSTASCII_STRINGPARAM( ", " ));
1477 sAttrs += aStr;
1479 if( aIter.IsAtEnd() )
1480 break;
1481 pItem = aIter.NextItem();
1483 if( sAttrs.Len() )
1485 if( rCntntAtPos.sStr.Len() )
1486 rCntntAtPos.sStr += '\n';
1487 rCntntAtPos.sStr.AppendAscii(
1488 RTL_CONSTASCII_STRINGPARAM( "Attr: " ) )
1489 += sAttrs;
1492 bRet = sal_True;
1493 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_CURR_ATTRS;
1495 #endif
1499 if( !bRet )
1501 rCntntAtPos.eCntntAtPos = SwContentAtPos::SW_NOTHING;
1502 rCntntAtPos.aFnd.pFld = 0;
1504 return bRet;
1507 // #i90516#
1508 const SwPostItField* SwCrsrShell::GetPostItFieldAtCursor() const
1510 const SwPostItField* pPostItFld = 0;
1512 if ( !IsTableMode() )
1514 const SwPosition* pCursorPos = _GetCrsr()->GetPoint();
1515 const SwTxtNode* pTxtNd = pCursorPos->nNode.GetNode().GetTxtNode();
1516 if ( pTxtNd )
1518 SwTxtAttr* pTxtAttr = pTxtNd->GetTxtAttrForCharAt(
1519 pCursorPos->nContent.GetIndex(), RES_TXTATR_FIELD );
1520 const SwField* pFld = pTxtAttr ? pTxtAttr->GetFld().GetFld() : 0;
1521 if ( pFld && pFld->Which()== RES_POSTITFLD )
1523 pPostItFld = static_cast<const SwPostItField*>(pFld);
1528 return pPostItFld;
1531 /// is the node in a protected section?
1532 bool SwContentAtPos::IsInProtectSect() const
1534 const SwTxtNode* pNd = 0;
1535 if( pFndTxtAttr )
1537 switch( eCntntAtPos )
1539 case SW_FIELD:
1540 case SW_CLICKFIELD:
1541 pNd = ((SwTxtFld*)pFndTxtAttr)->GetpTxtNode();
1542 break;
1544 case SW_FTN:
1545 pNd = &((SwTxtFtn*)pFndTxtAttr)->GetTxtNode();
1546 break;
1548 case SW_INETATTR:
1549 pNd = ((SwTxtINetFmt*)pFndTxtAttr)->GetpTxtNode();
1550 break;
1552 default:
1553 break;
1557 const SwCntntFrm* pFrm;
1558 return pNd && ( pNd->IsInProtectSect() ||
1559 ( 0 != ( pFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout(), 0,0,sal_False)) &&
1560 pFrm->IsProtected() ));
1563 bool SwContentAtPos::IsInRTLText()const
1565 bool bRet = false;
1566 const SwTxtNode* pNd = 0;
1567 if (pFndTxtAttr && (eCntntAtPos == SW_FTN))
1569 const SwTxtFtn* pTxtFtn = static_cast<const SwTxtFtn*>(pFndTxtAttr);
1570 if(pTxtFtn->GetStartNode())
1572 SwStartNode* pSttNd = pTxtFtn->GetStartNode()->GetNode().GetStartNode();
1573 SwPaM aTemp( *pSttNd );
1574 aTemp.Move(fnMoveForward, fnGoNode);
1575 SwCntntNode* pCntntNode = aTemp.GetCntntNode();
1576 if(pCntntNode && pCntntNode->IsTxtNode())
1577 pNd = static_cast<SwTxtNode*>(pCntntNode);
1580 if(pNd)
1582 SwIterator<SwTxtFrm,SwTxtNode> aIter(*pNd);
1583 SwTxtFrm* pTmpFrm = aIter.First();
1584 while( pTmpFrm )
1586 if ( !pTmpFrm->IsFollow())
1588 bRet = pTmpFrm->IsRightToLeft();
1589 break;
1591 pTmpFrm = aIter.Next();
1594 return bRet;
1597 sal_Bool SwCrsrShell::SelectTxtAttr( sal_uInt16 nWhich, sal_Bool bExpand,
1598 const SwTxtAttr* pTxtAttr )
1600 SET_CURR_SHELL( this );
1601 sal_Bool bRet = sal_False;
1603 if( !IsTableMode() )
1605 SwPosition& rPos = *pCurCrsr->GetPoint();
1606 if( !pTxtAttr )
1608 SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
1609 pTxtAttr = (pTxtNd)
1610 ? pTxtNd->GetTxtAttrAt(rPos.nContent.GetIndex(),
1611 static_cast<RES_TXTATR>(nWhich),
1612 (bExpand) ? SwTxtNode::EXPAND : SwTxtNode::DEFAULT)
1613 : 0;
1616 if( pTxtAttr )
1618 SwCallLink aLk( *this ); // watch Crsr-Moves
1619 SwCrsrSaveState aSaveState( *pCurCrsr );
1621 pCurCrsr->DeleteMark();
1622 rPos.nContent = *pTxtAttr->GetStart();
1623 pCurCrsr->SetMark();
1624 const xub_StrLen* pEnd = pTxtAttr->GetEnd();
1625 rPos.nContent = pEnd ? *pEnd : *pTxtAttr->GetStart() + 1;
1627 if( !pCurCrsr->IsSelOvr() )
1629 UpdateCrsr();
1630 bRet = sal_True;
1634 return bRet;
1638 bool SwCrsrShell::GotoINetAttr( const SwTxtINetFmt& rAttr )
1640 bool bRet = false;
1641 if( rAttr.GetpTxtNode() )
1643 SwCursor* pCrsr = getShellCrsr( true );
1645 SET_CURR_SHELL( this );
1646 SwCallLink aLk( *this ); // watch Crsr-Moves
1647 SwCrsrSaveState aSaveState( *pCrsr );
1649 pCrsr->GetPoint()->nNode = *rAttr.GetpTxtNode();
1650 pCrsr->GetPoint()->nContent.Assign( (SwTxtNode*)rAttr.GetpTxtNode(),
1651 *rAttr.GetStart() );
1652 bRet = !pCrsr->IsSelOvr();
1653 if( bRet )
1654 UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
1656 return bRet;
1660 const SwFmtINetFmt* SwCrsrShell::FindINetAttr( const String& rName ) const
1662 return pDoc->FindINetAttr( rName );
1665 sal_Bool SwCrsrShell::GetShadowCrsrPos( const Point& rPt, SwFillMode eFillMode,
1666 SwRect& rRect, sal_Int16& rOrient )
1669 SET_CURR_SHELL( this );
1670 sal_Bool bRet = sal_False;
1672 if (!IsTableMode() && !HasSelection()
1673 && GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1675 Point aPt( rPt );
1676 SwPosition aPos( *pCurCrsr->GetPoint() );
1678 SwFillCrsrPos aFPos( eFillMode );
1679 SwCrsrMoveState aTmpState( &aFPos );
1681 if( GetLayout()->GetCrsrOfst( &aPos, aPt, &aTmpState ) &&
1682 !aPos.nNode.GetNode().IsProtect())
1684 // start position in protected section?
1685 rRect = aFPos.aCrsr;
1686 rOrient = aFPos.eOrient;
1687 bRet = sal_True;
1690 return bRet;
1693 sal_Bool SwCrsrShell::SetShadowCrsrPos( const Point& rPt, SwFillMode eFillMode )
1695 SET_CURR_SHELL( this );
1696 sal_Bool bRet = sal_False;
1698 if (!IsTableMode() && !HasSelection()
1699 && GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1701 Point aPt( rPt );
1702 SwPosition aPos( *pCurCrsr->GetPoint() );
1704 SwFillCrsrPos aFPos( eFillMode );
1705 SwCrsrMoveState aTmpState( &aFPos );
1707 if( GetLayout()->GetCrsrOfst( &aPos, aPt, &aTmpState ) )
1709 SwCallLink aLk( *this ); // watch Crsr-Moves
1710 StartAction();
1712 SwCntntNode* pCNd = aPos.nNode.GetNode().GetCntntNode();
1713 SwUndoId nUndoId = UNDO_INS_FROM_SHADOWCRSR;
1714 // If only the paragraph attributes "Adjust" or "LRSpace" are set,
1715 // then the following should not delete those again.
1716 if( 0 == aFPos.nParaCnt + aFPos.nColumnCnt &&
1717 ( FILL_INDENT == aFPos.eMode ||
1718 ( text::HoriOrientation::NONE != aFPos.eOrient &&
1719 0 == aFPos.nTabCnt + aFPos.nSpaceCnt )) &&
1720 pCNd && pCNd->Len() )
1721 nUndoId = UNDO_EMPTY;
1723 GetDoc()->GetIDocumentUndoRedo().StartUndo( nUndoId, NULL );
1725 SwTxtFmtColl* pNextFmt = 0;
1726 SwTxtNode* pTNd = pCNd->GetTxtNode();
1727 if( pTNd )
1728 pNextFmt = &pTNd->GetTxtColl()->GetNextTxtFmtColl();
1730 const SwSectionNode* pSectNd = pCNd->FindSectionNode();
1731 if( pSectNd && aFPos.nParaCnt )
1733 SwNodeIndex aEnd( aPos.nNode, 1 );
1734 while( aEnd.GetNode().IsEndNode() &&
1735 (const SwNode*)&aEnd.GetNode() !=
1736 pSectNd->EndOfSectionNode() )
1737 ++aEnd;
1739 if( aEnd.GetNode().IsEndNode() &&
1740 pCNd->Len() == aPos.nContent.GetIndex() )
1741 aPos.nNode = *pSectNd->EndOfSectionNode();
1744 for( sal_uInt16 n = 0; n < aFPos.nParaCnt + aFPos.nColumnCnt; ++n )
1746 GetDoc()->AppendTxtNode( aPos );
1747 if( !n && pNextFmt )
1749 *pCurCrsr->GetPoint() = aPos;
1750 GetDoc()->SetTxtFmtColl( *pCurCrsr, pNextFmt, false );
1752 if( n < aFPos.nColumnCnt )
1754 *pCurCrsr->GetPoint() = aPos;
1755 GetDoc()->InsertPoolItem( *pCurCrsr,
1756 SvxFmtBreakItem( SVX_BREAK_COLUMN_BEFORE, RES_BREAK ), 0);
1760 *pCurCrsr->GetPoint() = aPos;
1761 switch( aFPos.eMode )
1763 case FILL_INDENT:
1764 if( 0 != (pCNd = aPos.nNode.GetNode().GetCntntNode() ))
1766 SfxItemSet aSet( GetDoc()->GetAttrPool(),
1767 RES_LR_SPACE, RES_LR_SPACE,
1768 RES_PARATR_ADJUST, RES_PARATR_ADJUST,
1769 0 );
1770 SvxLRSpaceItem aLR( (SvxLRSpaceItem&)
1771 pCNd->GetAttr( RES_LR_SPACE ) );
1772 aLR.SetTxtLeft( aFPos.nTabCnt );
1773 aLR.SetTxtFirstLineOfst( 0 );
1774 aSet.Put( aLR );
1776 const SvxAdjustItem& rAdj = (SvxAdjustItem&)pCNd->
1777 GetAttr( RES_PARATR_ADJUST );
1778 if( SVX_ADJUST_LEFT != rAdj.GetAdjust() )
1779 aSet.Put( SvxAdjustItem( SVX_ADJUST_LEFT, RES_PARATR_ADJUST ) );
1781 GetDoc()->InsertItemSet( *pCurCrsr, aSet, 0 );
1783 else {
1784 OSL_ENSURE( !this, "No CntntNode" );
1786 break;
1788 case FILL_TAB:
1789 case FILL_SPACE:
1791 rtl::OUStringBuffer sInsert;
1792 if (aFPos.nTabCnt)
1793 comphelper::string::padToLength(sInsert, aFPos.nTabCnt, '\t');
1794 if (aFPos.nSpaceCnt)
1795 comphelper::string::padToLength(sInsert, sInsert.getLength() + aFPos.nSpaceCnt, ' ');
1796 if (sInsert.getLength())
1797 GetDoc()->InsertString( *pCurCrsr, sInsert.makeStringAndClear());
1799 // no break - still need to set orientation
1800 case FILL_MARGIN:
1801 if( text::HoriOrientation::NONE != aFPos.eOrient )
1803 SvxAdjustItem aAdj( SVX_ADJUST_LEFT, RES_PARATR_ADJUST );
1804 switch( aFPos.eOrient )
1806 case text::HoriOrientation::CENTER:
1807 aAdj.SetAdjust( SVX_ADJUST_CENTER );
1808 break;
1809 case text::HoriOrientation::RIGHT:
1810 aAdj.SetAdjust( SVX_ADJUST_RIGHT );
1811 break;
1812 default:
1813 break;
1815 GetDoc()->InsertPoolItem( *pCurCrsr, aAdj, 0 );
1817 break;
1820 GetDoc()->GetIDocumentUndoRedo().EndUndo( nUndoId, NULL );
1821 EndAction();
1823 bRet = sal_True;
1826 return bRet;
1829 const SwRedline* SwCrsrShell::SelNextRedline()
1831 const SwRedline* pFnd = 0;
1832 if( !IsTableMode() )
1834 SET_CURR_SHELL( this );
1835 SwCallLink aLk( *this ); // watch Crsr-Moves
1836 SwCrsrSaveState aSaveState( *pCurCrsr );
1838 pFnd = GetDoc()->SelNextRedline( *pCurCrsr );
1839 if( pFnd && !pCurCrsr->IsInProtectTable() && !pCurCrsr->IsSelOvr() )
1840 UpdateCrsr( SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
1841 else
1842 pFnd = 0;
1844 return pFnd;
1847 const SwRedline* SwCrsrShell::SelPrevRedline()
1849 const SwRedline* pFnd = 0;
1850 if( !IsTableMode() )
1852 SET_CURR_SHELL( this );
1853 SwCallLink aLk( *this ); // watch Crsr-Moves
1854 SwCrsrSaveState aSaveState( *pCurCrsr );
1856 pFnd = GetDoc()->SelPrevRedline( *pCurCrsr );
1857 if( pFnd && !pCurCrsr->IsInProtectTable() && !pCurCrsr->IsSelOvr() )
1858 UpdateCrsr( SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
1859 else
1860 pFnd = 0;
1862 return pFnd;
1865 const SwRedline* SwCrsrShell::_GotoRedline( sal_uInt16 nArrPos, sal_Bool bSelect )
1867 const SwRedline* pFnd = 0;
1868 SwCallLink aLk( *this ); // watch Crsr-Moves
1869 SwCrsrSaveState aSaveState( *pCurCrsr );
1871 pFnd = GetDoc()->GetRedlineTbl()[ nArrPos ];
1872 if( pFnd )
1874 *pCurCrsr->GetPoint() = *pFnd->Start();
1876 SwCntntNode* pCNd;
1877 SwNodeIndex* pIdx = &pCurCrsr->GetPoint()->nNode;
1878 if( !pIdx->GetNode().IsCntntNode() &&
1879 0 != ( pCNd = GetDoc()->GetNodes().GoNextSection( pIdx,
1880 sal_True, IsReadOnlyAvailable() )) )
1882 if( *pIdx <= pFnd->End()->nNode )
1883 pCurCrsr->GetPoint()->nContent.Assign( pCNd, 0 );
1884 else
1885 pFnd = 0;
1888 if( pFnd && bSelect )
1890 pCurCrsr->SetMark();
1891 if( nsRedlineType_t::REDLINE_FMTCOLL == pFnd->GetType() )
1893 pCNd = pIdx->GetNode().GetCntntNode();
1894 pCurCrsr->GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
1895 pCurCrsr->GetMark()->nContent.Assign( pCNd, 0 );
1897 else
1898 *pCurCrsr->GetPoint() = *pFnd->End();
1900 pIdx = &pCurCrsr->GetPoint()->nNode;
1901 if( !pIdx->GetNode().IsCntntNode() &&
1902 0 != ( pCNd = GetDoc()->GetNodes().GoPrevSection( pIdx,
1903 sal_True, IsReadOnlyAvailable() )) )
1905 if( *pIdx >= pCurCrsr->GetMark()->nNode )
1906 pCurCrsr->GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
1907 else
1908 pFnd = 0;
1912 if( !pFnd )
1914 pCurCrsr->DeleteMark();
1915 pCurCrsr->RestoreSavePos();
1917 else if( bSelect && *pCurCrsr->GetMark() == *pCurCrsr->GetPoint() )
1918 pCurCrsr->DeleteMark();
1920 if( pFnd && !pCurCrsr->IsInProtectTable() && !pCurCrsr->IsSelOvr() )
1921 UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE
1922 | SwCrsrShell::READONLY );
1923 else
1925 pFnd = 0;
1926 if( bSelect )
1927 pCurCrsr->DeleteMark();
1930 return pFnd;
1933 const SwRedline* SwCrsrShell::GotoRedline( sal_uInt16 nArrPos, sal_Bool bSelect )
1935 const SwRedline* pFnd = 0;
1936 if( !IsTableMode() )
1938 SET_CURR_SHELL( this );
1940 const SwRedlineTbl& rTbl = GetDoc()->GetRedlineTbl();
1941 const SwRedline* pTmp = rTbl[ nArrPos ];
1942 sal_uInt16 nSeqNo = pTmp->GetSeqNo();
1943 if( nSeqNo && bSelect )
1945 bool bCheck = false;
1946 int nLoopCnt = 2;
1947 sal_uInt16 nArrSavPos = nArrPos;
1949 do {
1950 pTmp = _GotoRedline( nArrPos, sal_True );
1952 if( !pFnd )
1953 pFnd = pTmp;
1955 if( pTmp && bCheck )
1957 // Check for overlaps. These can happen when FmtColl-
1958 // Redlines were streched over a whole paragraph
1959 SwPaM* pCur = pCurCrsr;
1960 SwPaM* pNextPam = (SwPaM*)pCur->GetNext();
1961 SwPosition* pCStt = pCur->Start(), *pCEnd = pCur->End();
1962 while( pCur != pNextPam )
1964 const SwPosition *pNStt = pNextPam->Start(),
1965 *pNEnd = pNextPam->End();
1967 bool bDel = true;
1968 switch( ::ComparePosition( *pCStt, *pCEnd,
1969 *pNStt, *pNEnd ))
1971 case POS_INSIDE: // Pos1 is completely in Pos2
1972 if( !pCur->HasMark() )
1974 pCur->SetMark();
1975 *pCur->GetMark() = *pNStt;
1977 else
1978 *pCStt = *pNStt;
1979 *pCEnd = *pNEnd;
1980 break;
1982 case POS_OUTSIDE: // Pos2 is completely in Pos1
1983 case POS_EQUAL: // Pos1 has same size as Pos2
1984 break;
1986 case POS_OVERLAP_BEFORE: // Pos1 overlaps Pos2 at beginning
1987 if( !pCur->HasMark() )
1988 pCur->SetMark();
1989 *pCEnd = *pNEnd;
1990 break;
1991 case POS_OVERLAP_BEHIND: // Pos1 overlaps Pos2 at end
1992 if( !pCur->HasMark() )
1994 pCur->SetMark();
1995 *pCur->GetMark() = *pNStt;
1997 else
1998 *pCStt = *pNStt;
1999 break;
2001 default:
2002 bDel = false;
2005 if( bDel )
2007 // not needed anymore
2008 SwPaM* pPrevPam = (SwPaM*)pNextPam->GetPrev();
2009 delete pNextPam;
2010 pNextPam = pPrevPam;
2012 pNextPam = (SwPaM*)pNextPam->GetNext();
2016 sal_uInt16 nFndPos = 2 == nLoopCnt
2017 ? rTbl.FindNextOfSeqNo( nArrPos )
2018 : rTbl.FindPrevOfSeqNo( nArrPos );
2019 if( USHRT_MAX != nFndPos ||
2020 ( 0 != ( --nLoopCnt ) && USHRT_MAX != (
2021 nFndPos = rTbl.FindPrevOfSeqNo( nArrSavPos ))) )
2023 if( pTmp )
2025 // create new cursor
2026 CreateCrsr();
2027 bCheck = true;
2029 nArrPos = nFndPos;
2031 else
2032 nLoopCnt = 0;
2034 } while( nLoopCnt );
2036 else
2037 pFnd = _GotoRedline( nArrPos, bSelect );
2039 return pFnd;
2043 sal_Bool SwCrsrShell::SelectNxtPrvHyperlink( sal_Bool bNext )
2045 SwNodes& rNds = GetDoc()->GetNodes();
2046 const SwNode* pBodyEndNd = &rNds.GetEndOfContent();
2047 const SwNode* pBodySttNd = pBodyEndNd->StartOfSectionNode();
2048 sal_uLong nBodySttNdIdx = pBodySttNd->GetIndex();
2049 Point aPt;
2051 _SetGetExpFld aCmpPos( SwPosition( bNext ? *pBodyEndNd : *pBodySttNd ) );
2052 _SetGetExpFld aCurPos( bNext ? *pCurCrsr->End() : *pCurCrsr->Start() );
2053 if( aCurPos.GetNode() < nBodySttNdIdx )
2055 const SwCntntNode* pCNd = aCurPos.GetNodeFromCntnt()->GetCntntNode();
2056 SwCntntFrm* pFrm;
2057 if( pCNd && 0 != ( pFrm = pCNd->getLayoutFrm( GetLayout(), &aPt )) )
2058 aCurPos.SetBodyPos( *pFrm );
2061 // check first all the hyperlink fields
2063 const SwTxtNode* pTxtNd;
2064 const SwCharFmts* pFmts = GetDoc()->GetCharFmts();
2065 for( sal_uInt16 n = pFmts->size(); 1 < n; )
2067 SwIterator<SwTxtINetFmt,SwCharFmt> aIter(*(*pFmts)[--n]);
2069 for( SwTxtINetFmt* pFnd = aIter.First(); pFnd; pFnd = aIter.Next() )
2070 if( 0 != ( pTxtNd = pFnd->GetpTxtNode()) &&
2071 pTxtNd->GetNodes().IsDocNodes() )
2073 SwTxtINetFmt& rAttr = *pFnd;
2074 SwPosition aTmpPos( *pTxtNd );
2075 _SetGetExpFld aPos( aTmpPos.nNode, rAttr );
2076 SwCntntFrm* pFrm;
2077 if( pTxtNd->GetIndex() < nBodySttNdIdx &&
2078 0 != ( pFrm = pTxtNd->getLayoutFrm( GetLayout(), &aPt )) )
2079 aPos.SetBodyPos( *pFrm );
2081 if( bNext
2082 ? ( aPos < aCmpPos && aCurPos < aPos )
2083 : ( aCmpPos < aPos && aPos < aCurPos ))
2085 String sTxt( pTxtNd->GetExpandTxt( *rAttr.GetStart(),
2086 *rAttr.GetEnd() - *rAttr.GetStart() ) );
2088 sTxt = comphelper::string::remove(sTxt, 0x0a);
2089 sTxt = comphelper::string::strip(sTxt, ' ');
2091 if( sTxt.Len() )
2092 aCmpPos = aPos;
2097 // then check all the Flys with a URL or imapge map
2099 const SwFrmFmts* pFmts = GetDoc()->GetSpzFrmFmts();
2100 for( sal_uInt16 n = 0, nEnd = pFmts->size(); n < nEnd; ++n )
2102 SwFlyFrmFmt* pFmt = (SwFlyFrmFmt*)(*pFmts)[ n ];
2103 const SwFmtURL& rURLItem = pFmt->GetURL();
2104 if( rURLItem.GetMap() || rURLItem.GetURL().Len() )
2106 SwFlyFrm* pFly = pFmt->GetFrm( &aPt, sal_False );
2107 SwPosition aTmpPos( *pBodySttNd );
2108 if( pFly &&
2109 GetBodyTxtNode( *GetDoc(), aTmpPos, *pFly->GetLower() ) )
2111 _SetGetExpFld aPos( *pFmt, &aTmpPos );
2113 if( bNext
2114 ? ( aPos < aCmpPos && aCurPos < aPos )
2115 : ( aCmpPos < aPos && aPos < aCurPos ))
2116 aCmpPos = aPos;
2122 // found any URL ?
2123 sal_Bool bRet = sal_False;
2124 const SwTxtINetFmt* pFndAttr = aCmpPos.GetINetFmt();
2125 const SwFlyFrmFmt* pFndFmt = aCmpPos.GetFlyFmt();
2126 if( pFndAttr || pFndFmt )
2128 SET_CURR_SHELL( this );
2129 SwCallLink aLk( *this );
2131 // found a text attribute ?
2132 if( pFndAttr )
2134 SwCrsrSaveState aSaveState( *pCurCrsr );
2136 aCmpPos.GetPosOfContent( *pCurCrsr->GetPoint() );
2137 pCurCrsr->DeleteMark();
2138 pCurCrsr->SetMark();
2139 pCurCrsr->GetPoint()->nContent = *pFndAttr->SwTxtAttr::GetEnd();
2141 if( !pCurCrsr->IsInProtectTable() && !pCurCrsr->IsSelOvr() )
2143 UpdateCrsr( SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|
2144 SwCrsrShell::READONLY );
2145 bRet = sal_True;
2148 // found a draw object ?
2149 else if( RES_DRAWFRMFMT == pFndFmt->Which() )
2151 const SdrObject* pSObj = pFndFmt->FindSdrObject();
2152 ((SwFEShell*)this)->SelectObj( pSObj->GetCurrentBoundRect().Center() );
2153 MakeSelVisible();
2154 bRet = sal_True;
2156 else // then is it a fly
2158 SwFlyFrm* pFly = pFndFmt->GetFrm(&aPt, sal_False );
2159 if( pFly )
2161 ((SwFEShell*)this)->SelectFlyFrm( *pFly, sal_True );
2162 MakeSelVisible();
2163 bRet = sal_True;
2167 return bRet;
2170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */