Show duplicate attribute
[LibreOffice.git] / sc / inc / progress.hxx
blobd65c9b56ce37a851d355a54d4f3adf0d4c188b40
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 INCLUDED_SC_INC_PROGRESS_HXX
21 #define INCLUDED_SC_INC_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
39 class SC_DLLPUBLIC ScProgress
41 private:
42 static SfxProgress* pGlobalProgress;
43 static sal_uLong nGlobalRange;
44 static sal_uLong nGlobalPercent;
45 static bool bGlobalNoUserBreak;
46 static ScProgress* pInterpretProgress;
47 static ScProgress* pOldInterpretProgress;
48 static sal_uLong nInterpretProgress;
49 static bool bAllowInterpretProgress;
50 static ScDocument* pInterpretDoc;
51 static bool bIdleWasEnabled;
53 SfxProgress* pProgress;
55 ScProgress( const ScProgress& ) SAL_DELETED_FUNCTION;
56 ScProgress& operator=( const ScProgress& ) SAL_DELETED_FUNCTION;
58 static void CalcGlobalPercent( sal_uLong nVal )
60 nGlobalPercent = nGlobalRange ?
61 nVal * 100 / nGlobalRange : 0;
64 public:
65 static SfxProgress* GetGlobalSfxProgress() { return pGlobalProgress; }
66 static bool IsUserBreak() { return !bGlobalNoUserBreak; }
67 static void CreateInterpretProgress( ScDocument* pDoc,
68 bool bWait = true );
69 static ScProgress* GetInterpretProgress() { return pInterpretProgress; }
70 static void DeleteInterpretProgress();
71 static sal_uLong GetInterpretCount() { return nInterpretProgress; }
72 static sal_uLong GetGlobalRange() { return nGlobalRange; }
73 static sal_uLong GetGlobalPercent() { return nGlobalPercent; }
75 ScProgress( SfxObjectShell* pObjSh,
76 const OUString& rText,
77 sal_uLong nRange, bool bAllDocs = false,
78 bool bWait = true );
79 ~ScProgress();
81 #ifdef SC_PROGRESS_CXX
82 /// for DummyInterpret only, never use otherwise!!!
83 ScProgress();
84 #endif
85 /// might be NULL!
86 SfxProgress* GetSfxProgress() const { return pProgress; }
88 bool SetStateText( sal_uLong nVal, const OUString &rVal, sal_uLong nNewRange = 0 )
90 if ( pProgress )
92 if ( nNewRange )
93 nGlobalRange = nNewRange;
94 CalcGlobalPercent( nVal );
95 if ( !pProgress->SetStateText( nVal, rVal, nNewRange ) )
96 bGlobalNoUserBreak = false;
97 return bGlobalNoUserBreak;
99 return true;
101 bool SetState( sal_uLong nVal, sal_uLong nNewRange = 0 )
103 if ( pProgress )
105 if ( nNewRange )
106 nGlobalRange = nNewRange;
107 CalcGlobalPercent( nVal );
108 if ( !pProgress->SetState( nVal, nNewRange ) )
109 bGlobalNoUserBreak = false;
110 return bGlobalNoUserBreak;
112 return true;
114 bool SetStateCountDown( sal_uLong nVal )
116 if ( pProgress )
118 CalcGlobalPercent( nGlobalRange - nVal );
119 if ( !pProgress->SetState( nGlobalRange - nVal ) )
120 bGlobalNoUserBreak = false;
121 return bGlobalNoUserBreak;
123 return true;
125 bool SetStateOnPercent( sal_uLong nVal )
126 { /// only if percentage increased
127 if ( nGlobalRange && (nVal * 100 /
128 nGlobalRange) > nGlobalPercent )
129 return SetState( nVal );
130 return true;
132 bool SetStateCountDownOnPercent( sal_uLong nVal )
133 { /// only if percentage increased
134 if ( nGlobalRange &&
135 ((nGlobalRange - nVal) * 100 /
136 nGlobalRange) > nGlobalPercent )
137 return SetStateCountDown( nVal );
138 return true;
140 sal_uLong GetState()
142 if ( pProgress )
143 return pProgress->GetState();
144 return 0;
148 #endif
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */