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"
27 // ============================================================================
29 using namespace ::com::sun::star::task
;
30 using namespace ::com::sun::star::uno
;
34 const sal_Int32 PROGRESS_RANGE
= 1000000;
38 // ============================================================================
40 IProgressBar::~IProgressBar()
44 // ----------------------------------------------------------------------------
46 ISegmentProgressBar::~ISegmentProgressBar()
50 // ============================================================================
51 // ============================================================================
53 ProgressBar::ProgressBar( const Reference
< XStatusIndicator
>& rxIndicator
, const OUString
& rText
) :
54 mxIndicator( rxIndicator
),
57 if( mxIndicator
.is() )
58 mxIndicator
->start( rText
, PROGRESS_RANGE
);
61 ProgressBar::~ProgressBar()
63 if( mxIndicator
.is() )
67 double ProgressBar::getPosition() const
72 void ProgressBar::setPosition( double fPosition
)
74 OSL_ENSURE( (mfPosition
<= fPosition
) && (fPosition
<= 1.0), "ProgressBar::setPosition - invalid position" );
75 mfPosition
= getLimitedValue
< double >( fPosition
, mfPosition
, 1.0 );
76 if( mxIndicator
.is() )
77 mxIndicator
->setValue( static_cast< sal_Int32
>( mfPosition
* PROGRESS_RANGE
) );
80 // ============================================================================
84 class SubSegment
: public ISegmentProgressBar
87 explicit SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
);
89 virtual double getPosition() const;
90 virtual void setPosition( double fPosition
);
92 virtual double getFreeLength() const;
93 virtual ISegmentProgressBarRef
createSegment( double fLength
);
96 IProgressBar
& mrParentProgress
;
103 // ----------------------------------------------------------------------------
105 SubSegment::SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
) :
106 mrParentProgress( rParentProgress
),
107 mfStartPos( fStartPos
),
114 double SubSegment::getPosition() const
119 void SubSegment::setPosition( double fPosition
)
121 OSL_ENSURE( (mfPosition
<= fPosition
) && (fPosition
<= 1.0), "SubSegment::setPosition - invalid position" );
122 mfPosition
= getLimitedValue
< double >( fPosition
, mfPosition
, 1.0 );
123 mrParentProgress
.setPosition( mfStartPos
+ mfPosition
* mfLength
);
126 double SubSegment::getFreeLength() const
128 return 1.0 - mfFreeStart
;
131 ISegmentProgressBarRef
SubSegment::createSegment( double fLength
)
133 OSL_ENSURE( (0.0 < fLength
) && (fLength
<= getFreeLength()), "SubSegment::createSegment - invalid length" );
134 fLength
= getLimitedValue
< double >( fLength
, 0.0, getFreeLength() );
135 ISegmentProgressBarRef
xSegment( new prv::SubSegment( *this, mfFreeStart
, fLength
) );
136 mfFreeStart
+= fLength
;
142 // ============================================================================
144 SegmentProgressBar::SegmentProgressBar( const Reference
< XStatusIndicator
>& rxIndicator
, const OUString
& rText
) :
145 maProgress( rxIndicator
, rText
),
150 double SegmentProgressBar::getPosition() const
152 return maProgress
.getPosition();
155 void SegmentProgressBar::setPosition( double fPosition
)
157 maProgress
.setPosition( fPosition
);
160 double SegmentProgressBar::getFreeLength() const
162 return 1.0 - mfFreeStart
;
165 ISegmentProgressBarRef
SegmentProgressBar::createSegment( double fLength
)
167 OSL_ENSURE( (0.0 < fLength
) && (fLength
<= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" );
168 fLength
= getLimitedValue
< double >( fLength
, 0.0, getFreeLength() );
169 ISegmentProgressBarRef
xSegment( new prv::SubSegment( maProgress
, mfFreeStart
, fLength
) );
170 mfFreeStart
+= fLength
;
174 // ============================================================================
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */