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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 31 32 33 34 35 //___________________________________________________________________ 36 #include <xmloff/ProgressBarHelper.hxx> 37 #include <tools/debug.hxx> 38 #include <xmloff/xmltoken.hxx> 39 40 #include <stdlib.h> 41 42 using namespace ::com::sun::star; 43 44 const sal_Int32 nDefaultProgressBarRange = 1000000; 45 const float fProgressStep = 0.5; 46 47 ProgressBarHelper::ProgressBarHelper(const ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator>& xTempStatusIndicator, 48 const sal_Bool bTempStrict) 49 : xStatusIndicator(xTempStatusIndicator) 50 , nRange(nDefaultProgressBarRange) 51 , nReference(100) 52 , nValue(0) 53 , fOldPercent(0.0) 54 , bStrict(bTempStrict) 55 , bRepeat(sal_True) 56 #ifdef DBG_UTIL 57 , bFailure(sal_False) 58 #endif 59 { 60 } 61 62 ProgressBarHelper::~ProgressBarHelper() 63 { 64 } 65 66 sal_Int32 ProgressBarHelper::ChangeReference(sal_Int32 nNewReference) 67 { 68 if((nNewReference > 0) && (nNewReference != nReference)) 69 { 70 if (nReference) 71 { 72 double fPercent(nNewReference / nReference); 73 double fValue(nValue * fPercent); 74 #if OSL_DEBUG_LEVEL > 0 75 // workaround for toolchain bug on solaris/x86 Sun C++ 5.5 76 // just call some function here 77 (void) abs(nValue); 78 #endif 79 nValue = static_cast< sal_Int32 >(fValue); 80 nReference = nNewReference; 81 } 82 else 83 { 84 nReference = nNewReference; 85 nValue = 0; 86 } 87 } 88 return nValue; 89 } 90 91 void ProgressBarHelper::SetValue(sal_Int32 nTempValue) 92 { 93 if (xStatusIndicator.is() && (nReference > 0)) 94 { 95 if ((nTempValue >= nValue) && (!bStrict || (bStrict && (nTempValue <= nReference)))) 96 { 97 // #91317# no progress bar with values > 100% 98 if (nTempValue > nReference) 99 { 100 if (!bRepeat) 101 nValue = nReference; 102 else 103 { 104 // xStatusIndicator->end(); 105 // xStatusIndicator->start(); 106 xStatusIndicator->reset(); 107 nValue = 0; 108 } 109 } 110 else 111 nValue = nTempValue; 112 113 double fValue(nValue); 114 double fNewValue ((fValue * nRange) / nReference); 115 116 xmloff::token::IncRescheduleCount(); 117 118 xStatusIndicator->setValue((sal_Int32)fNewValue); 119 120 xmloff::token::DecRescheduleCount(); 121 122 // #95181# disabled, because we want to call setValue very often to enable a good reschedule 123 // double fPercent ((fNewValue * 100) / nRange); 124 // if (fPercent >= (fOldPercent + fProgressStep)) 125 // { 126 // xStatusIndicator->setValue((sal_Int32)fNewValue); 127 // fOldPercent = fPercent; 128 // } 129 } 130 #ifdef DBG_UTIL 131 else if (!bFailure) 132 { 133 DBG_ERROR("tried to set a wrong value on the progressbar"); 134 bFailure = sal_True; 135 } 136 #endif 137 } 138 } 139 140