LCOV - code coverage report
Current view: top level - sc/source/core/tool - chartlock.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 56 78 71.8 %
Date: 2015-06-13 12:38:46 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         244 : std::vector< WeakReference< frame::XModel > > lcl_getAllLivingCharts( ScDocument* pDoc )
      41             : {
      42         244 :     std::vector< WeakReference< frame::XModel > > aRet;
      43         244 :     if( !pDoc )
      44           0 :         return aRet;
      45         244 :     ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
      46         244 :     if (!pDrawLayer)
      47           0 :         return aRet;
      48             : 
      49         644 :     for (SCTAB nTab=0; nTab<=pDoc->GetMaxTableNumber(); nTab++)
      50             :     {
      51         400 :         if (pDoc->HasTable(nTab))
      52             :         {
      53         400 :             SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
      54             :             OSL_ENSURE(pPage,"Page ?");
      55             : 
      56         400 :             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
      57         400 :             SdrObject* pObject = aIter.Next();
      58        1052 :             while (pObject)
      59             :             {
      60         252 :                 if( ScDocument::IsChart( pObject ) )
      61             :                 {
      62         252 :                     uno::Reference< embed::XEmbeddedObject > xIPObj = static_cast<SdrOle2Obj*>(pObject)->GetObjRef();
      63         504 :                     uno::Reference< embed::XComponentSupplier > xCompSupp( xIPObj, uno::UNO_QUERY );
      64         252 :                     if( xCompSupp.is())
      65             :                     {
      66         252 :                         Reference< frame::XModel > xModel( xCompSupp->getComponent(), uno::UNO_QUERY );
      67         252 :                         if( xModel.is() )
      68         252 :                             aRet.push_back( xModel );
      69         252 :                     }
      70             :                 }
      71         252 :                 pObject = aIter.Next();
      72         400 :             }
      73             :         }
      74             :     }
      75         244 :     return aRet;
      76             : }
      77             : 
      78             : }//end anonymous namespace
      79             : 
      80             : // ScChartLockGuard
      81         244 : ScChartLockGuard::ScChartLockGuard( ScDocument* pDoc ) :
      82         244 :     maChartModels( lcl_getAllLivingCharts( pDoc ) )
      83             : {
      84         244 :     std::vector< WeakReference< frame::XModel > >::const_iterator aIter = maChartModels.begin();
      85         244 :     const std::vector< WeakReference< frame::XModel > >::const_iterator aEnd = maChartModels.end();
      86         496 :     for( ; aIter != aEnd; ++aIter )
      87             :     {
      88             :         try
      89             :         {
      90         252 :             Reference< frame::XModel > xModel( *aIter );
      91         252 :             if( xModel.is())
      92         252 :                 xModel->lockControllers();
      93             :         }
      94           0 :         catch ( uno::Exception& )
      95             :         {
      96             :             OSL_FAIL("Unexpected exception in ScChartLockGuard");
      97             :         }
      98             :     }
      99         244 : }
     100             : 
     101         488 : ScChartLockGuard::~ScChartLockGuard()
     102             : {
     103         244 :     std::vector< WeakReference< frame::XModel > >::const_iterator aIter = maChartModels.begin();
     104         244 :     const std::vector< WeakReference< frame::XModel > >::const_iterator aEnd = maChartModels.end();
     105         496 :     for( ; aIter != aEnd; ++aIter )
     106             :     {
     107             :         try
     108             :         {
     109         252 :             Reference< frame::XModel > xModel( *aIter );
     110         252 :             if( xModel.is())
     111         252 :                 xModel->unlockControllers();
     112             :         }
     113           0 :         catch ( uno::Exception& )
     114             :         {
     115             :             OSL_FAIL("Unexpected exception in ScChartLockGuard");
     116             :         }
     117             :     }
     118         244 : }
     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        2320 : ScTemporaryChartLock::ScTemporaryChartLock( ScDocument* pDocP ) :
     146        2320 :     mpDoc( pDocP )
     147             : {
     148        2320 :     maTimer.SetTimeout( SC_CHARTLOCKTIMEOUT );
     149        2320 :     maTimer.SetTimeoutHdl( LINK( this, ScTemporaryChartLock, TimeoutHdl ) );
     150        2320 : }
     151             : 
     152        6861 : ScTemporaryChartLock::~ScTemporaryChartLock()
     153             : {
     154        2287 :     mpDoc = 0;
     155        2287 :     StopLocking();
     156        4574 : }
     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        2316 : void ScTemporaryChartLock::StopLocking()
     166             : {
     167        2316 :     maTimer.Stop();
     168        2316 :     mapScChartLockGuard.reset();
     169        2316 : }
     170             : 
     171          30 : void ScTemporaryChartLock::AlsoLockThisChart( const Reference< frame::XModel >& xModel )
     172             : {
     173          30 :     if(mapScChartLockGuard.get())
     174           0 :         mapScChartLockGuard->AlsoLockThisChart( xModel );
     175          30 : }
     176             : 
     177           0 : IMPL_LINK_NOARG_TYPED(ScTemporaryChartLock, TimeoutHdl, Timer *, void)
     178             : {
     179           0 :     mapScChartLockGuard.reset();
     180         156 : }
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11