fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / undo / undodat.cxx
blob9fd47025438c1fa4b70c0b3937408337b3372151
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 TYPEINIT1(ScUndoDoOutline, ScSimpleUndo);
48 TYPEINIT1(ScUndoMakeOutline, ScSimpleUndo);
49 TYPEINIT1(ScUndoOutlineLevel, ScSimpleUndo);
50 TYPEINIT1(ScUndoOutlineBlock, ScSimpleUndo);
51 TYPEINIT1(ScUndoRemoveAllOutlines, ScSimpleUndo);
52 TYPEINIT1(ScUndoAutoOutline, ScSimpleUndo);
53 TYPEINIT1(ScUndoSubTotals, ScDBFuncUndo);
54 TYPEINIT1(ScUndoQuery, ScDBFuncUndo);
55 TYPEINIT1(ScUndoAutoFilter, ScDBFuncUndo);
56 TYPEINIT1(ScUndoDBData, ScSimpleUndo);
57 TYPEINIT1(ScUndoImportData, ScSimpleUndo);
58 TYPEINIT1(ScUndoRepeatDB, ScSimpleUndo);
59 TYPEINIT1(ScUndoDataPilot, ScSimpleUndo);
60 TYPEINIT1(ScUndoConsolidate, ScSimpleUndo);
61 TYPEINIT1(ScUndoChartData, ScSimpleUndo);
62 TYPEINIT1(ScUndoDataForm, SfxUndoAction);
64 // Show or hide outline groups
66 ScUndoDoOutline::ScUndoDoOutline( ScDocShell* pNewDocShell,
67 SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
68 ScDocument* pNewUndoDoc, bool bNewColumns,
69 sal_uInt16 nNewLevel, sal_uInt16 nNewEntry, bool bNewShow ) :
70 ScSimpleUndo( pNewDocShell ),
71 nStart( nNewStart ),
72 nEnd( nNewEnd ),
73 nTab( nNewTab ),
74 pUndoDoc( pNewUndoDoc ),
75 bColumns( bNewColumns ),
76 nLevel( nNewLevel ),
77 nEntry( nNewEntry ),
78 bShow( bNewShow )
82 ScUndoDoOutline::~ScUndoDoOutline()
84 delete pUndoDoc;
87 OUString ScUndoDoOutline::GetComment() const
88 { // Show outline" "Hide outline"
89 return bShow ?
90 ScGlobal::GetRscString( STR_UNDO_DOOUTLINE ) :
91 ScGlobal::GetRscString( STR_UNDO_REDOOUTLINE );
94 void ScUndoDoOutline::Undo()
96 BeginUndo();
98 ScDocument& rDoc = pDocShell->GetDocument();
99 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
101 // sheet has to be switched over (#46952#)!
103 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
104 if ( nVisTab != nTab )
105 pViewShell->SetTabNo( nTab );
107 // perform the inverse function
109 if (bShow)
110 pViewShell->HideOutline( bColumns, nLevel, nEntry, false, false );
111 else
112 pViewShell->ShowOutline( bColumns, nLevel, nEntry, false, false );
114 // Original column/row status
115 if (bColumns)
116 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
117 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false, &rDoc);
118 else
119 pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, &rDoc );
121 pViewShell->UpdateScrollBars();
123 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
125 EndUndo();
128 void ScUndoDoOutline::Redo()
130 BeginRedo();
132 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
134 // sheet has to be switched over (#46952#)!
136 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
137 if ( nVisTab != nTab )
138 pViewShell->SetTabNo( nTab );
140 if (bShow)
141 pViewShell->ShowOutline( bColumns, nLevel, nEntry, false );
142 else
143 pViewShell->HideOutline( bColumns, nLevel, nEntry, false );
145 EndRedo();
148 void ScUndoDoOutline::Repeat(SfxRepeatTarget& /* rTarget */)
152 bool ScUndoDoOutline::CanRepeat(SfxRepeatTarget& /* rTarget */) const
154 return false; // is not possible
157 /** Make or delete outline groups */
158 ScUndoMakeOutline::ScUndoMakeOutline( ScDocShell* pNewDocShell,
159 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
160 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
161 ScOutlineTable* pNewUndoTab, bool bNewColumns, bool bNewMake ) :
162 ScSimpleUndo( pNewDocShell ),
163 aBlockStart( nStartX, nStartY, nStartZ ),
164 aBlockEnd( nEndX, nEndY, nEndZ ),
165 pUndoTable( pNewUndoTab ),
166 bColumns( bNewColumns ),
167 bMake( bNewMake )
171 ScUndoMakeOutline::~ScUndoMakeOutline()
173 delete pUndoTable;
176 OUString ScUndoMakeOutline::GetComment() const
177 { // "Grouping" "Undo grouping"
178 return bMake ?
179 ScGlobal::GetRscString( STR_UNDO_MAKEOUTLINE ) :
180 ScGlobal::GetRscString( STR_UNDO_REMAKEOUTLINE );
183 void ScUndoMakeOutline::Undo()
185 BeginUndo();
187 ScDocument& rDoc = pDocShell->GetDocument();
188 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
189 SCTAB nTab = aBlockStart.Tab();
191 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
193 rDoc.SetOutlineTable( nTab, pUndoTable );
195 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
196 if ( nVisTab != nTab )
197 pViewShell->SetTabNo( nTab );
199 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
201 EndUndo();
204 void ScUndoMakeOutline::Redo()
206 BeginRedo();
208 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
210 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
212 if (bMake)
213 pViewShell->MakeOutline( bColumns, false );
214 else
215 pViewShell->RemoveOutline( bColumns, false );
217 pDocShell->PostPaint(0,0,aBlockStart.Tab(),MAXCOL,MAXROW,aBlockEnd.Tab(),PAINT_GRID);
219 EndRedo();
222 void ScUndoMakeOutline::Repeat(SfxRepeatTarget& rTarget)
224 if (rTarget.ISA(ScTabViewTarget))
226 ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
228 if (bMake)
229 rViewShell.MakeOutline( bColumns, true );
230 else
231 rViewShell.RemoveOutline( bColumns, true );
235 bool ScUndoMakeOutline::CanRepeat(SfxRepeatTarget& rTarget) const
237 return rTarget.ISA(ScTabViewTarget);
240 ScUndoOutlineLevel::ScUndoOutlineLevel( ScDocShell* pNewDocShell,
241 SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
242 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
243 bool bNewColumns, sal_uInt16 nNewLevel ) :
244 ScSimpleUndo( pNewDocShell ),
245 nStart( nNewStart ),
246 nEnd( nNewEnd ),
247 nTab( nNewTab ),
248 pUndoDoc( pNewUndoDoc ),
249 pUndoTable( pNewUndoTab ),
250 bColumns( bNewColumns ),
251 nLevel( nNewLevel )
255 ScUndoOutlineLevel::~ScUndoOutlineLevel()
257 delete pUndoDoc;
258 delete pUndoTable;
261 OUString ScUndoOutlineLevel::GetComment() const
262 { // "Select outline level"
263 return ScGlobal::GetRscString( STR_UNDO_OUTLINELEVEL );
266 void ScUndoOutlineLevel::Undo()
268 BeginUndo();
270 ScDocument& rDoc = pDocShell->GetDocument();
271 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
273 // Original Outline table
275 rDoc.SetOutlineTable( nTab, pUndoTable );
277 // Original column/row status
279 if (bColumns)
280 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
281 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false, &rDoc);
282 else
283 pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, &rDoc );
285 rDoc.UpdatePageBreaks( nTab );
287 pViewShell->UpdateScrollBars();
289 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
290 if ( nVisTab != nTab )
291 pViewShell->SetTabNo( nTab );
293 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
295 EndUndo();
298 void ScUndoOutlineLevel::Redo()
300 BeginRedo();
302 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
304 // sheet has to be switched on or off before this (#46952#) !!!
306 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
307 if ( nVisTab != nTab )
308 pViewShell->SetTabNo( nTab );
310 pViewShell->SelectLevel( bColumns, nLevel, false );
312 EndRedo();
315 void ScUndoOutlineLevel::Repeat(SfxRepeatTarget& rTarget)
317 if (rTarget.ISA(ScTabViewTarget))
318 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->SelectLevel( bColumns, nLevel, true );
321 bool ScUndoOutlineLevel::CanRepeat(SfxRepeatTarget& rTarget) const
323 return rTarget.ISA(ScTabViewTarget);
326 /** show/hide outline over block marks */
327 ScUndoOutlineBlock::ScUndoOutlineBlock( ScDocShell* pNewDocShell,
328 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
329 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
330 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab, bool bNewShow ) :
331 ScSimpleUndo( pNewDocShell ),
332 aBlockStart( nStartX, nStartY, nStartZ ),
333 aBlockEnd( nEndX, nEndY, nEndZ ),
334 pUndoDoc( pNewUndoDoc ),
335 pUndoTable( pNewUndoTab ),
336 bShow( bNewShow )
340 ScUndoOutlineBlock::~ScUndoOutlineBlock()
342 delete pUndoDoc;
343 delete pUndoTable;
346 OUString ScUndoOutlineBlock::GetComment() const
347 { // "Show outline" "Hide outline"
348 return bShow ?
349 ScGlobal::GetRscString( STR_UNDO_DOOUTLINEBLK ) :
350 ScGlobal::GetRscString( STR_UNDO_REDOOUTLINEBLK );
353 void ScUndoOutlineBlock::Undo()
355 BeginUndo();
357 ScDocument& rDoc = pDocShell->GetDocument();
358 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
359 SCTAB nTab = aBlockStart.Tab();
361 // Original Outline table
362 rDoc.SetOutlineTable( nTab, pUndoTable );
364 // Original column/row status
365 SCCOLROW nStartCol = aBlockStart.Col();
366 SCCOLROW nEndCol = aBlockEnd.Col();
367 SCCOLROW nStartRow = aBlockStart.Row();
368 SCCOLROW nEndRow = aBlockEnd.Row();
370 if (!bShow)
371 { // Size of the hidden blocks
372 size_t nLevel;
373 pUndoTable->GetColArray().FindTouchedLevel( nStartCol, nEndCol, nLevel );
374 pUndoTable->GetColArray().ExtendBlock( nLevel, nStartCol, nEndCol );
375 pUndoTable->GetRowArray().FindTouchedLevel( nStartRow, nEndRow, nLevel );
376 pUndoTable->GetRowArray().ExtendBlock( nLevel, nStartRow, nEndRow );
379 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
380 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false, &rDoc );
381 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, &rDoc );
383 rDoc.UpdatePageBreaks( nTab );
385 pViewShell->UpdateScrollBars();
387 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
388 if ( nVisTab != nTab )
389 pViewShell->SetTabNo( nTab );
391 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
393 EndUndo();
396 void ScUndoOutlineBlock::Redo()
398 BeginRedo();
400 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
402 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
403 if (bShow)
404 pViewShell->ShowMarkedOutlines( false );
405 else
406 pViewShell->HideMarkedOutlines( false );
408 EndRedo();
411 void ScUndoOutlineBlock::Repeat(SfxRepeatTarget& rTarget)
413 if (rTarget.ISA(ScTabViewTarget))
415 ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
417 if (bShow)
418 rViewShell.ShowMarkedOutlines( true );
419 else
420 rViewShell.HideMarkedOutlines( true );
424 bool ScUndoOutlineBlock::CanRepeat(SfxRepeatTarget& rTarget) const
426 return rTarget.ISA(ScTabViewTarget);
429 ScUndoRemoveAllOutlines::ScUndoRemoveAllOutlines( ScDocShell* pNewDocShell,
430 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
431 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
432 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
433 ScSimpleUndo( pNewDocShell ),
434 aBlockStart( nStartX, nStartY, nStartZ ),
435 aBlockEnd( nEndX, nEndY, nEndZ ),
436 pUndoDoc( pNewUndoDoc ),
437 pUndoTable( pNewUndoTab )
441 ScUndoRemoveAllOutlines::~ScUndoRemoveAllOutlines()
443 delete pUndoDoc;
444 delete pUndoTable;
447 OUString ScUndoRemoveAllOutlines::GetComment() const
448 { // "Remove outlines"
449 return ScGlobal::GetRscString( STR_UNDO_REMOVEALLOTLNS );
452 void ScUndoRemoveAllOutlines::Undo()
454 BeginUndo();
456 ScDocument& rDoc = pDocShell->GetDocument();
457 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
458 SCTAB nTab = aBlockStart.Tab();
460 // Original Outline table
461 rDoc.SetOutlineTable( nTab, pUndoTable );
463 // Original column/row status
464 SCCOL nStartCol = aBlockStart.Col();
465 SCCOL nEndCol = aBlockEnd.Col();
466 SCROW nStartRow = aBlockStart.Row();
467 SCROW nEndRow = aBlockEnd.Row();
469 pUndoDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, false, &rDoc );
470 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, &rDoc );
472 rDoc.UpdatePageBreaks( nTab );
474 pViewShell->UpdateScrollBars();
476 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
477 if ( nVisTab != nTab )
478 pViewShell->SetTabNo( nTab );
480 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
482 EndUndo();
485 void ScUndoRemoveAllOutlines::Redo()
487 BeginRedo();
489 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
491 // sheet has to be switched over (#46952#)!
493 SCTAB nTab = aBlockStart.Tab();
494 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
495 if ( nVisTab != nTab )
496 pViewShell->SetTabNo( nTab );
498 pViewShell->RemoveAllOutlines( false );
500 EndRedo();
503 void ScUndoRemoveAllOutlines::Repeat(SfxRepeatTarget& rTarget)
505 if (rTarget.ISA(ScTabViewTarget))
506 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->RemoveAllOutlines( true );
509 bool ScUndoRemoveAllOutlines::CanRepeat(SfxRepeatTarget& rTarget) const
511 return rTarget.ISA(ScTabViewTarget);
514 ScUndoAutoOutline::ScUndoAutoOutline( ScDocShell* pNewDocShell,
515 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
516 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
517 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
518 ScSimpleUndo( pNewDocShell ),
519 aBlockStart( nStartX, nStartY, nStartZ ),
520 aBlockEnd( nEndX, nEndY, nEndZ ),
521 pUndoDoc( pNewUndoDoc ),
522 pUndoTable( pNewUndoTab )
526 ScUndoAutoOutline::~ScUndoAutoOutline()
528 delete pUndoDoc;
529 delete pUndoTable;
532 OUString ScUndoAutoOutline::GetComment() const
534 return ScGlobal::GetRscString( STR_UNDO_AUTOOUTLINE );
537 void ScUndoAutoOutline::Undo()
539 BeginUndo();
541 ScDocument& rDoc = pDocShell->GetDocument();
542 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
543 SCTAB nTab = aBlockStart.Tab();
545 // Original outline table
546 rDoc.SetOutlineTable( nTab, pUndoTable );
548 // Original column/row status
549 if (pUndoDoc && pUndoTable)
551 SCCOLROW nStartCol;
552 SCCOLROW nStartRow;
553 SCCOLROW nEndCol;
554 SCCOLROW nEndRow;
555 pUndoTable->GetColArray().GetRange( nStartCol, nEndCol );
556 pUndoTable->GetRowArray().GetRange( nStartRow, nEndRow );
558 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
559 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false,
560 &rDoc);
561 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, &rDoc );
563 pViewShell->UpdateScrollBars();
566 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
567 if ( nVisTab != nTab )
568 pViewShell->SetTabNo( nTab );
570 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
572 EndUndo();
575 void ScUndoAutoOutline::Redo()
577 BeginRedo();
579 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
581 SCTAB nTab = aBlockStart.Tab();
582 if (pViewShell)
584 // sheet has to be switched on or off before this (#46952#) !!!
586 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
587 if ( nVisTab != nTab )
588 pViewShell->SetTabNo( nTab );
591 ScRange aRange( aBlockStart.Col(), aBlockStart.Row(), nTab,
592 aBlockEnd.Col(), aBlockEnd.Row(), nTab );
593 ScOutlineDocFunc aFunc( *pDocShell );
594 aFunc.AutoOutline( aRange, false );
596 // Select in View
597 // If it was called with a multi selection,
598 // then this is now the enclosing range...
600 if (pViewShell)
601 pViewShell->MarkRange( aRange );
603 EndRedo();
606 void ScUndoAutoOutline::Repeat(SfxRepeatTarget& rTarget)
608 if (rTarget.ISA(ScTabViewTarget))
609 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->AutoOutline( true );
612 bool ScUndoAutoOutline::CanRepeat(SfxRepeatTarget& rTarget) const
614 return rTarget.ISA(ScTabViewTarget);
617 ScUndoSubTotals::ScUndoSubTotals( ScDocShell* pNewDocShell, SCTAB nNewTab,
618 const ScSubTotalParam& rNewParam, SCROW nNewEndY,
619 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
620 ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB ) :
621 ScDBFuncUndo( pNewDocShell, ScRange( rNewParam.nCol1, rNewParam.nRow1, nNewTab,
622 rNewParam.nCol2, rNewParam.nRow2, nNewTab ) ),
623 nTab( nNewTab ),
624 aParam( rNewParam ),
625 nNewEndRow( nNewEndY ),
626 pUndoDoc( pNewUndoDoc ),
627 pUndoTable( pNewUndoTab ),
628 pUndoRange( pNewUndoRange ),
629 pUndoDB( pNewUndoDB )
633 ScUndoSubTotals::~ScUndoSubTotals()
635 delete pUndoDoc;
636 delete pUndoTable;
637 delete pUndoRange;
638 delete pUndoDB;
641 OUString ScUndoSubTotals::GetComment() const
642 { // "Subtotals"
643 return ScGlobal::GetRscString( STR_UNDO_SUBTOTALS );
646 void ScUndoSubTotals::Undo()
648 BeginUndo();
650 ScDocument& rDoc = pDocShell->GetDocument();
651 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
653 if (nNewEndRow > aParam.nRow2)
655 rDoc.DeleteRow( 0,nTab, MAXCOL,nTab, aParam.nRow2+1, static_cast<SCSIZE>(nNewEndRow-aParam.nRow2) );
657 else if (nNewEndRow < aParam.nRow2)
659 rDoc.InsertRow( 0,nTab, MAXCOL,nTab, nNewEndRow+1, static_cast<SCSIZE>(aParam.nRow2-nNewEndRow) );
662 // Original Outline table
663 rDoc.SetOutlineTable( nTab, pUndoTable );
665 // Original column/row status
666 if (pUndoTable)
668 SCCOLROW nStartCol;
669 SCCOLROW nStartRow;
670 SCCOLROW nEndCol;
671 SCCOLROW nEndRow;
672 pUndoTable->GetColArray().GetRange( nStartCol, nEndCol );
673 pUndoTable->GetRowArray().GetRange( nStartRow, nEndRow );
675 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
676 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false,
677 &rDoc);
678 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, &rDoc );
680 pViewShell->UpdateScrollBars();
683 // Original data and references
685 ScUndoUtil::MarkSimpleBlock( pDocShell, 0, aParam.nRow1+1, nTab,
686 MAXCOL, aParam.nRow2, nTab );
688 rDoc.DeleteAreaTab( 0,aParam.nRow1+1, MAXCOL,aParam.nRow2, nTab, IDF_ALL );
690 pUndoDoc->CopyToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
691 IDF_NONE, false, &rDoc ); // Flags
692 pUndoDoc->UndoToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
693 IDF_ALL, false, &rDoc );
695 ScUndoUtil::MarkSimpleBlock( pDocShell, aParam.nCol1,aParam.nRow1,nTab,
696 aParam.nCol2,aParam.nRow2,nTab );
698 if (pUndoRange)
699 rDoc.SetRangeName( new ScRangeName( *pUndoRange ) );
700 if (pUndoDB)
701 rDoc.SetDBCollection( new ScDBCollection( *pUndoDB ), true );
703 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
704 if ( nVisTab != nTab )
705 pViewShell->SetTabNo( nTab );
707 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
708 pDocShell->PostDataChanged();
710 EndUndo();
713 void ScUndoSubTotals::Redo()
715 BeginRedo();
717 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
719 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
720 if ( nVisTab != nTab )
721 pViewShell->SetTabNo( nTab );
723 ScUndoUtil::MarkSimpleBlock( pDocShell, aParam.nCol1,aParam.nRow1,nTab,
724 aParam.nCol2,aParam.nRow2,nTab );
725 pViewShell->DoSubTotals( aParam, false );
727 EndRedo();
730 void ScUndoSubTotals::Repeat(SfxRepeatTarget& /* rTarget */)
734 bool ScUndoSubTotals::CanRepeat(SfxRepeatTarget& /* rTarget */) const
736 return false; // is not possible due to column numbers
739 ScUndoQuery::ScUndoQuery( ScDocShell* pNewDocShell, SCTAB nNewTab, const ScQueryParam& rParam,
740 ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB,
741 const ScRange* pOld, bool bSize, const ScRange* pAdvSrc ) :
742 ScDBFuncUndo( pNewDocShell, ScRange( rParam.nCol1, rParam.nRow1, nNewTab,
743 rParam.nCol2, rParam.nRow2, nNewTab ) ),
744 pDrawUndo( NULL ),
745 nTab( nNewTab ),
746 aQueryParam( rParam ),
747 pUndoDoc( pNewUndoDoc ),
748 pUndoDB( pNewUndoDB ),
749 bIsAdvanced( false ),
750 bDestArea( false ),
751 bDoSize( bSize )
753 if ( pOld )
755 bDestArea = true;
756 aOldDest = *pOld;
758 if ( pAdvSrc )
760 bIsAdvanced = true;
761 aAdvSource = *pAdvSrc;
764 pDrawUndo = GetSdrUndoAction( &pDocShell->GetDocument() );
767 ScUndoQuery::~ScUndoQuery()
769 delete pUndoDoc;
770 delete pUndoDB;
771 DeleteSdrUndoAction( pDrawUndo );
774 OUString ScUndoQuery::GetComment() const
775 { // "Filter";
776 return ScGlobal::GetRscString( STR_UNDO_QUERY );
779 void ScUndoQuery::Undo()
781 BeginUndo();
783 ScDocument& rDoc = pDocShell->GetDocument();
784 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
786 bool bCopy = !aQueryParam.bInplace;
787 SCCOL nDestEndCol = 0;
788 SCROW nDestEndRow = 0;
789 if (bCopy)
791 nDestEndCol = aQueryParam.nDestCol + ( aQueryParam.nCol2-aQueryParam.nCol1 );
792 nDestEndRow = aQueryParam.nDestRow + ( aQueryParam.nRow2-aQueryParam.nRow1 );
794 ScDBData* pData = rDoc.GetDBAtCursor( aQueryParam.nDestCol, aQueryParam.nDestRow,
795 aQueryParam.nDestTab, true );
796 if (pData)
798 ScRange aNewDest;
799 pData->GetArea( aNewDest );
800 nDestEndCol = aNewDest.aEnd.Col();
801 nDestEndRow = aNewDest.aEnd.Row();
804 if ( bDoSize && bDestArea )
806 // aDestRange is the old range
807 rDoc.FitBlock( ScRange(
808 aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
809 nDestEndCol, nDestEndRow, aQueryParam.nDestTab ),
810 aOldDest );
813 ScUndoUtil::MarkSimpleBlock( pDocShell,
814 aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
815 nDestEndCol, nDestEndRow, aQueryParam.nDestTab );
816 rDoc.DeleteAreaTab( aQueryParam.nDestCol, aQueryParam.nDestRow,
817 nDestEndCol, nDestEndRow, aQueryParam.nDestTab, IDF_ALL );
819 pViewShell->DoneBlockMode();
821 pUndoDoc->CopyToDocument( aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
822 nDestEndCol, nDestEndRow, aQueryParam.nDestTab,
823 IDF_ALL, false, &rDoc );
824 // Attributes are always copied (#49287#)
826 // rest of the old range
827 if ( bDestArea && !bDoSize )
829 rDoc.DeleteAreaTab( aOldDest, IDF_ALL );
830 pUndoDoc->CopyToDocument( aOldDest, IDF_ALL, false, &rDoc );
833 else
834 pUndoDoc->CopyToDocument( 0, aQueryParam.nRow1, nTab, MAXCOL, aQueryParam.nRow2, nTab,
835 IDF_NONE, false, &rDoc );
837 if (pUndoDB)
838 rDoc.SetDBCollection( new ScDBCollection( *pUndoDB ), true );
840 if (!bCopy)
842 rDoc.InvalidatePageBreaks(nTab);
843 rDoc.UpdatePageBreaks( nTab );
846 ScRange aDirtyRange( 0 , aQueryParam.nRow1, nTab,
847 MAXCOL, aQueryParam.nRow2, nTab );
848 rDoc.SetDirty( aDirtyRange, true );
850 DoSdrUndoAction( pDrawUndo, &rDoc );
852 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
853 if ( nVisTab != nTab )
854 pViewShell->SetTabNo( nTab );
856 // Paint
858 if (bCopy)
860 SCCOL nEndX = nDestEndCol;
861 SCROW nEndY = nDestEndRow;
862 if (bDestArea)
864 if ( aOldDest.aEnd.Col() > nEndX )
865 nEndX = aOldDest.aEnd.Col();
866 if ( aOldDest.aEnd.Row() > nEndY )
867 nEndY = aOldDest.aEnd.Row();
869 if (bDoSize)
870 nEndY = MAXROW;
871 pDocShell->PostPaint( aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
872 nEndX, nEndY, aQueryParam.nDestTab, PAINT_GRID );
874 else
875 pDocShell->PostPaint( 0, aQueryParam.nRow1, nTab, MAXCOL, MAXROW, nTab,
876 PAINT_GRID | PAINT_LEFT );
877 pDocShell->PostDataChanged();
879 EndUndo();
882 void ScUndoQuery::Redo()
884 BeginRedo();
886 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
888 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
889 if ( nVisTab != nTab )
890 pViewShell->SetTabNo( nTab );
892 if ( bIsAdvanced )
893 pViewShell->Query( aQueryParam, &aAdvSource, false );
894 else
895 pViewShell->Query( aQueryParam, NULL, false );
897 EndRedo();
900 void ScUndoQuery::Repeat(SfxRepeatTarget& /* rTarget */)
904 bool ScUndoQuery::CanRepeat(SfxRepeatTarget& /* rTarget */) const
906 return false; // does not work due to column numbers
909 // Show or hide AutoFilter buttons (doesn't include filter settings)
911 ScUndoAutoFilter::ScUndoAutoFilter( ScDocShell* pNewDocShell, const ScRange& rRange,
912 const OUString& rName, bool bSet ) :
913 ScDBFuncUndo( pNewDocShell, rRange ),
914 aDBName( rName ),
915 bFilterSet( bSet )
919 ScUndoAutoFilter::~ScUndoAutoFilter()
923 OUString ScUndoAutoFilter::GetComment() const
925 return ScGlobal::GetRscString( STR_UNDO_QUERY ); // same as ScUndoQuery
928 void ScUndoAutoFilter::DoChange( bool bUndo )
930 bool bNewFilter = bUndo ? !bFilterSet : bFilterSet;
932 ScDocument& rDoc = pDocShell->GetDocument();
933 ScDBData* pDBData=NULL;
934 if (aDBName == STR_DB_LOCAL_NONAME)
936 SCTAB nTab = aOriginalRange.aStart.Tab();
937 pDBData = rDoc.GetAnonymousDBData(nTab);
939 else
941 ScDBCollection* pColl = rDoc.GetDBCollection();
942 pDBData = pColl->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(aDBName));
945 if ( pDBData )
947 pDBData->SetAutoFilter( bNewFilter );
949 SCCOL nRangeX1;
950 SCROW nRangeY1;
951 SCCOL nRangeX2;
952 SCROW nRangeY2;
953 SCTAB nRangeTab;
954 pDBData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
956 if ( bNewFilter )
957 rDoc.ApplyFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
958 else
959 rDoc.RemoveFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
961 pDocShell->PostPaint( nRangeX1, nRangeY1, nRangeTab, nRangeX2, nRangeY1, nRangeTab, PAINT_GRID );
965 void ScUndoAutoFilter::Undo()
967 BeginUndo();
968 DoChange( true );
969 EndUndo();
972 void ScUndoAutoFilter::Redo()
974 BeginRedo();
975 DoChange( false );
976 EndRedo();
979 void ScUndoAutoFilter::Repeat(SfxRepeatTarget& /* rTarget */)
983 bool ScUndoAutoFilter::CanRepeat(SfxRepeatTarget& /* rTarget */) const
985 return false;
988 // change database sections (dialog)
989 ScUndoDBData::ScUndoDBData( ScDocShell* pNewDocShell,
990 ScDBCollection* pNewUndoColl, ScDBCollection* pNewRedoColl ) :
991 ScSimpleUndo( pNewDocShell ),
992 pUndoColl( pNewUndoColl ),
993 pRedoColl( pNewRedoColl )
997 ScUndoDBData::~ScUndoDBData()
999 delete pUndoColl;
1000 delete pRedoColl;
1003 OUString ScUndoDBData::GetComment() const
1004 { // "Change database range";
1005 return ScGlobal::GetRscString( STR_UNDO_DBDATA );
1008 void ScUndoDBData::Undo()
1010 BeginUndo();
1012 ScDocument& rDoc = pDocShell->GetDocument();
1014 bool bOldAutoCalc = rDoc.GetAutoCalc();
1015 rDoc.SetAutoCalc( false ); // Avoid unnecessary calculations
1016 rDoc.PreprocessDBDataUpdate();
1017 rDoc.SetDBCollection( new ScDBCollection(*pUndoColl), true );
1018 rDoc.CompileHybridFormula();
1019 rDoc.SetAutoCalc( bOldAutoCalc );
1021 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
1023 EndUndo();
1026 void ScUndoDBData::Redo()
1028 BeginRedo();
1030 ScDocument& rDoc = pDocShell->GetDocument();
1032 bool bOldAutoCalc = rDoc.GetAutoCalc();
1033 rDoc.SetAutoCalc( false ); // Avoid unnecessary calculations
1034 rDoc.PreprocessDBDataUpdate();
1035 rDoc.SetDBCollection( new ScDBCollection(*pRedoColl), true );
1036 rDoc.CompileHybridFormula();
1037 rDoc.SetAutoCalc( bOldAutoCalc );
1039 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
1041 EndRedo();
1044 void ScUndoDBData::Repeat(SfxRepeatTarget& /* rTarget */)
1048 bool ScUndoDBData::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1050 return false; // is not possible
1053 ScUndoImportData::ScUndoImportData( ScDocShell* pNewDocShell, SCTAB nNewTab,
1054 const ScImportParam& rParam, SCCOL nNewEndX, SCROW nNewEndY,
1055 SCCOL nNewFormula,
1056 ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
1057 ScDBData* pNewUndoData, ScDBData* pNewRedoData ) :
1058 ScSimpleUndo( pNewDocShell ),
1059 nTab( nNewTab ),
1060 aImportParam( rParam ),
1061 nEndCol( nNewEndX ),
1062 nEndRow( nNewEndY ),
1063 pUndoDoc( pNewUndoDoc ),
1064 pRedoDoc( pNewRedoDoc ),
1065 pUndoDBData( pNewUndoData ),
1066 pRedoDBData( pNewRedoData ),
1067 nFormulaCols( nNewFormula ),
1068 bRedoFilled( false )
1070 // redo doc doesn't contain imported data (but everything else)
1073 ScUndoImportData::~ScUndoImportData()
1075 delete pUndoDoc;
1076 delete pRedoDoc;
1077 delete pUndoDBData;
1078 delete pRedoDBData;
1081 OUString ScUndoImportData::GetComment() const
1083 return ScGlobal::GetRscString( STR_UNDO_IMPORTDATA );
1086 void ScUndoImportData::Undo()
1088 BeginUndo();
1090 ScDocument& rDoc = pDocShell->GetDocument();
1091 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1093 ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab,
1094 nEndCol,nEndRow,nTab );
1096 SCTAB nTable;
1097 SCCOL nCol1, nCol2;
1098 SCROW nRow1, nRow2;
1099 ScDBData* pCurrentData = NULL;
1100 if (pUndoDBData && pRedoDBData)
1102 pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1103 pCurrentData = ScUndoUtil::GetOldDBData( pRedoDBData, &rDoc, nTab,
1104 nCol1, nRow1, nCol2, nRow2 );
1106 if ( !bRedoFilled )
1108 // read redo data from document at first undo
1109 // imported data is deleted later anyway,
1110 // so now delete each column after copying to save memory (#41216#)
1112 bool bOldAutoCalc = rDoc.GetAutoCalc();
1113 rDoc.SetAutoCalc( false ); // outside of the loop
1114 for (SCCOL nCopyCol = nCol1; nCopyCol <= nCol2; nCopyCol++)
1116 rDoc.CopyToDocument( nCopyCol,nRow1,nTab, nCopyCol,nRow2,nTab,
1117 IDF_CONTENTS & ~IDF_NOTE, false, pRedoDoc );
1118 rDoc.DeleteAreaTab( nCopyCol,nRow1, nCopyCol,nRow2, nTab, IDF_CONTENTS & ~IDF_NOTE );
1120 rDoc.SetAutoCalc( bOldAutoCalc );
1121 bRedoFilled = true;
1124 bool bMoveCells = pUndoDBData && pRedoDBData &&
1125 pRedoDBData->IsDoSize(); // the same in old and new
1126 if (bMoveCells)
1128 // Undo: first delete the new data, then FitBlock backwards
1130 ScRange aOld, aNew;
1131 pUndoDBData->GetArea( aOld );
1132 pRedoDBData->GetArea( aNew );
1134 rDoc.DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
1135 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, IDF_ALL & ~IDF_NOTE );
1137 aOld.aEnd.SetCol( aOld.aEnd.Col() + nFormulaCols ); // FitBlock also for formulas
1138 aNew.aEnd.SetCol( aNew.aEnd.Col() + nFormulaCols );
1139 rDoc.FitBlock( aNew, aOld, false ); // backwards
1141 else
1142 rDoc.DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
1143 nEndCol,nEndRow, nTab, IDF_ALL & ~IDF_NOTE );
1145 pUndoDoc->CopyToDocument( aImportParam.nCol1,aImportParam.nRow1,nTab,
1146 nEndCol+nFormulaCols,nEndRow,nTab,
1147 IDF_ALL & ~IDF_NOTE, false, &rDoc );
1149 if (pCurrentData)
1151 *pCurrentData = *pUndoDBData;
1153 pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1154 ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
1157 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
1158 if ( nVisTab != nTab )
1159 pViewShell->SetTabNo( nTab );
1161 if (bMoveCells)
1162 pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
1163 else
1164 pDocShell->PostPaint( aImportParam.nCol1,aImportParam.nRow1,nTab,
1165 nEndCol,nEndRow,nTab, PAINT_GRID );
1166 pDocShell->PostDataChanged();
1168 EndUndo();
1171 void ScUndoImportData::Redo()
1173 BeginRedo();
1175 ScDocument& rDoc = pDocShell->GetDocument();
1176 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1178 ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab,
1179 nEndCol,nEndRow,nTab );
1181 SCTAB nTable;
1182 SCCOL nCol1, nCol2;
1183 SCROW nRow1, nRow2;
1184 ScDBData* pCurrentData = NULL;
1185 if (pUndoDBData && pRedoDBData)
1187 pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1188 pCurrentData = ScUndoUtil::GetOldDBData( pUndoDBData, &rDoc, nTab,
1189 nCol1, nRow1, nCol2, nRow2 );
1191 bool bMoveCells = pUndoDBData && pRedoDBData &&
1192 pRedoDBData->IsDoSize(); // // the same in old and new
1193 if (bMoveCells)
1195 // Redo: FitBlock, then delete data (needed for CopyToDocument)
1197 ScRange aOld, aNew;
1198 pUndoDBData->GetArea( aOld );
1199 pRedoDBData->GetArea( aNew );
1201 aOld.aEnd.SetCol( aOld.aEnd.Col() + nFormulaCols ); // FitBlock also for formulas
1202 aNew.aEnd.SetCol( aNew.aEnd.Col() + nFormulaCols );
1203 rDoc.FitBlock( aOld, aNew );
1205 rDoc.DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
1206 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, IDF_ALL & ~IDF_NOTE );
1208 pRedoDoc->CopyToDocument( aNew, IDF_ALL & ~IDF_NOTE, false, &rDoc ); // including formulas
1210 else
1212 rDoc.DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
1213 nEndCol,nEndRow, nTab, IDF_ALL & ~IDF_NOTE );
1214 pRedoDoc->CopyToDocument( aImportParam.nCol1,aImportParam.nRow1,nTab,
1215 nEndCol,nEndRow,nTab, IDF_ALL & ~IDF_NOTE, false, &rDoc );
1218 if (pCurrentData)
1220 *pCurrentData = *pRedoDBData;
1222 pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1223 ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
1226 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
1227 if ( nVisTab != nTab )
1228 pViewShell->SetTabNo( nTab );
1230 if (bMoveCells)
1231 pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
1232 else
1233 pDocShell->PostPaint( aImportParam.nCol1,aImportParam.nRow1,nTab,
1234 nEndCol,nEndRow,nTab, PAINT_GRID );
1235 pDocShell->PostDataChanged();
1237 EndRedo();
1240 void ScUndoImportData::Repeat(SfxRepeatTarget& rTarget)
1242 if (rTarget.ISA(ScTabViewTarget))
1244 ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
1246 SCTAB nDummy;
1247 ScImportParam aNewParam(aImportParam);
1248 ScDBData* pDBData = rViewShell.GetDBData();
1249 pDBData->GetArea( nDummy, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
1251 rViewShell.ImportData( aNewParam );
1255 bool ScUndoImportData::CanRepeat(SfxRepeatTarget& rTarget) const
1257 // Repeat only for import using a database range, then pUndoDBData is set
1259 if (pUndoDBData)
1260 return rTarget.ISA(ScTabViewTarget);
1261 else
1262 return false; // Address book
1265 ScUndoRepeatDB::ScUndoRepeatDB( ScDocShell* pNewDocShell, SCTAB nNewTab,
1266 SCCOL nStartX, SCROW nStartY, SCCOL nEndX, SCROW nEndY,
1267 SCROW nResultEndRow, SCCOL nCurX, SCROW nCurY,
1268 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
1269 ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB,
1270 const ScRange* pOldQ, const ScRange* pNewQ ) :
1271 ScSimpleUndo( pNewDocShell ),
1272 aBlockStart( nStartX,nStartY,nNewTab ),
1273 aBlockEnd( nEndX,nEndY,nNewTab ),
1274 nNewEndRow( nResultEndRow ),
1275 aCursorPos( nCurX,nCurY,nNewTab ),
1276 pUndoDoc( pNewUndoDoc ),
1277 pUndoTable( pNewUndoTab ),
1278 pUndoRange( pNewUndoRange ),
1279 pUndoDB( pNewUndoDB ),
1280 bQuerySize( false )
1282 if ( pOldQ && pNewQ )
1284 aOldQuery = *pOldQ;
1285 aNewQuery = *pNewQ;
1286 bQuerySize = true;
1290 ScUndoRepeatDB::~ScUndoRepeatDB()
1292 delete pUndoDoc;
1293 delete pUndoTable;
1294 delete pUndoRange;
1295 delete pUndoDB;
1298 OUString ScUndoRepeatDB::GetComment() const
1300 return ScGlobal::GetRscString( STR_UNDO_REPEATDB );
1303 void ScUndoRepeatDB::Undo()
1305 BeginUndo();
1307 ScDocument& rDoc = pDocShell->GetDocument();
1308 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1309 SCTAB nTab = aBlockStart.Tab();
1311 if (bQuerySize)
1313 rDoc.FitBlock( aNewQuery, aOldQuery, false );
1315 if ( aNewQuery.aEnd.Col() == aOldQuery.aEnd.Col() )
1317 SCCOL nFormulaCols = 0;
1318 SCCOL nCol = aOldQuery.aEnd.Col() + 1;
1319 SCROW nRow = aOldQuery.aStart.Row() + 1; // test the header
1320 while ( nCol <= MAXCOL &&
1321 rDoc.GetCellType(ScAddress( nCol, nRow, nTab )) == CELLTYPE_FORMULA )
1322 ++nCol, ++nFormulaCols;
1324 if ( nFormulaCols > 0 )
1326 ScRange aOldForm = aOldQuery;
1327 aOldForm.aStart.SetCol( aOldQuery.aEnd.Col() + 1 );
1328 aOldForm.aEnd.SetCol( aOldQuery.aEnd.Col() + nFormulaCols );
1329 ScRange aNewForm = aOldForm;
1330 aNewForm.aEnd.SetRow( aNewQuery.aEnd.Row() );
1331 rDoc.FitBlock( aNewForm, aOldForm, false );
1336 // TODO Data from Filter in other range are still missing!
1338 if (nNewEndRow > aBlockEnd.Row())
1340 rDoc.DeleteRow( 0,nTab, MAXCOL,nTab, aBlockEnd.Row()+1, static_cast<SCSIZE>(nNewEndRow-aBlockEnd.Row()) );
1342 else if (nNewEndRow < aBlockEnd.Row())
1344 rDoc.InsertRow( 0,nTab, MAXCOL,nTab, nNewEndRow+1, static_cast<SCSIZE>(nNewEndRow-aBlockEnd.Row()) );
1347 // Original Outline table
1348 rDoc.SetOutlineTable( nTab, pUndoTable );
1350 // Original column/row status
1351 if (pUndoTable)
1353 SCCOLROW nStartCol;
1354 SCCOLROW nStartRow;
1355 SCCOLROW nEndCol;
1356 SCCOLROW nEndRow;
1357 pUndoTable->GetColArray().GetRange( nStartCol, nEndCol );
1358 pUndoTable->GetRowArray().GetRange( nStartRow, nEndRow );
1360 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
1361 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false,
1362 &rDoc );
1363 pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, &rDoc );
1365 pViewShell->UpdateScrollBars();
1368 // Original data and references
1369 ScUndoUtil::MarkSimpleBlock( pDocShell, 0, aBlockStart.Row(), nTab,
1370 MAXCOL, aBlockEnd.Row(), nTab );
1371 rDoc.DeleteAreaTab( 0, aBlockStart.Row(),
1372 MAXCOL, aBlockEnd.Row(), nTab, IDF_ALL );
1374 pUndoDoc->CopyToDocument( 0, aBlockStart.Row(), nTab, MAXCOL, aBlockEnd.Row(), nTab,
1375 IDF_NONE, false, &rDoc ); // Flags
1376 pUndoDoc->UndoToDocument( 0, aBlockStart.Row(), nTab, MAXCOL, aBlockEnd.Row(), nTab,
1377 IDF_ALL, false, &rDoc );
1379 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart.Col(),aBlockStart.Row(),nTab,
1380 aBlockEnd.Col(),aBlockEnd.Row(),nTab );
1382 if (pUndoRange)
1383 rDoc.SetRangeName( new ScRangeName( *pUndoRange ) );
1384 if (pUndoDB)
1385 rDoc.SetDBCollection( new ScDBCollection( *pUndoDB ), true );
1387 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
1388 if ( nVisTab != nTab )
1389 pViewShell->SetTabNo( nTab );
1391 pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
1392 pDocShell->PostDataChanged();
1394 EndUndo();
1397 void ScUndoRepeatDB::Redo()
1399 BeginRedo();
1401 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1402 SCTAB nTab = aBlockStart.Tab();
1404 SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
1405 if ( nVisTab != nTab )
1406 pViewShell->SetTabNo( nTab );
1408 ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart.Col(),aBlockStart.Row(),nTab,
1409 aBlockEnd.Col(),aBlockEnd.Row(),nTab );
1410 pViewShell->SetCursor( aCursorPos.Col(), aCursorPos.Row() );
1412 pViewShell->RepeatDB( false );
1414 EndRedo();
1417 void ScUndoRepeatDB::Repeat(SfxRepeatTarget& rTarget)
1419 if (rTarget.ISA(ScTabViewTarget))
1420 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->RepeatDB( true );
1423 bool ScUndoRepeatDB::CanRepeat(SfxRepeatTarget& rTarget) const
1425 return rTarget.ISA(ScTabViewTarget);
1428 ScUndoDataPilot::ScUndoDataPilot( ScDocShell* pNewDocShell,
1429 ScDocument* pOldDoc, ScDocument* pNewDoc,
1430 const ScDPObject* pOldObj, const ScDPObject* pNewObj, bool bMove ) :
1431 ScSimpleUndo( pNewDocShell ),
1432 pOldUndoDoc( pOldDoc ),
1433 pNewUndoDoc( pNewDoc ),
1434 pOldDPObject( NULL ),
1435 pNewDPObject( NULL ),
1436 bAllowMove( bMove )
1438 if (pOldObj)
1439 pOldDPObject = new ScDPObject( *pOldObj );
1440 if (pNewObj)
1441 pNewDPObject = new ScDPObject( *pNewObj );
1444 ScUndoDataPilot::~ScUndoDataPilot()
1446 delete pOldDPObject;
1447 delete pNewDPObject;
1448 delete pOldUndoDoc;
1449 delete pNewUndoDoc;
1452 OUString ScUndoDataPilot::GetComment() const
1454 sal_uInt16 nIndex;
1455 if ( pOldUndoDoc && pNewUndoDoc )
1456 nIndex = STR_UNDO_PIVOT_MODIFY;
1457 else if ( pNewUndoDoc )
1458 nIndex = STR_UNDO_PIVOT_NEW;
1459 else
1460 nIndex = STR_UNDO_PIVOT_DELETE;
1462 return ScGlobal::GetRscString( nIndex );
1465 void ScUndoDataPilot::Undo()
1467 BeginUndo();
1469 ScDocument& rDoc = pDocShell->GetDocument();
1471 ScRange aOldRange;
1472 ScRange aNewRange;
1474 if ( pNewDPObject && pNewUndoDoc )
1476 aNewRange = pNewDPObject->GetOutRange();
1477 rDoc.DeleteAreaTab( aNewRange, IDF_ALL );
1478 pNewUndoDoc->CopyToDocument( aNewRange, IDF_ALL, false, &rDoc );
1480 if ( pOldDPObject && pOldUndoDoc )
1482 aOldRange = pOldDPObject->GetOutRange();
1483 rDoc.DeleteAreaTab( aOldRange, IDF_ALL );
1484 pOldUndoDoc->CopyToDocument( aOldRange, IDF_ALL, false, &rDoc );
1487 // update objects in collection
1489 if ( pNewDPObject )
1491 // find updated object
1492 //! find by name!
1494 ScDPObject* pDocObj = rDoc.GetDPAtCursor(
1495 aNewRange.aStart.Col(), aNewRange.aStart.Row(), aNewRange.aStart.Tab() );
1496 OSL_ENSURE(pDocObj, "DPObject not found");
1497 if (pDocObj)
1499 if ( pOldDPObject )
1501 // restore old settings
1502 pOldDPObject->WriteSourceDataTo( *pDocObj );
1503 ScDPSaveData* pData = pOldDPObject->GetSaveData();
1504 if (pData)
1505 pDocObj->SetSaveData(*pData);
1506 pDocObj->SetOutRange( pOldDPObject->GetOutRange() );
1507 pOldDPObject->WriteTempDataTo( *pDocObj );
1509 else
1511 // delete inserted object
1512 rDoc.GetDPCollection()->FreeTable(pDocObj);
1516 else if ( pOldDPObject )
1518 // re-insert deleted object
1520 ScDPObject* pDestObj = new ScDPObject( *pOldDPObject );
1521 if ( !rDoc.GetDPCollection()->InsertNewTable(pDestObj) )
1523 OSL_FAIL("cannot insert DPObject");
1524 DELETEZ( pDestObj );
1528 if (pNewUndoDoc)
1529 pDocShell->PostPaint( aNewRange, PAINT_GRID, SC_PF_LINES );
1530 if (pOldUndoDoc)
1531 pDocShell->PostPaint( aOldRange, PAINT_GRID, SC_PF_LINES );
1532 pDocShell->PostDataChanged();
1534 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1535 if (pViewShell)
1537 //! set current sheet
1540 if (pNewDPObject)
1542 // notify API objects
1543 rDoc.BroadcastUno( ScDataPilotModifiedHint( pNewDPObject->GetName() ) );
1546 EndUndo();
1549 void ScUndoDataPilot::Redo()
1551 BeginRedo();
1553 //! copy output data instead of repeating the change,
1554 //! in case external data have changed!
1556 ScDocument& rDoc = pDocShell->GetDocument();
1558 ScDPObject* pSourceObj = NULL;
1559 if ( pOldDPObject )
1561 // find object to modify
1562 //! find by name!
1564 ScRange aOldRange = pOldDPObject->GetOutRange();
1565 pSourceObj = rDoc.GetDPAtCursor(
1566 aOldRange.aStart.Col(), aOldRange.aStart.Row(), aOldRange.aStart.Tab() );
1567 OSL_ENSURE(pSourceObj, "DPObject not found");
1570 ScDBDocFunc aFunc( *pDocShell );
1571 aFunc.DataPilotUpdate( pSourceObj, pNewDPObject, false, false, bAllowMove ); // no new undo action
1573 EndRedo();
1576 void ScUndoDataPilot::Repeat(SfxRepeatTarget& /* rTarget */)
1578 //! allow deletion
1581 bool ScUndoDataPilot::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1583 //! allow deletion
1584 return false;
1587 ScUndoConsolidate::ScUndoConsolidate( ScDocShell* pNewDocShell, const ScArea& rArea,
1588 const ScConsolidateParam& rPar, ScDocument* pNewUndoDoc,
1589 bool bReference, SCROW nInsCount, ScOutlineTable* pTab,
1590 ScDBData* pData ) :
1591 ScSimpleUndo( pNewDocShell ),
1592 aDestArea( rArea ),
1593 pUndoDoc( pNewUndoDoc ),
1594 aParam( rPar ),
1595 bInsRef( bReference ),
1596 nInsertCount( nInsCount ),
1597 pUndoTab( pTab ),
1598 pUndoData( pData )
1602 ScUndoConsolidate::~ScUndoConsolidate()
1604 delete pUndoDoc;
1605 delete pUndoTab;
1606 delete pUndoData;
1609 OUString ScUndoConsolidate::GetComment() const
1611 return ScGlobal::GetRscString( STR_UNDO_CONSOLIDATE );
1614 void ScUndoConsolidate::Undo()
1616 BeginUndo();
1618 ScDocument& rDoc = pDocShell->GetDocument();
1619 SCTAB nTab = aDestArea.nTab;
1621 ScRange aOldRange;
1622 if (pUndoData)
1623 pUndoData->GetArea(aOldRange);
1625 if (bInsRef)
1627 rDoc.DeleteRow( 0,nTab, MAXCOL,nTab, aDestArea.nRowStart, nInsertCount );
1628 rDoc.SetOutlineTable( nTab, pUndoTab );
1630 // Row status
1631 pUndoDoc->CopyToDocument( 0,0,nTab, MAXCOL,MAXROW,nTab, IDF_NONE, false, &rDoc );
1633 // Data and references
1634 rDoc.DeleteAreaTab( 0,aDestArea.nRowStart, MAXCOL,aDestArea.nRowEnd, nTab, IDF_ALL );
1635 pUndoDoc->UndoToDocument( 0, aDestArea.nRowStart, nTab,
1636 MAXCOL, aDestArea.nRowEnd, nTab,
1637 IDF_ALL, false, &rDoc );
1639 // Original range
1640 if (pUndoData)
1642 rDoc.DeleteAreaTab(aOldRange, IDF_ALL);
1643 pUndoDoc->CopyToDocument(aOldRange, IDF_ALL, false, &rDoc);
1646 pDocShell->PostPaint( 0,aDestArea.nRowStart,nTab, MAXCOL,MAXROW,nTab,
1647 PAINT_GRID | PAINT_LEFT | PAINT_SIZE );
1649 else
1651 rDoc.DeleteAreaTab( aDestArea.nColStart,aDestArea.nRowStart,
1652 aDestArea.nColEnd,aDestArea.nRowEnd, nTab, IDF_ALL );
1653 pUndoDoc->CopyToDocument( aDestArea.nColStart, aDestArea.nRowStart, nTab,
1654 aDestArea.nColEnd, aDestArea.nRowEnd, nTab,
1655 IDF_ALL, false, &rDoc );
1657 // Original range
1658 if (pUndoData)
1660 rDoc.DeleteAreaTab(aOldRange, IDF_ALL);
1661 pUndoDoc->CopyToDocument(aOldRange, IDF_ALL, false, &rDoc);
1664 SCCOL nEndX = aDestArea.nColEnd;
1665 SCROW nEndY = aDestArea.nRowEnd;
1666 if ( pUndoData )
1668 if ( aOldRange.aEnd.Col() > nEndX )
1669 nEndX = aOldRange.aEnd.Col();
1670 if ( aOldRange.aEnd.Row() > nEndY )
1671 nEndY = aOldRange.aEnd.Row();
1673 pDocShell->PostPaint( aDestArea.nColStart, aDestArea.nRowStart, nTab,
1674 nEndX, nEndY, nTab, PAINT_GRID );
1677 // Adjust Database range again
1678 if (pUndoData)
1680 ScDBCollection* pColl = rDoc.GetDBCollection();
1681 if (pColl)
1683 ScDBData* pDocData = pColl->getNamedDBs().findByUpperName(pUndoData->GetUpperName());
1684 if (pDocData)
1685 *pDocData = *pUndoData;
1689 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1690 if (pViewShell)
1692 SCTAB nViewTab = pViewShell->GetViewData().GetTabNo();
1693 if ( nViewTab != nTab )
1694 pViewShell->SetTabNo( nTab );
1697 EndUndo();
1700 void ScUndoConsolidate::Redo()
1702 BeginRedo();
1704 pDocShell->DoConsolidate( aParam, false );
1706 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1707 if (pViewShell)
1709 SCTAB nViewTab = pViewShell->GetViewData().GetTabNo();
1710 if ( nViewTab != aParam.nTab )
1711 pViewShell->SetTabNo( aParam.nTab );
1714 EndRedo();
1717 void ScUndoConsolidate::Repeat(SfxRepeatTarget& /* rTarget */)
1721 bool ScUndoConsolidate::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1723 return false;
1726 // Change source data of Chart
1727 void ScUndoChartData::Init()
1729 ScDocument& rDoc = pDocShell->GetDocument();
1730 aOldRangeListRef = new ScRangeList;
1731 rDoc.GetOldChartParameters( aChartName, *aOldRangeListRef, bOldColHeaders, bOldRowHeaders );
1734 ScUndoChartData::ScUndoChartData( ScDocShell* pNewDocShell, const OUString& rName,
1735 const ScRange& rNew, bool bColHdr, bool bRowHdr,
1736 bool bAdd ) :
1737 ScSimpleUndo( pNewDocShell ),
1738 aChartName( rName ),
1739 bNewColHeaders( bColHdr ),
1740 bNewRowHeaders( bRowHdr ),
1741 bAddRange( bAdd )
1743 aNewRangeListRef = new ScRangeList;
1744 aNewRangeListRef->Append( rNew );
1746 Init();
1749 ScUndoChartData::ScUndoChartData( ScDocShell* pNewDocShell, const OUString& rName,
1750 const ScRangeListRef& rNew, bool bColHdr, bool bRowHdr,
1751 bool bAdd ) :
1752 ScSimpleUndo( pNewDocShell ),
1753 aChartName( rName ),
1754 aNewRangeListRef( rNew ),
1755 bNewColHeaders( bColHdr ),
1756 bNewRowHeaders( bRowHdr ),
1757 bAddRange( bAdd )
1759 Init();
1762 ScUndoChartData::~ScUndoChartData()
1766 OUString ScUndoChartData::GetComment() const
1768 return ScGlobal::GetRscString( STR_UNDO_CHARTDATA );
1771 void ScUndoChartData::Undo()
1773 BeginUndo();
1775 pDocShell->GetDocument().UpdateChartArea( aChartName, aOldRangeListRef,
1776 bOldColHeaders, bOldRowHeaders, false );
1778 EndUndo();
1781 void ScUndoChartData::Redo()
1783 BeginRedo();
1785 pDocShell->GetDocument().UpdateChartArea( aChartName, aNewRangeListRef,
1786 bNewColHeaders, bNewRowHeaders, bAddRange );
1788 EndRedo();
1791 void ScUndoChartData::Repeat(SfxRepeatTarget& /* rTarget */)
1795 bool ScUndoChartData::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1797 return false;
1800 ScUndoDataForm::ScUndoDataForm( ScDocShell* pNewDocShell,
1801 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
1802 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
1803 const ScMarkData& rMark,
1804 ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
1805 InsertDeleteFlags nNewFlags,
1806 ScRefUndoData* pRefData,
1807 void* /*pFill1*/, void* /*pFill2*/, void* /*pFill3*/,
1808 bool bRedoIsFilled ) :
1809 ScBlockUndo( pNewDocShell, ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ), SC_UNDO_SIMPLE ),
1810 mpMarkData(new ScMarkData(rMark)),
1811 pUndoDoc( pNewUndoDoc ),
1812 pRedoDoc( pNewRedoDoc ),
1813 nFlags( nNewFlags ),
1814 pRefUndoData( pRefData ),
1815 pRefRedoData( NULL ),
1816 bRedoFilled( bRedoIsFilled )
1818 // pFill1,pFill2,pFill3 are there so the ctor calls for simple paste (without cutting)
1819 // don't have to be changed and branched for 641.
1820 // They can be removed later.
1822 if (!mpMarkData->IsMarked()) // no cell marked:
1823 mpMarkData->SetMarkArea(aBlockRange); // mark paste block
1825 if ( pRefUndoData )
1826 pRefUndoData->DeleteUnchanged( &pDocShell->GetDocument() );
1828 SetChangeTrack();
1831 ScUndoDataForm::~ScUndoDataForm()
1833 delete pUndoDoc;
1834 delete pRedoDoc;
1835 delete pRefUndoData;
1836 delete pRefRedoData;
1839 OUString ScUndoDataForm::GetComment() const
1841 return ScGlobal::GetRscString( STR_UNDO_PASTE );
1844 void ScUndoDataForm::SetChangeTrack()
1846 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
1847 if ( pChangeTrack && (nFlags & IDF_CONTENTS) )
1848 pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
1849 nStartChangeAction, nEndChangeAction, SC_CACM_PASTE );
1850 else
1851 nStartChangeAction = nEndChangeAction = 0;
1854 void ScUndoDataForm::Undo()
1856 BeginUndo();
1857 DoChange( true );
1858 ShowTable( aBlockRange );
1859 EndUndo();
1860 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
1863 void ScUndoDataForm::Redo()
1865 BeginRedo();
1866 ScDocument& rDoc = pDocShell->GetDocument();
1867 EnableDrawAdjust( &rDoc, false ); //! include in ScBlockUndo?
1868 DoChange( false );
1869 EnableDrawAdjust( &rDoc, true ); //! include in ScBlockUndo?
1870 EndRedo();
1871 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
1874 void ScUndoDataForm::Repeat(SfxRepeatTarget& /*rTarget*/)
1878 bool ScUndoDataForm::CanRepeat(SfxRepeatTarget& rTarget) const
1880 return (rTarget.ISA(ScTabViewTarget));
1883 void ScUndoDataForm::DoChange( const bool bUndo )
1885 ScDocument& rDoc = pDocShell->GetDocument();
1887 // RefUndoData for redo is created before first undo
1888 // (with DeleteUnchanged after the DoUndo call)
1889 bool bCreateRedoData = ( bUndo && pRefUndoData && !pRefRedoData );
1890 if ( bCreateRedoData )
1891 pRefRedoData = new ScRefUndoData( &rDoc );
1893 ScRefUndoData* pWorkRefData = bUndo ? pRefUndoData : pRefRedoData;
1895 // Always back-up either all or none of the content for Undo
1896 InsertDeleteFlags nUndoFlags = IDF_NONE;
1897 if (nFlags & IDF_CONTENTS)
1898 nUndoFlags |= IDF_CONTENTS;
1899 if (nFlags & IDF_ATTRIB)
1900 nUndoFlags |= IDF_ATTRIB;
1902 bool bPaintAll = false;
1904 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1906 SCTAB nTabCount = rDoc.GetTableCount();
1907 if ( bUndo && !bRedoFilled )
1909 if (!pRedoDoc)
1911 bool bColInfo = ( aBlockRange.aStart.Row()==0 && aBlockRange.aEnd.Row()==MAXROW );
1912 bool bRowInfo = ( aBlockRange.aStart.Col()==0 && aBlockRange.aEnd.Col()==MAXCOL );
1914 pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
1915 pRedoDoc->InitUndoSelected( &rDoc, *mpMarkData, bColInfo, bRowInfo );
1917 // read "redo" data from the document in the first undo
1918 // all sheets - CopyToDocument skips those that don't exist in pRedoDoc
1919 ScRange aCopyRange = aBlockRange;
1920 aCopyRange.aStart.SetTab(0);
1921 aCopyRange.aEnd.SetTab(nTabCount-1);
1922 rDoc.CopyToDocument( aCopyRange, IDF_VALUE, false, pRedoDoc );
1923 bRedoFilled = true;
1926 sal_uInt16 nExtFlags = 0;
1927 pDocShell->UpdatePaintExt( nExtFlags, aBlockRange );
1929 for ( sal_uInt16 i=0; i <= ( aBlockRange.aEnd.Col() - aBlockRange.aStart.Col() ); i++ )
1931 OUString aOldString = pUndoDoc->GetString(
1932 aBlockRange.aStart.Col()+i, aBlockRange.aStart.Row(), aBlockRange.aStart.Tab());
1933 rDoc.SetString( aBlockRange.aStart.Col()+i , aBlockRange.aStart.Row() , aBlockRange.aStart.Tab() , aOldString );
1936 if (pWorkRefData)
1938 pWorkRefData->DoUndo( &rDoc, true ); // TRUE = bSetChartRangeLists for SetChartListenerCollection
1939 if ( rDoc.RefreshAutoFilter( 0,0, MAXCOL,MAXROW, aBlockRange.aStart.Tab() ) )
1940 bPaintAll = true;
1943 if ( bCreateRedoData && pRefRedoData )
1944 pRefRedoData->DeleteUnchanged( &rDoc );
1946 if ( bUndo )
1948 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
1949 if ( pChangeTrack )
1950 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1952 else
1953 SetChangeTrack();
1955 ScRange aDrawRange( aBlockRange );
1956 rDoc.ExtendMerge( aDrawRange, true ); // only needed for single sheet (text/rtf etc.)
1957 sal_uInt16 nPaint = PAINT_GRID;
1958 if (bPaintAll)
1960 aDrawRange.aStart.SetCol(0);
1961 aDrawRange.aStart.SetRow(0);
1962 aDrawRange.aEnd.SetCol(MAXCOL);
1963 aDrawRange.aEnd.SetRow(MAXROW);
1964 nPaint |= PAINT_TOP | PAINT_LEFT;
1965 /*A*/ if (pViewShell)
1966 pViewShell->AdjustBlockHeight(false);
1968 else
1970 if ( aBlockRange.aStart.Row() == 0 && aBlockRange.aEnd.Row() == MAXROW ) // whole column
1972 nPaint |= PAINT_TOP;
1973 aDrawRange.aEnd.SetCol(MAXCOL);
1975 if ( aBlockRange.aStart.Col() == 0 && aBlockRange.aEnd.Col() == MAXCOL ) // whole row
1977 nPaint |= PAINT_LEFT;
1978 aDrawRange.aEnd.SetRow(MAXROW);
1980 /*A*/ if ((pViewShell) && pViewShell->AdjustBlockHeight(false))
1982 aDrawRange.aStart.SetCol(0);
1983 aDrawRange.aStart.SetRow(0);
1984 aDrawRange.aEnd.SetCol(MAXCOL);
1985 aDrawRange.aEnd.SetRow(MAXROW);
1986 nPaint |= PAINT_LEFT;
1988 pDocShell->UpdatePaintExt( nExtFlags, aDrawRange );
1991 if ( !bUndo ) // draw redo after updating row heights
1992 RedoSdrUndoAction( pDrawUndo ); //! include in ScBlockUndo?
1994 pDocShell->PostPaint( aDrawRange, nPaint, nExtFlags );
1996 pDocShell->PostDataChanged();
1997 if (pViewShell)
1998 pViewShell->CellContentChanged();
2001 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */