Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / progress.hxx
blob3c3c5f8c1baca3dad7ec61c9149e70cbb389478e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef SC_PROGRESS_HXX
21 #define SC_PROGRESS_HXX
23 #include <rtl/ustring.hxx>
24 #include <sfx2/progress.hxx>
25 #include "scdllapi.h"
27 class ScDocument;
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
37 #define MIN_NO_CODES_PER_PROGRESS_UPDATE 100
40 class SC_DLLPUBLIC ScProgress
42 private:
43 static SfxProgress* pGlobalProgress;
44 static sal_uLong nGlobalRange;
45 static sal_uLong nGlobalPercent;
46 static sal_Bool bGlobalNoUserBreak;
47 static ScProgress* pInterpretProgress;
48 static ScProgress* pOldInterpretProgress;
49 static sal_uLong nInterpretProgress;
50 static sal_Bool bAllowInterpretProgress;
51 static ScDocument* pInterpretDoc;
52 static bool bIdleWasEnabled;
54 SfxProgress* pProgress;
56 /// not implemented
57 ScProgress( const ScProgress& );
58 ScProgress& operator=( const ScProgress& );
60 static void CalcGlobalPercent( sal_uLong nVal )
62 nGlobalPercent = nGlobalRange ?
63 nVal * 100 / nGlobalRange : 0;
66 public:
67 static SfxProgress* GetGlobalSfxProgress() { return pGlobalProgress; }
68 static sal_Bool IsUserBreak() { return !bGlobalNoUserBreak; }
69 static void CreateInterpretProgress( ScDocument* pDoc,
70 sal_Bool bWait = sal_True );
71 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; }
77 ScProgress( SfxObjectShell* pObjSh,
78 const OUString& rText,
79 sal_uLong nRange, sal_Bool bAllDocs = false,
80 sal_Bool bWait = sal_True );
81 ~ScProgress();
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; }
90 sal_Bool SetStateText( sal_uLong nVal, const OUString &rVal, sal_uLong nNewRange = 0 )
92 if ( pProgress )
94 if ( nNewRange )
95 nGlobalRange = nNewRange;
96 CalcGlobalPercent( nVal );
97 if ( !pProgress->SetStateText( nVal, rVal, nNewRange ) )
98 bGlobalNoUserBreak = false;
99 return bGlobalNoUserBreak;
101 return sal_True;
103 sal_Bool SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
105 if ( pProgress )
107 if ( nNewRange )
108 nGlobalRange = nNewRange;
109 CalcGlobalPercent( nVal );
110 if ( !pProgress->SetState( nVal, nNewRange ) )
111 bGlobalNoUserBreak = false;
112 return bGlobalNoUserBreak;
114 return sal_True;
116 sal_Bool SetStateCountDown( sal_uLong nVal )
118 if ( pProgress )
120 CalcGlobalPercent( nGlobalRange - nVal );
121 if ( !pProgress->SetState( nGlobalRange - nVal ) )
122 bGlobalNoUserBreak = false;
123 return bGlobalNoUserBreak;
125 return sal_True;
127 sal_Bool SetStateOnPercent( sal_uLong nVal )
128 { /// only if percentage increased
129 if ( nGlobalRange && (nVal * 100 /
130 nGlobalRange) > nGlobalPercent )
131 return SetState( nVal );
132 return sal_True;
134 sal_Bool SetStateCountDownOnPercent( sal_uLong nVal )
135 { /// only if percentage increased
136 if ( nGlobalRange &&
137 ((nGlobalRange - nVal) * 100 /
138 nGlobalRange) > nGlobalPercent )
139 return SetStateCountDown( nVal );
140 return sal_True;
142 sal_uLong GetState()
144 if ( pProgress )
145 return pProgress->GetState();
146 return 0;
151 #endif
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */