Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / undo / undodat.cxx
blob57d08756b79ec4de136a2142ab6a0caa88798a92
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 <sfx2/app.hxx>
22 #include "undodat.hxx"
23 #include "undoutil.hxx"
24 #include "undoolk.hxx"
25 #include "document.hxx"
26 #include "docsh.hxx"
27 #include "tabvwsh.hxx"
28 #include "olinetab.hxx"
29 #include "dbdata.hxx"
30 #include "rangenam.hxx"
31 #include "pivot.hxx"
32 #include "globstr.hrc"
33 #include "global.hxx"
34 #include "globalnames.hxx"
35 #include "target.hxx"
36 #include "chartarr.hxx"
37 #include "dbdocfun.hxx"
38 #include "olinefun.hxx"
39 #include "dpobject.hxx"
40 #include "attrib.hxx"
41 #include "hints.hxx"
42 #include "sc.hrc"
43 #include "chgtrack.hxx"
44 #include "refundo.hxx"
45 #include "markdata.hxx"
47 // -----------------------------------------------------------------------
49 TYPEINIT1(ScUndoDoOutline, ScSimpleUndo);
50 TYPEINIT1(ScUndoMakeOutline, ScSimpleUndo);
51 TYPEINIT1(ScUndoOutlineLevel, ScSimpleUndo);
52 TYPEINIT1(ScUndoOutlineBlock, ScSimpleUndo);
53 TYPEINIT1(ScUndoRemoveAllOutlines, ScSimpleUndo);
54 TYPEINIT1(ScUndoAutoOutline, ScSimpleUndo);
55 TYPEINIT1(ScUndoSubTotals, ScDBFuncUndo);
56 TYPEINIT1(ScUndoSort, ScDBFuncUndo);
57 TYPEINIT1(ScUndoQuery, ScDBFuncUndo);
58 TYPEINIT1(ScUndoAutoFilter, ScDBFuncUndo);
59 TYPEINIT1(ScUndoDBData, ScSimpleUndo);
60 TYPEINIT1(ScUndoImportData, ScSimpleUndo);
61 TYPEINIT1(ScUndoRepeatDB, ScSimpleUndo);
62 TYPEINIT1(ScUndoDataPilot, ScSimpleUndo);
63 TYPEINIT1(ScUndoConsolidate, ScSimpleUndo);
64 TYPEINIT1(ScUndoChartData, ScSimpleUndo);
65 TYPEINIT1(ScUndoDataForm, SfxUndoAction);
67 // Show or hide outline groups
69 ScUndoDoOutline::ScUndoDoOutline( ScDocShell* pNewDocShell,
70 SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
71 ScDocument* pNewUndoDoc, sal_Bool bNewColumns,
72 sal_uInt16 nNewLevel, sal_uInt16 nNewEntry, sal_Bool bNewShow ) :
73 ScSimpleUndo( pNewDocShell ),
74 nStart( nNewStart ),
75 nEnd( nNewEnd ),
76 nTab( nNewTab ),
77 pUndoDoc( pNewUndoDoc ),
78 bColumns( bNewColumns ),
79 nLevel( nNewLevel ),
80 nEntry( nNewEntry ),
81 bShow( bNewShow )
85 ScUndoDoOutline::~ScUndoDoOutline()
87 delete pUndoDoc;
90 OUString ScUndoDoOutline::GetComment() const
91 { // Show outline" "Hide outline"
92 return bShow ?
93 ScGlobal::GetRscString( STR_UNDO_DOOUTLINE ) :
94 ScGlobal::GetRscString( STR_UNDO_REDOOUTLINE );
97 void ScUndoDoOutline::Undo()
99 BeginUndo();
101 ScDocument* pDoc = pDocShell->GetDocument();
102 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
104 // sheet has to be switched over (#46952#)!
106 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
107 if ( nVisTab != nTab )
108 pViewShell->SetTabNo( nTab );
110 // perform the inverse function
112 if (bShow)
113 pViewShell->HideOutline( bColumns, nLevel, nEntry, false, false );
114 else
115 pViewShell->ShowOutline( bColumns, nLevel, nEntry, false, false );
117 // Original column/row status
118 if (bColumns)
119 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
120 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false, pDoc);
121 else
122 pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pDoc );
124 pViewShell->UpdateScrollBars();
126 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
128 EndUndo();
131 void ScUndoDoOutline::Redo()
133 BeginRedo();
135 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
137 // sheet has to be switched over (#46952#)!
139 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
140 if ( nVisTab != nTab )
141 pViewShell->SetTabNo( nTab );
143 if (bShow)
144 pViewShell->ShowOutline( bColumns, nLevel, nEntry, false );
145 else
146 pViewShell->HideOutline( bColumns, nLevel, nEntry, false );
148 EndRedo();
151 void ScUndoDoOutline::Repeat(SfxRepeatTarget& /* rTarget */)
155 bool ScUndoDoOutline::CanRepeat(SfxRepeatTarget& /* rTarget */) const
157 return false; // is not possible
160 /** Make or delete outline groups */
161 ScUndoMakeOutline::ScUndoMakeOutline( ScDocShell* pNewDocShell,
162 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
163 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
164 ScOutlineTable* pNewUndoTab, sal_Bool bNewColumns, sal_Bool bNewMake ) :
165 ScSimpleUndo( pNewDocShell ),
166 aBlockStart( nStartX, nStartY, nStartZ ),
167 aBlockEnd( nEndX, nEndY, nEndZ ),
168 pUndoTable( pNewUndoTab ),
169 bColumns( bNewColumns ),
170 bMake( bNewMake )
174 ScUndoMakeOutline::~ScUndoMakeOutline()
176 delete pUndoTable;
179 OUString ScUndoMakeOutline::GetComment() const
180 { // "Grouping" "Undo grouping"
181 return bMake ?
182 ScGlobal::GetRscString( STR_UNDO_MAKEOUTLINE ) :
183 ScGlobal::GetRscString( STR_UNDO_REMAKEOUTLINE );
186 void ScUndoMakeOutline::Undo()
188 BeginUndo();
190 ScDocument* pDoc = pDocShell->GetDocument();
191 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
192 SCTAB nTab = aBlockStart.Tab();
194 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
196 pDoc->SetOutlineTable( nTab, pUndoTable );
198 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
199 if ( nVisTab != nTab )
200 pViewShell->SetTabNo( nTab );
202 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
204 EndUndo();
207 void ScUndoMakeOutline::Redo()
209 BeginRedo();
211 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
213 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
215 if (bMake)
216 pViewShell->MakeOutline( bColumns, false );
217 else
218 pViewShell->RemoveOutline( bColumns, false );
220 pDocShell->PostPaint(0,0,aBlockStart.Tab(),MAXCOL,MAXROW,aBlockEnd.Tab(),PAINT_GRID);
222 EndRedo();
225 void ScUndoMakeOutline::Repeat(SfxRepeatTarget& rTarget)
227 if (rTarget.ISA(ScTabViewTarget))
229 ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
231 if (bMake)
232 rViewShell.MakeOutline( bColumns, sal_True );
233 else
234 rViewShell.RemoveOutline( bColumns, sal_True );
238 bool ScUndoMakeOutline::CanRepeat(SfxRepeatTarget& rTarget) const
240 return rTarget.ISA(ScTabViewTarget);
243 ScUndoOutlineLevel::ScUndoOutlineLevel( ScDocShell* pNewDocShell,
244 SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
245 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
246 sal_Bool bNewColumns, sal_uInt16 nNewLevel ) :
247 ScSimpleUndo( pNewDocShell ),
248 nStart( nNewStart ),
249 nEnd( nNewEnd ),
250 nTab( nNewTab ),
251 pUndoDoc( pNewUndoDoc ),
252 pUndoTable( pNewUndoTab ),
253 bColumns( bNewColumns ),
254 nLevel( nNewLevel )
258 ScUndoOutlineLevel::~ScUndoOutlineLevel()
260 delete pUndoDoc;
261 delete pUndoTable;
264 OUString ScUndoOutlineLevel::GetComment() const
265 { // "Select outline level"
266 return ScGlobal::GetRscString( STR_UNDO_OUTLINELEVEL );
269 void ScUndoOutlineLevel::Undo()
271 BeginUndo();
273 ScDocument* pDoc = pDocShell->GetDocument();
274 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
276 // Original Outline table
278 pDoc->SetOutlineTable( nTab, pUndoTable );
280 // Original column/row status
282 if (bColumns)
283 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
284 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false, pDoc);
285 else
286 pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pDoc );
288 pDoc->UpdatePageBreaks( nTab );
290 pViewShell->UpdateScrollBars();
292 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
293 if ( nVisTab != nTab )
294 pViewShell->SetTabNo( nTab );
296 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
298 EndUndo();
301 void ScUndoOutlineLevel::Redo()
303 BeginRedo();
305 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
307 // sheet has to be switched on or off before this (#46952#) !!!
309 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
310 if ( nVisTab != nTab )
311 pViewShell->SetTabNo( nTab );
313 pViewShell->SelectLevel( bColumns, nLevel, false );
315 EndRedo();
318 void ScUndoOutlineLevel::Repeat(SfxRepeatTarget& rTarget)
320 if (rTarget.ISA(ScTabViewTarget))
321 ((ScTabViewTarget&)rTarget).GetViewShell()->SelectLevel( bColumns, nLevel, sal_True );
324 bool ScUndoOutlineLevel::CanRepeat(SfxRepeatTarget& rTarget) const
326 return rTarget.ISA(ScTabViewTarget);
329 /** show/hide outline over block marks */
330 ScUndoOutlineBlock::ScUndoOutlineBlock( ScDocShell* pNewDocShell,
331 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
332 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
333 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab, sal_Bool bNewShow ) :
334 ScSimpleUndo( pNewDocShell ),
335 aBlockStart( nStartX, nStartY, nStartZ ),
336 aBlockEnd( nEndX, nEndY, nEndZ ),
337 pUndoDoc( pNewUndoDoc ),
338 pUndoTable( pNewUndoTab ),
339 bShow( bNewShow )
343 ScUndoOutlineBlock::~ScUndoOutlineBlock()
345 delete pUndoDoc;
346 delete pUndoTable;
349 OUString ScUndoOutlineBlock::GetComment() const
350 { // "Show outline" "Hide outline"
351 return bShow ?
352 ScGlobal::GetRscString( STR_UNDO_DOOUTLINEBLK ) :
353 ScGlobal::GetRscString( STR_UNDO_REDOOUTLINEBLK );
356 void ScUndoOutlineBlock::Undo()
358 BeginUndo();
360 ScDocument* pDoc = pDocShell->GetDocument();
361 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
362 SCTAB nTab = aBlockStart.Tab();
364 // Original Outline table
365 pDoc->SetOutlineTable( nTab, pUndoTable );
367 // Original column/row status
368 SCCOLROW nStartCol = aBlockStart.Col();
369 SCCOLROW nEndCol = aBlockEnd.Col();
370 SCCOLROW nStartRow = aBlockStart.Row();
371 SCCOLROW nEndRow = aBlockEnd.Row();
373 if (!bShow)
374 { // Size of the hidden blocks
375 size_t nLevel;
376 pUndoTable->GetColArray()->FindTouchedLevel( nStartCol, nEndCol, nLevel );
377 pUndoTable->GetColArray()->ExtendBlock( nLevel, nStartCol, nEndCol );
378 pUndoTable->GetRowArray()->FindTouchedLevel( nStartRow, nEndRow, nLevel );
379 pUndoTable->GetRowArray()->ExtendBlock( nLevel, nStartRow, nEndRow );
382 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
383 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false, pDoc );
384 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
386 pDoc->UpdatePageBreaks( nTab );
388 pViewShell->UpdateScrollBars();
390 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
391 if ( nVisTab != nTab )
392 pViewShell->SetTabNo( nTab );
394 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
396 EndUndo();
399 void ScUndoOutlineBlock::Redo()
401 BeginRedo();
403 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
405 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
406 if (bShow)
407 pViewShell->ShowMarkedOutlines( false );
408 else
409 pViewShell->HideMarkedOutlines( false );
411 EndRedo();
414 void ScUndoOutlineBlock::Repeat(SfxRepeatTarget& rTarget)
416 if (rTarget.ISA(ScTabViewTarget))
418 ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
420 if (bShow)
421 rViewShell.ShowMarkedOutlines( sal_True );
422 else
423 rViewShell.HideMarkedOutlines( sal_True );
427 bool ScUndoOutlineBlock::CanRepeat(SfxRepeatTarget& rTarget) const
429 return rTarget.ISA(ScTabViewTarget);
432 ScUndoRemoveAllOutlines::ScUndoRemoveAllOutlines( ScDocShell* pNewDocShell,
433 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
434 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
435 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
436 ScSimpleUndo( pNewDocShell ),
437 aBlockStart( nStartX, nStartY, nStartZ ),
438 aBlockEnd( nEndX, nEndY, nEndZ ),
439 pUndoDoc( pNewUndoDoc ),
440 pUndoTable( pNewUndoTab )
444 ScUndoRemoveAllOutlines::~ScUndoRemoveAllOutlines()
446 delete pUndoDoc;
447 delete pUndoTable;
450 OUString ScUndoRemoveAllOutlines::GetComment() const
451 { // "Remove outlines"
452 return ScGlobal::GetRscString( STR_UNDO_REMOVEALLOTLNS );
455 void ScUndoRemoveAllOutlines::Undo()
457 BeginUndo();
459 ScDocument* pDoc = pDocShell->GetDocument();
460 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
461 SCTAB nTab = aBlockStart.Tab();
463 // Original Outline table
464 pDoc->SetOutlineTable( nTab, pUndoTable );
466 // Original column/row status
467 SCCOL nStartCol = aBlockStart.Col();
468 SCCOL nEndCol = aBlockEnd.Col();
469 SCROW nStartRow = aBlockStart.Row();
470 SCROW nEndRow = aBlockEnd.Row();
472 pUndoDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, false, pDoc );
473 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
475 pDoc->UpdatePageBreaks( nTab );
477 pViewShell->UpdateScrollBars();
479 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
480 if ( nVisTab != nTab )
481 pViewShell->SetTabNo( nTab );
483 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
485 EndUndo();
488 void ScUndoRemoveAllOutlines::Redo()
490 BeginRedo();
492 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
494 // sheet has to be switched over (#46952#)!
496 SCTAB nTab = aBlockStart.Tab();
497 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
498 if ( nVisTab != nTab )
499 pViewShell->SetTabNo( nTab );
501 pViewShell->RemoveAllOutlines( false );
503 EndRedo();
506 void ScUndoRemoveAllOutlines::Repeat(SfxRepeatTarget& rTarget)
508 if (rTarget.ISA(ScTabViewTarget))
509 ((ScTabViewTarget&)rTarget).GetViewShell()->RemoveAllOutlines( sal_True );
512 bool ScUndoRemoveAllOutlines::CanRepeat(SfxRepeatTarget& rTarget) const
514 return rTarget.ISA(ScTabViewTarget);
517 ScUndoAutoOutline::ScUndoAutoOutline( ScDocShell* pNewDocShell,
518 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
519 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
520 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
521 ScSimpleUndo( pNewDocShell ),
522 aBlockStart( nStartX, nStartY, nStartZ ),
523 aBlockEnd( nEndX, nEndY, nEndZ ),
524 pUndoDoc( pNewUndoDoc ),
525 pUndoTable( pNewUndoTab )
529 ScUndoAutoOutline::~ScUndoAutoOutline()
531 delete pUndoDoc;
532 delete pUndoTable;
535 OUString ScUndoAutoOutline::GetComment() const
537 return ScGlobal::GetRscString( STR_UNDO_AUTOOUTLINE );
540 void ScUndoAutoOutline::Undo()
542 BeginUndo();
544 ScDocument* pDoc = pDocShell->GetDocument();
545 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
546 SCTAB nTab = aBlockStart.Tab();
548 // Original outline table
549 pDoc->SetOutlineTable( nTab, pUndoTable );
551 // Original column/row status
552 if (pUndoDoc && pUndoTable)
554 SCCOLROW nStartCol;
555 SCCOLROW nStartRow;
556 SCCOLROW nEndCol;
557 SCCOLROW nEndRow;
558 pUndoTable->GetColArray()->GetRange( nStartCol, nEndCol );
559 pUndoTable->GetRowArray()->GetRange( nStartRow, nEndRow );
561 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
562 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false,
563 pDoc);
564 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
566 pViewShell->UpdateScrollBars();
569 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
570 if ( nVisTab != nTab )
571 pViewShell->SetTabNo( nTab );
573 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
575 EndUndo();
578 void ScUndoAutoOutline::Redo()
580 BeginRedo();
582 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
584 SCTAB nTab = aBlockStart.Tab();
585 if (pViewShell)
587 // sheet has to be switched on or off before this (#46952#) !!!
589 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
590 if ( nVisTab != nTab )
591 pViewShell->SetTabNo( nTab );
594 ScRange aRange( aBlockStart.Col(), aBlockStart.Row(), nTab,
595 aBlockEnd.Col(), aBlockEnd.Row(), nTab );
596 ScOutlineDocFunc aFunc( *pDocShell );
597 aFunc.AutoOutline( aRange, false, false );
599 // Select in View
600 // If it was called with a multi selection,
601 // then this is now the enclosing range...
603 if (pViewShell)
604 pViewShell->MarkRange( aRange );
606 EndRedo();
609 void ScUndoAutoOutline::Repeat(SfxRepeatTarget& rTarget)
611 if (rTarget.ISA(ScTabViewTarget))
612 ((ScTabViewTarget&)rTarget).GetViewShell()->AutoOutline( sal_True );
615 bool ScUndoAutoOutline::CanRepeat(SfxRepeatTarget& rTarget) const
617 return rTarget.ISA(ScTabViewTarget);
620 ScUndoSubTotals::ScUndoSubTotals( ScDocShell* pNewDocShell, SCTAB nNewTab,
621 const ScSubTotalParam& rNewParam, SCROW nNewEndY,
622 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
623 ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB ) :
624 ScDBFuncUndo( pNewDocShell, ScRange( rNewParam.nCol1, rNewParam.nRow1, nNewTab,
625 rNewParam.nCol2, rNewParam.nRow2, nNewTab ) ),
626 nTab( nNewTab ),
627 aParam( rNewParam ),
628 nNewEndRow( nNewEndY ),
629 pUndoDoc( pNewUndoDoc ),
630 pUndoTable( pNewUndoTab ),
631 pUndoRange( pNewUndoRange ),
632 pUndoDB( pNewUndoDB )
636 ScUndoSubTotals::~ScUndoSubTotals()
638 delete pUndoDoc;
639 delete pUndoTable;
640 delete pUndoRange;
641 delete pUndoDB;
644 OUString ScUndoSubTotals::GetComment() const
645 { // "Subtotals"
646 return ScGlobal::GetRscString( STR_UNDO_SUBTOTALS );
649 void ScUndoSubTotals::Undo()
651 BeginUndo();
653 ScDocument* pDoc = pDocShell->GetDocument();
654 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
656 if (nNewEndRow > aParam.nRow2)
658 pDoc->DeleteRow( 0,nTab, MAXCOL,nTab, aParam.nRow2+1, static_cast<SCSIZE>(nNewEndRow-aParam.nRow2) );
660 else if (nNewEndRow < aParam.nRow2)
662 pDoc->InsertRow( 0,nTab, MAXCOL,nTab, nNewEndRow+1, static_cast<SCSIZE>(aParam.nRow2-nNewEndRow) );
666 // Original Outline table
667 pDoc->SetOutlineTable( nTab, pUndoTable );
669 // Original column/row status
670 if (pUndoDoc && pUndoTable)
672 SCCOLROW nStartCol;
673 SCCOLROW nStartRow;
674 SCCOLROW nEndCol;
675 SCCOLROW nEndRow;
676 pUndoTable->GetColArray()->GetRange( nStartCol, nEndCol );
677 pUndoTable->GetRowArray()->GetRange( nStartRow, nEndRow );
679 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
680 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false,
681 pDoc);
682 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
684 pViewShell->UpdateScrollBars();
687 // Original data and references
689 ScUndoUtil::MarkSimpleBlock( pDocShell, 0, aParam.nRow1+1, nTab,
690 MAXCOL, aParam.nRow2, nTab );
692 pDoc->DeleteAreaTab( 0,aParam.nRow1+1, MAXCOL,aParam.nRow2, nTab, IDF_ALL );
694 pUndoDoc->CopyToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
695 IDF_NONE, false, pDoc ); // Flags
696 pUndoDoc->UndoToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
697 IDF_ALL, false, pDoc );
699 ScUndoUtil::MarkSimpleBlock( pDocShell, aParam.nCol1,aParam.nRow1,nTab,
700 aParam.nCol2,aParam.nRow2,nTab );
702 if (pUndoRange)
703 pDoc->SetRangeName( new ScRangeName( *pUndoRange ) );
704 if (pUndoDB)
705 pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), sal_True );
707 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
708 if ( nVisTab != nTab )
709 pViewShell->SetTabNo( nTab );
711 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
712 pDocShell->PostDataChanged();
714 EndUndo();
717 void ScUndoSubTotals::Redo()
719 BeginRedo();
721 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
723 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
724 if ( nVisTab != nTab )
725 pViewShell->SetTabNo( nTab );
727 ScUndoUtil::MarkSimpleBlock( pDocShell, aParam.nCol1,aParam.nRow1,nTab,
728 aParam.nCol2,aParam.nRow2,nTab );
729 pViewShell->DoSubTotals( aParam, false );
731 EndRedo();
734 void ScUndoSubTotals::Repeat(SfxRepeatTarget& /* rTarget */)
738 bool ScUndoSubTotals::CanRepeat(SfxRepeatTarget& /* rTarget */) const
740 return false; // is not possible due to column numbers
743 ScUndoSort::ScUndoSort( ScDocShell* pNewDocShell,
744 SCTAB nNewTab, const ScSortParam& rParam,
745 ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB,
746 const ScRange* pDest ) :
747 ScDBFuncUndo( pNewDocShell, ScRange( rParam.nCol1, rParam.nRow1, nNewTab,
748 rParam.nCol2, rParam.nRow2, nNewTab ) ),
749 nTab( nNewTab ),
750 aSortParam( rParam ),
751 pUndoDoc( pNewUndoDoc ),
752 pUndoDB( pNewUndoDB ),
753 bDestArea( false )
755 if ( pDest )
757 bDestArea = sal_True;
758 aDestRange = *pDest;
762 ScUndoSort::~ScUndoSort()
764 delete pUndoDoc;
765 delete pUndoDB;
768 OUString ScUndoSort::GetComment() const
770 return ScGlobal::GetRscString( STR_UNDO_SORT );
773 void ScUndoSort::Undo()
775 BeginUndo();
777 ScDocument* pDoc = pDocShell->GetDocument();
778 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
780 SCCOL nStartCol = aSortParam.nCol1;
781 SCROW nStartRow = aSortParam.nRow1;
782 SCCOL nEndCol = aSortParam.nCol2;
783 SCROW nEndRow = aSortParam.nRow2;
784 SCTAB nSortTab = nTab;
785 if ( !aSortParam.bInplace )
787 nStartCol = aSortParam.nDestCol;
788 nStartRow = aSortParam.nDestRow;
789 nEndCol = nStartCol + ( aSortParam.nCol2 - aSortParam.nCol1 );
790 nEndRow = nStartRow + ( aSortParam.nRow2 - aSortParam.nRow1 );
791 nSortTab = aSortParam.nDestTab;
794 ScUndoUtil::MarkSimpleBlock( pDocShell, nStartCol, nStartRow, nSortTab,
795 nEndCol, nEndRow, nSortTab );
797 // do not delete/copy note captions, they are handled in drawing undo (ScDBFuncUndo::mpDrawUndo)
798 pDoc->DeleteAreaTab( nStartCol,nStartRow, nEndCol,nEndRow, nSortTab, IDF_ALL|IDF_NOCAPTIONS );
799 pUndoDoc->CopyToDocument( nStartCol, nStartRow, nSortTab, nEndCol, nEndRow, nSortTab,
800 IDF_ALL|IDF_NOCAPTIONS, false, pDoc );
802 if (bDestArea)
804 // do not delete/copy note captions, they are handled in drawing undo (ScDBFuncUndo::mpDrawUndo)
805 pDoc->DeleteAreaTab( aDestRange, IDF_ALL|IDF_NOCAPTIONS );
806 pUndoDoc->CopyToDocument( aDestRange, IDF_ALL|IDF_NOCAPTIONS, false, pDoc );
809 // Row heights always (due to automatic adjustment)
810 // TODO change to use ScBlockUndo
811 pUndoDoc->CopyToDocument( 0, nStartRow, nSortTab, MAXCOL, nEndRow, nSortTab,
812 IDF_NONE, false, pDoc );
814 if (pUndoDB)
815 pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), sal_True );
817 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
818 if ( nVisTab != nSortTab )
819 pViewShell->SetTabNo( nSortTab );
821 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
822 pDocShell->PostDataChanged();
824 EndUndo();
827 void ScUndoSort::Redo()
829 BeginRedo();
831 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
833 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
834 if ( nVisTab != nTab )
835 pViewShell->SetTabNo( nTab );
837 pViewShell->MarkRange( ScRange( aSortParam.nCol1, aSortParam.nRow1, nTab,
838 aSortParam.nCol2, aSortParam.nRow2, nTab ) );
840 pViewShell->Sort( aSortParam, false );
842 // Paint source range due to selection
843 if ( !aSortParam.bInplace )
844 pDocShell->PostPaint( aSortParam.nCol1, aSortParam.nRow1, nTab,
845 aSortParam.nCol2, aSortParam.nRow2, nTab, PAINT_GRID );
847 EndRedo();
850 void ScUndoSort::Repeat(SfxRepeatTarget& /* rTarget */)
854 bool ScUndoSort::CanRepeat(SfxRepeatTarget& /* rTarget */) const
856 return false; // does not work due to column numbers
859 ScUndoQuery::ScUndoQuery( ScDocShell* pNewDocShell, SCTAB nNewTab, const ScQueryParam& rParam,
860 ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB,
861 const ScRange* pOld, sal_Bool bSize, const ScRange* pAdvSrc ) :
862 ScDBFuncUndo( pNewDocShell, ScRange( rParam.nCol1, rParam.nRow1, nNewTab,
863 rParam.nCol2, rParam.nRow2, nNewTab ) ),
864 pDrawUndo( NULL ),
865 nTab( nNewTab ),
866 aQueryParam( rParam ),
867 pUndoDoc( pNewUndoDoc ),
868 pUndoDB( pNewUndoDB ),
869 bIsAdvanced( false ),
870 bDestArea( false ),
871 bDoSize( bSize )
873 if ( pOld )
875 bDestArea = sal_True;
876 aOldDest = *pOld;
878 if ( pAdvSrc )
880 bIsAdvanced = sal_True;
881 aAdvSource = *pAdvSrc;
884 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
887 ScUndoQuery::~ScUndoQuery()
889 delete pUndoDoc;
890 delete pUndoDB;
891 DeleteSdrUndoAction( pDrawUndo );
894 OUString ScUndoQuery::GetComment() const
895 { // "Filter";
896 return ScGlobal::GetRscString( STR_UNDO_QUERY );
899 void ScUndoQuery::Undo()
901 BeginUndo();
903 ScDocument* pDoc = pDocShell->GetDocument();
904 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
906 sal_Bool bCopy = !aQueryParam.bInplace;
907 SCCOL nDestEndCol = 0;
908 SCROW nDestEndRow = 0;
909 if (bCopy)
911 nDestEndCol = aQueryParam.nDestCol + ( aQueryParam.nCol2-aQueryParam.nCol1 );
912 nDestEndRow = aQueryParam.nDestRow + ( aQueryParam.nRow2-aQueryParam.nRow1 );
914 ScDBData* pData = pDoc->GetDBAtCursor( aQueryParam.nDestCol, aQueryParam.nDestRow,
915 aQueryParam.nDestTab, sal_True );
916 if (pData)
918 ScRange aNewDest;
919 pData->GetArea( aNewDest );
920 nDestEndCol = aNewDest.aEnd.Col();
921 nDestEndRow = aNewDest.aEnd.Row();
924 if ( bDoSize && bDestArea )
926 // aDestRange is the old range
927 pDoc->FitBlock( ScRange(
928 aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
929 nDestEndCol, nDestEndRow, aQueryParam.nDestTab ),
930 aOldDest );
933 ScUndoUtil::MarkSimpleBlock( pDocShell,
934 aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
935 nDestEndCol, nDestEndRow, aQueryParam.nDestTab );
936 pDoc->DeleteAreaTab( aQueryParam.nDestCol, aQueryParam.nDestRow,
937 nDestEndCol, nDestEndRow, aQueryParam.nDestTab, IDF_ALL );
939 pViewShell->DoneBlockMode();
941 pUndoDoc->CopyToDocument( aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
942 nDestEndCol, nDestEndRow, aQueryParam.nDestTab,
943 IDF_ALL, false, pDoc );
944 // Attributes are always copied (#49287#)
946 // rest of the old range
947 if ( bDestArea && !bDoSize )
949 pDoc->DeleteAreaTab( aOldDest, IDF_ALL );
950 pUndoDoc->CopyToDocument( aOldDest, IDF_ALL, false, pDoc );
953 else
954 pUndoDoc->CopyToDocument( 0, aQueryParam.nRow1, nTab, MAXCOL, aQueryParam.nRow2, nTab,
955 IDF_NONE, false, pDoc );
957 if (pUndoDB)
958 pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), sal_True );
960 if (!bCopy)
962 pDoc->InvalidatePageBreaks(nTab);
963 pDoc->UpdatePageBreaks( nTab );
966 ScRange aDirtyRange( 0 , aQueryParam.nRow1, nTab,
967 MAXCOL, aQueryParam.nRow2, nTab );
968 pDoc->SetDirty( aDirtyRange );
970 DoSdrUndoAction( pDrawUndo, pDoc );
972 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
973 if ( nVisTab != nTab )
974 pViewShell->SetTabNo( nTab );
976 // Paint
978 if (bCopy)
980 SCCOL nEndX = nDestEndCol;
981 SCROW nEndY = nDestEndRow;
982 if (bDestArea)
984 if ( aOldDest.aEnd.Col() > nEndX )
985 nEndX = aOldDest.aEnd.Col();
986 if ( aOldDest.aEnd.Row() > nEndY )
987 nEndY = aOldDest.aEnd.Row();
989 if (bDoSize)
990 nEndY = MAXROW;
991 pDocShell->PostPaint( aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
992 nEndX, nEndY, aQueryParam.nDestTab, PAINT_GRID );
994 else
995 pDocShell->PostPaint( 0, aQueryParam.nRow1, nTab, MAXCOL, MAXROW, nTab,
996 PAINT_GRID | PAINT_LEFT );
997 pDocShell->PostDataChanged();
999 EndUndo();
1002 void ScUndoQuery::Redo()
1004 BeginRedo();
1006 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1008 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1009 if ( nVisTab != nTab )
1010 pViewShell->SetTabNo( nTab );
1012 if ( bIsAdvanced )
1013 pViewShell->Query( aQueryParam, &aAdvSource, false );
1014 else
1015 pViewShell->Query( aQueryParam, NULL, false );
1017 EndRedo();
1020 void ScUndoQuery::Repeat(SfxRepeatTarget& /* rTarget */)
1024 bool ScUndoQuery::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1026 return false; // does not work due to column numbers
1029 // Show or hide AutoFilter buttons (doesn't include filter settings)
1031 ScUndoAutoFilter::ScUndoAutoFilter( ScDocShell* pNewDocShell, const ScRange& rRange,
1032 const OUString& rName, bool bSet ) :
1033 ScDBFuncUndo( pNewDocShell, rRange ),
1034 aDBName( rName ),
1035 bFilterSet( bSet )
1039 ScUndoAutoFilter::~ScUndoAutoFilter()
1043 OUString ScUndoAutoFilter::GetComment() const
1045 return ScGlobal::GetRscString( STR_UNDO_QUERY ); // same as ScUndoQuery
1048 void ScUndoAutoFilter::DoChange( bool bUndo )
1050 bool bNewFilter = bUndo ? !bFilterSet : bFilterSet;
1052 ScDocument* pDoc = pDocShell->GetDocument();
1053 ScDBData* pDBData=NULL;
1054 if (aDBName.equalsAscii(STR_DB_LOCAL_NONAME))
1056 SCTAB nTab = aOriginalRange.aStart.Tab();
1057 pDBData = pDoc->GetAnonymousDBData(nTab);
1059 else
1061 ScDBCollection* pColl = pDoc->GetDBCollection();
1062 pDBData = pColl->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(aDBName));
1065 if ( pDBData )
1067 pDBData->SetAutoFilter( bNewFilter );
1069 SCCOL nRangeX1;
1070 SCROW nRangeY1;
1071 SCCOL nRangeX2;
1072 SCROW nRangeY2;
1073 SCTAB nRangeTab;
1074 pDBData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
1076 if ( bNewFilter )
1077 pDoc->ApplyFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
1078 else
1079 pDoc->RemoveFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
1081 pDocShell->PostPaint( nRangeX1, nRangeY1, nRangeTab, nRangeX2, nRangeY1, nRangeTab, PAINT_GRID );
1085 void ScUndoAutoFilter::Undo()
1087 BeginUndo();
1088 DoChange( sal_True );
1089 EndUndo();
1092 void ScUndoAutoFilter::Redo()
1094 BeginRedo();
1095 DoChange( false );
1096 EndRedo();
1099 void ScUndoAutoFilter::Repeat(SfxRepeatTarget& /* rTarget */)
1103 bool ScUndoAutoFilter::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1105 return false;
1108 // change database sections (dialog)
1109 ScUndoDBData::ScUndoDBData( ScDocShell* pNewDocShell,
1110 ScDBCollection* pNewUndoColl, ScDBCollection* pNewRedoColl ) :
1111 ScSimpleUndo( pNewDocShell ),
1112 pUndoColl( pNewUndoColl ),
1113 pRedoColl( pNewRedoColl )
1117 ScUndoDBData::~ScUndoDBData()
1119 delete pUndoColl;
1120 delete pRedoColl;
1123 OUString ScUndoDBData::GetComment() const
1124 { // "Change database range";
1125 return ScGlobal::GetRscString( STR_UNDO_DBDATA );
1128 void ScUndoDBData::Undo()
1130 BeginUndo();
1132 ScDocument* pDoc = pDocShell->GetDocument();
1134 sal_Bool bOldAutoCalc = pDoc->GetAutoCalc();
1135 pDoc->SetAutoCalc( false ); // Avoid unnecessary calculations
1136 pDoc->CompileDBFormula( sal_True ); // CreateFormulaString
1137 pDoc->SetDBCollection( new ScDBCollection(*pUndoColl), sal_True );
1138 pDoc->CompileDBFormula( false ); // CompileFormulaString
1139 pDoc->SetAutoCalc( bOldAutoCalc );
1141 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
1143 EndUndo();
1146 void ScUndoDBData::Redo()
1148 BeginRedo();
1150 ScDocument* pDoc = pDocShell->GetDocument();
1152 sal_Bool bOldAutoCalc = pDoc->GetAutoCalc();
1153 pDoc->SetAutoCalc( false ); // Avoid unnecessary calculations
1154 pDoc->CompileDBFormula( sal_True ); // CreateFormulaString
1155 pDoc->SetDBCollection( new ScDBCollection(*pRedoColl), sal_True );
1156 pDoc->CompileDBFormula( false ); // CompileFormulaString
1157 pDoc->SetAutoCalc( bOldAutoCalc );
1159 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
1161 EndRedo();
1164 void ScUndoDBData::Repeat(SfxRepeatTarget& /* rTarget */)
1168 bool ScUndoDBData::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1170 return false; // is not possible
1173 ScUndoImportData::ScUndoImportData( ScDocShell* pNewDocShell, SCTAB nNewTab,
1174 const ScImportParam& rParam, SCCOL nNewEndX, SCROW nNewEndY,
1175 SCCOL nNewFormula,
1176 ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
1177 ScDBData* pNewUndoData, ScDBData* pNewRedoData ) :
1178 ScSimpleUndo( pNewDocShell ),
1179 nTab( nNewTab ),
1180 aImportParam( rParam ),
1181 nEndCol( nNewEndX ),
1182 nEndRow( nNewEndY ),
1183 pUndoDoc( pNewUndoDoc ),
1184 pRedoDoc( pNewRedoDoc ),
1185 pUndoDBData( pNewUndoData ),
1186 pRedoDBData( pNewRedoData ),
1187 nFormulaCols( nNewFormula ),
1188 bRedoFilled( false )
1190 // redo doc doesn't contain imported data (but everything else)
1193 ScUndoImportData::~ScUndoImportData()
1195 delete pUndoDoc;
1196 delete pRedoDoc;
1197 delete pUndoDBData;
1198 delete pRedoDBData;
1201 OUString ScUndoImportData::GetComment() const
1203 return ScGlobal::GetRscString( STR_UNDO_IMPORTDATA );
1206 void ScUndoImportData::Undo()
1208 BeginUndo();
1210 ScDocument* pDoc = pDocShell->GetDocument();
1211 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1213 ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab,
1214 nEndCol,nEndRow,nTab );
1216 SCTAB nTable;
1217 SCCOL nCol1, nCol2;
1218 SCROW nRow1, nRow2;
1219 ScDBData* pCurrentData = NULL;
1220 if (pUndoDBData && pRedoDBData)
1222 pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1223 pCurrentData = ScUndoUtil::GetOldDBData( pRedoDBData, pDoc, nTab,
1224 nCol1, nRow1, nCol2, nRow2 );
1226 if ( !bRedoFilled )
1228 // read redo data from document at first undo
1229 // imported data is deleted later anyway,
1230 // so now delete each column after copying to save memory (#41216#)
1232 sal_Bool bOldAutoCalc = pDoc->GetAutoCalc();
1233 pDoc->SetAutoCalc( false ); // outside of the loop
1234 for (SCCOL nCopyCol = nCol1; nCopyCol <= nCol2; nCopyCol++)
1236 pDoc->CopyToDocument( nCopyCol,nRow1,nTab, nCopyCol,nRow2,nTab,
1237 IDF_CONTENTS & ~IDF_NOTE, false, pRedoDoc );
1238 pDoc->DeleteAreaTab( nCopyCol,nRow1, nCopyCol,nRow2, nTab, IDF_CONTENTS & ~IDF_NOTE );
1240 pDoc->SetAutoCalc( bOldAutoCalc );
1241 bRedoFilled = sal_True;
1244 sal_Bool bMoveCells = pUndoDBData && pRedoDBData &&
1245 pRedoDBData->IsDoSize(); // the same in old and new
1246 if (bMoveCells)
1248 // Undo: first delete the new data, then FitBlock backwards
1250 ScRange aOld, aNew;
1251 pUndoDBData->GetArea( aOld );
1252 pRedoDBData->GetArea( aNew );
1254 pDoc->DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
1255 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, IDF_ALL & ~IDF_NOTE );
1257 aOld.aEnd.SetCol( aOld.aEnd.Col() + nFormulaCols ); // FitBlock also for formulas
1258 aNew.aEnd.SetCol( aNew.aEnd.Col() + nFormulaCols );
1259 pDoc->FitBlock( aNew, aOld, false ); // backwards
1261 else
1262 pDoc->DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
1263 nEndCol,nEndRow, nTab, IDF_ALL & ~IDF_NOTE );
1265 pUndoDoc->CopyToDocument( aImportParam.nCol1,aImportParam.nRow1,nTab,
1266 nEndCol+nFormulaCols,nEndRow,nTab,
1267 IDF_ALL & ~IDF_NOTE, false, pDoc );
1269 if (pCurrentData)
1271 *pCurrentData = *pUndoDBData;
1273 pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1274 ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
1277 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1278 if ( nVisTab != nTab )
1279 pViewShell->SetTabNo( nTab );
1281 if (bMoveCells)
1282 pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
1283 else
1284 pDocShell->PostPaint( aImportParam.nCol1,aImportParam.nRow1,nTab,
1285 nEndCol,nEndRow,nTab, PAINT_GRID );
1286 pDocShell->PostDataChanged();
1288 EndUndo();
1291 void ScUndoImportData::Redo()
1293 BeginRedo();
1295 ScDocument* pDoc = pDocShell->GetDocument();
1296 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1298 ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab,
1299 nEndCol,nEndRow,nTab );
1301 SCTAB nTable;
1302 SCCOL nCol1, nCol2;
1303 SCROW nRow1, nRow2;
1304 ScDBData* pCurrentData = NULL;
1305 if (pUndoDBData && pRedoDBData)
1307 pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1308 pCurrentData = ScUndoUtil::GetOldDBData( pUndoDBData, pDoc, nTab,
1309 nCol1, nRow1, nCol2, nRow2 );
1311 sal_Bool bMoveCells = pUndoDBData && pRedoDBData &&
1312 pRedoDBData->IsDoSize(); // // the same in old and new
1313 if (bMoveCells)
1315 // Redo: FitBlock, then delete data (needed for CopyToDocument)
1317 ScRange aOld, aNew;
1318 pUndoDBData->GetArea( aOld );
1319 pRedoDBData->GetArea( aNew );
1321 aOld.aEnd.SetCol( aOld.aEnd.Col() + nFormulaCols ); // FitBlock also for formulas
1322 aNew.aEnd.SetCol( aNew.aEnd.Col() + nFormulaCols );
1323 pDoc->FitBlock( aOld, aNew );
1325 pDoc->DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
1326 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, IDF_ALL & ~IDF_NOTE );
1328 pRedoDoc->CopyToDocument( aNew, IDF_ALL & ~IDF_NOTE, false, pDoc ); // including formulas
1330 else
1332 pDoc->DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
1333 nEndCol,nEndRow, nTab, IDF_ALL & ~IDF_NOTE );
1334 pRedoDoc->CopyToDocument( aImportParam.nCol1,aImportParam.nRow1,nTab,
1335 nEndCol,nEndRow,nTab, IDF_ALL & ~IDF_NOTE, false, pDoc );
1338 if (pCurrentData)
1340 *pCurrentData = *pRedoDBData;
1342 pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1343 ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
1346 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1347 if ( nVisTab != nTab )
1348 pViewShell->SetTabNo( nTab );
1350 if (bMoveCells)
1351 pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
1352 else
1353 pDocShell->PostPaint( aImportParam.nCol1,aImportParam.nRow1,nTab,
1354 nEndCol,nEndRow,nTab, PAINT_GRID );
1355 pDocShell->PostDataChanged();
1357 EndRedo();
1360 void ScUndoImportData::Repeat(SfxRepeatTarget& rTarget)
1362 if (rTarget.ISA(ScTabViewTarget))
1364 ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
1366 SCTAB nDummy;
1367 ScImportParam aNewParam(aImportParam);
1368 ScDBData* pDBData = rViewShell.GetDBData();
1369 pDBData->GetArea( nDummy, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
1371 rViewShell.ImportData( aNewParam );
1375 bool ScUndoImportData::CanRepeat(SfxRepeatTarget& rTarget) const
1377 // Repeat only for import using a database range, then pUndoDBData is set
1379 if (pUndoDBData)
1380 return rTarget.ISA(ScTabViewTarget);
1381 else
1382 return false; // Address book
1386 ScUndoRepeatDB::ScUndoRepeatDB( ScDocShell* pNewDocShell, SCTAB nNewTab,
1387 SCCOL nStartX, SCROW nStartY, SCCOL nEndX, SCROW nEndY,
1388 SCROW nResultEndRow, SCCOL nCurX, SCROW nCurY,
1389 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
1390 ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB,
1391 const ScRange* pOldQ, const ScRange* pNewQ ) :
1392 ScSimpleUndo( pNewDocShell ),
1393 aBlockStart( nStartX,nStartY,nNewTab ),
1394 aBlockEnd( nEndX,nEndY,nNewTab ),
1395 nNewEndRow( nResultEndRow ),
1396 aCursorPos( nCurX,nCurY,nNewTab ),
1397 pUndoDoc( pNewUndoDoc ),
1398 pUndoTable( pNewUndoTab ),
1399 pUndoRange( pNewUndoRange ),
1400 pUndoDB( pNewUndoDB ),
1401 bQuerySize( false )
1403 if ( pOldQ && pNewQ )
1405 aOldQuery = *pOldQ;
1406 aNewQuery = *pNewQ;
1407 bQuerySize = sal_True;;
1411 ScUndoRepeatDB::~ScUndoRepeatDB()
1413 delete pUndoDoc;
1414 delete pUndoTable;
1415 delete pUndoRange;
1416 delete pUndoDB;
1419 OUString ScUndoRepeatDB::GetComment() const
1421 return ScGlobal::GetRscString( STR_UNDO_REPEATDB );
1424 void ScUndoRepeatDB::Undo()
1426 BeginUndo();
1428 ScDocument* pDoc = pDocShell->GetDocument();
1429 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1430 SCTAB nTab = aBlockStart.Tab();
1432 if (bQuerySize)
1434 pDoc->FitBlock( aNewQuery, aOldQuery, false );
1436 if ( aNewQuery.aEnd.Col() == aOldQuery.aEnd.Col() )
1438 SCCOL nFormulaCols = 0;
1439 SCCOL nCol = aOldQuery.aEnd.Col() + 1;
1440 SCROW nRow = aOldQuery.aStart.Row() + 1; // test the header
1441 while ( nCol <= MAXCOL &&
1442 pDoc->GetCellType(ScAddress( nCol, nRow, nTab )) == CELLTYPE_FORMULA )
1443 ++nCol, ++nFormulaCols;
1445 if ( nFormulaCols > 0 )
1447 ScRange aOldForm = aOldQuery;
1448 aOldForm.aStart.SetCol( aOldQuery.aEnd.Col() + 1 );
1449 aOldForm.aEnd.SetCol( aOldQuery.aEnd.Col() + nFormulaCols );
1450 ScRange aNewForm = aOldForm;
1451 aNewForm.aEnd.SetRow( aNewQuery.aEnd.Row() );
1452 pDoc->FitBlock( aNewForm, aOldForm, false );
1457 // TODO Data from Filter in other range are still missing!
1459 if (nNewEndRow > aBlockEnd.Row())
1461 pDoc->DeleteRow( 0,nTab, MAXCOL,nTab, aBlockEnd.Row()+1, static_cast<SCSIZE>(nNewEndRow-aBlockEnd.Row()) );
1463 else if (nNewEndRow < aBlockEnd.Row())
1465 pDoc->InsertRow( 0,nTab, MAXCOL,nTab, nNewEndRow+1, static_cast<SCSIZE>(nNewEndRow-aBlockEnd.Row()) );
1468 // Original Outline table
1469 pDoc->SetOutlineTable( nTab, pUndoTable );
1471 // Original column/row status
1472 if (pUndoDoc && pUndoTable)
1474 SCCOLROW nStartCol;
1475 SCCOLROW nStartRow;
1476 SCCOLROW nEndCol;
1477 SCCOLROW nEndRow;
1478 pUndoTable->GetColArray()->GetRange( nStartCol, nEndCol );
1479 pUndoTable->GetRowArray()->GetRange( nStartRow, nEndRow );
1481 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
1482 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false,
1483 pDoc );
1484 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
1486 pViewShell->UpdateScrollBars();
1489 // Original data and references
1490 ScUndoUtil::MarkSimpleBlock( pDocShell, 0, aBlockStart.Row(), nTab,
1491 MAXCOL, aBlockEnd.Row(), nTab );
1492 pDoc->DeleteAreaTab( 0, aBlockStart.Row(),
1493 MAXCOL, aBlockEnd.Row(), nTab, IDF_ALL );
1495 pUndoDoc->CopyToDocument( 0, aBlockStart.Row(), nTab, MAXCOL, aBlockEnd.Row(), nTab,
1496 IDF_NONE, false, pDoc ); // Flags
1497 pUndoDoc->UndoToDocument( 0, aBlockStart.Row(), nTab, MAXCOL, aBlockEnd.Row(), nTab,
1498 IDF_ALL, false, pDoc );
1500 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart.Col(),aBlockStart.Row(),nTab,
1501 aBlockEnd.Col(),aBlockEnd.Row(),nTab );
1503 if (pUndoRange)
1504 pDoc->SetRangeName( new ScRangeName( *pUndoRange ) );
1505 if (pUndoDB)
1506 pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), sal_True );
1508 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1509 if ( nVisTab != nTab )
1510 pViewShell->SetTabNo( nTab );
1512 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
1513 pDocShell->PostDataChanged();
1515 EndUndo();
1518 void ScUndoRepeatDB::Redo()
1520 BeginRedo();
1522 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1523 SCTAB nTab = aBlockStart.Tab();
1525 SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1526 if ( nVisTab != nTab )
1527 pViewShell->SetTabNo( nTab );
1529 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart.Col(),aBlockStart.Row(),nTab,
1530 aBlockEnd.Col(),aBlockEnd.Row(),nTab );
1531 pViewShell->SetCursor( aCursorPos.Col(), aCursorPos.Row() );
1533 pViewShell->RepeatDB( false );
1535 EndRedo();
1538 void ScUndoRepeatDB::Repeat(SfxRepeatTarget& rTarget)
1540 if (rTarget.ISA(ScTabViewTarget))
1541 ((ScTabViewTarget&)rTarget).GetViewShell()->RepeatDB( sal_True );
1544 bool ScUndoRepeatDB::CanRepeat(SfxRepeatTarget& rTarget) const
1546 return rTarget.ISA(ScTabViewTarget);
1549 ScUndoDataPilot::ScUndoDataPilot( ScDocShell* pNewDocShell,
1550 ScDocument* pOldDoc, ScDocument* pNewDoc,
1551 const ScDPObject* pOldObj, const ScDPObject* pNewObj, sal_Bool bMove ) :
1552 ScSimpleUndo( pNewDocShell ),
1553 pOldUndoDoc( pOldDoc ),
1554 pNewUndoDoc( pNewDoc ),
1555 pOldDPObject( NULL ),
1556 pNewDPObject( NULL ),
1557 bAllowMove( bMove )
1559 if (pOldObj)
1560 pOldDPObject = new ScDPObject( *pOldObj );
1561 if (pNewObj)
1562 pNewDPObject = new ScDPObject( *pNewObj );
1565 ScUndoDataPilot::~ScUndoDataPilot()
1567 delete pOldDPObject;
1568 delete pNewDPObject;
1569 delete pOldUndoDoc;
1570 delete pNewUndoDoc;
1573 OUString ScUndoDataPilot::GetComment() const
1575 sal_uInt16 nIndex;
1576 if ( pOldUndoDoc && pNewUndoDoc )
1577 nIndex = STR_UNDO_PIVOT_MODIFY;
1578 else if ( pNewUndoDoc )
1579 nIndex = STR_UNDO_PIVOT_NEW;
1580 else
1581 nIndex = STR_UNDO_PIVOT_DELETE;
1583 return ScGlobal::GetRscString( nIndex );
1586 void ScUndoDataPilot::Undo()
1588 BeginUndo();
1590 ScDocument* pDoc = pDocShell->GetDocument();
1592 ScRange aOldRange;
1593 ScRange aNewRange;
1595 if ( pNewDPObject && pNewUndoDoc )
1597 aNewRange = pNewDPObject->GetOutRange();
1598 pDoc->DeleteAreaTab( aNewRange, IDF_ALL );
1599 pNewUndoDoc->CopyToDocument( aNewRange, IDF_ALL, false, pDoc );
1601 if ( pOldDPObject && pOldUndoDoc )
1603 aOldRange = pOldDPObject->GetOutRange();
1604 pDoc->DeleteAreaTab( aOldRange, IDF_ALL );
1605 pOldUndoDoc->CopyToDocument( aOldRange, IDF_ALL, false, pDoc );
1608 // update objects in collection
1610 if ( pNewDPObject )
1612 // find updated object
1613 //! find by name!
1615 ScDPObject* pDocObj = pDoc->GetDPAtCursor(
1616 aNewRange.aStart.Col(), aNewRange.aStart.Row(), aNewRange.aStart.Tab() );
1617 OSL_ENSURE(pDocObj, "DPObject not found");
1618 if (pDocObj)
1620 if ( pOldDPObject )
1622 // restore old settings
1623 pOldDPObject->WriteSourceDataTo( *pDocObj );
1624 ScDPSaveData* pData = pOldDPObject->GetSaveData();
1625 if (pData)
1626 pDocObj->SetSaveData(*pData);
1627 pDocObj->SetOutRange( pOldDPObject->GetOutRange() );
1628 pOldDPObject->WriteTempDataTo( *pDocObj );
1630 else
1632 // delete inserted object
1633 pDoc->GetDPCollection()->FreeTable(pDocObj);
1637 else if ( pOldDPObject )
1639 // re-insert deleted object
1641 ScDPObject* pDestObj = new ScDPObject( *pOldDPObject );
1642 if ( !pDoc->GetDPCollection()->InsertNewTable(pDestObj) )
1644 OSL_FAIL("cannot insert DPObject");
1645 DELETEZ( pDestObj );
1649 if (pNewUndoDoc)
1650 pDocShell->PostPaint( aNewRange, PAINT_GRID, SC_PF_LINES );
1651 if (pOldUndoDoc)
1652 pDocShell->PostPaint( aOldRange, PAINT_GRID, SC_PF_LINES );
1653 pDocShell->PostDataChanged();
1655 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1656 if (pViewShell)
1658 //! set current sheet
1661 if (pNewDPObject)
1663 // notify API objects
1664 pDoc->BroadcastUno( ScDataPilotModifiedHint( pNewDPObject->GetName() ) );
1667 EndUndo();
1670 void ScUndoDataPilot::Redo()
1672 BeginRedo();
1674 //! copy output data instead of repeating the change,
1675 //! in case external data have changed!
1677 ScDocument* pDoc = pDocShell->GetDocument();
1679 ScDPObject* pSourceObj = NULL;
1680 if ( pOldDPObject )
1682 // find object to modify
1683 //! find by name!
1685 ScRange aOldRange = pOldDPObject->GetOutRange();
1686 pSourceObj = pDoc->GetDPAtCursor(
1687 aOldRange.aStart.Col(), aOldRange.aStart.Row(), aOldRange.aStart.Tab() );
1688 OSL_ENSURE(pSourceObj, "DPObject not found");
1691 ScDBDocFunc aFunc( *pDocShell );
1692 aFunc.DataPilotUpdate( pSourceObj, pNewDPObject, false, false, bAllowMove ); // no new undo action
1694 EndRedo();
1697 void ScUndoDataPilot::Repeat(SfxRepeatTarget& /* rTarget */)
1699 //! allow deletion
1702 bool ScUndoDataPilot::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1704 //! allow deletion
1705 return false;
1708 ScUndoConsolidate::ScUndoConsolidate( ScDocShell* pNewDocShell, const ScArea& rArea,
1709 const ScConsolidateParam& rPar, ScDocument* pNewUndoDoc,
1710 sal_Bool bReference, SCROW nInsCount, ScOutlineTable* pTab,
1711 ScDBData* pData ) :
1712 ScSimpleUndo( pNewDocShell ),
1713 aDestArea( rArea ),
1714 pUndoDoc( pNewUndoDoc ),
1715 aParam( rPar ),
1716 bInsRef( bReference ),
1717 nInsertCount( nInsCount ),
1718 pUndoTab( pTab ),
1719 pUndoData( pData )
1723 ScUndoConsolidate::~ScUndoConsolidate()
1725 delete pUndoDoc;
1726 delete pUndoTab;
1727 delete pUndoData;
1730 OUString ScUndoConsolidate::GetComment() const
1732 return ScGlobal::GetRscString( STR_UNDO_CONSOLIDATE );
1735 void ScUndoConsolidate::Undo()
1737 BeginUndo();
1739 ScDocument* pDoc = pDocShell->GetDocument();
1740 SCTAB nTab = aDestArea.nTab;
1742 ScRange aOldRange;
1743 if (pUndoData)
1744 pUndoData->GetArea(aOldRange);
1746 if (bInsRef)
1748 pDoc->DeleteRow( 0,nTab, MAXCOL,nTab, aDestArea.nRowStart, nInsertCount );
1749 pDoc->SetOutlineTable( nTab, pUndoTab );
1751 // Row status
1752 pUndoDoc->CopyToDocument( 0,0,nTab, MAXCOL,MAXROW,nTab, IDF_NONE, false, pDoc );
1754 // Data and references
1755 pDoc->DeleteAreaTab( 0,aDestArea.nRowStart, MAXCOL,aDestArea.nRowEnd, nTab, IDF_ALL );
1756 pUndoDoc->UndoToDocument( 0, aDestArea.nRowStart, nTab,
1757 MAXCOL, aDestArea.nRowEnd, nTab,
1758 IDF_ALL, false, pDoc );
1760 // Original range
1761 if (pUndoData)
1763 pDoc->DeleteAreaTab(aOldRange, IDF_ALL);
1764 pUndoDoc->CopyToDocument(aOldRange, IDF_ALL, false, pDoc);
1767 pDocShell->PostPaint( 0,aDestArea.nRowStart,nTab, MAXCOL,MAXROW,nTab,
1768 PAINT_GRID | PAINT_LEFT | PAINT_SIZE );
1770 else
1772 pDoc->DeleteAreaTab( aDestArea.nColStart,aDestArea.nRowStart,
1773 aDestArea.nColEnd,aDestArea.nRowEnd, nTab, IDF_ALL );
1774 pUndoDoc->CopyToDocument( aDestArea.nColStart, aDestArea.nRowStart, nTab,
1775 aDestArea.nColEnd, aDestArea.nRowEnd, nTab,
1776 IDF_ALL, false, pDoc );
1778 // Original range
1779 if (pUndoData)
1781 pDoc->DeleteAreaTab(aOldRange, IDF_ALL);
1782 pUndoDoc->CopyToDocument(aOldRange, IDF_ALL, false, pDoc);
1785 SCCOL nEndX = aDestArea.nColEnd;
1786 SCROW nEndY = aDestArea.nRowEnd;
1787 if ( pUndoData )
1789 if ( aOldRange.aEnd.Col() > nEndX )
1790 nEndX = aOldRange.aEnd.Col();
1791 if ( aOldRange.aEnd.Row() > nEndY )
1792 nEndY = aOldRange.aEnd.Row();
1794 pDocShell->PostPaint( aDestArea.nColStart, aDestArea.nRowStart, nTab,
1795 nEndX, nEndY, nTab, PAINT_GRID );
1798 // Adjust Database range again
1799 if (pUndoData)
1801 ScDBCollection* pColl = pDoc->GetDBCollection();
1802 if (pColl)
1804 ScDBData* pDocData = pColl->getNamedDBs().findByUpperName(pUndoData->GetUpperName());
1805 if (pDocData)
1806 *pDocData = *pUndoData;
1810 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1811 if (pViewShell)
1813 SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
1814 if ( nViewTab != nTab )
1815 pViewShell->SetTabNo( nTab );
1818 EndUndo();
1821 void ScUndoConsolidate::Redo()
1823 BeginRedo();
1825 pDocShell->DoConsolidate( aParam, false );
1827 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1828 if (pViewShell)
1830 SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
1831 if ( nViewTab != aParam.nTab )
1832 pViewShell->SetTabNo( aParam.nTab );
1835 EndRedo();
1838 void ScUndoConsolidate::Repeat(SfxRepeatTarget& /* rTarget */)
1842 bool ScUndoConsolidate::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1844 return false;
1847 // Change source data of Chart
1848 void ScUndoChartData::Init()
1850 ScDocument* pDoc = pDocShell->GetDocument();
1851 aOldRangeListRef = new ScRangeList;
1852 pDoc->GetOldChartParameters( aChartName, *aOldRangeListRef, bOldColHeaders, bOldRowHeaders );
1855 ScUndoChartData::ScUndoChartData( ScDocShell* pNewDocShell, const OUString& rName,
1856 const ScRange& rNew, bool bColHdr, bool bRowHdr,
1857 bool bAdd ) :
1858 ScSimpleUndo( pNewDocShell ),
1859 aChartName( rName ),
1860 bNewColHeaders( bColHdr ),
1861 bNewRowHeaders( bRowHdr ),
1862 bAddRange( bAdd )
1864 aNewRangeListRef = new ScRangeList;
1865 aNewRangeListRef->Append( rNew );
1867 Init();
1870 ScUndoChartData::ScUndoChartData( ScDocShell* pNewDocShell, const OUString& rName,
1871 const ScRangeListRef& rNew, bool bColHdr, bool bRowHdr,
1872 bool bAdd ) :
1873 ScSimpleUndo( pNewDocShell ),
1874 aChartName( rName ),
1875 aNewRangeListRef( rNew ),
1876 bNewColHeaders( bColHdr ),
1877 bNewRowHeaders( bRowHdr ),
1878 bAddRange( bAdd )
1880 Init();
1883 ScUndoChartData::~ScUndoChartData()
1887 OUString ScUndoChartData::GetComment() const
1889 return ScGlobal::GetRscString( STR_UNDO_CHARTDATA );
1892 void ScUndoChartData::Undo()
1894 BeginUndo();
1896 pDocShell->GetDocument()->UpdateChartArea( aChartName, aOldRangeListRef,
1897 bOldColHeaders, bOldRowHeaders, false );
1899 EndUndo();
1902 void ScUndoChartData::Redo()
1904 BeginRedo();
1906 pDocShell->GetDocument()->UpdateChartArea( aChartName, aNewRangeListRef,
1907 bNewColHeaders, bNewRowHeaders, bAddRange );
1909 EndRedo();
1912 void ScUndoChartData::Repeat(SfxRepeatTarget& /* rTarget */)
1916 bool ScUndoChartData::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1918 return false;
1921 ScUndoDataForm::ScUndoDataForm( ScDocShell* pNewDocShell,
1922 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
1923 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
1924 const ScMarkData& rMark,
1925 ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
1926 sal_uInt16 nNewFlags,
1927 ScRefUndoData* pRefData,
1928 void* /*pFill1*/, void* /*pFill2*/, void* /*pFill3*/,
1929 sal_Bool bRedoIsFilled ) :
1930 ScBlockUndo( pNewDocShell, ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ), SC_UNDO_SIMPLE ),
1931 mpMarkData(new ScMarkData(rMark)),
1932 pUndoDoc( pNewUndoDoc ),
1933 pRedoDoc( pNewRedoDoc ),
1934 nFlags( nNewFlags ),
1935 pRefUndoData( pRefData ),
1936 pRefRedoData( NULL ),
1937 bRedoFilled( bRedoIsFilled )
1939 // pFill1,pFill2,pFill3 are there so the ctor calls for simple paste (without cutting)
1940 // don't have to be changed and branched for 641.
1941 // They can be removed later.
1943 if (!mpMarkData->IsMarked()) // no cell marked:
1944 mpMarkData->SetMarkArea(aBlockRange); // mark paste block
1946 if ( pRefUndoData )
1947 pRefUndoData->DeleteUnchanged( pDocShell->GetDocument() );
1949 SetChangeTrack();
1952 ScUndoDataForm::~ScUndoDataForm()
1954 delete pUndoDoc;
1955 delete pRedoDoc;
1956 delete pRefUndoData;
1957 delete pRefRedoData;
1960 OUString ScUndoDataForm::GetComment() const
1962 return ScGlobal::GetRscString( STR_UNDO_PASTE );
1965 void ScUndoDataForm::SetChangeTrack()
1967 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1968 if ( pChangeTrack && (nFlags & IDF_CONTENTS) )
1969 pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
1970 nStartChangeAction, nEndChangeAction, SC_CACM_PASTE );
1971 else
1972 nStartChangeAction = nEndChangeAction = 0;
1975 void ScUndoDataForm::Undo()
1977 BeginUndo();
1978 DoChange( true );
1979 ShowTable( aBlockRange );
1980 EndUndo();
1981 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
1984 void ScUndoDataForm::Redo()
1986 BeginRedo();
1987 ScDocument* pDoc = pDocShell->GetDocument();
1988 EnableDrawAdjust( pDoc, false ); //! include in ScBlockUndo?
1989 DoChange( false );
1990 EnableDrawAdjust( pDoc, true ); //! include in ScBlockUndo?
1991 EndRedo();
1992 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
1995 void ScUndoDataForm::Repeat(SfxRepeatTarget& /*rTarget*/)
1999 bool ScUndoDataForm::CanRepeat(SfxRepeatTarget& rTarget) const
2001 return (rTarget.ISA(ScTabViewTarget));
2004 void ScUndoDataForm::DoChange( const sal_Bool bUndo )
2006 ScDocument* pDoc = pDocShell->GetDocument();
2008 // RefUndoData for redo is created before first undo
2009 // (with DeleteUnchanged after the DoUndo call)
2010 sal_Bool bCreateRedoData = ( bUndo && pRefUndoData && !pRefRedoData );
2011 if ( bCreateRedoData )
2012 pRefRedoData = new ScRefUndoData( pDoc );
2014 ScRefUndoData* pWorkRefData = bUndo ? pRefUndoData : pRefRedoData;
2016 // Always back-up either all or none of the content for Undo
2017 sal_uInt16 nUndoFlags = IDF_NONE;
2018 if (nFlags & IDF_CONTENTS)
2019 nUndoFlags |= IDF_CONTENTS;
2020 if (nFlags & IDF_ATTRIB)
2021 nUndoFlags |= IDF_ATTRIB;
2023 sal_Bool bPaintAll = false;
2025 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
2027 SCTAB nTabCount = pDoc->GetTableCount();
2028 if ( bUndo && !bRedoFilled )
2030 if (!pRedoDoc)
2032 sal_Bool bColInfo = ( aBlockRange.aStart.Row()==0 && aBlockRange.aEnd.Row()==MAXROW );
2033 sal_Bool bRowInfo = ( aBlockRange.aStart.Col()==0 && aBlockRange.aEnd.Col()==MAXCOL );
2035 pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
2036 pRedoDoc->InitUndoSelected( pDoc, *mpMarkData, bColInfo, bRowInfo );
2038 // read "redo" data from the document in the first undo
2039 // all sheets - CopyToDocument skips those that don't exist in pRedoDoc
2040 ScRange aCopyRange = aBlockRange;
2041 aCopyRange.aStart.SetTab(0);
2042 aCopyRange.aEnd.SetTab(nTabCount-1);
2043 pDoc->CopyToDocument( aCopyRange, 1, false, pRedoDoc );
2044 bRedoFilled = true;
2047 sal_uInt16 nExtFlags = 0;
2048 pDocShell->UpdatePaintExt( nExtFlags, aBlockRange );
2050 for ( sal_uInt16 i=0; i <= ( aBlockRange.aEnd.Col() - aBlockRange.aStart.Col() ); i++ )
2052 OUString aOldString = pUndoDoc->GetString(
2053 aBlockRange.aStart.Col()+i, aBlockRange.aStart.Row(), aBlockRange.aStart.Tab());
2054 pDoc->SetString( aBlockRange.aStart.Col()+i , aBlockRange.aStart.Row() , aBlockRange.aStart.Tab() , aOldString );
2057 if (pWorkRefData)
2059 pWorkRefData->DoUndo( pDoc, true ); // TRUE = bSetChartRangeLists for SetChartListenerCollection
2060 if ( pDoc->RefreshAutoFilter( 0,0, MAXCOL,MAXROW, aBlockRange.aStart.Tab() ) )
2061 bPaintAll = true;
2064 if ( bCreateRedoData && pRefRedoData )
2065 pRefRedoData->DeleteUnchanged( pDoc );
2067 if ( bUndo )
2069 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
2070 if ( pChangeTrack )
2071 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
2073 else
2074 SetChangeTrack();
2076 ScRange aDrawRange( aBlockRange );
2077 pDoc->ExtendMerge( aDrawRange, true ); // only needed for single sheet (text/rtf etc.)
2078 sal_uInt16 nPaint = PAINT_GRID;
2079 if (bPaintAll)
2081 aDrawRange.aStart.SetCol(0);
2082 aDrawRange.aStart.SetRow(0);
2083 aDrawRange.aEnd.SetCol(MAXCOL);
2084 aDrawRange.aEnd.SetRow(MAXROW);
2085 nPaint |= PAINT_TOP | PAINT_LEFT;
2086 /*A*/ if (pViewShell)
2087 pViewShell->AdjustBlockHeight(false);
2089 else
2091 if ( aBlockRange.aStart.Row() == 0 && aBlockRange.aEnd.Row() == MAXROW ) // whole column
2093 nPaint |= PAINT_TOP;
2094 aDrawRange.aEnd.SetCol(MAXCOL);
2096 if ( aBlockRange.aStart.Col() == 0 && aBlockRange.aEnd.Col() == MAXCOL ) // whole row
2098 nPaint |= PAINT_LEFT;
2099 aDrawRange.aEnd.SetRow(MAXROW);
2101 /*A*/ if ((pViewShell) && pViewShell->AdjustBlockHeight(false))
2103 aDrawRange.aStart.SetCol(0);
2104 aDrawRange.aStart.SetRow(0);
2105 aDrawRange.aEnd.SetCol(MAXCOL);
2106 aDrawRange.aEnd.SetRow(MAXROW);
2107 nPaint |= PAINT_LEFT;
2109 pDocShell->UpdatePaintExt( nExtFlags, aDrawRange );
2112 if ( !bUndo ) // draw redo after updating row heights
2113 RedoSdrUndoAction( pDrawUndo ); //! include in ScBlockUndo?
2115 pDocShell->PostPaint( aDrawRange, nPaint, nExtFlags );
2117 pDocShell->PostDataChanged();
2118 if (pViewShell)
2119 pViewShell->CellContentChanged();
2122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */