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