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 <osl/diagnose.h>
23 #include <com/sun/star/task/XStatusIndicator.hpp>
24 #include "oox/helper/helper.hxx"
28 using namespace ::com::sun::star::task
;
29 using namespace ::com::sun::star::uno
;
33 const sal_Int32 PROGRESS_RANGE
= 1000000;
37 IProgressBar::~IProgressBar()
41 ISegmentProgressBar::~ISegmentProgressBar()
45 ProgressBar::ProgressBar( const Reference
< XStatusIndicator
>& rxIndicator
, const OUString
& rText
) :
46 mxIndicator( rxIndicator
),
49 if( mxIndicator
.is() )
50 mxIndicator
->start( rText
, PROGRESS_RANGE
);
53 ProgressBar::~ProgressBar()
55 if( mxIndicator
.is() )
59 double ProgressBar::getPosition() const
64 void ProgressBar::setPosition( double fPosition
)
66 OSL_ENSURE( (mfPosition
<= fPosition
) && (fPosition
<= 1.0), "ProgressBar::setPosition - invalid position" );
67 mfPosition
= getLimitedValue
< double >( fPosition
, mfPosition
, 1.0 );
68 if( mxIndicator
.is() )
69 mxIndicator
->setValue( static_cast< sal_Int32
>( mfPosition
* PROGRESS_RANGE
) );
74 class SubSegment
: public ISegmentProgressBar
77 explicit SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
);
79 virtual double getPosition() const SAL_OVERRIDE
;
80 virtual void setPosition( double fPosition
) SAL_OVERRIDE
;
82 virtual double getFreeLength() const SAL_OVERRIDE
;
83 virtual ISegmentProgressBarRef
createSegment( double fLength
) SAL_OVERRIDE
;
86 IProgressBar
& mrParentProgress
;
93 SubSegment::SubSegment( IProgressBar
& rParentProgress
, double fStartPos
, double fLength
) :
94 mrParentProgress( rParentProgress
),
95 mfStartPos( fStartPos
),
102 double SubSegment::getPosition() const
107 void SubSegment::setPosition( double fPosition
)
109 OSL_ENSURE( (mfPosition
<= fPosition
) && (fPosition
<= 1.0), "SubSegment::setPosition - invalid position" );
110 mfPosition
= getLimitedValue
< double >( fPosition
, mfPosition
, 1.0 );
111 mrParentProgress
.setPosition( mfStartPos
+ mfPosition
* mfLength
);
114 double SubSegment::getFreeLength() const
116 return 1.0 - mfFreeStart
;
119 ISegmentProgressBarRef
SubSegment::createSegment( double fLength
)
121 OSL_ENSURE( (0.0 < fLength
) && (fLength
<= getFreeLength()), "SubSegment::createSegment - invalid length" );
122 fLength
= getLimitedValue
< double >( fLength
, 0.0, getFreeLength() );
123 ISegmentProgressBarRef
xSegment( new prv::SubSegment( *this, mfFreeStart
, fLength
) );
124 mfFreeStart
+= fLength
;
130 SegmentProgressBar::SegmentProgressBar( const Reference
< XStatusIndicator
>& rxIndicator
, const OUString
& rText
) :
131 maProgress( rxIndicator
, rText
),
136 double SegmentProgressBar::getPosition() const
138 return maProgress
.getPosition();
141 void SegmentProgressBar::setPosition( double fPosition
)
143 maProgress
.setPosition( fPosition
);
146 double SegmentProgressBar::getFreeLength() const
148 return 1.0 - mfFreeStart
;
151 ISegmentProgressBarRef
SegmentProgressBar::createSegment( double fLength
)
153 OSL_ENSURE( (0.0 < fLength
) && (fLength
<= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" );
154 fLength
= getLimitedValue
< double >( fLength
, 0.0, getFreeLength() );
155 ISegmentProgressBarRef
xSegment( new prv::SubSegment( maProgress
, mfFreeStart
, fLength
) );
156 mfFreeStart
+= fLength
;
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */