Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : :
31 : :
32 : :
33 : :
34 : : //___________________________________________________________________
35 : : #include <xmloff/ProgressBarHelper.hxx>
36 : : #include <tools/debug.hxx>
37 : : #include <xmloff/xmltoken.hxx>
38 : :
39 : : #include <stdlib.h>
40 : :
41 : : using namespace ::com::sun::star;
42 : :
43 : : const sal_Int32 nDefaultProgressBarRange = 1000000;
44 : :
45 : 576 : ProgressBarHelper::ProgressBarHelper(const ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator>& xTempStatusIndicator,
46 : : const sal_Bool bTempStrict)
47 : : : xStatusIndicator(xTempStatusIndicator)
48 : : , nRange(nDefaultProgressBarRange)
49 : : , nReference(100)
50 : : , nValue(0)
51 : : , bStrict(bTempStrict)
52 : 576 : , bRepeat(sal_True)
53 : : #ifdef DBG_UTIL
54 : : , bFailure(sal_False)
55 : : #endif
56 : : {
57 : 576 : }
58 : :
59 : 576 : ProgressBarHelper::~ProgressBarHelper()
60 : : {
61 : 576 : }
62 : :
63 : 8 : sal_Int32 ProgressBarHelper::ChangeReference(sal_Int32 nNewReference)
64 : : {
65 [ + - ][ + + ]: 8 : if((nNewReference > 0) && (nNewReference != nReference))
66 : : {
67 [ + - ]: 4 : if (nReference)
68 : : {
69 : 4 : double fPercent(nNewReference / nReference);
70 : 4 : double fValue(nValue * fPercent);
71 : : #if OSL_DEBUG_LEVEL > 0
72 : : // workaround for toolchain bug on solaris/x86 Sun C++ 5.5
73 : : // just call some function here
74 : : (void) abs(nValue);
75 : : #endif
76 : 4 : nValue = static_cast< sal_Int32 >(fValue);
77 : 4 : nReference = nNewReference;
78 : : }
79 : : else
80 : : {
81 : 0 : nReference = nNewReference;
82 : 0 : nValue = 0;
83 : : }
84 : : }
85 : 8 : return nValue;
86 : : }
87 : :
88 : 3106 : void ProgressBarHelper::SetValue(sal_Int32 nTempValue)
89 : : {
90 [ + + ][ + - ]: 3106 : if (xStatusIndicator.is() && (nReference > 0))
[ + + ]
91 : : {
92 [ + - ][ - + ]: 1042 : if ((nTempValue >= nValue) && (!bStrict || (bStrict && (nTempValue <= nReference))))
[ # # ][ # # ]
93 : : {
94 : : // #91317# no progress bar with values > 100%
95 [ + + ]: 1042 : if (nTempValue > nReference)
96 : : {
97 [ - + ]: 30 : if (!bRepeat)
98 : 0 : nValue = nReference;
99 : : else
100 : : {
101 : 30 : xStatusIndicator->reset();
102 : 30 : nValue = 0;
103 : : }
104 : : }
105 : : else
106 : 1012 : nValue = nTempValue;
107 : :
108 : 1042 : double fValue(nValue);
109 : 1042 : double fNewValue ((fValue * nRange) / nReference);
110 : :
111 : 1042 : xmloff::token::IncRescheduleCount();
112 : :
113 : 1042 : xStatusIndicator->setValue((sal_Int32)fNewValue);
114 : :
115 : 1042 : xmloff::token::DecRescheduleCount();
116 : :
117 : : // #95181# disabled, because we want to call setValue very often to enable a good reschedule
118 : : }
119 : : #ifdef DBG_UTIL
120 : : else if (!bFailure)
121 : : {
122 : : OSL_FAIL("tried to set a wrong value on the progressbar");
123 : : bFailure = sal_True;
124 : : }
125 : : #endif
126 : : }
127 : 3106 : }
128 : :
129 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|