Update ooo320-m1
[ooovba.git] / xmloff / source / core / ProgressBarHelper.cxx
blob94c8e2dc742733780d043a8f82b1d0e995a2a893
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ProgressBarHelper.cxx,v $
10 * $Revision: 1.23 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
38 //___________________________________________________________________
39 #include <xmloff/ProgressBarHelper.hxx>
40 #include <tools/debug.hxx>
41 #include <xmloff/xmltoken.hxx>
43 #include <stdlib.h>
45 using namespace ::com::sun::star;
47 const sal_Int32 nDefaultProgressBarRange = 1000000;
48 const float fProgressStep = 0.5;
50 ProgressBarHelper::ProgressBarHelper(const ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator>& xTempStatusIndicator,
51 const sal_Bool bTempStrict)
52 : xStatusIndicator(xTempStatusIndicator)
53 , nRange(nDefaultProgressBarRange)
54 , nReference(100)
55 , nValue(0)
56 , fOldPercent(0.0)
57 , bStrict(bTempStrict)
58 , bRepeat(sal_True)
59 #ifndef PRODUCT
60 , bFailure(sal_False)
61 #endif
65 ProgressBarHelper::~ProgressBarHelper()
69 sal_Int32 ProgressBarHelper::ChangeReference(sal_Int32 nNewReference)
71 if((nNewReference > 0) && (nNewReference != nReference))
73 if (nReference)
75 double fPercent(nNewReference / nReference);
76 double fValue(nValue * fPercent);
77 #if OSL_DEBUG_LEVEL > 0
78 // workaround for toolchain bug on solaris/x86 Sun C++ 5.5
79 // just call some function here
80 (void) abs(nValue);
81 #endif
82 nValue = static_cast< sal_Int32 >(fValue);
83 nReference = nNewReference;
85 else
87 nReference = nNewReference;
88 nValue = 0;
91 return nValue;
94 void ProgressBarHelper::SetValue(sal_Int32 nTempValue)
96 if (xStatusIndicator.is() && (nReference > 0))
98 if ((nTempValue >= nValue) && (!bStrict || (bStrict && (nTempValue <= nReference))))
100 // #91317# no progress bar with values > 100%
101 if (nTempValue > nReference)
103 if (!bRepeat)
104 nValue = nReference;
105 else
107 // xStatusIndicator->end();
108 // xStatusIndicator->start();
109 xStatusIndicator->reset();
110 nValue = 0;
113 else
114 nValue = nTempValue;
116 double fValue(nValue);
117 double fNewValue ((fValue * nRange) / nReference);
119 xmloff::token::IncRescheduleCount();
121 xStatusIndicator->setValue((sal_Int32)fNewValue);
123 xmloff::token::DecRescheduleCount();
125 // #95181# disabled, because we want to call setValue very often to enable a good reschedule
126 // double fPercent ((fNewValue * 100) / nRange);
127 // if (fPercent >= (fOldPercent + fProgressStep))
128 // {
129 // xStatusIndicator->setValue((sal_Int32)fNewValue);
130 // fOldPercent = fPercent;
131 // }
133 #ifndef PRODUCT
134 else if (!bFailure)
136 DBG_ERROR("tried to set a wrong value on the progressbar");
137 bFailure = sal_True;
139 #endif