xref: /aoo42x/main/sc/inc/progress.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_PROGRESS_HXX
25 #define SC_PROGRESS_HXX
26 
27 #include <sfx2/progress.hxx>
28 #include "scdllapi.h"
29 
30 class ScDocument;
31 
32 /*
33  * #i102566
34  * Drawing a progress bar update is not cheap, so if we draw it on every
35  * percentage change of 200 calculations we get one progress draw per 2
36  * calculations which is slower than doing the calculations themselves. So as a
37  * rough guide only do an update per MIN_NO_CODES_PER_PROGRESS_UPDATE
38  * calculations
39  */
40 #define MIN_NO_CODES_PER_PROGRESS_UPDATE 100
41 
42 
43 class SC_DLLPUBLIC ScProgress
44 {
45 private:
46 	static	SfxProgress*	pGlobalProgress;
47 	static	sal_uLong			nGlobalRange;
48 	static	sal_uLong			nGlobalPercent;
49 	static	sal_Bool			bGlobalNoUserBreak;
50 	static	ScProgress*		pInterpretProgress;
51 	static	ScProgress*		pOldInterpretProgress;
52 	static	sal_uLong			nInterpretProgress;
53 	static	sal_Bool			bAllowInterpretProgress;
54 	static	ScDocument*		pInterpretDoc;
55 	static	sal_Bool			bIdleWasDisabled;
56 
57 			SfxProgress*	pProgress;
58 
59 							// not implemented
60 							ScProgress( const ScProgress& );
61 			ScProgress&		operator=( const ScProgress& );
62 
CalcGlobalPercent(sal_uLong nVal)63 	static	void			CalcGlobalPercent( sal_uLong nVal )
64 								{
65 									nGlobalPercent = nGlobalRange ?
66 										nVal * 100 / nGlobalRange : 0;
67 								}
68 
69 public:
GetGlobalSfxProgress()70 	static	SfxProgress*	GetGlobalSfxProgress() { return pGlobalProgress; }
IsUserBreak()71 	static	sal_Bool			IsUserBreak() { return !bGlobalNoUserBreak; }
72 	static	void			CreateInterpretProgress( ScDocument* pDoc,
73 													sal_Bool bWait = sal_True );
GetInterpretProgress()74 	static	ScProgress*		GetInterpretProgress() { return pInterpretProgress; }
75 	static	void			DeleteInterpretProgress();
GetInterpretCount()76 	static	sal_uLong			GetInterpretCount() { return nInterpretProgress; }
GetGlobalRange()77 	static	sal_uLong			GetGlobalRange()	{ return nGlobalRange; }
GetGlobalPercent()78 	static	sal_uLong			GetGlobalPercent()	{ return nGlobalPercent; }
79 
80 							ScProgress( SfxObjectShell* pObjSh,
81 										 const String& rText,
82 										 sal_uLong nRange, sal_Bool bAllDocs = sal_False,
83 										 sal_Bool bWait = sal_True );
84 							~ScProgress();
85 
86 #ifdef SC_PROGRESS_CXX
87 							// nur fuer DummyInterpret, sonst nie benutzen!!!
88 							ScProgress();
89 #endif
90 							// kann NULL sein!
GetSfxProgress() const91 			SfxProgress*	GetSfxProgress() const { return pProgress; }
92 
SetStateText(sal_uLong nVal,const String & rVal,sal_uLong nNewRange=0)93 			sal_Bool			SetStateText( sal_uLong nVal, const String &rVal, sal_uLong nNewRange = 0 )
94 								{
95 									if ( pProgress )
96 									{
97 										if ( nNewRange )
98 											nGlobalRange = nNewRange;
99 										CalcGlobalPercent( nVal );
100 										if ( !pProgress->SetStateText( nVal, rVal, nNewRange ) )
101 											bGlobalNoUserBreak = sal_False;
102 										return bGlobalNoUserBreak;
103 									}
104 									return sal_True;
105 								}
SetState(sal_uLong nVal,sal_uLong nNewRange=0)106 			sal_Bool			SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
107 								{
108 									if ( pProgress )
109 									{
110 										if ( nNewRange )
111 											nGlobalRange = nNewRange;
112 										CalcGlobalPercent( nVal );
113 										if ( !pProgress->SetState( nVal, nNewRange ) )
114 											bGlobalNoUserBreak = sal_False;
115 										return bGlobalNoUserBreak;
116 									}
117 									return sal_True;
118 								}
SetStateCountDown(sal_uLong nVal)119 			sal_Bool			SetStateCountDown( sal_uLong nVal )
120 								{
121 									if ( pProgress )
122 									{
123 										CalcGlobalPercent( nGlobalRange - nVal );
124 										if ( !pProgress->SetState( nGlobalRange - nVal ) )
125 											bGlobalNoUserBreak = sal_False;
126 										return bGlobalNoUserBreak;
127 									}
128 									return sal_True;
129 								}
SetStateOnPercent(sal_uLong nVal)130 			sal_Bool			SetStateOnPercent( sal_uLong nVal )
131 								{	// nur wenn Prozent mehr als vorher
132 									if ( nGlobalRange && (nVal * 100 /
133 											nGlobalRange) > nGlobalPercent )
134 										return SetState( nVal );
135 									return sal_True;
136 								}
SetStateCountDownOnPercent(sal_uLong nVal)137 			sal_Bool			SetStateCountDownOnPercent( sal_uLong nVal )
138 								{	// nur wenn Prozent mehr als vorher
139 									if ( nGlobalRange &&
140 											((nGlobalRange - nVal) * 100 /
141 											nGlobalRange) > nGlobalPercent )
142 										return SetStateCountDown( nVal );
143 									return sal_True;
144 								}
GetState()145 			sal_uLong			GetState()
146 								{
147 									if ( pProgress )
148 										return pProgress->GetState();
149 									return 0;
150 								}
151 };
152 
153 
154 #endif
155 
156