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 .
20 #include <oox/helper/progressbar.hxx>
22 #include <com/sun/star/task/XStatusIndicator.hpp>
23 #include <oox/helper/helper.hxx>
25 #include <sal/log.hxx>
29 using namespace ::com::sun::star::task
;
30 using namespace ::com::sun::star::uno
;
34 const sal_Int32 PROGRESS_RANGE
= 1000000;
38 IProgressBar::~IProgressBar()
42 ISegmentProgressBar::~ISegmentProgressBar()
46 ProgressBar::ProgressBar( const Reference
< XStatusIndicator
>& rxIndicator
, const OUString
& rText
) :
47 mxIndicator( rxIndicator
),
50 if( mxIndicator
.is() )
51 mxIndicator
->start( rText
, PROGRESS_RANGE
);
54 ProgressBar::~ProgressBar()
56 if( mxIndicator
.is() )
60 double ProgressBar::getPosition() const
65 void ProgressBar::setPosition( double fPosition
)
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
) );
75 class SubSegment
: public ISegmentProgressBar
78 explicit SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
);
80 virtual double getPosition() const override
;
81 virtual void setPosition( double fPosition
) override
;
83 virtual double getFreeLength() const override
;
84 virtual ISegmentProgressBarRef
createSegment( double fLength
) override
;
87 IProgressBar
& mrParentProgress
;
88 double const mfStartPos
;
89 double const mfLength
;
94 SubSegment::SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
) :
95 mrParentProgress( rParentProgress
),
96 mfStartPos( fStartPos
),
103 double SubSegment::getPosition() const
108 void SubSegment::setPosition( double fPosition
)
110 SAL_WARN_IF( (mfPosition
> fPosition
) || (fPosition
> 1.0), "oox", "SubSegment::setPosition - invalid position" );
111 mfPosition
= getLimitedValue
< double >( fPosition
, mfPosition
, 1.0 );
112 mrParentProgress
.setPosition( mfStartPos
+ mfPosition
* mfLength
);
115 double SubSegment::getFreeLength() const
117 return 1.0 - mfFreeStart
;
120 ISegmentProgressBarRef
SubSegment::createSegment( double fLength
)
122 SAL_WARN_IF( (0.0 >= fLength
) || (fLength
> getFreeLength()), "oox", "SubSegment::createSegment - invalid length" );
123 fLength
= getLimitedValue
< double >( fLength
, 0.0, getFreeLength() );
124 ISegmentProgressBarRef
xSegment( new prv::SubSegment( *this, mfFreeStart
, fLength
) );
125 mfFreeStart
+= fLength
;
131 SegmentProgressBar::SegmentProgressBar( const Reference
< XStatusIndicator
>& rxIndicator
, const OUString
& rText
) :
132 maProgress( rxIndicator
, rText
),
137 double SegmentProgressBar::getPosition() const
139 return maProgress
.getPosition();
142 void SegmentProgressBar::setPosition( double fPosition
)
144 maProgress
.setPosition( fPosition
);
147 double SegmentProgressBar::getFreeLength() const
149 return 1.0 - mfFreeStart
;
152 ISegmentProgressBarRef
SegmentProgressBar::createSegment( double fLength
)
154 SAL_WARN_IF( (0.0 >= fLength
) || (fLength
> getFreeLength()), "oox", "SegmentProgressBar::createSegment - invalid length" );
155 fLength
= getLimitedValue
< double >( fLength
, 0.0, getFreeLength() );
156 ISegmentProgressBarRef
xSegment( new prv::SubSegment( maProgress
, mfFreeStart
, fLength
) );
157 mfFreeStart
+= fLength
;
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */