LibreOffice Module oox (master) 1
progressbar.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
21
22#include <com/sun/star/task/XStatusIndicator.hpp>
23#include <oox/helper/helper.hxx>
24
25#include <sal/log.hxx>
26
27namespace oox {
28
29using namespace ::com::sun::star::task;
30using namespace ::com::sun::star::uno;
31
32namespace {
33
34const sal_Int32 PROGRESS_RANGE = 1000000;
35
36} // namespace
37
39{
40}
41
43{
44}
45
46ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
47 mxIndicator( rxIndicator ),
48 mfPosition( 0 )
49{
50 if( mxIndicator.is() )
51 mxIndicator->start( rText, PROGRESS_RANGE );
52}
53
55{
56 if( mxIndicator.is() )
57 mxIndicator->end();
58}
59
61{
62 return mfPosition;
63}
64
65void ProgressBar::setPosition( double fPosition )
66{
67 SAL_WARN_IF( (mfPosition > fPosition) || (fPosition > 1.0), "oox", "ProgressBar::setPosition - invalid position" );
68 mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
69 if( mxIndicator.is() )
70 mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) );
71}
72
73namespace prv {
74
75namespace {
76
77class SubSegment : public ISegmentProgressBar
78{
79public:
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
88private:
89 IProgressBar& mrParentProgress;
90 double mfStartPos;
91 double mfLength;
92 double mfPosition;
94};
95
96}
97
98SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
99 mrParentProgress( rParentProgress ),
100 mfStartPos( fStartPos ),
101 mfLength( fLength ),
102 mfPosition( 0.0 ),
103 mfFreeStart( 0.0 )
104{
105}
106
107double SubSegment::getPosition() const
108{
109 return mfPosition;
110}
111
112void SubSegment::setPosition( double fPosition )
113{
114 SAL_WARN_IF( (mfPosition > fPosition) || (fPosition > 1.0), "oox", "SubSegment::setPosition - invalid position" );
115 mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
117}
118
119double SubSegment::getFreeLength() const
120{
121 return 1.0 - mfFreeStart;
122}
123
124ISegmentProgressBarRef SubSegment::createSegment( double fLength )
125{
126 SAL_WARN_IF( (0.0 >= fLength) || (fLength > getFreeLength()), "oox", "SubSegment::createSegment - invalid length" );
127 fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
128 ISegmentProgressBarRef xSegment = std::make_shared<prv::SubSegment>( *this, mfFreeStart, fLength );
129 mfFreeStart += fLength;
130 return xSegment;
131}
132
133} // namespace oox::prv
134
135SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
136 maProgress( rxIndicator, rText ),
137 mfFreeStart( 0.0 )
138{
139}
140
142{
143 return maProgress.getPosition();
144}
145
146void SegmentProgressBar::setPosition( double fPosition )
147{
148 maProgress.setPosition( fPosition );
149}
150
152{
153 return 1.0 - mfFreeStart;
154}
155
157{
158 SAL_WARN_IF( (0.0 >= fLength) || (fLength > getFreeLength()), "oox", "SegmentProgressBar::createSegment - invalid length" );
159 fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
160 ISegmentProgressBarRef xSegment = std::make_shared<prv::SubSegment>( maProgress, mfFreeStart, fLength );
161 mfFreeStart += fLength;
162 return xSegment;
163}
164
165} // namespace oox
166
167/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface for progress bar classes.
Definition: progressbar.hxx:40
virtual ~IProgressBar()
Definition: progressbar.cxx:38
Interface for a segment in a progress bar, that is able to create sub segments from itself.
Definition: progressbar.hxx:68
virtual ~ISegmentProgressBar() override
Definition: progressbar.cxx:42
css::uno::Reference< css::task::XStatusIndicator > mxIndicator
Definition: progressbar.hxx:98
virtual ~ProgressBar() override
Definition: progressbar.cxx:54
virtual void setPosition(double fPosition) override
Sets the current position of the progress bar.
Definition: progressbar.cxx:65
ProgressBar(const css::uno::Reference< css::task::XStatusIndicator > &rxIndicator, const OUString &rText)
virtual double getPosition() const override
Returns the current position of the progress bar.
Definition: progressbar.cxx:60
virtual ISegmentProgressBarRef createSegment(double fLength) override
Adds a new segment with the specified length.
virtual double getPosition() const override
Returns the current position of the progress bar segment.
virtual void setPosition(double fPosition) override
Sets the current position of the progress bar segment.
virtual double getFreeLength() const override
Returns the length that is still free for creating sub segments.
#define SAL_WARN_IF(condition, area, stream)
std::shared_ptr< ISegmentProgressBar > ISegmentProgressBarRef
Definition: progressbar.hxx:61
IProgressBar & mrParentProgress
Definition: progressbar.cxx:89
double mfStartPos
Definition: progressbar.cxx:90
double mfPosition
Definition: progressbar.cxx:92
double mfFreeStart
Definition: progressbar.cxx:93
double mfLength
Definition: progressbar.cxx:91
Any maProgress