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

Generated by: LCOV version 1.10