LCOV - code coverage report
Current view: top level - sc/source/ui/undo - undoblk3.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 208 912 22.8 %
Date: 2014-04-11 Functions: 48 200 24.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 "scitems.hxx"
      21             : #include <svx/algitem.hxx>
      22             : #include <editeng/boxitem.hxx>
      23             : #include <editeng/justifyitem.hxx>
      24             : #include <svl/srchitem.hxx>
      25             : #include <sfx2/linkmgr.hxx>
      26             : #include <sfx2/bindings.hxx>
      27             : #include <vcl/virdev.hxx>
      28             : #include <sfx2/app.hxx>
      29             : 
      30             : #include "undoblk.hxx"
      31             : #include "sc.hrc"
      32             : #include "globstr.hrc"
      33             : #include "global.hxx"
      34             : #include "rangenam.hxx"
      35             : #include "arealink.hxx"
      36             : #include "patattr.hxx"
      37             : #include "target.hxx"
      38             : #include "document.hxx"
      39             : #include "docpool.hxx"
      40             : #include "table.hxx"
      41             : #include "docsh.hxx"
      42             : #include "tabvwsh.hxx"
      43             : #include "undoolk.hxx"
      44             : #include "undoutil.hxx"
      45             : #include "chgtrack.hxx"
      46             : #include "dociter.hxx"
      47             : #include "formulacell.hxx"
      48             : #include "paramisc.hxx"
      49             : #include "postit.hxx"
      50             : #include "docuno.hxx"
      51             : #include "progress.hxx"
      52             : #include "editutil.hxx"
      53             : #include "editdataarray.hxx"
      54             : #include <rowheightcontext.hxx>
      55             : 
      56             : // STATIC DATA ---------------------------------------------------------------
      57             : 
      58           0 : TYPEINIT1(ScUndoDeleteContents,     SfxUndoAction);
      59           0 : TYPEINIT1(ScUndoFillTable,          SfxUndoAction);
      60           0 : TYPEINIT1(ScUndoSelectionAttr,      SfxUndoAction);
      61           0 : TYPEINIT1(ScUndoAutoFill,           SfxUndoAction);
      62           0 : TYPEINIT1(ScUndoMerge,              SfxUndoAction);
      63           0 : TYPEINIT1(ScUndoAutoFormat,         SfxUndoAction);
      64           0 : TYPEINIT1(ScUndoReplace,            SfxUndoAction);
      65           0 : TYPEINIT1(ScUndoTabOp,              SfxUndoAction);
      66           0 : TYPEINIT1(ScUndoConversion,         SfxUndoAction);
      67           0 : TYPEINIT1(ScUndoRefConversion,      SfxUndoAction);
      68           0 : TYPEINIT1(ScUndoRefreshLink,        SfxUndoAction);
      69           0 : TYPEINIT1(ScUndoInsertAreaLink,     SfxUndoAction);
      70           0 : TYPEINIT1(ScUndoRemoveAreaLink,     SfxUndoAction);
      71           0 : TYPEINIT1(ScUndoUpdateAreaLink,     SfxUndoAction);
      72             : 
      73             : // TODO:
      74             : /*A*/   // SetOptimalHeight on Document, when no View
      75             : 
      76          77 : ScUndoDeleteContents::ScUndoDeleteContents(
      77             :                 ScDocShell* pNewDocShell,
      78             :                 const ScMarkData& rMark, const ScRange& rRange,
      79             :                 ScDocument* pNewUndoDoc, bool bNewMulti,
      80             :                 sal_uInt16 nNewFlags, bool bObjects )
      81             :     :   ScSimpleUndo( pNewDocShell ),
      82             :         aRange      ( rRange ),
      83             :         aMarkData   ( rMark ),
      84             :         pUndoDoc    ( pNewUndoDoc ),
      85             :         pDrawUndo   ( NULL ),
      86             :         nFlags      ( nNewFlags ),
      87          77 :         bMulti      ( bNewMulti )   // unnecessary
      88             : {
      89          77 :     if (bObjects)
      90           5 :         pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
      91             : 
      92          77 :     if ( !(aMarkData.IsMarked() || aMarkData.IsMultiMarked()) )     // if no cell is selected:
      93           0 :         aMarkData.SetMarkArea( aRange );                            // select cell under cursor
      94             : 
      95          77 :     SetChangeTrack();
      96          77 : }
      97             : 
      98         230 : ScUndoDeleteContents::~ScUndoDeleteContents()
      99             : {
     100          77 :     delete pUndoDoc;
     101          77 :     DeleteSdrUndoAction( pDrawUndo );
     102         153 : }
     103             : 
     104          77 : OUString ScUndoDeleteContents::GetComment() const
     105             : {
     106          77 :     return ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS );    // "Delete"
     107             : }
     108             : 
     109          78 : void ScUndoDeleteContents::SetChangeTrack()
     110             : {
     111          78 :     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
     112          78 :     if ( pChangeTrack && (nFlags & IDF_CONTENTS) )
     113             :         pChangeTrack->AppendContentRange( aRange, pUndoDoc,
     114           0 :             nStartChangeAction, nEndChangeAction );
     115             :     else
     116          78 :         nStartChangeAction = nEndChangeAction = 0;
     117          78 : }
     118             : 
     119           3 : void ScUndoDeleteContents::DoChange( const bool bUndo )
     120             : {
     121           3 :     ScDocument* pDoc = pDocShell->GetDocument();
     122             : 
     123           3 :     SetViewMarkData( aMarkData );
     124             : 
     125           3 :     sal_uInt16 nExtFlags = 0;
     126             : 
     127           3 :     if (bUndo)  // only Undo
     128             :     {
     129           2 :         sal_uInt16 nUndoFlags = IDF_NONE; // copy either all or none of the content
     130           2 :         if (nFlags & IDF_CONTENTS)        // (Only the correct ones have been copied into UndoDoc)
     131           2 :             nUndoFlags |= IDF_CONTENTS;
     132           2 :         if (nFlags & IDF_ATTRIB)
     133           1 :             nUndoFlags |= IDF_ATTRIB;
     134           2 :         if (nFlags & IDF_EDITATTR)          // Edit-Engine attribute
     135           0 :             nUndoFlags |= IDF_STRING;       // -> Cells will be changed
     136             :         // do not create clones of note captions, they will be restored via drawing undo
     137           2 :         nUndoFlags |= IDF_NOCAPTIONS;
     138             : 
     139           2 :         ScRange aCopyRange = aRange;
     140           2 :         SCTAB nTabCount = pDoc->GetTableCount();
     141           2 :         aCopyRange.aStart.SetTab(0);
     142           2 :         aCopyRange.aEnd.SetTab(nTabCount-1);
     143             : 
     144           2 :         pUndoDoc->CopyToDocument( aCopyRange, nUndoFlags, bMulti, pDoc, &aMarkData );
     145           2 :         BroadcastChanges(aCopyRange);
     146             : 
     147           2 :         DoSdrUndoAction( pDrawUndo, pDoc );
     148             : 
     149           2 :         ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
     150           2 :         if ( pChangeTrack )
     151           0 :             pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
     152             : 
     153           2 :         pDocShell->UpdatePaintExt( nExtFlags, aRange );             // content after the change
     154             :     }
     155             :     else        // only Redo
     156             :     {
     157           1 :         pDocShell->UpdatePaintExt( nExtFlags, aRange );             // content before the change
     158             : 
     159           1 :         aMarkData.MarkToMulti();
     160           1 :         RedoSdrUndoAction( pDrawUndo );
     161             :         // do not delete objects and note captions, they have been removed via drawing undo
     162           1 :         sal_uInt16 nRedoFlags = (nFlags & ~IDF_OBJECTS) | IDF_NOCAPTIONS;
     163           1 :         pDoc->DeleteSelection( nRedoFlags, aMarkData );
     164           1 :         aMarkData.MarkToSimple();
     165             : 
     166           1 :         SetChangeTrack();
     167             :     }
     168             : 
     169           3 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     170           3 :     if ( !( (pViewShell) && pViewShell->AdjustRowHeight(
     171           3 :                                 aRange.aStart.Row(), aRange.aEnd.Row() ) ) )
     172           3 : /*A*/   pDocShell->PostPaint( aRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
     173             : 
     174           3 :     pDocShell->PostDataChanged();
     175           3 :     if (pViewShell)
     176           0 :         pViewShell->CellContentChanged();
     177             : 
     178           3 :     ShowTable( aRange );
     179           3 : }
     180             : 
     181           2 : void ScUndoDeleteContents::Undo()
     182             : {
     183           2 :     BeginUndo();
     184           2 :     DoChange( true );
     185           2 :     EndUndo();
     186             : 
     187           2 :     BroadcastChanges(aRange);
     188           2 :     HelperNotifyChanges::NotifyIfChangesListeners(*pDocShell, aRange);
     189           2 : }
     190             : 
     191           1 : void ScUndoDeleteContents::Redo()
     192             : {
     193           1 :     BeginRedo();
     194           1 :     DoChange( false );
     195           1 :     EndRedo();
     196             : 
     197           1 :     BroadcastChanges(aRange);
     198           1 :     HelperNotifyChanges::NotifyIfChangesListeners(*pDocShell, aRange);
     199           1 : }
     200             : 
     201           0 : void ScUndoDeleteContents::Repeat(SfxRepeatTarget& rTarget)
     202             : {
     203           0 :     if (rTarget.ISA(ScTabViewTarget))
     204           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->DeleteContents( nFlags, true );
     205           0 : }
     206             : 
     207           0 : bool ScUndoDeleteContents::CanRepeat(SfxRepeatTarget& rTarget) const
     208             : {
     209           0 :     return rTarget.ISA(ScTabViewTarget);
     210             : }
     211             : 
     212           0 : ScUndoFillTable::ScUndoFillTable( ScDocShell* pNewDocShell,
     213             :                 const ScMarkData& rMark,
     214             :                 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
     215             :                 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
     216             :                 ScDocument* pNewUndoDoc, bool bNewMulti, SCTAB nSrc,
     217             :                 sal_uInt16 nFlg, sal_uInt16 nFunc, bool bSkip, bool bLink )
     218             :     :   ScSimpleUndo( pNewDocShell ),
     219             :         aRange      ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
     220             :         aMarkData   ( rMark ),
     221             :         pUndoDoc    ( pNewUndoDoc ),
     222             :         nFlags      ( nFlg ),
     223             :         nFunction   ( nFunc ),
     224             :         nSrcTab     ( nSrc ),
     225             :         bMulti      ( bNewMulti ),
     226             :         bSkipEmpty  ( bSkip ),
     227           0 :         bAsLink     ( bLink )
     228             : {
     229           0 :     SetChangeTrack();
     230           0 : }
     231             : 
     232           0 : ScUndoFillTable::~ScUndoFillTable()
     233             : {
     234           0 :     delete pUndoDoc;
     235           0 : }
     236             : 
     237           0 : OUString ScUndoFillTable::GetComment() const
     238             : {
     239           0 :     return ScGlobal::GetRscString( STR_FILL_TAB );
     240             : }
     241             : 
     242           0 : void ScUndoFillTable::SetChangeTrack()
     243             : {
     244           0 :     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
     245           0 :     if ( pChangeTrack )
     246             :     {
     247           0 :         SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
     248           0 :         ScRange aWorkRange(aRange);
     249           0 :         nStartChangeAction = 0;
     250             :         sal_uLong nTmpAction;
     251           0 :         ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
     252           0 :         for (; itr != itrEnd && *itr < nTabCount; ++itr)
     253             :         {
     254           0 :             if (*itr != nSrcTab)
     255             :             {
     256           0 :                 aWorkRange.aStart.SetTab(*itr);
     257           0 :                 aWorkRange.aEnd.SetTab(*itr);
     258             :                 pChangeTrack->AppendContentRange( aWorkRange, pUndoDoc,
     259           0 :                     nTmpAction, nEndChangeAction );
     260           0 :                 if ( !nStartChangeAction )
     261           0 :                     nStartChangeAction = nTmpAction;
     262             :             }
     263             :         }
     264             :     }
     265             :     else
     266           0 :         nStartChangeAction = nEndChangeAction = 0;
     267           0 : }
     268             : 
     269           0 : void ScUndoFillTable::DoChange( const bool bUndo )
     270             : {
     271           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     272             : 
     273           0 :     SetViewMarkData( aMarkData );
     274             : 
     275           0 :     if (bUndo)  // only Undo
     276             :     {
     277           0 :         SCTAB nTabCount = pDoc->GetTableCount();
     278           0 :         ScRange aWorkRange(aRange);
     279           0 :         ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
     280           0 :         for (; itr != itrEnd && *itr < nTabCount; ++itr)
     281           0 :             if (*itr != nSrcTab)
     282             :             {
     283           0 :                 aWorkRange.aStart.SetTab(*itr);
     284           0 :                 aWorkRange.aEnd.SetTab(*itr);
     285           0 :                 if (bMulti)
     286           0 :                     pDoc->DeleteSelectionTab( *itr, IDF_ALL, aMarkData );
     287             :                 else
     288           0 :                     pDoc->DeleteAreaTab( aWorkRange, IDF_ALL );
     289           0 :                 pUndoDoc->CopyToDocument( aWorkRange, IDF_ALL, bMulti, pDoc, &aMarkData );
     290             :             }
     291             : 
     292           0 :         ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
     293           0 :         if ( pChangeTrack )
     294           0 :             pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
     295             :     }
     296             :     else        // only Redo
     297             :     {
     298           0 :         aMarkData.MarkToMulti();
     299           0 :         pDoc->FillTabMarked( nSrcTab, aMarkData, nFlags, nFunction, bSkipEmpty, bAsLink );
     300           0 :         aMarkData.MarkToSimple();
     301           0 :         SetChangeTrack();
     302             :     }
     303             : 
     304           0 :     pDocShell->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_EXTRAS);
     305           0 :     pDocShell->PostDataChanged();
     306             : 
     307             :     //  CellContentChanged comes with the selection
     308             : 
     309           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     310           0 :     if (pViewShell)
     311             :     {
     312           0 :         SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
     313           0 :         if ( !aMarkData.GetTableSelect(nTab) )
     314           0 :             pViewShell->SetTabNo( nSrcTab );
     315             : 
     316           0 :         pViewShell->DoneBlockMode();    // causes problems otherwise since selection is on the wrong sheet.
     317             :     }
     318           0 : }
     319             : 
     320           0 : void ScUndoFillTable::Undo()
     321             : {
     322           0 :     BeginUndo();
     323           0 :     DoChange( true );
     324           0 :     EndUndo();
     325           0 : }
     326             : 
     327           0 : void ScUndoFillTable::Redo()
     328             : {
     329           0 :     BeginRedo();
     330           0 :     DoChange( false );
     331           0 :     EndRedo();
     332           0 : }
     333             : 
     334           0 : void ScUndoFillTable::Repeat(SfxRepeatTarget& rTarget)
     335             : {
     336           0 :     if (rTarget.ISA(ScTabViewTarget))
     337           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
     338           0 : }
     339             : 
     340           0 : bool ScUndoFillTable::CanRepeat(SfxRepeatTarget& rTarget) const
     341             : {
     342           0 :     return rTarget.ISA(ScTabViewTarget);
     343             : }
     344             : 
     345         470 : ScUndoSelectionAttr::ScUndoSelectionAttr( ScDocShell* pNewDocShell,
     346             :                 const ScMarkData& rMark,
     347             :                 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
     348             :                 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
     349             :                 ScDocument* pNewUndoDoc, bool bNewMulti,
     350             :                 const ScPatternAttr* pNewApply,
     351             :                 const SvxBoxItem* pNewOuter, const SvxBoxInfoItem* pNewInner )
     352             :     :   ScSimpleUndo( pNewDocShell ),
     353             :         aMarkData   ( rMark ),
     354             :         aRange      ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
     355         470 :         mpDataArray(new ScEditDataArray),
     356             :         pUndoDoc    ( pNewUndoDoc ),
     357         940 :         bMulti      ( bNewMulti )
     358             : {
     359         470 :     ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
     360         470 :     pApplyPattern = (ScPatternAttr*) &pPool->Put( *pNewApply );
     361         470 :     pLineOuter = pNewOuter ? (SvxBoxItem*) &pPool->Put( *pNewOuter ) : NULL;
     362         470 :     pLineInner = pNewInner ? (SvxBoxInfoItem*) &pPool->Put( *pNewInner ) : NULL;
     363         470 : }
     364             : 
     365        1410 : ScUndoSelectionAttr::~ScUndoSelectionAttr()
     366             : {
     367         470 :     ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
     368         470 :     pPool->Remove(*pApplyPattern);
     369         470 :     if (pLineOuter)
     370           0 :         pPool->Remove(*pLineOuter);
     371         470 :     if (pLineInner)
     372           0 :         pPool->Remove(*pLineInner);
     373             : 
     374         470 :     delete pUndoDoc;
     375         940 : }
     376             : 
     377         486 : OUString ScUndoSelectionAttr::GetComment() const
     378             : {
     379             :     //"Attribute" "/Lines"
     380         486 :     return ScGlobal::GetRscString( pLineOuter ? STR_UNDO_SELATTRLINES : STR_UNDO_SELATTR );
     381             : }
     382             : 
     383           0 : ScEditDataArray* ScUndoSelectionAttr::GetDataArray()
     384             : {
     385           0 :     return mpDataArray.get();
     386             : }
     387             : 
     388           0 : void ScUndoSelectionAttr::DoChange( const bool bUndo )
     389             : {
     390           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     391             : 
     392           0 :     SetViewMarkData( aMarkData );
     393             : 
     394           0 :     ScRange aEffRange( aRange );
     395           0 :     if ( pDoc->HasAttrib( aEffRange, HASATTR_MERGED ) )         // merged cells?
     396           0 :         pDoc->ExtendMerge( aEffRange );
     397             : 
     398           0 :     sal_uInt16 nExtFlags = 0;
     399           0 :     pDocShell->UpdatePaintExt( nExtFlags, aEffRange );
     400             : 
     401           0 :     ChangeEditData(bUndo);
     402             : 
     403           0 :     if (bUndo)  // only for Undo
     404             :     {
     405           0 :         ScRange aCopyRange = aRange;
     406           0 :         SCTAB nTabCount = pDoc->GetTableCount();
     407           0 :         aCopyRange.aStart.SetTab(0);
     408           0 :         aCopyRange.aEnd.SetTab(nTabCount-1);
     409           0 :         pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, bMulti, pDoc, &aMarkData );
     410             :     }
     411             :     else        // only for Redo
     412             :     {
     413           0 :         aMarkData.MarkToMulti();
     414           0 :         pDoc->ApplySelectionPattern( *pApplyPattern, aMarkData );
     415           0 :         aMarkData.MarkToSimple();
     416             : 
     417           0 :         if (pLineOuter)
     418           0 :             pDoc->ApplySelectionFrame( aMarkData, pLineOuter, pLineInner );
     419             :     }
     420             : 
     421           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     422           0 :     if ( !( (pViewShell) && pViewShell->AdjustBlockHeight() ) )
     423           0 : /*A*/   pDocShell->PostPaint( aEffRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
     424             : 
     425           0 :     ShowTable( aRange );
     426           0 : }
     427             : 
     428           0 : void ScUndoSelectionAttr::ChangeEditData( const bool bUndo )
     429             : {
     430           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     431           0 :     for (const ScEditDataArray::Item* pItem = mpDataArray->First(); pItem; pItem = mpDataArray->Next())
     432             :     {
     433           0 :         ScAddress aPos(pItem->GetCol(), pItem->GetRow(), pItem->GetTab());
     434           0 :         if (pDoc->GetCellType(aPos) != CELLTYPE_EDIT)
     435           0 :             continue;
     436             : 
     437           0 :         if (bUndo)
     438             :         {
     439           0 :             if (pItem->GetOldData())
     440           0 :                 pDoc->SetEditText(aPos, *pItem->GetOldData(), NULL);
     441             :             else
     442           0 :                 pDoc->SetEmptyCell(aPos);
     443             :         }
     444             :         else
     445             :         {
     446           0 :             if (pItem->GetNewData())
     447           0 :                 pDoc->SetEditText(aPos, *pItem->GetNewData(), NULL);
     448             :             else
     449           0 :                 pDoc->SetEmptyCell(aPos);
     450             :         }
     451             :     }
     452           0 : }
     453             : 
     454           0 : void ScUndoSelectionAttr::Undo()
     455             : {
     456           0 :     BeginUndo();
     457           0 :     DoChange( true );
     458           0 :     EndUndo();
     459           0 : }
     460             : 
     461           0 : void ScUndoSelectionAttr::Redo()
     462             : {
     463           0 :     BeginRedo();
     464           0 :     DoChange( false );
     465           0 :     EndRedo();
     466           0 : }
     467             : 
     468           0 : void ScUndoSelectionAttr::Repeat(SfxRepeatTarget& rTarget)
     469             : {
     470           0 :     if (rTarget.ISA(ScTabViewTarget))
     471             :     {
     472           0 :         ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
     473           0 :         if (pLineOuter)
     474           0 :             rViewShell.ApplyPatternLines( *pApplyPattern, pLineOuter, pLineInner, true );
     475             :         else
     476           0 :             rViewShell.ApplySelectionPattern( *pApplyPattern, true );
     477             :     }
     478           0 : }
     479             : 
     480           8 : bool ScUndoSelectionAttr::CanRepeat(SfxRepeatTarget& rTarget) const
     481             : {
     482           8 :     return rTarget.ISA(ScTabViewTarget);
     483             : }
     484             : 
     485          16 : ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell,
     486             :                 const ScRange& rRange, const ScRange& rSourceArea,
     487             :                 ScDocument* pNewUndoDoc, const ScMarkData& rMark,
     488             :                 FillDir eNewFillDir, FillCmd eNewFillCmd, FillDateCmd eNewFillDateCmd,
     489             :                 double fNewStartValue, double fNewStepValue, double fNewMaxValue )
     490             :     :   ScBlockUndo( pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT ),
     491             :         aSource         ( rSourceArea ),
     492             :         aMarkData       ( rMark ),
     493             :         pUndoDoc        ( pNewUndoDoc ),
     494             :         eFillDir        ( eNewFillDir ),
     495             :         eFillCmd        ( eNewFillCmd ),
     496             :         eFillDateCmd    ( eNewFillDateCmd ),
     497             :         fStartValue     ( fNewStartValue ),
     498             :         fStepValue      ( fNewStepValue ),
     499          16 :         fMaxValue       ( fNewMaxValue )
     500             : {
     501          16 :     SetChangeTrack();
     502          16 : }
     503             : 
     504          45 : ScUndoAutoFill::~ScUndoAutoFill()
     505             : {
     506          15 :     delete pUndoDoc;
     507          30 : }
     508             : 
     509          18 : OUString ScUndoAutoFill::GetComment() const
     510             : {
     511          18 :     return ScGlobal::GetRscString( STR_UNDO_AUTOFILL ); //"Fill"
     512             : }
     513             : 
     514          17 : void ScUndoAutoFill::SetChangeTrack()
     515             : {
     516          17 :     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
     517          17 :     if ( pChangeTrack )
     518             :         pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
     519           0 :             nStartChangeAction, nEndChangeAction );
     520             :     else
     521          17 :         nStartChangeAction = nEndChangeAction = 0;
     522          17 : }
     523             : 
     524           1 : void ScUndoAutoFill::Undo()
     525             : {
     526           1 :     BeginUndo();
     527             : 
     528           1 :     ScDocument* pDoc = pDocShell->GetDocument();
     529             : 
     530           1 :     SCTAB nTabCount = pDoc->GetTableCount();
     531           1 :     ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
     532           2 :     for (; itr != itrEnd && *itr < nTabCount; ++itr)
     533             :     {
     534           1 :         ScRange aWorkRange = aBlockRange;
     535           1 :         aWorkRange.aStart.SetTab(*itr);
     536           1 :         aWorkRange.aEnd.SetTab(*itr);
     537             : 
     538           1 :         sal_uInt16 nExtFlags = 0;
     539           1 :         pDocShell->UpdatePaintExt( nExtFlags, aWorkRange );
     540           1 :         pDoc->DeleteAreaTab( aWorkRange, IDF_AUTOFILL );
     541           1 :         pUndoDoc->CopyToDocument( aWorkRange, IDF_AUTOFILL, false, pDoc );
     542             : 
     543           1 :         pDoc->ExtendMerge( aWorkRange, true );
     544           1 :         pDocShell->PostPaint( aWorkRange, PAINT_GRID, nExtFlags );
     545             :     }
     546           1 :     pDocShell->PostDataChanged();
     547           1 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     548           1 :     if (pViewShell)
     549           0 :         pViewShell->CellContentChanged();
     550             : 
     551           1 :     ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
     552           1 :     if ( pChangeTrack )
     553           0 :         pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
     554             : 
     555           1 :     EndUndo();
     556           1 : }
     557             : 
     558           1 : void ScUndoAutoFill::Redo()
     559             : {
     560           1 :     BeginRedo();
     561             : 
     562             : //! Select sheet
     563             : 
     564           1 :     SCCOLROW nCount = 0;
     565           1 :     switch (eFillDir)
     566             :     {
     567             :         case FILL_TO_BOTTOM:
     568           1 :             nCount = aBlockRange.aEnd.Row() - aSource.aEnd.Row();
     569           1 :             break;
     570             :         case FILL_TO_RIGHT:
     571           0 :             nCount = aBlockRange.aEnd.Col() - aSource.aEnd.Col();
     572           0 :             break;
     573             :         case FILL_TO_TOP:
     574           0 :             nCount = aSource.aStart.Row() - aBlockRange.aStart.Row();
     575           0 :             break;
     576             :         case FILL_TO_LEFT:
     577           0 :             nCount = aSource.aStart.Col() - aBlockRange.aStart.Col();
     578           0 :             break;
     579             :     }
     580             : 
     581           1 :     ScDocument* pDoc = pDocShell->GetDocument();
     582           1 :     if ( fStartValue != MAXDOUBLE )
     583             :     {
     584           0 :         SCCOL nValX = (eFillDir == FILL_TO_LEFT) ? aSource.aEnd.Col() : aSource.aStart.Col();
     585           0 :         SCROW nValY = (eFillDir == FILL_TO_TOP ) ? aSource.aEnd.Row() : aSource.aStart.Row();
     586           0 :         SCTAB nTab = aSource.aStart.Tab();
     587           0 :         pDoc->SetValue( nValX, nValY, nTab, fStartValue );
     588             :     }
     589             :     sal_uLong nProgCount;
     590           1 :     if (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_TOP)
     591           1 :         nProgCount = aSource.aEnd.Col() - aSource.aStart.Col() + 1;
     592             :     else
     593           0 :         nProgCount = aSource.aEnd.Row() - aSource.aStart.Row() + 1;
     594           1 :     nProgCount *= nCount;
     595             :     ScProgress aProgress( pDoc->GetDocumentShell(),
     596           1 :             ScGlobal::GetRscString(STR_FILL_SERIES_PROGRESS), nProgCount );
     597             : 
     598           1 :     pDoc->Fill( aSource.aStart.Col(), aSource.aStart.Row(),
     599           1 :             aSource.aEnd.Col(), aSource.aEnd.Row(), &aProgress,
     600             :             aMarkData, nCount,
     601             :             eFillDir, eFillCmd, eFillDateCmd,
     602           3 :             fStepValue, fMaxValue );
     603             : 
     604           1 :     SetChangeTrack();
     605             : 
     606           1 :     pDocShell->PostPaint( aBlockRange, PAINT_GRID );
     607           1 :     pDocShell->PostDataChanged();
     608           1 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     609           1 :     if (pViewShell)
     610           0 :         pViewShell->CellContentChanged();
     611             : 
     612           1 :     EndRedo();
     613           1 : }
     614             : 
     615           0 : void ScUndoAutoFill::Repeat(SfxRepeatTarget& rTarget)
     616             : {
     617           0 :     if (rTarget.ISA(ScTabViewTarget))
     618             :     {
     619           0 :         ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
     620           0 :         if (eFillCmd==FILL_SIMPLE)
     621           0 :             rViewShell.FillSimple( eFillDir, true );
     622             :         else
     623             :             rViewShell.FillSeries( eFillDir, eFillCmd, eFillDateCmd,
     624           0 :                                    fStartValue, fStepValue, fMaxValue, true );
     625             :     }
     626           0 : }
     627             : 
     628           0 : bool ScUndoAutoFill::CanRepeat(SfxRepeatTarget& rTarget) const
     629             : {
     630           0 :     return rTarget.ISA(ScTabViewTarget);
     631             : }
     632             : 
     633           4 : ScUndoMerge::ScUndoMerge( ScDocShell* pNewDocShell, const ScCellMergeOption& rOption,
     634             :                           bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo )
     635             :     :   ScSimpleUndo( pNewDocShell ),
     636             :         maOption(rOption),
     637             :         mbMergeContents( bMergeContents ),
     638             :         mpUndoDoc( pUndoDoc ),
     639           4 :         mpDrawUndo( pDrawUndo )
     640             : {
     641           4 : }
     642             : 
     643           9 : ScUndoMerge::~ScUndoMerge()
     644             : {
     645           3 :     delete mpUndoDoc;
     646           3 :     DeleteSdrUndoAction( mpDrawUndo );
     647           6 : }
     648             : 
     649           4 : OUString ScUndoMerge::GetComment() const
     650             : {
     651           4 :     return ScGlobal::GetRscString( STR_UNDO_MERGE );
     652             : }
     653             : 
     654           0 : void ScUndoMerge::DoChange( bool bUndo ) const
     655             : {
     656             :     using ::std::set;
     657             : 
     658           0 :     if (maOption.maTabs.empty())
     659             :         // Nothing to do.
     660           0 :         return;
     661             : 
     662           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     663           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     664             : 
     665           0 :     ScRange aCurRange = maOption.getSingleRange(pDocShell->GetCurTab());
     666           0 :     ScUndoUtil::MarkSimpleBlock(pDocShell, aCurRange);
     667             : 
     668           0 :     for (set<SCTAB>::const_iterator itr = maOption.maTabs.begin(), itrEnd = maOption.maTabs.end();
     669             :           itr != itrEnd; ++itr)
     670             :     {
     671           0 :         SCTAB nTab = *itr;
     672           0 :         ScRange aRange = maOption.getSingleRange(nTab);
     673             : 
     674           0 :         if (bUndo)
     675             :             // remove merge (contents are copied back below from undo document)
     676           0 :             pDoc->RemoveMerge( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aStart.Tab() );
     677             :         else
     678             :         {
     679             :             // repeat merge, but do not remove note captions (will be done by drawing redo below)
     680           0 :             pDoc->DoMerge( aRange.aStart.Tab(),
     681           0 :                            aRange.aStart.Col(), aRange.aStart.Row(),
     682           0 :                            aRange.aEnd.Col(),   aRange.aEnd.Row(), false );
     683             : 
     684           0 :             if (maOption.mbCenter)
     685             :             {
     686           0 :                 pDoc->ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
     687           0 :                                  aRange.aStart.Tab(),
     688           0 :                                  SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY ) );
     689           0 :                 pDoc->ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
     690           0 :                                  aRange.aStart.Tab(),
     691           0 :                                  SvxVerJustifyItem( SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY ) );
     692             :             }
     693             :         }
     694             : 
     695             :         // undo -> copy back deleted contents
     696           0 :         if (bUndo && mpUndoDoc)
     697             :         {
     698           0 :             pDoc->DeleteAreaTab( aRange, IDF_CONTENTS|IDF_NOCAPTIONS );
     699           0 :             mpUndoDoc->CopyToDocument( aRange, IDF_ALL|IDF_NOCAPTIONS, false, pDoc );
     700             :         }
     701             : 
     702             :         // redo -> merge contents again
     703           0 :         else if (!bUndo && mbMergeContents)
     704             :         {
     705           0 :             pDoc->DoMergeContents( aRange.aStart.Tab(),
     706           0 :                                    aRange.aStart.Col(), aRange.aStart.Row(),
     707           0 :                                    aRange.aEnd.Col(), aRange.aEnd.Row() );
     708             :         }
     709             : 
     710           0 :         if (bUndo)
     711           0 :             DoSdrUndoAction( mpDrawUndo, pDoc );
     712             :         else
     713           0 :             RedoSdrUndoAction( mpDrawUndo );
     714             : 
     715           0 :         bool bDidPaint = false;
     716           0 :         if ( pViewShell )
     717             :         {
     718           0 :             pViewShell->SetTabNo(nTab);
     719           0 :             bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow);
     720             :         }
     721             : 
     722           0 :         if (!bDidPaint)
     723           0 :             ScUndoUtil::PaintMore(pDocShell, aRange);
     724             :     }
     725             : 
     726           0 :     ShowTable(aCurRange);
     727             : }
     728             : 
     729           0 : void ScUndoMerge::Undo()
     730             : {
     731           0 :     BeginUndo();
     732           0 :     DoChange( true );
     733           0 :     EndUndo();
     734           0 : }
     735             : 
     736           0 : void ScUndoMerge::Redo()
     737             : {
     738           0 :     BeginRedo();
     739           0 :     DoChange( false );
     740           0 :     EndRedo();
     741           0 : }
     742             : 
     743           0 : void ScUndoMerge::Repeat(SfxRepeatTarget& rTarget)
     744             : {
     745           0 :     if (rTarget.ISA(ScTabViewTarget))
     746             :     {
     747           0 :         ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
     748           0 :         bool bCont = false;
     749           0 :         rViewShell.MergeCells( false, bCont, true );
     750             :     }
     751           0 : }
     752             : 
     753           0 : bool ScUndoMerge::CanRepeat(SfxRepeatTarget& rTarget) const
     754             : {
     755           0 :     return rTarget.ISA(ScTabViewTarget);
     756             : }
     757             : 
     758           0 : ScUndoAutoFormat::ScUndoAutoFormat( ScDocShell* pNewDocShell,
     759             :                         const ScRange& rRange, ScDocument* pNewUndoDoc,
     760             :                         const ScMarkData& rMark, bool bNewSize, sal_uInt16 nNewFormatNo )
     761             :     :   ScBlockUndo( pNewDocShell, rRange, bNewSize ? SC_UNDO_MANUALHEIGHT : SC_UNDO_AUTOHEIGHT ),
     762             :         pUndoDoc    ( pNewUndoDoc ),
     763             :         aMarkData   ( rMark ),
     764             :         bSize       ( bNewSize ),
     765           0 :         nFormatNo   ( nNewFormatNo )
     766             : {
     767           0 : }
     768             : 
     769           0 : ScUndoAutoFormat::~ScUndoAutoFormat()
     770             : {
     771           0 :     delete pUndoDoc;
     772           0 : }
     773             : 
     774           0 : OUString ScUndoAutoFormat::GetComment() const
     775             : {
     776           0 :     return ScGlobal::GetRscString( STR_UNDO_AUTOFORMAT );   //"Auto-Format"
     777             : }
     778             : 
     779           0 : void ScUndoAutoFormat::Undo()
     780             : {
     781           0 :     BeginUndo();
     782             : 
     783           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     784             : 
     785           0 :     SCTAB nTabCount = pDoc->GetTableCount();
     786           0 :     pDoc->DeleteArea( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(),
     787           0 :                       aBlockRange.aEnd.Col(), aBlockRange.aEnd.Row(),
     788           0 :                       aMarkData, IDF_ATTRIB );
     789           0 :     ScRange aCopyRange = aBlockRange;
     790           0 :     aCopyRange.aStart.SetTab(0);
     791           0 :     aCopyRange.aEnd.SetTab(nTabCount-1);
     792           0 :     pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, false, pDoc, &aMarkData );
     793             : 
     794             :     // cell heights and widths (IDF_NONE)
     795           0 :     if (bSize)
     796             :     {
     797           0 :         SCCOL nStartX = aBlockRange.aStart.Col();
     798           0 :         SCROW nStartY = aBlockRange.aStart.Row();
     799           0 :         SCTAB nStartZ = aBlockRange.aStart.Tab();
     800           0 :         SCCOL nEndX = aBlockRange.aEnd.Col();
     801           0 :         SCROW nEndY = aBlockRange.aEnd.Row();
     802           0 :         SCTAB nEndZ = aBlockRange.aEnd.Tab();
     803             : 
     804             :         pUndoDoc->CopyToDocument( nStartX, 0, 0, nEndX, MAXROW, nTabCount-1,
     805           0 :                                     IDF_NONE, false, pDoc, &aMarkData );
     806             :         pUndoDoc->CopyToDocument( 0, nStartY, 0, MAXCOL, nEndY, nTabCount-1,
     807           0 :                                     IDF_NONE, false, pDoc, &aMarkData );
     808             :         pDocShell->PostPaint( 0, 0, nStartZ, MAXCOL, MAXROW, nEndZ,
     809           0 :                               PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES );
     810             :     }
     811             :     else
     812           0 :         pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
     813             : 
     814           0 :     EndUndo();
     815           0 : }
     816             : 
     817           0 : void ScUndoAutoFormat::Redo()
     818             : {
     819           0 :     BeginRedo();
     820             : 
     821           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     822             : 
     823           0 :     SCCOL nStartX = aBlockRange.aStart.Col();
     824           0 :     SCROW nStartY = aBlockRange.aStart.Row();
     825           0 :     SCTAB nStartZ = aBlockRange.aStart.Tab();
     826           0 :     SCCOL nEndX = aBlockRange.aEnd.Col();
     827           0 :     SCROW nEndY = aBlockRange.aEnd.Row();
     828           0 :     SCTAB nEndZ = aBlockRange.aEnd.Tab();
     829             : 
     830           0 :     pDoc->AutoFormat( nStartX, nStartY, nEndX, nEndY, nFormatNo, aMarkData );
     831             : 
     832           0 :     if (bSize)
     833             :     {
     834           0 :         VirtualDevice aVirtDev;
     835           0 :         Fraction aZoomX(1,1);
     836           0 :         Fraction aZoomY = aZoomX;
     837             :         double nPPTX,nPPTY;
     838           0 :         ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     839           0 :         if (pViewShell)
     840             :         {
     841           0 :             ScViewData* pData = pViewShell->GetViewData();
     842           0 :             nPPTX = pData->GetPPTX();
     843           0 :             nPPTY = pData->GetPPTY();
     844           0 :             aZoomX = pData->GetZoomX();
     845           0 :             aZoomY = pData->GetZoomY();
     846             :         }
     847             :         else
     848             :         {
     849             :             // Keep zoom at 100
     850           0 :             nPPTX = ScGlobal::nScreenPPTX;
     851           0 :             nPPTY = ScGlobal::nScreenPPTY;
     852             :         }
     853             : 
     854           0 :         bool bFormula = false;  // remember
     855             : 
     856           0 :         sc::RowHeightContext aCxt(nPPTX, nPPTY, aZoomX, aZoomY, &aVirtDev);
     857           0 :         for (SCTAB nTab=nStartZ; nTab<=nEndZ; nTab++)
     858             :         {
     859           0 :             ScMarkData aDestMark;
     860           0 :             aDestMark.SelectOneTable( nTab );
     861           0 :             aDestMark.SetMarkArea( ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) );
     862           0 :             aDestMark.MarkToMulti();
     863             : 
     864             :             // as SC_SIZE_VISOPT
     865           0 :             for (SCROW nRow=nStartY; nRow<=nEndY; nRow++)
     866             :             {
     867           0 :                 sal_uInt8 nOld = pDoc->GetRowFlags(nRow,nTab);
     868           0 :                 bool bHidden = pDoc->RowHidden(nRow, nTab);
     869           0 :                 if ( !bHidden && ( nOld & CR_MANUALSIZE ) )
     870           0 :                     pDoc->SetRowFlags( nRow, nTab, nOld & ~CR_MANUALSIZE );
     871             :             }
     872             : 
     873           0 :             pDoc->SetOptimalHeight(aCxt, nStartY, nEndY, nTab);
     874             : 
     875           0 :             for (SCCOL nCol=nStartX; nCol<=nEndX; nCol++)
     876           0 :                 if (!pDoc->ColHidden(nCol, nTab))
     877             :                 {
     878             :                     sal_uInt16 nThisSize = STD_EXTRA_WIDTH + pDoc->GetOptimalColWidth( nCol, nTab,
     879             :                                                 &aVirtDev, nPPTX, nPPTY, aZoomX, aZoomY, bFormula,
     880           0 :                                                 &aDestMark );
     881           0 :                     pDoc->SetColWidth( nCol, nTab, nThisSize );
     882           0 :                     pDoc->ShowCol( nCol, nTab, true );
     883             :                 }
     884           0 :         }
     885             : 
     886             :         pDocShell->PostPaint( 0,      0,      nStartZ,
     887             :                               MAXCOL, MAXROW, nEndZ,
     888           0 :                               PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES);
     889             :     }
     890             :     else
     891           0 :         pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
     892             : 
     893           0 :     EndRedo();
     894           0 : }
     895             : 
     896           0 : void ScUndoAutoFormat::Repeat(SfxRepeatTarget& rTarget)
     897             : {
     898           0 :     if (rTarget.ISA(ScTabViewTarget))
     899           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->AutoFormat( nFormatNo, true );
     900           0 : }
     901             : 
     902           0 : bool ScUndoAutoFormat::CanRepeat(SfxRepeatTarget& rTarget) const
     903             : {
     904           0 :     return rTarget.ISA(ScTabViewTarget);
     905             : }
     906             : 
     907          22 : ScUndoReplace::ScUndoReplace( ScDocShell* pNewDocShell, const ScMarkData& rMark,
     908             :                                     SCCOL nCurX, SCROW nCurY, SCTAB nCurZ,
     909             :                                     const OUString& rNewUndoStr, ScDocument* pNewUndoDoc,
     910             :                                     const SvxSearchItem* pItem )
     911             :     :   ScSimpleUndo( pNewDocShell ),
     912             :         aCursorPos  ( nCurX, nCurY, nCurZ ),
     913             :         aMarkData   ( rMark ),
     914             :         aUndoStr    ( rNewUndoStr ),
     915          22 :         pUndoDoc    ( pNewUndoDoc )
     916             : {
     917          22 :     pSearchItem = new SvxSearchItem( *pItem );
     918          22 :     SetChangeTrack();
     919          22 : }
     920             : 
     921          60 : ScUndoReplace::~ScUndoReplace()
     922             : {
     923          20 :     delete pUndoDoc;
     924          20 :     delete pSearchItem;
     925          40 : }
     926             : 
     927          22 : void ScUndoReplace::SetChangeTrack()
     928             : {
     929          22 :     ScDocument* pDoc = pDocShell->GetDocument();
     930          22 :     ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
     931          22 :     if ( pChangeTrack )
     932             :     {
     933           0 :         if ( pUndoDoc )
     934             :         {   //! UndoDoc includes only the changed cells,
     935             :             // that is why an Iterator can be used
     936             :             pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
     937           0 :                 nStartChangeAction, nEndChangeAction );
     938             :         }
     939             :         else
     940             :         {
     941           0 :             nStartChangeAction = pChangeTrack->GetActionMax() + 1;
     942             :             ScChangeActionContent* pContent = new ScChangeActionContent(
     943           0 :                 ScRange( aCursorPos) );
     944           0 :             ScCellValue aCell;
     945           0 :             aCell.assign(*pDoc, aCursorPos);
     946           0 :             pContent->SetOldValue( aUndoStr, pDoc );
     947           0 :             pContent->SetNewValue(aCell, pDoc);
     948           0 :             pChangeTrack->Append( pContent );
     949           0 :             nEndChangeAction = pChangeTrack->GetActionMax();
     950             :         }
     951             :     }
     952             :     else
     953          22 :         nStartChangeAction = nEndChangeAction = 0;
     954          22 : }
     955             : 
     956          22 : OUString ScUndoReplace::GetComment() const
     957             : {
     958          22 :     return ScGlobal::GetRscString( STR_UNDO_REPLACE );  // "Replace"
     959             : }
     960             : 
     961           0 : void ScUndoReplace::Undo()
     962             : {
     963           0 :     BeginUndo();
     964             : 
     965           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     966           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     967             : 
     968           0 :     ShowTable( aCursorPos.Tab() );
     969             : 
     970           0 :     if (pUndoDoc)       // only for ReplaceAll !!
     971             :     {
     972             :         OSL_ENSURE(pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL,
     973             :                    "ScUndoReplace:: Wrong Mode");
     974             : 
     975           0 :         SetViewMarkData( aMarkData );
     976             : 
     977             : //! selected sheet
     978             : //! select range ?
     979             : 
     980             :         // Undo document has no row/column information, thus copy with
     981             :         // bColRowFlags = FALSE to not destroy Outline groups
     982             : 
     983           0 :         sal_uInt16 nUndoFlags = (pSearchItem->GetPattern()) ? IDF_ATTRIB : IDF_CONTENTS;
     984             :         pUndoDoc->CopyToDocument( 0,      0,      0,
     985             :                                   MAXCOL, MAXROW, MAXTAB,
     986           0 :                                   nUndoFlags, false, pDoc, NULL, false );   // without row flags
     987           0 :         pDocShell->PostPaintGridAll();
     988             :     }
     989           0 :     else if (pSearchItem->GetPattern() &&
     990           0 :              pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE)
     991             :     {
     992           0 :         OUString aTempStr = pSearchItem->GetSearchString();       // toggle
     993           0 :         pSearchItem->SetSearchString(pSearchItem->GetReplaceString());
     994           0 :         pSearchItem->SetReplaceString(aTempStr);
     995             :         pDoc->ReplaceStyle( *pSearchItem,
     996           0 :                             aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
     997           0 :                             aMarkData, true);
     998           0 :         pSearchItem->SetReplaceString(pSearchItem->GetSearchString());
     999           0 :         pSearchItem->SetSearchString(aTempStr);
    1000           0 :         if (pViewShell)
    1001           0 :             pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
    1002           0 :                                        SC_FOLLOW_JUMP, false, false );
    1003           0 :         pDocShell->PostPaintGridAll();
    1004             :     }
    1005           0 :     else if (pSearchItem->GetCellType() == SVX_SEARCHIN_NOTE)
    1006             :     {
    1007           0 :         ScPostIt* pNote = pDoc->GetNote(aCursorPos);
    1008             :         OSL_ENSURE( pNote, "ScUndoReplace::Undo - cell does not contain a note" );
    1009           0 :         if (pNote)
    1010           0 :             pNote->SetText( aCursorPos, aUndoStr );
    1011           0 :         if (pViewShell)
    1012           0 :             pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
    1013           0 :                                        SC_FOLLOW_JUMP, false, false );
    1014             :     }
    1015             :     else
    1016             :     {
    1017             :         // aUndoStr may contain line breaks
    1018           0 :         if ( aUndoStr.indexOf('\n') != -1 )
    1019             :         {
    1020           0 :             ScFieldEditEngine& rEngine = pDoc->GetEditEngine();
    1021           0 :             rEngine.SetText(aUndoStr);
    1022           0 :             pDoc->SetEditText(aCursorPos, rEngine.CreateTextObject());
    1023             :         }
    1024             :         else
    1025           0 :             pDoc->SetString( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aUndoStr );
    1026           0 :         if (pViewShell)
    1027           0 :             pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
    1028           0 :                                        SC_FOLLOW_JUMP, false, false );
    1029           0 :         pDocShell->PostPaintGridAll();
    1030             :     }
    1031             : 
    1032           0 :     ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
    1033           0 :     if ( pChangeTrack )
    1034           0 :         pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
    1035             : 
    1036           0 :     EndUndo();
    1037           0 : }
    1038             : 
    1039           0 : void ScUndoReplace::Redo()
    1040             : {
    1041           0 :     BeginRedo();
    1042             : 
    1043           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1044           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1045             : 
    1046           0 :     if (pViewShell)
    1047           0 :         pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
    1048           0 :                                    SC_FOLLOW_JUMP, false, false );
    1049           0 :     if (pUndoDoc)
    1050             :     {
    1051           0 :         if (pViewShell)
    1052             :         {
    1053           0 :             SetViewMarkData( aMarkData );
    1054             : 
    1055           0 :             pViewShell->SearchAndReplace( pSearchItem, false, true );
    1056             :         }
    1057             :     }
    1058           0 :     else if (pSearchItem->GetPattern() &&
    1059           0 :              pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE)
    1060             :     {
    1061             :         pDoc->ReplaceStyle( *pSearchItem,
    1062           0 :                             aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
    1063           0 :                             aMarkData, true);
    1064           0 :         pDocShell->PostPaintGridAll();
    1065             :     }
    1066             :     else
    1067           0 :         if (pViewShell)
    1068           0 :             pViewShell->SearchAndReplace( pSearchItem, false, true );
    1069             : 
    1070           0 :     SetChangeTrack();
    1071             : 
    1072           0 :     EndRedo();
    1073           0 : }
    1074             : 
    1075           0 : void ScUndoReplace::Repeat(SfxRepeatTarget& rTarget)
    1076             : {
    1077           0 :     if (rTarget.ISA(ScTabViewTarget))
    1078           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->SearchAndReplace( pSearchItem, true, false );
    1079           0 : }
    1080             : 
    1081           0 : bool ScUndoReplace::CanRepeat(SfxRepeatTarget& rTarget) const
    1082             : {
    1083           0 :     return rTarget.ISA(ScTabViewTarget);
    1084             : }
    1085             : 
    1086             : // multi-operation (only simple blocks)
    1087           3 : ScUndoTabOp::ScUndoTabOp( ScDocShell* pNewDocShell,
    1088             :                 SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
    1089             :                 SCCOL nEndX, SCROW nEndY, SCTAB nEndZ, ScDocument* pNewUndoDoc,
    1090             :                 const ScRefAddress& rFormulaCell,
    1091             :                 const ScRefAddress& rFormulaEnd,
    1092             :                 const ScRefAddress& rRowCell,
    1093             :                 const ScRefAddress& rColCell,
    1094             :                 ScTabOpParam::Mode eMode )
    1095             :     :   ScSimpleUndo( pNewDocShell ),
    1096             :         aRange          ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
    1097             :         pUndoDoc        ( pNewUndoDoc ),
    1098             :         theFormulaCell  ( rFormulaCell ),
    1099             :         theFormulaEnd   ( rFormulaEnd ),
    1100             :         theRowCell      ( rRowCell ),
    1101             :         theColCell      ( rColCell ),
    1102           3 :         meMode(eMode)
    1103             : {
    1104           3 : }
    1105             : 
    1106           9 : ScUndoTabOp::~ScUndoTabOp()
    1107             : {
    1108           3 :     delete pUndoDoc;
    1109           6 : }
    1110             : 
    1111           3 : OUString ScUndoTabOp::GetComment() const
    1112             : {
    1113           3 :     return ScGlobal::GetRscString( STR_UNDO_TABOP );    // "Multiple operation"
    1114             : }
    1115             : 
    1116           0 : void ScUndoTabOp::Undo()
    1117             : {
    1118           0 :     BeginUndo();
    1119             : 
    1120           0 :     ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
    1121             : 
    1122           0 :     sal_uInt16 nExtFlags = 0;
    1123           0 :     pDocShell->UpdatePaintExt( nExtFlags, aRange );
    1124             : 
    1125           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1126           0 :     pDoc->DeleteAreaTab( aRange,IDF_ALL & ~IDF_NOTE );
    1127           0 :     pUndoDoc->CopyToDocument( aRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
    1128           0 :     pDocShell->PostPaint( aRange, PAINT_GRID, nExtFlags );
    1129           0 :     pDocShell->PostDataChanged();
    1130           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1131           0 :     if (pViewShell)
    1132           0 :         pViewShell->CellContentChanged();
    1133             : 
    1134           0 :     EndUndo();
    1135           0 : }
    1136             : 
    1137           0 : void ScUndoTabOp::Redo()
    1138             : {
    1139           0 :     BeginRedo();
    1140             : 
    1141           0 :     ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
    1142             : 
    1143           0 :     ScTabOpParam aParam(theFormulaCell, theFormulaEnd, theRowCell, theColCell, meMode);
    1144             : 
    1145           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1146           0 :     if (pViewShell)
    1147           0 :         pViewShell->TabOp( aParam, false);
    1148             : 
    1149           0 :     EndRedo();
    1150           0 : }
    1151             : 
    1152           0 : void ScUndoTabOp::Repeat(SfxRepeatTarget& /* rTarget */)
    1153             : {
    1154           0 : }
    1155             : 
    1156           0 : bool ScUndoTabOp::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1157             : {
    1158           0 :     return false;
    1159             : }
    1160             : 
    1161           0 : ScUndoConversion::ScUndoConversion(
    1162             :         ScDocShell* pNewDocShell, const ScMarkData& rMark,
    1163             :         SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, ScDocument* pNewUndoDoc,
    1164             :         SCCOL nNewX, SCROW nNewY, SCTAB nNewZ, ScDocument* pNewRedoDoc,
    1165             :         const ScConversionParam& rConvParam ) :
    1166             :     ScSimpleUndo( pNewDocShell ),
    1167             :     aMarkData( rMark ),
    1168             :     aCursorPos( nCurX, nCurY, nCurZ ),
    1169             :     pUndoDoc( pNewUndoDoc ),
    1170             :     aNewCursorPos( nNewX, nNewY, nNewZ ),
    1171             :     pRedoDoc( pNewRedoDoc ),
    1172           0 :     maConvParam( rConvParam )
    1173             : {
    1174           0 :     SetChangeTrack();
    1175           0 : }
    1176             : 
    1177           0 : ScUndoConversion::~ScUndoConversion()
    1178             : {
    1179           0 :     delete pUndoDoc;
    1180           0 :     delete pRedoDoc;
    1181           0 : }
    1182             : 
    1183           0 : void ScUndoConversion::SetChangeTrack()
    1184             : {
    1185           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1186           0 :     ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
    1187           0 :     if ( pChangeTrack )
    1188             :     {
    1189           0 :         if ( pUndoDoc )
    1190             :             pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
    1191           0 :                 nStartChangeAction, nEndChangeAction );
    1192             :         else
    1193             :         {
    1194             :             OSL_FAIL( "ScUndoConversion::SetChangeTrack: no UndoDoc" );
    1195           0 :             nStartChangeAction = nEndChangeAction = 0;
    1196             :         }
    1197             :     }
    1198             :     else
    1199           0 :         nStartChangeAction = nEndChangeAction = 0;
    1200           0 : }
    1201             : 
    1202           0 : OUString ScUndoConversion::GetComment() const
    1203             : {
    1204           0 :     OUString aText;
    1205           0 :     switch( maConvParam.GetType() )
    1206             :     {
    1207           0 :         case SC_CONVERSION_SPELLCHECK:      aText = ScGlobal::GetRscString( STR_UNDO_SPELLING );    break;
    1208           0 :         case SC_CONVERSION_HANGULHANJA:     aText = ScGlobal::GetRscString( STR_UNDO_HANGULHANJA ); break;
    1209           0 :         case SC_CONVERSION_CHINESE_TRANSL:  aText = ScGlobal::GetRscString( STR_UNDO_CHINESE_TRANSLATION ); break;
    1210             :         default: OSL_FAIL( "ScUndoConversion::GetComment - unknown conversion type" );
    1211             :     }
    1212           0 :     return aText;
    1213             : }
    1214             : 
    1215           0 : void ScUndoConversion::DoChange( ScDocument* pRefDoc, const ScAddress& rCursorPos )
    1216             : {
    1217           0 :     if (pRefDoc)
    1218             :     {
    1219           0 :         ScDocument* pDoc = pDocShell->GetDocument();
    1220           0 :         ShowTable( rCursorPos.Tab() );
    1221             : 
    1222           0 :         SetViewMarkData( aMarkData );
    1223             : 
    1224           0 :         SCTAB nTabCount = pDoc->GetTableCount();
    1225             :         //  Undo/Redo-doc has only selected tables
    1226             : 
    1227           0 :         bool bMulti = aMarkData.IsMultiMarked();
    1228             :         pRefDoc->CopyToDocument( 0,      0,      0,
    1229             :                                  MAXCOL, MAXROW, nTabCount-1,
    1230           0 :                                  IDF_CONTENTS, bMulti, pDoc, &aMarkData );
    1231           0 :         pDocShell->PostPaintGridAll();
    1232             :     }
    1233             :     else
    1234             :     {
    1235             :         OSL_FAIL("no Un-/RedoDoc for Un-/RedoSpelling");
    1236             :     }
    1237           0 : }
    1238             : 
    1239           0 : void ScUndoConversion::Undo()
    1240             : {
    1241           0 :     BeginUndo();
    1242           0 :     DoChange( pUndoDoc, aCursorPos );
    1243           0 :     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
    1244           0 :     if ( pChangeTrack )
    1245           0 :         pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
    1246           0 :     EndUndo();
    1247           0 : }
    1248             : 
    1249           0 : void ScUndoConversion::Redo()
    1250             : {
    1251           0 :     BeginRedo();
    1252           0 :     DoChange( pRedoDoc, aNewCursorPos );
    1253           0 :     SetChangeTrack();
    1254           0 :     EndRedo();
    1255           0 : }
    1256             : 
    1257           0 : void ScUndoConversion::Repeat( SfxRepeatTarget& rTarget )
    1258             : {
    1259           0 :     if( rTarget.ISA( ScTabViewTarget ) )
    1260           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->DoSheetConversion( maConvParam, true );
    1261           0 : }
    1262             : 
    1263           0 : bool ScUndoConversion::CanRepeat(SfxRepeatTarget& rTarget) const
    1264             : {
    1265           0 :     return rTarget.ISA( ScTabViewTarget );
    1266             : }
    1267             : 
    1268           0 : ScUndoRefConversion::ScUndoRefConversion( ScDocShell* pNewDocShell,
    1269             :                                          const ScRange& aMarkRange, const ScMarkData& rMark,
    1270             :                                          ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc, bool bNewMulti, sal_uInt16 nNewFlag) :
    1271             : ScSimpleUndo( pNewDocShell ),
    1272             : aMarkData   ( rMark ),
    1273             : pUndoDoc    ( pNewUndoDoc ),
    1274             : pRedoDoc    ( pNewRedoDoc ),
    1275             : aRange      ( aMarkRange ),
    1276             : bMulti      ( bNewMulti ),
    1277           0 : nFlags      ( nNewFlag )
    1278             : {
    1279           0 :     SetChangeTrack();
    1280           0 : }
    1281             : 
    1282           0 : ScUndoRefConversion::~ScUndoRefConversion()
    1283             : {
    1284           0 :     delete pUndoDoc;
    1285           0 :     delete pRedoDoc;
    1286           0 : }
    1287             : 
    1288           0 : OUString ScUndoRefConversion::GetComment() const
    1289             : {
    1290           0 :     return ScGlobal::GetRscString( STR_UNDO_ENTERDATA ); // "Input"
    1291             : }
    1292             : 
    1293           0 : void ScUndoRefConversion::SetChangeTrack()
    1294             : {
    1295           0 :     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
    1296           0 :     if ( pChangeTrack && (nFlags & IDF_FORMULA) )
    1297             :         pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
    1298           0 :             nStartChangeAction, nEndChangeAction );
    1299             :     else
    1300           0 :         nStartChangeAction = nEndChangeAction = 0;
    1301           0 : }
    1302             : 
    1303           0 : void ScUndoRefConversion::DoChange( ScDocument* pRefDoc)
    1304             : {
    1305           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1306             : 
    1307           0 :     ShowTable(aRange);
    1308             : 
    1309           0 :     SetViewMarkData( aMarkData );
    1310             : 
    1311           0 :     ScRange aCopyRange = aRange;
    1312           0 :     SCTAB nTabCount = pDoc->GetTableCount();
    1313           0 :     aCopyRange.aStart.SetTab(0);
    1314           0 :     aCopyRange.aEnd.SetTab(nTabCount-1);
    1315           0 :     pRefDoc->CopyToDocument( aCopyRange, nFlags, bMulti, pDoc, &aMarkData );
    1316           0 :     pDocShell->PostPaint( aRange, PAINT_GRID);
    1317           0 :     pDocShell->PostDataChanged();
    1318           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1319           0 :     if (pViewShell)
    1320           0 :         pViewShell->CellContentChanged();
    1321           0 : }
    1322             : 
    1323           0 : void ScUndoRefConversion::Undo()
    1324             : {
    1325           0 :     BeginUndo();
    1326           0 :     if (pUndoDoc)
    1327           0 :         DoChange(pUndoDoc);
    1328           0 :     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
    1329           0 :     if ( pChangeTrack )
    1330           0 :         pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
    1331           0 :     EndUndo();
    1332           0 : }
    1333             : 
    1334           0 : void ScUndoRefConversion::Redo()
    1335             : {
    1336           0 :     BeginRedo();
    1337           0 :     if (pRedoDoc)
    1338           0 :         DoChange(pRedoDoc);
    1339           0 :     SetChangeTrack();
    1340           0 :     EndRedo();
    1341           0 : }
    1342             : 
    1343           0 : void ScUndoRefConversion::Repeat(SfxRepeatTarget& rTarget)
    1344             : {
    1345           0 :     if (rTarget.ISA(ScTabViewTarget))
    1346           0 :         ((ScTabViewTarget&)rTarget).GetViewShell()->DoRefConversion();
    1347           0 : }
    1348             : 
    1349           0 : bool ScUndoRefConversion::CanRepeat(SfxRepeatTarget& rTarget) const
    1350             : {
    1351           0 :     return rTarget.ISA(ScTabViewTarget);
    1352             : }
    1353             : 
    1354           2 : ScUndoRefreshLink::ScUndoRefreshLink( ScDocShell* pNewDocShell,
    1355             :                                     ScDocument* pNewUndoDoc )
    1356             :     :   ScSimpleUndo( pNewDocShell ),
    1357             :         pUndoDoc( pNewUndoDoc ),
    1358           2 :         pRedoDoc( NULL )
    1359             : {
    1360           2 : }
    1361             : 
    1362           6 : ScUndoRefreshLink::~ScUndoRefreshLink()
    1363             : {
    1364           2 :     delete pUndoDoc;
    1365           2 :     delete pRedoDoc;
    1366           4 : }
    1367             : 
    1368           4 : OUString ScUndoRefreshLink::GetComment() const
    1369             : {
    1370           4 :     return ScGlobal::GetRscString( STR_UNDO_UPDATELINK );
    1371             : }
    1372             : 
    1373           0 : void ScUndoRefreshLink::Undo()
    1374             : {
    1375           0 :     BeginUndo();
    1376             : 
    1377           0 :     bool bMakeRedo = !pRedoDoc;
    1378           0 :     if (bMakeRedo)
    1379           0 :         pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
    1380             : 
    1381           0 :     bool bFirst = true;
    1382           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1383           0 :     SCTAB nCount = pDoc->GetTableCount();
    1384           0 :     for (SCTAB nTab=0; nTab<nCount; nTab++)
    1385           0 :         if (pUndoDoc->HasTable(nTab))
    1386             :         {
    1387           0 :             ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
    1388           0 :             if (bMakeRedo)
    1389             :             {
    1390           0 :                 if (bFirst)
    1391           0 :                     pRedoDoc->InitUndo( pDoc, nTab, nTab, true, true );
    1392             :                 else
    1393           0 :                     pRedoDoc->AddUndoTab( nTab, nTab, true, true );
    1394           0 :                 bFirst = false;
    1395           0 :                 pDoc->CopyToDocument(aRange, IDF_ALL, false, pRedoDoc);
    1396             :                 pRedoDoc->SetLink( nTab,
    1397           0 :                                    pDoc->GetLinkMode(nTab),
    1398             :                                    pDoc->GetLinkDoc(nTab),
    1399             :                                    pDoc->GetLinkFlt(nTab),
    1400             :                                    pDoc->GetLinkOpt(nTab),
    1401             :                                    pDoc->GetLinkTab(nTab),
    1402           0 :                                    pDoc->GetLinkRefreshDelay(nTab) );
    1403           0 :                                 pRedoDoc->SetTabBgColor( nTab, pDoc->GetTabBgColor(nTab) );
    1404             :             }
    1405             : 
    1406           0 :             pDoc->DeleteAreaTab( aRange,IDF_ALL );
    1407           0 :             pUndoDoc->CopyToDocument( aRange, IDF_ALL, false, pDoc );
    1408           0 :             pDoc->SetLink( nTab, pUndoDoc->GetLinkMode(nTab), pUndoDoc->GetLinkDoc(nTab),
    1409             :                                  pUndoDoc->GetLinkFlt(nTab),  pUndoDoc->GetLinkOpt(nTab),
    1410             :                                  pUndoDoc->GetLinkTab(nTab),
    1411           0 :                                  pUndoDoc->GetLinkRefreshDelay(nTab) );
    1412           0 :                         pDoc->SetTabBgColor( nTab, pUndoDoc->GetTabBgColor(nTab) );
    1413             :         }
    1414             : 
    1415           0 :     pDocShell->PostPaintGridAll();
    1416           0 :         pDocShell->PostPaintExtras();
    1417             : 
    1418           0 :     EndUndo();
    1419           0 : }
    1420             : 
    1421           0 : void ScUndoRefreshLink::Redo()
    1422             : {
    1423             :     OSL_ENSURE(pRedoDoc, "No RedoDoc for ScUndoRefreshLink::Redo");
    1424             : 
    1425           0 :     BeginUndo();
    1426             : 
    1427           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1428           0 :     SCTAB nCount = pDoc->GetTableCount();
    1429           0 :     for (SCTAB nTab=0; nTab<nCount; nTab++)
    1430           0 :         if (pRedoDoc->HasTable(nTab))
    1431             :         {
    1432           0 :             ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
    1433             : 
    1434           0 :             pDoc->DeleteAreaTab( aRange, IDF_ALL );
    1435           0 :             pRedoDoc->CopyToDocument( aRange, IDF_ALL, false, pDoc );
    1436             :             pDoc->SetLink( nTab,
    1437           0 :                            pRedoDoc->GetLinkMode(nTab),
    1438             :                            pRedoDoc->GetLinkDoc(nTab),
    1439             :                            pRedoDoc->GetLinkFlt(nTab),
    1440             :                            pRedoDoc->GetLinkOpt(nTab),
    1441             :                            pRedoDoc->GetLinkTab(nTab),
    1442           0 :                            pRedoDoc->GetLinkRefreshDelay(nTab) );
    1443           0 :             pDoc->SetTabBgColor( nTab, pRedoDoc->GetTabBgColor(nTab) );
    1444             :         }
    1445             : 
    1446           0 :     pDocShell->PostPaintGridAll();
    1447           0 :         pDocShell->PostPaintExtras();
    1448             : 
    1449           0 :     EndUndo();
    1450           0 : }
    1451             : 
    1452           0 : void ScUndoRefreshLink::Repeat(SfxRepeatTarget& /* rTarget */)
    1453             : {
    1454             :     // makes no sense
    1455           0 : }
    1456             : 
    1457           2 : bool ScUndoRefreshLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1458             : {
    1459           2 :     return false;
    1460             : }
    1461             : 
    1462           0 : static ScAreaLink* lcl_FindAreaLink( sfx2::LinkManager* pLinkManager, const OUString& rDoc,
    1463             :                             const OUString& rFlt, const OUString& rOpt,
    1464             :                             const OUString& rSrc, const ScRange& rDest )
    1465             : {
    1466           0 :     const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
    1467           0 :     sal_uInt16 nCount = pLinkManager->GetLinks().size();
    1468           0 :     for (sal_uInt16 i=0; i<nCount; i++)
    1469             :     {
    1470           0 :         ::sfx2::SvBaseLink* pBase = *rLinks[i];
    1471           0 :         if (pBase->ISA(ScAreaLink))
    1472           0 :             if ( ((ScAreaLink*)pBase)->IsEqual( rDoc, rFlt, rOpt, rSrc, rDest ) )
    1473           0 :                 return (ScAreaLink*)pBase;
    1474             :     }
    1475             : 
    1476             :     OSL_FAIL("ScAreaLink not found");
    1477           0 :     return NULL;
    1478             : }
    1479             : 
    1480          16 : ScUndoInsertAreaLink::ScUndoInsertAreaLink( ScDocShell* pShell,
    1481             :                             const OUString& rDoc,
    1482             :                             const OUString& rFlt, const OUString& rOpt,
    1483             :                             const OUString& rArea, const ScRange& rDestRange,
    1484             :                             sal_uLong nRefresh )
    1485             :     :   ScSimpleUndo    ( pShell ),
    1486             :         aDocName        ( rDoc ),
    1487             :         aFltName        ( rFlt ),
    1488             :         aOptions        ( rOpt ),
    1489             :         aAreaName       ( rArea ),
    1490             :         aRange          ( rDestRange ),
    1491          16 :         nRefreshDelay   ( nRefresh )
    1492             : {
    1493          16 : }
    1494             : 
    1495          32 : ScUndoInsertAreaLink::~ScUndoInsertAreaLink()
    1496             : {
    1497          32 : }
    1498             : 
    1499          16 : OUString ScUndoInsertAreaLink::GetComment() const
    1500             : {
    1501          16 :     return ScGlobal::GetRscString( STR_UNDO_INSERTAREALINK );
    1502             : }
    1503             : 
    1504           0 : void ScUndoInsertAreaLink::Undo()
    1505             : {
    1506           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1507           0 :     sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
    1508             : 
    1509             :     ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
    1510           0 :                                             aAreaName, aRange );
    1511           0 :     if (pLink)
    1512           0 :         pLinkManager->Remove( pLink );
    1513             : 
    1514           0 :     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );     // Navigator
    1515           0 : }
    1516             : 
    1517           0 : void ScUndoInsertAreaLink::Redo()
    1518             : {
    1519           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1520           0 :     sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
    1521             : 
    1522             :     ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
    1523           0 :                                             aAreaName, aRange.aStart, nRefreshDelay );
    1524           0 :     pLink->SetInCreate( true );
    1525           0 :     pLink->SetDestArea( aRange );
    1526           0 :     pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
    1527           0 :     pLink->Update();
    1528           0 :     pLink->SetInCreate( false );
    1529             : 
    1530           0 :     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );     // Navigator
    1531           0 : }
    1532             : 
    1533           0 : void ScUndoInsertAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
    1534             : {
    1535             :     // makes no sense
    1536           0 : }
    1537             : 
    1538           0 : bool ScUndoInsertAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1539             : {
    1540           0 :     return false;
    1541             : }
    1542             : 
    1543           0 : ScUndoRemoveAreaLink::ScUndoRemoveAreaLink( ScDocShell* pShell,
    1544             :                             const OUString& rDoc, const OUString& rFlt, const OUString& rOpt,
    1545             :                             const OUString& rArea, const ScRange& rDestRange,
    1546             :                             sal_uLong nRefresh )
    1547             :     :   ScSimpleUndo    ( pShell ),
    1548             :         aDocName        ( rDoc ),
    1549             :         aFltName        ( rFlt ),
    1550             :         aOptions        ( rOpt ),
    1551             :         aAreaName       ( rArea ),
    1552             :         aRange          ( rDestRange ),
    1553           0 :         nRefreshDelay   ( nRefresh )
    1554             : {
    1555           0 : }
    1556             : 
    1557           0 : ScUndoRemoveAreaLink::~ScUndoRemoveAreaLink()
    1558             : {
    1559           0 : }
    1560             : 
    1561           0 : OUString ScUndoRemoveAreaLink::GetComment() const
    1562             : {
    1563           0 :     return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );   //! eigener Text ??
    1564             : }
    1565             : 
    1566           0 : void ScUndoRemoveAreaLink::Undo()
    1567             : {
    1568           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1569           0 :     sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
    1570             : 
    1571             :     ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
    1572           0 :                                         aAreaName, aRange.aStart, nRefreshDelay );
    1573           0 :     pLink->SetInCreate( true );
    1574           0 :     pLink->SetDestArea( aRange );
    1575           0 :     pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
    1576           0 :     pLink->Update();
    1577           0 :     pLink->SetInCreate( false );
    1578             : 
    1579           0 :     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );     // Navigator
    1580           0 : }
    1581             : 
    1582           0 : void ScUndoRemoveAreaLink::Redo()
    1583             : {
    1584           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1585           0 :     sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
    1586             : 
    1587             :     ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
    1588           0 :                                             aAreaName, aRange );
    1589           0 :     if (pLink)
    1590           0 :         pLinkManager->Remove( pLink );
    1591             : 
    1592           0 :     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );     // Navigator
    1593           0 : }
    1594             : 
    1595           0 : void ScUndoRemoveAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
    1596             : {
    1597             :     // makes no sense
    1598           0 : }
    1599             : 
    1600           0 : bool ScUndoRemoveAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1601             : {
    1602           0 :     return false;
    1603             : }
    1604             : 
    1605           4 : ScUndoUpdateAreaLink::ScUndoUpdateAreaLink( ScDocShell* pShell,
    1606             :                             const OUString& rOldD, const OUString& rOldF, const OUString& rOldO,
    1607             :                             const OUString& rOldA, const ScRange& rOldR, sal_uLong nOldRD,
    1608             :                             const OUString& rNewD, const OUString& rNewF, const OUString& rNewO,
    1609             :                             const OUString& rNewA, const ScRange& rNewR, sal_uLong nNewRD,
    1610             :                             ScDocument* pUndo, ScDocument* pRedo, bool bDoInsert )
    1611             :     :   ScSimpleUndo( pShell ),
    1612             :         aOldDoc     ( rOldD ),
    1613             :         aOldFlt     ( rOldF ),
    1614             :         aOldOpt     ( rOldO ),
    1615             :         aOldArea    ( rOldA ),
    1616             :         aOldRange   ( rOldR ),
    1617             :         aNewDoc     ( rNewD ),
    1618             :         aNewFlt     ( rNewF ),
    1619             :         aNewOpt     ( rNewO ),
    1620             :         aNewArea    ( rNewA ),
    1621             :         aNewRange   ( rNewR ),
    1622             :         pUndoDoc    ( pUndo ),
    1623             :         pRedoDoc    ( pRedo ),
    1624             :         nOldRefresh ( nOldRD ),
    1625             :         nNewRefresh ( nNewRD ),
    1626           4 :         bWithInsert ( bDoInsert )
    1627             : {
    1628             :     OSL_ENSURE( aOldRange.aStart == aNewRange.aStart, "AreaLink moved ?" );
    1629           4 : }
    1630             : 
    1631          12 : ScUndoUpdateAreaLink::~ScUndoUpdateAreaLink()
    1632             : {
    1633           4 :     delete pUndoDoc;
    1634           4 :     delete pRedoDoc;
    1635           8 : }
    1636             : 
    1637           4 : OUString ScUndoUpdateAreaLink::GetComment() const
    1638             : {
    1639           4 :     return ScGlobal::GetRscString( STR_UNDO_UPDATELINK );   //! own text ??
    1640             : }
    1641             : 
    1642           0 : void ScUndoUpdateAreaLink::DoChange( const bool bUndo ) const
    1643             : {
    1644           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1645             : 
    1646           0 :     SCCOL nEndX = std::max( aOldRange.aEnd.Col(), aNewRange.aEnd.Col() );
    1647           0 :     SCROW nEndY = std::max( aOldRange.aEnd.Row(), aNewRange.aEnd.Row() );
    1648           0 :     SCTAB nEndZ = std::max( aOldRange.aEnd.Tab(), aNewRange.aEnd.Tab() );    //?
    1649             : 
    1650           0 :     if ( bUndo )
    1651             :     {
    1652           0 :         if ( bWithInsert )
    1653             :         {
    1654           0 :             pDoc->FitBlock( aNewRange, aOldRange );
    1655           0 :             pDoc->DeleteAreaTab( aOldRange, IDF_ALL & ~IDF_NOTE );
    1656           0 :             pUndoDoc->UndoToDocument( aOldRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
    1657             :         }
    1658             :         else
    1659             :         {
    1660           0 :             ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
    1661           0 :             pDoc->DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
    1662           0 :             pUndoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
    1663             :         }
    1664             :     }
    1665             :     else
    1666             :     {
    1667           0 :         if ( bWithInsert )
    1668             :         {
    1669           0 :             pDoc->FitBlock( aOldRange, aNewRange );
    1670           0 :             pDoc->DeleteAreaTab( aNewRange, IDF_ALL & ~IDF_NOTE );
    1671           0 :             pRedoDoc->CopyToDocument( aNewRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
    1672             :         }
    1673             :         else
    1674             :         {
    1675           0 :             ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
    1676           0 :             pDoc->DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
    1677           0 :             pRedoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
    1678             :         }
    1679             :     }
    1680             : 
    1681           0 :     ScRange aWorkRange( aNewRange.aStart, ScAddress( nEndX, nEndY, nEndZ ) );
    1682           0 :     pDoc->ExtendMerge( aWorkRange, true );
    1683             : 
    1684             :     //  Paint
    1685             : 
    1686           0 :     if ( aNewRange.aEnd.Col() != aOldRange.aEnd.Col() )
    1687           0 :         aWorkRange.aEnd.SetCol(MAXCOL);
    1688           0 :     if ( aNewRange.aEnd.Row() != aOldRange.aEnd.Row() )
    1689           0 :         aWorkRange.aEnd.SetRow(MAXROW);
    1690             : 
    1691           0 :     if ( !pDocShell->AdjustRowHeight( aWorkRange.aStart.Row(), aWorkRange.aEnd.Row(), aWorkRange.aStart.Tab() ) )
    1692           0 :         pDocShell->PostPaint( aWorkRange, PAINT_GRID );
    1693             : 
    1694           0 :     pDocShell->PostDataChanged();
    1695           0 :     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
    1696           0 :     if (pViewShell)
    1697           0 :         pViewShell->CellContentChanged();
    1698           0 : }
    1699             : 
    1700           0 : void ScUndoUpdateAreaLink::Undo()
    1701             : {
    1702           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1703           0 :     sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
    1704             :     ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aNewDoc, aNewFlt, aNewOpt,
    1705           0 :                                             aNewArea, aNewRange );
    1706           0 :     if (pLink)
    1707             :     {
    1708           0 :         pLink->SetSource( aOldDoc, aOldFlt, aOldOpt, aOldArea );        // old data in Link
    1709           0 :         pLink->SetDestArea( aOldRange );
    1710           0 :         pLink->SetRefreshDelay( nOldRefresh );
    1711             :     }
    1712             : 
    1713           0 :     DoChange(true);
    1714           0 : }
    1715             : 
    1716           0 : void ScUndoUpdateAreaLink::Redo()
    1717             : {
    1718           0 :     ScDocument* pDoc = pDocShell->GetDocument();
    1719           0 :     sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
    1720             :     ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aOldDoc, aOldFlt, aOldOpt,
    1721           0 :                                             aOldArea, aOldRange );
    1722           0 :     if (pLink)
    1723             :     {
    1724           0 :         pLink->SetSource( aNewDoc, aNewFlt, aNewOpt, aNewArea );        // neue Werte im Link
    1725           0 :         pLink->SetDestArea( aNewRange );
    1726           0 :         pLink->SetRefreshDelay( nNewRefresh );
    1727             :     }
    1728             : 
    1729           0 :     DoChange(false);
    1730           0 : }
    1731             : 
    1732           0 : void ScUndoUpdateAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
    1733             : {
    1734             :     // makes no sense
    1735           0 : }
    1736             : 
    1737           0 : bool ScUndoUpdateAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
    1738             : {
    1739           0 :     return false;
    1740         102 : }
    1741             : 
    1742             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10