1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <xmloff/ProgressBarHelper.hxx>
23 #include <osl/diagnose.h>
25 using namespace ::com::sun::star
;
27 const sal_Int32 nDefaultProgressBarRange
= 1000000;
28 const float fProgressStep
= 0.5;
30 ProgressBarHelper::ProgressBarHelper(css::uno::Reference
< css::task::XStatusIndicator
> xTempStatusIndicator
,
31 const bool bTempStrict
)
32 : m_xStatusIndicator(std::move(xTempStatusIndicator
))
33 , m_nRange(nDefaultProgressBarRange
)
37 , m_bStrict(bTempStrict
)
45 ProgressBarHelper::~ProgressBarHelper()
49 void ProgressBarHelper::ChangeReference(sal_Int32 nNewReference
)
51 if((nNewReference
<= 0) || (nNewReference
== m_nReference
))
56 double fPercent(static_cast<double>(nNewReference
) / m_nReference
);
57 double fValue(m_nValue
* fPercent
);
58 m_nValue
= static_cast<sal_Int32
>(fValue
);
59 m_nReference
= nNewReference
;
63 m_nReference
= nNewReference
;
68 void ProgressBarHelper::SetValue(sal_Int32 nTempValue
)
70 if (!m_xStatusIndicator
.is() || (m_nReference
<= 0))
73 if ((nTempValue
>= m_nValue
) && (!m_bStrict
|| (nTempValue
<= m_nReference
)))
75 // #91317# no progress bar with values > 100%
76 if (nTempValue
> m_nReference
)
79 m_nValue
= m_nReference
;
82 m_xStatusIndicator
->reset();
87 m_nValue
= nTempValue
;
89 double fValue(m_nValue
);
90 double fNewValue ((fValue
* m_nRange
) / m_nReference
);
92 double fPercent((fNewValue
* 100) / m_nRange
);
93 if (fPercent
>= (m_fOldPercent
+ fProgressStep
) || fPercent
< m_fOldPercent
)
95 m_xStatusIndicator
->setValue(static_cast<sal_Int32
>(fNewValue
));
96 m_fOldPercent
= fPercent
;
100 else if (!m_bFailure
)
102 OSL_FAIL("tried to set a wrong value on the progressbar");
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */