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