LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/undo - refundo.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 63 87 72.4 %
Date: 2012-12-27 Functions: 5 6 83.3 %
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 "refundo.hxx"
      21             : #include "undobase.hxx"
      22             : #include "document.hxx"
      23             : #include "dbdata.hxx"
      24             : #include "rangenam.hxx"
      25             : #include "pivot.hxx"
      26             : #include "chartarr.hxx"
      27             : #include "stlpool.hxx"
      28             : #include "detdata.hxx"
      29             : #include "prnsave.hxx"
      30             : #include "chartlis.hxx"
      31             : #include "dpobject.hxx"
      32             : #include "areasave.hxx"
      33             : #include "unoreflist.hxx"
      34             : 
      35           3 : ScRefUndoData::ScRefUndoData( const ScDocument* pDoc ) :
      36           3 :     pUnoRefs( NULL )
      37             : {
      38           3 :     ScDBCollection* pOldDBColl = pDoc->GetDBCollection();
      39           3 :     pDBCollection = pOldDBColl ? new ScDBCollection(*pOldDBColl) : NULL;
      40             : 
      41           3 :     ScRangeName* pOldRanges = ((ScDocument*)pDoc)->GetRangeName();          //! const
      42           3 :     pRangeName = pOldRanges ? new ScRangeName(*pOldRanges) : NULL;
      43             : 
      44           3 :     pPrintRanges = pDoc->CreatePrintRangeSaver();       // recreated
      45             : 
      46             :     // when handling Pivot solely keep the range?
      47             : 
      48           3 :     ScDPCollection* pOldDP = ((ScDocument*)pDoc)->GetDPCollection();        //! const
      49           3 :     pDPCollection = pOldDP ? new ScDPCollection(*pOldDP) : NULL;
      50             : 
      51           3 :     ScDetOpList* pOldDetOp = pDoc->GetDetOpList();
      52           3 :     pDetOpList = pOldDetOp ? new ScDetOpList(*pOldDetOp) : 0;
      53             : 
      54             :     ScChartListenerCollection* pOldChartListenerCollection =
      55           3 :         pDoc->GetChartListenerCollection();
      56             :     pChartListenerCollection = pOldChartListenerCollection ?
      57           3 :         new ScChartListenerCollection( *pOldChartListenerCollection ) : NULL;
      58             : 
      59           3 :     pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(pDoc);     // returns NULL if empty
      60             : 
      61           3 :     const_cast<ScDocument*>(pDoc)->BeginUnoRefUndo();
      62           3 : }
      63             : 
      64           0 : ScRefUndoData::~ScRefUndoData()
      65             : {
      66           0 :     delete pDBCollection;
      67           0 :     delete pRangeName;
      68           0 :     delete pPrintRanges;
      69           0 :     delete pDPCollection;
      70           0 :     delete pDetOpList;
      71           0 :     delete pChartListenerCollection;
      72           0 :     delete pAreaLinks;
      73           0 :     delete pUnoRefs;
      74           0 : }
      75             : 
      76           3 : void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
      77             : {
      78           3 :     if (pDBCollection)
      79             :     {
      80           3 :         ScDBCollection* pNewDBColl = pDoc->GetDBCollection();
      81           3 :         if ( pNewDBColl && *pDBCollection == *pNewDBColl )
      82           1 :             DELETEZ(pDBCollection);
      83             :     }
      84           3 :     if (pRangeName)
      85             :     {
      86           3 :         ScRangeName* pNewRanges = ((ScDocument*)pDoc)->GetRangeName();      //! const
      87           3 :         if ( pNewRanges && *pRangeName == *pNewRanges )
      88           3 :             DELETEZ(pRangeName);
      89             :     }
      90             : 
      91           3 :     if (pPrintRanges)
      92             :     {
      93           3 :         ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver();
      94           3 :         if ( pNewRanges && *pPrintRanges == *pNewRanges )
      95           3 :             DELETEZ(pPrintRanges);
      96           3 :         delete pNewRanges;
      97             :     }
      98             : 
      99           3 :     if (pDPCollection)
     100             :     {
     101           3 :         ScDPCollection* pNewDP = ((ScDocument*)pDoc)->GetDPCollection();    //! const
     102           3 :         if ( pNewDP && pDPCollection->RefsEqual(*pNewDP) )
     103           3 :             DELETEZ(pDPCollection);
     104             :     }
     105             : 
     106           3 :     if (pDetOpList)
     107             :     {
     108           0 :         ScDetOpList* pNewDetOp = pDoc->GetDetOpList();
     109           0 :         if ( pNewDetOp && *pDetOpList == *pNewDetOp )
     110           0 :             DELETEZ(pDetOpList);
     111             :     }
     112             : 
     113           3 :     if ( pChartListenerCollection )
     114             :     {
     115             :         ScChartListenerCollection* pNewChartListenerCollection =
     116           3 :             pDoc->GetChartListenerCollection();
     117           6 :         if ( pNewChartListenerCollection &&
     118           3 :                 *pChartListenerCollection == *pNewChartListenerCollection )
     119           3 :             DELETEZ( pChartListenerCollection );
     120             :     }
     121             : 
     122           3 :     if (pAreaLinks)
     123             :     {
     124           0 :         if ( pAreaLinks->IsEqual( pDoc ) )
     125           0 :             DELETEZ(pAreaLinks);
     126             :     }
     127             : 
     128           3 :     if ( pDoc->HasUnoRefUndo() )
     129             :     {
     130           3 :         pUnoRefs = const_cast<ScDocument*>(pDoc)->EndUnoRefUndo();
     131           3 :         if ( pUnoRefs && pUnoRefs->IsEmpty() )
     132             :         {
     133           3 :             DELETEZ( pUnoRefs );
     134             :         }
     135             :     }
     136           3 : }
     137             : 
     138           2 : void ScRefUndoData::DoUndo( ScDocument* pDoc, sal_Bool bUndoRefFirst )
     139             : {
     140           2 :     if (pDBCollection)
     141           1 :         pDoc->SetDBCollection( new ScDBCollection(*pDBCollection) );
     142           2 :     if (pRangeName)
     143           0 :         pDoc->SetRangeName( new ScRangeName(*pRangeName) );
     144             : 
     145           2 :     if (pPrintRanges)
     146           0 :         pDoc->RestorePrintRanges(*pPrintRanges);
     147             : 
     148           2 :     if (pDPCollection)
     149             :     {
     150           0 :         ScDPCollection* pDocDP = pDoc->GetDPCollection();
     151           0 :         if (pDocDP)
     152           0 :             pDPCollection->WriteRefsTo( *pDocDP );
     153             :     }
     154             : 
     155           2 :     if (pDetOpList)
     156           0 :         pDoc->SetDetOpList( new ScDetOpList(*pDetOpList) );
     157             : 
     158             :     // bUndoRefFirst is bSetChartRangeLists
     159           2 :     if ( pChartListenerCollection )
     160             :         pDoc->SetChartListenerCollection( new ScChartListenerCollection(
     161           0 :             *pChartListenerCollection ), bUndoRefFirst );
     162             : 
     163           2 :     if (pDBCollection || pRangeName)
     164             :     {
     165           1 :         sal_Bool bOldAutoCalc = pDoc->GetAutoCalc();
     166           1 :         pDoc->SetAutoCalc( false ); // Avoid multiple calculations
     167           1 :         pDoc->CompileAll();
     168           1 :         pDoc->SetDirty();
     169           1 :         pDoc->SetAutoCalc( bOldAutoCalc );
     170             :     }
     171             : 
     172           2 :     if (pAreaLinks)
     173           0 :         pAreaLinks->Restore( pDoc );
     174             : 
     175           2 :     if ( pUnoRefs )
     176           0 :         pUnoRefs->Undo( pDoc );
     177          17 : }
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10