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 SC_PROGRESS_HXX
21 : #define SC_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 :
40 : class SC_DLLPUBLIC ScProgress
41 : {
42 : private:
43 : static SfxProgress* pGlobalProgress;
44 : static sal_uLong nGlobalRange;
45 : static sal_uLong nGlobalPercent;
46 : static bool bGlobalNoUserBreak;
47 : static ScProgress* pInterpretProgress;
48 : static ScProgress* pOldInterpretProgress;
49 : static sal_uLong nInterpretProgress;
50 : static bool bAllowInterpretProgress;
51 : static ScDocument* pInterpretDoc;
52 : static bool bIdleWasEnabled;
53 :
54 : SfxProgress* pProgress;
55 :
56 : /// not implemented
57 : ScProgress( const ScProgress& );
58 : ScProgress& operator=( const ScProgress& );
59 :
60 0 : static void CalcGlobalPercent( sal_uLong nVal )
61 : {
62 : nGlobalPercent = nGlobalRange ?
63 0 : nVal * 100 / nGlobalRange : 0;
64 0 : }
65 :
66 : public:
67 : static SfxProgress* GetGlobalSfxProgress() { return pGlobalProgress; }
68 0 : static bool IsUserBreak() { return !bGlobalNoUserBreak; }
69 : static void CreateInterpretProgress( ScDocument* pDoc,
70 : bool bWait = true );
71 0 : static ScProgress* GetInterpretProgress() { return pInterpretProgress; }
72 : static void DeleteInterpretProgress();
73 : static sal_uLong GetInterpretCount() { return nInterpretProgress; }
74 : static sal_uLong GetGlobalRange() { return nGlobalRange; }
75 : static sal_uLong GetGlobalPercent() { return nGlobalPercent; }
76 :
77 : ScProgress( SfxObjectShell* pObjSh,
78 : const OUString& rText,
79 : sal_uLong nRange, bool bAllDocs = false,
80 : bool bWait = true );
81 : ~ScProgress();
82 :
83 : #ifdef SC_PROGRESS_CXX
84 : /// for DummyInterpret only, never use otherwise!!!
85 : ScProgress();
86 : #endif
87 : /// might be NULL!
88 : SfxProgress* GetSfxProgress() const { return pProgress; }
89 :
90 0 : bool SetStateText( sal_uLong nVal, const OUString &rVal, sal_uLong nNewRange = 0 )
91 : {
92 0 : if ( pProgress )
93 : {
94 0 : if ( nNewRange )
95 0 : nGlobalRange = nNewRange;
96 0 : CalcGlobalPercent( nVal );
97 0 : if ( !pProgress->SetStateText( nVal, rVal, nNewRange ) )
98 0 : bGlobalNoUserBreak = false;
99 0 : return bGlobalNoUserBreak;
100 : }
101 0 : return true;
102 : }
103 0 : bool SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
104 : {
105 0 : if ( pProgress )
106 : {
107 0 : if ( nNewRange )
108 0 : nGlobalRange = nNewRange;
109 0 : CalcGlobalPercent( nVal );
110 0 : if ( !pProgress->SetState( nVal, nNewRange ) )
111 0 : bGlobalNoUserBreak = false;
112 0 : return bGlobalNoUserBreak;
113 : }
114 0 : return true;
115 : }
116 0 : bool SetStateCountDown( sal_uLong nVal )
117 : {
118 0 : if ( pProgress )
119 : {
120 0 : CalcGlobalPercent( nGlobalRange - nVal );
121 0 : if ( !pProgress->SetState( nGlobalRange - nVal ) )
122 0 : bGlobalNoUserBreak = false;
123 0 : return bGlobalNoUserBreak;
124 : }
125 0 : return true;
126 : }
127 0 : bool SetStateOnPercent( sal_uLong nVal )
128 : { /// only if percentage increased
129 0 : if ( nGlobalRange && (nVal * 100 /
130 0 : nGlobalRange) > nGlobalPercent )
131 0 : return SetState( nVal );
132 0 : return true;
133 : }
134 0 : bool SetStateCountDownOnPercent( sal_uLong nVal )
135 : { /// only if percentage increased
136 0 : if ( nGlobalRange &&
137 0 : ((nGlobalRange - nVal) * 100 /
138 0 : nGlobalRange) > nGlobalPercent )
139 0 : return SetStateCountDown( nVal );
140 0 : return true;
141 : }
142 0 : sal_uLong GetState()
143 : {
144 0 : if ( pProgress )
145 0 : return pProgress->GetState();
146 0 : return 0;
147 : }
148 : };
149 :
150 :
151 : #endif
152 :
153 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|