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

Generated by: LCOV version 1.10