LCOV - code coverage report
Current view: top level - sc/source/core/tool - progress.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 51 66 77.3 %
Date: 2014-11-03 Functions: 8 9 88.9 %
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 <sfx2/app.hxx>
      21             : #include <sfx2/objsh.hxx>
      22             : #include <sfx2/progress.hxx>
      23             : #include <sfx2/docfile.hxx>
      24             : #include <sfx2/sfxsids.hrc>
      25             : #include <svl/eitem.hxx>
      26             : #include <svl/itemset.hxx>
      27             : 
      28             : #define SC_PROGRESS_CXX
      29             : #include "progress.hxx"
      30             : #include "document.hxx"
      31             : #include "global.hxx"
      32             : #include "globstr.hrc"
      33             : 
      34             : using namespace com::sun::star;
      35             : 
      36          76 : static ScProgress theDummyInterpretProgress;
      37             : SfxProgress*    ScProgress::pGlobalProgress = NULL;
      38             : sal_uLong       ScProgress::nGlobalRange = 0;
      39             : sal_uLong       ScProgress::nGlobalPercent = 0;
      40             : bool            ScProgress::bGlobalNoUserBreak = true;
      41             : ScProgress*     ScProgress::pInterpretProgress = &theDummyInterpretProgress;
      42             : ScProgress*     ScProgress::pOldInterpretProgress = NULL;
      43             : sal_uLong       ScProgress::nInterpretProgress = 0;
      44             : bool            ScProgress::bAllowInterpretProgress = true;
      45             : ScDocument*     ScProgress::pInterpretDoc;
      46             : bool            ScProgress::bIdleWasEnabled = false;
      47             : 
      48           0 : static bool lcl_IsHiddenDocument( SfxObjectShell* pObjSh )
      49             : {
      50           0 :     if (pObjSh)
      51             :     {
      52           0 :         SfxMedium* pMed = pObjSh->GetMedium();
      53           0 :         if (pMed)
      54             :         {
      55           0 :             SfxItemSet* pSet = pMed->GetItemSet();
      56             :             const SfxPoolItem* pItem;
      57           0 :             if ( pSet && SfxItemState::SET == pSet->GetItemState( SID_HIDDEN, true, &pItem ) &&
      58           0 :                         static_cast<const SfxBoolItem*>(pItem)->GetValue() )
      59           0 :                 return true;
      60             :         }
      61             :     }
      62           0 :     return false;
      63             : }
      64             : 
      65         468 : static bool lcl_HasControllersLocked( SfxObjectShell& rObjSh )
      66             : {
      67         468 :     uno::Reference<frame::XModel> xModel( rObjSh.GetBaseModel() );
      68         468 :     if (xModel.is())
      69         468 :         return xModel->hasControllersLocked();
      70           0 :     return false;
      71             : }
      72             : 
      73         860 : ScProgress::ScProgress( SfxObjectShell* pObjSh, const OUString& rText,
      74             :                         sal_uLong nRange, bool bAllDocs, bool bWait )
      75             : {
      76             : 
      77         860 :     if ( pGlobalProgress || SfxProgress::GetActiveProgress( NULL ) )
      78             :     {
      79           0 :         if ( lcl_IsHiddenDocument(pObjSh) )
      80             :         {
      81             :             // loading a hidden document while a progress is active is possible - no error
      82           0 :             pProgress = NULL;
      83             :         }
      84             :         else
      85             :         {
      86             :             OSL_FAIL( "ScProgress: there can be only one!" );
      87           0 :             pProgress = NULL;
      88             :         }
      89             :     }
      90         860 :     else if ( SfxGetpApp()->IsDowning() )
      91             :     {
      92             :         //  This happens. E.g. when saving the clipboard-content as OLE when closing the app.
      93             :         //  In this case a SfxProgress would produce dirt in memory.
      94             :         //! Should that be this way ???
      95             : 
      96           0 :         pProgress = NULL;
      97             :     }
      98        1786 :     else if ( pObjSh && ( pObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ||
      99         936 :                           pObjSh->GetProgress() ||
     100         468 :                           lcl_HasControllersLocked(*pObjSh) ) )
     101             :     {
     102             :         //  no own progress for embedded objects,
     103             :         //  no second progress if the document already has one
     104             : 
     105         458 :         pProgress = NULL;
     106             :     }
     107             :     else
     108             :     {
     109         402 :         pProgress = new SfxProgress( pObjSh, rText, nRange, bAllDocs, bWait );
     110         402 :         pGlobalProgress = pProgress;
     111         402 :         nGlobalRange = nRange;
     112         402 :         nGlobalPercent = 0;
     113         402 :         bGlobalNoUserBreak = true;
     114             :     }
     115         860 : }
     116             : 
     117          76 : ScProgress::ScProgress() :
     118          76 :         pProgress( NULL )
     119             : {   // DummyInterpret
     120          76 : }
     121             : 
     122         936 : ScProgress::~ScProgress()
     123             : {
     124         936 :     if ( pProgress )
     125             :     {
     126         402 :         delete pProgress;
     127         402 :         pGlobalProgress = NULL;
     128         402 :         nGlobalRange = 0;
     129         402 :         nGlobalPercent = 0;
     130         402 :         bGlobalNoUserBreak = true;
     131             :     }
     132         936 : }
     133             : 
     134         145 : void ScProgress::CreateInterpretProgress( ScDocument* pDoc, bool bWait )
     135             : {
     136         145 :     if ( bAllowInterpretProgress )
     137             :     {
     138         145 :         if ( nInterpretProgress )
     139           0 :             nInterpretProgress++;
     140         145 :         else if ( pDoc->GetAutoCalc() )
     141             :         {
     142         122 :             nInterpretProgress = 1;
     143         122 :             bIdleWasEnabled = pDoc->IsIdleEnabled();
     144         122 :             pDoc->EnableIdle(false);
     145             :             // Interpreter may be called in many circumstances, also if another
     146             :             // progress bar is active, for example while adapting row heights.
     147             :             // Keep the dummy interpret progress.
     148         122 :             if ( !pGlobalProgress )
     149             :                 pInterpretProgress = new ScProgress( pDoc->GetDocumentShell(),
     150             :                     ScGlobal::GetRscString( STR_PROGRESS_CALCULATING ),
     151         122 :                     pDoc->GetFormulaCodeInTree()/MIN_NO_CODES_PER_PROGRESS_UPDATE, false, bWait );
     152         122 :             pInterpretDoc = pDoc;
     153             :         }
     154             :     }
     155         145 : }
     156             : 
     157         145 : void ScProgress::DeleteInterpretProgress()
     158             : {
     159         145 :     if ( bAllowInterpretProgress && nInterpretProgress )
     160             :     {
     161             :         /*  Do not decrement 'nInterpretProgress', before 'pInterpretProgress'
     162             :             is deleted. In rare cases, deletion of 'pInterpretProgress' causes
     163             :             a refresh of the sheet window which may call CreateInterpretProgress
     164             :             and DeleteInterpretProgress again (from Output::DrawStrings),
     165             :             resulting in double deletion of 'pInterpretProgress'. */
     166         122 :         if ( nInterpretProgress == 1 )
     167             :         {
     168         122 :             if ( pInterpretProgress != &theDummyInterpretProgress )
     169             :             {
     170             :                 // move pointer to local temporary to avoid double deletion
     171         122 :                 ScProgress* pTmpProgress = pInterpretProgress;
     172         122 :                 pInterpretProgress = &theDummyInterpretProgress;
     173         122 :                 delete pTmpProgress;
     174             :             }
     175         122 :             if ( pInterpretDoc )
     176         122 :                 pInterpretDoc->EnableIdle(bIdleWasEnabled);
     177             :         }
     178         122 :         --nInterpretProgress;
     179             :     }
     180         373 : }
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10