LCOV - code coverage report
Current view: top level - sc/source/core/tool - chartlock.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 13 78 16.7 %
Date: 2012-08-25 Functions: 4 13 30.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 130 3.8 %

           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                 :            : 
      30                 :            : #include <vcl/svapp.hxx>
      31                 :            : #include <svx/svditer.hxx>
      32                 :            : #include <svx/svdoole2.hxx>
      33                 :            : #include <svx/svdpage.hxx>
      34                 :            : 
      35                 :            : #include "chartlock.hxx"
      36                 :            : #include "document.hxx"
      37                 :            : #include "drwlayer.hxx"
      38                 :            : 
      39                 :            : using namespace com::sun::star;
      40                 :            : using ::com::sun::star::uno::Reference;
      41                 :            : using ::com::sun::star::uno::WeakReference;
      42                 :            : 
      43                 :            : #define SC_CHARTLOCKTIMEOUT 660
      44                 :            : 
      45                 :            : // ====================================================================
      46                 :            : 
      47                 :            : namespace
      48                 :            : {
      49                 :            : 
      50                 :          0 : std::vector< WeakReference< frame::XModel > > lcl_getAllLivingCharts( ScDocument* pDoc )
      51                 :            : {
      52                 :          0 :     std::vector< WeakReference< frame::XModel > > aRet;
      53         [ #  # ]:          0 :     if( !pDoc )
      54                 :          0 :         return aRet;
      55         [ #  # ]:          0 :     ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
      56         [ #  # ]:          0 :     if (!pDrawLayer)
      57                 :          0 :         return aRet;
      58                 :            : 
      59         [ #  # ]:          0 :     for (SCTAB nTab=0; nTab<=pDoc->GetMaxTableNumber(); nTab++)
      60                 :            :     {
      61 [ #  # ][ #  # ]:          0 :         if (pDoc->HasTable(nTab))
      62                 :            :         {
      63         [ #  # ]:          0 :             SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
      64                 :            :             OSL_ENSURE(pPage,"Page ?");
      65                 :            : 
      66         [ #  # ]:          0 :             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
      67         [ #  # ]:          0 :             SdrObject* pObject = aIter.Next();
      68         [ #  # ]:          0 :             while (pObject)
      69                 :            :             {
      70 [ #  # ][ #  # ]:          0 :                 if( pDoc->IsChart( pObject ) )
      71                 :            :                 {
      72         [ #  # ]:          0 :                     uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pObject)->GetObjRef();
      73         [ #  # ]:          0 :                     uno::Reference< embed::XComponentSupplier > xCompSupp( xIPObj, uno::UNO_QUERY );
      74         [ #  # ]:          0 :                     if( xCompSupp.is())
      75                 :            :                     {
      76 [ #  # ][ #  # ]:          0 :                         Reference< frame::XModel > xModel( xCompSupp->getComponent(), uno::UNO_QUERY );
                 [ #  # ]
      77         [ #  # ]:          0 :                         if( xModel.is() )
      78 [ #  # ][ #  # ]:          0 :                             aRet.push_back( xModel );
                 [ #  # ]
      79                 :          0 :                     }
      80                 :            :                 }
      81         [ #  # ]:          0 :                 pObject = aIter.Next();
      82                 :          0 :             }
      83                 :            :         }
      84                 :            :     }
      85                 :          0 :     return aRet;
      86                 :            : }
      87                 :            : 
      88                 :            : }//end anonymous namespace
      89                 :            : 
      90                 :            : // === ScChartLockGuard ======================================
      91                 :            : 
      92                 :          0 : ScChartLockGuard::ScChartLockGuard( ScDocument* pDoc ) :
      93                 :          0 :     maChartModels( lcl_getAllLivingCharts( pDoc ) )
      94                 :            : {
      95         [ #  # ]:          0 :     std::vector< WeakReference< frame::XModel > >::const_iterator aIter = maChartModels.begin();
      96         [ #  # ]:          0 :     const std::vector< WeakReference< frame::XModel > >::const_iterator aEnd = maChartModels.end();
      97 [ #  # ][ #  # ]:          0 :     for( ; aIter != aEnd; ++aIter )
      98                 :            :     {
      99                 :            :         try
     100                 :            :         {
     101         [ #  # ]:          0 :             Reference< frame::XModel > xModel( *aIter );
     102         [ #  # ]:          0 :             if( xModel.is())
     103 [ #  # ][ #  # ]:          0 :                 xModel->lockControllers();
                 [ #  # ]
     104                 :            :         }
     105         [ #  # ]:          0 :         catch ( uno::Exception& )
     106                 :            :         {
     107                 :            :             OSL_FAIL("Unexpected exception in ScChartLockGuard");
     108                 :            :         }
     109                 :            :     }
     110                 :          0 : }
     111                 :            : 
     112                 :          0 : ScChartLockGuard::~ScChartLockGuard()
     113                 :            : {
     114         [ #  # ]:          0 :     std::vector< WeakReference< frame::XModel > >::const_iterator aIter = maChartModels.begin();
     115         [ #  # ]:          0 :     const std::vector< WeakReference< frame::XModel > >::const_iterator aEnd = maChartModels.end();
     116 [ #  # ][ #  # ]:          0 :     for( ; aIter != aEnd; ++aIter )
     117                 :            :     {
     118                 :            :         try
     119                 :            :         {
     120         [ #  # ]:          0 :             Reference< frame::XModel > xModel( *aIter );
     121         [ #  # ]:          0 :             if( xModel.is())
     122 [ #  # ][ #  # ]:          0 :                 xModel->unlockControllers();
                 [ #  # ]
     123                 :            :         }
     124         [ #  # ]:          0 :         catch ( uno::Exception& )
     125                 :            :         {
     126                 :            :             OSL_FAIL("Unexpected exception in ScChartLockGuard");
     127                 :            :         }
     128                 :            :     }
     129         [ #  # ]:          0 : }
     130                 :            : 
     131                 :          0 : void ScChartLockGuard::AlsoLockThisChart( const Reference< frame::XModel >& xModel )
     132                 :            : {
     133         [ #  # ]:          0 :     if(!xModel.is())
     134                 :          0 :         return;
     135                 :            : 
     136         [ #  # ]:          0 :     WeakReference< frame::XModel > xWeakModel(xModel);
     137                 :            : 
     138                 :            :     std::vector< WeakReference< frame::XModel > >::iterator aFindIter(
     139         [ #  # ]:          0 :             ::std::find( maChartModels.begin(), maChartModels.end(), xWeakModel ) );
     140                 :            : 
     141 [ #  # ][ #  # ]:          0 :     if( aFindIter == maChartModels.end() )
     142                 :            :     {
     143                 :            :         try
     144                 :            :         {
     145 [ #  # ][ #  # ]:          0 :             xModel->lockControllers();
     146 [ #  # ][ #  # ]:          0 :             maChartModels.push_back( xModel );
         [ #  # ][ #  # ]
     147                 :            :         }
     148         [ #  # ]:          0 :         catch ( uno::Exception& )
     149                 :            :         {
     150                 :            :             OSL_FAIL("Unexpected exception in ScChartLockGuard");
     151                 :            :         }
     152         [ #  # ]:          0 :     }
     153                 :            : }
     154                 :            : 
     155                 :            : // === ScTemporaryChartLock ======================================
     156                 :            : 
     157                 :       1781 : ScTemporaryChartLock::ScTemporaryChartLock( ScDocument* pDocP ) :
     158                 :       1781 :     mpDoc( pDocP )
     159                 :            : {
     160         [ +  - ]:       1781 :     maTimer.SetTimeout( SC_CHARTLOCKTIMEOUT );
     161         [ +  - ]:       1781 :     maTimer.SetTimeoutHdl( LINK( this, ScTemporaryChartLock, TimeoutHdl ) );
     162                 :       1781 : }
     163                 :            : 
     164                 :            : 
     165         [ +  - ]:       1611 : ScTemporaryChartLock::~ScTemporaryChartLock()
     166                 :            : {
     167                 :       1611 :     mpDoc = 0;
     168         [ +  - ]:       1611 :     StopLocking();
     169         [ -  + ]:       3222 : }
     170                 :            : 
     171                 :          0 : void ScTemporaryChartLock::StartOrContinueLocking()
     172                 :            : {
     173         [ #  # ]:          0 :     if(!mapScChartLockGuard.get())
     174         [ #  # ]:          0 :         mapScChartLockGuard = std::auto_ptr< ScChartLockGuard >( new ScChartLockGuard(mpDoc) );
     175                 :          0 :     maTimer.Start();
     176                 :          0 : }
     177                 :            : 
     178                 :       1615 : void ScTemporaryChartLock::StopLocking()
     179                 :            : {
     180                 :       1615 :     maTimer.Stop();
     181                 :       1615 :     mapScChartLockGuard.reset();
     182                 :       1615 : }
     183                 :            : 
     184                 :          0 : void ScTemporaryChartLock::AlsoLockThisChart( const Reference< frame::XModel >& xModel )
     185                 :            : {
     186         [ #  # ]:          0 :     if(mapScChartLockGuard.get())
     187                 :          0 :         mapScChartLockGuard->AlsoLockThisChart( xModel );
     188                 :          0 : }
     189                 :            : 
     190                 :          0 : IMPL_LINK_NOARG(ScTemporaryChartLock, TimeoutHdl)
     191                 :            : {
     192                 :          0 :     mapScChartLockGuard.reset();
     193                 :          0 :     return 0;
     194                 :            : }
     195                 :            : 
     196                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10