update dev300-m58
[ooovba.git] / sw / source / core / undo / undobj.cxx
blob7e61652d71707bf0afc4181a3601b25e2512fb41
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undobj.cxx,v $
10 * $Revision: 1.29.52.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <txtftn.hxx>
36 #include <fmtanchr.hxx>
37 #include <ftnidx.hxx>
38 #include <frmfmt.hxx>
39 #include <doc.hxx>
40 #include <docary.hxx>
41 #include <swundo.hxx> // fuer die UndoIds
42 #include <pam.hxx>
43 #include <ndtxt.hxx>
44 #include <undobj.hxx>
45 #include <rolbck.hxx>
46 #include <ndnotxt.hxx>
47 #include <IMark.hxx>
48 #include <mvsave.hxx>
49 #include <redline.hxx>
50 #include <crossrefbookmark.hxx>
51 #ifndef _UNDO_HRC
52 #include <undo.hrc>
53 #endif
54 #ifndef _COMCORE_HRC
55 #include <comcore.hrc>
56 #endif
57 #include <docsh.hxx>
59 class SwRedlineSaveData : public SwUndRng, public SwRedlineData,
60 private SwUndoSaveSection
62 public:
63 SwRedlineSaveData( SwComparePosition eCmpPos,
64 const SwPosition& rSttPos, const SwPosition& rEndPos,
65 SwRedline& rRedl, BOOL bCopyNext );
66 ~SwRedlineSaveData();
67 void RedlineToDoc( SwPaM& rPam );
68 SwNodeIndex* GetMvSttIdx() const
69 { return SwUndoSaveSection::GetMvSttIdx(); }
71 #ifndef PRODUCT
72 USHORT nRedlineCount;
73 #endif
76 SV_IMPL_PTRARR( SwUndos, SwUndo*)
77 SV_IMPL_PTRARR( SwRedlineSaveDatas, SwRedlineSaveDataPtr )
79 SwUndoIter::SwUndoIter( SwPaM* pPam, SwUndoId nId )
81 nUndoId = nId;
82 bWeiter = nId ? TRUE : FALSE;
83 bUpdateAttr = FALSE;
84 pAktPam = pPam;
85 nEndCnt = 0;
86 pSelFmt = 0;
87 pMarkList = 0;
89 inline SwDoc& SwUndoIter::GetDoc() const { return *pAktPam->GetDoc(); }
91 //------------------------------------------------------------
93 // Diese Klasse speichert den Pam als USHORT's und kann diese wieder zu
95 // einem PaM zusammensetzen
96 SwUndRng::SwUndRng()
97 : nSttNode( 0 ), nEndNode( 0 ), nSttCntnt( 0 ), nEndCntnt( 0 )
101 SwUndRng::SwUndRng( const SwPaM& rPam )
103 SetValues( rPam );
106 void SwUndRng::SetValues( const SwPaM& rPam )
108 const SwPosition *pStt = rPam.Start();
109 if( rPam.HasMark() )
111 const SwPosition *pEnd = rPam.GetPoint() == pStt
112 ? rPam.GetMark()
113 : rPam.GetPoint();
114 nEndNode = pEnd->nNode.GetIndex();
115 nEndCntnt = pEnd->nContent.GetIndex();
117 else
118 // keine Selektion !!
119 nEndNode = 0, nEndCntnt = STRING_MAXLEN;
121 nSttNode = pStt->nNode.GetIndex();
122 nSttCntnt = pStt->nContent.GetIndex();
125 void SwUndRng::SetPaM( SwPaM & rPam, BOOL bCorrToCntnt ) const
127 rPam.DeleteMark();
128 rPam.GetPoint()->nNode = nSttNode;
129 SwNode* pNd = rPam.GetNode();
130 if( pNd->IsCntntNode() )
131 rPam.GetPoint()->nContent.Assign( pNd->GetCntntNode(), nSttCntnt );
132 else if( bCorrToCntnt )
133 rPam.Move( fnMoveForward, fnGoCntnt );
134 else
135 rPam.GetPoint()->nContent.Assign( 0, 0 );
137 if( !nEndNode && STRING_MAXLEN == nEndCntnt ) // keine Selection
138 return ;
140 rPam.SetMark();
141 if( nSttNode == nEndNode && nSttCntnt == nEndCntnt )
142 return; // nichts mehr zu tun
144 rPam.GetPoint()->nNode = nEndNode;
145 if( (pNd = rPam.GetNode())->IsCntntNode() )
146 rPam.GetPoint()->nContent.Assign( pNd->GetCntntNode(), nEndCntnt );
147 else if( bCorrToCntnt )
148 rPam.Move( fnMoveBackward, fnGoCntnt );
149 else
150 rPam.GetPoint()->nContent.Assign( 0, 0 );
153 void SwUndRng::SetPaM( SwUndoIter& rIter, BOOL bCorrToCntnt ) const
155 if( rIter.pAktPam )
156 SetPaM( *rIter.pAktPam, bCorrToCntnt );
159 //------------------------------------------------------------
162 void SwUndo::RemoveIdxFromSection( SwDoc& rDoc, ULONG nSttIdx,
163 ULONG* pEndIdx )
165 SwNodeIndex aIdx( rDoc.GetNodes(), nSttIdx );
166 SwNodeIndex aEndIdx( rDoc.GetNodes(), pEndIdx ? *pEndIdx
167 : aIdx.GetNode().EndOfSectionIndex() );
168 SwPosition aPos( rDoc.GetNodes().GetEndOfPostIts() );
169 rDoc.CorrAbs( aIdx, aEndIdx, aPos, TRUE );
172 void SwUndo::RemoveIdxFromRange( SwPaM& rPam, BOOL bMoveNext )
174 const SwPosition* pEnd = rPam.End();
175 if( bMoveNext )
177 if( pEnd != rPam.GetPoint() )
178 rPam.Exchange();
180 SwNodeIndex aStt( rPam.GetMark()->nNode );
181 SwNodeIndex aEnd( rPam.GetPoint()->nNode );
183 if( !rPam.Move( fnMoveForward ) )
185 rPam.Exchange();
186 if( !rPam.Move( fnMoveBackward ) )
188 rPam.GetPoint()->nNode = rPam.GetDoc()->GetNodes().GetEndOfPostIts();
189 rPam.GetPoint()->nContent.Assign( 0, 0 );
193 rPam.GetDoc()->CorrAbs( aStt, aEnd, *rPam.GetPoint(), TRUE );
195 else
196 rPam.GetDoc()->CorrAbs( rPam, *pEnd, TRUE );
199 void SwUndo::RemoveIdxRel( ULONG nIdx, const SwPosition& rPos )
201 // nur die Crsr verschieben; die Bookmarks/TOXMarks/.. werden vom
202 // entsp. JoinNext/JoinPrev erledigt!
203 SwNodeIndex aIdx( rPos.nNode.GetNode().GetNodes(), nIdx );
204 ::PaMCorrRel( aIdx, rPos );
207 SwUndo::SwUndo( SwUndoId nI )
208 : nId(nI), nOrigRedlineMode(nsRedlineMode_t::REDLINE_NONE),
209 bCacheComment(true), pComment(NULL)
213 bool SwUndo::IsDelBox() const
215 return GetId() == UNDO_COL_DELETE || GetId() == UNDO_ROW_DELETE ||
216 GetId() == UNDO_TABLE_DELBOX;
219 SwUndo::~SwUndo()
221 delete pComment;
224 void SwUndo::Repeat( SwUndoIter& rIter )
226 rIter.pLastUndoObj = this;
229 String SwUndo::GetComment() const
231 String aResult;
233 if (bCacheComment)
235 if (! pComment)
237 pComment = new String(SW_RES(UNDO_BASE + nId));
239 SwRewriter aRewriter = GetRewriter();
241 *pComment = aRewriter.Apply(*pComment);
244 aResult = *pComment;
246 else
248 aResult = String(SW_RES(UNDO_BASE + nId));
250 SwRewriter aRewriter = GetRewriter();
252 aResult = aRewriter.Apply(aResult);
255 return aResult;
258 SwUndoId SwUndo::GetEffectiveId() const
260 return GetId();
263 SwRewriter SwUndo::GetRewriter() const
265 SwRewriter aResult;
267 return aResult;
270 //------------------------------------------------------------
272 SwUndoSaveCntnt::SwUndoSaveCntnt()
273 : pHistory( 0 )
276 SwUndoSaveCntnt::~SwUndoSaveCntnt()
278 delete pHistory;
281 // wird fuer das Loeschen von Inhalt benoetigt. Fuer das ReDo werden
282 // Inhalte in das UndoNodesArray verschoben. Diese Methoden fuegen
283 // am Ende eines TextNodes fuer die Attribute einen Trenner ein.
284 // Dadurch werden die Attribute nicht expandiert.
285 // MoveTo.. verschiebt aus dem NodesArray in das UndoNodesArray
286 // MoveFrom.. verschiebt aus dem UndoNodesArray in das NodesArray
288 // 2.8.93: ist pEndNdIdx angebenen, wird vom Undo/Redo -Ins/DelFly
289 // aufgerufen. Dann soll die gesamte Section verschoben werden.
291 void SwUndoSaveCntnt::MoveToUndoNds( SwPaM& rPaM, SwNodeIndex* pNodeIdx,
292 SwIndex* pCntIdx, ULONG* pEndNdIdx, xub_StrLen* pEndCntIdx )
294 SwDoc& rDoc = *rPaM.GetDoc();
295 BOOL bUndo = rDoc.DoesUndo();
296 rDoc.DoUndo( FALSE );
298 SwNoTxtNode* pCpyNd = rPaM.GetNode()->GetNoTxtNode();
300 // jetzt kommt das eigentliche Loeschen(Verschieben)
301 SwNodes& rNds = (SwNodes&)*rDoc.GetUndoNds();
302 SwPosition aPos( pEndNdIdx ? rNds.GetEndOfPostIts()
303 : rNds.GetEndOfExtras() );
304 aPos.nNode--;
306 const SwPosition* pStt = rPaM.Start(), *pEnd = rPaM.End();
308 if( pCpyNd || pEndNdIdx || !aPos.nNode.GetNode().GetCntntNode() ||
309 (!pStt->nContent.GetIndex() && (pStt->nNode != pEnd->nNode ||
310 (!pStt->nNode.GetNode().GetCntntNode() ||
311 pStt->nNode.GetNode().GetCntntNode()->Len() ==
312 pEnd->nContent.GetIndex() ) ) ) )
314 aPos.nNode++;
315 aPos.nContent = 0;
317 else
318 aPos.nNode.GetNode().GetCntntNode()->MakeEndIndex( &aPos.nContent );
320 // als USHORT merken; die Indizies verschieben sich !!
321 ULONG nTmpMvNode = aPos.nNode.GetIndex();
322 xub_StrLen nTmpMvCntnt = aPos.nContent.GetIndex();
324 if( pCpyNd || pEndNdIdx )
326 SwNodeRange aRg( pStt->nNode, 0, pEnd->nNode, 1 );
327 rDoc.GetNodes()._MoveNodes( aRg, rNds, aPos.nNode, FALSE );
328 aPos.nContent = 0;
329 aPos.nNode--;
331 else
333 rDoc.GetNodes().Move( rPaM, aPos, rNds, FALSE );
335 SwTxtNode* pTxtNd = aPos.nNode.GetNode().GetTxtNode();
336 if( pTxtNd ) // fuege einen Trenner fuer die Attribute ein !
338 // weil aber beim Insert die Attribute angefasst/sprich
339 // aus dem Array geloescht und wieder eingefuegt werden, koennen
340 // dadurch Attribute verschwinden (z.B "Fett aus" von 10-20,
341 // "Fett an" von 12-15, dann wird durchs Insert/Delete das
342 // "Fett an" geloescht !! Ist hier aber nicht erwuenscht !!)
343 // DARUM: nicht die Hints anfassen, direct den String manipulieren
345 String& rStr = (String&)pTxtNd->GetTxt();
346 // Zur Sicherheit lieber nur wenn wirklich am Ende steht
347 if( rStr.Len() == aPos.nContent.GetIndex() )
349 rStr.Insert( ' ' );
350 ++aPos.nContent;
352 else
353 pTxtNd->Insert( ' ', aPos.nContent, INS_NOHINTEXPAND);
356 if( pEndNdIdx )
357 *pEndNdIdx = aPos.nNode.GetIndex();
358 if( pEndCntIdx )
359 *pEndCntIdx = aPos.nContent.GetIndex();
361 // alte Position
362 aPos.nNode = nTmpMvNode;
363 if( pNodeIdx )
364 *pNodeIdx = aPos.nNode;
366 if( pCntIdx )
368 SwCntntNode* pCNd = aPos.nNode.GetNode().GetCntntNode();
369 if( pCNd )
370 pCntIdx->Assign( pCNd, nTmpMvCntnt );
371 else
372 pCntIdx->Assign( 0, 0 );
375 rDoc.DoUndo( bUndo );
378 void SwUndoSaveCntnt::MoveFromUndoNds( SwDoc& rDoc, ULONG nNodeIdx,
379 xub_StrLen nCntIdx, SwPosition& rInsPos,
380 ULONG* pEndNdIdx, xub_StrLen* pEndCntIdx )
382 // jetzt kommt das wiederherstellen
383 SwNodes& rNds = (SwNodes&)*rDoc.GetUndoNds();
384 if( nNodeIdx == rNds.GetEndOfPostIts().GetIndex() )
385 return; // nichts gespeichert
387 BOOL bUndo = rDoc.DoesUndo();
388 rDoc.DoUndo( FALSE );
390 SwPaM aPaM( rInsPos );
391 if( pEndNdIdx ) // dann hole aus diesem den Bereich
392 aPaM.GetPoint()->nNode.Assign( rNds, *pEndNdIdx );
393 else
395 aPaM.GetPoint()->nNode = rNds.GetEndOfExtras();
396 GoInCntnt( aPaM, fnMoveBackward );
399 SwTxtNode* pTxtNd = aPaM.GetNode()->GetTxtNode();
400 if( !pEndNdIdx && pTxtNd ) // loesche den Trenner wieder
402 if( pEndCntIdx )
403 aPaM.GetPoint()->nContent.Assign( pTxtNd, *pEndCntIdx );
404 if( pTxtNd->GetTxt().Len() )
406 GoInCntnt( aPaM, fnMoveBackward );
407 pTxtNd->Erase( aPaM.GetPoint()->nContent, 1 );
410 aPaM.SetMark();
411 aPaM.GetPoint()->nNode = nNodeIdx;
412 aPaM.GetPoint()->nContent.Assign( aPaM.GetCntntNode(), nCntIdx );
414 _SaveRedlEndPosForRestore aRedlRest( rInsPos.nNode, rInsPos.nContent.GetIndex() );
416 rNds.Move( aPaM, rInsPos, rDoc.GetNodes() );
418 // noch den letzen Node loeschen.
419 if( !aPaM.GetPoint()->nContent.GetIndex() ||
420 ( aPaM.GetPoint()->nNode++ && // noch leere Nodes am Ende ??
421 &rNds.GetEndOfExtras() != &aPaM.GetPoint()->nNode.GetNode() ))
423 aPaM.GetPoint()->nContent.Assign( 0, 0 );
424 aPaM.SetMark();
425 rNds.Delete( aPaM.GetPoint()->nNode,
426 rNds.GetEndOfExtras().GetIndex() -
427 aPaM.GetPoint()->nNode.GetIndex() );
430 aRedlRest.Restore();
432 else if( pEndNdIdx || !pTxtNd )
434 SwNodeRange aRg( rNds, nNodeIdx, rNds, (pEndNdIdx
435 ? ((*pEndNdIdx) + 1)
436 : rNds.GetEndOfExtras().GetIndex() ) );
437 rNds._MoveNodes( aRg, rDoc.GetNodes(), rInsPos.nNode, 0 == pEndNdIdx );
440 else {
441 ASSERT( FALSE, "was ist es denn nun?" );
444 rDoc.DoUndo( bUndo );
447 // diese beiden Methoden bewegen den Point vom Pam zurueck/vor. Damit
448 // kann fuer ein Undo/Redo ein Bereich aufgespannt werden. (Der
449 // Point liegt dann vor dem manipuliertem Bereich !!)
450 // Das Flag gibt an, ob noch vorm Point Inhalt steht.
452 BOOL SwUndoSaveCntnt::MovePtBackward( SwPaM& rPam )
454 rPam.SetMark();
455 if( rPam.Move( fnMoveBackward ))
456 return TRUE;
458 // gibt es nach vorne keinen Inhalt mehr, so setze den Point einfach
459 // auf die vorherige Position (Node und Content, damit der Content
460 // abgemeldet wird !!)
461 rPam.GetPoint()->nNode--;
462 rPam.GetPoint()->nContent.Assign( 0, 0 );
463 return FALSE;
466 void SwUndoSaveCntnt::MovePtForward( SwPaM& rPam, BOOL bMvBkwrd )
468 // gab es noch Inhalt vor der Position ?
469 if( bMvBkwrd )
470 rPam.Move( fnMoveForward );
471 else
472 { // setzen Point auf die naechste Position
473 rPam.GetPoint()->nNode++;
474 SwCntntNode* pCNd = rPam.GetCntntNode();
475 if( pCNd )
476 pCNd->MakeStartIndex( &rPam.GetPoint()->nContent );
477 else
478 rPam.Move( fnMoveForward );
484 JP 21.03.94: loesche alle Objecte, die ContentIndizies auf den ang.
485 Bereich besitzen.
486 Zur Zeit gibts folgende Objecte
487 - Fussnoten
488 - Flys
489 - Bookmarks
490 - Verzeichnisse
492 // --> OD 2007-10-17 #i81002# - extending method:
493 // delete certain (not all) cross-reference bookmarks at text node of <rMark>
494 // and at text node of <rPoint>, if these text nodes aren't the same.
495 void SwUndoSaveCntnt::DelCntntIndex( const SwPosition& rMark,
496 const SwPosition& rPoint,
497 DelCntntType nDelCntntType )
499 const SwPosition *pStt = rMark < rPoint ? &rMark : &rPoint,
500 *pEnd = &rMark == pStt ? &rPoint : &rMark;
502 SwDoc* pDoc = rMark.nNode.GetNode().GetDoc();
504 BOOL bDoesUndo = pDoc->DoesUndo();
505 pDoc->DoUndo( FALSE );
507 // 1. Fussnoten
508 if( nsDelCntntType::DELCNT_FTN & nDelCntntType )
510 SwFtnIdxs& rFtnArr = pDoc->GetFtnIdxs();
511 if( rFtnArr.Count() )
513 const SwNode* pFtnNd;
514 USHORT nPos;
515 rFtnArr.SeekEntry( pStt->nNode, &nPos );
516 SwTxtFtn* pSrch;
518 // loesche erstmal alle, die dahinter stehen
519 while( nPos < rFtnArr.Count() && ( pFtnNd =
520 &( pSrch = rFtnArr[ nPos ] )->GetTxtNode())->GetIndex()
521 <= pEnd->nNode.GetIndex() )
523 xub_StrLen nFtnSttIdx = *pSrch->GetStart();
524 if( (nsDelCntntType::DELCNT_CHKNOCNTNT & nDelCntntType )
525 ? (&pEnd->nNode.GetNode() == pFtnNd )
526 : (( &pStt->nNode.GetNode() == pFtnNd &&
527 pStt->nContent.GetIndex() > nFtnSttIdx) ||
528 ( &pEnd->nNode.GetNode() == pFtnNd &&
529 nFtnSttIdx >= pEnd->nContent.GetIndex() )) )
531 ++nPos; // weiter suchen
532 continue;
535 // es muss leider ein Index angelegt werden. Sonst knallts im
536 // TextNode, weil im DTOR der SwFtn dieser geloescht wird !!
537 SwTxtNode* pTxtNd = (SwTxtNode*)pFtnNd;
538 if( !pHistory )
539 pHistory = new SwHistory;
540 SwTxtAttr* pFtnHnt = pTxtNd->GetTxtAttr( nFtnSttIdx );
541 ASSERT( pFtnHnt, "kein FtnAttribut" );
542 SwIndex aIdx( pTxtNd, nFtnSttIdx );
543 pHistory->Add( pFtnHnt, pTxtNd->GetIndex(), false );
544 pTxtNd->Erase( aIdx, 1 );
547 while( nPos-- && ( pFtnNd = &( pSrch = rFtnArr[ nPos ] )->
548 GetTxtNode())->GetIndex() >= pStt->nNode.GetIndex() )
550 xub_StrLen nFtnSttIdx = *pSrch->GetStart();
551 if( !(nsDelCntntType::DELCNT_CHKNOCNTNT & nDelCntntType) && (
552 ( &pStt->nNode.GetNode() == pFtnNd &&
553 pStt->nContent.GetIndex() > nFtnSttIdx ) ||
554 ( &pEnd->nNode.GetNode() == pFtnNd &&
555 nFtnSttIdx >= pEnd->nContent.GetIndex() )))
556 continue; // weiter suchen
558 // es muss leider ein Index angelegt werden. Sonst knallts im
559 // TextNode, weil im DTOR der SwFtn dieser geloescht wird !!
560 SwTxtNode* pTxtNd = (SwTxtNode*)pFtnNd;
561 if( !pHistory )
562 pHistory = new SwHistory;
563 SwTxtAttr* pFtnHnt = pTxtNd->GetTxtAttr( nFtnSttIdx );
564 ASSERT( pFtnHnt, "kein FtnAttribut" );
565 SwIndex aIdx( pTxtNd, nFtnSttIdx );
566 pHistory->Add( pFtnHnt, pTxtNd->GetIndex(), false );
567 pTxtNd->Erase( aIdx, 1 );
572 // 2. Flys
573 if( nsDelCntntType::DELCNT_FLY & nDelCntntType )
575 USHORT nChainInsPos = pHistory ? pHistory->Count() : 0;
576 const SwSpzFrmFmts& rSpzArr = *pDoc->GetSpzFrmFmts();
577 if( rSpzArr.Count() )
579 const BOOL bDelFwrd = rMark.nNode.GetIndex() <= rPoint.nNode.GetIndex();
580 SwFlyFrmFmt* pFmt;
581 const SwFmtAnchor* pAnchor;
582 USHORT n = rSpzArr.Count();
583 const SwPosition* pAPos;
585 while( n && rSpzArr.Count() )
587 pFmt = (SwFlyFrmFmt*)rSpzArr[--n];
588 pAnchor = &pFmt->GetAnchor();
589 switch( pAnchor->GetAnchorId() )
591 case FLY_IN_CNTNT:
592 if( 0 != (pAPos = pAnchor->GetCntntAnchor() ) &&
593 (( nsDelCntntType::DELCNT_CHKNOCNTNT & nDelCntntType )
594 ? ( pStt->nNode <= pAPos->nNode &&
595 pAPos->nNode < pEnd->nNode )
596 : ( *pStt <= *pAPos && *pAPos < *pEnd )) )
598 if( !pHistory )
599 pHistory = new SwHistory;
600 SwTxtNode* pTxtNd = pDoc->GetNodes()[ pAPos->nNode]->GetTxtNode();
601 SwTxtAttr* pFlyHnt = pTxtNd->GetTxtAttr( pAPos->nContent.GetIndex());
602 ASSERT( pFlyHnt, "kein FlyAttribut" );
603 pHistory->Add( pFlyHnt, 0, false );
604 // n wieder zurueck, damit nicht ein Format uebesprungen wird !
605 n = n >= rSpzArr.Count() ? rSpzArr.Count() : n+1;
607 break;
608 case FLY_AT_CNTNT:
610 pAPos = pAnchor->GetCntntAnchor();
611 if( pAPos )
613 bool bTmp;
614 if( nsDelCntntType::DELCNT_CHKNOCNTNT & nDelCntntType )
615 bTmp = pStt->nNode <= pAPos->nNode && pAPos->nNode < pEnd->nNode;
616 else
618 if (bDelFwrd)
619 bTmp = rMark.nNode < pAPos->nNode &&
620 pAPos->nNode <= rPoint.nNode;
621 else
622 bTmp = rPoint.nNode <= pAPos->nNode &&
623 pAPos->nNode < rMark.nNode;
626 if (bTmp)
628 if( !pHistory )
629 pHistory = new SwHistory;
631 // Moving the anchor?
632 if( !( nsDelCntntType::DELCNT_CHKNOCNTNT & nDelCntntType ) &&
633 ( rPoint.nNode.GetIndex() == pAPos->nNode.GetIndex() ) )
635 // Do not try to move the anchor to a table!
636 if( rMark.nNode.GetNode().GetTxtNode() )
638 pHistory->Add( *pFmt );
639 SwFmtAnchor aAnch( *pAnchor );
640 SwPosition aPos( rMark.nNode );
641 aAnch.SetAnchor( &aPos );
642 pFmt->SetFmtAttr( aAnch );
645 else
647 pHistory->Add( *pFmt, nChainInsPos );
648 // n wieder zurueck, damit nicht ein
649 // Format uebesprungen wird !
650 n = n >= rSpzArr.Count() ?
651 rSpzArr.Count() : n+1;
656 break;
657 case FLY_AUTO_CNTNT:
658 if( 0 != (pAPos = pAnchor->GetCntntAnchor() ) &&
659 ( pStt->nNode <= pAPos->nNode && pAPos->nNode <= pEnd->nNode ) )
661 if( !pHistory )
662 pHistory = new SwHistory;
663 if( pAPos->nNode < pEnd->nNode &&
664 ( ( nsDelCntntType::DELCNT_CHKNOCNTNT & nDelCntntType ) ||
665 ( pStt->nNode < pAPos->nNode || !pStt->nContent.GetIndex() ) ) )
667 // Here we identified the objects to destroy:
668 // - anchored between start and end of the selection
669 // - anchored in start of the selection with "CheckNoContent"
670 // - anchored in start of sel. and the selection start at pos 0
671 pHistory->Add( *pFmt, nChainInsPos );
672 n = n >= rSpzArr.Count() ? rSpzArr.Count() : n+1;
674 else if( !( nsDelCntntType::DELCNT_CHKNOCNTNT & nDelCntntType ) )
676 if( *pStt <= *pAPos && *pAPos < *pEnd )
678 // These are the objects anchored
679 // between section start and end position
680 // Do not try to move the anchor to a table!
681 if( rMark.nNode.GetNode().GetTxtNode() )
683 pHistory->Add( *pFmt );
684 SwFmtAnchor aAnch( *pAnchor );
685 aAnch.SetAnchor( &rMark );
686 pFmt->SetFmtAttr( aAnch );
691 break;
692 case FLY_AT_FLY:
694 if( 0 != (pAPos = pAnchor->GetCntntAnchor() ) &&
695 pStt->nNode == pAPos->nNode )
697 if( !pHistory )
698 pHistory = new SwHistory;
700 pHistory->Add( *pFmt, nChainInsPos );
702 // n wieder zurueck, damit nicht ein Format uebesprungen wird !
703 n = n >= rSpzArr.Count() ? rSpzArr.Count() : n+1;
705 break;
706 default: break;
712 // 3. Bookmarks
713 if( nsDelCntntType::DELCNT_BKM & nDelCntntType )
715 IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
716 if( pMarkAccess->getMarksCount() )
719 for( USHORT n = 0; n < pMarkAccess->getMarksCount(); ++n )
721 // --> OD 2007-10-17 #i81002#
722 bool bSavePos = false;
723 bool bSaveOtherPos = false;
724 const ::sw::mark::IMark* pBkmk = (pMarkAccess->getMarksBegin() + n)->get();
725 if( nsDelCntntType::DELCNT_CHKNOCNTNT & nDelCntntType )
727 if( pStt->nNode <= pBkmk->GetMarkPos().nNode &&
728 pBkmk->GetMarkPos().nNode < pEnd->nNode )
729 bSavePos = true;
730 if( pBkmk->IsExpanded() &&
731 pStt->nNode <= pBkmk->GetOtherMarkPos().nNode &&
732 pBkmk->GetOtherMarkPos().nNode < pEnd->nNode )
733 bSaveOtherPos = true;
735 else
737 // --> OD 2009-08-06 #i92125#
738 bool bKeepCrossRefBkmk( false );
740 if ( rMark.nNode == rPoint.nNode &&
741 ( IDocumentMarkAccess::GetType(*pBkmk) ==
742 IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK ||
743 IDocumentMarkAccess::GetType(*pBkmk) ==
744 IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK ) )
746 bKeepCrossRefBkmk = true;
749 if ( !bKeepCrossRefBkmk )
751 bool bMaybe = false;
752 if ( *pStt <= pBkmk->GetMarkPos() && pBkmk->GetMarkPos() <= *pEnd )
754 if( pBkmk->GetMarkPos() == *pEnd ||
755 ( *pStt == pBkmk->GetMarkPos() && pBkmk->IsExpanded() ) )
756 bMaybe = true;
757 else
758 bSavePos = true;
760 if( pBkmk->IsExpanded() &&
761 *pStt <= pBkmk->GetOtherMarkPos() && pBkmk->GetOtherMarkPos() <= *pEnd )
763 if( bSavePos || bSaveOtherPos ||
764 ( pBkmk->GetOtherMarkPos() < *pEnd && pBkmk->GetOtherMarkPos() > *pStt ) )
766 if( bMaybe )
767 bSavePos = true;
768 bSaveOtherPos = true;
772 // <--
774 // --> OD 2007-10-17 #i81002#
775 const bool bDifferentTxtNodesAtMarkAndPoint(
776 rMark.nNode != rPoint.nNode &&
777 rMark.nNode.GetNode().GetTxtNode() &&
778 rPoint.nNode.GetNode().GetTxtNode() );
779 // <--
780 if( !bSavePos && !bSaveOtherPos && bDifferentTxtNodesAtMarkAndPoint &&
781 dynamic_cast< const ::sw::mark::CrossRefBookmark* >(pBkmk))
783 // delete cross-reference bookmark at <pStt>, if only part of
784 // <pEnd> text node content is deleted.
785 if( pStt->nNode == pBkmk->GetMarkPos().nNode &&
786 pEnd->nContent.GetIndex() !=
787 pEnd->nNode.GetNode().GetTxtNode()->Len() )
789 bSavePos = true;
790 bSaveOtherPos = false;
792 // delete cross-reference bookmark at <pEnd>, if only part of
793 // <pStt> text node content is deleted.
794 else if( pEnd->nNode == pBkmk->GetMarkPos().nNode &&
795 pStt->nContent.GetIndex() != 0 )
797 bSavePos = true;
798 bSaveOtherPos = false;
802 if( bSavePos || bSaveOtherPos )
804 if( !pHistory )
805 pHistory = new SwHistory;
807 pHistory->Add( *pBkmk, bSavePos, bSaveOtherPos );
808 if(bSavePos &&
809 (bSaveOtherPos || !pBkmk->IsExpanded()))
811 pMarkAccess->deleteMark(pMarkAccess->getMarksBegin()+n);
812 n--;
819 pDoc->DoUndo( bDoesUndo );
823 // sicher eine vollstaendige Section im Undo-Nodes-Array
825 SwUndoSaveSection::SwUndoSaveSection()
826 : pMvStt( 0 ), pRedlSaveData( 0 ), nMvLen( 0 ), nStartPos( ULONG_MAX )
830 SwUndoSaveSection::~SwUndoSaveSection()
832 if( pMvStt ) // loesche noch den Bereich aus dem UndoNodes Array
834 // SaveSection speichert den Inhalt in der PostIt-Section
835 SwNodes& rUNds = pMvStt->GetNode().GetNodes();
836 rUNds.Delete( *pMvStt, nMvLen );
838 delete pMvStt;
840 delete pRedlSaveData;
843 void SwUndoSaveSection::SaveSection( SwDoc* pDoc, const SwNodeIndex& rSttIdx )
845 SwNodeRange aRg( rSttIdx.GetNode(), *rSttIdx.GetNode().EndOfSectionNode() );
846 SaveSection( pDoc, aRg );
850 void SwUndoSaveSection::SaveSection( SwDoc* , const SwNodeRange& rRange )
852 SwPaM aPam( rRange.aStart, rRange.aEnd );
854 // loesche alle Fussnoten / FlyFrames / Bookmarks / Verzeichnisse
855 DelCntntIndex( *aPam.GetMark(), *aPam.GetPoint() );
857 pRedlSaveData = new SwRedlineSaveDatas;
858 if( !SwUndo::FillSaveData( aPam, *pRedlSaveData, TRUE, TRUE ))
859 delete pRedlSaveData, pRedlSaveData = 0;
861 nStartPos = rRange.aStart.GetIndex();
863 aPam.GetPoint()->nNode--;
864 aPam.GetMark()->nNode++;
866 SwCntntNode* pCNd = aPam.GetCntntNode( FALSE );
867 if( pCNd )
868 aPam.GetMark()->nContent.Assign( pCNd, 0 );
869 if( 0 != ( pCNd = aPam.GetCntntNode( TRUE )) )
870 aPam.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
872 // Positionen als SwIndex merken, damit im DTOR dieser Bereich
873 // entfernt werden kann !!
874 ULONG nEnd;
875 pMvStt = new SwNodeIndex( rRange.aStart );
876 MoveToUndoNds( aPam, pMvStt, 0, &nEnd, 0 );
877 nMvLen = nEnd - pMvStt->GetIndex() + 1;
880 void SwUndoSaveSection::RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx,
881 USHORT nSectType )
883 if( ULONG_MAX != nStartPos ) // gab es ueberhaupt Inhalt ?
885 // ueberpruefe, ob der Inhalt an der alten Position steht
886 SwNodeIndex aSttIdx( pDoc->GetNodes(), nStartPos );
887 ASSERT( !pDoc->GetNodes()[ aSttIdx ]->GetCntntNode(),
888 "Position in irgendeiner Section" );
890 // move den Inhalt aus dem UndoNodes-Array in den Fly
891 SwStartNode* pSttNd = pDoc->GetNodes().MakeEmptySection( aSttIdx,
892 (SwStartNodeType)nSectType );
894 RestoreSection( pDoc, SwNodeIndex( *pSttNd->EndOfSectionNode() ));
896 if( pIdx )
897 *pIdx = *pSttNd;
901 void SwUndoSaveSection::RestoreSection( SwDoc* pDoc, const SwNodeIndex& rInsPos )
903 if( ULONG_MAX != nStartPos ) // gab es ueberhaupt Inhalt ?
905 SwPosition aInsPos( rInsPos );
906 ULONG nEnd = pMvStt->GetIndex() + nMvLen - 1;
907 MoveFromUndoNds( *pDoc, pMvStt->GetIndex(), 0, aInsPos, &nEnd, 0 );
909 // Indizies wieder zerstoren, Inhalt ist aus dem UndoNodes-Array
910 // entfernt worden.
911 DELETEZ( pMvStt );
912 nMvLen = 0;
914 if( pRedlSaveData )
916 SwUndo::SetSaveData( *pDoc, *pRedlSaveData );
917 delete pRedlSaveData, pRedlSaveData = 0;
922 // START
923 SwUndoStart::SwUndoStart( SwUndoId nInitId )
924 : SwUndo( UNDO_START ), nUserId( nInitId ), nEndOffset( 0 )
928 void SwUndoStart::Undo( SwUndoIter& rUndoIter )
930 if( !( --rUndoIter.nEndCnt ) && rUndoIter.bWeiter &&
931 ( rUndoIter.GetId() ? ( rUndoIter.GetId() == nUserId ||
932 ( UNDO_END == rUndoIter.GetId() && UNDO_START == GetId() )) : TRUE ))
933 rUndoIter.bWeiter = FALSE;
936 void SwUndoStart::Redo( SwUndoIter& rUndoIter )
938 rUndoIter.bWeiter = TRUE;
939 ++rUndoIter.nEndCnt;
942 void SwUndoStart::Repeat( SwUndoIter& rUndoIter )
944 rUndoIter.bWeiter = FALSE;
947 String SwUndoStart::GetComment() const
949 String sResult;
951 switch (nUserId)
953 case UNDO_START:
954 case UNDO_END:
955 sResult = String("??", RTL_TEXTENCODING_ASCII_US);
957 break;
959 default:
960 sResult = String(SW_RES(UNDO_BASE + nUserId));
961 sResult = GetRewriter().Apply(sResult);
964 return sResult;
967 SwRewriter SwUndoStart::GetRewriter() const
969 return mRewriter;
972 SwUndoId SwUndoStart::GetEffectiveId() const
974 return GetUserId();
977 void SwUndoStart::SetRewriter(const SwRewriter & rRewriter)
979 mRewriter = rRewriter;
982 // END
983 SwUndoEnd::SwUndoEnd( SwUndoId nInitId )
984 : SwUndo( UNDO_END ), nUserId( nInitId ), nSttOffset( 0 )
988 void SwUndoEnd::Undo( SwUndoIter& rUndoIter )
990 if( rUndoIter.GetId() == GetId() || !rUndoIter.GetId() )
991 rUndoIter.bWeiter = TRUE;
992 if( rUndoIter.bWeiter )
993 ++rUndoIter.nEndCnt;
996 void SwUndoEnd::Redo( SwUndoIter& rUndoIter )
998 if( !( --rUndoIter.nEndCnt ) && rUndoIter.bWeiter &&
999 ( rUndoIter.GetId() ? ( rUndoIter.GetId() == nUserId ||
1000 ( UNDO_END == rUndoIter.GetId() && UNDO_START == GetId() )) : TRUE ))
1001 rUndoIter.bWeiter = FALSE;
1004 void SwUndoEnd::Repeat( SwUndoIter& rUndoIter )
1006 rUndoIter.bWeiter = FALSE;
1009 String SwUndoEnd::GetComment() const
1011 String sResult;
1013 switch (nUserId)
1015 case UNDO_START:
1016 case UNDO_END:
1017 sResult = String("??", RTL_TEXTENCODING_ASCII_US);
1019 break;
1020 default:
1021 sResult = SW_RES(UNDO_BASE + nUserId);
1022 sResult = GetRewriter().Apply(sResult);
1025 return sResult;
1028 void SwUndoEnd::SetRewriter(const SwRewriter & rRewriter)
1030 mRewriter = rRewriter;
1033 SwUndoId SwUndoEnd::GetEffectiveId() const
1035 return GetUserId();
1038 SwRewriter SwUndoEnd::GetRewriter() const
1040 return mRewriter;
1043 /* \f */
1044 // sicher und setze die RedlineDaten
1046 SwRedlineSaveData::SwRedlineSaveData( SwComparePosition eCmpPos,
1047 const SwPosition& rSttPos,
1048 const SwPosition& rEndPos,
1049 SwRedline& rRedl,
1050 BOOL bCopyNext )
1051 : SwUndRng( rRedl ),
1052 SwRedlineData( rRedl.GetRedlineData(), bCopyNext )
1054 ASSERT( POS_OUTSIDE == eCmpPos ||
1055 !rRedl.GetContentIdx(), "Redline mit Content" );
1057 switch( eCmpPos )
1059 case POS_OVERLAP_BEFORE: // Pos1 ueberlappt Pos2 am Anfang
1060 nEndNode = rEndPos.nNode.GetIndex();
1061 nEndCntnt = rEndPos.nContent.GetIndex();
1062 break;
1063 case POS_OVERLAP_BEHIND: // Pos1 ueberlappt Pos2 am Ende
1064 nSttNode = rSttPos.nNode.GetIndex();
1065 nSttCntnt = rSttPos.nContent.GetIndex();
1066 break;
1068 case POS_INSIDE: // Pos1 liegt vollstaendig in Pos2
1069 nSttNode = rSttPos.nNode.GetIndex();
1070 nSttCntnt = rSttPos.nContent.GetIndex();
1071 nEndNode = rEndPos.nNode.GetIndex();
1072 nEndCntnt = rEndPos.nContent.GetIndex();
1073 break;
1075 case POS_OUTSIDE: // Pos2 liegt vollstaendig in Pos1
1076 if( rRedl.GetContentIdx() )
1078 // dann den Bereich ins UndoArray verschieben und merken
1079 SaveSection( rRedl.GetDoc(), *rRedl.GetContentIdx() );
1080 rRedl.SetContentIdx( 0 );
1082 break;
1084 case POS_EQUAL: // Pos1 ist genauso gross wie Pos2
1085 break;
1087 default:
1088 ASSERT( !this, "keine gueltigen Daten!" )
1091 #ifndef PRODUCT
1092 nRedlineCount = rSttPos.nNode.GetNode().GetDoc()->GetRedlineTbl().Count();
1093 #endif
1096 SwRedlineSaveData::~SwRedlineSaveData()
1100 void SwRedlineSaveData::RedlineToDoc( SwPaM& rPam )
1102 SwDoc& rDoc = *rPam.GetDoc();
1103 SwRedline* pRedl = new SwRedline( *this, rPam );
1105 if( GetMvSttIdx() )
1107 SwNodeIndex aIdx( rDoc.GetNodes() );
1108 RestoreSection( &rDoc, &aIdx, SwNormalStartNode );
1109 if( GetHistory() )
1110 GetHistory()->Rollback( &rDoc );
1111 pRedl->SetContentIdx( &aIdx );
1113 SetPaM( *pRedl );
1114 // erstmal die "alten" entfernen, damit im Append keine unerwarteten
1115 // Dinge passieren, wie z.B. eine Delete in eigenen Insert. Dann wird
1116 // naehmlich das gerade restaurierte wieder geloescht - nicht das gewollte
1117 rDoc.DeleteRedline( *pRedl, false, USHRT_MAX );
1119 RedlineMode_t eOld = rDoc.GetRedlineMode();
1120 rDoc.SetRedlineMode_intern((RedlineMode_t)(eOld | nsRedlineMode_t::REDLINE_DONTCOMBINE_REDLINES));
1121 //#i92154# let UI know about a new redline with comment
1122 if (rDoc.GetDocShell() && (pRedl->GetComment() != String(::rtl::OUString::createFromAscii(""))) )
1123 rDoc.GetDocShell()->Broadcast(SwRedlineHint(pRedl,SWREDLINE_INSERTED));
1125 rDoc.AppendRedline( pRedl, true );
1126 rDoc.SetRedlineMode_intern( eOld );
1129 BOOL SwUndo::FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
1130 BOOL bDelRange, BOOL bCopyNext )
1132 if( rSData.Count() )
1133 rSData.DeleteAndDestroy( 0, rSData.Count() );
1135 SwRedlineSaveData* pNewData;
1136 const SwPosition *pStt = rRange.Start(), *pEnd = rRange.End();
1137 const SwRedlineTbl& rTbl = rRange.GetDoc()->GetRedlineTbl();
1138 USHORT n = 0;
1139 rRange.GetDoc()->GetRedline( *pStt, &n );
1140 for( ; n < rTbl.Count(); ++n )
1142 SwRedline* pRedl = rTbl[ n ];
1143 const SwPosition *pRStt = pRedl->Start(), *pREnd = pRedl->End();
1145 SwComparePosition eCmpPos = ComparePosition( *pStt, *pEnd, *pRStt, *pREnd );
1146 if( POS_BEFORE != eCmpPos && POS_BEHIND != eCmpPos &&
1147 POS_COLLIDE_END != eCmpPos && POS_COLLIDE_START != eCmpPos )
1149 pNewData = new SwRedlineSaveData( eCmpPos, *pStt, *pEnd,
1150 *pRedl, bCopyNext );
1151 rSData.Insert( pNewData, rSData.Count() );
1154 if( rSData.Count() && bDelRange )
1155 rRange.GetDoc()->DeleteRedline( rRange, false, USHRT_MAX );
1156 return 0 != rSData.Count();
1159 BOOL SwUndo::FillSaveDataForFmt( const SwPaM& rRange, SwRedlineSaveDatas& rSData )
1161 if( rSData.Count() )
1162 rSData.DeleteAndDestroy( 0, rSData.Count() );
1164 SwRedlineSaveData* pNewData;
1165 const SwPosition *pStt = rRange.Start(), *pEnd = rRange.End();
1166 const SwRedlineTbl& rTbl = rRange.GetDoc()->GetRedlineTbl();
1167 USHORT n = 0;
1168 rRange.GetDoc()->GetRedline( *pStt, &n );
1169 for( ; n < rTbl.Count(); ++n )
1171 SwRedline* pRedl = rTbl[ n ];
1172 if( nsRedlineType_t::REDLINE_FORMAT == pRedl->GetType() )
1174 const SwPosition *pRStt = pRedl->Start(), *pREnd = pRedl->End();
1176 SwComparePosition eCmpPos = ComparePosition( *pStt, *pEnd, *pRStt, *pREnd );
1177 if( POS_BEFORE != eCmpPos && POS_BEHIND != eCmpPos &&
1178 POS_COLLIDE_END != eCmpPos && POS_COLLIDE_START != eCmpPos )
1180 pNewData = new SwRedlineSaveData( eCmpPos, *pStt, *pEnd,
1181 *pRedl, TRUE );
1182 rSData.Insert( pNewData, rSData.Count() );
1188 return 0 != rSData.Count();
1191 void SwUndo::SetSaveData( SwDoc& rDoc, const SwRedlineSaveDatas& rSData )
1193 RedlineMode_t eOld = rDoc.GetRedlineMode();
1194 rDoc.SetRedlineMode_intern( (RedlineMode_t)(( eOld & ~nsRedlineMode_t::REDLINE_IGNORE) | nsRedlineMode_t::REDLINE_ON ));
1195 SwPaM aPam( rDoc.GetNodes().GetEndOfContent() );
1197 for( USHORT n = rSData.Count(); n; )
1198 rSData[ --n ]->RedlineToDoc( aPam );
1200 // check redline count against count saved in RedlineSaveData object
1201 DBG_ASSERT( (rSData.Count() == 0) ||
1202 (rSData[0]->nRedlineCount == rDoc.GetRedlineTbl().Count()),
1203 "redline count not restored properly" );
1205 rDoc.SetRedlineMode_intern( eOld );
1208 BOOL SwUndo::HasHiddenRedlines( const SwRedlineSaveDatas& rSData )
1210 for( USHORT n = rSData.Count(); n; )
1211 if( rSData[ --n ]->GetMvSttIdx() )
1212 return TRUE;
1213 return FALSE;
1216 BOOL SwUndo::CanRedlineGroup( SwRedlineSaveDatas& rCurr,
1217 const SwRedlineSaveDatas& rCheck, BOOL bCurrIsEnd )
1219 BOOL bRet = FALSE;
1220 USHORT n;
1222 if( rCurr.Count() == rCheck.Count() )
1224 bRet = TRUE;
1225 for( n = 0; n < rCurr.Count(); ++n )
1227 const SwRedlineSaveData& rSet = *rCurr[ n ];
1228 const SwRedlineSaveData& rGet = *rCheck[ n ];
1229 if( rSet.nSttNode != rGet.nSttNode ||
1230 rSet.GetMvSttIdx() || rGet.GetMvSttIdx() ||
1231 ( bCurrIsEnd ? rSet.nSttCntnt != rGet.nEndCntnt
1232 : rSet.nEndCntnt != rGet.nSttCntnt ) ||
1233 !rGet.CanCombine( rSet ) )
1235 bRet = FALSE;
1236 break;
1240 if( bRet )
1241 for( n = 0; n < rCurr.Count(); ++n )
1243 SwRedlineSaveData& rSet = *rCurr[ n ];
1244 const SwRedlineSaveData& rGet = *rCheck[ n ];
1245 if( bCurrIsEnd )
1246 rSet.nSttCntnt = rGet.nSttCntnt;
1247 else
1248 rSet.nEndCntnt = rGet.nEndCntnt;
1251 return bRet;
1254 // #111827#
1255 String ShortenString(const String & rStr, xub_StrLen nLength, const String & rFillStr)
1257 ASSERT( nLength - rFillStr.Len() >= 2, "improper arguments")
1259 String aResult;
1261 if (rStr.Len() <= nLength)
1262 aResult = rStr;
1263 else
1265 long nTmpLength = nLength - rFillStr.Len();
1266 if ( nTmpLength < 2 )
1267 nTmpLength = 2;
1269 nLength = static_cast<xub_StrLen>(nTmpLength);
1271 const xub_StrLen nFrontLen = nLength - nLength / 2;
1272 const xub_StrLen nBackLen = nLength - nFrontLen;
1274 aResult += rStr.Copy(0, nFrontLen);
1275 aResult += rFillStr;
1276 aResult += rStr.Copy(rStr.Len() - nBackLen, nBackLen);
1279 return aResult;
1282 static bool lcl_IsSpecialCharacter(sal_Unicode nChar)
1284 switch (nChar)
1286 case CH_TXTATR_BREAKWORD:
1287 case CH_TXTATR_INWORD:
1288 case CH_TXTATR_TAB:
1289 case CH_TXTATR_NEWLINE:
1290 return true;
1292 default:
1293 break;
1296 return false;
1299 static String lcl_DenotedPortion(String rStr, xub_StrLen nStart,
1300 xub_StrLen nEnd)
1302 String aResult;
1304 if (nEnd - nStart > 0)
1306 sal_Unicode cLast = rStr.GetChar(nEnd - 1);
1307 if (lcl_IsSpecialCharacter(cLast))
1309 switch(cLast)
1311 case CH_TXTATR_TAB:
1312 aResult += String(SW_RES(STR_UNDO_TABS));
1314 break;
1315 case CH_TXTATR_NEWLINE:
1316 aResult += String(SW_RES(STR_UNDO_NLS));
1318 break;
1320 case CH_TXTATR_INWORD:
1321 case CH_TXTATR_BREAKWORD:
1322 aResult += UNDO_ARG2;
1324 break;
1327 SwRewriter aRewriter;
1328 aRewriter.AddRule(UNDO_ARG1,
1329 String::CreateFromInt32(nEnd - nStart));
1330 aResult = aRewriter.Apply(aResult);
1332 else
1334 aResult = String(SW_RES(STR_START_QUOTE));
1335 aResult += rStr.Copy(nStart, nEnd - nStart);
1336 aResult += String(SW_RES(STR_END_QUOTE));
1340 return aResult;
1343 String DenoteSpecialCharacters(const String & rStr)
1345 String aResult;
1347 if (rStr.Len() > 0)
1349 bool bStart = false;
1350 xub_StrLen nStart = 0;
1351 sal_Unicode cLast = 0;
1353 for (xub_StrLen i = 0; i < rStr.Len(); i++)
1355 if (lcl_IsSpecialCharacter(rStr.GetChar(i)))
1357 if (cLast != rStr.GetChar(i))
1358 bStart = true;
1361 else
1363 if (lcl_IsSpecialCharacter(cLast))
1364 bStart = true;
1367 if (bStart)
1369 aResult += lcl_DenotedPortion(rStr, nStart, i);
1371 nStart = i;
1372 bStart = false;
1375 cLast = rStr.GetChar(i);
1378 aResult += lcl_DenotedPortion(rStr, nStart, rStr.Len());
1380 else
1381 aResult = UNDO_ARG2;
1383 return aResult;