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