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