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

Generated by: LCOV version 1.10