LCOV - code coverage report
Current view: top level - sc/source/ui/undo - undodat.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 148 1031 14.4 %
Date: 2014-04-11 Functions: 57 228 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <sfx2/app.hxx>
      21             : 
      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"
      46             : 
      47           0 : TYPEINIT1(ScUndoDoOutline,          ScSimpleUndo);
      48           0 : TYPEINIT1(ScUndoMakeOutline,        ScSimpleUndo);
      49           0 : TYPEINIT1(ScUndoOutlineLevel,       ScSimpleUndo);
      50           0 : TYPEINIT1(ScUndoOutlineBlock,       ScSimpleUndo);
      51           0 : TYPEINIT1(ScUndoRemoveAllOutlines,  ScSimpleUndo);
      52           0 : TYPEINIT1(ScUndoAutoOutline,        ScSimpleUndo);
      53           0 : TYPEINIT1(ScUndoSubTotals,          ScDBFuncUndo);
      54           0 : TYPEINIT1(ScUndoSort,               ScDBFuncUndo);
      55           0 : TYPEINIT1(ScUndoQuery,              ScDBFuncUndo);
      56           0 : TYPEINIT1(ScUndoAutoFilter,         ScDBFuncUndo);
      57           0 : TYPEINIT1(ScUndoDBData,             ScSimpleUndo);
      58           0 : TYPEINIT1(ScUndoImportData,         ScSimpleUndo);
      59           0 : TYPEINIT1(ScUndoRepeatDB,           ScSimpleUndo);
      60           0 : TYPEINIT1(ScUndoDataPilot,          ScSimpleUndo);
      61           0 : TYPEINIT1(ScUndoConsolidate,        ScSimpleUndo);
      62           0 : TYPEINIT1(ScUndoChartData,          ScSimpleUndo);
      63           0 : TYPEINIT1(ScUndoDataForm,           SfxUndoAction);
      64             : 
      65             : // Show or hide outline groups
      66             : 
      67           0 : ScUndoDoOutline::ScUndoDoOutline( ScDocShell* pNewDocShell,
      68             :                             SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
      69             :                             ScDocument* pNewUndoDoc, bool bNewColumns,
      70             :                             sal_uInt16 nNewLevel, sal_uInt16 nNewEntry, bool bNewShow ) :
      71             :     ScSimpleUndo( pNewDocShell ),
      72             :     nStart( nNewStart ),
      73             :     nEnd( nNewEnd ),
      74             :     nTab( nNewTab ),
      75             :     pUndoDoc( pNewUndoDoc ),
      76             :     bColumns( bNewColumns ),
      77             :     nLevel( nNewLevel ),
      78             :     nEntry( nNewEntry ),
      79           0 :     bShow( bNewShow )
      80             : {
      81           0 : }
      82             : 
      83           0 : ScUndoDoOutline::~ScUndoDoOutline()
      84             : {
      85           0 :     delete pUndoDoc;
      86           0 : }
      87             : 
      88           0 : OUString ScUndoDoOutline::GetComment() const
      89             : {   // Show outline" "Hide outline"
      90             :     return bShow ?
      91             :         ScGlobal::GetRscString( STR_UNDO_DOOUTLINE ) :
      92           0 :         ScGlobal::GetRscString( STR_UNDO_REDOOUTLINE );
      93             : }
      94             : 
      95           0 : void ScUndoDoOutline::Undo()
      96             : {
      97           0 :     BeginUndo();
      98             : 
      99           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     100           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     101             : 
     102             :     // sheet has to be switched over (#46952#)!
     103             : 
     104           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     105           0 :     if ( nVisTab != nTab )
     106           0 :         pViewShell->SetTabNo( nTab );
     107             : 
     108             :     // perform the inverse function
     109             : 
     110           0 :     if (bShow)
     111           0 :         pViewShell->HideOutline( bColumns, nLevel, nEntry, false, false );
     112             :     else
     113           0 :         pViewShell->ShowOutline( bColumns, nLevel, nEntry, false, false );
     114             : 
     115             :     //  Original column/row status
     116           0 :     if (bColumns)
     117             :         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
     118           0 :                 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false, pDoc);
     119             :     else
     120           0 :         pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pDoc );
     121             : 
     122           0 :     pViewShell->UpdateScrollBars();
     123             : 
     124           0 :     pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
     125             : 
     126           0 :     EndUndo();
     127           0 : }
     128             : 
     129           0 : void ScUndoDoOutline::Redo()
     130             : {
     131           0 :     BeginRedo();
     132             : 
     133           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     134             : 
     135             :     // sheet has to be switched over (#46952#)!
     136             : 
     137           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     138           0 :     if ( nVisTab != nTab )
     139           0 :         pViewShell->SetTabNo( nTab );
     140             : 
     141           0 :     if (bShow)
     142           0 :         pViewShell->ShowOutline( bColumns, nLevel, nEntry, false );
     143             :     else
     144           0 :         pViewShell->HideOutline( bColumns, nLevel, nEntry, false );
     145             : 
     146           0 :     EndRedo();
     147           0 : }
     148             : 
     149           0 : void ScUndoDoOutline::Repeat(SfxRepeatTarget& /* rTarget */)
     150             : {
     151           0 : }
     152             : 
     153           0 : bool ScUndoDoOutline::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     154             : {
     155           0 :     return false;                       // is not possible
     156             : }
     157             : 
     158             : /** Make or delete outline groups */
     159          12 : ScUndoMakeOutline::ScUndoMakeOutline( ScDocShell* pNewDocShell,
     160             :                             SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
     161             :                             SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
     162             :                             ScOutlineTable* pNewUndoTab, bool bNewColumns, bool bNewMake ) :
     163             :     ScSimpleUndo( pNewDocShell ),
     164             :     aBlockStart( nStartX, nStartY, nStartZ ),
     165             :     aBlockEnd( nEndX, nEndY, nEndZ ),
     166             :     pUndoTable( pNewUndoTab ),
     167             :     bColumns( bNewColumns ),
     168          12 :     bMake( bNewMake )
     169             : {
     170          12 : }
     171             : 
     172          36 : ScUndoMakeOutline::~ScUndoMakeOutline()
     173             : {
     174          12 :     delete pUndoTable;
     175          24 : }
     176             : 
     177          12 : OUString ScUndoMakeOutline::GetComment() const
     178             : {   // "Grouping" "Undo grouping"
     179             :     return bMake ?
     180             :         ScGlobal::GetRscString( STR_UNDO_MAKEOUTLINE ) :
     181          12 :         ScGlobal::GetRscString( STR_UNDO_REMAKEOUTLINE );
     182             : }
     183             : 
     184           0 : void ScUndoMakeOutline::Undo()
     185             : {
     186           0 :     BeginUndo();
     187             : 
     188           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     189           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     190           0 :     SCTAB nTab = aBlockStart.Tab();
     191             : 
     192           0 :     ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
     193             : 
     194           0 :     pDoc->SetOutlineTable( nTab, pUndoTable );
     195             : 
     196           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     197           0 :     if ( nVisTab != nTab )
     198           0 :         pViewShell->SetTabNo( nTab );
     199             : 
     200           0 :     pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
     201             : 
     202           0 :     EndUndo();
     203           0 : }
     204             : 
     205           0 : void ScUndoMakeOutline::Redo()
     206             : {
     207           0 :     BeginRedo();
     208             : 
     209           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     210             : 
     211           0 :     ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
     212             : 
     213           0 :     if (bMake)
     214           0 :         pViewShell->MakeOutline( bColumns, false );
     215             :     else
     216           0 :         pViewShell->RemoveOutline( bColumns, false );
     217             : 
     218           0 :     pDocShell->PostPaint(0,0,aBlockStart.Tab(),MAXCOL,MAXROW,aBlockEnd.Tab(),PAINT_GRID);
     219             : 
     220           0 :     EndRedo();
     221           0 : }
     222             : 
     223           0 : void ScUndoMakeOutline::Repeat(SfxRepeatTarget& rTarget)
     224             : {
     225           0 :     if (rTarget.ISA(ScTabViewTarget))
     226             :     {
     227           0 :         ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
     228             : 
     229           0 :         if (bMake)
     230           0 :             rViewShell.MakeOutline( bColumns, true );
     231             :         else
     232           0 :             rViewShell.RemoveOutline( bColumns, true );
     233             :     }
     234           0 : }
     235             : 
     236           0 : bool ScUndoMakeOutline::CanRepeat(SfxRepeatTarget& rTarget) const
     237             : {
     238           0 :     return rTarget.ISA(ScTabViewTarget);
     239             : }
     240             : 
     241           1 : ScUndoOutlineLevel::ScUndoOutlineLevel( ScDocShell* pNewDocShell,
     242             :                         SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
     243             :                         ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
     244             :                         bool bNewColumns, sal_uInt16 nNewLevel ) :
     245             :     ScSimpleUndo( pNewDocShell ),
     246             :     nStart( nNewStart ),
     247             :     nEnd( nNewEnd ),
     248             :     nTab( nNewTab ),
     249             :     pUndoDoc( pNewUndoDoc ),
     250             :     pUndoTable( pNewUndoTab ),
     251             :     bColumns( bNewColumns ),
     252           1 :     nLevel( nNewLevel )
     253             : {
     254           1 : }
     255             : 
     256           3 : ScUndoOutlineLevel::~ScUndoOutlineLevel()
     257             : {
     258           1 :     delete pUndoDoc;
     259           1 :     delete pUndoTable;
     260           2 : }
     261             : 
     262           1 : OUString ScUndoOutlineLevel::GetComment() const
     263             : {   // "Select outline level"
     264           1 :     return ScGlobal::GetRscString( STR_UNDO_OUTLINELEVEL );
     265             : }
     266             : 
     267           0 : void ScUndoOutlineLevel::Undo()
     268             : {
     269           0 :     BeginUndo();
     270             : 
     271           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     272           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     273             : 
     274             :     //  Original Outline table
     275             : 
     276           0 :     pDoc->SetOutlineTable( nTab, pUndoTable );
     277             : 
     278             :     //  Original column/row status
     279             : 
     280           0 :     if (bColumns)
     281             :         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
     282           0 :                 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, false, pDoc);
     283             :     else
     284           0 :         pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, false, pDoc );
     285             : 
     286           0 :     pDoc->UpdatePageBreaks( nTab );
     287             : 
     288           0 :     pViewShell->UpdateScrollBars();
     289             : 
     290           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     291           0 :     if ( nVisTab != nTab )
     292           0 :         pViewShell->SetTabNo( nTab );
     293             : 
     294           0 :     pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
     295             : 
     296           0 :     EndUndo();
     297           0 : }
     298             : 
     299           0 : void ScUndoOutlineLevel::Redo()
     300             : {
     301           0 :     BeginRedo();
     302             : 
     303           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     304             : 
     305             :     // sheet has to be switched on or off before this (#46952#) !!!
     306             : 
     307           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     308           0 :     if ( nVisTab != nTab )
     309           0 :         pViewShell->SetTabNo( nTab );
     310             : 
     311           0 :     pViewShell->SelectLevel( bColumns, nLevel, false );
     312             : 
     313           0 :     EndRedo();
     314           0 : }
     315             : 
     316           0 : void ScUndoOutlineLevel::Repeat(SfxRepeatTarget& rTarget)
     317             : {
     318           0 :     if (rTarget.ISA(ScTabViewTarget))
     319           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->SelectLevel( bColumns, nLevel, true );
     320           0 : }
     321             : 
     322           0 : bool ScUndoOutlineLevel::CanRepeat(SfxRepeatTarget& rTarget) const
     323             : {
     324           0 :     return rTarget.ISA(ScTabViewTarget);
     325             : }
     326             : 
     327             : /** show/hide outline over block marks */
     328          21 : ScUndoOutlineBlock::ScUndoOutlineBlock( ScDocShell* pNewDocShell,
     329             :                         SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
     330             :                         SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
     331             :                         ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab, bool bNewShow ) :
     332             :     ScSimpleUndo( pNewDocShell ),
     333             :     aBlockStart( nStartX, nStartY, nStartZ ),
     334             :     aBlockEnd( nEndX, nEndY, nEndZ ),
     335             :     pUndoDoc( pNewUndoDoc ),
     336             :     pUndoTable( pNewUndoTab ),
     337          21 :     bShow( bNewShow )
     338             : {
     339          21 : }
     340             : 
     341          63 : ScUndoOutlineBlock::~ScUndoOutlineBlock()
     342             : {
     343          21 :     delete pUndoDoc;
     344          21 :     delete pUndoTable;
     345          42 : }
     346             : 
     347          21 : OUString ScUndoOutlineBlock::GetComment() const
     348             : {   // "Show outline" "Hide outline"
     349             :     return bShow ?
     350             :         ScGlobal::GetRscString( STR_UNDO_DOOUTLINEBLK ) :
     351          21 :         ScGlobal::GetRscString( STR_UNDO_REDOOUTLINEBLK );
     352             : }
     353             : 
     354           0 : void ScUndoOutlineBlock::Undo()
     355             : {
     356           0 :     BeginUndo();
     357             : 
     358           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     359           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     360           0 :     SCTAB nTab = aBlockStart.Tab();
     361             : 
     362             :     //  Original Outline table
     363           0 :     pDoc->SetOutlineTable( nTab, pUndoTable );
     364             : 
     365             :     //  Original column/row status
     366           0 :     SCCOLROW    nStartCol = aBlockStart.Col();
     367           0 :     SCCOLROW    nEndCol = aBlockEnd.Col();
     368           0 :     SCCOLROW    nStartRow = aBlockStart.Row();
     369           0 :     SCCOLROW    nEndRow = aBlockEnd.Row();
     370             : 
     371           0 :     if (!bShow)
     372             :     {                               // Size of the hidden blocks
     373             :         size_t nLevel;
     374           0 :         pUndoTable->GetColArray()->FindTouchedLevel( nStartCol, nEndCol, nLevel );
     375           0 :         pUndoTable->GetColArray()->ExtendBlock( nLevel, nStartCol, nEndCol );
     376           0 :         pUndoTable->GetRowArray()->FindTouchedLevel( nStartRow, nEndRow, nLevel );
     377           0 :         pUndoTable->GetRowArray()->ExtendBlock( nLevel, nStartRow, nEndRow );
     378             :     }
     379             : 
     380             :     pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
     381           0 :             static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false, pDoc );
     382           0 :     pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
     383             : 
     384           0 :     pDoc->UpdatePageBreaks( nTab );
     385             : 
     386           0 :     pViewShell->UpdateScrollBars();
     387             : 
     388           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     389           0 :     if ( nVisTab != nTab )
     390           0 :         pViewShell->SetTabNo( nTab );
     391             : 
     392           0 :     pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
     393             : 
     394           0 :     EndUndo();
     395           0 : }
     396             : 
     397           0 : void ScUndoOutlineBlock::Redo()
     398             : {
     399           0 :     BeginRedo();
     400             : 
     401           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     402             : 
     403           0 :     ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
     404           0 :     if (bShow)
     405           0 :         pViewShell->ShowMarkedOutlines( false );
     406             :     else
     407           0 :         pViewShell->HideMarkedOutlines( false );
     408             : 
     409           0 :     EndRedo();
     410           0 : }
     411             : 
     412           0 : void ScUndoOutlineBlock::Repeat(SfxRepeatTarget& rTarget)
     413             : {
     414           0 :     if (rTarget.ISA(ScTabViewTarget))
     415             :     {
     416           0 :         ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
     417             : 
     418           0 :         if (bShow)
     419           0 :             rViewShell.ShowMarkedOutlines( true );
     420             :         else
     421           0 :             rViewShell.HideMarkedOutlines( true );
     422             :     }
     423           0 : }
     424             : 
     425           0 : bool ScUndoOutlineBlock::CanRepeat(SfxRepeatTarget& rTarget) const
     426             : {
     427           0 :     return rTarget.ISA(ScTabViewTarget);
     428             : }
     429             : 
     430           4 : ScUndoRemoveAllOutlines::ScUndoRemoveAllOutlines( ScDocShell* pNewDocShell,
     431             :                                     SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
     432             :                                     SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
     433             :                                     ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
     434             :     ScSimpleUndo( pNewDocShell ),
     435             :     aBlockStart( nStartX, nStartY, nStartZ ),
     436             :     aBlockEnd( nEndX, nEndY, nEndZ ),
     437             :     pUndoDoc( pNewUndoDoc ),
     438           4 :     pUndoTable( pNewUndoTab )
     439             : {
     440           4 : }
     441             : 
     442          12 : ScUndoRemoveAllOutlines::~ScUndoRemoveAllOutlines()
     443             : {
     444           4 :     delete pUndoDoc;
     445           4 :     delete pUndoTable;
     446           8 : }
     447             : 
     448           4 : OUString ScUndoRemoveAllOutlines::GetComment() const
     449             : {   // "Remove outlines"
     450           4 :     return ScGlobal::GetRscString( STR_UNDO_REMOVEALLOTLNS );
     451             : }
     452             : 
     453           0 : void ScUndoRemoveAllOutlines::Undo()
     454             : {
     455           0 :     BeginUndo();
     456             : 
     457           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     458           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     459           0 :     SCTAB nTab = aBlockStart.Tab();
     460             : 
     461             :     //  Original Outline table
     462           0 :     pDoc->SetOutlineTable( nTab, pUndoTable );
     463             : 
     464             :     //  Original column/row status
     465           0 :     SCCOL   nStartCol = aBlockStart.Col();
     466           0 :     SCCOL   nEndCol = aBlockEnd.Col();
     467           0 :     SCROW   nStartRow = aBlockStart.Row();
     468           0 :     SCROW   nEndRow = aBlockEnd.Row();
     469             : 
     470           0 :     pUndoDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, false, pDoc );
     471           0 :     pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
     472             : 
     473           0 :     pDoc->UpdatePageBreaks( nTab );
     474             : 
     475           0 :     pViewShell->UpdateScrollBars();
     476             : 
     477           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     478           0 :     if ( nVisTab != nTab )
     479           0 :         pViewShell->SetTabNo( nTab );
     480             : 
     481           0 :     pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
     482             : 
     483           0 :     EndUndo();
     484           0 : }
     485             : 
     486           0 : void ScUndoRemoveAllOutlines::Redo()
     487             : {
     488           0 :     BeginRedo();
     489             : 
     490           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     491             : 
     492             :     // sheet has to be switched over (#46952#)!
     493             : 
     494           0 :     SCTAB nTab = aBlockStart.Tab();
     495           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     496           0 :     if ( nVisTab != nTab )
     497           0 :         pViewShell->SetTabNo( nTab );
     498             : 
     499           0 :     pViewShell->RemoveAllOutlines( false );
     500             : 
     501           0 :     EndRedo();
     502           0 : }
     503             : 
     504           0 : void ScUndoRemoveAllOutlines::Repeat(SfxRepeatTarget& rTarget)
     505             : {
     506           0 :     if (rTarget.ISA(ScTabViewTarget))
     507           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->RemoveAllOutlines( true );
     508           0 : }
     509             : 
     510           0 : bool ScUndoRemoveAllOutlines::CanRepeat(SfxRepeatTarget& rTarget) const
     511             : {
     512           0 :     return rTarget.ISA(ScTabViewTarget);
     513             : }
     514             : 
     515           1 : ScUndoAutoOutline::ScUndoAutoOutline( ScDocShell* pNewDocShell,
     516             :                                     SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
     517             :                                     SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
     518             :                                     ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
     519             :     ScSimpleUndo( pNewDocShell ),
     520             :     aBlockStart( nStartX, nStartY, nStartZ ),
     521             :     aBlockEnd( nEndX, nEndY, nEndZ ),
     522             :     pUndoDoc( pNewUndoDoc ),
     523           1 :     pUndoTable( pNewUndoTab )
     524             : {
     525           1 : }
     526             : 
     527           3 : ScUndoAutoOutline::~ScUndoAutoOutline()
     528             : {
     529           1 :     delete pUndoDoc;
     530           1 :     delete pUndoTable;
     531           2 : }
     532             : 
     533           1 : OUString ScUndoAutoOutline::GetComment() const
     534             : {
     535           1 :     return ScGlobal::GetRscString( STR_UNDO_AUTOOUTLINE );
     536             : }
     537             : 
     538           0 : void ScUndoAutoOutline::Undo()
     539             : {
     540           0 :     BeginUndo();
     541             : 
     542           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     543           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     544           0 :     SCTAB nTab = aBlockStart.Tab();
     545             : 
     546             :     // Original outline table
     547           0 :     pDoc->SetOutlineTable( nTab, pUndoTable );
     548             : 
     549             :     // Original column/row status
     550           0 :     if (pUndoDoc && pUndoTable)
     551             :     {
     552             :         SCCOLROW nStartCol;
     553             :         SCCOLROW nStartRow;
     554             :         SCCOLROW nEndCol;
     555             :         SCCOLROW nEndRow;
     556           0 :         pUndoTable->GetColArray()->GetRange( nStartCol, nEndCol );
     557           0 :         pUndoTable->GetRowArray()->GetRange( nStartRow, nEndRow );
     558             : 
     559             :         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
     560             :                 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false,
     561           0 :                 pDoc);
     562           0 :         pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
     563             : 
     564           0 :         pViewShell->UpdateScrollBars();
     565             :     }
     566             : 
     567           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     568           0 :     if ( nVisTab != nTab )
     569           0 :         pViewShell->SetTabNo( nTab );
     570             : 
     571           0 :     pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
     572             : 
     573           0 :     EndUndo();
     574           0 : }
     575             : 
     576           0 : void ScUndoAutoOutline::Redo()
     577             : {
     578           0 :     BeginRedo();
     579             : 
     580           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     581             : 
     582           0 :     SCTAB nTab = aBlockStart.Tab();
     583           0 :     if (pViewShell)
     584             :     {
     585             :         // sheet has to be switched on or off before this (#46952#) !!!
     586             : 
     587           0 :         SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     588           0 :         if ( nVisTab != nTab )
     589           0 :             pViewShell->SetTabNo( nTab );
     590             :     }
     591             : 
     592           0 :     ScRange aRange( aBlockStart.Col(), aBlockStart.Row(), nTab,
     593           0 :                     aBlockEnd.Col(),   aBlockEnd.Row(),   nTab );
     594           0 :     ScOutlineDocFunc aFunc( *pDocShell );
     595           0 :     aFunc.AutoOutline( aRange, false );
     596             : 
     597             :     //  Select in View
     598             :     //  If it was called with a multi selection,
     599             :     //  then this is now the enclosing range...
     600             : 
     601           0 :     if (pViewShell)
     602           0 :         pViewShell->MarkRange( aRange );
     603             : 
     604           0 :     EndRedo();
     605           0 : }
     606             : 
     607           0 : void ScUndoAutoOutline::Repeat(SfxRepeatTarget& rTarget)
     608             : {
     609           0 :     if (rTarget.ISA(ScTabViewTarget))
     610           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->AutoOutline( true );
     611           0 : }
     612             : 
     613           0 : bool ScUndoAutoOutline::CanRepeat(SfxRepeatTarget& rTarget) const
     614             : {
     615           0 :     return rTarget.ISA(ScTabViewTarget);
     616             : }
     617             : 
     618           2 : ScUndoSubTotals::ScUndoSubTotals( ScDocShell* pNewDocShell, SCTAB nNewTab,
     619             :                                 const ScSubTotalParam& rNewParam, SCROW nNewEndY,
     620             :                                 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
     621             :                                 ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB ) :
     622             :     ScDBFuncUndo( pNewDocShell, ScRange( rNewParam.nCol1, rNewParam.nRow1, nNewTab,
     623             :                                          rNewParam.nCol2, rNewParam.nRow2, nNewTab ) ),
     624             :     nTab( nNewTab ),
     625             :     aParam( rNewParam ),
     626             :     nNewEndRow( nNewEndY ),
     627             :     pUndoDoc( pNewUndoDoc ),
     628             :     pUndoTable( pNewUndoTab ),
     629             :     pUndoRange( pNewUndoRange ),
     630           2 :     pUndoDB( pNewUndoDB )
     631             : {
     632           2 : }
     633             : 
     634           6 : ScUndoSubTotals::~ScUndoSubTotals()
     635             : {
     636           2 :     delete pUndoDoc;
     637           2 :     delete pUndoTable;
     638           2 :     delete pUndoRange;
     639           2 :     delete pUndoDB;
     640           4 : }
     641             : 
     642           2 : OUString ScUndoSubTotals::GetComment() const
     643             : {   // "Subtotals"
     644           2 :     return ScGlobal::GetRscString( STR_UNDO_SUBTOTALS );
     645             : }
     646             : 
     647           0 : void ScUndoSubTotals::Undo()
     648             : {
     649           0 :     BeginUndo();
     650             : 
     651           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     652           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     653             : 
     654           0 :     if (nNewEndRow > aParam.nRow2)
     655             :     {
     656           0 :         pDoc->DeleteRow( 0,nTab, MAXCOL,nTab, aParam.nRow2+1, static_cast<SCSIZE>(nNewEndRow-aParam.nRow2) );
     657             :     }
     658           0 :     else if (nNewEndRow < aParam.nRow2)
     659             :     {
     660           0 :         pDoc->InsertRow( 0,nTab, MAXCOL,nTab, nNewEndRow+1, static_cast<SCSIZE>(aParam.nRow2-nNewEndRow) );
     661             :     }
     662             : 
     663             : 
     664             :     // Original Outline table
     665           0 :     pDoc->SetOutlineTable( nTab, pUndoTable );
     666             : 
     667             :     // Original column/row status
     668           0 :     if (pUndoTable)
     669             :     {
     670             :         SCCOLROW nStartCol;
     671             :         SCCOLROW nStartRow;
     672             :         SCCOLROW nEndCol;
     673             :         SCCOLROW nEndRow;
     674           0 :         pUndoTable->GetColArray()->GetRange( nStartCol, nEndCol );
     675           0 :         pUndoTable->GetRowArray()->GetRange( nStartRow, nEndRow );
     676             : 
     677             :         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
     678             :                 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false,
     679           0 :                 pDoc);
     680           0 :         pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
     681             : 
     682           0 :         pViewShell->UpdateScrollBars();
     683             :     }
     684             : 
     685             :     //  Original data and references
     686             : 
     687             :     ScUndoUtil::MarkSimpleBlock( pDocShell, 0, aParam.nRow1+1, nTab,
     688           0 :                                             MAXCOL, aParam.nRow2, nTab );
     689             : 
     690           0 :     pDoc->DeleteAreaTab( 0,aParam.nRow1+1, MAXCOL,aParam.nRow2, nTab, IDF_ALL );
     691             : 
     692             :     pUndoDoc->CopyToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
     693           0 :                                                             IDF_NONE, false, pDoc );    // Flags
     694             :     pUndoDoc->UndoToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
     695           0 :                                                             IDF_ALL, false, pDoc );
     696             : 
     697             :     ScUndoUtil::MarkSimpleBlock( pDocShell, aParam.nCol1,aParam.nRow1,nTab,
     698           0 :                                             aParam.nCol2,aParam.nRow2,nTab );
     699             : 
     700           0 :     if (pUndoRange)
     701           0 :         pDoc->SetRangeName( new ScRangeName( *pUndoRange ) );
     702           0 :     if (pUndoDB)
     703           0 :         pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), true );
     704             : 
     705           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     706           0 :     if ( nVisTab != nTab )
     707           0 :         pViewShell->SetTabNo( nTab );
     708             : 
     709           0 :     pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
     710           0 :     pDocShell->PostDataChanged();
     711             : 
     712           0 :     EndUndo();
     713           0 : }
     714             : 
     715           0 : void ScUndoSubTotals::Redo()
     716             : {
     717           0 :     BeginRedo();
     718             : 
     719           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     720             : 
     721           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     722           0 :     if ( nVisTab != nTab )
     723           0 :         pViewShell->SetTabNo( nTab );
     724             : 
     725             :     ScUndoUtil::MarkSimpleBlock( pDocShell, aParam.nCol1,aParam.nRow1,nTab,
     726           0 :                                             aParam.nCol2,aParam.nRow2,nTab );
     727           0 :     pViewShell->DoSubTotals( aParam, false );
     728             : 
     729           0 :     EndRedo();
     730           0 : }
     731             : 
     732           0 : void ScUndoSubTotals::Repeat(SfxRepeatTarget& /* rTarget */)
     733             : {
     734           0 : }
     735             : 
     736           0 : bool ScUndoSubTotals::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     737             : {
     738           0 :     return false;     // is not possible due to column numbers
     739             : }
     740             : 
     741           4 : ScUndoSort::ScUndoSort( ScDocShell* pNewDocShell,
     742             :                         SCTAB nNewTab, const ScSortParam& rParam,
     743             :                         ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB,
     744             :                         const ScRange* pDest ) :
     745             :     ScDBFuncUndo( pNewDocShell, ScRange( rParam.nCol1, rParam.nRow1, nNewTab,
     746             :                                          rParam.nCol2, rParam.nRow2, nNewTab ) ),
     747             :     nTab( nNewTab ),
     748             :     aSortParam( rParam ),
     749             :     pUndoDoc( pNewUndoDoc ),
     750             :     pUndoDB( pNewUndoDB ),
     751           4 :     bDestArea( false )
     752             : {
     753           4 :     if ( pDest )
     754             :     {
     755           0 :         bDestArea = true;
     756           0 :         aDestRange = *pDest;
     757             :     }
     758           4 : }
     759             : 
     760          12 : ScUndoSort::~ScUndoSort()
     761             : {
     762           4 :     delete pUndoDoc;
     763           4 :     delete pUndoDB;
     764           8 : }
     765             : 
     766           4 : OUString ScUndoSort::GetComment() const
     767             : {
     768           4 :     return ScGlobal::GetRscString( STR_UNDO_SORT );
     769             : }
     770             : 
     771           0 : void ScUndoSort::Undo()
     772             : {
     773           0 :     BeginUndo();
     774             : 
     775           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     776           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     777             : 
     778           0 :     SCCOL nStartCol = aSortParam.nCol1;
     779           0 :     SCROW nStartRow = aSortParam.nRow1;
     780           0 :     SCCOL nEndCol    = aSortParam.nCol2;
     781           0 :     SCROW nEndRow    = aSortParam.nRow2;
     782           0 :     SCTAB nSortTab  = nTab;
     783           0 :     if ( !aSortParam.bInplace )
     784             :     {
     785           0 :         nStartCol = aSortParam.nDestCol;
     786           0 :         nStartRow = aSortParam.nDestRow;
     787           0 :         nEndCol   = nStartCol + ( aSortParam.nCol2 - aSortParam.nCol1 );
     788           0 :         nEndRow   = nStartRow + ( aSortParam.nRow2 - aSortParam.nRow1 );
     789           0 :         nSortTab  = aSortParam.nDestTab;
     790             :     }
     791             : 
     792             :     ScUndoUtil::MarkSimpleBlock( pDocShell, nStartCol, nStartRow, nSortTab,
     793           0 :                                  nEndCol, nEndRow, nSortTab );
     794             : 
     795             :     // do not delete/copy note captions, they are handled in drawing undo (ScDBFuncUndo::mpDrawUndo)
     796           0 :     pDoc->DeleteAreaTab( nStartCol,nStartRow, nEndCol,nEndRow, nSortTab, IDF_ALL|IDF_NOCAPTIONS );
     797             :     pUndoDoc->CopyToDocument( nStartCol, nStartRow, nSortTab, nEndCol, nEndRow, nSortTab,
     798           0 :                                 IDF_ALL|IDF_NOCAPTIONS, false, pDoc );
     799             : 
     800           0 :     if (bDestArea)
     801             :     {
     802             :         // do not delete/copy note captions, they are handled in drawing undo (ScDBFuncUndo::mpDrawUndo)
     803           0 :         pDoc->DeleteAreaTab( aDestRange, IDF_ALL|IDF_NOCAPTIONS );
     804           0 :         pUndoDoc->CopyToDocument( aDestRange, IDF_ALL|IDF_NOCAPTIONS, false, pDoc );
     805             :     }
     806             : 
     807             :     // Row heights always (due to automatic adjustment)
     808             :     // TODO change to use ScBlockUndo
     809             :     pUndoDoc->CopyToDocument( 0, nStartRow, nSortTab, MAXCOL, nEndRow, nSortTab,
     810           0 :                               IDF_NONE, false, pDoc );
     811             : 
     812           0 :     if (pUndoDB)
     813           0 :         pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), true );
     814             : 
     815           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     816           0 :     if ( nVisTab != nSortTab )
     817           0 :         pViewShell->SetTabNo( nSortTab );
     818             : 
     819           0 :     pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
     820           0 :     pDocShell->PostDataChanged();
     821             : 
     822           0 :     EndUndo();
     823           0 : }
     824             : 
     825           0 : void ScUndoSort::Redo()
     826             : {
     827           0 :     BeginRedo();
     828             : 
     829           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     830             : 
     831           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     832           0 :     if ( nVisTab != nTab )
     833           0 :         pViewShell->SetTabNo( nTab );
     834             : 
     835             :     pViewShell->MarkRange( ScRange( aSortParam.nCol1, aSortParam.nRow1, nTab,
     836           0 :                                       aSortParam.nCol2, aSortParam.nRow2, nTab ) );
     837             : 
     838           0 :     pViewShell->Sort( aSortParam, false );
     839             : 
     840             :     // Paint source range due to selection
     841           0 :     if ( !aSortParam.bInplace )
     842             :         pDocShell->PostPaint( aSortParam.nCol1, aSortParam.nRow1, nTab,
     843           0 :                               aSortParam.nCol2, aSortParam.nRow2, nTab, PAINT_GRID );
     844             : 
     845           0 :     EndRedo();
     846           0 : }
     847             : 
     848           0 : void ScUndoSort::Repeat(SfxRepeatTarget& /* rTarget */)
     849             : {
     850           0 : }
     851             : 
     852           0 : bool ScUndoSort::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     853             : {
     854           0 :     return false;    // does not work due to column numbers
     855             : }
     856             : 
     857           4 : ScUndoQuery::ScUndoQuery( ScDocShell* pNewDocShell, SCTAB nNewTab, const ScQueryParam& rParam,
     858             :                             ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB,
     859             :                             const ScRange* pOld, bool bSize, const ScRange* pAdvSrc ) :
     860             :     ScDBFuncUndo( pNewDocShell, ScRange( rParam.nCol1, rParam.nRow1, nNewTab,
     861             :                                          rParam.nCol2, rParam.nRow2, nNewTab ) ),
     862             :     pDrawUndo( NULL ),
     863             :     nTab( nNewTab ),
     864             :     aQueryParam( rParam ),
     865             :     pUndoDoc( pNewUndoDoc ),
     866             :     pUndoDB( pNewUndoDB ),
     867             :     bIsAdvanced( false ),
     868             :     bDestArea( false ),
     869           4 :     bDoSize( bSize )
     870             : {
     871           4 :     if ( pOld )
     872             :     {
     873           0 :         bDestArea = true;
     874           0 :         aOldDest = *pOld;
     875             :     }
     876           4 :     if ( pAdvSrc )
     877             :     {
     878           0 :         bIsAdvanced = true;
     879           0 :         aAdvSource = *pAdvSrc;
     880             :     }
     881             : 
     882           4 :     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
     883           4 : }
     884             : 
     885          12 : ScUndoQuery::~ScUndoQuery()
     886             : {
     887           4 :     delete pUndoDoc;
     888           4 :     delete pUndoDB;
     889           4 :     DeleteSdrUndoAction( pDrawUndo );
     890           8 : }
     891             : 
     892           4 : OUString ScUndoQuery::GetComment() const
     893             : {   // "Filter";
     894           4 :     return ScGlobal::GetRscString( STR_UNDO_QUERY );
     895             : }
     896             : 
     897           0 : void ScUndoQuery::Undo()
     898             : {
     899           0 :     BeginUndo();
     900             : 
     901           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     902           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     903             : 
     904           0 :     bool bCopy = !aQueryParam.bInplace;
     905           0 :     SCCOL nDestEndCol = 0;
     906           0 :     SCROW nDestEndRow = 0;
     907           0 :     if (bCopy)
     908             :     {
     909           0 :         nDestEndCol = aQueryParam.nDestCol + ( aQueryParam.nCol2-aQueryParam.nCol1 );
     910           0 :         nDestEndRow = aQueryParam.nDestRow + ( aQueryParam.nRow2-aQueryParam.nRow1 );
     911             : 
     912             :         ScDBData* pData = pDoc->GetDBAtCursor( aQueryParam.nDestCol, aQueryParam.nDestRow,
     913           0 :                                                 aQueryParam.nDestTab, true );
     914           0 :         if (pData)
     915             :         {
     916           0 :             ScRange aNewDest;
     917           0 :             pData->GetArea( aNewDest );
     918           0 :             nDestEndCol = aNewDest.aEnd.Col();
     919           0 :             nDestEndRow = aNewDest.aEnd.Row();
     920             :         }
     921             : 
     922           0 :         if ( bDoSize && bDestArea )
     923             :         {
     924             :             //  aDestRange is the old range
     925             :             pDoc->FitBlock( ScRange(
     926             :                                 aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
     927             :                                 nDestEndCol, nDestEndRow, aQueryParam.nDestTab ),
     928           0 :                             aOldDest );
     929             :         }
     930             : 
     931             :         ScUndoUtil::MarkSimpleBlock( pDocShell,
     932             :                                     aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
     933           0 :                                     nDestEndCol, nDestEndRow, aQueryParam.nDestTab );
     934             :         pDoc->DeleteAreaTab( aQueryParam.nDestCol, aQueryParam.nDestRow,
     935           0 :                             nDestEndCol, nDestEndRow, aQueryParam.nDestTab, IDF_ALL );
     936             : 
     937           0 :         pViewShell->DoneBlockMode();
     938             : 
     939             :         pUndoDoc->CopyToDocument( aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
     940             :                                     nDestEndCol, nDestEndRow, aQueryParam.nDestTab,
     941           0 :                                     IDF_ALL, false, pDoc );
     942             :         //  Attributes are always copied (#49287#)
     943             : 
     944             :         // rest of the old range
     945           0 :         if ( bDestArea && !bDoSize )
     946             :         {
     947           0 :             pDoc->DeleteAreaTab( aOldDest, IDF_ALL );
     948           0 :             pUndoDoc->CopyToDocument( aOldDest, IDF_ALL, false, pDoc );
     949             :         }
     950             :     }
     951             :     else
     952             :         pUndoDoc->CopyToDocument( 0, aQueryParam.nRow1, nTab, MAXCOL, aQueryParam.nRow2, nTab,
     953           0 :                                         IDF_NONE, false, pDoc );
     954             : 
     955           0 :     if (pUndoDB)
     956           0 :         pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), true );
     957             : 
     958           0 :     if (!bCopy)
     959             :     {
     960           0 :         pDoc->InvalidatePageBreaks(nTab);
     961           0 :         pDoc->UpdatePageBreaks( nTab );
     962             :     }
     963             : 
     964             :     ScRange aDirtyRange( 0 , aQueryParam.nRow1, nTab,
     965           0 :         MAXCOL, aQueryParam.nRow2, nTab );
     966           0 :     pDoc->SetDirty( aDirtyRange );
     967             : 
     968           0 :     DoSdrUndoAction( pDrawUndo, pDoc );
     969             : 
     970           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
     971           0 :     if ( nVisTab != nTab )
     972           0 :         pViewShell->SetTabNo( nTab );
     973             : 
     974             :         //  Paint
     975             : 
     976           0 :     if (bCopy)
     977             :     {
     978           0 :         SCCOL nEndX = nDestEndCol;
     979           0 :         SCROW nEndY = nDestEndRow;
     980           0 :         if (bDestArea)
     981             :         {
     982           0 :             if ( aOldDest.aEnd.Col() > nEndX )
     983           0 :                 nEndX = aOldDest.aEnd.Col();
     984           0 :             if ( aOldDest.aEnd.Row() > nEndY )
     985           0 :                 nEndY = aOldDest.aEnd.Row();
     986             :         }
     987           0 :         if (bDoSize)
     988           0 :             nEndY = MAXROW;
     989             :         pDocShell->PostPaint( aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
     990           0 :                                     nEndX, nEndY, aQueryParam.nDestTab, PAINT_GRID );
     991             :     }
     992             :     else
     993             :         pDocShell->PostPaint( 0, aQueryParam.nRow1, nTab, MAXCOL, MAXROW, nTab,
     994           0 :                                                     PAINT_GRID | PAINT_LEFT );
     995           0 :     pDocShell->PostDataChanged();
     996             : 
     997           0 :     EndUndo();
     998           0 : }
     999             : 
    1000           0 : void ScUndoQuery::Redo()
    1001             : {
    1002           0 :     BeginRedo();
    1003             : 
    1004           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1005             : 
    1006           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
    1007           0 :     if ( nVisTab != nTab )
    1008           0 :         pViewShell->SetTabNo( nTab );
    1009             : 
    1010           0 :     if ( bIsAdvanced )
    1011           0 :         pViewShell->Query( aQueryParam, &aAdvSource, false );
    1012             :     else
    1013           0 :         pViewShell->Query( aQueryParam, NULL, false );
    1014             : 
    1015           0 :     EndRedo();
    1016           0 : }
    1017             : 
    1018           0 : void ScUndoQuery::Repeat(SfxRepeatTarget& /* rTarget */)
    1019             : {
    1020           0 : }
    1021             : 
    1022           0 : bool ScUndoQuery::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1023             : {
    1024           0 :     return false;    // does not work due to column numbers
    1025             : }
    1026             : 
    1027             : //      Show or hide AutoFilter buttons (doesn't include filter settings)
    1028             : 
    1029           0 : ScUndoAutoFilter::ScUndoAutoFilter( ScDocShell* pNewDocShell, const ScRange& rRange,
    1030             :                                     const OUString& rName, bool bSet ) :
    1031             :     ScDBFuncUndo( pNewDocShell, rRange ),
    1032             :     aDBName( rName ),
    1033           0 :     bFilterSet( bSet )
    1034             : {
    1035           0 : }
    1036             : 
    1037           0 : ScUndoAutoFilter::~ScUndoAutoFilter()
    1038             : {
    1039           0 : }
    1040             : 
    1041           0 : OUString ScUndoAutoFilter::GetComment() const
    1042             : {
    1043           0 :     return ScGlobal::GetRscString( STR_UNDO_QUERY );    // same as ScUndoQuery
    1044             : }
    1045             : 
    1046           0 : void ScUndoAutoFilter::DoChange( bool bUndo )
    1047             : {
    1048           0 :     bool bNewFilter = bUndo ? !bFilterSet : bFilterSet;
    1049             : 
    1050           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1051           0 :     ScDBData* pDBData=NULL;
    1052           0 :     if (aDBName.equalsAscii(STR_DB_LOCAL_NONAME))
    1053             :     {
    1054           0 :         SCTAB nTab = aOriginalRange.aStart.Tab();
    1055           0 :         pDBData = pDoc->GetAnonymousDBData(nTab);
    1056             :     }
    1057             :     else
    1058             :     {
    1059           0 :         ScDBCollection* pColl = pDoc->GetDBCollection();
    1060           0 :         pDBData = pColl->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(aDBName));
    1061             :     }
    1062             : 
    1063           0 :     if ( pDBData )
    1064             :     {
    1065           0 :         pDBData->SetAutoFilter( bNewFilter );
    1066             : 
    1067             :         SCCOL nRangeX1;
    1068             :         SCROW nRangeY1;
    1069             :         SCCOL nRangeX2;
    1070             :         SCROW nRangeY2;
    1071             :         SCTAB nRangeTab;
    1072           0 :         pDBData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
    1073             : 
    1074           0 :         if ( bNewFilter )
    1075           0 :             pDoc->ApplyFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
    1076             :         else
    1077           0 :             pDoc->RemoveFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
    1078             : 
    1079           0 :         pDocShell->PostPaint( nRangeX1, nRangeY1, nRangeTab, nRangeX2, nRangeY1, nRangeTab, PAINT_GRID );
    1080             :     }
    1081           0 : }
    1082             : 
    1083           0 : void ScUndoAutoFilter::Undo()
    1084             : {
    1085           0 :     BeginUndo();
    1086           0 :     DoChange( true );
    1087           0 :     EndUndo();
    1088           0 : }
    1089             : 
    1090           0 : void ScUndoAutoFilter::Redo()
    1091             : {
    1092           0 :     BeginRedo();
    1093           0 :     DoChange( false );
    1094           0 :     EndRedo();
    1095           0 : }
    1096             : 
    1097           0 : void ScUndoAutoFilter::Repeat(SfxRepeatTarget& /* rTarget */)
    1098             : {
    1099           0 : }
    1100             : 
    1101           0 : bool ScUndoAutoFilter::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1102             : {
    1103           0 :     return false;
    1104             : }
    1105             : 
    1106             : // change database sections (dialog)
    1107          47 : ScUndoDBData::ScUndoDBData( ScDocShell* pNewDocShell,
    1108             :                             ScDBCollection* pNewUndoColl, ScDBCollection* pNewRedoColl ) :
    1109             :     ScSimpleUndo( pNewDocShell ),
    1110             :     pUndoColl( pNewUndoColl ),
    1111          47 :     pRedoColl( pNewRedoColl )
    1112             : {
    1113          47 : }
    1114             : 
    1115         141 : ScUndoDBData::~ScUndoDBData()
    1116             : {
    1117          47 :     delete pUndoColl;
    1118          47 :     delete pRedoColl;
    1119          94 : }
    1120             : 
    1121          47 : OUString ScUndoDBData::GetComment() const
    1122             : {   // "Change database range";
    1123          47 :     return ScGlobal::GetRscString( STR_UNDO_DBDATA );
    1124             : }
    1125             : 
    1126           0 : void ScUndoDBData::Undo()
    1127             : {
    1128           0 :     BeginUndo();
    1129             : 
    1130           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1131             : 
    1132           0 :     bool bOldAutoCalc = pDoc->GetAutoCalc();
    1133           0 :     pDoc->SetAutoCalc( false );         // Avoid unnecessary calculations
    1134           0 :     pDoc->CompileDBFormula( true );     // CreateFormulaString
    1135           0 :     pDoc->SetDBCollection( new ScDBCollection(*pUndoColl), true );
    1136           0 :     pDoc->CompileDBFormula( false );    // CompileFormulaString
    1137           0 :     pDoc->SetAutoCalc( bOldAutoCalc );
    1138             : 
    1139           0 :     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
    1140             : 
    1141           0 :     EndUndo();
    1142           0 : }
    1143             : 
    1144           0 : void ScUndoDBData::Redo()
    1145             : {
    1146           0 :     BeginRedo();
    1147             : 
    1148           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1149             : 
    1150           0 :     bool bOldAutoCalc = pDoc->GetAutoCalc();
    1151           0 :     pDoc->SetAutoCalc( false );         // Avoid unnecessary calculations
    1152           0 :     pDoc->CompileDBFormula( true );     // CreateFormulaString
    1153           0 :     pDoc->SetDBCollection( new ScDBCollection(*pRedoColl), true );
    1154           0 :     pDoc->CompileDBFormula( false );    // CompileFormulaString
    1155           0 :     pDoc->SetAutoCalc( bOldAutoCalc );
    1156             : 
    1157           0 :     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
    1158             : 
    1159           0 :     EndRedo();
    1160           0 : }
    1161             : 
    1162           0 : void ScUndoDBData::Repeat(SfxRepeatTarget& /* rTarget */)
    1163             : {
    1164           0 : }
    1165             : 
    1166           0 : bool ScUndoDBData::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1167             : {
    1168           0 :     return false;    // is not possible
    1169             : }
    1170             : 
    1171           4 : ScUndoImportData::ScUndoImportData( ScDocShell* pNewDocShell, SCTAB nNewTab,
    1172             :                                 const ScImportParam& rParam, SCCOL nNewEndX, SCROW nNewEndY,
    1173             :                                 SCCOL nNewFormula,
    1174             :                                 ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
    1175             :                                 ScDBData* pNewUndoData, ScDBData* pNewRedoData ) :
    1176             :     ScSimpleUndo( pNewDocShell ),
    1177             :     nTab( nNewTab ),
    1178             :     aImportParam( rParam ),
    1179             :     nEndCol( nNewEndX ),
    1180             :     nEndRow( nNewEndY ),
    1181             :     pUndoDoc( pNewUndoDoc ),
    1182             :     pRedoDoc( pNewRedoDoc ),
    1183             :     pUndoDBData( pNewUndoData ),
    1184             :     pRedoDBData( pNewRedoData ),
    1185             :     nFormulaCols( nNewFormula ),
    1186           4 :     bRedoFilled( false )
    1187             : {
    1188             :     // redo doc doesn't contain imported data (but everything else)
    1189           4 : }
    1190             : 
    1191          12 : ScUndoImportData::~ScUndoImportData()
    1192             : {
    1193           4 :     delete pUndoDoc;
    1194           4 :     delete pRedoDoc;
    1195           4 :     delete pUndoDBData;
    1196           4 :     delete pRedoDBData;
    1197           8 : }
    1198             : 
    1199           4 : OUString ScUndoImportData::GetComment() const
    1200             : {
    1201           4 :     return ScGlobal::GetRscString( STR_UNDO_IMPORTDATA );
    1202             : }
    1203             : 
    1204           0 : void ScUndoImportData::Undo()
    1205             : {
    1206           0 :     BeginUndo();
    1207             : 
    1208           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1209           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1210             : 
    1211             :     ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab,
    1212           0 :                                                         nEndCol,nEndRow,nTab );
    1213             : 
    1214             :     SCTAB nTable;
    1215             :     SCCOL nCol1, nCol2;
    1216             :     SCROW nRow1, nRow2;
    1217           0 :     ScDBData* pCurrentData = NULL;
    1218           0 :     if (pUndoDBData && pRedoDBData)
    1219             :     {
    1220           0 :         pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
    1221             :         pCurrentData = ScUndoUtil::GetOldDBData( pRedoDBData, pDoc, nTab,
    1222           0 :                                                     nCol1, nRow1, nCol2, nRow2 );
    1223             : 
    1224           0 :         if ( !bRedoFilled )
    1225             :         {
    1226             :             //  read redo data from document at first undo
    1227             :             //  imported data is deleted later anyway,
    1228             :             //  so now delete each column after copying to save memory (#41216#)
    1229             : 
    1230           0 :             bool bOldAutoCalc = pDoc->GetAutoCalc();
    1231           0 :             pDoc->SetAutoCalc( false );             // outside of the loop
    1232           0 :             for (SCCOL nCopyCol = nCol1; nCopyCol <= nCol2; nCopyCol++)
    1233             :             {
    1234             :                 pDoc->CopyToDocument( nCopyCol,nRow1,nTab, nCopyCol,nRow2,nTab,
    1235           0 :                                         IDF_CONTENTS & ~IDF_NOTE, false, pRedoDoc );
    1236           0 :                 pDoc->DeleteAreaTab( nCopyCol,nRow1, nCopyCol,nRow2, nTab, IDF_CONTENTS & ~IDF_NOTE );
    1237             :             }
    1238           0 :             pDoc->SetAutoCalc( bOldAutoCalc );
    1239           0 :             bRedoFilled = true;
    1240             :         }
    1241             :     }
    1242           0 :     bool bMoveCells = pUndoDBData && pRedoDBData &&
    1243           0 :                         pRedoDBData->IsDoSize();        // the same in old and new
    1244           0 :     if (bMoveCells)
    1245             :     {
    1246             :         //  Undo: first delete the new data, then FitBlock backwards
    1247             : 
    1248           0 :         ScRange aOld, aNew;
    1249           0 :         pUndoDBData->GetArea( aOld );
    1250           0 :         pRedoDBData->GetArea( aNew );
    1251             : 
    1252           0 :         pDoc->DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
    1253           0 :                                 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, IDF_ALL & ~IDF_NOTE );
    1254             : 
    1255           0 :         aOld.aEnd.SetCol( aOld.aEnd.Col() + nFormulaCols );     // FitBlock also for formulas
    1256           0 :         aNew.aEnd.SetCol( aNew.aEnd.Col() + nFormulaCols );
    1257           0 :         pDoc->FitBlock( aNew, aOld, false );                    // backwards
    1258             :     }
    1259             :     else
    1260             :         pDoc->DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
    1261           0 :                                 nEndCol,nEndRow, nTab, IDF_ALL & ~IDF_NOTE );
    1262             : 
    1263             :     pUndoDoc->CopyToDocument( aImportParam.nCol1,aImportParam.nRow1,nTab,
    1264             :                                 nEndCol+nFormulaCols,nEndRow,nTab,
    1265           0 :                                 IDF_ALL & ~IDF_NOTE, false, pDoc );
    1266             : 
    1267           0 :     if (pCurrentData)
    1268             :     {
    1269           0 :         *pCurrentData = *pUndoDBData;
    1270             : 
    1271           0 :         pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
    1272           0 :         ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
    1273             :     }
    1274             : 
    1275           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
    1276           0 :     if ( nVisTab != nTab )
    1277           0 :         pViewShell->SetTabNo( nTab );
    1278             : 
    1279           0 :     if (bMoveCells)
    1280           0 :         pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
    1281             :     else
    1282             :         pDocShell->PostPaint( aImportParam.nCol1,aImportParam.nRow1,nTab,
    1283           0 :                                 nEndCol,nEndRow,nTab, PAINT_GRID );
    1284           0 :     pDocShell->PostDataChanged();
    1285             : 
    1286           0 :     EndUndo();
    1287           0 : }
    1288             : 
    1289           0 : void ScUndoImportData::Redo()
    1290             : {
    1291           0 :     BeginRedo();
    1292             : 
    1293           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1294           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1295             : 
    1296             :     ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab,
    1297           0 :                                                         nEndCol,nEndRow,nTab );
    1298             : 
    1299             :     SCTAB nTable;
    1300             :     SCCOL nCol1, nCol2;
    1301             :     SCROW nRow1, nRow2;
    1302           0 :     ScDBData* pCurrentData = NULL;
    1303           0 :     if (pUndoDBData && pRedoDBData)
    1304             :     {
    1305           0 :         pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
    1306             :         pCurrentData = ScUndoUtil::GetOldDBData( pUndoDBData, pDoc, nTab,
    1307           0 :                                                     nCol1, nRow1, nCol2, nRow2 );
    1308             :     }
    1309           0 :     bool bMoveCells = pUndoDBData && pRedoDBData &&
    1310           0 :                         pRedoDBData->IsDoSize();        // // the same in old and new
    1311           0 :     if (bMoveCells)
    1312             :     {
    1313             :         //  Redo: FitBlock, then delete data (needed for CopyToDocument)
    1314             : 
    1315           0 :         ScRange aOld, aNew;
    1316           0 :         pUndoDBData->GetArea( aOld );
    1317           0 :         pRedoDBData->GetArea( aNew );
    1318             : 
    1319           0 :         aOld.aEnd.SetCol( aOld.aEnd.Col() + nFormulaCols );     // FitBlock also for formulas
    1320           0 :         aNew.aEnd.SetCol( aNew.aEnd.Col() + nFormulaCols );
    1321           0 :         pDoc->FitBlock( aOld, aNew );
    1322             : 
    1323           0 :         pDoc->DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
    1324           0 :                                 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, IDF_ALL & ~IDF_NOTE );
    1325             : 
    1326           0 :         pRedoDoc->CopyToDocument( aNew, IDF_ALL & ~IDF_NOTE, false, pDoc );        // including formulas
    1327             :     }
    1328             :     else
    1329             :     {
    1330             :         pDoc->DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
    1331           0 :                                 nEndCol,nEndRow, nTab, IDF_ALL & ~IDF_NOTE );
    1332             :         pRedoDoc->CopyToDocument( aImportParam.nCol1,aImportParam.nRow1,nTab,
    1333           0 :                                 nEndCol,nEndRow,nTab, IDF_ALL & ~IDF_NOTE, false, pDoc );
    1334             :     }
    1335             : 
    1336           0 :     if (pCurrentData)
    1337             :     {
    1338           0 :         *pCurrentData = *pRedoDBData;
    1339             : 
    1340           0 :         pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
    1341           0 :         ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
    1342             :     }
    1343             : 
    1344           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
    1345           0 :     if ( nVisTab != nTab )
    1346           0 :         pViewShell->SetTabNo( nTab );
    1347             : 
    1348           0 :     if (bMoveCells)
    1349           0 :         pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
    1350             :     else
    1351             :         pDocShell->PostPaint( aImportParam.nCol1,aImportParam.nRow1,nTab,
    1352           0 :                                 nEndCol,nEndRow,nTab, PAINT_GRID );
    1353           0 :     pDocShell->PostDataChanged();
    1354             : 
    1355           0 :     EndRedo();
    1356           0 : }
    1357             : 
    1358           0 : void ScUndoImportData::Repeat(SfxRepeatTarget& rTarget)
    1359             : {
    1360           0 :     if (rTarget.ISA(ScTabViewTarget))
    1361             :     {
    1362           0 :         ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
    1363             : 
    1364             :         SCTAB nDummy;
    1365           0 :         ScImportParam aNewParam(aImportParam);
    1366           0 :         ScDBData* pDBData = rViewShell.GetDBData();
    1367           0 :         pDBData->GetArea( nDummy, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
    1368             : 
    1369           0 :         rViewShell.ImportData( aNewParam );
    1370             :     }
    1371           0 : }
    1372             : 
    1373           0 : bool ScUndoImportData::CanRepeat(SfxRepeatTarget& rTarget) const
    1374             : {
    1375             :     //  Repeat only for import using a database range, then pUndoDBData is set
    1376             : 
    1377           0 :     if (pUndoDBData)
    1378           0 :         return rTarget.ISA(ScTabViewTarget);
    1379             :     else
    1380           0 :         return false;       // Address book
    1381             : }
    1382             : 
    1383             : 
    1384          10 : ScUndoRepeatDB::ScUndoRepeatDB( ScDocShell* pNewDocShell, SCTAB nNewTab,
    1385             :                                 SCCOL nStartX, SCROW nStartY, SCCOL nEndX, SCROW nEndY,
    1386             :                                 SCROW nResultEndRow, SCCOL nCurX, SCROW nCurY,
    1387             :                                 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
    1388             :                                 ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB,
    1389             :                                 const ScRange* pOldQ, const ScRange* pNewQ ) :
    1390             :     ScSimpleUndo( pNewDocShell ),
    1391             :     aBlockStart( nStartX,nStartY,nNewTab ),
    1392             :     aBlockEnd( nEndX,nEndY,nNewTab ),
    1393             :     nNewEndRow( nResultEndRow ),
    1394             :     aCursorPos( nCurX,nCurY,nNewTab ),
    1395             :     pUndoDoc( pNewUndoDoc ),
    1396             :     pUndoTable( pNewUndoTab ),
    1397             :     pUndoRange( pNewUndoRange ),
    1398             :     pUndoDB( pNewUndoDB ),
    1399          10 :     bQuerySize( false )
    1400             : {
    1401          10 :     if ( pOldQ && pNewQ )
    1402             :     {
    1403           0 :         aOldQuery = *pOldQ;
    1404           0 :         aNewQuery = *pNewQ;
    1405           0 :         bQuerySize = true;
    1406             :     }
    1407          10 : }
    1408             : 
    1409          30 : ScUndoRepeatDB::~ScUndoRepeatDB()
    1410             : {
    1411          10 :     delete pUndoDoc;
    1412          10 :     delete pUndoTable;
    1413          10 :     delete pUndoRange;
    1414          10 :     delete pUndoDB;
    1415          20 : }
    1416             : 
    1417          10 : OUString ScUndoRepeatDB::GetComment() const
    1418             : {
    1419          10 :     return ScGlobal::GetRscString( STR_UNDO_REPEATDB );
    1420             : }
    1421             : 
    1422           0 : void ScUndoRepeatDB::Undo()
    1423             : {
    1424           0 :     BeginUndo();
    1425             : 
    1426           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1427           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1428           0 :     SCTAB nTab = aBlockStart.Tab();
    1429             : 
    1430           0 :     if (bQuerySize)
    1431             :     {
    1432           0 :         pDoc->FitBlock( aNewQuery, aOldQuery, false );
    1433             : 
    1434           0 :         if ( aNewQuery.aEnd.Col() == aOldQuery.aEnd.Col() )
    1435             :         {
    1436           0 :             SCCOL nFormulaCols = 0;
    1437           0 :             SCCOL nCol = aOldQuery.aEnd.Col() + 1;
    1438           0 :             SCROW nRow = aOldQuery.aStart.Row() + 1;        // test the header
    1439           0 :             while ( nCol <= MAXCOL &&
    1440           0 :                     pDoc->GetCellType(ScAddress( nCol, nRow, nTab )) == CELLTYPE_FORMULA )
    1441           0 :                 ++nCol, ++nFormulaCols;
    1442             : 
    1443           0 :             if ( nFormulaCols > 0 )
    1444             :             {
    1445           0 :                 ScRange aOldForm = aOldQuery;
    1446           0 :                 aOldForm.aStart.SetCol( aOldQuery.aEnd.Col() + 1 );
    1447           0 :                 aOldForm.aEnd.SetCol( aOldQuery.aEnd.Col() + nFormulaCols );
    1448           0 :                 ScRange aNewForm = aOldForm;
    1449           0 :                 aNewForm.aEnd.SetRow( aNewQuery.aEnd.Row() );
    1450           0 :                 pDoc->FitBlock( aNewForm, aOldForm, false );
    1451             :             }
    1452             :         }
    1453             :     }
    1454             : 
    1455             :     // TODO Data from Filter in other range are still missing!
    1456             : 
    1457           0 :     if (nNewEndRow > aBlockEnd.Row())
    1458             :     {
    1459           0 :         pDoc->DeleteRow( 0,nTab, MAXCOL,nTab, aBlockEnd.Row()+1, static_cast<SCSIZE>(nNewEndRow-aBlockEnd.Row()) );
    1460             :     }
    1461           0 :     else if (nNewEndRow < aBlockEnd.Row())
    1462             :     {
    1463           0 :         pDoc->InsertRow( 0,nTab, MAXCOL,nTab, nNewEndRow+1, static_cast<SCSIZE>(nNewEndRow-aBlockEnd.Row()) );
    1464             :     }
    1465             : 
    1466             :     // Original Outline table
    1467           0 :     pDoc->SetOutlineTable( nTab, pUndoTable );
    1468             : 
    1469             :     // Original column/row status
    1470           0 :     if (pUndoTable)
    1471             :     {
    1472             :         SCCOLROW nStartCol;
    1473             :         SCCOLROW nStartRow;
    1474             :         SCCOLROW nEndCol;
    1475             :         SCCOLROW nEndRow;
    1476           0 :         pUndoTable->GetColArray()->GetRange( nStartCol, nEndCol );
    1477           0 :         pUndoTable->GetRowArray()->GetRange( nStartRow, nEndRow );
    1478             : 
    1479             :         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
    1480             :                 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, false,
    1481           0 :                 pDoc );
    1482           0 :         pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, false, pDoc );
    1483             : 
    1484           0 :         pViewShell->UpdateScrollBars();
    1485             :     }
    1486             : 
    1487             :     //  Original data and references
    1488             :     ScUndoUtil::MarkSimpleBlock( pDocShell, 0, aBlockStart.Row(), nTab,
    1489           0 :                                             MAXCOL, aBlockEnd.Row(), nTab );
    1490             :     pDoc->DeleteAreaTab( 0, aBlockStart.Row(),
    1491           0 :                             MAXCOL, aBlockEnd.Row(), nTab, IDF_ALL );
    1492             : 
    1493             :     pUndoDoc->CopyToDocument( 0, aBlockStart.Row(), nTab, MAXCOL, aBlockEnd.Row(), nTab,
    1494           0 :                                                             IDF_NONE, false, pDoc );            // Flags
    1495             :     pUndoDoc->UndoToDocument( 0, aBlockStart.Row(), nTab, MAXCOL, aBlockEnd.Row(), nTab,
    1496           0 :                                                             IDF_ALL, false, pDoc );
    1497             : 
    1498           0 :     ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart.Col(),aBlockStart.Row(),nTab,
    1499           0 :                                             aBlockEnd.Col(),aBlockEnd.Row(),nTab );
    1500             : 
    1501           0 :     if (pUndoRange)
    1502           0 :         pDoc->SetRangeName( new ScRangeName( *pUndoRange ) );
    1503           0 :     if (pUndoDB)
    1504           0 :         pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), true );
    1505             : 
    1506           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
    1507           0 :     if ( nVisTab != nTab )
    1508           0 :         pViewShell->SetTabNo( nTab );
    1509             : 
    1510           0 :     pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
    1511           0 :     pDocShell->PostDataChanged();
    1512             : 
    1513           0 :     EndUndo();
    1514           0 : }
    1515             : 
    1516           0 : void ScUndoRepeatDB::Redo()
    1517             : {
    1518           0 :     BeginRedo();
    1519             : 
    1520           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1521           0 :     SCTAB nTab = aBlockStart.Tab();
    1522             : 
    1523           0 :     SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
    1524           0 :     if ( nVisTab != nTab )
    1525           0 :         pViewShell->SetTabNo( nTab );
    1526             : 
    1527           0 :     ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart.Col(),aBlockStart.Row(),nTab,
    1528           0 :                                             aBlockEnd.Col(),aBlockEnd.Row(),nTab );
    1529           0 :     pViewShell->SetCursor( aCursorPos.Col(), aCursorPos.Row() );
    1530             : 
    1531           0 :     pViewShell->RepeatDB( false );
    1532             : 
    1533           0 :     EndRedo();
    1534           0 : }
    1535             : 
    1536           0 : void ScUndoRepeatDB::Repeat(SfxRepeatTarget& rTarget)
    1537             : {
    1538           0 :     if (rTarget.ISA(ScTabViewTarget))
    1539           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->RepeatDB( true );
    1540           0 : }
    1541             : 
    1542           0 : bool ScUndoRepeatDB::CanRepeat(SfxRepeatTarget& rTarget) const
    1543             : {
    1544           0 :     return rTarget.ISA(ScTabViewTarget);
    1545             : }
    1546             : 
    1547          39 : ScUndoDataPilot::ScUndoDataPilot( ScDocShell* pNewDocShell,
    1548             :                             ScDocument* pOldDoc, ScDocument* pNewDoc,
    1549             :                             const ScDPObject* pOldObj, const ScDPObject* pNewObj, bool bMove ) :
    1550             :     ScSimpleUndo( pNewDocShell ),
    1551             :     pOldUndoDoc( pOldDoc ),
    1552             :     pNewUndoDoc( pNewDoc ),
    1553             :     pOldDPObject( NULL ),
    1554             :     pNewDPObject( NULL ),
    1555          39 :     bAllowMove( bMove )
    1556             : {
    1557          39 :     if (pOldObj)
    1558          22 :         pOldDPObject = new ScDPObject( *pOldObj );
    1559          39 :     if (pNewObj)
    1560          38 :         pNewDPObject = new ScDPObject( *pNewObj );
    1561          39 : }
    1562             : 
    1563         117 : ScUndoDataPilot::~ScUndoDataPilot()
    1564             : {
    1565          39 :     delete pOldDPObject;
    1566          39 :     delete pNewDPObject;
    1567          39 :     delete pOldUndoDoc;
    1568          39 :     delete pNewUndoDoc;
    1569          78 : }
    1570             : 
    1571          47 : OUString ScUndoDataPilot::GetComment() const
    1572             : {
    1573             :     sal_uInt16 nIndex;
    1574          47 :     if ( pOldUndoDoc && pNewUndoDoc )
    1575          21 :         nIndex = STR_UNDO_PIVOT_MODIFY;
    1576          26 :     else if ( pNewUndoDoc )
    1577          25 :         nIndex = STR_UNDO_PIVOT_NEW;
    1578             :     else
    1579           1 :         nIndex = STR_UNDO_PIVOT_DELETE;
    1580             : 
    1581          47 :     return ScGlobal::GetRscString( nIndex );
    1582             : }
    1583             : 
    1584           0 : void ScUndoDataPilot::Undo()
    1585             : {
    1586           0 :     BeginUndo();
    1587             : 
    1588           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1589             : 
    1590           0 :     ScRange aOldRange;
    1591           0 :     ScRange aNewRange;
    1592             : 
    1593           0 :     if ( pNewDPObject && pNewUndoDoc )
    1594             :     {
    1595           0 :         aNewRange = pNewDPObject->GetOutRange();
    1596           0 :         pDoc->DeleteAreaTab( aNewRange, IDF_ALL );
    1597           0 :         pNewUndoDoc->CopyToDocument( aNewRange, IDF_ALL, false, pDoc );
    1598             :     }
    1599           0 :     if ( pOldDPObject && pOldUndoDoc )
    1600             :     {
    1601           0 :         aOldRange = pOldDPObject->GetOutRange();
    1602           0 :         pDoc->DeleteAreaTab( aOldRange, IDF_ALL );
    1603           0 :         pOldUndoDoc->CopyToDocument( aOldRange, IDF_ALL, false, pDoc );
    1604             :     }
    1605             : 
    1606             :     //  update objects in collection
    1607             : 
    1608           0 :     if ( pNewDPObject )
    1609             :     {
    1610             :         //  find updated object
    1611             :         //! find by name!
    1612             : 
    1613             :         ScDPObject* pDocObj = pDoc->GetDPAtCursor(
    1614           0 :                             aNewRange.aStart.Col(), aNewRange.aStart.Row(), aNewRange.aStart.Tab() );
    1615             :         OSL_ENSURE(pDocObj, "DPObject not found");
    1616           0 :         if (pDocObj)
    1617             :         {
    1618           0 :             if ( pOldDPObject )
    1619             :             {
    1620             :                 //  restore old settings
    1621           0 :                 pOldDPObject->WriteSourceDataTo( *pDocObj );
    1622           0 :                 ScDPSaveData* pData = pOldDPObject->GetSaveData();
    1623           0 :                 if (pData)
    1624           0 :                     pDocObj->SetSaveData(*pData);
    1625           0 :                 pDocObj->SetOutRange( pOldDPObject->GetOutRange() );
    1626           0 :                 pOldDPObject->WriteTempDataTo( *pDocObj );
    1627             :             }
    1628             :             else
    1629             :             {
    1630             :                 //  delete inserted object
    1631           0 :                 pDoc->GetDPCollection()->FreeTable(pDocObj);
    1632             :             }
    1633             :         }
    1634             :     }
    1635           0 :     else if ( pOldDPObject )
    1636             :     {
    1637             :         //  re-insert deleted object
    1638             : 
    1639           0 :         ScDPObject* pDestObj = new ScDPObject( *pOldDPObject );
    1640           0 :         if ( !pDoc->GetDPCollection()->InsertNewTable(pDestObj) )
    1641             :         {
    1642             :             OSL_FAIL("cannot insert DPObject");
    1643           0 :             DELETEZ( pDestObj );
    1644             :         }
    1645             :     }
    1646             : 
    1647           0 :     if (pNewUndoDoc)
    1648           0 :         pDocShell->PostPaint( aNewRange, PAINT_GRID, SC_PF_LINES );
    1649           0 :     if (pOldUndoDoc)
    1650           0 :         pDocShell->PostPaint( aOldRange, PAINT_GRID, SC_PF_LINES );
    1651           0 :     pDocShell->PostDataChanged();
    1652             : 
    1653           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1654             :     if (pViewShell)
    1655             :     {
    1656             :         //! set current sheet
    1657             :     }
    1658             : 
    1659           0 :     if (pNewDPObject)
    1660             :     {
    1661             :         // notify API objects
    1662           0 :         pDoc->BroadcastUno( ScDataPilotModifiedHint( pNewDPObject->GetName() ) );
    1663             :     }
    1664             : 
    1665           0 :     EndUndo();
    1666           0 : }
    1667             : 
    1668           0 : void ScUndoDataPilot::Redo()
    1669             : {
    1670           0 :     BeginRedo();
    1671             : 
    1672             :     //! copy output data instead of repeating the change,
    1673             :     //! in case external data have changed!
    1674             : 
    1675           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1676             : 
    1677           0 :     ScDPObject* pSourceObj = NULL;
    1678           0 :     if ( pOldDPObject )
    1679             :     {
    1680             :         //  find object to modify
    1681             :         //! find by name!
    1682             : 
    1683           0 :         ScRange aOldRange = pOldDPObject->GetOutRange();
    1684             :         pSourceObj = pDoc->GetDPAtCursor(
    1685           0 :                         aOldRange.aStart.Col(), aOldRange.aStart.Row(), aOldRange.aStart.Tab() );
    1686             :         OSL_ENSURE(pSourceObj, "DPObject not found");
    1687             :     }
    1688             : 
    1689           0 :     ScDBDocFunc aFunc( *pDocShell );
    1690           0 :     aFunc.DataPilotUpdate( pSourceObj, pNewDPObject, false, false, bAllowMove );    // no new undo action
    1691             : 
    1692           0 :     EndRedo();
    1693           0 : }
    1694             : 
    1695           0 : void ScUndoDataPilot::Repeat(SfxRepeatTarget& /* rTarget */)
    1696             : {
    1697             :     //! allow deletion
    1698           0 : }
    1699             : 
    1700           8 : bool ScUndoDataPilot::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1701             : {
    1702             :     //! allow deletion
    1703           8 :     return false;
    1704             : }
    1705             : 
    1706           0 : ScUndoConsolidate::ScUndoConsolidate( ScDocShell* pNewDocShell, const ScArea& rArea,
    1707             :                     const ScConsolidateParam& rPar, ScDocument* pNewUndoDoc,
    1708             :                     bool bReference, SCROW nInsCount, ScOutlineTable* pTab,
    1709             :                     ScDBData* pData ) :
    1710             :     ScSimpleUndo( pNewDocShell ),
    1711             :     aDestArea( rArea ),
    1712             :     pUndoDoc( pNewUndoDoc ),
    1713             :     aParam( rPar ),
    1714             :     bInsRef( bReference ),
    1715             :     nInsertCount( nInsCount ),
    1716             :     pUndoTab( pTab ),
    1717           0 :     pUndoData( pData )
    1718             : {
    1719           0 : }
    1720             : 
    1721           0 : ScUndoConsolidate::~ScUndoConsolidate()
    1722             : {
    1723           0 :     delete pUndoDoc;
    1724           0 :     delete pUndoTab;
    1725           0 :     delete pUndoData;
    1726           0 : }
    1727             : 
    1728           0 : OUString ScUndoConsolidate::GetComment() const
    1729             : {
    1730           0 :     return ScGlobal::GetRscString( STR_UNDO_CONSOLIDATE );
    1731             : }
    1732             : 
    1733           0 : void ScUndoConsolidate::Undo()
    1734             : {
    1735           0 :     BeginUndo();
    1736             : 
    1737           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1738           0 :     SCTAB nTab = aDestArea.nTab;
    1739             : 
    1740           0 :     ScRange aOldRange;
    1741           0 :     if (pUndoData)
    1742           0 :         pUndoData->GetArea(aOldRange);
    1743             : 
    1744           0 :     if (bInsRef)
    1745             :     {
    1746           0 :         pDoc->DeleteRow( 0,nTab, MAXCOL,nTab, aDestArea.nRowStart, nInsertCount );
    1747           0 :         pDoc->SetOutlineTable( nTab, pUndoTab );
    1748             : 
    1749             :         // Row status
    1750           0 :         pUndoDoc->CopyToDocument( 0,0,nTab, MAXCOL,MAXROW,nTab, IDF_NONE, false, pDoc );
    1751             : 
    1752             :         // Data and references
    1753           0 :         pDoc->DeleteAreaTab( 0,aDestArea.nRowStart, MAXCOL,aDestArea.nRowEnd, nTab, IDF_ALL );
    1754             :         pUndoDoc->UndoToDocument( 0, aDestArea.nRowStart, nTab,
    1755             :                                     MAXCOL, aDestArea.nRowEnd, nTab,
    1756           0 :                                     IDF_ALL, false, pDoc );
    1757             : 
    1758             :         // Original range
    1759           0 :         if (pUndoData)
    1760             :         {
    1761           0 :             pDoc->DeleteAreaTab(aOldRange, IDF_ALL);
    1762           0 :             pUndoDoc->CopyToDocument(aOldRange, IDF_ALL, false, pDoc);
    1763             :         }
    1764             : 
    1765             :         pDocShell->PostPaint( 0,aDestArea.nRowStart,nTab, MAXCOL,MAXROW,nTab,
    1766           0 :                                 PAINT_GRID | PAINT_LEFT | PAINT_SIZE );
    1767             :     }
    1768             :     else
    1769             :     {
    1770             :         pDoc->DeleteAreaTab( aDestArea.nColStart,aDestArea.nRowStart,
    1771           0 :                                 aDestArea.nColEnd,aDestArea.nRowEnd, nTab, IDF_ALL );
    1772             :         pUndoDoc->CopyToDocument( aDestArea.nColStart, aDestArea.nRowStart, nTab,
    1773             :                                     aDestArea.nColEnd, aDestArea.nRowEnd, nTab,
    1774           0 :                                     IDF_ALL, false, pDoc );
    1775             : 
    1776             :         //  Original range
    1777           0 :         if (pUndoData)
    1778             :         {
    1779           0 :             pDoc->DeleteAreaTab(aOldRange, IDF_ALL);
    1780           0 :             pUndoDoc->CopyToDocument(aOldRange, IDF_ALL, false, pDoc);
    1781             :         }
    1782             : 
    1783           0 :         SCCOL nEndX = aDestArea.nColEnd;
    1784           0 :         SCROW nEndY = aDestArea.nRowEnd;
    1785           0 :         if ( pUndoData )
    1786             :         {
    1787           0 :             if ( aOldRange.aEnd.Col() > nEndX )
    1788           0 :                 nEndX = aOldRange.aEnd.Col();
    1789           0 :             if ( aOldRange.aEnd.Row() > nEndY )
    1790           0 :                 nEndY = aOldRange.aEnd.Row();
    1791             :         }
    1792             :         pDocShell->PostPaint( aDestArea.nColStart, aDestArea.nRowStart, nTab,
    1793           0 :                                     nEndX, nEndY, nTab, PAINT_GRID );
    1794             :     }
    1795             : 
    1796             :     // Adjust Database range again
    1797           0 :     if (pUndoData)
    1798             :     {
    1799           0 :         ScDBCollection* pColl = pDoc->GetDBCollection();
    1800           0 :         if (pColl)
    1801             :         {
    1802           0 :             ScDBData* pDocData = pColl->getNamedDBs().findByUpperName(pUndoData->GetUpperName());
    1803           0 :             if (pDocData)
    1804           0 :                 *pDocData = *pUndoData;
    1805             :         }
    1806             :     }
    1807             : 
    1808           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1809           0 :     if (pViewShell)
    1810             :     {
    1811           0 :         SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
    1812           0 :         if ( nViewTab != nTab )
    1813           0 :             pViewShell->SetTabNo( nTab );
    1814             :     }
    1815             : 
    1816           0 :     EndUndo();
    1817           0 : }
    1818             : 
    1819           0 : void ScUndoConsolidate::Redo()
    1820             : {
    1821           0 :     BeginRedo();
    1822             : 
    1823           0 :     pDocShell->DoConsolidate( aParam, false );
    1824             : 
    1825           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1826           0 :     if (pViewShell)
    1827             :     {
    1828           0 :         SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
    1829           0 :         if ( nViewTab != aParam.nTab )
    1830           0 :             pViewShell->SetTabNo( aParam.nTab );
    1831             :     }
    1832             : 
    1833           0 :     EndRedo();
    1834           0 : }
    1835             : 
    1836           0 : void ScUndoConsolidate::Repeat(SfxRepeatTarget& /* rTarget */)
    1837             : {
    1838           0 : }
    1839             : 
    1840           0 : bool ScUndoConsolidate::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1841             : {
    1842           0 :     return false;
    1843             : }
    1844             : 
    1845             : // Change source data of Chart
    1846           6 : void ScUndoChartData::Init()
    1847             : {
    1848           6 :     ScDocument* pDoc = pDocShell->GetDocument();
    1849           6 :     aOldRangeListRef = new ScRangeList;
    1850           6 :     pDoc->GetOldChartParameters( aChartName, *aOldRangeListRef, bOldColHeaders, bOldRowHeaders );
    1851           6 : }
    1852             : 
    1853           0 : ScUndoChartData::ScUndoChartData( ScDocShell* pNewDocShell, const OUString& rName,
    1854             :                                     const ScRange& rNew, bool bColHdr, bool bRowHdr,
    1855             :                                     bool bAdd ) :
    1856             :     ScSimpleUndo( pNewDocShell ),
    1857             :     aChartName( rName ),
    1858             :     bNewColHeaders( bColHdr ),
    1859             :     bNewRowHeaders( bRowHdr ),
    1860           0 :     bAddRange( bAdd )
    1861             : {
    1862           0 :     aNewRangeListRef = new ScRangeList;
    1863           0 :     aNewRangeListRef->Append( rNew );
    1864             : 
    1865           0 :     Init();
    1866           0 : }
    1867             : 
    1868           6 : ScUndoChartData::ScUndoChartData( ScDocShell* pNewDocShell, const OUString& rName,
    1869             :                                     const ScRangeListRef& rNew, bool bColHdr, bool bRowHdr,
    1870             :                                     bool bAdd ) :
    1871             :     ScSimpleUndo( pNewDocShell ),
    1872             :     aChartName( rName ),
    1873             :     aNewRangeListRef( rNew ),
    1874             :     bNewColHeaders( bColHdr ),
    1875             :     bNewRowHeaders( bRowHdr ),
    1876           6 :     bAddRange( bAdd )
    1877             : {
    1878           6 :     Init();
    1879           6 : }
    1880             : 
    1881          12 : ScUndoChartData::~ScUndoChartData()
    1882             : {
    1883          12 : }
    1884             : 
    1885           8 : OUString ScUndoChartData::GetComment() const
    1886             : {
    1887           8 :     return ScGlobal::GetRscString( STR_UNDO_CHARTDATA );
    1888             : }
    1889             : 
    1890           0 : void ScUndoChartData::Undo()
    1891             : {
    1892           0 :     BeginUndo();
    1893             : 
    1894             :     pDocShell->GetDocument()->UpdateChartArea( aChartName, aOldRangeListRef,
    1895           0 :                                 bOldColHeaders, bOldRowHeaders, false );
    1896             : 
    1897           0 :     EndUndo();
    1898           0 : }
    1899             : 
    1900           0 : void ScUndoChartData::Redo()
    1901             : {
    1902           0 :     BeginRedo();
    1903             : 
    1904             :     pDocShell->GetDocument()->UpdateChartArea( aChartName, aNewRangeListRef,
    1905           0 :                                 bNewColHeaders, bNewRowHeaders, bAddRange );
    1906             : 
    1907           0 :     EndRedo();
    1908           0 : }
    1909             : 
    1910           0 : void ScUndoChartData::Repeat(SfxRepeatTarget& /* rTarget */)
    1911             : {
    1912           0 : }
    1913             : 
    1914           2 : bool ScUndoChartData::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1915             : {
    1916           2 :     return false;
    1917             : }
    1918             : 
    1919           0 : ScUndoDataForm::ScUndoDataForm( ScDocShell* pNewDocShell,
    1920             :                                 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
    1921             :                                 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
    1922             :                                 const ScMarkData& rMark,
    1923             :                                 ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
    1924             :                                 sal_uInt16 nNewFlags,
    1925             :                                 ScRefUndoData* pRefData,
    1926             :                                 void* /*pFill1*/, void* /*pFill2*/, void* /*pFill3*/,
    1927             :                                 bool bRedoIsFilled ) :
    1928             :         ScBlockUndo( pNewDocShell, ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ), SC_UNDO_SIMPLE ),
    1929           0 :         mpMarkData(new ScMarkData(rMark)),
    1930             :         pUndoDoc( pNewUndoDoc ),
    1931             :         pRedoDoc( pNewRedoDoc ),
    1932             :         nFlags( nNewFlags ),
    1933             :         pRefUndoData( pRefData ),
    1934             :         pRefRedoData( NULL ),
    1935           0 :         bRedoFilled( bRedoIsFilled )
    1936             : {
    1937             :         //      pFill1,pFill2,pFill3 are there so the ctor calls for simple paste (without cutting)
    1938             :         //      don't have to be changed and branched for 641.
    1939             :         //      They can be removed later.
    1940             : 
    1941           0 :         if (!mpMarkData->IsMarked())                            // no cell marked:
    1942           0 :                 mpMarkData->SetMarkArea(aBlockRange);   //  mark paste block
    1943             : 
    1944           0 :         if ( pRefUndoData )
    1945           0 :                 pRefUndoData->DeleteUnchanged( pDocShell->GetDocument() );
    1946             : 
    1947           0 :         SetChangeTrack();
    1948           0 : }
    1949             : 
    1950           0 : ScUndoDataForm::~ScUndoDataForm()
    1951             : {
    1952           0 :         delete pUndoDoc;
    1953           0 :         delete pRedoDoc;
    1954           0 :         delete pRefUndoData;
    1955           0 :         delete pRefRedoData;
    1956           0 : }
    1957             : 
    1958           0 : OUString ScUndoDataForm::GetComment() const
    1959             : {
    1960           0 :         return ScGlobal::GetRscString( STR_UNDO_PASTE );
    1961             : }
    1962             : 
    1963           0 : void ScUndoDataForm::SetChangeTrack()
    1964             : {
    1965           0 :         ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
    1966           0 :         if ( pChangeTrack && (nFlags & IDF_CONTENTS) )
    1967             :                 pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
    1968           0 :                         nStartChangeAction, nEndChangeAction, SC_CACM_PASTE );
    1969             :         else
    1970           0 :                 nStartChangeAction = nEndChangeAction = 0;
    1971           0 : }
    1972             : 
    1973           0 : void ScUndoDataForm::Undo()
    1974             : {
    1975           0 :         BeginUndo();
    1976           0 :         DoChange( true );
    1977           0 :         ShowTable( aBlockRange );
    1978           0 :         EndUndo();
    1979           0 :         SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
    1980           0 : }
    1981             : 
    1982           0 : void ScUndoDataForm::Redo()
    1983             : {
    1984           0 :         BeginRedo();
    1985           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    1986           0 :         EnableDrawAdjust( pDoc, false );                                //! include in ScBlockUndo?
    1987           0 :         DoChange( false );
    1988           0 :         EnableDrawAdjust( pDoc, true );                                 //! include in ScBlockUndo?
    1989           0 :         EndRedo();
    1990           0 :         SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
    1991           0 : }
    1992             : 
    1993           0 : void ScUndoDataForm::Repeat(SfxRepeatTarget& /*rTarget*/)
    1994             : {
    1995           0 : }
    1996             : 
    1997           0 : bool ScUndoDataForm::CanRepeat(SfxRepeatTarget& rTarget) const
    1998             : {
    1999           0 :         return (rTarget.ISA(ScTabViewTarget));
    2000             : }
    2001             : 
    2002           0 : void ScUndoDataForm::DoChange( const bool bUndo )
    2003             : {
    2004           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    2005             : 
    2006             :     //      RefUndoData for redo is created before first undo
    2007             :     //      (with DeleteUnchanged after the DoUndo call)
    2008           0 :     bool bCreateRedoData = ( bUndo && pRefUndoData && !pRefRedoData );
    2009           0 :     if ( bCreateRedoData )
    2010           0 :             pRefRedoData = new ScRefUndoData( pDoc );
    2011             : 
    2012           0 :     ScRefUndoData* pWorkRefData = bUndo ? pRefUndoData : pRefRedoData;
    2013             : 
    2014             :     // Always back-up either all or none of the content for Undo
    2015           0 :     sal_uInt16 nUndoFlags = IDF_NONE;
    2016           0 :     if (nFlags & IDF_CONTENTS)
    2017           0 :             nUndoFlags |= IDF_CONTENTS;
    2018           0 :     if (nFlags & IDF_ATTRIB)
    2019           0 :             nUndoFlags |= IDF_ATTRIB;
    2020             : 
    2021           0 :     bool bPaintAll = false;
    2022             : 
    2023           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    2024             : 
    2025           0 :     SCTAB nTabCount = pDoc->GetTableCount();
    2026           0 :     if ( bUndo && !bRedoFilled )
    2027             :     {
    2028           0 :         if (!pRedoDoc)
    2029             :         {
    2030           0 :             bool bColInfo = ( aBlockRange.aStart.Row()==0 && aBlockRange.aEnd.Row()==MAXROW );
    2031           0 :             bool bRowInfo = ( aBlockRange.aStart.Col()==0 && aBlockRange.aEnd.Col()==MAXCOL );
    2032             : 
    2033           0 :             pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
    2034           0 :             pRedoDoc->InitUndoSelected( pDoc, *mpMarkData, bColInfo, bRowInfo );
    2035             :         }
    2036             :         //  read "redo" data from the document in the first undo
    2037             :             //  all sheets - CopyToDocument skips those that don't exist in pRedoDoc
    2038           0 :         ScRange aCopyRange = aBlockRange;
    2039           0 :         aCopyRange.aStart.SetTab(0);
    2040           0 :         aCopyRange.aEnd.SetTab(nTabCount-1);
    2041           0 :         pDoc->CopyToDocument( aCopyRange, 1, false, pRedoDoc );
    2042           0 :         bRedoFilled = true;
    2043             :     }
    2044             : 
    2045           0 :     sal_uInt16 nExtFlags = 0;
    2046           0 :     pDocShell->UpdatePaintExt( nExtFlags, aBlockRange );
    2047             : 
    2048           0 :     for ( sal_uInt16 i=0; i <= ( aBlockRange.aEnd.Col() - aBlockRange.aStart.Col() ); i++ )
    2049             :     {
    2050             :         OUString aOldString = pUndoDoc->GetString(
    2051           0 :             aBlockRange.aStart.Col()+i, aBlockRange.aStart.Row(), aBlockRange.aStart.Tab());
    2052           0 :         pDoc->SetString( aBlockRange.aStart.Col()+i , aBlockRange.aStart.Row() , aBlockRange.aStart.Tab() , aOldString );
    2053           0 :     }
    2054             : 
    2055           0 :     if (pWorkRefData)
    2056             :     {
    2057           0 :         pWorkRefData->DoUndo( pDoc, true );             // TRUE = bSetChartRangeLists for SetChartListenerCollection
    2058           0 :         if ( pDoc->RefreshAutoFilter( 0,0, MAXCOL,MAXROW, aBlockRange.aStart.Tab() ) )
    2059           0 :             bPaintAll = true;
    2060             :     }
    2061             : 
    2062           0 :     if ( bCreateRedoData && pRefRedoData )
    2063           0 :             pRefRedoData->DeleteUnchanged( pDoc );
    2064             : 
    2065           0 :     if ( bUndo )
    2066             :     {
    2067           0 :         ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
    2068           0 :         if ( pChangeTrack )
    2069           0 :             pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
    2070             :     }
    2071             :     else
    2072           0 :         SetChangeTrack();
    2073             : 
    2074           0 :     ScRange aDrawRange( aBlockRange );
    2075           0 :     pDoc->ExtendMerge( aDrawRange, true );      // only needed for single sheet (text/rtf etc.)
    2076           0 :     sal_uInt16 nPaint = PAINT_GRID;
    2077           0 :     if (bPaintAll)
    2078             :     {
    2079           0 :         aDrawRange.aStart.SetCol(0);
    2080           0 :         aDrawRange.aStart.SetRow(0);
    2081           0 :         aDrawRange.aEnd.SetCol(MAXCOL);
    2082           0 :         aDrawRange.aEnd.SetRow(MAXROW);
    2083           0 :         nPaint |= PAINT_TOP | PAINT_LEFT;
    2084           0 : /*A*/   if (pViewShell)
    2085           0 :             pViewShell->AdjustBlockHeight(false);
    2086             :     }
    2087             :     else
    2088             :     {
    2089           0 :         if ( aBlockRange.aStart.Row() == 0 && aBlockRange.aEnd.Row() == MAXROW )        // whole column
    2090             :         {
    2091           0 :             nPaint |= PAINT_TOP;
    2092           0 :             aDrawRange.aEnd.SetCol(MAXCOL);
    2093             :         }
    2094           0 :         if ( aBlockRange.aStart.Col() == 0 && aBlockRange.aEnd.Col() == MAXCOL )        // whole row
    2095             :         {
    2096           0 :             nPaint |= PAINT_LEFT;
    2097           0 :             aDrawRange.aEnd.SetRow(MAXROW);
    2098             :         }
    2099           0 : /*A*/   if ((pViewShell) && pViewShell->AdjustBlockHeight(false))
    2100             :         {
    2101           0 :             aDrawRange.aStart.SetCol(0);
    2102           0 :             aDrawRange.aStart.SetRow(0);
    2103           0 :             aDrawRange.aEnd.SetCol(MAXCOL);
    2104           0 :             aDrawRange.aEnd.SetRow(MAXROW);
    2105           0 :             nPaint |= PAINT_LEFT;
    2106             :         }
    2107           0 :         pDocShell->UpdatePaintExt( nExtFlags, aDrawRange );
    2108             :     }
    2109             : 
    2110           0 :     if ( !bUndo )                               //      draw redo after updating row heights
    2111           0 :         RedoSdrUndoAction( pDrawUndo );                 //!     include in ScBlockUndo?
    2112             : 
    2113           0 :     pDocShell->PostPaint( aDrawRange, nPaint, nExtFlags );
    2114             : 
    2115           0 :     pDocShell->PostDataChanged();
    2116           0 :     if (pViewShell)
    2117           0 :         pViewShell->CellContentChanged();
    2118         102 : }
    2119             : 
    2120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10