1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ProgressBarHelper.cxx,v $
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>
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
)
57 , bStrict(bTempStrict
)
65 ProgressBarHelper::~ProgressBarHelper()
69 sal_Int32
ProgressBarHelper::ChangeReference(sal_Int32 nNewReference
)
71 if((nNewReference
> 0) && (nNewReference
!= 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
82 nValue
= static_cast< sal_Int32
>(fValue
);
83 nReference
= nNewReference
;
87 nReference
= nNewReference
;
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
)
107 // xStatusIndicator->end();
108 // xStatusIndicator->start();
109 xStatusIndicator
->reset();
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))
129 // xStatusIndicator->setValue((sal_Int32)fNewValue);
130 // fOldPercent = fPercent;
136 DBG_ERROR("tried to set a wrong value on the progressbar");