LCOV - code coverage report
Current view: top level - sc/inc - progress.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 48 89.6 %
Date: 2015-06-13 12:38:46 Functions: 12 12 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 INCLUDED_SC_INC_PROGRESS_HXX
      21             : #define INCLUDED_SC_INC_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             : class SC_DLLPUBLIC ScProgress
      40             : {
      41             : private:
      42             :     static  SfxProgress*    pGlobalProgress;
      43             :     static  sal_uLong        nGlobalRange;
      44             :     static  sal_uLong       nGlobalPercent;
      45             :     static  bool            bGlobalNoUserBreak;
      46             :     static  ScProgress*     pInterpretProgress;
      47             :     static  ScProgress*     pOldInterpretProgress;
      48             :     static  sal_uLong       nInterpretProgress;
      49             :     static  bool            bAllowInterpretProgress;
      50             :     static  ScDocument*     pInterpretDoc;
      51             :     static  bool            bIdleWasEnabled;
      52             :             bool            bEnabled;
      53             : 
      54             :             SfxProgress*    pProgress;
      55             : 
      56             :                             ScProgress( const ScProgress& ) SAL_DELETED_FUNCTION;
      57             :             ScProgress&     operator=( const ScProgress& ) SAL_DELETED_FUNCTION;
      58             : 
      59        3917 :     static  void            CalcGlobalPercent( sal_uLong nVal )
      60             :                                 {
      61             :                                     nGlobalPercent = nGlobalRange ?
      62        3917 :                                         nVal * 100 / nGlobalRange : 0;
      63        3917 :                                 }
      64             : 
      65             : public:
      66             :     static  SfxProgress*    GetGlobalSfxProgress() { return pGlobalProgress; }
      67         257 :     static  bool            IsUserBreak() { return !bGlobalNoUserBreak; }
      68             :     static  void            CreateInterpretProgress( ScDocument* pDoc,
      69             :                                                     bool bWait = true );
      70       11810 :     static  ScProgress*     GetInterpretProgress() { return pInterpretProgress; }
      71             :     static  void            DeleteInterpretProgress();
      72             :     static  sal_uLong           GetInterpretCount() { return nInterpretProgress; }
      73             :     static  sal_uLong           GetGlobalRange()    { return nGlobalRange; }
      74             :     static  sal_uLong           GetGlobalPercent()  { return nGlobalPercent; }
      75             : 
      76             :                             ScProgress( SfxObjectShell* pObjSh,
      77             :                                          const OUString& rText,
      78             :                                          sal_uLong nRange, bool bAllDocs = false,
      79             :                                          bool bWait = true );
      80             :                             ~ScProgress();
      81             : 
      82             : #ifdef SC_PROGRESS_CXX
      83             :                             /// for DummyInterpret only, never use otherwise!!!
      84             :                             ScProgress();
      85             : #endif
      86             :                             /// might be NULL!
      87             :             SfxProgress*    GetSfxProgress() const { return pProgress; }
      88             : 
      89           4 :             bool            SetStateText( sal_uLong nVal, const OUString &rVal, sal_uLong nNewRange = 0 )
      90             :                                 {
      91           4 :                                     if ( pProgress )
      92             :                                     {
      93           4 :                                         if ( nNewRange )
      94           0 :                                             nGlobalRange = nNewRange;
      95           4 :                                         CalcGlobalPercent( nVal );
      96           4 :                                         if ( !pProgress->SetStateText( nVal, rVal, nNewRange ) )
      97           0 :                                             bGlobalNoUserBreak = false;
      98           4 :                                         return bGlobalNoUserBreak;
      99             :                                     }
     100           0 :                                     return true;
     101             :                                 }
     102       12000 :             bool            SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
     103             :                                 {
     104       12000 :                                     if ( pProgress )
     105             :                                     {
     106        3896 :                                         if ( nNewRange )
     107           4 :                                             nGlobalRange = nNewRange;
     108        3896 :                                         CalcGlobalPercent( nVal );
     109        3896 :                                         if ( !pProgress->SetState( nVal, nNewRange ) )
     110           0 :                                             bGlobalNoUserBreak = false;
     111        3896 :                                         return bGlobalNoUserBreak;
     112             :                                     }
     113        8104 :                                     return true;
     114             :                                 }
     115          18 :             bool            SetStateCountDown( sal_uLong nVal )
     116             :                                 {
     117          18 :                                     if ( pProgress )
     118             :                                     {
     119          17 :                                         CalcGlobalPercent( nGlobalRange - nVal );
     120          17 :                                         if ( !pProgress->SetState( nGlobalRange - nVal ) )
     121           0 :                                             bGlobalNoUserBreak = false;
     122          17 :                                         return bGlobalNoUserBreak;
     123             :                                     }
     124           1 :                                     return true;
     125             :                                 }
     126         288 :             bool            SetStateOnPercent( sal_uLong nVal )
     127             :                                 {   /// only if percentage increased
     128         333 :                                     if ( nGlobalRange && (nVal * 100 /
     129          45 :                                             nGlobalRange) > nGlobalPercent )
     130          40 :                                         return SetState( nVal );
     131         248 :                                     return true;
     132             :                                 }
     133       13354 :             bool            SetStateCountDownOnPercent( sal_uLong nVal )
     134             :                                 {   /// only if percentage increased
     135       13392 :                                     if ( nGlobalRange &&
     136          38 :                                             ((nGlobalRange - nVal) * 100 /
     137          38 :                                             nGlobalRange) > nGlobalPercent )
     138          18 :                                         return SetStateCountDown( nVal );
     139       13336 :                                     return true;
     140             :                                 }
     141          17 :             sal_uLong           GetState()
     142             :                                 {
     143          17 :                                     if ( pProgress )
     144          15 :                                         return pProgress->GetState();
     145           2 :                                     return 0;
     146             :                                 }
     147       11810 :             bool                Enabled() const { return bEnabled; }
     148           6 :             void                Disable() { bEnabled = false; }
     149           6 :             void                Enable() { bEnabled = true; }
     150             : };
     151             : 
     152             : #endif
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11