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

Generated by: LCOV version 1.10