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