LibreOffice Module sc (master)  1
progress.hxx
Go to the documentation of this file.
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 <tools/solar.h>
26 #include "scdllapi.h"
27 
28 class ScDocument;
29 
30 /*
31  * #i102566
32  * Drawing a progress bar update is not cheap, so if we draw it on every
33  * percentage change of 200 calculations we get one progress draw per 2
34  * calculations which is slower than doing the calculations themselves. So as a
35  * rough guide only do an update per MIN_NO_CODES_PER_PROGRESS_UPDATE
36  * calculations
37  */
38 #define MIN_NO_CODES_PER_PROGRESS_UPDATE 100
39 
41 {
42 private:
49  static bool bIdleWasEnabled;
50  bool bEnabled;
51 
52  std::unique_ptr<SfxProgress> pProgress;
53 
54  ScProgress( const ScProgress& ) = delete;
55  ScProgress& operator=( const ScProgress& ) = delete;
56 
57  static void CalcGlobalPercent( sal_uLong nVal )
58  {
59  nGlobalPercent = nGlobalRange ?
60  nVal * 100 / nGlobalRange : 0;
61  }
62 
63 public:
64  static void CreateInterpretProgress( ScDocument* pDoc,
65  bool bWait = true );
66  static ScProgress* GetInterpretProgress() { return pInterpretProgress; }
67  static void DeleteInterpretProgress();
68 
69  ScProgress( SfxObjectShell* pObjSh,
70  const OUString& rText,
71  sal_uLong nRange,
72  bool bWait );
73  ~ScProgress();
74 
75 #ifdef SC_PROGRESS_CXX
76  ScProgress();
78 #endif
79  void SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
80  {
81  if ( pProgress )
82  {
83  if ( nNewRange )
84  nGlobalRange = nNewRange;
85  CalcGlobalPercent( nVal );
86  pProgress->SetState( nVal, nNewRange );
87  }
88  }
90  {
91  if ( pProgress )
92  {
93  CalcGlobalPercent( nGlobalRange - nVal );
94  pProgress->SetState( nGlobalRange - nVal );
95  }
96  }
98  {
99  if ( nGlobalRange && (nVal * 100 /
100  nGlobalRange) > nGlobalPercent )
101  SetState( nVal );
102  }
104  {
105  if ( nGlobalRange &&
106  ((nGlobalRange - nVal) * 100 /
107  nGlobalRange) > nGlobalPercent )
108  SetStateCountDown( nVal );
109  }
111  {
112  if ( pProgress )
113  return pProgress->GetState();
114  return 0;
115  }
116  bool Enabled() const { return bEnabled; }
117  void Disable() { bEnabled = false; }
118  void Enable() { bEnabled = true; }
119 };
120 
121 #endif
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SfxProgress * pGlobalProgress
Definition: progress.hxx:43
bool Enabled() const
Definition: progress.hxx:116
static ScProgress * GetInterpretProgress()
Definition: progress.hxx:66
void Enable()
Definition: progress.hxx:118
bool bEnabled
Definition: progress.hxx:50
void SetStateCountDownOnPercent(sal_uLong nVal)
Definition: progress.hxx:103
static sal_uLong nInterpretProgress
Definition: progress.hxx:47
sal_uIntPtr sal_uLong
void SetStateOnPercent(sal_uLong nVal)
Definition: progress.hxx:97
void Disable()
Definition: progress.hxx:117
std::unique_ptr< SfxProgress > pProgress
Definition: progress.hxx:52
static sal_uLong nGlobalRange
Definition: progress.hxx:44
static sal_uLong nGlobalPercent
Definition: progress.hxx:45
sal_uLong GetState() const
Definition: progress.hxx:110
static ScDocument * pInterpretDoc
Definition: progress.hxx:48
static ScProgress * pInterpretProgress
Definition: progress.hxx:46
void SetState(sal_uLong nVal, sal_uLong nNewRange=0)
Definition: progress.hxx:79
static bool bIdleWasEnabled
Definition: progress.hxx:49
void SetStateCountDown(sal_uLong nVal)
Definition: progress.hxx:89
static void CalcGlobalPercent(sal_uLong nVal)
Definition: progress.hxx:57
#define SC_DLLPUBLIC
Definition: scdllapi.h:28