1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <rtl/ustring.hxx>
23 #include <sfx2/progress.hxx>
24 #include <tools/solar.h>
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
37 #define MIN_NO_CODES_PER_PROGRESS_UPDATE 100
39 class SC_DLLPUBLIC ScProgress
42 static SfxProgress
* pGlobalProgress
;
43 static sal_uInt64 nGlobalRange
;
44 static sal_uInt64 nGlobalPercent
;
45 static ScProgress
* pInterpretProgress
;
46 static sal_uInt64 nInterpretProgress
;
47 static ScDocument
* pInterpretDoc
;
48 static bool bIdleWasEnabled
;
51 std::unique_ptr
<SfxProgress
> pProgress
;
53 ScProgress( const ScProgress
& ) = delete;
54 ScProgress
& operator=( const ScProgress
& ) = delete;
56 static void CalcGlobalPercent( sal_uInt64 nVal
)
58 nGlobalPercent
= nGlobalRange
?
59 nVal
* 100 / nGlobalRange
: 0;
63 static void CreateInterpretProgress( ScDocument
* pDoc
,
65 static ScProgress
* GetInterpretProgress() { return pInterpretProgress
; }
66 static void DeleteInterpretProgress();
68 ScProgress( SfxObjectShell
* pObjSh
,
69 const OUString
& rText
,
74 #ifdef SC_PROGRESS_CXX
75 /// for DummyInterpret only, never use otherwise!!!
78 void SetState( sal_uInt64 nVal
, sal_uInt64 nNewRange
= 0 )
83 nGlobalRange
= nNewRange
;
84 CalcGlobalPercent( nVal
);
85 pProgress
->SetState( nVal
, nNewRange
);
88 void SetStateCountDown( sal_uInt64 nVal
)
92 CalcGlobalPercent( nGlobalRange
- nVal
);
93 pProgress
->SetState( nGlobalRange
- nVal
);
96 void SetStateOnPercent( sal_uInt64 nVal
)
97 { /// only if percentage increased
98 if ( nGlobalRange
&& (nVal
* 100 /
99 nGlobalRange
) > nGlobalPercent
)
102 void SetStateCountDownOnPercent( sal_uInt64 nVal
)
103 { /// only if percentage increased
105 ((nGlobalRange
- nVal
) * 100 /
106 nGlobalRange
) > nGlobalPercent
)
107 SetStateCountDown( nVal
);
109 sal_uInt64
GetState() const
112 return pProgress
->GetState();
115 bool Enabled() const { return bEnabled
; }
116 void Disable() { bEnabled
= false; }
117 void Enable() { bEnabled
= true; }
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */