Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / oox / source / helper / progressbar.cxx
blobada6f7ecd4be2e1d505a41a47413ba8a9accc627
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <oox/helper/progressbar.hxx>
22 #include <com/sun/star/task/XStatusIndicator.hpp>
23 #include <oox/helper/helper.hxx>
25 namespace oox {
27 using namespace ::com::sun::star::task;
28 using namespace ::com::sun::star::uno;
30 namespace {
32 const sal_Int32 PROGRESS_RANGE = 1000000;
34 } // namespace
36 IProgressBar::~IProgressBar()
40 ISegmentProgressBar::~ISegmentProgressBar()
44 ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
45 mxIndicator( rxIndicator ),
46 mfPosition( 0 )
48 if( mxIndicator.is() )
49 mxIndicator->start( rText, PROGRESS_RANGE );
52 ProgressBar::~ProgressBar()
54 if( mxIndicator.is() )
55 mxIndicator->end();
58 double ProgressBar::getPosition() const
60 return mfPosition;
63 void ProgressBar::setPosition( double fPosition )
65 SAL_WARN_IF( (mfPosition > fPosition) || (fPosition > 1.0), "oox", "ProgressBar::setPosition - invalid position" );
66 mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
67 if( mxIndicator.is() )
68 mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) );
71 namespace prv {
73 class SubSegment : public ISegmentProgressBar
75 public:
76 explicit SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength );
78 virtual double getPosition() const override;
79 virtual void setPosition( double fPosition ) override;
81 virtual double getFreeLength() const override;
82 virtual ISegmentProgressBarRef createSegment( double fLength ) override;
84 private:
85 IProgressBar& mrParentProgress;
86 double mfStartPos;
87 double mfLength;
88 double mfPosition;
89 double mfFreeStart;
92 SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
93 mrParentProgress( rParentProgress ),
94 mfStartPos( fStartPos ),
95 mfLength( fLength ),
96 mfPosition( 0.0 ),
97 mfFreeStart( 0.0 )
101 double SubSegment::getPosition() const
103 return mfPosition;
106 void SubSegment::setPosition( double fPosition )
108 SAL_WARN_IF( (mfPosition > fPosition) || (fPosition > 1.0), "oox", "SubSegment::setPosition - invalid position" );
109 mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
110 mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength );
113 double SubSegment::getFreeLength() const
115 return 1.0 - mfFreeStart;
118 ISegmentProgressBarRef SubSegment::createSegment( double fLength )
120 SAL_WARN_IF( (0.0 >= fLength) || (fLength > getFreeLength()), "oox", "SubSegment::createSegment - invalid length" );
121 fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
122 ISegmentProgressBarRef xSegment( new prv::SubSegment( *this, mfFreeStart, fLength ) );
123 mfFreeStart += fLength;
124 return xSegment;
127 } // namespace prv
129 SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
130 maProgress( rxIndicator, rText ),
131 mfFreeStart( 0.0 )
135 double SegmentProgressBar::getPosition() const
137 return maProgress.getPosition();
140 void SegmentProgressBar::setPosition( double fPosition )
142 maProgress.setPosition( fPosition );
145 double SegmentProgressBar::getFreeLength() const
147 return 1.0 - mfFreeStart;
150 ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength )
152 SAL_WARN_IF( (0.0 >= fLength) || (fLength > getFreeLength()), "oox", "SegmentProgressBar::createSegment - invalid length" );
153 fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
154 ISegmentProgressBarRef xSegment( new prv::SubSegment( maProgress, mfFreeStart, fLength ) );
155 mfFreeStart += fLength;
156 return xSegment;
159 } // namespace oox
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */