LCOV - code coverage report
Current view: top level - sc/source/ui/undo - areasave.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 96 8.3 %
Date: 2012-08-25 Functions: 1 17 5.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 126 1.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <sfx2/linkmgr.hxx>
      30                 :            : 
      31                 :            : #include "areasave.hxx"
      32                 :            : #include "arealink.hxx"
      33                 :            : #include "document.hxx"
      34                 :            : 
      35                 :            : // -----------------------------------------------------------------------
      36                 :            : 
      37                 :          0 : ScAreaLinkSaver::ScAreaLinkSaver( const ScAreaLink& rSource ) :
      38                 :          0 :     aFileName   ( rSource.GetFile() ),
      39                 :          0 :     aFilterName ( rSource.GetFilter() ),
      40                 :          0 :     aOptions    ( rSource.GetOptions() ),
      41                 :          0 :     aSourceArea ( rSource.GetSource() ),
      42                 :          0 :     aDestArea   ( rSource.GetDestArea() ),
      43   [ #  #  #  #  :          0 :     nRefresh    ( rSource.GetRefreshDelay() )       // seconds
                   #  # ]
      44                 :            : {
      45                 :          0 : }
      46                 :            : 
      47                 :          0 : ScAreaLinkSaver::ScAreaLinkSaver( const ScAreaLinkSaver& rCopy ) :
      48                 :            :     aFileName   ( rCopy.aFileName ),
      49                 :            :     aFilterName ( rCopy.aFilterName ),
      50                 :            :     aOptions    ( rCopy.aOptions ),
      51                 :            :     aSourceArea ( rCopy.aSourceArea ),
      52                 :            :     aDestArea   ( rCopy.aDestArea ),
      53                 :          0 :     nRefresh    ( rCopy.nRefresh )
      54                 :            : {
      55                 :          0 : }
      56                 :            : 
      57                 :          0 : ScAreaLinkSaver::~ScAreaLinkSaver() {}
      58                 :            : 
      59                 :          0 : bool ScAreaLinkSaver::IsEqualSource( const ScAreaLink& rCompare ) const
      60                 :            : {
      61 [ #  # ][ #  # ]:          0 :     return ( aFileName.equals(rCompare.GetFile()) &&
                 [ #  # ]
      62 [ #  # ][ #  # ]:          0 :              aFilterName.equals(rCompare.GetFilter()) &&
                 [ #  # ]
      63 [ #  # ][ #  # ]:          0 :              aOptions.equals(rCompare.GetOptions()) &&
                 [ #  # ]
      64 [ #  # ][ #  # ]:          0 :              aSourceArea.equals(rCompare.GetSource()) &&
                 [ #  # ]
      65 [ #  # ][ #  #  :          0 :              nRefresh == rCompare.GetRefreshDelay() );
          #  #  #  #  #  
                      # ]
      66                 :            : }
      67                 :            : 
      68                 :          0 : bool ScAreaLinkSaver::IsEqual( const ScAreaLink& rCompare ) const
      69                 :            : {
      70                 :          0 :     return ( IsEqualSource( rCompare ) &&
      71 [ #  # ][ #  # ]:          0 :              aDestArea == rCompare.GetDestArea() );
      72                 :            : }
      73                 :            : 
      74                 :          0 : void ScAreaLinkSaver::WriteToLink( ScAreaLink& rLink ) const
      75                 :            : {
      76                 :          0 :     rLink.SetDestArea( aDestArea );
      77                 :          0 : }
      78                 :            : 
      79                 :          0 : void ScAreaLinkSaver::InsertNewLink( ScDocument* pDoc ) const
      80                 :            : {
      81                 :            :     // (see ScUndoRemoveAreaLink::Undo)
      82                 :            : 
      83                 :          0 :     sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
      84                 :          0 :     SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
      85                 :            : 
      86 [ #  # ][ #  # ]:          0 :     if ( pLinkManager && pObjSh )
      87                 :            :     {
      88                 :            :         ScAreaLink* pLink = new ScAreaLink( pObjSh, aFileName, aFilterName, aOptions,
      89 [ #  # ][ #  # ]:          0 :                                             aSourceArea, aDestArea.aStart, nRefresh );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      90                 :          0 :         pLink->SetInCreate( sal_True );
      91         [ #  # ]:          0 :         pLink->SetDestArea( aDestArea );
      92 [ #  # ][ #  # ]:          0 :         String aTmp1(aFilterName), aTmp2(aSourceArea);
      93 [ #  # ][ #  # ]:          0 :         pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aFileName, &aTmp1, &aTmp2 );
                 [ #  # ]
      94         [ #  # ]:          0 :         pLink->Update();
      95 [ #  # ][ #  # ]:          0 :         pLink->SetInCreate( false );
      96                 :            :     }
      97                 :          0 : }
      98                 :            : 
      99                 :          0 : ScAreaLinkSaveCollection::ScAreaLinkSaveCollection() {}
     100                 :            : 
     101                 :          0 : ScAreaLinkSaveCollection::ScAreaLinkSaveCollection( const ScAreaLinkSaveCollection& r ) :
     102                 :          0 :     maData(r.maData) {}
     103                 :            : 
     104                 :          0 : ScAreaLinkSaveCollection::~ScAreaLinkSaveCollection() {}
     105                 :            : 
     106                 :          0 : bool ScAreaLinkSaveCollection::IsEqual( const ScDocument* pDoc ) const
     107                 :            : {
     108                 :            :     // IsEqual can be checked in sequence.
     109                 :            :     // Neither ref-update nor removing links will change the order.
     110                 :            : 
     111                 :          0 :     sfx2::LinkManager* pLinkManager = const_cast<ScDocument*>(pDoc)->GetLinkManager();
     112         [ #  # ]:          0 :     if (pLinkManager)
     113                 :            :     {
     114                 :          0 :         size_t nPos = 0;
     115                 :          0 :         const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
     116                 :          0 :         sal_uInt16 nLinkCount = rLinks.size();
     117         [ #  # ]:          0 :         for (sal_uInt16 i=0; i<nLinkCount; i++)
     118                 :            :         {
     119                 :          0 :             ::sfx2::SvBaseLink* pBase = *rLinks[i];
     120         [ #  # ]:          0 :             if (pBase->ISA(ScAreaLink))
     121                 :            :             {
     122 [ #  # ][ #  # ]:          0 :                 if ( nPos >= size() || !(*this)[nPos]->IsEqual( *(ScAreaLink*)pBase ) )
                 [ #  # ]
     123                 :          0 :                     return false;
     124                 :            : 
     125                 :          0 :                 ++nPos;
     126                 :            :             }
     127                 :            :         }
     128         [ #  # ]:          0 :         if ( nPos < size() )
     129                 :          0 :             return false;           // fewer links in the document than in the save collection
     130                 :            :     }
     131                 :            : 
     132                 :          0 :     return true;
     133                 :            : }
     134                 :            : 
     135                 :          0 : ScAreaLink* lcl_FindLink( const ::sfx2::SvBaseLinks& rLinks, const ScAreaLinkSaver& rSaver )
     136                 :            : {
     137                 :          0 :     sal_uInt16 nLinkCount = rLinks.size();
     138         [ #  # ]:          0 :     for (sal_uInt16 i=0; i<nLinkCount; i++)
     139                 :            :     {
     140                 :          0 :         ::sfx2::SvBaseLink* pBase = *rLinks[i];
     141         [ #  # ]:          0 :         if ( pBase->ISA(ScAreaLink) &&
           [ #  #  #  # ]
     142                 :          0 :              rSaver.IsEqualSource( *static_cast<ScAreaLink*>(pBase) ) )
     143                 :            :         {
     144                 :          0 :             return static_cast<ScAreaLink*>(pBase);     // found
     145                 :            :         }
     146                 :            :     }
     147                 :          0 :     return NULL;    // not found
     148                 :            : }
     149                 :            : 
     150                 :          0 : void ScAreaLinkSaveCollection::Restore( ScDocument* pDoc ) const
     151                 :            : {
     152                 :            :     // The save collection may contain additional entries that are not in the document.
     153                 :            :     // They must be inserted again.
     154                 :            :     // Entries from the save collection must be searched via source data, as the order
     155                 :            :     // of links changes if deleted entries are re-added to the link manager (always at the end).
     156                 :            : 
     157                 :          0 :     sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
     158         [ #  # ]:          0 :     if (pLinkManager)
     159                 :            :     {
     160                 :          0 :         const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
     161                 :          0 :         size_t nSaveCount = size();
     162         [ #  # ]:          0 :         for (size_t nPos=0; nPos<nSaveCount; ++nPos)
     163                 :            :         {
     164                 :          0 :             const ScAreaLinkSaver* pSaver = (*this)[nPos];
     165                 :          0 :             ScAreaLink* pLink = lcl_FindLink( rLinks, *pSaver );
     166         [ #  # ]:          0 :             if ( pLink )
     167                 :          0 :                 pSaver->WriteToLink( *pLink );          // restore output position
     168                 :            :             else
     169                 :          0 :                 pSaver->InsertNewLink( pDoc );          // re-insert deleted link
     170                 :            :         }
     171                 :            :     }
     172                 :          0 : }
     173                 :            : 
     174                 :         36 : ScAreaLinkSaveCollection* ScAreaLinkSaveCollection::CreateFromDoc( const ScDocument* pDoc )
     175                 :            : {
     176                 :         36 :     ScAreaLinkSaveCollection* pColl = NULL;
     177                 :            : 
     178                 :         36 :     sfx2::LinkManager* pLinkManager = const_cast<ScDocument*>(pDoc)->GetLinkManager();
     179         [ +  - ]:         36 :     if (pLinkManager)
     180                 :            :     {
     181                 :         36 :         const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
     182                 :         36 :         sal_uInt16 nLinkCount = rLinks.size();
     183         [ -  + ]:         36 :         for (sal_uInt16 i=0; i<nLinkCount; i++)
     184                 :            :         {
     185                 :          0 :             ::sfx2::SvBaseLink* pBase = *rLinks[i];
     186         [ #  # ]:          0 :             if (pBase->ISA(ScAreaLink))
     187                 :            :             {
     188         [ #  # ]:          0 :                 if (!pColl)
     189         [ #  # ]:          0 :                     pColl = new ScAreaLinkSaveCollection;
     190                 :            : 
     191         [ #  # ]:          0 :                 ScAreaLinkSaver* pSaver = new ScAreaLinkSaver( *(ScAreaLink*)pBase );
     192                 :          0 :                 pColl->push_back(pSaver);
     193                 :            :             }
     194                 :            :         }
     195                 :            :     }
     196                 :            : 
     197                 :         36 :     return pColl;
     198                 :            : }
     199                 :            : 
     200                 :          0 : const ScAreaLinkSaver* ScAreaLinkSaveCollection::operator [](size_t nIndex) const
     201                 :            : {
     202                 :          0 :     return &maData[nIndex];
     203                 :            : }
     204                 :            : 
     205                 :          0 : size_t ScAreaLinkSaveCollection::size() const
     206                 :            : {
     207                 :          0 :     return maData.size();
     208                 :            : }
     209                 :            : 
     210                 :          0 : void ScAreaLinkSaveCollection::push_back(ScAreaLinkSaver* p)
     211                 :            : {
     212                 :          0 :     maData.push_back(p);
     213                 :          0 : }
     214                 :            : 
     215                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10