LibreOffice Module xmloff (master) 1
ProgressBarHelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <utility>
22
23#include <osl/diagnose.h>
24
25using namespace ::com::sun::star;
26
27const sal_Int32 nDefaultProgressBarRange = 1000000;
28const float fProgressStep = 0.5;
29
30ProgressBarHelper::ProgressBarHelper(css::uno::Reference < css::task::XStatusIndicator> xTempStatusIndicator,
31 const bool bTempStrict)
32: m_xStatusIndicator(std::move(xTempStatusIndicator))
34, m_nReference(100)
35, m_nValue(0)
36, m_fOldPercent(0.0)
37, m_bStrict(bTempStrict)
38, m_bRepeat(true)
39#ifdef DBG_UTIL
40, m_bFailure(false)
41#endif
42{
43}
44
46{
47}
48
49void ProgressBarHelper::ChangeReference(sal_Int32 nNewReference)
50{
51 if((nNewReference <= 0) || (nNewReference == m_nReference))
52 return;
53
54 if (m_nReference)
55 {
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;
60 }
61 else
62 {
63 m_nReference = nNewReference;
64 m_nValue = 0;
65 }
66}
67
68void ProgressBarHelper::SetValue(sal_Int32 nTempValue)
69{
70 if (!m_xStatusIndicator.is() || (m_nReference <= 0))
71 return;
72
73 if ((nTempValue >= m_nValue) && (!m_bStrict || (nTempValue <= m_nReference)))
74 {
75 // #91317# no progress bar with values > 100%
76 if (nTempValue > m_nReference)
77 {
78 if (!m_bRepeat)
80 else
81 {
82 m_xStatusIndicator->reset();
83 m_nValue = 0;
84 }
85 }
86 else
87 m_nValue = nTempValue;
88
89 double fValue(m_nValue);
90 double fNewValue ((fValue * m_nRange) / m_nReference);
91
92 double fPercent((fNewValue * 100) / m_nRange);
93 if (fPercent >= (m_fOldPercent + fProgressStep) || fPercent < m_fOldPercent)
94 {
95 m_xStatusIndicator->setValue(static_cast<sal_Int32>(fNewValue));
96 m_fOldPercent = fPercent;
97 }
98 }
99#ifdef DBG_UTIL
100 else if (!m_bFailure)
101 {
102 OSL_FAIL("tried to set a wrong value on the progressbar");
103 m_bFailure = true;
104 }
105#endif
106}
107
108/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const float fProgressStep
const sal_Int32 nDefaultProgressBarRange
ProgressBarHelper(css::uno::Reference< css::task::XStatusIndicator > xStatusIndicator, const bool bStrict)
void SetValue(sal_Int32 nValue)
css::uno::Reference< css::task::XStatusIndicator > m_xStatusIndicator
void ChangeReference(sal_Int32 nNewReference)