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
27class 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{
41private:
43 static sal_uInt64 nGlobalRange;
44 static sal_uInt64 nGlobalPercent;
46 static sal_uInt64 nInterpretProgress;
48 static bool bIdleWasEnabled;
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_uInt64 nVal )
57 {
58 nGlobalPercent = nGlobalRange ?
59 nVal * 100 / nGlobalRange : 0;
60 }
61
62public:
63 static void CreateInterpretProgress( ScDocument* pDoc,
64 bool bWait = true );
65 static ScProgress* GetInterpretProgress() { return pInterpretProgress; }
66 static void DeleteInterpretProgress();
67
69 const OUString& rText,
70 sal_uInt64 nRange,
71 bool bWait );
73
74#ifdef SC_PROGRESS_CXX
76 ScProgress();
77#endif
78 void SetState( sal_uInt64 nVal, sal_uInt64 nNewRange = 0 )
79 {
80 if ( pProgress )
81 {
82 if ( nNewRange )
83 nGlobalRange = nNewRange;
84 CalcGlobalPercent( nVal );
85 pProgress->SetState( nVal, nNewRange );
86 }
87 }
88 void SetStateCountDown( sal_uInt64 nVal )
89 {
90 if ( pProgress )
91 {
92 CalcGlobalPercent( nGlobalRange - nVal );
93 pProgress->SetState( nGlobalRange - nVal );
94 }
95 }
96 void SetStateOnPercent( sal_uInt64 nVal )
97 {
98 if ( nGlobalRange && (nVal * 100 /
99 nGlobalRange) > nGlobalPercent )
100 SetState( nVal );
101 }
102 void SetStateCountDownOnPercent( sal_uInt64 nVal )
103 {
104 if ( nGlobalRange &&
105 ((nGlobalRange - nVal) * 100 /
106 nGlobalRange) > nGlobalPercent )
107 SetStateCountDown( nVal );
108 }
109 sal_uInt64 GetState() const
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 sal_uInt64 nGlobalRange
Definition: progress.hxx:43
static sal_uInt64 nGlobalPercent
Definition: progress.hxx:44
ScProgress(const ScProgress &)=delete
sal_uInt64 GetState() const
Definition: progress.hxx:109
static ScDocument * pInterpretDoc
Definition: progress.hxx:47
void Enable()
Definition: progress.hxx:117
ScProgress & operator=(const ScProgress &)=delete
void SetStateCountDownOnPercent(sal_uInt64 nVal)
Definition: progress.hxx:102
bool bEnabled
Definition: progress.hxx:49
static SfxProgress * pGlobalProgress
Definition: progress.hxx:42
void SetState(sal_uInt64 nVal, sal_uInt64 nNewRange=0)
Definition: progress.hxx:78
std::unique_ptr< SfxProgress > pProgress
Definition: progress.hxx:51
static bool bIdleWasEnabled
Definition: progress.hxx:48
void SetStateCountDown(sal_uInt64 nVal)
Definition: progress.hxx:88
void Disable()
Definition: progress.hxx:116
static void CalcGlobalPercent(sal_uInt64 nVal)
Definition: progress.hxx:56
void SetStateOnPercent(sal_uInt64 nVal)
Definition: progress.hxx:96
static sal_uInt64 nInterpretProgress
Definition: progress.hxx:46
static ScProgress * GetInterpretProgress()
Definition: progress.hxx:65
static ScProgress * pInterpretProgress
Definition: progress.hxx:45
bool Enabled() const
Definition: progress.hxx:115
#define SC_DLLPUBLIC
Definition: scdllapi.h:27