1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
27 #include "tabvwsh.hxx"
28 #include "olinetab.hxx"
30 #include "rangenam.hxx"
32 #include "globstr.hrc"
34 #include "globalnames.hxx"
36 #include "chartarr.hxx"
37 #include "dbdocfun.hxx"
38 #include "olinefun.hxx"
39 #include "dpobject.hxx"
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
),
77 pUndoDoc( pNewUndoDoc
),
78 bColumns( bNewColumns
),
85 ScUndoDoOutline::~ScUndoDoOutline()
90 OUString
ScUndoDoOutline::GetComment() const
91 { // Show outline" "Hide outline"
93 ScGlobal::GetRscString( STR_UNDO_DOOUTLINE
) :
94 ScGlobal::GetRscString( STR_UNDO_REDOOUTLINE
);
97 void ScUndoDoOutline::Undo()
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
113 pViewShell
->HideOutline( bColumns
, nLevel
, nEntry
, false, false );
115 pViewShell
->ShowOutline( bColumns
, nLevel
, nEntry
, false, false );
117 // Original column/row status
119 pUndoDoc
->CopyToDocument( static_cast<SCCOL
>(nStart
), 0, nTab
,
120 static_cast<SCCOL
>(nEnd
), MAXROW
, nTab
, IDF_NONE
, false, pDoc
);
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
);
131 void ScUndoDoOutline::Redo()
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
);
144 pViewShell
->ShowOutline( bColumns
, nLevel
, nEntry
, false );
146 pViewShell
->HideOutline( bColumns
, nLevel
, nEntry
, false );
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
),
174 ScUndoMakeOutline::~ScUndoMakeOutline()
179 OUString
ScUndoMakeOutline::GetComment() const
180 { // "Grouping" "Undo grouping"
182 ScGlobal::GetRscString( STR_UNDO_MAKEOUTLINE
) :
183 ScGlobal::GetRscString( STR_UNDO_REMAKEOUTLINE
);
186 void ScUndoMakeOutline::Undo()
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
);
207 void ScUndoMakeOutline::Redo()
211 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
213 ScUndoUtil::MarkSimpleBlock( pDocShell
, aBlockStart
, aBlockEnd
);
216 pViewShell
->MakeOutline( bColumns
, false );
218 pViewShell
->RemoveOutline( bColumns
, false );
220 pDocShell
->PostPaint(0,0,aBlockStart
.Tab(),MAXCOL
,MAXROW
,aBlockEnd
.Tab(),PAINT_GRID
);
225 void ScUndoMakeOutline::Repeat(SfxRepeatTarget
& rTarget
)
227 if (rTarget
.ISA(ScTabViewTarget
))
229 ScTabViewShell
& rViewShell
= *((ScTabViewTarget
&)rTarget
).GetViewShell();
232 rViewShell
.MakeOutline( bColumns
, sal_True
);
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
),
251 pUndoDoc( pNewUndoDoc
),
252 pUndoTable( pNewUndoTab
),
253 bColumns( bNewColumns
),
258 ScUndoOutlineLevel::~ScUndoOutlineLevel()
264 OUString
ScUndoOutlineLevel::GetComment() const
265 { // "Select outline level"
266 return ScGlobal::GetRscString( STR_UNDO_OUTLINELEVEL
);
269 void ScUndoOutlineLevel::Undo()
273 ScDocument
* pDoc
= pDocShell
->GetDocument();
274 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
276 // Original Outline table
278 pDoc
->SetOutlineTable( nTab
, pUndoTable
);
280 // Original column/row status
283 pUndoDoc
->CopyToDocument( static_cast<SCCOL
>(nStart
), 0, nTab
,
284 static_cast<SCCOL
>(nEnd
), MAXROW
, nTab
, IDF_NONE
, false, pDoc
);
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
);
301 void ScUndoOutlineLevel::Redo()
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 );
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
),
343 ScUndoOutlineBlock::~ScUndoOutlineBlock()
349 OUString
ScUndoOutlineBlock::GetComment() const
350 { // "Show outline" "Hide outline"
352 ScGlobal::GetRscString( STR_UNDO_DOOUTLINEBLK
) :
353 ScGlobal::GetRscString( STR_UNDO_REDOOUTLINEBLK
);
356 void ScUndoOutlineBlock::Undo()
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();
374 { // Size of the hidden blocks
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
);
399 void ScUndoOutlineBlock::Redo()
403 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
405 ScUndoUtil::MarkSimpleBlock( pDocShell
, aBlockStart
, aBlockEnd
);
407 pViewShell
->ShowMarkedOutlines( false );
409 pViewShell
->HideMarkedOutlines( false );
414 void ScUndoOutlineBlock::Repeat(SfxRepeatTarget
& rTarget
)
416 if (rTarget
.ISA(ScTabViewTarget
))
418 ScTabViewShell
& rViewShell
= *((ScTabViewTarget
&)rTarget
).GetViewShell();
421 rViewShell
.ShowMarkedOutlines( sal_True
);
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()
450 OUString
ScUndoRemoveAllOutlines::GetComment() const
451 { // "Remove outlines"
452 return ScGlobal::GetRscString( STR_UNDO_REMOVEALLOTLNS
);
455 void ScUndoRemoveAllOutlines::Undo()
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
);
488 void ScUndoRemoveAllOutlines::Redo()
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 );
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()
535 OUString
ScUndoAutoOutline::GetComment() const
537 return ScGlobal::GetRscString( STR_UNDO_AUTOOUTLINE
);
540 void ScUndoAutoOutline::Undo()
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
)
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,
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
);
578 void ScUndoAutoOutline::Redo()
582 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
584 SCTAB nTab
= aBlockStart
.Tab();
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 );
600 // If it was called with a multi selection,
601 // then this is now the enclosing range...
604 pViewShell
->MarkRange( aRange
);
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
) ),
628 nNewEndRow( nNewEndY
),
629 pUndoDoc( pNewUndoDoc
),
630 pUndoTable( pNewUndoTab
),
631 pUndoRange( pNewUndoRange
),
632 pUndoDB( pNewUndoDB
)
636 ScUndoSubTotals::~ScUndoSubTotals()
644 OUString
ScUndoSubTotals::GetComment() const
646 return ScGlobal::GetRscString( STR_UNDO_SUBTOTALS
);
649 void ScUndoSubTotals::Undo()
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
)
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,
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
);
703 pDoc
->SetRangeName( new ScRangeName( *pUndoRange
) );
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();
717 void ScUndoSubTotals::Redo()
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 );
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
) ),
750 aSortParam( rParam
),
751 pUndoDoc( pNewUndoDoc
),
752 pUndoDB( pNewUndoDB
),
757 bDestArea
= sal_True
;
762 ScUndoSort::~ScUndoSort()
768 OUString
ScUndoSort::GetComment() const
770 return ScGlobal::GetRscString( STR_UNDO_SORT
);
773 void ScUndoSort::Undo()
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
);
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
);
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();
827 void ScUndoSort::Redo()
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
);
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
) ),
866 aQueryParam( rParam
),
867 pUndoDoc( pNewUndoDoc
),
868 pUndoDB( pNewUndoDB
),
869 bIsAdvanced( false ),
875 bDestArea
= sal_True
;
880 bIsAdvanced
= sal_True
;
881 aAdvSource
= *pAdvSrc
;
884 pDrawUndo
= GetSdrUndoAction( pDocShell
->GetDocument() );
887 ScUndoQuery::~ScUndoQuery()
891 DeleteSdrUndoAction( pDrawUndo
);
894 OUString
ScUndoQuery::GetComment() const
896 return ScGlobal::GetRscString( STR_UNDO_QUERY
);
899 void ScUndoQuery::Undo()
903 ScDocument
* pDoc
= pDocShell
->GetDocument();
904 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
906 sal_Bool bCopy
= !aQueryParam
.bInplace
;
907 SCCOL nDestEndCol
= 0;
908 SCROW nDestEndRow
= 0;
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
);
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
),
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
);
954 pUndoDoc
->CopyToDocument( 0, aQueryParam
.nRow1
, nTab
, MAXCOL
, aQueryParam
.nRow2
, nTab
,
955 IDF_NONE
, false, pDoc
);
958 pDoc
->SetDBCollection( new ScDBCollection( *pUndoDB
), sal_True
);
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
);
980 SCCOL nEndX
= nDestEndCol
;
981 SCROW nEndY
= nDestEndRow
;
984 if ( aOldDest
.aEnd
.Col() > nEndX
)
985 nEndX
= aOldDest
.aEnd
.Col();
986 if ( aOldDest
.aEnd
.Row() > nEndY
)
987 nEndY
= aOldDest
.aEnd
.Row();
991 pDocShell
->PostPaint( aQueryParam
.nDestCol
, aQueryParam
.nDestRow
, aQueryParam
.nDestTab
,
992 nEndX
, nEndY
, aQueryParam
.nDestTab
, PAINT_GRID
);
995 pDocShell
->PostPaint( 0, aQueryParam
.nRow1
, nTab
, MAXCOL
, MAXROW
, nTab
,
996 PAINT_GRID
| PAINT_LEFT
);
997 pDocShell
->PostDataChanged();
1002 void ScUndoQuery::Redo()
1006 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
1008 SCTAB nVisTab
= pViewShell
->GetViewData()->GetTabNo();
1009 if ( nVisTab
!= nTab
)
1010 pViewShell
->SetTabNo( nTab
);
1013 pViewShell
->Query( aQueryParam
, &aAdvSource
, false );
1015 pViewShell
->Query( aQueryParam
, NULL
, false );
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
),
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
);
1061 ScDBCollection
* pColl
= pDoc
->GetDBCollection();
1062 pDBData
= pColl
->getNamedDBs().findByUpperName(ScGlobal::pCharClass
->uppercase(aDBName
));
1067 pDBData
->SetAutoFilter( bNewFilter
);
1074 pDBData
->GetArea( nRangeTab
, nRangeX1
, nRangeY1
, nRangeX2
, nRangeY2
);
1077 pDoc
->ApplyFlagsTab( nRangeX1
, nRangeY1
, nRangeX2
, nRangeY1
, nRangeTab
, SC_MF_AUTO
);
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()
1088 DoChange( sal_True
);
1092 void ScUndoAutoFilter::Redo()
1099 void ScUndoAutoFilter::Repeat(SfxRepeatTarget
& /* rTarget */)
1103 bool ScUndoAutoFilter::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
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()
1123 OUString
ScUndoDBData::GetComment() const
1124 { // "Change database range";
1125 return ScGlobal::GetRscString( STR_UNDO_DBDATA
);
1128 void ScUndoDBData::Undo()
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
) );
1146 void ScUndoDBData::Redo()
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
) );
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
,
1176 ScDocument
* pNewUndoDoc
, ScDocument
* pNewRedoDoc
,
1177 ScDBData
* pNewUndoData
, ScDBData
* pNewRedoData
) :
1178 ScSimpleUndo( pNewDocShell
),
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()
1201 OUString
ScUndoImportData::GetComment() const
1203 return ScGlobal::GetRscString( STR_UNDO_IMPORTDATA
);
1206 void ScUndoImportData::Undo()
1210 ScDocument
* pDoc
= pDocShell
->GetDocument();
1211 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
1213 ScUndoUtil::MarkSimpleBlock( pDocShell
, aImportParam
.nCol1
,aImportParam
.nRow1
,nTab
,
1214 nEndCol
,nEndRow
,nTab
);
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
);
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
1248 // Undo: first delete the new data, then FitBlock backwards
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
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
);
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
);
1282 pDocShell
->PostPaint( 0,0,nTab
, MAXCOL
,MAXROW
,nTab
, PAINT_GRID
);
1284 pDocShell
->PostPaint( aImportParam
.nCol1
,aImportParam
.nRow1
,nTab
,
1285 nEndCol
,nEndRow
,nTab
, PAINT_GRID
);
1286 pDocShell
->PostDataChanged();
1291 void ScUndoImportData::Redo()
1295 ScDocument
* pDoc
= pDocShell
->GetDocument();
1296 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
1298 ScUndoUtil::MarkSimpleBlock( pDocShell
, aImportParam
.nCol1
,aImportParam
.nRow1
,nTab
,
1299 nEndCol
,nEndRow
,nTab
);
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
1315 // Redo: FitBlock, then delete data (needed for CopyToDocument)
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
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
);
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
);
1351 pDocShell
->PostPaint( 0,0,nTab
, MAXCOL
,MAXROW
,nTab
, PAINT_GRID
);
1353 pDocShell
->PostPaint( aImportParam
.nCol1
,aImportParam
.nRow1
,nTab
,
1354 nEndCol
,nEndRow
,nTab
, PAINT_GRID
);
1355 pDocShell
->PostDataChanged();
1360 void ScUndoImportData::Repeat(SfxRepeatTarget
& rTarget
)
1362 if (rTarget
.ISA(ScTabViewTarget
))
1364 ScTabViewShell
& rViewShell
= *((ScTabViewTarget
&)rTarget
).GetViewShell();
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
1380 return rTarget
.ISA(ScTabViewTarget
);
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
),
1403 if ( pOldQ
&& pNewQ
)
1407 bQuerySize
= sal_True
;;
1411 ScUndoRepeatDB::~ScUndoRepeatDB()
1419 OUString
ScUndoRepeatDB::GetComment() const
1421 return ScGlobal::GetRscString( STR_UNDO_REPEATDB
);
1424 void ScUndoRepeatDB::Undo()
1428 ScDocument
* pDoc
= pDocShell
->GetDocument();
1429 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
1430 SCTAB nTab
= aBlockStart
.Tab();
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
)
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,
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
);
1504 pDoc
->SetRangeName( new ScRangeName( *pUndoRange
) );
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();
1518 void ScUndoRepeatDB::Redo()
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 );
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
),
1560 pOldDPObject
= new ScDPObject( *pOldObj
);
1562 pNewDPObject
= new ScDPObject( *pNewObj
);
1565 ScUndoDataPilot::~ScUndoDataPilot()
1567 delete pOldDPObject
;
1568 delete pNewDPObject
;
1573 OUString
ScUndoDataPilot::GetComment() const
1576 if ( pOldUndoDoc
&& pNewUndoDoc
)
1577 nIndex
= STR_UNDO_PIVOT_MODIFY
;
1578 else if ( pNewUndoDoc
)
1579 nIndex
= STR_UNDO_PIVOT_NEW
;
1581 nIndex
= STR_UNDO_PIVOT_DELETE
;
1583 return ScGlobal::GetRscString( nIndex
);
1586 void ScUndoDataPilot::Undo()
1590 ScDocument
* pDoc
= pDocShell
->GetDocument();
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
1612 // find updated object
1615 ScDPObject
* pDocObj
= pDoc
->GetDPAtCursor(
1616 aNewRange
.aStart
.Col(), aNewRange
.aStart
.Row(), aNewRange
.aStart
.Tab() );
1617 OSL_ENSURE(pDocObj
, "DPObject not found");
1622 // restore old settings
1623 pOldDPObject
->WriteSourceDataTo( *pDocObj
);
1624 ScDPSaveData
* pData
= pOldDPObject
->GetSaveData();
1626 pDocObj
->SetSaveData(*pData
);
1627 pDocObj
->SetOutRange( pOldDPObject
->GetOutRange() );
1628 pOldDPObject
->WriteTempDataTo( *pDocObj
);
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
);
1650 pDocShell
->PostPaint( aNewRange
, PAINT_GRID
, SC_PF_LINES
);
1652 pDocShell
->PostPaint( aOldRange
, PAINT_GRID
, SC_PF_LINES
);
1653 pDocShell
->PostDataChanged();
1655 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
1658 //! set current sheet
1663 // notify API objects
1664 pDoc
->BroadcastUno( ScDataPilotModifiedHint( pNewDPObject
->GetName() ) );
1670 void ScUndoDataPilot::Redo()
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
;
1682 // find object to modify
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
1697 void ScUndoDataPilot::Repeat(SfxRepeatTarget
& /* rTarget */)
1702 bool ScUndoDataPilot::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
1708 ScUndoConsolidate::ScUndoConsolidate( ScDocShell
* pNewDocShell
, const ScArea
& rArea
,
1709 const ScConsolidateParam
& rPar
, ScDocument
* pNewUndoDoc
,
1710 sal_Bool bReference
, SCROW nInsCount
, ScOutlineTable
* pTab
,
1712 ScSimpleUndo( pNewDocShell
),
1714 pUndoDoc( pNewUndoDoc
),
1716 bInsRef( bReference
),
1717 nInsertCount( nInsCount
),
1723 ScUndoConsolidate::~ScUndoConsolidate()
1730 OUString
ScUndoConsolidate::GetComment() const
1732 return ScGlobal::GetRscString( STR_UNDO_CONSOLIDATE
);
1735 void ScUndoConsolidate::Undo()
1739 ScDocument
* pDoc
= pDocShell
->GetDocument();
1740 SCTAB nTab
= aDestArea
.nTab
;
1744 pUndoData
->GetArea(aOldRange
);
1748 pDoc
->DeleteRow( 0,nTab
, MAXCOL
,nTab
, aDestArea
.nRowStart
, nInsertCount
);
1749 pDoc
->SetOutlineTable( nTab
, pUndoTab
);
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
);
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
);
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
);
1781 pDoc
->DeleteAreaTab(aOldRange
, IDF_ALL
);
1782 pUndoDoc
->CopyToDocument(aOldRange
, IDF_ALL
, false, pDoc
);
1785 SCCOL nEndX
= aDestArea
.nColEnd
;
1786 SCROW nEndY
= aDestArea
.nRowEnd
;
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
1801 ScDBCollection
* pColl
= pDoc
->GetDBCollection();
1804 ScDBData
* pDocData
= pColl
->getNamedDBs().findByUpperName(pUndoData
->GetUpperName());
1806 *pDocData
= *pUndoData
;
1810 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
1813 SCTAB nViewTab
= pViewShell
->GetViewData()->GetTabNo();
1814 if ( nViewTab
!= nTab
)
1815 pViewShell
->SetTabNo( nTab
);
1821 void ScUndoConsolidate::Redo()
1825 pDocShell
->DoConsolidate( aParam
, false );
1827 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
1830 SCTAB nViewTab
= pViewShell
->GetViewData()->GetTabNo();
1831 if ( nViewTab
!= aParam
.nTab
)
1832 pViewShell
->SetTabNo( aParam
.nTab
);
1838 void ScUndoConsolidate::Repeat(SfxRepeatTarget
& /* rTarget */)
1842 bool ScUndoConsolidate::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
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
,
1858 ScSimpleUndo( pNewDocShell
),
1859 aChartName( rName
),
1860 bNewColHeaders( bColHdr
),
1861 bNewRowHeaders( bRowHdr
),
1864 aNewRangeListRef
= new ScRangeList
;
1865 aNewRangeListRef
->Append( rNew
);
1870 ScUndoChartData::ScUndoChartData( ScDocShell
* pNewDocShell
, const OUString
& rName
,
1871 const ScRangeListRef
& rNew
, bool bColHdr
, bool bRowHdr
,
1873 ScSimpleUndo( pNewDocShell
),
1874 aChartName( rName
),
1875 aNewRangeListRef( rNew
),
1876 bNewColHeaders( bColHdr
),
1877 bNewRowHeaders( bRowHdr
),
1883 ScUndoChartData::~ScUndoChartData()
1887 OUString
ScUndoChartData::GetComment() const
1889 return ScGlobal::GetRscString( STR_UNDO_CHARTDATA
);
1892 void ScUndoChartData::Undo()
1896 pDocShell
->GetDocument()->UpdateChartArea( aChartName
, aOldRangeListRef
,
1897 bOldColHeaders
, bOldRowHeaders
, false );
1902 void ScUndoChartData::Redo()
1906 pDocShell
->GetDocument()->UpdateChartArea( aChartName
, aNewRangeListRef
,
1907 bNewColHeaders
, bNewRowHeaders
, bAddRange
);
1912 void ScUndoChartData::Repeat(SfxRepeatTarget
& /* rTarget */)
1916 bool ScUndoChartData::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
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
1947 pRefUndoData
->DeleteUnchanged( pDocShell
->GetDocument() );
1952 ScUndoDataForm::~ScUndoDataForm()
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
);
1972 nStartChangeAction
= nEndChangeAction
= 0;
1975 void ScUndoDataForm::Undo()
1979 ShowTable( aBlockRange
);
1981 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED
) );
1984 void ScUndoDataForm::Redo()
1987 ScDocument
* pDoc
= pDocShell
->GetDocument();
1988 EnableDrawAdjust( pDoc
, false ); //! include in ScBlockUndo?
1990 EnableDrawAdjust( pDoc
, true ); //! include in ScBlockUndo?
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
)
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
);
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
);
2059 pWorkRefData
->DoUndo( pDoc
, true ); // TRUE = bSetChartRangeLists for SetChartListenerCollection
2060 if ( pDoc
->RefreshAutoFilter( 0,0, MAXCOL
,MAXROW
, aBlockRange
.aStart
.Tab() ) )
2064 if ( bCreateRedoData
&& pRefRedoData
)
2065 pRefRedoData
->DeleteUnchanged( pDoc
);
2069 ScChangeTrack
* pChangeTrack
= pDoc
->GetChangeTrack();
2071 pChangeTrack
->Undo( nStartChangeAction
, nEndChangeAction
);
2076 ScRange
aDrawRange( aBlockRange
);
2077 pDoc
->ExtendMerge( aDrawRange
, true ); // only needed for single sheet (text/rtf etc.)
2078 sal_uInt16 nPaint
= PAINT_GRID
;
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);
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();
2119 pViewShell
->CellContentChanged();
2122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */