bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / undo / undoblk3.cxx
blob6066984a2f555f6004dc56e44d5e534e09065efc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "scitems.hxx"
21 #include <svx/algitem.hxx>
22 #include <editeng/boxitem.hxx>
23 #include <editeng/justifyitem.hxx>
24 #include <svl/srchitem.hxx>
25 #include <sfx2/linkmgr.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <vcl/virdev.hxx>
28 #include <sfx2/app.hxx>
30 #include "undoblk.hxx"
31 #include "sc.hrc"
32 #include "globstr.hrc"
33 #include "global.hxx"
34 #include "rangenam.hxx"
35 #include "arealink.hxx"
36 #include "patattr.hxx"
37 #include "target.hxx"
38 #include "document.hxx"
39 #include "docpool.hxx"
40 #include "table.hxx"
41 #include "docsh.hxx"
42 #include "tabvwsh.hxx"
43 #include "undoolk.hxx"
44 #include "undoutil.hxx"
45 #include "chgtrack.hxx"
46 #include "dociter.hxx"
47 #include "formulacell.hxx"
48 #include "paramisc.hxx"
49 #include "postit.hxx"
50 #include "docuno.hxx"
51 #include "progress.hxx"
52 #include "editutil.hxx"
54 // STATIC DATA ---------------------------------------------------------------
56 TYPEINIT1(ScUndoDeleteContents, SfxUndoAction);
57 TYPEINIT1(ScUndoFillTable, SfxUndoAction);
58 TYPEINIT1(ScUndoSelectionAttr, SfxUndoAction);
59 TYPEINIT1(ScUndoAutoFill, SfxUndoAction);
60 TYPEINIT1(ScUndoMerge, SfxUndoAction);
61 TYPEINIT1(ScUndoAutoFormat, SfxUndoAction);
62 TYPEINIT1(ScUndoReplace, SfxUndoAction);
63 TYPEINIT1(ScUndoTabOp, SfxUndoAction);
64 TYPEINIT1(ScUndoConversion, SfxUndoAction);
65 TYPEINIT1(ScUndoRefConversion, SfxUndoAction);
66 TYPEINIT1(ScUndoRefreshLink, SfxUndoAction);
67 TYPEINIT1(ScUndoInsertAreaLink, SfxUndoAction);
68 TYPEINIT1(ScUndoRemoveAreaLink, SfxUndoAction);
69 TYPEINIT1(ScUndoUpdateAreaLink, SfxUndoAction);
71 // TODO:
72 /*A*/ // SetOptimalHeight on Document, when no View
74 ScUndoDeleteContents::ScUndoDeleteContents(
75 ScDocShell* pNewDocShell,
76 const ScMarkData& rMark, const ScRange& rRange,
77 ScDocument* pNewUndoDoc, sal_Bool bNewMulti,
78 sal_uInt16 nNewFlags, sal_Bool bObjects )
79 : ScSimpleUndo( pNewDocShell ),
80 aRange ( rRange ),
81 aMarkData ( rMark ),
82 pUndoDoc ( pNewUndoDoc ),
83 pDrawUndo ( NULL ),
84 nFlags ( nNewFlags ),
85 bMulti ( bNewMulti ) // unnecessary
87 if (bObjects)
88 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
90 if ( !(aMarkData.IsMarked() || aMarkData.IsMultiMarked()) ) // if no cell is selected:
91 aMarkData.SetMarkArea( aRange ); // select cell under cursor
93 SetChangeTrack();
96 ScUndoDeleteContents::~ScUndoDeleteContents()
98 delete pUndoDoc;
99 DeleteSdrUndoAction( pDrawUndo );
102 OUString ScUndoDeleteContents::GetComment() const
104 return ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS ); // "Delete"
107 void ScUndoDeleteContents::SetChangeTrack()
109 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
110 if ( pChangeTrack && (nFlags & IDF_CONTENTS) )
111 pChangeTrack->AppendContentRange( aRange, pUndoDoc,
112 nStartChangeAction, nEndChangeAction );
113 else
114 nStartChangeAction = nEndChangeAction = 0;
117 void ScUndoDeleteContents::DoChange( const sal_Bool bUndo )
119 ScDocument* pDoc = pDocShell->GetDocument();
121 SetViewMarkData( aMarkData );
123 sal_uInt16 nExtFlags = 0;
125 if (bUndo) // only Undo
127 sal_uInt16 nUndoFlags = IDF_NONE; // copy either all or none of the content
128 if (nFlags & IDF_CONTENTS) // (Only the correct ones have been copied into UndoDoc)
129 nUndoFlags |= IDF_CONTENTS;
130 if (nFlags & IDF_ATTRIB)
131 nUndoFlags |= IDF_ATTRIB;
132 if (nFlags & IDF_EDITATTR) // Edit-Engine attribute
133 nUndoFlags |= IDF_STRING; // -> Cells will be changed
134 // do not create clones of note captions, they will be restored via drawing undo
135 nUndoFlags |= IDF_NOCAPTIONS;
137 ScRange aCopyRange = aRange;
138 SCTAB nTabCount = pDoc->GetTableCount();
139 aCopyRange.aStart.SetTab(0);
140 aCopyRange.aEnd.SetTab(nTabCount-1);
142 pUndoDoc->CopyToDocument( aCopyRange, nUndoFlags, bMulti, pDoc, &aMarkData );
144 DoSdrUndoAction( pDrawUndo, pDoc );
146 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
147 if ( pChangeTrack )
148 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
150 pDocShell->UpdatePaintExt( nExtFlags, aRange ); // content after the change
152 else // only Redo
154 pDocShell->UpdatePaintExt( nExtFlags, aRange ); // content before the change
156 aMarkData.MarkToMulti();
157 RedoSdrUndoAction( pDrawUndo );
158 // do not delete objects and note captions, they have been removed via drawing undo
159 sal_uInt16 nRedoFlags = (nFlags & ~IDF_OBJECTS) | IDF_NOCAPTIONS;
160 pDoc->DeleteSelection( nRedoFlags, aMarkData );
161 aMarkData.MarkToSimple();
163 SetChangeTrack();
166 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
167 if ( !( (pViewShell) && pViewShell->AdjustRowHeight(
168 aRange.aStart.Row(), aRange.aEnd.Row() ) ) )
169 /*A*/ pDocShell->PostPaint( aRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
171 pDocShell->PostDataChanged();
172 if (pViewShell)
173 pViewShell->CellContentChanged();
175 ShowTable( aRange );
178 void ScUndoDeleteContents::Undo()
180 BeginUndo();
181 DoChange( sal_True );
182 EndUndo();
184 // #i97876# Spreadsheet data changes are not notified
185 ScModelObj* pModelObj = ScModelObj::getImplementation( pDocShell->GetModel() );
186 if ( pModelObj && pModelObj->HasChangesListeners() )
188 ScRangeList aChangeRanges;
189 aChangeRanges.Append( aRange );
190 pModelObj->NotifyChanges( OUString( "cell-change" ), aChangeRanges );
194 void ScUndoDeleteContents::Redo()
196 BeginRedo();
197 DoChange( false );
198 EndRedo();
200 // #i97876# Spreadsheet data changes are not notified
201 ScModelObj* pModelObj = ScModelObj::getImplementation( pDocShell->GetModel() );
202 if ( pModelObj && pModelObj->HasChangesListeners() )
204 ScRangeList aChangeRanges;
205 aChangeRanges.Append( aRange );
206 pModelObj->NotifyChanges( OUString( "cell-change" ), aChangeRanges );
210 void ScUndoDeleteContents::Repeat(SfxRepeatTarget& rTarget)
212 if (rTarget.ISA(ScTabViewTarget))
213 ((ScTabViewTarget&)rTarget).GetViewShell()->DeleteContents( nFlags, sal_True );
216 sal_Bool ScUndoDeleteContents::CanRepeat(SfxRepeatTarget& rTarget) const
218 return (rTarget.ISA(ScTabViewTarget));
221 ScUndoFillTable::ScUndoFillTable( ScDocShell* pNewDocShell,
222 const ScMarkData& rMark,
223 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
224 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
225 ScDocument* pNewUndoDoc, sal_Bool bNewMulti, SCTAB nSrc,
226 sal_uInt16 nFlg, sal_uInt16 nFunc, sal_Bool bSkip, sal_Bool bLink )
227 : ScSimpleUndo( pNewDocShell ),
228 aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
229 aMarkData ( rMark ),
230 pUndoDoc ( pNewUndoDoc ),
231 nFlags ( nFlg ),
232 nFunction ( nFunc ),
233 nSrcTab ( nSrc ),
234 bMulti ( bNewMulti ),
235 bSkipEmpty ( bSkip ),
236 bAsLink ( bLink )
238 SetChangeTrack();
241 ScUndoFillTable::~ScUndoFillTable()
243 delete pUndoDoc;
246 OUString ScUndoFillTable::GetComment() const
248 return ScGlobal::GetRscString( STR_FILL_TAB );
251 void ScUndoFillTable::SetChangeTrack()
253 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
254 if ( pChangeTrack )
256 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
257 ScRange aWorkRange(aRange);
258 nStartChangeAction = 0;
259 sal_uLong nTmpAction;
260 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
261 for (; itr != itrEnd && *itr < nTabCount; ++itr)
263 if (*itr != nSrcTab)
265 aWorkRange.aStart.SetTab(*itr);
266 aWorkRange.aEnd.SetTab(*itr);
267 pChangeTrack->AppendContentRange( aWorkRange, pUndoDoc,
268 nTmpAction, nEndChangeAction );
269 if ( !nStartChangeAction )
270 nStartChangeAction = nTmpAction;
274 else
275 nStartChangeAction = nEndChangeAction = 0;
278 void ScUndoFillTable::DoChange( const sal_Bool bUndo )
280 ScDocument* pDoc = pDocShell->GetDocument();
282 SetViewMarkData( aMarkData );
284 if (bUndo) // only Undo
286 SCTAB nTabCount = pDoc->GetTableCount();
287 ScRange aWorkRange(aRange);
288 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
289 for (; itr != itrEnd && *itr < nTabCount; ++itr)
290 if (*itr != nSrcTab)
292 aWorkRange.aStart.SetTab(*itr);
293 aWorkRange.aEnd.SetTab(*itr);
294 if (bMulti)
295 pDoc->DeleteSelectionTab( *itr, IDF_ALL, aMarkData );
296 else
297 pDoc->DeleteAreaTab( aWorkRange, IDF_ALL );
298 pUndoDoc->CopyToDocument( aWorkRange, IDF_ALL, bMulti, pDoc, &aMarkData );
301 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
302 if ( pChangeTrack )
303 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
305 else // only Redo
307 aMarkData.MarkToMulti();
308 pDoc->FillTabMarked( nSrcTab, aMarkData, nFlags, nFunction, bSkipEmpty, bAsLink );
309 aMarkData.MarkToSimple();
310 SetChangeTrack();
313 pDocShell->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_EXTRAS);
314 pDocShell->PostDataChanged();
316 // CellContentChanged comes with the selection
318 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
319 if (pViewShell)
321 SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
322 if ( !aMarkData.GetTableSelect(nTab) )
323 pViewShell->SetTabNo( nSrcTab );
325 pViewShell->DoneBlockMode(); // causes problems otherwise since selection is on the wrong sheet.
329 void ScUndoFillTable::Undo()
331 BeginUndo();
332 DoChange( sal_True );
333 EndUndo();
336 void ScUndoFillTable::Redo()
338 BeginRedo();
339 DoChange( false );
340 EndRedo();
343 void ScUndoFillTable::Repeat(SfxRepeatTarget& rTarget)
345 if (rTarget.ISA(ScTabViewTarget))
346 ((ScTabViewTarget&)rTarget).GetViewShell()->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
349 sal_Bool ScUndoFillTable::CanRepeat(SfxRepeatTarget& rTarget) const
351 return (rTarget.ISA(ScTabViewTarget));
354 ScUndoSelectionAttr::ScUndoSelectionAttr( ScDocShell* pNewDocShell,
355 const ScMarkData& rMark,
356 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
357 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
358 ScDocument* pNewUndoDoc, sal_Bool bNewMulti,
359 const ScPatternAttr* pNewApply,
360 const SvxBoxItem* pNewOuter, const SvxBoxInfoItem* pNewInner )
361 : ScSimpleUndo( pNewDocShell ),
362 aMarkData ( rMark ),
363 aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
364 mpDataArray(new ScEditDataArray),
365 pUndoDoc ( pNewUndoDoc ),
366 bMulti ( bNewMulti )
368 ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
369 pApplyPattern = (ScPatternAttr*) &pPool->Put( *pNewApply );
370 pLineOuter = pNewOuter ? (SvxBoxItem*) &pPool->Put( *pNewOuter ) : NULL;
371 pLineInner = pNewInner ? (SvxBoxInfoItem*) &pPool->Put( *pNewInner ) : NULL;
374 ScUndoSelectionAttr::~ScUndoSelectionAttr()
376 ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
377 pPool->Remove(*pApplyPattern);
378 if (pLineOuter)
379 pPool->Remove(*pLineOuter);
380 if (pLineInner)
381 pPool->Remove(*pLineInner);
383 delete pUndoDoc;
386 OUString ScUndoSelectionAttr::GetComment() const
388 //"Attribute" "/Lines"
389 return ScGlobal::GetRscString( pLineOuter ? STR_UNDO_SELATTRLINES : STR_UNDO_SELATTR );
392 ScEditDataArray* ScUndoSelectionAttr::GetDataArray()
394 return mpDataArray.get();
397 void ScUndoSelectionAttr::DoChange( const sal_Bool bUndo )
399 ScDocument* pDoc = pDocShell->GetDocument();
401 SetViewMarkData( aMarkData );
403 ScRange aEffRange( aRange );
404 if ( pDoc->HasAttrib( aEffRange, HASATTR_MERGED ) ) // merged cells?
405 pDoc->ExtendMerge( aEffRange );
407 sal_uInt16 nExtFlags = 0;
408 pDocShell->UpdatePaintExt( nExtFlags, aEffRange );
410 ChangeEditData(bUndo);
412 if (bUndo) // only for Undo
414 ScRange aCopyRange = aRange;
415 SCTAB nTabCount = pDoc->GetTableCount();
416 aCopyRange.aStart.SetTab(0);
417 aCopyRange.aEnd.SetTab(nTabCount-1);
418 pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, bMulti, pDoc, &aMarkData );
420 else // only for Redo
422 aMarkData.MarkToMulti();
423 pDoc->ApplySelectionPattern( *pApplyPattern, aMarkData );
424 aMarkData.MarkToSimple();
426 if (pLineOuter)
427 pDoc->ApplySelectionFrame( aMarkData, pLineOuter, pLineInner );
430 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
431 if ( !( (pViewShell) && pViewShell->AdjustBlockHeight() ) )
432 /*A*/ pDocShell->PostPaint( aEffRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
434 ShowTable( aRange );
437 void ScUndoSelectionAttr::ChangeEditData( const bool bUndo )
439 ScDocument* pDoc = pDocShell->GetDocument();
440 for (const ScEditDataArray::Item* pItem = mpDataArray->First(); pItem; pItem = mpDataArray->Next())
442 ScAddress aPos(pItem->GetCol(), pItem->GetRow(), pItem->GetTab());
443 if (pDoc->GetCellType(aPos) != CELLTYPE_EDIT)
444 continue;
446 if (bUndo)
448 if (pItem->GetOldData())
449 pDoc->SetEditText(aPos, *pItem->GetOldData(), NULL);
450 else
451 pDoc->SetEmptyCell(aPos);
453 else
455 if (pItem->GetNewData())
456 pDoc->SetEditText(aPos, *pItem->GetNewData(), NULL);
457 else
458 pDoc->SetEmptyCell(aPos);
463 void ScUndoSelectionAttr::Undo()
465 BeginUndo();
466 DoChange( sal_True );
467 EndUndo();
470 void ScUndoSelectionAttr::Redo()
472 BeginRedo();
473 DoChange( false );
474 EndRedo();
477 void ScUndoSelectionAttr::Repeat(SfxRepeatTarget& rTarget)
479 if (rTarget.ISA(ScTabViewTarget))
481 ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
482 if (pLineOuter)
483 rViewShell.ApplyPatternLines( *pApplyPattern, pLineOuter, pLineInner, sal_True );
484 else
485 rViewShell.ApplySelectionPattern( *pApplyPattern, sal_True );
489 sal_Bool ScUndoSelectionAttr::CanRepeat(SfxRepeatTarget& rTarget) const
491 return (rTarget.ISA(ScTabViewTarget));
494 ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell,
495 const ScRange& rRange, const ScRange& rSourceArea,
496 ScDocument* pNewUndoDoc, const ScMarkData& rMark,
497 FillDir eNewFillDir, FillCmd eNewFillCmd, FillDateCmd eNewFillDateCmd,
498 double fNewStartValue, double fNewStepValue, double fNewMaxValue )
499 : ScBlockUndo( pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT ),
500 aSource ( rSourceArea ),
501 aMarkData ( rMark ),
502 pUndoDoc ( pNewUndoDoc ),
503 eFillDir ( eNewFillDir ),
504 eFillCmd ( eNewFillCmd ),
505 eFillDateCmd ( eNewFillDateCmd ),
506 fStartValue ( fNewStartValue ),
507 fStepValue ( fNewStepValue ),
508 fMaxValue ( fNewMaxValue )
510 SetChangeTrack();
513 ScUndoAutoFill::~ScUndoAutoFill()
515 delete pUndoDoc;
518 OUString ScUndoAutoFill::GetComment() const
520 return ScGlobal::GetRscString( STR_UNDO_AUTOFILL ); //"Fill"
523 void ScUndoAutoFill::SetChangeTrack()
525 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
526 if ( pChangeTrack )
527 pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
528 nStartChangeAction, nEndChangeAction );
529 else
530 nStartChangeAction = nEndChangeAction = 0;
533 void ScUndoAutoFill::Undo()
535 BeginUndo();
537 ScDocument* pDoc = pDocShell->GetDocument();
539 SCTAB nTabCount = pDoc->GetTableCount();
540 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
541 for (; itr != itrEnd && *itr < nTabCount; ++itr)
543 ScRange aWorkRange = aBlockRange;
544 aWorkRange.aStart.SetTab(*itr);
545 aWorkRange.aEnd.SetTab(*itr);
547 sal_uInt16 nExtFlags = 0;
548 pDocShell->UpdatePaintExt( nExtFlags, aWorkRange );
549 pDoc->DeleteAreaTab( aWorkRange, IDF_AUTOFILL );
550 pUndoDoc->CopyToDocument( aWorkRange, IDF_AUTOFILL, false, pDoc );
552 pDoc->ExtendMerge( aWorkRange, sal_True );
553 pDocShell->PostPaint( aWorkRange, PAINT_GRID, nExtFlags );
555 pDocShell->PostDataChanged();
556 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
557 if (pViewShell)
558 pViewShell->CellContentChanged();
560 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
561 if ( pChangeTrack )
562 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
564 EndUndo();
567 void ScUndoAutoFill::Redo()
569 BeginRedo();
571 //! Select sheet
573 SCCOLROW nCount = 0;
574 switch (eFillDir)
576 case FILL_TO_BOTTOM:
577 nCount = aBlockRange.aEnd.Row() - aSource.aEnd.Row();
578 break;
579 case FILL_TO_RIGHT:
580 nCount = aBlockRange.aEnd.Col() - aSource.aEnd.Col();
581 break;
582 case FILL_TO_TOP:
583 nCount = aSource.aStart.Row() - aBlockRange.aStart.Row();
584 break;
585 case FILL_TO_LEFT:
586 nCount = aSource.aStart.Col() - aBlockRange.aStart.Col();
587 break;
590 ScDocument* pDoc = pDocShell->GetDocument();
591 if ( fStartValue != MAXDOUBLE )
593 SCCOL nValX = (eFillDir == FILL_TO_LEFT) ? aSource.aEnd.Col() : aSource.aStart.Col();
594 SCROW nValY = (eFillDir == FILL_TO_TOP ) ? aSource.aEnd.Row() : aSource.aStart.Row();
595 SCTAB nTab = aSource.aStart.Tab();
596 pDoc->SetValue( nValX, nValY, nTab, fStartValue );
598 sal_uLong nProgCount;
599 if (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_TOP)
600 nProgCount = aSource.aEnd.Col() - aSource.aStart.Col() + 1;
601 else
602 nProgCount = aSource.aEnd.Row() - aSource.aStart.Row() + 1;
603 nProgCount *= nCount;
604 ScProgress aProgress( pDoc->GetDocumentShell(),
605 ScGlobal::GetRscString(STR_FILL_SERIES_PROGRESS), nProgCount );
607 pDoc->Fill( aSource.aStart.Col(), aSource.aStart.Row(),
608 aSource.aEnd.Col(), aSource.aEnd.Row(), &aProgress,
609 aMarkData, nCount,
610 eFillDir, eFillCmd, eFillDateCmd,
611 fStepValue, fMaxValue );
613 SetChangeTrack();
615 pDocShell->PostPaint( aBlockRange, PAINT_GRID );
616 pDocShell->PostDataChanged();
617 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
618 if (pViewShell)
619 pViewShell->CellContentChanged();
621 EndRedo();
624 void ScUndoAutoFill::Repeat(SfxRepeatTarget& rTarget)
626 if (rTarget.ISA(ScTabViewTarget))
628 ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
629 if (eFillCmd==FILL_SIMPLE)
630 rViewShell.FillSimple( eFillDir, sal_True );
631 else
632 rViewShell.FillSeries( eFillDir, eFillCmd, eFillDateCmd,
633 fStartValue, fStepValue, fMaxValue, sal_True );
637 sal_Bool ScUndoAutoFill::CanRepeat(SfxRepeatTarget& rTarget) const
639 return (rTarget.ISA(ScTabViewTarget));
642 ScUndoMerge::ScUndoMerge( ScDocShell* pNewDocShell, const ScCellMergeOption& rOption,
643 bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo )
644 : ScSimpleUndo( pNewDocShell ),
645 maOption(rOption),
646 mbMergeContents( bMergeContents ),
647 mpUndoDoc( pUndoDoc ),
648 mpDrawUndo( pDrawUndo )
652 ScUndoMerge::~ScUndoMerge()
654 delete mpUndoDoc;
655 DeleteSdrUndoAction( mpDrawUndo );
658 OUString ScUndoMerge::GetComment() const
660 return ScGlobal::GetRscString( STR_UNDO_MERGE );
663 void ScUndoMerge::DoChange( bool bUndo ) const
665 using ::std::set;
667 if (maOption.maTabs.empty())
668 // Nothing to do.
669 return;
671 ScDocument* pDoc = pDocShell->GetDocument();
672 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
674 ScRange aCurRange = maOption.getSingleRange(pDocShell->GetCurTab());
675 ScUndoUtil::MarkSimpleBlock(pDocShell, aCurRange);
677 for (set<SCTAB>::const_iterator itr = maOption.maTabs.begin(), itrEnd = maOption.maTabs.end();
678 itr != itrEnd; ++itr)
680 SCTAB nTab = *itr;
681 ScRange aRange = maOption.getSingleRange(nTab);
683 if (bUndo)
684 // remove merge (contents are copied back below from undo document)
685 pDoc->RemoveMerge( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aStart.Tab() );
686 else
688 // repeat merge, but do not remove note captions (will be done by drawing redo below)
689 pDoc->DoMerge( aRange.aStart.Tab(),
690 aRange.aStart.Col(), aRange.aStart.Row(),
691 aRange.aEnd.Col(), aRange.aEnd.Row(), false );
693 if (maOption.mbCenter)
695 pDoc->ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
696 aRange.aStart.Tab(),
697 SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY ) );
698 pDoc->ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
699 aRange.aStart.Tab(),
700 SvxVerJustifyItem( SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY ) );
704 // undo -> copy back deleted contents
705 if (bUndo && mpUndoDoc)
707 pDoc->DeleteAreaTab( aRange, IDF_CONTENTS|IDF_NOCAPTIONS );
708 mpUndoDoc->CopyToDocument( aRange, IDF_ALL|IDF_NOCAPTIONS, false, pDoc );
711 // redo -> merge contents again
712 else if (!bUndo && mbMergeContents)
714 pDoc->DoMergeContents( aRange.aStart.Tab(),
715 aRange.aStart.Col(), aRange.aStart.Row(),
716 aRange.aEnd.Col(), aRange.aEnd.Row() );
719 if (bUndo)
720 DoSdrUndoAction( mpDrawUndo, pDoc );
721 else
722 RedoSdrUndoAction( mpDrawUndo );
724 bool bDidPaint = false;
725 if ( pViewShell )
727 pViewShell->SetTabNo(nTab);
728 bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow);
731 if (!bDidPaint)
732 ScUndoUtil::PaintMore(pDocShell, aRange);
735 ShowTable(aCurRange);
738 void ScUndoMerge::Undo()
740 BeginUndo();
741 DoChange( true );
742 EndUndo();
745 void ScUndoMerge::Redo()
747 BeginRedo();
748 DoChange( false );
749 EndRedo();
752 void ScUndoMerge::Repeat(SfxRepeatTarget& rTarget)
754 if (rTarget.ISA(ScTabViewTarget))
756 ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
757 sal_Bool bCont = false;
758 rViewShell.MergeCells( false, bCont, sal_True );
762 sal_Bool ScUndoMerge::CanRepeat(SfxRepeatTarget& rTarget) const
764 return (rTarget.ISA(ScTabViewTarget));
767 ScUndoAutoFormat::ScUndoAutoFormat( ScDocShell* pNewDocShell,
768 const ScRange& rRange, ScDocument* pNewUndoDoc,
769 const ScMarkData& rMark, sal_Bool bNewSize, sal_uInt16 nNewFormatNo )
770 : ScBlockUndo( pNewDocShell, rRange, bNewSize ? SC_UNDO_MANUALHEIGHT : SC_UNDO_AUTOHEIGHT ),
771 pUndoDoc ( pNewUndoDoc ),
772 aMarkData ( rMark ),
773 bSize ( bNewSize ),
774 nFormatNo ( nNewFormatNo )
778 ScUndoAutoFormat::~ScUndoAutoFormat()
780 delete pUndoDoc;
783 OUString ScUndoAutoFormat::GetComment() const
785 return ScGlobal::GetRscString( STR_UNDO_AUTOFORMAT ); //"Auto-Format"
788 void ScUndoAutoFormat::Undo()
790 BeginUndo();
792 ScDocument* pDoc = pDocShell->GetDocument();
794 SCTAB nTabCount = pDoc->GetTableCount();
795 pDoc->DeleteArea( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(),
796 aBlockRange.aEnd.Col(), aBlockRange.aEnd.Row(),
797 aMarkData, IDF_ATTRIB );
798 ScRange aCopyRange = aBlockRange;
799 aCopyRange.aStart.SetTab(0);
800 aCopyRange.aEnd.SetTab(nTabCount-1);
801 pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, false, pDoc, &aMarkData );
803 // cell heights and widths (IDF_NONE)
804 if (bSize)
806 SCCOL nStartX = aBlockRange.aStart.Col();
807 SCROW nStartY = aBlockRange.aStart.Row();
808 SCTAB nStartZ = aBlockRange.aStart.Tab();
809 SCCOL nEndX = aBlockRange.aEnd.Col();
810 SCROW nEndY = aBlockRange.aEnd.Row();
811 SCTAB nEndZ = aBlockRange.aEnd.Tab();
813 pUndoDoc->CopyToDocument( nStartX, 0, 0, nEndX, MAXROW, nTabCount-1,
814 IDF_NONE, false, pDoc, &aMarkData );
815 pUndoDoc->CopyToDocument( 0, nStartY, 0, MAXCOL, nEndY, nTabCount-1,
816 IDF_NONE, false, pDoc, &aMarkData );
817 pDocShell->PostPaint( 0, 0, nStartZ, MAXCOL, MAXROW, nEndZ,
818 PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES );
820 else
821 pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
823 EndUndo();
826 void ScUndoAutoFormat::Redo()
828 BeginRedo();
830 ScDocument* pDoc = pDocShell->GetDocument();
832 SCCOL nStartX = aBlockRange.aStart.Col();
833 SCROW nStartY = aBlockRange.aStart.Row();
834 SCTAB nStartZ = aBlockRange.aStart.Tab();
835 SCCOL nEndX = aBlockRange.aEnd.Col();
836 SCROW nEndY = aBlockRange.aEnd.Row();
837 SCTAB nEndZ = aBlockRange.aEnd.Tab();
839 pDoc->AutoFormat( nStartX, nStartY, nEndX, nEndY, nFormatNo, aMarkData );
841 if (bSize)
843 VirtualDevice aVirtDev;
844 Fraction aZoomX(1,1);
845 Fraction aZoomY = aZoomX;
846 double nPPTX,nPPTY;
847 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
848 if (pViewShell)
850 ScViewData* pData = pViewShell->GetViewData();
851 nPPTX = pData->GetPPTX();
852 nPPTY = pData->GetPPTY();
853 aZoomX = pData->GetZoomX();
854 aZoomY = pData->GetZoomY();
856 else
858 // Keep zoom at 100
859 nPPTX = ScGlobal::nScreenPPTX;
860 nPPTY = ScGlobal::nScreenPPTY;
863 sal_Bool bFormula = false; // remember
865 for (SCTAB nTab=nStartZ; nTab<=nEndZ; nTab++)
867 ScMarkData aDestMark;
868 aDestMark.SelectOneTable( nTab );
869 aDestMark.SetMarkArea( ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) );
870 aDestMark.MarkToMulti();
872 // as SC_SIZE_VISOPT
873 for (SCROW nRow=nStartY; nRow<=nEndY; nRow++)
875 sal_uInt8 nOld = pDoc->GetRowFlags(nRow,nTab);
876 bool bHidden = pDoc->RowHidden(nRow, nTab);
877 if ( !bHidden && ( nOld & CR_MANUALSIZE ) )
878 pDoc->SetRowFlags( nRow, nTab, nOld & ~CR_MANUALSIZE );
880 pDoc->SetOptimalHeight( nStartY, nEndY, nTab, 0, &aVirtDev,
881 nPPTX, nPPTY, aZoomX, aZoomY, false );
883 for (SCCOL nCol=nStartX; nCol<=nEndX; nCol++)
884 if (!pDoc->ColHidden(nCol, nTab))
886 sal_uInt16 nThisSize = STD_EXTRA_WIDTH + pDoc->GetOptimalColWidth( nCol, nTab,
887 &aVirtDev, nPPTX, nPPTY, aZoomX, aZoomY, bFormula,
888 &aDestMark );
889 pDoc->SetColWidth( nCol, nTab, nThisSize );
890 pDoc->ShowCol( nCol, nTab, sal_True );
894 pDocShell->PostPaint( 0, 0, nStartZ,
895 MAXCOL, MAXROW, nEndZ,
896 PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES);
898 else
899 pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
901 EndRedo();
904 void ScUndoAutoFormat::Repeat(SfxRepeatTarget& rTarget)
906 if (rTarget.ISA(ScTabViewTarget))
907 ((ScTabViewTarget&)rTarget).GetViewShell()->AutoFormat( nFormatNo, sal_True );
910 sal_Bool ScUndoAutoFormat::CanRepeat(SfxRepeatTarget& rTarget) const
912 return (rTarget.ISA(ScTabViewTarget));
915 ScUndoReplace::ScUndoReplace( ScDocShell* pNewDocShell, const ScMarkData& rMark,
916 SCCOL nCurX, SCROW nCurY, SCTAB nCurZ,
917 const String& rNewUndoStr, ScDocument* pNewUndoDoc,
918 const SvxSearchItem* pItem )
919 : ScSimpleUndo( pNewDocShell ),
920 aCursorPos ( nCurX, nCurY, nCurZ ),
921 aMarkData ( rMark ),
922 aUndoStr ( rNewUndoStr ),
923 pUndoDoc ( pNewUndoDoc )
925 pSearchItem = new SvxSearchItem( *pItem );
926 SetChangeTrack();
929 ScUndoReplace::~ScUndoReplace()
931 delete pUndoDoc;
932 delete pSearchItem;
935 void ScUndoReplace::SetChangeTrack()
937 ScDocument* pDoc = pDocShell->GetDocument();
938 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
939 if ( pChangeTrack )
941 if ( pUndoDoc )
942 { //! UndoDoc includes only the changed cells,
943 // that is why an Iterator can be used
944 pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
945 nStartChangeAction, nEndChangeAction );
947 else
949 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
950 ScChangeActionContent* pContent = new ScChangeActionContent(
951 ScRange( aCursorPos) );
952 ScCellValue aCell;
953 aCell.assign(*pDoc, aCursorPos);
954 pContent->SetOldValue( aUndoStr, pDoc );
955 pContent->SetNewValue(aCell, pDoc);
956 pChangeTrack->Append( pContent );
957 nEndChangeAction = pChangeTrack->GetActionMax();
960 else
961 nStartChangeAction = nEndChangeAction = 0;
964 OUString ScUndoReplace::GetComment() const
966 return ScGlobal::GetRscString( STR_UNDO_REPLACE ); // "Replace"
969 void ScUndoReplace::Undo()
971 BeginUndo();
973 ScDocument* pDoc = pDocShell->GetDocument();
974 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
976 ShowTable( aCursorPos.Tab() );
978 if (pUndoDoc) // only for ReplaceAll !!
980 OSL_ENSURE(pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL,
981 "ScUndoReplace:: Wrong Mode");
983 SetViewMarkData( aMarkData );
985 //! selected sheet
986 //! select range ?
988 // Undo document has no row/column information, thus copy with
989 // bColRowFlags = FALSE to not destroy Outline groups
991 sal_uInt16 nUndoFlags = (pSearchItem->GetPattern()) ? IDF_ATTRIB : IDF_CONTENTS;
992 pUndoDoc->CopyToDocument( 0, 0, 0,
993 MAXCOL, MAXROW, MAXTAB,
994 nUndoFlags, false, pDoc, NULL, false ); // without row flags
995 pDocShell->PostPaintGridAll();
997 else if (pSearchItem->GetPattern() &&
998 pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE)
1000 String aTempStr = pSearchItem->GetSearchString(); // toggle
1001 pSearchItem->SetSearchString(pSearchItem->GetReplaceString());
1002 pSearchItem->SetReplaceString(aTempStr);
1003 pDoc->ReplaceStyle( *pSearchItem,
1004 aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
1005 aMarkData, sal_True);
1006 pSearchItem->SetReplaceString(pSearchItem->GetSearchString());
1007 pSearchItem->SetSearchString(aTempStr);
1008 if (pViewShell)
1009 pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1010 SC_FOLLOW_JUMP, false, false );
1011 pDocShell->PostPaintGridAll();
1013 else if (pSearchItem->GetCellType() == SVX_SEARCHIN_NOTE)
1015 ScPostIt* pNote = pDoc->GetNotes( aCursorPos.Tab() )->findByAddress( aCursorPos );
1016 OSL_ENSURE( pNote, "ScUndoReplace::Undo - cell does not contain a note" );
1017 if (pNote)
1018 pNote->SetText( aCursorPos, aUndoStr );
1019 if (pViewShell)
1020 pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1021 SC_FOLLOW_JUMP, false, false );
1023 else
1025 // aUndoStr may contain line breaks
1026 if ( aUndoStr.Search('\n') != STRING_NOTFOUND )
1028 ScFieldEditEngine& rEngine = pDoc->GetEditEngine();
1029 rEngine.SetText(aUndoStr);
1030 pDoc->SetEditText(aCursorPos, rEngine.CreateTextObject());
1032 else
1033 pDoc->SetString( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aUndoStr );
1034 if (pViewShell)
1035 pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1036 SC_FOLLOW_JUMP, false, false );
1037 pDocShell->PostPaintGridAll();
1040 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
1041 if ( pChangeTrack )
1042 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1044 EndUndo();
1047 void ScUndoReplace::Redo()
1049 BeginRedo();
1051 ScDocument* pDoc = pDocShell->GetDocument();
1052 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1054 if (pViewShell)
1055 pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1056 SC_FOLLOW_JUMP, false, false );
1057 if (pUndoDoc)
1059 if (pViewShell)
1061 SetViewMarkData( aMarkData );
1063 pViewShell->SearchAndReplace( pSearchItem, false, sal_True );
1066 else if (pSearchItem->GetPattern() &&
1067 pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE)
1069 pDoc->ReplaceStyle( *pSearchItem,
1070 aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
1071 aMarkData, sal_True);
1072 pDocShell->PostPaintGridAll();
1074 else
1075 if (pViewShell)
1076 pViewShell->SearchAndReplace( pSearchItem, false, sal_True );
1078 SetChangeTrack();
1080 EndRedo();
1083 void ScUndoReplace::Repeat(SfxRepeatTarget& rTarget)
1085 if (rTarget.ISA(ScTabViewTarget))
1086 ((ScTabViewTarget&)rTarget).GetViewShell()->SearchAndReplace( pSearchItem, sal_True, false );
1089 sal_Bool ScUndoReplace::CanRepeat(SfxRepeatTarget& rTarget) const
1091 return (rTarget.ISA(ScTabViewTarget));
1094 // multi-operation (only simple blocks)
1095 ScUndoTabOp::ScUndoTabOp( ScDocShell* pNewDocShell,
1096 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
1097 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ, ScDocument* pNewUndoDoc,
1098 const ScRefAddress& rFormulaCell,
1099 const ScRefAddress& rFormulaEnd,
1100 const ScRefAddress& rRowCell,
1101 const ScRefAddress& rColCell,
1102 sal_uInt8 nMd )
1103 : ScSimpleUndo( pNewDocShell ),
1104 aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
1105 pUndoDoc ( pNewUndoDoc ),
1106 theFormulaCell ( rFormulaCell ),
1107 theFormulaEnd ( rFormulaEnd ),
1108 theRowCell ( rRowCell ),
1109 theColCell ( rColCell ),
1110 nMode ( nMd )
1114 ScUndoTabOp::~ScUndoTabOp()
1116 delete pUndoDoc;
1119 OUString ScUndoTabOp::GetComment() const
1121 return ScGlobal::GetRscString( STR_UNDO_TABOP ); // "Multiple operation"
1124 void ScUndoTabOp::Undo()
1126 BeginUndo();
1128 ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
1130 sal_uInt16 nExtFlags = 0;
1131 pDocShell->UpdatePaintExt( nExtFlags, aRange );
1133 ScDocument* pDoc = pDocShell->GetDocument();
1134 pDoc->DeleteAreaTab( aRange,IDF_ALL & ~IDF_NOTE );
1135 pUndoDoc->CopyToDocument( aRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1136 pDocShell->PostPaint( aRange, PAINT_GRID, nExtFlags );
1137 pDocShell->PostDataChanged();
1138 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1139 if (pViewShell)
1140 pViewShell->CellContentChanged();
1142 EndUndo();
1145 void ScUndoTabOp::Redo()
1147 BeginRedo();
1149 ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
1151 ScTabOpParam aParam( theFormulaCell, theFormulaEnd,
1152 theRowCell, theColCell,
1153 nMode );
1155 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1156 if (pViewShell)
1157 pViewShell->TabOp( aParam, false);
1159 EndRedo();
1162 void ScUndoTabOp::Repeat(SfxRepeatTarget& /* rTarget */)
1166 sal_Bool ScUndoTabOp::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1168 return false;
1171 ScUndoConversion::ScUndoConversion(
1172 ScDocShell* pNewDocShell, const ScMarkData& rMark,
1173 SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, ScDocument* pNewUndoDoc,
1174 SCCOL nNewX, SCROW nNewY, SCTAB nNewZ, ScDocument* pNewRedoDoc,
1175 const ScConversionParam& rConvParam ) :
1176 ScSimpleUndo( pNewDocShell ),
1177 aMarkData( rMark ),
1178 aCursorPos( nCurX, nCurY, nCurZ ),
1179 pUndoDoc( pNewUndoDoc ),
1180 aNewCursorPos( nNewX, nNewY, nNewZ ),
1181 pRedoDoc( pNewRedoDoc ),
1182 maConvParam( rConvParam )
1184 SetChangeTrack();
1187 ScUndoConversion::~ScUndoConversion()
1189 delete pUndoDoc;
1190 delete pRedoDoc;
1193 void ScUndoConversion::SetChangeTrack()
1195 ScDocument* pDoc = pDocShell->GetDocument();
1196 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
1197 if ( pChangeTrack )
1199 if ( pUndoDoc )
1200 pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
1201 nStartChangeAction, nEndChangeAction );
1202 else
1204 OSL_FAIL( "ScUndoConversion::SetChangeTrack: no UndoDoc" );
1205 nStartChangeAction = nEndChangeAction = 0;
1208 else
1209 nStartChangeAction = nEndChangeAction = 0;
1212 OUString ScUndoConversion::GetComment() const
1214 OUString aText;
1215 switch( maConvParam.GetType() )
1217 case SC_CONVERSION_SPELLCHECK: aText = ScGlobal::GetRscString( STR_UNDO_SPELLING ); break;
1218 case SC_CONVERSION_HANGULHANJA: aText = ScGlobal::GetRscString( STR_UNDO_HANGULHANJA ); break;
1219 case SC_CONVERSION_CHINESE_TRANSL: aText = ScGlobal::GetRscString( STR_UNDO_CHINESE_TRANSLATION ); break;
1220 default: OSL_FAIL( "ScUndoConversion::GetComment - unknown conversion type" );
1222 return aText;
1225 void ScUndoConversion::DoChange( ScDocument* pRefDoc, const ScAddress& rCursorPos )
1227 if (pRefDoc)
1229 ScDocument* pDoc = pDocShell->GetDocument();
1230 ShowTable( rCursorPos.Tab() );
1232 SetViewMarkData( aMarkData );
1234 SCTAB nTabCount = pDoc->GetTableCount();
1235 // Undo/Redo-doc has only selected tables
1237 sal_Bool bMulti = aMarkData.IsMultiMarked();
1238 pRefDoc->CopyToDocument( 0, 0, 0,
1239 MAXCOL, MAXROW, nTabCount-1,
1240 IDF_CONTENTS, bMulti, pDoc, &aMarkData );
1241 pDocShell->PostPaintGridAll();
1243 else
1245 OSL_FAIL("no Un-/RedoDoc for Un-/RedoSpelling");
1249 void ScUndoConversion::Undo()
1251 BeginUndo();
1252 DoChange( pUndoDoc, aCursorPos );
1253 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1254 if ( pChangeTrack )
1255 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1256 EndUndo();
1259 void ScUndoConversion::Redo()
1261 BeginRedo();
1262 DoChange( pRedoDoc, aNewCursorPos );
1263 SetChangeTrack();
1264 EndRedo();
1267 void ScUndoConversion::Repeat( SfxRepeatTarget& rTarget )
1269 if( rTarget.ISA( ScTabViewTarget ) )
1270 ((ScTabViewTarget&)rTarget).GetViewShell()->DoSheetConversion( maConvParam, sal_True );
1273 sal_Bool ScUndoConversion::CanRepeat(SfxRepeatTarget& rTarget) const
1275 return rTarget.ISA( ScTabViewTarget );
1278 ScUndoRefConversion::ScUndoRefConversion( ScDocShell* pNewDocShell,
1279 const ScRange& aMarkRange, const ScMarkData& rMark,
1280 ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc, sal_Bool bNewMulti, sal_uInt16 nNewFlag) :
1281 ScSimpleUndo( pNewDocShell ),
1282 aMarkData ( rMark ),
1283 pUndoDoc ( pNewUndoDoc ),
1284 pRedoDoc ( pNewRedoDoc ),
1285 aRange ( aMarkRange ),
1286 bMulti ( bNewMulti ),
1287 nFlags ( nNewFlag )
1289 SetChangeTrack();
1292 ScUndoRefConversion::~ScUndoRefConversion()
1294 delete pUndoDoc;
1295 delete pRedoDoc;
1298 OUString ScUndoRefConversion::GetComment() const
1300 return ScGlobal::GetRscString( STR_UNDO_ENTERDATA ); // "Input"
1303 void ScUndoRefConversion::SetChangeTrack()
1305 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1306 if ( pChangeTrack && (nFlags & IDF_FORMULA) )
1307 pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
1308 nStartChangeAction, nEndChangeAction );
1309 else
1310 nStartChangeAction = nEndChangeAction = 0;
1313 void ScUndoRefConversion::DoChange( ScDocument* pRefDoc)
1315 ScDocument* pDoc = pDocShell->GetDocument();
1317 ShowTable(aRange);
1319 SetViewMarkData( aMarkData );
1321 ScRange aCopyRange = aRange;
1322 SCTAB nTabCount = pDoc->GetTableCount();
1323 aCopyRange.aStart.SetTab(0);
1324 aCopyRange.aEnd.SetTab(nTabCount-1);
1325 pRefDoc->CopyToDocument( aCopyRange, nFlags, bMulti, pDoc, &aMarkData );
1326 pDocShell->PostPaint( aRange, PAINT_GRID);
1327 pDocShell->PostDataChanged();
1328 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1329 if (pViewShell)
1330 pViewShell->CellContentChanged();
1333 void ScUndoRefConversion::Undo()
1335 BeginUndo();
1336 if (pUndoDoc)
1337 DoChange(pUndoDoc);
1338 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1339 if ( pChangeTrack )
1340 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1341 EndUndo();
1344 void ScUndoRefConversion::Redo()
1346 BeginRedo();
1347 if (pRedoDoc)
1348 DoChange(pRedoDoc);
1349 SetChangeTrack();
1350 EndRedo();
1353 void ScUndoRefConversion::Repeat(SfxRepeatTarget& rTarget)
1355 if (rTarget.ISA(ScTabViewTarget))
1356 ((ScTabViewTarget&)rTarget).GetViewShell()->DoRefConversion();
1359 sal_Bool ScUndoRefConversion::CanRepeat(SfxRepeatTarget& rTarget) const
1361 return (rTarget.ISA(ScTabViewTarget));
1364 ScUndoRefreshLink::ScUndoRefreshLink( ScDocShell* pNewDocShell,
1365 ScDocument* pNewUndoDoc )
1366 : ScSimpleUndo( pNewDocShell ),
1367 pUndoDoc( pNewUndoDoc ),
1368 pRedoDoc( NULL )
1372 ScUndoRefreshLink::~ScUndoRefreshLink()
1374 delete pUndoDoc;
1375 delete pRedoDoc;
1378 OUString ScUndoRefreshLink::GetComment() const
1380 return ScGlobal::GetRscString( STR_UNDO_UPDATELINK );
1383 void ScUndoRefreshLink::Undo()
1385 BeginUndo();
1387 sal_Bool bMakeRedo = !pRedoDoc;
1388 if (bMakeRedo)
1389 pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
1391 sal_Bool bFirst = sal_True;
1392 ScDocument* pDoc = pDocShell->GetDocument();
1393 SCTAB nCount = pDoc->GetTableCount();
1394 for (SCTAB nTab=0; nTab<nCount; nTab++)
1395 if (pUndoDoc->HasTable(nTab))
1397 ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
1398 if (bMakeRedo)
1400 if (bFirst)
1401 pRedoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
1402 else
1403 pRedoDoc->AddUndoTab( nTab, nTab, true, true );
1404 bFirst = false;
1405 pDoc->CopyToDocument(aRange, IDF_ALL, false, pRedoDoc);
1406 pRedoDoc->SetLink( nTab,
1407 pDoc->GetLinkMode(nTab),
1408 pDoc->GetLinkDoc(nTab),
1409 pDoc->GetLinkFlt(nTab),
1410 pDoc->GetLinkOpt(nTab),
1411 pDoc->GetLinkTab(nTab),
1412 pDoc->GetLinkRefreshDelay(nTab) );
1413 pRedoDoc->SetTabBgColor( nTab, pDoc->GetTabBgColor(nTab) );
1416 pDoc->DeleteAreaTab( aRange,IDF_ALL );
1417 pUndoDoc->CopyToDocument( aRange, IDF_ALL, false, pDoc );
1418 pDoc->SetLink( nTab, pUndoDoc->GetLinkMode(nTab), pUndoDoc->GetLinkDoc(nTab),
1419 pUndoDoc->GetLinkFlt(nTab), pUndoDoc->GetLinkOpt(nTab),
1420 pUndoDoc->GetLinkTab(nTab),
1421 pUndoDoc->GetLinkRefreshDelay(nTab) );
1422 pDoc->SetTabBgColor( nTab, pUndoDoc->GetTabBgColor(nTab) );
1425 pDocShell->PostPaintGridAll();
1426 pDocShell->PostPaintExtras();
1428 EndUndo();
1431 void ScUndoRefreshLink::Redo()
1433 OSL_ENSURE(pRedoDoc, "No RedoDoc for ScUndoRefreshLink::Redo");
1435 BeginUndo();
1437 ScDocument* pDoc = pDocShell->GetDocument();
1438 SCTAB nCount = pDoc->GetTableCount();
1439 for (SCTAB nTab=0; nTab<nCount; nTab++)
1440 if (pRedoDoc->HasTable(nTab))
1442 ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
1444 pDoc->DeleteAreaTab( aRange, IDF_ALL );
1445 pRedoDoc->CopyToDocument( aRange, IDF_ALL, false, pDoc );
1446 pDoc->SetLink( nTab,
1447 pRedoDoc->GetLinkMode(nTab),
1448 pRedoDoc->GetLinkDoc(nTab),
1449 pRedoDoc->GetLinkFlt(nTab),
1450 pRedoDoc->GetLinkOpt(nTab),
1451 pRedoDoc->GetLinkTab(nTab),
1452 pRedoDoc->GetLinkRefreshDelay(nTab) );
1453 pDoc->SetTabBgColor( nTab, pRedoDoc->GetTabBgColor(nTab) );
1456 pDocShell->PostPaintGridAll();
1457 pDocShell->PostPaintExtras();
1459 EndUndo();
1462 void ScUndoRefreshLink::Repeat(SfxRepeatTarget& /* rTarget */)
1464 // makes no sense
1467 sal_Bool ScUndoRefreshLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1469 return false;
1472 static ScAreaLink* lcl_FindAreaLink( sfx2::LinkManager* pLinkManager, const String& rDoc,
1473 const String& rFlt, const String& rOpt,
1474 const String& rSrc, const ScRange& rDest )
1476 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
1477 sal_uInt16 nCount = pLinkManager->GetLinks().size();
1478 for (sal_uInt16 i=0; i<nCount; i++)
1480 ::sfx2::SvBaseLink* pBase = *rLinks[i];
1481 if (pBase->ISA(ScAreaLink))
1482 if ( ((ScAreaLink*)pBase)->IsEqual( rDoc, rFlt, rOpt, rSrc, rDest ) )
1483 return (ScAreaLink*)pBase;
1486 OSL_FAIL("ScAreaLink not found");
1487 return NULL;
1490 ScUndoInsertAreaLink::ScUndoInsertAreaLink( ScDocShell* pShell,
1491 const String& rDoc,
1492 const String& rFlt, const String& rOpt,
1493 const String& rArea, const ScRange& rDestRange,
1494 sal_uLong nRefresh )
1495 : ScSimpleUndo ( pShell ),
1496 aDocName ( rDoc ),
1497 aFltName ( rFlt ),
1498 aOptions ( rOpt ),
1499 aAreaName ( rArea ),
1500 aRange ( rDestRange ),
1501 nRefreshDelay ( nRefresh )
1505 ScUndoInsertAreaLink::~ScUndoInsertAreaLink()
1509 OUString ScUndoInsertAreaLink::GetComment() const
1511 return ScGlobal::GetRscString( STR_UNDO_INSERTAREALINK );
1514 void ScUndoInsertAreaLink::Undo()
1516 ScDocument* pDoc = pDocShell->GetDocument();
1517 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1519 ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
1520 aAreaName, aRange );
1521 if (pLink)
1522 pLinkManager->Remove( pLink );
1524 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1527 void ScUndoInsertAreaLink::Redo()
1529 ScDocument* pDoc = pDocShell->GetDocument();
1530 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1532 ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
1533 aAreaName, aRange.aStart, nRefreshDelay );
1534 pLink->SetInCreate( sal_True );
1535 pLink->SetDestArea( aRange );
1536 pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
1537 pLink->Update();
1538 pLink->SetInCreate( false );
1540 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1543 void ScUndoInsertAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1545 // makes no sense
1548 sal_Bool ScUndoInsertAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1550 return false;
1553 ScUndoRemoveAreaLink::ScUndoRemoveAreaLink( ScDocShell* pShell,
1554 const String& rDoc, const String& rFlt, const String& rOpt,
1555 const String& rArea, const ScRange& rDestRange,
1556 sal_uLong nRefresh )
1557 : ScSimpleUndo ( pShell ),
1558 aDocName ( rDoc ),
1559 aFltName ( rFlt ),
1560 aOptions ( rOpt ),
1561 aAreaName ( rArea ),
1562 aRange ( rDestRange ),
1563 nRefreshDelay ( nRefresh )
1567 ScUndoRemoveAreaLink::~ScUndoRemoveAreaLink()
1571 OUString ScUndoRemoveAreaLink::GetComment() const
1573 return ScGlobal::GetRscString( STR_UNDO_REMOVELINK ); //! eigener Text ??
1576 void ScUndoRemoveAreaLink::Undo()
1578 ScDocument* pDoc = pDocShell->GetDocument();
1579 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1581 ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
1582 aAreaName, aRange.aStart, nRefreshDelay );
1583 pLink->SetInCreate( sal_True );
1584 pLink->SetDestArea( aRange );
1585 pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
1586 pLink->Update();
1587 pLink->SetInCreate( false );
1589 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1592 void ScUndoRemoveAreaLink::Redo()
1594 ScDocument* pDoc = pDocShell->GetDocument();
1595 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1597 ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
1598 aAreaName, aRange );
1599 if (pLink)
1600 pLinkManager->Remove( pLink );
1602 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1605 void ScUndoRemoveAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1607 // makes no sense
1610 sal_Bool ScUndoRemoveAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1612 return false;
1615 ScUndoUpdateAreaLink::ScUndoUpdateAreaLink( ScDocShell* pShell,
1616 const String& rOldD, const String& rOldF, const String& rOldO,
1617 const String& rOldA, const ScRange& rOldR, sal_uLong nOldRD,
1618 const String& rNewD, const String& rNewF, const String& rNewO,
1619 const String& rNewA, const ScRange& rNewR, sal_uLong nNewRD,
1620 ScDocument* pUndo, ScDocument* pRedo, sal_Bool bDoInsert )
1621 : ScSimpleUndo( pShell ),
1622 aOldDoc ( rOldD ),
1623 aOldFlt ( rOldF ),
1624 aOldOpt ( rOldO ),
1625 aOldArea ( rOldA ),
1626 aOldRange ( rOldR ),
1627 aNewDoc ( rNewD ),
1628 aNewFlt ( rNewF ),
1629 aNewOpt ( rNewO ),
1630 aNewArea ( rNewA ),
1631 aNewRange ( rNewR ),
1632 pUndoDoc ( pUndo ),
1633 pRedoDoc ( pRedo ),
1634 nOldRefresh ( nOldRD ),
1635 nNewRefresh ( nNewRD ),
1636 bWithInsert ( bDoInsert )
1638 OSL_ENSURE( aOldRange.aStart == aNewRange.aStart, "AreaLink moved ?" );
1641 ScUndoUpdateAreaLink::~ScUndoUpdateAreaLink()
1643 delete pUndoDoc;
1644 delete pRedoDoc;
1647 OUString ScUndoUpdateAreaLink::GetComment() const
1649 return ScGlobal::GetRscString( STR_UNDO_UPDATELINK ); //! own text ??
1652 void ScUndoUpdateAreaLink::DoChange( const sal_Bool bUndo ) const
1654 ScDocument* pDoc = pDocShell->GetDocument();
1656 SCCOL nEndX = std::max( aOldRange.aEnd.Col(), aNewRange.aEnd.Col() );
1657 SCROW nEndY = std::max( aOldRange.aEnd.Row(), aNewRange.aEnd.Row() );
1658 SCTAB nEndZ = std::max( aOldRange.aEnd.Tab(), aNewRange.aEnd.Tab() ); //?
1660 if ( bUndo )
1662 if ( bWithInsert )
1664 pDoc->FitBlock( aNewRange, aOldRange );
1665 pDoc->DeleteAreaTab( aOldRange, IDF_ALL & ~IDF_NOTE );
1666 pUndoDoc->UndoToDocument( aOldRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1668 else
1670 ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
1671 pDoc->DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
1672 pUndoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1675 else
1677 if ( bWithInsert )
1679 pDoc->FitBlock( aOldRange, aNewRange );
1680 pDoc->DeleteAreaTab( aNewRange, IDF_ALL & ~IDF_NOTE );
1681 pRedoDoc->CopyToDocument( aNewRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1683 else
1685 ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
1686 pDoc->DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
1687 pRedoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1691 ScRange aWorkRange( aNewRange.aStart, ScAddress( nEndX, nEndY, nEndZ ) );
1692 pDoc->ExtendMerge( aWorkRange, sal_True );
1694 // Paint
1696 if ( aNewRange.aEnd.Col() != aOldRange.aEnd.Col() )
1697 aWorkRange.aEnd.SetCol(MAXCOL);
1698 if ( aNewRange.aEnd.Row() != aOldRange.aEnd.Row() )
1699 aWorkRange.aEnd.SetRow(MAXROW);
1701 if ( !pDocShell->AdjustRowHeight( aWorkRange.aStart.Row(), aWorkRange.aEnd.Row(), aWorkRange.aStart.Tab() ) )
1702 pDocShell->PostPaint( aWorkRange, PAINT_GRID );
1704 pDocShell->PostDataChanged();
1705 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1706 if (pViewShell)
1707 pViewShell->CellContentChanged();
1710 void ScUndoUpdateAreaLink::Undo()
1712 ScDocument* pDoc = pDocShell->GetDocument();
1713 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1714 ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aNewDoc, aNewFlt, aNewOpt,
1715 aNewArea, aNewRange );
1716 if (pLink)
1718 pLink->SetSource( aOldDoc, aOldFlt, aOldOpt, aOldArea ); // old data in Link
1719 pLink->SetDestArea( aOldRange );
1720 pLink->SetRefreshDelay( nOldRefresh );
1723 DoChange(sal_True);
1726 void ScUndoUpdateAreaLink::Redo()
1728 ScDocument* pDoc = pDocShell->GetDocument();
1729 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1730 ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aOldDoc, aOldFlt, aOldOpt,
1731 aOldArea, aOldRange );
1732 if (pLink)
1734 pLink->SetSource( aNewDoc, aNewFlt, aNewOpt, aNewArea ); // neue Werte im Link
1735 pLink->SetDestArea( aNewRange );
1736 pLink->SetRefreshDelay( nNewRefresh );
1739 DoChange(false);
1742 void ScUndoUpdateAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1744 // makes no sense
1747 sal_Bool ScUndoUpdateAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1749 return false;
1752 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */