LCOV - code coverage report
Current view: top level - sc/source/core/tool - progress.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 66 0.0 %
Date: 2014-04-14 Functions: 0 9 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 <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           0 : static ScProgress theDummyInterpretProgress;
      38             : SfxProgress*    ScProgress::pGlobalProgress = NULL;
      39             : sal_uLong       ScProgress::nGlobalRange = 0;
      40             : sal_uLong       ScProgress::nGlobalPercent = 0;
      41             : bool            ScProgress::bGlobalNoUserBreak = true;
      42             : ScProgress*     ScProgress::pInterpretProgress = &theDummyInterpretProgress;
      43             : ScProgress*     ScProgress::pOldInterpretProgress = NULL;
      44             : sal_uLong       ScProgress::nInterpretProgress = 0;
      45             : bool            ScProgress::bAllowInterpretProgress = true;
      46             : ScDocument*     ScProgress::pInterpretDoc;
      47             : bool            ScProgress::bIdleWasEnabled = 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, 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           0 : ScProgress::ScProgress( SfxObjectShell* pObjSh, const OUString& rText,
      76             :                         sal_uLong nRange, bool bAllDocs, bool bWait )
      77             : {
      78             : 
      79           0 :     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           0 :     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           0 :     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           0 :         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 = true;
     116             :     }
     117           0 : }
     118             : 
     119             : 
     120           0 : ScProgress::ScProgress() :
     121           0 :         pProgress( NULL )
     122             : {   // DummyInterpret
     123           0 : }
     124             : 
     125             : 
     126           0 : ScProgress::~ScProgress()
     127             : {
     128           0 :     if ( pProgress )
     129             :     {
     130           0 :         delete pProgress;
     131           0 :         pGlobalProgress = NULL;
     132           0 :         nGlobalRange = 0;
     133           0 :         nGlobalPercent = 0;
     134           0 :         bGlobalNoUserBreak = true;
     135             :     }
     136           0 : }
     137             : 
     138             : 
     139           0 : void ScProgress::CreateInterpretProgress( ScDocument* pDoc, bool bWait )
     140             : {
     141           0 :     if ( bAllowInterpretProgress )
     142             :     {
     143           0 :         if ( nInterpretProgress )
     144           0 :             nInterpretProgress++;
     145           0 :         else if ( pDoc->GetAutoCalc() )
     146             :         {
     147           0 :             nInterpretProgress = 1;
     148           0 :             bIdleWasEnabled = pDoc->IsIdleEnabled();
     149           0 :             pDoc->EnableIdle(false);
     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           0 :             if ( !pGlobalProgress )
     154             :                 pInterpretProgress = new ScProgress( pDoc->GetDocumentShell(),
     155             :                     ScGlobal::GetRscString( STR_PROGRESS_CALCULATING ),
     156           0 :                     pDoc->GetFormulaCodeInTree()/MIN_NO_CODES_PER_PROGRESS_UPDATE, false, bWait );
     157           0 :             pInterpretDoc = pDoc;
     158             :         }
     159             :     }
     160           0 : }
     161             : 
     162           0 : void ScProgress::DeleteInterpretProgress()
     163             : {
     164           0 :     if ( bAllowInterpretProgress && nInterpretProgress )
     165             :     {
     166             :         /*  Do not decrement 'nInterpretProgress', before 'pInterpretProgress'
     167             :             is deleted. In rare cases, deletion of 'pInterpretProgress' causes
     168             :             a refresh of the sheet window which may call CreateInterpretProgress
     169             :             and DeleteInterpretProgress again (from Output::DrawStrings),
     170             :             resulting in double deletion of 'pInterpretProgress'. */
     171           0 :         if ( nInterpretProgress == 1 )
     172             :         {
     173           0 :             if ( pInterpretProgress != &theDummyInterpretProgress )
     174             :             {
     175             :                 // move pointer to local temporary to avoid double deletion
     176           0 :                 ScProgress* pTmpProgress = pInterpretProgress;
     177           0 :                 pInterpretProgress = &theDummyInterpretProgress;
     178           0 :                 delete pTmpProgress;
     179             :             }
     180           0 :             if ( pInterpretDoc )
     181           0 :                 pInterpretDoc->EnableIdle(bIdleWasEnabled);
     182             :         }
     183           0 :         --nInterpretProgress;
     184             :     }
     185           0 : }
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10