Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sc / inc / progress.hxx
blob0607c054dd42aa019d3cb230b62e017f2339779a
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 <sfx2/progress.hxx>
24 #include "scdllapi.h"
26 class ScDocument;
29 * #i102566
30 * Drawing a progress bar update is not cheap, so if we draw it on every
31 * percentage change of 200 calculations we get one progress draw per 2
32 * calculations which is slower than doing the calculations themselves. So as a
33 * rough guide only do an update per MIN_NO_CODES_PER_PROGRESS_UPDATE
34 * calculations
36 #define MIN_NO_CODES_PER_PROGRESS_UPDATE 100
39 class SC_DLLPUBLIC ScProgress
41 private:
42 static SfxProgress* pGlobalProgress;
43 static sal_uLong nGlobalRange;
44 static sal_uLong nGlobalPercent;
45 static sal_Bool bGlobalNoUserBreak;
46 static ScProgress* pInterpretProgress;
47 static ScProgress* pOldInterpretProgress;
48 static sal_uLong nInterpretProgress;
49 static sal_Bool bAllowInterpretProgress;
50 static ScDocument* pInterpretDoc;
51 static sal_Bool bIdleWasDisabled;
53 SfxProgress* pProgress;
55 // not implemented
56 ScProgress( const ScProgress& );
57 ScProgress& operator=( const ScProgress& );
59 static void CalcGlobalPercent( sal_uLong nVal )
61 nGlobalPercent = nGlobalRange ?
62 nVal * 100 / nGlobalRange : 0;
65 public:
66 static SfxProgress* GetGlobalSfxProgress() { return pGlobalProgress; }
67 static sal_Bool IsUserBreak() { return !bGlobalNoUserBreak; }
68 static void CreateInterpretProgress( ScDocument* pDoc,
69 sal_Bool bWait = sal_True );
70 static ScProgress* GetInterpretProgress() { return pInterpretProgress; }
71 static void DeleteInterpretProgress();
72 static sal_uLong GetInterpretCount() { return nInterpretProgress; }
73 static sal_uLong GetGlobalRange() { return nGlobalRange; }
74 static sal_uLong GetGlobalPercent() { return nGlobalPercent; }
76 ScProgress( SfxObjectShell* pObjSh,
77 const String& rText,
78 sal_uLong nRange, sal_Bool bAllDocs = false,
79 sal_Bool bWait = sal_True );
80 ~ScProgress();
82 #ifdef SC_PROGRESS_CXX
83 // for DummyInterpret only, never use otherwise!!!
84 ScProgress();
85 #endif
86 // might be NULL!
87 SfxProgress* GetSfxProgress() const { return pProgress; }
89 sal_Bool SetStateText( sal_uLong nVal, const String &rVal, sal_uLong nNewRange = 0 )
91 if ( pProgress )
93 if ( nNewRange )
94 nGlobalRange = nNewRange;
95 CalcGlobalPercent( nVal );
96 if ( !pProgress->SetStateText( nVal, rVal, nNewRange ) )
97 bGlobalNoUserBreak = false;
98 return bGlobalNoUserBreak;
100 return sal_True;
102 sal_Bool SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
104 if ( pProgress )
106 if ( nNewRange )
107 nGlobalRange = nNewRange;
108 CalcGlobalPercent( nVal );
109 if ( !pProgress->SetState( nVal, nNewRange ) )
110 bGlobalNoUserBreak = false;
111 return bGlobalNoUserBreak;
113 return sal_True;
115 sal_Bool SetStateCountDown( sal_uLong nVal )
117 if ( pProgress )
119 CalcGlobalPercent( nGlobalRange - nVal );
120 if ( !pProgress->SetState( nGlobalRange - nVal ) )
121 bGlobalNoUserBreak = false;
122 return bGlobalNoUserBreak;
124 return sal_True;
126 sal_Bool SetStateOnPercent( sal_uLong nVal )
127 { // only if percentage increased
128 if ( nGlobalRange && (nVal * 100 /
129 nGlobalRange) > nGlobalPercent )
130 return SetState( nVal );
131 return sal_True;
133 sal_Bool SetStateCountDownOnPercent( sal_uLong nVal )
134 { // only if percentage increased
135 if ( nGlobalRange &&
136 ((nGlobalRange - nVal) * 100 /
137 nGlobalRange) > nGlobalPercent )
138 return SetStateCountDown( nVal );
139 return sal_True;
141 sal_uLong GetState()
143 if ( pProgress )
144 return pProgress->GetState();
145 return 0;
150 #endif
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */