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
) );
77 class SubSegment
: public ISegmentProgressBar
80 explicit SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
);
82 virtual double getPosition() const override
;
83 virtual void setPosition( double fPosition
) override
;
85 virtual double getFreeLength() const override
;
86 virtual ISegmentProgressBarRef
createSegment( double fLength
) override
;
89 IProgressBar
& mrParentProgress
;
98 SubSegment::SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
) :
99 mrParentProgress( rParentProgress
),
100 mfStartPos( fStartPos
),
107 double SubSegment::getPosition() const
112 void SubSegment::setPosition( double fPosition
)
114 SAL_WARN_IF( (mfPosition
> fPosition
) || (fPosition
> 1.0), "oox", "SubSegment::setPosition - invalid position" );
115 mfPosition
= getLimitedValue
< double >( fPosition
, mfPosition
, 1.0 );
116 mrParentProgress
.setPosition( mfStartPos
+ mfPosition
* mfLength
);
119 double SubSegment::getFreeLength() const
121 return 1.0 - mfFreeStart
;
124 ISegmentProgressBarRef
SubSegment::createSegment( double fLength
)
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
;
133 } // namespace oox::prv
135 SegmentProgressBar::SegmentProgressBar( const Reference
< XStatusIndicator
>& rxIndicator
, const OUString
& rText
) :
136 maProgress( rxIndicator
, rText
),
141 double SegmentProgressBar::getPosition() const
143 return maProgress
.getPosition();
146 void SegmentProgressBar::setPosition( double fPosition
)
148 maProgress
.setPosition( fPosition
);
151 double SegmentProgressBar::getFreeLength() const
153 return 1.0 - mfFreeStart
;
156 ISegmentProgressBarRef
SegmentProgressBar::createSegment( double fLength
)
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
;
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */