Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <vcl/wrkwin.hxx>
21 : #include <vcl/dialog.hxx>
22 : #include <vcl/msgbox.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <impedit.hxx>
25 : #include <editundo.hxx>
26 : #include <editeng/editview.hxx>
27 : #include <editeng/editeng.hxx>
28 :
29 : DBG_NAME( EditUndo )
30 :
31 0 : static void lcl_DoSetSelection( EditView* pView, sal_uInt16 nPara )
32 : {
33 0 : EPaM aEPaM( nPara, 0 );
34 0 : EditPaM aPaM( pView->GetImpEditEngine()->CreateEditPaM( aEPaM ) );
35 0 : aPaM.SetIndex( aPaM.GetNode()->Len() );
36 0 : EditSelection aSel( aPaM, aPaM );
37 0 : pView->GetImpEditView()->SetEditSelection( aSel );
38 0 : }
39 :
40 15006 : EditUndoManager::EditUndoManager(sal_uInt16 nMaxUndoActionCount )
41 : : SfxUndoManager(nMaxUndoActionCount),
42 15006 : mpEditEngine(0)
43 : {
44 15006 : }
45 :
46 13711 : void EditUndoManager::SetEditEngine(EditEngine* pNew)
47 : {
48 13711 : mpEditEngine = pNew;
49 13711 : }
50 :
51 2 : bool EditUndoManager::Undo()
52 : {
53 2 : if ( !mpEditEngine || GetUndoActionCount() == 0 )
54 0 : return false;
55 :
56 : DBG_ASSERT( mpEditEngine->GetActiveView(), "Active View?" );
57 :
58 2 : if ( !mpEditEngine->GetActiveView() )
59 : {
60 0 : if (!mpEditEngine->GetEditViews().empty())
61 0 : mpEditEngine->SetActiveView(mpEditEngine->GetEditViews()[0]);
62 : else
63 : {
64 : OSL_FAIL("Undo in engine is not possible without a View! ");
65 0 : return false;
66 : }
67 : }
68 :
69 2 : mpEditEngine->GetActiveView()->GetImpEditView()->DrawSelection(); // Remove the old selection
70 :
71 2 : mpEditEngine->SetUndoMode( sal_True );
72 2 : bool bDone = SfxUndoManager::Undo();
73 2 : mpEditEngine->SetUndoMode( sal_False );
74 :
75 2 : EditSelection aNewSel( mpEditEngine->GetActiveView()->GetImpEditView()->GetEditSelection() );
76 : DBG_ASSERT( !aNewSel.IsInvalid(), "Invalid selection after Undo () ");
77 : DBG_ASSERT( !aNewSel.DbgIsBuggy( mpEditEngine->GetEditDoc() ), "Broken selection afte Undo () ");
78 :
79 2 : aNewSel.Min() = aNewSel.Max();
80 2 : mpEditEngine->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
81 2 : mpEditEngine->FormatAndUpdate( mpEditEngine->GetActiveView() );
82 :
83 2 : return bDone;
84 : }
85 :
86 1 : bool EditUndoManager::Redo()
87 : {
88 1 : if ( !mpEditEngine || GetRedoActionCount() == 0 )
89 0 : return false;
90 :
91 : DBG_ASSERT( mpEditEngine->GetActiveView(), "Active View?" );
92 :
93 1 : if ( !mpEditEngine->GetActiveView() )
94 : {
95 0 : if (!mpEditEngine->GetEditViews().empty())
96 0 : mpEditEngine->SetActiveView(mpEditEngine->GetEditViews()[0]);
97 : else
98 : {
99 : OSL_FAIL( "Redo in Engine ohne View nicht moeglich!" );
100 0 : return false;
101 : }
102 : }
103 :
104 1 : mpEditEngine->GetActiveView()->GetImpEditView()->DrawSelection(); // Remove the old selection
105 :
106 1 : mpEditEngine->SetUndoMode( sal_True );
107 1 : bool bDone = SfxUndoManager::Redo();
108 1 : mpEditEngine->SetUndoMode( sal_False );
109 :
110 1 : EditSelection aNewSel( mpEditEngine->GetActiveView()->GetImpEditView()->GetEditSelection() );
111 : DBG_ASSERT( !aNewSel.IsInvalid(), "Invalid selection after Undo () ");
112 : DBG_ASSERT( !aNewSel.DbgIsBuggy( mpEditEngine->GetEditDoc() ), "Broken selection afte Undo () ");
113 :
114 1 : aNewSel.Min() = aNewSel.Max();
115 1 : mpEditEngine->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
116 1 : mpEditEngine->FormatAndUpdate( mpEditEngine->GetActiveView() );
117 :
118 1 : return bDone;
119 : }
120 :
121 38564 : EditUndo::EditUndo(sal_uInt16 nI, EditEngine* pEE) :
122 38564 : nId(nI), mpEditEngine(pEE)
123 : {
124 38564 : }
125 :
126 38529 : EditUndo::~EditUndo()
127 : {
128 38529 : }
129 :
130 12 : EditEngine* EditUndo::GetEditEngine()
131 : {
132 12 : return mpEditEngine;
133 : }
134 :
135 38536 : sal_uInt16 EditUndo::GetId() const
136 : {
137 : DBG_CHKTHIS( EditUndo, 0 );
138 38536 : return nId;
139 : }
140 :
141 0 : bool EditUndo::CanRepeat(SfxRepeatTarget&) const
142 : {
143 0 : return false;
144 : }
145 :
146 38564 : OUString EditUndo::GetComment() const
147 : {
148 38564 : OUString aComment;
149 :
150 38564 : if (mpEditEngine)
151 38536 : aComment = mpEditEngine->GetUndoComment( GetId() );
152 :
153 38564 : return aComment;
154 : }
155 :
156 6 : EditUndoDelContent::EditUndoDelContent(
157 : EditEngine* pEE, ContentNode* pNode, sal_Int32 nPortion) :
158 : EditUndo(EDITUNDO_DELCONTENT, pEE),
159 : bDelObject(true),
160 : nNode(nPortion),
161 6 : pContentNode(pNode) {}
162 :
163 18 : EditUndoDelContent::~EditUndoDelContent()
164 : {
165 6 : if ( bDelObject )
166 6 : delete pContentNode;
167 12 : }
168 :
169 0 : void EditUndoDelContent::Undo()
170 : {
171 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
172 0 : GetEditEngine()->InsertContent( pContentNode, nNode );
173 0 : bDelObject = false; // belongs to the Engine again
174 0 : EditSelection aSel( EditPaM( pContentNode, 0 ), EditPaM( pContentNode, pContentNode->Len() ) );
175 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
176 0 : }
177 :
178 0 : void EditUndoDelContent::Redo()
179 : {
180 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
181 :
182 0 : EditEngine* pEE = GetEditEngine();
183 :
184 : // pNode is no longer correct, if the paragraphs where merged
185 : // in between Undos
186 0 : pContentNode = pEE->GetEditDoc().GetObject( nNode );
187 : DBG_ASSERT( pContentNode, "EditUndoDelContent::Redo(): Node?!" );
188 :
189 0 : pEE->RemoveParaPortion(nNode);
190 :
191 : // Do not delete node, depends on the undo!
192 0 : pEE->GetEditDoc().Remove( nNode );
193 0 : if (pEE->IsCallParaInsertedOrDeleted())
194 0 : pEE->ParagraphDeleted( nNode );
195 :
196 0 : DeletedNodeInfo* pInf = new DeletedNodeInfo( (sal_uLong)pContentNode, nNode );
197 0 : pEE->AppendDeletedNodeInfo(pInf);
198 0 : pEE->UpdateSelections();
199 :
200 0 : ContentNode* pN = ( nNode < pEE->GetEditDoc().Count() )
201 0 : ? pEE->GetEditDoc().GetObject( nNode )
202 0 : : pEE->GetEditDoc().GetObject( nNode-1 );
203 : DBG_ASSERT( pN && ( pN != pContentNode ), "?! RemoveContent !? " );
204 0 : EditPaM aPaM( pN, pN->Len() );
205 :
206 0 : bDelObject = true; // belongs to the Engine again
207 :
208 0 : pEE->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
209 0 : }
210 :
211 21 : EditUndoConnectParas::EditUndoConnectParas(
212 : EditEngine* pEE, sal_Int32 nN, sal_uInt16 nSP,
213 : const SfxItemSet& rLeftParaAttribs, const SfxItemSet& rRightParaAttribs,
214 : const SfxStyleSheet* pLeftStyle, const SfxStyleSheet* pRightStyle, bool bBkwrd) :
215 : EditUndo(EDITUNDO_CONNECTPARAS, pEE),
216 : aLeftParaAttribs(rLeftParaAttribs),
217 : aRightParaAttribs(rRightParaAttribs),
218 21 : bBackward(bBkwrd)
219 : {
220 21 : nNode = nN;
221 21 : nSepPos = nSP;
222 :
223 21 : if ( pLeftStyle )
224 : {
225 2 : aLeftStyleName = pLeftStyle->GetName();
226 2 : eLeftStyleFamily = pLeftStyle->GetFamily();
227 : }
228 21 : if ( pRightStyle )
229 : {
230 2 : aRightStyleName = pRightStyle->GetName();
231 2 : eRightStyleFamily = pRightStyle->GetFamily();
232 : }
233 21 : }
234 :
235 42 : EditUndoConnectParas::~EditUndoConnectParas()
236 : {
237 42 : }
238 :
239 0 : void EditUndoConnectParas::Undo()
240 : {
241 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
242 :
243 : // For SplitContent ParagraphInserted can not be called yet because the
244 : // Outliner relies on the attributes to initialize the depth
245 :
246 0 : sal_Bool bCall = GetEditEngine()->IsCallParaInsertedOrDeleted();
247 0 : GetEditEngine()->SetCallParaInsertedOrDeleted(false);
248 :
249 0 : EditPaM aPaM = GetEditEngine()->SplitContent(nNode, nSepPos);
250 0 : GetEditEngine()->SetParaAttribs( nNode, aLeftParaAttribs );
251 0 : GetEditEngine()->SetParaAttribs( nNode+1, aRightParaAttribs );
252 :
253 0 : GetEditEngine()->SetCallParaInsertedOrDeleted( bCall );
254 0 : if (GetEditEngine()->IsCallParaInsertedOrDeleted())
255 0 : GetEditEngine()->ParagraphInserted( nNode+1 );
256 :
257 0 : if (GetEditEngine()->GetStyleSheetPool())
258 : {
259 0 : if ( aLeftStyleName.Len() )
260 0 : GetEditEngine()->SetStyleSheet( nNode, (SfxStyleSheet*)GetEditEngine()->GetStyleSheetPool()->Find( aLeftStyleName, eLeftStyleFamily ) );
261 0 : if ( aRightStyleName.Len() )
262 0 : GetEditEngine()->SetStyleSheet( nNode+1, (SfxStyleSheet*)GetEditEngine()->GetStyleSheetPool()->Find( aRightStyleName, eRightStyleFamily ) );
263 : }
264 :
265 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
266 0 : }
267 :
268 0 : void EditUndoConnectParas::Redo()
269 : {
270 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: Np Active View!" );
271 0 : EditPaM aPaM = GetEditEngine()->ConnectContents( nNode, bBackward );
272 :
273 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
274 0 : }
275 :
276 368 : EditUndoSplitPara::EditUndoSplitPara(
277 : EditEngine* pEE, sal_Int32 nN, sal_uInt16 nSP) :
278 : EditUndo(EDITUNDO_SPLITPARA, pEE),
279 368 : nNode(nN), nSepPos(nSP) {}
280 :
281 736 : EditUndoSplitPara::~EditUndoSplitPara() {}
282 :
283 0 : void EditUndoSplitPara::Undo()
284 : {
285 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
286 0 : EditPaM aPaM = GetEditEngine()->ConnectContents(nNode, false);
287 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
288 0 : }
289 :
290 0 : void EditUndoSplitPara::Redo()
291 : {
292 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
293 0 : EditPaM aPaM = GetEditEngine()->SplitContent(nNode, nSepPos);
294 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
295 0 : }
296 :
297 12865 : EditUndoInsertChars::EditUndoInsertChars(
298 : EditEngine* pEE, const EPaM& rEPaM, const String& rStr) :
299 : EditUndo(EDITUNDO_INSERTCHARS, pEE),
300 : aEPaM(rEPaM),
301 12865 : aText(rStr) {}
302 :
303 2 : void EditUndoInsertChars::Undo()
304 : {
305 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
306 2 : EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
307 2 : EditSelection aSel( aPaM, aPaM );
308 2 : aSel.Max().GetIndex() = aSel.Max().GetIndex() + aText.Len();
309 2 : EditPaM aNewPaM( GetEditEngine()->DeleteSelection(aSel) );
310 2 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aNewPaM, aNewPaM ) );
311 2 : }
312 :
313 1 : void EditUndoInsertChars::Redo()
314 : {
315 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
316 1 : EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
317 1 : GetEditEngine()->InsertText(EditSelection(aPaM, aPaM), aText);
318 1 : EditPaM aNewPaM( aPaM );
319 1 : aNewPaM.GetIndex() = aNewPaM.GetIndex() + aText.Len();
320 1 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aNewPaM ) );
321 1 : }
322 :
323 0 : bool EditUndoInsertChars::Merge( SfxUndoAction* pNextAction )
324 : {
325 0 : EditUndoInsertChars* pNext = dynamic_cast<EditUndoInsertChars*>(pNextAction);
326 0 : if (!pNext)
327 0 : return false;
328 :
329 0 : if ( aEPaM.nPara != pNext->aEPaM.nPara )
330 0 : return false;
331 :
332 0 : if ( ( aEPaM.nIndex + aText.Len() ) == pNext->aEPaM.nIndex )
333 : {
334 0 : aText += pNext->aText;
335 0 : return true;
336 : }
337 0 : return false;
338 : }
339 :
340 126 : EditUndoRemoveChars::EditUndoRemoveChars(
341 : EditEngine* pEE, const EPaM& rEPaM, const String& rStr) :
342 : EditUndo(EDITUNDO_REMOVECHARS, pEE),
343 126 : aEPaM(rEPaM), aText(rStr) {}
344 :
345 1 : void EditUndoRemoveChars::Undo()
346 : {
347 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
348 1 : EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
349 1 : EditSelection aSel( aPaM, aPaM );
350 1 : GetEditEngine()->InsertText(aSel, aText);
351 1 : aSel.Max().GetIndex() = aSel.Max().GetIndex() + aText.Len();
352 1 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
353 1 : }
354 :
355 0 : void EditUndoRemoveChars::Redo()
356 : {
357 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
358 0 : EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
359 0 : EditSelection aSel( aPaM, aPaM );
360 0 : aSel.Max().GetIndex() = aSel.Max().GetIndex() + aText.Len();
361 0 : EditPaM aNewPaM = GetEditEngine()->DeleteSelection(aSel);
362 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aNewPaM);
363 0 : }
364 :
365 2560 : EditUndoInsertFeature::EditUndoInsertFeature(
366 : EditEngine* pEE, const EPaM& rEPaM, const SfxPoolItem& rFeature) :
367 2560 : EditUndo(EDITUNDO_INSERTFEATURE, pEE), aEPaM(rEPaM)
368 : {
369 2560 : pFeature = rFeature.Clone();
370 : DBG_ASSERT( pFeature, "Feature could not be duplicated: EditUndoInsertFeature" );
371 2560 : }
372 :
373 7680 : EditUndoInsertFeature::~EditUndoInsertFeature()
374 : {
375 2560 : delete pFeature;
376 5120 : }
377 :
378 0 : void EditUndoInsertFeature::Undo()
379 : {
380 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
381 0 : EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
382 0 : EditSelection aSel( aPaM, aPaM );
383 : // Attributes are then corrected implicitly by the document ...
384 0 : aSel.Max().GetIndex()++;
385 0 : GetEditEngine()->DeleteSelection(aSel);
386 0 : aSel.Max().GetIndex()--; // For Selection
387 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
388 0 : }
389 :
390 0 : void EditUndoInsertFeature::Redo()
391 : {
392 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
393 0 : EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
394 0 : EditSelection aSel( aPaM, aPaM );
395 0 : GetEditEngine()->InsertFeature(aSel, *pFeature);
396 0 : if ( pFeature->Which() == EE_FEATURE_FIELD )
397 0 : GetEditEngine()->UpdateFieldsOnly();
398 0 : aSel.Max().GetIndex()++;
399 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
400 0 : }
401 :
402 0 : EditUndoMoveParagraphs::EditUndoMoveParagraphs(
403 : EditEngine* pEE, const Range& rParas, sal_Int32 n) :
404 0 : EditUndo(EDITUNDO_MOVEPARAGRAPHS, pEE), nParagraphs(rParas), nDest(n) {}
405 :
406 0 : EditUndoMoveParagraphs::~EditUndoMoveParagraphs() {}
407 :
408 0 : void EditUndoMoveParagraphs::Undo()
409 : {
410 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
411 0 : Range aTmpRange( nParagraphs );
412 0 : long nTmpDest = aTmpRange.Min();
413 :
414 0 : long nDiff = ( nDest - aTmpRange.Min() );
415 0 : aTmpRange.Min() += nDiff;
416 0 : aTmpRange.Max() += nDiff;
417 :
418 0 : if ( nParagraphs.Min() < (long)nDest )
419 : {
420 0 : long nLen = aTmpRange.Len();
421 0 : aTmpRange.Min() -= nLen;
422 0 : aTmpRange.Max() -= nLen;
423 : }
424 : else
425 0 : nTmpDest += aTmpRange.Len();
426 :
427 0 : EditSelection aNewSel = GetEditEngine()->MoveParagraphs(aTmpRange, nTmpDest, 0);
428 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
429 0 : }
430 :
431 0 : void EditUndoMoveParagraphs::Redo()
432 : {
433 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
434 0 : EditSelection aNewSel = GetEditEngine()->MoveParagraphs(nParagraphs, nDest, 0);
435 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
436 0 : }
437 :
438 1638 : EditUndoSetStyleSheet::EditUndoSetStyleSheet(
439 : EditEngine* pEE, sal_Int32 nP, const String& rPrevName, SfxStyleFamily ePrevFam,
440 : const String& rNewName, SfxStyleFamily eNewFam, const SfxItemSet& rPrevParaAttribs) :
441 : EditUndo(EDITUNDO_STYLESHEET, pEE),
442 : aPrevName(rPrevName),
443 : aNewName(rNewName),
444 1638 : aPrevParaAttribs(rPrevParaAttribs)
445 : {
446 1638 : ePrevFamily = ePrevFam;
447 1638 : eNewFamily = eNewFam;
448 1638 : nPara = nP;
449 1638 : }
450 :
451 3276 : EditUndoSetStyleSheet::~EditUndoSetStyleSheet()
452 : {
453 3276 : }
454 :
455 0 : void EditUndoSetStyleSheet::Undo()
456 : {
457 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
458 0 : GetEditEngine()->SetStyleSheet( nPara, (SfxStyleSheet*)GetEditEngine()->GetStyleSheetPool()->Find( aPrevName, ePrevFamily ) );
459 0 : GetEditEngine()->SetParaAttribsOnly( nPara, aPrevParaAttribs );
460 0 : lcl_DoSetSelection( GetEditEngine()->GetActiveView(), nPara );
461 0 : }
462 :
463 0 : void EditUndoSetStyleSheet::Redo()
464 : {
465 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
466 0 : GetEditEngine()->SetStyleSheet( nPara, (SfxStyleSheet*)GetEditEngine()->GetStyleSheetPool()->Find( aNewName, eNewFamily ) );
467 0 : lcl_DoSetSelection( GetEditEngine()->GetActiveView(), nPara );
468 0 : }
469 :
470 18196 : EditUndoSetParaAttribs::EditUndoSetParaAttribs(
471 : EditEngine* pEE, sal_Int32 nP, const SfxItemSet& rPrevItems, const SfxItemSet& rNewItems) :
472 : EditUndo(EDITUNDO_PARAATTRIBS, pEE),
473 : nPara(nP),
474 : aPrevItems(rPrevItems),
475 18196 : aNewItems(rNewItems) {}
476 :
477 36392 : EditUndoSetParaAttribs::~EditUndoSetParaAttribs() {}
478 :
479 0 : void EditUndoSetParaAttribs::Undo()
480 : {
481 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
482 0 : GetEditEngine()->SetParaAttribsOnly( nPara, aPrevItems );
483 0 : lcl_DoSetSelection( GetEditEngine()->GetActiveView(), nPara );
484 0 : }
485 :
486 0 : void EditUndoSetParaAttribs::Redo()
487 : {
488 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
489 0 : GetEditEngine()->SetParaAttribsOnly( nPara, aNewItems );
490 0 : lcl_DoSetSelection( GetEditEngine()->GetActiveView(), nPara );
491 0 : }
492 :
493 2756 : EditUndoSetAttribs::EditUndoSetAttribs(EditEngine* pEE, const ESelection& rESel, const SfxItemSet& rNewItems) :
494 : EditUndo(EDITUNDO_ATTRIBS, pEE),
495 2756 : aESel(rESel), aNewAttribs(rNewItems)
496 : {
497 : // When EditUndoSetAttribs actually is a RemoveAttribs this could be
498 : // /recognize by the empty itemset, but then it would have to be caught in
499 : // its own place, which possible a setAttribs does with an empty itemset.
500 2756 : bSetIsRemove = sal_False;
501 2756 : bRemoveParaAttribs = sal_False;
502 2756 : nRemoveWhich = 0;
503 2756 : nSpecial = 0;
504 2756 : }
505 :
506 : namespace {
507 :
508 : struct RemoveAttribsFromPool : std::unary_function<ContentAttribsInfo, void>
509 : {
510 : SfxItemPool& mrPool;
511 : public:
512 2756 : RemoveAttribsFromPool(SfxItemPool& rPool) : mrPool(rPool) {}
513 3116 : void operator() (ContentAttribsInfo& rInfo)
514 : {
515 3116 : rInfo.RemoveAllCharAttribsFromPool(mrPool);
516 3116 : }
517 : };
518 :
519 : }
520 :
521 8268 : EditUndoSetAttribs::~EditUndoSetAttribs()
522 : {
523 : // Get Items from Pool...
524 2756 : SfxItemPool* pPool = aNewAttribs.GetPool();
525 2756 : std::for_each(aPrevAttribs.begin(), aPrevAttribs.end(), RemoveAttribsFromPool(*pPool));
526 5512 : }
527 :
528 0 : void EditUndoSetAttribs::Undo()
529 : {
530 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
531 0 : EditEngine* pEE = GetEditEngine();
532 0 : bool bFields = false;
533 0 : for ( sal_Int32 nPara = aESel.nStartPara; nPara <= aESel.nEndPara; nPara++ )
534 : {
535 0 : const ContentAttribsInfo& rInf = aPrevAttribs[nPara-aESel.nStartPara];
536 :
537 : // first the paragraph attributes ...
538 0 : pEE->SetParaAttribsOnly(nPara, rInf.GetPrevParaAttribs());
539 :
540 : // Then the character attributes ...
541 : // Remove all attributes including features, are later re-established.
542 0 : pEE->RemoveCharAttribs(nPara, 0, true);
543 : DBG_ASSERT( pEE->GetEditDoc().GetObject( nPara ), "Undo (SetAttribs): pNode = NULL!" );
544 0 : ContentNode* pNode = pEE->GetEditDoc().GetObject( nPara );
545 0 : for (size_t nAttr = 0; nAttr < rInf.GetPrevCharAttribs().size(); ++nAttr)
546 : {
547 0 : const EditCharAttrib& rX = rInf.GetPrevCharAttribs()[nAttr];
548 : // is automatically "poolsized"
549 0 : pEE->GetEditDoc().InsertAttrib(pNode, rX.GetStart(), rX.GetEnd(), *rX.GetItem());
550 0 : if (rX.Which() == EE_FEATURE_FIELD)
551 0 : bFields = true;
552 : }
553 : }
554 0 : if ( bFields )
555 0 : pEE->UpdateFieldsOnly();
556 0 : ImpSetSelection(pEE->GetActiveView());
557 0 : }
558 :
559 0 : void EditUndoSetAttribs::Redo()
560 : {
561 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
562 0 : EditEngine* pEE = GetEditEngine();
563 :
564 0 : EditSelection aSel = pEE->CreateSelection(aESel);
565 0 : if ( !bSetIsRemove )
566 0 : pEE->SetAttribs( aSel, aNewAttribs, nSpecial );
567 : else
568 0 : pEE->RemoveCharAttribs( aSel, bRemoveParaAttribs, nRemoveWhich );
569 :
570 0 : ImpSetSelection( GetEditEngine()->GetActiveView() );
571 0 : }
572 :
573 3116 : void EditUndoSetAttribs::AppendContentInfo(ContentAttribsInfo* pNew)
574 : {
575 3116 : aPrevAttribs.push_back(pNew);
576 3116 : }
577 :
578 0 : void EditUndoSetAttribs::ImpSetSelection( EditView* /*pView*/ )
579 : {
580 0 : EditEngine* pEE = GetEditEngine();
581 0 : EditSelection aSel = pEE->CreateSelection(aESel);
582 0 : pEE->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
583 0 : }
584 :
585 0 : EditUndoTransliteration::EditUndoTransliteration(EditEngine* pEE, const ESelection& rESel, sal_Int32 nM) :
586 : EditUndo(EDITUNDO_TRANSLITERATE, pEE),
587 0 : aOldESel(rESel), nMode(nM), pTxtObj(NULL) {}
588 :
589 0 : EditUndoTransliteration::~EditUndoTransliteration()
590 : {
591 0 : delete pTxtObj;
592 0 : }
593 :
594 0 : void EditUndoTransliteration::Undo()
595 : {
596 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
597 :
598 0 : EditEngine* pEE = GetEditEngine();
599 :
600 0 : EditSelection aSel = pEE->CreateSelection(aNewESel);
601 :
602 : // Insert text, but don't expand Atribs at the current position:
603 0 : aSel = pEE->DeleteSelected( aSel );
604 0 : EditSelection aDelSel( aSel );
605 0 : aSel = pEE->InsertParaBreak( aSel );
606 0 : aDelSel.Max() = aSel.Min();
607 0 : aDelSel.Max().GetNode()->GetCharAttribs().DeleteEmptyAttribs( pEE->GetEditDoc().GetItemPool() );
608 0 : EditSelection aNewSel;
609 0 : if ( pTxtObj )
610 : {
611 0 : aNewSel = pEE->InsertText( *pTxtObj, aSel );
612 : }
613 : else
614 : {
615 0 : aNewSel = pEE->InsertText( aSel, aText );
616 : }
617 0 : if ( aNewSel.Min().GetNode() == aDelSel.Max().GetNode() )
618 : {
619 0 : aNewSel.Min().SetNode( aDelSel.Min().GetNode() );
620 0 : aNewSel.Min().GetIndex() =
621 0 : aNewSel.Min().GetIndex() + aDelSel.Min().GetIndex();
622 : }
623 0 : if ( aNewSel.Max().GetNode() == aDelSel.Max().GetNode() )
624 : {
625 0 : aNewSel.Max().SetNode( aDelSel.Min().GetNode() );
626 0 : aNewSel.Max().GetIndex() =
627 0 : aNewSel.Max().GetIndex() + aDelSel.Min().GetIndex();
628 : }
629 0 : pEE->DeleteSelected( aDelSel );
630 0 : pEE->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
631 0 : }
632 :
633 0 : void EditUndoTransliteration::Redo()
634 : {
635 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
636 0 : EditEngine* pEE = GetEditEngine();
637 :
638 0 : EditSelection aSel = pEE->CreateSelection(aOldESel);
639 0 : EditSelection aNewSel = pEE->TransliterateText( aSel, nMode );
640 0 : pEE->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
641 0 : }
642 :
643 0 : EditUndoMarkSelection::EditUndoMarkSelection(EditEngine* pEE, const ESelection& rSel) :
644 0 : EditUndo(EDITUNDO_MARKSELECTION, pEE), aSelection(rSel) {}
645 :
646 0 : EditUndoMarkSelection::~EditUndoMarkSelection() {}
647 :
648 0 : void EditUndoMarkSelection::Undo()
649 : {
650 : DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
651 0 : if ( GetEditEngine()->GetActiveView() )
652 : {
653 0 : if ( GetEditEngine()->IsFormatted() )
654 0 : GetEditEngine()->GetActiveView()->SetSelection( aSelection );
655 : else
656 0 : GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( GetEditEngine()->CreateSelection(aSelection) );
657 : }
658 0 : }
659 :
660 0 : void EditUndoMarkSelection::Redo()
661 : {
662 : // For redo unimportant, because at the beginning of the undo parentheses
663 267 : }
664 :
665 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|