1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: progressbar.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/helper/progressbar.hxx"
32 #include <com/sun/star/task/XStatusIndicator.hpp>
33 #include "oox/helper/helper.hxx"
35 using ::rtl::OUString
;
36 using ::com::sun::star::uno::Reference
;
37 using ::com::sun::star::task::XStatusIndicator
;
41 // ============================================================================
45 const sal_Int32 PROGRESS_RANGE
= 1000000;
49 // ============================================================================
51 IProgressBar::~IProgressBar()
55 // ----------------------------------------------------------------------------
57 ISegmentProgressBar::~ISegmentProgressBar()
61 // ============================================================================
62 // ============================================================================
64 ProgressBar::ProgressBar( const Reference
< XStatusIndicator
>& rxIndicator
, const OUString
& rText
) :
65 mxIndicator( rxIndicator
),
68 if( mxIndicator
.is() )
69 mxIndicator
->start( rText
, PROGRESS_RANGE
);
72 ProgressBar::~ProgressBar()
74 if( mxIndicator
.is() )
78 double ProgressBar::getPosition() const
83 void ProgressBar::setPosition( double fPosition
)
85 OSL_ENSURE( (mfPosition
<= fPosition
) && (fPosition
<= 1.0), "ProgressBar::setPosition - invalid position" );
86 mfPosition
= getLimitedValue
< double >( fPosition
, mfPosition
, 1.0 );
87 if( mxIndicator
.is() )
88 mxIndicator
->setValue( static_cast< sal_Int32
>( mfPosition
* PROGRESS_RANGE
) );
91 // ============================================================================
95 class SubSegment
: public ISegmentProgressBar
98 explicit SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
);
100 virtual double getPosition() const;
101 virtual void setPosition( double fPosition
);
103 virtual double getFreeLength() const;
104 virtual ISegmentProgressBarRef
createSegment( double fLength
);
107 IProgressBar
& mrParentProgress
;
114 // ----------------------------------------------------------------------------
116 SubSegment::SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
) :
117 mrParentProgress( rParentProgress
),
118 mfStartPos( fStartPos
),
125 double SubSegment::getPosition() const
130 void SubSegment::setPosition( double fPosition
)
132 OSL_ENSURE( (mfPosition
<= fPosition
) && (fPosition
<= 1.0), "SubSegment::setPosition - invalid position" );
133 mfPosition
= getLimitedValue
< double >( fPosition
, mfPosition
, 1.0 );
134 mrParentProgress
.setPosition( mfStartPos
+ mfPosition
* mfLength
);
137 double SubSegment::getFreeLength() const
139 return 1.0 - mfFreeStart
;
142 ISegmentProgressBarRef
SubSegment::createSegment( double fLength
)
144 OSL_ENSURE( (0.0 < fLength
) && (fLength
<= getFreeLength()), "SubSegment::createSegment - invalid length" );
145 fLength
= getLimitedValue
< double >( fLength
, 0.0, getFreeLength() );
146 ISegmentProgressBarRef
xSegment( new prv::SubSegment( *this, mfFreeStart
, fLength
) );
147 mfFreeStart
+= fLength
;
153 // ============================================================================
155 SegmentProgressBar::SegmentProgressBar( const Reference
< XStatusIndicator
>& rxIndicator
, const OUString
& rText
) :
156 maProgress( rxIndicator
, rText
),
161 double SegmentProgressBar::getPosition() const
163 return maProgress
.getPosition();
166 void SegmentProgressBar::setPosition( double fPosition
)
168 maProgress
.setPosition( fPosition
);
171 double SegmentProgressBar::getFreeLength() const
173 return 1.0 - mfFreeStart
;
176 ISegmentProgressBarRef
SegmentProgressBar::createSegment( double fLength
)
178 OSL_ENSURE( (0.0 < fLength
) && (fLength
<= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" );
179 fLength
= getLimitedValue
< double >( fLength
, 0.0, getFreeLength() );
180 ISegmentProgressBarRef
xSegment( new prv::SubSegment( maProgress
, mfFreeStart
, fLength
) );
181 mfFreeStart
+= fLength
;
185 // ============================================================================