GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / helper / progressbar.cxx
blob6b6dd014e5401840f857960b9a7a927e6a6c1e19
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
25 namespace oox {
27 // ============================================================================
29 using namespace ::com::sun::star::task;
30 using namespace ::com::sun::star::uno;
32 namespace {
34 const sal_Int32 PROGRESS_RANGE = 1000000;
36 } // namespace
38 // ============================================================================
40 IProgressBar::~IProgressBar()
44 // ----------------------------------------------------------------------------
46 ISegmentProgressBar::~ISegmentProgressBar()
50 // ============================================================================
51 // ============================================================================
53 ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
54 mxIndicator( rxIndicator ),
55 mfPosition( 0 )
57 if( mxIndicator.is() )
58 mxIndicator->start( rText, PROGRESS_RANGE );
61 ProgressBar::~ProgressBar()
63 if( mxIndicator.is() )
64 mxIndicator->end();
67 double ProgressBar::getPosition() const
69 return mfPosition;
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 // ============================================================================
82 namespace prv {
84 class SubSegment : public ISegmentProgressBar
86 public:
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 );
95 private:
96 IProgressBar& mrParentProgress;
97 double mfStartPos;
98 double mfLength;
99 double mfPosition;
100 double mfFreeStart;
103 // ----------------------------------------------------------------------------
105 SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
106 mrParentProgress( rParentProgress ),
107 mfStartPos( fStartPos ),
108 mfLength( fLength ),
109 mfPosition( 0.0 ),
110 mfFreeStart( 0.0 )
114 double SubSegment::getPosition() const
116 return mfPosition;
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;
137 return xSegment;
140 } // namespace prv
142 // ============================================================================
144 SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
145 maProgress( rxIndicator, rText ),
146 mfFreeStart( 0.0 )
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;
171 return xSegment;
174 // ============================================================================
176 } // namespace oox
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */