1*ca5ec200SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ca5ec200SAndrew Rist * distributed with this work for additional information 6*ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance 9*ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ca5ec200SAndrew Rist * software distributed under the License is distributed on an 15*ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the 17*ca5ec200SAndrew Rist * specific language governing permissions and limitations 18*ca5ec200SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ca5ec200SAndrew Rist *************************************************************/ 21*ca5ec200SAndrew Rist 22*ca5ec200SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "oox/helper/progressbar.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicator.hpp> 27cdf0e10cSrcweir #include "oox/helper/helper.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir namespace oox { 30cdf0e10cSrcweir 31cdf0e10cSrcweir // ============================================================================ 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace ::com::sun::star::task; 34cdf0e10cSrcweir using namespace ::com::sun::star::uno; 35cdf0e10cSrcweir 36cdf0e10cSrcweir using ::rtl::OUString; 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace { 39cdf0e10cSrcweir 40cdf0e10cSrcweir const sal_Int32 PROGRESS_RANGE = 1000000; 41cdf0e10cSrcweir 42cdf0e10cSrcweir } // namespace 43cdf0e10cSrcweir 44cdf0e10cSrcweir // ============================================================================ 45cdf0e10cSrcweir 46cdf0e10cSrcweir IProgressBar::~IProgressBar() 47cdf0e10cSrcweir { 48cdf0e10cSrcweir } 49cdf0e10cSrcweir 50cdf0e10cSrcweir // ---------------------------------------------------------------------------- 51cdf0e10cSrcweir 52cdf0e10cSrcweir ISegmentProgressBar::~ISegmentProgressBar() 53cdf0e10cSrcweir { 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ============================================================================ 57cdf0e10cSrcweir // ============================================================================ 58cdf0e10cSrcweir 59cdf0e10cSrcweir ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) : 60cdf0e10cSrcweir mxIndicator( rxIndicator ), 61cdf0e10cSrcweir mfPosition( 0 ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir if( mxIndicator.is() ) 64cdf0e10cSrcweir mxIndicator->start( rText, PROGRESS_RANGE ); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir ProgressBar::~ProgressBar() 68cdf0e10cSrcweir { 69cdf0e10cSrcweir if( mxIndicator.is() ) 70cdf0e10cSrcweir mxIndicator->end(); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir double ProgressBar::getPosition() const 74cdf0e10cSrcweir { 75cdf0e10cSrcweir return mfPosition; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir void ProgressBar::setPosition( double fPosition ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "ProgressBar::setPosition - invalid position" ); 81cdf0e10cSrcweir mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 ); 82cdf0e10cSrcweir if( mxIndicator.is() ) 83cdf0e10cSrcweir mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) ); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir // ============================================================================ 87cdf0e10cSrcweir 88cdf0e10cSrcweir namespace prv { 89cdf0e10cSrcweir 90cdf0e10cSrcweir class SubSegment : public ISegmentProgressBar 91cdf0e10cSrcweir { 92cdf0e10cSrcweir public: 93cdf0e10cSrcweir explicit SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir virtual double getPosition() const; 96cdf0e10cSrcweir virtual void setPosition( double fPosition ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir virtual double getFreeLength() const; 99cdf0e10cSrcweir virtual ISegmentProgressBarRef createSegment( double fLength ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir private: 102cdf0e10cSrcweir IProgressBar& mrParentProgress; 103cdf0e10cSrcweir double mfStartPos; 104cdf0e10cSrcweir double mfLength; 105cdf0e10cSrcweir double mfPosition; 106cdf0e10cSrcweir double mfFreeStart; 107cdf0e10cSrcweir }; 108cdf0e10cSrcweir 109cdf0e10cSrcweir // ---------------------------------------------------------------------------- 110cdf0e10cSrcweir 111cdf0e10cSrcweir SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) : 112cdf0e10cSrcweir mrParentProgress( rParentProgress ), 113cdf0e10cSrcweir mfStartPos( fStartPos ), 114cdf0e10cSrcweir mfLength( fLength ), 115cdf0e10cSrcweir mfPosition( 0.0 ), 116cdf0e10cSrcweir mfFreeStart( 0.0 ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir double SubSegment::getPosition() const 121cdf0e10cSrcweir { 122cdf0e10cSrcweir return mfPosition; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir void SubSegment::setPosition( double fPosition ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "SubSegment::setPosition - invalid position" ); 128cdf0e10cSrcweir mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 ); 129cdf0e10cSrcweir mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength ); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir double SubSegment::getFreeLength() const 133cdf0e10cSrcweir { 134cdf0e10cSrcweir return 1.0 - mfFreeStart; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir ISegmentProgressBarRef SubSegment::createSegment( double fLength ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SubSegment::createSegment - invalid length" ); 140cdf0e10cSrcweir fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() ); 141cdf0e10cSrcweir ISegmentProgressBarRef xSegment( new prv::SubSegment( *this, mfFreeStart, fLength ) ); 142cdf0e10cSrcweir mfFreeStart += fLength; 143cdf0e10cSrcweir return xSegment; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir } // namespace prv 147cdf0e10cSrcweir 148cdf0e10cSrcweir // ============================================================================ 149cdf0e10cSrcweir 150cdf0e10cSrcweir SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) : 151cdf0e10cSrcweir maProgress( rxIndicator, rText ), 152cdf0e10cSrcweir mfFreeStart( 0.0 ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir double SegmentProgressBar::getPosition() const 157cdf0e10cSrcweir { 158cdf0e10cSrcweir return maProgress.getPosition(); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir void SegmentProgressBar::setPosition( double fPosition ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir maProgress.setPosition( fPosition ); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir double SegmentProgressBar::getFreeLength() const 167cdf0e10cSrcweir { 168cdf0e10cSrcweir return 1.0 - mfFreeStart; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" ); 174cdf0e10cSrcweir fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() ); 175cdf0e10cSrcweir ISegmentProgressBarRef xSegment( new prv::SubSegment( maProgress, mfFreeStart, fLength ) ); 176cdf0e10cSrcweir mfFreeStart += fLength; 177cdf0e10cSrcweir return xSegment; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir // ============================================================================ 181cdf0e10cSrcweir 182cdf0e10cSrcweir } // namespace oox 183