1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "oox/helper/progressbar.hxx" 29 30 #include <com/sun/star/task/XStatusIndicator.hpp> 31 #include "oox/helper/helper.hxx" 32 33 namespace oox { 34 35 // ============================================================================ 36 37 using namespace ::com::sun::star::task; 38 using namespace ::com::sun::star::uno; 39 40 using ::rtl::OUString; 41 42 namespace { 43 44 const sal_Int32 PROGRESS_RANGE = 1000000; 45 46 } // namespace 47 48 // ============================================================================ 49 50 IProgressBar::~IProgressBar() 51 { 52 } 53 54 // ---------------------------------------------------------------------------- 55 56 ISegmentProgressBar::~ISegmentProgressBar() 57 { 58 } 59 60 // ============================================================================ 61 // ============================================================================ 62 63 ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) : 64 mxIndicator( rxIndicator ), 65 mfPosition( 0 ) 66 { 67 if( mxIndicator.is() ) 68 mxIndicator->start( rText, PROGRESS_RANGE ); 69 } 70 71 ProgressBar::~ProgressBar() 72 { 73 if( mxIndicator.is() ) 74 mxIndicator->end(); 75 } 76 77 double ProgressBar::getPosition() const 78 { 79 return mfPosition; 80 } 81 82 void ProgressBar::setPosition( double fPosition ) 83 { 84 OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "ProgressBar::setPosition - invalid position" ); 85 mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 ); 86 if( mxIndicator.is() ) 87 mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) ); 88 } 89 90 // ============================================================================ 91 92 namespace prv { 93 94 class SubSegment : public ISegmentProgressBar 95 { 96 public: 97 explicit SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ); 98 99 virtual double getPosition() const; 100 virtual void setPosition( double fPosition ); 101 102 virtual double getFreeLength() const; 103 virtual ISegmentProgressBarRef createSegment( double fLength ); 104 105 private: 106 IProgressBar& mrParentProgress; 107 double mfStartPos; 108 double mfLength; 109 double mfPosition; 110 double mfFreeStart; 111 }; 112 113 // ---------------------------------------------------------------------------- 114 115 SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) : 116 mrParentProgress( rParentProgress ), 117 mfStartPos( fStartPos ), 118 mfLength( fLength ), 119 mfPosition( 0.0 ), 120 mfFreeStart( 0.0 ) 121 { 122 } 123 124 double SubSegment::getPosition() const 125 { 126 return mfPosition; 127 } 128 129 void SubSegment::setPosition( double fPosition ) 130 { 131 OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "SubSegment::setPosition - invalid position" ); 132 mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 ); 133 mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength ); 134 } 135 136 double SubSegment::getFreeLength() const 137 { 138 return 1.0 - mfFreeStart; 139 } 140 141 ISegmentProgressBarRef SubSegment::createSegment( double fLength ) 142 { 143 OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SubSegment::createSegment - invalid length" ); 144 fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() ); 145 ISegmentProgressBarRef xSegment( new prv::SubSegment( *this, mfFreeStart, fLength ) ); 146 mfFreeStart += fLength; 147 return xSegment; 148 } 149 150 } // namespace prv 151 152 // ============================================================================ 153 154 SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) : 155 maProgress( rxIndicator, rText ), 156 mfFreeStart( 0.0 ) 157 { 158 } 159 160 double SegmentProgressBar::getPosition() const 161 { 162 return maProgress.getPosition(); 163 } 164 165 void SegmentProgressBar::setPosition( double fPosition ) 166 { 167 maProgress.setPosition( fPosition ); 168 } 169 170 double SegmentProgressBar::getFreeLength() const 171 { 172 return 1.0 - mfFreeStart; 173 } 174 175 ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength ) 176 { 177 OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" ); 178 fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() ); 179 ISegmentProgressBarRef xSegment( new prv::SubSegment( maProgress, mfFreeStart, fLength ) ); 180 mfFreeStart += fLength; 181 return xSegment; 182 } 183 184 // ============================================================================ 185 186 } // namespace oox 187