LCOV - code coverage report
Current view: top level - sc/inc - progress.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 39 45 86.7 %
Date: 2014-04-11 Functions: 9 9 100.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             : #ifndef SC_PROGRESS_HXX
      21             : #define SC_PROGRESS_HXX
      22             : 
      23             : #include <rtl/ustring.hxx>
      24             : #include <sfx2/progress.hxx>
      25             : #include "scdllapi.h"
      26             : 
      27             : class ScDocument;
      28             : 
      29             : /*
      30             :  * #i102566
      31             :  * Drawing a progress bar update is not cheap, so if we draw it on every
      32             :  * percentage change of 200 calculations we get one progress draw per 2
      33             :  * calculations which is slower than doing the calculations themselves. So as a
      34             :  * rough guide only do an update per MIN_NO_CODES_PER_PROGRESS_UPDATE
      35             :  * calculations
      36             :  */
      37             : #define MIN_NO_CODES_PER_PROGRESS_UPDATE 100
      38             : 
      39             : 
      40             : class SC_DLLPUBLIC ScProgress
      41             : {
      42             : private:
      43             :     static  SfxProgress*    pGlobalProgress;
      44             :     static  sal_uLong        nGlobalRange;
      45             :     static  sal_uLong       nGlobalPercent;
      46             :     static  bool            bGlobalNoUserBreak;
      47             :     static  ScProgress*     pInterpretProgress;
      48             :     static  ScProgress*     pOldInterpretProgress;
      49             :     static  sal_uLong       nInterpretProgress;
      50             :     static  bool            bAllowInterpretProgress;
      51             :     static  ScDocument*     pInterpretDoc;
      52             :     static  bool            bIdleWasEnabled;
      53             : 
      54             :             SfxProgress*    pProgress;
      55             : 
      56             :                             /// not implemented
      57             :                             ScProgress( const ScProgress& );
      58             :             ScProgress&     operator=( const ScProgress& );
      59             : 
      60        3440 :     static  void            CalcGlobalPercent( sal_uLong nVal )
      61             :                                 {
      62             :                                     nGlobalPercent = nGlobalRange ?
      63        3440 :                                         nVal * 100 / nGlobalRange : 0;
      64        3440 :                                 }
      65             : 
      66             : public:
      67             :     static  SfxProgress*    GetGlobalSfxProgress() { return pGlobalProgress; }
      68          93 :     static  bool            IsUserBreak() { return !bGlobalNoUserBreak; }
      69             :     static  void            CreateInterpretProgress( ScDocument* pDoc,
      70             :                                                     bool bWait = true );
      71        6271 :     static  ScProgress*     GetInterpretProgress() { return pInterpretProgress; }
      72             :     static  void            DeleteInterpretProgress();
      73             :     static  sal_uLong           GetInterpretCount() { return nInterpretProgress; }
      74             :     static  sal_uLong           GetGlobalRange()    { return nGlobalRange; }
      75             :     static  sal_uLong           GetGlobalPercent()  { return nGlobalPercent; }
      76             : 
      77             :                             ScProgress( SfxObjectShell* pObjSh,
      78             :                                          const OUString& rText,
      79             :                                          sal_uLong nRange, bool bAllDocs = false,
      80             :                                          bool bWait = true );
      81             :                             ~ScProgress();
      82             : 
      83             : #ifdef SC_PROGRESS_CXX
      84             :                             /// for DummyInterpret only, never use otherwise!!!
      85             :                             ScProgress();
      86             : #endif
      87             :                             /// might be NULL!
      88             :             SfxProgress*    GetSfxProgress() const { return pProgress; }
      89             : 
      90           4 :             bool            SetStateText( sal_uLong nVal, const OUString &rVal, sal_uLong nNewRange = 0 )
      91             :                                 {
      92           4 :                                     if ( pProgress )
      93             :                                     {
      94           4 :                                         if ( nNewRange )
      95           0 :                                             nGlobalRange = nNewRange;
      96           4 :                                         CalcGlobalPercent( nVal );
      97           4 :                                         if ( !pProgress->SetStateText( nVal, rVal, nNewRange ) )
      98           0 :                                             bGlobalNoUserBreak = false;
      99           4 :                                         return bGlobalNoUserBreak;
     100             :                                     }
     101           0 :                                     return true;
     102             :                                 }
     103        8218 :             bool            SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
     104             :                                 {
     105        8218 :                                     if ( pProgress )
     106             :                                     {
     107        3428 :                                         if ( nNewRange )
     108           4 :                                             nGlobalRange = nNewRange;
     109        3428 :                                         CalcGlobalPercent( nVal );
     110        3428 :                                         if ( !pProgress->SetState( nVal, nNewRange ) )
     111           0 :                                             bGlobalNoUserBreak = false;
     112        3428 :                                         return bGlobalNoUserBreak;
     113             :                                     }
     114        4790 :                                     return true;
     115             :                                 }
     116           9 :             bool            SetStateCountDown( sal_uLong nVal )
     117             :                                 {
     118           9 :                                     if ( pProgress )
     119             :                                     {
     120           8 :                                         CalcGlobalPercent( nGlobalRange - nVal );
     121           8 :                                         if ( !pProgress->SetState( nGlobalRange - nVal ) )
     122           0 :                                             bGlobalNoUserBreak = false;
     123           8 :                                         return bGlobalNoUserBreak;
     124             :                                     }
     125           1 :                                     return true;
     126             :                                 }
     127         169 :             bool            SetStateOnPercent( sal_uLong nVal )
     128             :                                 {   /// only if percentage increased
     129         217 :                                     if ( nGlobalRange && (nVal * 100 /
     130          48 :                                             nGlobalRange) > nGlobalPercent )
     131          43 :                                         return SetState( nVal );
     132         126 :                                     return true;
     133             :                                 }
     134        6968 :             bool            SetStateCountDownOnPercent( sal_uLong nVal )
     135             :                                 {   /// only if percentage increased
     136        6997 :                                     if ( nGlobalRange &&
     137          29 :                                             ((nGlobalRange - nVal) * 100 /
     138          29 :                                             nGlobalRange) > nGlobalPercent )
     139           9 :                                         return SetStateCountDown( nVal );
     140        6959 :                                     return true;
     141             :                                 }
     142          17 :             sal_uLong           GetState()
     143             :                                 {
     144          17 :                                     if ( pProgress )
     145          17 :                                         return pProgress->GetState();
     146           0 :                                     return 0;
     147             :                                 }
     148             : };
     149             : 
     150             : 
     151             : #endif
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10