fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / undo / undoblk3.cxx
blob764d7170f624d950f5dd0d068170f279c65f5980
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"
53 #include "editdataarray.hxx"
54 #include <rowheightcontext.hxx>
56 // STATIC DATA ---------------------------------------------------------------
58 TYPEINIT1(ScUndoDeleteContents, SfxUndoAction);
59 TYPEINIT1(ScUndoFillTable, SfxUndoAction);
60 TYPEINIT1(ScUndoSelectionAttr, SfxUndoAction);
61 TYPEINIT1(ScUndoAutoFill, SfxUndoAction);
62 TYPEINIT1(ScUndoMerge, SfxUndoAction);
63 TYPEINIT1(ScUndoAutoFormat, SfxUndoAction);
64 TYPEINIT1(ScUndoReplace, SfxUndoAction);
65 TYPEINIT1(ScUndoTabOp, SfxUndoAction);
66 TYPEINIT1(ScUndoConversion, SfxUndoAction);
67 TYPEINIT1(ScUndoRefConversion, SfxUndoAction);
68 TYPEINIT1(ScUndoRefreshLink, SfxUndoAction);
69 TYPEINIT1(ScUndoInsertAreaLink, SfxUndoAction);
70 TYPEINIT1(ScUndoRemoveAreaLink, SfxUndoAction);
71 TYPEINIT1(ScUndoUpdateAreaLink, SfxUndoAction);
73 // TODO:
74 /*A*/ // SetOptimalHeight on Document, when no View
76 ScUndoDeleteContents::ScUndoDeleteContents(
77 ScDocShell* pNewDocShell,
78 const ScMarkData& rMark, const ScRange& rRange,
79 ScDocument* pNewUndoDoc, bool bNewMulti,
80 InsertDeleteFlags nNewFlags, bool bObjects )
81 : ScSimpleUndo( pNewDocShell ),
82 aRange ( rRange ),
83 aMarkData ( rMark ),
84 pUndoDoc ( pNewUndoDoc ),
85 pDrawUndo ( NULL ),
86 nFlags ( nNewFlags ),
87 bMulti ( bNewMulti ) // unnecessary
89 if (bObjects)
90 pDrawUndo = GetSdrUndoAction( &pDocShell->GetDocument() );
92 if ( !(aMarkData.IsMarked() || aMarkData.IsMultiMarked()) ) // if no cell is selected:
93 aMarkData.SetMarkArea( aRange ); // select cell under cursor
95 SetChangeTrack();
98 ScUndoDeleteContents::~ScUndoDeleteContents()
100 delete pUndoDoc;
101 DeleteSdrUndoAction( pDrawUndo );
104 OUString ScUndoDeleteContents::GetComment() const
106 return ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS ); // "Delete"
109 void ScUndoDeleteContents::SetDataSpans( const boost::shared_ptr<DataSpansType>& pSpans )
111 mpDataSpans = pSpans;
114 void ScUndoDeleteContents::SetChangeTrack()
116 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
117 if ( pChangeTrack && (nFlags & IDF_CONTENTS) )
118 pChangeTrack->AppendContentRange( aRange, pUndoDoc,
119 nStartChangeAction, nEndChangeAction );
120 else
121 nStartChangeAction = nEndChangeAction = 0;
124 void ScUndoDeleteContents::DoChange( const bool bUndo )
126 ScDocument& rDoc = pDocShell->GetDocument();
128 SetViewMarkData( aMarkData );
130 sal_uInt16 nExtFlags = 0;
132 if (bUndo) // only Undo
134 InsertDeleteFlags nUndoFlags = IDF_NONE; // copy either all or none of the content
135 if (nFlags & IDF_CONTENTS) // (Only the correct ones have been copied into UndoDoc)
136 nUndoFlags |= IDF_CONTENTS;
137 if (nFlags & IDF_ATTRIB)
138 nUndoFlags |= IDF_ATTRIB;
139 if (nFlags & IDF_EDITATTR) // Edit-Engine attribute
140 nUndoFlags |= IDF_STRING; // -> Cells will be changed
141 // do not create clones of note captions, they will be restored via drawing undo
142 nUndoFlags |= IDF_NOCAPTIONS;
144 ScRange aCopyRange = aRange;
145 SCTAB nTabCount = rDoc.GetTableCount();
146 aCopyRange.aStart.SetTab(0);
147 aCopyRange.aEnd.SetTab(nTabCount-1);
149 pUndoDoc->CopyToDocument( aCopyRange, nUndoFlags, bMulti, &rDoc, &aMarkData );
151 DoSdrUndoAction( pDrawUndo, &rDoc );
153 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
154 if ( pChangeTrack )
155 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
157 pDocShell->UpdatePaintExt( nExtFlags, aRange ); // content after the change
159 else // only Redo
161 pDocShell->UpdatePaintExt( nExtFlags, aRange ); // content before the change
163 aMarkData.MarkToMulti();
164 RedoSdrUndoAction( pDrawUndo );
165 // do not delete objects and note captions, they have been removed via drawing undo
166 InsertDeleteFlags nRedoFlags = (nFlags & ~IDF_OBJECTS) | IDF_NOCAPTIONS;
167 rDoc.DeleteSelection( nRedoFlags, aMarkData );
168 aMarkData.MarkToSimple();
170 SetChangeTrack();
173 if (nFlags & IDF_CONTENTS)
175 // Broadcast only when the content changes. fdo#74687
176 if (mpDataSpans)
177 BroadcastChanges(*mpDataSpans);
178 else
179 BroadcastChanges(aRange);
182 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
183 if ( !( (pViewShell) && pViewShell->AdjustRowHeight(
184 aRange.aStart.Row(), aRange.aEnd.Row() ) ) )
185 /*A*/ pDocShell->PostPaint( aRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
187 if (pViewShell)
188 pViewShell->CellContentChanged();
190 ShowTable( aRange );
193 void ScUndoDeleteContents::Undo()
195 BeginUndo();
196 DoChange( true );
197 EndUndo();
199 HelperNotifyChanges::NotifyIfChangesListeners(*pDocShell, aRange);
202 void ScUndoDeleteContents::Redo()
204 BeginRedo();
205 DoChange( false );
206 EndRedo();
208 HelperNotifyChanges::NotifyIfChangesListeners(*pDocShell, aRange);
211 void ScUndoDeleteContents::Repeat(SfxRepeatTarget& rTarget)
213 if (rTarget.ISA(ScTabViewTarget))
214 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DeleteContents( nFlags, true );
217 bool ScUndoDeleteContents::CanRepeat(SfxRepeatTarget& rTarget) const
219 return rTarget.ISA(ScTabViewTarget);
222 ScUndoFillTable::ScUndoFillTable( ScDocShell* pNewDocShell,
223 const ScMarkData& rMark,
224 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
225 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
226 ScDocument* pNewUndoDoc, bool bNewMulti, SCTAB nSrc,
227 InsertDeleteFlags nFlg, sal_uInt16 nFunc, bool bSkip, bool bLink )
228 : ScSimpleUndo( pNewDocShell ),
229 aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
230 aMarkData ( rMark ),
231 pUndoDoc ( pNewUndoDoc ),
232 nFlags ( nFlg ),
233 nFunction ( nFunc ),
234 nSrcTab ( nSrc ),
235 bMulti ( bNewMulti ),
236 bSkipEmpty ( bSkip ),
237 bAsLink ( bLink )
239 SetChangeTrack();
242 ScUndoFillTable::~ScUndoFillTable()
244 delete pUndoDoc;
247 OUString ScUndoFillTable::GetComment() const
249 return ScGlobal::GetRscString( STR_FILL_TAB );
252 void ScUndoFillTable::SetChangeTrack()
254 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
255 if ( pChangeTrack )
257 SCTAB nTabCount = pDocShell->GetDocument().GetTableCount();
258 ScRange aWorkRange(aRange);
259 nStartChangeAction = 0;
260 sal_uLong nTmpAction;
261 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
262 for (; itr != itrEnd && *itr < nTabCount; ++itr)
264 if (*itr != nSrcTab)
266 aWorkRange.aStart.SetTab(*itr);
267 aWorkRange.aEnd.SetTab(*itr);
268 pChangeTrack->AppendContentRange( aWorkRange, pUndoDoc,
269 nTmpAction, nEndChangeAction );
270 if ( !nStartChangeAction )
271 nStartChangeAction = nTmpAction;
275 else
276 nStartChangeAction = nEndChangeAction = 0;
279 void ScUndoFillTable::DoChange( const bool bUndo )
281 ScDocument& rDoc = pDocShell->GetDocument();
283 SetViewMarkData( aMarkData );
285 if (bUndo) // only Undo
287 SCTAB nTabCount = rDoc.GetTableCount();
288 ScRange aWorkRange(aRange);
289 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
290 for (; itr != itrEnd && *itr < nTabCount; ++itr)
291 if (*itr != nSrcTab)
293 aWorkRange.aStart.SetTab(*itr);
294 aWorkRange.aEnd.SetTab(*itr);
295 if (bMulti)
296 rDoc.DeleteSelectionTab( *itr, IDF_ALL, aMarkData );
297 else
298 rDoc.DeleteAreaTab( aWorkRange, IDF_ALL );
299 pUndoDoc->CopyToDocument( aWorkRange, IDF_ALL, bMulti, &rDoc, &aMarkData );
302 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
303 if ( pChangeTrack )
304 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
306 else // only Redo
308 aMarkData.MarkToMulti();
309 rDoc.FillTabMarked( nSrcTab, aMarkData, nFlags, nFunction, bSkipEmpty, bAsLink );
310 aMarkData.MarkToSimple();
311 SetChangeTrack();
314 pDocShell->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_EXTRAS);
315 pDocShell->PostDataChanged();
317 // CellContentChanged comes with the selection
319 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
320 if (pViewShell)
322 SCTAB nTab = pViewShell->GetViewData().GetTabNo();
323 if ( !aMarkData.GetTableSelect(nTab) )
324 pViewShell->SetTabNo( nSrcTab );
326 pViewShell->DoneBlockMode(); // causes problems otherwise since selection is on the wrong sheet.
330 void ScUndoFillTable::Undo()
332 BeginUndo();
333 DoChange( true );
334 EndUndo();
337 void ScUndoFillTable::Redo()
339 BeginRedo();
340 DoChange( false );
341 EndRedo();
344 void ScUndoFillTable::Repeat(SfxRepeatTarget& rTarget)
346 if (rTarget.ISA(ScTabViewTarget))
347 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
350 bool ScUndoFillTable::CanRepeat(SfxRepeatTarget& rTarget) const
352 return rTarget.ISA(ScTabViewTarget);
355 ScUndoSelectionAttr::ScUndoSelectionAttr( ScDocShell* pNewDocShell,
356 const ScMarkData& rMark,
357 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
358 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
359 ScDocument* pNewUndoDoc, bool bNewMulti,
360 const ScPatternAttr* pNewApply,
361 const SvxBoxItem* pNewOuter, const SvxBoxInfoItem* pNewInner )
362 : ScSimpleUndo( pNewDocShell ),
363 aMarkData ( rMark ),
364 aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
365 mpDataArray(new ScEditDataArray),
366 pUndoDoc ( pNewUndoDoc ),
367 bMulti ( bNewMulti )
369 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
370 pApplyPattern = const_cast<ScPatternAttr*>(static_cast<const ScPatternAttr*>( &pPool->Put( *pNewApply ) ));
371 pLineOuter = pNewOuter ? const_cast<SvxBoxItem*>(static_cast<const SvxBoxItem*>( &pPool->Put( *pNewOuter ) )) : NULL;
372 pLineInner = pNewInner ? const_cast<SvxBoxInfoItem*>(static_cast<const SvxBoxInfoItem*>( &pPool->Put( *pNewInner ) )) : NULL;
375 ScUndoSelectionAttr::~ScUndoSelectionAttr()
377 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
378 pPool->Remove(*pApplyPattern);
379 if (pLineOuter)
380 pPool->Remove(*pLineOuter);
381 if (pLineInner)
382 pPool->Remove(*pLineInner);
384 delete pUndoDoc;
387 OUString ScUndoSelectionAttr::GetComment() const
389 //"Attribute" "/Lines"
390 return ScGlobal::GetRscString( pLineOuter ? STR_UNDO_SELATTRLINES : STR_UNDO_SELATTR );
393 ScEditDataArray* ScUndoSelectionAttr::GetDataArray()
395 return mpDataArray.get();
398 void ScUndoSelectionAttr::DoChange( const bool bUndo )
400 ScDocument& rDoc = pDocShell->GetDocument();
402 SetViewMarkData( aMarkData );
404 ScRange aEffRange( aRange );
405 if ( rDoc.HasAttrib( aEffRange, HASATTR_MERGED ) ) // merged cells?
406 rDoc.ExtendMerge( aEffRange );
408 sal_uInt16 nExtFlags = 0;
409 pDocShell->UpdatePaintExt( nExtFlags, aEffRange );
411 ChangeEditData(bUndo);
413 if (bUndo) // only for Undo
415 ScRange aCopyRange = aRange;
416 SCTAB nTabCount = rDoc.GetTableCount();
417 aCopyRange.aStart.SetTab(0);
418 aCopyRange.aEnd.SetTab(nTabCount-1);
419 pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, bMulti, &rDoc, &aMarkData );
421 else // only for Redo
423 aMarkData.MarkToMulti();
424 rDoc.ApplySelectionPattern( *pApplyPattern, aMarkData );
425 aMarkData.MarkToSimple();
427 if (pLineOuter)
428 rDoc.ApplySelectionFrame( aMarkData, pLineOuter, pLineInner );
431 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
432 if ( !( (pViewShell) && pViewShell->AdjustBlockHeight() ) )
433 /*A*/ pDocShell->PostPaint( aEffRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
435 ShowTable( aRange );
438 void ScUndoSelectionAttr::ChangeEditData( const bool bUndo )
440 ScDocument& rDoc = pDocShell->GetDocument();
441 for (const ScEditDataArray::Item* pItem = mpDataArray->First(); pItem; pItem = mpDataArray->Next())
443 ScAddress aPos(pItem->GetCol(), pItem->GetRow(), pItem->GetTab());
444 if (rDoc.GetCellType(aPos) != CELLTYPE_EDIT)
445 continue;
447 if (bUndo)
449 if (pItem->GetOldData())
450 rDoc.SetEditText(aPos, *pItem->GetOldData(), NULL);
451 else
452 rDoc.SetEmptyCell(aPos);
454 else
456 if (pItem->GetNewData())
457 rDoc.SetEditText(aPos, *pItem->GetNewData(), NULL);
458 else
459 rDoc.SetEmptyCell(aPos);
464 void ScUndoSelectionAttr::Undo()
466 BeginUndo();
467 DoChange( true );
468 EndUndo();
471 void ScUndoSelectionAttr::Redo()
473 BeginRedo();
474 DoChange( false );
475 EndRedo();
478 void ScUndoSelectionAttr::Repeat(SfxRepeatTarget& rTarget)
480 if (rTarget.ISA(ScTabViewTarget))
482 ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
483 if (pLineOuter)
484 rViewShell.ApplyPatternLines( *pApplyPattern, pLineOuter, pLineInner, true );
485 else
486 rViewShell.ApplySelectionPattern( *pApplyPattern, true );
490 bool ScUndoSelectionAttr::CanRepeat(SfxRepeatTarget& rTarget) const
492 return rTarget.ISA(ScTabViewTarget);
495 ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell,
496 const ScRange& rRange, const ScRange& rSourceArea,
497 ScDocument* pNewUndoDoc, const ScMarkData& rMark,
498 FillDir eNewFillDir, FillCmd eNewFillCmd, FillDateCmd eNewFillDateCmd,
499 double fNewStartValue, double fNewStepValue, double fNewMaxValue )
500 : ScBlockUndo( pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT ),
501 aSource ( rSourceArea ),
502 aMarkData ( rMark ),
503 pUndoDoc ( pNewUndoDoc ),
504 eFillDir ( eNewFillDir ),
505 eFillCmd ( eNewFillCmd ),
506 eFillDateCmd ( eNewFillDateCmd ),
507 fStartValue ( fNewStartValue ),
508 fStepValue ( fNewStepValue ),
509 fMaxValue ( fNewMaxValue )
511 SetChangeTrack();
514 ScUndoAutoFill::~ScUndoAutoFill()
516 delete pUndoDoc;
519 OUString ScUndoAutoFill::GetComment() const
521 return ScGlobal::GetRscString( STR_UNDO_AUTOFILL ); //"Fill"
524 void ScUndoAutoFill::SetChangeTrack()
526 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
527 if ( pChangeTrack )
528 pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
529 nStartChangeAction, nEndChangeAction );
530 else
531 nStartChangeAction = nEndChangeAction = 0;
534 void ScUndoAutoFill::Undo()
536 BeginUndo();
538 ScDocument& rDoc = pDocShell->GetDocument();
540 SCTAB nTabCount = rDoc.GetTableCount();
541 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
542 for (; itr != itrEnd && *itr < nTabCount; ++itr)
544 ScRange aWorkRange = aBlockRange;
545 aWorkRange.aStart.SetTab(*itr);
546 aWorkRange.aEnd.SetTab(*itr);
548 sal_uInt16 nExtFlags = 0;
549 pDocShell->UpdatePaintExt( nExtFlags, aWorkRange );
550 rDoc.DeleteAreaTab( aWorkRange, IDF_AUTOFILL );
551 pUndoDoc->CopyToDocument( aWorkRange, IDF_AUTOFILL, false, &rDoc );
553 rDoc.ExtendMerge( aWorkRange, true );
554 pDocShell->PostPaint( aWorkRange, PAINT_GRID, nExtFlags );
556 pDocShell->PostDataChanged();
557 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
558 if (pViewShell)
559 pViewShell->CellContentChanged();
561 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
562 if ( pChangeTrack )
563 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
565 EndUndo();
568 void ScUndoAutoFill::Redo()
570 BeginRedo();
572 //! Select sheet
574 SCCOLROW nCount = 0;
575 switch (eFillDir)
577 case FILL_TO_BOTTOM:
578 nCount = aBlockRange.aEnd.Row() - aSource.aEnd.Row();
579 break;
580 case FILL_TO_RIGHT:
581 nCount = aBlockRange.aEnd.Col() - aSource.aEnd.Col();
582 break;
583 case FILL_TO_TOP:
584 nCount = aSource.aStart.Row() - aBlockRange.aStart.Row();
585 break;
586 case FILL_TO_LEFT:
587 nCount = aSource.aStart.Col() - aBlockRange.aStart.Col();
588 break;
591 ScDocument& rDoc = pDocShell->GetDocument();
592 if ( fStartValue != MAXDOUBLE )
594 SCCOL nValX = (eFillDir == FILL_TO_LEFT) ? aSource.aEnd.Col() : aSource.aStart.Col();
595 SCROW nValY = (eFillDir == FILL_TO_TOP ) ? aSource.aEnd.Row() : aSource.aStart.Row();
596 SCTAB nTab = aSource.aStart.Tab();
597 rDoc.SetValue( nValX, nValY, nTab, fStartValue );
599 sal_uLong nProgCount;
600 if (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_TOP)
601 nProgCount = aSource.aEnd.Col() - aSource.aStart.Col() + 1;
602 else
603 nProgCount = aSource.aEnd.Row() - aSource.aStart.Row() + 1;
604 nProgCount *= nCount;
605 ScProgress aProgress( rDoc.GetDocumentShell(),
606 ScGlobal::GetRscString(STR_FILL_SERIES_PROGRESS), nProgCount );
608 rDoc.Fill( aSource.aStart.Col(), aSource.aStart.Row(),
609 aSource.aEnd.Col(), aSource.aEnd.Row(), &aProgress,
610 aMarkData, nCount,
611 eFillDir, eFillCmd, eFillDateCmd,
612 fStepValue, fMaxValue );
614 SetChangeTrack();
616 pDocShell->PostPaint( aBlockRange, PAINT_GRID );
617 pDocShell->PostDataChanged();
618 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
619 if (pViewShell)
620 pViewShell->CellContentChanged();
622 EndRedo();
625 void ScUndoAutoFill::Repeat(SfxRepeatTarget& rTarget)
627 if (rTarget.ISA(ScTabViewTarget))
629 ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
630 if (eFillCmd==FILL_SIMPLE)
631 rViewShell.FillSimple( eFillDir, true );
632 else
633 rViewShell.FillSeries( eFillDir, eFillCmd, eFillDateCmd,
634 fStartValue, fStepValue, fMaxValue, true );
638 bool ScUndoAutoFill::CanRepeat(SfxRepeatTarget& rTarget) const
640 return rTarget.ISA(ScTabViewTarget);
643 ScUndoMerge::ScUndoMerge( ScDocShell* pNewDocShell, const ScCellMergeOption& rOption,
644 bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo )
645 : ScSimpleUndo( pNewDocShell ),
646 maOption(rOption),
647 mbMergeContents( bMergeContents ),
648 mpUndoDoc( pUndoDoc ),
649 mpDrawUndo( pDrawUndo )
653 ScUndoMerge::~ScUndoMerge()
655 delete mpUndoDoc;
656 DeleteSdrUndoAction( mpDrawUndo );
659 OUString ScUndoMerge::GetComment() const
661 return ScGlobal::GetRscString( STR_UNDO_MERGE );
664 void ScUndoMerge::DoChange( bool bUndo ) const
666 using ::std::set;
668 if (maOption.maTabs.empty())
669 // Nothing to do.
670 return;
672 ScDocument& rDoc = pDocShell->GetDocument();
673 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
675 ScRange aCurRange = maOption.getSingleRange(ScDocShell::GetCurTab());
676 ScUndoUtil::MarkSimpleBlock(pDocShell, aCurRange);
678 for (set<SCTAB>::const_iterator itr = maOption.maTabs.begin(), itrEnd = maOption.maTabs.end();
679 itr != itrEnd; ++itr)
681 SCTAB nTab = *itr;
682 ScRange aRange = maOption.getSingleRange(nTab);
684 if (bUndo)
685 // remove merge (contents are copied back below from undo document)
686 rDoc.RemoveMerge( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aStart.Tab() );
687 else
689 // repeat merge, but do not remove note captions (will be done by drawing redo below)
690 rDoc.DoMerge( aRange.aStart.Tab(),
691 aRange.aStart.Col(), aRange.aStart.Row(),
692 aRange.aEnd.Col(), aRange.aEnd.Row(), false );
694 if (maOption.mbCenter)
696 rDoc.ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
697 aRange.aStart.Tab(),
698 SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY ) );
699 rDoc.ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
700 aRange.aStart.Tab(),
701 SvxVerJustifyItem( SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY ) );
705 // undo -> copy back deleted contents
706 if (bUndo && mpUndoDoc)
708 rDoc.DeleteAreaTab( aRange, IDF_CONTENTS|IDF_NOCAPTIONS );
709 mpUndoDoc->CopyToDocument( aRange, IDF_ALL|IDF_NOCAPTIONS, false, &rDoc );
712 // redo -> merge contents again
713 else if (!bUndo && mbMergeContents)
715 rDoc.DoMergeContents( aRange.aStart.Tab(),
716 aRange.aStart.Col(), aRange.aStart.Row(),
717 aRange.aEnd.Col(), aRange.aEnd.Row() );
720 if (bUndo)
721 DoSdrUndoAction( mpDrawUndo, &rDoc );
722 else
723 RedoSdrUndoAction( mpDrawUndo );
725 bool bDidPaint = false;
726 if ( pViewShell )
728 pViewShell->SetTabNo(nTab);
729 bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow);
732 if (!bDidPaint)
733 ScUndoUtil::PaintMore(pDocShell, aRange);
736 ShowTable(aCurRange);
739 void ScUndoMerge::Undo()
741 BeginUndo();
742 DoChange( true );
743 EndUndo();
746 void ScUndoMerge::Redo()
748 BeginRedo();
749 DoChange( false );
750 EndRedo();
753 void ScUndoMerge::Repeat(SfxRepeatTarget& rTarget)
755 if (rTarget.ISA(ScTabViewTarget))
757 ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
758 bool bCont = false;
759 rViewShell.MergeCells( false, bCont, true );
763 bool ScUndoMerge::CanRepeat(SfxRepeatTarget& rTarget) const
765 return rTarget.ISA(ScTabViewTarget);
768 ScUndoAutoFormat::ScUndoAutoFormat( ScDocShell* pNewDocShell,
769 const ScRange& rRange, ScDocument* pNewUndoDoc,
770 const ScMarkData& rMark, bool bNewSize, sal_uInt16 nNewFormatNo )
771 : ScBlockUndo( pNewDocShell, rRange, bNewSize ? SC_UNDO_MANUALHEIGHT : SC_UNDO_AUTOHEIGHT ),
772 pUndoDoc ( pNewUndoDoc ),
773 aMarkData ( rMark ),
774 bSize ( bNewSize ),
775 nFormatNo ( nNewFormatNo )
779 ScUndoAutoFormat::~ScUndoAutoFormat()
781 delete pUndoDoc;
784 OUString ScUndoAutoFormat::GetComment() const
786 return ScGlobal::GetRscString( STR_UNDO_AUTOFORMAT ); //"Auto-Format"
789 void ScUndoAutoFormat::Undo()
791 BeginUndo();
793 ScDocument& rDoc = pDocShell->GetDocument();
795 SCTAB nTabCount = rDoc.GetTableCount();
796 rDoc.DeleteArea( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(),
797 aBlockRange.aEnd.Col(), aBlockRange.aEnd.Row(),
798 aMarkData, IDF_ATTRIB );
799 ScRange aCopyRange = aBlockRange;
800 aCopyRange.aStart.SetTab(0);
801 aCopyRange.aEnd.SetTab(nTabCount-1);
802 pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, false, &rDoc, &aMarkData );
804 // cell heights and widths (IDF_NONE)
805 if (bSize)
807 SCCOL nStartX = aBlockRange.aStart.Col();
808 SCROW nStartY = aBlockRange.aStart.Row();
809 SCTAB nStartZ = aBlockRange.aStart.Tab();
810 SCCOL nEndX = aBlockRange.aEnd.Col();
811 SCROW nEndY = aBlockRange.aEnd.Row();
812 SCTAB nEndZ = aBlockRange.aEnd.Tab();
814 pUndoDoc->CopyToDocument( nStartX, 0, 0, nEndX, MAXROW, nTabCount-1,
815 IDF_NONE, false, &rDoc, &aMarkData );
816 pUndoDoc->CopyToDocument( 0, nStartY, 0, MAXCOL, nEndY, nTabCount-1,
817 IDF_NONE, false, &rDoc, &aMarkData );
818 pDocShell->PostPaint( 0, 0, nStartZ, MAXCOL, MAXROW, nEndZ,
819 PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES );
821 else
822 pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
824 EndUndo();
827 void ScUndoAutoFormat::Redo()
829 BeginRedo();
831 ScDocument& rDoc = pDocShell->GetDocument();
833 SCCOL nStartX = aBlockRange.aStart.Col();
834 SCROW nStartY = aBlockRange.aStart.Row();
835 SCTAB nStartZ = aBlockRange.aStart.Tab();
836 SCCOL nEndX = aBlockRange.aEnd.Col();
837 SCROW nEndY = aBlockRange.aEnd.Row();
838 SCTAB nEndZ = aBlockRange.aEnd.Tab();
840 rDoc.AutoFormat( nStartX, nStartY, nEndX, nEndY, nFormatNo, aMarkData );
842 if (bSize)
844 ScopedVclPtrInstance< VirtualDevice > pVirtDev;
845 Fraction aZoomX(1,1);
846 Fraction aZoomY = aZoomX;
847 double nPPTX,nPPTY;
848 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
849 if (pViewShell)
851 ScViewData& rData = pViewShell->GetViewData();
852 nPPTX = rData.GetPPTX();
853 nPPTY = rData.GetPPTY();
854 aZoomX = rData.GetZoomX();
855 aZoomY = rData.GetZoomY();
857 else
859 // Keep zoom at 100
860 nPPTX = ScGlobal::nScreenPPTX;
861 nPPTY = ScGlobal::nScreenPPTY;
864 bool bFormula = false; // remember
866 sc::RowHeightContext aCxt(nPPTX, nPPTY, aZoomX, aZoomY, pVirtDev);
867 for (SCTAB nTab=nStartZ; nTab<=nEndZ; nTab++)
869 ScMarkData aDestMark;
870 aDestMark.SelectOneTable( nTab );
871 aDestMark.SetMarkArea( ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) );
872 aDestMark.MarkToMulti();
874 // as SC_SIZE_VISOPT
875 for (SCROW nRow=nStartY; nRow<=nEndY; nRow++)
877 sal_uInt8 nOld = rDoc.GetRowFlags(nRow,nTab);
878 bool bHidden = rDoc.RowHidden(nRow, nTab);
879 if ( !bHidden && ( nOld & CR_MANUALSIZE ) )
880 rDoc.SetRowFlags( nRow, nTab, nOld & ~CR_MANUALSIZE );
883 rDoc.SetOptimalHeight(aCxt, nStartY, nEndY, nTab);
885 for (SCCOL nCol=nStartX; nCol<=nEndX; nCol++)
886 if (!rDoc.ColHidden(nCol, nTab))
888 sal_uInt16 nThisSize = STD_EXTRA_WIDTH + rDoc.GetOptimalColWidth( nCol, nTab,
889 pVirtDev, nPPTX, nPPTY, aZoomX, aZoomY, bFormula,
890 &aDestMark );
891 rDoc.SetColWidth( nCol, nTab, nThisSize );
892 rDoc.ShowCol( nCol, nTab, true );
896 pDocShell->PostPaint( 0, 0, nStartZ,
897 MAXCOL, MAXROW, nEndZ,
898 PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES);
900 else
901 pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
903 EndRedo();
906 void ScUndoAutoFormat::Repeat(SfxRepeatTarget& rTarget)
908 if (rTarget.ISA(ScTabViewTarget))
909 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->AutoFormat( nFormatNo, true );
912 bool ScUndoAutoFormat::CanRepeat(SfxRepeatTarget& rTarget) const
914 return rTarget.ISA(ScTabViewTarget);
917 ScUndoReplace::ScUndoReplace( ScDocShell* pNewDocShell, const ScMarkData& rMark,
918 SCCOL nCurX, SCROW nCurY, SCTAB nCurZ,
919 const OUString& rNewUndoStr, ScDocument* pNewUndoDoc,
920 const SvxSearchItem* pItem )
921 : ScSimpleUndo( pNewDocShell ),
922 aCursorPos ( nCurX, nCurY, nCurZ ),
923 aMarkData ( rMark ),
924 aUndoStr ( rNewUndoStr ),
925 pUndoDoc ( pNewUndoDoc )
927 pSearchItem = new SvxSearchItem( *pItem );
928 SetChangeTrack();
931 ScUndoReplace::~ScUndoReplace()
933 delete pUndoDoc;
934 delete pSearchItem;
937 void ScUndoReplace::SetChangeTrack()
939 ScDocument& rDoc = pDocShell->GetDocument();
940 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
941 if ( pChangeTrack )
943 if ( pUndoDoc )
944 { //! UndoDoc includes only the changed cells,
945 // that is why an Iterator can be used
946 pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
947 nStartChangeAction, nEndChangeAction );
949 else
951 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
952 ScChangeActionContent* pContent = new ScChangeActionContent(
953 ScRange( aCursorPos) );
954 ScCellValue aCell;
955 aCell.assign(rDoc, aCursorPos);
956 pContent->SetOldValue( aUndoStr, &rDoc );
957 pContent->SetNewValue(aCell, &rDoc);
958 pChangeTrack->Append( pContent );
959 nEndChangeAction = pChangeTrack->GetActionMax();
962 else
963 nStartChangeAction = nEndChangeAction = 0;
966 OUString ScUndoReplace::GetComment() const
968 return ScGlobal::GetRscString( STR_UNDO_REPLACE ); // "Replace"
971 void ScUndoReplace::Undo()
973 BeginUndo();
975 ScDocument& rDoc = pDocShell->GetDocument();
976 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
978 ShowTable( aCursorPos.Tab() );
980 if (pUndoDoc) // only for ReplaceAll !!
982 OSL_ENSURE(pSearchItem->GetCommand() == SvxSearchCmd::REPLACE_ALL,
983 "ScUndoReplace:: Wrong Mode");
985 SetViewMarkData( aMarkData );
987 //! selected sheet
988 //! select range ?
990 // Undo document has no row/column information, thus copy with
991 // bColRowFlags = FALSE to not destroy Outline groups
993 InsertDeleteFlags nUndoFlags = (pSearchItem->GetPattern()) ? IDF_ATTRIB : IDF_CONTENTS;
994 pUndoDoc->CopyToDocument( 0, 0, 0,
995 MAXCOL, MAXROW, MAXTAB,
996 nUndoFlags, false, &rDoc, NULL, false ); // without row flags
997 pDocShell->PostPaintGridAll();
999 else if (pSearchItem->GetPattern() &&
1000 pSearchItem->GetCommand() == SvxSearchCmd::REPLACE)
1002 OUString aTempStr = pSearchItem->GetSearchString(); // toggle
1003 pSearchItem->SetSearchString(pSearchItem->GetReplaceString());
1004 pSearchItem->SetReplaceString(aTempStr);
1005 rDoc.ReplaceStyle( *pSearchItem,
1006 aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
1007 aMarkData, true);
1008 pSearchItem->SetReplaceString(pSearchItem->GetSearchString());
1009 pSearchItem->SetSearchString(aTempStr);
1010 if (pViewShell)
1011 pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1012 SC_FOLLOW_JUMP, false, false );
1013 pDocShell->PostPaintGridAll();
1015 else if (pSearchItem->GetCellType() == SvxSearchCellType::NOTE)
1017 ScPostIt* pNote = rDoc.GetNote(aCursorPos);
1018 OSL_ENSURE( pNote, "ScUndoReplace::Undo - cell does not contain a note" );
1019 if (pNote)
1020 pNote->SetText( aCursorPos, aUndoStr );
1021 if (pViewShell)
1022 pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1023 SC_FOLLOW_JUMP, false, false );
1025 else
1027 // aUndoStr may contain line breaks
1028 if ( aUndoStr.indexOf('\n') != -1 )
1030 ScFieldEditEngine& rEngine = rDoc.GetEditEngine();
1031 rEngine.SetText(aUndoStr);
1032 rDoc.SetEditText(aCursorPos, rEngine.CreateTextObject());
1034 else
1035 rDoc.SetString( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aUndoStr );
1036 if (pViewShell)
1037 pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1038 SC_FOLLOW_JUMP, false, false );
1039 pDocShell->PostPaintGridAll();
1042 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
1043 if ( pChangeTrack )
1044 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1046 EndUndo();
1049 void ScUndoReplace::Redo()
1051 BeginRedo();
1053 ScDocument& rDoc = pDocShell->GetDocument();
1054 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1056 if (pViewShell)
1057 pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1058 SC_FOLLOW_JUMP, false, false );
1059 if (pUndoDoc)
1061 if (pViewShell)
1063 SetViewMarkData( aMarkData );
1065 pViewShell->SearchAndReplace( pSearchItem, false, true );
1068 else if (pSearchItem->GetPattern() &&
1069 pSearchItem->GetCommand() == SvxSearchCmd::REPLACE)
1071 rDoc.ReplaceStyle( *pSearchItem,
1072 aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
1073 aMarkData, true);
1074 pDocShell->PostPaintGridAll();
1076 else
1077 if (pViewShell)
1078 pViewShell->SearchAndReplace( pSearchItem, false, true );
1080 SetChangeTrack();
1082 EndRedo();
1085 void ScUndoReplace::Repeat(SfxRepeatTarget& rTarget)
1087 if (rTarget.ISA(ScTabViewTarget))
1088 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->SearchAndReplace( pSearchItem, true, false );
1091 bool ScUndoReplace::CanRepeat(SfxRepeatTarget& rTarget) const
1093 return rTarget.ISA(ScTabViewTarget);
1096 // multi-operation (only simple blocks)
1097 ScUndoTabOp::ScUndoTabOp( ScDocShell* pNewDocShell,
1098 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
1099 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ, ScDocument* pNewUndoDoc,
1100 const ScRefAddress& rFormulaCell,
1101 const ScRefAddress& rFormulaEnd,
1102 const ScRefAddress& rRowCell,
1103 const ScRefAddress& rColCell,
1104 ScTabOpParam::Mode eMode )
1105 : ScSimpleUndo( pNewDocShell ),
1106 aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
1107 pUndoDoc ( pNewUndoDoc ),
1108 theFormulaCell ( rFormulaCell ),
1109 theFormulaEnd ( rFormulaEnd ),
1110 theRowCell ( rRowCell ),
1111 theColCell ( rColCell ),
1112 meMode(eMode)
1116 ScUndoTabOp::~ScUndoTabOp()
1118 delete pUndoDoc;
1121 OUString ScUndoTabOp::GetComment() const
1123 return ScGlobal::GetRscString( STR_UNDO_TABOP ); // "Multiple operation"
1126 void ScUndoTabOp::Undo()
1128 BeginUndo();
1130 ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
1132 sal_uInt16 nExtFlags = 0;
1133 pDocShell->UpdatePaintExt( nExtFlags, aRange );
1135 ScDocument& rDoc = pDocShell->GetDocument();
1136 rDoc.DeleteAreaTab( aRange,IDF_ALL & ~IDF_NOTE );
1137 pUndoDoc->CopyToDocument( aRange, IDF_ALL & ~IDF_NOTE, false, &rDoc );
1138 pDocShell->PostPaint( aRange, PAINT_GRID, nExtFlags );
1139 pDocShell->PostDataChanged();
1140 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1141 if (pViewShell)
1142 pViewShell->CellContentChanged();
1144 EndUndo();
1147 void ScUndoTabOp::Redo()
1149 BeginRedo();
1151 ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
1153 ScTabOpParam aParam(theFormulaCell, theFormulaEnd, theRowCell, theColCell, meMode);
1155 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1156 if (pViewShell)
1157 pViewShell->TabOp( aParam, false);
1159 EndRedo();
1162 void ScUndoTabOp::Repeat(SfxRepeatTarget& /* rTarget */)
1166 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& rDoc = pDocShell->GetDocument();
1196 ScChangeTrack* pChangeTrack = rDoc.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& rDoc = pDocShell->GetDocument();
1230 ShowTable( rCursorPos.Tab() );
1232 SetViewMarkData( aMarkData );
1234 SCTAB nTabCount = rDoc.GetTableCount();
1235 // Undo/Redo-doc has only selected tables
1237 bool bMulti = aMarkData.IsMultiMarked();
1238 pRefDoc->CopyToDocument( 0, 0, 0,
1239 MAXCOL, MAXROW, nTabCount-1,
1240 IDF_CONTENTS, bMulti, &rDoc, &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 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DoSheetConversion( maConvParam, true );
1273 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, bool bNewMulti, InsertDeleteFlags 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& rDoc = pDocShell->GetDocument();
1317 ShowTable(aRange);
1319 SetViewMarkData( aMarkData );
1321 ScRange aCopyRange = aRange;
1322 SCTAB nTabCount = rDoc.GetTableCount();
1323 aCopyRange.aStart.SetTab(0);
1324 aCopyRange.aEnd.SetTab(nTabCount-1);
1325 pRefDoc->CopyToDocument( aCopyRange, nFlags, bMulti, &rDoc, &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 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DoRefConversion();
1359 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 bool bMakeRedo = !pRedoDoc;
1388 if (bMakeRedo)
1389 pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
1391 bool bFirst = true;
1392 ScDocument& rDoc = pDocShell->GetDocument();
1393 SCTAB nCount = rDoc.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( &rDoc, nTab, nTab, true, true );
1402 else
1403 pRedoDoc->AddUndoTab( nTab, nTab, true, true );
1404 bFirst = false;
1405 rDoc.CopyToDocument(aRange, IDF_ALL, false, pRedoDoc);
1406 pRedoDoc->SetLink( nTab,
1407 rDoc.GetLinkMode(nTab),
1408 rDoc.GetLinkDoc(nTab),
1409 rDoc.GetLinkFlt(nTab),
1410 rDoc.GetLinkOpt(nTab),
1411 rDoc.GetLinkTab(nTab),
1412 rDoc.GetLinkRefreshDelay(nTab) );
1413 pRedoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) );
1416 rDoc.DeleteAreaTab( aRange,IDF_ALL );
1417 pUndoDoc->CopyToDocument( aRange, IDF_ALL, false, &rDoc );
1418 rDoc.SetLink( nTab, pUndoDoc->GetLinkMode(nTab), pUndoDoc->GetLinkDoc(nTab),
1419 pUndoDoc->GetLinkFlt(nTab), pUndoDoc->GetLinkOpt(nTab),
1420 pUndoDoc->GetLinkTab(nTab),
1421 pUndoDoc->GetLinkRefreshDelay(nTab) );
1422 rDoc.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& rDoc = pDocShell->GetDocument();
1438 SCTAB nCount = rDoc.GetTableCount();
1439 for (SCTAB nTab=0; nTab<nCount; nTab++)
1440 if (pRedoDoc->HasTable(nTab))
1442 ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
1444 rDoc.DeleteAreaTab( aRange, IDF_ALL );
1445 pRedoDoc->CopyToDocument( aRange, IDF_ALL, false, &rDoc );
1446 rDoc.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 rDoc.SetTabBgColor( nTab, pRedoDoc->GetTabBgColor(nTab) );
1456 pDocShell->PostPaintGridAll();
1457 pDocShell->PostPaintExtras();
1459 EndUndo();
1462 void ScUndoRefreshLink::Repeat(SfxRepeatTarget& /* rTarget */)
1464 // makes no sense
1467 bool ScUndoRefreshLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1469 return false;
1472 static ScAreaLink* lcl_FindAreaLink( sfx2::LinkManager* pLinkManager, const OUString& rDoc,
1473 const OUString& rFlt, const OUString& rOpt,
1474 const OUString& 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 ( static_cast<ScAreaLink*>(pBase)->IsEqual( rDoc, rFlt, rOpt, rSrc, rDest ) )
1483 return static_cast<ScAreaLink*>(pBase);
1486 OSL_FAIL("ScAreaLink not found");
1487 return NULL;
1490 ScUndoInsertAreaLink::ScUndoInsertAreaLink( ScDocShell* pShell,
1491 const OUString& rDoc,
1492 const OUString& rFlt, const OUString& rOpt,
1493 const OUString& 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& rDoc = pDocShell->GetDocument();
1517 sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
1519 ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
1520 aAreaName, aRange );
1521 if (pLink)
1522 pLinkManager->Remove( pLink );
1524 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1527 void ScUndoInsertAreaLink::Redo()
1529 ScDocument& rDoc = pDocShell->GetDocument();
1530 sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
1532 ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
1533 aAreaName, aRange.aStart, nRefreshDelay );
1534 pLink->SetInCreate( true );
1535 pLink->SetDestArea( aRange );
1536 pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
1537 pLink->Update();
1538 pLink->SetInCreate( false );
1540 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1543 void ScUndoInsertAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1545 // makes no sense
1548 bool ScUndoInsertAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1550 return false;
1553 ScUndoRemoveAreaLink::ScUndoRemoveAreaLink( ScDocShell* pShell,
1554 const OUString& rDoc, const OUString& rFlt, const OUString& rOpt,
1555 const OUString& 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& rDoc = pDocShell->GetDocument();
1579 sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
1581 ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
1582 aAreaName, aRange.aStart, nRefreshDelay );
1583 pLink->SetInCreate( true );
1584 pLink->SetDestArea( aRange );
1585 pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
1586 pLink->Update();
1587 pLink->SetInCreate( false );
1589 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1592 void ScUndoRemoveAreaLink::Redo()
1594 ScDocument& rDoc = pDocShell->GetDocument();
1595 sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
1597 ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
1598 aAreaName, aRange );
1599 if (pLink)
1600 pLinkManager->Remove( pLink );
1602 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1605 void ScUndoRemoveAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1607 // makes no sense
1610 bool ScUndoRemoveAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1612 return false;
1615 ScUndoUpdateAreaLink::ScUndoUpdateAreaLink( ScDocShell* pShell,
1616 const OUString& rOldD, const OUString& rOldF, const OUString& rOldO,
1617 const OUString& rOldA, const ScRange& rOldR, sal_uLong nOldRD,
1618 const OUString& rNewD, const OUString& rNewF, const OUString& rNewO,
1619 const OUString& rNewA, const ScRange& rNewR, sal_uLong nNewRD,
1620 ScDocument* pUndo, ScDocument* pRedo, 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 bool bUndo ) const
1654 ScDocument& rDoc = 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 rDoc.FitBlock( aNewRange, aOldRange );
1665 rDoc.DeleteAreaTab( aOldRange, IDF_ALL & ~IDF_NOTE );
1666 pUndoDoc->UndoToDocument( aOldRange, IDF_ALL & ~IDF_NOTE, false, &rDoc );
1668 else
1670 ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
1671 rDoc.DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
1672 pUndoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, false, &rDoc );
1675 else
1677 if ( bWithInsert )
1679 rDoc.FitBlock( aOldRange, aNewRange );
1680 rDoc.DeleteAreaTab( aNewRange, IDF_ALL & ~IDF_NOTE );
1681 pRedoDoc->CopyToDocument( aNewRange, IDF_ALL & ~IDF_NOTE, false, &rDoc );
1683 else
1685 ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
1686 rDoc.DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
1687 pRedoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, false, &rDoc );
1691 ScRange aWorkRange( aNewRange.aStart, ScAddress( nEndX, nEndY, nEndZ ) );
1692 rDoc.ExtendMerge( aWorkRange, 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& rDoc = pDocShell->GetDocument();
1713 sfx2::LinkManager* pLinkManager = rDoc.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(true);
1726 void ScUndoUpdateAreaLink::Redo()
1728 ScDocument& rDoc = pDocShell->GetDocument();
1729 sfx2::LinkManager* pLinkManager = rDoc.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 bool ScUndoUpdateAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1749 return false;
1752 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */