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