1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <UndoInsert.hxx>
23 #include <hintids.hxx>
24 #include <unotools/charclass.hxx>
25 #include <sot/storage.hxx>
26 #include <editeng/keepitem.hxx>
27 #include <svx/svdobj.hxx>
28 #include <xmloff/odffields.hxx>
31 #include <fmtcntnt.hxx>
32 #include <fmtanchr.hxx>
35 #include <IDocumentUndoRedo.hxx>
39 #include <UndoCore.hxx>
40 #include <UndoDelete.hxx>
41 #include <UndoAttribute.hxx>
49 #include <swtable.hxx>
50 #include <redline.hxx>
52 #include <acorrect.hxx>
53 #include <dcontact.hxx>
55 #include <comcore.hrc> // #111827#
58 using namespace ::com::sun::star
;
61 //------------------------------------------------------------
65 String
* SwUndoInsert::GetTxtFromDoc() const
67 String
* pResult
= NULL
;
69 SwNodeIndex
aNd( pDoc
->GetNodes(), nNode
);
70 SwCntntNode
* pCNd
= aNd
.GetNode().GetCntntNode();
71 SwPaM
aPaM( *pCNd
, nCntnt
);
75 if( pCNd
->IsTxtNode() )
77 OUString sTxt
= static_cast<SwTxtNode
*>(pCNd
)->GetTxt();
79 sal_Int32 nStart
= nCntnt
-nLen
;
80 sal_Int32 nLength
= nLen
;
88 pResult
= new String(sTxt
.copy(nStart
, nLength
));
94 void SwUndoInsert::Init(const SwNodeIndex
& rNd
)
97 pDoc
= rNd
.GetNode().GetDoc();
98 if( pDoc
->IsRedlineOn() )
100 pRedlData
= new SwRedlineData( nsRedlineType_t::REDLINE_INSERT
,
101 pDoc
->GetRedlineAuthor() );
102 SetRedlineMode( pDoc
->GetRedlineMode() );
105 pUndoTxt
= GetTxtFromDoc();
107 bCacheComment
= false;
111 SwUndoInsert::SwUndoInsert( const SwNodeIndex
& rNd
, xub_StrLen nCnt
,
113 const IDocumentContentOperations::InsertFlags nInsertFlags
,
115 : SwUndo(UNDO_TYPING
), pTxt( 0 ), pRedlData( 0 ),
116 nNode( rNd
.GetIndex() ), nCntnt(nCnt
), nLen(nL
),
117 bIsWordDelim( bWDelim
), bIsAppend( sal_False
)
119 , m_nInsertFlags(nInsertFlags
)
125 SwUndoInsert::SwUndoInsert( const SwNodeIndex
& rNd
)
126 : SwUndo(UNDO_SPLITNODE
), pTxt( 0 ),
127 pRedlData( 0 ), nNode( rNd
.GetIndex() ), nCntnt(0), nLen(1),
128 bIsWordDelim( sal_False
), bIsAppend( sal_True
)
130 , m_nInsertFlags(IDocumentContentOperations::INS_EMPTYEXPAND
)
135 // Check if the next Insert can be combined with the current one. If so
136 // change the length and InsPos. As a result, SwDoc::Inser will not add a
137 // new object into the Undo list.
139 sal_Bool
SwUndoInsert::CanGrouping( sal_Unicode cIns
)
141 if( !bIsAppend
&& bIsWordDelim
==
142 !GetAppCharClass().isLetterNumeric( OUString( cIns
)) )
148 pUndoTxt
->Insert(cIns
);
155 sal_Bool
SwUndoInsert::CanGrouping( const SwPosition
& rPos
)
157 sal_Bool bRet
= sal_False
;
158 if( nNode
== rPos
.nNode
.GetIndex() &&
159 nCntnt
== rPos
.nContent
.GetIndex() )
162 SwDoc
& rDoc
= *rPos
.nNode
.GetNode().GetDoc();
163 if( ( ~nsRedlineMode_t::REDLINE_SHOW_MASK
& rDoc
.GetRedlineMode() ) ==
164 ( ~nsRedlineMode_t::REDLINE_SHOW_MASK
& GetRedlineMode() ) )
168 // than there is or was still an active Redline:
169 // Check if there is another Redline at the InsPosition. If the
170 // same exists only once, it can be combined.
171 const SwRedlineTbl
& rTbl
= rDoc
.GetRedlineTbl();
174 SwRedlineData
aRData( nsRedlineType_t::REDLINE_INSERT
, rDoc
.GetRedlineAuthor() );
175 const SwIndexReg
* pIReg
= rPos
.nContent
.GetIdxReg();
177 for( sal_uInt16 i
= 0; i
< rTbl
.size(); ++i
)
179 SwRedline
* pRedl
= rTbl
[ i
];
180 if( pIReg
== (pIdx
= &pRedl
->End()->nContent
)->GetIdxReg() &&
181 nCntnt
== pIdx
->GetIndex() )
183 if( !pRedl
->HasMark() || !pRedlData
||
184 *pRedl
!= *pRedlData
|| *pRedl
!= aRData
)
197 SwUndoInsert::~SwUndoInsert()
199 if (m_pUndoNodeIndex
) // delete the section from UndoNodes array
201 // Insert saves the content in IconSection
202 SwNodes
& rUNds
= m_pUndoNodeIndex
->GetNodes();
203 rUNds
.Delete(*m_pUndoNodeIndex
,
204 rUNds
.GetEndOfExtras().GetIndex() - m_pUndoNodeIndex
->GetIndex());
205 m_pUndoNodeIndex
.reset();
207 else if( pTxt
) // the inserted text
213 void SwUndoInsert::UndoImpl(::sw::UndoRedoContext
& rContext
)
215 SwDoc
*const pTmpDoc
= & rContext
.GetDoc();
216 SwPaM
*const pPam(& rContext
.GetCursorSupplier().CreateNewShellCursor());
220 pPam
->GetPoint()->nNode
= nNode
;
222 if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
224 pPam
->GetPoint()->nContent
.Assign( pPam
->GetCntntNode(), 0 );
226 pPam
->Move( fnMoveBackward
);
228 pTmpDoc
->DeleteRedline( *pPam
, true, USHRT_MAX
);
231 pTmpDoc
->DelFullPara( *pPam
);
232 pPam
->GetPoint()->nContent
.Assign( pPam
->GetCntntNode(), 0 );
236 sal_uLong nNd
= nNode
;
237 xub_StrLen nCnt
= nCntnt
;
240 SwNodeIndex
aNd( pTmpDoc
->GetNodes(), nNode
);
241 SwCntntNode
* pCNd
= aNd
.GetNode().GetCntntNode();
242 SwPaM
aPaM( *pCNd
, nCntnt
);
246 SwTxtNode
* const pTxtNode( pCNd
->GetTxtNode() );
249 aPaM
.GetPoint()->nContent
-= nLen
;
250 if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
251 pTmpDoc
->DeleteRedline( aPaM
, true, USHRT_MAX
);
254 // RSID was added: remove any CHARFMT/AUTOFMT that may be
255 // set on the deleted text; EraseText will leave empty
256 // ones behind otherwise
257 pTxtNode
->DeleteAttributes(RES_TXTATR_AUTOFMT
,
258 aPaM
.GetPoint()->nContent
.GetIndex(),
259 aPaM
.GetMark()->nContent
.GetIndex());
260 pTxtNode
->DeleteAttributes(RES_TXTATR_CHARFMT
,
261 aPaM
.GetPoint()->nContent
.GetIndex(),
262 aPaM
.GetMark()->nContent
.GetIndex());
264 RemoveIdxFromRange( aPaM
, sal_False
);
265 pTxt
= new String( pTxtNode
->GetTxt().copy(nCntnt
-nLen
, nLen
) );
266 pTxtNode
->EraseText( aPaM
.GetPoint()->nContent
, nLen
);
268 // Undo deletes fieldmarks in two step: first the end then the start position.
269 // Once the start position is deleted, make sure the fieldmark itself is deleted as well.
272 IDocumentMarkAccess
* const pMarkAccess
= pTmpDoc
->getIDocumentMarkAccess();
273 for ( IDocumentMarkAccess::const_iterator_t i
= pMarkAccess
->getMarksBegin(); i
!= pMarkAccess
->getMarksEnd(); ++i
)
275 sw::mark::IMark
* pMark
= i
->get();
276 if (pMark
->GetMarkStart() == *aPaM
.GetPoint() && pMark
->GetMarkStart().nContent
== aPaM
.GetPoint()->nContent
)
278 sw::mark::IFieldmark
* pFieldmark
= dynamic_cast<sw::mark::IFieldmark
*>(pMark
);
279 if (pFieldmark
&& pFieldmark
->GetFieldname() == ODF_COMMENTRANGE
)
281 pTmpDoc
->getIDocumentMarkAccess()->deleteMark(pMark
);
288 else // otherwise Graphics/OLE/Text/...
290 aPaM
.Move(fnMoveBackward
);
291 if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
292 pTmpDoc
->DeleteRedline( aPaM
, true, USHRT_MAX
);
293 RemoveIdxFromRange( aPaM
, sal_False
);
296 nNd
= aPaM
.GetPoint()->nNode
.GetIndex();
297 nCnt
= aPaM
.GetPoint()->nContent
.GetIndex();
301 m_pUndoNodeIndex
.reset(
302 new SwNodeIndex(pDoc
->GetNodes().GetEndOfContent()));
303 MoveToUndoNds(aPaM
, m_pUndoNodeIndex
.get());
305 nNode
= aPaM
.GetPoint()->nNode
.GetIndex();
306 nCntnt
= aPaM
.GetPoint()->nContent
.GetIndex();
309 // set cursor to Undo range
312 pPam
->GetPoint()->nNode
= nNd
;
313 pPam
->GetPoint()->nContent
.Assign(
314 pPam
->GetPoint()->nNode
.GetNode().GetCntntNode(), nCnt
);
321 void SwUndoInsert::RedoImpl(::sw::UndoRedoContext
& rContext
)
323 SwDoc
*const pTmpDoc
= & rContext
.GetDoc();
324 SwPaM
*const pPam(& rContext
.GetCursorSupplier().CreateNewShellCursor());
329 pPam
->GetPoint()->nNode
= nNode
- 1;
330 pTmpDoc
->AppendTxtNode( *pPam
->GetPoint() );
333 pPam
->Move( fnMoveBackward
);
336 if( pRedlData
&& IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
338 RedlineMode_t eOld
= pTmpDoc
->GetRedlineMode();
339 pTmpDoc
->SetRedlineMode_intern((RedlineMode_t
)(eOld
& ~nsRedlineMode_t::REDLINE_IGNORE
));
340 pTmpDoc
->AppendRedline( new SwRedline( *pRedlData
, *pPam
), true);
341 pTmpDoc
->SetRedlineMode_intern( eOld
);
343 else if( !( nsRedlineMode_t::REDLINE_IGNORE
& GetRedlineMode() ) &&
344 !pTmpDoc
->GetRedlineTbl().empty() )
345 pTmpDoc
->SplitRedline( *pPam
);
351 pPam
->GetPoint()->nNode
= nNode
;
352 SwCntntNode
*const pCNd
=
353 pPam
->GetPoint()->nNode
.GetNode().GetCntntNode();
354 pPam
->GetPoint()->nContent
.Assign( pCNd
, nCntnt
);
358 sal_Bool bMvBkwrd
= MovePtBackward( *pPam
);
362 SwTxtNode
*const pTxtNode
= pCNd
->GetTxtNode();
363 OSL_ENSURE( pTxtNode
, "where is my textnode ?" );
365 pTxtNode
->InsertText( *pTxt
, pPam
->GetMark()->nContent
,
367 assert(ins
.getLength() == pTxt
->Len()); // must succeed
369 if (m_bWithRsid
) // re-insert RSID
371 SwPaM
pam(*pPam
->GetMark(), 0); // mark -> point
372 pTmpDoc
->UpdateRsid(pam
, ins
.getLength());
377 // re-insert content again (first detach m_pUndoNodeIndex!)
378 sal_uLong
const nMvNd
= m_pUndoNodeIndex
->GetIndex();
379 m_pUndoNodeIndex
.reset();
380 MoveFromUndoNds(*pTmpDoc
, nMvNd
, *pPam
->GetMark());
382 nNode
= pPam
->GetMark()->nNode
.GetIndex();
383 nCntnt
= pPam
->GetMark()->nContent
.GetIndex();
385 MovePtForward( *pPam
, bMvBkwrd
);
387 if( pRedlData
&& IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
389 RedlineMode_t eOld
= pTmpDoc
->GetRedlineMode();
390 pTmpDoc
->SetRedlineMode_intern((RedlineMode_t
)(eOld
& ~nsRedlineMode_t::REDLINE_IGNORE
));
391 pTmpDoc
->AppendRedline( new SwRedline( *pRedlData
,
393 pTmpDoc
->SetRedlineMode_intern( eOld
);
395 else if( !( nsRedlineMode_t::REDLINE_IGNORE
& GetRedlineMode() ) &&
396 !pTmpDoc
->GetRedlineTbl().empty() )
397 pTmpDoc
->SplitRedline(*pPam
);
401 pUndoTxt
= GetTxtFromDoc();
404 void SwUndoInsert::RepeatImpl(::sw::RepeatContext
& rContext
)
409 SwDoc
& rDoc
= rContext
.GetDoc();
410 SwNodeIndex
aNd( rDoc
.GetNodes(), nNode
);
411 SwCntntNode
* pCNd
= aNd
.GetNode().GetCntntNode();
413 if( !bIsAppend
&& 1 == nLen
) // >1 than always Text, otherwise Graphics/OLE/Text/...
415 SwPaM
aPaM( *pCNd
, nCntnt
);
417 aPaM
.Move(fnMoveBackward
);
418 pCNd
= aPaM
.GetCntntNode();
421 // What happens with the possible selected range ???
423 switch( pCNd
->GetNodeType() )
428 rDoc
.AppendTxtNode( *rContext
.GetRepeatPaM().GetPoint() );
432 OUString
const aTxt( static_cast<SwTxtNode
*>(pCNd
)->GetTxt() );
433 ::sw::GroupUndoGuard
const undoGuard(rDoc
.GetIDocumentUndoRedo());
434 rDoc
.InsertString( rContext
.GetRepeatPaM(),
435 aTxt
.copy(nCntnt
- nLen
, nLen
) );
440 SwGrfNode
* pGrfNd
= (SwGrfNode
*)pCNd
;
441 String sFile
, sFilter
;
442 if( pGrfNd
->IsGrfLink() )
443 pGrfNd
->GetFileFilterNms( &sFile
, &sFilter
);
445 rDoc
.Insert( rContext
.GetRepeatPaM(), sFile
, sFilter
,
447 0/* Graphics collection*/, NULL
, NULL
);
453 // StarView does not yet provide an option to copy a StarOBJ
454 SvStorageRef aRef
= new SvStorage( aEmptyStr
);
455 SwOLEObj
& rSwOLE
= (SwOLEObj
&)((SwOLENode
*)pCNd
)->GetOLEObj();
457 // temporary storage until object is inserted
458 // TODO/MBA: seems that here a physical copy is done - not as in drawing layer! Testing!
459 // TODO/LATER: Copying through the container would copy the replacement image as well
460 comphelper::EmbeddedObjectContainer aCnt
;
461 OUString aName
= aCnt
.CreateUniqueObjectName();
462 if ( aCnt
.StoreEmbeddedObject( rSwOLE
.GetOleRef(), aName
, sal_True
) )
464 uno::Reference
< embed::XEmbeddedObject
> aNew
= aCnt
.GetEmbeddedObject( aName
);
465 rDoc
.Insert( rContext
.GetRepeatPaM(),
466 svt::EmbeddedObjectRef( aNew
,
467 static_cast<SwOLENode
*>(pCNd
)->GetAspect() ),
477 SwRewriter
SwUndoInsert::GetRewriter() const
480 String
* pStr
= NULL
;
490 String aString
= ShortenString(DenoteSpecialCharacters(*pStr
),
492 String(SW_RES(STR_LDOTS
)));
494 aResult
.AddRule(UndoArg1
, aString
);
501 aResult
.AddRule(UndoArg1
, String("??", RTL_TEXTENCODING_ASCII_US
));
508 // SwUndoReplace /////////////////////////////////////////////////////////
511 class SwUndoReplace::Impl
512 : private SwUndoSaveCntnt
516 sal_uLong m_nSttNd
, m_nEndNd
, m_nOffset
;
517 xub_StrLen m_nSttCnt
, m_nEndCnt
, m_nSetPos
, m_nSelEnd
;
518 bool m_bSplitNext
: 1;
520 // metadata references for paragraph and following para (if m_bSplitNext)
521 ::boost::shared_ptr
< ::sfx2::MetadatableUndo
> m_pMetadataUndoStart
;
522 ::boost::shared_ptr
< ::sfx2::MetadatableUndo
> m_pMetadataUndoEnd
;
525 Impl(SwPaM
const& rPam
, OUString
const& rIns
, bool const bRegExp
);
530 virtual void UndoImpl( ::sw::UndoRedoContext
& );
531 virtual void RedoImpl( ::sw::UndoRedoContext
& );
533 void SetEnd(SwPaM
const& rPam
);
535 OUString
const& GetOld() const { return m_sOld
; }
536 OUString
const& GetIns() const { return m_sIns
; }
540 SwUndoReplace::SwUndoReplace(SwPaM
const& rPam
,
541 OUString
const& rIns
, bool const bRegExp
)
542 : SwUndo( UNDO_REPLACE
)
543 , m_pImpl(new Impl(rPam
, rIns
, bRegExp
))
547 SwUndoReplace::~SwUndoReplace()
551 void SwUndoReplace::UndoImpl(::sw::UndoRedoContext
& rContext
)
553 m_pImpl
->UndoImpl(rContext
);
556 void SwUndoReplace::RedoImpl(::sw::UndoRedoContext
& rContext
)
558 m_pImpl
->RedoImpl(rContext
);
562 MakeUndoReplaceRewriter(sal_uLong
const occurrences
,
563 OUString
const& sOld
, OUString
const& sNew
)
569 aResult
.AddRule(UndoArg1
, OUString::number(occurrences
));
570 aResult
.AddRule(UndoArg2
, String(SW_RES(STR_OCCURRENCES_OF
)));
573 aTmpStr
+= String(SW_RES(STR_START_QUOTE
));
574 aTmpStr
+= ShortenString(sOld
, nUndoStringLength
,
576 aTmpStr
+= String(SW_RES(STR_END_QUOTE
));
577 aResult
.AddRule(UndoArg3
, aTmpStr
);
579 else if (1 == occurrences
)
584 aTmpStr
+= String(SW_RES(STR_START_QUOTE
));
586 aTmpStr
+= ShortenString(sOld
, nUndoStringLength
,
588 aTmpStr
+= String(SW_RES(STR_END_QUOTE
));
589 aResult
.AddRule(UndoArg1
, aTmpStr
);
592 aResult
.AddRule(UndoArg2
, String(SW_RES(STR_YIELDS
)));
597 aTmpStr
+= String(SW_RES(STR_START_QUOTE
));
599 aTmpStr
+= ShortenString(sNew
, nUndoStringLength
,
601 aTmpStr
+= String(SW_RES(STR_END_QUOTE
));
602 aResult
.AddRule(UndoArg3
, aTmpStr
);
610 SwRewriter
SwUndoReplace::GetRewriter() const
612 return MakeUndoReplaceRewriter(1, m_pImpl
->GetOld(), m_pImpl
->GetIns());
615 void SwUndoReplace::SetEnd(SwPaM
const& rPam
)
617 m_pImpl
->SetEnd(rPam
);
620 SwUndoReplace::Impl::Impl(
621 SwPaM
const& rPam
, OUString
const& rIns
, bool const bRegExp
)
627 const SwPosition
* pStt( rPam
.Start() );
628 const SwPosition
* pEnd( rPam
.End() );
630 m_nSttNd
= m_nEndNd
= pStt
->nNode
.GetIndex();
631 m_nSttCnt
= pStt
->nContent
.GetIndex();
632 m_nSelEnd
= m_nEndCnt
= pEnd
->nContent
.GetIndex();
634 m_bSplitNext
= m_nSttNd
!= pEnd
->nNode
.GetIndex();
636 SwTxtNode
* pNd
= pStt
->nNode
.GetNode().GetTxtNode();
637 OSL_ENSURE( pNd
, "Dude, where's my TextNode?" );
639 pHistory
= new SwHistory
;
640 DelCntntIndex( *rPam
.GetMark(), *rPam
.GetPoint() );
642 m_nSetPos
= pHistory
->Count();
644 sal_uLong nNewPos
= pStt
->nNode
.GetIndex();
645 m_nOffset
= m_nSttNd
- nNewPos
;
647 if ( pNd
->GetpSwpHints() )
649 pHistory
->CopyAttr( pNd
->GetpSwpHints(), nNewPos
, 0,
650 pNd
->GetTxt().getLength(), true );
655 if( pNd
->HasSwAttrSet() )
656 pHistory
->CopyFmtAttr( *pNd
->GetpSwAttrSet(), nNewPos
);
657 pHistory
->Add( pNd
->GetTxtColl(), nNewPos
, ND_TEXTNODE
);
659 SwTxtNode
* pNext
= pEnd
->nNode
.GetNode().GetTxtNode();
660 sal_uLong nTmp
= pNext
->GetIndex();
661 pHistory
->CopyAttr( pNext
->GetpSwpHints(), nTmp
, 0,
662 pNext
->GetTxt().getLength(), true );
663 if( pNext
->HasSwAttrSet() )
664 pHistory
->CopyFmtAttr( *pNext
->GetpSwAttrSet(), nTmp
);
665 pHistory
->Add( pNext
->GetTxtColl(),nTmp
, ND_TEXTNODE
);
667 m_pMetadataUndoStart
= pNd
->CreateUndo();
668 m_pMetadataUndoEnd
= pNext
->CreateUndo();
671 if( !pHistory
->Count() )
672 delete pHistory
, pHistory
= 0;
674 xub_StrLen nECnt
= m_bSplitNext
? pNd
->GetTxt().getLength()
675 : pEnd
->nContent
.GetIndex();
676 m_sOld
= pNd
->GetTxt().copy( m_nSttCnt
, nECnt
- m_nSttCnt
);
679 void SwUndoReplace::Impl::UndoImpl(::sw::UndoRedoContext
& rContext
)
681 SwDoc
*const pDoc
= & rContext
.GetDoc();
682 SwPaM
& rPam(rContext
.GetCursorSupplier().CreateNewShellCursor());
685 SwTxtNode
* pNd
= pDoc
->GetNodes()[ m_nSttNd
- m_nOffset
]->GetTxtNode();
686 OSL_ENSURE( pNd
, "Dude, where's my TextNode?" );
688 SwAutoCorrExceptWord
* pACEWord
= pDoc
->GetAutoCorrExceptWord();
691 if ((1 == m_sIns
.getLength()) && (1 == m_sOld
.getLength()))
693 SwPosition
aPos( *pNd
); aPos
.nContent
.Assign( pNd
, m_nSttCnt
);
694 pACEWord
->CheckChar( aPos
, m_sOld
[ 0 ] );
696 pDoc
->SetAutoCorrExceptWord( 0 );
699 SwIndex
aIdx( pNd
, m_nSttCnt
);
700 // don't look at m_sIns for deletion, maybe it was not completely inserted
702 rPam
.GetPoint()->nNode
= *pNd
;
703 rPam
.GetPoint()->nContent
.Assign( pNd
, m_nSttCnt
);
705 rPam
.GetPoint()->nNode
= m_nEndNd
- m_nOffset
;
706 rPam
.GetPoint()->nContent
.Assign( rPam
.GetCntntNode(), m_nEndCnt
);
707 // move it out of the way so it is not registered at deleted node
710 pDoc
->DeleteAndJoin( rPam
);
712 pNd
= rPam
.GetNode()->GetTxtNode();
713 OSL_ENSURE( pNd
, "Dude, where's my TextNode?" );
714 aIdx
.Assign( pNd
, m_nSttCnt
);
719 SwPosition
aPos( *pNd
, aIdx
);
720 pDoc
->SplitNode( aPos
, false );
721 pNd
->RestoreMetadata(m_pMetadataUndoEnd
);
722 pNd
= pDoc
->GetNodes()[ m_nSttNd
- m_nOffset
]->GetTxtNode();
723 aIdx
.Assign( pNd
, m_nSttCnt
);
725 pNd
->RestoreMetadata(m_pMetadataUndoStart
);
728 if (!m_sOld
.isEmpty())
730 OUString
const ins( pNd
->InsertText( m_sOld
, aIdx
) );
731 assert(ins
.getLength() == m_sOld
.getLength()); // must succeed
736 if( pNd
->GetpSwpHints() )
737 pNd
->ClearSwpHintsArr( true );
739 pHistory
->TmpRollback( pDoc
, m_nSetPos
, false );
740 if ( m_nSetPos
) // there were footnotes/FlyFrames
742 // are there others than these?
743 if( m_nSetPos
< pHistory
->Count() )
745 // than save those attributes as well
747 aHstr
.Move( 0, pHistory
, m_nSetPos
);
748 pHistory
->Rollback( pDoc
);
749 pHistory
->Move( 0, &aHstr
);
753 pHistory
->Rollback( pDoc
);
759 rPam
.GetPoint()->nNode
= m_nSttNd
;
760 rPam
.GetPoint()->nContent
= aIdx
;
763 void SwUndoReplace::Impl::RedoImpl(::sw::UndoRedoContext
& rContext
)
765 SwDoc
& rDoc
= rContext
.GetDoc();
766 SwPaM
& rPam(rContext
.GetCursorSupplier().CreateNewShellCursor());
768 rPam
.GetPoint()->nNode
= m_nSttNd
;
770 SwTxtNode
* pNd
= rPam
.GetPoint()->nNode
.GetNode().GetTxtNode();
771 OSL_ENSURE( pNd
, "Dude, where's my TextNode?" );
772 rPam
.GetPoint()->nContent
.Assign( pNd
, m_nSttCnt
);
776 rPam
.GetPoint()->nNode
= m_nSttNd
+ 1;
777 pNd
= rPam
.GetPoint()->nNode
.GetNode().GetTxtNode();
779 rPam
.GetPoint()->nContent
.Assign( pNd
, m_nSelEnd
);
783 SwHistory
* pSave
= pHistory
;
786 DelCntntIndex( *rPam
.GetMark(), *rPam
.GetPoint() );
787 m_nSetPos
= pHistory
->Count();
790 pHistory
->Move( 0, &aHst
);
794 pHistory
= new SwHistory
;
795 DelCntntIndex( *rPam
.GetMark(), *rPam
.GetPoint() );
796 m_nSetPos
= pHistory
->Count();
798 delete pHistory
, pHistory
= 0;
801 rDoc
.ReplaceRange( rPam
, m_sIns
, m_bRegExp
);
805 void SwUndoReplace::Impl::SetEnd(SwPaM
const& rPam
)
807 const SwPosition
* pEnd
= rPam
.End();
808 m_nEndNd
= m_nOffset
+ pEnd
->nNode
.GetIndex();
809 m_nEndCnt
= pEnd
->nContent
.GetIndex();
813 // SwUndoReRead //////////////////////////////////////////////////////////
816 SwUndoReRead::SwUndoReRead( const SwPaM
& rPam
, const SwGrfNode
& rGrfNd
)
817 : SwUndo( UNDO_REREAD
), nPos( rPam
.GetPoint()->nNode
.GetIndex() )
819 SaveGraphicData( rGrfNd
);
823 SwUndoReRead::~SwUndoReRead()
831 void SwUndoReRead::SetAndSave(::sw::UndoRedoContext
& rContext
)
833 SwDoc
& rDoc
= rContext
.GetDoc();
834 SwGrfNode
* pGrfNd
= rDoc
.GetNodes()[ nPos
]->GetGrfNode();
839 // cache the old values
840 Graphic
* pOldGrf
= pGrf
;
841 String
* pOldNm
= pNm
;
842 String
* pOldFltr
= pFltr
;
843 sal_uInt16 nOldMirr
= nMirr
;
845 SaveGraphicData( *pGrfNd
);
848 pGrfNd
->ReRead( *pOldNm
, pFltr
? *pFltr
: aEmptyStr
, 0, 0, sal_True
);
854 pGrfNd
->ReRead( aEmptyStr
, aEmptyStr
, pOldGrf
, 0, sal_True
);
858 if( RES_MIRROR_GRAPH_DONT
!= nOldMirr
)
859 pGrfNd
->SetAttr( SwMirrorGrf() );
861 rContext
.SetSelections(pGrfNd
->GetFlyFmt(), 0);
865 void SwUndoReRead::UndoImpl(::sw::UndoRedoContext
& rContext
)
867 SetAndSave(rContext
);
871 void SwUndoReRead::RedoImpl(::sw::UndoRedoContext
& rContext
)
873 SetAndSave(rContext
);
877 void SwUndoReRead::SaveGraphicData( const SwGrfNode
& rGrfNd
)
879 if( rGrfNd
.IsGrfLink() )
883 rGrfNd
.GetFileFilterNms( pNm
, pFltr
);
888 ((SwGrfNode
&)rGrfNd
).SwapIn( sal_True
);
889 pGrf
= new Graphic( rGrfNd
.GetGrf() );
892 nMirr
= rGrfNd
.GetSwAttrSet().GetMirrorGrf().GetValue();
896 SwUndoInsertLabel::SwUndoInsertLabel( const SwLabelType eTyp
,
898 const String
& rSeparator
,
899 const String
& rNumberSeparator
,
901 const sal_uInt16 nInitId
,
902 const String
& rCharacterStyle
,
903 const sal_Bool bCpyBorder
)
904 : SwUndo( UNDO_INSERTLABEL
),
906 sSeparator( rSeparator
),
907 sNumberSeparator( rNumberSeparator
),//#i61007# order of captions
908 sCharacterStyle( rCharacterStyle
),
913 bCpyBrd( bCpyBorder
)
915 bUndoKeep
= sal_False
;
917 OBJECT
.pUndoAttr
= 0;
920 SwUndoInsertLabel::~SwUndoInsertLabel()
922 if( LTYPE_OBJECT
== eType
|| LTYPE_DRAW
== eType
)
924 delete OBJECT
.pUndoFly
;
925 delete OBJECT
.pUndoAttr
;
928 delete NODE
.pUndoInsNd
;
931 void SwUndoInsertLabel::UndoImpl(::sw::UndoRedoContext
& rContext
)
933 SwDoc
& rDoc
= rContext
.GetDoc();
935 if( LTYPE_OBJECT
== eType
|| LTYPE_DRAW
== eType
)
937 OSL_ENSURE( OBJECT
.pUndoAttr
&& OBJECT
.pUndoFly
, "Pointer not initialized" );
939 SdrObject
*pSdrObj
= 0;
940 if( OBJECT
.pUndoAttr
&&
941 0 != (pFmt
= (SwFrmFmt
*)OBJECT
.pUndoAttr
->GetFmt( rDoc
)) &&
942 ( LTYPE_DRAW
!= eType
||
943 0 != (pSdrObj
= pFmt
->FindSdrObject()) ) )
945 OBJECT
.pUndoAttr
->UndoImpl(rContext
);
946 OBJECT
.pUndoFly
->UndoImpl(rContext
);
947 if( LTYPE_DRAW
== eType
)
949 pSdrObj
->SetLayer( nLayerId
);
953 else if( NODE
.nNode
)
955 if ( eType
== LTYPE_TABLE
&& bUndoKeep
)
957 SwTableNode
*pNd
= rDoc
.GetNodes()[
958 rDoc
.GetNodes()[NODE
.nNode
-1]->StartOfSectionIndex()]->GetTableNode();
960 pNd
->GetTable().GetFrmFmt()->ResetFmtAttr( RES_KEEP
);
962 SwPaM
aPam( rDoc
.GetNodes().GetEndOfContent() );
963 aPam
.GetPoint()->nNode
= NODE
.nNode
;
965 aPam
.GetPoint()->nNode
= NODE
.nNode
+ 1;
966 NODE
.pUndoInsNd
= new SwUndoDelete( aPam
, sal_True
);
971 void SwUndoInsertLabel::RedoImpl(::sw::UndoRedoContext
& rContext
)
973 SwDoc
& rDoc
= rContext
.GetDoc();
975 if( LTYPE_OBJECT
== eType
|| LTYPE_DRAW
== eType
)
977 OSL_ENSURE( OBJECT
.pUndoAttr
&& OBJECT
.pUndoFly
, "Pointer not initialized" );
979 SdrObject
*pSdrObj
= 0;
980 if( OBJECT
.pUndoAttr
&&
981 0 != (pFmt
= (SwFrmFmt
*)OBJECT
.pUndoAttr
->GetFmt( rDoc
)) &&
982 ( LTYPE_DRAW
!= eType
||
983 0 != (pSdrObj
= pFmt
->FindSdrObject()) ) )
985 OBJECT
.pUndoFly
->RedoImpl(rContext
);
986 OBJECT
.pUndoAttr
->RedoImpl(rContext
);
987 if( LTYPE_DRAW
== eType
)
989 pSdrObj
->SetLayer( nLayerId
);
990 if( pSdrObj
->GetLayer() == rDoc
.GetHellId() )
991 pSdrObj
->SetLayer( rDoc
.GetHeavenId() );
992 // OD 02.07.2003 #108784#
993 else if( pSdrObj
->GetLayer() == rDoc
.GetInvisibleHellId() )
994 pSdrObj
->SetLayer( rDoc
.GetInvisibleHeavenId() );
998 else if( NODE
.pUndoInsNd
)
1000 if ( eType
== LTYPE_TABLE
&& bUndoKeep
)
1002 SwTableNode
*pNd
= rDoc
.GetNodes()[
1003 rDoc
.GetNodes()[NODE
.nNode
-1]->StartOfSectionIndex()]->GetTableNode();
1005 pNd
->GetTable().GetFrmFmt()->SetFmtAttr( SvxFmtKeepItem(sal_True
, RES_KEEP
) );
1007 NODE
.pUndoInsNd
->UndoImpl(rContext
);
1008 delete NODE
.pUndoInsNd
, NODE
.pUndoInsNd
= 0;
1012 void SwUndoInsertLabel::RepeatImpl(::sw::RepeatContext
& rContext
)
1014 SwDoc
& rDoc
= rContext
.GetDoc();
1015 const SwPosition
& rPos
= *rContext
.GetRepeatPaM().GetPoint();
1019 SwCntntNode
* pCNd
= rPos
.nNode
.GetNode().GetCntntNode();
1025 const SwTableNode
* pTNd
= pCNd
->FindTableNode();
1027 nIdx
= pTNd
->GetIndex();
1035 SwCntntFrm
*pCnt
= pCNd
->getLayoutFrm( rDoc
.GetCurrentLayout() );
1036 if( pCnt
&& 0 != ( pFly
= pCnt
->FindFlyFrm() ) )
1037 nIdx
= pFly
->GetFmt()->GetCntnt().GetCntntIdx()->GetIndex();
1046 rDoc
.InsertLabel( eType
, sText
, sSeparator
, sNumberSeparator
, bBefore
,
1047 nFldId
, nIdx
, sCharacterStyle
, bCpyBrd
);
1052 SwRewriter
SwUndoInsertLabel::GetRewriter() const
1054 SwRewriter aRewriter
;
1058 aTmpStr
+= String(SW_RES(STR_START_QUOTE
));
1059 aTmpStr
+= ShortenString(sText
, nUndoStringLength
,
1060 String(SW_RES(STR_LDOTS
)));
1061 aTmpStr
+= String(SW_RES(STR_END_QUOTE
));
1063 aRewriter
.AddRule(UndoArg1
, aTmpStr
);
1068 void SwUndoInsertLabel::SetFlys( SwFrmFmt
& rOldFly
, SfxItemSet
& rChgSet
,
1071 if( LTYPE_OBJECT
== eType
|| LTYPE_DRAW
== eType
)
1073 SwUndoFmtAttrHelper
aTmp( rOldFly
, false );
1074 rOldFly
.SetFmtAttr( rChgSet
);
1075 if ( aTmp
.GetUndo() )
1077 OBJECT
.pUndoAttr
= aTmp
.ReleaseUndo();
1079 OBJECT
.pUndoFly
= new SwUndoInsLayFmt( &rNewFly
,0,0 );
1083 void SwUndoInsertLabel::SetDrawObj( sal_uInt8 nLId
)
1085 if( LTYPE_DRAW
== eType
)
1091 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */