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 #pragma once
21 
22 #include <rtl/ustring.hxx>
23 #include <sfx2/progress.hxx>
24 #include <tools/solar.h>
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 
40 {
41 private:
48  static bool bIdleWasEnabled;
49  bool bEnabled;
50 
51  std::unique_ptr<SfxProgress> pProgress;
52 
53  ScProgress( const ScProgress& ) = delete;
54  ScProgress& operator=( const ScProgress& ) = delete;
55 
56  static void CalcGlobalPercent( sal_uLong nVal )
57  {
58  nGlobalPercent = nGlobalRange ?
59  nVal * 100 / nGlobalRange : 0;
60  }
61 
62 public:
63  static void CreateInterpretProgress( ScDocument* pDoc,
64  bool bWait = true );
65  static ScProgress* GetInterpretProgress() { return pInterpretProgress; }
66  static void DeleteInterpretProgress();
67 
68  ScProgress( SfxObjectShell* pObjSh,
69  const OUString& rText,
70  sal_uLong nRange,
71  bool bWait );
72  ~ScProgress();
73 
74 #ifdef SC_PROGRESS_CXX
75  ScProgress();
77 #endif
78  void SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
79  {
80  if ( pProgress )
81  {
82  if ( nNewRange )
83  nGlobalRange = nNewRange;
84  CalcGlobalPercent( nVal );
85  pProgress->SetState( nVal, nNewRange );
86  }
87  }
89  {
90  if ( pProgress )
91  {
92  CalcGlobalPercent( nGlobalRange - nVal );
93  pProgress->SetState( nGlobalRange - nVal );
94  }
95  }
97  {
98  if ( nGlobalRange && (nVal * 100 /
99  nGlobalRange) > nGlobalPercent )
100  SetState( nVal );
101  }
103  {
104  if ( nGlobalRange &&
105  ((nGlobalRange - nVal) * 100 /
106  nGlobalRange) > nGlobalPercent )
107  SetStateCountDown( nVal );
108  }
110  {
111  if ( pProgress )
112  return pProgress->GetState();
113  return 0;
114  }
115  bool Enabled() const { return bEnabled; }
116  void Disable() { bEnabled = false; }
117  void Enable() { bEnabled = true; }
118 };
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SfxProgress * pGlobalProgress
Definition: progress.hxx:42
bool Enabled() const
Definition: progress.hxx:115
static ScProgress * GetInterpretProgress()
Definition: progress.hxx:65
void Enable()
Definition: progress.hxx:117
bool bEnabled
Definition: progress.hxx:49
void SetStateCountDownOnPercent(sal_uLong nVal)
Definition: progress.hxx:102
static sal_uLong nInterpretProgress
Definition: progress.hxx:46
sal_uIntPtr sal_uLong
void SetStateOnPercent(sal_uLong nVal)
Definition: progress.hxx:96
void Disable()
Definition: progress.hxx:116
std::unique_ptr< SfxProgress > pProgress
Definition: progress.hxx:51
static sal_uLong nGlobalRange
Definition: progress.hxx:43
static sal_uLong nGlobalPercent
Definition: progress.hxx:44
sal_uLong GetState() const
Definition: progress.hxx:109
static ScDocument * pInterpretDoc
Definition: progress.hxx:47
static ScProgress * pInterpretProgress
Definition: progress.hxx:45
void SetState(sal_uLong nVal, sal_uLong nNewRange=0)
Definition: progress.hxx:78
static bool bIdleWasEnabled
Definition: progress.hxx:48
void SetStateCountDown(sal_uLong nVal)
Definition: progress.hxx:88
static void CalcGlobalPercent(sal_uLong nVal)
Definition: progress.hxx:56
#define SC_DLLPUBLIC
Definition: scdllapi.h:27