1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30cdf0e10cSrcweir 31cdf0e10cSrcweir //___________________________________________________________________ 32cdf0e10cSrcweir #include <xmloff/ProgressBarHelper.hxx> 33cdf0e10cSrcweir #include <tools/debug.hxx> 34cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <stdlib.h> 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace ::com::sun::star; 39cdf0e10cSrcweir 40cdf0e10cSrcweir const sal_Int32 nDefaultProgressBarRange = 1000000; 41cdf0e10cSrcweir const float fProgressStep = 0.5; 42cdf0e10cSrcweir 43cdf0e10cSrcweir ProgressBarHelper::ProgressBarHelper(const ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator>& xTempStatusIndicator, 44cdf0e10cSrcweir const sal_Bool bTempStrict) 45cdf0e10cSrcweir : xStatusIndicator(xTempStatusIndicator) 46cdf0e10cSrcweir , nRange(nDefaultProgressBarRange) 47cdf0e10cSrcweir , nReference(100) 48cdf0e10cSrcweir , nValue(0) 49cdf0e10cSrcweir , fOldPercent(0.0) 50cdf0e10cSrcweir , bStrict(bTempStrict) 51cdf0e10cSrcweir , bRepeat(sal_True) 52cdf0e10cSrcweir #ifdef DBG_UTIL 53cdf0e10cSrcweir , bFailure(sal_False) 54cdf0e10cSrcweir #endif 55cdf0e10cSrcweir { 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir ProgressBarHelper::~ProgressBarHelper() 59cdf0e10cSrcweir { 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir sal_Int32 ProgressBarHelper::ChangeReference(sal_Int32 nNewReference) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir if((nNewReference > 0) && (nNewReference != nReference)) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir if (nReference) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir double fPercent(nNewReference / nReference); 69cdf0e10cSrcweir double fValue(nValue * fPercent); 70cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 71cdf0e10cSrcweir // workaround for toolchain bug on solaris/x86 Sun C++ 5.5 72cdf0e10cSrcweir // just call some function here 73cdf0e10cSrcweir (void) abs(nValue); 74cdf0e10cSrcweir #endif 75cdf0e10cSrcweir nValue = static_cast< sal_Int32 >(fValue); 76cdf0e10cSrcweir nReference = nNewReference; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir else 79cdf0e10cSrcweir { 80cdf0e10cSrcweir nReference = nNewReference; 81cdf0e10cSrcweir nValue = 0; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir } 84cdf0e10cSrcweir return nValue; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir void ProgressBarHelper::SetValue(sal_Int32 nTempValue) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir if (xStatusIndicator.is() && (nReference > 0)) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir if ((nTempValue >= nValue) && (!bStrict || (bStrict && (nTempValue <= nReference)))) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir // #91317# no progress bar with values > 100% 94cdf0e10cSrcweir if (nTempValue > nReference) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir if (!bRepeat) 97cdf0e10cSrcweir nValue = nReference; 98cdf0e10cSrcweir else 99cdf0e10cSrcweir { 100cdf0e10cSrcweir // xStatusIndicator->end(); 101cdf0e10cSrcweir // xStatusIndicator->start(); 102cdf0e10cSrcweir xStatusIndicator->reset(); 103cdf0e10cSrcweir nValue = 0; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir else 107cdf0e10cSrcweir nValue = nTempValue; 108cdf0e10cSrcweir 109cdf0e10cSrcweir double fValue(nValue); 110cdf0e10cSrcweir double fNewValue ((fValue * nRange) / nReference); 111cdf0e10cSrcweir 112cdf0e10cSrcweir xmloff::token::IncRescheduleCount(); 113cdf0e10cSrcweir 114cdf0e10cSrcweir xStatusIndicator->setValue((sal_Int32)fNewValue); 115cdf0e10cSrcweir 116cdf0e10cSrcweir xmloff::token::DecRescheduleCount(); 117cdf0e10cSrcweir 118cdf0e10cSrcweir // #95181# disabled, because we want to call setValue very often to enable a good reschedule 119cdf0e10cSrcweir // double fPercent ((fNewValue * 100) / nRange); 120cdf0e10cSrcweir // if (fPercent >= (fOldPercent + fProgressStep)) 121cdf0e10cSrcweir // { 122cdf0e10cSrcweir // xStatusIndicator->setValue((sal_Int32)fNewValue); 123cdf0e10cSrcweir // fOldPercent = fPercent; 124cdf0e10cSrcweir // } 125cdf0e10cSrcweir } 126cdf0e10cSrcweir #ifdef DBG_UTIL 127cdf0e10cSrcweir else if (!bFailure) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir DBG_ERROR("tried to set a wrong value on the progressbar"); 130cdf0e10cSrcweir bFailure = sal_True; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir #endif 133cdf0e10cSrcweir } 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136