Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_PROGRESS_HXX
30 : : #define SC_PROGRESS_HXX
31 : :
32 : : #include <sfx2/progress.hxx>
33 : : #include "scdllapi.h"
34 : :
35 : : class ScDocument;
36 : :
37 : : /*
38 : : * #i102566
39 : : * Drawing a progress bar update is not cheap, so if we draw it on every
40 : : * percentage change of 200 calculations we get one progress draw per 2
41 : : * calculations which is slower than doing the calculations themselves. So as a
42 : : * rough guide only do an update per MIN_NO_CODES_PER_PROGRESS_UPDATE
43 : : * calculations
44 : : */
45 : : #define MIN_NO_CODES_PER_PROGRESS_UPDATE 100
46 : :
47 : :
48 : : class SC_DLLPUBLIC ScProgress
49 : : {
50 : : private:
51 : : static SfxProgress* pGlobalProgress;
52 : : static sal_uLong nGlobalRange;
53 : : static sal_uLong nGlobalPercent;
54 : : static sal_Bool bGlobalNoUserBreak;
55 : : static ScProgress* pInterpretProgress;
56 : : static ScProgress* pOldInterpretProgress;
57 : : static sal_uLong nInterpretProgress;
58 : : static sal_Bool bAllowInterpretProgress;
59 : : static ScDocument* pInterpretDoc;
60 : : static sal_Bool bIdleWasDisabled;
61 : :
62 : : SfxProgress* pProgress;
63 : :
64 : : // not implemented
65 : : ScProgress( const ScProgress& );
66 : : ScProgress& operator=( const ScProgress& );
67 : :
68 : 955 : static void CalcGlobalPercent( sal_uLong nVal )
69 : : {
70 : : nGlobalPercent = nGlobalRange ?
71 [ + + ]: 955 : nVal * 100 / nGlobalRange : 0;
72 : 955 : }
73 : :
74 : : public:
75 : : static SfxProgress* GetGlobalSfxProgress() { return pGlobalProgress; }
76 : 205 : static sal_Bool IsUserBreak() { return !bGlobalNoUserBreak; }
77 : : static void CreateInterpretProgress( ScDocument* pDoc,
78 : : sal_Bool bWait = sal_True );
79 : 2619 : static ScProgress* GetInterpretProgress() { return pInterpretProgress; }
80 : : static void DeleteInterpretProgress();
81 : : static sal_uLong GetInterpretCount() { return nInterpretProgress; }
82 : : static sal_uLong GetGlobalRange() { return nGlobalRange; }
83 : : static sal_uLong GetGlobalPercent() { return nGlobalPercent; }
84 : :
85 : : ScProgress( SfxObjectShell* pObjSh,
86 : : const String& rText,
87 : : sal_uLong nRange, sal_Bool bAllDocs = false,
88 : : sal_Bool bWait = sal_True );
89 : : ~ScProgress();
90 : :
91 : : #ifdef SC_PROGRESS_CXX
92 : : // for DummyInterpret only, never use otherwise!!!
93 : : ScProgress();
94 : : #endif
95 : : // might be NULL!
96 : : SfxProgress* GetSfxProgress() const { return pProgress; }
97 : :
98 : 6 : sal_Bool SetStateText( sal_uLong nVal, const String &rVal, sal_uLong nNewRange = 0 )
99 : : {
100 [ + - ]: 6 : if ( pProgress )
101 : : {
102 [ - + ]: 6 : if ( nNewRange )
103 : 0 : nGlobalRange = nNewRange;
104 : 6 : CalcGlobalPercent( nVal );
105 [ - + ]: 6 : if ( !pProgress->SetStateText( nVal, rVal, nNewRange ) )
106 : 0 : bGlobalNoUserBreak = false;
107 : 6 : return bGlobalNoUserBreak;
108 : : }
109 : 6 : return sal_True;
110 : : }
111 : 7130 : sal_Bool SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
112 : : {
113 [ + + ]: 7130 : if ( pProgress )
114 : : {
115 [ - + ]: 935 : if ( nNewRange )
116 : 0 : nGlobalRange = nNewRange;
117 : 935 : CalcGlobalPercent( nVal );
118 [ - + ]: 935 : if ( !pProgress->SetState( nVal, nNewRange ) )
119 : 0 : bGlobalNoUserBreak = false;
120 : 935 : return bGlobalNoUserBreak;
121 : : }
122 : 7130 : return sal_True;
123 : : }
124 : 17 : sal_Bool SetStateCountDown( sal_uLong nVal )
125 : : {
126 [ + + ]: 17 : if ( pProgress )
127 : : {
128 : 14 : CalcGlobalPercent( nGlobalRange - nVal );
129 [ - + ]: 14 : if ( !pProgress->SetState( nGlobalRange - nVal ) )
130 : 0 : bGlobalNoUserBreak = false;
131 : 14 : return bGlobalNoUserBreak;
132 : : }
133 : 17 : return sal_True;
134 : : }
135 : 319 : sal_Bool SetStateOnPercent( sal_uLong nVal )
136 : : { // only if percentage increased
137 [ + + ][ + + ]: 319 : if ( nGlobalRange && (nVal * 100 /
138 : : nGlobalRange) > nGlobalPercent )
139 : 51 : return SetState( nVal );
140 : 319 : return sal_True;
141 : : }
142 : 3686 : sal_Bool SetStateCountDownOnPercent( sal_uLong nVal )
143 : : { // only if percentage increased
144 [ + + ][ + - ]: 3686 : if ( nGlobalRange &&
145 : : ((nGlobalRange - nVal) * 100 /
146 : : nGlobalRange) > nGlobalPercent )
147 : 17 : return SetStateCountDown( nVal );
148 : 3686 : return sal_True;
149 : : }
150 : 12 : sal_uLong GetState()
151 : : {
152 [ + - ]: 12 : if ( pProgress )
153 : 12 : return pProgress->GetState();
154 : 12 : return 0;
155 : : }
156 : : };
157 : :
158 : :
159 : : #endif
160 : :
161 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|