Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/helper/progressbar.cxx
Line
Count
Source
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 <oox/helper/progressbar.hxx>
21
22
#include <com/sun/star/task/XStatusIndicator.hpp>
23
#include <oox/helper/helper.hxx>
24
25
#include <sal/log.hxx>
26
27
namespace oox {
28
29
using namespace ::com::sun::star::task;
30
using namespace ::com::sun::star::uno;
31
32
namespace {
33
34
const sal_Int32 PROGRESS_RANGE      = 1000000;
35
36
} // namespace
37
38
IProgressBar::~IProgressBar()
39
49.5k
{
40
49.5k
}
41
42
ISegmentProgressBar::~ISegmentProgressBar()
43
{
44
}
45
46
ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
47
3.94k
    mxIndicator( rxIndicator ),
48
3.94k
    mfPosition( 0 )
49
3.94k
{
50
3.94k
    if( mxIndicator.is() )
51
0
        mxIndicator->start( rText, PROGRESS_RANGE );
52
3.94k
}
53
54
ProgressBar::~ProgressBar()
55
3.94k
{
56
3.94k
    if( mxIndicator.is() )
57
0
        mxIndicator->end();
58
3.94k
}
59
60
double ProgressBar::getPosition() const
61
0
{
62
0
    return mfPosition;
63
0
}
64
65
void ProgressBar::setPosition( double fPosition )
66
35.8k
{
67
35.8k
    SAL_WARN_IF( (mfPosition > fPosition) || (fPosition > 1.0), "oox", "ProgressBar::setPosition - invalid position" );
68
35.8k
    mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
69
35.8k
    if( mxIndicator.is() )
70
0
        mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) );
71
35.8k
}
72
73
namespace prv {
74
75
namespace {
76
77
class SubSegment : public ISegmentProgressBar
78
{
79
public:
80
    explicit            SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength );
81
82
    virtual double      getPosition() const override;
83
    virtual void        setPosition( double fPosition ) override;
84
85
    virtual double      getFreeLength() const override;
86
    virtual ISegmentProgressBarRef createSegment( double fLength ) override;
87
88
private:
89
    IProgressBar&       mrParentProgress;
90
    double              mfStartPos;
91
    double              mfLength;
92
    double              mfPosition;
93
    double              mfFreeStart;
94
};
95
96
}
97
98
SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
99
33.1k
    mrParentProgress( rParentProgress ),
100
33.1k
    mfStartPos( fStartPos ),
101
33.1k
    mfLength( fLength ),
102
33.1k
    mfPosition( 0.0 ),
103
33.1k
    mfFreeStart( 0.0 )
104
33.1k
{
105
33.1k
}
106
107
double SubSegment::getPosition() const
108
0
{
109
0
    return mfPosition;
110
0
}
111
112
void SubSegment::setPosition( double fPosition )
113
52.6k
{
114
52.6k
    SAL_WARN_IF( (mfPosition > fPosition) || (fPosition > 1.0), "oox", "SubSegment::setPosition - invalid position" );
115
52.6k
    mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
116
52.6k
    mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength );
117
52.6k
}
118
119
double SubSegment::getFreeLength() const
120
17.0k
{
121
17.0k
    return 1.0 - mfFreeStart;
122
17.0k
}
123
124
ISegmentProgressBarRef SubSegment::createSegment( double fLength )
125
17.0k
{
126
17.0k
    SAL_WARN_IF( (0.0 >= fLength) || (fLength > getFreeLength()), "oox", "SubSegment::createSegment - invalid length" );
127
17.0k
    fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
128
17.0k
    ISegmentProgressBarRef xSegment = std::make_shared<prv::SubSegment>( *this, mfFreeStart, fLength );
129
17.0k
    mfFreeStart += fLength;
130
17.0k
    return xSegment;
131
17.0k
}
132
133
} // namespace oox::prv
134
135
SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
136
3.94k
    maProgress( rxIndicator, rText ),
137
3.94k
    mfFreeStart( 0.0 )
138
3.94k
{
139
3.94k
}
140
141
double SegmentProgressBar::getPosition() const
142
0
{
143
0
    return maProgress.getPosition();
144
0
}
145
146
void SegmentProgressBar::setPosition( double fPosition )
147
0
{
148
0
    maProgress.setPosition( fPosition );
149
0
}
150
151
double SegmentProgressBar::getFreeLength() const
152
28.4k
{
153
28.4k
    return 1.0 - mfFreeStart;
154
28.4k
}
155
156
ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength )
157
16.1k
{
158
16.1k
    SAL_WARN_IF( (0.0 >= fLength) || (fLength > getFreeLength()), "oox", "SegmentProgressBar::createSegment - invalid length" );
159
16.1k
    fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
160
16.1k
    ISegmentProgressBarRef xSegment = std::make_shared<prv::SubSegment>( maProgress, mfFreeStart, fLength );
161
16.1k
    mfFreeStart += fLength;
162
16.1k
    return xSegment;
163
16.1k
}
164
165
} // namespace oox
166
167
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */