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: editundo.cxx,v $
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_svx.hxx"
34 #include <eeng_pch.hxx>
36 #include <impedit.hxx>
37 #include <editundo.hxx>
38 #include <svx/editview.hxx>
39 #include <svx/editeng.hxx>
43 #define MAX_UNDOS 100 // ab dieser Menge darf geloescht werden....
44 #define MIN_UNDOS 50 // soviel muss stehen bleiben...
46 #define NO_UNDO 0xFFFF
47 #define GROUP_NOTFOUND 0xFFFF
49 TYPEINIT1( EditUndo
, SfxUndoAction
);
50 TYPEINIT1( EditUndoDelContent
, EditUndo
);
51 TYPEINIT1( EditUndoConnectParas
, EditUndo
);
52 TYPEINIT1( EditUndoSplitPara
, EditUndo
);
53 TYPEINIT1( EditUndoInsertChars
, EditUndo
);
54 TYPEINIT1( EditUndoRemoveChars
, EditUndo
);
55 TYPEINIT1( EditUndoInsertFeature
, EditUndo
);
56 TYPEINIT1( EditUndoMoveParagraphs
, EditUndo
);
57 TYPEINIT1( EditUndoSetStyleSheet
, EditUndo
);
58 TYPEINIT1( EditUndoSetParaAttribs
, EditUndo
);
59 TYPEINIT1( EditUndoSetAttribs
, EditUndo
);
60 TYPEINIT1( EditUndoTransliteration
, EditUndo
);
61 TYPEINIT1( EditUndoMarkSelection
, EditUndo
);
63 void lcl_DoSetSelection( EditView
* pView
, USHORT nPara
)
65 EPaM
aEPaM( nPara
, 0 );
66 EditPaM
aPaM( pView
->GetImpEditEngine()->CreateEditPaM( aEPaM
) );
67 aPaM
.SetIndex( aPaM
.GetNode()->Len() );
68 EditSelection
aSel( aPaM
, aPaM
);
69 pView
->GetImpEditView()->SetEditSelection( aSel
);
72 \f// -----------------------------------------------------------------------
74 // ------------------------------------------------------------------------
75 EditUndoManager::EditUndoManager( ImpEditEngine
* p
)
80 BOOL __EXPORT
EditUndoManager::Undo( USHORT nCount
)
82 if ( GetUndoActionCount() == 0 )
85 DBG_ASSERT( pImpEE
->GetActiveView(), "Active View?" );
87 if ( !pImpEE
->GetActiveView() )
89 if ( pImpEE
->GetEditViews().Count() )
90 pImpEE
->SetActiveView( pImpEE
->GetEditViews().GetObject(0) );
93 DBG_ERROR( "Undo in Engine ohne View nicht moeglich!" );
98 pImpEE
->GetActiveView()->GetImpEditView()->DrawSelection(); // alte Selektion entfernen
100 pImpEE
->SetUndoMode( TRUE
);
101 BOOL bDone
= SfxUndoManager::Undo( nCount
);
102 pImpEE
->SetUndoMode( FALSE
);
104 EditSelection
aNewSel( pImpEE
->GetActiveView()->GetImpEditView()->GetEditSelection() );
105 DBG_ASSERT( !aNewSel
.IsInvalid(), "Ungueltige Selektion nach Undo()" );
106 DBG_ASSERT( !aNewSel
.DbgIsBuggy( pImpEE
->GetEditDoc() ), "Kaputte Selektion nach Undo()" );
108 aNewSel
.Min() = aNewSel
.Max();
109 pImpEE
->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel
);
110 pImpEE
->FormatAndUpdate( pImpEE
->GetActiveView() );
115 BOOL __EXPORT
EditUndoManager::Redo( USHORT nCount
)
117 if ( GetRedoActionCount() == 0 )
120 DBG_ASSERT( pImpEE
->GetActiveView(), "Active View?" );
122 if ( !pImpEE
->GetActiveView() )
124 if ( pImpEE
->GetEditViews().Count() )
125 pImpEE
->SetActiveView( pImpEE
->GetEditViews().GetObject(0) );
128 DBG_ERROR( "Redo in Engine ohne View nicht moeglich!" );
133 pImpEE
->GetActiveView()->GetImpEditView()->DrawSelection(); // alte Selektion entfernen
135 pImpEE
->SetUndoMode( TRUE
);
136 BOOL bDone
= SfxUndoManager::Redo( nCount
);
137 pImpEE
->SetUndoMode( FALSE
);
139 EditSelection
aNewSel( pImpEE
->GetActiveView()->GetImpEditView()->GetEditSelection() );
140 DBG_ASSERT( !aNewSel
.IsInvalid(), "Ungueltige Selektion nach Undo()" );
141 DBG_ASSERT( !aNewSel
.DbgIsBuggy( pImpEE
->GetEditDoc() ), "Kaputte Selektion nach Redo()" );
143 aNewSel
.Min() = aNewSel
.Max();
144 pImpEE
->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel
);
145 pImpEE
->FormatAndUpdate( pImpEE
->GetActiveView() );
150 \f// -----------------------------------------------------------------------
152 // ------------------------------------------------------------------------
153 EditUndo::EditUndo( USHORT nI
, ImpEditEngine
* p
)
155 DBG_CTOR( EditUndo
, 0 );
160 EditUndo::~EditUndo()
162 DBG_DTOR( EditUndo
, 0 );
165 USHORT __EXPORT
EditUndo::GetId() const
167 DBG_CHKTHIS( EditUndo
, 0 );
171 BOOL __EXPORT
EditUndo::CanRepeat(SfxRepeatTarget
&) const
176 XubString __EXPORT
EditUndo::GetComment() const
181 EditEngine
* pEditEng
= pImpEE
->GetEditEnginePtr();
182 aComment
= pEditEng
->GetUndoComment( GetId() );
187 \f// -----------------------------------------------------------------------
188 // EditUndoDelContent
189 // ------------------------------------------------------------------------
190 EditUndoDelContent::EditUndoDelContent( ImpEditEngine
* _pImpEE
, ContentNode
* pNode
, USHORT n
)
191 : EditUndo( EDITUNDO_DELCONTENT
, _pImpEE
)
193 pContentNode
= pNode
;
198 EditUndoDelContent::~EditUndoDelContent()
204 void __EXPORT
EditUndoDelContent::Undo()
206 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
207 GetImpEditEngine()->InsertContent( pContentNode
, nNode
);
208 bDelObject
= FALSE
; // gehoert wieder der Engine
209 EditSelection
aSel( EditPaM( pContentNode
, 0 ), EditPaM( pContentNode
, pContentNode
->Len() ) );
210 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aSel
);
213 void __EXPORT
EditUndoDelContent::Redo()
215 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
217 ImpEditEngine
* _pImpEE
= GetImpEditEngine();
219 // pNode stimmt nicht mehr, falls zwischendurch Undos, in denen
220 // Absaetze verschmolzen sind.
221 pContentNode
= _pImpEE
->GetEditDoc().SaveGetObject( nNode
);
222 DBG_ASSERT( pContentNode
, "EditUndoDelContent::Redo(): Node?!" );
224 delete _pImpEE
->GetParaPortions()[nNode
];
225 _pImpEE
->GetParaPortions().Remove( nNode
);
227 // Node nicht loeschen, haengt im Undo!
228 _pImpEE
->GetEditDoc().Remove( nNode
);
229 if( _pImpEE
->IsCallParaInsertedOrDeleted() )
230 _pImpEE
->GetEditEnginePtr()->ParagraphDeleted( nNode
);
232 DeletedNodeInfo
* pInf
= new DeletedNodeInfo( (ULONG
)pContentNode
, nNode
);
233 _pImpEE
->aDeletedNodes
.Insert( pInf
, _pImpEE
->aDeletedNodes
.Count() );
234 _pImpEE
->UpdateSelections();
236 ContentNode
* pN
= ( nNode
< _pImpEE
->GetEditDoc().Count() )
237 ? _pImpEE
->GetEditDoc().SaveGetObject( nNode
)
238 : _pImpEE
->GetEditDoc().SaveGetObject( nNode
-1 );
239 DBG_ASSERT( pN
&& ( pN
!= pContentNode
), "?! RemoveContent !? " );
240 EditPaM
aPaM( pN
, pN
->Len() );
242 bDelObject
= TRUE
; // gehoert wieder dem Undo
244 _pImpEE
->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM
, aPaM
) );
247 \f// -----------------------------------------------------------------------
248 // EditUndoConnectParas
249 // ------------------------------------------------------------------------
250 EditUndoConnectParas::EditUndoConnectParas( ImpEditEngine
* _pImpEE
, USHORT nN
, USHORT nSP
,
251 const SfxItemSet
& rLeftParaAttribs
, const SfxItemSet
& rRightParaAttribs
,
252 const SfxStyleSheet
* pLeftStyle
, const SfxStyleSheet
* pRightStyle
, BOOL bBkwrd
)
253 : EditUndo( EDITUNDO_CONNECTPARAS
, _pImpEE
),
254 aLeftParaAttribs( rLeftParaAttribs
),
255 aRightParaAttribs( rRightParaAttribs
)
262 aLeftStyleName
= pLeftStyle
->GetName();
263 eLeftStyleFamily
= pLeftStyle
->GetFamily();
267 aRightStyleName
= pRightStyle
->GetName();
268 eRightStyleFamily
= pRightStyle
->GetFamily();
274 EditUndoConnectParas::~EditUndoConnectParas()
278 void __EXPORT
EditUndoConnectParas::Undo()
280 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
282 // Bei SplitContent darf noch kein ParagraphInserted gerufen werden,
283 // weil der Outliner sich auf die Attribute verlaesst um die Tiefe
284 // des Absatzes zu initialisieren
286 BOOL bCall
= GetImpEditEngine()->IsCallParaInsertedOrDeleted();
287 GetImpEditEngine()->SetCallParaInsertedOrDeleted( FALSE
);
289 EditPaM aPaM
= GetImpEditEngine()->SplitContent( nNode
, nSepPos
);
290 GetImpEditEngine()->SetParaAttribs( nNode
, aLeftParaAttribs
);
291 GetImpEditEngine()->SetParaAttribs( nNode
+1, aRightParaAttribs
);
293 GetImpEditEngine()->SetCallParaInsertedOrDeleted( bCall
);
294 if ( GetImpEditEngine()->IsCallParaInsertedOrDeleted() )
295 GetImpEditEngine()->GetEditEnginePtr()->ParagraphInserted( nNode
+1 );
297 if ( GetImpEditEngine()->GetStyleSheetPool() )
299 if ( aLeftStyleName
.Len() )
300 GetImpEditEngine()->SetStyleSheet( (USHORT
)nNode
, (SfxStyleSheet
*)GetImpEditEngine()->GetStyleSheetPool()->Find( aLeftStyleName
, eLeftStyleFamily
) );
301 if ( aRightStyleName
.Len() )
302 GetImpEditEngine()->SetStyleSheet( nNode
+1, (SfxStyleSheet
*)GetImpEditEngine()->GetStyleSheetPool()->Find( aRightStyleName
, eRightStyleFamily
) );
305 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM
, aPaM
) );
308 void __EXPORT
EditUndoConnectParas::Redo()
310 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
311 EditPaM aPaM
= GetImpEditEngine()->ConnectContents( nNode
, bBackward
);
313 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM
, aPaM
) );
316 \f// -----------------------------------------------------------------------
318 // ------------------------------------------------------------------------
319 EditUndoSplitPara::EditUndoSplitPara( ImpEditEngine
* _pImpEE
, USHORT nN
, USHORT nSP
)
320 : EditUndo( EDITUNDO_SPLITPARA
, _pImpEE
)
326 EditUndoSplitPara::~EditUndoSplitPara()
330 void __EXPORT
EditUndoSplitPara::Undo()
332 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
333 EditPaM aPaM
= GetImpEditEngine()->ConnectContents( nNode
, FALSE
);
334 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM
, aPaM
) );
337 void __EXPORT
EditUndoSplitPara::Redo()
339 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
340 EditPaM aPaM
= GetImpEditEngine()->SplitContent( nNode
, nSepPos
);
341 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM
, aPaM
) );
344 \f// -----------------------------------------------------------------------
345 // EditUndoInsertChars
346 // ------------------------------------------------------------------------
347 EditUndoInsertChars::EditUndoInsertChars( ImpEditEngine
* _pImpEE
, const EPaM
& rEPaM
, const XubString
& rStr
)
348 : EditUndo( EDITUNDO_INSERTCHARS
, _pImpEE
),
349 aEPaM( rEPaM
), aText( rStr
)
353 void __EXPORT
EditUndoInsertChars::Undo()
355 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
356 EditPaM
aPaM( GetImpEditEngine()->CreateEditPaM( aEPaM
) );
357 EditSelection
aSel( aPaM
, aPaM
);
358 aSel
.Max().GetIndex() = aSel
.Max().GetIndex() + aText
.Len();
359 EditPaM
aNewPaM( GetImpEditEngine()->ImpDeleteSelection( aSel
) );
360 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aNewPaM
, aNewPaM
) );
363 void __EXPORT
EditUndoInsertChars::Redo()
365 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
366 EditPaM
aPaM( GetImpEditEngine()->CreateEditPaM( aEPaM
) );
367 GetImpEditEngine()->ImpInsertText( EditSelection( aPaM
, aPaM
), aText
);
368 EditPaM
aNewPaM( aPaM
);
369 aNewPaM
.GetIndex() = aNewPaM
.GetIndex() + aText
.Len();
370 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM
, aNewPaM
) );
373 BOOL __EXPORT
EditUndoInsertChars::Merge( SfxUndoAction
* pNextAction
)
375 if ( !pNextAction
->ISA( EditUndoInsertChars
) )
378 EditUndoInsertChars
* pNext
= (EditUndoInsertChars
*)pNextAction
;
380 if ( aEPaM
.nPara
!= pNext
->aEPaM
.nPara
)
383 if ( ( aEPaM
.nIndex
+ aText
.Len() ) == pNext
->aEPaM
.nIndex
)
385 aText
+= pNext
->aText
;
391 \f// -----------------------------------------------------------------------
392 // EditUndoRemoveChars
393 // ------------------------------------------------------------------------
394 EditUndoRemoveChars::EditUndoRemoveChars( ImpEditEngine
* _pImpEE
, const EPaM
& rEPaM
, const XubString
& rStr
)
395 : EditUndo( EDITUNDO_REMOVECHARS
, _pImpEE
),
396 aEPaM( rEPaM
), aText( rStr
)
400 void __EXPORT
EditUndoRemoveChars::Undo()
402 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
403 EditPaM
aPaM( GetImpEditEngine()->CreateEditPaM( aEPaM
) );
404 EditSelection
aSel( aPaM
, aPaM
);
405 GetImpEditEngine()->ImpInsertText( aSel
, aText
);
406 aSel
.Max().GetIndex() = aSel
.Max().GetIndex() + aText
.Len();
407 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aSel
);
410 void __EXPORT
EditUndoRemoveChars::Redo()
412 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
413 EditPaM
aPaM( GetImpEditEngine()->CreateEditPaM( aEPaM
) );
414 EditSelection
aSel( aPaM
, aPaM
);
415 aSel
.Max().GetIndex() = aSel
.Max().GetIndex() + aText
.Len();
416 EditPaM aNewPaM
= GetImpEditEngine()->ImpDeleteSelection( aSel
);
417 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewPaM
);
420 \f// -----------------------------------------------------------------------
421 // EditUndoInsertFeature
422 // ------------------------------------------------------------------------
423 EditUndoInsertFeature::EditUndoInsertFeature( ImpEditEngine
* _pImpEE
, const EPaM
& rEPaM
, const SfxPoolItem
& rFeature
)
424 : EditUndo( EDITUNDO_INSERTFEATURE
, _pImpEE
), aEPaM( rEPaM
)
426 pFeature
= rFeature
.Clone();
427 DBG_ASSERT( pFeature
, "Feature konnte nicht dupliziert werden: EditUndoInsertFeature" );
430 EditUndoInsertFeature::~EditUndoInsertFeature()
435 void __EXPORT
EditUndoInsertFeature::Undo()
437 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
438 EditPaM
aPaM( GetImpEditEngine()->CreateEditPaM( aEPaM
) );
439 EditSelection
aSel( aPaM
, aPaM
);
440 // Attribute werden dort implizit vom Dokument korrigiert...
441 aSel
.Max().GetIndex()++;
442 EditPaM aNewPaM
= GetImpEditEngine()->ImpDeleteSelection( aSel
);
443 aSel
.Max().GetIndex()--; // Fuer Selektion
444 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aSel
);
447 void __EXPORT
EditUndoInsertFeature::Redo()
449 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
450 EditPaM
aPaM( GetImpEditEngine()->CreateEditPaM( aEPaM
) );
451 EditSelection
aSel( aPaM
, aPaM
);
452 GetImpEditEngine()->ImpInsertFeature( aSel
, *pFeature
);
453 if ( pFeature
->Which() == EE_FEATURE_FIELD
)
454 GetImpEditEngine()->UpdateFields();
455 aSel
.Max().GetIndex()++;
456 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aSel
);
459 \f// -----------------------------------------------------------------------
460 // EditUndoMoveParagraphs
461 // ------------------------------------------------------------------------
462 EditUndoMoveParagraphs::EditUndoMoveParagraphs
463 ( ImpEditEngine
* _pImpEE
, const Range
& rParas
, USHORT n
)
464 : EditUndo( EDITUNDO_MOVEPARAGRAPHS
, _pImpEE
),
465 nParagraphs( rParas
)
470 EditUndoMoveParagraphs::~EditUndoMoveParagraphs()
474 void __EXPORT
EditUndoMoveParagraphs::Undo()
476 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
477 Range
aTmpRange( nParagraphs
);
478 long nTmpDest
= aTmpRange
.Min();
480 long nDiff
= ( nDest
- aTmpRange
.Min() );
481 aTmpRange
.Min() += nDiff
;
482 aTmpRange
.Max() += nDiff
;
484 if ( nParagraphs
.Min() < (long)nDest
)
486 long nLen
= aTmpRange
.Len();
487 aTmpRange
.Min() -= nLen
;
488 aTmpRange
.Max() -= nLen
;
491 nTmpDest
+= aTmpRange
.Len();
493 EditSelection
aNewSel( GetImpEditEngine()->MoveParagraphs( aTmpRange
, (USHORT
)nTmpDest
, 0 ) );
494 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel
);
497 void __EXPORT
EditUndoMoveParagraphs::Redo()
499 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
500 EditSelection
aNewSel( GetImpEditEngine()->MoveParagraphs( nParagraphs
, nDest
, 0 ) );
501 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel
);
504 \f// -----------------------------------------------------------------------
505 // EditUndoSetStyleSheet
506 // ------------------------------------------------------------------------
507 EditUndoSetStyleSheet::EditUndoSetStyleSheet( ImpEditEngine
* _pImpEE
, USHORT nP
,
508 const XubString
& rPrevName
, SfxStyleFamily ePrevFam
,
509 const XubString
& rNewName
, SfxStyleFamily eNewFam
,
510 const SfxItemSet
& rPrevParaAttribs
)
511 : EditUndo( EDITUNDO_STYLESHEET
, _pImpEE
), aPrevName( rPrevName
), aNewName( rNewName
),
512 aPrevParaAttribs( rPrevParaAttribs
)
514 ePrevFamily
= ePrevFam
;
515 eNewFamily
= eNewFam
;
519 EditUndoSetStyleSheet::~EditUndoSetStyleSheet()
523 void __EXPORT
EditUndoSetStyleSheet::Undo()
525 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
526 GetImpEditEngine()->SetStyleSheet( nPara
, (SfxStyleSheet
*)GetImpEditEngine()->GetStyleSheetPool()->Find( aPrevName
, ePrevFamily
) );
527 GetImpEditEngine()->SetParaAttribs( nPara
, aPrevParaAttribs
);
528 lcl_DoSetSelection( GetImpEditEngine()->GetActiveView(), nPara
);
531 void __EXPORT
EditUndoSetStyleSheet::Redo()
533 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
534 GetImpEditEngine()->SetStyleSheet( nPara
, (SfxStyleSheet
*)GetImpEditEngine()->GetStyleSheetPool()->Find( aNewName
, eNewFamily
) );
535 lcl_DoSetSelection( GetImpEditEngine()->GetActiveView(), nPara
);
538 \f// -----------------------------------------------------------------------
539 // EditUndoSetParaAttribs
540 // ------------------------------------------------------------------------
541 EditUndoSetParaAttribs::EditUndoSetParaAttribs( ImpEditEngine
* _pImpEE
, USHORT nP
, const SfxItemSet
& rPrevItems
, const SfxItemSet
& rNewItems
)
542 : EditUndo( EDITUNDO_PARAATTRIBS
, _pImpEE
),
543 aPrevItems( rPrevItems
),
544 aNewItems(rNewItems
)
549 EditUndoSetParaAttribs::~EditUndoSetParaAttribs()
553 void __EXPORT
EditUndoSetParaAttribs::Undo()
555 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
556 GetImpEditEngine()->SetParaAttribs( nPara
, aPrevItems
);
557 lcl_DoSetSelection( GetImpEditEngine()->GetActiveView(), nPara
);
560 void __EXPORT
EditUndoSetParaAttribs::Redo()
562 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
563 GetImpEditEngine()->SetParaAttribs( nPara
, aNewItems
);
564 lcl_DoSetSelection( GetImpEditEngine()->GetActiveView(), nPara
);
567 \f// -----------------------------------------------------------------------
568 // EditUndoSetAttribs
569 // ------------------------------------------------------------------------
570 EditUndoSetAttribs::EditUndoSetAttribs( ImpEditEngine
* _pImpEE
, const ESelection
& rESel
, const SfxItemSet
& rNewItems
)
571 : EditUndo( EDITUNDO_ATTRIBS
, _pImpEE
),
573 aNewAttribs( rNewItems
)
575 // Wenn das EditUndoSetAttribs eigentlich ein RemoveAttribs ist, koennte
576 // man das eigentlich an einem leeren ItemSet erkennen, aber dann muesste
577 // an einigen Stellen abgefangen werden, das ggf. ein SetAttribs mit einem
578 // leeren ItemSet gemacht wird.
579 // => Ich habe lieber diesen Member spendiert...
580 bSetIsRemove
= FALSE
;
581 bRemoveParaAttribs
= FALSE
;
586 EditUndoSetAttribs::~EditUndoSetAttribs()
588 // Items aus Pool holen...
589 SfxItemPool
* pPool
= aNewAttribs
.GetPool();
590 USHORT nContents
= aPrevAttribs
.Count();
591 for ( USHORT n
= 0; n
< nContents
; n
++ )
593 ContentAttribsInfo
* pInf
= aPrevAttribs
[n
];
594 DBG_ASSERT( pInf
, "Undo_DTOR (SetAttribs): pInf = NULL!" );
595 for ( USHORT nAttr
= 0; nAttr
< pInf
->GetPrevCharAttribs().Count(); nAttr
++ )
597 EditCharAttrib
* pX
= pInf
->GetPrevCharAttribs()[nAttr
];
598 DBG_ASSERT( pX
, "Undo_DTOR (SetAttribs): pX = NULL!" );
599 pPool
->Remove( *pX
->GetItem() );
606 void __EXPORT
EditUndoSetAttribs::Undo()
608 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
609 ImpEditEngine
* _pImpEE
= GetImpEditEngine();
610 BOOL bFields
= FALSE
;
611 for ( USHORT nPara
= aESel
.nStartPara
; nPara
<= aESel
.nEndPara
; nPara
++ )
613 ContentAttribsInfo
* pInf
= aPrevAttribs
[ (USHORT
)(nPara
-aESel
.nStartPara
) ];
614 DBG_ASSERT( pInf
, "Undo (SetAttribs): pInf = NULL!" );
616 // erstmal die Absatzattribute...
617 _pImpEE
->SetParaAttribs( nPara
, pInf
->GetPrevParaAttribs() );
619 // Dann die Zeichenattribute...
620 // Alle Attribute inkl. Features entfernen, werden wieder neu eingestellt.
621 _pImpEE
->RemoveCharAttribs( nPara
, 0, TRUE
);
622 DBG_ASSERT( _pImpEE
->GetEditDoc().SaveGetObject( nPara
), "Undo (SetAttribs): pNode = NULL!" );
623 ContentNode
* pNode
= _pImpEE
->GetEditDoc().GetObject( nPara
);
624 for ( USHORT nAttr
= 0; nAttr
< pInf
->GetPrevCharAttribs().Count(); nAttr
++ )
626 EditCharAttrib
* pX
= pInf
->GetPrevCharAttribs()[nAttr
];
627 DBG_ASSERT( pX
, "Redo (SetAttribs): pX = NULL!" );
628 // wird autom. 'eingepoolt'.
629 _pImpEE
->GetEditDoc().InsertAttrib( pNode
, pX
->GetStart(), pX
->GetEnd(), *pX
->GetItem() );
630 if ( pX
->Which() == EE_FEATURE_FIELD
)
635 _pImpEE
->UpdateFields();
636 ImpSetSelection( GetImpEditEngine()->GetActiveView() );
639 void __EXPORT
EditUndoSetAttribs::Redo()
641 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
642 ImpEditEngine
* _pImpEE
= GetImpEditEngine();
644 EditSelection
aSel( _pImpEE
->CreateSel( aESel
) );
646 _pImpEE
->SetAttribs( aSel
, aNewAttribs
, nSpecial
);
648 _pImpEE
->RemoveCharAttribs( aSel
, bRemoveParaAttribs
, nRemoveWhich
);
650 ImpSetSelection( GetImpEditEngine()->GetActiveView() );
653 void EditUndoSetAttribs::ImpSetSelection( EditView
* /*pView*/ )
655 ImpEditEngine
* _pImpEE
= GetImpEditEngine();
656 EditSelection
aSel( _pImpEE
->CreateSel( aESel
) );
657 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aSel
);
660 \f// -----------------------------------------------------------------------
661 // EditUndoTransliteration
662 // ------------------------------------------------------------------------
663 EditUndoTransliteration::EditUndoTransliteration( ImpEditEngine
* _pImpEE
, const ESelection
& rESel
, sal_Int32 nM
)
664 : EditUndo( EDITUNDO_TRANSLITERATE
, _pImpEE
), aOldESel( rESel
)
670 EditUndoTransliteration::~EditUndoTransliteration()
675 void __EXPORT
EditUndoTransliteration::Undo()
677 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
679 ImpEditEngine
* _pImpEE
= GetImpEditEngine();
681 EditSelection
aSel( _pImpEE
->CreateSel( aNewESel
) );
683 // Insert text, but don't expand Atribs at the current position:
684 aSel
= _pImpEE
->DeleteSelected( aSel
);
685 EditSelection
aDelSel( aSel
);
686 aSel
= _pImpEE
->InsertParaBreak( aSel
);
687 aDelSel
.Max() = aSel
.Min();
688 aDelSel
.Max().GetNode()->GetCharAttribs().DeleteEmptyAttribs( _pImpEE
->GetEditDoc().GetItemPool() );
689 EditSelection aNewSel
;
692 aNewSel
= _pImpEE
->InsertText( *pTxtObj
, aSel
);
696 aNewSel
= _pImpEE
->InsertText( aSel
, aText
);
698 if ( aNewSel
.Min().GetNode() == aDelSel
.Max().GetNode() )
700 aNewSel
.Min().SetNode( aDelSel
.Min().GetNode() );
701 aNewSel
.Min().GetIndex() =
702 aNewSel
.Min().GetIndex() + aDelSel
.Min().GetIndex();
704 if ( aNewSel
.Max().GetNode() == aDelSel
.Max().GetNode() )
706 aNewSel
.Max().SetNode( aDelSel
.Min().GetNode() );
707 aNewSel
.Max().GetIndex() =
708 aNewSel
.Max().GetIndex() + aDelSel
.Min().GetIndex();
710 _pImpEE
->DeleteSelected( aDelSel
);
712 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel
);
715 void __EXPORT
EditUndoTransliteration::Redo()
717 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
718 ImpEditEngine
* _pImpEE
= GetImpEditEngine();
720 EditSelection
aSel( _pImpEE
->CreateSel( aOldESel
) );
721 EditSelection aNewSel
= _pImpEE
->TransliterateText( aSel
, nMode
);
722 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel
);
725 \f// -----------------------------------------------------------------------
726 // EditUndoMarkSelection
727 // ------------------------------------------------------------------------
728 EditUndoMarkSelection::EditUndoMarkSelection( ImpEditEngine
* _pImpEE
, const ESelection
& rSel
)
729 : EditUndo( EDITUNDO_MARKSELECTION
, _pImpEE
), aSelection( rSel
)
733 EditUndoMarkSelection::~EditUndoMarkSelection()
737 void __EXPORT
EditUndoMarkSelection::Undo()
739 DBG_ASSERT( GetImpEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
740 if ( GetImpEditEngine()->GetActiveView() )
742 if ( GetImpEditEngine()->IsFormatted() )
743 GetImpEditEngine()->GetActiveView()->SetSelection( aSelection
);
745 GetImpEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( GetImpEditEngine()->CreateSel( aSelection
) );
749 void __EXPORT
EditUndoMarkSelection::Redo()
751 // Fuer Redo unwichtig, weil am Anfang der Undo-Klammerung